• Peter Rosin's avatar
    iio: imu: inv_mpu6050: change the i2c gate to be mux-locked · 1ffcfaf1
    Peter Rosin authored
    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: default avatarJonathan Cameron <jic23@kernel.org>
    Acked-by: default avatarDaniel Baluta <daniel.baluta@intel.com>
    Tested-by: default avatarCrestez Dan Leonard <leonard.crestez@intel.com>
    Signed-off-by: default avatarPeter Rosin <peda@axentia.se>
    Signed-off-by: default avatarWolfram Sang <wsa@the-dreams.de>
    1ffcfaf1
i2c-topology 14.7 KB