Linux-IIO Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH v7 0/2] iio: cros_ec: Add lid angle driver
@ 2019-05-17 23:38 Gwendal Grignou
  2019-05-17 23:38 ` [PATCH v7 1/2] mfd: cros_ec: Register cros_ec_lid_angle driver when presented Gwendal Grignou
  2019-05-17 23:38 ` [PATCH v7 2/2] iio: cros_ec: Add lid angle driver Gwendal Grignou
  0 siblings, 2 replies; 9+ messages in thread
From: Gwendal Grignou @ 2019-05-17 23:38 UTC (permalink / raw)
  To: enric.balletbo, bleung, groeck, lee.jones, jic23
  Cc: linux-iio, linux-kernel, Gwendal Grignou

Add a IIO driver that reports the angle between the lid and the base for
ChromeOS convertible device.

Tested on eve with ToT EC firmware.
Check driver is loaded and lid angle is correct.

Changes in v7:
- Split the patch in two, as there are no build dependency between
  mfd and iio changes.

Gwendal Grignou (2):
  mfd: cros_ec: Register cros_ec_lid_angle driver when present
  iio: cros_ec: Add lid angle driver

 drivers/iio/common/cros_ec_sensors/Kconfig    |   9 ++
 drivers/iio/common/cros_ec_sensors/Makefile   |   1 +
 .../cros_ec_sensors/cros_ec_lid_angle.c       | 139 ++++++++++++++++++
 drivers/mfd/cros_ec_dev.c                     |  13 +-
 4 files changed, 159 insertions(+), 3 deletions(-)
 create mode 100644 drivers/iio/common/cros_ec_sensors/cros_ec_lid_angle.c

-- 
2.21.0.1020.gf2820cf01a-goog


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH v7 1/2] mfd: cros_ec: Register cros_ec_lid_angle driver when presented
  2019-05-17 23:38 [PATCH v7 0/2] iio: cros_ec: Add lid angle driver Gwendal Grignou
@ 2019-05-17 23:38 ` Gwendal Grignou
  2019-06-03 12:31   ` Lee Jones
  2019-05-17 23:38 ` [PATCH v7 2/2] iio: cros_ec: Add lid angle driver Gwendal Grignou
  1 sibling, 1 reply; 9+ messages in thread
From: Gwendal Grignou @ 2019-05-17 23:38 UTC (permalink / raw)
  To: enric.balletbo, bleung, groeck, lee.jones, jic23
  Cc: linux-iio, linux-kernel, Gwendal Grignou

Register driver when EC indicates has precise lid angle calculation code
running.
Fix incorrect extra resource allocation in cros_ec_sensors_register().

Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
---
Changes in v7:
- Split patch in two: This is the MFD section.

 drivers/mfd/cros_ec_dev.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/drivers/mfd/cros_ec_dev.c b/drivers/mfd/cros_ec_dev.c
index 54a58df571b6..d992365472b8 100644
--- a/drivers/mfd/cros_ec_dev.c
+++ b/drivers/mfd/cros_ec_dev.c
@@ -297,13 +297,15 @@ static void cros_ec_sensors_register(struct cros_ec_dev *ec)
 
 	resp = (struct ec_response_motion_sense *)msg->data;
 	sensor_num = resp->dump.sensor_count;
-	/* Allocate 1 extra sensors in FIFO are needed */
-	sensor_cells = kcalloc(sensor_num + 1, sizeof(struct mfd_cell),
+	/*
+	 * Allocate 2 extra sensors if lid angle sensor and/or FIFO are needed.
+	 */
+	sensor_cells = kcalloc(sensor_num + 2, sizeof(struct mfd_cell),
 			       GFP_KERNEL);
 	if (sensor_cells == NULL)
 		goto error;
 
-	sensor_platforms = kcalloc(sensor_num + 1,
+	sensor_platforms = kcalloc(sensor_num,
 				   sizeof(struct cros_ec_sensor_platform),
 				   GFP_KERNEL);
 	if (sensor_platforms == NULL)
@@ -363,6 +365,11 @@ static void cros_ec_sensors_register(struct cros_ec_dev *ec)
 		sensor_cells[id].name = "cros-ec-ring";
 		id++;
 	}
+	if (cros_ec_check_features(ec,
+				EC_FEATURE_REFINED_TABLET_MODE_HYSTERESIS)) {
+		sensor_cells[id].name = "cros-ec-lid-angle";
+		id++;
+	}
 
 	ret = mfd_add_devices(ec->dev, 0, sensor_cells, id,
 			      NULL, 0, NULL);
-- 
2.21.0.1020.gf2820cf01a-goog


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH v7 2/2] iio: cros_ec: Add lid angle driver
  2019-05-17 23:38 [PATCH v7 0/2] iio: cros_ec: Add lid angle driver Gwendal Grignou
  2019-05-17 23:38 ` [PATCH v7 1/2] mfd: cros_ec: Register cros_ec_lid_angle driver when presented Gwendal Grignou
@ 2019-05-17 23:38 ` Gwendal Grignou
  2019-05-18  9:53   ` Jonathan Cameron
  1 sibling, 1 reply; 9+ messages in thread
From: Gwendal Grignou @ 2019-05-17 23:38 UTC (permalink / raw)
  To: enric.balletbo, bleung, groeck, lee.jones, jic23
  Cc: linux-iio, linux-kernel, Gwendal Grignou

Add a IIO driver that reports the angle between the lid and the base for
ChromeOS convertible device.

Tested on eve with ToT EC firmware.
Check driver is loaded and lid angle is correct.

Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
---
Changes in v7:
- Split patch in two: This is the IIO section.

Changes in v6:
- Fix lock held in an error path error.

Changes in v5:
- Remove unnecessary define.
- v4 was the wrong patch file

Changes in v3:
- Use static channel array, simplify code because index is always 0.

Changes in v2:
- Fix license, remove driver_module field.

 drivers/iio/common/cros_ec_sensors/Kconfig    |   9 ++
 drivers/iio/common/cros_ec_sensors/Makefile   |   1 +
 .../cros_ec_sensors/cros_ec_lid_angle.c       | 139 ++++++++++++++++++
 3 files changed, 149 insertions(+)
 create mode 100644 drivers/iio/common/cros_ec_sensors/cros_ec_lid_angle.c

diff --git a/drivers/iio/common/cros_ec_sensors/Kconfig b/drivers/iio/common/cros_ec_sensors/Kconfig
index 135f6825903f..aacc2ab9c34f 100644
--- a/drivers/iio/common/cros_ec_sensors/Kconfig
+++ b/drivers/iio/common/cros_ec_sensors/Kconfig
@@ -20,3 +20,12 @@ config IIO_CROS_EC_SENSORS
 	  Accelerometers, Gyroscope and Magnetometer that are
 	  presented by the ChromeOS EC Sensor hub.
 	  Creates an IIO device for each functions.
+
+config IIO_CROS_EC_SENSORS_LID_ANGLE
+	tristate "ChromeOS EC Sensor for lid angle"
+	depends on IIO_CROS_EC_SENSORS_CORE
+	help
+	  Module to report the angle between lid and base for some
+	  convertible devices.
+	  This module is loaded when the EC can calculate the angle between the base
+	  and the lid.
diff --git a/drivers/iio/common/cros_ec_sensors/Makefile b/drivers/iio/common/cros_ec_sensors/Makefile
index ec716ff2a775..a35ee232ac07 100644
--- a/drivers/iio/common/cros_ec_sensors/Makefile
+++ b/drivers/iio/common/cros_ec_sensors/Makefile
@@ -4,3 +4,4 @@
 
 obj-$(CONFIG_IIO_CROS_EC_SENSORS_CORE) += cros_ec_sensors_core.o
 obj-$(CONFIG_IIO_CROS_EC_SENSORS) += cros_ec_sensors.o
+obj-$(CONFIG_IIO_CROS_EC_SENSORS_LID_ANGLE) += cros_ec_lid_angle.o
diff --git a/drivers/iio/common/cros_ec_sensors/cros_ec_lid_angle.c b/drivers/iio/common/cros_ec_sensors/cros_ec_lid_angle.c
new file mode 100644
index 000000000000..876dfd176b0e
--- /dev/null
+++ b/drivers/iio/common/cros_ec_sensors/cros_ec_lid_angle.c
@@ -0,0 +1,139 @@
+// SPDX-License-Identifier: GPL-2.0
+
+/*
+ * cros_ec_lid_angle - Driver for CrOS EC lid angle sensor.
+ *
+ * Copyright 2018 Google, Inc
+ *
+ * This driver uses the cros-ec interface to communicate with the Chrome OS
+ * EC about counter sensors. Counters are presented through
+ * iio sysfs.
+ */
+
+#include <linux/delay.h>
+#include <linux/device.h>
+#include <linux/iio/buffer.h>
+#include <linux/iio/common/cros_ec_sensors_core.h>
+#include <linux/iio/iio.h>
+#include <linux/iio/kfifo_buf.h>
+#include <linux/iio/trigger.h>
+#include <linux/iio/triggered_buffer.h>
+#include <linux/iio/trigger_consumer.h>
+#include <linux/kernel.h>
+#include <linux/mfd/cros_ec.h>
+#include <linux/mfd/cros_ec_commands.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+
+#define DRV_NAME "cros-ec-lid-angle"
+
+/*
+ * One channel for the lid angle, the other for timestamp.
+ */
+static const struct iio_chan_spec cros_ec_lid_angle_channels[] = {
+	{
+		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
+		.scan_type.realbits = CROS_EC_SENSOR_BITS,
+		.scan_type.storagebits = CROS_EC_SENSOR_BITS,
+		.scan_type.sign = 'u',
+		.type = IIO_ANGL
+	},
+	IIO_CHAN_SOFT_TIMESTAMP(1)
+};
+
+/* State data for ec_sensors iio driver. */
+struct cros_ec_lid_angle_state {
+	/* Shared by all sensors */
+	struct cros_ec_sensors_core_state core;
+};
+
+static int cros_ec_sensors_read_lid_angle(struct iio_dev *indio_dev,
+					  unsigned long scan_mask, s16 *data)
+{
+	struct cros_ec_sensors_core_state *st = iio_priv(indio_dev);
+	int ret;
+
+	st->param.cmd = MOTIONSENSE_CMD_LID_ANGLE;
+	ret = cros_ec_motion_send_host_cmd(st, sizeof(st->resp->lid_angle));
+	if (ret) {
+		dev_warn(&indio_dev->dev, "Unable to read lid angle\n");
+		return ret;
+	}
+
+	*data = st->resp->lid_angle.value;
+	return 0;
+}
+
+static int cros_ec_lid_angle_read(struct iio_dev *indio_dev,
+				    struct iio_chan_spec const *chan,
+				    int *val, int *val2, long mask)
+{
+	struct cros_ec_lid_angle_state *st = iio_priv(indio_dev);
+	s16 data;
+	int ret;
+
+	mutex_lock(&st->core.cmd_lock);
+	ret = cros_ec_sensors_read_lid_angle(indio_dev, 1, &data);
+	if (ret == 0) {
+		*val = data;
+		ret = IIO_VAL_INT;
+	}
+	mutex_unlock(&st->core.cmd_lock);
+	return ret;
+}
+
+static const struct iio_info cros_ec_lid_angle_info = {
+	.read_raw = &cros_ec_lid_angle_read,
+};
+
+static int cros_ec_lid_angle_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct iio_dev *indio_dev;
+	struct cros_ec_lid_angle_state *state;
+	int ret;
+
+	indio_dev = devm_iio_device_alloc(dev, sizeof(*state));
+	if (!indio_dev)
+		return -ENOMEM;
+
+	ret = cros_ec_sensors_core_init(pdev, indio_dev, false);
+	if (ret)
+		return ret;
+
+	indio_dev->info = &cros_ec_lid_angle_info;
+	state = iio_priv(indio_dev);
+	indio_dev->channels = cros_ec_lid_angle_channels;
+	indio_dev->num_channels = ARRAY_SIZE(cros_ec_lid_angle_channels);
+
+	state->core.read_ec_sensors_data = cros_ec_sensors_read_lid_angle;
+
+	ret = devm_iio_triggered_buffer_setup(dev, indio_dev, NULL,
+			cros_ec_sensors_capture, NULL);
+	if (ret)
+		return ret;
+
+	return devm_iio_device_register(dev, indio_dev);
+}
+
+static const struct platform_device_id cros_ec_lid_angle_ids[] = {
+	{
+		.name = DRV_NAME,
+	},
+	{ /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(platform, cros_ec_lid_angle_ids);
+
+static struct platform_driver cros_ec_lid_angle_platform_driver = {
+	.driver = {
+		.name	= DRV_NAME,
+		.pm	= &cros_ec_sensors_pm_ops,
+	},
+	.probe		= cros_ec_lid_angle_probe,
+	.id_table	= cros_ec_lid_angle_ids,
+};
+module_platform_driver(cros_ec_lid_angle_platform_driver);
+
+MODULE_DESCRIPTION("ChromeOS EC driver for reporting convertible lid angle.");
+MODULE_LICENSE("GPL v2");
-- 
2.21.0.1020.gf2820cf01a-goog


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v7 2/2] iio: cros_ec: Add lid angle driver
  2019-05-17 23:38 ` [PATCH v7 2/2] iio: cros_ec: Add lid angle driver Gwendal Grignou
@ 2019-05-18  9:53   ` Jonathan Cameron
  2019-06-14 21:54     ` Gwendal Grignou
  0 siblings, 1 reply; 9+ messages in thread
From: Jonathan Cameron @ 2019-05-18  9:53 UTC (permalink / raw)
  To: Gwendal Grignou
  Cc: enric.balletbo, bleung, groeck, lee.jones, linux-iio, linux-kernel

On Fri, 17 May 2019 16:38:56 -0700
Gwendal Grignou <gwendal@chromium.org> wrote:

> Add a IIO driver that reports the angle between the lid and the base for
> ChromeOS convertible device.
> 
> Tested on eve with ToT EC firmware.
> Check driver is loaded and lid angle is correct.
> 
> Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Hi Gwendal.

Please do list dependencies in patches.  I think this one is still
dependent on the larger set of MFD changes. 

For my reference

Acked-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

Please do poke if this seems to have gotten lost once the precursors
are upstream.

Thanks,

Jonathan

> ---
> Changes in v7:
> - Split patch in two: This is the IIO section.
> 
> Changes in v6:
> - Fix lock held in an error path error.
> 
> Changes in v5:
> - Remove unnecessary define.
> - v4 was the wrong patch file
> 
> Changes in v3:
> - Use static channel array, simplify code because index is always 0.
> 
> Changes in v2:
> - Fix license, remove driver_module field.
> 
>  drivers/iio/common/cros_ec_sensors/Kconfig    |   9 ++
>  drivers/iio/common/cros_ec_sensors/Makefile   |   1 +
>  .../cros_ec_sensors/cros_ec_lid_angle.c       | 139 ++++++++++++++++++
>  3 files changed, 149 insertions(+)
>  create mode 100644 drivers/iio/common/cros_ec_sensors/cros_ec_lid_angle.c
> 
> diff --git a/drivers/iio/common/cros_ec_sensors/Kconfig b/drivers/iio/common/cros_ec_sensors/Kconfig
> index 135f6825903f..aacc2ab9c34f 100644
> --- a/drivers/iio/common/cros_ec_sensors/Kconfig
> +++ b/drivers/iio/common/cros_ec_sensors/Kconfig
> @@ -20,3 +20,12 @@ config IIO_CROS_EC_SENSORS
>  	  Accelerometers, Gyroscope and Magnetometer that are
>  	  presented by the ChromeOS EC Sensor hub.
>  	  Creates an IIO device for each functions.
> +
> +config IIO_CROS_EC_SENSORS_LID_ANGLE
> +	tristate "ChromeOS EC Sensor for lid angle"
> +	depends on IIO_CROS_EC_SENSORS_CORE
> +	help
> +	  Module to report the angle between lid and base for some
> +	  convertible devices.
> +	  This module is loaded when the EC can calculate the angle between the base
> +	  and the lid.
> diff --git a/drivers/iio/common/cros_ec_sensors/Makefile b/drivers/iio/common/cros_ec_sensors/Makefile
> index ec716ff2a775..a35ee232ac07 100644
> --- a/drivers/iio/common/cros_ec_sensors/Makefile
> +++ b/drivers/iio/common/cros_ec_sensors/Makefile
> @@ -4,3 +4,4 @@
>  
>  obj-$(CONFIG_IIO_CROS_EC_SENSORS_CORE) += cros_ec_sensors_core.o
>  obj-$(CONFIG_IIO_CROS_EC_SENSORS) += cros_ec_sensors.o
> +obj-$(CONFIG_IIO_CROS_EC_SENSORS_LID_ANGLE) += cros_ec_lid_angle.o
> diff --git a/drivers/iio/common/cros_ec_sensors/cros_ec_lid_angle.c b/drivers/iio/common/cros_ec_sensors/cros_ec_lid_angle.c
> new file mode 100644
> index 000000000000..876dfd176b0e
> --- /dev/null
> +++ b/drivers/iio/common/cros_ec_sensors/cros_ec_lid_angle.c
> @@ -0,0 +1,139 @@
> +// SPDX-License-Identifier: GPL-2.0
> +
> +/*
> + * cros_ec_lid_angle - Driver for CrOS EC lid angle sensor.
> + *
> + * Copyright 2018 Google, Inc
> + *
> + * This driver uses the cros-ec interface to communicate with the Chrome OS
> + * EC about counter sensors. Counters are presented through
> + * iio sysfs.
> + */
> +
> +#include <linux/delay.h>
> +#include <linux/device.h>
> +#include <linux/iio/buffer.h>
> +#include <linux/iio/common/cros_ec_sensors_core.h>
> +#include <linux/iio/iio.h>
> +#include <linux/iio/kfifo_buf.h>
> +#include <linux/iio/trigger.h>
> +#include <linux/iio/triggered_buffer.h>
> +#include <linux/iio/trigger_consumer.h>
> +#include <linux/kernel.h>
> +#include <linux/mfd/cros_ec.h>
> +#include <linux/mfd/cros_ec_commands.h>
> +#include <linux/module.h>
> +#include <linux/platform_device.h>
> +#include <linux/slab.h>
> +
> +#define DRV_NAME "cros-ec-lid-angle"
> +
> +/*
> + * One channel for the lid angle, the other for timestamp.
> + */
> +static const struct iio_chan_spec cros_ec_lid_angle_channels[] = {
> +	{
> +		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
> +		.scan_type.realbits = CROS_EC_SENSOR_BITS,
> +		.scan_type.storagebits = CROS_EC_SENSOR_BITS,
> +		.scan_type.sign = 'u',
> +		.type = IIO_ANGL
> +	},
> +	IIO_CHAN_SOFT_TIMESTAMP(1)
> +};
> +
> +/* State data for ec_sensors iio driver. */
> +struct cros_ec_lid_angle_state {
> +	/* Shared by all sensors */
> +	struct cros_ec_sensors_core_state core;
> +};
> +
> +static int cros_ec_sensors_read_lid_angle(struct iio_dev *indio_dev,
> +					  unsigned long scan_mask, s16 *data)
> +{
> +	struct cros_ec_sensors_core_state *st = iio_priv(indio_dev);
> +	int ret;
> +
> +	st->param.cmd = MOTIONSENSE_CMD_LID_ANGLE;
> +	ret = cros_ec_motion_send_host_cmd(st, sizeof(st->resp->lid_angle));
> +	if (ret) {
> +		dev_warn(&indio_dev->dev, "Unable to read lid angle\n");
> +		return ret;
> +	}
> +
> +	*data = st->resp->lid_angle.value;
> +	return 0;
> +}
> +
> +static int cros_ec_lid_angle_read(struct iio_dev *indio_dev,
> +				    struct iio_chan_spec const *chan,
> +				    int *val, int *val2, long mask)
> +{
> +	struct cros_ec_lid_angle_state *st = iio_priv(indio_dev);
> +	s16 data;
> +	int ret;
> +
> +	mutex_lock(&st->core.cmd_lock);
> +	ret = cros_ec_sensors_read_lid_angle(indio_dev, 1, &data);
> +	if (ret == 0) {
> +		*val = data;
> +		ret = IIO_VAL_INT;
> +	}
> +	mutex_unlock(&st->core.cmd_lock);
> +	return ret;
> +}
> +
> +static const struct iio_info cros_ec_lid_angle_info = {
> +	.read_raw = &cros_ec_lid_angle_read,
> +};
> +
> +static int cros_ec_lid_angle_probe(struct platform_device *pdev)
> +{
> +	struct device *dev = &pdev->dev;
> +	struct iio_dev *indio_dev;
> +	struct cros_ec_lid_angle_state *state;
> +	int ret;
> +
> +	indio_dev = devm_iio_device_alloc(dev, sizeof(*state));
> +	if (!indio_dev)
> +		return -ENOMEM;
> +
> +	ret = cros_ec_sensors_core_init(pdev, indio_dev, false);
> +	if (ret)
> +		return ret;
> +
> +	indio_dev->info = &cros_ec_lid_angle_info;
> +	state = iio_priv(indio_dev);
> +	indio_dev->channels = cros_ec_lid_angle_channels;
> +	indio_dev->num_channels = ARRAY_SIZE(cros_ec_lid_angle_channels);
> +
> +	state->core.read_ec_sensors_data = cros_ec_sensors_read_lid_angle;
> +
> +	ret = devm_iio_triggered_buffer_setup(dev, indio_dev, NULL,
> +			cros_ec_sensors_capture, NULL);
> +	if (ret)
> +		return ret;
> +
> +	return devm_iio_device_register(dev, indio_dev);
> +}
> +
> +static const struct platform_device_id cros_ec_lid_angle_ids[] = {
> +	{
> +		.name = DRV_NAME,
> +	},
> +	{ /* sentinel */ }
> +};
> +MODULE_DEVICE_TABLE(platform, cros_ec_lid_angle_ids);
> +
> +static struct platform_driver cros_ec_lid_angle_platform_driver = {
> +	.driver = {
> +		.name	= DRV_NAME,
> +		.pm	= &cros_ec_sensors_pm_ops,
> +	},
> +	.probe		= cros_ec_lid_angle_probe,
> +	.id_table	= cros_ec_lid_angle_ids,
> +};
> +module_platform_driver(cros_ec_lid_angle_platform_driver);
> +
> +MODULE_DESCRIPTION("ChromeOS EC driver for reporting convertible lid angle.");
> +MODULE_LICENSE("GPL v2");


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v7 1/2] mfd: cros_ec: Register cros_ec_lid_angle driver when presented
  2019-05-17 23:38 ` [PATCH v7 1/2] mfd: cros_ec: Register cros_ec_lid_angle driver when presented Gwendal Grignou
@ 2019-06-03 12:31   ` Lee Jones
  0 siblings, 0 replies; 9+ messages in thread
From: Lee Jones @ 2019-06-03 12:31 UTC (permalink / raw)
  To: Gwendal Grignou
  Cc: enric.balletbo, bleung, groeck, jic23, linux-iio, linux-kernel

On Fri, 17 May 2019, Gwendal Grignou wrote:

> Register driver when EC indicates has precise lid angle calculation code
> running.
> Fix incorrect extra resource allocation in cros_ec_sensors_register().
> 
> Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
> ---
> Changes in v7:
> - Split patch in two: This is the MFD section.
> 
>  drivers/mfd/cros_ec_dev.c | 13 ++++++++++---
>  1 file changed, 10 insertions(+), 3 deletions(-)

Applied, thanks.

-- 
Lee Jones [李琼斯]
Linaro Services Technical Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v7 2/2] iio: cros_ec: Add lid angle driver
  2019-05-18  9:53   ` Jonathan Cameron
@ 2019-06-14 21:54     ` Gwendal Grignou
  2019-06-19 20:49       ` Enric Balletbo Serra
  0 siblings, 1 reply; 9+ messages in thread
From: Gwendal Grignou @ 2019-06-14 21:54 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Enric Balletbo i Serra, Benson Leung, Guenter Roeck, Lee Jones,
	linux-iio, linux-kernel

On Sat, May 18, 2019 at 2:53 AM Jonathan Cameron <jic23@kernel.org> wrote:
>
> On Fri, 17 May 2019 16:38:56 -0700
> Gwendal Grignou <gwendal@chromium.org> wrote:
>
> > Add a IIO driver that reports the angle between the lid and the base for
> > ChromeOS convertible device.
> >
> > Tested on eve with ToT EC firmware.
> > Check driver is loaded and lid angle is correct.
> >
> > Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
> Hi Gwendal.
>
> Please do list dependencies in patches.  I think this one is still
> dependent on the larger set of MFD changes.
>
> For my reference
>
> Acked-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
>
> Please do poke if this seems to have gotten lost once the precursors
> are upstream.
The large set of MFD changes for update cros_ec_commands.h has landed
in a immutable branch:
git://git.kernel.org/pub/scm/linux/kernel/git/lee/mfd.git branch
ib-mfd-cros-5.3.

Thanks,
Gwendal.


>
> Thanks,
>
> Jonathan
>
> > ---
> > Changes in v7:
> > - Split patch in two: This is the IIO section.
> >
> > Changes in v6:
> > - Fix lock held in an error path error.
> >
> > Changes in v5:
> > - Remove unnecessary define.
> > - v4 was the wrong patch file
> >
> > Changes in v3:
> > - Use static channel array, simplify code because index is always 0.
> >
> > Changes in v2:
> > - Fix license, remove driver_module field.
> >
> >  drivers/iio/common/cros_ec_sensors/Kconfig    |   9 ++
> >  drivers/iio/common/cros_ec_sensors/Makefile   |   1 +
> >  .../cros_ec_sensors/cros_ec_lid_angle.c       | 139 ++++++++++++++++++
> >  3 files changed, 149 insertions(+)
> >  create mode 100644 drivers/iio/common/cros_ec_sensors/cros_ec_lid_angle.c
> >
> > diff --git a/drivers/iio/common/cros_ec_sensors/Kconfig b/drivers/iio/common/cros_ec_sensors/Kconfig
> > index 135f6825903f..aacc2ab9c34f 100644
> > --- a/drivers/iio/common/cros_ec_sensors/Kconfig
> > +++ b/drivers/iio/common/cros_ec_sensors/Kconfig
> > @@ -20,3 +20,12 @@ config IIO_CROS_EC_SENSORS
> >         Accelerometers, Gyroscope and Magnetometer that are
> >         presented by the ChromeOS EC Sensor hub.
> >         Creates an IIO device for each functions.
> > +
> > +config IIO_CROS_EC_SENSORS_LID_ANGLE
> > +     tristate "ChromeOS EC Sensor for lid angle"
> > +     depends on IIO_CROS_EC_SENSORS_CORE
> > +     help
> > +       Module to report the angle between lid and base for some
> > +       convertible devices.
> > +       This module is loaded when the EC can calculate the angle between the base
> > +       and the lid.
> > diff --git a/drivers/iio/common/cros_ec_sensors/Makefile b/drivers/iio/common/cros_ec_sensors/Makefile
> > index ec716ff2a775..a35ee232ac07 100644
> > --- a/drivers/iio/common/cros_ec_sensors/Makefile
> > +++ b/drivers/iio/common/cros_ec_sensors/Makefile
> > @@ -4,3 +4,4 @@
> >
> >  obj-$(CONFIG_IIO_CROS_EC_SENSORS_CORE) += cros_ec_sensors_core.o
> >  obj-$(CONFIG_IIO_CROS_EC_SENSORS) += cros_ec_sensors.o
> > +obj-$(CONFIG_IIO_CROS_EC_SENSORS_LID_ANGLE) += cros_ec_lid_angle.o
> > diff --git a/drivers/iio/common/cros_ec_sensors/cros_ec_lid_angle.c b/drivers/iio/common/cros_ec_sensors/cros_ec_lid_angle.c
> > new file mode 100644
> > index 000000000000..876dfd176b0e
> > --- /dev/null
> > +++ b/drivers/iio/common/cros_ec_sensors/cros_ec_lid_angle.c
> > @@ -0,0 +1,139 @@
> > +// SPDX-License-Identifier: GPL-2.0
> > +
> > +/*
> > + * cros_ec_lid_angle - Driver for CrOS EC lid angle sensor.
> > + *
> > + * Copyright 2018 Google, Inc
> > + *
> > + * This driver uses the cros-ec interface to communicate with the Chrome OS
> > + * EC about counter sensors. Counters are presented through
> > + * iio sysfs.
> > + */
> > +
> > +#include <linux/delay.h>
> > +#include <linux/device.h>
> > +#include <linux/iio/buffer.h>
> > +#include <linux/iio/common/cros_ec_sensors_core.h>
> > +#include <linux/iio/iio.h>
> > +#include <linux/iio/kfifo_buf.h>
> > +#include <linux/iio/trigger.h>
> > +#include <linux/iio/triggered_buffer.h>
> > +#include <linux/iio/trigger_consumer.h>
> > +#include <linux/kernel.h>
> > +#include <linux/mfd/cros_ec.h>
> > +#include <linux/mfd/cros_ec_commands.h>
> > +#include <linux/module.h>
> > +#include <linux/platform_device.h>
> > +#include <linux/slab.h>
> > +
> > +#define DRV_NAME "cros-ec-lid-angle"
> > +
> > +/*
> > + * One channel for the lid angle, the other for timestamp.
> > + */
> > +static const struct iio_chan_spec cros_ec_lid_angle_channels[] = {
> > +     {
> > +             .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
> > +             .scan_type.realbits = CROS_EC_SENSOR_BITS,
> > +             .scan_type.storagebits = CROS_EC_SENSOR_BITS,
> > +             .scan_type.sign = 'u',
> > +             .type = IIO_ANGL
> > +     },
> > +     IIO_CHAN_SOFT_TIMESTAMP(1)
> > +};
> > +
> > +/* State data for ec_sensors iio driver. */
> > +struct cros_ec_lid_angle_state {
> > +     /* Shared by all sensors */
> > +     struct cros_ec_sensors_core_state core;
> > +};
> > +
> > +static int cros_ec_sensors_read_lid_angle(struct iio_dev *indio_dev,
> > +                                       unsigned long scan_mask, s16 *data)
> > +{
> > +     struct cros_ec_sensors_core_state *st = iio_priv(indio_dev);
> > +     int ret;
> > +
> > +     st->param.cmd = MOTIONSENSE_CMD_LID_ANGLE;
> > +     ret = cros_ec_motion_send_host_cmd(st, sizeof(st->resp->lid_angle));
> > +     if (ret) {
> > +             dev_warn(&indio_dev->dev, "Unable to read lid angle\n");
> > +             return ret;
> > +     }
> > +
> > +     *data = st->resp->lid_angle.value;
> > +     return 0;
> > +}
> > +
> > +static int cros_ec_lid_angle_read(struct iio_dev *indio_dev,
> > +                                 struct iio_chan_spec const *chan,
> > +                                 int *val, int *val2, long mask)
> > +{
> > +     struct cros_ec_lid_angle_state *st = iio_priv(indio_dev);
> > +     s16 data;
> > +     int ret;
> > +
> > +     mutex_lock(&st->core.cmd_lock);
> > +     ret = cros_ec_sensors_read_lid_angle(indio_dev, 1, &data);
> > +     if (ret == 0) {
> > +             *val = data;
> > +             ret = IIO_VAL_INT;
> > +     }
> > +     mutex_unlock(&st->core.cmd_lock);
> > +     return ret;
> > +}
> > +
> > +static const struct iio_info cros_ec_lid_angle_info = {
> > +     .read_raw = &cros_ec_lid_angle_read,
> > +};
> > +
> > +static int cros_ec_lid_angle_probe(struct platform_device *pdev)
> > +{
> > +     struct device *dev = &pdev->dev;
> > +     struct iio_dev *indio_dev;
> > +     struct cros_ec_lid_angle_state *state;
> > +     int ret;
> > +
> > +     indio_dev = devm_iio_device_alloc(dev, sizeof(*state));
> > +     if (!indio_dev)
> > +             return -ENOMEM;
> > +
> > +     ret = cros_ec_sensors_core_init(pdev, indio_dev, false);
> > +     if (ret)
> > +             return ret;
> > +
> > +     indio_dev->info = &cros_ec_lid_angle_info;
> > +     state = iio_priv(indio_dev);
> > +     indio_dev->channels = cros_ec_lid_angle_channels;
> > +     indio_dev->num_channels = ARRAY_SIZE(cros_ec_lid_angle_channels);
> > +
> > +     state->core.read_ec_sensors_data = cros_ec_sensors_read_lid_angle;
> > +
> > +     ret = devm_iio_triggered_buffer_setup(dev, indio_dev, NULL,
> > +                     cros_ec_sensors_capture, NULL);
> > +     if (ret)
> > +             return ret;
> > +
> > +     return devm_iio_device_register(dev, indio_dev);
> > +}
> > +
> > +static const struct platform_device_id cros_ec_lid_angle_ids[] = {
> > +     {
> > +             .name = DRV_NAME,
> > +     },
> > +     { /* sentinel */ }
> > +};
> > +MODULE_DEVICE_TABLE(platform, cros_ec_lid_angle_ids);
> > +
> > +static struct platform_driver cros_ec_lid_angle_platform_driver = {
> > +     .driver = {
> > +             .name   = DRV_NAME,
> > +             .pm     = &cros_ec_sensors_pm_ops,
> > +     },
> > +     .probe          = cros_ec_lid_angle_probe,
> > +     .id_table       = cros_ec_lid_angle_ids,
> > +};
> > +module_platform_driver(cros_ec_lid_angle_platform_driver);
> > +
> > +MODULE_DESCRIPTION("ChromeOS EC driver for reporting convertible lid angle.");
> > +MODULE_LICENSE("GPL v2");
>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v7 2/2] iio: cros_ec: Add lid angle driver
  2019-06-14 21:54     ` Gwendal Grignou
@ 2019-06-19 20:49       ` Enric Balletbo Serra
  2019-06-21 15:31         ` Jonathan Cameron
  0 siblings, 1 reply; 9+ messages in thread
From: Enric Balletbo Serra @ 2019-06-19 20:49 UTC (permalink / raw)
  To: Gwendal Grignou
  Cc: Jonathan Cameron, Enric Balletbo i Serra, Benson Leung,
	Guenter Roeck, Lee Jones, linux-iio, linux-kernel

Missatge de Gwendal Grignou <gwendal@chromium.org> del dia dv., 14 de
juny 2019 a les 23:56:
>
> On Sat, May 18, 2019 at 2:53 AM Jonathan Cameron <jic23@kernel.org> wrote:
> >
> > On Fri, 17 May 2019 16:38:56 -0700
> > Gwendal Grignou <gwendal@chromium.org> wrote:
> >
> > > Add a IIO driver that reports the angle between the lid and the base for
> > > ChromeOS convertible device.
> > >
> > > Tested on eve with ToT EC firmware.
> > > Check driver is loaded and lid angle is correct.
> > >
> > > Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
> > Hi Gwendal.
> >
> > Please do list dependencies in patches.  I think this one is still
> > dependent on the larger set of MFD changes.
> >
> > For my reference
> >
> > Acked-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> >
> > Please do poke if this seems to have gotten lost once the precursors
> > are upstream.
> The large set of MFD changes for update cros_ec_commands.h has landed
> in a immutable branch:
> git://git.kernel.org/pub/scm/linux/kernel/git/lee/mfd.git branch
> ib-mfd-cros-5.3.
>

Jonathan, if you don't want to deal with the big patchset that this
depends and the immutable branch, I can pick the patch and can go
through the chrome-platform tree. I think it is unlikely have merge
conflicts, as these patches only touch cros-ec iio parts and, anyway,
I'll need to deal with the immutable branch because other patches also
depends on the ib.

Thanks,
~ Enric

> Thanks,
> Gwendal.
>
>
> >
> > Thanks,
> >
> > Jonathan
> >
> > > ---
> > > Changes in v7:
> > > - Split patch in two: This is the IIO section.
> > >
> > > Changes in v6:
> > > - Fix lock held in an error path error.
> > >
> > > Changes in v5:
> > > - Remove unnecessary define.
> > > - v4 was the wrong patch file
> > >
> > > Changes in v3:
> > > - Use static channel array, simplify code because index is always 0.
> > >
> > > Changes in v2:
> > > - Fix license, remove driver_module field.
> > >
> > >  drivers/iio/common/cros_ec_sensors/Kconfig    |   9 ++
> > >  drivers/iio/common/cros_ec_sensors/Makefile   |   1 +
> > >  .../cros_ec_sensors/cros_ec_lid_angle.c       | 139 ++++++++++++++++++
> > >  3 files changed, 149 insertions(+)
> > >  create mode 100644 drivers/iio/common/cros_ec_sensors/cros_ec_lid_angle.c
> > >
> > > diff --git a/drivers/iio/common/cros_ec_sensors/Kconfig b/drivers/iio/common/cros_ec_sensors/Kconfig
> > > index 135f6825903f..aacc2ab9c34f 100644
> > > --- a/drivers/iio/common/cros_ec_sensors/Kconfig
> > > +++ b/drivers/iio/common/cros_ec_sensors/Kconfig
> > > @@ -20,3 +20,12 @@ config IIO_CROS_EC_SENSORS
> > >         Accelerometers, Gyroscope and Magnetometer that are
> > >         presented by the ChromeOS EC Sensor hub.
> > >         Creates an IIO device for each functions.
> > > +
> > > +config IIO_CROS_EC_SENSORS_LID_ANGLE
> > > +     tristate "ChromeOS EC Sensor for lid angle"
> > > +     depends on IIO_CROS_EC_SENSORS_CORE
> > > +     help
> > > +       Module to report the angle between lid and base for some
> > > +       convertible devices.
> > > +       This module is loaded when the EC can calculate the angle between the base
> > > +       and the lid.
> > > diff --git a/drivers/iio/common/cros_ec_sensors/Makefile b/drivers/iio/common/cros_ec_sensors/Makefile
> > > index ec716ff2a775..a35ee232ac07 100644
> > > --- a/drivers/iio/common/cros_ec_sensors/Makefile
> > > +++ b/drivers/iio/common/cros_ec_sensors/Makefile
> > > @@ -4,3 +4,4 @@
> > >
> > >  obj-$(CONFIG_IIO_CROS_EC_SENSORS_CORE) += cros_ec_sensors_core.o
> > >  obj-$(CONFIG_IIO_CROS_EC_SENSORS) += cros_ec_sensors.o
> > > +obj-$(CONFIG_IIO_CROS_EC_SENSORS_LID_ANGLE) += cros_ec_lid_angle.o
> > > diff --git a/drivers/iio/common/cros_ec_sensors/cros_ec_lid_angle.c b/drivers/iio/common/cros_ec_sensors/cros_ec_lid_angle.c
> > > new file mode 100644
> > > index 000000000000..876dfd176b0e
> > > --- /dev/null
> > > +++ b/drivers/iio/common/cros_ec_sensors/cros_ec_lid_angle.c
> > > @@ -0,0 +1,139 @@
> > > +// SPDX-License-Identifier: GPL-2.0
> > > +
> > > +/*
> > > + * cros_ec_lid_angle - Driver for CrOS EC lid angle sensor.
> > > + *
> > > + * Copyright 2018 Google, Inc
> > > + *
> > > + * This driver uses the cros-ec interface to communicate with the Chrome OS
> > > + * EC about counter sensors. Counters are presented through
> > > + * iio sysfs.
> > > + */
> > > +
> > > +#include <linux/delay.h>
> > > +#include <linux/device.h>
> > > +#include <linux/iio/buffer.h>
> > > +#include <linux/iio/common/cros_ec_sensors_core.h>
> > > +#include <linux/iio/iio.h>
> > > +#include <linux/iio/kfifo_buf.h>
> > > +#include <linux/iio/trigger.h>
> > > +#include <linux/iio/triggered_buffer.h>
> > > +#include <linux/iio/trigger_consumer.h>
> > > +#include <linux/kernel.h>
> > > +#include <linux/mfd/cros_ec.h>
> > > +#include <linux/mfd/cros_ec_commands.h>
> > > +#include <linux/module.h>
> > > +#include <linux/platform_device.h>
> > > +#include <linux/slab.h>
> > > +
> > > +#define DRV_NAME "cros-ec-lid-angle"
> > > +
> > > +/*
> > > + * One channel for the lid angle, the other for timestamp.
> > > + */
> > > +static const struct iio_chan_spec cros_ec_lid_angle_channels[] = {
> > > +     {
> > > +             .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
> > > +             .scan_type.realbits = CROS_EC_SENSOR_BITS,
> > > +             .scan_type.storagebits = CROS_EC_SENSOR_BITS,
> > > +             .scan_type.sign = 'u',
> > > +             .type = IIO_ANGL
> > > +     },
> > > +     IIO_CHAN_SOFT_TIMESTAMP(1)
> > > +};
> > > +
> > > +/* State data for ec_sensors iio driver. */
> > > +struct cros_ec_lid_angle_state {
> > > +     /* Shared by all sensors */
> > > +     struct cros_ec_sensors_core_state core;
> > > +};
> > > +
> > > +static int cros_ec_sensors_read_lid_angle(struct iio_dev *indio_dev,
> > > +                                       unsigned long scan_mask, s16 *data)
> > > +{
> > > +     struct cros_ec_sensors_core_state *st = iio_priv(indio_dev);
> > > +     int ret;
> > > +
> > > +     st->param.cmd = MOTIONSENSE_CMD_LID_ANGLE;
> > > +     ret = cros_ec_motion_send_host_cmd(st, sizeof(st->resp->lid_angle));
> > > +     if (ret) {
> > > +             dev_warn(&indio_dev->dev, "Unable to read lid angle\n");
> > > +             return ret;
> > > +     }
> > > +
> > > +     *data = st->resp->lid_angle.value;
> > > +     return 0;
> > > +}
> > > +
> > > +static int cros_ec_lid_angle_read(struct iio_dev *indio_dev,
> > > +                                 struct iio_chan_spec const *chan,
> > > +                                 int *val, int *val2, long mask)
> > > +{
> > > +     struct cros_ec_lid_angle_state *st = iio_priv(indio_dev);
> > > +     s16 data;
> > > +     int ret;
> > > +
> > > +     mutex_lock(&st->core.cmd_lock);
> > > +     ret = cros_ec_sensors_read_lid_angle(indio_dev, 1, &data);
> > > +     if (ret == 0) {
> > > +             *val = data;
> > > +             ret = IIO_VAL_INT;
> > > +     }
> > > +     mutex_unlock(&st->core.cmd_lock);
> > > +     return ret;
> > > +}
> > > +
> > > +static const struct iio_info cros_ec_lid_angle_info = {
> > > +     .read_raw = &cros_ec_lid_angle_read,
> > > +};
> > > +
> > > +static int cros_ec_lid_angle_probe(struct platform_device *pdev)
> > > +{
> > > +     struct device *dev = &pdev->dev;
> > > +     struct iio_dev *indio_dev;
> > > +     struct cros_ec_lid_angle_state *state;
> > > +     int ret;
> > > +
> > > +     indio_dev = devm_iio_device_alloc(dev, sizeof(*state));
> > > +     if (!indio_dev)
> > > +             return -ENOMEM;
> > > +
> > > +     ret = cros_ec_sensors_core_init(pdev, indio_dev, false);
> > > +     if (ret)
> > > +             return ret;
> > > +
> > > +     indio_dev->info = &cros_ec_lid_angle_info;
> > > +     state = iio_priv(indio_dev);
> > > +     indio_dev->channels = cros_ec_lid_angle_channels;
> > > +     indio_dev->num_channels = ARRAY_SIZE(cros_ec_lid_angle_channels);
> > > +
> > > +     state->core.read_ec_sensors_data = cros_ec_sensors_read_lid_angle;
> > > +
> > > +     ret = devm_iio_triggered_buffer_setup(dev, indio_dev, NULL,
> > > +                     cros_ec_sensors_capture, NULL);
> > > +     if (ret)
> > > +             return ret;
> > > +
> > > +     return devm_iio_device_register(dev, indio_dev);
> > > +}
> > > +
> > > +static const struct platform_device_id cros_ec_lid_angle_ids[] = {
> > > +     {
> > > +             .name = DRV_NAME,
> > > +     },
> > > +     { /* sentinel */ }
> > > +};
> > > +MODULE_DEVICE_TABLE(platform, cros_ec_lid_angle_ids);
> > > +
> > > +static struct platform_driver cros_ec_lid_angle_platform_driver = {
> > > +     .driver = {
> > > +             .name   = DRV_NAME,
> > > +             .pm     = &cros_ec_sensors_pm_ops,
> > > +     },
> > > +     .probe          = cros_ec_lid_angle_probe,
> > > +     .id_table       = cros_ec_lid_angle_ids,
> > > +};
> > > +module_platform_driver(cros_ec_lid_angle_platform_driver);
> > > +
> > > +MODULE_DESCRIPTION("ChromeOS EC driver for reporting convertible lid angle.");
> > > +MODULE_LICENSE("GPL v2");
> >

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v7 2/2] iio: cros_ec: Add lid angle driver
  2019-06-19 20:49       ` Enric Balletbo Serra
@ 2019-06-21 15:31         ` Jonathan Cameron
  2019-06-25 13:53           ` Enric Balletbo i Serra
  0 siblings, 1 reply; 9+ messages in thread
From: Jonathan Cameron @ 2019-06-21 15:31 UTC (permalink / raw)
  To: Enric Balletbo Serra
  Cc: Gwendal Grignou, Jonathan Cameron, Enric Balletbo i Serra,
	Benson Leung, Guenter Roeck, Lee Jones, linux-iio, linux-kernel

On Wed, 19 Jun 2019 22:49:04 +0200
Enric Balletbo Serra <eballetbo@gmail.com> wrote:

> Missatge de Gwendal Grignou <gwendal@chromium.org> del dia dv., 14 de
> juny 2019 a les 23:56:
> >
> > On Sat, May 18, 2019 at 2:53 AM Jonathan Cameron <jic23@kernel.org> wrote:  
> > >
> > > On Fri, 17 May 2019 16:38:56 -0700
> > > Gwendal Grignou <gwendal@chromium.org> wrote:
> > >  
> > > > Add a IIO driver that reports the angle between the lid and the base for
> > > > ChromeOS convertible device.
> > > >
> > > > Tested on eve with ToT EC firmware.
> > > > Check driver is loaded and lid angle is correct.
> > > >
> > > > Signed-off-by: Gwendal Grignou <gwendal@chromium.org>  
> > > Hi Gwendal.
> > >
> > > Please do list dependencies in patches.  I think this one is still
> > > dependent on the larger set of MFD changes.
> > >
> > > For my reference
> > >
> > > Acked-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> > >
> > > Please do poke if this seems to have gotten lost once the precursors
> > > are upstream.  
> > The large set of MFD changes for update cros_ec_commands.h has landed
> > in a immutable branch:
> > git://git.kernel.org/pub/scm/linux/kernel/git/lee/mfd.git branch
> > ib-mfd-cros-5.3.
> >  
> 
> Jonathan, if you don't want to deal with the big patchset that this
> depends and the immutable branch, I can pick the patch and can go
> through the chrome-platform tree. I think it is unlikely have merge
> conflicts, as these patches only touch cros-ec iio parts and, anyway,
> I'll need to deal with the immutable branch because other patches also
> depends on the ib.

That would be great thanks.

I'll almost always take the option that involves me doing less work ;)

Jonathan

> 
> Thanks,
> ~ Enric
> 
> > Thanks,
> > Gwendal.
> >
> >  
> > >
> > > Thanks,
> > >
> > > Jonathan
> > >  
> > > > ---
> > > > Changes in v7:
> > > > - Split patch in two: This is the IIO section.
> > > >
> > > > Changes in v6:
> > > > - Fix lock held in an error path error.
> > > >
> > > > Changes in v5:
> > > > - Remove unnecessary define.
> > > > - v4 was the wrong patch file
> > > >
> > > > Changes in v3:
> > > > - Use static channel array, simplify code because index is always 0.
> > > >
> > > > Changes in v2:
> > > > - Fix license, remove driver_module field.
> > > >
> > > >  drivers/iio/common/cros_ec_sensors/Kconfig    |   9 ++
> > > >  drivers/iio/common/cros_ec_sensors/Makefile   |   1 +
> > > >  .../cros_ec_sensors/cros_ec_lid_angle.c       | 139 ++++++++++++++++++
> > > >  3 files changed, 149 insertions(+)
> > > >  create mode 100644 drivers/iio/common/cros_ec_sensors/cros_ec_lid_angle.c
> > > >
> > > > diff --git a/drivers/iio/common/cros_ec_sensors/Kconfig b/drivers/iio/common/cros_ec_sensors/Kconfig
> > > > index 135f6825903f..aacc2ab9c34f 100644
> > > > --- a/drivers/iio/common/cros_ec_sensors/Kconfig
> > > > +++ b/drivers/iio/common/cros_ec_sensors/Kconfig
> > > > @@ -20,3 +20,12 @@ config IIO_CROS_EC_SENSORS
> > > >         Accelerometers, Gyroscope and Magnetometer that are
> > > >         presented by the ChromeOS EC Sensor hub.
> > > >         Creates an IIO device for each functions.
> > > > +
> > > > +config IIO_CROS_EC_SENSORS_LID_ANGLE
> > > > +     tristate "ChromeOS EC Sensor for lid angle"
> > > > +     depends on IIO_CROS_EC_SENSORS_CORE
> > > > +     help
> > > > +       Module to report the angle between lid and base for some
> > > > +       convertible devices.
> > > > +       This module is loaded when the EC can calculate the angle between the base
> > > > +       and the lid.
> > > > diff --git a/drivers/iio/common/cros_ec_sensors/Makefile b/drivers/iio/common/cros_ec_sensors/Makefile
> > > > index ec716ff2a775..a35ee232ac07 100644
> > > > --- a/drivers/iio/common/cros_ec_sensors/Makefile
> > > > +++ b/drivers/iio/common/cros_ec_sensors/Makefile
> > > > @@ -4,3 +4,4 @@
> > > >
> > > >  obj-$(CONFIG_IIO_CROS_EC_SENSORS_CORE) += cros_ec_sensors_core.o
> > > >  obj-$(CONFIG_IIO_CROS_EC_SENSORS) += cros_ec_sensors.o
> > > > +obj-$(CONFIG_IIO_CROS_EC_SENSORS_LID_ANGLE) += cros_ec_lid_angle.o
> > > > diff --git a/drivers/iio/common/cros_ec_sensors/cros_ec_lid_angle.c b/drivers/iio/common/cros_ec_sensors/cros_ec_lid_angle.c
> > > > new file mode 100644
> > > > index 000000000000..876dfd176b0e
> > > > --- /dev/null
> > > > +++ b/drivers/iio/common/cros_ec_sensors/cros_ec_lid_angle.c
> > > > @@ -0,0 +1,139 @@
> > > > +// SPDX-License-Identifier: GPL-2.0
> > > > +
> > > > +/*
> > > > + * cros_ec_lid_angle - Driver for CrOS EC lid angle sensor.
> > > > + *
> > > > + * Copyright 2018 Google, Inc
> > > > + *
> > > > + * This driver uses the cros-ec interface to communicate with the Chrome OS
> > > > + * EC about counter sensors. Counters are presented through
> > > > + * iio sysfs.
> > > > + */
> > > > +
> > > > +#include <linux/delay.h>
> > > > +#include <linux/device.h>
> > > > +#include <linux/iio/buffer.h>
> > > > +#include <linux/iio/common/cros_ec_sensors_core.h>
> > > > +#include <linux/iio/iio.h>
> > > > +#include <linux/iio/kfifo_buf.h>
> > > > +#include <linux/iio/trigger.h>
> > > > +#include <linux/iio/triggered_buffer.h>
> > > > +#include <linux/iio/trigger_consumer.h>
> > > > +#include <linux/kernel.h>
> > > > +#include <linux/mfd/cros_ec.h>
> > > > +#include <linux/mfd/cros_ec_commands.h>
> > > > +#include <linux/module.h>
> > > > +#include <linux/platform_device.h>
> > > > +#include <linux/slab.h>
> > > > +
> > > > +#define DRV_NAME "cros-ec-lid-angle"
> > > > +
> > > > +/*
> > > > + * One channel for the lid angle, the other for timestamp.
> > > > + */
> > > > +static const struct iio_chan_spec cros_ec_lid_angle_channels[] = {
> > > > +     {
> > > > +             .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
> > > > +             .scan_type.realbits = CROS_EC_SENSOR_BITS,
> > > > +             .scan_type.storagebits = CROS_EC_SENSOR_BITS,
> > > > +             .scan_type.sign = 'u',
> > > > +             .type = IIO_ANGL
> > > > +     },
> > > > +     IIO_CHAN_SOFT_TIMESTAMP(1)
> > > > +};
> > > > +
> > > > +/* State data for ec_sensors iio driver. */
> > > > +struct cros_ec_lid_angle_state {
> > > > +     /* Shared by all sensors */
> > > > +     struct cros_ec_sensors_core_state core;
> > > > +};
> > > > +
> > > > +static int cros_ec_sensors_read_lid_angle(struct iio_dev *indio_dev,
> > > > +                                       unsigned long scan_mask, s16 *data)
> > > > +{
> > > > +     struct cros_ec_sensors_core_state *st = iio_priv(indio_dev);
> > > > +     int ret;
> > > > +
> > > > +     st->param.cmd = MOTIONSENSE_CMD_LID_ANGLE;
> > > > +     ret = cros_ec_motion_send_host_cmd(st, sizeof(st->resp->lid_angle));
> > > > +     if (ret) {
> > > > +             dev_warn(&indio_dev->dev, "Unable to read lid angle\n");
> > > > +             return ret;
> > > > +     }
> > > > +
> > > > +     *data = st->resp->lid_angle.value;
> > > > +     return 0;
> > > > +}
> > > > +
> > > > +static int cros_ec_lid_angle_read(struct iio_dev *indio_dev,
> > > > +                                 struct iio_chan_spec const *chan,
> > > > +                                 int *val, int *val2, long mask)
> > > > +{
> > > > +     struct cros_ec_lid_angle_state *st = iio_priv(indio_dev);
> > > > +     s16 data;
> > > > +     int ret;
> > > > +
> > > > +     mutex_lock(&st->core.cmd_lock);
> > > > +     ret = cros_ec_sensors_read_lid_angle(indio_dev, 1, &data);
> > > > +     if (ret == 0) {
> > > > +             *val = data;
> > > > +             ret = IIO_VAL_INT;
> > > > +     }
> > > > +     mutex_unlock(&st->core.cmd_lock);
> > > > +     return ret;
> > > > +}
> > > > +
> > > > +static const struct iio_info cros_ec_lid_angle_info = {
> > > > +     .read_raw = &cros_ec_lid_angle_read,
> > > > +};
> > > > +
> > > > +static int cros_ec_lid_angle_probe(struct platform_device *pdev)
> > > > +{
> > > > +     struct device *dev = &pdev->dev;
> > > > +     struct iio_dev *indio_dev;
> > > > +     struct cros_ec_lid_angle_state *state;
> > > > +     int ret;
> > > > +
> > > > +     indio_dev = devm_iio_device_alloc(dev, sizeof(*state));
> > > > +     if (!indio_dev)
> > > > +             return -ENOMEM;
> > > > +
> > > > +     ret = cros_ec_sensors_core_init(pdev, indio_dev, false);
> > > > +     if (ret)
> > > > +             return ret;
> > > > +
> > > > +     indio_dev->info = &cros_ec_lid_angle_info;
> > > > +     state = iio_priv(indio_dev);
> > > > +     indio_dev->channels = cros_ec_lid_angle_channels;
> > > > +     indio_dev->num_channels = ARRAY_SIZE(cros_ec_lid_angle_channels);
> > > > +
> > > > +     state->core.read_ec_sensors_data = cros_ec_sensors_read_lid_angle;
> > > > +
> > > > +     ret = devm_iio_triggered_buffer_setup(dev, indio_dev, NULL,
> > > > +                     cros_ec_sensors_capture, NULL);
> > > > +     if (ret)
> > > > +             return ret;
> > > > +
> > > > +     return devm_iio_device_register(dev, indio_dev);
> > > > +}
> > > > +
> > > > +static const struct platform_device_id cros_ec_lid_angle_ids[] = {
> > > > +     {
> > > > +             .name = DRV_NAME,
> > > > +     },
> > > > +     { /* sentinel */ }
> > > > +};
> > > > +MODULE_DEVICE_TABLE(platform, cros_ec_lid_angle_ids);
> > > > +
> > > > +static struct platform_driver cros_ec_lid_angle_platform_driver = {
> > > > +     .driver = {
> > > > +             .name   = DRV_NAME,
> > > > +             .pm     = &cros_ec_sensors_pm_ops,
> > > > +     },
> > > > +     .probe          = cros_ec_lid_angle_probe,
> > > > +     .id_table       = cros_ec_lid_angle_ids,
> > > > +};
> > > > +module_platform_driver(cros_ec_lid_angle_platform_driver);
> > > > +
> > > > +MODULE_DESCRIPTION("ChromeOS EC driver for reporting convertible lid angle.");
> > > > +MODULE_LICENSE("GPL v2");  
> > >  



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v7 2/2] iio: cros_ec: Add lid angle driver
  2019-06-21 15:31         ` Jonathan Cameron
@ 2019-06-25 13:53           ` Enric Balletbo i Serra
  0 siblings, 0 replies; 9+ messages in thread
From: Enric Balletbo i Serra @ 2019-06-25 13:53 UTC (permalink / raw)
  To: Jonathan Cameron, Enric Balletbo Serra
  Cc: Gwendal Grignou, Jonathan Cameron, Benson Leung, Guenter Roeck,
	Lee Jones, linux-iio, linux-kernel



On 21/6/19 17:31, Jonathan Cameron wrote:
> On Wed, 19 Jun 2019 22:49:04 +0200
> Enric Balletbo Serra <eballetbo@gmail.com> wrote:
> 
>> Missatge de Gwendal Grignou <gwendal@chromium.org> del dia dv., 14 de
>> juny 2019 a les 23:56:
>>>
>>> On Sat, May 18, 2019 at 2:53 AM Jonathan Cameron <jic23@kernel.org> wrote:  
>>>>
>>>> On Fri, 17 May 2019 16:38:56 -0700
>>>> Gwendal Grignou <gwendal@chromium.org> wrote:
>>>>  
>>>>> Add a IIO driver that reports the angle between the lid and the base for
>>>>> ChromeOS convertible device.
>>>>>
>>>>> Tested on eve with ToT EC firmware.
>>>>> Check driver is loaded and lid angle is correct.
>>>>>
>>>>> Signed-off-by: Gwendal Grignou <gwendal@chromium.org>  
>>>> Hi Gwendal.
>>>>
>>>> Please do list dependencies in patches.  I think this one is still
>>>> dependent on the larger set of MFD changes.
>>>>
>>>> For my reference
>>>>
>>>> Acked-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
>>>>
>>>> Please do poke if this seems to have gotten lost once the precursors
>>>> are upstream.  
>>> The large set of MFD changes for update cros_ec_commands.h has landed
>>> in a immutable branch:
>>> git://git.kernel.org/pub/scm/linux/kernel/git/lee/mfd.git branch
>>> ib-mfd-cros-5.3.
>>>  
>>
>> Jonathan, if you don't want to deal with the big patchset that this
>> depends and the immutable branch, I can pick the patch and can go
>> through the chrome-platform tree. I think it is unlikely have merge
>> conflicts, as these patches only touch cros-ec iio parts and, anyway,
>> I'll need to deal with the immutable branch because other patches also
>> depends on the ib.
> 
> That would be great thanks.
> 

Ok, applied for 5.3 via chrome-platform tree

Thanks,
~ Enric

> I'll almost always take the option that involves me doing less work ;)
> 
> Jonathan
> 
>>
>> Thanks,
>> ~ Enric
>>
>>> Thanks,
>>> Gwendal.
>>>
>>>  
>>>>
>>>> Thanks,
>>>>
>>>> Jonathan
>>>>  
>>>>> ---
>>>>> Changes in v7:
>>>>> - Split patch in two: This is the IIO section.
>>>>>
>>>>> Changes in v6:
>>>>> - Fix lock held in an error path error.
>>>>>
>>>>> Changes in v5:
>>>>> - Remove unnecessary define.
>>>>> - v4 was the wrong patch file
>>>>>
>>>>> Changes in v3:
>>>>> - Use static channel array, simplify code because index is always 0.
>>>>>
>>>>> Changes in v2:
>>>>> - Fix license, remove driver_module field.
>>>>>
>>>>>  drivers/iio/common/cros_ec_sensors/Kconfig    |   9 ++
>>>>>  drivers/iio/common/cros_ec_sensors/Makefile   |   1 +
>>>>>  .../cros_ec_sensors/cros_ec_lid_angle.c       | 139 ++++++++++++++++++
>>>>>  3 files changed, 149 insertions(+)
>>>>>  create mode 100644 drivers/iio/common/cros_ec_sensors/cros_ec_lid_angle.c
>>>>>
>>>>> diff --git a/drivers/iio/common/cros_ec_sensors/Kconfig b/drivers/iio/common/cros_ec_sensors/Kconfig
>>>>> index 135f6825903f..aacc2ab9c34f 100644
>>>>> --- a/drivers/iio/common/cros_ec_sensors/Kconfig
>>>>> +++ b/drivers/iio/common/cros_ec_sensors/Kconfig
>>>>> @@ -20,3 +20,12 @@ config IIO_CROS_EC_SENSORS
>>>>>         Accelerometers, Gyroscope and Magnetometer that are
>>>>>         presented by the ChromeOS EC Sensor hub.
>>>>>         Creates an IIO device for each functions.
>>>>> +
>>>>> +config IIO_CROS_EC_SENSORS_LID_ANGLE
>>>>> +     tristate "ChromeOS EC Sensor for lid angle"
>>>>> +     depends on IIO_CROS_EC_SENSORS_CORE
>>>>> +     help
>>>>> +       Module to report the angle between lid and base for some
>>>>> +       convertible devices.
>>>>> +       This module is loaded when the EC can calculate the angle between the base
>>>>> +       and the lid.
>>>>> diff --git a/drivers/iio/common/cros_ec_sensors/Makefile b/drivers/iio/common/cros_ec_sensors/Makefile
>>>>> index ec716ff2a775..a35ee232ac07 100644
>>>>> --- a/drivers/iio/common/cros_ec_sensors/Makefile
>>>>> +++ b/drivers/iio/common/cros_ec_sensors/Makefile
>>>>> @@ -4,3 +4,4 @@
>>>>>
>>>>>  obj-$(CONFIG_IIO_CROS_EC_SENSORS_CORE) += cros_ec_sensors_core.o
>>>>>  obj-$(CONFIG_IIO_CROS_EC_SENSORS) += cros_ec_sensors.o
>>>>> +obj-$(CONFIG_IIO_CROS_EC_SENSORS_LID_ANGLE) += cros_ec_lid_angle.o
>>>>> diff --git a/drivers/iio/common/cros_ec_sensors/cros_ec_lid_angle.c b/drivers/iio/common/cros_ec_sensors/cros_ec_lid_angle.c
>>>>> new file mode 100644
>>>>> index 000000000000..876dfd176b0e
>>>>> --- /dev/null
>>>>> +++ b/drivers/iio/common/cros_ec_sensors/cros_ec_lid_angle.c
>>>>> @@ -0,0 +1,139 @@
>>>>> +// SPDX-License-Identifier: GPL-2.0
>>>>> +
>>>>> +/*
>>>>> + * cros_ec_lid_angle - Driver for CrOS EC lid angle sensor.
>>>>> + *
>>>>> + * Copyright 2018 Google, Inc
>>>>> + *
>>>>> + * This driver uses the cros-ec interface to communicate with the Chrome OS
>>>>> + * EC about counter sensors. Counters are presented through
>>>>> + * iio sysfs.
>>>>> + */
>>>>> +
>>>>> +#include <linux/delay.h>
>>>>> +#include <linux/device.h>
>>>>> +#include <linux/iio/buffer.h>
>>>>> +#include <linux/iio/common/cros_ec_sensors_core.h>
>>>>> +#include <linux/iio/iio.h>
>>>>> +#include <linux/iio/kfifo_buf.h>
>>>>> +#include <linux/iio/trigger.h>
>>>>> +#include <linux/iio/triggered_buffer.h>
>>>>> +#include <linux/iio/trigger_consumer.h>
>>>>> +#include <linux/kernel.h>
>>>>> +#include <linux/mfd/cros_ec.h>
>>>>> +#include <linux/mfd/cros_ec_commands.h>
>>>>> +#include <linux/module.h>
>>>>> +#include <linux/platform_device.h>
>>>>> +#include <linux/slab.h>
>>>>> +
>>>>> +#define DRV_NAME "cros-ec-lid-angle"
>>>>> +
>>>>> +/*
>>>>> + * One channel for the lid angle, the other for timestamp.
>>>>> + */
>>>>> +static const struct iio_chan_spec cros_ec_lid_angle_channels[] = {
>>>>> +     {
>>>>> +             .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
>>>>> +             .scan_type.realbits = CROS_EC_SENSOR_BITS,
>>>>> +             .scan_type.storagebits = CROS_EC_SENSOR_BITS,
>>>>> +             .scan_type.sign = 'u',
>>>>> +             .type = IIO_ANGL
>>>>> +     },
>>>>> +     IIO_CHAN_SOFT_TIMESTAMP(1)
>>>>> +};
>>>>> +
>>>>> +/* State data for ec_sensors iio driver. */
>>>>> +struct cros_ec_lid_angle_state {
>>>>> +     /* Shared by all sensors */
>>>>> +     struct cros_ec_sensors_core_state core;
>>>>> +};
>>>>> +
>>>>> +static int cros_ec_sensors_read_lid_angle(struct iio_dev *indio_dev,
>>>>> +                                       unsigned long scan_mask, s16 *data)
>>>>> +{
>>>>> +     struct cros_ec_sensors_core_state *st = iio_priv(indio_dev);
>>>>> +     int ret;
>>>>> +
>>>>> +     st->param.cmd = MOTIONSENSE_CMD_LID_ANGLE;
>>>>> +     ret = cros_ec_motion_send_host_cmd(st, sizeof(st->resp->lid_angle));
>>>>> +     if (ret) {
>>>>> +             dev_warn(&indio_dev->dev, "Unable to read lid angle\n");
>>>>> +             return ret;
>>>>> +     }
>>>>> +
>>>>> +     *data = st->resp->lid_angle.value;
>>>>> +     return 0;
>>>>> +}
>>>>> +
>>>>> +static int cros_ec_lid_angle_read(struct iio_dev *indio_dev,
>>>>> +                                 struct iio_chan_spec const *chan,
>>>>> +                                 int *val, int *val2, long mask)
>>>>> +{
>>>>> +     struct cros_ec_lid_angle_state *st = iio_priv(indio_dev);
>>>>> +     s16 data;
>>>>> +     int ret;
>>>>> +
>>>>> +     mutex_lock(&st->core.cmd_lock);
>>>>> +     ret = cros_ec_sensors_read_lid_angle(indio_dev, 1, &data);
>>>>> +     if (ret == 0) {
>>>>> +             *val = data;
>>>>> +             ret = IIO_VAL_INT;
>>>>> +     }
>>>>> +     mutex_unlock(&st->core.cmd_lock);
>>>>> +     return ret;
>>>>> +}
>>>>> +
>>>>> +static const struct iio_info cros_ec_lid_angle_info = {
>>>>> +     .read_raw = &cros_ec_lid_angle_read,
>>>>> +};
>>>>> +
>>>>> +static int cros_ec_lid_angle_probe(struct platform_device *pdev)
>>>>> +{
>>>>> +     struct device *dev = &pdev->dev;
>>>>> +     struct iio_dev *indio_dev;
>>>>> +     struct cros_ec_lid_angle_state *state;
>>>>> +     int ret;
>>>>> +
>>>>> +     indio_dev = devm_iio_device_alloc(dev, sizeof(*state));
>>>>> +     if (!indio_dev)
>>>>> +             return -ENOMEM;
>>>>> +
>>>>> +     ret = cros_ec_sensors_core_init(pdev, indio_dev, false);
>>>>> +     if (ret)
>>>>> +             return ret;
>>>>> +
>>>>> +     indio_dev->info = &cros_ec_lid_angle_info;
>>>>> +     state = iio_priv(indio_dev);
>>>>> +     indio_dev->channels = cros_ec_lid_angle_channels;
>>>>> +     indio_dev->num_channels = ARRAY_SIZE(cros_ec_lid_angle_channels);
>>>>> +
>>>>> +     state->core.read_ec_sensors_data = cros_ec_sensors_read_lid_angle;
>>>>> +
>>>>> +     ret = devm_iio_triggered_buffer_setup(dev, indio_dev, NULL,
>>>>> +                     cros_ec_sensors_capture, NULL);
>>>>> +     if (ret)
>>>>> +             return ret;
>>>>> +
>>>>> +     return devm_iio_device_register(dev, indio_dev);
>>>>> +}
>>>>> +
>>>>> +static const struct platform_device_id cros_ec_lid_angle_ids[] = {
>>>>> +     {
>>>>> +             .name = DRV_NAME,
>>>>> +     },
>>>>> +     { /* sentinel */ }
>>>>> +};
>>>>> +MODULE_DEVICE_TABLE(platform, cros_ec_lid_angle_ids);
>>>>> +
>>>>> +static struct platform_driver cros_ec_lid_angle_platform_driver = {
>>>>> +     .driver = {
>>>>> +             .name   = DRV_NAME,
>>>>> +             .pm     = &cros_ec_sensors_pm_ops,
>>>>> +     },
>>>>> +     .probe          = cros_ec_lid_angle_probe,
>>>>> +     .id_table       = cros_ec_lid_angle_ids,
>>>>> +};
>>>>> +module_platform_driver(cros_ec_lid_angle_platform_driver);
>>>>> +
>>>>> +MODULE_DESCRIPTION("ChromeOS EC driver for reporting convertible lid angle.");
>>>>> +MODULE_LICENSE("GPL v2");  
>>>>  
> 
> 

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, back to index

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-17 23:38 [PATCH v7 0/2] iio: cros_ec: Add lid angle driver Gwendal Grignou
2019-05-17 23:38 ` [PATCH v7 1/2] mfd: cros_ec: Register cros_ec_lid_angle driver when presented Gwendal Grignou
2019-06-03 12:31   ` Lee Jones
2019-05-17 23:38 ` [PATCH v7 2/2] iio: cros_ec: Add lid angle driver Gwendal Grignou
2019-05-18  9:53   ` Jonathan Cameron
2019-06-14 21:54     ` Gwendal Grignou
2019-06-19 20:49       ` Enric Balletbo Serra
2019-06-21 15:31         ` Jonathan Cameron
2019-06-25 13:53           ` Enric Balletbo i Serra

Linux-IIO Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-iio/0 linux-iio/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-iio linux-iio/ https://lore.kernel.org/linux-iio \
		linux-iio@vger.kernel.org linux-iio@archiver.kernel.org
	public-inbox-index linux-iio


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-iio


AGPL code for this site: git clone https://public-inbox.org/ public-inbox