summaryrefslogtreecommitdiff
path: root/board/rambi
diff options
context:
space:
mode:
authorRandall Spangler <rspangler@chromium.org>2013-10-07 10:59:45 -0700
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2013-10-08 20:41:32 +0000
commitff8c8fee79e148567c0f2128db69563acb29ee54 (patch)
tree0d3daa52c091a36c997c0cd42be8267678a13f7f /board/rambi
parent99157c265c8353e166059e17d250d9991d4e7ae0 (diff)
downloadchrome-ec-ff8c8fee79e148567c0f2128db69563acb29ee54.tar.gz
rambi: Control LEDs using PWM
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
Diffstat (limited to 'board/rambi')
-rw-r--r--board/rambi/board.c6
-rw-r--r--board/rambi/board.h1
-rw-r--r--board/rambi/build.mk2
-rw-r--r--board/rambi/led.c45
4 files changed, 50 insertions, 4 deletions
diff --git a/board/rambi/board.c b/board/rambi/board.c
index b864de5ef1..7a6f926763 100644
--- a/board/rambi/board.c
+++ b/board/rambi/board.c
@@ -110,7 +110,7 @@ const struct gpio_alt_func gpio_alt_funcs[] = {
{GPIO_D, 0x0f, 2, MODULE_SPI}, /* SPI1 */
{GPIO_L, 0x3f, 15, MODULE_LPC}, /* LPC */
{GPIO_M, 0x33, 15, MODULE_LPC}, /* LPC */
- {GPIO_N, 0x50, 1, MODULE_PWM_LED}, /* Power LEDs */
+ {GPIO_N, 0x50, 1, MODULE_PWM_LED, GPIO_OPEN_DRAIN}, /* Power LEDs */
};
const int gpio_alt_funcs_count = ARRAY_SIZE(gpio_alt_funcs);
@@ -152,8 +152,8 @@ BUILD_ASSERT(ARRAY_SIZE(adc_channels) == ADC_CH_COUNT);
/* PWM channels */
const struct pwm_t pwm_channels[] = {
- [PWM_CH_LED_GREEN] = {4, 0},
- [PWM_CH_LED_RED] = {3, 0},
+ [PWM_CH_LED_GREEN] = {4, PWM_CONFIG_ACTIVE_LOW},
+ [PWM_CH_LED_RED] = {3, PWM_CONFIG_ACTIVE_LOW},
};
BUILD_ASSERT(ARRAY_SIZE(pwm_channels) == PWM_CH_COUNT);
diff --git a/board/rambi/board.h b/board/rambi/board.h
index d9f038e850..2fdb718013 100644
--- a/board/rambi/board.h
+++ b/board/rambi/board.h
@@ -14,6 +14,7 @@
#define CONFIG_CMD_GSV
#define CONFIG_EXTPOWER_GPIO
#define CONFIG_KEYBOARD_PROTOCOL_8042
+#define CONFIG_LED_COMMON
#undef CONFIG_PECI
#define CONFIG_POWER_BUTTON
#define CONFIG_POWER_BUTTON_X86
diff --git a/board/rambi/build.mk b/board/rambi/build.mk
index 1843369ed4..ea89781339 100644
--- a/board/rambi/build.mk
+++ b/board/rambi/build.mk
@@ -9,4 +9,4 @@
# the IC is TI Stellaris LM4
CHIP:=lm4
-board-y=board.o
+board-y=board.o led.o
diff --git a/board/rambi/led.c b/board/rambi/led.c
new file mode 100644
index 0000000000..451aae2bc3
--- /dev/null
+++ b/board/rambi/led.c
@@ -0,0 +1,45 @@
+/* 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.
+ *
+ * Battery LED control for Rambi
+ */
+
+#include "gpio.h"
+#include "hooks.h"
+#include "led_common.h"
+#include "pwm.h"
+#include "util.h"
+
+const enum ec_led_id supported_led_ids[] = {EC_LED_ID_BATTERY_LED};
+const int supported_led_ids_count = ARRAY_SIZE(supported_led_ids);
+
+void led_get_brightness_range(enum ec_led_id led_id, uint8_t *brightness_range)
+{
+ brightness_range[EC_LED_COLOR_RED] = 100;
+ brightness_range[EC_LED_COLOR_GREEN] = 100;
+}
+
+int led_set_brightness(enum ec_led_id led_id, const uint8_t *brightness)
+{
+ pwm_set_duty(PWM_CH_LED_RED, brightness[EC_LED_COLOR_RED]);
+ pwm_set_duty(PWM_CH_LED_GREEN, brightness[EC_LED_COLOR_GREEN]);
+ return EC_SUCCESS;
+}
+
+static void led_init(void)
+{
+ /* Configure GPIOs */
+ gpio_config_module(MODULE_PWM_LED, 1);
+
+ /*
+ * Enable PWMs and set to 0% duty cycle. If they're disabled, the LM4
+ * seems to ground the pins instead of letting them float.
+ */
+ pwm_enable(PWM_CH_LED_RED, 1);
+ pwm_set_duty(PWM_CH_LED_RED, 0);
+
+ pwm_enable(PWM_CH_LED_GREEN, 1);
+ pwm_set_duty(PWM_CH_LED_GREEN, 0);
+}
+DECLARE_HOOK(HOOK_INIT, led_init, HOOK_PRIO_DEFAULT);