Lines Matching +full:adc +full:- +full:vref

1 // SPDX-License-Identifier: GPL-2.0+
3 * lpc32xx_adc.c - Support for ADC in LPC32XX
5 * 3-channel, 10-bit ADC
45 #define LPC32XXAD_NAME "lpc32xx-adc"
51 struct regulator *vref; member
67 mutex_lock(&indio_dev->mlock); in lpc32xx_read_raw()
68 ret = clk_prepare_enable(st->clk); in lpc32xx_read_raw()
70 mutex_unlock(&indio_dev->mlock); in lpc32xx_read_raw()
74 __raw_writel(LPC32XXAD_INTERNAL | (chan->address) | in lpc32xx_read_raw()
76 LPC32XXAD_SELECT(st->adc_base)); in lpc32xx_read_raw()
79 LPC32XXAD_CTRL(st->adc_base)); in lpc32xx_read_raw()
80 wait_for_completion(&st->completion); /* set by ISR */ in lpc32xx_read_raw()
81 clk_disable_unprepare(st->clk); in lpc32xx_read_raw()
82 *val = st->value; in lpc32xx_read_raw()
83 mutex_unlock(&indio_dev->mlock); in lpc32xx_read_raw()
88 *val = regulator_get_voltage(st->vref) / 1000; in lpc32xx_read_raw()
93 return -EINVAL; in lpc32xx_read_raw()
135 st->value = __raw_readl(LPC32XXAD_VALUE(st->adc_base)) & in lpc32xx_adc_isr()
137 complete(&st->completion); in lpc32xx_adc_isr()
146 int retval = -ENODEV; in lpc32xx_adc_probe()
152 dev_err(&pdev->dev, "failed to get platform I/O memory\n"); in lpc32xx_adc_probe()
153 return -ENXIO; in lpc32xx_adc_probe()
156 iodev = devm_iio_device_alloc(&pdev->dev, sizeof(*st)); in lpc32xx_adc_probe()
158 return -ENOMEM; in lpc32xx_adc_probe()
162 st->adc_base = devm_ioremap(&pdev->dev, res->start, in lpc32xx_adc_probe()
164 if (!st->adc_base) { in lpc32xx_adc_probe()
165 dev_err(&pdev->dev, "failed mapping memory\n"); in lpc32xx_adc_probe()
166 return -EBUSY; in lpc32xx_adc_probe()
169 st->clk = devm_clk_get(&pdev->dev, NULL); in lpc32xx_adc_probe()
170 if (IS_ERR(st->clk)) { in lpc32xx_adc_probe()
171 dev_err(&pdev->dev, "failed getting clock\n"); in lpc32xx_adc_probe()
172 return PTR_ERR(st->clk); in lpc32xx_adc_probe()
177 return -ENXIO; in lpc32xx_adc_probe()
179 retval = devm_request_irq(&pdev->dev, irq, lpc32xx_adc_isr, 0, in lpc32xx_adc_probe()
182 dev_err(&pdev->dev, "failed requesting interrupt\n"); in lpc32xx_adc_probe()
186 st->vref = devm_regulator_get(&pdev->dev, "vref"); in lpc32xx_adc_probe()
187 if (IS_ERR(st->vref)) { in lpc32xx_adc_probe()
188 iodev->channels = lpc32xx_adc_iio_channels; in lpc32xx_adc_probe()
189 dev_info(&pdev->dev, in lpc32xx_adc_probe()
190 "Missing vref regulator: No scaling available\n"); in lpc32xx_adc_probe()
192 iodev->channels = lpc32xx_adc_iio_scale_channels; in lpc32xx_adc_probe()
197 init_completion(&st->completion); in lpc32xx_adc_probe()
199 iodev->name = LPC32XXAD_NAME; in lpc32xx_adc_probe()
200 iodev->info = &lpc32xx_adc_iio_info; in lpc32xx_adc_probe()
201 iodev->modes = INDIO_DIRECT_MODE; in lpc32xx_adc_probe()
202 iodev->num_channels = ARRAY_SIZE(lpc32xx_adc_iio_channels); in lpc32xx_adc_probe()
204 retval = devm_iio_device_register(&pdev->dev, iodev); in lpc32xx_adc_probe()
208 dev_info(&pdev->dev, "LPC32XX ADC driver loaded, IRQ %d\n", irq); in lpc32xx_adc_probe()
214 { .compatible = "nxp,lpc3220-adc" },
230 MODULE_DESCRIPTION("LPC32XX ADC driver");