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 <jay.vasanth@microchip.com>
This commit is contained in:
parent
845c1185a2
commit
7c65268f3e
|
@ -234,3 +234,9 @@
|
|||
&kso13_gpio126 >;
|
||||
pinctrl-names = "default";
|
||||
};
|
||||
|
||||
&pwm0 {
|
||||
status = "okay";
|
||||
pinctrl-0 = <&pwm0_gpio053>;
|
||||
pinctrl-names = "default";
|
||||
};
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -9,17 +9,19 @@
|
|||
|
||||
#include <errno.h>
|
||||
|
||||
#include <soc.h>
|
||||
#include <drivers/pwm.h>
|
||||
#include <device.h>
|
||||
#ifdef CONFIG_SOC_SERIES_MEC172X
|
||||
#include <drivers/clock_control/mchp_xec_clock_control.h>
|
||||
#include <drivers/interrupt_controller/intc_mchp_xec_ecia.h>
|
||||
#endif
|
||||
#include <device.h>
|
||||
#ifdef CONFIG_PINCTRL
|
||||
#include <drivers/pinctrl.h>
|
||||
#endif
|
||||
#include <drivers/pwm.h>
|
||||
#include <errno.h>
|
||||
#include <kernel.h>
|
||||
#include <init.h>
|
||||
#include <pm/device.h>
|
||||
#include <soc.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <logging/log.h>
|
||||
|
@ -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, \
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
|
Loading…
Reference in a new issue