diff options
author | Ting Shen <phoenixshen@google.com> | 2020-05-15 19:41:21 +0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-07-02 11:03:14 +0000 |
commit | 12489f5be5d1c0867c83ebcfa97773edafd60259 (patch) | |
tree | 08dd773b276539bd2be1d24186b29dd8aa4c6b83 /driver | |
parent | fc5f9662cd4ad5bd6fe69226e2034d512c78e1b2 (diff) | |
download | chrome-ec-12489f5be5d1c0867c83ebcfa97773edafd60259.tar.gz |
mt6360: implement led driver
BUG=b:151802370
TEST=with CL:2203474, see led lit
BRANCH=master
Signed-off-by: Ting Shen <phoenixshen@google.com>
Change-Id: If64a851377f93aea125b7402a3f4afb771abe6e7
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2203473
Reviewed-by: Eric Yilun Lin <yllin@chromium.org>
Tested-by: Ting Shen <phoenixshen@chromium.org>
Commit-Queue: Ting Shen <phoenixshen@chromium.org>
Diffstat (limited to 'driver')
-rw-r--r-- | driver/bc12/mt6360.c | 29 | ||||
-rw-r--r-- | driver/bc12/mt6360.h | 19 |
2 files changed, 48 insertions, 0 deletions
diff --git a/driver/bc12/mt6360.c b/driver/bc12/mt6360.c index 4f0dbc4cf6..418d3f9b61 100644 --- a/driver/bc12/mt6360.c +++ b/driver/bc12/mt6360.c @@ -13,6 +13,7 @@ #include "timer.h" #include "usb_charge.h" #include "usb_pd.h" +#include "util.h" /* Console output macros */ #define CPRINTF(format, args...) cprintf(CC_CHARGER, format, ## args) @@ -160,6 +161,34 @@ static void mt6360_usb_charger_task(const int port) } } +/* RGB LED */ +int mt6360_led_enable(enum mt6360_led_id led_id, int enable) +{ + if (!IN_RANGE(led_id, 0, MT6360_LED_COUNT)) + return EC_ERROR_INVAL; + + if (enable) + return mt6360_set_bit(MT6360_REG_RGB_EN, + MT6360_MASK_ISINK_EN(led_id)); + return mt6360_clr_bit(MT6360_REG_RGB_EN, MT6360_MASK_ISINK_EN(led_id)); +} + +int mt6360_led_set_brightness(enum mt6360_led_id led_id, int brightness) +{ + int val; + + if (!IN_RANGE(led_id, 0, MT6360_LED_COUNT)) + return EC_ERROR_INVAL; + if (!IN_RANGE(brightness, 0, 16)) + return EC_ERROR_INVAL; + + RETURN_ERROR(mt6360_read8(MT6360_REG_RGB_ISINK(led_id), &val)); + val &= ~MT6360_MASK_CUR_SEL; + val |= brightness; + + return mt6360_write8(MT6360_REG_RGB_ISINK(led_id), val); +} + const struct bc12_drv mt6360_drv = { .usb_charger_task = mt6360_usb_charger_task, }; diff --git a/driver/bc12/mt6360.h b/driver/bc12/mt6360.h index 1b01f490cb..330b85337f 100644 --- a/driver/bc12/mt6360.h +++ b/driver/bc12/mt6360.h @@ -21,6 +21,12 @@ #define MT6360_MASK_DCP 0x40 #define MT6360_MASK_CDP 0x50 +#define MT6360_REG_RGB_EN 0x80 +#define MT6360_MASK_ISINK_EN(x) BIT(7 - (x)) + +#define MT6360_REG_RGB_ISINK(x) (0x81 + (x)) +#define MT6360_MASK_CUR_SEL 0xF + #define MT6360_REG_DPDMIRQ 0xD6 #define MT6360_MASK_DPDMIRQ_ATTACH BIT(0) #define MT6360_MASK_DPDMIRQ_DETACH BIT(1) @@ -28,11 +34,24 @@ #define MT6360_REG_DPDM_MASK1 0xF6 #define MT6360_REG_DPDM_MASK1_CHGDET_DONEI_M BIT(0) +enum mt6360_led_id { + MT6360_LED_RGB1, + MT6360_LED_RGB2, + MT6360_LED_RGB3, + MT6360_LED_RGB_ML, + + MT6360_LED_COUNT, +}; + struct mt6360_config_t { int i2c_port; int i2c_addr_flags; }; +int mt6360_led_enable(enum mt6360_led_id led_id, int enable); + +int mt6360_led_set_brightness(enum mt6360_led_id led_id, int brightness); + extern const struct mt6360_config_t mt6360_config; extern const struct bc12_drv mt6360_drv; |