summaryrefslogtreecommitdiffstats
path: root/drivers/pinctrl/pinctrl-mcp23s08.c
diff options
context:
space:
mode:
authorSebastian Reichel <sebastian.reichel@collabora.co.uk>2017-05-15 11:24:36 +0200
committerLinus Walleij <linus.walleij@linaro.org>2017-05-23 09:50:47 +0200
commitce9bd0a0ff106b478012dc2e4c2b10bb0138dd7a (patch)
tree12c1f851119041be093958dc2a58c5bfb9186a43 /drivers/pinctrl/pinctrl-mcp23s08.c
parentpinctrl: mcp23s08: generalize irq property handling (diff)
downloadlinux-ce9bd0a0ff106b478012dc2e4c2b10bb0138dd7a.tar.xz
linux-ce9bd0a0ff106b478012dc2e4c2b10bb0138dd7a.zip
pinctrl: mcp23s08: simplify spi_present_mask handling
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Diffstat (limited to 'drivers/pinctrl/pinctrl-mcp23s08.c')
-rw-r--r--drivers/pinctrl/pinctrl-mcp23s08.c29
1 files changed, 10 insertions, 19 deletions
diff --git a/drivers/pinctrl/pinctrl-mcp23s08.c b/drivers/pinctrl/pinctrl-mcp23s08.c
index b39da587f2fa..29d9c1fd4309 100644
--- a/drivers/pinctrl/pinctrl-mcp23s08.c
+++ b/drivers/pinctrl/pinctrl-mcp23s08.c
@@ -36,6 +36,8 @@
#define MCP_TYPE_017 3
#define MCP_TYPE_S18 4
+#define MCP_MAX_DEV_PER_CS 8
+
/* Registers are all 8 bits wide.
*
* The mcp23s17 has twice as many bits, and can be configured to work
@@ -1064,7 +1066,6 @@ static int mcp23s08_probe(struct spi_device *spi)
int status, type;
unsigned ngpio = 0;
const struct of_device_id *match;
- u32 spi_present_mask = 0;
match = of_match_device(of_match_ptr(mcp23s08_spi_of_match), &spi->dev);
if (match)
@@ -1078,36 +1079,26 @@ static int mcp23s08_probe(struct spi_device *spi)
pdata->base = -1;
status = device_property_read_u32(&spi->dev,
- "microchip,spi-present-mask", &spi_present_mask);
+ "microchip,spi-present-mask", &pdata->spi_present_mask);
if (status) {
status = device_property_read_u32(&spi->dev,
- "mcp,spi-present-mask", &spi_present_mask);
+ "mcp,spi-present-mask",
+ &pdata->spi_present_mask);
if (status) {
dev_err(&spi->dev, "missing spi-present-mask");
return -ENODEV;
}
}
- } else {
- for (addr = 0; addr < ARRAY_SIZE(pdata->chip); addr++) {
- if (!pdata->chip[addr].is_present)
- continue;
- if ((type == MCP_TYPE_S08) && (addr > 3)) {
- dev_err(&spi->dev,
- "mcp23s08 only supports address 0..3");
- return -EINVAL;
- }
- spi_present_mask |= BIT(addr);
- }
}
- if (!spi_present_mask || spi_present_mask >= 256) {
+ if (!pdata->spi_present_mask || pdata->spi_present_mask > 0xff) {
dev_err(&spi->dev, "invalid spi-present-mask");
return -ENODEV;
}
- for (addr = 0; addr < ARRAY_SIZE(pdata->chip); addr++) {
- if (spi_present_mask & BIT(addr))
+ for (addr = 0; addr < MCP_MAX_DEV_PER_CS; addr++) {
+ if (pdata->spi_present_mask & BIT(addr))
chips++;
}
@@ -1122,8 +1113,8 @@ static int mcp23s08_probe(struct spi_device *spi)
spi_set_drvdata(spi, data);
- for (addr = 0; addr < ARRAY_SIZE(pdata->chip); addr++) {
- if (!(spi_present_mask & (1 << addr)))
+ for (addr = 0; addr < MCP_MAX_DEV_PER_CS; addr++) {
+ if (!(pdata->spi_present_mask & BIT(addr)))
continue;
chips--;
data->mcp[addr] = &data->chip[chips];