linux/Documentation/i2c
Peter Rosin 1ffcfaf195 iio: imu: inv_mpu6050: change the i2c gate to be mux-locked
The root i2c adapter lock is then no longer held by the i2c mux during
accesses behind the i2c gate, and such accesses need to take that lock
just like any other ordinary i2c accesses do.

So, declare the i2c gate mux-locked, and zap the code that makes the
unlocked i2c accesses and just use ordinary regmap_write accesses.

This also happens to fix the deadlock described in
http://patchwork.ozlabs.org/patch/584776/ authored by
Adriana Reus <adriana.reus@intel.com> and submitted by
Daniel Baluta <daniel.baluta@intel.com>

----------8<----------
iio: imu: inv_mpu6050: Fix deadlock between i2c adapter lock and mpu lock

This deadlock occurs if the accel/gyro and the sensor on the auxiliary
I2C (in my setup it's an ak8975) are working at the same time.

Scenario:

      T1					T2
     ====				       ====
inv_mpu6050_read_fifo                  aux sensor op (eg. ak8975_read_raw)
        |                                     |
mutex_lock(&indio_dev->mlock)           i2c_transfer
        |                                     |
i2c transaction                         i2c adapter lock
        |                                     |
i2c adapter lock                        i2c_mux_master_xfer
                                              |
                                        inv_mpu6050_select_bypass
                                              |
                                        mutex_lock(&indio_dev->mlock)

When we operate on an mpu sensor the order of locking is mpu lock
followed by the i2c adapter lock. However, when we operate the auxiliary
sensor the order of locking is the other way around.

...
----------8<----------

The reason this patch fixes the deadlock is that T2 does not grab the
i2c adapter lock until the very end (and grabs the newfangled i2c mux
lock where it previously grabbed the i2c adapter lock).

Acked-by: Jonathan Cameron <jic23@kernel.org>
Acked-by: Daniel Baluta <daniel.baluta@intel.com>
Tested-by: Crestez Dan Leonard <leonard.crestez@intel.com>
Signed-off-by: Peter Rosin <peda@axentia.se>
Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
2016-05-04 22:39:30 +02:00
..
busses i2c: i801: add Intel Lewisburg device IDs 2015-11-20 16:22:21 +01:00
muxes
dev-interface Doc: i2c: Fix typo in Documentation/i2c 2016-02-10 13:12:14 -07:00
fault-codes
functionality i2c: fix reference to functionality constants definition 2015-02-19 16:57:48 +01:00
i2c-protocol Documentation: i2c: improve section about flags mangling the protocol 2014-04-06 13:53:48 +02:00
i2c-stub i2c: stub: Add support for banked register ranges 2014-07-17 19:56:15 +02:00
i2c-topology iio: imu: inv_mpu6050: change the i2c gate to be mux-locked 2016-05-04 22:39:30 +02:00
instantiating-devices Documentation: i2c: mention ACPI method for instantiating devices 2014-02-15 19:46:34 +01:00
old-module-parameters
slave-eeprom-backend Doc: i2c: Fix typo in Documentation/i2c 2016-02-10 13:12:14 -07:00
slave-interface i2c: support 10 bit and slave addresses in sysfs 'new_device' 2015-08-24 14:05:15 +02:00
smbus-protocol
summary Documentation: i2c: describe the new slave mode 2015-03-27 16:53:39 +01:00
ten-bit-addresses i2c: support 10 bit and slave addresses in sysfs 'new_device' 2015-08-24 14:05:15 +02:00
upgrading-clients Documentation: i2c: Use PM ops instead of legacy suspend/resume 2014-12-04 19:09:03 +01:00
writing-clients Documentation: i2c: Use PM ops instead of legacy suspend/resume 2014-12-04 19:09:03 +01:00