Lines Matching refs:mux
28 struct mux { struct
39 static int iio_mux_select(struct mux *mux, int idx) in iio_mux_select() argument
41 struct mux_child *child = &mux->child[idx]; in iio_mux_select()
42 struct iio_chan_spec const *chan = &mux->chan[idx]; in iio_mux_select()
46 ret = mux_control_select_delay(mux->control, chan->channel, in iio_mux_select()
47 mux->delay_us); in iio_mux_select()
49 mux->cached_state = -1; in iio_mux_select()
53 if (mux->cached_state == chan->channel) in iio_mux_select()
66 ret = iio_write_channel_ext_info(mux->parent, attr, in iio_mux_select()
71 mux_control_deselect(mux->control); in iio_mux_select()
72 mux->cached_state = -1; in iio_mux_select()
77 mux->cached_state = chan->channel; in iio_mux_select()
82 static void iio_mux_deselect(struct mux *mux) in iio_mux_deselect() argument
84 mux_control_deselect(mux->control); in iio_mux_deselect()
91 struct mux *mux = iio_priv(indio_dev); in mux_read_raw() local
92 int idx = chan - mux->chan; in mux_read_raw()
95 ret = iio_mux_select(mux, idx); in mux_read_raw()
101 ret = iio_read_channel_raw(mux->parent, val); in mux_read_raw()
105 ret = iio_read_channel_scale(mux->parent, val, val2); in mux_read_raw()
112 iio_mux_deselect(mux); in mux_read_raw()
122 struct mux *mux = iio_priv(indio_dev); in mux_read_avail() local
123 int idx = chan - mux->chan; in mux_read_avail()
126 ret = iio_mux_select(mux, idx); in mux_read_avail()
133 ret = iio_read_avail_channel_raw(mux->parent, vals, length); in mux_read_avail()
140 iio_mux_deselect(mux); in mux_read_avail()
149 struct mux *mux = iio_priv(indio_dev); in mux_write_raw() local
150 int idx = chan - mux->chan; in mux_write_raw()
153 ret = iio_mux_select(mux, idx); in mux_write_raw()
159 ret = iio_write_channel_raw(mux->parent, val); in mux_write_raw()
166 iio_mux_deselect(mux); in mux_write_raw()
180 struct mux *mux = iio_priv(indio_dev); in mux_read_ext_info() local
181 int idx = chan - mux->chan; in mux_read_ext_info()
184 ret = iio_mux_select(mux, idx); in mux_read_ext_info()
188 ret = iio_read_channel_ext_info(mux->parent, in mux_read_ext_info()
189 mux->ext_info[private].name, in mux_read_ext_info()
192 iio_mux_deselect(mux); in mux_read_ext_info()
202 struct mux *mux = iio_priv(indio_dev); in mux_write_ext_info() local
203 int idx = chan - mux->chan; in mux_write_ext_info()
210 ret = iio_mux_select(mux, idx); in mux_write_ext_info()
216 iio_mux_deselect(mux); in mux_write_ext_info()
222 ret = iio_write_channel_ext_info(mux->parent, in mux_write_ext_info()
223 mux->ext_info[private].name, in mux_write_ext_info()
226 iio_mux_deselect(mux); in mux_write_ext_info()
231 devm_kfree(dev, mux->child[idx].ext_info_cache[private].data); in mux_write_ext_info()
232 mux->child[idx].ext_info_cache[private].data = new; in mux_write_ext_info()
233 mux->child[idx].ext_info_cache[private].size = len; in mux_write_ext_info()
235 iio_mux_deselect(mux); in mux_write_ext_info()
240 static int mux_configure_channel(struct device *dev, struct mux *mux, in mux_configure_channel() argument
243 struct mux_child *child = &mux->child[idx]; in mux_configure_channel()
244 struct iio_chan_spec *chan = &mux->chan[idx]; in mux_configure_channel()
245 struct iio_chan_spec const *pchan = mux->parent->channel; in mux_configure_channel()
254 chan->ext_info = mux->ext_info; in mux_configure_channel()
256 ret = iio_get_channel_type(mux->parent, &chan->type); in mux_configure_channel()
270 if (state >= mux_control_states(mux->control)) { in mux_configure_channel()
277 num_ext_info = iio_get_channel_ext_info_count(mux->parent); in mux_configure_channel()
298 ret = iio_read_channel_ext_info(mux->parent, in mux_configure_channel()
299 mux->ext_info[i].name, in mux_configure_channel()
345 struct mux *mux; in mux_probe() local
366 sizeof_ext_info *= sizeof(*mux->ext_info); in mux_probe()
379 sizeof_priv = sizeof(*mux); in mux_probe()
380 sizeof_priv += sizeof(*mux->child) * children; in mux_probe()
381 sizeof_priv += sizeof(*mux->chan) * children; in mux_probe()
388 mux = iio_priv(indio_dev); in mux_probe()
389 mux->child = (struct mux_child *)(mux + 1); in mux_probe()
390 mux->chan = (struct iio_chan_spec *)(mux->child + children); in mux_probe()
394 mux->parent = parent; in mux_probe()
395 mux->cached_state = -1; in mux_probe()
397 mux->delay_us = 0; in mux_probe()
398 of_property_read_u32(np, "settle-time-us", &mux->delay_us); in mux_probe()
403 indio_dev->channels = mux->chan; in mux_probe()
406 mux->ext_info = devm_kmemdup(dev, in mux_probe()
409 if (!mux->ext_info) in mux_probe()
412 for (i = 0; mux->ext_info[i].name; ++i) { in mux_probe()
414 mux->ext_info[i].read = mux_read_ext_info; in mux_probe()
416 mux->ext_info[i].write = mux_write_ext_info; in mux_probe()
417 mux->ext_info[i].private = i; in mux_probe()
421 mux->control = devm_mux_control_get(dev, NULL); in mux_probe()
422 if (IS_ERR(mux->control)) { in mux_probe()
423 if (PTR_ERR(mux->control) != -EPROBE_DEFER) in mux_probe()
425 return PTR_ERR(mux->control); in mux_probe()
433 ret = mux_configure_channel(dev, mux, state, label, i++); in mux_probe()