mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Nick Crews <ncrews@chromium.org>
To: enric.balletbo@collabora.com, bleung@chromium.org
Cc: linux-kernel@vger.kernel.org, dlaurie@chromium.org,
	derat@google.com, groeck@google.com, dtor@google.com,
	lamzin@google.com, sjg@gchromium.org,
	Nick Crews <ncrews@chromium.org>
Subject: [PATCH 3/3] platform/chrome: wilco_ec: Add Boot on AC support
Date: Fri,  5 Apr 2019 14:07:42 -0600	[thread overview]
Message-ID: <20190405200742.107973-3-ncrews@chromium.org> (raw)
In-Reply-To: <20190405200742.107973-1-ncrews@chromium.org>

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


  parent reply	other threads:[~2019-04-05 20:08 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-05 20:07 [PATCH 1/3] platform/chrome: wilco_ec: Standardize mailbox interface Nick Crews
2019-04-05 20:07 ` [PATCH 2/3] platform/chrome: wilco_ec: Add USB PowerShare Policy control Nick Crews
2019-04-05 20:07 ` Nick Crews [this message]
2019-04-05 21:21 ` [PATCH 1/3] platform/chrome: wilco_ec: Standardize mailbox interface Enric Balletbo Serra
2019-04-05 21:43   ` Nick Crews

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190405200742.107973-3-ncrews@chromium.org \
    --to=ncrews@chromium.org \
    --cc=bleung@chromium.org \
    --cc=derat@google.com \
    --cc=dlaurie@chromium.org \
    --cc=dtor@google.com \
    --cc=enric.balletbo@collabora.com \
    --cc=groeck@google.com \
    --cc=lamzin@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sjg@gchromium.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®