Lines Matching refs:mux

29 struct mux {  struct
40 static int iio_mux_select(struct mux *mux, int idx) in iio_mux_select() argument
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()
67 ret = iio_write_channel_ext_info(mux->parent, attr, 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()
83 static void iio_mux_deselect(struct mux *mux) in iio_mux_deselect() argument
85 mux_control_deselect(mux->control); in iio_mux_deselect()
92 struct mux *mux = iio_priv(indio_dev); in mux_read_raw() local
93 int idx = chan - mux->chan; in mux_read_raw()
96 ret = iio_mux_select(mux, idx); 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()
113 iio_mux_deselect(mux); in mux_read_raw()
123 struct mux *mux = iio_priv(indio_dev); in mux_read_avail() local
124 int idx = chan - mux->chan; in mux_read_avail()
127 ret = iio_mux_select(mux, idx); in mux_read_avail()
134 ret = iio_read_avail_channel_raw(mux->parent, vals, length); in mux_read_avail()
141 iio_mux_deselect(mux); in mux_read_avail()
150 struct mux *mux = iio_priv(indio_dev); in mux_write_raw() local
151 int idx = chan - mux->chan; in mux_write_raw()
154 ret = iio_mux_select(mux, idx); in mux_write_raw()
160 ret = iio_write_channel_raw(mux->parent, val); in mux_write_raw()
167 iio_mux_deselect(mux); in mux_write_raw()
181 struct mux *mux = iio_priv(indio_dev); in mux_read_ext_info() local
182 int idx = chan - mux->chan; in mux_read_ext_info()
185 ret = iio_mux_select(mux, idx); 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()
193 iio_mux_deselect(mux); in mux_read_ext_info()
203 struct mux *mux = iio_priv(indio_dev); in mux_write_ext_info() local
204 int idx = chan - mux->chan; in mux_write_ext_info()
211 ret = iio_mux_select(mux, idx); in mux_write_ext_info()
217 iio_mux_deselect(mux); 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()
227 iio_mux_deselect(mux); 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()
236 iio_mux_deselect(mux); in mux_write_ext_info()
241 static int mux_configure_channel(struct device *dev, struct mux *mux, in mux_configure_channel() argument
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()
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()
271 if (state >= mux_control_states(mux->control)) { in mux_configure_channel()
278 num_ext_info = iio_get_channel_ext_info_count(mux->parent); 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()
333 struct mux *mux; in mux_probe() local
351 sizeof_ext_info *= sizeof(*mux->ext_info); in mux_probe()
376 sizeof_priv = sizeof(*mux); in mux_probe()
377 sizeof_priv += sizeof(*mux->child) * children; in mux_probe()
378 sizeof_priv += sizeof(*mux->chan) * children; in mux_probe()
385 mux = iio_priv(indio_dev); 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()
400 indio_dev->channels = mux->chan; in mux_probe()
403 mux->ext_info = devm_kmemdup(dev, in mux_probe()
406 if (!mux->ext_info) in mux_probe()
409 for (i = 0; mux->ext_info[i].name; ++i) { in mux_probe()
411 mux->ext_info[i].read = mux_read_ext_info; 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 return dev_err_probe(dev, PTR_ERR(mux->control), in mux_probe()
428 ret = mux_configure_channel(dev, mux, state, labels[state], i++); in mux_probe()