diff options
author | YB.Ha <ybha@samsung.com> | 2017-11-13 15:56:01 +0900 |
---|---|---|
committer | ChromeOS Commit Bot <chromeos-commit-bot@chromium.org> | 2017-12-08 03:09:43 +0000 |
commit | b7331af1fd77560b02e3f0b10b54d5517106721c (patch) | |
tree | d86e04e815cfc8f32c8985514e9926f2d8abef87 | |
parent | 38f86e93b38e42bd5af6a05e664469df10cdfe34 (diff) | |
download | chrome-ec-b7331af1fd77560b02e3f0b10b54d5517106721c.tar.gz |
caroline : Add EL lamp driver & control keyboard backlight.
- Add MAXIM Max14521 EL lamp driver
- Add commands & hooks to control keyboard backlight
BRANCH=firmware-glados-7820.B
BUG=b:68022216
TEST=emerge-caroline chromeos-ec ec-utils
Signed-off-by: yb.ha <ybha@samsung.com>
Change-Id: I3f3dae16e3dae2e11ea391cd74a804bcefec2181
Reviewed-on: https://chromium-review.googlesource.com/765624
Tested-by: YongBeum Ha <ybha@samsung.com>
Commit-Queue: YongBeum Ha <ybha@samsung.com>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
-rw-r--r-- | board/caroline/board.c | 22 | ||||
-rw-r--r-- | board/caroline/board.h | 11 | ||||
-rw-r--r-- | board/caroline/gpio.inc | 2 | ||||
-rw-r--r-- | common/pwm_kblight.c | 2 | ||||
-rw-r--r-- | driver/build.mk | 3 | ||||
-rw-r--r-- | driver/kbl_max14521.c | 138 | ||||
-rw-r--r-- | driver/kbl_max14521.h | 13 | ||||
-rw-r--r-- | include/config.h | 3 |
8 files changed, 194 insertions, 0 deletions
diff --git a/board/caroline/board.c b/board/caroline/board.c index ec28ce6133..e658259d02 100644 --- a/board/caroline/board.c +++ b/board/caroline/board.c @@ -15,6 +15,7 @@ #include "console.h" #include "driver/accel_bma2x2.h" #include "driver/accelgyro_bmi160.h" +#include "driver/kbl_max14521.h" #include "extpower.h" #include "gpio.h" #include "hooks.h" @@ -692,3 +693,24 @@ void chipset_set_pmic_slp_sus_l(int level) previous_level = level; } } + +/* + * Control KBLIGHT + */ +/*****************************************************************************/ +/* Hooks */ + +static void kblight_enable(void) +{ + gpio_set_level(GPIO_KBDBKLIT_RST_L, 1); + msleep(10); + max14521_init(); +} +DECLARE_HOOK(HOOK_CHIPSET_RESUME, kblight_enable, HOOK_PRIO_DEFAULT); + +static void kblight_disable(void) +{ + gpio_set_level(GPIO_KBDBKLIT_RST_L, 0); +} +DECLARE_HOOK(HOOK_CHIPSET_SUSPEND, kblight_disable, HOOK_PRIO_DEFAULT); +DECLARE_HOOK(HOOK_CHIPSET_SHUTDOWN, kblight_disable, HOOK_PRIO_DEFAULT); diff --git a/board/caroline/board.h b/board/caroline/board.h index aa4e91e37e..364d884f8f 100644 --- a/board/caroline/board.h +++ b/board/caroline/board.h @@ -61,6 +61,7 @@ #define CONFIG_HOSTCMD_PD #define CONFIG_I2C #define CONFIG_I2C_MASTER +#define CONFIG_KBLIGHT_MAX14521 #define CONFIG_KEYBOARD_COL2_INVERTED #define CONFIG_KEYBOARD_PROTOCOL_8042 #define CONFIG_LED_COMMON @@ -72,6 +73,9 @@ #define CONFIG_POWER_COMMON #define CONFIG_POWER_S0IX #define CONFIG_POWER_SIGNAL_INTERRUPT_STORM_DETECT_THRESHOLD 30 +#undef CONFIG_PWM +#define CONFIG_PWM_KBLIGHT +#define CONFIG_PWM_KBLIGHT_CHIP /* All data won't fit in data RAM. So, moving boundary slightly. */ #undef CONFIG_RO_SIZE #define CONFIG_RO_SIZE (104 * 1024) @@ -132,6 +136,7 @@ /* I2C ports */ #define I2C_PORT_PMIC MEC1322_I2C0_0 +#define I2C_PORT_KBLIGHT MEC1322_I2C0_0 #define I2C_PORT_USB_CHARGER_1 MEC1322_I2C0_1 #define I2C_PORT_USB_MUX MEC1322_I2C0_1 #define I2C_PORT_USB_CHARGER_2 MEC1322_I2C0_0 @@ -224,6 +229,12 @@ enum sensor_id { BASE_GYRO, }; +enum pwm_channel { + PWM_CH_KBLIGHT, + /* Number of PWM channels */ + PWM_CH_COUNT, +}; + enum temp_sensor_id { TEMP_SENSOR_BATTERY, diff --git a/board/caroline/gpio.inc b/board/caroline/gpio.inc index f1f9efdfb2..2b28b693e6 100644 --- a/board/caroline/gpio.inc +++ b/board/caroline/gpio.inc @@ -99,6 +99,8 @@ GPIO(PP1800_DX_AUDIO_EN, PIN(141), GPIO_OUT_LOW) GPIO(PCH_RTCRST, PIN(163), GPIO_OUT_LOW) GPIO(PMIC_SLP_SUS_L, PIN(201), GPIO_OUT_LOW) +GPIO(KBDBKLIT_RST_L, PIN(34), GPIO_OUT_LOW) + /* Alternate functions GPIO definitions */ /* GPIO162(UART_RX), GPIO165(UART_TX) */ diff --git a/common/pwm_kblight.c b/common/pwm_kblight.c index 15a2feb2bc..26030f2dc4 100644 --- a/common/pwm_kblight.c +++ b/common/pwm_kblight.c @@ -73,6 +73,7 @@ DECLARE_HOST_COMMAND(EC_CMD_PWM_SET_KEYBOARD_BACKLIGHT, pwm_command_set_keyboard_backlight, EC_VER_MASK(0)); +#ifndef CONFIG_PWM_KBLIGHT_CHIP /*****************************************************************************/ /* Hooks */ @@ -124,3 +125,4 @@ static void pwm_kblight_lid_change(void) pwm_enable(PWM_CH_KBLIGHT, lid_is_open()); } DECLARE_HOOK(HOOK_LID_CHANGE, pwm_kblight_lid_change, HOOK_PRIO_DEFAULT); +#endif diff --git a/driver/build.mk b/driver/build.mk index 71a49af52d..c06bbf5a16 100644 --- a/driver/build.mk +++ b/driver/build.mk @@ -22,6 +22,9 @@ driver-$(CONFIG_ALS_ISL29035)+=als_isl29035.o driver-$(CONFIG_ALS_OPT3001)+=als_opt3001.o driver-$(CONFIG_ALS_SI114X)+=als_si114x.o +#Keyboard Backlight +driver-$(CONFIG_KBLIGHT_MAX14521)+=kbl_max14521.o + # Batteries driver-$(CONFIG_BATTERY_BQ20Z453)+=battery/bq20z453.o driver-$(CONFIG_BATTERY_BQ27541)+=battery/bq27541.o diff --git a/driver/kbl_max14521.c b/driver/kbl_max14521.c new file mode 100644 index 0000000000..f510fb6b54 --- /dev/null +++ b/driver/kbl_max14521.c @@ -0,0 +1,138 @@ +/* Copyright (c) 2017 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. + * + * Maxim MAX14521 EL lamp driver + */ + +#include "common.h" +#include "console.h" +#include "driver/kbl_max14521.h" +#include "hooks.h" +#include "host_command.h" +#include "i2c.h" +#include "lid_switch.h" +#include "pwm.h" +#include "system.h" +#include "util.h" + + +/* I2C interface */ +#define MAX14521_I2C_ADDR 0xF0 +#define MAX14521_REG_DEV_ID 0x00 +#define MAX14251_DEVICE_ID 0xB2 +#define MAX14521_REG_PWR_MODE 0x01 +#define MAX14521_REG_EL_FREQ 0x02 +#define MAX14521_REG_EL_SHAPE 0x03 +#define MAX14521_REG_BST_FREQ 0x04 +#define MAX14521_REG_AUDIO 0x05 +#define MAX14521_REG_EL1_T_V 0x06 +#define MAX14521_REG_EL2_T_V 0x07 +#define MAX14521_REG_EL3_T_V 0x08 +#define MAX14521_REG_EL4_T_V 0x09 +#define MAX14521_REG_EL_UPDATE 0x0A + +#define MAX14521_PWR_MODE_EN 0x01 +#define MAX14521_PWR_MODE_DIS 0x00 +#define MAX14521_BST_FREQ_1KHZ 0x04 +#define MAX14521_EL_FREQ_180HZ 0x73 +/* Ramping Time Configuration : 2 seconds */ +#define MAX14521_RT_2SEC (0x07 << 5) + +#define MAX14521_VSTEP_MAX 31 +static int curr_percent; +static int g_pwm_duty; + +static int max14521_set_kblight(int percent) +{ + int rv, step; + + if(percent == 0) { + curr_percent = 0; + + return i2c_write8(I2C_PORT_KBLIGHT, MAX14521_I2C_ADDR, + MAX14521_REG_PWR_MODE, MAX14521_PWR_MODE_DIS); + } + + if(percent < 0) + return EC_ERROR_PARAM1; + + if(percent > 100) + return EC_ERROR_PARAM1; + + step = (percent * (MAX14521_VSTEP_MAX - 1)) / 100 + 1; + + if(curr_percent == 0) { + rv = i2c_write8(I2C_PORT_KBLIGHT, MAX14521_I2C_ADDR, + MAX14521_REG_PWR_MODE, MAX14521_PWR_MODE_EN); + + if(rv) + return rv; + } + + /* Write ramping time and voltage */ + rv = i2c_write8(I2C_PORT_KBLIGHT, MAX14521_I2C_ADDR, + MAX14521_REG_EL1_T_V, MAX14521_RT_2SEC | step); + + if(rv) + return rv; + + /* It is needed that write update register to change output level of EL.*/ + rv = i2c_write8(I2C_PORT_KBLIGHT, MAX14521_I2C_ADDR, + MAX14521_REG_EL_UPDATE, MAX14521_RT_2SEC | step); + + if(rv) + return rv; + + curr_percent = percent; + + return EC_SUCCESS; +} + +int max14521_init(void) +{ + int rv; + + rv = i2c_write8(I2C_PORT_KBLIGHT, MAX14521_I2C_ADDR, + MAX14521_REG_BST_FREQ, MAX14521_BST_FREQ_1KHZ); + + if(rv) + return rv; + + rv = i2c_write8(I2C_PORT_KBLIGHT, MAX14521_I2C_ADDR, + MAX14521_REG_EL_FREQ, MAX14521_EL_FREQ_180HZ); + + if(rv) + return rv; + + return max14521_set_kblight(0); +} + +static int max14521_get_kblight(void) +{ + return curr_percent; +} + +/*****************************************************************************/ +/* Commands to control keyboard backlight by ACPI */ +static void update_kblight(void) +{ + max14521_set_kblight(g_pwm_duty); +} +DECLARE_DEFERRED(update_kblight); + +int pwm_get_duty(enum pwm_channel ch) +{ + return max14521_get_kblight(); +} + +void pwm_set_duty(enum pwm_channel ch, int data) +{ + g_pwm_duty = data; + hook_call_deferred(update_kblight, 0); +} + +int pwm_get_enabled(enum pwm_channel ch) +{ + return (curr_percent != 0); +} diff --git a/driver/kbl_max14521.h b/driver/kbl_max14521.h new file mode 100644 index 0000000000..e31759572a --- /dev/null +++ b/driver/kbl_max14521.h @@ -0,0 +1,13 @@ +/* Copyright 2017 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. + * + * MAXIM MAX14521 EL lamp driver + */ + +#ifndef __CROS_EC_KBLIGHT_MAX14521_H +#define __CROS_EC_KBLIGHT_MAX14521_H + +int max14521_init(void); + +#endif /* __CROS_EC_KBLIGHT_MAX14521_H */ diff --git a/include/config.h b/include/config.h index aaf2b6c7ca..9bf23c4ac3 100644 --- a/include/config.h +++ b/include/config.h @@ -1571,6 +1571,9 @@ /* Support PWM output to keyboard backlight */ #undef CONFIG_PWM_KBLIGHT +/* The keyboard backlight PWM is implemented in an external chip */ +#undef CONFIG_PWM_KBLIGHT_CHIP + /* Base address of RAM for the chip */ #undef CONFIG_RAM_BASE |