Lines Matching refs:adc

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()
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()
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()
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()
180 mutex_unlock(&adc->lock); in adc0832_read_raw()
186 *value = regulator_get_voltage(adc->reg); in adc0832_read_raw()
208 struct adc0832 *adc = iio_priv(indio_dev); in adc0832_trigger_handler() local
212 mutex_lock(&adc->lock); in adc0832_trigger_handler()
218 int ret = adc0832_adc_conversion(adc, scan_chan->channel, in adc0832_trigger_handler()
221 dev_warn(&adc->spi->dev, in adc0832_trigger_handler()
226 adc->data[i] = ret; in adc0832_trigger_handler()
229 iio_push_to_buffers_with_timestamp(indio_dev, adc->data, in adc0832_trigger_handler()
232 mutex_unlock(&adc->lock); in adc0832_trigger_handler()
247 struct adc0832 *adc; in adc0832_probe() local
250 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*adc)); in adc0832_probe()
254 adc = iio_priv(indio_dev); in adc0832_probe()
255 adc->spi = spi; in adc0832_probe()
256 mutex_init(&adc->lock); in adc0832_probe()
264 adc->mux_bits = 0; in adc0832_probe()
269 adc->mux_bits = 1; in adc0832_probe()
274 adc->mux_bits = 2; in adc0832_probe()
279 adc->mux_bits = 3; in adc0832_probe()
287 adc->reg = devm_regulator_get(&spi->dev, "vref"); in adc0832_probe()
288 if (IS_ERR(adc->reg)) in adc0832_probe()
289 return PTR_ERR(adc->reg); in adc0832_probe()
291 ret = regulator_enable(adc->reg); in adc0832_probe()
296 adc->reg); in adc0832_probe()