mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2026-01-10 01:21:49 +00:00
Rambi has a pair of LEDs which are attached to the PWM fan controller.
Add support for them. Also add a generic 'pwmduty' command which can
be used to get/set the duty cycle for any PWM channel.
Also fix rounding errors in pwm module, so that set/get duty doesn't
keep rounding down.
BUG=chrome-os-partner:22895
BRANCH=none
TEST=Boot rambi. LEDs are off.
pwmduty -> both are 0%
pwmduty 0 10 -> green LED on dimly
pwmduty 1 10 -> red LED on dimly
pwmduty 0 99 -> green LED on brightly
pwmduty 1 100 -> red LED on brightly
pwmduty 1 0 -> red LED off
pwmduty 1 -1 -> red LED turns back on because fan controller is disabled
pwmduty -> channel 0 at 99%, channel 1 disabled
Build all platforms. Pass all unit tests.
Change-Id: Ib0a6289a757554e696a9a0153a85bdc34e2ee2ae
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/172094
64 lines
1.3 KiB
C
64 lines
1.3 KiB
C
/* Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
* found in the LICENSE file.
|
|
*/
|
|
|
|
#include "common.h"
|
|
#include "console.h"
|
|
#include "pwm.h"
|
|
#include "util.h"
|
|
|
|
/**
|
|
* Print status of a PWM channel.
|
|
*
|
|
* @param ch Channel to print.
|
|
*/
|
|
static void print_channel(enum pwm_channel ch)
|
|
{
|
|
if (pwm_get_enabled(ch))
|
|
ccprintf(" %d: %d%%\n", ch, pwm_get_duty(ch));
|
|
else
|
|
ccprintf(" %d: disabled\n", ch);
|
|
}
|
|
|
|
static int cc_pwm_duty(int argc, char **argv)
|
|
{
|
|
int percent = 0;
|
|
int ch;
|
|
char *e;
|
|
|
|
if (argc < 2) {
|
|
ccprintf("PWM channels:\n");
|
|
for (ch = 0; ch < PWM_CH_COUNT; ch++)
|
|
print_channel(ch);
|
|
return EC_SUCCESS;
|
|
}
|
|
|
|
ch = strtoi(argv[1], &e, 0);
|
|
if (*e || ch < 0 || ch >= PWM_CH_COUNT)
|
|
return EC_ERROR_PARAM1;
|
|
|
|
if (argc > 2) {
|
|
percent = strtoi(argv[2], &e, 0);
|
|
if (*e || percent > 100) {
|
|
/* Bad param */
|
|
return EC_ERROR_PARAM1;
|
|
} else if (percent < 0) {
|
|
/* Negative = disable */
|
|
pwm_enable(ch, 0);
|
|
} else {
|
|
ccprintf("Setting channel %d to %d%%\n", ch, percent);
|
|
pwm_enable(ch, 1);
|
|
pwm_set_duty(ch, percent);
|
|
}
|
|
}
|
|
|
|
print_channel(ch);
|
|
|
|
return EC_SUCCESS;
|
|
}
|
|
DECLARE_CONSOLE_COMMAND(pwmduty, cc_pwm_duty,
|
|
"[channel [<percent> | -1=disable]]",
|
|
"Get/set PWM duty cycles ",
|
|
NULL);
|