Skip to content

Commit 054cc09

Browse files
arbraunscarlescufi
authored andcommitted
drivers: add bindings for all existing mcp23xxx variants
This allows getting rid of the ngpios property, which is implicit in the part number. It also prepares for configuring pins as open-drain on supporting chips in the next commit. Signed-off-by: Armin Brauns <[email protected]>
1 parent 75b3bf5 commit 054cc09

16 files changed

+146
-46
lines changed

doc/releases/migration-guide-4.0.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ Device Drivers and Devicetree
4545
* The ``compatible`` of the LiteX uart controller has been renamed from
4646
``litex,uart0`` to :dtcompatible:`litex,uart`. (:github:`74522`)
4747

48+
* The devicetree bindings for the Microchip ``mcp23xxx`` series have been split up. Users of
49+
``microchip,mcp230xx`` and ``microchip,mcp23sxx`` should change their devicetree ``compatible``
50+
values to the specific chip variant, e.g. :dtcompatible:`microchip,mcp23017`.
51+
The ``ngpios`` devicetree property has been removed, since it is implied by the model name.
52+
(:github:`65797`)
53+
4854
Controller Area Network (CAN)
4955
=============================
5056

drivers/gpio/Kconfig.mcp23xxx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ config GPIO_MCP23XXX
1212
menuconfig GPIO_MCP230XX
1313
bool "MCP230XX I2C-based GPIO chip"
1414
default y
15-
depends on DT_HAS_MICROCHIP_MCP230XX_ENABLED
15+
depends on DT_HAS_MICROCHIP_MCP23008_ENABLED || \
16+
DT_HAS_MICROCHIP_MCP23009_ENABLED || \
17+
DT_HAS_MICROCHIP_MCP23016_ENABLED || \
18+
DT_HAS_MICROCHIP_MCP23017_ENABLED || \
19+
DT_HAS_MICROCHIP_MCP23018_ENABLED
1620
depends on I2C
1721
select GPIO_MCP23XXX
1822
help
@@ -31,7 +35,10 @@ endif #GPIO_MCP230XX
3135
menuconfig GPIO_MCP23SXX
3236
bool "MCP23SXX SPI-based GPIO chip"
3337
default y
34-
depends on DT_HAS_MICROCHIP_MCP23SXX_ENABLED
38+
depends on DT_HAS_MICROCHIP_MCP23S08_ENABLED || \
39+
DT_HAS_MICROCHIP_MCP23S09_ENABLED || \
40+
DT_HAS_MICROCHIP_MCP23S17_ENABLED || \
41+
DT_HAS_MICROCHIP_MCP23S18_ENABLED
3542
depends on SPI
3643
select GPIO_MCP23XXX
3744
help

drivers/gpio/gpio_mcp230xx.c

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

78-
#define DT_DRV_COMPAT microchip_mcp230xx
79-
80-
#define GPIO_MCP230XX_DEVICE(inst) \
78+
#define GPIO_MCP230XX_DEVICE(inst, num_gpios) \
8179
static struct mcp23xxx_drv_data mcp230xx_##inst##_drvdata = { \
8280
/* Default for registers according to datasheet */ \
8381
.reg_cache.iodir = 0xFFFF, .reg_cache.ipol = 0x0, .reg_cache.gpinten = 0x0, \
@@ -94,7 +92,7 @@ static int mcp230xx_bus_is_ready(const struct device *dev)
9492
}, \
9593
.gpio_int = GPIO_DT_SPEC_INST_GET_OR(inst, int_gpios, {0}), \
9694
.gpio_reset = GPIO_DT_SPEC_INST_GET_OR(inst, reset_gpios, {0}), \
97-
.ngpios = DT_INST_PROP(inst, ngpios), \
95+
.ngpios = num_gpios, \
9896
.read_fn = mcp230xx_read_port_regs, \
9997
.write_fn = mcp230xx_write_port_regs, \
10098
.bus_fn = mcp230xx_bus_is_ready, \
@@ -103,4 +101,18 @@ static int mcp230xx_bus_is_ready(const struct device *dev)
103101
&mcp230xx_##inst##_config, POST_KERNEL, \
104102
CONFIG_GPIO_MCP230XX_INIT_PRIORITY, &gpio_mcp23xxx_api_table);
105103

106-
DT_INST_FOREACH_STATUS_OKAY(GPIO_MCP230XX_DEVICE)
104+
#define DT_DRV_COMPAT microchip_mcp23008
105+
DT_INST_FOREACH_STATUS_OKAY_VARGS(GPIO_MCP230XX_DEVICE, 8)
106+
#undef DT_DRV_COMPAT
107+
#define DT_DRV_COMPAT microchip_mcp23009
108+
DT_INST_FOREACH_STATUS_OKAY_VARGS(GPIO_MCP230XX_DEVICE, 8)
109+
#undef DT_DRV_COMPAT
110+
#define DT_DRV_COMPAT microchip_mcp23016
111+
DT_INST_FOREACH_STATUS_OKAY_VARGS(GPIO_MCP230XX_DEVICE, 16)
112+
#undef DT_DRV_COMPAT
113+
#define DT_DRV_COMPAT microchip_mcp23017
114+
DT_INST_FOREACH_STATUS_OKAY_VARGS(GPIO_MCP230XX_DEVICE, 16)
115+
#undef DT_DRV_COMPAT
116+
#define DT_DRV_COMPAT microchip_mcp23018
117+
DT_INST_FOREACH_STATUS_OKAY_VARGS(GPIO_MCP230XX_DEVICE, 16)
118+
#undef DT_DRV_COMPAT

drivers/gpio/gpio_mcp23sxx.c

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

116-
#define DT_DRV_COMPAT microchip_mcp23sxx
117-
118-
#define GPIO_MCP23SXX_DEVICE(inst) \
116+
#define GPIO_MCP23SXX_DEVICE(inst, num_gpios) \
119117
static struct mcp23xxx_drv_data mcp23sxx_##inst##_drvdata = { \
120118
/* Default for registers according to datasheet */ \
121119
.reg_cache.iodir = 0xFFFF, .reg_cache.ipol = 0x0, .reg_cache.gpinten = 0x0, \
@@ -134,7 +132,7 @@ static int mcp23sxx_bus_is_ready(const struct device *dev)
134132
}, \
135133
.gpio_int = GPIO_DT_SPEC_INST_GET_OR(inst, int_gpios, {0}), \
136134
.gpio_reset = GPIO_DT_SPEC_INST_GET_OR(inst, reset_gpios, {0}), \
137-
.ngpios = DT_INST_PROP(inst, ngpios), \
135+
.ngpios = num_gpios, \
138136
.read_fn = mcp23sxx_read_port_regs, \
139137
.write_fn = mcp23sxx_write_port_regs, \
140138
.bus_fn = mcp23sxx_bus_is_ready \
@@ -143,4 +141,16 @@ static int mcp23sxx_bus_is_ready(const struct device *dev)
143141
&mcp23sxx_##inst##_config, POST_KERNEL, \
144142
CONFIG_GPIO_MCP23SXX_INIT_PRIORITY, &gpio_mcp23xxx_api_table);
145143

146-
DT_INST_FOREACH_STATUS_OKAY(GPIO_MCP23SXX_DEVICE)
144+
145+
#define DT_DRV_COMPAT microchip_mcp23s08
146+
DT_INST_FOREACH_STATUS_OKAY_VARGS(GPIO_MCP23SXX_DEVICE, 8)
147+
#undef DT_DRV_COMPAT
148+
#define DT_DRV_COMPAT microchip_mcp23s09
149+
DT_INST_FOREACH_STATUS_OKAY_VARGS(GPIO_MCP23SXX_DEVICE, 8)
150+
#undef DT_DRV_COMPAT
151+
#define DT_DRV_COMPAT microchip_mcp23s17
152+
DT_INST_FOREACH_STATUS_OKAY_VARGS(GPIO_MCP23SXX_DEVICE, 16)
153+
#undef DT_DRV_COMPAT
154+
#define DT_DRV_COMPAT microchip_mcp23s18
155+
DT_INST_FOREACH_STATUS_OKAY_VARGS(GPIO_MCP23SXX_DEVICE, 16)
156+
#undef DT_DRV_COMPAT
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#
2+
# Copyright (c) 2024 SILA Embedded Solutions GmbH
3+
#
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
7+
description: This is a representation of the Microchip MCP23008 I2C GPIO Expander.
8+
9+
compatible: "microchip,mcp23008"
10+
11+
include: ["microchip,mcp23xxx.yaml", i2c-device.yaml]
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#
2+
# Copyright (c) 2024 SILA Embedded Solutions GmbH
3+
#
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
7+
description: This is a representation of the Microchip MCP23009 I2C GPIO Expander.
8+
9+
compatible: "microchip,mcp23009"
10+
11+
include: ["microchip,mcp23xxx.yaml", i2c-device.yaml]
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#
2+
# Copyright (c) 2024 SILA Embedded Solutions GmbH
3+
#
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
7+
description: This is a representation of the Microchip MCP23016 I2C GPIO Expander.
8+
9+
compatible: "microchip,mcp23016"
10+
11+
include: ["microchip,mcp23xxx.yaml", i2c-device.yaml]
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#
2+
# Copyright (c) 2024 SILA Embedded Solutions GmbH
3+
#
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
7+
description: This is a representation of the Microchip MCP23017 I2C GPIO Expander.
8+
9+
compatible: "microchip,mcp23017"
10+
11+
include: ["microchip,mcp23xxx.yaml", i2c-device.yaml]
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#
2+
# Copyright (c) 2024 SILA Embedded Solutions GmbH
3+
#
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
7+
description: This is a representation of the Microchip MCP23018 I2C GPIO Expander.
8+
9+
compatible: "microchip,mcp23018"
10+
11+
include: ["microchip,mcp23xxx.yaml", i2c-device.yaml]

dts/bindings/gpio/microchip,mcp230xx.yaml

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)