Skip to content

Commit 337e5e6

Browse files
committed
drivers: gpio: mcp23xxx: fix drive mode validation for input pins
The drive mode validation added in commit ede19a4 was rejecting valid configurations for input pins. The validation ensures that GPIO_SINGLE_ENDED and GPIO_LINE_OPEN_DRAIN flags match the hardware capabilities of each MCP23xxx variant (push-pull vs open-drain). However, this validation was applied to all pin configurations, including input pins. Input pins do not have a drive mode, so applications typically configure them without setting drive mode flags. This caused the validation to incorrectly reject input pin configurations with -ENOTSUP. Fix by only validating drive mode flags when GPIO_OUTPUT is set. Input pins now configure successfully, while output pins still receive proper validation to ensure the requested drive mode matches the hardware capabilities. Fixes: ede19a4 ("drivers: mcp23xxx: add support for open-drain ...") Signed-off-by: Cliff Brake <[email protected]>
1 parent 7c39469 commit 337e5e6

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

drivers/gpio/gpio_mcp23xxx.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,18 @@ static int mcp23xxx_pin_cfg(const struct device *dev, gpio_pin_t pin, gpio_flags
180180

181181
k_sem_take(&drv_data->lock, K_FOREVER);
182182

183-
if ((bool)(flags & GPIO_SINGLE_ENDED) != config->is_open_drain ||
184-
(bool)(flags & GPIO_LINE_OPEN_DRAIN) != config->is_open_drain) {
185-
ret = -ENOTSUP;
186-
goto done;
183+
/* Validate drive mode flags for output pins only.
184+
* The MCP23xxx hardware has a fixed drive mode per chip variant:
185+
* - MCP23x08/x17: Push-pull outputs only
186+
* - MCP23x09/x18: Open-drain outputs only
187+
* Input pins don't have a drive mode, so skip validation for them.
188+
*/
189+
if (flags & GPIO_OUTPUT) {
190+
if ((bool)(flags & GPIO_SINGLE_ENDED) != config->is_open_drain ||
191+
(bool)(flags & GPIO_LINE_OPEN_DRAIN) != config->is_open_drain) {
192+
ret = -ENOTSUP;
193+
goto done;
194+
}
187195
}
188196

189197
ret = setup_pin_dir(dev, pin, flags);

0 commit comments

Comments
 (0)