diff options
author | Yilun Lin <yllin@google.com> | 2018-07-11 12:45:34 +0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-07-11 05:24:12 -0700 |
commit | b2fbe4c24610fda7314361c2efab31c7ae7aca8a (patch) | |
tree | c5de802f3ffb5a52a610248d043ded8f07cc8149 /driver/charger | |
parent | 58ee1a67118bf138ab0ac0100982d9639a9c6e21 (diff) | |
download | chrome-ec-b2fbe4c24610fda7314361c2efab31c7ae7aca8a.tar.gz |
charger/mt6370: Support RGB LED.
TEST=test on EVB, and checks the led blinks accordingly.
BUG=b:80160408
BRANCH=none
Change-Id: Id0a06f51fd6369daa42e080af5e705321b93c732
Signed-off-by: Yilun Lin <yllin@google.com>
Reviewed-on: https://chromium-review.googlesource.com/1132723
Commit-Ready: Yilun Lin <yllin@chromium.org>
Tested-by: Yilun Lin <yllin@chromium.org>
Reviewed-by: Nicolas Boichat <drinkcat@chromium.org>
Diffstat (limited to 'driver/charger')
-rw-r--r-- | driver/charger/rt946x.c | 66 | ||||
-rw-r--r-- | driver/charger/rt946x.h | 90 |
2 files changed, 156 insertions, 0 deletions
diff --git a/driver/charger/rt946x.c b/driver/charger/rt946x.c index f14ad97a27..d7dcbf82a6 100644 --- a/driver/charger/rt946x.c +++ b/driver/charger/rt946x.c @@ -981,3 +981,69 @@ int rt946x_enable_charge_termination(int en) return (en ? rt946x_set_bit : rt946x_clr_bit) (RT946X_REG_CHGCTRL2, RT946X_MASK_TE); } + +#ifdef CONFIG_CHARGER_MT6370 +/* MT6370 RGB LED */ + +int mt6370_led_set_dim_mode(enum mt6370_led_index index, + enum mt6370_led_dim_mode mode) +{ + if (index <= MT6370_LED_ID_OFF || index >= MT6370_LED_ID_COUNT) + return EC_ERROR_INVAL; + + rt946x_update_bits(MT6370_REG_RGBDIM_BASE + index, + MT6370_MASK_RGB_DIMMODE, + mode << MT6370_SHIFT_RGB_DIMMODE); + return EC_SUCCESS; +} + +int mt6370_led_set_color(enum mt6370_led_index index) +{ + int val; + + if (index >= MT6370_LED_ID_COUNT) + return EC_ERROR_INVAL; + + if (index == MT6370_LED_ID_OFF) + val = 0; + else + val = 1 << (MT6370_SHIFT_RGB_ISNKDIM_BASE + index); + + rt946x_update_bits(MT6370_REG_RGBEN, MT6370_MASK_RGB_ISNK_ALL_EN, val); + return EC_SUCCESS; +} + +int mt6370_led_set_brightness(enum mt6370_led_index index, uint8_t brightness) +{ + if (index >= MT6370_LED_ID_COUNT || index <= MT6370_LED_ID_OFF) + return EC_ERROR_INVAL; + + rt946x_update_bits(MT6370_REG_RGBISNK_BASE + index, + MT6370_MASK_RGBISNK_CURSEL, + brightness << MT6370_SHIFT_RGBISNK_CURSEL); + return EC_SUCCESS; +} + +int mt6370_led_set_pwm_dim_duty(enum mt6370_led_index index, uint8_t dim_duty) +{ + if (index >= MT6370_LED_ID_COUNT || index <= MT6370_LED_ID_OFF) + return EC_ERROR_INVAL; + + rt946x_update_bits(MT6370_REG_RGBDIM_BASE + index, + MT6370_MASK_RGB_DIMDUTY, + dim_duty << MT6370_SHIFT_RGB_DIMDUTY); + return EC_SUCCESS; +} + +int mt6370_led_set_pwm_frequency(enum mt6370_led_index index, + enum mt6370_led_pwm_freq freq) +{ + if (index >= MT6370_LED_ID_COUNT || index <= MT6370_LED_ID_OFF) + return EC_ERROR_INVAL; + + rt946x_update_bits(MT6370_REG_RGBISNK_BASE + index, + MT6370_MASK_RGBISNK_DIMFSEL, + freq << MT6370_SHIFT_RGBISNK_DIMFSEL); + return EC_SUCCESS; +} +#endif diff --git a/driver/charger/rt946x.h b/driver/charger/rt946x.h index 9ff4eaad10..69e7b8b6af 100644 --- a/driver/charger/rt946x.h +++ b/driver/charger/rt946x.h @@ -118,6 +118,19 @@ #define RT946X_REG_CHGNTC 0X4B #define RT946X_REG_ADCDATAH 0X4C #define RT946X_REG_ADCDATAL 0X4D +/* RGB led */ +#define MT6370_REG_RGBDIM_BASE 0x81 +#define MT6370_REG_RGB1DIM 0x82 +#define MT6370_REG_RGB2DIM 0x83 +#define MT6370_REG_RGB3DIM 0x84 +#define MT6370_REG_RGBEN 0x85 +#define MT6370_REG_RGBISNK_BASE 0x85 +#define MT6370_REG_RGB1ISNK 0x86 +#define MT6370_REG_RGB2ISNK 0x87 +#define MT6370_REG_RGB3ISNK 0x88 +#define MT6370_REG_RGBCHRINDDIM 0x92 +#define MT6370_REG_RGBCHRINDCTRL 0x93 + #define RT946X_REG_DPDMIRQ 0xC6 /* status event */ #define MT6370_REG_CHGSTAT1 0xD0 @@ -366,6 +379,38 @@ #define RT946X_MASK_DPDMIRQ_ATTACH (1 << RT946X_SHIFT_DPDMIRQ_ATTACH) #endif +/* ========== RGBDIM 0x82/0x83/0x84 (mt6370) ============ */ +#define MT6370_LED_PWM_DIMDUTY_MIN 0x00 +#define MT6370_LED_PWM_DIMDUTY_MAX 0x1f + +#define MT6370_SHIFT_RGB_DIMMODE 5 +#define MT6370_SHIFT_RGB_DIMDUTY 0 + +#define MT6370_MASK_RGB_DIMMODE (3 << MT6370_SHIFT_RGB_DIMMODE) +#define MT6370_MASK_RGB_DIMDUTY (0x1f << MT6370_SHIFT_RGB_DIMDUTY) + +/* ========== RGBEN 0x85 (mt6370) ============ */ +#define MT6370_SHIFT_RGB_ISNK1DIM 7 +#define MT6370_SHIFT_RGB_ISNK2DIM 6 +#define MT6370_SHIFT_RGB_ISNK3DIM 5 +#define MT6370_SHIFT_RGB_ISNKDIM_BASE 4 + +#define MT6370_MASK_RGB_ISNK1DIM_EN (1 << MT6370_SHIFT_RGB_ISNK1DIM) +#define MT6370_MASK_RGB_ISNK2DIM_EN (1 << MT6370_SHIFT_RGB_ISNK2DIM) +#define MT6370_MASK_RGB_ISNK3DIM_EN (1 << MT6370_SHIFT_RGB_ISNK3DIM) +#define MT6370_MASK_RGB_ISNK_ALL_EN (MT6370_MASK_RGB_ISNK1DIM_EN | \ + MT6370_MASK_RGB_ISNK2DIM_EN | \ + MT6370_MASK_RGB_ISNK3DIM_EN) + +/* ========== RGB_ISNK 0x86/0x87/0x88 (mt6370) ============ */ +#define MT6370_LED_BRIGHTNESS_MIN 0 +#define MT6370_LED_BRIGHTNESS_MAX 7 + +#define MT6370_SHIFT_RGBISNK_CURSEL 0 +#define MT6370_SHIFT_RGBISNK_DIMFSEL 3 +#define MT6370_MASK_RGBISNK_CURSEL (0x7 << MT6370_SHIFT_RGBISNK_CURSEL) +#define MT6370_MASK_RGBISNK_DIMFSEL (0x7 << MT6370_SHIFT_RGBISNK_DIMFSEL) + /* ========== CHGSTAT2 0xD1 (mt6370) ============ */ #ifdef CONFIG_CHARGER_MT6370 #define MT6370_SHIFT_CHG_VBUSOV_STAT 7 @@ -420,4 +465,49 @@ int rt946x_cutoff_battery(void); /* Enable/Disable charge temination */ int rt946x_enable_charge_termination(int en); +#ifdef CONFIG_CHARGER_MT6370 + +enum mt6370_led_index { + MT6370_LED_ID_OFF = 0, + MT6370_LED_ID1 = 1, + MT6370_LED_ID2 = 2, + MT6370_LED_ID3 = 3, + MT6370_LED_ID_COUNT, /* The bound of the ID indexes. */ +}; + +enum mt6370_led_dim_mode { + MT6370_LED_DIM_MODE_PWM = 0, + MT6370_LED_DIM_MODE_BREATH = 1, + MT6370_LED_DIM_MODE_REGISTER = 3 +}; + +enum mt6370_led_pwm_freq { + MT6370_LED_PWM_FREQ01 = 0, /* 0.1 Hz */ + MT6370_LED_PWM_FREQ02 = 1, /* 0.2 Hz */ + MT6370_LED_PWM_FREQ05 = 2, /* 0.5 Hz */ + MT6370_LED_PWM_FREQ1 = 3, /* 1 Hz */ + MT6370_LED_PWM_FREQ2 = 4, /* 2 Hz */ + MT6370_LED_PWM_FREQ5 = 5, /* 5 Hz */ + MT6370_LED_PWM_FREQ200 = 6, /* 200 Hz */ + MT6370_LED_PWM_FREQ1000 = 7 /* 1000 Hz */ +}; + +/* Set LED brightness */ +int mt6370_led_set_brightness(enum mt6370_led_index index, uint8_t brightness); + +/* Set LED Color */ +int mt6370_led_set_color(enum mt6370_led_index index); + +/* Set LED dim mode, available modes: REGISTER, PWM, BREATH. */ +int mt6370_led_set_dim_mode(enum mt6370_led_index index, + enum mt6370_led_dim_mode mode); + +/* Set LED PWM mode duty */ +int mt6370_led_set_pwm_dim_duty(enum mt6370_led_index index, uint8_t dim_duty); + +/* Set LED PWM mode frequency */ +int mt6370_led_set_pwm_frequency(enum mt6370_led_index index, + enum mt6370_led_pwm_freq freq); +#endif + #endif /* __CROS_EC_RT946X_H */ |