From 95f6dc6c3580db38356f8b5019ee38208b22699e Mon Sep 17 00:00:00 2001 From: Mulin Chao Date: Mon, 21 Feb 2022 19:17:26 -0800 Subject: [PATCH] drivers: ps2: add Zephyr pinctrl support Replace soc-specific pin functions with Zephyr pinctrl api functions for pin-mux configuration in ps2 driver. Signed-off-by: Mulin Chao --- drivers/ps2/ps2_npcx_channel.c | 19 +++++++++++-------- dts/arm/nuvoton/npcx.dtsi | 4 ---- .../ps2/nuvoton,npcx-ps2-channel.yaml | 7 ++++--- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/drivers/ps2/ps2_npcx_channel.c b/drivers/ps2/ps2_npcx_channel.c index bd1f2fbfe3..6cbe59512e 100644 --- a/drivers/ps2/ps2_npcx_channel.c +++ b/drivers/ps2/ps2_npcx_channel.c @@ -17,6 +17,7 @@ */ #include +#include #include #include @@ -27,12 +28,11 @@ LOG_MODULE_REGISTER(ps2_npcx_channel, CONFIG_PS2_LOG_LEVEL); /* Device config */ struct ps2_npcx_ch_config { - /* pinmux configuration */ - const uint8_t alts_size; - const struct npcx_alt *alts_list; /* Indicate the channel's number of the PS/2 channel device */ uint8_t channel_id; const struct device *ps2_ctrl; + /* pinmux configuration */ + const struct pinctrl_dev_config *pcfg; }; /* PS/2 api functions */ @@ -78,6 +78,7 @@ static int ps2_npcx_ch_inhibit_interface(const struct device *dev) static int ps2_npcx_channel_init(const struct device *dev) { const struct ps2_npcx_ch_config *const config = dev->config; + int ret; if (!device_is_ready(config->ps2_ctrl)) { LOG_ERR("%s device not ready", config->ps2_ctrl->name); @@ -85,7 +86,11 @@ static int ps2_npcx_channel_init(const struct device *dev) } /* Configure pin-mux for PS/2 device */ - npcx_pinctrl_mux_configure(config->alts_list, config->alts_size, 1); + ret = pinctrl_apply_state(config->pcfg, PINCTRL_STATE_DEFAULT); + if (ret < 0) { + LOG_ERR("PS2 pinctrl setup failed (%d)", ret); + return ret; + } return 0; } @@ -101,14 +106,12 @@ static const struct ps2_driver_api ps2_channel_npcx_driver_api = { /* PS/2 channel initialization macro functions */ #define NPCX_PS2_CHANNEL_INIT(inst) \ \ - static const struct npcx_alt ps2_channel_alts##inst[] = \ - NPCX_DT_ALT_ITEMS_LIST(inst); \ + PINCTRL_DT_INST_DEFINE(inst); \ \ static const struct ps2_npcx_ch_config ps2_npcx_ch_cfg_##inst = { \ .channel_id = DT_INST_PROP(inst, channel), \ - .alts_size = ARRAY_SIZE(ps2_channel_alts##inst), \ - .alts_list = ps2_channel_alts##inst, \ .ps2_ctrl = DEVICE_DT_GET(DT_INST_PARENT(inst)), \ + .pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(inst), \ }; \ \ DEVICE_DT_INST_DEFINE(inst, ps2_npcx_channel_init, NULL, NULL, \ diff --git a/dts/arm/nuvoton/npcx.dtsi b/dts/arm/nuvoton/npcx.dtsi index a1edb62589..1157052411 100644 --- a/dts/arm/nuvoton/npcx.dtsi +++ b/dts/arm/nuvoton/npcx.dtsi @@ -531,7 +531,6 @@ ps2_channel0: io_ps2_channel0 { compatible = "nuvoton,npcx-ps2-channel"; channel = <0x00>; - pinctrl-0 = <&alt3_ps2_0_sl>; /* PIN67.70 */ label = "PS2_CHANNEL_0"; status = "disabled"; }; @@ -539,7 +538,6 @@ ps2_channel1: io_ps2_channel1 { compatible = "nuvoton,npcx-ps2-channel"; channel = <0x01>; - pinctrl-0 = <&alt3_ps2_1_sl>; /* PIN62.63 */ label = "PS2_CHANNEL_1"; status = "disabled"; }; @@ -547,7 +545,6 @@ ps2_channel2: io_ps2_channel2 { compatible = "nuvoton,npcx-ps2-channel"; channel = <0x02>; - pinctrl-0 = <&alt3_ps2_2_sl>; /* PIN37.34 */ label = "PS2_CHANNEL_2"; status = "disabled"; }; @@ -555,7 +552,6 @@ ps2_channel3: io_ps2_channel3 { compatible = "nuvoton,npcx-ps2-channel"; channel = <0x03>; - pinctrl-0 = <&altc_ps2_3_sl2>; /* PINA6.A7 */ label = "PS2_CHANNEL_3"; status = "disabled"; }; diff --git a/dts/bindings/ps2/nuvoton,npcx-ps2-channel.yaml b/dts/bindings/ps2/nuvoton,npcx-ps2-channel.yaml index f50f26c24e..c66785e3af 100644 --- a/dts/bindings/ps2/nuvoton,npcx-ps2-channel.yaml +++ b/dts/bindings/ps2/nuvoton,npcx-ps2-channel.yaml @@ -5,7 +5,7 @@ description: Nuvoton, NPCX-PS/2 channel pads node compatible: "nuvoton,npcx-ps2-channel" -include: base.yaml +include: [base.yaml, pinctrl-device.yaml] properties: channel: @@ -14,6 +14,7 @@ properties: description: index of i2c channel pinctrl-0: - type: phandles required: true - description: configurations of pinmux controllers + + pinctrl-names: + required: true