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 <jay.vasanth@microchip.com>
This commit is contained in:
Jay Vasanth 2022-04-11 16:23:20 -04:00 committed by Maureen Helm
commit b7f60b2354
3 changed files with 40 additions and 1 deletions

View file

@ -247,3 +247,9 @@
pinctrl-0 = <&tach0_gpio050>; pinctrl-0 = <&tach0_gpio050>;
pinctrl-names = "default"; pinctrl-names = "default";
}; };
&ps2_0 {
status = "okay";
pinctrl-0 = <&ps2_clk0a_gpio114 &ps2_dat0a_gpio115>;
pinctrl-names = "default";
};

View file

@ -14,6 +14,9 @@
#include <drivers/clock_control/mchp_xec_clock_control.h> #include <drivers/clock_control/mchp_xec_clock_control.h>
#include <drivers/interrupt_controller/intc_mchp_xec_ecia.h> #include <drivers/interrupt_controller/intc_mchp_xec_ecia.h>
#endif #endif
#ifdef CONFIG_PINCTRL
#include <drivers/pinctrl.h>
#endif
#include <drivers/ps2.h> #include <drivers/ps2.h>
#include <soc.h> #include <soc.h>
#include <logging/log.h> #include <logging/log.h>
@ -32,6 +35,9 @@ struct ps2_xec_config {
uint8_t pcr_idx; uint8_t pcr_idx;
uint8_t pcr_pos; uint8_t pcr_pos;
void (*irq_config_func)(void); void (*irq_config_func)(void);
#ifdef CONFIG_PINCTRL
const struct pinctrl_dev_config *pcfg;
#endif
}; };
struct ps2_xec_data { 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; const struct ps2_xec_config * const cfg = dev->config;
struct ps2_xec_data * const data = dev->data; 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); ps2_xec_slp_en_clr(dev);
k_sem_init(&data->tx_lock, 0, 1); k_sem_init(&data->tx_lock, 0, 1);
@ -262,6 +277,21 @@ static int ps2_xec_init(const struct device *dev)
return 0; 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) \ #define XEC_PS2_CONFIG(inst) \
static const struct ps2_xec_config ps2_xec_config_##inst = { \ static const struct ps2_xec_config ps2_xec_config_##inst = { \
.regs = (struct ps2_regs * const)(DT_INST_REG_ADDR(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)), \ .pcr_pos = (uint8_t)(DT_INST_PROP_BY_IDX(inst, pcrs, 1)), \
.irq_config_func = ps2_xec_irq_config_func_##inst, \ .irq_config_func = ps2_xec_irq_config_func_##inst, \
} }
#endif
#define PS2_XEC_DEVICE(i) \ #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; \ static struct ps2_xec_data ps2_xec_port_data_##i; \
\ \
XEC_PS2_PINCTRL_CFG(i); \
\
XEC_PS2_CONFIG(i); \ XEC_PS2_CONFIG(i); \
\ \
DEVICE_DT_INST_DEFINE(i, &ps2_xec_init, \ DEVICE_DT_INST_DEFINE(i, &ps2_xec_init, \

View file

@ -5,7 +5,7 @@ description: Microchip XEC PS/2 controller
compatible: "microchip,xec-ps2" compatible: "microchip,xec-ps2"
include: ps2.yaml include: [ps2.yaml, pinctrl-device.yaml]
properties: properties:
reg: reg: