summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorRandall Spangler <rspangler@chromium.org>2014-02-11 15:33:46 -0800
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2014-02-22 00:50:37 +0000
commit930b41e6a9782e7c8e37f3a283de2e8a3164b155 (patch)
tree5eaf1d7071aaad8e63e5e46ca778cb1aa9a41158 /common
parentff711e4a475c917df0cb38ef747bd4207a513591 (diff)
downloadchrome-ec-930b41e6a9782e7c8e37f3a283de2e8a3164b155.tar.gz
Allow AP to set wireless power state in suspend
Previously, the AP could only set the current wireless power state. It couldn't determine what the EC would do in S3, nor could it get the current wireless power state. Extend the wireless command to do so, and add an EC console command to aid in debugging. BUG=chrome-os-partner:25655 BRANCH=rambi TEST=manual; expected numbers are from EC 'wireless' command AP off -> 0x0, 0x9 AP on -> 0xd 0x9 AP suspended -> 0x9 0x9 AP on -> 0xd 0x9 ectool wireless 0x1 -> 0x1 0x9 ectool wireless 0xd -> 0xd 0x9 ectool wireless 0 0 0 0 -> 0xd 0x9 (and prints 0xd 0x9 to root shell) ectool wireless 5 -1 -1 0 -> 0x5 0x9 AP suspended -> 0x1 0x9 (doesn't turn on 0x8, just turns off 0x4) AP on -> 0xd 0x9 ectool wireless 0 0 0 -1 -> 0xd 0x0 AP suspended -> 0x0 0x0 AP on -> 0xd 0x9 Change-Id: I8ead2d4a4423b51ec4f638bf94c62de98726b25c Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/187273
Diffstat (limited to 'common')
-rw-r--r--common/wireless.c123
1 files changed, 119 insertions, 4 deletions
diff --git a/common/wireless.c b/common/wireless.c
index 2344f08cd5..54a0689906 100644
--- a/common/wireless.c
+++ b/common/wireless.c
@@ -6,10 +6,32 @@
/* Wireless power management */
#include "common.h"
+#include "console.h"
#include "gpio.h"
#include "host_command.h"
+#include "util.h"
+#include "wireless.h"
-void wireless_enable(int flags)
+/* Unless told otherwise, disable wireless in suspend */
+#ifndef CONFIG_WIRELESS_SUSPEND
+#define CONFIG_WIRELESS_SUSPEND 0
+#endif
+
+/*
+ * Flags which will be left on when suspending. Other flags will be disabled
+ * when suspending.
+ */
+static int suspend_flags = CONFIG_WIRELESS_SUSPEND;
+
+/**
+ * Set wireless switch state.
+ *
+ * @param flags Enable flags from ec_commands.h (EC_WIRELESS_SWITCH_*),
+ * 0 to turn all wireless off, or -1 to turn all wireless
+ * on.
+ * @param mask Which of those flags to set
+ */
+static void wireless_enable(int flags)
{
#ifdef WIRELESS_GPIO_WLAN
gpio_set_level(WIRELESS_GPIO_WLAN,
@@ -33,14 +55,107 @@ void wireless_enable(int flags)
}
+static int wireless_get(void)
+{
+ int flags = 0;
+
+#ifdef WIRELESS_GPIO_WLAN
+ if (gpio_get_level(WIRELESS_GPIO_WLAN))
+ flags |= EC_WIRELESS_SWITCH_WLAN;
+#endif
+
+#ifdef WIRELESS_GPIO_WWAN
+ if (gpio_get_level(WIRELESS_GPIO_WWAN))
+ flags |= EC_WIRELESS_SWITCH_WWAN;
+#endif
+
+#ifdef WIRELESS_GPIO_BLUETOOTH
+ if (gpio_get_level(WIRELESS_GPIO_BLUETOOTH))
+ flags |= EC_WIRELESS_SWITCH_BLUETOOTH;
+#endif
+
+#ifdef WIRELESS_GPIO_WLAN_POWER
+ if (gpio_get_level(WIRELESS_GPIO_WLAN_POWER))
+ flags |= EC_WIRELESS_SWITCH_WLAN_POWER;
+#endif
+
+ return flags;
+}
+
+void wireless_set_state(enum wireless_power_state state)
+{
+ switch (state) {
+ case WIRELESS_OFF:
+ wireless_enable(0);
+ break;
+ case WIRELESS_SUSPEND:
+ /*
+ * When suspending, only turn things off. If the AP has
+ * disabled WiFi power, going into S3 should not re-enable it.
+ */
+ wireless_enable(wireless_get() & suspend_flags);
+ break;
+ case WIRELESS_ON:
+ wireless_enable(EC_WIRELESS_SWITCH_ALL);
+ break;
+ }
+}
+
static int wireless_enable_cmd(struct host_cmd_handler_args *args)
{
- const struct ec_params_switch_enable_wireless *p = args->params;
+ const struct ec_params_switch_enable_wireless_v1 *p = args->params;
+ struct ec_response_switch_enable_wireless_v1 *r = args->response;
+
+ if (args->version == 0) {
+ /* Ver.0 command just set all current flags */
+ wireless_enable(p->now_flags);
+ return EC_RES_SUCCESS;
+ }
- wireless_enable(p->enabled);
+ /* Ver.1 can set flags based on mask */
+ wireless_enable((wireless_get() & ~p->now_mask) |
+ (p->now_flags & p->now_mask));
+ suspend_flags = (suspend_flags & ~p->suspend_mask) |
+ (p->suspend_flags & p->suspend_mask);
+
+ /* And return the current flags */
+ r->now_flags = wireless_get();
+ r->suspend_flags = suspend_flags;
+ args->response_size = sizeof(*r);
return EC_RES_SUCCESS;
}
DECLARE_HOST_COMMAND(EC_CMD_SWITCH_ENABLE_WIRELESS,
wireless_enable_cmd,
- EC_VER_MASK(0));
+ EC_VER_MASK(0) | EC_VER_MASK(1));
+
+static int command_wireless(int argc, char **argv)
+{
+ char *e;
+ int i;
+
+ if (argc >= 2) {
+ i = strtoi(argv[1], &e, 0);
+ if (*e)
+ return EC_ERROR_PARAM1;
+
+ wireless_enable(i);
+ }
+
+ if (argc >= 3) {
+ i = strtoi(argv[2], &e, 0);
+ if (*e)
+ return EC_ERROR_PARAM2;
+
+ suspend_flags = i;
+ }
+
+ ccprintf("Wireless flags: now=0x%x, suspend=0x%x\n", wireless_get(),
+ suspend_flags);
+
+ return EC_SUCCESS;
+}
+DECLARE_CONSOLE_COMMAND(wireless, command_wireless,
+ "[now [suspend]]",
+ "Get/set wireless flags",
+ NULL);