[PATCH V5] platform/chrome: mfd/cros_ec_dev: Add sysfile to force

2019-03-08 Thread RaviChandra Sadineni
On chromebooks, power_manager daemon normally shuts down(S5) the device
when the battery charge falls below 4% threshold. ChromeOS EC then
normally spends an hour in S5 before hibernating. If the battery charge
falls below critical threshold in the mean time, EC does a battery cutoff
instead of hibernating. On some chromebooks, S5 is optimal enough
resulting in EC hibernating without battery cutoff. This results in
battery deep discharging. This is a bad user experience as battery
has to trickle charge before booting when the AC is plugged in the next
time.

This patch exposes a sysfs file for an userland daemon to suggest EC if it
has to do a battery cutoff instead of hibernating when the system enters
S5 next time.

This attribute is present only if EC supports EC_FEATURE_BATTERY.

Signed-off-by: RaviChandra Sadineni 
---
V5: Expose flag only when EC_FEATURE_BATTERY is supported.
V4: Addressed comments from Enric.
V3: Make battery-cutoff generic and expose 'at-shutdown' flag.
V2: Use kstrtobool() instead of kstrtou8() and add documentation.

.../ABI/testing/sysfs-class-chromeos  | 16 ++
 drivers/mfd/cros_ec_dev.c |  4 ++
 drivers/platform/chrome/cros_ec_sysfs.c   | 49 +++
 include/linux/mfd/cros_ec.h   |  2 +
 4 files changed, 71 insertions(+)

diff --git a/Documentation/ABI/testing/sysfs-class-chromeos 
b/Documentation/ABI/testing/sysfs-class-chromeos
index 5819699d66ec..0927704d1629 100644
--- a/Documentation/ABI/testing/sysfs-class-chromeos
+++ b/Documentation/ABI/testing/sysfs-class-chromeos
@@ -30,3 +30,19 @@ Date:August 2015
 KernelVersion: 4.2
 Description:
Show the information about the EC software and hardware.
+
+What:   /sys/class/chromeos//battery_cuttoff
+Date:   February 2019
+Contact:Ravi Chandra Sadineni 
+Description:
+cros_ec battery cuttoff configuration. Only option
+currently exposed is 'at-shutdown'.
+
+'at-shutdown' sends a host command to EC requesting
+battery cutoff on next shutdown. If AC is plugged
+in before next shutdown, EC ignores the request and
+resets the flag.
+
+Currently EC does not expose a host command to read
+the status of battery cutoff configuration. Thus this
+flag is write-only.
diff --git a/drivers/mfd/cros_ec_dev.c b/drivers/mfd/cros_ec_dev.c
index ed809fc97df8..7580be23dfb3 100644
--- a/drivers/mfd/cros_ec_dev.c
+++ b/drivers/mfd/cros_ec_dev.c
@@ -502,6 +502,10 @@ static int ec_device_probe(struct platform_device *pdev)
 retval);
}
 
+   /* check whether EC_FEATURE_BATTERY is supported. */
+   if (cros_ec_check_features(ec, EC_FEATURE_BATTERY))
+   ec->has_battery = true;
+
return 0;
 
 failed:
diff --git a/drivers/platform/chrome/cros_ec_sysfs.c 
b/drivers/platform/chrome/cros_ec_sysfs.c
index fe0b7614ae1b..3d9ab55dddc0 100644
--- a/drivers/platform/chrome/cros_ec_sysfs.c
+++ b/drivers/platform/chrome/cros_ec_sysfs.c
@@ -308,14 +308,61 @@ static ssize_t kb_wake_angle_store(struct device *dev,
return count;
 }
 
+/* Battery cutoff control */
+static ssize_t battery_cutoff_store(struct device *dev,
+   struct device_attribute *attr,
+   const char *buf, size_t count)
+{
+   struct ec_params_battery_cutoff *param;
+   struct cros_ec_command *msg;
+   int ret;
+   struct cros_ec_dev *ec = to_cros_ec_dev(dev);
+   char *p;
+   int len;
+
+   msg = kmalloc(sizeof(*msg) + EC_HOST_PARAM_SIZE, GFP_KERNEL);
+   if (!msg)
+   return -ENOMEM;
+
+   param = (struct ec_params_battery_cutoff *)msg->data;
+   msg->command = EC_CMD_BATTERY_CUT_OFF + ec->cmd_offset;
+   msg->version = 1;
+   msg->outsize = sizeof(*param);
+   msg->insize = 0;
+
+   p = memchr(buf, '\n', count);
+   len = p ? p - buf : count;
+
+   if (len == 11 && !strncmp(buf, "at-shutdown", len)) {
+   param->flags = EC_BATTERY_CUTOFF_FLAG_AT_SHUTDOWN;
+   } else {
+   count = -EINVAL;
+   goto exit;
+   }
+
+   ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
+   if (ret < 0)
+   count = ret;
+exit:
+   kfree(msg);
+   return count;
+}
+
 /* Module initialization */
 
 static DEVICE_ATTR_RW(reboot);
 static DEVICE_ATTR_RO(version);
 static DEVICE_ATTR_RO(flashinfo);
 static DEVICE_ATTR_RW(kb_wake_angle);
+/*
+ * Currently EC does not expose a host command to read the status of
+ * battery cutoff configuration. Also there is no requirement to read
+ * the flag from userland. So marking this attribute as write-only.
+ */
+static DEVICE_ATTR_WO(battery_cut

[PATCH V4] cros_ec: Expose sysfile to force battery cutoff on shutdown.

2019-03-07 Thread RaviChandra Sadineni
From: RaviChandra Sadineni 

On chromebooks, power_manager daemon normally shuts down(S5) the device
when the battery charge falls below 4% threshold. ChromeOS EC then
normally spends an hour in S5 before hibernating. If the battery charge
falls below critical threshold in the mean time, EC does a battery cutoff
instead of hibernating. On some chromebooks, S5 is optimal enough
resulting in EC hibernating without battery cutoff. This results in
battery deep discharging. This is a bad user experience as battery
has to trickle charge before booting when the AC is plugged in the next
time.

This patch exposes a sysfs file for an userland daemon to suggest EC if it
has to do a battery cutoff instead of hibernating when the system enters
S5 next time.

Signed-off-by: RaviChandra Sadineni 
---
V4: Addressed comments from Enric.
V3: Make battery-cutoff generic and expose 'at-shutdown' flag.
V2: Use kstrtobool() instead of kstrtou8() and add documentation.

.../ABI/testing/sysfs-class-chromeos  | 16 +++
 drivers/platform/chrome/cros_ec_sysfs.c   | 47 +++
 2 files changed, 63 insertions(+)

diff --git a/Documentation/ABI/testing/sysfs-class-chromeos 
b/Documentation/ABI/testing/sysfs-class-chromeos
index 5819699d66ec..0927704d1629 100644
--- a/Documentation/ABI/testing/sysfs-class-chromeos
+++ b/Documentation/ABI/testing/sysfs-class-chromeos
@@ -30,3 +30,19 @@ Date:August 2015
 KernelVersion: 4.2
 Description:
Show the information about the EC software and hardware.
+
+What:   /sys/class/chromeos//battery_cuttoff
+Date:   February 2019
+Contact:Ravi Chandra Sadineni 
+Description:
+cros_ec battery cuttoff configuration. Only option
+currently exposed is 'at-shutdown'.
+
+'at-shutdown' sends a host command to EC requesting
+battery cutoff on next shutdown. If AC is plugged
+in before next shutdown, EC ignores the request and
+resets the flag.
+
+Currently EC does not expose a host command to read
+the status of battery cutoff configuration. Thus this
+flag is write-only.
diff --git a/drivers/platform/chrome/cros_ec_sysfs.c 
b/drivers/platform/chrome/cros_ec_sysfs.c
index fe0b7614ae1b..a35e1188f28f 100644
--- a/drivers/platform/chrome/cros_ec_sysfs.c
+++ b/drivers/platform/chrome/cros_ec_sysfs.c
@@ -308,14 +308,61 @@ static ssize_t kb_wake_angle_store(struct device *dev,
return count;
 }
 
+/* Battery cutoff control */
+static ssize_t battery_cutoff_store(struct device *dev,
+   struct device_attribute *attr,
+   const char *buf, size_t count)
+{
+   struct ec_params_battery_cutoff *param;
+   struct cros_ec_command *msg;
+   int ret;
+   struct cros_ec_dev *ec = to_cros_ec_dev(dev);
+   char *p;
+   int len;
+
+   msg = kmalloc(sizeof(*msg) + EC_HOST_PARAM_SIZE, GFP_KERNEL);
+   if (!msg)
+   return -ENOMEM;
+
+   param = (struct ec_params_battery_cutoff *)msg->data;
+   msg->command = EC_CMD_BATTERY_CUT_OFF + ec->cmd_offset;
+   msg->version = 1;
+   msg->outsize = sizeof(*param);
+   msg->insize = 0;
+
+   p = memchr(buf, '\n', count);
+   len = p ? p - buf : count;
+
+   if (len == 11 && !strncmp(buf, "at-shutdown", len)) {
+   param->flags = EC_BATTERY_CUTOFF_FLAG_AT_SHUTDOWN;
+   } else {
+   count = -EINVAL;
+   goto exit;
+   }
+
+   ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
+   if (ret < 0)
+   count = ret;
+exit:
+   kfree(msg);
+   return count;
+}
+
 /* Module initialization */
 
 static DEVICE_ATTR_RW(reboot);
 static DEVICE_ATTR_RO(version);
 static DEVICE_ATTR_RO(flashinfo);
 static DEVICE_ATTR_RW(kb_wake_angle);
+/*
+ * Currently EC does not expose a host command to read the status of
+ * battery cutoff configuration. Also there is no requirement to read
+ * the flag from userland. So marking this attribute as write-only.
+ */
+static DEVICE_ATTR_WO(battery_cutoff);
 
 static struct attribute *__ec_attrs[] = {
+   &dev_attr_battery_cutoff.attr,
&dev_attr_kb_wake_angle.attr,
&dev_attr_reboot.attr,
&dev_attr_version.attr,
-- 
2.20.1



[PATCH V3] cros_ec: Expose sysfile to force battery cut-off on shutdown.

2019-03-04 Thread RaviChandra Sadineni
On chromebooks, power_manager daemon normally shutsdown(S5) the device
when the battery charge falls below 4% threshold. Chromeos EC then
normally spends an hour in S5 before hibernating. If the battery charge
falls below critical threshold in the mean time, EC does a battery cutoff
instead of hibernating. On some chromebooks, S5 is optimal enough
resulting in EC hibernating without battery cut-off. This results in
battery deep-discharging. This is a bad user experience as battery
has to trickle charge before booting when the A.C is plugged in the next
time.

This patch exposes a sysfs file for an userland daemon to suggest EC if it
has to do a battery cut-off instead of hibernating when the system enters
S5 next time.

Signed-off-by: RaviChandra Sadineni 
---

V3: Make battery-cutoff generic and expose 'at-shutdown' flag.
V2: Use kstrtobool() instead of kstrtou8() and add documentation.


.../ABI/testing/sysfs-class-chromeos  | 10 
 drivers/platform/chrome/cros_ec_sysfs.c   | 48 +++
 2 files changed, 58 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-class-chromeos

diff --git a/Documentation/ABI/testing/sysfs-class-chromeos 
b/Documentation/ABI/testing/sysfs-class-chromeos
new file mode 100644
index ..d5ab22c44977
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-class-chromeos
@@ -0,0 +1,10 @@
+What:   /sys/class/chromeos/cros_ec/battery-cuttoff
+Date:   February 2019
+Contact:Ravi Chandra Sadineni 
+Description:
+cros_ec battery cuttoff configuration. Only option
+currently exposed is 'at-shutdown'.
+
+'at-shutdown' sends a host command to EC requesting
+battery cutoff on next shutdown. If AC is plugged
+in before next shutdown, EC ignores the request.
diff --git a/drivers/platform/chrome/cros_ec_sysfs.c 
b/drivers/platform/chrome/cros_ec_sysfs.c
index f34a50121064..6ef6b860c818 100644
--- a/drivers/platform/chrome/cros_ec_sysfs.c
+++ b/drivers/platform/chrome/cros_ec_sysfs.c
@@ -322,14 +322,62 @@ static ssize_t kb_wake_angle_store(struct device *dev,
return count;
 }
 
+/* Battery cut-off control */
+static ssize_t battery_cutoff_store(struct device *dev,
+   struct device_attribute *attr,
+   const char *buf, size_t count)
+{
+   struct ec_params_battery_cutoff *param;
+   struct cros_ec_command *msg;
+   int ret;
+   struct cros_ec_dev *ec =
+   container_of(dev, struct cros_ec_dev, class_dev);
+   char *p;
+   int len;
+
+   msg = kmalloc(sizeof(*msg) + EC_HOST_PARAM_SIZE, GFP_KERNEL);
+   if (!msg)
+   return -ENOMEM;
+
+   param = (struct ec_params_battery_cutoff *)msg->data;
+   msg->command = EC_CMD_BATTERY_CUT_OFF + ec->cmd_offset;
+   msg->version = 1;
+   msg->outsize = sizeof(*param);
+   msg->insize = 0;
+
+   p = memchr(buf, '\n', count);
+   len = p ? p - buf : count;
+
+   if (len == 11 && !strncmp(buf, "at-shutdown", len)) {
+   param->flags = EC_BATTERY_CUTOFF_FLAG_AT_SHUTDOWN;
+   } else {
+   kfree(msg);
+   return -EINVAL;
+   }
+
+   ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
+   kfree(msg);
+   if (ret < 0)
+   return ret;
+   return count;
+}
+
 /* Module initialization */
 
 static DEVICE_ATTR_RW(reboot);
 static DEVICE_ATTR_RO(version);
 static DEVICE_ATTR_RO(flashinfo);
 static DEVICE_ATTR_RW(kb_wake_angle);
+/*
+ * Currently EC does not expose a host command to read the status of
+ * battery cut-off configuration. Also there is no requirement to read
+ * the status of these flags from userland. So marking this attribute as
+ *  write-only.
+ */
+static DEVICE_ATTR_WO(battery_cutoff);
 
 static struct attribute *__ec_attrs[] = {
+   &dev_attr_battery_cutoff.attr,
&dev_attr_kb_wake_angle.attr,
&dev_attr_reboot.attr,
&dev_attr_version.attr,
-- 
2.20.1


[PATCH V3] cros_ec: Expose sysfile to force battery cut-off on shutdown.

2019-03-04 Thread RaviChandra Sadineni
On chromebooks, power_manager daemon normally shutsdown(S5) the device
when the battery charge falls below 4% threshold. Chromeos EC then
normally spends an hour in S5 before hibernating. If the battery charge
falls below critical threshold in the mean time, EC does a battery cutoff
instead of hibernating. On some chromebooks, S5 is optimal enough
resulting in EC hibernating without battery cut-off. This results in
battery deep-discharging. This is a bad user experience as battery
has to trickle charge before booting when the A.C is plugged in the next
time.

This patch exposes a sysfs file for an userland daemon to suggest EC if it
has to do a battery cut-off instead of hibernating when the system enters
S5 next time.

Signed-off-by: RaviChandra Sadineni 
---

V3: Make battery-cutoff generic and expose 'at-shutdown' flag.
V2: Use kstrtobool() instead of kstrtou8() and add documentation.


.../ABI/testing/sysfs-class-chromeos  | 10 
 drivers/platform/chrome/cros_ec_sysfs.c   | 48 +++
 2 files changed, 58 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-class-chromeos

diff --git a/Documentation/ABI/testing/sysfs-class-chromeos 
b/Documentation/ABI/testing/sysfs-class-chromeos
new file mode 100644
index ..d5ab22c44977
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-class-chromeos
@@ -0,0 +1,10 @@
+What:   /sys/class/chromeos/cros_ec/battery-cuttoff
+Date:   February 2019
+Contact:Ravi Chandra Sadineni 
+Description:
+cros_ec battery cuttoff configuration. Only option
+currently exposed is 'at-shutdown'.
+
+'at-shutdown' sends a host command to EC requesting
+battery cutoff on next shutdown. If AC is plugged
+in before next shutdown, EC ignores the request.
diff --git a/drivers/platform/chrome/cros_ec_sysfs.c 
b/drivers/platform/chrome/cros_ec_sysfs.c
index f34a50121064..6ef6b860c818 100644
--- a/drivers/platform/chrome/cros_ec_sysfs.c
+++ b/drivers/platform/chrome/cros_ec_sysfs.c
@@ -322,14 +322,62 @@ static ssize_t kb_wake_angle_store(struct device *dev,
return count;
 }
 
+/* Battery cut-off control */
+static ssize_t battery_cutoff_store(struct device *dev,
+   struct device_attribute *attr,
+   const char *buf, size_t count)
+{
+   struct ec_params_battery_cutoff *param;
+   struct cros_ec_command *msg;
+   int ret;
+   struct cros_ec_dev *ec =
+   container_of(dev, struct cros_ec_dev, class_dev);
+   char *p;
+   int len;
+
+   msg = kmalloc(sizeof(*msg) + EC_HOST_PARAM_SIZE, GFP_KERNEL);
+   if (!msg)
+   return -ENOMEM;
+
+   param = (struct ec_params_battery_cutoff *)msg->data;
+   msg->command = EC_CMD_BATTERY_CUT_OFF + ec->cmd_offset;
+   msg->version = 1;
+   msg->outsize = sizeof(*param);
+   msg->insize = 0;
+
+   p = memchr(buf, '\n', count);
+   len = p ? p - buf : count;
+
+   if (len == 11 && !strncmp(buf, "at-shutdown", len)) {
+   param->flags = EC_BATTERY_CUTOFF_FLAG_AT_SHUTDOWN;
+   } else {
+   kfree(msg);
+   return -EINVAL;
+   }
+
+   ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
+   kfree(msg);
+   if (ret < 0)
+   return ret;
+   return count;
+}
+
 /* Module initialization */
 
 static DEVICE_ATTR_RW(reboot);
 static DEVICE_ATTR_RO(version);
 static DEVICE_ATTR_RO(flashinfo);
 static DEVICE_ATTR_RW(kb_wake_angle);
+/*
+ * Currently EC does not expose a host command to read the status of
+ * battery cut-off configuration. Also there is no requirement to read
+ * the status of these flags from userland. So marking this attribute as
+ *  write-only.
+ */
+static DEVICE_ATTR_WO(battery_cutoff);
 
 static struct attribute *__ec_attrs[] = {
+   &dev_attr_battery_cutoff.attr,
&dev_attr_kb_wake_angle.attr,
&dev_attr_reboot.attr,
&dev_attr_version.attr,
-- 
2.20.1
story | grep send-email


[PATCH V2] cros_ec: Expose sysfile to force battery cut-off on shutdown.

2019-03-03 Thread RaviChandra Sadineni
On chromebooks, power_manager daemon normally shutsdown(S5) the device
when the battery charge falls below 4% threshold. Chromeos EC then
normally spends an hour in S5 before hibernating. If the battery charge
falls below critical threshold in the mean time, EC does a battery cutoff
instead of hibernating. On some chromebooks, S5 is optimal enough
resulting in EC hibernating without battery cut-off. This results in
battery deep-discharging. This is a bad user experience as battery
has to trickle charge before booting when the A.C is plugged in the next
time.

This patch exposes a sysfs file for an userland daemon to suggest EC if it
has to do a battery cut-off instead of hibernating when the system enters
S5 next time.

Signed-off-by: RaviChandra Sadineni 
---
V2: Use kstrtobool() instead of kstrtou8() and add documentation.

 .../ABI/testing/sysfs-class-chromeos  |  8 
 drivers/platform/chrome/cros_ec_sysfs.c   | 37 +++
 2 files changed, 45 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-class-chromeos

diff --git a/Documentation/ABI/testing/sysfs-class-chromeos 
b/Documentation/ABI/testing/sysfs-class-chromeos
new file mode 100644
index ..44d3cee6e7ae
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-class-chromeos
@@ -0,0 +1,8 @@
+What:   /sys/class/chromeos/cros_ec/cutoff_at_shutdown
+Date:   February 2019
+Contact:Ravi Chandra Sadineni 
+Description:
+On writing '[Yy1]' to cutoff_at_shutdown property,
+kernel sends a host command to EC requesting battery
+cutoff on next shutdown. If AC is plugged in before
+next shutdown, EC resets this flag.
diff --git a/drivers/platform/chrome/cros_ec_sysfs.c 
b/drivers/platform/chrome/cros_ec_sysfs.c
index f34a50121064..f5168ce8bfc7 100644
--- a/drivers/platform/chrome/cros_ec_sysfs.c
+++ b/drivers/platform/chrome/cros_ec_sysfs.c
@@ -322,14 +322,51 @@ static ssize_t kb_wake_angle_store(struct device *dev,
return count;
 }
 
+/* Battery cut-off control */
+static ssize_t cutoff_at_shutdown_store(struct device *dev,
+  struct device_attribute *attr,
+  const char *buf, size_t count)
+{
+   struct ec_params_battery_cutoff *param;
+   struct cros_ec_command *msg;
+   int ret;
+   struct cros_ec_dev *ec = container_of(
+   dev, struct cros_ec_dev, class_dev);
+   bool cutoff_battery;
+
+   if (kstrtobool(buf, &cutoff_battery))
+   return -EINVAL;
+
+   if (!cutoff_battery)
+   return count;
+
+   msg = kmalloc(sizeof(*msg) + EC_HOST_PARAM_SIZE, GFP_KERNEL);
+   if (!msg)
+   return -ENOMEM;
+
+   param = (struct ec_params_battery_cutoff *)msg->data;
+   msg->command = EC_CMD_BATTERY_CUT_OFF + ec->cmd_offset;
+   msg->version = 1;
+   param->flags = EC_BATTERY_CUTOFF_FLAG_AT_SHUTDOWN;
+   msg->outsize = sizeof(*param);
+   msg->insize = 0;
+   ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
+   kfree(msg);
+   if (ret < 0)
+   return ret;
+   return count;
+}
+
 /* Module initialization */
 
 static DEVICE_ATTR_RW(reboot);
 static DEVICE_ATTR_RO(version);
 static DEVICE_ATTR_RO(flashinfo);
 static DEVICE_ATTR_RW(kb_wake_angle);
+static DEVICE_ATTR_WO(cutoff_at_shutdown);
 
 static struct attribute *__ec_attrs[] = {
+   &dev_attr_cutoff_battery_at_shutdown.attr,
&dev_attr_kb_wake_angle.attr,
&dev_attr_reboot.attr,
&dev_attr_version.attr,
-- 
2.20.1



[PATCH] cros_ec: Expose sysfile to force battery cut-off on shutdown.

2019-03-01 Thread RaviChandra Sadineni
On chromebooks, power_manager daemon normally shutsdown(S5) the device
when the battery charge falls below 4% threshold. ChromeOS EC then
normally spends an hour in S5 before hibernating. If the battery charge
falls below critical threshold in the mean time, EC does a battery cutoff
instead of hibernating. On some chromebooks, S5 is optimal enough
resulting in EC hibernating without battery cut-off. This results in
battery deep-discharging. This is a bad user experience as battery
has to trickle charge before booting when the A.C is plugged in the next
time.

This patch exposes a sysfs file for an userland daemon to suggest EC if it
has to do a battery cut-off instead of hibernating when the system enters
S5 next time.

Signed-off-by: RaviChandra Sadineni 
---
 drivers/platform/chrome/cros_ec_sysfs.c | 34 +
 1 file changed, 34 insertions(+)

diff --git a/drivers/platform/chrome/cros_ec_sysfs.c 
b/drivers/platform/chrome/cros_ec_sysfs.c
index f34a50121064..151c7c143941 100644
--- a/drivers/platform/chrome/cros_ec_sysfs.c
+++ b/drivers/platform/chrome/cros_ec_sysfs.c
@@ -322,14 +322,48 @@ static ssize_t kb_wake_angle_store(struct device *dev,
return count;
 }
 
+/* Battery cut-off control */
+static ssize_t cutoff_battery_at_shutdown_store(struct device *dev,
+  struct device_attribute *attr,
+  const char *buf, size_t count)
+{
+   struct ec_params_battery_cutoff *param;
+   struct cros_ec_command *msg;
+   int ret;
+   struct cros_ec_dev *ec = container_of(
+   dev, struct cros_ec_dev, class_dev);
+   uint8_t cutoff_battery;
+
+   if (kstrtou8(buf, 10, &cutoff_battery) || (cutoff_battery != 1))
+   return -EINVAL;
+
+   msg = kmalloc(sizeof(*msg) + EC_HOST_PARAM_SIZE, GFP_KERNEL);
+   if (!msg)
+   return -ENOMEM;
+
+   param = (struct ec_params_battery_cutoff *)msg->data;
+   msg->command = EC_CMD_BATTERY_CUT_OFF + ec->cmd_offset;
+   msg->version = 1;
+   param->flags = EC_BATTERY_CUTOFF_FLAG_AT_SHUTDOWN;
+   msg->outsize = sizeof(*param);
+   msg->insize = 0;
+   ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
+   kfree(msg);
+   if (ret < 0)
+   return ret;
+   return count;
+}
+
 /* Module initialization */
 
 static DEVICE_ATTR_RW(reboot);
 static DEVICE_ATTR_RO(version);
 static DEVICE_ATTR_RO(flashinfo);
 static DEVICE_ATTR_RW(kb_wake_angle);
+static DEVICE_ATTR_WO(cutoff_battery_at_shutdown);
 
 static struct attribute *__ec_attrs[] = {
+   &dev_attr_cutoff_battery_at_shutdown.attr,
&dev_attr_kb_wake_angle.attr,
&dev_attr_reboot.attr,
&dev_attr_version.attr,
-- 
2.20.1



mfd: cros_ec: Check for mkbp events on resume only if supported.

2018-08-20 Thread RaviChandra Sadineni
Currently on every resume we check for mkbp events and notify the
clients. This helps in identifying the wakeup sources. But on devices
that do not support mkbp protocol, we might end up querying key state of
the keyboard in a loop which blocks the resume. Instead check for events
only if mkbp is supported.

Signed-off-by: RaviChandra Sadineni 
---

 Note: This patch fixes the suspend/resume issue on Snow and Peach-Pit
 Chromebooks, both on vanilla v4.18 as well as linux-next from 20 August 
 2018. Further info at: https://lkml.org/lkml/2018/6/5/1076
 
 drivers/mfd/cros_ec.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/mfd/cros_ec.c b/drivers/mfd/cros_ec.c
index 65a9757a6d21..fe6f83766144 100644
--- a/drivers/mfd/cros_ec.c
+++ b/drivers/mfd/cros_ec.c
@@ -218,7 +218,8 @@ EXPORT_SYMBOL(cros_ec_suspend);
 
 static void cros_ec_report_events_during_suspend(struct cros_ec_device *ec_dev)
 {
-   while (cros_ec_get_next_event(ec_dev, NULL) > 0)
+   while (ec_dev->mkbp_event_supported &&
+  cros_ec_get_next_event(ec_dev, NULL) > 0)
blocking_notifier_call_chain(&ec_dev->event_notifier,
 1, ec_dev);
 }
-- 
2.16.4



Input: cros_ec_keyb: Remove check before calling pm_wakeup_event.

2018-08-17 Thread RaviChandra Sadineni
From: RaviChandra Sadineni 

hi Merek,

Unfortunately I could not get the device to boot even after using the 
exynos_defconfig. 
Can you please try this patch and see if this fixes the issue. If not can you 
enable the
debug logs and send me the logs.


Currently on every resume we check for mkbp events and notify the
clients. This helps in identifying the wakeup sources. But on devices
that do not support mkbp protocol, we might end up getting key state of
the keyboard in a loop and block the resume. Instead check for events only
if  mkbp is supported.

Signed-off-by: RaviChandra Sadineni 
---
 drivers/mfd/cros_ec.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/mfd/cros_ec.c b/drivers/mfd/cros_ec.c
index 65a9757a6d21..fe6f83766144 100644
--- a/drivers/mfd/cros_ec.c
+++ b/drivers/mfd/cros_ec.c
@@ -218,7 +218,8 @@ EXPORT_SYMBOL(cros_ec_suspend);
 
 static void cros_ec_report_events_during_suspend(struct cros_ec_device *ec_dev)
 {
-   while (cros_ec_get_next_event(ec_dev, NULL) > 0)
+   while (ec_dev->mkbp_event_supported &&
+  cros_ec_get_next_event(ec_dev, NULL) > 0)
blocking_notifier_call_chain(&ec_dev->event_notifier,
 1, ec_dev);
 }
-- 
2.16.4