diff options
author | Ting Shen <phoenixshen@google.com> | 2020-05-06 18:06:52 +0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-05-29 05:11:24 +0000 |
commit | 8975cbb645f1f07c3682334d02510a8a1d3f730b (patch) | |
tree | 1c65f1c460b25e785181b15c2d78b303b4cfacfc /driver/bc12 | |
parent | fad8f404df3e1b2278326c08247a62edce434f32 (diff) | |
download | chrome-ec-8975cbb645f1f07c3682334d02510a8a1d3f730b.tar.gz |
bc12: create bc12 driver structure
To support linking multiple bc12 drivers into ec binary, we have to
remove the common symbols in drivers.
This CL creates a bc12_drv structure to hold the original driver-specific
usb_charger_* functions, and implements common usb_charger_* functions
which whill dispatch the function call based on the information in
bc12_drv table.
Also add a CONFIG_BC12_SINGLE_DRIVER and enabled by default for
backward compatibility. If CONFIG_BC12_SINGLE_DRIVER is defined,
a default bc12_drv array with proper size and content will be created
for the board.
BUG=b:155611686
TEST=1) make buildall.
2) verify single driver mode on krane (rt946x) and juniper
(pi3usb9201).
3) verify multiple driver works on asurada, see CL:2189624 for
example usage.
4) verify single driver multi chip on blooglet.
BRANCH=none
Signed-off-by: Ting Shen <phoenixshen@google.com>
Change-Id: I8a96eda47c94aeb6cc150b498cfa1a6eefcc4a5b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2187080
Reviewed-by: Jett Rink <jettrink@chromium.org>
Commit-Queue: Ting Shen <phoenixshen@chromium.org>
Tested-by: Ting Shen <phoenixshen@chromium.org>
Diffstat (limited to 'driver/bc12')
-rw-r--r-- | driver/bc12/max14637.c | 31 | ||||
-rw-r--r-- | driver/bc12/max14637.h | 1 | ||||
-rw-r--r-- | driver/bc12/pi3usb9201.c | 32 | ||||
-rw-r--r-- | driver/bc12/pi3usb9201.h | 1 | ||||
-rw-r--r-- | driver/bc12/pi3usb9281.c | 34 | ||||
-rw-r--r-- | driver/bc12/pi3usb9281.h | 1 |
6 files changed, 69 insertions, 31 deletions
diff --git a/driver/bc12/max14637.c b/driver/bc12/max14637.c index 2aab525f00..91b5441a68 100644 --- a/driver/bc12/max14637.c +++ b/driver/bc12/max14637.c @@ -151,9 +151,8 @@ static void detect_or_power_down_ic(const int port) } } -void usb_charger_task(void *u) +static void max14637_usb_charger_task(const int port) { - const int port = (intptr_t)u; uint32_t evt; const struct max14637_config_t * const cfg = &max14637_config[port]; @@ -175,15 +174,8 @@ void usb_charger_task(void *u) } } -void usb_charger_set_switches(int port, enum usb_switch setting) -{ - /* - * The MAX14637 automatically sets up the USB 2.0 high-speed switches. - */ -} - #if defined(CONFIG_CHARGE_RAMP_SW) || defined(CONFIG_CHARGE_RAMP_HW) -int usb_charger_ramp_allowed(int supplier) +static int max14637_ramp_allowed(int supplier) { /* * Due to the limitations in the application of the MAX14637, we @@ -193,7 +185,7 @@ int usb_charger_ramp_allowed(int supplier) return supplier == CHARGE_SUPPLIER_OTHER; } -int usb_charger_ramp_max(int supplier, int sup_curr) +static int max14637_ramp_max(int supplier, int sup_curr) { /* Use the current limit that was decided by the MAX14637. */ if (supplier == CHARGE_SUPPLIER_OTHER) @@ -220,3 +212,20 @@ static void bc12_chipset_startup(void) } DECLARE_HOOK(HOOK_CHIPSET_STARTUP, bc12_chipset_startup, HOOK_PRIO_DEFAULT); DECLARE_HOOK(HOOK_CHIPSET_RESUME, bc12_chipset_startup, HOOK_PRIO_DEFAULT); + +const struct bc12_drv max14637_drv = { + .usb_charger_task = max14637_usb_charger_task, +#if defined(CONFIG_CHARGE_RAMP_SW) || defined(CONFIG_CHARGE_RAMP_HW) + .ramp_allowed = max14637_ramp_allowed, + .ramp_max = max14637_ramp_max, +#endif /* CONFIG_CHARGE_RAMP_SW || CONFIG_CHARGE_RAMP_HW */ +}; + +#ifdef CONFIG_BC12_SINGLE_DRIVER +/* provide a default bc12_ports[] for backward compatibility */ +struct bc12_config bc12_ports[CHARGE_PORT_COUNT] = { + [0 ... (CHARGE_PORT_COUNT - 1)] = { + .drv = &max14637_drv, + }, +}; +#endif /* CONFIG_BC12_SINGLE_DRIVER */ diff --git a/driver/bc12/max14637.h b/driver/bc12/max14637.h index 789504b1eb..2b18bc222b 100644 --- a/driver/bc12/max14637.h +++ b/driver/bc12/max14637.h @@ -30,3 +30,4 @@ struct max14637_config_t { */ extern const struct max14637_config_t max14637_config[CONFIG_USB_PD_PORT_MAX_COUNT]; +extern const struct bc12_drv max14637_drv; diff --git a/driver/bc12/pi3usb9201.c b/driver/bc12/pi3usb9201.c index f8dbadd5c7..5178d81dae 100644 --- a/driver/bc12/pi3usb9201.c +++ b/driver/bc12/pi3usb9201.c @@ -227,9 +227,8 @@ static void bc12_power_up(int port) pi3usb9201_interrupt_mask(port, 1); } -void usb_charger_task(void *u) +static void pi3usb9201_usb_charger_task(const int port) { - int port = (task_get_current() == TASK_ID_USB_CHG_P0 ? 0 : 1); uint32_t evt; int i; @@ -325,16 +324,8 @@ void usb_charger_task(void *u) } } -void usb_charger_set_switches(int port, enum usb_switch setting) -{ - /* - * Switches are controlled automatically based on whether the port is - * acting as a source or as sink and the result of BC1.2 detection. - */ -} - #if defined(CONFIG_CHARGE_RAMP_SW) || defined(CONFIG_CHARGE_RAMP_HW) -int usb_charger_ramp_allowed(int supplier) +static int pi3usb9201_ramp_allowed(int supplier) { /* Don't allow ramp if charge supplier is OTHER, SDP, or NONE */ return !(supplier == CHARGE_SUPPLIER_OTHER || @@ -342,7 +333,7 @@ int usb_charger_ramp_allowed(int supplier) supplier == CHARGE_SUPPLIER_NONE); } -int usb_charger_ramp_max(int supplier, int sup_curr) +static int pi3usb9201_ramp_max(int supplier, int sup_curr) { /* * Use the level from the bc12_chg_limits table above except for @@ -362,3 +353,20 @@ int usb_charger_ramp_max(int supplier, int sup_curr) } } #endif /* CONFIG_CHARGE_RAMP_SW || CONFIG_CHARGE_RAMP_HW */ + +const struct bc12_drv pi3usb9201_drv = { + .usb_charger_task = pi3usb9201_usb_charger_task, +#if defined(CONFIG_CHARGE_RAMP_SW) || defined(CONFIG_CHARGE_RAMP_HW) + .ramp_allowed = pi3usb9201_ramp_allowed, + .ramp_max = pi3usb9201_ramp_max, +#endif /* CONFIG_CHARGE_RAMP_SW || CONFIG_CHARGE_RAMP_HW */ +}; + +#ifdef CONFIG_BC12_SINGLE_DRIVER +/* provide a default bc12_ports[] for backward compatibility */ +struct bc12_config bc12_ports[CHARGE_PORT_COUNT] = { + [0 ... (CHARGE_PORT_COUNT - 1)] = { + .drv = &pi3usb9201_drv, + } +}; +#endif /* CONFIG_BC12_SINGLE_DRIVER */ diff --git a/driver/bc12/pi3usb9201.h b/driver/bc12/pi3usb9201.h index d9ee80a0d0..e3029999ca 100644 --- a/driver/bc12/pi3usb9201.h +++ b/driver/bc12/pi3usb9201.h @@ -50,3 +50,4 @@ enum pi3usb9201_mode { /* Configuration struct defined at board level */ extern const struct pi3usb9201_config_t pi3usb9201_bc12_chips[]; +extern const struct bc12_drv pi3usb9201_drv; diff --git a/driver/bc12/pi3usb9281.c b/driver/bc12/pi3usb9281.c index 1e1304e4f3..85b6cf2282 100644 --- a/driver/bc12/pi3usb9281.c +++ b/driver/bc12/pi3usb9281.c @@ -259,7 +259,7 @@ static int pi3usb9281_set_pins(int port, uint8_t val) return pi3usb9281_write(port, PI3USB9281_REG_MANUAL, val); } -static int pi3usb9281_set_switches(int port, int open) +static int pi3usb9281_set_switches_impl(int port, int open) { int res = EC_ERROR_UNKNOWN; uint8_t ctrl; @@ -279,7 +279,7 @@ static int pi3usb9281_set_switches(int port, int open) return res; } -void usb_charger_set_switches(int port, enum usb_switch setting) +static void pi3usb9281_set_switches(int port, enum usb_switch setting) { /* If switch is not changing then return */ if (setting == usb_switch_state[port]) @@ -357,7 +357,7 @@ static uint32_t bc12_detect(int port) * Restore data switch settings - switches return to * closed on reset until restored. */ - usb_charger_set_switches(port, USB_SWITCH_RESTORE); + pi3usb9281_set_switches(port, USB_SWITCH_RESTORE); /* * Wait after reset, before re-enabling interrupt, so that @@ -416,9 +416,8 @@ static uint32_t bc12_detect(int port) return evt; } -void usb_charger_task(void *u) +static void pi3usb9281_usb_charger_task(const int port) { - int port = (task_get_current() == TASK_ID_USB_CHG_P0 ? 0 : 1); uint32_t evt; /* Initialize chip and enable interrupts */ @@ -441,7 +440,8 @@ void usb_charger_task(void *u) } if (evt & USB_CHG_EVENT_MUX) - pi3usb9281_set_switches(port, usb_switch_state[port]); + pi3usb9281_set_switches_impl( + port, usb_switch_state[port]); /* * Re-enable interrupts on pericom charger detector since the @@ -462,7 +462,7 @@ void usb_charger_task(void *u) } #if defined(CONFIG_CHARGE_RAMP_SW) || defined(CONFIG_CHARGE_RAMP_HW) -int usb_charger_ramp_allowed(int supplier) +static int pi3usb9281_ramp_allowed(int supplier) { return supplier == CHARGE_SUPPLIER_BC12_DCP || supplier == CHARGE_SUPPLIER_BC12_SDP || @@ -470,7 +470,7 @@ int usb_charger_ramp_allowed(int supplier) supplier == CHARGE_SUPPLIER_PROPRIETARY; } -int usb_charger_ramp_max(int supplier, int sup_curr) +static int pi3usb9281_ramp_max(int supplier, int sup_curr) { switch (supplier) { case CHARGE_SUPPLIER_BC12_DCP: @@ -485,3 +485,21 @@ int usb_charger_ramp_max(int supplier, int sup_curr) } } #endif /* CONFIG_CHARGE_RAMP_SW || CONFIG_CHARGE_RAMP_HW */ + +const struct bc12_drv pi3usb9281_drv = { + .usb_charger_task = pi3usb9281_usb_charger_task, + .set_switches = pi3usb9281_set_switches, +#if defined(CONFIG_CHARGE_RAMP_SW) || defined(CONFIG_CHARGE_RAMP_HW) + .ramp_allowed = pi3usb9281_ramp_allowed, + .ramp_max = pi3usb9281_ramp_max, +#endif /* CONFIG_CHARGE_RAMP_SW || CONFIG_CHARGE_RAMP_HW */ +}; + +#ifdef CONFIG_BC12_SINGLE_DRIVER +/* provide a default bc12_ports[] for backward compatibility */ +struct bc12_config bc12_ports[CHARGE_PORT_COUNT] = { + [0 ... (CHARGE_PORT_COUNT - 1)] = { + .drv = &pi3usb9281_drv, + }, +}; +#endif /* CONFIG_BC12_SINGLE_DRIVER */ diff --git a/driver/bc12/pi3usb9281.h b/driver/bc12/pi3usb9281.h index 69b671500e..ca1828f49c 100644 --- a/driver/bc12/pi3usb9281.h +++ b/driver/bc12/pi3usb9281.h @@ -79,4 +79,5 @@ int pi3usb9281_enable_interrupts(int port); /* Get the device type */ int pi3usb9281_get_device_type(int port); +extern const struct bc12_drv pi3usb9281_drv; #endif /* __CROS_EC_PI3USB9281_H */ |