diff options
author | Shawn Nematbakhsh <shawnn@chromium.org> | 2015-12-01 13:49:15 -0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2015-12-04 01:20:33 -0800 |
commit | 99c186b70109f387639acb6d8df5a37423d8f4bb (patch) | |
tree | 21aef832a98994790e4e892687636c47726a8ae5 /chip/stm32/pwm.c | |
parent | 743a9ea7cd39dffc4f1dc104803f767ba774372b (diff) | |
download | chrome-ec-99c186b70109f387639acb6d8df5a37423d8f4bb.tar.gz |
stm32: pwm: Allow configuration of pwm frequency + complementary outputs
Allow boards to customize both the PWM frequency / period and the
enabling of complementary output signals.
BUG=chrome-os-partner:48044
TEST=Manual with snoball w/ subsequent commit. Run `pwm <ch> 50` for
each channel, verify with `adc` that each PD output voltage is
approximately VBUCK / 2.
BRANCH=None
Change-Id: I61cbb4a5b656f41ec7cec59339f5247902256295
Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/315141
Commit-Ready: Shawn N <shawnn@chromium.org>
Tested-by: Shawn N <shawnn@chromium.org>
Reviewed-by: Alec Berg <alecaberg@chromium.org>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Diffstat (limited to 'chip/stm32/pwm.c')
-rw-r--r-- | chip/stm32/pwm.c | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/chip/stm32/pwm.c b/chip/stm32/pwm.c index a457cb709d..aa5149b074 100644 --- a/chip/stm32/pwm.c +++ b/chip/stm32/pwm.c @@ -37,6 +37,9 @@ static void pwm_configure(enum pwm_channel ch) const struct pwm_t *pwm = pwm_channels + ch; timer_ctlr_t *tim = (timer_ctlr_t *)(pwm->tim.base); volatile unsigned *ccmr = NULL; + /* Default frequency = 100 Hz */ + int frequency = pwm->frequency ? pwm->frequency : 100; + uint16_t ccer; if (using_pwm[ch]) return; @@ -54,7 +57,7 @@ static void pwm_configure(enum pwm_channel ch) * * frequency = cpu_freq / (cpu_freq/10000 + 1) / (99 + 1) = 100 Hz. */ - tim->psc = clock_get_freq() / 10000 - 1; + tim->psc = clock_get_freq() / (frequency * 100) - 1; tim->arr = 99; if (pwm->channel <= 2) /* Channel ID starts from 1 */ @@ -70,9 +73,15 @@ static void pwm_configure(enum pwm_channel ch) /* Output enable. Set active high/low. */ if (pwm->flags & PWM_CONFIG_ACTIVE_LOW) - tim->ccer = 3 << (pwm->channel * 4 - 4); + ccer = 3 << (pwm->channel * 4 - 4); else - tim->ccer = 1 << (pwm->channel * 4 - 4); + ccer = 1 << (pwm->channel * 4 - 4); + + /* Enable complementary output, if present. */ + if (pwm->flags & PWM_CONFIG_COMPLEMENTARY_OUTPUT) + ccer |= (ccer << 2); + + tim->ccer = ccer; /* * Main output enable. |