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 | |
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')
-rw-r--r-- | board/glados/board.c | 14 | ||||
-rw-r--r-- | board/glados/board.h | 16 | ||||
-rw-r--r-- | board/host/board.h | 9 | ||||
-rw-r--r-- | board/oak/board.c | 14 | ||||
-rw-r--r-- | board/oak/board.h | 16 | ||||
-rw-r--r-- | board/ryu/board.c | 128 | ||||
-rw-r--r-- | board/ryu/board.h | 23 | ||||
-rw-r--r-- | board/ryu/ec.tasklist | 3 | ||||
-rw-r--r-- | board/ryu_p4p5/board.c | 128 | ||||
-rw-r--r-- | board/ryu_p4p5/board.h | 23 | ||||
-rw-r--r-- | board/ryu_p4p5/ec.tasklist | 3 | ||||
-rw-r--r-- | board/samus_pd/board.c | 143 | ||||
-rw-r--r-- | board/samus_pd/board.h | 21 |
13 files changed, 35 insertions, 506 deletions
diff --git a/board/glados/board.c b/board/glados/board.c index 7c62e36939..1f88043cc4 100644 --- a/board/glados/board.c +++ b/board/glados/board.c @@ -36,7 +36,6 @@ /* Default input current limit when VBUS is present */ #define DEFAULT_CURR_LIMIT 500 /* mA */ -#define USB_BC12_CHARGE_VOLTAGE 5000 /* mV */ /* Exchange status with PD MCU. */ static void pd_mcu_interrupt(enum gpio_signal signal) @@ -99,19 +98,6 @@ const struct i2c_port_t i2c_ports[] = { }; const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports); -/* 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); - /** * Discharge battery when on AC power for factory test. */ diff --git a/board/glados/board.h b/board/glados/board.h index d9be43cc95..da54b2a861 100644 --- a/board/glados/board.h +++ b/board/glados/board.h @@ -96,22 +96,6 @@ enum power_signal { POWER_SIGNAL_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[]; - /* start as a sink in case we have no other power supply/battery */ #define PD_DEFAULT_STATE PD_STATE_SNK_DISCONNECTED diff --git a/board/host/board.h b/board/host/board.h index 677237ab43..99a5798e02 100644 --- a/board/host/board.h +++ b/board/host/board.h @@ -39,8 +39,8 @@ enum adc_channel { ADC_CH_COUNT }; -/* Charge suppliers */ -enum charge_supplier { +/* Fake test charge suppliers */ +enum { CHARGE_SUPPLIER_TEST1, CHARGE_SUPPLIER_TEST2, CHARGE_SUPPLIER_TEST3, @@ -49,11 +49,10 @@ enum charge_supplier { CHARGE_SUPPLIER_TEST6, CHARGE_SUPPLIER_TEST7, CHARGE_SUPPLIER_TEST8, - CHARGE_SUPPLIER_TEST9, - CHARGE_SUPPLIER_COUNT + CHARGE_SUPPLIER_TEST_COUNT }; -/* supplier_priority table defined in board.c */ +/* Custom charge_manager priority table is defined in test code */ extern const int supplier_priority[]; /* Standard-current Rp */ diff --git a/board/oak/board.c b/board/oak/board.c index f4fc84918c..1877c7c0c7 100644 --- a/board/oak/board.c +++ b/board/oak/board.c @@ -40,7 +40,6 @@ /* Default input current limit when VBUS is present */ #define DEFAULT_CURR_LIMIT 500 /* mA */ -#define USB_BC12_CHARGE_VOLTAGE 5000 /* mV */ static void ap_reset_deferred(void) { @@ -109,19 +108,6 @@ const struct i2c_port_t i2c_ports[] = { const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports); -/* 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 int discharging_on_ac; /** diff --git a/board/oak/board.h b/board/oak/board.h index c4745c4d69..e00ce7be50 100644 --- a/board/oak/board.h +++ b/board/oak/board.h @@ -138,22 +138,6 @@ enum adc_channel { ADC_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[]; - /* start as a sink in case we have no other power supply/battery */ #define PD_DEFAULT_STATE PD_STATE_SNK_DISCONNECTED diff --git a/board/ryu/board.c b/board/ryu/board.c index 24655456ba..0c15c674b7 100644 --- a/board/ryu/board.c +++ b/board/ryu/board.c @@ -91,113 +91,9 @@ void vbus_evt(enum gpio_signal signal) task_wake(TASK_ID_PD); } -/* Wait 200ms after a charger is detected to debounce pin contact order */ -#define USB_CHG_DEBOUNCE_DELAY_MS 200 -/* - * Wait 100ms 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 device_type, charger_status; - struct charge_port_info charge; - int type; - charge.voltage = USB_BC12_CHARGE_VOLTAGE; - - while (1) { - /* Read interrupt register to clear */ - pi3usb9281_get_interrupts(0); - - /* Set device type */ - device_type = pi3usb9281_get_device_type(0); - charger_status = pi3usb9281_get_charger_status(0); - - /* 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 */ - pi3usb9281_reset(0); - /* - * Restore data switch settings - switches return to - * closed on reset until restored. - */ - if (usb_switch_state) - pi3usb9281_set_switches(0, 1); - - /* Clear possible disconnect interrupt */ - pi3usb9281_get_interrupts(0); - /* Mask attach interrupt */ - pi3usb9281_set_interrupt_mask(0, - 0xff & - ~PI3USB9281_INT_ATTACH); - /* Re-enable interrupts */ - pi3usb9281_enable_interrupts(0); - msleep(USB_CHG_RESET_DELAY_MS); - - /* Clear possible attach interrupt */ - pi3usb9281_get_interrupts(0); - /* Re-enable attach interrupt */ - pi3usb9281_set_interrupt_mask(0, 0xff); - - /* Re-read ID registers */ - device_type = pi3usb9281_get_device_type(0); - charger_status = pi3usb9281_get_charger_status(0); - } - - 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; - - /* Attachment: decode + update available charge */ - if (device_type || PI3USB9281_CHG_STATUS_ANY(charger_status)) { - charge.current = pi3usb9281_get_ilim(device_type, - charger_status); - charge_manager_update_charge(type, 0, &charge); - } else { /* Detachment: update available charge to 0 */ - charge.current = 0; - charge_manager_update_charge( - CHARGE_SUPPLIER_PROPRIETARY, - 0, - &charge); - charge_manager_update_charge( - CHARGE_SUPPLIER_BC12_CDP, - 0, - &charge); - charge_manager_update_charge( - CHARGE_SUPPLIER_BC12_DCP, - 0, - &charge); - charge_manager_update_charge( - CHARGE_SUPPLIER_BC12_SDP, - 0, - &charge); - charge_manager_update_charge( - CHARGE_SUPPLIER_OTHER, - 0, - &charge); - } - - /* notify host of power info change */ - pd_send_host_event(PD_EVENT_POWER_CHANGE); - - /* Wait for interrupt */ - task_wait_event(-1); - } -} - void usb_evt(enum gpio_signal signal) { - task_wake(TASK_ID_USB_CHG); + task_wake(TASK_ID_USB_CHG_P0); } #include "gpio_list.h" @@ -343,19 +239,6 @@ const struct adc_t adc_channels[] = { }; BUILD_ASSERT(ARRAY_SIZE(adc_channels) == ADC_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); - /* I2C ports */ const struct i2c_port_t i2c_ports[] = { {"master", I2C_PORT_MASTER, 100, @@ -428,14 +311,15 @@ struct motion_sensor_t motion_sensors[] = { }; const unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors); -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) + if (setting == usb_switch_state) return; - usb_switch_state = open; - pi3usb9281_set_switches(port, open); + if (setting != USB_SWITCH_RESTORE) + usb_switch_state = setting; + pi3usb9281_set_switches(port, usb_switch_state); } void board_set_usb_mux(int port, enum typec_mux mux, diff --git a/board/ryu/board.h b/board/ryu/board.h index 5a8c085e76..2cc8fa4e61 100644 --- a/board/ryu/board.h +++ b/board/ryu/board.h @@ -23,6 +23,7 @@ #define CONFIG_CHARGE_MANAGER #define CONFIG_FORCE_CONSOLE_RESUME #define CONFIG_STM_HWTIMER32 +#define CONFIG_USB_CHARGER #define CONFIG_USB_POWER_DELIVERY #define CONFIG_USB_PD_ALT_MODE #define CONFIG_USB_PD_ALT_MODE_DFP @@ -168,22 +169,6 @@ enum adc_channel { ADC_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[]; - /* USB string indexes */ enum usb_strings { USB_STR_DESC = 0, @@ -197,6 +182,9 @@ enum usb_strings { USB_STR_COUNT }; +/* VBUS enable GPIO */ +#define GPIO_USB_C0_5V_EN GPIO_CHGR_OTG + /* 1.5A Rp */ #define PD_SRC_VNC PD_SRC_1_5_VNC_MV #define PD_SRC_RD_THRESHOLD PD_SRC_1_5_RD_THRESH_MV @@ -226,9 +214,6 @@ int board_discharge_on_ac(int enable); /* Set the charge current limit. */ void board_set_charge_limit(int charge_ma); -/* Send host event to AP */ -void pd_send_host_event(int mask); - /* PP1800 transition GPIO interrupt handler */ void pp1800_on_off_evt(enum gpio_signal signal); diff --git a/board/ryu/ec.tasklist b/board/ryu/ec.tasklist index 78b7a758c8..6b672c7b17 100644 --- a/board/ryu/ec.tasklist +++ b/board/ryu/ec.tasklist @@ -18,7 +18,8 @@ */ #define CONFIG_TASK_LIST \ TASK_ALWAYS(HOOKS, hook_task, NULL, LARGER_TASK_STACK_SIZE) \ - TASK_ALWAYS(USB_CHG, usb_charger_task, NULL, SMALLER_TASK_STACK_SIZE) \ + TASK_ALWAYS(USB_CHG_P0, usb_charger_task, NULL, \ + SMALLER_TASK_STACK_SIZE) \ TASK_NOTEST(LIGHTBAR, lightbar_task, NULL, LARGER_TASK_STACK_SIZE) \ TASK_ALWAYS(CHARGER, charger_task, NULL, TASK_STACK_SIZE) \ TASK_NOTEST(MOTIONSENSE, motion_sense_task, NULL, TASK_STACK_SIZE) \ diff --git a/board/ryu_p4p5/board.c b/board/ryu_p4p5/board.c index 28e2c20cb4..4ce21be02a 100644 --- a/board/ryu_p4p5/board.c +++ b/board/ryu_p4p5/board.c @@ -89,113 +89,9 @@ void vbus_evt(enum gpio_signal signal) task_wake(TASK_ID_PD); } -/* Wait 200ms after a charger is detected to debounce pin contact order */ -#define USB_CHG_DEBOUNCE_DELAY_MS 200 -/* - * Wait 100ms 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 device_type, charger_status; - struct charge_port_info charge; - int type; - charge.voltage = USB_BC12_CHARGE_VOLTAGE; - - while (1) { - /* Read interrupt register to clear */ - pi3usb9281_get_interrupts(0); - - /* Set device type */ - device_type = pi3usb9281_get_device_type(0); - charger_status = pi3usb9281_get_charger_status(0); - - /* 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 */ - pi3usb9281_reset(0); - /* - * Restore data switch settings - switches return to - * closed on reset until restored. - */ - if (usb_switch_state) - pi3usb9281_set_switches(0, 1); - - /* Clear possible disconnect interrupt */ - pi3usb9281_get_interrupts(0); - /* Mask attach interrupt */ - pi3usb9281_set_interrupt_mask(0, - 0xff & - ~PI3USB9281_INT_ATTACH); - /* Re-enable interrupts */ - pi3usb9281_enable_interrupts(0); - msleep(USB_CHG_RESET_DELAY_MS); - - /* Clear possible attach interrupt */ - pi3usb9281_get_interrupts(0); - /* Re-enable attach interrupt */ - pi3usb9281_set_interrupt_mask(0, 0xff); - - /* Re-read ID registers */ - device_type = pi3usb9281_get_device_type(0); - charger_status = pi3usb9281_get_charger_status(0); - } - - 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; - - /* Attachment: decode + update available charge */ - if (device_type || PI3USB9281_CHG_STATUS_ANY(charger_status)) { - charge.current = pi3usb9281_get_ilim(device_type, - charger_status); - charge_manager_update_charge(type, 0, &charge); - } else { /* Detachment: update available charge to 0 */ - charge.current = 0; - charge_manager_update_charge( - CHARGE_SUPPLIER_PROPRIETARY, - 0, - &charge); - charge_manager_update_charge( - CHARGE_SUPPLIER_BC12_CDP, - 0, - &charge); - charge_manager_update_charge( - CHARGE_SUPPLIER_BC12_DCP, - 0, - &charge); - charge_manager_update_charge( - CHARGE_SUPPLIER_BC12_SDP, - 0, - &charge); - charge_manager_update_charge( - CHARGE_SUPPLIER_OTHER, - 0, - &charge); - } - - /* notify host of power info change */ - pd_send_host_event(PD_EVENT_POWER_CHANGE); - - /* Wait for interrupt */ - task_wait_event(-1); - } -} - void usb_evt(enum gpio_signal signal) { - task_wake(TASK_ID_USB_CHG); + task_wake(TASK_ID_USB_CHG_P0); } #include "gpio_list.h" @@ -364,19 +260,6 @@ const struct adc_t adc_channels[] = { }; BUILD_ASSERT(ARRAY_SIZE(adc_channels) == ADC_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); - /* I2C ports */ const struct i2c_port_t i2c_ports[] = { {"master", I2C_PORT_MASTER, 100, @@ -386,14 +269,15 @@ const struct i2c_port_t i2c_ports[] = { }; const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports); -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) + if (setting == usb_switch_state) return; - usb_switch_state = open; - pi3usb9281_set_switches(port, open); + if (setting != USB_SWITCH_RESTORE) + usb_switch_state = setting; + pi3usb9281_set_switches(port, usb_switch_state); } /* TODO(crosbug.com/p/38333) remove me */ diff --git a/board/ryu_p4p5/board.h b/board/ryu_p4p5/board.h index 9fbf93221b..4d039b2ea0 100644 --- a/board/ryu_p4p5/board.h +++ b/board/ryu_p4p5/board.h @@ -25,6 +25,7 @@ #define CONFIG_CMD_CHGRAMP #define CONFIG_FORCE_CONSOLE_RESUME #define CONFIG_STM_HWTIMER32 +#define CONFIG_USB_CHARGER #define CONFIG_USB_POWER_DELIVERY #define CONFIG_USB_PD_DUAL_ROLE #define CONFIG_USB_PD_FLASH_ERASE_CHECK @@ -164,22 +165,6 @@ enum adc_channel { ADC_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[]; - /* USB string indexes */ enum usb_strings { USB_STR_DESC = 0, @@ -193,6 +178,9 @@ enum usb_strings { USB_STR_COUNT }; +/* VBUS enable GPIO */ +#define GPIO_USB_C0_5V_EN GPIO_USBC_5V_EN + /* 1.5A Rp */ #define PD_SRC_VNC PD_SRC_1_5_VNC_MV #define PD_SRC_RD_THRESHOLD PD_SRC_1_5_RD_THRESH_MV @@ -222,9 +210,6 @@ int board_discharge_on_ac(int enable); /* Set the charge current limit. */ void board_set_charge_limit(int charge_ma); -/* Send host event to AP */ -void pd_send_host_event(int mask); - /* PP1800 transition GPIO interrupt handler */ void pp1800_on_off_evt(enum gpio_signal signal); diff --git a/board/ryu_p4p5/ec.tasklist b/board/ryu_p4p5/ec.tasklist index cb9fb5adf2..373e6e09b8 100644 --- a/board/ryu_p4p5/ec.tasklist +++ b/board/ryu_p4p5/ec.tasklist @@ -19,7 +19,8 @@ #define CONFIG_TASK_LIST \ TASK_ALWAYS(HOOKS, hook_task, NULL, LARGER_TASK_STACK_SIZE) \ TASK_ALWAYS(CHG_RAMP, chg_ramp_task, NULL, SMALLER_TASK_STACK_SIZE) \ - TASK_ALWAYS(USB_CHG, usb_charger_task, NULL, SMALLER_TASK_STACK_SIZE) \ + TASK_ALWAYS(USB_CHG_P0, usb_charger_task, NULL, \ + SMALLER_TASK_STACK_SIZE) \ TASK_NOTEST(LIGHTBAR, lightbar_task, NULL, LARGER_TASK_STACK_SIZE) \ TASK_ALWAYS(CHARGER, charger_task, NULL, TASK_STACK_SIZE) \ TASK_NOTEST(CHIPSET, chipset_task, NULL, TASK_STACK_SIZE) \ 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 */ |