Lines Matching +full:adc +full:- +full:chan
1 // SPDX-License-Identifier: GPL-2.0
3 * STMicroelectronics STMPE811 IIO ADC Driver
5 * 4 channel, 10/12-bit ADC
7 * Copyright (C) 2013-2018 Toradex AG <stefan.agner@toradex.com>
62 struct iio_chan_spec const *chan, int *val) in stmpe_read_voltage() argument
66 mutex_lock(&info->lock); in stmpe_read_voltage()
68 reinit_completion(&info->completion); in stmpe_read_voltage()
70 info->channel = (u8)chan->channel; in stmpe_read_voltage()
72 if (info->channel > STMPE_ADC_LAST_NR) { in stmpe_read_voltage()
73 mutex_unlock(&info->lock); in stmpe_read_voltage()
74 return -EINVAL; in stmpe_read_voltage()
77 stmpe_reg_write(info->stmpe, STMPE_REG_ADC_CAPT, in stmpe_read_voltage()
78 STMPE_ADC_CH(info->channel)); in stmpe_read_voltage()
80 ret = wait_for_completion_timeout(&info->completion, STMPE_ADC_TIMEOUT); in stmpe_read_voltage()
83 stmpe_reg_write(info->stmpe, STMPE_REG_ADC_INT_STA, in stmpe_read_voltage()
84 STMPE_ADC_CH(info->channel)); in stmpe_read_voltage()
85 mutex_unlock(&info->lock); in stmpe_read_voltage()
86 return -ETIMEDOUT; in stmpe_read_voltage()
89 *val = info->value; in stmpe_read_voltage()
91 mutex_unlock(&info->lock); in stmpe_read_voltage()
97 struct iio_chan_spec const *chan, int *val) in stmpe_read_temp() argument
101 mutex_lock(&info->lock); in stmpe_read_temp()
103 reinit_completion(&info->completion); in stmpe_read_temp()
105 info->channel = (u8)chan->channel; in stmpe_read_temp()
107 if (info->channel != STMPE_TEMP_CHANNEL) { in stmpe_read_temp()
108 mutex_unlock(&info->lock); in stmpe_read_temp()
109 return -EINVAL; in stmpe_read_temp()
112 stmpe_reg_write(info->stmpe, STMPE_REG_TEMP_CTRL, in stmpe_read_temp()
115 ret = wait_for_completion_timeout(&info->completion, STMPE_ADC_TIMEOUT); in stmpe_read_temp()
118 mutex_unlock(&info->lock); in stmpe_read_temp()
119 return -ETIMEDOUT; in stmpe_read_temp()
126 *val = ((449960l * info->value) / 1024l) - 273150; in stmpe_read_temp()
128 mutex_unlock(&info->lock); in stmpe_read_temp()
134 struct iio_chan_spec const *chan, in stmpe_read_raw() argument
146 switch (chan->type) { in stmpe_read_raw()
148 ret = stmpe_read_voltage(info, chan, val); in stmpe_read_raw()
152 ret = stmpe_read_temp(info, chan, val); in stmpe_read_raw()
155 return -EINVAL; in stmpe_read_raw()
165 *val2 = info->stmpe->mod_12b ? 12 : 10; in stmpe_read_raw()
172 return -EINVAL; in stmpe_read_raw()
180 if (info->channel <= STMPE_ADC_LAST_NR) { in stmpe_adc_isr()
183 int_sta = stmpe_reg_read(info->stmpe, STMPE_REG_ADC_INT_STA); in stmpe_adc_isr()
186 if (!(int_sta & STMPE_ADC_CH(info->channel))) in stmpe_adc_isr()
190 stmpe_block_read(info->stmpe, in stmpe_adc_isr()
191 STMPE_REG_ADC_DATA_CH(info->channel), 2, (u8 *) &data); in stmpe_adc_isr()
193 stmpe_reg_write(info->stmpe, STMPE_REG_ADC_INT_STA, int_sta); in stmpe_adc_isr()
194 } else if (info->channel == STMPE_TEMP_CHANNEL) { in stmpe_adc_isr()
196 stmpe_block_read(info->stmpe, STMPE_REG_TEMP_DATA, 2, in stmpe_adc_isr()
202 info->value = (u32) be16_to_cpu(data); in stmpe_adc_isr()
203 complete(&info->completion); in stmpe_adc_isr()
212 static void stmpe_adc_voltage_chan(struct iio_chan_spec *ics, int chan) in stmpe_adc_voltage_chan() argument
214 ics->type = IIO_VOLTAGE; in stmpe_adc_voltage_chan()
215 ics->info_mask_separate = BIT(IIO_CHAN_INFO_RAW); in stmpe_adc_voltage_chan()
216 ics->info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE); in stmpe_adc_voltage_chan()
217 ics->indexed = 1; in stmpe_adc_voltage_chan()
218 ics->channel = chan; in stmpe_adc_voltage_chan()
221 static void stmpe_adc_temp_chan(struct iio_chan_spec *ics, int chan) in stmpe_adc_temp_chan() argument
223 ics->type = IIO_TEMP; in stmpe_adc_temp_chan()
224 ics->info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED); in stmpe_adc_temp_chan()
225 ics->indexed = 1; in stmpe_adc_temp_chan()
226 ics->channel = chan; in stmpe_adc_temp_chan()
229 static int stmpe_adc_init_hw(struct stmpe_adc *adc) in stmpe_adc_init_hw() argument
232 struct stmpe *stmpe = adc->stmpe; in stmpe_adc_init_hw()
236 dev_err(stmpe->dev, "Could not enable clock for ADC\n"); in stmpe_adc_init_hw()
268 indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(struct stmpe_adc)); in stmpe_adc_probe()
270 dev_err(&pdev->dev, "failed allocating iio device\n"); in stmpe_adc_probe()
271 return -ENOMEM; in stmpe_adc_probe()
275 mutex_init(&info->lock); in stmpe_adc_probe()
277 init_completion(&info->completion); in stmpe_adc_probe()
278 ret = devm_request_threaded_irq(&pdev->dev, irq_adc, NULL, in stmpe_adc_probe()
280 "stmpe-adc", info); in stmpe_adc_probe()
282 dev_err(&pdev->dev, "failed requesting irq, irq = %d\n", in stmpe_adc_probe()
289 ret = devm_request_threaded_irq(&pdev->dev, irq_temp, NULL, in stmpe_adc_probe()
291 "stmpe-adc", info); in stmpe_adc_probe()
293 dev_warn(&pdev->dev, "failed requesting irq for" in stmpe_adc_probe()
299 indio_dev->name = dev_name(&pdev->dev); in stmpe_adc_probe()
300 indio_dev->info = &stmpe_adc_iio_info; in stmpe_adc_probe()
301 indio_dev->modes = INDIO_DIRECT_MODE; in stmpe_adc_probe()
303 info->stmpe = dev_get_drvdata(pdev->dev.parent); in stmpe_adc_probe()
305 np = pdev->dev.of_node; in stmpe_adc_probe()
308 dev_err(&pdev->dev, "no device tree node found\n"); in stmpe_adc_probe()
310 of_property_read_u32(np, "st,norequest-mask", &norequest_mask); in stmpe_adc_probe()
314 stmpe_adc_voltage_chan(&info->stmpe_adc_iio_channels[num_chan], i); in stmpe_adc_probe()
317 stmpe_adc_temp_chan(&info->stmpe_adc_iio_channels[num_chan], i); in stmpe_adc_probe()
319 indio_dev->channels = info->stmpe_adc_iio_channels; in stmpe_adc_probe()
320 indio_dev->num_channels = num_chan; in stmpe_adc_probe()
326 stmpe_reg_write(info->stmpe, STMPE_REG_ADC_INT_EN, in stmpe_adc_probe()
329 stmpe_reg_write(info->stmpe, STMPE_REG_ADC_INT_STA, in stmpe_adc_probe()
332 return devm_iio_device_register(&pdev->dev, indio_dev); in stmpe_adc_probe()
350 .name = "stmpe-adc",
357 { .compatible = "st,stmpe-adc", },
363 MODULE_DESCRIPTION("STMPEXXX ADC driver");
365 MODULE_ALIAS("platform:stmpe-adc");