From 7c65268f3ef8c1fadb3670870570b66e4326ba46 Mon Sep 17 00:00:00 2001 From: Jay Vasanth Date: Fri, 11 Mar 2022 14:52:59 -0500 Subject: [PATCH] drivers: pwm: Microchp XEC PWM driver add PINCTRL support Add build time optional PINCTRL support to common PWM driver for Microchip XEC MEC15xx and MEC172x families. Signed-off-by: Jay Vasanth --- .../mec172xevb_assy6906.dts | 6 +++ drivers/pwm/Kconfig.xec | 1 + drivers/pwm/pwm_mchp_xec.c | 38 +++++++++++++++++-- dts/bindings/pwm/microchip,xec-pwm.yaml | 2 +- 4 files changed, 42 insertions(+), 5 deletions(-) diff --git a/boards/arm/mec172xevb_assy6906/mec172xevb_assy6906.dts b/boards/arm/mec172xevb_assy6906/mec172xevb_assy6906.dts index 76f403e642..33bf03c42d 100644 --- a/boards/arm/mec172xevb_assy6906/mec172xevb_assy6906.dts +++ b/boards/arm/mec172xevb_assy6906/mec172xevb_assy6906.dts @@ -234,3 +234,9 @@ &kso13_gpio126 >; pinctrl-names = "default"; }; + +&pwm0 { + status = "okay"; + pinctrl-0 = <&pwm0_gpio053>; + pinctrl-names = "default"; +}; diff --git a/drivers/pwm/Kconfig.xec b/drivers/pwm/Kconfig.xec index f54b54dd16..19f1815f93 100644 --- a/drivers/pwm/Kconfig.xec +++ b/drivers/pwm/Kconfig.xec @@ -6,5 +6,6 @@ config PWM_XEC bool "Microchip XEC PWM" depends on SOC_FAMILY_MEC + default $(dt_compat_enabled,${DT_COMPAT_ST_PWM_XEC}) help Enable driver to utilize PWM on the Microchip XEC IP block. diff --git a/drivers/pwm/pwm_mchp_xec.c b/drivers/pwm/pwm_mchp_xec.c index 8dd95e003b..4c0575825d 100644 --- a/drivers/pwm/pwm_mchp_xec.c +++ b/drivers/pwm/pwm_mchp_xec.c @@ -9,17 +9,19 @@ #include -#include -#include +#include #ifdef CONFIG_SOC_SERIES_MEC172X #include #include #endif -#include +#ifdef CONFIG_PINCTRL +#include +#endif +#include #include #include #include -#include +#include #include #include @@ -54,6 +56,9 @@ struct pwm_xec_config { struct pwm_regs * const regs; uint8_t pcr_idx; uint8_t pcr_pos; +#ifdef CONFIG_PINCTRL + const struct pinctrl_dev_config *pcfg; +#endif }; struct xec_params { @@ -380,20 +385,45 @@ static const struct pwm_driver_api pwm_xec_driver_api = { static int pwm_xec_init(const struct device *dev) { +#ifdef CONFIG_PINCTRL + const struct pwm_xec_config * const cfg = dev->config; + int ret = pinctrl_apply_state(cfg->pcfg, PINCTRL_STATE_DEFAULT); + + if (ret != 0) { + LOG_ERR("XEC PWM pinctrl init failed (%d)", ret); + return ret; + } +#else ARG_UNUSED(dev); +#endif return 0; } +#ifdef CONFIG_PINCTRL +#define XEC_PWM_PINCTRL_DEF(inst) PINCTRL_DT_INST_DEFINE(inst) +#define XEC_PWM_CONFIG(inst) \ + static struct pwm_xec_config pwm_xec_config_##inst = { \ + .regs = (struct pwm_regs * const)DT_INST_REG_ADDR(inst), \ + .pcr_idx = (uint8_t)DT_INST_PROP_BY_IDX(inst, pcrs, 0), \ + .pcr_pos = (uint8_t)DT_INST_PROP_BY_IDX(inst, pcrs, 1), \ + .pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(inst), \ + }; + +#else +#define XEC_PWM_PINCTRL_DEF(inst) #define XEC_PWM_CONFIG(inst) \ static struct pwm_xec_config pwm_xec_config_##inst = { \ .regs = (struct pwm_regs * const)DT_INST_REG_ADDR(inst), \ .pcr_idx = (uint8_t)DT_INST_PROP_BY_IDX(inst, pcrs, 0), \ .pcr_pos = (uint8_t)DT_INST_PROP_BY_IDX(inst, pcrs, 1), \ }; +#endif #define XEC_PWM_DEVICE_INIT(index) \ \ + XEC_PWM_PINCTRL_DEF(index); \ + \ XEC_PWM_CONFIG(index); \ \ DEVICE_DT_INST_DEFINE(index, &pwm_xec_init, \ diff --git a/dts/bindings/pwm/microchip,xec-pwm.yaml b/dts/bindings/pwm/microchip,xec-pwm.yaml index 623d3045d0..e66d8adab3 100644 --- a/dts/bindings/pwm/microchip,xec-pwm.yaml +++ b/dts/bindings/pwm/microchip,xec-pwm.yaml @@ -3,7 +3,7 @@ description: Microchip XEC PWM -include: [pwm-controller.yaml, base.yaml] +include: [pwm-controller.yaml, base.yaml, pinctrl-device.yaml] compatible: "microchip,xec-pwm"