Skip to contentSkip to conversation

Add ALS and barometer driver to ChromesOS EC sensor hub

PATCH Superseded Gwendal Grignou 2 participants 6 messages Jan 4, 2018 – Jan 8, 2018

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Add ALS and barometer driver to ChromesOS EC sensor hub

This patchset adds 2 drivers for supporting barometer, light and proximity sensors when connected behind the Embedded Controller in a ChromeBook.

Gwendal Grignou (3):
iio: cros_ec: light code cleanup
iio: cros_ec: Add EC driver for Light and Proximity
iio: cros_ec: add barometer driver

 drivers/iio/common/cros_ec_sensors/Kconfig         |  16 ++
 drivers/iio/common/cros_ec_sensors/Makefile        |   2 +
 drivers/iio/common/cros_ec_sensors/cros_ec_baro.c  | 222 +++++++++++++++++
 .../common/cros_ec_sensors/cros_ec_light_prox.c    | 269 +++++++++++++++++++++
 .../iio/common/cros_ec_sensors/cros_ec_sensors.c   |   5 +-
 .../common/cros_ec_sensors/cros_ec_sensors_core.c  |   7 +-
 6 files changed, 514 insertions(+), 7 deletions(-)
 create mode 100644 drivers/iio/common/cros_ec_sensors/cros_ec_baro.c
 create mode 100644 drivers/iio/common/cros_ec_sensors/cros_ec_light_prox.c
Signature · 1 line
2.16.0.rc0.223.g4a4ac83678-goog
#1 lore raw

PATCH 1/3 iio: cros_ec: light code cleanup

- use dev instead of &pdev->dev when defined
- remove syfs.h inclusion.

---
 drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c      | 5 ++---
 drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c | 7 +++----
 2 files changed, 5 insertions(+), 7 deletions(-)
drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c +2 -3
index 7d30c59da3e2..2297c8ce7cb8 100644
@@ -29,7 +29,6 @@
 #include <linux/module.h>
 #include <linux/platform_device.h>
 #include <linux/slab.h>
-#include <linux/sysfs.h>
 
 #include "cros_ec_sensors_core.h"
 
@@ -201,7 +200,7 @@ static int cros_ec_sensors_probe(struct platform_device *pdev)
 		return -EINVAL;
 	}
 
-	indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*state));
+	indio_dev = devm_iio_device_alloc(dev, sizeof(*state));
 	if (!indio_dev)
 		return -ENOMEM;
 
@@ -241,7 +240,7 @@ static int cros_ec_sensors_probe(struct platform_device *pdev)
 			channel->type = IIO_MAGN;
 			break;
 		default:
-			dev_err(&pdev->dev, "Unknown motion sensor\n");
+			dev_err(dev, "Unknown motion sensor\n");
 			return -EINVAL;
 		}
 	}
drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c +3 -4
index 416cae5ebbd0..d50a32ba91fe 100644
@@ -24,7 +24,6 @@
 #include <linux/mfd/cros_ec_commands.h>
 #include <linux/module.h>
 #include <linux/slab.h>
-#include <linux/sysfs.h>
 #include <linux/platform_device.h>
 
 #include "cros_ec_sensors_core.h"
@@ -41,13 +40,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_dev *ec = dev_get_drvdata(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->msg = devm_kzalloc(&pdev->dev,
+	state->msg = devm_kzalloc(dev,
 				max((u16)sizeof(struct ec_params_motion_sense),
 				state->ec->max_response), GFP_KERNEL);
 	if (!state->msg)
@@ -62,7 +61,7 @@ int cros_ec_sensors_core_init(struct platform_device *pdev,
 	state->msg->command = EC_CMD_MOTION_SENSE_CMD + ec->cmd_offset;
 	state->msg->outsize = sizeof(struct ec_params_motion_sense);
 
-	indio_dev->dev.parent = &pdev->dev;
+	indio_dev->dev.parent = dev;
 	indio_dev->name = pdev->name;
 
 	if (physical_device) {
Signature · 1 line
2.16.0.rc0.223.g4a4ac83678-goog
#2 lore raw

Re: [PATCH 1/3] iio: cros_ec: light code cleanup

Hi Gwendal,

Quoted 69 lines · Gwendal Grignou

- use dev instead of &pdev->dev when defined
- remove syfs.h inclusion.

---
 drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c      | 5 ++---
 drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c | 7 +++----
 2 files changed, 5 insertions(+), 7 deletions(-)
drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c +2 -3
index 7d30c59da3e2..2297c8ce7cb8 100644
@@ -29,7 +29,6 @@
 #include <linux/module.h>
 #include <linux/platform_device.h>
 #include <linux/slab.h>
-#include <linux/sysfs.h>
 
 #include "cros_ec_sensors_core.h"
 
@@ -201,7 +200,7 @@ static int cros_ec_sensors_probe(struct platform_device *pdev)
 		return -EINVAL;
 	}
 
-	indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*state));
+	indio_dev = devm_iio_device_alloc(dev, sizeof(*state));
 	if (!indio_dev)
 		return -ENOMEM;
 
@@ -241,7 +240,7 @@ static int cros_ec_sensors_probe(struct platform_device *pdev)
 			channel->type = IIO_MAGN;
 			break;
 		default:
-			dev_err(&pdev->dev, "Unknown motion sensor\n");
+			dev_err(dev, "Unknown motion sensor\n");
 			return -EINVAL;
 		}
 	}
drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c +2 -3
index 416cae5ebbd0..d50a32ba91fe 100644
@@ -24,7 +24,6 @@
 #include <linux/mfd/cros_ec_commands.h>
 #include <linux/module.h>
 #include <linux/slab.h>
-#include <linux/sysfs.h>
 #include <linux/platform_device.h>
 
 #include "cros_ec_sensors_core.h"
@@ -41,13 +40,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_dev *ec = dev_get_drvdata(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->msg = devm_kzalloc(&pdev->dev,
+	state->msg = devm_kzalloc(dev,
 				max((u16)sizeof(struct ec_params_motion_sense),
 				state->ec->max_response), GFP_KERNEL);
 	if (!state->msg)

drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c int cros_ec_sensors_core_init(struct platform_device *pdev, · line 67

Quoted 8 lines
drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c +1 -1
@@ -62,7 +61,7 @@ int cros_ec_sensors_core_init(struct platform_device *pdev,
 	state->msg->command = EC_CMD_MOTION_SENSE_CMD + ec->cmd_offset;
 	state->msg->outsize = sizeof(struct ec_params_motion_sense);
 
-	indio_dev->dev.parent = &pdev->dev;
+	indio_dev->dev.parent = dev;
 	indio_dev->name = pdev->name;
 
 	if (physical_device) {

This patch looks good to me but did you miss to include the patch when you sent v2? At least I did not receive the patch within v2 nor is available in linux-iio patchwork v2 series.

Best regards,
Enric

#3 lore raw

Re: [PATCH 1/3] iio: cros_ec: light code cleanup

Quoted 6 lines · Enric Balletbo i Serra

Hi Gwendal,

Quoted 3 lines · Gwendal Grignou

- use dev instead of &pdev->dev when defined
- remove syfs.h inclusion.

Quoted 7 lines
Quoted 2 lines

---

This patch looks good to me but did you miss to include the patch when you sent v2? At least I did not receive the patch within v2 nor is available in linux-iio patchwork v2 series.

I did not resend it as there was not change in this patch between v1 and v2, my mistake. I am resending a newer patch anyway, as the 2 other patches in v2 were incorrect.

Gwendal.

Quoted 3 lines

Best regards,
Enric

#4 lore raw

PATCH 2/3 iio: cros_ec: Add EC driver for Light and Proximity

In reply to Gwendal Grignou

Add driver for light and proximity sensors exposed by EC.

Reviewed-on: https://chromium-review.googlesource.com/291360

[rebase44(groeck): Adjust for API changes]
[rebase414(gwendal): Adjust for API changes]
(cherry picked from commit 17e781c5f2747236ea1f9de6906e04aa92d383cb)
---
 drivers/iio/common/cros_ec_sensors/Kconfig         |   9 +
 drivers/iio/common/cros_ec_sensors/Makefile        |   1 +
 .../common/cros_ec_sensors/cros_ec_light_prox.c    | 269 +++++++++++++++++++++
 3 files changed, 279 insertions(+)
 create mode 100644 drivers/iio/common/cros_ec_sensors/cros_ec_light_prox.c
drivers/iio/common/cros_ec_sensors/Kconfig +9 -0
index 135f6825903f..b70138566870 100644
@@ -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_LIGHT_PROX
+	tristate "ChromeOS EC Light and Proximity Sensors"
+	depends on IIO_CROS_EC_SENSORS_CORE
+	help
+	  Module to handle Light and Proximity sensors
+	  presented by the ChromeOS EC Sensor hub.
+	  Create an IIO device for each funcions.
+	  Only one source is exposed by the EC.
drivers/iio/common/cros_ec_sensors/Makefile +1 -0
index ec716ff2a775..7aaf2a2dcdbd 100644
@@ -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_LIGHT_PROX) += cros_ec_light_prox.o
drivers/iio/common/cros_ec_sensors/cros_ec_light_prox.c new file +269 -0

269 lines not on this page · raw message

Signature · 1 line
2.16.0.rc0.223.g4a4ac83678-goog
#5 lore raw

PATCH 3/3 iio: cros_ec: add barometer driver

In reply to Gwendal Grignou

Add a driver when EC presents a barometer.

BUG=chrome-os-partner:57111
TEST=Check the values returned by the EC
cat scale
0.040000000
cat in_pressure_raw
24097
scale * in_pressure_raw --> 963.88 hPa

Reviewed-on: https://chromium-review.googlesource.com/382832

(cherry picked from commit 686988372cdc ("CHROMIUM: iio: cros_ec:

add cros_ec barometer driver"))

---
 drivers/iio/common/cros_ec_sensors/Kconfig        |   7 +
 drivers/iio/common/cros_ec_sensors/Makefile       |   1 +
 drivers/iio/common/cros_ec_sensors/cros_ec_baro.c | 222 ++++++++++++++++++++++
 3 files changed, 230 insertions(+)
 create mode 100644 drivers/iio/common/cros_ec_sensors/cros_ec_baro.c
drivers/iio/common/cros_ec_sensors/Kconfig +7 -0
index b70138566870..f5c95198580f 100644
@@ -21,6 +21,13 @@ config IIO_CROS_EC_SENSORS
 	  presented by the ChromeOS EC Sensor hub.
 	  Creates an IIO device for each functions.
 
+config IIO_CROS_EC_BARO
+	tristate "ChromeOS EC Barometer Sensor"
+	depends on IIO_CROS_EC_SENSORS_CORE
+	help
+	  Module to handle Barometer sensor when
+	  presented by the ChromeOS EC Sensor hub.
+
 config IIO_CROS_EC_LIGHT_PROX
 	tristate "ChromeOS EC Light and Proximity Sensors"
 	depends on IIO_CROS_EC_SENSORS_CORE
drivers/iio/common/cros_ec_sensors/Makefile +1 -0
index 7aaf2a2dcdbd..71103495aada 100644
@@ -4,4 +4,5 @@
 
 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_BARO) += cros_ec_baro.o
 obj-$(CONFIG_IIO_CROS_EC_LIGHT_PROX) += cros_ec_light_prox.o
drivers/iio/common/cros_ec_sensors/cros_ec_baro.c new file +222 -0

222 lines not on this page · raw message

Signature · 1 line
2.16.0.rc0.223.g4a4ac83678-goog