Lines Matching +full:adc +full:- +full:chan
1 // SPDX-License-Identifier: GPL-2.0+
3 * ADC driver for the RICOH RN5T618 power management chip family
26 /* average 4-time conversion mode */
75 ret = regmap_bulk_read(rn5t618->regmap, reg, data, sizeof(data)); in rn5t618_read_adc_reg()
86 struct rn5t618_adc_data *adc = data; in rn5t618_adc_irq() local
91 regmap_write(adc->rn5t618->regmap, RN5T618_IR_ADC1, 0); in rn5t618_adc_irq()
92 regmap_write(adc->rn5t618->regmap, RN5T618_IR_ADC2, 0); in rn5t618_adc_irq()
94 ret = regmap_read(adc->rn5t618->regmap, RN5T618_IR_ADC3, &r); in rn5t618_adc_irq()
96 dev_err(adc->dev, "failed to read IRQ status: %d\n", ret); in rn5t618_adc_irq()
98 regmap_write(adc->rn5t618->regmap, RN5T618_IR_ADC3, 0); in rn5t618_adc_irq()
101 complete(&adc->conv_completion); in rn5t618_adc_irq()
107 const struct iio_chan_spec *chan, in rn5t618_adc_read() argument
110 struct rn5t618_adc_data *adc = iio_priv(iio_dev); in rn5t618_adc_read() local
116 rn5t618_ratios[chan->channel].numerator; in rn5t618_adc_read()
117 *val2 = rn5t618_ratios[chan->channel].denominator * 4095; in rn5t618_adc_read()
123 ret = regmap_update_bits(adc->rn5t618->regmap, RN5T618_ADCCNT3, in rn5t618_adc_read()
125 chan->channel); in rn5t618_adc_read()
129 ret = regmap_write(adc->rn5t618->regmap, RN5T618_EN_ADCIR3, in rn5t618_adc_read()
134 ret = regmap_update_bits(adc->rn5t618->regmap, RN5T618_ADCCNT3, in rn5t618_adc_read()
141 init_completion(&adc->conv_completion); in rn5t618_adc_read()
143 ret = regmap_update_bits(adc->rn5t618->regmap, RN5T618_ADCCNT3, in rn5t618_adc_read()
149 ret = wait_for_completion_timeout(&adc->conv_completion, in rn5t618_adc_read()
152 dev_warn(adc->dev, "timeout waiting for adc result\n"); in rn5t618_adc_read()
153 return -ETIMEDOUT; in rn5t618_adc_read()
156 ret = rn5t618_read_adc_reg(adc->rn5t618, in rn5t618_adc_read()
157 RN5T618_ILIMDATAH + 2 * chan->channel, in rn5t618_adc_read()
196 struct rn5t618_adc_data *adc; in rn5t618_adc_probe() local
197 struct rn5t618 *rn5t618 = dev_get_drvdata(pdev->dev.parent); in rn5t618_adc_probe()
199 iio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*adc)); in rn5t618_adc_probe()
201 dev_err(&pdev->dev, "failed allocating iio device\n"); in rn5t618_adc_probe()
202 return -ENOMEM; in rn5t618_adc_probe()
205 adc = iio_priv(iio_dev); in rn5t618_adc_probe()
206 adc->dev = &pdev->dev; in rn5t618_adc_probe()
207 adc->rn5t618 = rn5t618; in rn5t618_adc_probe()
209 if (rn5t618->irq_data) in rn5t618_adc_probe()
210 adc->irq = regmap_irq_get_virq(rn5t618->irq_data, in rn5t618_adc_probe()
213 if (adc->irq <= 0) { in rn5t618_adc_probe()
214 dev_err(&pdev->dev, "get virq failed\n"); in rn5t618_adc_probe()
215 return -EINVAL; in rn5t618_adc_probe()
218 init_completion(&adc->conv_completion); in rn5t618_adc_probe()
220 iio_dev->name = dev_name(&pdev->dev); in rn5t618_adc_probe()
221 iio_dev->info = &rn5t618_adc_iio_info; in rn5t618_adc_probe()
222 iio_dev->modes = INDIO_DIRECT_MODE; in rn5t618_adc_probe()
223 iio_dev->channels = rn5t618_adc_iio_channels; in rn5t618_adc_probe()
224 iio_dev->num_channels = ARRAY_SIZE(rn5t618_adc_iio_channels); in rn5t618_adc_probe()
226 /* stop any auto-conversion */ in rn5t618_adc_probe()
227 ret = regmap_write(rn5t618->regmap, RN5T618_ADCCNT3, 0); in rn5t618_adc_probe()
233 ret = devm_request_threaded_irq(adc->dev, adc->irq, NULL, in rn5t618_adc_probe()
235 IRQF_ONESHOT, dev_name(adc->dev), in rn5t618_adc_probe()
236 adc); in rn5t618_adc_probe()
238 dev_err(adc->dev, "request irq %d failed: %d\n", adc->irq, ret); in rn5t618_adc_probe()
242 return devm_iio_device_register(adc->dev, iio_dev); in rn5t618_adc_probe()
247 .name = "rn5t618-adc",
253 MODULE_ALIAS("platform:rn5t618-adc");
254 MODULE_DESCRIPTION("RICOH RN5T618 ADC driver");