summaryrefslogtreecommitdiff
path: root/driver
diff options
context:
space:
mode:
authorTing Shen <phoenixshen@google.com>2020-05-06 18:06:52 +0800
committerCommit Bot <commit-bot@chromium.org>2020-05-29 05:11:24 +0000
commit8975cbb645f1f07c3682334d02510a8a1d3f730b (patch)
tree1c65f1c460b25e785181b15c2d78b303b4cfacfc /driver
parentfad8f404df3e1b2278326c08247a62edce434f32 (diff)
downloadchrome-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')
-rw-r--r--driver/bc12/max14637.c31
-rw-r--r--driver/bc12/max14637.h1
-rw-r--r--driver/bc12/pi3usb9201.c32
-rw-r--r--driver/bc12/pi3usb9201.h1
-rw-r--r--driver/bc12/pi3usb9281.c34
-rw-r--r--driver/bc12/pi3usb9281.h1
-rw-r--r--driver/charger/bd9995x.c43
-rw-r--r--driver/charger/rt946x.c27
-rw-r--r--driver/charger/rt946x.h1
9 files changed, 129 insertions, 42 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 */
diff --git a/driver/charger/bd9995x.c b/driver/charger/bd9995x.c
index 58f13af6f6..2531d4225d 100644
--- a/driver/charger/bd9995x.c
+++ b/driver/charger/bd9995x.c
@@ -584,7 +584,7 @@ static int usb_charger_process(int chgnum, int port)
}
#ifdef CONFIG_CHARGE_RAMP_SW
-int usb_charger_ramp_allowed(int supplier)
+static int bd9995x_ramp_allowed(int supplier)
{
return supplier == CHARGE_SUPPLIER_BC12_DCP ||
supplier == CHARGE_SUPPLIER_BC12_SDP ||
@@ -592,7 +592,7 @@ int usb_charger_ramp_allowed(int supplier)
supplier == CHARGE_SUPPLIER_OTHER;
}
-int usb_charger_ramp_max(int supplier, int sup_curr)
+static int bd9995x_ramp_max(int supplier, int sup_curr)
{
return bd9995x_get_bc12_ilim(supplier);
}
@@ -1261,7 +1261,7 @@ int bd9995x_bc12_enable_charging(int port, int enable)
BD9995X_EXTENDED_COMMAND);
}
-void usb_charger_set_switches(int port, enum usb_switch setting)
+static void bd9995x_set_switches(int port, enum usb_switch setting)
{
/* If switch is not changing then return */
if (setting == usb_switch_state[port])
@@ -1288,7 +1288,7 @@ void bd9995x_vbus_interrupt(enum gpio_signal signal)
task_wake(TASK_ID_USB_CHG);
}
-void usb_charger_task(void *u)
+static void bd9995x_usb_charger_task(const int unused)
{
static int initialized;
int changed, port, interrupts;
@@ -1725,3 +1725,38 @@ const struct charger_drv bd9995x_drv = {
.get_option = &bd9995x_get_option,
.set_option = &bd9995x_set_option,
};
+
+#ifdef CONFIG_BC12_SINGLE_DRIVER
+/* provide a default bc12_ports[] for backward compatibility */
+struct bc12_config bc12_ports[BD9995X_CHARGE_PORT_COUNT] = {
+ {
+ .drv = &(const struct bc12_drv) {
+ .usb_charger_task = bd9995x_usb_charger_task,
+ .set_switches = bd9995x_set_switches,
+#if defined(CONFIG_CHARGE_RAMP_SW)
+ .ramp_allowed = bd9995x_ramp_allowed,
+ .ramp_max = bd9995x_ramp_max,
+#endif /* CONFIG_CHARGE_RAMP_SW */
+ },
+ },
+ {
+ .drv = &(const struct bc12_drv) {
+ /* bd9995x uses a single task thread for both ports */
+ .usb_charger_task = NULL,
+ .set_switches = bd9995x_set_switches,
+#if defined(CONFIG_CHARGE_RAMP_SW)
+ .ramp_allowed = bd9995x_ramp_allowed,
+ .ramp_max = bd9995x_ramp_max,
+#endif /* CONFIG_CHARGE_RAMP_SW */
+ },
+ },
+};
+BUILD_ASSERT(ARRAY_SIZE(bc12_ports) == CHARGE_PORT_COUNT);
+#else
+/*
+ * TODO:
+ * This driver assumes its two ports is always on number 0 and 1.
+ * Prohibit multiple driver for safety.
+ */
+#error config not supported
+#endif /* CONFIG_BC12_SINGLE_DRIVER */
diff --git a/driver/charger/rt946x.c b/driver/charger/rt946x.c
index 4d0bb39aa2..e139161a31 100644
--- a/driver/charger/rt946x.c
+++ b/driver/charger/rt946x.c
@@ -1515,7 +1515,7 @@ static void rt946x_bc12_workaround(void)
}
DECLARE_DEFERRED(rt946x_bc12_workaround);
-void usb_charger_task(void *u)
+static void rt946x_usb_charger_task(const int unused)
{
struct charge_port_info chg;
int bc12_type = CHARGE_SUPPLIER_NONE;
@@ -1590,16 +1590,12 @@ wait_event:
}
}
-void usb_charger_set_switches(int port, enum usb_switch setting)
-{
-}
-
-int usb_charger_ramp_allowed(int supplier)
+static int rt946x_ramp_allowed(int supplier)
{
return supplier == CHARGE_SUPPLIER_BC12_DCP;
}
-int usb_charger_ramp_max(int supplier, int sup_curr)
+static int rt946x_ramp_max(int supplier, int sup_curr)
{
return rt946x_get_bc12_ilim(supplier);
}
@@ -1899,3 +1895,20 @@ const struct charger_drv rt946x_drv = {
.ramp_get_current_limit = &rt946x_ramp_get_current_limit,
#endif
};
+
+#ifdef HAS_TASK_USB_CHG
+const struct bc12_drv rt946x_bc12_drv = {
+ .usb_charger_task = rt946x_usb_charger_task,
+ .ramp_allowed = rt946x_ramp_allowed,
+ .ramp_max = rt946x_ramp_max,
+};
+
+#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 = &rt946x_bc12_drv,
+ },
+};
+#endif /* CONFIG_BC12_SINGLE_DRIVER */
+#endif
diff --git a/driver/charger/rt946x.h b/driver/charger/rt946x.h
index c2522aaf1a..38ec200c77 100644
--- a/driver/charger/rt946x.h
+++ b/driver/charger/rt946x.h
@@ -861,5 +861,6 @@ int mt6370_reduce_db_bl_driving(void);
#endif
extern const struct charger_drv rt946x_drv;
+extern const struct bc12_drv rt946x_bc12_drv;
#endif /* __CROS_EC_RT946X_H */