Lines Matching +full:adc +full:- +full:dev
1 // SPDX-License-Identifier: GPL-2.0
5 * Driver for Texas Instruments' ADC128S052, ADC122S021 and ADC124S021 ADC chip.
35 static int adc128_adc_conversion(struct adc128 *adc, u8 channel) in adc128_adc_conversion() argument
39 mutex_lock(&adc->lock); in adc128_adc_conversion()
41 adc->buffer[0] = channel << 3; in adc128_adc_conversion()
42 adc->buffer[1] = 0; in adc128_adc_conversion()
44 ret = spi_write(adc->spi, &adc->buffer, 2); in adc128_adc_conversion()
46 mutex_unlock(&adc->lock); in adc128_adc_conversion()
50 ret = spi_read(adc->spi, &adc->buffer, 2); in adc128_adc_conversion()
52 mutex_unlock(&adc->lock); in adc128_adc_conversion()
57 return ((adc->buffer[0] << 8 | adc->buffer[1]) & 0xFFF); in adc128_adc_conversion()
64 struct adc128 *adc = iio_priv(indio_dev); in adc128_read_raw() local
70 ret = adc128_adc_conversion(adc, channel->channel); in adc128_read_raw()
79 ret = regulator_get_voltage(adc->reg); in adc128_read_raw()
88 return -EINVAL; in adc128_read_raw()
144 struct adc128 *adc; in adc128_probe() local
147 if (dev_fwnode(&spi->dev)) in adc128_probe()
148 config = (unsigned long) device_get_match_data(&spi->dev); in adc128_probe()
150 config = spi_get_device_id(spi)->driver_data; in adc128_probe()
152 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*adc)); in adc128_probe()
154 return -ENOMEM; in adc128_probe()
156 adc = iio_priv(indio_dev); in adc128_probe()
157 adc->spi = spi; in adc128_probe()
159 indio_dev->name = spi_get_device_id(spi)->name; in adc128_probe()
160 indio_dev->modes = INDIO_DIRECT_MODE; in adc128_probe()
161 indio_dev->info = &adc128_info; in adc128_probe()
163 indio_dev->channels = adc128_config[config].channels; in adc128_probe()
164 indio_dev->num_channels = adc128_config[config].num_channels; in adc128_probe()
166 adc->reg = devm_regulator_get(&spi->dev, "vref"); in adc128_probe()
167 if (IS_ERR(adc->reg)) in adc128_probe()
168 return PTR_ERR(adc->reg); in adc128_probe()
170 ret = regulator_enable(adc->reg); in adc128_probe()
173 ret = devm_add_action_or_reset(&spi->dev, adc128_disable_regulator, in adc128_probe()
174 adc->reg); in adc128_probe()
178 mutex_init(&adc->lock); in adc128_probe()
180 return devm_iio_device_register(&spi->dev, indio_dev); in adc128_probe()