diff options
author | Vic Yang <victoryang@chromium.org> | 2013-05-20 15:17:17 +0800 |
---|---|---|
committer | ChromeBot <chrome-bot@google.com> | 2013-05-20 08:46:50 -0700 |
commit | 3438fcf2b81c2462b5cc2fe2c0e3933b22fcbd63 (patch) | |
tree | d489976510224f7557803abead806ddeb16c8edc | |
parent | fc4267054cb89397cca85efe83868615f6c9c562 (diff) | |
download | chrome-ec-3438fcf2b81c2462b5cc2fe2c0e3933b22fcbd63.tar.gz |
Revert "Monitor video detachment with ADC watchdog"
This reverts commit a041fe062a1122301fb0f5a7113b14dc8c33e782.
ADC watchdog is sourcing too much current onto ID_OUT net, and causes
voltage to rise by 0.4V. Let's revert this and use the monitoring loop.
BUG=chrome-os-partner:18397
TEST=Plug in the dongle and see kernel message about cable detect.
BRANCH=spring
Change-Id: I01d9cace1febc91140d302fe9572e6f0bbb8a036
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/55713
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
-rw-r--r-- | board/spring/usb_charging.c | 108 |
1 files changed, 38 insertions, 70 deletions
diff --git a/board/spring/usb_charging.c b/board/spring/usb_charging.c index f0c40ea403..f8f9717ba4 100644 --- a/board/spring/usb_charging.c +++ b/board/spring/usb_charging.c @@ -80,8 +80,7 @@ static int nominal_pwm_duty; static int current_pwm_duty; static int user_pwm_duty = -1; -static int pending_toad_redetect; -static int pending_video_detach; +static int pending_tsu6721_reset; static enum { LIMIT_NORMAL, @@ -91,7 +90,6 @@ static enum { static enum { ADC_WATCH_NONE, ADC_WATCH_TOAD, - ADC_WATCH_VIDEO, } current_watchdog = ADC_WATCH_NONE; struct { @@ -337,7 +335,7 @@ static int board_pwm_check_vbus_low(int vbus, int battery_current) return vbus < PWM_CTRL_VBUS_HARD_LOW && current_pwm_duty < 100; } -static void board_power_tweak(void) +static void board_pwm_tweak(void) { int vbus, current; int next; @@ -346,17 +344,6 @@ static void board_power_tweak(void) return; vbus = adc_read_channel(ADC_CH_USB_VBUS_SNS); - - /* Check video power input change */ - if (current_dev_type & TSU6721_TYPE_JIG_UART_ON) { - if (get_video_power() && vbus > 4000) { - set_video_power(0); - } else if (!get_video_power() && vbus <= 4000) { - board_pwm_duty_cycle(100); - set_video_power(1); - } - } - if (battery_current(¤t)) return; @@ -386,7 +373,7 @@ static void board_power_tweak(void) } } } -DECLARE_HOOK(HOOK_SECOND, board_power_tweak, HOOK_PRIO_DEFAULT); +DECLARE_HOOK(HOOK_SECOND, board_pwm_tweak, HOOK_PRIO_DEFAULT); void board_pwm_nominal_duty_cycle(int percent) { @@ -415,43 +402,13 @@ static void board_adc_watch_toad(void) current_watchdog = ADC_WATCH_TOAD; } -static void board_adc_watch_video(void) -{ - int retry_count = 10; - - /* - * Let DP_SNS voltage settle so that we don't trigger watchdog - * unintentionally. - */ - while (retry_count-- && - adc_read_channel(ADC_CH_USB_DP_SNS) > VIDEO_ID_THRESHOLD) - msleep(20); - - /* DP_SNS kept high. Assuming dongle detached already. */ - if (retry_count <= 0) { - pending_video_detach = 1; - return; - } - - /* - * Watch DP_SNS and interrupt if voltage goes above - * VIDEO_ID_THRESHOLD - */ - adc_enable_watchdog(STM32_AIN(2), VIDEO_ID_THRESHOLD * 4096 / 3300, 0); - task_clear_pending_irq(STM32_IRQ_ADC_1); - task_enable_irq(STM32_IRQ_ADC_1); - current_watchdog = ADC_WATCH_VIDEO; -} - - static void board_adc_watchdog_interrupt(void) { - if (current_watchdog == ADC_WATCH_TOAD) - pending_toad_redetect = 1; - else if (current_watchdog == ADC_WATCH_VIDEO) - pending_video_detach = 1; - task_disable_irq(STM32_IRQ_ADC_1); - task_wake(TASK_ID_PMU_TPS65090_CHARGER); + if (current_watchdog == ADC_WATCH_TOAD) { + pending_tsu6721_reset = 1; + task_disable_irq(STM32_IRQ_ADC_1); + task_wake(TASK_ID_PMU_TPS65090_CHARGER); + } } DECLARE_IRQ(STM32_IRQ_ADC_1, board_adc_watchdog_interrupt, 2); @@ -585,6 +542,7 @@ static void usb_log_dev_type(int dev_type) static void usb_device_change(int dev_type) { + if (current_dev_type == dev_type) return; @@ -610,8 +568,6 @@ static void usb_device_change(int dev_type) if ((dev_type & TOAD_DEVICE_TYPE) && (dev_type & TSU6721_TYPE_VBUS_DEBOUNCED)) board_adc_watch_toad(); - else if (dev_type & TSU6721_TYPE_JIG_UART_ON) - board_adc_watch_video(); usb_log_dev_type(dev_type); @@ -624,36 +580,48 @@ static void usb_device_change(int dev_type) enable_sleep(SLEEP_MASK_USB_PWR); } -void board_usb_charge_update(int force_update) +/* + * TODO(victoryang): Get rid of polling loop when ADC watchdog is ready. + * See crosbug.com/p/18171 + */ +static void board_usb_monitor_detach(void) { - int int_val = 0; - int want_reset = 0; + int vbus; - if (pending_video_detach || pending_toad_redetect) { - current_watchdog = ADC_WATCH_NONE; - adc_disable_watchdog(); - want_reset = 1; - } + if (!(current_dev_type & TSU6721_TYPE_JIG_UART_ON)) + return; - if (pending_video_detach) { + if (adc_read_channel(ADC_CH_USB_DP_SNS) > VIDEO_ID_THRESHOLD) { set_video_power(0); gpio_set_level(GPIO_ID_MUX, 0); msleep(DELAY_ID_MUX_MS); tsu6721_enable_interrupts(); + usb_device_change(TSU6721_TYPE_NONE); } - pending_video_detach = 0; - pending_toad_redetect = 0; - - if (!want_reset) { - int_val = tsu6721_get_interrupts(); - want_reset = (int_val & TSU6721_INT_DETACH); + /* Check if there is external power */ + vbus = adc_read_channel(ADC_CH_USB_VBUS_SNS); + if (get_video_power() && vbus > 4000) { + set_video_power(0); + } else if (!get_video_power() && vbus <= 4000) { + board_pwm_duty_cycle(100); + set_video_power(1); } +} +DECLARE_HOOK(HOOK_SECOND, board_usb_monitor_detach, HOOK_PRIO_DEFAULT); - if (want_reset) { +void board_usb_charge_update(int force_update) +{ + int int_val = 0; + + if (pending_tsu6721_reset) { + current_watchdog = ADC_WATCH_NONE; + adc_disable_watchdog(); tsu6721_reset(); force_update = 1; - } + pending_tsu6721_reset = 0; + } else + int_val = tsu6721_get_interrupts(); if (int_val & TSU6721_INT_DETACH) usb_device_change(TSU6721_TYPE_NONE); |