linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jean-Baptiste Maneyrol <JManeyrol@invensense.com>
To: Jonathan Cameron <jic23@kernel.org>
Cc: "linux-iio@vger.kernel.org" <linux-iio@vger.kernel.org>,
	Peter Rosin <peda@axentia.se>
Subject: Re: [PATCH 01/13] iio: imu: inv_mpu6050: enable i2c aux mux bypass only once
Date: Tue, 18 Feb 2020 16:03:31 +0000	[thread overview]
Message-ID: <CH2PR12MB4181C91F701528E7082E5AB1C4110@CH2PR12MB4181.namprd12.prod.outlook.com> (raw)
In-Reply-To: <20200215173004.7569c210@archlinux>

Hello,

sorry first for the desastrous text formatting.

The main idea behind is to be backward compatible with existing setup. Otherwise using i2c-mux to do nothing is not very useful. But this way we ensure backward compatibility and gain the advantage of not having to do i2c transaction with the mpu chip before every transaction with the auxiliary chip.

JB


From: Jonathan Cameron <jic23@kernel.org>

Sent: Saturday, February 15, 2020 18:30

To: Jean-Baptiste Maneyrol <JManeyrol@invensense.com>

Cc: linux-iio@vger.kernel.org <linux-iio@vger.kernel.org>; Peter Rosin <peda@axentia.se>

Subject: Re: [PATCH 01/13] iio: imu: inv_mpu6050: enable i2c aux mux bypass only once

 


 CAUTION: This email originated from outside of the organization. Please make sure the sender is who they say they are and do not click links or open attachments unless you recognize the sender and know the content is safe.



On Wed, 12 Feb 2020 18:40:36 +0100

Jean-Baptiste Maneyrol <jmaneyrol@invensense.com> wrote:



> i2c auxiliary mux is done by analog switches. You do not need to

> set them for every i2c transfer.

> Just set i2c bypass bit at init and do noting in i2c de/select.

> 

> Signed-off-by: Jean-Baptiste Maneyrol <jmaneyrol@invensense.com>

Fair enough.  Given we are making the decision based on DT and that

can't change on reprobing etc so this change makes sense to me I think.



It does leave us making rather odd use of the mux code, so I'd

just like Peter to take a quick look at this before I apply it.



Jonathan



> ---

>  drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c | 71 +++++++++--------------

>  1 file changed, 28 insertions(+), 43 deletions(-)

> 

> diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c

> index 1363d3776523..24df880248f2 100644

> --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c

> +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c

> @@ -20,38 +20,6 @@ static const struct regmap_config inv_mpu_regmap_config = {


>  static int inv_mpu6050_select_bypass(struct i2c_mux_core *muxc, u32 chan_id)

>  {

> -     struct iio_dev *indio_dev = i2c_mux_priv(muxc);

> -     struct inv_mpu6050_state *st = iio_priv(indio_dev);

> -     int ret;

> -

> -     mutex_lock(&st->lock);

> -

> -     ret = inv_mpu6050_set_power_itg(st, true);

> -     if (ret)

> -             goto error_unlock;

> -

> -     ret = regmap_write(st->map, st->reg->int_pin_cfg,

> -                        st->irq_mask | INV_MPU6050_BIT_BYPASS_EN);

> -

> -error_unlock:

> -     mutex_unlock(&st->lock);

> -

> -     return ret;

> -}

> -

> -static int inv_mpu6050_deselect_bypass(struct i2c_mux_core *muxc, u32 chan_id)

> -{

> -     struct iio_dev *indio_dev = i2c_mux_priv(muxc);

> -     struct inv_mpu6050_state *st = iio_priv(indio_dev);

> -

> -     mutex_lock(&st->lock);

> -

> -     /* It doesn't really matter if any of the calls fail */

> -     regmap_write(st->map, st->reg->int_pin_cfg, st->irq_mask);

> -     inv_mpu6050_set_power_itg(st, false);

> -

> -     mutex_unlock(&st->lock);

> -

>        return 0;

>  }


> @@ -79,19 +47,20 @@ static bool inv_mpu_i2c_aux_bus(struct device *dev)

>        }

>  }


> -/*

> - * 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)

> +static int inv_mpu_i2c_aux_setup(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;

> +     int ret;


> +     /*

> +      * MPU9xxx magnetometer support requires to disable i2c auxiliary bus.

> +      * 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.

> +      */

>        switch (st->chip_type) {

>        case INV_MPU9150:

>        case INV_MPU9250:

> @@ -107,7 +76,24 @@ static int inv_mpu_magn_disable(struct iio_dev *indio_dev)

>                break;

>        }


> +     /* enable i2c bypass when using i2c auxiliary bus */

> +     if (inv_mpu_i2c_aux_bus(dev)) {

> +             ret = inv_mpu6050_set_power_itg(st, true);

> +             if (ret)

> +                     return ret;

> +             ret = regmap_write(st->map, st->reg->int_pin_cfg,

> +                                st->irq_mask | INV_MPU6050_BIT_BYPASS_EN);

> +             if (ret)

> +                     goto error;

> +             ret = inv_mpu6050_set_power_itg(st, false);

> +             if (ret)

> +                     goto error;

> +     }

> +

>        return 0;

> +error:

> +     inv_mpu6050_set_power_itg(st, false);

> +     return ret;

>  }


>  /**

> @@ -151,7 +137,7 @@ static int inv_mpu_probe(struct i2c_client *client,

>        }


>        result = inv_mpu_core_probe(regmap, client->irq, name,

> -                                 inv_mpu_magn_disable, chip_type);

> +                                 inv_mpu_i2c_aux_setup, chip_type);

>        if (result < 0)

>                return result;


> @@ -160,8 +146,7 @@ static int inv_mpu_probe(struct i2c_client *client,

>                /* declare i2c auxiliary bus */

>                st->muxc = i2c_mux_alloc(client->adapter, &client->dev,

>                                         1, 0, I2C_MUX_LOCKED | I2C_MUX_GATE,

> -                                      inv_mpu6050_select_bypass,

> -                                      inv_mpu6050_deselect_bypass);

> +                                      inv_mpu6050_select_bypass, NULL);

>                if (!st->muxc)

>                        return -ENOMEM;

>                st->muxc->priv = dev_get_drvdata(&client->dev);




  reply	other threads:[~2020-02-18 16:18 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-12 17:40 [PATCH 00/13] Rework sensors engines and power management Jean-Baptiste Maneyrol
2020-02-12 17:40 ` [PATCH 01/13] iio: imu: inv_mpu6050: enable i2c aux mux bypass only once Jean-Baptiste Maneyrol
2020-02-15 17:30   ` Jonathan Cameron
2020-02-18 16:03     ` Jean-Baptiste Maneyrol [this message]
2020-02-12 17:40 ` [PATCH 02/13] iio: imu: inv_mpu6050: delete useless check Jean-Baptiste Maneyrol
2020-02-12 17:40 ` [PATCH 03/13] iio: imu: inv_mpu6050: set power on/off only once during all init Jean-Baptiste Maneyrol
2020-02-12 17:40 ` [PATCH 04/13] iio: imu: inv_mpu6050: simplify polling magnetometer Jean-Baptiste Maneyrol
2020-02-12 17:40 ` [PATCH 05/13] iio: imu: inv_mpu6050: early init of chip_config for use at setup Jean-Baptiste Maneyrol
2020-02-12 17:40 ` [PATCH 06/13] iio: imu: inv_mpu6050: add all signal path resets at init Jean-Baptiste Maneyrol
2020-02-12 17:40 ` [PATCH 07/13] iio: imu: inv_mpu6050: fix sleep time when turning regulators on Jean-Baptiste Maneyrol
2020-02-12 17:40 ` [PATCH 08/13] iio: imu: inv_mpu6050: rewrite power and engine management Jean-Baptiste Maneyrol
2020-02-15 18:09   ` Jonathan Cameron
2020-02-12 17:40 ` [PATCH 09/13] iio: imu: inv_mpu6050: fix data polling interface Jean-Baptiste Maneyrol
2020-02-12 17:40 ` [PATCH 10/13] iio: imu: inv_mpu6050: factorize fifo enable/disable Jean-Baptiste Maneyrol
2020-02-12 17:40 ` [PATCH 11/13] iio: imu: inv_mpu6050: dynamic sampling rate change Jean-Baptiste Maneyrol
2020-02-12 17:40 ` [PATCH 12/13] iio: imu: inv_mpu6050: use runtime pm with autosuspend Jean-Baptiste Maneyrol
2020-02-15 18:22   ` Jonathan Cameron
2020-02-18 16:44     ` Jean-Baptiste Maneyrol
2020-02-12 17:40 ` [PATCH 13/13] iio: imu: inv_mpu6050: temperature only work with accel/gyro Jean-Baptiste Maneyrol
2020-02-15 18:23   ` Jonathan Cameron
2020-02-18 16:46     ` Jean-Baptiste Maneyrol

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=CH2PR12MB4181C91F701528E7082E5AB1C4110@CH2PR12MB4181.namprd12.prod.outlook.com \
    --to=jmaneyrol@invensense.com \
    --cc=jic23@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=peda@axentia.se \
    /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;
as well as URLs for NNTP newsgroup(s).