Skip to content

Commit b694af6

Browse files
mmahadevan108kartben
authored andcommitted
drivers: gpio: Setup the pinctrl in the NXP LPC GPIO driver
The pinctrl register bits need to be restored to GPIO mode after we exit from certain low power modes. We cannot rely on the pin function to default to GPIO. Signed-off-by: Mahesh Mahadevan <mahesh.mahadevan@nxp.com>
1 parent 9201179 commit b694af6

File tree

4 files changed

+39
-2
lines changed

4 files changed

+39
-2
lines changed

boards/nxp/frdm_rw612/frdm_rw612-pinctrl.dtsi

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,24 @@
7979
slew-rate = "normal";
8080
};
8181
};
82+
83+
pinmux_hsgpio0: pinmux_hsgpio0 {
84+
group0 {
85+
pinmux = <IO_MUX_GPIO11
86+
IO_MUX_GPIO12
87+
IO_MUX_GPIO18
88+
IO_MUX_GPIO21
89+
>;
90+
slew-rate = "normal";
91+
};
92+
};
93+
94+
pinmux_hsgpio1: pinmux_hsgpio1 {
95+
group0 {
96+
pinmux = <IO_MUX_GPIO44
97+
IO_MUX_GPIO55
98+
>;
99+
slew-rate = "normal";
100+
};
101+
};
82102
};

boards/nxp/frdm_rw612/frdm_rw612_common.dtsi

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@
7575

7676
&hsgpio0 {
7777
status = "okay";
78+
pinctrl-0 = <&pinmux_hsgpio0>;
79+
pinctrl-names = "default";
80+
};
81+
82+
&hsgpio1 {
83+
status = "okay";
84+
pinctrl-0 = <&pinmux_hsgpio1>;
85+
pinctrl-names = "default";
7886
};
7987

8088
&flexspi {

drivers/gpio/gpio_mcux_lpc.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <zephyr/device.h>
1919
#include <zephyr/drivers/gpio.h>
2020
#include <zephyr/pm/device.h>
21+
#include <zephyr/drivers/pinctrl.h>
2122
#include <zephyr/irq.h>
2223
#include <soc.h>
2324
#include <fsl_common.h>
@@ -52,6 +53,7 @@ struct gpio_mcux_lpc_config {
5253
MCI_IO_MUX_Type * pinmux_base;
5354
#endif
5455
uint32_t port_no;
56+
const struct pinctrl_dev_config *pincfg;
5557
};
5658

5759
struct gpio_mcux_lpc_data {
@@ -417,6 +419,7 @@ static int gpio_mcux_lpc_manage_cb(const struct device *port,
417419
static int gpio_mcux_lpc_pm_action(const struct device *dev, enum pm_device_action action)
418420
{
419421
const struct gpio_mcux_lpc_config *config = dev->config;
422+
int error;
420423

421424
switch (action) {
422425
case PM_DEVICE_ACTION_RESUME:
@@ -427,6 +430,10 @@ static int gpio_mcux_lpc_pm_action(const struct device *dev, enum pm_device_acti
427430
break;
428431
case PM_DEVICE_ACTION_TURN_ON:
429432
GPIO_PortInit(config->gpio_base, config->port_no);
433+
error = pinctrl_apply_state(config->pincfg, PINCTRL_STATE_DEFAULT);
434+
if (error) {
435+
return error;
436+
}
430437
break;
431438
default:
432439
return -ENOTSUP;
@@ -479,6 +486,7 @@ static DEVICE_API(gpio, gpio_mcux_lpc_driver_api) = {
479486

480487

481488
#define GPIO_MCUX_LPC(n) \
489+
PINCTRL_DT_INST_DEFINE(n); \
482490
static int lpc_gpio_init_##n(const struct device *dev); \
483491
\
484492
static const struct gpio_mcux_lpc_config gpio_mcux_lpc_config_##n = { \
@@ -488,7 +496,8 @@ static DEVICE_API(gpio, gpio_mcux_lpc_driver_api) = {
488496
.gpio_base = (GPIO_Type *)DT_REG_ADDR(DT_INST_PARENT(n)), \
489497
.pinmux_base = PINMUX_BASE, \
490498
.int_source = DT_INST_ENUM_IDX(n, int_source), \
491-
.port_no = DT_INST_REG_ADDR(n) \
499+
.port_no = DT_INST_REG_ADDR(n), \
500+
.pincfg = PINCTRL_DT_INST_DEV_CONFIG_GET(n) \
492501
}; \
493502
\
494503
static struct gpio_mcux_lpc_data gpio_mcux_lpc_data_##n; \

dts/bindings/gpio/nxp,lpc-gpio-port.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: LPC GPIO port device.
55

66
compatible: "nxp,lpc-gpio-port"
77

8-
include: [gpio-controller.yaml, base.yaml]
8+
include: [gpio-controller.yaml, base.yaml, pinctrl-device.yaml]
99

1010
properties:
1111
reg:

0 commit comments

Comments
 (0)