[rtc-linux] [PATCH v3 0/4] mfd: cros-ec: Some fixes and improvements.

2017-07-12 Thread Enric Balletbo i Serra
Dear all,

Basically this is a resend and rebase due that [2] and [3] are currently
merged so all dependecies are in mainline now.

To remmember:

* 1/4 mfd: cros_ec: Get rid of cros_ec_check_features from cros_ec_dev.

As pointed by Lee Jones in this thread [1] we should not use the MFD API
outside of MFD. For this reason the cros-ec-rtc did not get accepted yet.
The reality is that we are calling mfd_add_devices from cros-ec-dev driver
already, so this patch get rid off the MFD calls inside the chardev driver
and moves to cros-ec MFD. Also I think the chardev device should simply
implement the ioctl calls to access to it from userspace.

The above patch involves MFD, IIO and platform chrome subsystems.

* 2/4 mfd: cros_ec: Introduce RTC commands and events definitions
* 3/4 rtc: cros-ec: add cros-ec-rtc driver
* 4/4 mfd: cros_ec: add RTC as mfd subdevice

These patches are the cros-ec RTC driver, 3 and 4 patches are already
acked by the subsystem maintainers involved and are equal to the last
version I send. Patch 5 registers the rtc cell inside the cros-ec MFD
intead of cros-ec-dev chardev driver.

Changes since v2:
- Rebase on top of mainline.
- Removed patch 'mfd: cros-ec: Fix host command buffer size' from series
as was already picked.

Changes since v1:
- Removed patch 'iio: cros_ec_sensors: Fix return value to get raw and
calibbias data' from series as was already picked.
- Removed patch 'iio: cros_ec_sensors: Fix return value to get raw and
calibbias data' from series as was already picked.
- Patch 2/5: Acked-by: Jonathan Cameron <***@kernel.org>

[1] https://www.spinics.net/lists/kernel/msg2465099.html
[2] https://lkml.org/lkml/2017/3/17/319
[3] https://lkml.org/lkml/2017/3/17/321

Best regards,

Enric Balletbo i Serra (1):
  mfd: cros_ec: Get rid of cros_ec_check_features from cros_ec_dev.

Stephen Barber (3):
  mfd: cros_ec: Introduce RTC commands and events definitions.
  rtc: cros-ec: add cros-ec-rtc driver.
  mfd: cros_ec: add RTC as mfd subdevice

 .../iio/common/cros_ec_sensors/cros_ec_sensors.c   |   8 -
 .../common/cros_ec_sensors/cros_ec_sensors_core.c  |   8 +-
 drivers/iio/light/cros_ec_light_prox.c |   8 -
 drivers/iio/pressure/cros_ec_baro.c|   8 -
 drivers/mfd/cros_ec.c  | 178 +
 drivers/platform/chrome/cros_ec_dev.c  | 161 
 drivers/rtc/Kconfig|  10 +
 drivers/rtc/Makefile   |   1 +
 drivers/rtc/rtc-cros-ec.c  | 412 +
 include/linux/mfd/cros_ec.h|   6 +-
 include/linux/mfd/cros_ec_commands.h   |   8 +
 11 files changed, 619 insertions(+), 189 deletions(-)
 create mode 100644 drivers/rtc/rtc-cros-ec.c

-- 
2.9.3

-- 
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
--- 
You received this message because you are subscribed to the Google Groups 
"rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rtc-linux+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[rtc-linux] [PATCH v3 2/4] mfd: cros_ec: Introduce RTC commands and events definitions.

2017-07-12 Thread Enric Balletbo i Serra
From: Stephen Barber 

The EC can function as a simple RT, this patch adds the RTC related
definitions needed by the rtc-cros-ec driver.

Signed-off-by: Stephen Barber 
Signed-off-by: Enric Balletbo i Serra 
Acked-by: Lee Jones 
---
 include/linux/mfd/cros_ec_commands.h | 8 
 1 file changed, 8 insertions(+)

diff --git a/include/linux/mfd/cros_ec_commands.h 
b/include/linux/mfd/cros_ec_commands.h
index 190c8f4..26ef492 100644
--- a/include/linux/mfd/cros_ec_commands.h
+++ b/include/linux/mfd/cros_ec_commands.h
@@ -286,6 +286,9 @@ enum host_event_code {
/* Hang detect logic detected a hang and warm rebooted the AP */
EC_HOST_EVENT_HANG_REBOOT = 21,
 
+   /* EC RTC event occurred */
+   EC_HOST_EVENT_RTC = 26,
+
/*
 * The high bit of the event mask is not used as a host event code.  If
 * it reads back as set, then the entire event mask should be
@@ -794,6 +797,8 @@ enum ec_feature_code {
EC_FEATURE_USB_MUX = 23,
/* Motion Sensor code has an internal software FIFO */
EC_FEATURE_MOTION_SENSE_FIFO = 24,
+   /* EC has RTC feature that can be controlled by host commands */
+   EC_FEATURE_RTC = 27,
 };
 
 #define EC_FEATURE_MASK_0(event_code) (1UL << (event_code % 32))
@@ -1704,6 +1709,9 @@ struct ec_response_rtc {
 #define EC_CMD_RTC_SET_VALUE 0x46
 #define EC_CMD_RTC_SET_ALARM 0x47
 
+/* Pass as param to SET_ALARM to clear the current alarm */
+#define EC_RTC_ALARM_CLEAR 0
+
 /*/
 /* Port80 log access */
 
-- 
2.9.3

-- 
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
--- 
You received this message because you are subscribed to the Google Groups 
"rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rtc-linux+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[rtc-linux] [PATCH v3 3/4] rtc: cros-ec: add cros-ec-rtc driver.

2017-07-12 Thread Enric Balletbo i Serra
From: Stephen Barber 

On platforms with a Chrome OS EC, the EC can function as a simple RTC.
Add a basic driver with this functionality.

Signed-off-by: Stephen Barber 
Signed-off-by: Enric Balletbo i Serra 
Acked-by: Alexandre Belloni 
---
 drivers/rtc/Kconfig   |  10 ++
 drivers/rtc/Makefile  |   1 +
 drivers/rtc/rtc-cros-ec.c | 412 ++
 3 files changed, 423 insertions(+)
 create mode 100644 drivers/rtc/rtc-cros-ec.c

diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index 8d3b957..c255f27 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -1204,6 +1204,16 @@ config RTC_DRV_ZYNQMP
  If you say yes here you get support for the RTC controller found on
  Xilinx Zynq Ultrascale+ MPSoC.
 
+config RTC_DRV_CROS_EC
+   tristate "Chrome OS EC RTC driver"
+   depends on MFD_CROS_EC
+   help
+ If you say yes here you will get support for the
+ Chrome OS Embedded Controller's RTC.
+
+ This driver can also be built as a module. If so, the module
+ will be called rtc-cros-ec.
+
 comment "on-CPU RTC drivers"
 
 config RTC_DRV_ASM9260
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index 13857d2..8162983 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -41,6 +41,7 @@ obj-$(CONFIG_RTC_DRV_BQ4802)  += rtc-bq4802.o
 obj-$(CONFIG_RTC_DRV_CMOS) += rtc-cmos.o
 obj-$(CONFIG_RTC_DRV_COH901331)+= rtc-coh901331.o
 obj-$(CONFIG_RTC_DRV_CPCAP)+= rtc-cpcap.o
+obj-$(CONFIG_RTC_DRV_CROS_EC)  += rtc-cros-ec.o
 obj-$(CONFIG_RTC_DRV_DA9052)   += rtc-da9052.o
 obj-$(CONFIG_RTC_DRV_DA9055)   += rtc-da9055.o
 obj-$(CONFIG_RTC_DRV_DA9063)   += rtc-da9063.o
diff --git a/drivers/rtc/rtc-cros-ec.c b/drivers/rtc/rtc-cros-ec.c
new file mode 100644
index 000..a5c2512
--- /dev/null
+++ b/drivers/rtc/rtc-cros-ec.c
@@ -0,0 +1,412 @@
+/*
+ * RTC driver for Chrome OS Embedded Controller
+ *
+ * Copyright (c) 2017, Google, Inc
+ *
+ * Author: Stephen Barber 
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define DRV_NAME   "cros-ec-rtc"
+
+/**
+ * struct cros_ec_rtc - Driver data for EC RTC
+ *
+ * @cros_ec: Pointer to EC device
+ * @rtc: Pointer to RTC device
+ * @notifier: Notifier info for responding to EC events
+ * @saved_alarm: Alarm to restore when interrupts are reenabled
+ */
+struct cros_ec_rtc {
+   struct cros_ec_device *cros_ec;
+   struct rtc_device *rtc;
+   struct notifier_block notifier;
+   u32 saved_alarm;
+};
+
+static int cros_ec_rtc_get(struct cros_ec_device *cros_ec, u32 command,
+  u32 *response)
+{
+   int ret;
+   struct {
+   struct cros_ec_command msg;
+   struct ec_response_rtc data;
+   } __packed msg;
+
+   memset(&msg, 0, sizeof(msg));
+   msg.msg.command = command;
+   msg.msg.insize = sizeof(msg.data);
+
+   ret = cros_ec_cmd_xfer_status(cros_ec, &msg.msg);
+   if (ret < 0) {
+   dev_err(cros_ec->dev,
+   "error getting %s from EC: %d\n",
+   command == EC_CMD_RTC_GET_VALUE ? "time" : "alarm",
+   ret);
+   return ret;
+   }
+
+   *response = msg.data.time;
+
+   return 0;
+}
+
+static int cros_ec_rtc_set(struct cros_ec_device *cros_ec, u32 command,
+  u32 param)
+{
+   int ret = 0;
+   struct {
+   struct cros_ec_command msg;
+   struct ec_response_rtc data;
+   } __packed msg;
+
+   memset(&msg, 0, sizeof(msg));
+   msg.msg.command = command;
+   msg.msg.outsize = sizeof(msg.data);
+   msg.data.time = param;
+
+   ret = cros_ec_cmd_xfer_status(cros_ec, &msg.msg);
+   if (ret < 0) {
+   dev_err(cros_ec->dev, "error setting %s on EC: %d\n",
+   command == EC_CMD_RTC_SET_VALUE ? "time" : "alarm",
+   ret);
+   return ret;
+   }
+
+   return 0;
+}
+
+/* Read the current time from the EC. */
+static int cros_ec_rtc_read_time(struct device *dev, struct rtc_time *tm)
+{
+   struct cros_ec_rtc *cros_ec_rtc = dev_get_drvdata(dev);
+   struct cros_ec_device *cros_ec = cros_ec_rtc->cros_ec;
+   int ret;
+   u32 time;
+
+   ret = cros_ec_rtc_get(cros_ec, EC_CMD_RTC_G

[rtc-linux] [PATCH v3 4/4] mfd: cros_ec: add RTC as mfd subdevice

2017-07-12 Thread Enric Balletbo i Serra
From: Stephen Barber 

If the EC supports RTC host commands, expose an RTC device.

Signed-off-by: Stephen Barber 
Signed-off-by: Enric Balletbo i Serra 
---
 drivers/mfd/cros_ec.c | 18 ++
 1 file changed, 18 insertions(+)

diff --git a/drivers/mfd/cros_ec.c b/drivers/mfd/cros_ec.c
index 75a27a6..ff972fb 100644
--- a/drivers/mfd/cros_ec.c
+++ b/drivers/mfd/cros_ec.c
@@ -51,6 +51,10 @@ static const struct mfd_cell ec_pd_cell = {
.pdata_size = sizeof(pd_p),
 };
 
+static const struct mfd_cell ec_rtc_cell = {
+   .name = "cros-ec-rtc",
+};
+
 static irqreturn_t ec_irq_thread(int irq, void *data)
 {
struct cros_ec_device *ec_dev = data;
@@ -245,6 +249,16 @@ static void cros_ec_sensors_register(struct cros_ec_device 
*ec_dev)
kfree(msg);
 }
 
+static void cros_ec_rtc_register(struct cros_ec_device *ec_dev)
+{
+   int ret;
+
+   ret = mfd_add_devices(ec_dev->dev, PLATFORM_DEVID_AUTO, &ec_rtc_cell,
+ 1, NULL, 0, NULL);
+   if (ret)
+   dev_err(ec_dev->dev, "failed to add EC RTC\n");
+}
+
 int cros_ec_register(struct cros_ec_device *ec_dev)
 {
struct device *dev = ec_dev->dev;
@@ -294,6 +308,10 @@ int cros_ec_register(struct cros_ec_device *ec_dev)
if (cros_ec_check_features(ec_dev, EC_FEATURE_MOTION_SENSE))
cros_ec_sensors_register(ec_dev);
 
+   /* Check whether this EC has RTC support */
+   if (cros_ec_check_features(ec_dev, EC_FEATURE_RTC))
+   cros_ec_rtc_register(ec_dev);
+
if (ec_dev->max_passthru) {
/*
 * Register a PD device as well on top of this device.
-- 
2.9.3

-- 
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
--- 
You received this message because you are subscribed to the Google Groups 
"rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rtc-linux+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[rtc-linux] [PATCH v3 1/4] mfd: cros_ec: Get rid of cros_ec_check_features from cros_ec_dev.

2017-07-12 Thread Enric Balletbo i Serra
The cros_ec_dev driver should be used only to expose the Chrome OS Embedded
Controller to user-space and should not be used to add MFD devices by
calling mfd_add_devices. This patch moves this logic to the MFD cros_ec
driver and removes the MFD bits from the character device driver. Also
makes independent the IIO driver from the character device as also has no
sense.

Signed-off-by: Enric Balletbo i Serra 
Acked-by: Jonathan Cameron 
---
 .../iio/common/cros_ec_sensors/cros_ec_sensors.c   |   8 -
 .../common/cros_ec_sensors/cros_ec_sensors_core.c  |   8 +-
 drivers/iio/light/cros_ec_light_prox.c |   8 -
 drivers/iio/pressure/cros_ec_baro.c|   8 -
 drivers/mfd/cros_ec.c  | 160 
 drivers/platform/chrome/cros_ec_dev.c  | 161 -
 include/linux/mfd/cros_ec.h|   6 +-
 7 files changed, 170 insertions(+), 189 deletions(-)

diff --git a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c 
b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c
index 38e8783..9b53a01 100644
--- a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c
+++ b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c
@@ -191,19 +191,11 @@ static const struct iio_info ec_sensors_info = {
 static int cros_ec_sensors_probe(struct platform_device *pdev)
 {
struct device *dev = &pdev->dev;
-   struct cros_ec_dev *ec_dev = dev_get_drvdata(dev->parent);
-   struct cros_ec_device *ec_device;
struct iio_dev *indio_dev;
struct cros_ec_sensors_state *state;
struct iio_chan_spec *channel;
int ret, i;
 
-   if (!ec_dev || !ec_dev->ec_dev) {
-   dev_warn(&pdev->dev, "No CROS EC device found.\n");
-   return -EINVAL;
-   }
-   ec_device = ec_dev->ec_dev;
-
indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*state));
if (!indio_dev)
return -ENOMEM;
diff --git a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c 
b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
index 416cae5..0cdb64a 100644
--- a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
+++ b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
@@ -41,12 +41,13 @@ int cros_ec_sensors_core_init(struct platform_device *pdev,
 {
struct device *dev = &pdev->dev;
struct cros_ec_sensors_core_state *state = iio_priv(indio_dev);
-   struct cros_ec_dev *ec = dev_get_drvdata(pdev->dev.parent);
+   struct cros_ec_device *ec_dev = dev_get_drvdata(pdev->dev.parent);
struct cros_ec_sensor_platform *sensor_platform = dev_get_platdata(dev);
 
platform_set_drvdata(pdev, indio_dev);
 
-   state->ec = ec->ec_dev;
+   state->ec = ec_dev;
+
state->msg = devm_kzalloc(&pdev->dev,
max((u16)sizeof(struct ec_params_motion_sense),
state->ec->max_response), GFP_KERNEL);
@@ -59,7 +60,8 @@ int cros_ec_sensors_core_init(struct platform_device *pdev,
 
/* Set up the host command structure. */
state->msg->version = 2;
-   state->msg->command = EC_CMD_MOTION_SENSE_CMD + ec->cmd_offset;
+   state->msg->command = EC_CMD_MOTION_SENSE_CMD +
+   sensor_platform->cmd_offset;
state->msg->outsize = sizeof(struct ec_params_motion_sense);
 
indio_dev->dev.parent = &pdev->dev;
diff --git a/drivers/iio/light/cros_ec_light_prox.c 
b/drivers/iio/light/cros_ec_light_prox.c
index 7217223..2133ddc 100644
--- a/drivers/iio/light/cros_ec_light_prox.c
+++ b/drivers/iio/light/cros_ec_light_prox.c
@@ -181,19 +181,11 @@ static const struct iio_info cros_ec_light_prox_info = {
 static int cros_ec_light_prox_probe(struct platform_device *pdev)
 {
struct device *dev = &pdev->dev;
-   struct cros_ec_dev *ec_dev = dev_get_drvdata(dev->parent);
-   struct cros_ec_device *ec_device;
struct iio_dev *indio_dev;
struct cros_ec_light_prox_state *state;
struct iio_chan_spec *channel;
int ret;
 
-   if (!ec_dev || !ec_dev->ec_dev) {
-   dev_warn(dev, "No CROS EC device found.\n");
-   return -EINVAL;
-   }
-   ec_device = ec_dev->ec_dev;
-
indio_dev = devm_iio_device_alloc(dev, sizeof(*state));
if (!indio_dev)
return -ENOMEM;
diff --git a/drivers/iio/pressure/cros_ec_baro.c 
b/drivers/iio/pressure/cros_ec_baro.c
index 48b2a30..dbea18b 100644
--- a/drivers/iio/pressure/cros_ec_baro.c
+++ b/drivers/iio/pressure/cros_ec_baro.c
@@ -126,19 +126,11 @@ static const struct iio_info cros_ec_baro_info = {
 static int cros_ec_baro_probe(struct platform_device *pdev)
 {
struct device *dev = &pdev->dev;
-   struct cros_ec_dev *ec_dev = dev_get_drvd

[rtc-linux] [PATCH v4 1/2] mfd: cros_ec: Introduce RTC commands and events definitions.

2017-11-10 Thread Enric Balletbo i Serra
From: Stephen Barber 

The EC can function as a simple RT, this patch adds the RTC related
definitions needed by the rtc-cros-ec driver.

Signed-off-by: Stephen Barber 
Signed-off-by: Enric Balletbo i Serra 
Acked-by: Lee Jones 
Acked-by: Benson Leung 
---
 include/linux/mfd/cros_ec_commands.h | 8 
 1 file changed, 8 insertions(+)

diff --git a/include/linux/mfd/cros_ec_commands.h 
b/include/linux/mfd/cros_ec_commands.h
index 2b16e95..c6046a2 100644
--- a/include/linux/mfd/cros_ec_commands.h
+++ b/include/linux/mfd/cros_ec_commands.h
@@ -291,6 +291,9 @@ enum host_event_code {
/* EC desires to change state of host-controlled USB mux */
EC_HOST_EVENT_USB_MUX = 28,
 
+   /* EC RTC event occurred */
+   EC_HOST_EVENT_RTC = 26,
+
/*
 * The high bit of the event mask is not used as a host event code.  If
 * it reads back as set, then the entire event mask should be
@@ -799,6 +802,8 @@ enum ec_feature_code {
EC_FEATURE_USB_MUX = 23,
/* Motion Sensor code has an internal software FIFO */
EC_FEATURE_MOTION_SENSE_FIFO = 24,
+   /* EC has RTC feature that can be controlled by host commands */
+   EC_FEATURE_RTC = 27,
 };
 
 #define EC_FEATURE_MASK_0(event_code) (1UL << (event_code % 32))
@@ -1709,6 +1714,9 @@ struct ec_response_rtc {
 #define EC_CMD_RTC_SET_VALUE 0x46
 #define EC_CMD_RTC_SET_ALARM 0x47
 
+/* Pass as param to SET_ALARM to clear the current alarm */
+#define EC_RTC_ALARM_CLEAR 0
+
 /*/
 /* Port80 log access */
 
-- 
2.9.3

-- 
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
--- 
You received this message because you are subscribed to the Google Groups 
"rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rtc-linux+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[rtc-linux] [PATCH v4 2/2] rtc: cros-ec: add cros-ec-rtc driver.

2017-11-10 Thread Enric Balletbo i Serra
From: Stephen Barber 

On platforms with a Chrome OS EC, the EC can function as a simple RTC.
Add a basic driver with this functionality.

Signed-off-by: Stephen Barber 
Signed-off-by: Enric Balletbo i Serra 
Acked-by: Alexandre Belloni 
Acked-by: Benson Leung 
---
 drivers/rtc/Kconfig   |  10 ++
 drivers/rtc/Makefile  |   1 +
 drivers/rtc/rtc-cros-ec.c | 413 ++
 3 files changed, 424 insertions(+)
 create mode 100644 drivers/rtc/rtc-cros-ec.c

diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index e0e58f3..f157288 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -1231,6 +1231,16 @@ config RTC_DRV_ZYNQMP
  If you say yes here you get support for the RTC controller found on
  Xilinx Zynq Ultrascale+ MPSoC.
 
+config RTC_DRV_CROS_EC
+   tristate "Chrome OS EC RTC driver"
+   depends on MFD_CROS_EC
+   help
+ If you say yes here you will get support for the
+ Chrome OS Embedded Controller's RTC.
+
+ This driver can also be built as a module. If so, the module
+ will be called rtc-cros-ec.
+
 comment "on-CPU RTC drivers"
 
 config RTC_DRV_ASM9260
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index 0bf1fc0..08789d7 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -44,6 +44,7 @@ obj-$(CONFIG_RTC_DRV_BQ4802)  += rtc-bq4802.o
 obj-$(CONFIG_RTC_DRV_CMOS) += rtc-cmos.o
 obj-$(CONFIG_RTC_DRV_COH901331)+= rtc-coh901331.o
 obj-$(CONFIG_RTC_DRV_CPCAP)+= rtc-cpcap.o
+obj-$(CONFIG_RTC_DRV_CROS_EC)  += rtc-cros-ec.o
 obj-$(CONFIG_RTC_DRV_DA9052)   += rtc-da9052.o
 obj-$(CONFIG_RTC_DRV_DA9055)   += rtc-da9055.o
 obj-$(CONFIG_RTC_DRV_DA9063)   += rtc-da9063.o
diff --git a/drivers/rtc/rtc-cros-ec.c b/drivers/rtc/rtc-cros-ec.c
new file mode 100644
index 000..f0ea689
--- /dev/null
+++ b/drivers/rtc/rtc-cros-ec.c
@@ -0,0 +1,413 @@
+/*
+ * RTC driver for Chrome OS Embedded Controller
+ *
+ * Copyright (c) 2017, Google, Inc
+ *
+ * Author: Stephen Barber 
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define DRV_NAME   "cros-ec-rtc"
+
+/**
+ * struct cros_ec_rtc - Driver data for EC RTC
+ *
+ * @cros_ec: Pointer to EC device
+ * @rtc: Pointer to RTC device
+ * @notifier: Notifier info for responding to EC events
+ * @saved_alarm: Alarm to restore when interrupts are reenabled
+ */
+struct cros_ec_rtc {
+   struct cros_ec_device *cros_ec;
+   struct rtc_device *rtc;
+   struct notifier_block notifier;
+   u32 saved_alarm;
+};
+
+static int cros_ec_rtc_get(struct cros_ec_device *cros_ec, u32 command,
+  u32 *response)
+{
+   int ret;
+   struct {
+   struct cros_ec_command msg;
+   struct ec_response_rtc data;
+   } __packed msg;
+
+   memset(&msg, 0, sizeof(msg));
+   msg.msg.command = command;
+   msg.msg.insize = sizeof(msg.data);
+
+   ret = cros_ec_cmd_xfer_status(cros_ec, &msg.msg);
+   if (ret < 0) {
+   dev_err(cros_ec->dev,
+   "error getting %s from EC: %d\n",
+   command == EC_CMD_RTC_GET_VALUE ? "time" : "alarm",
+   ret);
+   return ret;
+   }
+
+   *response = msg.data.time;
+
+   return 0;
+}
+
+static int cros_ec_rtc_set(struct cros_ec_device *cros_ec, u32 command,
+  u32 param)
+{
+   int ret = 0;
+   struct {
+   struct cros_ec_command msg;
+   struct ec_response_rtc data;
+   } __packed msg;
+
+   memset(&msg, 0, sizeof(msg));
+   msg.msg.command = command;
+   msg.msg.outsize = sizeof(msg.data);
+   msg.data.time = param;
+
+   ret = cros_ec_cmd_xfer_status(cros_ec, &msg.msg);
+   if (ret < 0) {
+   dev_err(cros_ec->dev, "error setting %s on EC: %d\n",
+   command == EC_CMD_RTC_SET_VALUE ? "time" : "alarm",
+   ret);
+   return ret;
+   }
+
+   return 0;
+}
+
+/* Read the current time from the EC. */
+static int cros_ec_rtc_read_time(struct device *dev, struct rtc_time *tm)
+{
+   struct cros_ec_rtc *cros_ec_rtc = dev_get_drvdata(dev);
+   struct cros_ec_device *cros_ec = cros_ec_rtc->cros_ec;
+   int ret;
+   u32 time;
+
+   ret = cros_ec_

[rtc-linux] [PATCH v4 0/2] Add support for cros-ec-rtc driver.

2017-11-10 Thread Enric Balletbo i Serra
Dear all,

This is an attempt to revive some patches from that [1] patchset, some
of them are still under discussion but I think there is no reason to not
have the other two in this fourth version to land upstream meanwhile we
discuss about the others.

[1] https://lkml.org/lkml/2017/7/12/182

Changes since v3:
* Rebased an retested with current mainline using a Samsung Chromebook Plus
* Removed from patchset
  * 1/4 mfd: cros_ec: Get rid of cros_ec_check_features from cros_ec_dev.
  * 4/4 mfd: cros_ec: add RTC as mfd subdevice.

Changes since v2:
- Rebase on top of mainline.
- Removed patch 'mfd: cros-ec: Fix host command buffer size' from series
as was already picked.

Changes since v1:
- Removed patch 'iio: cros_ec_sensors: Fix return value to get raw and
calibbias data' from series as was already picked.
- Removed patch 'iio: cros_ec_sensors: Fix return value to get raw and
calibbias data' from series as was already picked.
- Patch 2/5: Acked-by: Jonathan Cameron <***@kernel.org>

Best regards,

 Enric

Stephen Barber (2):
  mfd: cros_ec: Introduce RTC commands and events definitions.
  rtc: cros-ec: add cros-ec-rtc driver.

 drivers/rtc/Kconfig  |  10 +
 drivers/rtc/Makefile |   1 +
 drivers/rtc/rtc-cros-ec.c| 413 +++
 include/linux/mfd/cros_ec_commands.h |   8 +
 4 files changed, 432 insertions(+)
 create mode 100644 drivers/rtc/rtc-cros-ec.c

-- 
2.9.3

-- 
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
--- 
You received this message because you are subscribed to the Google Groups 
"rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rtc-linux+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[rtc-linux] [PATCH 1/4] mfd: cros_ec: Add helper for event notifier.

2017-01-11 Thread Enric Balletbo i Serra
From: Gwendal Grignou 

Add cros_ec_get_event() entry point to retrieve event within functions
called by the notifier.

Signed-off-by: Gwendal Grignou 
Signed-off-by: Enric Balletbo i Serra 
---
 drivers/platform/chrome/cros_ec_proto.c | 20 
 include/linux/mfd/cros_ec.h | 10 ++
 2 files changed, 30 insertions(+)

diff --git a/drivers/platform/chrome/cros_ec_proto.c 
b/drivers/platform/chrome/cros_ec_proto.c
index ed5dee7..7428c2b 100644
--- a/drivers/platform/chrome/cros_ec_proto.c
+++ b/drivers/platform/chrome/cros_ec_proto.c
@@ -494,3 +494,23 @@ int cros_ec_get_next_event(struct cros_ec_device *ec_dev)
return get_keyboard_state_event(ec_dev);
 }
 EXPORT_SYMBOL(cros_ec_get_next_event);
+
+u32 cros_ec_get_host_event(struct cros_ec_device *ec_dev)
+{
+   u32 host_event;
+
+   BUG_ON(!ec_dev->mkbp_event_supported);
+
+   if (ec_dev->event_data.event_type != EC_MKBP_EVENT_HOST_EVENT)
+   return 0;
+
+   if (ec_dev->event_size != sizeof(host_event)) {
+   dev_warn(ec_dev->dev, "Invalid host event size\n");
+   return 0;
+   }
+
+   host_event = get_unaligned_le32(&ec_dev->event_data.data.host_event);
+
+   return host_event;
+}
+EXPORT_SYMBOL(cros_ec_get_host_event);
diff --git a/include/linux/mfd/cros_ec.h b/include/linux/mfd/cros_ec.h
index b3d04de..be2c4eb 100644
--- a/include/linux/mfd/cros_ec.h
+++ b/include/linux/mfd/cros_ec.h
@@ -299,6 +299,16 @@ int cros_ec_query_all(struct cros_ec_device *ec_dev);
  */
 int cros_ec_get_next_event(struct cros_ec_device *ec_dev);
 
+/**
+ * cros_ec_get_host_event - Return a mask of event set by the EC.
+ *
+ * When MKBP is supported, when the EC raises an interrupt,
+ * We collect the events raised and call the functions in the ec notifier.
+ *
+ * This function is a helper to know which events are raised.
+ */
+u32 cros_ec_get_host_event(struct cros_ec_device *ec_dev);
+
 /* sysfs stuff */
 extern struct attribute_group cros_ec_attr_group;
 extern struct attribute_group cros_ec_lightbar_attr_group;
-- 
2.9.3

-- 
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
--- 
You received this message because you are subscribed to the Google Groups 
"rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rtc-linux+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[rtc-linux] [PATCH 4/4] mfd: cros_ec: add RTC as mfd subdevice

2017-01-11 Thread Enric Balletbo i Serra
From: Stephen Barber 

If the EC supports RTC host commands, expose an RTC device.

Signed-off-by: Stephen Barber 
Signed-off-by: Enric Balletbo i Serra 
---
 drivers/platform/chrome/cros_ec_dev.c | 22 ++
 1 file changed, 22 insertions(+)

diff --git a/drivers/platform/chrome/cros_ec_dev.c 
b/drivers/platform/chrome/cros_ec_dev.c
index 47268ec..ebe029d 100644
--- a/drivers/platform/chrome/cros_ec_dev.c
+++ b/drivers/platform/chrome/cros_ec_dev.c
@@ -383,6 +383,24 @@ static void cros_ec_sensors_register(struct cros_ec_dev 
*ec)
kfree(msg);
 }
 
+static const struct mfd_cell cros_ec_rtc_devs[] = {
+   {
+   .name = "cros-ec-rtc",
+   .id   = -1,
+   },
+};
+
+static void cros_ec_rtc_register(struct cros_ec_dev *ec)
+{
+   int ret;
+
+   ret = mfd_add_devices(ec->dev, 0, cros_ec_rtc_devs,
+ ARRAY_SIZE(cros_ec_rtc_devs),
+ NULL, 0, NULL);
+   if (ret)
+   dev_err(ec->dev, "failed to add cros-ec-rtc device: %d\n", ret);
+}
+
 static int ec_device_probe(struct platform_device *pdev)
 {
int retval = -ENOMEM;
@@ -441,6 +459,10 @@ static int ec_device_probe(struct platform_device *pdev)
if (cros_ec_check_features(ec, EC_FEATURE_MOTION_SENSE))
cros_ec_sensors_register(ec);
 
+   /* check whether this EC instance has RTC host command support */
+   if (cros_ec_check_features(ec, EC_FEATURE_RTC))
+   cros_ec_rtc_register(ec);
+
return 0;
 
 dev_reg_failed:
-- 
2.9.3

-- 
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
--- 
You received this message because you are subscribed to the Google Groups 
"rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rtc-linux+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[rtc-linux] [PATCH 2/4] mfd: cros_ec: Introduce RTC commands and events definitions.

2017-01-11 Thread Enric Balletbo i Serra
From: Stephen Barber 

The EC can function as a simple RT, this patch adds the RTC related
definitions needed by the rtc-cros-ec driver.

Signed-off-by: Stephen Barber 
Signed-off-by: Enric Balletbo i Serra 
---
 include/linux/mfd/cros_ec_commands.h | 8 
 1 file changed, 8 insertions(+)

diff --git a/include/linux/mfd/cros_ec_commands.h 
b/include/linux/mfd/cros_ec_commands.h
index 80d401d..73f7a62 100644
--- a/include/linux/mfd/cros_ec_commands.h
+++ b/include/linux/mfd/cros_ec_commands.h
@@ -286,6 +286,9 @@ enum host_event_code {
/* Hang detect logic detected a hang and warm rebooted the AP */
EC_HOST_EVENT_HANG_REBOOT = 21,
 
+   /* EC RTC event occurred */
+   EC_HOST_EVENT_RTC = 26,
+
/*
 * The high bit of the event mask is not used as a host event code.  If
 * it reads back as set, then the entire event mask should be
@@ -790,6 +793,8 @@ enum ec_feature_code {
EC_FEATURE_USB_MUX = 23,
/* Motion Sensor code has an internal software FIFO */
EC_FEATURE_MOTION_SENSE_FIFO = 24,
+   /* EC has RTC feature that can be controlled by host commands */
+   EC_FEATURE_RTC = 27,
 };
 
 #define EC_FEATURE_MASK_0(event_code) (1UL << (event_code % 32))
@@ -1682,6 +1687,9 @@ struct ec_response_rtc {
 #define EC_CMD_RTC_SET_VALUE 0x46
 #define EC_CMD_RTC_SET_ALARM 0x47
 
+/* Pass as param to SET_ALARM to clear the current alarm */
+#define EC_RTC_ALARM_CLEAR 0
+
 /*/
 /* Port80 log access */
 
-- 
2.9.3

-- 
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
--- 
You received this message because you are subscribed to the Google Groups 
"rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rtc-linux+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[rtc-linux] [PATCH 3/4] rtc: cros-ec: add cros-ec-rtc driver.

2017-01-11 Thread Enric Balletbo i Serra
From: Stephen Barber 

On platforms with a Chrome OS EC, the EC can function as a simple RTC.
Add a basic driver with this functionality.

Signed-off-by: Stephen Barber 
Signed-off-by: Enric Balletbo i Serra 
---
 drivers/rtc/Kconfig   |  10 ++
 drivers/rtc/Makefile  |   1 +
 drivers/rtc/rtc-cros-ec.c | 416 ++
 3 files changed, 427 insertions(+)
 create mode 100644 drivers/rtc/rtc-cros-ec.c

diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index c93c5a8..b58ce06 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -207,6 +207,16 @@ config RTC_DRV_AS3722
  This driver can also be built as a module. If so, the module
  will be called rtc-as3722.
 
+config RTC_DRV_CROS_EC
+   tristate "Chrome OS EC RTC driver"
+   depends on MFD_CROS_EC
+   help
+ If you say yes here you will get support for the
+ Chrome OS Embedded Controller's RTC.
+
+ This driver can also be built as a module. If so, the module
+ will be called rtc-cros-ec.
+
 config RTC_DRV_DS1307
tristate "Dallas/Maxim DS1307/37/38/39/40, ST M41T00, EPSON RX-8025, 
ISL12057"
help
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index f13ab1c..dd753e6 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -40,6 +40,7 @@ obj-$(CONFIG_RTC_DRV_BQ32K)   += rtc-bq32k.o
 obj-$(CONFIG_RTC_DRV_BQ4802)   += rtc-bq4802.o
 obj-$(CONFIG_RTC_DRV_CMOS) += rtc-cmos.o
 obj-$(CONFIG_RTC_DRV_COH901331)+= rtc-coh901331.o
+obj-$(CONFIG_RTC_DRV_CROS_EC)  += rtc-cros-ec.o
 obj-$(CONFIG_RTC_DRV_DA9052)   += rtc-da9052.o
 obj-$(CONFIG_RTC_DRV_DA9055)   += rtc-da9055.o
 obj-$(CONFIG_RTC_DRV_DA9063)   += rtc-da9063.o
diff --git a/drivers/rtc/rtc-cros-ec.c b/drivers/rtc/rtc-cros-ec.c
new file mode 100644
index 000..7a5d48c
--- /dev/null
+++ b/drivers/rtc/rtc-cros-ec.c
@@ -0,0 +1,416 @@
+/*
+ * RTC driver for Chrome OS Embedded Controller
+ *
+ * Copyright (c) 2017, Google, Inc
+ *
+ * Author: Stephen Barber 
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define DRV_NAME   "cros-ec-rtc"
+
+/**
+ * struct cros_ec_rtc - Driver data for EC RTC
+ *
+ * @cros_ec: Pointer to EC device
+ * @rtc: Pointer to RTC device
+ * @notifier: Notifier info for responding to EC events
+ * @saved_alarm: Alarm to restore when interrupts are reenabled
+ */
+struct cros_ec_rtc {
+   struct cros_ec_device *cros_ec;
+   struct rtc_device *rtc;
+   struct notifier_block notifier;
+   u32 saved_alarm;
+};
+
+static int cros_ec_rtc_get(struct cros_ec_device *cros_ec, u32 command,
+  u32 *response)
+{
+   int ret;
+   struct {
+   struct cros_ec_command msg;
+   struct ec_response_rtc data;
+   } __packed msg;
+
+   memset(&msg, 0, sizeof(msg));
+   msg.msg.command = command;
+   msg.msg.insize = sizeof(msg.data);
+
+   ret = cros_ec_cmd_xfer_status(cros_ec, &msg.msg);
+   if (ret < 0) {
+   dev_err(cros_ec->dev,
+   "error getting %s from EC: %d\n",
+   command == EC_CMD_RTC_GET_VALUE ? "time" : "alarm",
+   ret);
+   return ret;
+   }
+
+   *response = msg.data.time;
+
+   return 0;
+}
+
+static int cros_ec_rtc_set(struct cros_ec_device *cros_ec, u32 command,
+  u32 param)
+{
+   int ret = 0;
+   struct {
+   struct cros_ec_command msg;
+   struct ec_response_rtc data;
+   } __packed msg;
+
+   memset(&msg, 0, sizeof(msg));
+   msg.msg.command = command;
+   msg.msg.outsize = sizeof(msg.data);
+   msg.data.time = param;
+
+   ret = cros_ec_cmd_xfer_status(cros_ec, &msg.msg);
+   if (ret < 0) {
+   dev_err(cros_ec->dev, "error setting %s on EC: %d\n",
+   command == EC_CMD_RTC_SET_VALUE ? "time" : "alarm",
+   ret);
+   return ret;
+   }
+
+   return 0;
+}
+
+/* Read the current time from the EC. */
+static int cros_ec_rtc_read_time(struct device *dev, struct rtc_time *tm)
+{
+   struct cros_ec_rtc *cros_ec_rtc = dev_get_drvdata(dev);
+   struct cros_ec_device *cros_ec = cros_ec_rtc->cros_ec;
+   int ret;
+   u32 time;
+
+   ret = cros_ec_

[rtc-linux] [PATCH v2 4/4] mfd: cros_ec: add RTC as mfd subdevice

2017-01-19 Thread Enric Balletbo i Serra
From: Stephen Barber 

If the EC supports RTC host commands, expose an RTC device.

Signed-off-by: Stephen Barber 
Signed-off-by: Enric Balletbo i Serra 
---
 drivers/platform/chrome/cros_ec_dev.c | 22 ++
 1 file changed, 22 insertions(+)

diff --git a/drivers/platform/chrome/cros_ec_dev.c 
b/drivers/platform/chrome/cros_ec_dev.c
index 47268ec..ebe029d 100644
--- a/drivers/platform/chrome/cros_ec_dev.c
+++ b/drivers/platform/chrome/cros_ec_dev.c
@@ -383,6 +383,24 @@ static void cros_ec_sensors_register(struct cros_ec_dev 
*ec)
kfree(msg);
 }
 
+static const struct mfd_cell cros_ec_rtc_devs[] = {
+   {
+   .name = "cros-ec-rtc",
+   .id   = -1,
+   },
+};
+
+static void cros_ec_rtc_register(struct cros_ec_dev *ec)
+{
+   int ret;
+
+   ret = mfd_add_devices(ec->dev, 0, cros_ec_rtc_devs,
+ ARRAY_SIZE(cros_ec_rtc_devs),
+ NULL, 0, NULL);
+   if (ret)
+   dev_err(ec->dev, "failed to add cros-ec-rtc device: %d\n", ret);
+}
+
 static int ec_device_probe(struct platform_device *pdev)
 {
int retval = -ENOMEM;
@@ -441,6 +459,10 @@ static int ec_device_probe(struct platform_device *pdev)
if (cros_ec_check_features(ec, EC_FEATURE_MOTION_SENSE))
cros_ec_sensors_register(ec);
 
+   /* check whether this EC instance has RTC host command support */
+   if (cros_ec_check_features(ec, EC_FEATURE_RTC))
+   cros_ec_rtc_register(ec);
+
return 0;
 
 dev_reg_failed:
-- 
2.9.3

-- 
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
--- 
You received this message because you are subscribed to the Google Groups 
"rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rtc-linux+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[rtc-linux] [PATCH v2 1/4] mfd: cros_ec: Add helper for event notifier.

2017-01-19 Thread Enric Balletbo i Serra
From: Gwendal Grignou 

Add cros_ec_get_event() entry point to retrieve event within functions
called by the notifier.

Signed-off-by: Gwendal Grignou 
Signed-off-by: Enric Balletbo i Serra 
Acked-by: Lee Jones 
---

Changelog:

 * Added the ack by Lee Jones

 drivers/platform/chrome/cros_ec_proto.c | 20 
 include/linux/mfd/cros_ec.h | 10 ++
 2 files changed, 30 insertions(+)

diff --git a/drivers/platform/chrome/cros_ec_proto.c 
b/drivers/platform/chrome/cros_ec_proto.c
index ed5dee7..7428c2b 100644
--- a/drivers/platform/chrome/cros_ec_proto.c
+++ b/drivers/platform/chrome/cros_ec_proto.c
@@ -494,3 +494,23 @@ int cros_ec_get_next_event(struct cros_ec_device *ec_dev)
return get_keyboard_state_event(ec_dev);
 }
 EXPORT_SYMBOL(cros_ec_get_next_event);
+
+u32 cros_ec_get_host_event(struct cros_ec_device *ec_dev)
+{
+   u32 host_event;
+
+   BUG_ON(!ec_dev->mkbp_event_supported);
+
+   if (ec_dev->event_data.event_type != EC_MKBP_EVENT_HOST_EVENT)
+   return 0;
+
+   if (ec_dev->event_size != sizeof(host_event)) {
+   dev_warn(ec_dev->dev, "Invalid host event size\n");
+   return 0;
+   }
+
+   host_event = get_unaligned_le32(&ec_dev->event_data.data.host_event);
+
+   return host_event;
+}
+EXPORT_SYMBOL(cros_ec_get_host_event);
diff --git a/include/linux/mfd/cros_ec.h b/include/linux/mfd/cros_ec.h
index b3d04de..be2c4eb 100644
--- a/include/linux/mfd/cros_ec.h
+++ b/include/linux/mfd/cros_ec.h
@@ -299,6 +299,16 @@ int cros_ec_query_all(struct cros_ec_device *ec_dev);
  */
 int cros_ec_get_next_event(struct cros_ec_device *ec_dev);
 
+/**
+ * cros_ec_get_host_event - Return a mask of event set by the EC.
+ *
+ * When MKBP is supported, when the EC raises an interrupt,
+ * We collect the events raised and call the functions in the ec notifier.
+ *
+ * This function is a helper to know which events are raised.
+ */
+u32 cros_ec_get_host_event(struct cros_ec_device *ec_dev);
+
 /* sysfs stuff */
 extern struct attribute_group cros_ec_attr_group;
 extern struct attribute_group cros_ec_lightbar_attr_group;
-- 
2.9.3

-- 
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
--- 
You received this message because you are subscribed to the Google Groups 
"rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rtc-linux+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[rtc-linux] [PATCH v2 3/4] rtc: cros-ec: add cros-ec-rtc driver.

2017-01-19 Thread Enric Balletbo i Serra
From: Stephen Barber 

On platforms with a Chrome OS EC, the EC can function as a simple RTC.
Add a basic driver with this functionality.

Signed-off-by: Stephen Barber 
Signed-off-by: Enric Balletbo i Serra 
---

Changelog

 * Moved RTC_DRV_CROS_EC after "Platform RTC drivers" (Alexandre Belloni)
 * Remove check for invalid date/time as is not useful (Alexandre Belloni)

 drivers/rtc/Kconfig   |  10 ++
 drivers/rtc/Makefile  |   1 +
 drivers/rtc/rtc-cros-ec.c | 413 ++
 3 files changed, 424 insertions(+)
 create mode 100644 drivers/rtc/rtc-cros-ec.c

diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index c93c5a8..59ab3d6 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -1204,6 +1204,16 @@ config RTC_DRV_ZYNQMP
  If you say yes here you get support for the RTC controller found on
  Xilinx Zynq Ultrascale+ MPSoC.
 
+config RTC_DRV_CROS_EC
+   tristate "Chrome OS EC RTC driver"
+   depends on MFD_CROS_EC
+   help
+ If you say yes here you will get support for the
+ Chrome OS Embedded Controller's RTC.
+
+ This driver can also be built as a module. If so, the module
+ will be called rtc-cros-ec.
+
 comment "on-CPU RTC drivers"
 
 config RTC_DRV_ASM9260
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index f13ab1c..dd753e6 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -40,6 +40,7 @@ obj-$(CONFIG_RTC_DRV_BQ32K)   += rtc-bq32k.o
 obj-$(CONFIG_RTC_DRV_BQ4802)   += rtc-bq4802.o
 obj-$(CONFIG_RTC_DRV_CMOS) += rtc-cmos.o
 obj-$(CONFIG_RTC_DRV_COH901331)+= rtc-coh901331.o
+obj-$(CONFIG_RTC_DRV_CROS_EC)  += rtc-cros-ec.o
 obj-$(CONFIG_RTC_DRV_DA9052)   += rtc-da9052.o
 obj-$(CONFIG_RTC_DRV_DA9055)   += rtc-da9055.o
 obj-$(CONFIG_RTC_DRV_DA9063)   += rtc-da9063.o
diff --git a/drivers/rtc/rtc-cros-ec.c b/drivers/rtc/rtc-cros-ec.c
new file mode 100644
index 000..f0ea689
--- /dev/null
+++ b/drivers/rtc/rtc-cros-ec.c
@@ -0,0 +1,413 @@
+/*
+ * RTC driver for Chrome OS Embedded Controller
+ *
+ * Copyright (c) 2017, Google, Inc
+ *
+ * Author: Stephen Barber 
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define DRV_NAME   "cros-ec-rtc"
+
+/**
+ * struct cros_ec_rtc - Driver data for EC RTC
+ *
+ * @cros_ec: Pointer to EC device
+ * @rtc: Pointer to RTC device
+ * @notifier: Notifier info for responding to EC events
+ * @saved_alarm: Alarm to restore when interrupts are reenabled
+ */
+struct cros_ec_rtc {
+   struct cros_ec_device *cros_ec;
+   struct rtc_device *rtc;
+   struct notifier_block notifier;
+   u32 saved_alarm;
+};
+
+static int cros_ec_rtc_get(struct cros_ec_device *cros_ec, u32 command,
+  u32 *response)
+{
+   int ret;
+   struct {
+   struct cros_ec_command msg;
+   struct ec_response_rtc data;
+   } __packed msg;
+
+   memset(&msg, 0, sizeof(msg));
+   msg.msg.command = command;
+   msg.msg.insize = sizeof(msg.data);
+
+   ret = cros_ec_cmd_xfer_status(cros_ec, &msg.msg);
+   if (ret < 0) {
+   dev_err(cros_ec->dev,
+   "error getting %s from EC: %d\n",
+   command == EC_CMD_RTC_GET_VALUE ? "time" : "alarm",
+   ret);
+   return ret;
+   }
+
+   *response = msg.data.time;
+
+   return 0;
+}
+
+static int cros_ec_rtc_set(struct cros_ec_device *cros_ec, u32 command,
+  u32 param)
+{
+   int ret = 0;
+   struct {
+   struct cros_ec_command msg;
+   struct ec_response_rtc data;
+   } __packed msg;
+
+   memset(&msg, 0, sizeof(msg));
+   msg.msg.command = command;
+   msg.msg.outsize = sizeof(msg.data);
+   msg.data.time = param;
+
+   ret = cros_ec_cmd_xfer_status(cros_ec, &msg.msg);
+   if (ret < 0) {
+   dev_err(cros_ec->dev, "error setting %s on EC: %d\n",
+   command == EC_CMD_RTC_SET_VALUE ? "time" : "alarm",
+   ret);
+   return ret;
+   }
+
+   return 0;
+}
+
+/* Read the current time from the EC. */
+static int cros_ec_rtc_read_time(struct device *dev, struct rtc_time *tm)
+{
+   struct cros_ec_rtc *cros_ec_rtc = dev_get_drvdata(dev);
+   struct cros_ec_dev

[rtc-linux] [PATCH v2 2/4] mfd: cros_ec: Introduce RTC commands and events definitions.

2017-01-19 Thread Enric Balletbo i Serra
From: Stephen Barber 

The EC can function as a simple RT, this patch adds the RTC related
definitions needed by the rtc-cros-ec driver.

Signed-off-by: Stephen Barber 
Signed-off-by: Enric Balletbo i Serra 
Acked-by: Lee Jones 
---

Changelog:

 * Added the ack by Lee Jones

 include/linux/mfd/cros_ec_commands.h | 8 
 1 file changed, 8 insertions(+)

diff --git a/include/linux/mfd/cros_ec_commands.h 
b/include/linux/mfd/cros_ec_commands.h
index 80d401d..73f7a62 100644
--- a/include/linux/mfd/cros_ec_commands.h
+++ b/include/linux/mfd/cros_ec_commands.h
@@ -286,6 +286,9 @@ enum host_event_code {
/* Hang detect logic detected a hang and warm rebooted the AP */
EC_HOST_EVENT_HANG_REBOOT = 21,
 
+   /* EC RTC event occurred */
+   EC_HOST_EVENT_RTC = 26,
+
/*
 * The high bit of the event mask is not used as a host event code.  If
 * it reads back as set, then the entire event mask should be
@@ -790,6 +793,8 @@ enum ec_feature_code {
EC_FEATURE_USB_MUX = 23,
/* Motion Sensor code has an internal software FIFO */
EC_FEATURE_MOTION_SENSE_FIFO = 24,
+   /* EC has RTC feature that can be controlled by host commands */
+   EC_FEATURE_RTC = 27,
 };
 
 #define EC_FEATURE_MASK_0(event_code) (1UL << (event_code % 32))
@@ -1682,6 +1687,9 @@ struct ec_response_rtc {
 #define EC_CMD_RTC_SET_VALUE 0x46
 #define EC_CMD_RTC_SET_ALARM 0x47
 
+/* Pass as param to SET_ALARM to clear the current alarm */
+#define EC_RTC_ALARM_CLEAR 0
+
 /*/
 /* Port80 log access */
 
-- 
2.9.3

-- 
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
--- 
You received this message because you are subscribed to the Google Groups 
"rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rtc-linux+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[rtc-linux] [PATCH] rtc: bq32000: add support to enable disable the trickle charge FET bypass.

2017-01-27 Thread Enric Balletbo i Serra
The bq32000 includes a trickle charge circuit to maintain the charge of the
backup supply when a super capacitor is used.

You can enable the charging circuit by setting 'trickle-resistor-ohms',
additionally you can set TCFE to 1 to bypass the internal diode and boost
the charge voltage of the backup supply. You might want to enable/disable
the TCFE switch from userspace (e.g when device is only connected to a
battery)

This patch introduces a new sysfs entry to enable and disable this FET
form userspace.

Signed-off-by: Enric Balletbo i Serra 
---
 .../ABI/testing/sysfs-bus-i2c-devices-bq32k|  7 ++
 drivers/rtc/rtc-bq32k.c| 76 ++
 2 files changed, 83 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-bus-i2c-devices-bq32k

diff --git a/Documentation/ABI/testing/sysfs-bus-i2c-devices-bq32k 
b/Documentation/ABI/testing/sysfs-bus-i2c-devices-bq32k
new file mode 100644
index 000..398b258
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-bus-i2c-devices-bq32k
@@ -0,0 +1,7 @@
+What:  /sys/bus/i2c/devices/.../trickle_charge_bypass
+Date:  Jan 2017
+KernelVersion: 4.11
+Contact:   Enric Balletbo i Serra 
+Description:Attribute for enable/disable the trickle charge bypass
+   The trickle_charge_bypass attribute allows the userspace to
+enable/disable the Trickle charge FET bypass.
diff --git a/drivers/rtc/rtc-bq32k.c b/drivers/rtc/rtc-bq32k.c
index 3977424..2b22393 100644
--- a/drivers/rtc/rtc-bq32k.c
+++ b/drivers/rtc/rtc-bq32k.c
@@ -34,6 +34,7 @@
 #define BQ32K_CALIBRATION  0x07/* CAL_CFG1, calibration and control */
 #define BQ32K_TCH2 0x08/* Trickle charge enable */
 #define BQ32K_CFG2 0x09/* Trickle charger control */
+#define BQ32K_TCFE BIT(6)  /* Trickle charge FET bypass */
 
 struct bq32k_regs {
uint8_t seconds;
@@ -188,6 +189,65 @@ static int trickle_charger_of_init(struct device *dev, 
struct device_node *node)
return 0;
 }
 
+static ssize_t bq32k_sysfs_show_tricklecharge_bypass(struct device *dev,
+  struct device_attribute *attr,
+  char *buf)
+{
+   int reg, error;
+
+   error = bq32k_read(dev, ®, BQ32K_CFG2, 1);
+   if (error)
+   return error;
+
+   return sprintf(buf, "%d\n", (reg & BQ32K_TCFE) ? 1 : 0);
+}
+
+static ssize_t bq32k_sysfs_store_tricklecharge_bypass(struct device *dev,
+   struct device_attribute *attr,
+   const char *buf, size_t count)
+{
+   int reg, enable, error;
+
+   if (kstrtoint(buf, 0, &enable))
+   return -EINVAL;
+
+   error = bq32k_read(dev, ®, BQ32K_CFG2, 1);
+   if (error)
+   return error;
+
+   if (enable) {
+   reg |= BQ32K_TCFE;
+   error = bq32k_write(dev, ®, BQ32K_CFG2, 1);
+   if (error)
+   return error;
+
+   dev_info(dev, "Enabled trickle charge FET bypass.\n");
+   } else {
+   reg &= ~BQ32K_TCFE;
+   error = bq32k_write(dev, ®, BQ32K_CFG2, 1);
+   if (error)
+   return error;
+
+   dev_info(dev, "Disabled trickle charge FET bypass.\n");
+   }
+
+   return count;
+}
+
+static DEVICE_ATTR(trickle_charge_bypass, 0644,
+  bq32k_sysfs_show_tricklecharge_bypass,
+  bq32k_sysfs_store_tricklecharge_bypass);
+
+static int bq32k_sysfs_register(struct device *dev)
+{
+   return device_create_file(dev, &dev_attr_trickle_charge_bypass);
+}
+
+static void bq32k_sysfs_unregister(struct device *dev)
+{
+   device_remove_file(dev, &dev_attr_trickle_charge_bypass);
+}
+
 static int bq32k_probe(struct i2c_client *client,
const struct i2c_device_id *id)
 {
@@ -224,11 +284,26 @@ static int bq32k_probe(struct i2c_client *client,
if (IS_ERR(rtc))
return PTR_ERR(rtc);
 
+   error = bq32k_sysfs_register(&client->dev);
+   if (error) {
+   dev_err(&client->dev,
+   "Unable to create sysfs entries for rtc bq32000\n");
+   return error;
+   }
+
+
i2c_set_clientdata(client, rtc);
 
return 0;
 }
 
+static int bq32k_remove(struct i2c_client *client)
+{
+   bq32k_sysfs_unregister(&client->dev);
+
+   return 0;
+}
+
 static const struct i2c_device_id bq32k_id[] = {
{ "bq32000", 0 },
{ }
@@ -240,6 +315,7 @@ static struct i2c_driver bq32k_driver = {
.name   = "bq32k",
},
.probe  = bq32k_probe,
+   .remove = bq32k_remove,
.id_table   =

[rtc-linux] Re: [PATCH v2 3/4] rtc: cros-ec: add cros-ec-rtc driver.

2017-02-14 Thread Enric Balletbo i Serra
Hi Lee,

On 23/01/17 13:14, Lee Jones wrote:
> On Mon, 23 Jan 2017, Alexandre Belloni wrote:
> 
>> On 19/01/2017 at 13:30:31 +0100, Enric Balletbo i Serra wrote :
>>> From: Stephen Barber 
>>>
>>> On platforms with a Chrome OS EC, the EC can function as a simple RTC.
>>> Add a basic driver with this functionality.
>>>
>>> Signed-off-by: Stephen Barber 
>>> Signed-off-by: Enric Balletbo i Serra 
>>
>> Acked-by: Alexandre Belloni 
>>
>> Lee, this can go through the mfd tree. Hopefully, nobody will add a new
>> driver nearby ;)
> 
> Yes, I can take the set, once all of the Acks are obtained.
> 

Now that the patch series have all the acks, this will finally go through the 
mfd tree?

I suppose is too late for the upcoming merge window ... so just want to make 
sure which tree I should monitor to not forget it :)

Thanks,
 Enric



-- 
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
--- 
You received this message because you are subscribed to the Google Groups 
"rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rtc-linux+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[rtc-linux] [PATCH v3 1/4] mfd: cros_ec: Add helper for event notifier.

2017-02-14 Thread Enric Balletbo i Serra
From: Gwendal Grignou 

Add cros_ec_get_event() entry point to retrieve event within functions
called by the notifier.

Signed-off-by: Gwendal Grignou 
Signed-off-by: Enric Balletbo i Serra 
Acked-by: Lee Jones 
---
Changes since v2:
 - none
Changes since v1:
 - Acked by Lee Jones

 drivers/platform/chrome/cros_ec_proto.c | 20 
 include/linux/mfd/cros_ec.h | 10 ++
 2 files changed, 30 insertions(+)

diff --git a/drivers/platform/chrome/cros_ec_proto.c 
b/drivers/platform/chrome/cros_ec_proto.c
index ed5dee7..7428c2b 100644
--- a/drivers/platform/chrome/cros_ec_proto.c
+++ b/drivers/platform/chrome/cros_ec_proto.c
@@ -494,3 +494,23 @@ int cros_ec_get_next_event(struct cros_ec_device *ec_dev)
return get_keyboard_state_event(ec_dev);
 }
 EXPORT_SYMBOL(cros_ec_get_next_event);
+
+u32 cros_ec_get_host_event(struct cros_ec_device *ec_dev)
+{
+   u32 host_event;
+
+   BUG_ON(!ec_dev->mkbp_event_supported);
+
+   if (ec_dev->event_data.event_type != EC_MKBP_EVENT_HOST_EVENT)
+   return 0;
+
+   if (ec_dev->event_size != sizeof(host_event)) {
+   dev_warn(ec_dev->dev, "Invalid host event size\n");
+   return 0;
+   }
+
+   host_event = get_unaligned_le32(&ec_dev->event_data.data.host_event);
+
+   return host_event;
+}
+EXPORT_SYMBOL(cros_ec_get_host_event);
diff --git a/include/linux/mfd/cros_ec.h b/include/linux/mfd/cros_ec.h
index b3d04de..be2c4eb 100644
--- a/include/linux/mfd/cros_ec.h
+++ b/include/linux/mfd/cros_ec.h
@@ -299,6 +299,16 @@ int cros_ec_query_all(struct cros_ec_device *ec_dev);
  */
 int cros_ec_get_next_event(struct cros_ec_device *ec_dev);
 
+/**
+ * cros_ec_get_host_event - Return a mask of event set by the EC.
+ *
+ * When MKBP is supported, when the EC raises an interrupt,
+ * We collect the events raised and call the functions in the ec notifier.
+ *
+ * This function is a helper to know which events are raised.
+ */
+u32 cros_ec_get_host_event(struct cros_ec_device *ec_dev);
+
 /* sysfs stuff */
 extern struct attribute_group cros_ec_attr_group;
 extern struct attribute_group cros_ec_lightbar_attr_group;
-- 
2.9.3

-- 
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
--- 
You received this message because you are subscribed to the Google Groups 
"rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rtc-linux+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[rtc-linux] [PATCH v3 4/4] mfd: cros_ec: add RTC as mfd subdevice

2017-02-14 Thread Enric Balletbo i Serra
From: Stephen Barber 

If the EC supports RTC host commands, expose an RTC device.

Signed-off-by: Stephen Barber 
Signed-off-by: Enric Balletbo i Serra 
Acked-by: Benson Leung 
---
Changes since v2:
 - Acked by Benson Leung
Changes since v1:
 - none

 drivers/platform/chrome/cros_ec_dev.c | 22 ++
 1 file changed, 22 insertions(+)

diff --git a/drivers/platform/chrome/cros_ec_dev.c 
b/drivers/platform/chrome/cros_ec_dev.c
index 47268ec..ebe029d 100644
--- a/drivers/platform/chrome/cros_ec_dev.c
+++ b/drivers/platform/chrome/cros_ec_dev.c
@@ -383,6 +383,24 @@ static void cros_ec_sensors_register(struct cros_ec_dev 
*ec)
kfree(msg);
 }
 
+static const struct mfd_cell cros_ec_rtc_devs[] = {
+   {
+   .name = "cros-ec-rtc",
+   .id   = -1,
+   },
+};
+
+static void cros_ec_rtc_register(struct cros_ec_dev *ec)
+{
+   int ret;
+
+   ret = mfd_add_devices(ec->dev, 0, cros_ec_rtc_devs,
+ ARRAY_SIZE(cros_ec_rtc_devs),
+ NULL, 0, NULL);
+   if (ret)
+   dev_err(ec->dev, "failed to add cros-ec-rtc device: %d\n", ret);
+}
+
 static int ec_device_probe(struct platform_device *pdev)
 {
int retval = -ENOMEM;
@@ -441,6 +459,10 @@ static int ec_device_probe(struct platform_device *pdev)
if (cros_ec_check_features(ec, EC_FEATURE_MOTION_SENSE))
cros_ec_sensors_register(ec);
 
+   /* check whether this EC instance has RTC host command support */
+   if (cros_ec_check_features(ec, EC_FEATURE_RTC))
+   cros_ec_rtc_register(ec);
+
return 0;
 
 dev_reg_failed:
-- 
2.9.3

-- 
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
--- 
You received this message because you are subscribed to the Google Groups 
"rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rtc-linux+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[rtc-linux] [PATCH v3 2/4] mfd: cros_ec: Introduce RTC commands and events definitions.

2017-02-14 Thread Enric Balletbo i Serra
From: Stephen Barber 

The EC can function as a simple RT, this patch adds the RTC related
definitions needed by the rtc-cros-ec driver.

Signed-off-by: Stephen Barber 
Signed-off-by: Enric Balletbo i Serra 
Acked-by: Lee Jones 
---
Changes since v2:
 - none
Changes since v1:
 - Acked by Lee Jones

 include/linux/mfd/cros_ec_commands.h | 8 
 1 file changed, 8 insertions(+)

diff --git a/include/linux/mfd/cros_ec_commands.h 
b/include/linux/mfd/cros_ec_commands.h
index 80d401d..73f7a62 100644
--- a/include/linux/mfd/cros_ec_commands.h
+++ b/include/linux/mfd/cros_ec_commands.h
@@ -286,6 +286,9 @@ enum host_event_code {
/* Hang detect logic detected a hang and warm rebooted the AP */
EC_HOST_EVENT_HANG_REBOOT = 21,
 
+   /* EC RTC event occurred */
+   EC_HOST_EVENT_RTC = 26,
+
/*
 * The high bit of the event mask is not used as a host event code.  If
 * it reads back as set, then the entire event mask should be
@@ -790,6 +793,8 @@ enum ec_feature_code {
EC_FEATURE_USB_MUX = 23,
/* Motion Sensor code has an internal software FIFO */
EC_FEATURE_MOTION_SENSE_FIFO = 24,
+   /* EC has RTC feature that can be controlled by host commands */
+   EC_FEATURE_RTC = 27,
 };
 
 #define EC_FEATURE_MASK_0(event_code) (1UL << (event_code % 32))
@@ -1682,6 +1687,9 @@ struct ec_response_rtc {
 #define EC_CMD_RTC_SET_VALUE 0x46
 #define EC_CMD_RTC_SET_ALARM 0x47
 
+/* Pass as param to SET_ALARM to clear the current alarm */
+#define EC_RTC_ALARM_CLEAR 0
+
 /*/
 /* Port80 log access */
 
-- 
2.9.3

-- 
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
--- 
You received this message because you are subscribed to the Google Groups 
"rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rtc-linux+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[rtc-linux] [PATCH v3 3/4] rtc: cros-ec: add cros-ec-rtc driver.

2017-02-14 Thread Enric Balletbo i Serra
From: Stephen Barber 

On platforms with a Chrome OS EC, the EC can function as a simple RTC.
Add a basic driver with this functionality.

Signed-off-by: Stephen Barber 
Signed-off-by: Enric Balletbo i Serra 
Acked-by: Alexandre Belloni 
---
Changes since v2:
 - Acked by Alexandre Belloni
Changes since v1:
 - Moved RTC_DRV_CROS_EC after "Platform RTC drivers" (Alexandre Belloni)
 - Remove check for invalid date/time as is not useful (Alexandre Belloni)

 drivers/rtc/Kconfig   |  10 ++
 drivers/rtc/Makefile  |   1 +
 drivers/rtc/rtc-cros-ec.c | 413 ++
 3 files changed, 424 insertions(+)
 create mode 100644 drivers/rtc/rtc-cros-ec.c

diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index c93c5a8..59ab3d6 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -1204,6 +1204,16 @@ config RTC_DRV_ZYNQMP
  If you say yes here you get support for the RTC controller found on
  Xilinx Zynq Ultrascale+ MPSoC.
 
+config RTC_DRV_CROS_EC
+   tristate "Chrome OS EC RTC driver"
+   depends on MFD_CROS_EC
+   help
+ If you say yes here you will get support for the
+ Chrome OS Embedded Controller's RTC.
+
+ This driver can also be built as a module. If so, the module
+ will be called rtc-cros-ec.
+
 comment "on-CPU RTC drivers"
 
 config RTC_DRV_ASM9260
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index f13ab1c..dd753e6 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -40,6 +40,7 @@ obj-$(CONFIG_RTC_DRV_BQ32K)   += rtc-bq32k.o
 obj-$(CONFIG_RTC_DRV_BQ4802)   += rtc-bq4802.o
 obj-$(CONFIG_RTC_DRV_CMOS) += rtc-cmos.o
 obj-$(CONFIG_RTC_DRV_COH901331)+= rtc-coh901331.o
+obj-$(CONFIG_RTC_DRV_CROS_EC)  += rtc-cros-ec.o
 obj-$(CONFIG_RTC_DRV_DA9052)   += rtc-da9052.o
 obj-$(CONFIG_RTC_DRV_DA9055)   += rtc-da9055.o
 obj-$(CONFIG_RTC_DRV_DA9063)   += rtc-da9063.o
diff --git a/drivers/rtc/rtc-cros-ec.c b/drivers/rtc/rtc-cros-ec.c
new file mode 100644
index 000..f0ea689
--- /dev/null
+++ b/drivers/rtc/rtc-cros-ec.c
@@ -0,0 +1,413 @@
+/*
+ * RTC driver for Chrome OS Embedded Controller
+ *
+ * Copyright (c) 2017, Google, Inc
+ *
+ * Author: Stephen Barber 
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define DRV_NAME   "cros-ec-rtc"
+
+/**
+ * struct cros_ec_rtc - Driver data for EC RTC
+ *
+ * @cros_ec: Pointer to EC device
+ * @rtc: Pointer to RTC device
+ * @notifier: Notifier info for responding to EC events
+ * @saved_alarm: Alarm to restore when interrupts are reenabled
+ */
+struct cros_ec_rtc {
+   struct cros_ec_device *cros_ec;
+   struct rtc_device *rtc;
+   struct notifier_block notifier;
+   u32 saved_alarm;
+};
+
+static int cros_ec_rtc_get(struct cros_ec_device *cros_ec, u32 command,
+  u32 *response)
+{
+   int ret;
+   struct {
+   struct cros_ec_command msg;
+   struct ec_response_rtc data;
+   } __packed msg;
+
+   memset(&msg, 0, sizeof(msg));
+   msg.msg.command = command;
+   msg.msg.insize = sizeof(msg.data);
+
+   ret = cros_ec_cmd_xfer_status(cros_ec, &msg.msg);
+   if (ret < 0) {
+   dev_err(cros_ec->dev,
+   "error getting %s from EC: %d\n",
+   command == EC_CMD_RTC_GET_VALUE ? "time" : "alarm",
+   ret);
+   return ret;
+   }
+
+   *response = msg.data.time;
+
+   return 0;
+}
+
+static int cros_ec_rtc_set(struct cros_ec_device *cros_ec, u32 command,
+  u32 param)
+{
+   int ret = 0;
+   struct {
+   struct cros_ec_command msg;
+   struct ec_response_rtc data;
+   } __packed msg;
+
+   memset(&msg, 0, sizeof(msg));
+   msg.msg.command = command;
+   msg.msg.outsize = sizeof(msg.data);
+   msg.data.time = param;
+
+   ret = cros_ec_cmd_xfer_status(cros_ec, &msg.msg);
+   if (ret < 0) {
+   dev_err(cros_ec->dev, "error setting %s on EC: %d\n",
+   command == EC_CMD_RTC_SET_VALUE ? "time" : "alarm",
+   ret);
+   return ret;
+   }
+
+   return 0;
+}
+
+/* Read the current time from the EC. */
+static int cros_ec_rtc_read_time(struct device *dev, struct rtc_time *tm)
+{
+

[rtc-linux] Re: [PATCH v2 3/4] rtc: cros-ec: add cros-ec-rtc driver.

2017-02-14 Thread Enric Balletbo i Serra


On 14/02/17 16:26, Lee Jones wrote:
> On Tue, 14 Feb 2017, Enric Balletbo i Serra wrote:
> 
>> Hi Lee,
>>
>> On 23/01/17 13:14, Lee Jones wrote:
>>> On Mon, 23 Jan 2017, Alexandre Belloni wrote:
>>>
>>>> On 19/01/2017 at 13:30:31 +0100, Enric Balletbo i Serra wrote :
>>>>> From: Stephen Barber 
>>>>>
>>>>> On platforms with a Chrome OS EC, the EC can function as a simple RTC.
>>>>> Add a basic driver with this functionality.
>>>>>
>>>>> Signed-off-by: Stephen Barber 
>>>>> Signed-off-by: Enric Balletbo i Serra 
>>>>
>>>> Acked-by: Alexandre Belloni 
>>>>
>>>> Lee, this can go through the mfd tree. Hopefully, nobody will add a new
>>>> driver nearby ;)
>>>
>>> Yes, I can take the set, once all of the Acks are obtained.
>>>
>>
>> Now that the patch series have all the acks, this will finally go through 
>> the mfd tree?
>>
>> I suppose is too late for the upcoming merge window ... so just want to make 
>> sure which tree I should monitor to not forget it :)
> 
> You need to submit it, complete with all the Acks you received.
> 
> Yes, it's too late for this cycle.
> 

Ok, thanks Lee, just submitted v3 with all the acks

Cheers,
  Enric

-- 
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
--- 
You received this message because you are subscribed to the Google Groups 
"rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rtc-linux+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[rtc-linux] Re: [PATCH v3 4/4] mfd: cros_ec: add RTC as mfd subdevice

2017-03-14 Thread Enric Balletbo i Serra
Hi Lee,

On 14/03/17 14:59, Lee Jones wrote:
> On Tue, 14 Feb 2017, Enric Balletbo i Serra wrote:
> 
>> From: Stephen Barber 
>>
>> If the EC supports RTC host commands, expose an RTC device.
>>
>> Signed-off-by: Stephen Barber 
>> Signed-off-by: Enric Balletbo i Serra 
>> Acked-by: Benson Leung 
>> ---
>> Changes since v2:
>>  - Acked by Benson Leung
>> Changes since v1:
>>  - none
>>
>>  drivers/platform/chrome/cros_ec_dev.c | 22 ++
>>  1 file changed, 22 insertions(+)
>>
>> diff --git a/drivers/platform/chrome/cros_ec_dev.c 
>> b/drivers/platform/chrome/cros_ec_dev.c
>> index 47268ec..ebe029d 100644
>> --- a/drivers/platform/chrome/cros_ec_dev.c
>> +++ b/drivers/platform/chrome/cros_ec_dev.c
>> @@ -383,6 +383,24 @@ static void cros_ec_sensors_register(struct cros_ec_dev 
>> *ec)
>>  kfree(msg);
>>  }
>>  
>> +static const struct mfd_cell cros_ec_rtc_devs[] = {
>> +{
>> +.name = "cros-ec-rtc",
>> +.id   = -1,
>> +},
>> +};
>> +
>> +static void cros_ec_rtc_register(struct cros_ec_dev *ec)
>> +{
>> +int ret;
>> +
>> +ret = mfd_add_devices(ec->dev, 0, cros_ec_rtc_devs,
>> +  ARRAY_SIZE(cros_ec_rtc_devs),
>> +  NULL, 0, NULL);
>> +if (ret)
>> +dev_err(ec->dev, "failed to add cros-ec-rtc device: %d\n", ret);
>> +}
> 
> Holey poop!  Why are you using the MFD API outside of MFD?
> 
> Why can't you register this from the MFD driver?
> 

Actually the MFD doesn't know how to check if this feature is available or not,
instead is the platform driver cros_ec_dev who knows how to check this and if it
exists adds the rtc device.

if (cros_ec_check_features(ec, EC_FEATURE_RTC))
cros_ec_rtc_register(ec); /* add the mfd device */

Same approach was used in the same file for the Sensors Hub (already upstream). 
See:

  drivers/platform/chrome/cros_ec_dev.c:462
  drivers/platform/chrome/cros_ec_dev.c:372

I didn't know that the MFD API was restricted outside MFD. In such case what I
need to do is let know the MFD driver about the cros_ec_check_features
(implemented in platform driver cros_ec_dev), this doesn't seems good to me but
I might be wrong. So please, let me know which option do you prefer and if it's
the case we will need to change I'll try to do it.

Note that I think that a similar use case is used in
drivers/iio/common/ssp_sensors/ssp_dev.c:535, where the iio driver registers the
sensors to the mfd.

Thanks,
  Enric

>>  static int ec_device_probe(struct platform_device *pdev)
>>  {
>>  int retval = -ENOMEM;
>> @@ -441,6 +459,10 @@ static int ec_device_probe(struct platform_device *pdev)
>>  if (cros_ec_check_features(ec, EC_FEATURE_MOTION_SENSE))
>>  cros_ec_sensors_register(ec);
>>  
>> +/* check whether this EC instance has RTC host command support */
>> +if (cros_ec_check_features(ec, EC_FEATURE_RTC))
>> +cros_ec_rtc_register(ec);
>> +
>>  return 0;
>>  
>>  dev_reg_failed:
> 

-- 
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
--- 
You received this message because you are subscribed to the Google Groups 
"rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rtc-linux+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[rtc-linux] Re: [PATCH v3 4/4] mfd: cros_ec: add RTC as mfd subdevice

2017-03-15 Thread Enric Balletbo i Serra
Hi Lee,

On 15/03/17 11:24, Lee Jones wrote:
> On Tue, 14 Mar 2017, Enric Balletbo i Serra wrote:
>> On 14/03/17 14:59, Lee Jones wrote:
>>> On Tue, 14 Feb 2017, Enric Balletbo i Serra wrote:
>>>
>>>> From: Stephen Barber 
>>>>
>>>> If the EC supports RTC host commands, expose an RTC device.
>>>>
>>>> Signed-off-by: Stephen Barber 
>>>> Signed-off-by: Enric Balletbo i Serra 
>>>> Acked-by: Benson Leung 
>>>> ---
>>>> Changes since v2:
>>>>  - Acked by Benson Leung
>>>> Changes since v1:
>>>>  - none
>>>>
>>>>  drivers/platform/chrome/cros_ec_dev.c | 22 ++
>>>>  1 file changed, 22 insertions(+)
>>>>
>>>> diff --git a/drivers/platform/chrome/cros_ec_dev.c 
>>>> b/drivers/platform/chrome/cros_ec_dev.c
>>>> index 47268ec..ebe029d 100644
>>>> --- a/drivers/platform/chrome/cros_ec_dev.c
>>>> +++ b/drivers/platform/chrome/cros_ec_dev.c
>>>> @@ -383,6 +383,24 @@ static void cros_ec_sensors_register(struct 
>>>> cros_ec_dev *ec)
>>>>kfree(msg);
>>>>  }
>>>>  
>>>> +static const struct mfd_cell cros_ec_rtc_devs[] = {
>>>> +  {
>>>> +  .name = "cros-ec-rtc",
>>>> +  .id   = -1,
>>>> +  },
>>>> +};
>>>> +
>>>> +static void cros_ec_rtc_register(struct cros_ec_dev *ec)
>>>> +{
>>>> +  int ret;
>>>> +
>>>> +  ret = mfd_add_devices(ec->dev, 0, cros_ec_rtc_devs,
>>>> +ARRAY_SIZE(cros_ec_rtc_devs),
>>>> +NULL, 0, NULL);
>>>> +  if (ret)
>>>> +  dev_err(ec->dev, "failed to add cros-ec-rtc device: %d\n", ret);
>>>> +}
>>>
>>> Holey poop!  Why are you using the MFD API outside of MFD?
>>>
>>> Why can't you register this from the MFD driver?
>>>
>>
>> Actually the MFD doesn't know how to check if this feature is available or 
>> not,
>> instead is the platform driver cros_ec_dev who knows how to check this and 
>> if it
>> exists adds the rtc device.
>>
>> if (cros_ec_check_features(ec, EC_FEATURE_RTC))
>>  cros_ec_rtc_register(ec); /* add the mfd device */
>>
>> Same approach was used in the same file for the Sensors Hub (already 
>> upstream). See:
>>
>>   drivers/platform/chrome/cros_ec_dev.c:462
>>   drivers/platform/chrome/cros_ec_dev.c:372
>>
>> I didn't know that the MFD API was restricted outside MFD. In such case what 
>> I
>> need to do is let know the MFD driver about the cros_ec_check_features
>> (implemented in platform driver cros_ec_dev), this doesn't seems good to me 
>> but
>> I might be wrong. So please, let me know which option do you prefer and if 
>> it's
>> the case we will need to change I'll try to do it.
>>
>> Note that I think that a similar use case is used in
>> drivers/iio/common/ssp_sensors/ssp_dev.c:535, where the iio driver registers 
>> the
>> sensors to the mfd.
> 
> It would be advantageous to avoid a web of inter-subsystem calls to
> register devices.  I think I could bear calls to mfd_add_* from
> drivers/platform, as the two subsystems are fairly interchangeable,
> and it does have the added benefit of saving duplication of the device
> registering code.  Calling mfd_add_* from IIO seems plain wrong though.
> 
> A better solution however and one that we've utilised in the past is
> to have the MFD drivers call into the platform (i.e. drivers/platform)
> drivers to see if certain devices are available.  Is this possible in
> your use-case?
> 

So just to be clear before I start to work on it. What you want is I get rid of
the MFD stuff from drivers/platform/chrome/cros_ec_dev and move to
drivers/mfd/cros_ec.c. The platform/chrome driver should publish how to check
the features and leave the mfd/cros_ec driver add the MFD subdevices.

For this patch series this means get rid of:

drivers/platform/chrome/cros_ec_dev.c:412:static const struct mfd_cell
cros_ec_rtc_devs[] ...

drivers/platform/chrome/cros_ec_dev.c:404: ret = mfd_add_devices(ec->dev,
0,cros_ec_rtc_devs ...

As I said the sensors subdevice (which is already upstream) uses the same
approach, so I think you will also want do the same for the sensors subdevice?
Sounds good if first we try to land the RTC part and the I'll prepare a patch
series to fix the sensors hub part?

> NB: 

[rtc-linux] [PATCH 1/7] mfd: cros-ec: Fix host command buffer size

2017-03-24 Thread Enric Balletbo i Serra
From: Vic Yang 

For SPI, we can get up to 32 additional bytes for response preamble.
The current overhead (2 bytes) may cause problems when we try to receive
a big response. Update it to 32 bytes.

Without this fix we could see a kernel BUG when we receive a big response
from the Chrome EC when is connected via SPI.

Signed-off-by: Vic Yang 
Tested-by: Enric Balletbo i Serra 
---

  This patch is a FIX, and I think that would be interesting see it merged
in this release cycle. This should go through the MFD tree and can be picked
independently of the other patches. Lee Jones I think this is for you.

 include/linux/mfd/cros_ec.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/include/linux/mfd/cros_ec.h b/include/linux/mfd/cros_ec.h
index b3e812f..3b16c90 100644
--- a/include/linux/mfd/cros_ec.h
+++ b/include/linux/mfd/cros_ec.h
@@ -35,10 +35,11 @@
  * Max bus-specific overhead incurred by request/responses.
  * I2C requires 1 additional byte for requests.
  * I2C requires 2 additional bytes for responses.
+ * SPI requires up to 32 additional bytes for responses.
  * */
 #define EC_PROTO_VERSION_UNKNOWN   0
 #define EC_MAX_REQUEST_OVERHEAD1
-#define EC_MAX_RESPONSE_OVERHEAD   2
+#define EC_MAX_RESPONSE_OVERHEAD   32
 
 /*
  * Command interface between EC and AP, for LPC, I2C and SPI interfaces.
-- 
2.9.3

-- 
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
--- 
You received this message because you are subscribed to the Google Groups 
"rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rtc-linux+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[rtc-linux] [PATCH 0/7] mfd: cros-ec: Some fixes and improvements.

2017-03-24 Thread Enric Balletbo i Serra
Dear all,

This is another patch series to fix and improve some cros-ec mfd related
things.

 * 1/7 mfd: cros-ec: Fix host command buffer size

  This patch is a FIX, and I think that would be interesting see it merged
in this release cycle. This should go through the MFD tree and can be picked
independently of the other patches. Lee Jones I think this is for you.

 * 2/7 iio: cros_ec_sensors: Fix return value to get raw and calibbias data.

  This is another FIX, so would be interesting see it merged in this release
cycle too. Like the above patch can be picked independently of the other
patches and should go through IIO Jonathan's Cameron tree.

 * 3/7 iio: cros_ec_sensors: Use devm to setup the triggered buffer.

  This is an improvement that can wait to 4.12 merge window, again can be
picked independently of the other patches and can go through IIO Jonathan's
Cameron tree.

 * 4/7 mfd: cros_ec: Get rid of cros_ec_check_features from cros_ec_dev.

  As pointed by Lee Jones in this thread [1] we should not use the MFD API
outside of MFD. For this reason the cros-ec-rtc did not get accepted yet.
The reality is that we are calling mfd_add_devices from cros-ec-dev driver
already, so this patch get rid off the MFD calls inside the chardev driver
and moves to cros-ec MFD. Also I think the chardev device should simply
implement the ioctl calls to access to it from userspace.

 The above patch involves MFD, IIO and platform chrome subsystems.

 * 5/7 mfd: cros_ec: Introduce RTC commands and events definitions
 * 6/7 rtc: cros-ec: add cros-ec-rtc driver
 * 7/7 mfd: cros_ec: add RTC as mfd subdevice

 These patches are the cros-ec RTC driver, 5 and 6 patches are already
acked by the subsystem maintainers involved and are equal to the last
version I send. Patch 7 registers the rtc cell inside the cros-ec MFD
intead of cros-ec-dev chardev driver.

 Note that these 3 patches depends on [2] to build. I recommend apply
these series on top of [3]

[1] https://www.spinics.net/lists/kernel/msg2465099.html
[2] https://lkml.org/lkml/2017/3/17/319
[3] https://lkml.org/lkml/2017/3/17/321

Best regards,

Enric Balletbo i Serra (3):
  iio: cros_ec_sensors: Fix return value to get raw and calibbias data.
  iio: cros_ec_sensors: Use devm to setup the triggered buffer.
  mfd: cros_ec: Get rid of cros_ec_check_features from cros_ec_dev.

Stephen Barber (3):
  mfd: cros_ec: Introduce RTC commands and events definitions.
  rtc: cros-ec: add cros-ec-rtc driver.
  mfd: cros_ec: add RTC as mfd subdevice

Vic Yang (1):
  mfd: cros-ec: Fix host command buffer size

 .../iio/common/cros_ec_sensors/cros_ec_sensors.c   |  38 +-
 .../common/cros_ec_sensors/cros_ec_sensors_core.c  |   8 +-
 drivers/iio/light/cros_ec_light_prox.c |   8 -
 drivers/iio/pressure/cros_ec_baro.c|   8 -
 drivers/mfd/cros_ec.c  | 178 +
 drivers/platform/chrome/cros_ec_dev.c  | 161 
 drivers/rtc/Kconfig|  10 +
 drivers/rtc/Makefile   |   1 +
 drivers/rtc/rtc-cros-ec.c  | 412 +
 include/linux/mfd/cros_ec.h|   9 +-
 include/linux/mfd/cros_ec_commands.h   |   8 +
 11 files changed, 626 insertions(+), 215 deletions(-)
 create mode 100644 drivers/rtc/rtc-cros-ec.c

-- 
2.9.3

-- 
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
--- 
You received this message because you are subscribed to the Google Groups 
"rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rtc-linux+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[rtc-linux] [PATCH 3/7] iio: cros_ec_sensors: Use devm to setup the triggered buffer.

2017-03-24 Thread Enric Balletbo i Serra
Use resourced managed function devm_iio_triggered_buffer_setup
to make error path simpler and be able to get rid of the remove
function.

Signed-off-by: Enric Balletbo i Serra 
---

  This is an improvement that can wait to 4.12 merge window, again can be
picked independently of the other patches and can go through IIO Jonathan's
Cameron tree.

 .../iio/common/cros_ec_sensors/cros_ec_sensors.c   | 26 +++---
 1 file changed, 3 insertions(+), 23 deletions(-)

diff --git a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c 
b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c
index c17596f..38e8783 100644
--- a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c
+++ b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c
@@ -267,31 +267,12 @@ static int cros_ec_sensors_probe(struct platform_device 
*pdev)
else
state->core.read_ec_sensors_data = cros_ec_sensors_read_cmd;
 
-   ret = iio_triggered_buffer_setup(indio_dev, NULL,
-cros_ec_sensors_capture, NULL);
+   ret = devm_iio_triggered_buffer_setup(dev, indio_dev, NULL,
+   cros_ec_sensors_capture, NULL);
if (ret)
return ret;
 
-   ret = iio_device_register(indio_dev);
-   if (ret)
-   goto error_uninit_buffer;
-
-   return 0;
-
-error_uninit_buffer:
-   iio_triggered_buffer_cleanup(indio_dev);
-
-   return ret;
-}
-
-static int cros_ec_sensors_remove(struct platform_device *pdev)
-{
-   struct iio_dev *indio_dev = platform_get_drvdata(pdev);
-
-   iio_device_unregister(indio_dev);
-   iio_triggered_buffer_cleanup(indio_dev);
-
-   return 0;
+   return devm_iio_device_register(dev, indio_dev);
 }
 
 static const struct platform_device_id cros_ec_sensors_ids[] = {
@@ -313,7 +294,6 @@ static struct platform_driver 
cros_ec_sensors_platform_driver = {
.name   = "cros-ec-sensors",
},
.probe  = cros_ec_sensors_probe,
-   .remove = cros_ec_sensors_remove,
.id_table   = cros_ec_sensors_ids,
 };
 module_platform_driver(cros_ec_sensors_platform_driver);
-- 
2.9.3

-- 
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
--- 
You received this message because you are subscribed to the Google Groups 
"rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rtc-linux+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[rtc-linux] [PATCH 4/7] mfd: cros_ec: Get rid of cros_ec_check_features from cros_ec_dev.

2017-03-24 Thread Enric Balletbo i Serra
The cros_ec_dev driver should be used only to expose the Chrome OS Embedded
Controller to user-space and should not be used to add MFD devices by
calling mfd_add_devices. This patch moves this logic to the MFD cros_ec
driver and removes the MFD bits from the character device driver. Also
makes independent the IIO driver from the character device as also has no
sense.

Signed-off-by: Enric Balletbo i Serra 
---

  As pointed by Lee Jones in this thread [1] we should not use the MFD API
outside of MFD. For this reason the cros-ec-rtc did not get accepted yet.
The reality is that we are calling mfd_add_devices from cros-ec-dev driver
already, so this patch get rid off the MFD calls inside the chardev driver
and moves to cros-ec MFD. Also I think the chardev device should simply
implement the ioctl calls to access to it from userspace.

[1]  https://www.spinics.net/lists/kernel/msg2465099.html

 .../iio/common/cros_ec_sensors/cros_ec_sensors.c   |   8 -
 .../common/cros_ec_sensors/cros_ec_sensors_core.c  |   8 +-
 drivers/iio/light/cros_ec_light_prox.c |   8 -
 drivers/iio/pressure/cros_ec_baro.c|   8 -
 drivers/mfd/cros_ec.c  | 160 
 drivers/platform/chrome/cros_ec_dev.c  | 161 -
 include/linux/mfd/cros_ec.h|   6 +-
 7 files changed, 170 insertions(+), 189 deletions(-)

diff --git a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c 
b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c
index 38e8783..9b53a01 100644
--- a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c
+++ b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c
@@ -191,19 +191,11 @@ static const struct iio_info ec_sensors_info = {
 static int cros_ec_sensors_probe(struct platform_device *pdev)
 {
struct device *dev = &pdev->dev;
-   struct cros_ec_dev *ec_dev = dev_get_drvdata(dev->parent);
-   struct cros_ec_device *ec_device;
struct iio_dev *indio_dev;
struct cros_ec_sensors_state *state;
struct iio_chan_spec *channel;
int ret, i;
 
-   if (!ec_dev || !ec_dev->ec_dev) {
-   dev_warn(&pdev->dev, "No CROS EC device found.\n");
-   return -EINVAL;
-   }
-   ec_device = ec_dev->ec_dev;
-
indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*state));
if (!indio_dev)
return -ENOMEM;
diff --git a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c 
b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
index 416cae5..0cdb64a 100644
--- a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
+++ b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
@@ -41,12 +41,13 @@ int cros_ec_sensors_core_init(struct platform_device *pdev,
 {
struct device *dev = &pdev->dev;
struct cros_ec_sensors_core_state *state = iio_priv(indio_dev);
-   struct cros_ec_dev *ec = dev_get_drvdata(pdev->dev.parent);
+   struct cros_ec_device *ec_dev = dev_get_drvdata(pdev->dev.parent);
struct cros_ec_sensor_platform *sensor_platform = dev_get_platdata(dev);
 
platform_set_drvdata(pdev, indio_dev);
 
-   state->ec = ec->ec_dev;
+   state->ec = ec_dev;
+
state->msg = devm_kzalloc(&pdev->dev,
max((u16)sizeof(struct ec_params_motion_sense),
state->ec->max_response), GFP_KERNEL);
@@ -59,7 +60,8 @@ int cros_ec_sensors_core_init(struct platform_device *pdev,
 
/* Set up the host command structure. */
state->msg->version = 2;
-   state->msg->command = EC_CMD_MOTION_SENSE_CMD + ec->cmd_offset;
+   state->msg->command = EC_CMD_MOTION_SENSE_CMD +
+   sensor_platform->cmd_offset;
state->msg->outsize = sizeof(struct ec_params_motion_sense);
 
indio_dev->dev.parent = &pdev->dev;
diff --git a/drivers/iio/light/cros_ec_light_prox.c 
b/drivers/iio/light/cros_ec_light_prox.c
index 7217223..2133ddc 100644
--- a/drivers/iio/light/cros_ec_light_prox.c
+++ b/drivers/iio/light/cros_ec_light_prox.c
@@ -181,19 +181,11 @@ static const struct iio_info cros_ec_light_prox_info = {
 static int cros_ec_light_prox_probe(struct platform_device *pdev)
 {
struct device *dev = &pdev->dev;
-   struct cros_ec_dev *ec_dev = dev_get_drvdata(dev->parent);
-   struct cros_ec_device *ec_device;
struct iio_dev *indio_dev;
struct cros_ec_light_prox_state *state;
struct iio_chan_spec *channel;
int ret;
 
-   if (!ec_dev || !ec_dev->ec_dev) {
-   dev_warn(dev, "No CROS EC device found.\n");
-   return -EINVAL;
-   }
-   ec_device = ec_dev->ec_dev;
-
indio_dev = devm_iio_device_alloc(dev, sizeof(*state));
if (!indio_dev)
 

[rtc-linux] [PATCH 6/7] rtc: cros-ec: add cros-ec-rtc driver.

2017-03-24 Thread Enric Balletbo i Serra
From: Stephen Barber 

On platforms with a Chrome OS EC, the EC can function as a simple RTC.
Add a basic driver with this functionality.

Signed-off-by: Stephen Barber 
Signed-off-by: Enric Balletbo i Serra 
Acked-by: Alexandre Belloni 
---
 drivers/rtc/Kconfig   |  10 ++
 drivers/rtc/Makefile  |   1 +
 drivers/rtc/rtc-cros-ec.c | 412 ++
 3 files changed, 423 insertions(+)
 create mode 100644 drivers/rtc/rtc-cros-ec.c

diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index 050bec7..b2939b4 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -1204,6 +1204,16 @@ config RTC_DRV_ZYNQMP
  If you say yes here you get support for the RTC controller found on
  Xilinx Zynq Ultrascale+ MPSoC.
 
+config RTC_DRV_CROS_EC
+   tristate "Chrome OS EC RTC driver"
+   depends on MFD_CROS_EC
+   help
+ If you say yes here you will get support for the
+ Chrome OS Embedded Controller's RTC.
+
+ This driver can also be built as a module. If so, the module
+ will be called rtc-cros-ec.
+
 comment "on-CPU RTC drivers"
 
 config RTC_DRV_ASM9260
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index 13857d2..8162983 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -41,6 +41,7 @@ obj-$(CONFIG_RTC_DRV_BQ4802)  += rtc-bq4802.o
 obj-$(CONFIG_RTC_DRV_CMOS) += rtc-cmos.o
 obj-$(CONFIG_RTC_DRV_COH901331)+= rtc-coh901331.o
 obj-$(CONFIG_RTC_DRV_CPCAP)+= rtc-cpcap.o
+obj-$(CONFIG_RTC_DRV_CROS_EC)  += rtc-cros-ec.o
 obj-$(CONFIG_RTC_DRV_DA9052)   += rtc-da9052.o
 obj-$(CONFIG_RTC_DRV_DA9055)   += rtc-da9055.o
 obj-$(CONFIG_RTC_DRV_DA9063)   += rtc-da9063.o
diff --git a/drivers/rtc/rtc-cros-ec.c b/drivers/rtc/rtc-cros-ec.c
new file mode 100644
index 000..a5c2512
--- /dev/null
+++ b/drivers/rtc/rtc-cros-ec.c
@@ -0,0 +1,412 @@
+/*
+ * RTC driver for Chrome OS Embedded Controller
+ *
+ * Copyright (c) 2017, Google, Inc
+ *
+ * Author: Stephen Barber 
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define DRV_NAME   "cros-ec-rtc"
+
+/**
+ * struct cros_ec_rtc - Driver data for EC RTC
+ *
+ * @cros_ec: Pointer to EC device
+ * @rtc: Pointer to RTC device
+ * @notifier: Notifier info for responding to EC events
+ * @saved_alarm: Alarm to restore when interrupts are reenabled
+ */
+struct cros_ec_rtc {
+   struct cros_ec_device *cros_ec;
+   struct rtc_device *rtc;
+   struct notifier_block notifier;
+   u32 saved_alarm;
+};
+
+static int cros_ec_rtc_get(struct cros_ec_device *cros_ec, u32 command,
+  u32 *response)
+{
+   int ret;
+   struct {
+   struct cros_ec_command msg;
+   struct ec_response_rtc data;
+   } __packed msg;
+
+   memset(&msg, 0, sizeof(msg));
+   msg.msg.command = command;
+   msg.msg.insize = sizeof(msg.data);
+
+   ret = cros_ec_cmd_xfer_status(cros_ec, &msg.msg);
+   if (ret < 0) {
+   dev_err(cros_ec->dev,
+   "error getting %s from EC: %d\n",
+   command == EC_CMD_RTC_GET_VALUE ? "time" : "alarm",
+   ret);
+   return ret;
+   }
+
+   *response = msg.data.time;
+
+   return 0;
+}
+
+static int cros_ec_rtc_set(struct cros_ec_device *cros_ec, u32 command,
+  u32 param)
+{
+   int ret = 0;
+   struct {
+   struct cros_ec_command msg;
+   struct ec_response_rtc data;
+   } __packed msg;
+
+   memset(&msg, 0, sizeof(msg));
+   msg.msg.command = command;
+   msg.msg.outsize = sizeof(msg.data);
+   msg.data.time = param;
+
+   ret = cros_ec_cmd_xfer_status(cros_ec, &msg.msg);
+   if (ret < 0) {
+   dev_err(cros_ec->dev, "error setting %s on EC: %d\n",
+   command == EC_CMD_RTC_SET_VALUE ? "time" : "alarm",
+   ret);
+   return ret;
+   }
+
+   return 0;
+}
+
+/* Read the current time from the EC. */
+static int cros_ec_rtc_read_time(struct device *dev, struct rtc_time *tm)
+{
+   struct cros_ec_rtc *cros_ec_rtc = dev_get_drvdata(dev);
+   struct cros_ec_device *cros_ec = cros_ec_rtc->cros_ec;
+   int ret;
+   u32 time;
+
+   ret = cros_ec_rtc_get(cros_ec, EC_CMD_RTC_G

[rtc-linux] [PATCH 2/7] iio: cros_ec_sensors: Fix return value to get raw and calibbias data.

2017-03-24 Thread Enric Balletbo i Serra
The cros_ec_sensors_read function must return the type of value on all
cases. This was always true except for RAW and CALIBBIAS data which
returned an error or 0. This patch just fixes the mistake I introduced
when submitting the series.

Fixes: commit c14dca07a31d (iio: cros_ec_sensors: add ChromeOS EC
Contiguous Sensors driver)

Signed-off-by: Enric Balletbo i Serra 
---

  This is another FIX, so would be interesting see it merged in this release
cycle too. Like the above patch can be picked independently of the other
patches and should go through IIO Jonathan's Cameron tree.

 drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c 
b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c
index d6c372b..c17596f 100644
--- a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c
+++ b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c
@@ -61,7 +61,7 @@ static int cros_ec_sensors_read(struct iio_dev *indio_dev,
ret = st->core.read_ec_sensors_data(indio_dev, 1 << idx, &data);
if (ret < 0)
break;
-
+   ret = IIO_VAL_INT;
*val = data;
break;
case IIO_CHAN_INFO_CALIBBIAS:
@@ -76,7 +76,7 @@ static int cros_ec_sensors_read(struct iio_dev *indio_dev,
for (i = CROS_EC_SENSOR_X; i < CROS_EC_SENSOR_MAX_AXIS; i++)
st->core.calib[i] =
st->core.resp->sensor_offset.offset[i];
-
+   ret = IIO_VAL_INT;
*val = st->core.calib[idx];
break;
case IIO_CHAN_INFO_SCALE:
-- 
2.9.3

-- 
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
--- 
You received this message because you are subscribed to the Google Groups 
"rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rtc-linux+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[rtc-linux] [PATCH 5/7] mfd: cros_ec: Introduce RTC commands and events definitions.

2017-03-24 Thread Enric Balletbo i Serra
From: Stephen Barber 

The EC can function as a simple RT, this patch adds the RTC related
definitions needed by the rtc-cros-ec driver.

Signed-off-by: Stephen Barber 
Signed-off-by: Enric Balletbo i Serra 
Acked-by: Lee Jones 
---
 include/linux/mfd/cros_ec_commands.h | 8 
 1 file changed, 8 insertions(+)

diff --git a/include/linux/mfd/cros_ec_commands.h 
b/include/linux/mfd/cros_ec_commands.h
index 84e1abb..852ce34 100644
--- a/include/linux/mfd/cros_ec_commands.h
+++ b/include/linux/mfd/cros_ec_commands.h
@@ -286,6 +286,9 @@ enum host_event_code {
/* Hang detect logic detected a hang and warm rebooted the AP */
EC_HOST_EVENT_HANG_REBOOT = 21,
 
+   /* EC RTC event occurred */
+   EC_HOST_EVENT_RTC = 26,
+
/*
 * The high bit of the event mask is not used as a host event code.  If
 * it reads back as set, then the entire event mask should be
@@ -794,6 +797,8 @@ enum ec_feature_code {
EC_FEATURE_USB_MUX = 23,
/* Motion Sensor code has an internal software FIFO */
EC_FEATURE_MOTION_SENSE_FIFO = 24,
+   /* EC has RTC feature that can be controlled by host commands */
+   EC_FEATURE_RTC = 27,
 };
 
 #define EC_FEATURE_MASK_0(event_code) (1UL << (event_code % 32))
@@ -1704,6 +1709,9 @@ struct ec_response_rtc {
 #define EC_CMD_RTC_SET_VALUE 0x46
 #define EC_CMD_RTC_SET_ALARM 0x47
 
+/* Pass as param to SET_ALARM to clear the current alarm */
+#define EC_RTC_ALARM_CLEAR 0
+
 /*/
 /* Port80 log access */
 
-- 
2.9.3

-- 
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
--- 
You received this message because you are subscribed to the Google Groups 
"rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rtc-linux+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[rtc-linux] [PATCH 7/7] mfd: cros_ec: add RTC as mfd subdevice

2017-03-24 Thread Enric Balletbo i Serra
From: Stephen Barber 

If the EC supports RTC host commands, expose an RTC device.

Signed-off-by: Stephen Barber 
Signed-off-by: Enric Balletbo i Serra 
---
 drivers/mfd/cros_ec.c | 18 ++
 1 file changed, 18 insertions(+)

diff --git a/drivers/mfd/cros_ec.c b/drivers/mfd/cros_ec.c
index bbc17ab..1ff88b1 100644
--- a/drivers/mfd/cros_ec.c
+++ b/drivers/mfd/cros_ec.c
@@ -51,6 +51,11 @@ static const struct mfd_cell ec_pd_cell = {
.pdata_size = sizeof(pd_p),
 };
 
+static const struct mfd_cell ec_rtc_cell = {
+   .name = "cros-ec-rtc",
+   .id   = -1,
+};
+
 static irqreturn_t ec_irq_thread(int irq, void *data)
 {
struct cros_ec_device *ec_dev = data;
@@ -238,6 +243,15 @@ static void cros_ec_sensors_register(struct cros_ec_device 
*ec_dev)
kfree(msg);
 }
 
+static void cros_ec_rtc_register(struct cros_ec_device *ec_dev)
+{
+   int ret;
+
+   ret = mfd_add_devices(ec_dev->dev, 0, &ec_rtc_cell, 1, NULL, 0, NULL);
+   if (ret)
+   dev_err(ec_dev->dev, "failed to add EC RTC\n");
+}
+
 int cros_ec_register(struct cros_ec_device *ec_dev)
 {
struct device *dev = ec_dev->dev;
@@ -287,6 +301,10 @@ int cros_ec_register(struct cros_ec_device *ec_dev)
if (cros_ec_check_features(ec_dev, EC_FEATURE_MOTION_SENSE))
cros_ec_sensors_register(ec_dev);
 
+   /* Check whether this EC has RTC support */
+   if (cros_ec_check_features(ec_dev, EC_FEATURE_RTC))
+   cros_ec_rtc_register(ec_dev);
+
if (ec_dev->max_passthru) {
/*
 * Register a PD device as well on top of this device.
-- 
2.9.3

-- 
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
--- 
You received this message because you are subscribed to the Google Groups 
"rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rtc-linux+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[rtc-linux] Re: [PATCH 7/7] mfd: cros_ec: add RTC as mfd subdevice

2017-04-03 Thread Enric Balletbo i Serra


On 03/04/17 16:25, Lee Jones wrote:
> On Fri, 24 Mar 2017, Enric Balletbo i Serra wrote:
> 
>> From: Stephen Barber 
>>
>> If the EC supports RTC host commands, expose an RTC device.
>>
>> Signed-off-by: Stephen Barber 
>> Signed-off-by: Enric Balletbo i Serra 
>> ---
>>  drivers/mfd/cros_ec.c | 18 ++
>>  1 file changed, 18 insertions(+)
>>
>> diff --git a/drivers/mfd/cros_ec.c b/drivers/mfd/cros_ec.c
>> index bbc17ab..1ff88b1 100644
>> --- a/drivers/mfd/cros_ec.c
>> +++ b/drivers/mfd/cros_ec.c
>> @@ -51,6 +51,11 @@ static const struct mfd_cell ec_pd_cell = {
>>  .pdata_size = sizeof(pd_p),
>>  };
>>  
>> +static const struct mfd_cell ec_rtc_cell = {
>> +.name = "cros-ec-rtc",
>> +.id   = -1,
> 
> Why -1?
> 
>> +};
>> +
>>  static irqreturn_t ec_irq_thread(int irq, void *data)
>>  {
>>  struct cros_ec_device *ec_dev = data;
>> @@ -238,6 +243,15 @@ static void cros_ec_sensors_register(struct 
>> cros_ec_device *ec_dev)
>>  kfree(msg);
>>  }
>>  
>> +static void cros_ec_rtc_register(struct cros_ec_device *ec_dev)
>> +{
>> +int ret;
>> +
>> +ret = mfd_add_devices(ec_dev->dev, 0, &ec_rtc_cell, 1, NULL, 0, NULL);
> 
> Why 0?
> 

Right, just maintained the one in the original. I think I can use
PLATFORM_DEVID_AUTO here?

>> +if (ret)
>> +dev_err(ec_dev->dev, "failed to add EC RTC\n");
>> +}
>> +
>>  int cros_ec_register(struct cros_ec_device *ec_dev)
>>  {
>>  struct device *dev = ec_dev->dev;
>> @@ -287,6 +301,10 @@ int cros_ec_register(struct cros_ec_device *ec_dev)
>>  if (cros_ec_check_features(ec_dev, EC_FEATURE_MOTION_SENSE))
>>  cros_ec_sensors_register(ec_dev);
>>  
>> +/* Check whether this EC has RTC support */
>> +if (cros_ec_check_features(ec_dev, EC_FEATURE_RTC))
>> +cros_ec_rtc_register(ec_dev);
>> +
>>  if (ec_dev->max_passthru) {
>>  /*
>>   * Register a PD device as well on top of this device.
> 

-- 
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
--- 
You received this message because you are subscribed to the Google Groups 
"rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rtc-linux+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[rtc-linux] Re: [PATCH 1/7] mfd: cros-ec: Fix host command buffer size

2017-04-03 Thread Enric Balletbo i Serra


On 03/04/17 16:30, Lee Jones wrote:
> On Mon, 03 Apr 2017, Lee Jones wrote:
> 
>> On Fri, 24 Mar 2017, Enric Balletbo i Serra wrote:
>>
>>> From: Vic Yang 
>>>
>>> For SPI, we can get up to 32 additional bytes for response preamble.
>>> The current overhead (2 bytes) may cause problems when we try to receive
>>> a big response. Update it to 32 bytes.
>>>
>>> Without this fix we could see a kernel BUG when we receive a big response
>>> from the Chrome EC when is connected via SPI.
>>>
>>> Signed-off-by: Vic Yang 
>>> Tested-by: Enric Balletbo i Serra 
>>> ---
>>>
>>>   This patch is a FIX, and I think that would be interesting see it merged
>>> in this release cycle. This should go through the MFD tree and can be picked
>>> independently of the other patches. Lee Jones I think this is for you.
>>>
>>>  include/linux/mfd/cros_ec.h | 3 ++-
>>>  1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> Applied, thanks.
> 
> Scrap that, I'll keep it with the set.
> 

Ok, I'll send a v2 asap with this patch and the few modifications requested on
patch 7/7. I'm wondering though if this specific patch could go with current
release cycle as (explained above) is a fix and current kernel is affected.

Thanks,
 Enric

>>> diff --git a/include/linux/mfd/cros_ec.h b/include/linux/mfd/cros_ec.h
>>> index b3e812f..3b16c90 100644
>>> --- a/include/linux/mfd/cros_ec.h
>>> +++ b/include/linux/mfd/cros_ec.h
>>> @@ -35,10 +35,11 @@
>>>   * Max bus-specific overhead incurred by request/responses.
>>>   * I2C requires 1 additional byte for requests.
>>>   * I2C requires 2 additional bytes for responses.
>>> + * SPI requires up to 32 additional bytes for responses.
>>>   * */
>>>  #define EC_PROTO_VERSION_UNKNOWN   0
>>>  #define EC_MAX_REQUEST_OVERHEAD1
>>> -#define EC_MAX_RESPONSE_OVERHEAD   2
>>> +#define EC_MAX_RESPONSE_OVERHEAD   32
>>>  
>>>  /*
>>>   * Command interface between EC and AP, for LPC, I2C and SPI interfaces.
>>
> 

-- 
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
--- 
You received this message because you are subscribed to the Google Groups 
"rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rtc-linux+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[rtc-linux] [PATCH v2 0/5] mfd: cros-ec: Some fixes and improvements.

2017-04-03 Thread Enric Balletbo i Serra
Dear all,

This is another patch series to fix and improve some cros-ec mfd related
things.

 * 1/5 mfd: cros-ec: Fix host command buffer size

  This patch is a FIX, and I think that would be interesting see it merged
in this release cycle. This should go through the MFD tree and can be picked
independently of the other patches. Lee Jones I think this is for you.

 * 2/5 mfd: cros_ec: Get rid of cros_ec_check_features from cros_ec_dev.

  As pointed by Lee Jones in this thread [1] we should not use the MFD API
outside of MFD. For this reason the cros-ec-rtc did not get accepted yet.
The reality is that we are calling mfd_add_devices from cros-ec-dev driver
already, so this patch get rid off the MFD calls inside the chardev driver
and moves to cros-ec MFD. Also I think the chardev device should simply
implement the ioctl calls to access to it from userspace.

 The above patch involves MFD, IIO and platform chrome subsystems.

 * 3/5 mfd: cros_ec: Introduce RTC commands and events definitions
 * 4/5 rtc: cros-ec: add cros-ec-rtc driver
 * 5/5 mfd: cros_ec: add RTC as mfd subdevice

 These patches are the cros-ec RTC driver, 3 and 4 patches are already
acked by the subsystem maintainers involved and are equal to the last
version I send. Patch 5 registers the rtc cell inside the cros-ec MFD
intead of cros-ec-dev chardev driver.

 Note that these 3 patches depends on [2] to build. I recommend apply
these series on top of [3]

Changes since v1:
 - Removed patch 'iio: cros_ec_sensors: Fix return value to get raw and
   calibbias data' from series as was already picked.
 - Removed patch 'iio: cros_ec_sensors: Fix return value to get raw and
   calibbias data' from series as was already picked.
 - Patch 2/5: Acked-by: Jonathan Cameron 

[1] https://www.spinics.net/lists/kernel/msg2465099.html
[2] https://lkml.org/lkml/2017/3/17/319
[3] https://lkml.org/lkml/2017/3/17/321

Best regards,

Enric Balletbo i Serra (1):
  mfd: cros_ec: Get rid of cros_ec_check_features from cros_ec_dev.

Stephen Barber (3):
  mfd: cros_ec: Introduce RTC commands and events definitions.
  rtc: cros-ec: add cros-ec-rtc driver.
  mfd: cros_ec: add RTC as mfd subdevice

Vic Yang (1):
  mfd: cros-ec: Fix host command buffer size

 .../iio/common/cros_ec_sensors/cros_ec_sensors.c   |   8 -
 .../common/cros_ec_sensors/cros_ec_sensors_core.c  |   8 +-
 drivers/iio/light/cros_ec_light_prox.c |   8 -
 drivers/iio/pressure/cros_ec_baro.c|   8 -
 drivers/mfd/cros_ec.c  | 178 +
 drivers/platform/chrome/cros_ec_dev.c  | 161 
 drivers/rtc/Kconfig|  10 +
 drivers/rtc/Makefile   |   1 +
 drivers/rtc/rtc-cros-ec.c  | 412 +
 include/linux/mfd/cros_ec.h|   9 +-
 include/linux/mfd/cros_ec_commands.h   |   8 +
 11 files changed, 621 insertions(+), 190 deletions(-)
 create mode 100644 drivers/rtc/rtc-cros-ec.c

-- 
2.9.3

-- 
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
--- 
You received this message because you are subscribed to the Google Groups 
"rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rtc-linux+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[rtc-linux] [PATCH v2 1/5] mfd: cros-ec: Fix host command buffer size

2017-04-03 Thread Enric Balletbo i Serra
From: Vic Yang 

For SPI, we can get up to 32 additional bytes for response preamble.
The current overhead (2 bytes) may cause problems when we try to receive
a big response. Update it to 32 bytes.

Without this fix we could see a kernel BUG when we receive a big response
from the Chrome EC when is connected via SPI.

Signed-off-by: Vic Yang 
Tested-by: Enric Balletbo i Serra 
---

  This patch is a FIX, and I think that would be interesting see it merged
in this release cycle. This should go through the MFD tree and can be picked
independently of the other patches. Lee Jones I think this is for you.

Changes since v1:
 - None

 include/linux/mfd/cros_ec.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/include/linux/mfd/cros_ec.h b/include/linux/mfd/cros_ec.h
index b3e812f..3b16c90 100644
--- a/include/linux/mfd/cros_ec.h
+++ b/include/linux/mfd/cros_ec.h
@@ -35,10 +35,11 @@
  * Max bus-specific overhead incurred by request/responses.
  * I2C requires 1 additional byte for requests.
  * I2C requires 2 additional bytes for responses.
+ * SPI requires up to 32 additional bytes for responses.
  * */
 #define EC_PROTO_VERSION_UNKNOWN   0
 #define EC_MAX_REQUEST_OVERHEAD1
-#define EC_MAX_RESPONSE_OVERHEAD   2
+#define EC_MAX_RESPONSE_OVERHEAD   32
 
 /*
  * Command interface between EC and AP, for LPC, I2C and SPI interfaces.
-- 
2.9.3

-- 
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
--- 
You received this message because you are subscribed to the Google Groups 
"rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rtc-linux+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[rtc-linux] [PATCH v2 4/5] rtc: cros-ec: add cros-ec-rtc driver.

2017-04-03 Thread Enric Balletbo i Serra
From: Stephen Barber 

On platforms with a Chrome OS EC, the EC can function as a simple RTC.
Add a basic driver with this functionality.

Signed-off-by: Stephen Barber 
Signed-off-by: Enric Balletbo i Serra 
Acked-by: Alexandre Belloni 
---

Changes since v1:
 - None

 drivers/rtc/Kconfig   |  10 ++
 drivers/rtc/Makefile  |   1 +
 drivers/rtc/rtc-cros-ec.c | 412 ++
 3 files changed, 423 insertions(+)
 create mode 100644 drivers/rtc/rtc-cros-ec.c

diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index 050bec7..b2939b4 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -1204,6 +1204,16 @@ config RTC_DRV_ZYNQMP
  If you say yes here you get support for the RTC controller found on
  Xilinx Zynq Ultrascale+ MPSoC.
 
+config RTC_DRV_CROS_EC
+   tristate "Chrome OS EC RTC driver"
+   depends on MFD_CROS_EC
+   help
+ If you say yes here you will get support for the
+ Chrome OS Embedded Controller's RTC.
+
+ This driver can also be built as a module. If so, the module
+ will be called rtc-cros-ec.
+
 comment "on-CPU RTC drivers"
 
 config RTC_DRV_ASM9260
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index 13857d2..8162983 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -41,6 +41,7 @@ obj-$(CONFIG_RTC_DRV_BQ4802)  += rtc-bq4802.o
 obj-$(CONFIG_RTC_DRV_CMOS) += rtc-cmos.o
 obj-$(CONFIG_RTC_DRV_COH901331)+= rtc-coh901331.o
 obj-$(CONFIG_RTC_DRV_CPCAP)+= rtc-cpcap.o
+obj-$(CONFIG_RTC_DRV_CROS_EC)  += rtc-cros-ec.o
 obj-$(CONFIG_RTC_DRV_DA9052)   += rtc-da9052.o
 obj-$(CONFIG_RTC_DRV_DA9055)   += rtc-da9055.o
 obj-$(CONFIG_RTC_DRV_DA9063)   += rtc-da9063.o
diff --git a/drivers/rtc/rtc-cros-ec.c b/drivers/rtc/rtc-cros-ec.c
new file mode 100644
index 000..a5c2512
--- /dev/null
+++ b/drivers/rtc/rtc-cros-ec.c
@@ -0,0 +1,412 @@
+/*
+ * RTC driver for Chrome OS Embedded Controller
+ *
+ * Copyright (c) 2017, Google, Inc
+ *
+ * Author: Stephen Barber 
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define DRV_NAME   "cros-ec-rtc"
+
+/**
+ * struct cros_ec_rtc - Driver data for EC RTC
+ *
+ * @cros_ec: Pointer to EC device
+ * @rtc: Pointer to RTC device
+ * @notifier: Notifier info for responding to EC events
+ * @saved_alarm: Alarm to restore when interrupts are reenabled
+ */
+struct cros_ec_rtc {
+   struct cros_ec_device *cros_ec;
+   struct rtc_device *rtc;
+   struct notifier_block notifier;
+   u32 saved_alarm;
+};
+
+static int cros_ec_rtc_get(struct cros_ec_device *cros_ec, u32 command,
+  u32 *response)
+{
+   int ret;
+   struct {
+   struct cros_ec_command msg;
+   struct ec_response_rtc data;
+   } __packed msg;
+
+   memset(&msg, 0, sizeof(msg));
+   msg.msg.command = command;
+   msg.msg.insize = sizeof(msg.data);
+
+   ret = cros_ec_cmd_xfer_status(cros_ec, &msg.msg);
+   if (ret < 0) {
+   dev_err(cros_ec->dev,
+   "error getting %s from EC: %d\n",
+   command == EC_CMD_RTC_GET_VALUE ? "time" : "alarm",
+   ret);
+   return ret;
+   }
+
+   *response = msg.data.time;
+
+   return 0;
+}
+
+static int cros_ec_rtc_set(struct cros_ec_device *cros_ec, u32 command,
+  u32 param)
+{
+   int ret = 0;
+   struct {
+   struct cros_ec_command msg;
+   struct ec_response_rtc data;
+   } __packed msg;
+
+   memset(&msg, 0, sizeof(msg));
+   msg.msg.command = command;
+   msg.msg.outsize = sizeof(msg.data);
+   msg.data.time = param;
+
+   ret = cros_ec_cmd_xfer_status(cros_ec, &msg.msg);
+   if (ret < 0) {
+   dev_err(cros_ec->dev, "error setting %s on EC: %d\n",
+   command == EC_CMD_RTC_SET_VALUE ? "time" : "alarm",
+   ret);
+   return ret;
+   }
+
+   return 0;
+}
+
+/* Read the current time from the EC. */
+static int cros_ec_rtc_read_time(struct device *dev, struct rtc_time *tm)
+{
+   struct cros_ec_rtc *cros_ec_rtc = dev_get_drvdata(dev);
+   struct cros_ec_device *cros_ec = cros_ec_rtc->cros_ec;
+   int ret;
+   u32 time;
+
+   ret = cros_ec_

[rtc-linux] [PATCH v2 3/5] mfd: cros_ec: Introduce RTC commands and events definitions.

2017-04-03 Thread Enric Balletbo i Serra
From: Stephen Barber 

The EC can function as a simple RT, this patch adds the RTC related
definitions needed by the rtc-cros-ec driver.

Signed-off-by: Stephen Barber 
Signed-off-by: Enric Balletbo i Serra 
Acked-by: Lee Jones 
---
 include/linux/mfd/cros_ec_commands.h | 8 
 1 file changed, 8 insertions(+)

diff --git a/include/linux/mfd/cros_ec_commands.h 
b/include/linux/mfd/cros_ec_commands.h
index 84e1abb..852ce34 100644
--- a/include/linux/mfd/cros_ec_commands.h
+++ b/include/linux/mfd/cros_ec_commands.h
@@ -286,6 +286,9 @@ enum host_event_code {
/* Hang detect logic detected a hang and warm rebooted the AP */
EC_HOST_EVENT_HANG_REBOOT = 21,
 
+   /* EC RTC event occurred */
+   EC_HOST_EVENT_RTC = 26,
+
/*
 * The high bit of the event mask is not used as a host event code.  If
 * it reads back as set, then the entire event mask should be
@@ -794,6 +797,8 @@ enum ec_feature_code {
EC_FEATURE_USB_MUX = 23,
/* Motion Sensor code has an internal software FIFO */
EC_FEATURE_MOTION_SENSE_FIFO = 24,
+   /* EC has RTC feature that can be controlled by host commands */
+   EC_FEATURE_RTC = 27,
 };
 
 #define EC_FEATURE_MASK_0(event_code) (1UL << (event_code % 32))
@@ -1704,6 +1709,9 @@ struct ec_response_rtc {
 #define EC_CMD_RTC_SET_VALUE 0x46
 #define EC_CMD_RTC_SET_ALARM 0x47
 
+/* Pass as param to SET_ALARM to clear the current alarm */
+#define EC_RTC_ALARM_CLEAR 0
+
 /*/
 /* Port80 log access */
 
-- 
2.9.3

-- 
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
--- 
You received this message because you are subscribed to the Google Groups 
"rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rtc-linux+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[rtc-linux] [PATCH v2 5/5] mfd: cros_ec: add RTC as mfd subdevice

2017-04-03 Thread Enric Balletbo i Serra
From: Stephen Barber 

If the EC supports RTC host commands, expose an RTC device.

Signed-off-by: Stephen Barber 
Signed-off-by: Enric Balletbo i Serra 
---

Changes since v1:
 - Use PLATFORM_DEVID_AUTO to add the subdevice.

 drivers/mfd/cros_ec.c | 18 ++
 1 file changed, 18 insertions(+)

diff --git a/drivers/mfd/cros_ec.c b/drivers/mfd/cros_ec.c
index bbc17ab..76874be 100644
--- a/drivers/mfd/cros_ec.c
+++ b/drivers/mfd/cros_ec.c
@@ -51,6 +51,10 @@ static const struct mfd_cell ec_pd_cell = {
.pdata_size = sizeof(pd_p),
 };
 
+static const struct mfd_cell ec_rtc_cell = {
+   .name = "cros-ec-rtc",
+};
+
 static irqreturn_t ec_irq_thread(int irq, void *data)
 {
struct cros_ec_device *ec_dev = data;
@@ -238,6 +242,16 @@ static void cros_ec_sensors_register(struct cros_ec_device 
*ec_dev)
kfree(msg);
 }
 
+static void cros_ec_rtc_register(struct cros_ec_device *ec_dev)
+{
+   int ret;
+
+   ret = mfd_add_devices(ec_dev->dev, PLATFORM_DEVID_AUTO, &ec_rtc_cell,
+ 1, NULL, 0, NULL);
+   if (ret)
+   dev_err(ec_dev->dev, "failed to add EC RTC\n");
+}
+
 int cros_ec_register(struct cros_ec_device *ec_dev)
 {
struct device *dev = ec_dev->dev;
@@ -287,6 +301,10 @@ int cros_ec_register(struct cros_ec_device *ec_dev)
if (cros_ec_check_features(ec_dev, EC_FEATURE_MOTION_SENSE))
cros_ec_sensors_register(ec_dev);
 
+   /* Check whether this EC has RTC support */
+   if (cros_ec_check_features(ec_dev, EC_FEATURE_RTC))
+   cros_ec_rtc_register(ec_dev);
+
if (ec_dev->max_passthru) {
/*
 * Register a PD device as well on top of this device.
-- 
2.9.3

-- 
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
--- 
You received this message because you are subscribed to the Google Groups 
"rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rtc-linux+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[rtc-linux] [PATCH v2 2/5] mfd: cros_ec: Get rid of cros_ec_check_features from cros_ec_dev.

2017-04-03 Thread Enric Balletbo i Serra
The cros_ec_dev driver should be used only to expose the Chrome OS Embedded
Controller to user-space and should not be used to add MFD devices by
calling mfd_add_devices. This patch moves this logic to the MFD cros_ec
driver and removes the MFD bits from the character device driver. Also
makes independent the IIO driver from the character device as also has no
sense.

Signed-off-by: Enric Balletbo i Serra 
Acked-by: Jonathan Cameron 
---

  As pointed by Lee Jones in this thread [1] we should not use the MFD API
outside of MFD. For this reason the cros-ec-rtc did not get accepted yet.
The reality is that we are calling mfd_add_devices from cros-ec-dev driver
already, so this patch get rid off the MFD calls inside the chardev driver
and moves to cros-ec MFD. Also I think the chardev device should simply
implement the ioctl calls to access to it from userspace.

Changes since v1:
 - Acked-by: Jonathan Cameron 

[1]  https://www.spinics.net/lists/kernel/msg2465099.html

 .../iio/common/cros_ec_sensors/cros_ec_sensors.c   |   8 -
 .../common/cros_ec_sensors/cros_ec_sensors_core.c  |   8 +-
 drivers/iio/light/cros_ec_light_prox.c |   8 -
 drivers/iio/pressure/cros_ec_baro.c|   8 -
 drivers/mfd/cros_ec.c  | 160 
 drivers/platform/chrome/cros_ec_dev.c  | 161 -
 include/linux/mfd/cros_ec.h|   6 +-
 7 files changed, 170 insertions(+), 189 deletions(-)

diff --git a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c 
b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c
index 38e8783..9b53a01 100644
--- a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c
+++ b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c
@@ -191,19 +191,11 @@ static const struct iio_info ec_sensors_info = {
 static int cros_ec_sensors_probe(struct platform_device *pdev)
 {
struct device *dev = &pdev->dev;
-   struct cros_ec_dev *ec_dev = dev_get_drvdata(dev->parent);
-   struct cros_ec_device *ec_device;
struct iio_dev *indio_dev;
struct cros_ec_sensors_state *state;
struct iio_chan_spec *channel;
int ret, i;
 
-   if (!ec_dev || !ec_dev->ec_dev) {
-   dev_warn(&pdev->dev, "No CROS EC device found.\n");
-   return -EINVAL;
-   }
-   ec_device = ec_dev->ec_dev;
-
indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*state));
if (!indio_dev)
return -ENOMEM;
diff --git a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c 
b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
index 416cae5..0cdb64a 100644
--- a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
+++ b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
@@ -41,12 +41,13 @@ int cros_ec_sensors_core_init(struct platform_device *pdev,
 {
struct device *dev = &pdev->dev;
struct cros_ec_sensors_core_state *state = iio_priv(indio_dev);
-   struct cros_ec_dev *ec = dev_get_drvdata(pdev->dev.parent);
+   struct cros_ec_device *ec_dev = dev_get_drvdata(pdev->dev.parent);
struct cros_ec_sensor_platform *sensor_platform = dev_get_platdata(dev);
 
platform_set_drvdata(pdev, indio_dev);
 
-   state->ec = ec->ec_dev;
+   state->ec = ec_dev;
+
state->msg = devm_kzalloc(&pdev->dev,
max((u16)sizeof(struct ec_params_motion_sense),
state->ec->max_response), GFP_KERNEL);
@@ -59,7 +60,8 @@ int cros_ec_sensors_core_init(struct platform_device *pdev,
 
/* Set up the host command structure. */
state->msg->version = 2;
-   state->msg->command = EC_CMD_MOTION_SENSE_CMD + ec->cmd_offset;
+   state->msg->command = EC_CMD_MOTION_SENSE_CMD +
+   sensor_platform->cmd_offset;
state->msg->outsize = sizeof(struct ec_params_motion_sense);
 
indio_dev->dev.parent = &pdev->dev;
diff --git a/drivers/iio/light/cros_ec_light_prox.c 
b/drivers/iio/light/cros_ec_light_prox.c
index 7217223..2133ddc 100644
--- a/drivers/iio/light/cros_ec_light_prox.c
+++ b/drivers/iio/light/cros_ec_light_prox.c
@@ -181,19 +181,11 @@ static const struct iio_info cros_ec_light_prox_info = {
 static int cros_ec_light_prox_probe(struct platform_device *pdev)
 {
struct device *dev = &pdev->dev;
-   struct cros_ec_dev *ec_dev = dev_get_drvdata(dev->parent);
-   struct cros_ec_device *ec_device;
struct iio_dev *indio_dev;
struct cros_ec_light_prox_state *state;
struct iio_chan_spec *channel;
int ret;
 
-   if (!ec_dev || !ec_dev->ec_dev) {
-   dev_warn(dev, "No CROS EC device found.\n");
-   return -EINVAL;
-   }
-   ec_device = ec_dev->ec_dev;
-
i

[rtc-linux] Re: [PATCH v2 2/5] mfd: cros_ec: Get rid of cros_ec_check_features from cros_ec_dev.

2017-04-20 Thread Enric Balletbo i Serra


On 11/04/17 11:19, Lee Jones wrote:
> On Mon, 03 Apr 2017, Enric Balletbo i Serra wrote:
> 
>> The cros_ec_dev driver should be used only to expose the Chrome OS Embedded
>> Controller to user-space and should not be used to add MFD devices by
>> calling mfd_add_devices. This patch moves this logic to the MFD cros_ec
>> driver and removes the MFD bits from the character device driver. Also
>> makes independent the IIO driver from the character device as also has no
>> sense.
>>
>> Signed-off-by: Enric Balletbo i Serra 
>> Acked-by: Jonathan Cameron 
>> ---
>>
>>   As pointed by Lee Jones in this thread [1] we should not use the MFD API
>> outside of MFD. For this reason the cros-ec-rtc did not get accepted yet.
>> The reality is that we are calling mfd_add_devices from cros-ec-dev driver
>> already, so this patch get rid off the MFD calls inside the chardev driver
>> and moves to cros-ec MFD. Also I think the chardev device should simply
>> implement the ioctl calls to access to it from userspace.
>>
>> Changes since v1:
>>  - Acked-by: Jonathan Cameron 
>>
>> [1]  https://www.spinics.net/lists/kernel/msg2465099.html
>>
>>  .../iio/common/cros_ec_sensors/cros_ec_sensors.c   |   8 -
>>  .../common/cros_ec_sensors/cros_ec_sensors_core.c  |   8 +-
>>  drivers/iio/light/cros_ec_light_prox.c |   8 -
>>  drivers/iio/pressure/cros_ec_baro.c|   8 -
>>  drivers/mfd/cros_ec.c  | 160 
>> 
>>  drivers/platform/chrome/cros_ec_dev.c  | 161 
>> -
> 
> Did you create this patch with "-M"?
> 

Oops, no, will do in next version

> This also requires a drivers/platform Ack.
> 

Olof, Benson, could one of you take a look at this and ack if you find this it
is ok, please?

Thanks,
 Enric


>>  include/linux/mfd/cros_ec.h|   6 +-
>>  7 files changed, 170 insertions(+), 189 deletions(-)
>>
>> diff --git a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c 
>> b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c
>> index 38e8783..9b53a01 100644
>> --- a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c
>> +++ b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c
>> @@ -191,19 +191,11 @@ static const struct iio_info ec_sensors_info = {
>>  static int cros_ec_sensors_probe(struct platform_device *pdev)
>>  {
>>  struct device *dev = &pdev->dev;
>> -struct cros_ec_dev *ec_dev = dev_get_drvdata(dev->parent);
>> -struct cros_ec_device *ec_device;
>>  struct iio_dev *indio_dev;
>>  struct cros_ec_sensors_state *state;
>>  struct iio_chan_spec *channel;
>>  int ret, i;
>>  
>> -if (!ec_dev || !ec_dev->ec_dev) {
>> -dev_warn(&pdev->dev, "No CROS EC device found.\n");
>> -return -EINVAL;
>> -}
>> -ec_device = ec_dev->ec_dev;
>> -
>>  indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*state));
>>  if (!indio_dev)
>>  return -ENOMEM;
>> diff --git a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c 
>> b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
>> index 416cae5..0cdb64a 100644
>> --- a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
>> +++ b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
>> @@ -41,12 +41,13 @@ int cros_ec_sensors_core_init(struct platform_device 
>> *pdev,
>>  {
>>  struct device *dev = &pdev->dev;
>>  struct cros_ec_sensors_core_state *state = iio_priv(indio_dev);
>> -struct cros_ec_dev *ec = dev_get_drvdata(pdev->dev.parent);
>> +struct cros_ec_device *ec_dev = dev_get_drvdata(pdev->dev.parent);
>>  struct cros_ec_sensor_platform *sensor_platform = dev_get_platdata(dev);
>>  
>>  platform_set_drvdata(pdev, indio_dev);
>>  
>> -state->ec = ec->ec_dev;
>> +state->ec = ec_dev;
>> +
>>  state->msg = devm_kzalloc(&pdev->dev,
>>  max((u16)sizeof(struct ec_params_motion_sense),
>>  state->ec->max_response), GFP_KERNEL);
>> @@ -59,7 +60,8 @@ int cros_ec_sensors_core_init(struct platform_device *pdev,
>>  
>>  /* Set up the host command structure. */
>>  state->msg->version = 2;
>> -state->msg->command = EC_CMD_MOTION_SENSE_CMD + ec->cmd_offset;
>> +state->msg->command = EC_CMD_MOTION_SENSE_CMD +
>> + 

[rtc-linux] Re: [PATCH v2 5/5] mfd: cros_ec: add RTC as mfd subdevice

2017-04-20 Thread Enric Balletbo i Serra
Lee,

On 11/04/17 11:48, Lee Jones wrote:
> On Mon, 03 Apr 2017, Enric Balletbo i Serra wrote:
> 
>> From: Stephen Barber 
>>
>> If the EC supports RTC host commands, expose an RTC device.
> 
> This could be made nicer by checking RTC compatibility in the RTC
> driver.  So register it regardless, then check if the device is
> supported from within.  If it's not supported simply return -ENODEV
> from probe.
> 

Currently rtc-cros-ec and the other subdevices doesn't know how to check the
cros-ec MFD features, to do this I need to export cros_ec_check_features to a
public header and the rtc and other subdrivers should call the check function.

Seems to me more reasonable that the MFD checks the possible cells that can have
and only register the ones that really has (the cros-ec MFD can have different
cells depending on the device). Call every probe for all possible cells seems to
me a unnecessary step. The MFD is able to know which cells has, so IMHO then the
subdrivers are more independent of the MFD.

It's just an opinion so I'll let you the final decision.

Cheers,
 Enric

>> Signed-off-by: Stephen Barber 
>> Signed-off-by: Enric Balletbo i Serra 
>> ---
>>
>> Changes since v1:
>>  - Use PLATFORM_DEVID_AUTO to add the subdevice.
>>
>>  drivers/mfd/cros_ec.c | 18 ++
>>  1 file changed, 18 insertions(+)
>>
>> diff --git a/drivers/mfd/cros_ec.c b/drivers/mfd/cros_ec.c
>> index bbc17ab..76874be 100644
>> --- a/drivers/mfd/cros_ec.c
>> +++ b/drivers/mfd/cros_ec.c
>> @@ -51,6 +51,10 @@ static const struct mfd_cell ec_pd_cell = {
>>  .pdata_size = sizeof(pd_p),
>>  };
>>  
>> +static const struct mfd_cell ec_rtc_cell = {
>> +.name = "cros-ec-rtc",
>> +};
>> +
>>  static irqreturn_t ec_irq_thread(int irq, void *data)
>>  {
>>  struct cros_ec_device *ec_dev = data;
>> @@ -238,6 +242,16 @@ static void cros_ec_sensors_register(struct 
>> cros_ec_device *ec_dev)
>>  kfree(msg);
>>  }
>>  
>> +static void cros_ec_rtc_register(struct cros_ec_device *ec_dev)
>> +{
>> +int ret;
>> +
>> +ret = mfd_add_devices(ec_dev->dev, PLATFORM_DEVID_AUTO, &ec_rtc_cell,
>> +  1, NULL, 0, NULL);
>> +if (ret)
>> +dev_err(ec_dev->dev, "failed to add EC RTC\n");
>> +}
>> +
>>  int cros_ec_register(struct cros_ec_device *ec_dev)
>>  {
>>  struct device *dev = ec_dev->dev;
>> @@ -287,6 +301,10 @@ int cros_ec_register(struct cros_ec_device *ec_dev)
>>  if (cros_ec_check_features(ec_dev, EC_FEATURE_MOTION_SENSE))
>>  cros_ec_sensors_register(ec_dev);
>>  
>> +/* Check whether this EC has RTC support */
>> +if (cros_ec_check_features(ec_dev, EC_FEATURE_RTC))
>> +cros_ec_rtc_register(ec_dev);
>> +
>>  if (ec_dev->max_passthru) {
>>  /*
>>   * Register a PD device as well on top of this device.
> 

-- 
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
--- 
You received this message because you are subscribed to the Google Groups 
"rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rtc-linux+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.