diff options
author | Daisuke Nojiri <dnojiri@chromium.org> | 2018-05-08 14:45:55 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-05-11 12:10:44 -0700 |
commit | 94b4c511a6a5f185bce14d30731f165c4c48d752 (patch) | |
tree | 1b26f85d80991d24cf22eb5e123796dd3d48c3cf /driver/led | |
parent | f21a0681c78e67ccc11f350dc3a455360fc765fb (diff) | |
download | chrome-ec-94b4c511a6a5f185bce14d30731f165c4c48d752.tar.gz |
kblight: Add keyboard backlight control module
This patch promotes board/nami/keyboard_backlight.c to common
directory.
Board customization is done via board_kblight_init callback.
It currently supports two drivers: direct PWM control and lm3509.
Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org>
BUG=b:78360907,b:78141647
BRANCH=none
TEST=On Nami (for lm3509) and Sona (pwm), verify the followings:
1. Alt + brightness up/down works
2. After suspend-resume, brightness is restored
3. Lid close/open
4. After screen is off, keyboard backlight is turned off
Change-Id: I584c06e8702fe7b289999698f277311cfd3400bd
Reviewed-on: https://chromium-review.googlesource.com/1051027
Commit-Ready: Daisuke Nojiri <dnojiri@chromium.org>
Tested-by: Daisuke Nojiri <dnojiri@chromium.org>
Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
Diffstat (limited to 'driver/led')
-rw-r--r-- | driver/led/lm3509.c | 22 | ||||
-rw-r--r-- | driver/led/lm3509.h | 24 |
2 files changed, 18 insertions, 28 deletions
diff --git a/driver/led/lm3509.c b/driver/led/lm3509.c index 58838e2bbe..4f5a911da4 100644 --- a/driver/led/lm3509.c +++ b/driver/led/lm3509.c @@ -7,6 +7,7 @@ #include "compile_time_macros.h" #include "i2c.h" +#include "keyboard_backlight.h" #include "lm3509.h" inline int lm3509_write(uint8_t reg, uint8_t val) @@ -44,7 +45,7 @@ static int brightness_to_bmain(int percent) return i - 1; } -int lm3509_power(int enable) +static int lm3509_power(int enable) { int ret = 0; uint8_t gp = 0, bmain = 0; @@ -71,7 +72,7 @@ int lm3509_power(int enable) return ret; } -int lm3509_set_brightness(int percent) +static int lm3509_set_brightness(int percent) { /* We don't need to read/mask/write BMAIN because bit6 and 7 are non * functional read only bits. @@ -79,13 +80,24 @@ int lm3509_set_brightness(int percent) return lm3509_write(LM3509_REG_BMAIN, brightness_to_bmain(percent)); } -int lm3509_get_brightness(int *percent) +static int lm3509_get_brightness(void) { int rv, val; rv = lm3509_read(LM3509_REG_BMAIN, &val); if (rv) - return rv; + return -1; val &= LM3509_BMAIN_MASK; - *percent = lm3509_brightness[val] / 10; + return lm3509_brightness[val] / 10; +} + +static int lm3509_init(void) +{ return EC_SUCCESS; } + +const struct kblight_drv kblight_lm3509 = { + .init = lm3509_init, + .set = lm3509_set_brightness, + .get = lm3509_get_brightness, + .enable = lm3509_power, +}; diff --git a/driver/led/lm3509.h b/driver/led/lm3509.h index 12ca480562..f1fbd6b3d4 100644 --- a/driver/led/lm3509.h +++ b/driver/led/lm3509.h @@ -17,28 +17,6 @@ #define LM3509_BMAIN_MASK 0x1F -/** - * Power on/off and initialize LM3509. - * - * @param enable: 1 to enable or 0 to disable. - * @return EC_SUCCESS or EC_ERROR_* on error. - */ -int lm3509_power(int enable); - -/** - * Set brightness level - * - * @param percent: Brightness level: 0 - 100% - * @return EC_SUCCESS or EC_ERROR_* on error. - */ -int lm3509_set_brightness(int percent); - -/** - * Get current brightness level - * - * @param percent: Current brightness level. - * @return EC_SUCCESS or EC_ERROR_* on error. - */ -int lm3509_get_brightness(int *percent); +extern const struct kblight_drv kblight_lm3509; #endif /* __CROS_EC_LM3509_H */ |