diff options
Diffstat (limited to 'driver/bc12/mt6360.c')
-rw-r--r-- | driver/bc12/mt6360.c | 29 |
1 files changed, 29 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, }; |