Skip to content

Commit 250bbbd

Browse files
LorenzoBianconijic23
authored andcommitted
iio: common: st_sensors: move st_sensors_of_i2c_probe() in common code
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>
1 parent 1371856 commit 250bbbd

8 files changed

Lines changed: 51 additions & 43 deletions

File tree

‎drivers/iio/accel/st_accel_i2c.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@ static int st_accel_i2c_probe(struct i2c_client *client,
144144
adata = iio_priv(indio_dev);
145145

146146
if (client->dev.of_node) {
147-
st_sensors_of_i2c_probe(client, st_accel_of_match);
147+
st_sensors_of_name_probe(&client->dev, st_accel_of_match,
148+
client->name, sizeof(client->name));
148149
} else if (ACPI_HANDLE(&client->dev)) {
149150
ret = st_sensors_match_acpi_device(&client->dev);
150151
if ((ret < 0) || (ret >= ST_ACCEL_MAX))

‎drivers/iio/common/st_sensors/st_sensors_core.c‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <linux/iio/iio.h>
1616
#include <linux/regulator/consumer.h>
1717
#include <linux/of.h>
18+
#include <linux/of_device.h>
1819
#include <asm/unaligned.h>
1920
#include <linux/iio/common/st_sensors.h>
2021

@@ -345,6 +346,36 @@ static struct st_sensors_platform_data *st_sensors_of_probe(struct device *dev,
345346

346347
return pdata;
347348
}
349+
350+
/**
351+
* st_sensors_of_name_probe() - device tree probe for ST sensor name
352+
* @dev: driver model representation of the device.
353+
* @match: the OF match table for the device, containing compatible strings
354+
* but also a .data field with the corresponding internal kernel name
355+
* used by this sensor.
356+
* @name: device name buffer reference.
357+
* @len: device name buffer length.
358+
*
359+
* In effect this function matches a compatible string to an internal kernel
360+
* name for a certain sensor device, so that the rest of the autodetection can
361+
* rely on that name from this point on. I2C/SPI devices will be renamed
362+
* to match the internal kernel convention.
363+
*/
364+
void st_sensors_of_name_probe(struct device *dev,
365+
const struct of_device_id *match,
366+
char *name, int len)
367+
{
368+
const struct of_device_id *of_id;
369+
370+
of_id = of_match_device(match, dev);
371+
if (!of_id || !of_id->data)
372+
return;
373+
374+
/* The name from the OF match takes precedence if present */
375+
strncpy(name, of_id->data, len);
376+
name[len - 1] = '\0';
377+
}
378+
EXPORT_SYMBOL(st_sensors_of_name_probe);
348379
#else
349380
static struct st_sensors_platform_data *st_sensors_of_probe(struct device *dev,
350381
struct st_sensors_platform_data *defdata)

‎drivers/iio/common/st_sensors/st_sensors_i2c.c‎

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -79,35 +79,6 @@ void st_sensors_i2c_configure(struct iio_dev *indio_dev,
7979
}
8080
EXPORT_SYMBOL(st_sensors_i2c_configure);
8181

82-
#ifdef CONFIG_OF
83-
/**
84-
* st_sensors_of_i2c_probe() - device tree probe for ST I2C sensors
85-
* @client: the I2C client device for the sensor
86-
* @match: the OF match table for the device, containing compatible strings
87-
* but also a .data field with the corresponding internal kernel name
88-
* used by this sensor.
89-
*
90-
* In effect this function matches a compatible string to an internal kernel
91-
* name for a certain sensor device, so that the rest of the autodetection can
92-
* rely on that name from this point on. I2C client devices will be renamed
93-
* to match the internal kernel convention.
94-
*/
95-
void st_sensors_of_i2c_probe(struct i2c_client *client,
96-
const struct of_device_id *match)
97-
{
98-
const struct of_device_id *of_id;
99-
100-
of_id = of_match_device(match, &client->dev);
101-
if (!of_id)
102-
return;
103-
104-
/* The name from the OF match takes precedence if present */
105-
strncpy(client->name, of_id->data, sizeof(client->name));
106-
client->name[sizeof(client->name) - 1] = '\0';
107-
}
108-
EXPORT_SYMBOL(st_sensors_of_i2c_probe);
109-
#endif
110-
11182
#ifdef CONFIG_ACPI
11283
int st_sensors_match_acpi_device(struct device *dev)
11384
{

‎drivers/iio/gyro/st_gyro_i2c.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ static int st_gyro_i2c_probe(struct i2c_client *client,
7575
return -ENOMEM;
7676

7777
gdata = iio_priv(indio_dev);
78-
st_sensors_of_i2c_probe(client, st_gyro_of_match);
78+
st_sensors_of_name_probe(&client->dev, st_gyro_of_match,
79+
client->name, sizeof(client->name));
7980

8081
st_sensors_i2c_configure(indio_dev, client, gdata);
8182

‎drivers/iio/magnetometer/st_magn_i2c.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ static int st_magn_i2c_probe(struct i2c_client *client,
5959
return -ENOMEM;
6060

6161
mdata = iio_priv(indio_dev);
62-
st_sensors_of_i2c_probe(client, st_magn_of_match);
62+
st_sensors_of_name_probe(&client->dev, st_magn_of_match,
63+
client->name, sizeof(client->name));
6364

6465
st_sensors_i2c_configure(indio_dev, client, mdata);
6566

‎drivers/iio/pressure/st_pressure_i2c.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ static int st_press_i2c_probe(struct i2c_client *client,
7777
press_data = iio_priv(indio_dev);
7878

7979
if (client->dev.of_node) {
80-
st_sensors_of_i2c_probe(client, st_press_of_match);
80+
st_sensors_of_name_probe(&client->dev, st_press_of_match,
81+
client->name, sizeof(client->name));
8182
} else if (ACPI_HANDLE(&client->dev)) {
8283
ret = st_sensors_match_acpi_device(&client->dev);
8384
if ((ret < 0) || (ret >= ST_PRESS_MAX))

‎include/linux/iio/common/st_sensors.h‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,4 +325,16 @@ ssize_t st_sensors_sysfs_sampling_frequency_avail(struct device *dev,
325325
ssize_t st_sensors_sysfs_scale_avail(struct device *dev,
326326
struct device_attribute *attr, char *buf);
327327

328+
#ifdef CONFIG_OF
329+
void st_sensors_of_name_probe(struct device *dev,
330+
const struct of_device_id *match,
331+
char *name, int len);
332+
#else
333+
static inline void st_sensors_of_name_probe(struct device *dev,
334+
const struct of_device_id *match,
335+
char *name, int len)
336+
{
337+
}
338+
#endif
339+
328340
#endif /* ST_SENSORS_H */

‎include/linux/iio/common/st_sensors_i2c.h‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,6 @@
1818
void st_sensors_i2c_configure(struct iio_dev *indio_dev,
1919
struct i2c_client *client, struct st_sensor_data *sdata);
2020

21-
#ifdef CONFIG_OF
22-
void st_sensors_of_i2c_probe(struct i2c_client *client,
23-
const struct of_device_id *match);
24-
#else
25-
static inline void st_sensors_of_i2c_probe(struct i2c_client *client,
26-
const struct of_device_id *match)
27-
{
28-
}
29-
#endif
30-
3121
#ifdef CONFIG_ACPI
3222
int st_sensors_match_acpi_device(struct device *dev);
3323
#else

0 commit comments

Comments
 (0)