Multiple SPI MCP23S17s sharing a CS line

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

We have a user asking for help to construct a Device Tree overlay to use
the GPIOs exported by multiple MCP23S17s sharing an SPI Chip Select line. This is a special feature of the MCP devices whereby the SPI bus
is treated rather like an I2C bus with each device assigned a unique
address. His problem is in constructing gpiospecs to refer to all of the
GPIOs.

The mcp23s08 driver claims to support this feature, and there is a DT
property ("microchip,spi-present-mask") to declare which addresses are
used buy the devices. I've spent an hour or so looking at the driver code and crawling through the kernel GPIO infrastructure, and I don't think it's possible. Here's my logic:

1. Although all devices that are found are presented as a single SPI device, they are each registered as independent gpio_chips.

2. A gpio_chip has (amongst other things) a pointer to is Device Tree node, a number of GPIOs, and a function that translates from the "gpiospec" descriptors found in the device tree to an index into the GPIOs exposed by the device. Note that it doesn't include the base of a range - all gpio_chips have GPIOs indexed from 0.

3. The mcp23s08 doesn't specify a translation function, so it inherits the default of_gpio_simple_xlate that checks that the first parameter is less than the number of GPIOs the device supports, and returns it.

4. When another DT node refers to a GPIO, it does so using a gpiospec. This is passed to gpiochip_find, which uses of_gpiochip_match_node_and_xlate to filter through all the registered GPIO controllers to find one which:

i) has a DT node which matches the first cell (e.g. "&gpio"),
ii) has a translation function, and
iii) the translation function succeeds.

5. Continuing point 2, all the MCP devices that share an SPI CS/CE inherit the same DT node, which means they will all pass test i). Test ii) is trivially passed by all of the devices. Since they all have the same translation function (of_gpiochip_match_node_and_xlate), and they are all given the same gpiospec to translate, and you aren't meant to mix different size variants, the sharing devices will also either all pass or all fail the test iii).

Therefore I think it's impossible to construct gpiospecs to refer to all of the GPIOs exported by MCP23S17s in this configuration. Please explain
where I've gone wrong.

Thanks,

Phil Elwell



[Index of Archives]     [Linux SPI]     [Linux Kernel]     [Linux ARM (vger)]     [Linux ARM MSM]     [Linux Omap]     [Linux Arm]     [Linux Tegra]     [Fedora ARM]     [Linux for Samsung SOC]     [eCos]     [Linux Fastboot]     [Gcc Help]     [Git]     [DCCP]     [IETF Announce]     [Security]     [Linux MIPS]     [Yosemite Campsites]

  Powered by Linux