diff options
author | Vic Yang <victoryang@chromium.org> | 2013-01-19 23:48:43 +0800 |
---|---|---|
committer | ChromeBot <chrome-bot@google.com> | 2013-01-21 20:25:47 -0800 |
commit | 17dae824d21ae31882aa6318c4fcce0bbf50e1e5 (patch) | |
tree | d1aac6778643ea5ff84474f64e51bae1d3819632 | |
parent | c8a61c39ef25411e9ac28cbf3e42954a19aca7a3 (diff) | |
download | chrome-ec-17dae824d21ae31882aa6318c4fcce0bbf50e1e5.tar.gz |
spring: Add LP5562 driver
BUG=chrome-os-partner:17341
TEST=Set LED color on Spring board
BRANCH=none
Change-Id: Ibae11a0cf8a724a38e96c5c49952799101bb5764
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/41693
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
-rw-r--r-- | board/spring/board.h | 3 | ||||
-rw-r--r-- | common/build.mk | 1 | ||||
-rw-r--r-- | common/lp5562.c | 86 | ||||
-rw-r--r-- | include/lp5562.h | 38 |
4 files changed, 128 insertions, 0 deletions
diff --git a/board/spring/board.h b/board/spring/board.h index dd2ef7bf99..dee62008ce 100644 --- a/board/spring/board.h +++ b/board/spring/board.h @@ -58,6 +58,9 @@ /* Charger/accessories detection */ #define CONFIG_TSU6721 +/* LED driver */ +#define CONFIG_LP5562 + /* Timer selection */ #define TIM_CLOCK_MSB 2 #define TIM_CLOCK_LSB 4 diff --git a/common/build.mk b/common/build.mk index ee73575399..3366e0c254 100644 --- a/common/build.mk +++ b/common/build.mk @@ -18,6 +18,7 @@ common-$(CONFIG_FLASH)+=flash_common.o fmap.o common-$(CONFIG_I2C)+=i2c_commands.o common-$(CONFIG_IR357x)+=ir357x.o common-$(CONFIG_KEYBOARD_TEST)+=keyboard_test.o +common-$(CONFIG_LP5562)+=lp5562.o common-$(CONFIG_LPC)+=port80.o common-$(CONFIG_POWER_LED)+=power_led.o common-$(CONFIG_PSTORE)+=pstore_commands.o diff --git a/common/lp5562.c b/common/lp5562.c new file mode 100644 index 0000000000..50f0f940a2 --- /dev/null +++ b/common/lp5562.c @@ -0,0 +1,86 @@ +/* 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. + * + * TI LP5562 driver. + */ + +#include "board.h" +#include "console.h" +#include "i2c.h" +#include "lp5562.h" +#include "timer.h" +#include "uart.h" +#include "util.h" + +/* 8-bit I2C address */ +#define LP5562_I2C_ADDR (0x30 << 1) + +inline int lp5562_write(uint8_t reg, uint8_t val) +{ + return i2c_write8(I2C_PORT_HOST, LP5562_I2C_ADDR, reg, val); +} + +int lp5562_set_color(uint8_t red, uint8_t green, uint8_t blue) +{ + int ret = 0; + + ret |= lp5562_write(LP5562_REG_B_PWM, blue); + ret |= lp5562_write(LP5562_REG_G_PWM, green); + ret |= lp5562_write(LP5562_REG_R_PWM, red); + + return ret; +} + +int lp5562_poweron(void) +{ + int ret = 0; + + ret |= lp5562_write(LP5562_REG_ENABLE, 0x40); + udelay(500); /* start-up delay */ + + ret |= lp5562_write(LP5562_REG_CONFIG, 0x1); + ret |= lp5562_write(LP5562_REG_LED_MAP, 0x0); + + return ret; +} + +int lp5562_poweroff(void) +{ + return lp5562_write(LP5562_REG_ENABLE, 0x0); +} + +/*****************************************************************************/ +/* Console commands */ + +static int command_lp5562(int argc, char **argv) +{ + if (argc == 4) { + char *e; + uint8_t red, green, blue; + + red = strtoi(argv[1], &e, 0); + if (e && *e) + return EC_ERROR_PARAM1; + green = strtoi(argv[2], &e, 0); + if (e && *e) + return EC_ERROR_PARAM2; + blue = strtoi(argv[3], &e, 0); + if (e && *e) + return EC_ERROR_PARAM3; + + return lp5562_set_color(red, green, blue); + } else if (argc == 2) { + if (!strcasecmp(argv[1], "on")) + return lp5562_poweron(); + else if (!strcasecmp(argv[1], "off")) + return lp5562_poweroff(); + return EC_ERROR_PARAM1; + } + + return EC_ERROR_INVAL; +} +DECLARE_CONSOLE_COMMAND(lp5562, command_lp5562, + "on | off | <red> <green> <blue>", + "Set the color of the LED", + NULL); diff --git a/include/lp5562.h b/include/lp5562.h new file mode 100644 index 0000000000..5e848ec9ac --- /dev/null +++ b/include/lp5562.h @@ -0,0 +1,38 @@ +/* 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. + * + * TI LP5562 LED driver. + */ + +#ifndef LP5562_H +#define LP5562_H + +#define LP5562_REG_ENABLE 0x00 +#define LP5562_REG_OP_MODE 0x01 +#define LP5562_REG_B_PWM 0x02 +#define LP5562_REG_G_PWM 0x03 +#define LP5562_REG_R_PWM 0x04 +#define LP5562_REG_B_CURRENT 0x05 +#define LP5562_REG_G_CURRENT 0x06 +#define LP5562_REG_R_CURRENT 0x07 +#define LP5562_REG_CONFIG 0x08 +#define LP5562_REG_ENG1_PC 0x09 +#define LP5562_REG_ENG2_PC 0x0a +#define LP5562_REG_ENG3_PC 0x0b +#define LP5562_REG_STATUS 0x0c +#define LP5562_REG_RESET 0x0d +#define LP5562_REG_W_PWM 0x0e +#define LP5562_REG_W_CURRENT 0x0f +#define LP5562_REG_LED_MAP 0x70 + +/* Power on and initialize LP5562. */ +int lp5562_poweron(void); + +/* Power off LP5562. */ +int lp5562_poweroff(void); + +/* Set LED color. */ +int lp5562_set_color(uint8_t red, uint8_t green, uint8_t blue); + +#endif /* LP5562_H */ |