diff options
author | David Brownell <david-b@pacbell.net> | 2008-07-25 04:46:09 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2008-07-25 13:53:30 -0400 |
commit | 8f1cc3b10e6ee0c5c7c8ed27f8771c4f252b4862 (patch) | |
tree | a64611af44cf46aea2e2b145fad85042bb647a3d /include/linux/spi/mcp23s08.h | |
parent | d8f388d8dc8d4f36539dd37c1fff62cc404ea0fc (diff) |
gpio: mcp23s08 handles multiple chips per chipselect
Teach the mcp23s08 driver about a curious feature of these chips: up to
four of them can share the same chipselect, with the SPI signals wired in
parallel, by matching two bits in the first protocol byte against two
address lines on the chip.
This is handled by three software changes:
* Platform data now holds an array of per-chip structs, not
just one chip's address and pullup configuration.
* Probe() and remove() now use another level of structure,
wrapping an instance of the original structure for each
mcp23s08 chip sharing that chipselect.
* The HAEN bit is set, so that the hardware address bits can no
longer be ignored (boot firmware may not have enabled them).
The "one struct per chip" preserves the guts of the current code,
but platform_data will need minor changes.
OLD:
/* incorrect "slave" ID may not have mattered */
.slave = 3,
.pullups = BIT(3) | BIT(1) | BIT(0),
NEW:
/* slave address _must_ match chip's wiring */
.chip[3] = {
.is_present = true,
.pullups = BIT(3) | BIT(1) | BIT(0),
},
There's no change in how things _behave_ for spi_device nodes with a
single mcp23s08 chip. New multi-chip configurations assign GPIOs in
sequence, without holes. The spi_device just resembles a bigger
controller, but internally it has multiple gpio_chip instances.
Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'include/linux/spi/mcp23s08.h')
-rw-r--r-- | include/linux/spi/mcp23s08.h | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/include/linux/spi/mcp23s08.h b/include/linux/spi/mcp23s08.h index 835ddf47d45c..22ef107d7704 100644 --- a/include/linux/spi/mcp23s08.h +++ b/include/linux/spi/mcp23s08.h | |||
@@ -1,18 +1,25 @@ | |||
1 | 1 | ||
2 | /* FIXME driver should be able to handle all four slaves that | 2 | /* FIXME driver should be able to handle IRQs... */ |
3 | * can be hooked up to each chipselect, as well as IRQs... | 3 | |
4 | */ | 4 | struct mcp23s08_chip_info { |
5 | bool is_present; /* true iff populated */ | ||
6 | u8 pullups; /* BIT(x) means enable pullup x */ | ||
7 | }; | ||
5 | 8 | ||
6 | struct mcp23s08_platform_data { | 9 | struct mcp23s08_platform_data { |
7 | /* four slaves can share one SPI chipselect */ | 10 | /* Four slaves (numbered 0..3) can share one SPI chipselect, and |
8 | u8 slave; | 11 | * will provide 8..32 GPIOs using 1..4 gpio_chip instances. |
12 | */ | ||
13 | struct mcp23s08_chip_info chip[4]; | ||
9 | 14 | ||
10 | /* number assigned to the first GPIO */ | 15 | /* "base" is the number of the first GPIO. Dynamic assignment is |
16 | * not currently supported, and even if there are gaps in chip | ||
17 | * addressing the GPIO numbers are sequential .. so for example | ||
18 | * if only slaves 0 and 3 are present, their GPIOs range from | ||
19 | * base to base+15. | ||
20 | */ | ||
11 | unsigned base; | 21 | unsigned base; |
12 | 22 | ||
13 | /* pins with pullups */ | ||
14 | u8 pullups; | ||
15 | |||
16 | void *context; /* param to setup/teardown */ | 23 | void *context; /* param to setup/teardown */ |
17 | 24 | ||
18 | int (*setup)(struct spi_device *spi, | 25 | int (*setup)(struct spi_device *spi, |