lkml.org 
[lkml]   [2019]   [Apr]   [5]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 3/3] platform/chrome: wilco_ec: Add Boot on AC support
Date
Boot on AC is a policy which makes the device boot from S5 when AC
power is connected. This is useful for users who want to run their
device headless or with a dock.

Signed-off-by: Nick Crews <ncrews@chromium.org>
---
drivers/platform/chrome/wilco_ec/sysfs.c | 52 ++++++++++++++++++++++++
1 file changed, 52 insertions(+)

diff --git a/drivers/platform/chrome/wilco_ec/sysfs.c b/drivers/platform/chrome/wilco_ec/sysfs.c
index ec5211257a58..52cbdb1f30b6 100644
--- a/drivers/platform/chrome/wilco_ec/sysfs.c
+++ b/drivers/platform/chrome/wilco_ec/sysfs.c
@@ -5,6 +5,10 @@
* Sysfs properties used to modify EC-controlled features on Wilco devices.
* The entries will appear under /sys/bus/platform/devices/GOOG000C:00/
*
+ * Boot on AC is a policy which makes the device boot from S5 when AC
+ * power is connected. This is useful for users who want to run their
+ * device headless or with a dock.
+ *
* USB PowerShare is a policy which affects charging via the special
* USB PowerShare port (marked with a small lightning bolt or battery icon)
* when in low power states:
@@ -18,6 +22,18 @@
#include <linux/platform_data/wilco-ec.h>
#include <linux/sysfs.h>

+#define CMD_KB_CMOS 0x7C
+#define SUB_CMD_KB_CMOS_AUTO_ON 0x03
+
+struct boot_on_ac_request {
+ u8 cmd; /* Always CMD_KB_CMOS */
+ u8 reserved1;
+ u8 sub_cmd; /* Always SUB_CMD_KB_CMOS_AUTO_ON */
+ u8 reserved3to5[3];
+ u8 val; /* Either 0 or 1*/
+ u8 reserved7;
+} __packed;
+
#define CMD_USB_POWER_SHARE 0x39

enum usb_power_share_op {
@@ -38,6 +54,41 @@ struct usb_power_share_response {
u8 val; /* When getting, set by EC to either 0 or 1 */
} __packed;

+static ssize_t boot_on_ac_store(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t count)
+{
+ struct wilco_ec_device *ec = dev_get_drvdata(dev);
+ struct boot_on_ac_request rq;
+ struct wilco_ec_message msg;
+ int ret;
+ u8 val;
+
+ ret = kstrtou8(buf, 10, &val);
+ if (ret < 0)
+ return ret;
+
+ if (val != 0 && val != 1)
+ return -EINVAL;
+
+ memset(&rq, 0, sizeof(rq));
+ rq.cmd = CMD_KB_CMOS;
+ rq.sub_cmd = SUB_CMD_KB_CMOS_AUTO_ON;
+ rq.val = val;
+
+ memset(&msg, 0, sizeof(msg));
+ msg.type = WILCO_EC_MSG_LEGACY;
+ msg.request_data = &rq;
+ msg.request_size = sizeof(rq);
+ ret = wilco_ec_mailbox(ec, &msg);
+ if (ret < 0)
+ return ret;
+
+ return count;
+}
+
+static DEVICE_ATTR_WO(boot_on_ac);
+
static int send_usb_power_share(struct wilco_ec_device *ec,
struct usb_power_share_request *rq,
struct usb_power_share_response *rs)
@@ -110,6 +161,7 @@ static ssize_t usb_power_share_store(struct device *dev,
static DEVICE_ATTR_RW(usb_power_share);

static struct attribute *wilco_dev_attrs[] = {
+ &dev_attr_boot_on_ac.attr,
&dev_attr_usb_power_share.attr,
NULL,
};
--
2.20.1
\
 
 \ /
  Last update: 2019-04-05 22:09    [W:0.076 / U:4.384 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site