summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaisuke Nojiri <dnojiri@chromium.org>2017-04-17 11:33:37 -0700
committerchrome-bot <chrome-bot@chromium.org>2017-05-01 21:54:10 -0700
commit95139fa58280335f302827d96154038a7c23e0c0 (patch)
treed70700fd3a01d2a215b680d43617ffe0b048387d
parent86950ba929104de0e2ef2de34e4cd2f6064d4482 (diff)
downloadchrome-ec-95139fa58280335f302827d96154038a7c23e0c0.tar.gz
usb_port_power: Allow variable number of ports
Currently, usb_port_power_dumb allows fixed number of ports (2) and usb_port_power_smart allows less than 4 ports. This change removes the limitation and makes them accept variable number of ports. BUG=chromium:715178 BRANCH=none TEST=Verified usbchargemode returns consistent charge_mode across sysjumps on Electro. Change-Id: I7675c65ba03d3e6f7f53b2fe48cbe510231d945a Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/481077 Reviewed-by: Randall Spangler <rspangler@chromium.org>
-rw-r--r--board/kahlee/board.c4
-rw-r--r--board/reef/board.c4
-rw-r--r--board/samus/board.c5
-rw-r--r--board/strago/board.c5
-rw-r--r--common/usb_port_power_dumb.c54
-rw-r--r--common/usb_port_power_smart.c45
6 files changed, 58 insertions, 59 deletions
diff --git a/board/kahlee/board.c b/board/kahlee/board.c
index f612c0071a..843f035f5f 100644
--- a/board/kahlee/board.c
+++ b/board/kahlee/board.c
@@ -222,6 +222,10 @@ struct usb_mux usb_muxes[CONFIG_USB_PD_PORT_COUNT] = {
}
};
+const int usb_port_enable[CONFIG_USB_PORT_POWER_SMART_PORT_COUNT] = {
+ GPIO_USB1_ENABLE,
+};
+
/**
* Reset PD MCU -- currently only called from handle_pending_reboot() in
* common/power.c just before hard resetting the system. This logic is likely
diff --git a/board/reef/board.c b/board/reef/board.c
index 5db387f6b9..23247c4f95 100644
--- a/board/reef/board.c
+++ b/board/reef/board.c
@@ -299,6 +299,10 @@ struct usb_mux usb_muxes[CONFIG_USB_PD_PORT_COUNT] = {
}
};
+const int usb_port_enable[CONFIG_USB_PORT_POWER_SMART_PORT_COUNT] = {
+ GPIO_USB1_ENABLE,
+};
+
/* called from anx74xx_set_power_mode() */
void board_set_tcpc_power_mode(int port, int mode)
{
diff --git a/board/samus/board.c b/board/samus/board.c
index 53c56c9070..d6523c57bb 100644
--- a/board/samus/board.c
+++ b/board/samus/board.c
@@ -267,6 +267,11 @@ void board_reset_pd_mcu(void)
gpio_set_level(GPIO_USB_MCU_RST, 0);
}
+const int usb_port_enable[CONFIG_USB_PORT_POWER_SMART_PORT_COUNT] = {
+ GPIO_USB1_ENABLE,
+ GPIO_USB2_ENABLE,
+};
+
/* Base Sensor mutex */
static struct mutex g_base_mutex;
diff --git a/board/strago/board.c b/board/strago/board.c
index 6459488567..67e44be830 100644
--- a/board/strago/board.c
+++ b/board/strago/board.c
@@ -139,6 +139,11 @@ struct usb_mux usb_muxes[CONFIG_USB_PD_PORT_COUNT] = {
},
};
+const int usb_port_enable[CONFIG_USB_PORT_POWER_SMART_PORT_COUNT] = {
+ GPIO_USB1_ENABLE,
+ GPIO_USB2_ENABLE,
+};
+
/*
* Temperature sensors data; must be in same order as enum temp_sensor_id.
* Sensor index and name must match those present in coreboot:
diff --git a/common/usb_port_power_dumb.c b/common/usb_port_power_dumb.c
index 2db167fceb..b909fd1c41 100644
--- a/common/usb_port_power_dumb.c
+++ b/common/usb_port_power_dumb.c
@@ -21,32 +21,27 @@
#define USB_SYSJUMP_TAG 0x5550 /* "UP" - Usb Port */
#define USB_HOOK_VERSION 1
-/* We need to think about this a little more */
-BUILD_ASSERT(USB_PORT_COUNT == 2);
-
-static struct usb_state {
- uint8_t en[USB_PORT_COUNT];
-} state;
+static uint8_t charge_mode[USB_PORT_COUNT];
+extern const int usb_port_enable[USB_PORT_COUNT];
static void usb_port_set_enabled(int port_id, int en)
{
- if (port_id == 0)
- gpio_set_level(GPIO_USB1_ENABLE, en);
- else
- gpio_set_level(GPIO_USB2_ENABLE, en);
- state.en[port_id] = en;
+ gpio_set_level(usb_port_enable[port_id], en);
+ charge_mode[port_id] = en;
}
static void usb_port_all_ports_on(void)
{
- usb_port_set_enabled(0, 1);
- usb_port_set_enabled(1, 1);
+ int i;
+ for (i = 0; i < USB_PORT_COUNT; i++)
+ usb_port_set_enabled(i, 1);
}
static void usb_port_all_ports_off(void)
{
- usb_port_set_enabled(0, 0);
- usb_port_set_enabled(1, 0);
+ int i;
+ for (i = 0; i < USB_PORT_COUNT; i++)
+ usb_port_set_enabled(i, 0);
}
/*****************************************************************************/
@@ -93,6 +88,7 @@ static int command_set_mode(int argc, char **argv)
{
int port_id = -1;
int mode = -1;
+ int i;
char *e;
switch (argc) {
@@ -107,9 +103,9 @@ static int command_set_mode(int argc, char **argv)
usb_port_set_enabled(port_id, mode);
/* fallthrough */
case 1:
- ccprintf("Port 0: %s\nPort 1: %s\n",
- state.en[0] ? "on" : "off",
- state.en[1] ? "on" : "off");
+ for (i = 0; i < USB_PORT_COUNT; i++)
+ ccprintf("Port %d: %s\n",
+ i, charge_mode[i] ? "on" : "off");
return EC_SUCCESS;
}
@@ -126,23 +122,25 @@ DECLARE_CONSOLE_COMMAND(usbchargemode, command_set_mode,
static void usb_port_preserve_state(void)
{
system_add_jump_tag(USB_SYSJUMP_TAG, USB_HOOK_VERSION,
- sizeof(state), &state);
+ sizeof(charge_mode), charge_mode);
}
DECLARE_HOOK(HOOK_SYSJUMP, usb_port_preserve_state, HOOK_PRIO_DEFAULT);
static void usb_port_init(void)
{
- const struct usb_state *prev;
- int version, size;
-
- prev = (const struct usb_state *)system_get_jump_tag(USB_SYSJUMP_TAG,
- &version, &size);
- if (prev && version == USB_HOOK_VERSION && size == sizeof(*prev)) {
- usb_port_set_enabled(0, prev->en[0]);
- usb_port_set_enabled(1, prev->en[1]);
- } else {
+ const uint8_t *prev;
+ int version, size, i;
+
+ prev = (const uint8_t *)system_get_jump_tag(USB_SYSJUMP_TAG,
+ &version, &size);
+ if (!prev || version != USB_HOOK_VERSION ||
+ size != sizeof(charge_mode)) {
usb_port_all_ports_off();
+ return;
}
+
+ for (i = 0; i < USB_PORT_COUNT; i++)
+ usb_port_set_enabled(i, prev[i]);
}
DECLARE_HOOK(HOOK_INIT, usb_port_init, HOOK_PRIO_DEFAULT);
diff --git a/common/usb_port_power_smart.c b/common/usb_port_power_smart.c
index 86836df96d..fb9e1e1230 100644
--- a/common/usb_port_power_smart.c
+++ b/common/usb_port_power_smart.c
@@ -25,13 +25,11 @@
#define CONFIG_USB_PORT_POWER_SMART_DEFAULT_MODE USB_CHARGE_MODE_SDP2
#endif
-/* The previous USB port state before sys jump */
-struct usb_state {
- uint8_t port_mode[CONFIG_USB_PORT_POWER_SMART_PORT_COUNT];
-};
-
static uint8_t charge_mode[CONFIG_USB_PORT_POWER_SMART_PORT_COUNT];
+/* GPIOs to enable/disable USB ports. Board specific. */
+extern const int usb_port_enable[CONFIG_USB_PORT_POWER_SMART_PORT_COUNT];
+
static void usb_charge_set_control_mode(int port_id, int mode)
{
#ifdef CONFIG_USB_PORT_POWER_SMART_SIMPLE
@@ -57,18 +55,7 @@ static void usb_charge_set_control_mode(int port_id, int mode)
static void usb_charge_set_enabled(int port_id, int en)
{
ASSERT(port_id < CONFIG_USB_PORT_POWER_SMART_PORT_COUNT);
-#if CONFIG_USB_PORT_POWER_SMART_PORT_COUNT >= 1
- if (port_id == 0)
- gpio_set_level(GPIO_USB1_ENABLE, en);
-#endif
-#if CONFIG_USB_PORT_POWER_SMART_PORT_COUNT >= 2
- if (port_id == 1)
- gpio_set_level(GPIO_USB2_ENABLE, en);
-#endif
-#if CONFIG_USB_PORT_POWER_SMART_PORT_COUNT >= 3
- if (port_id == 2)
- gpio_set_level(GPIO_USB3_ENABLE, en);
-#endif
+ gpio_set_level(usb_port_enable[port_id], en);
}
static void usb_charge_set_ilim(int port_id, int sel)
@@ -195,31 +182,27 @@ DECLARE_HOST_COMMAND(EC_CMD_USB_CHARGE_SET_MODE,
static void usb_charge_preserve_state(void)
{
- struct usb_state state;
- int i;
-
- for (i = 0; i < CONFIG_USB_PORT_POWER_SMART_PORT_COUNT; i++)
- state.port_mode[i] = charge_mode[i];
-
system_add_jump_tag(USB_SYSJUMP_TAG, USB_HOOK_VERSION,
- sizeof(state), &state);
+ sizeof(charge_mode), charge_mode);
}
DECLARE_HOOK(HOOK_SYSJUMP, usb_charge_preserve_state, HOOK_PRIO_DEFAULT);
static void usb_charge_init(void)
{
- const struct usb_state *prev;
+ const uint8_t *prev;
int version, size, i;
- prev = (const struct usb_state *)system_get_jump_tag(USB_SYSJUMP_TAG,
- &version, &size);
+ prev = (const uint8_t *)system_get_jump_tag(USB_SYSJUMP_TAG,
+ &version, &size);
- if (prev && version == USB_HOOK_VERSION && size == sizeof(*prev)) {
- for (i = 0; i < CONFIG_USB_PORT_POWER_SMART_PORT_COUNT; i++)
- usb_charge_set_mode(i, prev->port_mode[i]);
- } else {
+ if (!prev || version != USB_HOOK_VERSION ||
+ size != sizeof(charge_mode)) {
usb_charge_all_ports_ctrl(USB_CHARGE_MODE_DISABLED);
+ return;
}
+
+ for (i = 0; i < CONFIG_USB_PORT_POWER_SMART_PORT_COUNT; i++)
+ usb_charge_set_mode(i, prev[i]);
}
DECLARE_HOOK(HOOK_INIT, usb_charge_init, HOOK_PRIO_DEFAULT);