Lines Matching +full:adc +full:- +full:channels +full:- +full:used
1 // SPDX-License-Identifier: GPL-2.0-only
5 * Driver for Texas Instruments' ADC084S021 ADC chip.
29 /* Buffer used to align data */
31 __be16 channels[4]; member
39 __be16 rx_buf[5]; /* First 16-bits are trash */
68 * adc084s021_adc_conversion() - Read an ADC channel and return its value.
70 * @adc: The ADC SPI data.
73 static int adc084s021_adc_conversion(struct adc084s021 *adc, __be16 *data) in adc084s021_adc_conversion() argument
75 int n_words = (adc->spi_trans.len >> 1) - 1; /* Discard first word */ in adc084s021_adc_conversion()
79 ret = spi_sync(adc->spi, &adc->message); in adc084s021_adc_conversion()
84 *(data + i) = adc->rx_buf[i + 1]; in adc084s021_adc_conversion()
93 struct adc084s021 *adc = iio_priv(indio_dev); in adc084s021_read_raw() local
103 ret = regulator_enable(adc->reg); in adc084s021_read_raw()
109 adc->tx_buf[0] = channel->channel << 3; in adc084s021_read_raw()
110 ret = adc084s021_adc_conversion(adc, &be_val); in adc084s021_read_raw()
112 regulator_disable(adc->reg); in adc084s021_read_raw()
117 *val = (*val >> channel->scan_type.shift) & 0xff; in adc084s021_read_raw()
121 ret = regulator_enable(adc->reg); in adc084s021_read_raw()
125 ret = regulator_get_voltage(adc->reg); in adc084s021_read_raw()
126 regulator_disable(adc->reg); in adc084s021_read_raw()
134 return -EINVAL; in adc084s021_read_raw()
139 * adc084s021_buffer_trigger_handler() - Read ADC channels and push to buffer.
141 * @irq: The interrupt number (not used).
147 struct iio_dev *indio_dev = pf->indio_dev; in adc084s021_buffer_trigger_handler()
148 struct adc084s021 *adc = iio_priv(indio_dev); in adc084s021_buffer_trigger_handler() local
150 mutex_lock(&adc->lock); in adc084s021_buffer_trigger_handler()
152 if (adc084s021_adc_conversion(adc, adc->scan.channels) < 0) in adc084s021_buffer_trigger_handler()
153 dev_err(&adc->spi->dev, "Failed to read data\n"); in adc084s021_buffer_trigger_handler()
155 iio_push_to_buffers_with_timestamp(indio_dev, &adc->scan, in adc084s021_buffer_trigger_handler()
157 mutex_unlock(&adc->lock); in adc084s021_buffer_trigger_handler()
158 iio_trigger_notify_done(indio_dev->trig); in adc084s021_buffer_trigger_handler()
165 struct adc084s021 *adc = iio_priv(indio_dev); in adc084s021_buffer_preenable() local
169 for_each_set_bit(scan_index, indio_dev->active_scan_mask, in adc084s021_buffer_preenable()
170 indio_dev->masklength) { in adc084s021_buffer_preenable()
172 &indio_dev->channels[scan_index]; in adc084s021_buffer_preenable()
173 adc->tx_buf[i++] = channel->channel << 3; in adc084s021_buffer_preenable()
175 adc->spi_trans.len = 2 + (i * sizeof(__be16)); /* Trash + channels */ in adc084s021_buffer_preenable()
177 return regulator_enable(adc->reg); in adc084s021_buffer_preenable()
182 struct adc084s021 *adc = iio_priv(indio_dev); in adc084s021_buffer_postdisable() local
184 adc->spi_trans.len = 4; /* Trash + single channel */ in adc084s021_buffer_postdisable()
186 return regulator_disable(adc->reg); in adc084s021_buffer_postdisable()
201 struct adc084s021 *adc; in adc084s021_probe() local
204 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*adc)); in adc084s021_probe()
206 dev_err(&spi->dev, "Failed to allocate IIO device\n"); in adc084s021_probe()
207 return -ENOMEM; in adc084s021_probe()
210 adc = iio_priv(indio_dev); in adc084s021_probe()
211 adc->spi = spi; in adc084s021_probe()
214 indio_dev->name = spi_get_device_id(spi)->name; in adc084s021_probe()
215 indio_dev->modes = INDIO_DIRECT_MODE; in adc084s021_probe()
216 indio_dev->info = &adc084s021_info; in adc084s021_probe()
217 indio_dev->channels = adc084s021_channels; in adc084s021_probe()
218 indio_dev->num_channels = ARRAY_SIZE(adc084s021_channels); in adc084s021_probe()
221 adc->spi_trans.tx_buf = adc->tx_buf; in adc084s021_probe()
222 adc->spi_trans.rx_buf = adc->rx_buf; in adc084s021_probe()
223 adc->spi_trans.len = 4; /* Trash + single channel */ in adc084s021_probe()
224 spi_message_init_with_transfers(&adc->message, &adc->spi_trans, 1); in adc084s021_probe()
226 adc->reg = devm_regulator_get(&spi->dev, "vref"); in adc084s021_probe()
227 if (IS_ERR(adc->reg)) in adc084s021_probe()
228 return PTR_ERR(adc->reg); in adc084s021_probe()
230 mutex_init(&adc->lock); in adc084s021_probe()
233 ret = devm_iio_triggered_buffer_setup(&spi->dev, indio_dev, NULL, in adc084s021_probe()
237 dev_err(&spi->dev, "Failed to setup triggered buffer\n"); in adc084s021_probe()
241 return devm_iio_device_register(&spi->dev, indio_dev); in adc084s021_probe()