Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Sebastian Reichel and committed by
Linus Walleij
ce9bd0a0 5b1a7e80

+13 -26
+2 -2
arch/blackfin/mach-bf527/boards/tll6527m.c
··· 351 351 #if IS_ENABLED(CONFIG_PINCTRL_MCP23S08) 352 352 #include <linux/spi/mcp23s08.h> 353 353 static const struct mcp23s08_platform_data bfin_mcp23s08_sys_gpio_info = { 354 - .chip[0].is_present = true, 354 + .spi_present_mask = BIT(0), 355 355 .base = 0x30, 356 356 }; 357 357 static const struct mcp23s08_platform_data bfin_mcp23s08_usr_gpio_info = { 358 - .chip[2].is_present = true, 358 + .spi_present_mask = BIT(2), 359 359 .base = 0x38, 360 360 }; 361 361 #endif
+10 -19
drivers/pinctrl/pinctrl-mcp23s08.c
··· 36 36 #define MCP_TYPE_017 3 37 37 #define MCP_TYPE_S18 4 38 38 39 + #define MCP_MAX_DEV_PER_CS 8 40 + 39 41 /* Registers are all 8 bits wide. 40 42 * 41 43 * The mcp23s17 has twice as many bits, and can be configured to work ··· 1066 1064 int status, type; 1067 1065 unsigned ngpio = 0; 1068 1066 const struct of_device_id *match; 1069 - u32 spi_present_mask = 0; 1070 1067 1071 1068 match = of_match_device(of_match_ptr(mcp23s08_spi_of_match), &spi->dev); 1072 1069 if (match) ··· 1079 1078 pdata->base = -1; 1080 1079 1081 1080 status = device_property_read_u32(&spi->dev, 1082 - "microchip,spi-present-mask", &spi_present_mask); 1081 + "microchip,spi-present-mask", &pdata->spi_present_mask); 1083 1082 if (status) { 1084 1083 status = device_property_read_u32(&spi->dev, 1085 - "mcp,spi-present-mask", &spi_present_mask); 1084 + "mcp,spi-present-mask", 1085 + &pdata->spi_present_mask); 1086 1086 1087 1087 if (status) { 1088 1088 dev_err(&spi->dev, "missing spi-present-mask"); 1089 1089 return -ENODEV; 1090 1090 } 1091 1091 } 1092 - } else { 1093 - for (addr = 0; addr < ARRAY_SIZE(pdata->chip); addr++) { 1094 - if (!pdata->chip[addr].is_present) 1095 - continue; 1096 - if ((type == MCP_TYPE_S08) && (addr > 3)) { 1097 - dev_err(&spi->dev, 1098 - "mcp23s08 only supports address 0..3"); 1099 - return -EINVAL; 1100 - } 1101 - spi_present_mask |= BIT(addr); 1102 - } 1103 1092 } 1104 1093 1105 - if (!spi_present_mask || spi_present_mask >= 256) { 1094 + if (!pdata->spi_present_mask || pdata->spi_present_mask > 0xff) { 1106 1095 dev_err(&spi->dev, "invalid spi-present-mask"); 1107 1096 return -ENODEV; 1108 1097 } 1109 1098 1110 - for (addr = 0; addr < ARRAY_SIZE(pdata->chip); addr++) { 1111 - if (spi_present_mask & BIT(addr)) 1099 + for (addr = 0; addr < MCP_MAX_DEV_PER_CS; addr++) { 1100 + if (pdata->spi_present_mask & BIT(addr)) 1112 1101 chips++; 1113 1102 } 1114 1103 ··· 1113 1122 1114 1123 spi_set_drvdata(spi, data); 1115 1124 1116 - for (addr = 0; addr < ARRAY_SIZE(pdata->chip); addr++) { 1117 - if (!(spi_present_mask & (1 << addr))) 1125 + for (addr = 0; addr < MCP_MAX_DEV_PER_CS; addr++) { 1126 + if (!(pdata->spi_present_mask & BIT(addr))) 1118 1127 continue; 1119 1128 chips--; 1120 1129 data->mcp[addr] = &data->chip[chips];
+1 -5
include/linux/spi/mcp23s08.h
··· 1 1 2 2 /* FIXME driver should be able to handle IRQs... */ 3 3 4 - struct mcp23s08_chip_info { 5 - bool is_present; /* true if populated */ 6 - }; 7 - 8 4 struct mcp23s08_platform_data { 9 5 /* For mcp23s08, up to 4 slaves (numbered 0..3) can share one SPI 10 6 * chipselect, each providing 1 gpio_chip instance with 8 gpios. ··· 8 12 * chipselect, each providing 1 gpio_chip (port A + port B) with 9 13 * 16 gpios. 10 14 */ 11 - struct mcp23s08_chip_info chip[8]; 15 + u32 spi_present_mask; 12 16 13 17 /* "base" is the number of the first GPIO. Dynamic assignment is 14 18 * not currently supported, and even if there are gaps in chip