Lines Matching +full:iio +full:- +full:consumer

1 // SPDX-License-Identifier: GPL-2.0
3 * IIO multiplexer driver
11 #include <linux/iio/consumer.h>
12 #include <linux/iio/iio.h>
16 #include <linux/mux/consumer.h>
42 struct mux_child *child = &mux->child[idx]; in iio_mux_select()
43 struct iio_chan_spec const *chan = &mux->chan[idx]; in iio_mux_select()
47 ret = mux_control_select_delay(mux->control, chan->channel, in iio_mux_select()
48 mux->delay_us); in iio_mux_select()
50 mux->cached_state = -1; in iio_mux_select()
54 if (mux->cached_state == chan->channel) in iio_mux_select()
57 if (chan->ext_info) { in iio_mux_select()
58 for (i = 0; chan->ext_info[i].name; ++i) { in iio_mux_select()
59 const char *attr = chan->ext_info[i].name; in iio_mux_select()
62 cache = &child->ext_info_cache[i]; in iio_mux_select()
64 if (cache->size < 0) in iio_mux_select()
67 ret = iio_write_channel_ext_info(mux->parent, attr, in iio_mux_select()
68 cache->data, in iio_mux_select()
69 cache->size); in iio_mux_select()
72 mux_control_deselect(mux->control); in iio_mux_select()
73 mux->cached_state = -1; in iio_mux_select()
78 mux->cached_state = chan->channel; in iio_mux_select()
85 mux_control_deselect(mux->control); in iio_mux_deselect()
93 int idx = chan - mux->chan; in mux_read_raw()
102 ret = iio_read_channel_raw(mux->parent, val); in mux_read_raw()
106 ret = iio_read_channel_scale(mux->parent, val, val2); in mux_read_raw()
110 ret = -EINVAL; in mux_read_raw()
124 int idx = chan - mux->chan; in mux_read_avail()
134 ret = iio_read_avail_channel_raw(mux->parent, vals, length); in mux_read_avail()
138 ret = -EINVAL; in mux_read_avail()
151 int idx = chan - mux->chan; in mux_write_raw()
160 ret = iio_write_channel_raw(mux->parent, val); in mux_write_raw()
164 ret = -EINVAL; in mux_write_raw()
182 int idx = chan - mux->chan; in mux_read_ext_info()
189 ret = iio_read_channel_ext_info(mux->parent, in mux_read_ext_info()
190 mux->ext_info[private].name, in mux_read_ext_info()
202 struct device *dev = indio_dev->dev.parent; in mux_write_ext_info()
204 int idx = chan - mux->chan; in mux_write_ext_info()
209 return -EINVAL; in mux_write_ext_info()
218 return -ENOMEM; in mux_write_ext_info()
223 ret = iio_write_channel_ext_info(mux->parent, in mux_write_ext_info()
224 mux->ext_info[private].name, in mux_write_ext_info()
232 devm_kfree(dev, mux->child[idx].ext_info_cache[private].data); in mux_write_ext_info()
233 mux->child[idx].ext_info_cache[private].data = new; in mux_write_ext_info()
234 mux->child[idx].ext_info_cache[private].size = len; in mux_write_ext_info()
244 struct mux_child *child = &mux->child[idx]; in mux_configure_channel()
245 struct iio_chan_spec *chan = &mux->chan[idx]; in mux_configure_channel()
246 struct iio_chan_spec const *pchan = mux->parent->channel; in mux_configure_channel()
252 chan->indexed = 1; in mux_configure_channel()
253 chan->output = pchan->output; in mux_configure_channel()
254 chan->datasheet_name = label; in mux_configure_channel()
255 chan->ext_info = mux->ext_info; in mux_configure_channel()
257 ret = iio_get_channel_type(mux->parent, &chan->type); in mux_configure_channel()
264 chan->info_mask_separate |= BIT(IIO_CHAN_INFO_RAW); in mux_configure_channel()
266 chan->info_mask_separate |= BIT(IIO_CHAN_INFO_SCALE); in mux_configure_channel()
269 chan->info_mask_separate_available |= BIT(IIO_CHAN_INFO_RAW); in mux_configure_channel()
271 if (state >= mux_control_states(mux->control)) { in mux_configure_channel()
273 return -EINVAL; in mux_configure_channel()
276 chan->channel = state; in mux_configure_channel()
278 num_ext_info = iio_get_channel_ext_info_count(mux->parent); in mux_configure_channel()
282 return -ENOMEM; in mux_configure_channel()
284 child->ext_info_cache = devm_kcalloc(dev, in mux_configure_channel()
286 sizeof(*child->ext_info_cache), in mux_configure_channel()
288 if (!child->ext_info_cache) in mux_configure_channel()
289 return -ENOMEM; in mux_configure_channel()
292 child->ext_info_cache[i].size = -1; in mux_configure_channel()
294 if (!pchan->ext_info[i].write) in mux_configure_channel()
296 if (!pchan->ext_info[i].read) in mux_configure_channel()
299 ret = iio_read_channel_ext_info(mux->parent, in mux_configure_channel()
300 mux->ext_info[i].name, in mux_configure_channel()
304 pchan->ext_info[i].name); in mux_configure_channel()
309 pchan->ext_info[i].name); in mux_configure_channel()
310 return -EINVAL; in mux_configure_channel()
313 child->ext_info_cache[i].data = devm_kmemdup(dev, page, ret + 1, in mux_configure_channel()
315 if (!child->ext_info_cache[i].data) in mux_configure_channel()
316 return -ENOMEM; in mux_configure_channel()
318 child->ext_info_cache[i].data[ret] = 0; in mux_configure_channel()
319 child->ext_info_cache[i].size = ret; in mux_configure_channel()
330 struct device *dev = &pdev->dev; in mux_probe()
351 sizeof_ext_info *= sizeof(*mux->ext_info); in mux_probe()
360 return -ENOMEM; in mux_probe()
373 return -EINVAL; in mux_probe()
377 sizeof_priv += sizeof(*mux->child) * children; in mux_probe()
378 sizeof_priv += sizeof(*mux->chan) * children; in mux_probe()
383 return -ENOMEM; in mux_probe()
386 mux->child = (struct mux_child *)(mux + 1); in mux_probe()
387 mux->chan = (struct iio_chan_spec *)(mux->child + children); in mux_probe()
391 mux->parent = parent; in mux_probe()
392 mux->cached_state = -1; in mux_probe()
394 mux->delay_us = 0; in mux_probe()
395 device_property_read_u32(dev, "settle-time-us", &mux->delay_us); in mux_probe()
397 indio_dev->name = dev_name(dev); in mux_probe()
398 indio_dev->info = &mux_info; in mux_probe()
399 indio_dev->modes = INDIO_DIRECT_MODE; in mux_probe()
400 indio_dev->channels = mux->chan; in mux_probe()
401 indio_dev->num_channels = children; in mux_probe()
403 mux->ext_info = devm_kmemdup(dev, in mux_probe()
404 parent->channel->ext_info, in mux_probe()
406 if (!mux->ext_info) in mux_probe()
407 return -ENOMEM; in mux_probe()
409 for (i = 0; mux->ext_info[i].name; ++i) { in mux_probe()
410 if (parent->channel->ext_info[i].read) in mux_probe()
411 mux->ext_info[i].read = mux_read_ext_info; in mux_probe()
412 if (parent->channel->ext_info[i].write) in mux_probe()
413 mux->ext_info[i].write = mux_write_ext_info; in mux_probe()
414 mux->ext_info[i].private = i; in mux_probe()
418 mux->control = devm_mux_control_get(dev, NULL); in mux_probe()
419 if (IS_ERR(mux->control)) { in mux_probe()
420 if (PTR_ERR(mux->control) != -EPROBE_DEFER) in mux_probe()
421 dev_err(dev, "failed to get control-mux\n"); in mux_probe()
422 return PTR_ERR(mux->control); in mux_probe()
437 dev_err(dev, "failed to register iio device\n"); in mux_probe()
445 { .compatible = "io-channel-mux" },
453 .name = "iio-mux",
459 MODULE_DESCRIPTION("IIO multiplexer driver");