drivers: pwm: mchp: Low power mode enabled
Updated the driver with low power feature Signed-off-by: Manimaran A <manimaran.a@microchip.com>
This commit is contained in:
parent
25d496949f
commit
85a70c9847
|
@ -19,6 +19,7 @@
|
|||
#endif
|
||||
#include <zephyr/drivers/pinctrl.h>
|
||||
#include <zephyr/logging/log.h>
|
||||
#include <zephyr/pm/device.h>
|
||||
|
||||
#include <soc.h>
|
||||
|
||||
|
@ -62,6 +63,10 @@ struct xec_params {
|
|||
uint8_t div;
|
||||
};
|
||||
|
||||
struct pwm_xec_data {
|
||||
uint32_t config;
|
||||
};
|
||||
|
||||
#define NUM_DIV_ELEMS 16
|
||||
|
||||
static const uint32_t max_freq_high_on_div[NUM_DIV_ELEMS] = {
|
||||
|
@ -368,6 +373,50 @@ static int pwm_xec_get_cycles_per_sec(const struct device *dev,
|
|||
return 0;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_PM_DEVICE
|
||||
static int pwm_xec_pm_action(const struct device *dev, enum pm_device_action action)
|
||||
{
|
||||
const struct pwm_xec_config *const devcfg = dev->config;
|
||||
struct pwm_regs * const regs = devcfg->regs;
|
||||
struct pwm_xec_data * const data = dev->data;
|
||||
int ret = 0;
|
||||
|
||||
switch (action) {
|
||||
case PM_DEVICE_ACTION_RESUME:
|
||||
ret = pinctrl_apply_state(devcfg->pcfg, PINCTRL_STATE_DEFAULT);
|
||||
if (ret != 0) {
|
||||
LOG_ERR("XEC PWM pinctrl setup failed (%d)", ret);
|
||||
}
|
||||
|
||||
/* Turn on PWM only if it is ON before sleep */
|
||||
if ((data->config & MCHP_PWM_CFG_ENABLE) == MCHP_PWM_CFG_ENABLE) {
|
||||
|
||||
regs->CONFIG |= MCHP_PWM_CFG_ENABLE;
|
||||
|
||||
data->config &= (~MCHP_PWM_CFG_ENABLE);
|
||||
}
|
||||
break;
|
||||
case PM_DEVICE_ACTION_SUSPEND:
|
||||
if ((regs->CONFIG & MCHP_PWM_CFG_ENABLE) == MCHP_PWM_CFG_ENABLE) {
|
||||
/* Do copy first, then clear mode. */
|
||||
data->config = regs->CONFIG;
|
||||
|
||||
regs->CONFIG &= ~(MCHP_PWM_CFG_ENABLE);
|
||||
}
|
||||
|
||||
ret = pinctrl_apply_state(devcfg->pcfg, PINCTRL_STATE_SLEEP);
|
||||
/* pinctrl-1 does not exist. */
|
||||
if (ret == -ENOENT) {
|
||||
ret = 0;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
ret = -ENOTSUP;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
#endif /* CONFIG_PM_DEVICE */
|
||||
|
||||
static const struct pwm_driver_api pwm_xec_driver_api = {
|
||||
.set_cycles = pwm_xec_set_cycles,
|
||||
.get_cycles_per_sec = pwm_xec_get_cycles_per_sec,
|
||||
|
@ -396,13 +445,17 @@ static int pwm_xec_init(const struct device *dev)
|
|||
|
||||
#define XEC_PWM_DEVICE_INIT(index) \
|
||||
\
|
||||
static struct pwm_xec_data pwm_xec_data_##index; \
|
||||
\
|
||||
PINCTRL_DT_INST_DEFINE(index); \
|
||||
\
|
||||
XEC_PWM_CONFIG(index); \
|
||||
\
|
||||
PM_DEVICE_DT_INST_DEFINE(index, pwm_xec_pm_action); \
|
||||
\
|
||||
DEVICE_DT_INST_DEFINE(index, &pwm_xec_init, \
|
||||
NULL, \
|
||||
NULL, \
|
||||
PM_DEVICE_DT_INST_GET(index), \
|
||||
&pwm_xec_data_##index, \
|
||||
&pwm_xec_config_##index, POST_KERNEL, \
|
||||
CONFIG_PWM_INIT_PRIORITY, \
|
||||
&pwm_xec_driver_api);
|
||||
|
|
|
@ -1088,4 +1088,68 @@
|
|||
pinmux = < MCHP_XEC_PINMUX(0155, MCHP_AF2) >;
|
||||
low-power-enable;
|
||||
};
|
||||
|
||||
/* PWM */
|
||||
pwm0_gpio053_sleep: pwm0_gpio053_sleep {
|
||||
pinmux = < MCHP_XEC_PINMUX(053, MCHP_AF1) >;
|
||||
};
|
||||
|
||||
pwm0_alt_gpio241_sleep: pwm0_alt_gpio241_sleep {
|
||||
pinmux = < MCHP_XEC_PINMUX(0241, MCHP_AF1) >;
|
||||
};
|
||||
|
||||
pwm1_gpio054_sleep: pwm1_gpio054_sleep {
|
||||
pinmux = < MCHP_XEC_PINMUX(054, MCHP_AF1) >;
|
||||
};
|
||||
|
||||
pwm1_alt_gpio254_sleep: pwm1_alt_gpio254_sleep {
|
||||
pinmux = < MCHP_XEC_PINMUX(0254, MCHP_AF1) >;
|
||||
};
|
||||
|
||||
pwm2_gpio055_sleep: pwm2_gpio055_sleep {
|
||||
pinmux = < MCHP_XEC_PINMUX(055, MCHP_AF1) >;
|
||||
};
|
||||
|
||||
pwm2_alt_gpio045_sleep: pwm2_alt_gpio045_sleep {
|
||||
pinmux = < MCHP_XEC_PINMUX(045, MCHP_AF2) >;
|
||||
};
|
||||
pwm3_gpio056_sleep: pwm3_gpio056_sleep {
|
||||
pinmux = < MCHP_XEC_PINMUX(056, MCHP_AF1) >;
|
||||
};
|
||||
|
||||
pwm3_alt_gpio047_sleep: pwm3_alt_gpio047_sleep {
|
||||
pinmux = < MCHP_XEC_PINMUX(047, MCHP_AF2) >;
|
||||
};
|
||||
|
||||
pwm4_gpio011_sleep: pwm4_gpio011_sleep {
|
||||
pinmux = < MCHP_XEC_PINMUX(011, MCHP_AF2) >;
|
||||
};
|
||||
|
||||
pwm5_gpio002_sleep: pwm5_gpio002_sleep {
|
||||
pinmux = < MCHP_XEC_PINMUX(02, MCHP_AF1) >;
|
||||
};
|
||||
|
||||
pwm6_gpio014_sleep: pwm6_gpio014_sleep {
|
||||
pinmux = < MCHP_XEC_PINMUX(014, MCHP_AF1) >;
|
||||
};
|
||||
|
||||
pwm6_alt_gpio063_sleep: pwm6_alt_gpio063_sleep {
|
||||
pinmux = < MCHP_XEC_PINMUX(063, MCHP_AF2) >;
|
||||
};
|
||||
|
||||
pwm7_gpio015_sleep: pwm7_gpio015_sleep {
|
||||
pinmux = < MCHP_XEC_PINMUX(015, MCHP_AF1) >;
|
||||
};
|
||||
|
||||
pwm7_alt_gpio061_sleep: pwm7_alt_gpio061_sleep {
|
||||
pinmux = < MCHP_XEC_PINMUX(061, MCHP_AF2) >;
|
||||
};
|
||||
|
||||
pwm8_gpio035_sleep: pwm8_gpio035_sleep {
|
||||
pinmux = < MCHP_XEC_PINMUX(035, MCHP_AF1) >;
|
||||
};
|
||||
|
||||
pwm8_alt_gpio175_sleep: pwm8_alt_gpio175_sleep {
|
||||
pinmux = < MCHP_XEC_PINMUX(0175, MCHP_AF3) >;
|
||||
};
|
||||
};
|
||||
|
|
|
@ -1113,4 +1113,74 @@
|
|||
low-power-enable;
|
||||
};
|
||||
|
||||
/* PWM */
|
||||
pwm0_gpio053_sleep: pwm0_gpio053_sleep {
|
||||
pinmux = < MCHP_XEC_PINMUX(053, MCHP_AF1) >;
|
||||
low-power-enable;
|
||||
};
|
||||
|
||||
pwm0_alt_gpio241_sleep: pwm0_alt_gpio241_sleep {
|
||||
pinmux = < MCHP_XEC_PINMUX(0241, MCHP_AF4) >;
|
||||
low-power-enable;
|
||||
};
|
||||
|
||||
pwm1_gpio054_sleep: pwm1_gpio054_sleep {
|
||||
pinmux = < MCHP_XEC_PINMUX(054, MCHP_AF1) >;
|
||||
low-power-enable;
|
||||
};
|
||||
|
||||
pwm2_gpio055_sleep: pwm2_gpio055_sleep {
|
||||
pinmux = < MCHP_XEC_PINMUX(055, MCHP_AF1) >;
|
||||
low-power-enable;
|
||||
};
|
||||
|
||||
pwm2_alt_gpio045_sleep: pwm2_alt_gpio045_sleep {
|
||||
pinmux = < MCHP_XEC_PINMUX(045, MCHP_AF2) >;
|
||||
low-power-enable;
|
||||
};
|
||||
|
||||
pwm3_gpio056_sleep: pwm3_gpio056_sleep {
|
||||
pinmux = < MCHP_XEC_PINMUX(056, MCHP_AF1) >;
|
||||
low-power-enable;
|
||||
};
|
||||
|
||||
pwm3_alt_gpio047_sleep: pwm3_alt_gpio047_sleep {
|
||||
pinmux = < MCHP_XEC_PINMUX(047, MCHP_AF2) >;
|
||||
low-power-enable;
|
||||
};
|
||||
pwm4_gpio011_sleep: pwm4_gpio011_sleep {
|
||||
pinmux = < MCHP_XEC_PINMUX(011, MCHP_AF2) >;
|
||||
low-power-enable;
|
||||
};
|
||||
|
||||
pwm5_gpio002_sleep: pwm5_gpio002_sleep {
|
||||
pinmux = < MCHP_XEC_PINMUX(02, MCHP_AF1) >;
|
||||
low-power-enable;
|
||||
};
|
||||
|
||||
pwm6_gpio014_sleep: pwm6_gpio014_sleep {
|
||||
pinmux = < MCHP_XEC_PINMUX(014, MCHP_AF1) >;
|
||||
low-power-enable;
|
||||
};
|
||||
|
||||
pwm6_alt_gpio063_sleep: pwm6_alt_gpio063_sleep {
|
||||
pinmux = < MCHP_XEC_PINMUX(063, MCHP_AF2) >;
|
||||
low-power-enable;
|
||||
};
|
||||
|
||||
pwm7_gpio015_sleep: pwm7_gpio015_sleep {
|
||||
pinmux = < MCHP_XEC_PINMUX(015, MCHP_AF1) >;
|
||||
low-power-enable;
|
||||
};
|
||||
|
||||
pwm8_gpio035_sleep: pwm8_gpio035_sleep {
|
||||
pinmux = < MCHP_XEC_PINMUX(035, MCHP_AF1) >;
|
||||
low-power-enable;
|
||||
};
|
||||
|
||||
pwm8_alt_gpio175_sleep: pwm8_alt_gpio175_sleep {
|
||||
pinmux = < MCHP_XEC_PINMUX(0175, MCHP_AF3) >;
|
||||
low-power-enable;
|
||||
};
|
||||
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue