22 Aug, 2018

1 commit

  • Pull i2c updates from Wolfram Sang:

    - the core has now a lockless variant of i2c_smbus_xfer. Some open
    coded versions of this got removed in drivers. This also enables
    proper SCCB support in regmap.

    - locking got a more precise naming. i2c_{un}lock_adapter() had to go,
    and we know use i2c_lock_bus() consistently with flags like
    I2C_LOCK_ROOT_ADAPTER and I2C_LOCK_SEGMENT to avoid ambiguity.

    - the gpio fault injector got a new delicate testcase

    - the bus recovery procedure got fixed to handle the new testcase
    correctly

    - a new quirk flag for controllers not able to handle zero length
    messages together with driver updates to use it

    - new drivers: FSI bus attached I2C masters, GENI I2C controller, Owl
    family S900

    - and a good set of driver improvements and bugfixes

    * 'i2c/for-4.19' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux: (77 commits)
    i2c: rcar: implement STOP and REP_START according to docs
    i2c: rcar: refactor private flags
    i2c: core: ACPI: Make acpi_gsb_i2c_read_bytes() check i2c_transfer return value
    i2c: core: ACPI: Properly set status byte to 0 for multi-byte writes
    dt-bindings: i2c: rcar: Add r8a774a1 support
    dt-bindings: i2c: sh_mobile: Add r8a774a1 support
    i2c: imx: Simplify stopped state tracking
    i2c: imx: Fix race condition in dma read
    i2c: pasemi: remove hardcoded bus numbers on smbus
    i2c: designware: Add SPDX license tag
    i2c: designware: Convert to use struct i2c_timings
    i2c: core: Parse SDA hold time from firmware
    i2c: designware-pcidrv: Mark expected switch fall-through
    i2c: amd8111: Mark expected switch fall-through
    i2c: sh_mobile: use core to detect 'no zero length read' quirk
    i2c: xlr: use core to detect 'no zero length' quirk
    i2c: rcar: use core to detect 'no zero length' quirk
    i2c: stu300: use core to detect 'no zero length' quirk
    i2c: pmcmsp: use core to detect 'no zero length' quirk
    i2c: mxs: use core to detect 'no zero length' quirk
    ...

    Linus Torvalds
     

25 Jul, 2018

1 commit

  • If an i2c topology has instances of nested muxes, then a lockdep splat
    is produced when when i2c_parent_lock_bus() is called. Here is an
    example:

    ============================================
    WARNING: possible recursive locking detected
    --------------------------------------------
    insmod/68159 is trying to acquire lock:
    (i2c_register_adapter#2){+.+.}, at: i2c_parent_lock_bus+0x32/0x50 [i2c_mux]

    but task is already holding lock:
    (i2c_register_adapter#2){+.+.}, at: i2c_parent_lock_bus+0x32/0x50 [i2c_mux]

    other info that might help us debug this:
    Possible unsafe locking scenario:

    CPU0
    ----
    lock(i2c_register_adapter#2);
    lock(i2c_register_adapter#2);

    *** DEADLOCK ***

    May be due to missing lock nesting notation

    1 lock held by insmod/68159:
    #0: (i2c_register_adapter#2){+.+.}, at: i2c_parent_lock_bus+0x32/0x50 [i2c_mux]

    stack backtrace:
    CPU: 13 PID: 68159 Comm: insmod Tainted: G O
    Call Trace:
    dump_stack+0x67/0x98
    __lock_acquire+0x162e/0x1780
    lock_acquire+0xba/0x200
    rt_mutex_lock+0x44/0x60
    i2c_parent_lock_bus+0x32/0x50 [i2c_mux]
    i2c_parent_lock_bus+0x3e/0x50 [i2c_mux]
    i2c_smbus_xfer+0xf0/0x700
    i2c_smbus_read_byte+0x42/0x70
    my2c_init+0xa2/0x1000 [my2c]
    do_one_initcall+0x51/0x192
    do_init_module+0x62/0x216
    load_module+0x20f9/0x2b50
    SYSC_init_module+0x19a/0x1c0
    SyS_init_module+0xe/0x10
    do_syscall_64+0x6c/0x1a0
    entry_SYSCALL_64_after_hwframe+0x42/0xb7

    Reported-by: John Sperbeck
    Tested-by: John Sperbeck
    Signed-off-by: Peter Rosin
    Signed-off-by: Peter Zijlstra (Intel)
    Cc: Davidlohr Bueso
    Cc: Deepa Dinamani
    Cc: Greg Kroah-Hartman
    Cc: Linus Torvalds
    Cc: Peter Chang
    Cc: Peter Zijlstra
    Cc: Philippe Ombredanne
    Cc: Thomas Gleixner
    Cc: Will Deacon
    Cc: Wolfram Sang
    Link: http://lkml.kernel.org/r/20180720083914.1950-3-peda@axentia.se
    Signed-off-by: Ingo Molnar

    Peter Rosin
     

04 Jul, 2018

1 commit

  • Calling the __i2c_smbus_xfer wrapper in __i2c_mux_smbus_xfer provides
    retries and thus makes the parent-locked case consistent with the both
    mux-locked (i2c_mux_smbus_xfer) and the I2C transfer cases.

    Signed-off-by: Peter Rosin
    Signed-off-by: Wolfram Sang

    Peter Rosin
     

24 May, 2018

1 commit


16 May, 2017

1 commit


03 Apr, 2017

1 commit


03 Mar, 2017

1 commit


31 Aug, 2016

1 commit


26 Aug, 2016

3 commits


05 May, 2016

2 commits

  • With a i2c topology like the following

    GPIO ---| ------ BAT1
    | v /
    I2C -----+----------+---- MUX
    | \
    EEPROM ------ BAT2

    there is a locking problem with the GPIO controller since it is a client
    on the same i2c bus that it muxes. Transfers to the mux clients (e.g. BAT1)
    will lock the whole i2c bus prior to attempting to switch the mux to the
    correct i2c segment. In the above case, the GPIO device is an I/O expander
    with an i2c interface, and since the GPIO subsystem knows nothing (and
    rightfully so) about the lockless needs of the i2c mux code, this results
    in a deadlock when the GPIO driver issues i2c transfers to modify the
    mux.

    So, observing that while it is needed to have the i2c bus locked during the
    actual MUX update in order to avoid random garbage on the slave side, it
    is not strictly a must to have it locked over the whole sequence of a full
    select-transfer-deselect mux client operation. The mux itself needs to be
    locked, so transfers to clients behind the mux are serialized, and the mux
    needs to be stable during all i2c traffic (otherwise individual mux slave
    segments might see garbage, or worse).

    Introduce this new locking concept as "mux-locked" muxes, and call the
    pre-existing mux locking scheme "parent-locked".

    Modify the i2c mux locking so that muxes that are "mux-locked" locks only
    the muxes on the parent adapter instead of the whole i2c bus when there is
    a transfer to the slave side of the mux. This lock serializes transfers to
    the slave side of the muxes on the parent adapter.

    Add code to i2c-mux-gpio and i2c-mux-pinctrl that checks if all involved
    gpio/pinctrl devices have a parent that is an i2c adapter in the same
    adapter tree that is muxed, and request a "mux-locked mux" if that is the
    case.

    Modify the select-transfer-deselect code for "mux-locked" muxes so
    that each of the select-transfer-deselect ops locks the mux parent
    adapter individually.

    Signed-off-by: Peter Rosin
    Signed-off-by: Wolfram Sang

    Peter Rosin
     
  • Instead of checking for i2c parent adapters for every lock/unlock, simply
    override the locking for muxes to always lock/unlock the parent adapter
    directly.

    Signed-off-by: Peter Rosin
    Signed-off-by: Wolfram Sang

    Peter Rosin
     

22 Apr, 2016

2 commits

  • All i2c mux users are using an explicit i2c mux core, drop support
    for implicit i2c mux cores.

    Signed-off-by: Peter Rosin
    Signed-off-by: Wolfram Sang

    Peter Rosin
     
  • All i2c-muxes have a parent adapter and one or many child
    adapters. A mux also has some means of selection. Previously,
    this was stored per child adapter, but it is only needed
    to keep track of this per mux.

    Add an i2c mux core, that keeps track of this consistently.

    Also add some glue for users of the old interface, which will
    create one implicit mux core per child adapter.

    Signed-off-by: Peter Rosin
    Tested-by: Antti Palosaari
    Tested-by: Crestez Dan Leonard
    Signed-off-by: Wolfram Sang

    Peter Rosin
     

21 Feb, 2016

1 commit


25 Oct, 2015

1 commit

  • Although I2C mux devices are easily enumerated using ACPI (_HID/_CID or
    device property compatible string match), enumerating I2C client devices
    connected through an I2C mux needs a little extra work.

    This change implements a method for describing an I2C device hierarchy that
    includes mux devices by using an ACPI Device() for each mux channel along
    with an _ADR to set the channel number for the device. See
    Documentation/acpi/i2c-muxes.txt for a simple example.

    To make this work the ismt, i801, and designware pci/platform devs now
    share an ACPI companion with their I2C adapter dev similar to how it's done
    in OF. This is done on the assumption that power management functions will
    not be called directly on the I2C dev that is sharing the ACPI node.

    Acked-by: Mika Westerberg
    Tested-by: Mika Westerberg
    Signed-off-by: Dustin Byford
    Signed-off-by: Wolfram Sang

    Dustin Byford
     

17 Jun, 2015

2 commits

  • Newly introduced quirks infrastructure doesn't work for the devices behind
    MUXes because MUX's master_xfer() calls parent's master_xfer() directly
    without checking the quirks. Instead of duplicating check code in MUX just
    call __i2c_transfer() instead. This has a side effect on tracing (messages
    will appear on both MUX bus and parent bus), but maybe that's not bad at
    the end.

    Signed-off-by: Alexander Sverdlin
    Tested-by: Łukasz Gemborowski
    Signed-off-by: Wolfram Sang
    Cc: stable@kernel.org
    Fixes: b7f625840267b1 ("i2c: add quirk checks to core")

    Alexander Sverdlin
     
  • Inherit parent adapter quirks in MUX in case the devices on the multiplexed
    buses are interested in the adapter limitations.

    Signed-off-by: Łukasz Gemborowski
    Signed-off-by: Alexander Sverdlin
    Signed-off-by: Wolfram Sang
    Cc: stable@kernel.org
    Fixes: b7f625840267b1 ("i2c: add quirk checks to core")

    Alexander Sverdlin
     

24 Apr, 2015

1 commit

  • Those symlinks are created for the mux_dev, so we need to remove it from
    there. Currently, it breaks for muxes where the mux_dev is not the device
    of the parent adapter like this:

    [ 78.234644] WARNING: CPU: 0 PID: 365 at fs/sysfs/dir.c:31 sysfs_warn_dup+0x5c/0x78()
    [ 78.242438] sysfs: cannot create duplicate filename '/devices/platform/i2cbus@8/channel-0'

    Remove confusing comments while we are here.

    Signed-off-by: Wolfram Sang
    Signed-off-by: Wolfram Sang
    Fixes: c9449affad2ae0
    Cc: stable@kernel.org

    Wolfram Sang
     

18 Nov, 2014

2 commits

  • This makes the topology clearer. For instance, by adding a pca9547
    device with address 0x70 to bus i2c-0, you get:

    /sys/class/i2c-dev/i2c-0/device/0-0070/channel-0 -> i2c-1
    ...
    /sys/class/i2c-dev/i2c-0/device/0-0070/channel-7 -> i2c-8

    Signed-off-by: Gerlando Falauto
    [wsa: simplified sysfs-usage and fixed format string usage]
    Signed-off-by: Wolfram Sang
    Acked-by: Martin Belanger
    Acked-by: Danielle Costantino

    Gerlando Falauto
     
  • The current implementation creates muxed i2c- busses as immediate
    children of their i2c- parent bus. In case of multiple muxes on one
    bus, it is impossible to determine which muxed bus comes from which mux.

    It could be argued that the parent device should be changed from the
    parent adapter to the mux device. This has pros and cons. To improve the
    topology, simply add a "mux_device" symlink pointing to the actual
    muxing device, so we can distinguish muxed busses. Doing it this way, we
    don't break the ABI.

    Signed-off-by: Wolfram Sang
    Tested-by: Guenter Roeck

    Wolfram Sang
     

13 Dec, 2013

1 commit

  • If a muxed i2c bus gets created the default retry count and
    timeout of the muxed bus is zero. Hence it it possible that you
    end up with a situation where the parent controller sets a default
    retry count and timeout which gets applied and used while the muxed
    bus (using the same controller) has a default retry count of zero
    and a default timeout of 1s (set in i2c_add_adapter()). This can be
    solved by initializing the retry count and timeout of the muxed
    bus with the values used by the the parent at creation time.

    Signed-off-by: Elie De Brauwer
    Signed-off-by: Wolfram Sang

    Elie De Brauwer
     

23 Aug, 2013

1 commit

  • I2C of helpers used to live in of_i2c.c but experience (from SPI) shows
    that it is much cleaner to have this in the core. This also removes a
    circular dependency between the helpers and the core, and so we can
    finally register child nodes in the core instead of doing this manually
    in each driver. So, fix the drivers and documentation, too.

    Signed-off-by: Wolfram Sang

    Wolfram Sang
     

02 Apr, 2013

2 commits

  • i2c_del_mux_adapter always returns 0 and none of it current users check its
    return value anyway. It is also an essential requirement of the Linux device
    driver model, that functions which may be called from a device's remove callback
    to free resources provided by the device, are not allowed to fail. This is the
    case for i2c_del_mux_adapter(), so make its return type void to make the
    fact that it won't fail explicit.

    Signed-off-by: Lars-Peter Clausen
    Reviewed-by: Jean Delvare
    Signed-off-by: Wolfram Sang

    Lars-Peter Clausen
     
  • i2c_del_adapter() always returns 0. So all checks testing whether it will be
    non zero will always evaluate to false and the conditional code is dead code.
    This patch updates all callers of i2c_del_mux_adapter() to ignore the return
    value and assume that it will always succeed (which it will). In a subsequent
    patch the return type of i2c_del_adapter() will be made void.

    Signed-off-by: Lars-Peter Clausen
    Acked-by: Ben Hutchings
    Reviewed-by: Jean Delvare
    Acked-by: Shawn Guo
    Signed-off-by: Wolfram Sang

    Lars-Peter Clausen
     

06 Oct, 2012

1 commit

  • Let I2C bus segments behind multiplexers have a class. This allows for
    device auto-detection on these segments. As long as parent segments
    don't share the same class, it should be fine.

    I implemented support in drivers i2c-mux-gpio and i2c-mux-pca954x. I
    left i2c-mux-pca9541 and i2c-mux-pinctrl alone for the moment as I
    don't know if this feature makes sense for the use cases of these
    drivers.

    Signed-off-by: Jean Delvare
    Cc: Peter Korsgaard
    Cc: David Daney
    Cc: Michael Lawnick
    Cc: Rodolfo Giometti

    Jean Delvare
     

12 May, 2012

2 commits

  • For 'normal' i2c bus drivers, we can call of_i2c_register_devices()
    and have the device tree framework automatically populate the bus with
    the devices specified in the device tree.

    This patch adds a common code to the i2c mux framework to have the mux
    sub-busses be populated by the of_i2c_register_devices() too. If the
    mux device has an of_node, we populate the sub-bus' of_node so that
    the subsequent call to of_i2c_register_devices() will find the
    corresponding devices.

    It seemed better to put this logic in i2c_add_mux_adapter() rather
    than the individual mux drivers, as they will all probably want to do
    the same thing.

    Signed-off-by: David Daney
    Acked-by: Stephen Warren
    Tested-by: Lars-Peter Clausen

    [wsa: removed superfluous ret-variable and fixed a typo in a comment]
    Signed-off-by: Wolfram Sang

    David Daney
     
  • And adjust all callers.

    The new device parameter is used in the next patch to initialize the
    mux's of_node so that its children may be automatically populated.

    Signed-off-by: David Daney
    Tested-by: Lars-Peter Clausen
    Signed-off-by: Wolfram Sang

    David Daney
     

16 Nov, 2010

1 commit

  • It's about time to make it clear that i2c_adapter.id is deprecated.
    Hopefully this will remind the last user to move over to a different
    strategy.

    Signed-off-by: Jean Delvare
    Acked-by: Jarod Wilson
    Acked-by: Mauro Carvalho Chehab
    Acked-by: Hans Verkuil

    Jean Delvare
     

12 Aug, 2010

1 commit