summaryrefslogtreecommitdiff
path: root/common/pwm.c
diff options
context:
space:
mode:
authorRandall Spangler <rspangler@chromium.org>2013-10-16 13:23:10 -0700
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2013-10-23 20:07:25 +0000
commit8cf03ac0563294fbdeca2dc133d06f0b51c9a546 (patch)
tree6b07c493e7567a3221d8592b4337d2787d6bc531 /common/pwm.c
parent2464d08e4d310a3f63208f22df4502c5250c4b58 (diff)
downloadchrome-ec-8cf03ac0563294fbdeca2dc133d06f0b51c9a546.tar.gz
Move source files to driver/ and power/ subdirs
The common/ subdir was getting cluttered. Move drivers for external components to a new driver/ tree, and move what used to be called chipset_*.c to a new power/ directory. This does not move/rename header files or CONFIG options. That will be done in subsequent steps, since moving and modifying .c files in the same CL is harder to review. BUG=chrome-os-partner:18343 BRANCH=none TEST=build all boards; pass unit tests Change-Id: I67a3003dc8564783a320335cf0e9620a21982d5e Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/173601 Reviewed-by: Bill Richardson <wfrichar@chromium.org> Tested-by: Bill Richardson <wfrichar@chromium.org> Reviewed-by: Vic Yang <victoryang@chromium.org>
Diffstat (limited to 'common/pwm.c')
-rw-r--r--common/pwm.c63
1 files changed, 63 insertions, 0 deletions
diff --git a/common/pwm.c b/common/pwm.c
new file mode 100644
index 0000000000..3a3073d142
--- /dev/null
+++ b/common/pwm.c
@@ -0,0 +1,63 @@
+/* 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);