Skip to content

Commit 29fe58f

Browse files
soburikartben
authored andcommitted
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 <[email protected]>
1 parent bda1e76 commit 29fe58f

File tree

2 files changed

+21
-21
lines changed

2 files changed

+21
-21
lines changed

drivers/gpio/gpio_mcp230xx.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,15 @@ static int mcp230xx_bus_is_ready(const struct device *dev)
7575
return 0;
7676
}
7777

78-
#define GPIO_MCP230XX_DEVICE(inst, num_gpios, open_drain) \
79-
static struct mcp23xxx_drv_data mcp230xx_##inst##_drvdata = { \
78+
#define GPIO_MCP230XX_DEVICE(inst, num_gpios, open_drain, model) \
79+
static struct mcp23xxx_drv_data mcp##model##_##inst##_drvdata = { \
8080
/* Default for registers according to datasheet */ \
8181
.reg_cache.iodir = 0xFFFF, .reg_cache.ipol = 0x0, .reg_cache.gpinten = 0x0, \
8282
.reg_cache.defval = 0x0, .reg_cache.intcon = 0x0, .reg_cache.iocon = 0x0, \
8383
.reg_cache.gppu = 0x0, .reg_cache.intf = 0x0, .reg_cache.intcap = 0x0, \
8484
.reg_cache.gpio = 0x0, .reg_cache.olat = 0x0, \
8585
}; \
86-
static const struct mcp23xxx_config mcp230xx_##inst##_config = { \
86+
static const struct mcp23xxx_config mcp##model##_##inst##_config = { \
8787
.config = { \
8888
.port_pin_mask = GPIO_PORT_PIN_MASK_FROM_DT_INST(inst), \
8989
}, \
@@ -98,22 +98,22 @@ static int mcp230xx_bus_is_ready(const struct device *dev)
9898
.write_fn = mcp230xx_write_port_regs, \
9999
.bus_fn = mcp230xx_bus_is_ready, \
100100
}; \
101-
DEVICE_DT_INST_DEFINE(inst, gpio_mcp23xxx_init, NULL, &mcp230xx_##inst##_drvdata, \
102-
&mcp230xx_##inst##_config, POST_KERNEL, \
101+
DEVICE_DT_INST_DEFINE(inst, gpio_mcp23xxx_init, NULL, &mcp##model##_##inst##_drvdata, \
102+
&mcp##model##_##inst##_config, POST_KERNEL, \
103103
CONFIG_GPIO_MCP230XX_INIT_PRIORITY, &gpio_mcp23xxx_api_table);
104104

105105
#define DT_DRV_COMPAT microchip_mcp23008
106-
DT_INST_FOREACH_STATUS_OKAY_VARGS(GPIO_MCP230XX_DEVICE, 8, false)
106+
DT_INST_FOREACH_STATUS_OKAY_VARGS(GPIO_MCP230XX_DEVICE, 8, false, 23008)
107107
#undef DT_DRV_COMPAT
108108
#define DT_DRV_COMPAT microchip_mcp23009
109-
DT_INST_FOREACH_STATUS_OKAY_VARGS(GPIO_MCP230XX_DEVICE, 8, true)
109+
DT_INST_FOREACH_STATUS_OKAY_VARGS(GPIO_MCP230XX_DEVICE, 8, true, 23009)
110110
#undef DT_DRV_COMPAT
111111
#define DT_DRV_COMPAT microchip_mcp23016
112-
DT_INST_FOREACH_STATUS_OKAY_VARGS(GPIO_MCP230XX_DEVICE, 16, false)
112+
DT_INST_FOREACH_STATUS_OKAY_VARGS(GPIO_MCP230XX_DEVICE, 16, false, 23016)
113113
#undef DT_DRV_COMPAT
114114
#define DT_DRV_COMPAT microchip_mcp23017
115-
DT_INST_FOREACH_STATUS_OKAY_VARGS(GPIO_MCP230XX_DEVICE, 16, false)
115+
DT_INST_FOREACH_STATUS_OKAY_VARGS(GPIO_MCP230XX_DEVICE, 16, false, 23017)
116116
#undef DT_DRV_COMPAT
117117
#define DT_DRV_COMPAT microchip_mcp23018
118-
DT_INST_FOREACH_STATUS_OKAY_VARGS(GPIO_MCP230XX_DEVICE, 16, true)
118+
DT_INST_FOREACH_STATUS_OKAY_VARGS(GPIO_MCP230XX_DEVICE, 16, true, 23018)
119119
#undef DT_DRV_COMPAT

drivers/gpio/gpio_mcp23sxx.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -113,20 +113,20 @@ static int mcp23sxx_bus_is_ready(const struct device *dev)
113113
return 0;
114114
}
115115

116-
#define GPIO_MCP23SXX_DEVICE(inst, num_gpios, open_drain) \
117-
static struct mcp23xxx_drv_data mcp23sxx_##inst##_drvdata = { \
116+
#define GPIO_MCP23SXX_DEVICE(inst, num_gpios, open_drain, model) \
117+
static struct mcp23xxx_drv_data mcp##model##_##inst##_drvdata = { \
118118
/* Default for registers according to datasheet */ \
119119
.reg_cache.iodir = 0xFFFF, .reg_cache.ipol = 0x0, .reg_cache.gpinten = 0x0, \
120120
.reg_cache.defval = 0x0, .reg_cache.intcon = 0x0, .reg_cache.iocon = 0x0, \
121121
.reg_cache.gppu = 0x0, .reg_cache.intf = 0x0, .reg_cache.intcap = 0x0, \
122122
.reg_cache.gpio = 0x0, .reg_cache.olat = 0x0, \
123123
}; \
124-
static struct mcp23xxx_config mcp23sxx_##inst##_config = { \
124+
static struct mcp23xxx_config mcp##model##_##inst##_config = { \
125125
.config = { \
126-
.port_pin_mask = GPIO_PORT_PIN_MASK_FROM_DT_INST(inst), \
126+
.port_pin_mask = GPIO_PORT_PIN_MASK_FROM_DT_INST(inst), \
127127
}, \
128128
.bus = { \
129-
.spi = SPI_DT_SPEC_INST_GET(inst, \
129+
.spi = SPI_DT_SPEC_INST_GET(inst, \
130130
SPI_OP_MODE_MASTER | SPI_MODE_CPOL | \
131131
SPI_MODE_CPHA | SPI_WORD_SET(8), 0) \
132132
}, \
@@ -138,20 +138,20 @@ static int mcp23sxx_bus_is_ready(const struct device *dev)
138138
.write_fn = mcp23sxx_write_port_regs, \
139139
.bus_fn = mcp23sxx_bus_is_ready \
140140
}; \
141-
DEVICE_DT_INST_DEFINE(inst, gpio_mcp23xxx_init, NULL, &mcp23sxx_##inst##_drvdata, \
142-
&mcp23sxx_##inst##_config, POST_KERNEL, \
141+
DEVICE_DT_INST_DEFINE(inst, gpio_mcp23xxx_init, NULL, &mcp##model##_##inst##_drvdata, \
142+
&mcp##model##_##inst##_config, POST_KERNEL, \
143143
CONFIG_GPIO_MCP23SXX_INIT_PRIORITY, &gpio_mcp23xxx_api_table);
144144

145145

146146
#define DT_DRV_COMPAT microchip_mcp23s08
147-
DT_INST_FOREACH_STATUS_OKAY_VARGS(GPIO_MCP23SXX_DEVICE, 8, false)
147+
DT_INST_FOREACH_STATUS_OKAY_VARGS(GPIO_MCP23SXX_DEVICE, 8, false, 23s08)
148148
#undef DT_DRV_COMPAT
149149
#define DT_DRV_COMPAT microchip_mcp23s09
150-
DT_INST_FOREACH_STATUS_OKAY_VARGS(GPIO_MCP23SXX_DEVICE, 8, true)
150+
DT_INST_FOREACH_STATUS_OKAY_VARGS(GPIO_MCP23SXX_DEVICE, 8, true, 23s09)
151151
#undef DT_DRV_COMPAT
152152
#define DT_DRV_COMPAT microchip_mcp23s17
153-
DT_INST_FOREACH_STATUS_OKAY_VARGS(GPIO_MCP23SXX_DEVICE, 16, false)
153+
DT_INST_FOREACH_STATUS_OKAY_VARGS(GPIO_MCP23SXX_DEVICE, 16, false, 23s17)
154154
#undef DT_DRV_COMPAT
155155
#define DT_DRV_COMPAT microchip_mcp23s18
156-
DT_INST_FOREACH_STATUS_OKAY_VARGS(GPIO_MCP23SXX_DEVICE, 16, true)
156+
DT_INST_FOREACH_STATUS_OKAY_VARGS(GPIO_MCP23SXX_DEVICE, 16, true, 23s18)
157157
#undef DT_DRV_COMPAT

0 commit comments

Comments
 (0)