summaryrefslogtreecommitdiff
path: root/chip/npcx/pwm.c
diff options
context:
space:
mode:
Diffstat (limited to 'chip/npcx/pwm.c')
-rw-r--r--chip/npcx/pwm.c24
1 files changed, 15 insertions, 9 deletions
diff --git a/chip/npcx/pwm.c b/chip/npcx/pwm.c
index eb743b3db4..b5ff0da835 100644
--- a/chip/npcx/pwm.c
+++ b/chip/npcx/pwm.c
@@ -54,7 +54,7 @@ enum npcx_pwm_heartbeat_mode {
* @param freq desired PWM frequency
* @notes changed when initialization
*/
-static void pwm_set_freq(enum pwm_channel ch, uint32_t freq)
+void pwm_set_freq(enum pwm_channel ch, uint32_t freq)
{
int mdl = pwm_channels[ch].channel;
uint32_t clock;
@@ -77,11 +77,8 @@ static void pwm_set_freq(enum pwm_channel ch, uint32_t freq)
/* Calculate prescaler */
pre = DIV_ROUND_UP(clock, (0xffff * freq));
- /*
- * Calculate maximum resolution for the given freq. and prescaler. And
- * prevent it exceed the resolution of CTR/DCR registers.
- */
- pwm_res[ch] = MIN((clock / pre) / freq, NPCX_PWM_MAX_RAW_DUTY);
+ /* Calculate maximum resolution for the given freq. and prescaler */
+ pwm_res[ch] = (clock / pre) / freq;
/* Set PWM prescaler. */
NPCX_PRSC(mdl) = pre - 1;
@@ -98,6 +95,7 @@ static void pwm_set_freq(enum pwm_channel ch, uint32_t freq)
*
* @param ch operation channel
* @param enabled enabled flag
+ * @return none
*/
void pwm_enable(enum pwm_channel ch, int enabled)
{
@@ -124,6 +122,7 @@ int pwm_get_enabled(enum pwm_channel ch)
*
* @param ch operation channel
* @param percent duty cycle percent
+ * @return none
*/
void pwm_set_duty(enum pwm_channel ch, int percent)
{
@@ -136,6 +135,7 @@ void pwm_set_duty(enum pwm_channel ch, int percent)
*
* @param ch operation channel
* @param duty cycle duty
+ * @return none
*/
void pwm_set_raw_duty(enum pwm_channel ch, uint16_t duty)
{
@@ -154,8 +154,10 @@ void pwm_set_raw_duty(enum pwm_channel ch, uint16_t duty)
/* duty ranges from 0 - 0xffff, so scale down to 0 - pwm_res[ch] */
sd = DIV_ROUND_NEAREST(duty * pwm_res[ch], EC_PWM_MAX_DUTY);
- /* Set the duty cycle. If it is zero, set DCR > CTR */
- NPCX_DCR(mdl) = sd ? sd : NPCX_PWM_MAX_RAW_DUTY + 1;
+ /* Set the duty cycle */
+ NPCX_DCR(mdl) = (uint16_t)sd;
+
+ pwm_enable(ch, !!duty);
}
/**
@@ -181,7 +183,7 @@ uint16_t pwm_get_raw_duty(enum pwm_channel ch)
int mdl = pwm_channels[ch].channel;
/* Return duty */
- if (NPCX_DCR(mdl) > NPCX_CTR(mdl))
+ if (!pwm_get_enabled(ch))
return 0;
else
/*
@@ -196,6 +198,7 @@ uint16_t pwm_get_raw_duty(enum pwm_channel ch)
* PWM configuration.
*
* @param ch operation channel
+ * @return none
*/
void pwm_config(enum pwm_channel ch)
{
@@ -229,6 +232,9 @@ void pwm_config(enum pwm_channel ch)
/**
* PWM initial.
+ *
+ * @param none
+ * @return none
*/
static void pwm_init(void)
{