Lines Matching +full:channel +full:- +full:7
1 // SPDX-License-Identifier: GPL-2.0+
3 * ADS8344 16-bit 8-Channel ADC driver
17 #define ADS8344_START BIT(7)
19 #define ADS8344_CHANNEL(channel) ((channel) << 4) argument
26 * Lock protecting access to adc->tx_buff and rx_buff,
39 .channel = chan, \
49 .channel = (chan1), \
65 ADS8344_VOLTAGE_CHANNEL(7, 7),
69 ADS8344_VOLTAGE_CHANNEL_DIFF(6, 7, 11),
73 ADS8344_VOLTAGE_CHANNEL_DIFF(7, 6, 15),
76 static int ads8344_adc_conversion(struct ads8344 *adc, int channel, in ads8344_adc_conversion() argument
79 struct spi_device *spi = adc->spi; in ads8344_adc_conversion()
82 adc->tx_buf = ADS8344_START; in ads8344_adc_conversion()
84 adc->tx_buf |= ADS8344_SINGLE_END; in ads8344_adc_conversion()
85 adc->tx_buf |= ADS8344_CHANNEL(channel); in ads8344_adc_conversion()
86 adc->tx_buf |= ADS8344_CLOCK_INTERNAL; in ads8344_adc_conversion()
88 ret = spi_write(spi, &adc->tx_buf, 1); in ads8344_adc_conversion()
94 ret = spi_read(spi, adc->rx_buf, sizeof(adc->rx_buf)); in ads8344_adc_conversion()
98 return adc->rx_buf[0] << 9 | adc->rx_buf[1] << 1 | adc->rx_buf[2] >> 7; in ads8344_adc_conversion()
102 struct iio_chan_spec const *channel, int *value, in ads8344_read_raw() argument
109 mutex_lock(&adc->lock); in ads8344_read_raw()
110 *value = ads8344_adc_conversion(adc, channel->address, in ads8344_read_raw()
111 channel->differential); in ads8344_read_raw()
112 mutex_unlock(&adc->lock); in ads8344_read_raw()
118 *value = regulator_get_voltage(adc->reg); in ads8344_read_raw()
128 return -EINVAL; in ads8344_read_raw()
147 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*adc)); in ads8344_probe()
149 return -ENOMEM; in ads8344_probe()
152 adc->spi = spi; in ads8344_probe()
153 mutex_init(&adc->lock); in ads8344_probe()
155 indio_dev->name = dev_name(&spi->dev); in ads8344_probe()
156 indio_dev->info = &ads8344_info; in ads8344_probe()
157 indio_dev->modes = INDIO_DIRECT_MODE; in ads8344_probe()
158 indio_dev->channels = ads8344_channels; in ads8344_probe()
159 indio_dev->num_channels = ARRAY_SIZE(ads8344_channels); in ads8344_probe()
161 adc->reg = devm_regulator_get(&spi->dev, "vref"); in ads8344_probe()
162 if (IS_ERR(adc->reg)) in ads8344_probe()
163 return PTR_ERR(adc->reg); in ads8344_probe()
165 ret = regulator_enable(adc->reg); in ads8344_probe()
169 ret = devm_add_action_or_reset(&spi->dev, ads8344_reg_disable, adc->reg); in ads8344_probe()
173 return devm_iio_device_register(&spi->dev, indio_dev); in ads8344_probe()