diff options
author | Elmo_Lan <elmo_lan@compal.corp-partner.google.com> | 2018-01-23 07:12:46 -0500 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-03-02 22:22:34 -0800 |
commit | 6790a884a46f18e858a6b308d3b00f86ef915e3f (patch) | |
tree | 4bf4cbcfd33118ccba1b66464c5af1d52b5d47df | |
parent | f32d92b7f5aa5e6951133bb7b893d264b1bb70e2 (diff) | |
download | chrome-ec-6790a884a46f18e858a6b308d3b00f86ef915e3f.tar.gz |
Nami: add keyboard backlight function
Base on LM3509 chip. Add file LM3509.C and LM3509.H
to control keyboard backlight when S0/LidOpen is turn on,
others is turn off.
BUG=b:73055990
BRANCH=none
TEST=Verify keyboard backlight function in resume and suspend.
S0/LidOpen is turn on; S4/S5/G3/LidClose is turn off.
Change-Id: Ief9e385f969c9dfc9e8f0d4e47ea7803cee747aa
Signed-off-by: Elmo_Lan <elmo_lan@compal.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/881081
Commit-Ready: Raymond Chou <raymond_chou@compal.corp-partner.google.com>
Tested-by: Elthan Huang <elthan_huang@compal.corp-partner.google.com>
Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
Reviewed-by: Elthan Huang <elthan_huang@compal.corp-partner.google.com>
-rw-r--r-- | board/nami/board.c | 14 | ||||
-rw-r--r-- | board/nami/board.h | 6 | ||||
-rw-r--r-- | driver/build.mk | 1 | ||||
-rw-r--r-- | driver/led/lm3509.c | 43 | ||||
-rw-r--r-- | driver/led/lm3509.h | 24 | ||||
-rw-r--r-- | include/config.h | 3 |
6 files changed, 88 insertions, 3 deletions
diff --git a/board/nami/board.c b/board/nami/board.c index 81241ef264..8bb9eef9d3 100644 --- a/board/nami/board.c +++ b/board/nami/board.c @@ -21,6 +21,7 @@ #include "driver/accel_bma2x2.h" #include "driver/als_opt3001.h" #include "driver/baro_bmp280.h" +#include "driver/led/lm3509.h" #include "driver/tcpm/ps8xxx.h" #include "driver/tcpm/tcpci.h" #include "driver/tcpm/tcpm.h" @@ -695,6 +696,8 @@ void lid_angle_peripheral_enable(int enable) static void board_chipset_resume(void) { gpio_set_level(GPIO_ENABLE_BACKLIGHT_L, 0); + if (lid_is_open()) + lm3509_poweron(); } DECLARE_HOOK(HOOK_CHIPSET_RESUME, board_chipset_resume, HOOK_PRIO_DEFAULT); @@ -702,5 +705,16 @@ DECLARE_HOOK(HOOK_CHIPSET_RESUME, board_chipset_resume, HOOK_PRIO_DEFAULT); static void board_chipset_suspend(void) { gpio_set_level(GPIO_ENABLE_BACKLIGHT_L, 1); + lm3509_poweroff(); } DECLARE_HOOK(HOOK_CHIPSET_SUSPEND, board_chipset_suspend, HOOK_PRIO_DEFAULT); + +/* Control keyboard backlight when Lid status change */ +static void lm3509_kblight_lid_change(void) +{ + if (lid_is_open()) + lm3509_poweron(); + else + lm3509_poweroff(); +} +DECLARE_HOOK(HOOK_LID_CHANGE, lm3509_kblight_lid_change, HOOK_PRIO_DEFAULT); diff --git a/board/nami/board.h b/board/nami/board.h index e88b7b0621..2d1d256c92 100644 --- a/board/nami/board.h +++ b/board/nami/board.h @@ -126,6 +126,9 @@ #define CONFIG_LID_ANGLE_TABLET_MODE #define CONFIG_LID_ANGLE_INVALID_CHECK +/* KB backlight driver */ +#define CONFIG_LED_DRIVER_LM3509 + /* FIFO size is in power of 2. */ #define CONFIG_ACCEL_FIFO 1024 @@ -176,12 +179,11 @@ #define I2C_PORT_BATTERY NPCX_I2C_PORT1 #define I2C_PORT_CHARGER NPCX_I2C_PORT1 #define I2C_PORT_PMIC NPCX_I2C_PORT2 -/* dnojiri: KB backlight */ +#define I2C_PORT_KBLIGHT NPCX_I2C_PORT2 #define I2C_PORT_GYRO NPCX_I2C_PORT3 #define I2C_PORT_ACCEL NPCX_I2C_PORT3 #define I2C_PORT_THERMAL NPCX_I2C_PORT3 #define I2C_PORT_ALS NPCX_I2C_PORT3 -/* dnojiri: ALS, G-sensor */ /* I2C addresses */ #define I2C_ADDR_MP2949 0x40 diff --git a/driver/build.mk b/driver/build.mk index a7eef9e948..597b055de9 100644 --- a/driver/build.mk +++ b/driver/build.mk @@ -67,6 +67,7 @@ driver-$(CONFIG_INA219)$(CONFIG_INA231)+=ina2xx.o # LED drivers driver-$(CONFIG_LED_DRIVER_DS2413)+=led/ds2413.o +driver-$(CONFIG_LED_DRIVER_LM3509)+=led/lm3509.o driver-$(CONFIG_LED_DRIVER_LM3630A)+=led/lm3630a.o driver-$(CONFIG_LED_DRIVER_LP5562)+=led/lp5562.o diff --git a/driver/led/lm3509.c b/driver/led/lm3509.c new file mode 100644 index 0000000000..463627a210 --- /dev/null +++ b/driver/led/lm3509.c @@ -0,0 +1,43 @@ +/* Copyright 2018 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 LM3509 LED driver. + */ + +#include "i2c.h" +#include "lm3509.h" + +inline int lm3509_write(uint8_t reg, uint8_t val) +{ + return i2c_write8(I2C_PORT_KBLIGHT, LM3509_I2C_ADDR, reg, val); +} + +int lm3509_poweron(void) +{ + int ret = 0; + + /* BIT= description + * [2]= set both main and seconfary current same, both control by BMAIN. + * [1]= enable secondary current sink. + * [0]= enable main current sink. + */ + ret |= lm3509_write(LM3509_REG_GP, 0x07); + /* Brigntness register + * 0x00= 0% + * 0x1F= 100% + */ + ret |= lm3509_write(LM3509_REG_BMAIN, 0x1F); + + return ret; +} + +int lm3509_poweroff(void) +{ + int ret = 0; + + ret |= lm3509_write(LM3509_REG_GP, 0x00); + ret |= lm3509_write(LM3509_REG_BMAIN, 0x00); + + return ret; +} diff --git a/driver/led/lm3509.h b/driver/led/lm3509.h new file mode 100644 index 0000000000..ca8c67edbf --- /dev/null +++ b/driver/led/lm3509.h @@ -0,0 +1,24 @@ +/* Copyright 2018 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 LM3509 LED driver. + */ + +#ifndef __CROS_EC_LM3509_H +#define __CROS_EC_LM3509_H + +/* 8-bit I2C address */ +#define LM3509_I2C_ADDR 0x6C + +#define LM3509_REG_GP 0x10 +#define LM3509_REG_BMAIN 0xA0 +#define LM3509_REG_BSUB 0xB0 + +/* Power on and initialize LM3509. */ +int lm3509_poweron(void); + +/* Power off LM3509. */ +int lm3509_poweroff(void); + +#endif /* __CROS_EC_LM3509_H */ diff --git a/include/config.h b/include/config.h index bdf40ec722..aff35fd164 100644 --- a/include/config.h +++ b/include/config.h @@ -803,7 +803,7 @@ #define CONFIG_CMD_INA #undef CONFIG_CMD_JUMPTAGS #define CONFIG_CMD_KEYBOARD -#undef CONFIG_CMD_LEDTEST +#undef CONFIG_CMD_LEDTEST #undef CONFIG_CMD_LID_ANGLE #undef CONFIG_CMD_MCDP #define CONFIG_CMD_MD @@ -1936,6 +1936,7 @@ /* Support for LED driver chip(s) */ #undef CONFIG_LED_DRIVER_DS2413 /* Maxim DS2413, on one-wire interface */ +#undef CONFIG_LED_DRIVER_LM3509 /* LM3509, on I2C interface */ #undef CONFIG_LED_DRIVER_LM3630A /* LM3630A, on I2C interface */ #undef CONFIG_LED_DRIVER_LP5562 /* LP5562, on I2C interface */ |