From 29fe58f7a4c691ea90d57ef3eb5f3ab5b68e216e Mon Sep 17 00:00:00 2001 From: TOKITA Hiroshi Date: Wed, 27 Nov 2024 12:56:51 +0900 Subject: [PATCH] drivers: gpio: mcp23xxx: Fix to allow the use of multiple models Compilation will fail if multiple models are used at the same time. Changing to define different unique names for the symbols to avoid conflicts. Signed-off-by: TOKITA Hiroshi --- drivers/gpio/gpio_mcp230xx.c | 20 ++++++++++---------- drivers/gpio/gpio_mcp23sxx.c | 22 +++++++++++----------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/drivers/gpio/gpio_mcp230xx.c b/drivers/gpio/gpio_mcp230xx.c index d44431ed96c59f..e1a283ce5213ea 100644 --- a/drivers/gpio/gpio_mcp230xx.c +++ b/drivers/gpio/gpio_mcp230xx.c @@ -75,15 +75,15 @@ static int mcp230xx_bus_is_ready(const struct device *dev) return 0; } -#define GPIO_MCP230XX_DEVICE(inst, num_gpios, open_drain) \ - static struct mcp23xxx_drv_data mcp230xx_##inst##_drvdata = { \ +#define GPIO_MCP230XX_DEVICE(inst, num_gpios, open_drain, model) \ + static struct mcp23xxx_drv_data mcp##model##_##inst##_drvdata = { \ /* Default for registers according to datasheet */ \ .reg_cache.iodir = 0xFFFF, .reg_cache.ipol = 0x0, .reg_cache.gpinten = 0x0, \ .reg_cache.defval = 0x0, .reg_cache.intcon = 0x0, .reg_cache.iocon = 0x0, \ .reg_cache.gppu = 0x0, .reg_cache.intf = 0x0, .reg_cache.intcap = 0x0, \ .reg_cache.gpio = 0x0, .reg_cache.olat = 0x0, \ }; \ - static const struct mcp23xxx_config mcp230xx_##inst##_config = { \ + static const struct mcp23xxx_config mcp##model##_##inst##_config = { \ .config = { \ .port_pin_mask = GPIO_PORT_PIN_MASK_FROM_DT_INST(inst), \ }, \ @@ -98,22 +98,22 @@ static int mcp230xx_bus_is_ready(const struct device *dev) .write_fn = mcp230xx_write_port_regs, \ .bus_fn = mcp230xx_bus_is_ready, \ }; \ - DEVICE_DT_INST_DEFINE(inst, gpio_mcp23xxx_init, NULL, &mcp230xx_##inst##_drvdata, \ - &mcp230xx_##inst##_config, POST_KERNEL, \ + DEVICE_DT_INST_DEFINE(inst, gpio_mcp23xxx_init, NULL, &mcp##model##_##inst##_drvdata, \ + &mcp##model##_##inst##_config, POST_KERNEL, \ CONFIG_GPIO_MCP230XX_INIT_PRIORITY, &gpio_mcp23xxx_api_table); #define DT_DRV_COMPAT microchip_mcp23008 -DT_INST_FOREACH_STATUS_OKAY_VARGS(GPIO_MCP230XX_DEVICE, 8, false) +DT_INST_FOREACH_STATUS_OKAY_VARGS(GPIO_MCP230XX_DEVICE, 8, false, 23008) #undef DT_DRV_COMPAT #define DT_DRV_COMPAT microchip_mcp23009 -DT_INST_FOREACH_STATUS_OKAY_VARGS(GPIO_MCP230XX_DEVICE, 8, true) +DT_INST_FOREACH_STATUS_OKAY_VARGS(GPIO_MCP230XX_DEVICE, 8, true, 23009) #undef DT_DRV_COMPAT #define DT_DRV_COMPAT microchip_mcp23016 -DT_INST_FOREACH_STATUS_OKAY_VARGS(GPIO_MCP230XX_DEVICE, 16, false) +DT_INST_FOREACH_STATUS_OKAY_VARGS(GPIO_MCP230XX_DEVICE, 16, false, 23016) #undef DT_DRV_COMPAT #define DT_DRV_COMPAT microchip_mcp23017 -DT_INST_FOREACH_STATUS_OKAY_VARGS(GPIO_MCP230XX_DEVICE, 16, false) +DT_INST_FOREACH_STATUS_OKAY_VARGS(GPIO_MCP230XX_DEVICE, 16, false, 23017) #undef DT_DRV_COMPAT #define DT_DRV_COMPAT microchip_mcp23018 -DT_INST_FOREACH_STATUS_OKAY_VARGS(GPIO_MCP230XX_DEVICE, 16, true) +DT_INST_FOREACH_STATUS_OKAY_VARGS(GPIO_MCP230XX_DEVICE, 16, true, 23018) #undef DT_DRV_COMPAT diff --git a/drivers/gpio/gpio_mcp23sxx.c b/drivers/gpio/gpio_mcp23sxx.c index c0ec7061df9335..8d2749e50501a2 100644 --- a/drivers/gpio/gpio_mcp23sxx.c +++ b/drivers/gpio/gpio_mcp23sxx.c @@ -113,20 +113,20 @@ static int mcp23sxx_bus_is_ready(const struct device *dev) return 0; } -#define GPIO_MCP23SXX_DEVICE(inst, num_gpios, open_drain) \ - static struct mcp23xxx_drv_data mcp23sxx_##inst##_drvdata = { \ +#define GPIO_MCP23SXX_DEVICE(inst, num_gpios, open_drain, model) \ + static struct mcp23xxx_drv_data mcp##model##_##inst##_drvdata = { \ /* Default for registers according to datasheet */ \ .reg_cache.iodir = 0xFFFF, .reg_cache.ipol = 0x0, .reg_cache.gpinten = 0x0, \ .reg_cache.defval = 0x0, .reg_cache.intcon = 0x0, .reg_cache.iocon = 0x0, \ .reg_cache.gppu = 0x0, .reg_cache.intf = 0x0, .reg_cache.intcap = 0x0, \ .reg_cache.gpio = 0x0, .reg_cache.olat = 0x0, \ }; \ - static struct mcp23xxx_config mcp23sxx_##inst##_config = { \ + static struct mcp23xxx_config mcp##model##_##inst##_config = { \ .config = { \ - .port_pin_mask = GPIO_PORT_PIN_MASK_FROM_DT_INST(inst), \ + .port_pin_mask = GPIO_PORT_PIN_MASK_FROM_DT_INST(inst), \ }, \ .bus = { \ - .spi = SPI_DT_SPEC_INST_GET(inst, \ + .spi = SPI_DT_SPEC_INST_GET(inst, \ SPI_OP_MODE_MASTER | SPI_MODE_CPOL | \ SPI_MODE_CPHA | SPI_WORD_SET(8), 0) \ }, \ @@ -138,20 +138,20 @@ static int mcp23sxx_bus_is_ready(const struct device *dev) .write_fn = mcp23sxx_write_port_regs, \ .bus_fn = mcp23sxx_bus_is_ready \ }; \ - DEVICE_DT_INST_DEFINE(inst, gpio_mcp23xxx_init, NULL, &mcp23sxx_##inst##_drvdata, \ - &mcp23sxx_##inst##_config, POST_KERNEL, \ + DEVICE_DT_INST_DEFINE(inst, gpio_mcp23xxx_init, NULL, &mcp##model##_##inst##_drvdata, \ + &mcp##model##_##inst##_config, POST_KERNEL, \ CONFIG_GPIO_MCP23SXX_INIT_PRIORITY, &gpio_mcp23xxx_api_table); #define DT_DRV_COMPAT microchip_mcp23s08 -DT_INST_FOREACH_STATUS_OKAY_VARGS(GPIO_MCP23SXX_DEVICE, 8, false) +DT_INST_FOREACH_STATUS_OKAY_VARGS(GPIO_MCP23SXX_DEVICE, 8, false, 23s08) #undef DT_DRV_COMPAT #define DT_DRV_COMPAT microchip_mcp23s09 -DT_INST_FOREACH_STATUS_OKAY_VARGS(GPIO_MCP23SXX_DEVICE, 8, true) +DT_INST_FOREACH_STATUS_OKAY_VARGS(GPIO_MCP23SXX_DEVICE, 8, true, 23s09) #undef DT_DRV_COMPAT #define DT_DRV_COMPAT microchip_mcp23s17 -DT_INST_FOREACH_STATUS_OKAY_VARGS(GPIO_MCP23SXX_DEVICE, 16, false) +DT_INST_FOREACH_STATUS_OKAY_VARGS(GPIO_MCP23SXX_DEVICE, 16, false, 23s17) #undef DT_DRV_COMPAT #define DT_DRV_COMPAT microchip_mcp23s18 -DT_INST_FOREACH_STATUS_OKAY_VARGS(GPIO_MCP23SXX_DEVICE, 16, true) +DT_INST_FOREACH_STATUS_OKAY_VARGS(GPIO_MCP23SXX_DEVICE, 16, true, 23s18) #undef DT_DRV_COMPAT