iio: common: st_sensors: move st_sensors_of_i2c_probe() in common code
authorLorenzo Bianconi <lorenzo.bianconi83@gmail.com>
Tue, 20 Jun 2017 19:52:08 +0000 (21:52 +0200)
committerJonathan Cameron <jic23@kernel.org>
Sat, 1 Jul 2017 09:16:56 +0000 (10:16 +0100)
Move st_sensors_of_i2c_probe() in st_sensors_core and rename it in
st_sensors_of_name_probe(). That change is necessary to add device-tree
support in spi code otherwise the rest of the autodetection will fail
since spi->modalias (and indio_dev->name) will be set using compatible
string value that differs from standard sensor name

Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@st.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
drivers/iio/accel/st_accel_i2c.c
drivers/iio/common/st_sensors/st_sensors_core.c
drivers/iio/common/st_sensors/st_sensors_i2c.c
drivers/iio/gyro/st_gyro_i2c.c
drivers/iio/magnetometer/st_magn_i2c.c
drivers/iio/pressure/st_pressure_i2c.c
include/linux/iio/common/st_sensors.h
include/linux/iio/common/st_sensors_i2c.h

index 543f0ad7fd7e383922201ab258ade3761c766f5a..ac67826135be42b1bb42192f4f0228c9e69f8058 100644 (file)
@@ -144,7 +144,8 @@ static int st_accel_i2c_probe(struct i2c_client *client,
        adata = iio_priv(indio_dev);
 
        if (client->dev.of_node) {
-               st_sensors_of_i2c_probe(client, st_accel_of_match);
+               st_sensors_of_name_probe(&client->dev, st_accel_of_match,
+                                        client->name, sizeof(client->name));
        } else if (ACPI_HANDLE(&client->dev)) {
                ret = st_sensors_match_acpi_device(&client->dev);
                if ((ret < 0) || (ret >= ST_ACCEL_MAX))
index 79c8c7cd70d5c6d74fc2e32cad372f8644233c6b..274868100fd088e382e228cdfd49ec0919f66eb5 100644 (file)
@@ -15,6 +15,7 @@
 #include <linux/iio/iio.h>
 #include <linux/regulator/consumer.h>
 #include <linux/of.h>
+#include <linux/of_device.h>
 #include <asm/unaligned.h>
 #include <linux/iio/common/st_sensors.h>
 
@@ -345,6 +346,36 @@ static struct st_sensors_platform_data *st_sensors_of_probe(struct device *dev,
 
        return pdata;
 }
+
+/**
+ * st_sensors_of_name_probe() - device tree probe for ST sensor name
+ * @dev: driver model representation of the device.
+ * @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.
+ * @name: device name buffer reference.
+ * @len: device name buffer length.
+ *
+ * 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/SPI devices will be renamed
+ * to match the internal kernel convention.
+ */
+void st_sensors_of_name_probe(struct device *dev,
+                             const struct of_device_id *match,
+                             char *name, int len)
+{
+       const struct of_device_id *of_id;
+
+       of_id = of_match_device(match, dev);
+       if (!of_id || !of_id->data)
+               return;
+
+       /* The name from the OF match takes precedence if present */
+       strncpy(name, of_id->data, len);
+       name[len - 1] = '\0';
+}
+EXPORT_SYMBOL(st_sensors_of_name_probe);
 #else
 static struct st_sensors_platform_data *st_sensors_of_probe(struct device *dev,
                struct st_sensors_platform_data *defdata)
index c83df4dbfcd73567440e8d186938644b6bf02c91..b81e48e9f27e0db1edf1c097e7412d0ab2c34fda 100644 (file)
@@ -79,35 +79,6 @@ 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';
-}
-EXPORT_SYMBOL(st_sensors_of_i2c_probe);
-#endif
-
 #ifdef CONFIG_ACPI
 int st_sensors_match_acpi_device(struct device *dev)
 {
index 3f628746cb93e411685140056c44f55d9ba28eee..b405b82b91772424ed75546ccfa60f33cce5e98a 100644 (file)
@@ -75,7 +75,8 @@ static int st_gyro_i2c_probe(struct i2c_client *client,
                return -ENOMEM;
 
        gdata = iio_priv(indio_dev);
-       st_sensors_of_i2c_probe(client, st_gyro_of_match);
+       st_sensors_of_name_probe(&client->dev, st_gyro_of_match,
+                                client->name, sizeof(client->name));
 
        st_sensors_i2c_configure(indio_dev, client, gdata);
 
index 8aa37af306edd61f83424f77314a922523a8c2f1..6a6c8121ac2c153a20e22340443b9e84ec5981ce 100644 (file)
@@ -59,7 +59,8 @@ static int st_magn_i2c_probe(struct i2c_client *client,
                return -ENOMEM;
 
        mdata = iio_priv(indio_dev);
-       st_sensors_of_i2c_probe(client, st_magn_of_match);
+       st_sensors_of_name_probe(&client->dev, st_magn_of_match,
+                                client->name, sizeof(client->name));
 
        st_sensors_i2c_configure(indio_dev, client, mdata);
 
index 17417a4d5a5f955be36aeb48ff8ec73f558e4bdc..7f15e927fa2bce3acf5e190a16c7b4878fb123d2 100644 (file)
@@ -77,7 +77,8 @@ static int st_press_i2c_probe(struct i2c_client *client,
        press_data = iio_priv(indio_dev);
 
        if (client->dev.of_node) {
-               st_sensors_of_i2c_probe(client, st_press_of_match);
+               st_sensors_of_name_probe(&client->dev, st_press_of_match,
+                                        client->name, sizeof(client->name));
        } else if (ACPI_HANDLE(&client->dev)) {
                ret = st_sensors_match_acpi_device(&client->dev);
                if ((ret < 0) || (ret >= ST_PRESS_MAX))
index 497f2b3a5a62c8da6f87107de16519b176cc9f1f..1f8211b6438b86e152a2a06f0f0c535d0c7579c5 100644 (file)
@@ -325,4 +325,16 @@ ssize_t st_sensors_sysfs_sampling_frequency_avail(struct device *dev,
 ssize_t st_sensors_sysfs_scale_avail(struct device *dev,
                                struct device_attribute *attr, char *buf);
 
+#ifdef CONFIG_OF
+void st_sensors_of_name_probe(struct device *dev,
+                             const struct of_device_id *match,
+                             char *name, int len);
+#else
+static inline void st_sensors_of_name_probe(struct device *dev,
+                                           const struct of_device_id *match,
+                                           char *name, int len)
+{
+}
+#endif
+
 #endif /* ST_SENSORS_H */
index 254de3c7dde8aa348139e4783ce9376251213688..0a2c25e06d1f95001a9f56bd2c7b3aad607a17f3 100644 (file)
 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
-
 #ifdef CONFIG_ACPI
 int st_sensors_match_acpi_device(struct device *dev);
 #else