diff options
Diffstat (limited to 'board/spring/usb_charging.c')
-rw-r--r-- | board/spring/usb_charging.c | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/board/spring/usb_charging.c b/board/spring/usb_charging.c index d10f1cfa6e..e4d9a362fd 100644 --- a/board/spring/usb_charging.c +++ b/board/spring/usb_charging.c @@ -9,10 +9,17 @@ #include "console.h" #include "gpio.h" #include "registers.h" +#include "task.h" +#include "timer.h" +#include "tsu6721.h" #include "util.h" #define PWM_FREQUENCY 100 /* Hz */ +/* Console output macros */ +#define CPUTS(outstr) cputs(CC_USBCHARGE, outstr) +#define CPRINTF(format, args...) cprintf(CC_USBCHARGE, format, ## args) + static enum ilim_config current_ilim_config = ILIM_CONFIG_MANUAL_OFF; static void board_ilim_use_gpio(void) @@ -99,6 +106,56 @@ void board_pwm_duty_cycle(int percent) STM32_TIM_CCR1(3) = (percent * STM32_TIM_ARR(3)) / 100; } +void usb_charge_interrupt(enum gpio_signal signal) +{ + task_wake(TASK_ID_PMU_TPS65090_CHARGER); +} + +static void usb_device_change(int dev_type) +{ + static int last_dev_type; + + if (last_dev_type == dev_type) + return; + last_dev_type = dev_type; + + CPRINTF("[%T USB Attached: "); + if (dev_type == TSU6721_TYPE_NONE) + CPRINTF("Nothing]\n"); + else if (dev_type & TSU6721_TYPE_OTG) + CPRINTF("OTG]\n"); + else if (dev_type & TSU6721_TYPE_USB_HOST) + CPRINTF("USB Host]\n"); + else if (dev_type & TSU6721_TYPE_CHG12) + CPRINTF("Type 1/2 Charger]\n"); + else if (dev_type & TSU6721_TYPE_NON_STD_CHG) + CPRINTF("Non standard charger]\n"); + else if (dev_type & TSU6721_TYPE_DCP) + CPRINTF("DCP]\n"); + else if (dev_type & TSU6721_TYPE_CDP) + CPRINTF("CDP]\n"); + else if (dev_type & TSU6721_TYPE_U200_CHG) + CPRINTF("U200]\n"); + else if (dev_type & TSU6721_TYPE_APPLE_CHG) + CPRINTF("Apple charger]\n"); + else if (dev_type & TSU6721_TYPE_JIG_UART_ON) + CPRINTF("JIG UART ON]\n"); + else if (dev_type & TSU6721_TYPE_VBUS_DEBOUNCED) + CPRINTF("Unknown with power]\n"); + else + CPRINTF("Unknown]\n"); +} + +void board_usb_charge_update(void) +{ + int int_val = tsu6721_get_interrupts(); + + if (int_val & TSU6721_INT_DETACH) + usb_device_change(TSU6721_TYPE_NONE); + else if (int_val) + usb_device_change(tsu6721_get_device_type()); +} + /* * Console command for debugging. * TODO(victoryang): Remove after charging control is done. |