|
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 |
|
@@ -345,6 +346,36 @@ static struct st_sensors_platform_data *st_sensors_of_probe(struct device *dev, |
345 | 346 |
|
346 | 347 | return pdata; |
347 | 348 | } |
| 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); |
348 | 379 | #else |
349 | 380 | static struct st_sensors_platform_data *st_sensors_of_probe(struct device *dev, |
350 | 381 | struct st_sensors_platform_data *defdata) |
|
0 commit comments