diff options
Diffstat (limited to 'drivers/iio/multiplexer/iio-mux.c')
-rw-r--r-- | drivers/iio/multiplexer/iio-mux.c | 63 |
1 files changed, 31 insertions, 32 deletions
diff --git a/drivers/iio/multiplexer/iio-mux.c b/drivers/iio/multiplexer/iio-mux.c index 0422ef57914c..93558fddfa9b 100644 --- a/drivers/iio/multiplexer/iio-mux.c +++ b/drivers/iio/multiplexer/iio-mux.c @@ -10,11 +10,12 @@ #include <linux/err.h> #include <linux/iio/consumer.h> #include <linux/iio/iio.h> +#include <linux/mod_devicetable.h> #include <linux/module.h> #include <linux/mutex.h> #include <linux/mux/consumer.h> -#include <linux/of.h> #include <linux/platform_device.h> +#include <linux/property.h> struct mux_ext_info_cache { char *data; @@ -33,6 +34,7 @@ struct mux { struct iio_chan_spec *chan; struct iio_chan_spec_ext_info *ext_info; struct mux_child *child; + u32 delay_us; }; static int iio_mux_select(struct mux *mux, int idx) @@ -42,7 +44,8 @@ static int iio_mux_select(struct mux *mux, int idx) int ret; int i; - ret = mux_control_select(mux->control, chan->channel); + ret = mux_control_select_delay(mux->control, chan->channel, + mux->delay_us); if (ret < 0) { mux->cached_state = -1; return ret; @@ -322,43 +325,25 @@ static int mux_configure_channel(struct device *dev, struct mux *mux, return 0; } -/* - * Same as of_property_for_each_string(), but also keeps track of the - * index of each string. - */ -#define of_property_for_each_string_index(np, propname, prop, s, i) \ - for (prop = of_find_property(np, propname, NULL), \ - s = of_prop_next_string(prop, NULL), \ - i = 0; \ - s; \ - s = of_prop_next_string(prop, s), \ - i++) - static int mux_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; - struct device_node *np = pdev->dev.of_node; struct iio_dev *indio_dev; struct iio_channel *parent; struct mux *mux; - struct property *prop; - const char *label; + const char **labels; + int all_children; + int children; u32 state; int sizeof_ext_info; - int children; int sizeof_priv; int i; int ret; - if (!np) - return -ENODEV; - parent = devm_iio_channel_get(dev, "parent"); - if (IS_ERR(parent)) { - if (PTR_ERR(parent) != -EPROBE_DEFER) - dev_err(dev, "failed to get parent channel\n"); - return PTR_ERR(parent); - } + if (IS_ERR(parent)) + return dev_err_probe(dev, PTR_ERR(parent), + "failed to get parent channel\n"); sizeof_ext_info = iio_get_channel_ext_info_count(parent); if (sizeof_ext_info) { @@ -366,9 +351,21 @@ static int mux_probe(struct platform_device *pdev) sizeof_ext_info *= sizeof(*mux->ext_info); } + all_children = device_property_string_array_count(dev, "channels"); + if (all_children < 0) + return all_children; + + labels = devm_kmalloc_array(dev, all_children, sizeof(*labels), GFP_KERNEL); + if (!labels) + return -ENOMEM; + + ret = device_property_read_string_array(dev, "channels", labels, all_children); + if (ret < 0) + return ret; + children = 0; - of_property_for_each_string(np, "channels", prop, label) { - if (*label) + for (state = 0; state < all_children; state++) { + if (*labels[state]) children++; } if (children <= 0) { @@ -394,8 +391,10 @@ static int mux_probe(struct platform_device *pdev) mux->parent = parent; mux->cached_state = -1; + mux->delay_us = 0; + device_property_read_u32(dev, "settle-time-us", &mux->delay_us); + indio_dev->name = dev_name(dev); - indio_dev->dev.parent = dev; indio_dev->info = &mux_info; indio_dev->modes = INDIO_DIRECT_MODE; indio_dev->channels = mux->chan; @@ -424,11 +423,11 @@ static int mux_probe(struct platform_device *pdev) } i = 0; - of_property_for_each_string_index(np, "channels", prop, label, state) { - if (!*label) + for (state = 0; state < all_children; state++) { + if (!*labels[state]) continue; - ret = mux_configure_channel(dev, mux, state, label, i++); + ret = mux_configure_channel(dev, mux, state, labels[state], i++); if (ret < 0) return ret; } |