Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Lorenzo Bianconi and committed by
Jonathan Cameron
250bbbdb 13718564

+51 -43
+2 -1
drivers/iio/accel/st_accel_i2c.c
··· 144 144 adata = iio_priv(indio_dev); 145 145 146 146 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)); 148 149 } else if (ACPI_HANDLE(&client->dev)) { 149 150 ret = st_sensors_match_acpi_device(&client->dev); 150 151 if ((ret < 0) || (ret >= ST_ACCEL_MAX))
+31
drivers/iio/common/st_sensors/st_sensors_core.c
··· 15 15 #include <linux/iio/iio.h> 16 16 #include <linux/regulator/consumer.h> 17 17 #include <linux/of.h> 18 + #include <linux/of_device.h> 18 19 #include <asm/unaligned.h> 19 20 #include <linux/iio/common/st_sensors.h> 20 21 ··· 346 345 347 346 return pdata; 348 347 } 348 + 349 + /** 350 + * st_sensors_of_name_probe() - device tree probe for ST sensor name 351 + * @dev: driver model representation of the device. 352 + * @match: the OF match table for the device, containing compatible strings 353 + * but also a .data field with the corresponding internal kernel name 354 + * used by this sensor. 355 + * @name: device name buffer reference. 356 + * @len: device name buffer length. 357 + * 358 + * In effect this function matches a compatible string to an internal kernel 359 + * name for a certain sensor device, so that the rest of the autodetection can 360 + * rely on that name from this point on. I2C/SPI devices will be renamed 361 + * to match the internal kernel convention. 362 + */ 363 + void st_sensors_of_name_probe(struct device *dev, 364 + const struct of_device_id *match, 365 + char *name, int len) 366 + { 367 + const struct of_device_id *of_id; 368 + 369 + of_id = of_match_device(match, dev); 370 + if (!of_id || !of_id->data) 371 + return; 372 + 373 + /* The name from the OF match takes precedence if present */ 374 + strncpy(name, of_id->data, len); 375 + name[len - 1] = '\0'; 376 + } 377 + EXPORT_SYMBOL(st_sensors_of_name_probe); 349 378 #else 350 379 static struct st_sensors_platform_data *st_sensors_of_probe(struct device *dev, 351 380 struct st_sensors_platform_data *defdata)
-29
drivers/iio/common/st_sensors/st_sensors_i2c.c
··· 79 79 } 80 80 EXPORT_SYMBOL(st_sensors_i2c_configure); 81 81 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 - 111 82 #ifdef CONFIG_ACPI 112 83 int st_sensors_match_acpi_device(struct device *dev) 113 84 {
+2 -1
drivers/iio/gyro/st_gyro_i2c.c
··· 75 75 return -ENOMEM; 76 76 77 77 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)); 79 80 80 81 st_sensors_i2c_configure(indio_dev, client, gdata); 81 82
+2 -1
drivers/iio/magnetometer/st_magn_i2c.c
··· 59 59 return -ENOMEM; 60 60 61 61 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)); 63 64 64 65 st_sensors_i2c_configure(indio_dev, client, mdata); 65 66
+2 -1
drivers/iio/pressure/st_pressure_i2c.c
··· 77 77 press_data = iio_priv(indio_dev); 78 78 79 79 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)); 81 82 } else if (ACPI_HANDLE(&client->dev)) { 82 83 ret = st_sensors_match_acpi_device(&client->dev); 83 84 if ((ret < 0) || (ret >= ST_PRESS_MAX))
+12
include/linux/iio/common/st_sensors.h
··· 325 325 ssize_t st_sensors_sysfs_scale_avail(struct device *dev, 326 326 struct device_attribute *attr, char *buf); 327 327 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 + 328 340 #endif /* ST_SENSORS_H */
-10
include/linux/iio/common/st_sensors_i2c.h
··· 18 18 void st_sensors_i2c_configure(struct iio_dev *indio_dev, 19 19 struct i2c_client *client, struct st_sensor_data *sdata); 20 20 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 - 31 21 #ifdef CONFIG_ACPI 32 22 int st_sensors_match_acpi_device(struct device *dev); 33 23 #else