···3636#define MCP_TYPE_017 33737#define MCP_TYPE_S18 438383939+#define MCP_MAX_DEV_PER_CS 84040+3941/* Registers are all 8 bits wide.4042 *4143 * The mcp23s17 has twice as many bits, and can be configured to work···10661064 int status, type;10671065 unsigned ngpio = 0;10681066 const struct of_device_id *match;10691069- u32 spi_present_mask = 0;1070106710711068 match = of_match_device(of_match_ptr(mcp23s08_spi_of_match), &spi->dev);10721069 if (match)···10791078 pdata->base = -1;1080107910811080 status = device_property_read_u32(&spi->dev,10821082- "microchip,spi-present-mask", &spi_present_mask);10811081+ "microchip,spi-present-mask", &pdata->spi_present_mask);10831082 if (status) {10841083 status = device_property_read_u32(&spi->dev,10851085- "mcp,spi-present-mask", &spi_present_mask);10841084+ "mcp,spi-present-mask",10851085+ &pdata->spi_present_mask);1086108610871087 if (status) {10881088 dev_err(&spi->dev, "missing spi-present-mask");10891089 return -ENODEV;10901090 }10911091 }10921092- } else {10931093- for (addr = 0; addr < ARRAY_SIZE(pdata->chip); addr++) {10941094- if (!pdata->chip[addr].is_present)10951095- continue;10961096- if ((type == MCP_TYPE_S08) && (addr > 3)) {10971097- dev_err(&spi->dev,10981098- "mcp23s08 only supports address 0..3");10991099- return -EINVAL;11001100- }11011101- spi_present_mask |= BIT(addr);11021102- }11031092 }1104109311051105- if (!spi_present_mask || spi_present_mask >= 256) {10941094+ if (!pdata->spi_present_mask || pdata->spi_present_mask > 0xff) {11061095 dev_err(&spi->dev, "invalid spi-present-mask");11071096 return -ENODEV;11081097 }1109109811101110- for (addr = 0; addr < ARRAY_SIZE(pdata->chip); addr++) {11111111- if (spi_present_mask & BIT(addr))10991099+ for (addr = 0; addr < MCP_MAX_DEV_PER_CS; addr++) {11001100+ if (pdata->spi_present_mask & BIT(addr))11121101 chips++;11131102 }11141103···1113112211141123 spi_set_drvdata(spi, data);1115112411161116- for (addr = 0; addr < ARRAY_SIZE(pdata->chip); addr++) {11171117- if (!(spi_present_mask & (1 << addr)))11251125+ for (addr = 0; addr < MCP_MAX_DEV_PER_CS; addr++) {11261126+ if (!(pdata->spi_present_mask & BIT(addr)))11181127 continue;11191128 chips--;11201129 data->mcp[addr] = &data->chip[chips];
+1-5
include/linux/spi/mcp23s08.h
···1122/* FIXME driver should be able to handle IRQs... */3344-struct mcp23s08_chip_info {55- bool is_present; /* true if populated */66-};77-84struct mcp23s08_platform_data {95 /* For mcp23s08, up to 4 slaves (numbered 0..3) can share one SPI106 * chipselect, each providing 1 gpio_chip instance with 8 gpios.···812 * chipselect, each providing 1 gpio_chip (port A + port B) with913 * 16 gpios.1014 */1111- struct mcp23s08_chip_info chip[8];1515+ u32 spi_present_mask;12161317 /* "base" is the number of the first GPIO. Dynamic assignment is1418 * not currently supported, and even if there are gaps in chip