Lines Matching +full:lpc3220 +full:- +full:clk
1 // SPDX-License-Identifier: GPL-2.0+
3 * lpc32xx_adc.c - Support for ADC in LPC32XX
5 * 3-channel, 10-bit ADC
10 #include <linux/clk.h>
46 #define LPC32XXAD_NAME "lpc32xx-adc"
50 struct clk *clk; member
70 mutex_lock(&st->lock); in lpc32xx_read_raw()
71 ret = clk_prepare_enable(st->clk); in lpc32xx_read_raw()
73 mutex_unlock(&st->lock); in lpc32xx_read_raw()
77 __raw_writel(LPC32XXAD_INTERNAL | (chan->address) | in lpc32xx_read_raw()
79 LPC32XXAD_SELECT(st->adc_base)); in lpc32xx_read_raw()
82 LPC32XXAD_CTRL(st->adc_base)); in lpc32xx_read_raw()
83 wait_for_completion(&st->completion); /* set by ISR */ in lpc32xx_read_raw()
84 clk_disable_unprepare(st->clk); in lpc32xx_read_raw()
85 *val = st->value; in lpc32xx_read_raw()
86 mutex_unlock(&st->lock); in lpc32xx_read_raw()
91 *val = regulator_get_voltage(st->vref) / 1000; in lpc32xx_read_raw()
96 return -EINVAL; in lpc32xx_read_raw()
138 st->value = __raw_readl(LPC32XXAD_VALUE(st->adc_base)) & in lpc32xx_adc_isr()
140 complete(&st->completion); in lpc32xx_adc_isr()
149 int retval = -ENODEV; in lpc32xx_adc_probe()
155 dev_err(&pdev->dev, "failed to get platform I/O memory\n"); in lpc32xx_adc_probe()
156 return -ENXIO; in lpc32xx_adc_probe()
159 iodev = devm_iio_device_alloc(&pdev->dev, sizeof(*st)); in lpc32xx_adc_probe()
161 return -ENOMEM; in lpc32xx_adc_probe()
165 st->adc_base = devm_ioremap(&pdev->dev, res->start, in lpc32xx_adc_probe()
167 if (!st->adc_base) { in lpc32xx_adc_probe()
168 dev_err(&pdev->dev, "failed mapping memory\n"); in lpc32xx_adc_probe()
169 return -EBUSY; in lpc32xx_adc_probe()
172 st->clk = devm_clk_get(&pdev->dev, NULL); in lpc32xx_adc_probe()
173 if (IS_ERR(st->clk)) { in lpc32xx_adc_probe()
174 dev_err(&pdev->dev, "failed getting clock\n"); in lpc32xx_adc_probe()
175 return PTR_ERR(st->clk); in lpc32xx_adc_probe()
182 retval = devm_request_irq(&pdev->dev, irq, lpc32xx_adc_isr, 0, in lpc32xx_adc_probe()
185 dev_err(&pdev->dev, "failed requesting interrupt\n"); in lpc32xx_adc_probe()
189 st->vref = devm_regulator_get(&pdev->dev, "vref"); in lpc32xx_adc_probe()
190 if (IS_ERR(st->vref)) { in lpc32xx_adc_probe()
191 iodev->channels = lpc32xx_adc_iio_channels; in lpc32xx_adc_probe()
192 dev_info(&pdev->dev, in lpc32xx_adc_probe()
195 iodev->channels = lpc32xx_adc_iio_scale_channels; in lpc32xx_adc_probe()
200 init_completion(&st->completion); in lpc32xx_adc_probe()
202 iodev->name = LPC32XXAD_NAME; in lpc32xx_adc_probe()
203 iodev->info = &lpc32xx_adc_iio_info; in lpc32xx_adc_probe()
204 iodev->modes = INDIO_DIRECT_MODE; in lpc32xx_adc_probe()
205 iodev->num_channels = ARRAY_SIZE(lpc32xx_adc_iio_channels); in lpc32xx_adc_probe()
207 mutex_init(&st->lock); in lpc32xx_adc_probe()
209 retval = devm_iio_device_register(&pdev->dev, iodev); in lpc32xx_adc_probe()
213 dev_info(&pdev->dev, "LPC32XX ADC driver loaded, IRQ %d\n", irq); in lpc32xx_adc_probe()
219 { .compatible = "nxp,lpc3220-adc" },