From: Jonathan Cameron <jic23@kernel.org>
To: Jean-Baptiste Maneyrol <JManeyrol@invensense.com>
Cc: "linux-iio@vger.kernel.org" <linux-iio@vger.kernel.org>
Subject: Re: [PATCH v3 1/7] iio: imu: inv_mpu6050: disable i2c mux for MPU925x
Date: Sat, 5 Oct 2019 11:57:50 +0100 [thread overview]
Message-ID: <20191005115750.5ba997ce@archlinux> (raw)
In-Reply-To: <20190916094128.30122-2-jmaneyrol@invensense.com>
On Mon, 16 Sep 2019 09:41:58 +0000
Jean-Baptiste Maneyrol <JManeyrol@invensense.com> wrote:
> Disable i2c mux for supported 9xxx chips. This is a
> pre-requesite for controling 9xxx magnetometer using the
> i2c master of the chip.
>
> Check in device-tree that there is no i2c-gate device declared
> for ensuring backward compatibility with existing setups.
>
> Signed-off-by: Jean-Baptiste Maneyrol <jmaneyrol@invensense.com>
Applied to the togreg branch of iio.git and pushed out as testing for
the autobuilders to play with it.
Thanks,
Jonathan
> ---
> drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 7 +--
> drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c | 60 +++++++++++++++++++---
> drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h | 2 +
> 3 files changed, 58 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
> index b17f060b52fc..7b2e4d81bbba 100644
> --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
> +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
> @@ -1156,9 +1156,6 @@ int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name,
> return result;
> }
>
> - if (inv_mpu_bus_setup)
> - inv_mpu_bus_setup(indio_dev);
> -
> dev_set_drvdata(dev, indio_dev);
> indio_dev->dev.parent = dev;
> /* name will be NULL when enumerated via ACPI */
> @@ -1167,6 +1164,10 @@ int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name,
> else
> indio_dev->name = dev_name(dev);
>
> + /* requires parent device set in indio_dev */
> + if (inv_mpu_bus_setup)
> + inv_mpu_bus_setup(indio_dev);
> +
> if (chip_type == INV_ICM20602) {
> indio_dev->channels = inv_icm20602_channels;
> indio_dev->num_channels = ARRAY_SIZE(inv_icm20602_channels);
> diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c
> index 4b8b5a87398c..389cc8505e0e 100644
> --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c
> +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c
> @@ -68,6 +68,56 @@ static const char *inv_mpu_match_acpi_device(struct device *dev,
> return dev_name(dev);
> }
>
> +static bool inv_mpu_i2c_aux_bus(struct device *dev)
> +{
> + struct inv_mpu6050_state *st = iio_priv(dev_get_drvdata(dev));
> +
> + switch (st->chip_type) {
> + case INV_ICM20608:
> + case INV_ICM20602:
> + /* no i2c auxiliary bus on the chip */
> + return false;
> + case INV_MPU9250:
> + case INV_MPU9255:
> + if (st->magn_disabled)
> + return true;
> + else
> + return false;
> + default:
> + return true;
> + }
> +}
> +
> +/*
> + * MPU9xxx magnetometer support requires to disable i2c auxiliary bus support.
> + * To ensure backward compatibility with existing setups, do not disable
> + * i2c auxiliary bus if it used.
> + * Check for i2c-gate node in devicetree and set magnetometer disabled.
> + * Only MPU6500 is supported by ACPI, no need to check.
> + */
> +static int inv_mpu_magn_disable(struct iio_dev *indio_dev)
> +{
> + struct inv_mpu6050_state *st = iio_priv(indio_dev);
> + struct device *dev = indio_dev->dev.parent;
> + struct device_node *mux_node;
> +
> + switch (st->chip_type) {
> + case INV_MPU9250:
> + case INV_MPU9255:
> + mux_node = of_get_child_by_name(dev->of_node, "i2c-gate");
> + if (mux_node != NULL) {
> + st->magn_disabled = true;
> + dev_warn(dev, "disable internal use of magnetometer\n");
> + }
> + of_node_put(mux_node);
> + break;
> + default:
> + break;
> + }
> +
> + return 0;
> +}
> +
> /**
> * inv_mpu_probe() - probe function.
> * @client: i2c client.
> @@ -112,17 +162,12 @@ static int inv_mpu_probe(struct i2c_client *client,
> }
>
> result = inv_mpu_core_probe(regmap, client->irq, name,
> - NULL, chip_type);
> + inv_mpu_magn_disable, chip_type);
> if (result < 0)
> return result;
>
> st = iio_priv(dev_get_drvdata(&client->dev));
> - switch (st->chip_type) {
> - case INV_ICM20608:
> - case INV_ICM20602:
> - /* no i2c auxiliary bus on the chip */
> - break;
> - default:
> + if (inv_mpu_i2c_aux_bus(&client->dev)) {
> /* declare i2c auxiliary bus */
> st->muxc = i2c_mux_alloc(client->adapter, &client->dev,
> 1, 0, I2C_MUX_LOCKED | I2C_MUX_GATE,
> @@ -137,7 +182,6 @@ static int inv_mpu_probe(struct i2c_client *client,
> result = inv_mpu_acpi_create_mux_client(client);
> if (result)
> goto out_del_mux;
> - break;
> }
>
> return 0;
> diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
> index db1c6904388b..cbbb2fb8949a 100644
> --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
> +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
> @@ -125,6 +125,7 @@ struct inv_mpu6050_hw {
> * @it_timestamp: timestamp from previous interrupt.
> * @data_timestamp: timestamp for next data sample.
> * @vddio_supply voltage regulator for the chip.
> + * @magn_disabled: magnetometer disabled for backward compatibility reason.
> */
> struct inv_mpu6050_state {
> struct mutex lock;
> @@ -146,6 +147,7 @@ struct inv_mpu6050_state {
> s64 it_timestamp;
> s64 data_timestamp;
> struct regulator *vddio_supply;
> + bool magn_disabled;
> };
>
> /*register and associated bit definition*/
next prev parent reply other threads:[~2019-10-05 10:57 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-16 9:41 [PATCH v3 0/7] add magnetometer support for MPU925x Jean-Baptiste Maneyrol
2019-09-16 9:41 ` [PATCH v3 1/7] iio: imu: inv_mpu6050: disable i2c mux " Jean-Baptiste Maneyrol
2019-10-05 10:57 ` Jonathan Cameron [this message]
2019-09-16 9:42 ` [PATCH v3 2/7] iio: imu: inv_mpu6050: add header include protection macro Jean-Baptiste Maneyrol
2019-10-05 10:58 ` Jonathan Cameron
2019-09-16 9:42 ` [PATCH v3 3/7] iio: imu: inv_mpu6050: add defines for supporting 9-axis chips Jean-Baptiste Maneyrol
2019-10-05 10:58 ` Jonathan Cameron
2019-09-16 9:42 ` [PATCH v3 4/7] iio: imu: inv_mpu6050: fix objects syntax in Makefile Jean-Baptiste Maneyrol
2019-10-05 11:00 ` Jonathan Cameron
2019-09-16 9:42 ` [PATCH v3 5/7] iio: imu: inv_mpu6050: helpers for using i2c master on auxiliary bus Jean-Baptiste Maneyrol
2019-10-05 11:06 ` Jonathan Cameron
2019-09-16 9:42 ` [PATCH v3 6/7] iio: imu: inv_mpu6050: add MPU925x magnetometer support Jean-Baptiste Maneyrol
2019-10-05 11:13 ` Jonathan Cameron
2019-09-16 9:42 ` [PATCH v3 7/7] iio: imu: inv_mpu6050: add fifo support for magnetometer data Jean-Baptiste Maneyrol
2019-10-05 11:15 ` Jonathan Cameron
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20191005115750.5ba997ce@archlinux \
--to=jic23@kernel.org \
--cc=JManeyrol@invensense.com \
--cc=linux-iio@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox