Lines Matching +full:lpc1850 +full:- +full:adc
1 // SPDX-License-Identifier: GPL-2.0-only
3 * IIO ADC driver for NXP LPC18xx ADC
8 * - Hardware triggers
9 * - Burst mode
10 * - Interrupts
11 * - DMA
27 /* LPC18XX ADC registers and bits */
70 static int lpc18xx_adc_read_chan(struct lpc18xx_adc *adc, unsigned int ch) in lpc18xx_adc_read_chan() argument
75 reg = adc->cr_reg | BIT(ch) | LPC18XX_ADC_CR_START_NOW; in lpc18xx_adc_read_chan()
76 writel(reg, adc->base + LPC18XX_ADC_CR); in lpc18xx_adc_read_chan()
78 ret = readl_poll_timeout(adc->base + LPC18XX_ADC_GDR, reg, in lpc18xx_adc_read_chan()
81 dev_warn(adc->dev, "adc read timed out\n"); in lpc18xx_adc_read_chan()
92 struct lpc18xx_adc *adc = iio_priv(indio_dev); in lpc18xx_adc_read_raw() local
96 mutex_lock(&adc->lock); in lpc18xx_adc_read_raw()
97 *val = lpc18xx_adc_read_chan(adc, chan->channel); in lpc18xx_adc_read_raw()
98 mutex_unlock(&adc->lock); in lpc18xx_adc_read_raw()
105 *val = regulator_get_voltage(adc->vref) / 1000; in lpc18xx_adc_read_raw()
111 return -EINVAL; in lpc18xx_adc_read_raw()
121 struct lpc18xx_adc *adc; in lpc18xx_adc_probe() local
126 indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*adc)); in lpc18xx_adc_probe()
128 return -ENOMEM; in lpc18xx_adc_probe()
131 adc = iio_priv(indio_dev); in lpc18xx_adc_probe()
132 adc->dev = &pdev->dev; in lpc18xx_adc_probe()
133 mutex_init(&adc->lock); in lpc18xx_adc_probe()
135 adc->base = devm_platform_ioremap_resource(pdev, 0); in lpc18xx_adc_probe()
136 if (IS_ERR(adc->base)) in lpc18xx_adc_probe()
137 return PTR_ERR(adc->base); in lpc18xx_adc_probe()
139 adc->clk = devm_clk_get(&pdev->dev, NULL); in lpc18xx_adc_probe()
140 if (IS_ERR(adc->clk)) { in lpc18xx_adc_probe()
141 dev_err(&pdev->dev, "error getting clock\n"); in lpc18xx_adc_probe()
142 return PTR_ERR(adc->clk); in lpc18xx_adc_probe()
145 rate = clk_get_rate(adc->clk); in lpc18xx_adc_probe()
148 adc->vref = devm_regulator_get(&pdev->dev, "vref"); in lpc18xx_adc_probe()
149 if (IS_ERR(adc->vref)) { in lpc18xx_adc_probe()
150 dev_err(&pdev->dev, "error getting regulator\n"); in lpc18xx_adc_probe()
151 return PTR_ERR(adc->vref); in lpc18xx_adc_probe()
154 indio_dev->name = dev_name(&pdev->dev); in lpc18xx_adc_probe()
155 indio_dev->info = &lpc18xx_adc_info; in lpc18xx_adc_probe()
156 indio_dev->modes = INDIO_DIRECT_MODE; in lpc18xx_adc_probe()
157 indio_dev->channels = lpc18xx_adc_iio_channels; in lpc18xx_adc_probe()
158 indio_dev->num_channels = ARRAY_SIZE(lpc18xx_adc_iio_channels); in lpc18xx_adc_probe()
160 ret = regulator_enable(adc->vref); in lpc18xx_adc_probe()
162 dev_err(&pdev->dev, "unable to enable regulator\n"); in lpc18xx_adc_probe()
166 ret = clk_prepare_enable(adc->clk); in lpc18xx_adc_probe()
168 dev_err(&pdev->dev, "unable to enable clock\n"); in lpc18xx_adc_probe()
172 adc->cr_reg = (clkdiv << LPC18XX_ADC_CR_CLKDIV_SHIFT) | in lpc18xx_adc_probe()
174 writel(adc->cr_reg, adc->base + LPC18XX_ADC_CR); in lpc18xx_adc_probe()
178 dev_err(&pdev->dev, "unable to register device\n"); in lpc18xx_adc_probe()
185 writel(0, adc->base + LPC18XX_ADC_CR); in lpc18xx_adc_probe()
186 clk_disable_unprepare(adc->clk); in lpc18xx_adc_probe()
188 regulator_disable(adc->vref); in lpc18xx_adc_probe()
195 struct lpc18xx_adc *adc = iio_priv(indio_dev); in lpc18xx_adc_remove() local
199 writel(0, adc->base + LPC18XX_ADC_CR); in lpc18xx_adc_remove()
200 clk_disable_unprepare(adc->clk); in lpc18xx_adc_remove()
201 regulator_disable(adc->vref); in lpc18xx_adc_remove()
207 { .compatible = "nxp,lpc1850-adc" },
216 .name = "lpc18xx-adc",
222 MODULE_DESCRIPTION("LPC18xx ADC driver");