linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/6] iio: enable ST Sensors on Ux500
@ 2014-04-13 19:08 Linus Walleij
  2014-04-13 19:08 ` [PATCH 1/6] iio: st_sensors: announce registered sensors Linus Walleij
                   ` (5 more replies)
  0 siblings, 6 replies; 15+ messages in thread
From: Linus Walleij @ 2014-04-13 19:08 UTC (permalink / raw)
  To: Jonathan Cameron, linux-iio, Denis CIOCCA; +Cc: Lee Jones, Linus Walleij

This series:
- Patches the ST sensor drivers to all announce their presence and
  grab regulators for vdd and vddio if need be
- Adds device tree bindings and probe path for device tree
- Registers the applicable sensors for Ux500 so you can see how it
  plays out.

All but the last patch should eventually be merged through the
IIO tree if we can agree upon the implementation. I will merge the
last patch through the Ux500 tree.

Linus Walleij (6):
  iio: st_sensors: announce registered sensors
  iio: st_sensors: move regulator retrieveal to core
  iio: st_sensors: get platform data from device tree
  iio: st_sensors: add device tree bindings
  iio: st_sensors: add devicetree probing support
  ARM: ux500: add misc sensors to the device trees

 .../devicetree/bindings/iio/st-sensors.txt         | 54 ++++++++++++++++
 arch/arm/boot/dts/ste-href.dtsi                    | 30 +++++++++
 arch/arm/boot/dts/ste-hrefv60plus.dtsi             | 15 ++++-
 arch/arm/boot/dts/ste-snowball.dts                 | 38 +++++++++++-
 drivers/iio/accel/st_accel.h                       | 47 ++++++++++++++
 drivers/iio/accel/st_accel_core.c                  |  7 +++
 drivers/iio/accel/st_accel_i2c.c                   |  2 +
 drivers/iio/common/st_sensors/st_sensors_core.c    | 72 +++++++++++++++++++++-
 drivers/iio/common/st_sensors/st_sensors_i2c.c     | 29 +++++++++
 drivers/iio/gyro/st_gyro.h                         | 35 +++++++++++
 drivers/iio/gyro/st_gyro_core.c                    |  7 +++
 drivers/iio/gyro/st_gyro_i2c.c                     |  2 +
 drivers/iio/magnetometer/st_magn.h                 | 19 ++++++
 drivers/iio/magnetometer/st_magn_core.c            |  7 +++
 drivers/iio/magnetometer/st_magn_i2c.c             |  2 +
 drivers/iio/pressure/st_pressure.h                 | 19 ++++++
 drivers/iio/pressure/st_pressure_core.c            | 42 ++-----------
 drivers/iio/pressure/st_pressure_i2c.c             |  2 +
 include/linux/iio/common/st_sensors.h              |  4 ++
 include/linux/iio/common/st_sensors_i2c.h          | 11 ++++
 20 files changed, 401 insertions(+), 43 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/iio/st-sensors.txt

-- 
1.9.0

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

* [PATCH 1/6] iio: st_sensors: announce registered sensors
  2014-04-13 19:08 [PATCH 0/6] iio: enable ST Sensors on Ux500 Linus Walleij
@ 2014-04-13 19:08 ` Linus Walleij
  2014-04-23 21:21   ` Jonathan Cameron
  2014-04-13 19:08 ` [PATCH 2/6] iio: st_sensors: move regulator retrieveal to core Linus Walleij
                   ` (4 subsequent siblings)
  5 siblings, 1 reply; 15+ messages in thread
From: Linus Walleij @ 2014-04-13 19:08 UTC (permalink / raw)
  To: Jonathan Cameron, linux-iio, Denis CIOCCA; +Cc: Lee Jones, Linus Walleij

It is pretty helpful to know already from dmesg that a certain
device is successfully registered, instead of having to browse
sysfs to see if it's actually there.

Cc: Lee Jones <lee.jones@linaro.org>
Cc: Denis CIOCCA <denis.ciocca@st.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 drivers/iio/accel/st_accel_core.c       | 3 +++
 drivers/iio/gyro/st_gyro_core.c         | 3 +++
 drivers/iio/magnetometer/st_magn_core.c | 3 +++
 drivers/iio/pressure/st_pressure_core.c | 3 +++
 4 files changed, 12 insertions(+)

diff --git a/drivers/iio/accel/st_accel_core.c b/drivers/iio/accel/st_accel_core.c
index 38caedc76b98..4e06fcf5b891 100644
--- a/drivers/iio/accel/st_accel_core.c
+++ b/drivers/iio/accel/st_accel_core.c
@@ -496,6 +496,9 @@ int st_accel_common_probe(struct iio_dev *indio_dev,
 	if (err)
 		goto st_accel_device_register_error;
 
+	dev_info(&indio_dev->dev, "registered accelerometer %s\n",
+		 indio_dev->name);
+
 	return 0;
 
 st_accel_device_register_error:
diff --git a/drivers/iio/gyro/st_gyro_core.c b/drivers/iio/gyro/st_gyro_core.c
index a8e174a47bc4..bc71f4d1e2ce 100644
--- a/drivers/iio/gyro/st_gyro_core.c
+++ b/drivers/iio/gyro/st_gyro_core.c
@@ -344,6 +344,9 @@ int st_gyro_common_probe(struct iio_dev *indio_dev,
 	if (err)
 		goto st_gyro_device_register_error;
 
+	dev_info(&indio_dev->dev, "registered gyroscope %s\n",
+		 indio_dev->name);
+
 	return 0;
 
 st_gyro_device_register_error:
diff --git a/drivers/iio/magnetometer/st_magn_core.c b/drivers/iio/magnetometer/st_magn_core.c
index 52bbcfa1e077..8e33a7682d33 100644
--- a/drivers/iio/magnetometer/st_magn_core.c
+++ b/drivers/iio/magnetometer/st_magn_core.c
@@ -387,6 +387,9 @@ int st_magn_common_probe(struct iio_dev *indio_dev,
 	if (err)
 		goto st_magn_device_register_error;
 
+	dev_info(&indio_dev->dev, "registered magnetometer %s\n",
+		 indio_dev->name);
+
 	return 0;
 
 st_magn_device_register_error:
diff --git a/drivers/iio/pressure/st_pressure_core.c b/drivers/iio/pressure/st_pressure_core.c
index 7418768ed49c..013becbe8f47 100644
--- a/drivers/iio/pressure/st_pressure_core.c
+++ b/drivers/iio/pressure/st_pressure_core.c
@@ -474,6 +474,9 @@ int st_press_common_probe(struct iio_dev *indio_dev,
 	if (err)
 		goto st_press_device_register_error;
 
+	dev_info(&indio_dev->dev, "registered pressure sensor %s\n",
+		 indio_dev->name);
+
 	return err;
 
 st_press_device_register_error:
-- 
1.9.0


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

* [PATCH 2/6] iio: st_sensors: move regulator retrieveal to core
  2014-04-13 19:08 [PATCH 0/6] iio: enable ST Sensors on Ux500 Linus Walleij
  2014-04-13 19:08 ` [PATCH 1/6] iio: st_sensors: announce registered sensors Linus Walleij
@ 2014-04-13 19:08 ` Linus Walleij
  2014-04-13 19:09 ` [PATCH 3/6] iio: st_sensors: get platform data from device tree Linus Walleij
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 15+ messages in thread
From: Linus Walleij @ 2014-04-13 19:08 UTC (permalink / raw)
  To: Jonathan Cameron, linux-iio, Denis CIOCCA; +Cc: Lee Jones, Linus Walleij

Currently the pressure sensor has code to retrieve and enable two
regulators for Vdd and Vdd IO, but actually these voltage inputs
are found on all of these ST sensors, so move the regulator
handling to the core and make sure all the ST sensors call these
functions on probe() and remove() to enable/disable power.

Here also mover over to obtaining the regulator from the *parent*
device of the IIO device, as the IIO device is created on-the-fly
in this very subsystem it very unlikely evert have any regulators
attached to it whatsoever. It is much more likely that the parent
is a platform device, possibly instantiated from a device tree,
which in turn have Vdd and Vdd IO supplied assigned to it.

Cc: Lee Jones <lee.jones@linaro.org>
Cc: Denis CIOCCA <denis.ciocca@st.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 drivers/iio/accel/st_accel_core.c               |  4 +++
 drivers/iio/common/st_sensors/st_sensors_core.c | 37 +++++++++++++++++++++++
 drivers/iio/gyro/st_gyro_core.c                 |  4 +++
 drivers/iio/magnetometer/st_magn_core.c         |  4 +++
 drivers/iio/pressure/st_pressure_core.c         | 39 ++-----------------------
 include/linux/iio/common/st_sensors.h           |  4 +++
 6 files changed, 55 insertions(+), 37 deletions(-)

diff --git a/drivers/iio/accel/st_accel_core.c b/drivers/iio/accel/st_accel_core.c
index 4e06fcf5b891..a2abf7c2ce3b 100644
--- a/drivers/iio/accel/st_accel_core.c
+++ b/drivers/iio/accel/st_accel_core.c
@@ -459,6 +459,8 @@ int st_accel_common_probe(struct iio_dev *indio_dev,
 	indio_dev->modes = INDIO_DIRECT_MODE;
 	indio_dev->info = &accel_info;
 
+	st_sensors_power_enable(indio_dev);
+
 	err = st_sensors_check_device_support(indio_dev,
 				ARRAY_SIZE(st_accel_sensors), st_accel_sensors);
 	if (err < 0)
@@ -515,6 +517,8 @@ void st_accel_common_remove(struct iio_dev *indio_dev)
 {
 	struct st_sensor_data *adata = iio_priv(indio_dev);
 
+	st_sensors_power_disable(indio_dev);
+
 	iio_device_unregister(indio_dev);
 	if (adata->get_irq_data_ready(indio_dev) > 0)
 		st_sensors_deallocate_trigger(indio_dev);
diff --git a/drivers/iio/common/st_sensors/st_sensors_core.c b/drivers/iio/common/st_sensors/st_sensors_core.c
index 7ba1ef270213..e8b932fed70e 100644
--- a/drivers/iio/common/st_sensors/st_sensors_core.c
+++ b/drivers/iio/common/st_sensors/st_sensors_core.c
@@ -13,6 +13,7 @@
 #include <linux/slab.h>
 #include <linux/delay.h>
 #include <linux/iio/iio.h>
+#include <linux/regulator/consumer.h>
 #include <asm/unaligned.h>
 
 #include <linux/iio/common/st_sensors.h>
@@ -198,6 +199,42 @@ int st_sensors_set_axis_enable(struct iio_dev *indio_dev, u8 axis_enable)
 }
 EXPORT_SYMBOL(st_sensors_set_axis_enable);
 
+void st_sensors_power_enable(struct iio_dev *indio_dev)
+{
+	struct st_sensor_data *pdata = iio_priv(indio_dev);
+	int err;
+
+	/* Regulators not mandatory, but if requested we should enable them. */
+	pdata->vdd = devm_regulator_get_optional(indio_dev->dev.parent, "vdd");
+	if (!IS_ERR(pdata->vdd)) {
+		err = regulator_enable(pdata->vdd);
+		if (err != 0)
+			dev_warn(&indio_dev->dev,
+				 "Failed to enable specified Vdd supply\n");
+	}
+
+	pdata->vdd_io = devm_regulator_get_optional(indio_dev->dev.parent, "vddio");
+	if (!IS_ERR(pdata->vdd_io)) {
+		err = regulator_enable(pdata->vdd_io);
+		if (err != 0)
+			dev_warn(&indio_dev->dev,
+				 "Failed to enable specified Vdd_IO supply\n");
+	}
+}
+EXPORT_SYMBOL(st_sensors_power_enable);
+
+void st_sensors_power_disable(struct iio_dev *indio_dev)
+{
+	struct st_sensor_data *pdata = iio_priv(indio_dev);
+
+	if (!IS_ERR(pdata->vdd))
+		regulator_disable(pdata->vdd);
+
+	if (!IS_ERR(pdata->vdd_io))
+		regulator_disable(pdata->vdd_io);
+}
+EXPORT_SYMBOL(st_sensors_power_disable);
+
 static int st_sensors_set_drdy_int_pin(struct iio_dev *indio_dev,
 				       struct st_sensors_platform_data *pdata)
 {
diff --git a/drivers/iio/gyro/st_gyro_core.c b/drivers/iio/gyro/st_gyro_core.c
index bc71f4d1e2ce..ed74a9069989 100644
--- a/drivers/iio/gyro/st_gyro_core.c
+++ b/drivers/iio/gyro/st_gyro_core.c
@@ -311,6 +311,8 @@ int st_gyro_common_probe(struct iio_dev *indio_dev,
 	indio_dev->modes = INDIO_DIRECT_MODE;
 	indio_dev->info = &gyro_info;
 
+	st_sensors_power_enable(indio_dev);
+
 	err = st_sensors_check_device_support(indio_dev,
 				ARRAY_SIZE(st_gyro_sensors), st_gyro_sensors);
 	if (err < 0)
@@ -363,6 +365,8 @@ void st_gyro_common_remove(struct iio_dev *indio_dev)
 {
 	struct st_sensor_data *gdata = iio_priv(indio_dev);
 
+	st_sensors_power_disable(indio_dev);
+
 	iio_device_unregister(indio_dev);
 	if (gdata->get_irq_data_ready(indio_dev) > 0)
 		st_sensors_deallocate_trigger(indio_dev);
diff --git a/drivers/iio/magnetometer/st_magn_core.c b/drivers/iio/magnetometer/st_magn_core.c
index 8e33a7682d33..240a21dd0c61 100644
--- a/drivers/iio/magnetometer/st_magn_core.c
+++ b/drivers/iio/magnetometer/st_magn_core.c
@@ -355,6 +355,8 @@ int st_magn_common_probe(struct iio_dev *indio_dev,
 	indio_dev->modes = INDIO_DIRECT_MODE;
 	indio_dev->info = &magn_info;
 
+	st_sensors_power_enable(indio_dev);
+
 	err = st_sensors_check_device_support(indio_dev,
 				ARRAY_SIZE(st_magn_sensors), st_magn_sensors);
 	if (err < 0)
@@ -406,6 +408,8 @@ void st_magn_common_remove(struct iio_dev *indio_dev)
 {
 	struct st_sensor_data *mdata = iio_priv(indio_dev);
 
+	st_sensors_power_disable(indio_dev);
+
 	iio_device_unregister(indio_dev);
 	if (mdata->get_irq_data_ready(indio_dev) > 0)
 		st_sensors_deallocate_trigger(indio_dev);
diff --git a/drivers/iio/pressure/st_pressure_core.c b/drivers/iio/pressure/st_pressure_core.c
index 013becbe8f47..cd7e01f3a93b 100644
--- a/drivers/iio/pressure/st_pressure_core.c
+++ b/drivers/iio/pressure/st_pressure_core.c
@@ -23,7 +23,6 @@
 #include <linux/iio/sysfs.h>
 #include <linux/iio/trigger.h>
 #include <linux/iio/buffer.h>
-#include <linux/regulator/consumer.h>
 #include <asm/unaligned.h>
 
 #include <linux/iio/common/st_sensors.h>
@@ -387,40 +386,6 @@ static const struct iio_trigger_ops st_press_trigger_ops = {
 #define ST_PRESS_TRIGGER_OPS NULL
 #endif
 
-static void st_press_power_enable(struct iio_dev *indio_dev)
-{
-	struct st_sensor_data *pdata = iio_priv(indio_dev);
-	int err;
-
-	/* Regulators not mandatory, but if requested we should enable them. */
-	pdata->vdd = devm_regulator_get_optional(&indio_dev->dev, "vdd");
-	if (!IS_ERR(pdata->vdd)) {
-		err = regulator_enable(pdata->vdd);
-		if (err != 0)
-			dev_warn(&indio_dev->dev,
-				 "Failed to enable specified Vdd supply\n");
-	}
-
-	pdata->vdd_io = devm_regulator_get_optional(&indio_dev->dev, "vddio");
-	if (!IS_ERR(pdata->vdd_io)) {
-		err = regulator_enable(pdata->vdd_io);
-		if (err != 0)
-			dev_warn(&indio_dev->dev,
-				 "Failed to enable specified Vdd_IO supply\n");
-	}
-}
-
-static void st_press_power_disable(struct iio_dev *indio_dev)
-{
-	struct st_sensor_data *pdata = iio_priv(indio_dev);
-
-	if (!IS_ERR(pdata->vdd))
-		regulator_disable(pdata->vdd);
-
-	if (!IS_ERR(pdata->vdd_io))
-		regulator_disable(pdata->vdd_io);
-}
-
 int st_press_common_probe(struct iio_dev *indio_dev,
 				struct st_sensors_platform_data *plat_data)
 {
@@ -431,7 +396,7 @@ int st_press_common_probe(struct iio_dev *indio_dev,
 	indio_dev->modes = INDIO_DIRECT_MODE;
 	indio_dev->info = &press_info;
 
-	st_press_power_enable(indio_dev);
+	st_sensors_power_enable(indio_dev);
 
 	err = st_sensors_check_device_support(indio_dev,
 					      ARRAY_SIZE(st_press_sensors),
@@ -493,7 +458,7 @@ void st_press_common_remove(struct iio_dev *indio_dev)
 {
 	struct st_sensor_data *pdata = iio_priv(indio_dev);
 
-	st_press_power_disable(indio_dev);
+	st_sensors_power_disable(indio_dev);
 
 	iio_device_unregister(indio_dev);
 	if (pdata->get_irq_data_ready(indio_dev) > 0)
diff --git a/include/linux/iio/common/st_sensors.h b/include/linux/iio/common/st_sensors.h
index 3c005eb3a0a4..96f51f0e0096 100644
--- a/include/linux/iio/common/st_sensors.h
+++ b/include/linux/iio/common/st_sensors.h
@@ -269,6 +269,10 @@ int st_sensors_set_enable(struct iio_dev *indio_dev, bool enable);
 
 int st_sensors_set_axis_enable(struct iio_dev *indio_dev, u8 axis_enable);
 
+void st_sensors_power_enable(struct iio_dev *indio_dev);
+
+void st_sensors_power_disable(struct iio_dev *indio_dev);
+
 int st_sensors_set_odr(struct iio_dev *indio_dev, unsigned int odr);
 
 int st_sensors_set_dataready_irq(struct iio_dev *indio_dev, bool enable);
-- 
1.9.0


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

* [PATCH 3/6] iio: st_sensors: get platform data from device tree
  2014-04-13 19:08 [PATCH 0/6] iio: enable ST Sensors on Ux500 Linus Walleij
  2014-04-13 19:08 ` [PATCH 1/6] iio: st_sensors: announce registered sensors Linus Walleij
  2014-04-13 19:08 ` [PATCH 2/6] iio: st_sensors: move regulator retrieveal to core Linus Walleij
@ 2014-04-13 19:09 ` Linus Walleij
  2014-04-26 10:56   ` Jonathan Cameron
  2014-04-13 19:09 ` [PATCH 4/6] iio: st_sensors: add device tree bindings Linus Walleij
                   ` (2 subsequent siblings)
  5 siblings, 1 reply; 15+ messages in thread
From: Linus Walleij @ 2014-04-13 19:09 UTC (permalink / raw)
  To: Jonathan Cameron, linux-iio, Denis CIOCCA; +Cc: Lee Jones, Linus Walleij

Currently the STMicroelectronics sensors only support one single
platform data item: configuration of the DRDY (data ready) pin
for a particular design. Augment the core to prioritize and take
this information from the device tree if the parent device has an
assigned device node, else fall back to passed in platform data
(usually the default data).

Cc: Lee Jones <lee.jones@linaro.org>
Cc: Denis CIOCCA <denis.ciocca@st.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 drivers/iio/common/st_sensors/st_sensors_core.c | 35 ++++++++++++++++++++++++-
 1 file changed, 34 insertions(+), 1 deletion(-)

diff --git a/drivers/iio/common/st_sensors/st_sensors_core.c b/drivers/iio/common/st_sensors/st_sensors_core.c
index e8b932fed70e..1cdcef94e6a2 100644
--- a/drivers/iio/common/st_sensors/st_sensors_core.c
+++ b/drivers/iio/common/st_sensors/st_sensors_core.c
@@ -14,8 +14,8 @@
 #include <linux/delay.h>
 #include <linux/iio/iio.h>
 #include <linux/regulator/consumer.h>
+#include <linux/of.h>
 #include <asm/unaligned.h>
-
 #include <linux/iio/common/st_sensors.h>
 
 
@@ -265,14 +265,47 @@ static int st_sensors_set_drdy_int_pin(struct iio_dev *indio_dev,
 	return 0;
 }
 
+#ifdef CONFIG_OF
+static struct st_sensors_platform_data *st_sensors_of_probe(struct device *dev,
+		struct st_sensors_platform_data *defdata)
+{
+	struct st_sensors_platform_data *pdata;
+	struct device_node *np = dev->of_node;
+	u32 val;
+
+	if (!np)
+		return NULL;
+
+	pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
+	if (!of_property_read_u32(np, "st,drdy-int-pin", &val) && (val <= 2))
+		pdata->drdy_int_pin = (u8) val;
+	else
+		pdata->drdy_int_pin = defdata ? defdata->drdy_int_pin : 1;
+
+	return pdata;
+}
+#else
+static struct st_sensors_platform_data *st_sensors_of_probe(struct device *dev,
+		struct st_sensors_platform_data *defdata)
+{
+	return NULL;
+}
+#endif
+
 int st_sensors_init_sensor(struct iio_dev *indio_dev,
 					struct st_sensors_platform_data *pdata)
 {
 	struct st_sensor_data *sdata = iio_priv(indio_dev);
+	struct st_sensors_platform_data *of_pdata;
 	int err = 0;
 
 	mutex_init(&sdata->tb.buf_lock);
 
+	/* If OF/DT pdata exists, it will take precedence of anything else */
+	of_pdata = st_sensors_of_probe(indio_dev->dev.parent, pdata);
+	if (of_pdata)
+		pdata = of_pdata;
+
 	if (pdata)
 		err = st_sensors_set_drdy_int_pin(indio_dev, pdata);
 
-- 
1.9.0


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

* [PATCH 4/6] iio: st_sensors: add device tree bindings
  2014-04-13 19:08 [PATCH 0/6] iio: enable ST Sensors on Ux500 Linus Walleij
                   ` (2 preceding siblings ...)
  2014-04-13 19:09 ` [PATCH 3/6] iio: st_sensors: get platform data from device tree Linus Walleij
@ 2014-04-13 19:09 ` Linus Walleij
  2014-04-13 19:09 ` [PATCH 5/6] iio: st_sensors: add devicetree probing support Linus Walleij
  2014-04-13 19:09 ` [PATCH 6/6] ARM: ux500: add misc sensors to the device trees Linus Walleij
  5 siblings, 0 replies; 15+ messages in thread
From: Linus Walleij @ 2014-04-13 19:09 UTC (permalink / raw)
  To: Jonathan Cameron, linux-iio, Denis CIOCCA
  Cc: Lee Jones, Linus Walleij, devicetree

This adds some basic, simple device tree bindings to the STMicro
MEMS sensor drivers.

Cc: devicetree@vger.kernel.org
Cc: Lee Jones <lee.jones@linaro.org>
Cc: Denis CIOCCA <denis.ciocca@st.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 .../devicetree/bindings/iio/st-sensors.txt         | 54 ++++++++++++++++++++++
 1 file changed, 54 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/st-sensors.txt

diff --git a/Documentation/devicetree/bindings/iio/st-sensors.txt b/Documentation/devicetree/bindings/iio/st-sensors.txt
new file mode 100644
index 000000000000..a7a0a15913ad
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/st-sensors.txt
@@ -0,0 +1,54 @@
+STMicroelectronics MEMS sensors
+
+The STMicroelectronics sensor devices are pretty straight-forward I2C or
+SPI devices, all sharing the same device tree descriptions no matter what
+type of sensor it is.
+
+Required properties:
+- compatible: see the list of valid compatible strings below
+- reg: the I2C or SPI address the device will respond to
+
+Optional properties:
+- vdd-supply: an optional regulator that needs to be on to provide VDD
+  power to the sensor.
+- vddio-supply: an optional regulator that needs to be on to provide the
+  VDD IO power to the sensor.
+- st,drdy-int-pin: the pin on the package that will be used to signal
+  "data ready" (valid values: 1 or 2). This property is not configurable
+  on all sensors.
+
+Sensors may also have applicable pin control settings, those use the
+standard bindings from pinctrl/pinctrl-bindings.txt.
+
+Valid compatible strings:
+
+Accelerometers:
+- st,lsm303dlh-accel
+- st,lsm303dlhc-accel
+- st,lis3dh-accel
+- st,lsm330d-accel
+- st,lsm330dl-accel
+- st,lsm330dlc-accel
+- st,lis331dlh-accel
+- st,lsm303dl-accel
+- st,lsm303dlm-accel
+- st,lsm330-accel
+
+Gyroscopes:
+- st,l3g4200d-gyro
+- st,lsm330d-gyro
+- st,lsm330dl-gyro
+- st,lsm330dlc-gyro
+- st,l3gd20-gyro
+- st,l3g4is-gyro
+- st,lsm330-gyro
+
+Magnetometers:
+- st,lsm303dlhc-magn
+- st,lsm303dlm-magn
+- st,lis3mdl-magn
+
+Pressure sensors:
+- st,lps001wp-press
+- st,lps25h-press
+- st,lps331ap-press
-- 
1.9.0


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

* [PATCH 5/6] iio: st_sensors: add devicetree probing support
  2014-04-13 19:08 [PATCH 0/6] iio: enable ST Sensors on Ux500 Linus Walleij
                   ` (3 preceding siblings ...)
  2014-04-13 19:09 ` [PATCH 4/6] iio: st_sensors: add device tree bindings Linus Walleij
@ 2014-04-13 19:09 ` Linus Walleij
  2014-04-23 21:19   ` Jonathan Cameron
  2014-04-13 19:09 ` [PATCH 6/6] ARM: ux500: add misc sensors to the device trees Linus Walleij
  5 siblings, 1 reply; 15+ messages in thread
From: Linus Walleij @ 2014-04-13 19:09 UTC (permalink / raw)
  To: Jonathan Cameron, linux-iio, Denis CIOCCA; +Cc: Lee Jones, Linus Walleij

The I2C devices that make up the STMicroelectronics MEMS sensors
may be sneakily enabled by cleverly giving the device node the same
name as a string match from the platform device ID table. However
the right method is to use the compatible string.

On detection, the ST sensors use the ID string to probe and
instatiate the right sensor driver, so pass the kernel-internal ID
string in the .data field of the OF match table, and set the I2C
client name to this name when a compatible match is used.

This avoids having misc Linux-specific strings floating around in
the device tree.

Cc: Lee Jones <lee.jones@linaro.org>
Cc: Denis CIOCCA <denis.ciocca@st.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 drivers/iio/accel/st_accel.h                   | 47 ++++++++++++++++++++++++++
 drivers/iio/accel/st_accel_i2c.c               |  2 ++
 drivers/iio/common/st_sensors/st_sensors_i2c.c | 29 ++++++++++++++++
 drivers/iio/gyro/st_gyro.h                     | 35 +++++++++++++++++++
 drivers/iio/gyro/st_gyro_i2c.c                 |  2 ++
 drivers/iio/magnetometer/st_magn.h             | 19 +++++++++++
 drivers/iio/magnetometer/st_magn_i2c.c         |  2 ++
 drivers/iio/pressure/st_pressure.h             | 19 +++++++++++
 drivers/iio/pressure/st_pressure_i2c.c         |  2 ++
 include/linux/iio/common/st_sensors_i2c.h      | 11 ++++++
 10 files changed, 168 insertions(+)

diff --git a/drivers/iio/accel/st_accel.h b/drivers/iio/accel/st_accel.h
index c3877630b2e4..42e1069c869f 100644
--- a/drivers/iio/accel/st_accel.h
+++ b/drivers/iio/accel/st_accel.h
@@ -25,6 +25,53 @@
 #define LSM303DLM_ACCEL_DEV_NAME	"lsm303dlm_accel"
 #define LSM330_ACCEL_DEV_NAME		"lsm330_accel"
 
+#ifdef CONFIG_OF
+static const struct of_device_id st_accel_of_match[] = {
+	{
+		.compatible = "st,lsm303dlh-accel",
+		.data = LSM303DLH_ACCEL_DEV_NAME,
+	},
+	{
+		.compatible = "st,lsm303dlhc-accel",
+		.data = LSM303DLHC_ACCEL_DEV_NAME,
+	},
+	{
+		.compatible = "st,lis3dh-accel",
+		.data = LIS3DH_ACCEL_DEV_NAME,
+	},
+	{
+		.compatible = "st,lsm330d-accel",
+		.data = LSM330D_ACCEL_DEV_NAME,
+	},
+	{
+		.compatible = "st,lsm330dl-accel",
+		.data = LSM330DL_ACCEL_DEV_NAME,
+	},
+	{
+		.compatible = "st,lsm330dlc-accel",
+		.data = LSM330DLC_ACCEL_DEV_NAME,
+	},
+	{
+		.compatible = "st,lis331dlh-accel",
+		.data = LIS331DLH_ACCEL_DEV_NAME,
+	},
+	{
+		.compatible = "st,lsm303dl-accel",
+		.data = LSM303DL_ACCEL_DEV_NAME,
+	},
+	{
+		.compatible = "st,lsm303dlm-accel",
+		.data = LSM303DLM_ACCEL_DEV_NAME,
+	},
+	{
+		.compatible = "st,lsm330-accel",
+		.data = LSM330_ACCEL_DEV_NAME,
+	},
+	{},
+};
+MODULE_DEVICE_TABLE(of, st_accel_of_match);
+#endif
+
 /**
 * struct st_sensors_platform_data - default accel platform data
 * @drdy_int_pin: default accel DRDY is available on INT1 pin.
diff --git a/drivers/iio/accel/st_accel_i2c.c b/drivers/iio/accel/st_accel_i2c.c
index d7bedbdfc81d..05f7e14ce14f 100644
--- a/drivers/iio/accel/st_accel_i2c.c
+++ b/drivers/iio/accel/st_accel_i2c.c
@@ -31,6 +31,7 @@ static int st_accel_i2c_probe(struct i2c_client *client,
 
 	adata = iio_priv(indio_dev);
 	adata->dev = &client->dev;
+	st_sensors_of_i2c_probe(client, st_accel_of_match);
 
 	st_sensors_i2c_configure(indio_dev, client, adata);
 
@@ -67,6 +68,7 @@ static struct i2c_driver st_accel_driver = {
 	.driver = {
 		.owner = THIS_MODULE,
 		.name = "st-accel-i2c",
+		.of_match_table = of_match_ptr(st_accel_of_match),
 	},
 	.probe = st_accel_i2c_probe,
 	.remove = st_accel_i2c_remove,
diff --git a/drivers/iio/common/st_sensors/st_sensors_i2c.c b/drivers/iio/common/st_sensors/st_sensors_i2c.c
index 38af9440c103..12246e9529ef 100644
--- a/drivers/iio/common/st_sensors/st_sensors_i2c.c
+++ b/drivers/iio/common/st_sensors/st_sensors_i2c.c
@@ -12,6 +12,7 @@
 #include <linux/module.h>
 #include <linux/slab.h>
 #include <linux/iio/iio.h>
+#include <linux/of_device.h>
 
 #include <linux/iio/common/st_sensors_i2c.h>
 
@@ -76,6 +77,34 @@ void st_sensors_i2c_configure(struct iio_dev *indio_dev,
 }
 EXPORT_SYMBOL(st_sensors_i2c_configure);
 
+#ifdef CONFIG_OF
+/**
+ * st_sensors_of_i2c_probe() - device tree probe for ST I2C sensors
+ * @client: the I2C client device for the sensor
+ * @match: the OF match table for the device, containing compatible strings
+ *	but also a .data field with the corresponding internal kernel name
+ *	used by this sensor.
+ *
+ * In effect this function matches a compatible string to an internal kernel
+ * name for a certain sensor device, so that the rest of the autodetection can
+ * rely on that name from this point on. I2C client devices will be renamed
+ * to match the internal kernel convention.
+ */
+void st_sensors_of_i2c_probe(struct i2c_client *client,
+			     const struct of_device_id *match)
+{
+	const struct of_device_id *of_id;
+
+	of_id = of_match_device(match, &client->dev);
+	if (!of_id)
+		return;
+
+	/* The name from the OF match takes precedence if present */
+	strncpy(client->name, of_id->data, sizeof(client->name));
+	client->name[sizeof(client->name) - 1] = '\0';
+}
+#endif
+
 MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
 MODULE_DESCRIPTION("STMicroelectronics ST-sensors i2c driver");
 MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/gyro/st_gyro.h b/drivers/iio/gyro/st_gyro.h
index c197360c450b..f27ccd02d82a 100644
--- a/drivers/iio/gyro/st_gyro.h
+++ b/drivers/iio/gyro/st_gyro.h
@@ -22,6 +22,41 @@
 #define L3G4IS_GYRO_DEV_NAME		"l3g4is_ui"
 #define LSM330_GYRO_DEV_NAME		"lsm330_gyro"
 
+#ifdef CONFIG_OF
+static const struct of_device_id st_gyro_of_match[] = {
+	{
+		.compatible = "st,l3g4200d-gyro",
+		.data = L3G4200D_GYRO_DEV_NAME,
+	},
+	{
+		.compatible = "st,lsm330d-gyro",
+		.data = LSM330D_GYRO_DEV_NAME,
+	},
+	{
+		.compatible = "st,lsm330dl-gyro",
+		.data = LSM330DL_GYRO_DEV_NAME,
+	},
+	{
+		.compatible = "st,lsm330dlc-gyro",
+		.data = LSM330DLC_GYRO_DEV_NAME,
+	},
+	{
+		.compatible = "st,l3gd20-gyro",
+		.data = L3GD20_GYRO_DEV_NAME,
+	},
+	{
+		.compatible = "st,l3g4is-gyro",
+		.data = L3G4IS_GYRO_DEV_NAME,
+	},
+	{
+		.compatible = "st,lsm330-gyro",
+		.data = LSM330_GYRO_DEV_NAME,
+	},
+	{},
+};
+MODULE_DEVICE_TABLE(of, st_gyro_of_match);
+#endif
+
 /**
  * struct st_sensors_platform_data - gyro platform data
  * @drdy_int_pin: DRDY on gyros is available only on INT2 pin.
diff --git a/drivers/iio/gyro/st_gyro_i2c.c b/drivers/iio/gyro/st_gyro_i2c.c
index 23c12f361b05..889f5dfa4a1a 100644
--- a/drivers/iio/gyro/st_gyro_i2c.c
+++ b/drivers/iio/gyro/st_gyro_i2c.c
@@ -31,6 +31,7 @@ static int st_gyro_i2c_probe(struct i2c_client *client,
 
 	gdata = iio_priv(indio_dev);
 	gdata->dev = &client->dev;
+	st_sensors_of_i2c_probe(client, st_gyro_of_match);
 
 	st_sensors_i2c_configure(indio_dev, client, gdata);
 
@@ -65,6 +66,7 @@ static struct i2c_driver st_gyro_driver = {
 	.driver = {
 		.owner = THIS_MODULE,
 		.name = "st-gyro-i2c",
+		.of_match_table = of_match_ptr(st_gyro_of_match),
 	},
 	.probe = st_gyro_i2c_probe,
 	.remove = st_gyro_i2c_remove,
diff --git a/drivers/iio/magnetometer/st_magn.h b/drivers/iio/magnetometer/st_magn.h
index 694e33e0fb72..557f5f232a6e 100644
--- a/drivers/iio/magnetometer/st_magn.h
+++ b/drivers/iio/magnetometer/st_magn.h
@@ -18,6 +18,25 @@
 #define LSM303DLM_MAGN_DEV_NAME		"lsm303dlm_magn"
 #define LIS3MDL_MAGN_DEV_NAME		"lis3mdl"
 
+#ifdef CONFIG_OF
+static const struct of_device_id st_magn_of_match[] = {
+	{
+		.compatible = "st,lsm303dlhc-magn",
+		.data = LSM303DLHC_MAGN_DEV_NAME,
+	},
+	{
+		.compatible = "st,lsm303dlm-magn",
+		.data = LSM303DLM_MAGN_DEV_NAME,
+	},
+	{
+		.compatible = "st,lis3mdl-magn",
+		.data = LIS3MDL_MAGN_DEV_NAME,
+	},
+	{},
+};
+MODULE_DEVICE_TABLE(of, st_magn_of_match);
+#endif
+
 int st_magn_common_probe(struct iio_dev *indio_dev,
 					struct st_sensors_platform_data *pdata);
 void st_magn_common_remove(struct iio_dev *indio_dev);
diff --git a/drivers/iio/magnetometer/st_magn_i2c.c b/drivers/iio/magnetometer/st_magn_i2c.c
index 892e0feeb5c1..88a525ed7926 100644
--- a/drivers/iio/magnetometer/st_magn_i2c.c
+++ b/drivers/iio/magnetometer/st_magn_i2c.c
@@ -31,6 +31,7 @@ static int st_magn_i2c_probe(struct i2c_client *client,
 
 	mdata = iio_priv(indio_dev);
 	mdata->dev = &client->dev;
+	st_sensors_of_i2c_probe(client, st_magn_of_match);
 
 	st_sensors_i2c_configure(indio_dev, client, mdata);
 
@@ -61,6 +62,7 @@ static struct i2c_driver st_magn_driver = {
 	.driver = {
 		.owner = THIS_MODULE,
 		.name = "st-magn-i2c",
+		.of_match_table = of_match_ptr(st_magn_of_match),
 	},
 	.probe = st_magn_i2c_probe,
 	.remove = st_magn_i2c_remove,
diff --git a/drivers/iio/pressure/st_pressure.h b/drivers/iio/pressure/st_pressure.h
index 242943c0c4e4..01648734e571 100644
--- a/drivers/iio/pressure/st_pressure.h
+++ b/drivers/iio/pressure/st_pressure.h
@@ -18,6 +18,25 @@
 #define LPS25H_PRESS_DEV_NAME		"lps25h"
 #define LPS331AP_PRESS_DEV_NAME		"lps331ap"
 
+#ifdef CONFIG_OF
+static const struct of_device_id st_press_of_match[] = {
+	{
+		.compatible = "st,lps001wp-press",
+		.data = LPS001WP_PRESS_DEV_NAME,
+	},
+	{
+		.compatible = "st,lps25h-press",
+		.data = LPS25H_PRESS_DEV_NAME,
+	},
+	{
+		.compatible = "st,lps331ap-press",
+		.data = LPS331AP_PRESS_DEV_NAME,
+	},
+	{},
+};
+MODULE_DEVICE_TABLE(of, st_press_of_match);
+#endif
+
 /**
  * struct st_sensors_platform_data - default press platform data
  * @drdy_int_pin: default press DRDY is available on INT1 pin.
diff --git a/drivers/iio/pressure/st_pressure_i2c.c b/drivers/iio/pressure/st_pressure_i2c.c
index 3cd73e39b840..0de0c71a29be 100644
--- a/drivers/iio/pressure/st_pressure_i2c.c
+++ b/drivers/iio/pressure/st_pressure_i2c.c
@@ -31,6 +31,7 @@ static int st_press_i2c_probe(struct i2c_client *client,
 
 	pdata = iio_priv(indio_dev);
 	pdata->dev = &client->dev;
+	st_sensors_of_i2c_probe(client, st_press_of_match);
 
 	st_sensors_i2c_configure(indio_dev, client, pdata);
 
@@ -60,6 +61,7 @@ static struct i2c_driver st_press_driver = {
 	.driver = {
 		.owner = THIS_MODULE,
 		.name = "st-press-i2c",
+		.of_match_table = of_match_ptr(st_press_of_match),
 	},
 	.probe = st_press_i2c_probe,
 	.remove = st_press_i2c_remove,
diff --git a/include/linux/iio/common/st_sensors_i2c.h b/include/linux/iio/common/st_sensors_i2c.h
index 67d845385ae2..1796af093368 100644
--- a/include/linux/iio/common/st_sensors_i2c.h
+++ b/include/linux/iio/common/st_sensors_i2c.h
@@ -13,8 +13,19 @@
 
 #include <linux/i2c.h>
 #include <linux/iio/common/st_sensors.h>
+#include <linux/of.h>
 
 void st_sensors_i2c_configure(struct iio_dev *indio_dev,
 		struct i2c_client *client, struct st_sensor_data *sdata);
 
+#ifdef CONFIG_OF
+void st_sensors_of_i2c_probe(struct i2c_client *client,
+			     const struct of_device_id *match);
+#else
+static inline void st_sensors_of_i2c_probe(struct i2c_client *client,
+					   const struct of_device_id *match)
+{
+}
+#endif
+
 #endif /* ST_SENSORS_I2C_H */
-- 
1.9.0


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

* [PATCH 6/6] ARM: ux500: add misc sensors to the device trees
  2014-04-13 19:08 [PATCH 0/6] iio: enable ST Sensors on Ux500 Linus Walleij
                   ` (4 preceding siblings ...)
  2014-04-13 19:09 ` [PATCH 5/6] iio: st_sensors: add devicetree probing support Linus Walleij
@ 2014-04-13 19:09 ` Linus Walleij
  5 siblings, 0 replies; 15+ messages in thread
From: Linus Walleij @ 2014-04-13 19:09 UTC (permalink / raw)
  To: Jonathan Cameron, linux-iio, Denis CIOCCA; +Cc: Lee Jones, Linus Walleij

This adds the STMicroelectonics MEMS sensor devices to the Ux500
family device trees:

- Accelerometer
- Magnetometer
- Gyroscope
- Pressure (barometer)

Cc: Lee Jones <lee.jones@linaro.org>
Cc: Denis CIOCCA <denis.ciocca@st.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 arch/arm/boot/dts/ste-href.dtsi        | 30 +++++++++++++++++++++++++++
 arch/arm/boot/dts/ste-hrefv60plus.dtsi | 15 ++++++++++++--
 arch/arm/boot/dts/ste-snowball.dts     | 38 +++++++++++++++++++++++++++++++---
 3 files changed, 78 insertions(+), 5 deletions(-)

diff --git a/arch/arm/boot/dts/ste-href.dtsi b/arch/arm/boot/dts/ste-href.dtsi
index 6cb9b68e2188..fe64c472931c 100644
--- a/arch/arm/boot/dts/ste-href.dtsi
+++ b/arch/arm/boot/dts/ste-href.dtsi
@@ -103,6 +103,36 @@
 				compatible = "rohm,bh1780gli";
 				reg = <0x29>;
 			};
+			lsm303dlh@18 {
+				/* Accelerometer */
+				compatible = "st,lsm303dlh-accel";
+				st,drdy-int-pin = <1>;
+				reg = <0x18>;
+				vdd-supply = <&ab8500_ldo_aux1_reg>;
+				vddio-supply = <&db8500_vsmps2_reg>;
+			};
+			lsm303dlm@1e {
+				/* Magnetometer */
+				compatible = "st,lsm303dlm-magn";
+				reg = <0x1e>;
+				vdd-supply = <&ab8500_ldo_aux1_reg>;
+				vddio-supply = <&db8500_vsmps2_reg>;
+			};
+			l3g4200d@68 {
+				/* Gyroscope */
+				compatible = "st,l3g4200d-gyro";
+				st,drdy-int-pin = <2>;
+				reg = <0x68>;
+				vdd-supply = <&ab8500_ldo_aux1_reg>;
+				vddio-supply = <&db8500_vsmps2_reg>;
+			};
+			lsp001wm@5c {
+				/* Barometer/pressure sensor */
+				compatible = "st,lps001wp-press";
+				reg = <0x5c>;
+				vdd-supply = <&ab8500_ldo_aux1_reg>;
+				vddio-supply = <&db8500_vsmps2_reg>;
+			};
 		};
 
 		i2c@80110000 {
diff --git a/arch/arm/boot/dts/ste-hrefv60plus.dtsi b/arch/arm/boot/dts/ste-hrefv60plus.dtsi
index c2341061b943..e912d422b99e 100644
--- a/arch/arm/boot/dts/ste-hrefv60plus.dtsi
+++ b/arch/arm/boot/dts/ste-hrefv60plus.dtsi
@@ -35,8 +35,6 @@
 			 */
 			pinctrl-names = "default";
 			pinctrl-0 = <&ipgpio_hrefv60_mode>,
-				  <&accel_hrefv60_mode>,
-				  <&magneto_hrefv60_mode>,
 				  <&etm_hrefv60_mode>,
 				  <&nahj_hrefv60_mode>,
 				  <&nfc_hrefv60_mode>,
@@ -238,5 +236,18 @@
 				};
 			};
 		};
+
+		i2c@80128000 {
+			lsm303dlh@18 {
+				/* Pins for the accelerometer */
+				pinctrl-names = "default";
+				pinctrl-0 = <&accel_hrefv60_mode>;
+			};
+			lsm303dlm@1e {
+				/* Pins for the magnetometer */
+				pinctrl-names = "default";
+				pinctrl-0 = <&magneto_hrefv60_mode>;
+			};
+		};
 	};
 };
diff --git a/arch/arm/boot/dts/ste-snowball.dts b/arch/arm/boot/dts/ste-snowball.dts
index a2f632d0be2a..cc1abc063b4b 100644
--- a/arch/arm/boot/dts/ste-snowball.dts
+++ b/arch/arm/boot/dts/ste-snowball.dts
@@ -241,6 +241,40 @@
 			pinctrl-names = "default","sleep";
 			pinctrl-0 = <&i2c2_default_mode>;
 			pinctrl-1 = <&i2c2_sleep_mode>;
+			lsm303dlh@18 {
+				/* Accelerometer */
+				compatible = "st,lsm303dlh-accel";
+				st,drdy-int-pin = <1>;
+				reg = <0x18>;
+				vdd-supply = <&ab8500_ldo_aux1_reg>;
+				vddio-supply = <&db8500_vsmps2_reg>;
+				pinctrl-names = "default";
+				pinctrl-0 = <&accel_snowball_mode>;
+			};
+			lsm303dlm@1e {
+				/* Magnetometer */
+				compatible = "st,lsm303dlm-magn";
+				reg = <0x1e>;
+				vdd-supply = <&ab8500_ldo_aux1_reg>;
+				vddio-supply = <&db8500_vsmps2_reg>;
+				pinctrl-names = "default";
+				pinctrl-0 = <&magneto_snowball_mode>;
+			};
+			l3g4200d@68 {
+				/* Gyroscope */
+				compatible = "st,l3g4200d-gyro";
+				st,drdy-int-pin = <2>;
+				reg = <0x68>;
+				vdd-supply = <&ab8500_ldo_aux1_reg>;
+				vddio-supply = <&db8500_vsmps2_reg>;
+			};
+			lsp001wm@5c {
+				/* Barometer/pressure sensor */
+				compatible = "st,lps001wp-press";
+				reg = <0x5c>;
+				vdd-supply = <&ab8500_ldo_aux1_reg>;
+				vddio-supply = <&db8500_vsmps2_reg>;
+			};
 		};
 
 		i2c@80110000 {
@@ -361,9 +395,7 @@
 			 * can be moved over to being controlled by respective device.
 			 */
 			pinctrl-names = "default";
-			pinctrl-0 = <&accel_snowball_mode>,
-				  <&magneto_snowball_mode>,
-				  <&gbf_snowball_mode>,
+			pinctrl-0 = <&gbf_snowball_mode>,
 				  <&wlan_snowball_mode>;
 
 			ethernet {
-- 
1.9.0


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

* Re: [PATCH 5/6] iio: st_sensors: add devicetree probing support
  2014-04-13 19:09 ` [PATCH 5/6] iio: st_sensors: add devicetree probing support Linus Walleij
@ 2014-04-23 21:19   ` Jonathan Cameron
  2014-04-24  8:33     ` Linus Walleij
  0 siblings, 1 reply; 15+ messages in thread
From: Jonathan Cameron @ 2014-04-23 21:19 UTC (permalink / raw)
  To: Linus Walleij, linux-iio, Denis CIOCCA; +Cc: Lee Jones

On 13/04/14 20:09, Linus Walleij wrote:
> The I2C devices that make up the STMicroelectronics MEMS sensors
> may be sneakily enabled by cleverly giving the device node the same
> name as a string match from the platform device ID table. However
> the right method is to use the compatible string.
>
> On detection, the ST sensors use the ID string to probe and
> instatiate the right sensor driver, so pass the kernel-internal ID
> string in the .data field of the OF match table, and set the I2C
> client name to this name when a compatible match is used.
>
> This avoids having misc Linux-specific strings floating around in
> the device tree.
I can't make up my mind whether I like this or not.
Having said that it fixes an ABI compatibility issue that I couldn't
see a way around so nicely done.

(note I'll leave this set be for now given the device tree element
and that it hasn't been 3 weeks yet)
>
> Cc: Lee Jones <lee.jones@linaro.org>
> Cc: Denis CIOCCA <denis.ciocca@st.com>
> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
> ---
>   drivers/iio/accel/st_accel.h                   | 47 ++++++++++++++++++++++++++
>   drivers/iio/accel/st_accel_i2c.c               |  2 ++
>   drivers/iio/common/st_sensors/st_sensors_i2c.c | 29 ++++++++++++++++
>   drivers/iio/gyro/st_gyro.h                     | 35 +++++++++++++++++++
>   drivers/iio/gyro/st_gyro_i2c.c                 |  2 ++
>   drivers/iio/magnetometer/st_magn.h             | 19 +++++++++++
>   drivers/iio/magnetometer/st_magn_i2c.c         |  2 ++
>   drivers/iio/pressure/st_pressure.h             | 19 +++++++++++
>   drivers/iio/pressure/st_pressure_i2c.c         |  2 ++
>   include/linux/iio/common/st_sensors_i2c.h      | 11 ++++++
>   10 files changed, 168 insertions(+)
>
> diff --git a/drivers/iio/accel/st_accel.h b/drivers/iio/accel/st_accel.h
> index c3877630b2e4..42e1069c869f 100644
> --- a/drivers/iio/accel/st_accel.h
> +++ b/drivers/iio/accel/st_accel.h
> @@ -25,6 +25,53 @@
>   #define LSM303DLM_ACCEL_DEV_NAME	"lsm303dlm_accel"
>   #define LSM330_ACCEL_DEV_NAME		"lsm330_accel"
>
> +#ifdef CONFIG_OF
> +static const struct of_device_id st_accel_of_match[] = {
> +	{
> +		.compatible = "st,lsm303dlh-accel",
> +		.data = LSM303DLH_ACCEL_DEV_NAME,
> +	},
> +	{
> +		.compatible = "st,lsm303dlhc-accel",
> +		.data = LSM303DLHC_ACCEL_DEV_NAME,
> +	},
> +	{
> +		.compatible = "st,lis3dh-accel",
> +		.data = LIS3DH_ACCEL_DEV_NAME,
> +	},
> +	{
> +		.compatible = "st,lsm330d-accel",
> +		.data = LSM330D_ACCEL_DEV_NAME,
> +	},
> +	{
> +		.compatible = "st,lsm330dl-accel",
> +		.data = LSM330DL_ACCEL_DEV_NAME,
> +	},
> +	{
> +		.compatible = "st,lsm330dlc-accel",
> +		.data = LSM330DLC_ACCEL_DEV_NAME,
> +	},
> +	{
> +		.compatible = "st,lis331dlh-accel",
> +		.data = LIS331DLH_ACCEL_DEV_NAME,
> +	},
> +	{
> +		.compatible = "st,lsm303dl-accel",
> +		.data = LSM303DL_ACCEL_DEV_NAME,
> +	},
> +	{
> +		.compatible = "st,lsm303dlm-accel",
> +		.data = LSM303DLM_ACCEL_DEV_NAME,
> +	},
> +	{
> +		.compatible = "st,lsm330-accel",
> +		.data = LSM330_ACCEL_DEV_NAME,
> +	},
> +	{},
> +};
> +MODULE_DEVICE_TABLE(of, st_accel_of_match);
> +#endif
> +
>   /**
>   * struct st_sensors_platform_data - default accel platform data
>   * @drdy_int_pin: default accel DRDY is available on INT1 pin.
> diff --git a/drivers/iio/accel/st_accel_i2c.c b/drivers/iio/accel/st_accel_i2c.c
> index d7bedbdfc81d..05f7e14ce14f 100644
> --- a/drivers/iio/accel/st_accel_i2c.c
> +++ b/drivers/iio/accel/st_accel_i2c.c
> @@ -31,6 +31,7 @@ static int st_accel_i2c_probe(struct i2c_client *client,
>
>   	adata = iio_priv(indio_dev);
>   	adata->dev = &client->dev;
> +	st_sensors_of_i2c_probe(client, st_accel_of_match);
>
>   	st_sensors_i2c_configure(indio_dev, client, adata);
>
> @@ -67,6 +68,7 @@ static struct i2c_driver st_accel_driver = {
>   	.driver = {
>   		.owner = THIS_MODULE,
>   		.name = "st-accel-i2c",
> +		.of_match_table = of_match_ptr(st_accel_of_match),
>   	},
>   	.probe = st_accel_i2c_probe,
>   	.remove = st_accel_i2c_remove,
> diff --git a/drivers/iio/common/st_sensors/st_sensors_i2c.c b/drivers/iio/common/st_sensors/st_sensors_i2c.c
> index 38af9440c103..12246e9529ef 100644
> --- a/drivers/iio/common/st_sensors/st_sensors_i2c.c
> +++ b/drivers/iio/common/st_sensors/st_sensors_i2c.c
> @@ -12,6 +12,7 @@
>   #include <linux/module.h>
>   #include <linux/slab.h>
>   #include <linux/iio/iio.h>
> +#include <linux/of_device.h>
>
>   #include <linux/iio/common/st_sensors_i2c.h>
>
> @@ -76,6 +77,34 @@ void st_sensors_i2c_configure(struct iio_dev *indio_dev,
>   }
>   EXPORT_SYMBOL(st_sensors_i2c_configure);
>
> +#ifdef CONFIG_OF
> +/**
> + * st_sensors_of_i2c_probe() - device tree probe for ST I2C sensors
> + * @client: the I2C client device for the sensor
> + * @match: the OF match table for the device, containing compatible strings
> + *	but also a .data field with the corresponding internal kernel name
> + *	used by this sensor.
> + *
> + * In effect this function matches a compatible string to an internal kernel
> + * name for a certain sensor device, so that the rest of the autodetection can
> + * rely on that name from this point on. I2C client devices will be renamed
> + * to match the internal kernel convention.
> + */
> +void st_sensors_of_i2c_probe(struct i2c_client *client,
> +			     const struct of_device_id *match)
> +{
> +	const struct of_device_id *of_id;
> +
> +	of_id = of_match_device(match, &client->dev);
> +	if (!of_id)
> +		return;
> +
> +	/* The name from the OF match takes precedence if present */
> +	strncpy(client->name, of_id->data, sizeof(client->name));
> +	client->name[sizeof(client->name) - 1] = '\0';
> +}
> +#endif
> +
>   MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
>   MODULE_DESCRIPTION("STMicroelectronics ST-sensors i2c driver");
>   MODULE_LICENSE("GPL v2");
> diff --git a/drivers/iio/gyro/st_gyro.h b/drivers/iio/gyro/st_gyro.h
> index c197360c450b..f27ccd02d82a 100644
> --- a/drivers/iio/gyro/st_gyro.h
> +++ b/drivers/iio/gyro/st_gyro.h
> @@ -22,6 +22,41 @@
>   #define L3G4IS_GYRO_DEV_NAME		"l3g4is_ui"
>   #define LSM330_GYRO_DEV_NAME		"lsm330_gyro"
>
> +#ifdef CONFIG_OF
> +static const struct of_device_id st_gyro_of_match[] = {
> +	{
> +		.compatible = "st,l3g4200d-gyro",
> +		.data = L3G4200D_GYRO_DEV_NAME,
> +	},
> +	{
> +		.compatible = "st,lsm330d-gyro",
> +		.data = LSM330D_GYRO_DEV_NAME,
> +	},
> +	{
> +		.compatible = "st,lsm330dl-gyro",
> +		.data = LSM330DL_GYRO_DEV_NAME,
> +	},
> +	{
> +		.compatible = "st,lsm330dlc-gyro",
> +		.data = LSM330DLC_GYRO_DEV_NAME,
> +	},
> +	{
> +		.compatible = "st,l3gd20-gyro",
> +		.data = L3GD20_GYRO_DEV_NAME,
> +	},
> +	{
> +		.compatible = "st,l3g4is-gyro",
> +		.data = L3G4IS_GYRO_DEV_NAME,
> +	},
> +	{
> +		.compatible = "st,lsm330-gyro",
> +		.data = LSM330_GYRO_DEV_NAME,
> +	},
> +	{},
> +};
> +MODULE_DEVICE_TABLE(of, st_gyro_of_match);
> +#endif
> +
>   /**
>    * struct st_sensors_platform_data - gyro platform data
>    * @drdy_int_pin: DRDY on gyros is available only on INT2 pin.
> diff --git a/drivers/iio/gyro/st_gyro_i2c.c b/drivers/iio/gyro/st_gyro_i2c.c
> index 23c12f361b05..889f5dfa4a1a 100644
> --- a/drivers/iio/gyro/st_gyro_i2c.c
> +++ b/drivers/iio/gyro/st_gyro_i2c.c
> @@ -31,6 +31,7 @@ static int st_gyro_i2c_probe(struct i2c_client *client,
>
>   	gdata = iio_priv(indio_dev);
>   	gdata->dev = &client->dev;
> +	st_sensors_of_i2c_probe(client, st_gyro_of_match);
>
>   	st_sensors_i2c_configure(indio_dev, client, gdata);
>
> @@ -65,6 +66,7 @@ static struct i2c_driver st_gyro_driver = {
>   	.driver = {
>   		.owner = THIS_MODULE,
>   		.name = "st-gyro-i2c",
> +		.of_match_table = of_match_ptr(st_gyro_of_match),
>   	},
>   	.probe = st_gyro_i2c_probe,
>   	.remove = st_gyro_i2c_remove,
> diff --git a/drivers/iio/magnetometer/st_magn.h b/drivers/iio/magnetometer/st_magn.h
> index 694e33e0fb72..557f5f232a6e 100644
> --- a/drivers/iio/magnetometer/st_magn.h
> +++ b/drivers/iio/magnetometer/st_magn.h
> @@ -18,6 +18,25 @@
>   #define LSM303DLM_MAGN_DEV_NAME		"lsm303dlm_magn"
>   #define LIS3MDL_MAGN_DEV_NAME		"lis3mdl"
>
> +#ifdef CONFIG_OF
> +static const struct of_device_id st_magn_of_match[] = {
> +	{
> +		.compatible = "st,lsm303dlhc-magn",
> +		.data = LSM303DLHC_MAGN_DEV_NAME,
> +	},
> +	{
> +		.compatible = "st,lsm303dlm-magn",
> +		.data = LSM303DLM_MAGN_DEV_NAME,
> +	},
> +	{
> +		.compatible = "st,lis3mdl-magn",
> +		.data = LIS3MDL_MAGN_DEV_NAME,
> +	},
> +	{},
> +};
> +MODULE_DEVICE_TABLE(of, st_magn_of_match);
> +#endif
> +
>   int st_magn_common_probe(struct iio_dev *indio_dev,
>   					struct st_sensors_platform_data *pdata);
>   void st_magn_common_remove(struct iio_dev *indio_dev);
> diff --git a/drivers/iio/magnetometer/st_magn_i2c.c b/drivers/iio/magnetometer/st_magn_i2c.c
> index 892e0feeb5c1..88a525ed7926 100644
> --- a/drivers/iio/magnetometer/st_magn_i2c.c
> +++ b/drivers/iio/magnetometer/st_magn_i2c.c
> @@ -31,6 +31,7 @@ static int st_magn_i2c_probe(struct i2c_client *client,
>
>   	mdata = iio_priv(indio_dev);
>   	mdata->dev = &client->dev;
> +	st_sensors_of_i2c_probe(client, st_magn_of_match);
>
>   	st_sensors_i2c_configure(indio_dev, client, mdata);
>
> @@ -61,6 +62,7 @@ static struct i2c_driver st_magn_driver = {
>   	.driver = {
>   		.owner = THIS_MODULE,
>   		.name = "st-magn-i2c",
> +		.of_match_table = of_match_ptr(st_magn_of_match),
>   	},
>   	.probe = st_magn_i2c_probe,
>   	.remove = st_magn_i2c_remove,
> diff --git a/drivers/iio/pressure/st_pressure.h b/drivers/iio/pressure/st_pressure.h
> index 242943c0c4e4..01648734e571 100644
> --- a/drivers/iio/pressure/st_pressure.h
> +++ b/drivers/iio/pressure/st_pressure.h
> @@ -18,6 +18,25 @@
>   #define LPS25H_PRESS_DEV_NAME		"lps25h"
>   #define LPS331AP_PRESS_DEV_NAME		"lps331ap"
>
> +#ifdef CONFIG_OF
> +static const struct of_device_id st_press_of_match[] = {
> +	{
> +		.compatible = "st,lps001wp-press",
> +		.data = LPS001WP_PRESS_DEV_NAME,
> +	},
> +	{
> +		.compatible = "st,lps25h-press",
> +		.data = LPS25H_PRESS_DEV_NAME,
> +	},
> +	{
> +		.compatible = "st,lps331ap-press",
> +		.data = LPS331AP_PRESS_DEV_NAME,
> +	},
> +	{},
> +};
> +MODULE_DEVICE_TABLE(of, st_press_of_match);
> +#endif
> +
>   /**
>    * struct st_sensors_platform_data - default press platform data
>    * @drdy_int_pin: default press DRDY is available on INT1 pin.
> diff --git a/drivers/iio/pressure/st_pressure_i2c.c b/drivers/iio/pressure/st_pressure_i2c.c
> index 3cd73e39b840..0de0c71a29be 100644
> --- a/drivers/iio/pressure/st_pressure_i2c.c
> +++ b/drivers/iio/pressure/st_pressure_i2c.c
> @@ -31,6 +31,7 @@ static int st_press_i2c_probe(struct i2c_client *client,
>
>   	pdata = iio_priv(indio_dev);
>   	pdata->dev = &client->dev;
> +	st_sensors_of_i2c_probe(client, st_press_of_match);
>
>   	st_sensors_i2c_configure(indio_dev, client, pdata);
>
> @@ -60,6 +61,7 @@ static struct i2c_driver st_press_driver = {
>   	.driver = {
>   		.owner = THIS_MODULE,
>   		.name = "st-press-i2c",
> +		.of_match_table = of_match_ptr(st_press_of_match),
>   	},
>   	.probe = st_press_i2c_probe,
>   	.remove = st_press_i2c_remove,
> diff --git a/include/linux/iio/common/st_sensors_i2c.h b/include/linux/iio/common/st_sensors_i2c.h
> index 67d845385ae2..1796af093368 100644
> --- a/include/linux/iio/common/st_sensors_i2c.h
> +++ b/include/linux/iio/common/st_sensors_i2c.h
> @@ -13,8 +13,19 @@
>
>   #include <linux/i2c.h>
>   #include <linux/iio/common/st_sensors.h>
> +#include <linux/of.h>
>
>   void st_sensors_i2c_configure(struct iio_dev *indio_dev,
>   		struct i2c_client *client, struct st_sensor_data *sdata);
>
> +#ifdef CONFIG_OF
> +void st_sensors_of_i2c_probe(struct i2c_client *client,
> +			     const struct of_device_id *match);
> +#else
> +static inline void st_sensors_of_i2c_probe(struct i2c_client *client,
> +					   const struct of_device_id *match)
> +{
> +}
> +#endif
> +
>   #endif /* ST_SENSORS_I2C_H */
>


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

* Re: [PATCH 1/6] iio: st_sensors: announce registered sensors
  2014-04-13 19:08 ` [PATCH 1/6] iio: st_sensors: announce registered sensors Linus Walleij
@ 2014-04-23 21:21   ` Jonathan Cameron
  2014-04-24  8:30     ` Linus Walleij
  0 siblings, 1 reply; 15+ messages in thread
From: Jonathan Cameron @ 2014-04-23 21:21 UTC (permalink / raw)
  To: Linus Walleij, linux-iio, Denis CIOCCA; +Cc: Lee Jones

On 13/04/14 20:08, Linus Walleij wrote:
> It is pretty helpful to know already from dmesg that a certain
> device is successfully registered, instead of having to browse
> sysfs to see if it's actually there.
>
> Cc: Lee Jones <lee.jones@linaro.org>
> Cc: Denis CIOCCA <denis.ciocca@st.com>
> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

hmm.. Normally I get irritated with these sorts of I'm here
messages - it's not exactly hard to tell it has been successfully
probed without filling the logs with messages fairly light on
info.  Having said that I tend to let these go in new drivers
so I don't care that strongly...


> ---
>   drivers/iio/accel/st_accel_core.c       | 3 +++
>   drivers/iio/gyro/st_gyro_core.c         | 3 +++
>   drivers/iio/magnetometer/st_magn_core.c | 3 +++
>   drivers/iio/pressure/st_pressure_core.c | 3 +++
>   4 files changed, 12 insertions(+)
>
> diff --git a/drivers/iio/accel/st_accel_core.c b/drivers/iio/accel/st_accel_core.c
> index 38caedc76b98..4e06fcf5b891 100644
> --- a/drivers/iio/accel/st_accel_core.c
> +++ b/drivers/iio/accel/st_accel_core.c
> @@ -496,6 +496,9 @@ int st_accel_common_probe(struct iio_dev *indio_dev,
>   	if (err)
>   		goto st_accel_device_register_error;
>
> +	dev_info(&indio_dev->dev, "registered accelerometer %s\n",
> +		 indio_dev->name);
> +
>   	return 0;
>
>   st_accel_device_register_error:
> diff --git a/drivers/iio/gyro/st_gyro_core.c b/drivers/iio/gyro/st_gyro_core.c
> index a8e174a47bc4..bc71f4d1e2ce 100644
> --- a/drivers/iio/gyro/st_gyro_core.c
> +++ b/drivers/iio/gyro/st_gyro_core.c
> @@ -344,6 +344,9 @@ int st_gyro_common_probe(struct iio_dev *indio_dev,
>   	if (err)
>   		goto st_gyro_device_register_error;
>
> +	dev_info(&indio_dev->dev, "registered gyroscope %s\n",
> +		 indio_dev->name);
> +
>   	return 0;
>
>   st_gyro_device_register_error:
> diff --git a/drivers/iio/magnetometer/st_magn_core.c b/drivers/iio/magnetometer/st_magn_core.c
> index 52bbcfa1e077..8e33a7682d33 100644
> --- a/drivers/iio/magnetometer/st_magn_core.c
> +++ b/drivers/iio/magnetometer/st_magn_core.c
> @@ -387,6 +387,9 @@ int st_magn_common_probe(struct iio_dev *indio_dev,
>   	if (err)
>   		goto st_magn_device_register_error;
>
> +	dev_info(&indio_dev->dev, "registered magnetometer %s\n",
> +		 indio_dev->name);
> +
>   	return 0;
>
>   st_magn_device_register_error:
> diff --git a/drivers/iio/pressure/st_pressure_core.c b/drivers/iio/pressure/st_pressure_core.c
> index 7418768ed49c..013becbe8f47 100644
> --- a/drivers/iio/pressure/st_pressure_core.c
> +++ b/drivers/iio/pressure/st_pressure_core.c
> @@ -474,6 +474,9 @@ int st_press_common_probe(struct iio_dev *indio_dev,
>   	if (err)
>   		goto st_press_device_register_error;
>
> +	dev_info(&indio_dev->dev, "registered pressure sensor %s\n",
> +		 indio_dev->name);
> +
>   	return err;
>
>   st_press_device_register_error:
>


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

* Re: [PATCH 1/6] iio: st_sensors: announce registered sensors
  2014-04-23 21:21   ` Jonathan Cameron
@ 2014-04-24  8:30     ` Linus Walleij
  2014-04-26 10:51       ` Jonathan Cameron
  0 siblings, 1 reply; 15+ messages in thread
From: Linus Walleij @ 2014-04-24  8:30 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: linux-iio@vger.kernel.org, Denis CIOCCA, Lee Jones

On Wed, Apr 23, 2014 at 11:21 PM, Jonathan Cameron <jic23@kernel.org> wrote:
> On 13/04/14 20:08, Linus Walleij wrote:
>>
>> It is pretty helpful to know already from dmesg that a certain
>> device is successfully registered, instead of having to browse
>> sysfs to see if it's actually there.
>>
>> Cc: Lee Jones <lee.jones@linaro.org>
>> Cc: Denis CIOCCA <denis.ciocca@st.com>
>> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
>
>
> hmm.. Normally I get irritated with these sorts of I'm here
> messages - it's not exactly hard to tell it has been successfully
> probed without filling the logs with messages fairly light on
> info.  Having said that I tend to let these go in new drivers
> so I don't care that strongly...

Your pick, this patch is orthogonal to the rest.

I tend to stick a oneliner at the end of successful probe
to verify that the device driver has been compiled in and
that it probes correctly so that the device tree etc is in
order. Of course there are other ways to determine that
but the dmesg give it all in one place for all devices.

Yours,
Linus Walleij

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

* Re: [PATCH 5/6] iio: st_sensors: add devicetree probing support
  2014-04-23 21:19   ` Jonathan Cameron
@ 2014-04-24  8:33     ` Linus Walleij
  2014-04-26 10:57       ` Jonathan Cameron
  0 siblings, 1 reply; 15+ messages in thread
From: Linus Walleij @ 2014-04-24  8:33 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: linux-iio@vger.kernel.org, Denis CIOCCA, Lee Jones

On Wed, Apr 23, 2014 at 11:19 PM, Jonathan Cameron <jic23@kernel.org> wrote:

> I can't make up my mind whether I like this or not.
> Having said that it fixes an ABI compatibility issue that I couldn't
> see a way around so nicely done.

Lots of redundant strings is device trees second name.

> (note I'll leave this set be for now given the device tree element
> and that it hasn't been 3 weeks yet)

I'll respin the patch anyway, the OF compatible table should
be in the core file rather than the .h file. I try to keep it in common
code so I2C and SPI alike be able to use the same table
atleast.

Yours,
Linus Walleij

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

* Re: [PATCH 1/6] iio: st_sensors: announce registered sensors
  2014-04-24  8:30     ` Linus Walleij
@ 2014-04-26 10:51       ` Jonathan Cameron
  0 siblings, 0 replies; 15+ messages in thread
From: Jonathan Cameron @ 2014-04-26 10:51 UTC (permalink / raw)
  To: Linus Walleij; +Cc: linux-iio@vger.kernel.org, Denis CIOCCA, Lee Jones

On 24/04/14 09:30, Linus Walleij wrote:
> On Wed, Apr 23, 2014 at 11:21 PM, Jonathan Cameron <jic23@kernel.org> wrote:
>> On 13/04/14 20:08, Linus Walleij wrote:
>>>
>>> It is pretty helpful to know already from dmesg that a certain
>>> device is successfully registered, instead of having to browse
>>> sysfs to see if it's actually there.
>>>
>>> Cc: Lee Jones <lee.jones@linaro.org>
>>> Cc: Denis CIOCCA <denis.ciocca@st.com>
>>> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
>>
>>
>> hmm.. Normally I get irritated with these sorts of I'm here
>> messages - it's not exactly hard to tell it has been successfully
>> probed without filling the logs with messages fairly light on
>> info.  Having said that I tend to let these go in new drivers
>> so I don't care that strongly...
>
> Your pick, this patch is orthogonal to the rest.
>
> I tend to stick a oneliner at the end of successful probe
> to verify that the device driver has been compiled in and
> that it probes correctly so that the device tree etc is in
> order. Of course there are other ways to determine that
> but the dmesg give it all in one place for all devices.
>
Fair enough I suppose. Applied to the togreg branch of iio.git.
Will initially be pushed out as testing for the autobuilders
to play around with it.



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

* Re: [PATCH 3/6] iio: st_sensors: get platform data from device tree
  2014-04-13 19:09 ` [PATCH 3/6] iio: st_sensors: get platform data from device tree Linus Walleij
@ 2014-04-26 10:56   ` Jonathan Cameron
  0 siblings, 0 replies; 15+ messages in thread
From: Jonathan Cameron @ 2014-04-26 10:56 UTC (permalink / raw)
  To: Linus Walleij, linux-iio, Denis CIOCCA; +Cc: Lee Jones

On 13/04/14 20:09, Linus Walleij wrote:
> Currently the STMicroelectronics sensors only support one single
> platform data item: configuration of the DRDY (data ready) pin
> for a particular design. Augment the core to prioritize and take
> this information from the device tree if the parent device has an
> assigned device node, else fall back to passed in platform data
> (usually the default data).
>
> Cc: Lee Jones <lee.jones@linaro.org>
> Cc: Denis CIOCCA <denis.ciocca@st.com>
> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
This one adds binding elements so needs to sit for another week I think...
If you are respinning patch 5 then I'll probably wait for a repost before
taking another look at the remaining 4 patches.

Thanks,

Jonathan
> ---
>   drivers/iio/common/st_sensors/st_sensors_core.c | 35 ++++++++++++++++++++++++-
>   1 file changed, 34 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/iio/common/st_sensors/st_sensors_core.c b/drivers/iio/common/st_sensors/st_sensors_core.c
> index e8b932fed70e..1cdcef94e6a2 100644
> --- a/drivers/iio/common/st_sensors/st_sensors_core.c
> +++ b/drivers/iio/common/st_sensors/st_sensors_core.c
> @@ -14,8 +14,8 @@
>   #include <linux/delay.h>
>   #include <linux/iio/iio.h>
>   #include <linux/regulator/consumer.h>
> +#include <linux/of.h>
>   #include <asm/unaligned.h>
> -
>   #include <linux/iio/common/st_sensors.h>
>
>
> @@ -265,14 +265,47 @@ static int st_sensors_set_drdy_int_pin(struct iio_dev *indio_dev,
>   	return 0;
>   }
>
> +#ifdef CONFIG_OF
> +static struct st_sensors_platform_data *st_sensors_of_probe(struct device *dev,
> +		struct st_sensors_platform_data *defdata)
> +{
> +	struct st_sensors_platform_data *pdata;
> +	struct device_node *np = dev->of_node;
> +	u32 val;
> +
> +	if (!np)
> +		return NULL;
> +
> +	pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
> +	if (!of_property_read_u32(np, "st,drdy-int-pin", &val) && (val <= 2))
> +		pdata->drdy_int_pin = (u8) val;
> +	else
> +		pdata->drdy_int_pin = defdata ? defdata->drdy_int_pin : 1;
> +
> +	return pdata;
> +}
> +#else
> +static struct st_sensors_platform_data *st_sensors_of_probe(struct device *dev,
> +		struct st_sensors_platform_data *defdata)
> +{
> +	return NULL;
> +}
> +#endif
> +
>   int st_sensors_init_sensor(struct iio_dev *indio_dev,
>   					struct st_sensors_platform_data *pdata)
>   {
>   	struct st_sensor_data *sdata = iio_priv(indio_dev);
> +	struct st_sensors_platform_data *of_pdata;
>   	int err = 0;
>
>   	mutex_init(&sdata->tb.buf_lock);
>
> +	/* If OF/DT pdata exists, it will take precedence of anything else */
> +	of_pdata = st_sensors_of_probe(indio_dev->dev.parent, pdata);
> +	if (of_pdata)
> +		pdata = of_pdata;
> +
>   	if (pdata)
>   		err = st_sensors_set_drdy_int_pin(indio_dev, pdata);
>
>


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

* Re: [PATCH 5/6] iio: st_sensors: add devicetree probing support
  2014-04-24  8:33     ` Linus Walleij
@ 2014-04-26 10:57       ` Jonathan Cameron
  2014-06-02 12:07         ` Linus Walleij
  0 siblings, 1 reply; 15+ messages in thread
From: Jonathan Cameron @ 2014-04-26 10:57 UTC (permalink / raw)
  To: Linus Walleij; +Cc: linux-iio@vger.kernel.org, Denis CIOCCA, Lee Jones

On 24/04/14 09:33, Linus Walleij wrote:
> On Wed, Apr 23, 2014 at 11:19 PM, Jonathan Cameron <jic23@kernel.org> wrote:
>
>> I can't make up my mind whether I like this or not.
>> Having said that it fixes an ABI compatibility issue that I couldn't
>> see a way around so nicely done.
>
> Lots of redundant strings is device trees second name.
>
>> (note I'll leave this set be for now given the device tree element
>> and that it hasn't been 3 weeks yet)
>
> I'll respin the patch anyway, the OF compatible table should
> be in the core file rather than the .h file. I try to keep it in common
> code so I2C and SPI alike be able to use the same table
> atleast.

Cool, I'll wait on that then (and the remaining week of the 3 weeks to tick
by).


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

* Re: [PATCH 5/6] iio: st_sensors: add devicetree probing support
  2014-04-26 10:57       ` Jonathan Cameron
@ 2014-06-02 12:07         ` Linus Walleij
  0 siblings, 0 replies; 15+ messages in thread
From: Linus Walleij @ 2014-06-02 12:07 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: linux-iio@vger.kernel.org, Denis CIOCCA, Lee Jones

On Sat, Apr 26, 2014 at 12:57 PM, Jonathan Cameron <jic23@kernel.org> wrote:
> On 24/04/14 09:33, Linus Walleij wrote:
>>
>> On Wed, Apr 23, 2014 at 11:19 PM, Jonathan Cameron <jic23@kernel.org>
>> wrote:
>>
>>> I can't make up my mind whether I like this or not.
>>> Having said that it fixes an ABI compatibility issue that I couldn't
>>> see a way around so nicely done.
>>
>>
>> Lots of redundant strings is device trees second name.
>>
>>> (note I'll leave this set be for now given the device tree element
>>> and that it hasn't been 3 weeks yet)
>>
>>
>> I'll respin the patch anyway, the OF compatible table should
>> be in the core file rather than the .h file. I try to keep it in common
>> code so I2C and SPI alike be able to use the same table
>> atleast.
>
>
> Cool, I'll wait on that then (and the remaining week of the 3 weeks to tick
> by).

Hm I couldn't figure out any better way to do this when things
come around.

Feel free to merge this patch whenever you feel it's ready, I
guess after the merge window now.

Yours,
Linus Walleij

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

end of thread, other threads:[~2014-06-02 12:07 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-04-13 19:08 [PATCH 0/6] iio: enable ST Sensors on Ux500 Linus Walleij
2014-04-13 19:08 ` [PATCH 1/6] iio: st_sensors: announce registered sensors Linus Walleij
2014-04-23 21:21   ` Jonathan Cameron
2014-04-24  8:30     ` Linus Walleij
2014-04-26 10:51       ` Jonathan Cameron
2014-04-13 19:08 ` [PATCH 2/6] iio: st_sensors: move regulator retrieveal to core Linus Walleij
2014-04-13 19:09 ` [PATCH 3/6] iio: st_sensors: get platform data from device tree Linus Walleij
2014-04-26 10:56   ` Jonathan Cameron
2014-04-13 19:09 ` [PATCH 4/6] iio: st_sensors: add device tree bindings Linus Walleij
2014-04-13 19:09 ` [PATCH 5/6] iio: st_sensors: add devicetree probing support Linus Walleij
2014-04-23 21:19   ` Jonathan Cameron
2014-04-24  8:33     ` Linus Walleij
2014-04-26 10:57       ` Jonathan Cameron
2014-06-02 12:07         ` Linus Walleij
2014-04-13 19:09 ` [PATCH 6/6] ARM: ux500: add misc sensors to the device trees Linus Walleij

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).