Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1445262 > unrolled thread

[PATCH 00/10] Add support for cros-ec-sensors

Started byEnric Balletbo i Serra <enric.balletbo@collabora.com>
First post2016-07-18 09:10 +0200
Last post2016-07-18 09:10 +0200
Articles 6 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH 00/10] Add support for cros-ec-sensors Enric Balletbo i Serra <enric.balletbo@collabora.com> - 2016-07-18 09:10 +0200
    [PATCH 03/10] iio: core: Add double tap as possible gesture Enric Balletbo i Serra <enric.balletbo@collabora.com> - 2016-07-18 09:10 +0200
      Re: [PATCH 03/10] iio: core: Add double tap as possible gesture Jonathan Cameron <jic23@kernel.org> - 2016-07-19 07:40 +0200
    [PATCH 01/10] mfd: cros_ec: add ChromeOS EC sensor platform information. Enric Balletbo i Serra <enric.balletbo@collabora.com> - 2016-07-18 09:10 +0200
      Re: [PATCH 01/10] mfd: cros_ec: add ChromeOS EC sensor platform  information. Jonathan Cameron <jic23@kernel.org> - 2016-07-19 07:40 +0200
    [PATCH 10/10] platform/chrome: cros_ec_dev - Register cros-ec sensors Enric Balletbo i Serra <enric.balletbo@collabora.com> - 2016-07-18 09:10 +0200

#1445262 — [PATCH 00/10] Add support for cros-ec-sensors

FromEnric Balletbo i Serra <enric.balletbo@collabora.com>
Date2016-07-18 09:10 +0200
Subject[PATCH 00/10] Add support for cros-ec-sensors
Message-ID<rWaQF-352-5@gated-at.bofh.it>
Hi,

This is the first patchset to add support for the sensors behind the ChromeOS
Embedded Controller. The first two patches needs to reviewed  by Lee Jones
as are MFD related, then there are six IIO patches for Jonathan Cameron and
finally the last two patches are platform/chrome specific so are for Olof.

The code was checked out from the ChromeOS v3.18 tree and forward ported to
mainline solving all the conflicts and build issues. I splitted the code in
single patches that have sense by themselves in order to avoid the chances
to fail.

Note that the patches depends on this [1] to apply and work.

[1] https://lkml.org/lkml/2016/7/1/188

Waiting for your reviews and feedback.

Best regards,

Enric Balletbo i Serra (8):
  mfd: cros_ec: add ChromeOS EC sensor platform information.
  mfd: cros_ec: update MOTIONSENSE definitions and commands.
  iio: cros_ec: Add common functions for cros_ec sensors.
  iio: cros_ec_sensors: add ChromeOS EC Contiguous Sensors driver
  iio: cros_ec_light_prox: add ChromeOS EC Light and Proximity Sensors
  iio: cros_ec_activity: add ChromeOS EC Activity Sensors
  iio: cros_ec_sensors_ring: add ChromeOS EC Sensors Ring
  platform/chrome: cros_ec_dev - Register cros-ec sensors

Gwendal Grignou (1):
  iio: core: Add double tap as possible gesture

Vincent Palatin (1):
  platform/chrome: Introduce a new function to check EC features.

 drivers/iio/common/Kconfig                         |   1 +
 drivers/iio/common/Makefile                        |   1 +
 drivers/iio/common/cros_ec_sensors/Kconfig         |  50 ++
 drivers/iio/common/cros_ec_sensors/Makefile        |   9 +
 .../iio/common/cros_ec_sensors/cros_ec_activity.c  | 294 +++++++++++
 .../common/cros_ec_sensors/cros_ec_light_prox.c    | 288 +++++++++++
 .../iio/common/cros_ec_sensors/cros_ec_sensors.c   | 322 ++++++++++++
 .../common/cros_ec_sensors/cros_ec_sensors_core.c  | 564 +++++++++++++++++++++
 .../common/cros_ec_sensors/cros_ec_sensors_core.h  | 155 ++++++
 .../common/cros_ec_sensors/cros_ec_sensors_ring.c  | 541 ++++++++++++++++++++
 drivers/iio/industrialio-core.c                    |   1 +
 drivers/platform/chrome/cros_ec_dev.c              | 159 ++++++
 include/linux/mfd/cros_ec.h                        |  11 +
 include/linux/mfd/cros_ec_commands.h               | 344 +++++++++++--
 include/uapi/linux/iio/types.h                     |   1 +
 15 files changed, 2712 insertions(+), 29 deletions(-)
 create mode 100644 drivers/iio/common/cros_ec_sensors/Kconfig
 create mode 100644 drivers/iio/common/cros_ec_sensors/Makefile
 create mode 100644 drivers/iio/common/cros_ec_sensors/cros_ec_activity.c
 create mode 100644 drivers/iio/common/cros_ec_sensors/cros_ec_light_prox.c
 create mode 100644 drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c
 create mode 100644 drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
 create mode 100644 drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.h
 create mode 100644 drivers/iio/common/cros_ec_sensors/cros_ec_sensors_ring.c

-- 
2.1.0

[toc] | [next] | [standalone]


#1445263 — [PATCH 03/10] iio: core: Add double tap as possible gesture

FromEnric Balletbo i Serra <enric.balletbo@collabora.com>
Date2016-07-18 09:10 +0200
Subject[PATCH 03/10] iio: core: Add double tap as possible gesture
Message-ID<rWaQG-352-35@gated-at.bofh.it>
In reply to#1445262
From: Gwendal Grignou <gwendal@chromium.org>

This is an interface change: however, the sysfs entry is based on string,
so if other gestures are added on the trunk in the meantime, we will
still be able to merge this change.

Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Signed-off-by: Guenter Roeck <groeck@chromium.org>
[enric: Rebased and resolved conflicts]
Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
---
 drivers/iio/industrialio-core.c | 1 +
 include/uapi/linux/iio/types.h  | 1 +
 2 files changed, 2 insertions(+)

diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
index e6319a9..f700e67 100644
--- a/drivers/iio/industrialio-core.c
+++ b/drivers/iio/industrialio-core.c
@@ -119,6 +119,7 @@ static const char * const iio_modifier_names[] = {
 	[IIO_MOD_Q] = "q",
 	[IIO_MOD_CO2] = "co2",
 	[IIO_MOD_VOC] = "voc",
+	[IIO_MOD_DOUBLE_TAP] = "double_tap",
 };
 
 /* relies on pairs of these shared then separate */
diff --git a/include/uapi/linux/iio/types.h b/include/uapi/linux/iio/types.h
index b0916fc..c290167 100644
--- a/include/uapi/linux/iio/types.h
+++ b/include/uapi/linux/iio/types.h
@@ -79,6 +79,7 @@ enum iio_modifier {
 	IIO_MOD_CO2,
 	IIO_MOD_VOC,
 	IIO_MOD_LIGHT_UV,
+	IIO_MOD_DOUBLE_TAP,
 };
 
 enum iio_event_type {
-- 
2.1.0

[toc] | [prev] | [next] | [standalone]


#1446035 — Re: [PATCH 03/10] iio: core: Add double tap as possible gesture

FromJonathan Cameron <jic23@kernel.org>
Date2016-07-19 07:40 +0200
SubjectRe: [PATCH 03/10] iio: core: Add double tap as possible gesture
Message-ID<rWvV8-8mi-13@gated-at.bofh.it>
In reply to#1445263
On 18/07/16 08:02, Enric Balletbo i Serra wrote:
> From: Gwendal Grignou <gwendal@chromium.org>
> 
> This is an interface change: however, the sysfs entry is based on string,
> so if other gestures are added on the trunk in the meantime, we will
> still be able to merge this change.
> 
> Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
> Signed-off-by: Guenter Roeck <groeck@chromium.org>
> [enric: Rebased and resolved conflicts]
> Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
So you are creating an entire channel type for double tap?

Not keen on this I'm afraid.

The activity types in there are the moment are not events, but rather
attempts to estimate the 'likelihood' that a given activity is currently
being undertaken.

Hmm. Double tap is more of an event type.  It's one I've been wondering
how to describe for a while... At the end of the day it's just a
reasonably sophisticated filter - kind of a 'magic' version of Rate
of Change.  Unfortunately there isn't a clean mathematical definition
as it can be implemented in lots of ways.  

I guess the best may be to just have it as an event type on it's own...

What do others think?

Jonathan
> ---
>  drivers/iio/industrialio-core.c | 1 +
>  include/uapi/linux/iio/types.h  | 1 +
>  2 files changed, 2 insertions(+)
> 
> diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
> index e6319a9..f700e67 100644
> --- a/drivers/iio/industrialio-core.c
> +++ b/drivers/iio/industrialio-core.c
> @@ -119,6 +119,7 @@ static const char * const iio_modifier_names[] = {
>  	[IIO_MOD_Q] = "q",
>  	[IIO_MOD_CO2] = "co2",
>  	[IIO_MOD_VOC] = "voc",
> +	[IIO_MOD_DOUBLE_TAP] = "double_tap",
>  };
>  
>  /* relies on pairs of these shared then separate */
> diff --git a/include/uapi/linux/iio/types.h b/include/uapi/linux/iio/types.h
> index b0916fc..c290167 100644
> --- a/include/uapi/linux/iio/types.h
> +++ b/include/uapi/linux/iio/types.h
> @@ -79,6 +79,7 @@ enum iio_modifier {
>  	IIO_MOD_CO2,
>  	IIO_MOD_VOC,
>  	IIO_MOD_LIGHT_UV,
> +	IIO_MOD_DOUBLE_TAP,
>  };
>  
>  enum iio_event_type {
> 

[toc] | [prev] | [next] | [standalone]


#1445266 — [PATCH 01/10] mfd: cros_ec: add ChromeOS EC sensor platform information.

FromEnric Balletbo i Serra <enric.balletbo@collabora.com>
Date2016-07-18 09:10 +0200
Subject[PATCH 01/10] mfd: cros_ec: add ChromeOS EC sensor platform information.
Message-ID<rWaQH-352-39@gated-at.bofh.it>
In reply to#1445262
The platform information will be used for the new cros-ec sensors driver
that presents sensors attached to the ChromeOS Embedded Controller.

Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
---
 include/linux/mfd/cros_ec.h | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/include/linux/mfd/cros_ec.h b/include/linux/mfd/cros_ec.h
index d6539c1..cd4833a 100644
--- a/include/linux/mfd/cros_ec.h
+++ b/include/linux/mfd/cros_ec.h
@@ -151,6 +151,16 @@ struct cros_ec_device {
 	int event_size;
 };
 
+/* struct cros_ec_sensor_platform - ChromeOS EC sensor platform information
+ *
+ * On top of cros_ec_devicem information cros_ec_sensors needs.
+ *
+ * @sensor_num: Id of the sensor, as reported by the EC.
+ */
+struct cros_ec_sensor_platform {
+	u8 sensor_num;
+};
+
 /* struct cros_ec_platform - ChromeOS EC platform information
  *
  * @ec_name: name of EC device (e.g. 'cros-ec', 'cros-pd', ...)
-- 
2.1.0

[toc] | [prev] | [next] | [standalone]


#1446038 — Re: [PATCH 01/10] mfd: cros_ec: add ChromeOS EC sensor platform information.

FromJonathan Cameron <jic23@kernel.org>
Date2016-07-19 07:40 +0200
SubjectRe: [PATCH 01/10] mfd: cros_ec: add ChromeOS EC sensor platform information.
Message-ID<rWvV8-8mi-21@gated-at.bofh.it>
In reply to#1445266
On 18/07/16 08:02, Enric Balletbo i Serra wrote:
> The platform information will be used for the new cros-ec sensors driver
> that presents sensors attached to the ChromeOS Embedded Controller.
> 
> Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
> Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
Bring this in as an when you need it in the rest of the series.
It certainly doesn't need it's own patch.
> ---
>  include/linux/mfd/cros_ec.h | 10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/include/linux/mfd/cros_ec.h b/include/linux/mfd/cros_ec.h
> index d6539c1..cd4833a 100644
> --- a/include/linux/mfd/cros_ec.h
> +++ b/include/linux/mfd/cros_ec.h
> @@ -151,6 +151,16 @@ struct cros_ec_device {
>  	int event_size;
>  };
>  
Check your kernel doc formatting.
> +/* struct cros_ec_sensor_platform - ChromeOS EC sensor platform information
> + *
> + * On top of cros_ec_devicem information cros_ec_sensors needs.
> + *
> + * @sensor_num: Id of the sensor, as reported by the EC.
> + */
> +struct cros_ec_sensor_platform {
> +	u8 sensor_num;
> +};
> +
>  /* struct cros_ec_platform - ChromeOS EC platform information
>   *
>   * @ec_name: name of EC device (e.g. 'cros-ec', 'cros-pd', ...)
> 

[toc] | [prev] | [next] | [standalone]


#1445267 — [PATCH 10/10] platform/chrome: cros_ec_dev - Register cros-ec sensors

FromEnric Balletbo i Serra <enric.balletbo@collabora.com>
Date2016-07-18 09:10 +0200
Subject[PATCH 10/10] platform/chrome: cros_ec_dev - Register cros-ec sensors
Message-ID<rWaQH-352-41@gated-at.bofh.it>
In reply to#1445262
Check whether the ChromeOS Embedded Controller is a sensor hub and in
such case issue a command to get the number of sensors and register them
all.

Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
---
 drivers/platform/chrome/cros_ec_dev.c | 122 ++++++++++++++++++++++++++++++++++
 1 file changed, 122 insertions(+)

diff --git a/drivers/platform/chrome/cros_ec_dev.c b/drivers/platform/chrome/cros_ec_dev.c
index fa5f060..0bec60e 100644
--- a/drivers/platform/chrome/cros_ec_dev.c
+++ b/drivers/platform/chrome/cros_ec_dev.c
@@ -18,6 +18,7 @@
  */
 
 #include <linux/fs.h>
+#include <linux/mfd/core.h>
 #include <linux/module.h>
 #include <linux/platform_device.h>
 #include <linux/slab.h>
@@ -265,6 +266,123 @@ static void __remove(struct device *dev)
 	kfree(ec);
 }
 
+static void cros_ec_sensors_register(struct cros_ec_dev *ec)
+{
+	/*
+	 * Issue a command to get the number of sensor reported.
+	 * Build an array of sensors driver and register them all.
+	 */
+	int ret, i, id, sensor_num;
+	struct mfd_cell *sensor_cells;
+	struct cros_ec_sensor_platform *sensor_platforms;
+	int sensor_type[MOTIONSENSE_TYPE_MAX];
+	struct ec_params_motion_sense *params;
+	struct ec_response_motion_sense *resp;
+	struct cros_ec_command *msg;
+
+	msg = kzalloc(sizeof(struct cros_ec_command) +
+		      max(sizeof(*params), sizeof(*resp)), GFP_KERNEL);
+	if (msg == NULL)
+		return;
+
+	msg->version = 2;
+	msg->command = EC_CMD_MOTION_SENSE_CMD + ec->cmd_offset;
+	msg->outsize = sizeof(*params);
+	msg->insize = sizeof(*resp);
+
+	params = (struct ec_params_motion_sense *)msg->data;
+	params->cmd = MOTIONSENSE_CMD_DUMP;
+
+	ret = cros_ec_cmd_xfer(ec->ec_dev, msg);
+	if (ret < 0 || msg->result != EC_RES_SUCCESS) {
+		dev_warn(ec->dev, "cannot get EC sensor information: %d/%d\n",
+			 ret, msg->result);
+		goto error;
+	}
+
+	resp = (struct ec_response_motion_sense *)msg->data;
+	sensor_num = resp->dump.sensor_count;
+	/* Allocate 2 extra sensors in case lid angle or FIFO are needed */
+	sensor_cells = kzalloc(sizeof(struct mfd_cell) * (sensor_num + 2),
+			       GFP_KERNEL);
+	if (sensor_cells == NULL)
+		goto error;
+
+	sensor_platforms = kzalloc(sizeof(struct cros_ec_sensor_platform) *
+		  (sensor_num + 1), GFP_KERNEL);
+	if (sensor_platforms == NULL)
+		goto error_platforms;
+
+	memset(sensor_type, 0, sizeof(sensor_type));
+	id = 0;
+	for (i = 0; i < sensor_num; i++) {
+		params->cmd = MOTIONSENSE_CMD_INFO;
+		params->info.sensor_num = i;
+		ret = cros_ec_cmd_xfer(ec->ec_dev, msg);
+		if ((ret < 0) || msg->result != EC_RES_SUCCESS) {
+			dev_warn(ec->dev, "no info for EC sensor %d : %d/%d\n",
+				 i, ret, msg->result);
+			continue;
+		}
+		switch (resp->info.type) {
+		case MOTIONSENSE_TYPE_ACCEL:
+			sensor_cells[id].name = "cros-ec-accel";
+			break;
+		case MOTIONSENSE_TYPE_GYRO:
+			sensor_cells[id].name = "cros-ec-gyro";
+			break;
+		case MOTIONSENSE_TYPE_MAG:
+			sensor_cells[id].name = "cros-ec-mag";
+			break;
+		case MOTIONSENSE_TYPE_PROX:
+			sensor_cells[id].name = "cros-ec-prox";
+			break;
+		case MOTIONSENSE_TYPE_LIGHT:
+			sensor_cells[id].name = "cros-ec-light";
+			break;
+		case MOTIONSENSE_TYPE_ACTIVITY:
+			sensor_cells[id].name = "cros-ec-activity";
+			break;
+		default:
+			dev_warn(ec->dev, "unknown type %d\n", resp->info.type);
+			continue;
+		}
+		sensor_platforms[id].sensor_num = i;
+		sensor_cells[id].id = sensor_type[resp->info.type];
+		sensor_cells[id].platform_data = &sensor_platforms[id];
+		sensor_cells[id].pdata_size =
+			sizeof(struct cros_ec_sensor_platform);
+
+		sensor_type[resp->info.type]++;
+		id++;
+	}
+	if (sensor_type[MOTIONSENSE_TYPE_ACCEL] >= 2) {
+		sensor_platforms[id].sensor_num = sensor_num;
+
+		sensor_cells[id].name = "cros-ec-angle";
+		sensor_cells[id].id = 0;
+		sensor_cells[id].platform_data = &sensor_platforms[id];
+		sensor_cells[id].pdata_size =
+			sizeof(struct cros_ec_sensor_platform);
+		id++;
+	}
+	if (cros_ec_check_features(ec, EC_FEATURE_MOTION_SENSE_FIFO)) {
+		sensor_cells[id].name = "cros-ec-ring";
+		id++;
+	}
+
+	ret = mfd_add_devices(ec->dev, 0, sensor_cells, id,
+			      NULL, 0, NULL);
+	if (ret)
+		dev_err(ec->dev, "failed to add EC sensors\n");
+
+	kfree(sensor_platforms);
+error_platforms:
+	kfree(sensor_cells);
+error:
+	kfree(msg);
+}
+
 static int ec_device_probe(struct platform_device *pdev)
 {
 	int retval = -ENOMEM;
@@ -319,6 +437,10 @@ static int ec_device_probe(struct platform_device *pdev)
 		goto dev_reg_failed;
 	}
 
+	/* check whether this EC is a sensor hub. */
+	if (cros_ec_check_features(ec, EC_FEATURE_MOTION_SENSE))
+		cros_ec_sensors_register(ec);
+
 	return 0;
 
 dev_reg_failed:
-- 
2.1.0

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web