Skip to content

Commit 2b556e1

Browse files
committed
drivers: gpio_mcux: fix handling of unsupported configurations
The MCUX GPIO peripheral must be configured as either input or output. Reject attempts to configure disconnected or bidirectional. Signed-off-by: Peter Bigot <[email protected]>
1 parent 6ad847b commit 2b556e1

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

drivers/gpio/gpio_mcux.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,20 @@ static int gpio_mcux_configure(struct device *dev,
105105
*/
106106

107107
if (access_op == GPIO_ACCESS_BY_PIN) {
108-
if ((flags & GPIO_INPUT) != 0) {
108+
switch (flags & GPIO_DIR_MASK) {
109+
case GPIO_INPUT:
109110
gpio_base->PDDR &= ~BIT(pin);
110-
} else { /* GPIO_OUTPUT */
111+
break;
112+
case GPIO_OUTPUT:
111113
if ((flags & GPIO_OUTPUT_INIT_HIGH) != 0) {
112114
gpio_base->PSOR = BIT(pin);
113115
} else if ((flags & GPIO_OUTPUT_INIT_LOW) != 0) {
114116
gpio_base->PCOR = BIT(pin);
115117
}
116118
gpio_base->PDDR |= BIT(pin);
119+
break;
120+
default:
121+
return -ENOTSUP;
117122
}
118123
} else { /* GPIO_ACCESS_BY_PORT */
119124
if ((flags & GPIO_INPUT) != 0) {

0 commit comments

Comments
 (0)