diff options
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; |