Lines Matching +full:num +full:- +full:channels
1 // SPDX-License-Identifier: GPL-2.0-only
31 __be16 channels[4]; member
39 __be16 rx_buf[5]; /* First 16-bits are trash */
42 #define ADC084S021_VOLTAGE_CHANNEL(num) \ argument
45 .channel = (num), \
47 .scan_index = (num), \
68 * adc084s021_adc_conversion() - Read an ADC channel and return its value.
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()
103 ret = regulator_enable(adc->reg); in adc084s021_read_raw()
109 adc->tx_buf[0] = channel->channel << 3; 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.
147 struct iio_dev *indio_dev = pf->indio_dev; in adc084s021_buffer_trigger_handler()
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()
171 &indio_dev->channels[scan_index]; in adc084s021_buffer_preenable()
172 adc->tx_buf[i++] = channel->channel << 3; in adc084s021_buffer_preenable()
174 adc->spi_trans.len = 2 + (i * sizeof(__be16)); /* Trash + channels */ in adc084s021_buffer_preenable()
176 return regulator_enable(adc->reg); in adc084s021_buffer_preenable()
183 adc->spi_trans.len = 4; /* Trash + single channel */ in adc084s021_buffer_postdisable()
185 return regulator_disable(adc->reg); in adc084s021_buffer_postdisable()
203 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*adc)); in adc084s021_probe()
205 dev_err(&spi->dev, "Failed to allocate IIO device\n"); in adc084s021_probe()
206 return -ENOMEM; in adc084s021_probe()
210 adc->spi = spi; in adc084s021_probe()
213 indio_dev->name = spi_get_device_id(spi)->name; in adc084s021_probe()
214 indio_dev->modes = INDIO_DIRECT_MODE; in adc084s021_probe()
215 indio_dev->info = &adc084s021_info; in adc084s021_probe()
216 indio_dev->channels = adc084s021_channels; in adc084s021_probe()
217 indio_dev->num_channels = ARRAY_SIZE(adc084s021_channels); in adc084s021_probe()
220 adc->spi_trans.tx_buf = adc->tx_buf; in adc084s021_probe()
221 adc->spi_trans.rx_buf = adc->rx_buf; in adc084s021_probe()
222 adc->spi_trans.len = 4; /* Trash + single channel */ in adc084s021_probe()
223 spi_message_init_with_transfers(&adc->message, &adc->spi_trans, 1); in adc084s021_probe()
225 adc->reg = devm_regulator_get(&spi->dev, "vref"); in adc084s021_probe()
226 if (IS_ERR(adc->reg)) in adc084s021_probe()
227 return PTR_ERR(adc->reg); in adc084s021_probe()
229 mutex_init(&adc->lock); in adc084s021_probe()
232 ret = devm_iio_triggered_buffer_setup(&spi->dev, indio_dev, NULL, in adc084s021_probe()
236 dev_err(&spi->dev, "Failed to setup triggered buffer\n"); in adc084s021_probe()
240 return devm_iio_device_register(&spi->dev, indio_dev); in adc084s021_probe()