Skip to content

Commit e54b72a

Browse files
arbraunsChromeos LUCI
authored andcommitted
drivers: mcp23xxx: add support for open-drain chip variants
Pin definitions should correctly reflect the actual drive mode of the GPIO controller, either push-pull or open drain. (cherry picked from commit ede19a4) Original-Signed-off-by: Armin Brauns <[email protected]> GitOrigin-RevId: ede19a4 Cr-Build-Id: 8740088176811114337 Cr-Build-Url: https://cr-buildbucket.appspot.com/build/8740088176811114337 Copybot-Job-Name: zephyr-main-copybot-downstream Change-Id: I5f29d8e14c3606d24a38c601c0fb9130fec36088 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/zephyr/+/5777138 Tested-by: Jeremy Bettis <[email protected]> Commit-Queue: Jeremy Bettis <[email protected]> Reviewed-by: Jeremy Bettis <[email protected]> Tested-by: ChromeOS Prod (Robot) <[email protected]>
1 parent a5f1bd0 commit e54b72a

File tree

5 files changed

+20
-13
lines changed

5 files changed

+20
-13
lines changed

doc/releases/migration-guide-4.0.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ Device Drivers and Devicetree
4949
``microchip,mcp230xx`` and ``microchip,mcp23sxx`` should change their devicetree ``compatible``
5050
values to the specific chip variant, e.g. :dtcompatible:`microchip,mcp23017`.
5151
The ``ngpios`` devicetree property has been removed, since it is implied by the model name.
52-
(:github:`65797`)
52+
Chip variants with open-drain outputs (``mcp23x09``, ``mcp23x18``) now correctly reflect this in
53+
their driver API, users of these devices should ensure they pass appropriate values to
54+
:c:func:`gpio_pin_set`. (:github:`65797`)
5355

5456
Controller Area Network (CAN)
5557
=============================

drivers/gpio/gpio_mcp230xx.c

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

78-
#define GPIO_MCP230XX_DEVICE(inst, num_gpios) \
78+
#define GPIO_MCP230XX_DEVICE(inst, num_gpios, open_drain) \
7979
static struct mcp23xxx_drv_data mcp230xx_##inst##_drvdata = { \
8080
/* Default for registers according to datasheet */ \
8181
.reg_cache.iodir = 0xFFFF, .reg_cache.ipol = 0x0, .reg_cache.gpinten = 0x0, \
@@ -93,6 +93,7 @@ static int mcp230xx_bus_is_ready(const struct device *dev)
9393
.gpio_int = GPIO_DT_SPEC_INST_GET_OR(inst, int_gpios, {0}), \
9494
.gpio_reset = GPIO_DT_SPEC_INST_GET_OR(inst, reset_gpios, {0}), \
9595
.ngpios = num_gpios, \
96+
.is_open_drain = open_drain, \
9697
.read_fn = mcp230xx_read_port_regs, \
9798
.write_fn = mcp230xx_write_port_regs, \
9899
.bus_fn = mcp230xx_bus_is_ready, \
@@ -102,17 +103,17 @@ static int mcp230xx_bus_is_ready(const struct device *dev)
102103
CONFIG_GPIO_MCP230XX_INIT_PRIORITY, &gpio_mcp23xxx_api_table);
103104

104105
#define DT_DRV_COMPAT microchip_mcp23008
105-
DT_INST_FOREACH_STATUS_OKAY_VARGS(GPIO_MCP230XX_DEVICE, 8)
106+
DT_INST_FOREACH_STATUS_OKAY_VARGS(GPIO_MCP230XX_DEVICE, 8, false)
106107
#undef DT_DRV_COMPAT
107108
#define DT_DRV_COMPAT microchip_mcp23009
108-
DT_INST_FOREACH_STATUS_OKAY_VARGS(GPIO_MCP230XX_DEVICE, 8)
109+
DT_INST_FOREACH_STATUS_OKAY_VARGS(GPIO_MCP230XX_DEVICE, 8, true)
109110
#undef DT_DRV_COMPAT
110111
#define DT_DRV_COMPAT microchip_mcp23016
111-
DT_INST_FOREACH_STATUS_OKAY_VARGS(GPIO_MCP230XX_DEVICE, 16)
112+
DT_INST_FOREACH_STATUS_OKAY_VARGS(GPIO_MCP230XX_DEVICE, 16, false)
112113
#undef DT_DRV_COMPAT
113114
#define DT_DRV_COMPAT microchip_mcp23017
114-
DT_INST_FOREACH_STATUS_OKAY_VARGS(GPIO_MCP230XX_DEVICE, 16)
115+
DT_INST_FOREACH_STATUS_OKAY_VARGS(GPIO_MCP230XX_DEVICE, 16, false)
115116
#undef DT_DRV_COMPAT
116117
#define DT_DRV_COMPAT microchip_mcp23018
117-
DT_INST_FOREACH_STATUS_OKAY_VARGS(GPIO_MCP230XX_DEVICE, 16)
118+
DT_INST_FOREACH_STATUS_OKAY_VARGS(GPIO_MCP230XX_DEVICE, 16, true)
118119
#undef DT_DRV_COMPAT

drivers/gpio/gpio_mcp23sxx.c

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

116-
#define GPIO_MCP23SXX_DEVICE(inst, num_gpios) \
116+
#define GPIO_MCP23SXX_DEVICE(inst, num_gpios, open_drain) \
117117
static struct mcp23xxx_drv_data mcp23sxx_##inst##_drvdata = { \
118118
/* Default for registers according to datasheet */ \
119119
.reg_cache.iodir = 0xFFFF, .reg_cache.ipol = 0x0, .reg_cache.gpinten = 0x0, \
@@ -133,6 +133,7 @@ static int mcp23sxx_bus_is_ready(const struct device *dev)
133133
.gpio_int = GPIO_DT_SPEC_INST_GET_OR(inst, int_gpios, {0}), \
134134
.gpio_reset = GPIO_DT_SPEC_INST_GET_OR(inst, reset_gpios, {0}), \
135135
.ngpios = num_gpios, \
136+
.is_open_drain = open_drain, \
136137
.read_fn = mcp23sxx_read_port_regs, \
137138
.write_fn = mcp23sxx_write_port_regs, \
138139
.bus_fn = mcp23sxx_bus_is_ready \
@@ -143,14 +144,14 @@ static int mcp23sxx_bus_is_ready(const struct device *dev)
143144

144145

145146
#define DT_DRV_COMPAT microchip_mcp23s08
146-
DT_INST_FOREACH_STATUS_OKAY_VARGS(GPIO_MCP23SXX_DEVICE, 8)
147+
DT_INST_FOREACH_STATUS_OKAY_VARGS(GPIO_MCP23SXX_DEVICE, 8, false)
147148
#undef DT_DRV_COMPAT
148149
#define DT_DRV_COMPAT microchip_mcp23s09
149-
DT_INST_FOREACH_STATUS_OKAY_VARGS(GPIO_MCP23SXX_DEVICE, 8)
150+
DT_INST_FOREACH_STATUS_OKAY_VARGS(GPIO_MCP23SXX_DEVICE, 8, true)
150151
#undef DT_DRV_COMPAT
151152
#define DT_DRV_COMPAT microchip_mcp23s17
152-
DT_INST_FOREACH_STATUS_OKAY_VARGS(GPIO_MCP23SXX_DEVICE, 16)
153+
DT_INST_FOREACH_STATUS_OKAY_VARGS(GPIO_MCP23SXX_DEVICE, 16, false)
153154
#undef DT_DRV_COMPAT
154155
#define DT_DRV_COMPAT microchip_mcp23s18
155-
DT_INST_FOREACH_STATUS_OKAY_VARGS(GPIO_MCP23SXX_DEVICE, 16)
156+
DT_INST_FOREACH_STATUS_OKAY_VARGS(GPIO_MCP23SXX_DEVICE, 16, true)
156157
#undef DT_DRV_COMPAT

drivers/gpio/gpio_mcp23xxx.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ static int setup_pin_pull(const struct device *dev, uint32_t pin, int flags)
171171
static int mcp23xxx_pin_cfg(const struct device *dev, gpio_pin_t pin, gpio_flags_t flags)
172172
{
173173
struct mcp23xxx_drv_data *drv_data = dev->data;
174+
const struct mcp23xxx_config *config = dev->config;
174175
int ret;
175176

176177
if (k_is_in_isr()) {
@@ -179,7 +180,8 @@ static int mcp23xxx_pin_cfg(const struct device *dev, gpio_pin_t pin, gpio_flags
179180

180181
k_sem_take(&drv_data->lock, K_FOREVER);
181182

182-
if ((flags & GPIO_SINGLE_ENDED) != 0U) {
183+
if ((bool)(flags & GPIO_SINGLE_ENDED) != config->is_open_drain ||
184+
(bool)(flags & GPIO_LINE_OPEN_DRAIN) != config->is_open_drain) {
183185
ret = -ENOTSUP;
184186
goto done;
185187
}

drivers/gpio/gpio_mcp23xxx.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ struct mcp23xxx_config {
6161
struct gpio_dt_spec gpio_reset;
6262

6363
uint8_t ngpios;
64+
bool is_open_drain;
6465
mcp23xxx_read_port_regs read_fn;
6566
mcp23xxx_write_port_regs write_fn;
6667
mcp23xxx_bus_is_ready bus_fn;

0 commit comments

Comments
 (0)