diff options
author | Shawn Nematbakhsh <shawnn@chromium.org> | 2015-06-08 13:58:47 -0700 |
---|---|---|
committer | ChromeOS Commit Bot <chromeos-commit-bot@chromium.org> | 2015-06-10 19:48:08 +0000 |
commit | e05ed041cfe60db7d1bff5424d4579a52aea402f (patch) | |
tree | 1fd7a6e78c42682b1f9eb331c12084a4b44c3b56 /board/samus_pd | |
parent | 5d7c4f0cd6b7b020e70c9f9ec5f60a8457b90f12 (diff) | |
download | chrome-ec-e05ed041cfe60db7d1bff5424d4579a52aea402f.tar.gz |
charger: Move USB charger / BC1.2 task to common code
Move the task responsible for detection of USB chargers to common code
to reduce code duplication.
BUG=chrome-os-partner:40920
TEST=Manual on samus_pd. Plug USB charger, verify detection is correct
on both charge ports.
BRANCH=None
Change-Id: I362f8b5b51741509e459c66928131f1f6d2a3b1d
Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/276210
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Reviewed-by: Alec Berg <alecaberg@chromium.org>
Diffstat (limited to 'board/samus_pd')
-rw-r--r-- | board/samus_pd/board.c | 143 | ||||
-rw-r--r-- | board/samus_pd/board.h | 21 |
2 files changed, 7 insertions, 157 deletions
diff --git a/board/samus_pd/board.c b/board/samus_pd/board.c index 59b562f888..eee86c4a8b 100644 --- a/board/samus_pd/board.c +++ b/board/samus_pd/board.c @@ -77,19 +77,6 @@ const struct pwm_t pwm_channels[] = { }; BUILD_ASSERT(ARRAY_SIZE(pwm_channels) == PWM_CH_COUNT); -/* Charge supplier priority: lower number indicates higher priority. */ -const int supplier_priority[] = { - [CHARGE_SUPPLIER_PD] = 0, - [CHARGE_SUPPLIER_TYPEC] = 1, - [CHARGE_SUPPLIER_PROPRIETARY] = 1, - [CHARGE_SUPPLIER_BC12_DCP] = 1, - [CHARGE_SUPPLIER_BC12_CDP] = 2, - [CHARGE_SUPPLIER_BC12_SDP] = 3, - [CHARGE_SUPPLIER_OTHER] = 3, - [CHARGE_SUPPLIER_VBUS] = 4 -}; -BUILD_ASSERT(ARRAY_SIZE(supplier_priority) == CHARGE_SUPPLIER_COUNT); - static void pericom_port0_reenable_interrupts(void) { CPRINTS("VBUS p0 %d", gpio_get_level(GPIO_USB_C0_VBUS_WAKE)); @@ -156,124 +143,6 @@ void vbus1_evt(enum gpio_signal signal) task_wake(TASK_ID_PD_C1); } -/* Wait after a charger is detected to debounce pin contact order */ -#define USB_CHG_DEBOUNCE_DELAY_MS 1000 -/* - * Wait after reset, before re-enabling attach interrupt, so that the - * spurious attach interrupt from certain ports is ignored. - */ -#define USB_CHG_RESET_DELAY_MS 100 - -void usb_charger_task(void) -{ - int port = (task_get_current() == TASK_ID_USB_CHG_P0 ? 0 : 1); - int vbus_source = (port == 0 ? GPIO_USB_C0_5V_EN : GPIO_USB_C1_5V_EN); - int device_type, charger_status; - struct charge_port_info charge; - int type; - charge.voltage = USB_BC12_CHARGE_VOLTAGE; - - while (1) { - /* Read interrupt register to clear on chip */ - pi3usb9281_get_interrupts(port); - - if (gpio_get_level(vbus_source)) { - /* If we're sourcing VBUS then we're not charging */ - device_type = charger_status = 0; - } else { - /* Set device type */ - device_type = pi3usb9281_get_device_type(port); - charger_status = pi3usb9281_get_charger_status(port); - } - - /* Debounce pin plug order if we detect a charger */ - if (device_type || PI3USB9281_CHG_STATUS_ANY(charger_status)) { - msleep(USB_CHG_DEBOUNCE_DELAY_MS); - - /* - * Trigger chip reset to refresh detection registers. - * WARNING: This reset is acceptable for samus_pd, - * but may not be acceptable for devices that have - * an OTG / device mode, as we may be interrupting - * the connection. - */ - pi3usb9281_reset(port); - /* - * Restore data switch settings - switches return to - * closed on reset until restored. - */ - mutex_lock(&usb_switch_lock[port]); - if (usb_switch_state[port]) - pi3usb9281_set_switches(port, 1); - mutex_unlock(&usb_switch_lock[port]); - /* Clear possible disconnect interrupt */ - pi3usb9281_get_interrupts(port); - /* Mask attach interrupt */ - pi3usb9281_set_interrupt_mask(port, - 0xff & - ~PI3USB9281_INT_ATTACH); - /* Re-enable interrupts */ - pi3usb9281_enable_interrupts(port); - msleep(USB_CHG_RESET_DELAY_MS); - - /* Clear possible attach interrupt */ - pi3usb9281_get_interrupts(port); - /* Re-enable attach interrupt */ - pi3usb9281_set_interrupt_mask(port, 0xff); - - /* Re-read ID registers */ - device_type = pi3usb9281_get_device_type(port); - charger_status = pi3usb9281_get_charger_status(port); - } - - /* Attachment: decode + update available charge */ - if (device_type || PI3USB9281_CHG_STATUS_ANY(charger_status)) { - if (PI3USB9281_CHG_STATUS_ANY(charger_status)) - type = CHARGE_SUPPLIER_PROPRIETARY; - else if (device_type & PI3USB9281_TYPE_CDP) - type = CHARGE_SUPPLIER_BC12_CDP; - else if (device_type & PI3USB9281_TYPE_DCP) - type = CHARGE_SUPPLIER_BC12_DCP; - else if (device_type & PI3USB9281_TYPE_SDP) - type = CHARGE_SUPPLIER_BC12_SDP; - else - type = CHARGE_SUPPLIER_OTHER; - - charge.current = pi3usb9281_get_ilim(device_type, - charger_status); - charge_manager_update_charge(type, port, &charge); - } else { /* Detachment: update available charge to 0 */ - charge.current = 0; - charge_manager_update_charge( - CHARGE_SUPPLIER_PROPRIETARY, - port, - &charge); - charge_manager_update_charge( - CHARGE_SUPPLIER_BC12_CDP, - port, - &charge); - charge_manager_update_charge( - CHARGE_SUPPLIER_BC12_DCP, - port, - &charge); - charge_manager_update_charge( - CHARGE_SUPPLIER_BC12_SDP, - port, - &charge); - charge_manager_update_charge( - CHARGE_SUPPLIER_OTHER, - port, - &charge); - } - - /* notify host of power info change */ - pd_send_host_event(PD_EVENT_POWER_CHANGE); - - /* Wait for interrupt */ - task_wait_event(-1); - } -} - /* Charge manager callback function, called on delayed override timeout */ void board_charge_manager_override_timeout(void) { @@ -549,16 +418,16 @@ const struct usb_port_mux usb_muxes[] = { }; BUILD_ASSERT(ARRAY_SIZE(usb_muxes) == CONFIG_USB_PD_PORT_COUNT); - -static void board_set_usb_switches(int port, int open) +void board_set_usb_switches(int port, enum usb_switch setting) { - /* If switch is not changing, then return */ - if (open == usb_switch_state[port]) + /* If switch is not changing then return */ + if (setting == usb_switch_state[port]) return; mutex_lock(&usb_switch_lock[port]); - usb_switch_state[port] = open; - pi3usb9281_set_switches(port, open); + if (setting != USB_SWITCH_RESTORE) + usb_switch_state[port] = setting; + pi3usb9281_set_switches(port, usb_switch_state[port]); mutex_unlock(&usb_switch_lock[port]); } diff --git a/board/samus_pd/board.h b/board/samus_pd/board.h index dbcd97fec5..c3dcd49ca0 100644 --- a/board/samus_pd/board.h +++ b/board/samus_pd/board.h @@ -44,6 +44,7 @@ #undef CONFIG_PWM #define CONFIG_STM_HWTIMER32 #undef CONFIG_TASK_PROFILING +#define CONFIG_USB_CHARGER #define CONFIG_USB_POWER_DELIVERY #define CONFIG_USB_PD_ALT_MODE #define CONFIG_USB_PD_ALT_MODE_DFP @@ -53,7 +54,6 @@ #define CONFIG_USB_PD_CUSTOM_VDM #define CONFIG_USB_PD_DUAL_ROLE #define CONFIG_USB_PD_FLASH_ERASE_CHECK -#define CONFIG_USB_PD_HOST_EVENT_ON_POWER_CHANGE #define CONFIG_USB_PD_INTERNAL_COMP #define CONFIG_USB_PD_LOGGING #define CONFIG_USB_PD_LOG_SIZE 512 @@ -114,22 +114,6 @@ enum pwm_channel { PWM_CH_COUNT }; -/* Charge suppliers */ -enum charge_supplier { - CHARGE_SUPPLIER_PD, - CHARGE_SUPPLIER_TYPEC, - CHARGE_SUPPLIER_BC12_DCP, - CHARGE_SUPPLIER_BC12_CDP, - CHARGE_SUPPLIER_BC12_SDP, - CHARGE_SUPPLIER_PROPRIETARY, - CHARGE_SUPPLIER_OTHER, - CHARGE_SUPPLIER_VBUS, - CHARGE_SUPPLIER_COUNT -}; - -/* supplier_priority table defined in board.c */ -extern const int supplier_priority[]; - /* Standard-current Rp */ #define PD_SRC_VNC PD_SRC_DEF_VNC_MV #define PD_SRC_RD_THRESHOLD PD_SRC_DEF_RD_THRESH_MV @@ -163,9 +147,6 @@ extern const int supplier_priority[]; /* Get the last received battery level. */ int board_get_battery_soc(void); -/* Send host event to AP */ -void pd_send_host_event(int mask); - #endif /* !__ASSEMBLER__ */ #endif /* __BOARD_H */ |