From b7f60b23548b92ce074fd6e29c8227d651526ac1 Mon Sep 17 00:00:00 2001 From: Jay Vasanth Date: Mon, 11 Apr 2022 16:23:20 -0400 Subject: [PATCH] drivers: ps2: Microchip XEC PS2 driver add PINCTRL support Add optional PINCTRL support to the Microchip XEC PS2 driver shared between MEC15xx and MEC172x families. Signed-off-by: Jay Vasanth --- .../mec172xevb_assy6906.dts | 6 ++++ drivers/ps2/ps2_mchp_xec.c | 33 +++++++++++++++++++ dts/bindings/ps2/microchip,xec-ps2.yaml | 2 +- 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/boards/arm/mec172xevb_assy6906/mec172xevb_assy6906.dts b/boards/arm/mec172xevb_assy6906/mec172xevb_assy6906.dts index 187662e6a68..96ace6dcb60 100644 --- a/boards/arm/mec172xevb_assy6906/mec172xevb_assy6906.dts +++ b/boards/arm/mec172xevb_assy6906/mec172xevb_assy6906.dts @@ -247,3 +247,9 @@ pinctrl-0 = <&tach0_gpio050>; pinctrl-names = "default"; }; + +&ps2_0 { + status = "okay"; + pinctrl-0 = <&ps2_clk0a_gpio114 &ps2_dat0a_gpio115>; + pinctrl-names = "default"; +}; diff --git a/drivers/ps2/ps2_mchp_xec.c b/drivers/ps2/ps2_mchp_xec.c index 982033fe69f..12664b8065b 100644 --- a/drivers/ps2/ps2_mchp_xec.c +++ b/drivers/ps2/ps2_mchp_xec.c @@ -14,6 +14,9 @@ #include #include #endif +#ifdef CONFIG_PINCTRL +#include +#endif #include #include #include @@ -32,6 +35,9 @@ struct ps2_xec_config { uint8_t pcr_idx; uint8_t pcr_pos; void (*irq_config_func)(void); +#ifdef CONFIG_PINCTRL + const struct pinctrl_dev_config *pcfg; +#endif }; struct ps2_xec_data { @@ -253,6 +259,15 @@ static int ps2_xec_init(const struct device *dev) const struct ps2_xec_config * const cfg = dev->config; struct ps2_xec_data * const data = dev->data; +#ifdef CONFIG_PINCTRL + int ret = pinctrl_apply_state(cfg->pcfg, PINCTRL_STATE_DEFAULT); + + if (ret != 0) { + LOG_ERR("XEC PS2 pinctrl init failed (%d)", ret); + return ret; + } +#endif + ps2_xec_slp_en_clr(dev); k_sem_init(&data->tx_lock, 0, 1); @@ -262,6 +277,21 @@ static int ps2_xec_init(const struct device *dev) return 0; } +#ifdef CONFIG_PINCTRL +#define XEC_PS2_PINCTRL_CFG(inst) PINCTRL_DT_INST_DEFINE(inst) +#define XEC_PS2_CONFIG(inst) \ + static const struct ps2_xec_config ps2_xec_config_##inst = { \ + .regs = (struct ps2_regs * const)(DT_INST_REG_ADDR(inst)), \ + .isr_nvic = DT_INST_IRQN(inst), \ + .girq_id = (uint8_t)(DT_INST_PROP_BY_IDX(inst, girqs, 0)), \ + .girq_bit = (uint8_t)(DT_INST_PROP_BY_IDX(inst, girqs, 1)), \ + .pcr_idx = (uint8_t)(DT_INST_PROP_BY_IDX(inst, pcrs, 0)), \ + .pcr_pos = (uint8_t)(DT_INST_PROP_BY_IDX(inst, pcrs, 1)), \ + .irq_config_func = ps2_xec_irq_config_func_##inst, \ + .pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(inst), \ + } +#else +#define XEC_PS2_PINCTRL_CFG(inst) #define XEC_PS2_CONFIG(inst) \ static const struct ps2_xec_config ps2_xec_config_##inst = { \ .regs = (struct ps2_regs * const)(DT_INST_REG_ADDR(inst)), \ @@ -272,6 +302,7 @@ static int ps2_xec_init(const struct device *dev) .pcr_pos = (uint8_t)(DT_INST_PROP_BY_IDX(inst, pcrs, 1)), \ .irq_config_func = ps2_xec_irq_config_func_##inst, \ } +#endif #define PS2_XEC_DEVICE(i) \ \ @@ -286,6 +317,8 @@ static int ps2_xec_init(const struct device *dev) \ static struct ps2_xec_data ps2_xec_port_data_##i; \ \ + XEC_PS2_PINCTRL_CFG(i); \ + \ XEC_PS2_CONFIG(i); \ \ DEVICE_DT_INST_DEFINE(i, &ps2_xec_init, \ diff --git a/dts/bindings/ps2/microchip,xec-ps2.yaml b/dts/bindings/ps2/microchip,xec-ps2.yaml index 940343655f6..75bf61a304a 100644 --- a/dts/bindings/ps2/microchip,xec-ps2.yaml +++ b/dts/bindings/ps2/microchip,xec-ps2.yaml @@ -5,7 +5,7 @@ description: Microchip XEC PS/2 controller compatible: "microchip,xec-ps2" -include: ps2.yaml +include: [ps2.yaml, pinctrl-device.yaml] properties: reg: