Lines Matching +full:adc +full:- +full:channels
1 // SPDX-License-Identifier: GPL-2.0-only
3 * ADC0831/ADC0832/ADC0834/ADC0838 8-bit ADC driver
7 * Datasheet: https://www.ti.com/lit/ds/symlink/adc0832-n.pdf
33 * Max size needed: 16x 1 byte ADC data + 8 bytes timestamp
34 * May be shorter if not all channels are enabled subject
120 static int adc0831_adc_conversion(struct adc0832 *adc) in adc0831_adc_conversion() argument
122 struct spi_device *spi = adc->spi; in adc0831_adc_conversion()
125 ret = spi_read(spi, &adc->rx_buf, 2); in adc0831_adc_conversion()
130 * Skip TRI-STATE and a leading zero in adc0831_adc_conversion()
132 return (adc->rx_buf[0] << 2 & 0xff) | (adc->rx_buf[1] >> 6); in adc0831_adc_conversion()
135 static int adc0832_adc_conversion(struct adc0832 *adc, int channel, in adc0832_adc_conversion() argument
138 struct spi_device *spi = adc->spi; in adc0832_adc_conversion()
140 .tx_buf = adc->tx_buf, in adc0832_adc_conversion()
141 .rx_buf = adc->rx_buf, in adc0832_adc_conversion()
146 if (!adc->mux_bits) in adc0832_adc_conversion()
147 return adc0831_adc_conversion(adc); in adc0832_adc_conversion()
150 adc->tx_buf[0] = 1 << (adc->mux_bits + 1); in adc0832_adc_conversion()
151 /* single-ended or differential */ in adc0832_adc_conversion()
152 adc->tx_buf[0] |= differential ? 0 : (1 << adc->mux_bits); in adc0832_adc_conversion()
154 adc->tx_buf[0] |= (channel % 2) << (adc->mux_bits - 1); in adc0832_adc_conversion()
156 if (adc->mux_bits > 1) in adc0832_adc_conversion()
157 adc->tx_buf[0] |= channel / 2; in adc0832_adc_conversion()
159 /* align Data output BIT7 (MSB) to 8-bit boundary */ in adc0832_adc_conversion()
160 adc->tx_buf[0] <<= 1; in adc0832_adc_conversion()
166 return adc->rx_buf[1]; in adc0832_adc_conversion()
173 struct adc0832 *adc = iio_priv(iio); in adc0832_read_raw() local
177 mutex_lock(&adc->lock); in adc0832_read_raw()
178 *value = adc0832_adc_conversion(adc, channel->channel, in adc0832_read_raw()
179 channel->differential); in adc0832_read_raw()
180 mutex_unlock(&adc->lock); in adc0832_read_raw()
186 *value = regulator_get_voltage(adc->reg); in adc0832_read_raw()
197 return -EINVAL; in adc0832_read_raw()
207 struct iio_dev *indio_dev = pf->indio_dev; in adc0832_trigger_handler()
208 struct adc0832 *adc = iio_priv(indio_dev); in adc0832_trigger_handler() local
212 mutex_lock(&adc->lock); in adc0832_trigger_handler()
216 &indio_dev->channels[scan_index]; in adc0832_trigger_handler()
217 int ret = adc0832_adc_conversion(adc, scan_chan->channel, in adc0832_trigger_handler()
218 scan_chan->differential); in adc0832_trigger_handler()
220 dev_warn(&adc->spi->dev, in adc0832_trigger_handler()
225 adc->data[i] = ret; in adc0832_trigger_handler()
228 iio_push_to_buffers_with_timestamp(indio_dev, adc->data, in adc0832_trigger_handler()
231 mutex_unlock(&adc->lock); in adc0832_trigger_handler()
233 iio_trigger_notify_done(indio_dev->trig); in adc0832_trigger_handler()
246 struct adc0832 *adc; in adc0832_probe() local
249 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*adc)); in adc0832_probe()
251 return -ENOMEM; in adc0832_probe()
253 adc = iio_priv(indio_dev); in adc0832_probe()
254 adc->spi = spi; in adc0832_probe()
255 mutex_init(&adc->lock); in adc0832_probe()
257 indio_dev->name = spi_get_device_id(spi)->name; in adc0832_probe()
258 indio_dev->info = &adc0832_info; in adc0832_probe()
259 indio_dev->modes = INDIO_DIRECT_MODE; in adc0832_probe()
261 switch (spi_get_device_id(spi)->driver_data) { in adc0832_probe()
263 adc->mux_bits = 0; in adc0832_probe()
264 indio_dev->channels = adc0831_channels; in adc0832_probe()
265 indio_dev->num_channels = ARRAY_SIZE(adc0831_channels); in adc0832_probe()
268 adc->mux_bits = 1; in adc0832_probe()
269 indio_dev->channels = adc0832_channels; in adc0832_probe()
270 indio_dev->num_channels = ARRAY_SIZE(adc0832_channels); in adc0832_probe()
273 adc->mux_bits = 2; in adc0832_probe()
274 indio_dev->channels = adc0834_channels; in adc0832_probe()
275 indio_dev->num_channels = ARRAY_SIZE(adc0834_channels); in adc0832_probe()
278 adc->mux_bits = 3; in adc0832_probe()
279 indio_dev->channels = adc0838_channels; in adc0832_probe()
280 indio_dev->num_channels = ARRAY_SIZE(adc0838_channels); in adc0832_probe()
283 return -EINVAL; in adc0832_probe()
286 adc->reg = devm_regulator_get(&spi->dev, "vref"); in adc0832_probe()
287 if (IS_ERR(adc->reg)) in adc0832_probe()
288 return PTR_ERR(adc->reg); in adc0832_probe()
290 ret = regulator_enable(adc->reg); in adc0832_probe()
294 ret = devm_add_action_or_reset(&spi->dev, adc0832_reg_disable, in adc0832_probe()
295 adc->reg); in adc0832_probe()
299 ret = devm_iio_triggered_buffer_setup(&spi->dev, indio_dev, NULL, in adc0832_probe()
304 return devm_iio_device_register(&spi->dev, indio_dev); in adc0832_probe()