Lines Matching +full:parent +full:- +full:child

1 // SPDX-License-Identifier: GPL-2.0
31 struct iio_channel *parent; member
35 struct mux_child *child; member
40 struct mux_child *child = &mux->child[idx]; in iio_mux_select() local
41 struct iio_chan_spec const *chan = &mux->chan[idx]; in iio_mux_select()
45 ret = mux_control_select(mux->control, chan->channel); in iio_mux_select()
47 mux->cached_state = -1; in iio_mux_select()
51 if (mux->cached_state == chan->channel) in iio_mux_select()
54 if (chan->ext_info) { in iio_mux_select()
55 for (i = 0; chan->ext_info[i].name; ++i) { in iio_mux_select()
56 const char *attr = chan->ext_info[i].name; in iio_mux_select()
59 cache = &child->ext_info_cache[i]; in iio_mux_select()
61 if (cache->size < 0) in iio_mux_select()
64 ret = iio_write_channel_ext_info(mux->parent, attr, in iio_mux_select()
65 cache->data, in iio_mux_select()
66 cache->size); in iio_mux_select()
69 mux_control_deselect(mux->control); in iio_mux_select()
70 mux->cached_state = -1; in iio_mux_select()
75 mux->cached_state = chan->channel; in iio_mux_select()
82 mux_control_deselect(mux->control); in iio_mux_deselect()
90 int idx = chan - mux->chan; in mux_read_raw()
99 ret = iio_read_channel_raw(mux->parent, val); in mux_read_raw()
103 ret = iio_read_channel_scale(mux->parent, val, val2); in mux_read_raw()
107 ret = -EINVAL; in mux_read_raw()
121 int idx = chan - mux->chan; in mux_read_avail()
131 ret = iio_read_avail_channel_raw(mux->parent, vals, length); in mux_read_avail()
135 ret = -EINVAL; in mux_read_avail()
148 int idx = chan - mux->chan; in mux_write_raw()
157 ret = iio_write_channel_raw(mux->parent, val); in mux_write_raw()
161 ret = -EINVAL; in mux_write_raw()
179 int idx = chan - mux->chan; in mux_read_ext_info()
186 ret = iio_read_channel_ext_info(mux->parent, in mux_read_ext_info()
187 mux->ext_info[private].name, in mux_read_ext_info()
199 struct device *dev = indio_dev->dev.parent; in mux_write_ext_info()
201 int idx = chan - mux->chan; in mux_write_ext_info()
206 return -EINVAL; in mux_write_ext_info()
215 return -ENOMEM; in mux_write_ext_info()
220 ret = iio_write_channel_ext_info(mux->parent, in mux_write_ext_info()
221 mux->ext_info[private].name, in mux_write_ext_info()
229 devm_kfree(dev, mux->child[idx].ext_info_cache[private].data); in mux_write_ext_info()
230 mux->child[idx].ext_info_cache[private].data = new; in mux_write_ext_info()
231 mux->child[idx].ext_info_cache[private].size = len; in mux_write_ext_info()
241 struct mux_child *child = &mux->child[idx]; in mux_configure_channel() local
242 struct iio_chan_spec *chan = &mux->chan[idx]; in mux_configure_channel()
243 struct iio_chan_spec const *pchan = mux->parent->channel; in mux_configure_channel()
249 chan->indexed = 1; in mux_configure_channel()
250 chan->output = pchan->output; in mux_configure_channel()
251 chan->datasheet_name = label; in mux_configure_channel()
252 chan->ext_info = mux->ext_info; in mux_configure_channel()
254 ret = iio_get_channel_type(mux->parent, &chan->type); in mux_configure_channel()
256 dev_err(dev, "failed to get parent channel type\n"); in mux_configure_channel()
261 chan->info_mask_separate |= BIT(IIO_CHAN_INFO_RAW); in mux_configure_channel()
263 chan->info_mask_separate |= BIT(IIO_CHAN_INFO_SCALE); in mux_configure_channel()
266 chan->info_mask_separate_available |= BIT(IIO_CHAN_INFO_RAW); in mux_configure_channel()
268 if (state >= mux_control_states(mux->control)) { in mux_configure_channel()
270 return -EINVAL; in mux_configure_channel()
273 chan->channel = state; in mux_configure_channel()
275 num_ext_info = iio_get_channel_ext_info_count(mux->parent); in mux_configure_channel()
279 return -ENOMEM; in mux_configure_channel()
281 child->ext_info_cache = devm_kcalloc(dev, in mux_configure_channel()
283 sizeof(*child->ext_info_cache), in mux_configure_channel()
285 if (!child->ext_info_cache) in mux_configure_channel()
286 return -ENOMEM; in mux_configure_channel()
289 child->ext_info_cache[i].size = -1; in mux_configure_channel()
291 if (!pchan->ext_info[i].write) in mux_configure_channel()
293 if (!pchan->ext_info[i].read) in mux_configure_channel()
296 ret = iio_read_channel_ext_info(mux->parent, in mux_configure_channel()
297 mux->ext_info[i].name, in mux_configure_channel()
301 pchan->ext_info[i].name); in mux_configure_channel()
306 pchan->ext_info[i].name); in mux_configure_channel()
307 return -EINVAL; in mux_configure_channel()
310 child->ext_info_cache[i].data = devm_kmemdup(dev, page, ret + 1, in mux_configure_channel()
312 if (!child->ext_info_cache[i].data) in mux_configure_channel()
313 return -ENOMEM; in mux_configure_channel()
315 child->ext_info_cache[i].data[ret] = 0; in mux_configure_channel()
316 child->ext_info_cache[i].size = ret; in mux_configure_channel()
339 struct device *dev = &pdev->dev; in mux_probe()
340 struct device_node *np = pdev->dev.of_node; in mux_probe()
342 struct iio_channel *parent; in mux_probe() local
354 return -ENODEV; in mux_probe()
356 parent = devm_iio_channel_get(dev, "parent"); in mux_probe()
357 if (IS_ERR(parent)) in mux_probe()
358 return dev_err_probe(dev, PTR_ERR(parent), in mux_probe()
359 "failed to get parent channel\n"); in mux_probe()
361 sizeof_ext_info = iio_get_channel_ext_info_count(parent); in mux_probe()
364 sizeof_ext_info *= sizeof(*mux->ext_info); in mux_probe()
373 dev_err(dev, "not even a single child\n"); in mux_probe()
374 return -EINVAL; in mux_probe()
378 sizeof_priv += sizeof(*mux->child) * children; in mux_probe()
379 sizeof_priv += sizeof(*mux->chan) * children; in mux_probe()
384 return -ENOMEM; in mux_probe()
387 mux->child = (struct mux_child *)(mux + 1); in mux_probe()
388 mux->chan = (struct iio_chan_spec *)(mux->child + children); in mux_probe()
392 mux->parent = parent; in mux_probe()
393 mux->cached_state = -1; in mux_probe()
395 indio_dev->name = dev_name(dev); in mux_probe()
396 indio_dev->info = &mux_info; in mux_probe()
397 indio_dev->modes = INDIO_DIRECT_MODE; in mux_probe()
398 indio_dev->channels = mux->chan; in mux_probe()
399 indio_dev->num_channels = children; in mux_probe()
401 mux->ext_info = devm_kmemdup(dev, in mux_probe()
402 parent->channel->ext_info, in mux_probe()
404 if (!mux->ext_info) in mux_probe()
405 return -ENOMEM; in mux_probe()
407 for (i = 0; mux->ext_info[i].name; ++i) { in mux_probe()
408 if (parent->channel->ext_info[i].read) in mux_probe()
409 mux->ext_info[i].read = mux_read_ext_info; in mux_probe()
410 if (parent->channel->ext_info[i].write) in mux_probe()
411 mux->ext_info[i].write = mux_write_ext_info; in mux_probe()
412 mux->ext_info[i].private = i; in mux_probe()
416 mux->control = devm_mux_control_get(dev, NULL); in mux_probe()
417 if (IS_ERR(mux->control)) { in mux_probe()
418 if (PTR_ERR(mux->control) != -EPROBE_DEFER) in mux_probe()
419 dev_err(dev, "failed to get control-mux\n"); in mux_probe()
420 return PTR_ERR(mux->control); in mux_probe()
443 { .compatible = "io-channel-mux" },
451 .name = "iio-mux",