diff options
author | Shawn Nematbakhsh <shawnn@chromium.org> | 2016-05-26 14:38:38 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2016-05-27 18:08:58 -0700 |
commit | d1beddc463f488e527a90bf5adea92e4e9199a8f (patch) | |
tree | 606209a936928e338424abf219f6eddf933304f3 /common/pwm.c | |
parent | 8f886b40f4335a43bde5da9096308ae91935c7eb (diff) | |
download | chrome-ec-d1beddc463f488e527a90bf5adea92e4e9199a8f.tar.gz |
pwm: Modify new PWM host commands to take 16-bit duty cycle
EC_CMD_PWM_SET_DUTY / EC_CMD_PWM_GET_DUTY were recently added and are
not yet in use. Future-proof these commands by taking a 16-bit duty
cycle parameter and converting it between the [0-100] percent used by
internal EC functions.
BUG=chromium:615109
BRANCH=None
TEST=Manual on chell.
`ectool pwmsetduty kb 65535` - Verify KB backlight goes to 100%
`ectool pwmgetduty kb` - Prints 65535
`ectool pwmgetduty 0` - Prints 65535
`ectool pwmsetduty 0 0` - Verify KB backlight goes to 0%
`ectool pwmgetduty kb` - Prints 0
`ectool pwmgetduty disp` - Error res 3 (unsupported PWM type)
`ectool pwmsetduty 1` - Error res 3 (non-existent PWM index)
`ectool pwmsetduty kb 6550` +
`ectool pwmgetduty kb` - Prints 6553 (round up)
`ectool pwmsetduty kb 6560` +
`ectool pwmgetduty kb` - Prints 6553 (round down)
Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Change-Id: Ic6996fc6e1e69359274b2f9a1120ee7002db991c
Reviewed-on: https://chromium-review.googlesource.com/347608
Commit-Ready: Shawn N <shawnn@chromium.org>
Tested-by: Shawn N <shawnn@chromium.org>
Tested-by: Brian Norris <briannorris@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Reviewed-by: Brian Norris <briannorris@chromium.org>
Diffstat (limited to 'common/pwm.c')
-rw-r--r-- | common/pwm.c | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/common/pwm.c b/common/pwm.c index c689b0acac..84e242abf4 100644 --- a/common/pwm.c +++ b/common/pwm.c @@ -40,19 +40,25 @@ static int get_target_channel(enum pwm_channel *channel, int type, int index) return *channel >= PWM_CH_COUNT; } +/* + * TODO(crbug.com/615109): These host commands use 16 bit duty cycle, but + * all of our internal code uses percent on [0, 100]. Convert internal + * functions to use 16 bit duty and remove the conversions below. + */ static int host_command_pwm_set_duty(struct host_cmd_handler_args *args) { const struct ec_params_pwm_set_duty *p = args->params; enum pwm_channel channel; + int percent; - if (p->percent > 100) - return EC_RES_INVALID_PARAM; + /* Convert 16 bit duty to percent on [0, 100] */ + percent = DIV_ROUND_NEAREST(p->duty * 100, EC_PWM_MAX_DUTY); if (get_target_channel(&channel, p->pwm_type, p->index)) return EC_RES_INVALID_PARAM; - pwm_set_duty(channel, p->percent); - pwm_enable(channel, p->percent > 0); + pwm_set_duty(channel, percent); + pwm_enable(channel, percent > 0); return EC_RES_SUCCESS; } @@ -70,7 +76,8 @@ static int host_command_pwm_get_duty(struct host_cmd_handler_args *args) if (get_target_channel(&channel, p->pwm_type, p->index)) return EC_RES_INVALID_PARAM; - r->percent = pwm_get_duty(channel); + /* Convert percent on [0, 100] to 16 bit duty */ + r->duty = pwm_get_duty(channel) * EC_PWM_MAX_DUTY / 100; args->response_size = sizeof(*r); return EC_RES_SUCCESS; |