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

iio: multiplexer: Make use of device properties

Convert the module to be property provider agnostic and allow
it to be used on non-OF platforms.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Acked-by: Peter Rosin <peda@axentia.se>
Link: https://lore.kernel.org/r/20220302160025.54348-1-andriy.shevchenko@linux.intel.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Andy Shevchenko and committed by
Jonathan Cameron
879a5237 fee4ac32

+23 -27
-1
drivers/iio/multiplexer/Kconfig
··· 9 9 config IIO_MUX 10 10 tristate "IIO multiplexer driver" 11 11 select MULTIPLEXER 12 - depends on OF || COMPILE_TEST 13 12 help 14 13 Say yes here to build support for the IIO multiplexer. 15 14
+23 -26
drivers/iio/multiplexer/iio-mux.c
··· 10 10 #include <linux/err.h> 11 11 #include <linux/iio/consumer.h> 12 12 #include <linux/iio/iio.h> 13 + #include <linux/mod_devicetable.h> 13 14 #include <linux/module.h> 14 15 #include <linux/mutex.h> 15 16 #include <linux/mux/consumer.h> 16 - #include <linux/of.h> 17 17 #include <linux/platform_device.h> 18 + #include <linux/property.h> 18 19 19 20 struct mux_ext_info_cache { 20 21 char *data; ··· 325 324 return 0; 326 325 } 327 326 328 - /* 329 - * Same as of_property_for_each_string(), but also keeps track of the 330 - * index of each string. 331 - */ 332 - #define of_property_for_each_string_index(np, propname, prop, s, i) \ 333 - for (prop = of_find_property(np, propname, NULL), \ 334 - s = of_prop_next_string(prop, NULL), \ 335 - i = 0; \ 336 - s; \ 337 - s = of_prop_next_string(prop, s), \ 338 - i++) 339 - 340 327 static int mux_probe(struct platform_device *pdev) 341 328 { 342 329 struct device *dev = &pdev->dev; 343 - struct device_node *np = pdev->dev.of_node; 344 330 struct iio_dev *indio_dev; 345 331 struct iio_channel *parent; 346 332 struct mux *mux; 347 - struct property *prop; 348 - const char *label; 333 + const char **labels; 334 + int all_children; 335 + int children; 349 336 u32 state; 350 337 int sizeof_ext_info; 351 - int children; 352 338 int sizeof_priv; 353 339 int i; 354 340 int ret; 355 - 356 - if (!np) 357 - return -ENODEV; 358 341 359 342 parent = devm_iio_channel_get(dev, "parent"); 360 343 if (IS_ERR(parent)) ··· 351 366 sizeof_ext_info *= sizeof(*mux->ext_info); 352 367 } 353 368 369 + all_children = device_property_string_array_count(dev, "channels"); 370 + if (all_children < 0) 371 + return all_children; 372 + 373 + labels = devm_kmalloc_array(dev, all_children, sizeof(*labels), GFP_KERNEL); 374 + if (!labels) 375 + return -ENOMEM; 376 + 377 + ret = device_property_read_string_array(dev, "channels", labels, all_children); 378 + if (ret < 0) 379 + return ret; 380 + 354 381 children = 0; 355 - of_property_for_each_string(np, "channels", prop, label) { 356 - if (*label) 382 + for (state = 0; state < all_children; state++) { 383 + if (*labels[state]) 357 384 children++; 358 385 } 359 386 if (children <= 0) { ··· 392 395 mux->cached_state = -1; 393 396 394 397 mux->delay_us = 0; 395 - of_property_read_u32(np, "settle-time-us", &mux->delay_us); 398 + device_property_read_u32(dev, "settle-time-us", &mux->delay_us); 396 399 397 400 indio_dev->name = dev_name(dev); 398 401 indio_dev->info = &mux_info; ··· 423 426 } 424 427 425 428 i = 0; 426 - of_property_for_each_string_index(np, "channels", prop, label, state) { 427 - if (!*label) 429 + for (state = 0; state < all_children; state++) { 430 + if (!*labels[state]) 428 431 continue; 429 432 430 - ret = mux_configure_channel(dev, mux, state, label, i++); 433 + ret = mux_configure_channel(dev, mux, state, labels[state], i++); 431 434 if (ret < 0) 432 435 return ret; 433 436 }