Lines Matching refs:adc

119 static void imx8qxp_adc_reset(struct imx8qxp_adc *adc)  in imx8qxp_adc_reset()  argument
124 ctrl = readl(adc->regs + IMX8QXP_ADR_ADC_CTRL); in imx8qxp_adc_reset()
126 writel(ctrl, adc->regs + IMX8QXP_ADR_ADC_CTRL); in imx8qxp_adc_reset()
129 writel(ctrl, adc->regs + IMX8QXP_ADR_ADC_CTRL); in imx8qxp_adc_reset()
133 writel(ctrl, adc->regs + IMX8QXP_ADR_ADC_CTRL); in imx8qxp_adc_reset()
136 static void imx8qxp_adc_reg_config(struct imx8qxp_adc *adc, int channel) in imx8qxp_adc_reg_config() argument
146 writel(adc_cfg, adc->regs + IMX8QXP_ADR_ADC_CFG); in imx8qxp_adc_reg_config()
153 writel(adc_tctrl, adc->regs + IMX8QXP_ADR_ADC_TCTRL(0)); in imx8qxp_adc_reg_config()
161 writel(adc_cmdl, adc->regs + IMX8QXP_ADR_ADC_CMDL(0)); in imx8qxp_adc_reg_config()
169 writel(adc_cmdh, adc->regs + IMX8QXP_ADR_ADC_CMDH(0)); in imx8qxp_adc_reg_config()
172 static void imx8qxp_adc_fifo_config(struct imx8qxp_adc *adc) in imx8qxp_adc_fifo_config() argument
176 fifo_ctrl = readl(adc->regs + IMX8QXP_ADR_ADC_FCTRL); in imx8qxp_adc_fifo_config()
180 writel(fifo_ctrl, adc->regs + IMX8QXP_ADR_ADC_FCTRL); in imx8qxp_adc_fifo_config()
183 interrupt_en = readl(adc->regs + IMX8QXP_ADR_ADC_IE); in imx8qxp_adc_fifo_config()
185 writel(interrupt_en, adc->regs + IMX8QXP_ADR_ADC_IE); in imx8qxp_adc_fifo_config()
188 static void imx8qxp_adc_disable(struct imx8qxp_adc *adc) in imx8qxp_adc_disable() argument
192 ctrl = readl(adc->regs + IMX8QXP_ADR_ADC_CTRL); in imx8qxp_adc_disable()
194 writel(ctrl, adc->regs + IMX8QXP_ADR_ADC_CTRL); in imx8qxp_adc_disable()
201 struct imx8qxp_adc *adc = iio_priv(indio_dev); in imx8qxp_adc_read_raw() local
202 struct device *dev = adc->dev; in imx8qxp_adc_read_raw()
211 mutex_lock(&adc->lock); in imx8qxp_adc_read_raw()
212 reinit_completion(&adc->completion); in imx8qxp_adc_read_raw()
214 imx8qxp_adc_reg_config(adc, chan->channel); in imx8qxp_adc_read_raw()
216 imx8qxp_adc_fifo_config(adc); in imx8qxp_adc_read_raw()
219 ctrl = readl(adc->regs + IMX8QXP_ADR_ADC_CTRL); in imx8qxp_adc_read_raw()
221 writel(ctrl, adc->regs + IMX8QXP_ADR_ADC_CTRL); in imx8qxp_adc_read_raw()
223 writel(1, adc->regs + IMX8QXP_ADR_ADC_SWTRIG); in imx8qxp_adc_read_raw()
225 ret = wait_for_completion_interruptible_timeout(&adc->completion, in imx8qxp_adc_read_raw()
232 mutex_unlock(&adc->lock); in imx8qxp_adc_read_raw()
236 mutex_unlock(&adc->lock); in imx8qxp_adc_read_raw()
241 readl(adc->regs + IMX8QXP_ADR_ADC_RESFIFO)); in imx8qxp_adc_read_raw()
243 mutex_unlock(&adc->lock); in imx8qxp_adc_read_raw()
247 vref_uv = regulator_get_voltage(adc->vref); in imx8qxp_adc_read_raw()
253 *val = clk_get_rate(adc->clk) / 3; in imx8qxp_adc_read_raw()
263 struct imx8qxp_adc *adc = dev_id; in imx8qxp_adc_isr() local
267 readl(adc->regs + IMX8QXP_ADR_ADC_FCTRL)); in imx8qxp_adc_isr()
270 complete(&adc->completion); in imx8qxp_adc_isr()
278 struct imx8qxp_adc *adc = iio_priv(indio_dev); in imx8qxp_adc_reg_access() local
279 struct device *dev = adc->dev; in imx8qxp_adc_reg_access()
286 *readval = readl(adc->regs + reg); in imx8qxp_adc_reg_access()
301 struct imx8qxp_adc *adc; in imx8qxp_adc_probe() local
307 indio_dev = devm_iio_device_alloc(dev, sizeof(*adc)); in imx8qxp_adc_probe()
313 adc = iio_priv(indio_dev); in imx8qxp_adc_probe()
314 adc->dev = dev; in imx8qxp_adc_probe()
316 mutex_init(&adc->lock); in imx8qxp_adc_probe()
317 adc->regs = devm_platform_ioremap_resource(pdev, 0); in imx8qxp_adc_probe()
318 if (IS_ERR(adc->regs)) in imx8qxp_adc_probe()
319 return PTR_ERR(adc->regs); in imx8qxp_adc_probe()
325 adc->clk = devm_clk_get(dev, "per"); in imx8qxp_adc_probe()
326 if (IS_ERR(adc->clk)) in imx8qxp_adc_probe()
327 return dev_err_probe(dev, PTR_ERR(adc->clk), "Failed getting clock\n"); in imx8qxp_adc_probe()
329 adc->ipg_clk = devm_clk_get(dev, "ipg"); in imx8qxp_adc_probe()
330 if (IS_ERR(adc->ipg_clk)) in imx8qxp_adc_probe()
331 return dev_err_probe(dev, PTR_ERR(adc->ipg_clk), "Failed getting clock\n"); in imx8qxp_adc_probe()
333 adc->vref = devm_regulator_get(dev, "vref"); in imx8qxp_adc_probe()
334 if (IS_ERR(adc->vref)) in imx8qxp_adc_probe()
335 return dev_err_probe(dev, PTR_ERR(adc->vref), "Failed getting reference voltage\n"); in imx8qxp_adc_probe()
337 ret = regulator_enable(adc->vref); in imx8qxp_adc_probe()
345 init_completion(&adc->completion); in imx8qxp_adc_probe()
353 ret = clk_prepare_enable(adc->clk); in imx8qxp_adc_probe()
359 ret = clk_prepare_enable(adc->ipg_clk); in imx8qxp_adc_probe()
365 ret = devm_request_irq(dev, irq, imx8qxp_adc_isr, 0, ADC_DRIVER_NAME, adc); in imx8qxp_adc_probe()
371 imx8qxp_adc_reset(adc); in imx8qxp_adc_probe()
375 imx8qxp_adc_disable(adc); in imx8qxp_adc_probe()
388 clk_disable_unprepare(adc->ipg_clk); in imx8qxp_adc_probe()
390 clk_disable_unprepare(adc->clk); in imx8qxp_adc_probe()
392 regulator_disable(adc->vref); in imx8qxp_adc_probe()
400 struct imx8qxp_adc *adc = iio_priv(indio_dev); in imx8qxp_adc_remove() local
401 struct device *dev = adc->dev; in imx8qxp_adc_remove()
407 imx8qxp_adc_disable(adc); in imx8qxp_adc_remove()
409 clk_disable_unprepare(adc->clk); in imx8qxp_adc_remove()
410 clk_disable_unprepare(adc->ipg_clk); in imx8qxp_adc_remove()
411 regulator_disable(adc->vref); in imx8qxp_adc_remove()
422 struct imx8qxp_adc *adc = iio_priv(indio_dev); in imx8qxp_adc_runtime_suspend() local
424 imx8qxp_adc_disable(adc); in imx8qxp_adc_runtime_suspend()
426 clk_disable_unprepare(adc->clk); in imx8qxp_adc_runtime_suspend()
427 clk_disable_unprepare(adc->ipg_clk); in imx8qxp_adc_runtime_suspend()
428 regulator_disable(adc->vref); in imx8qxp_adc_runtime_suspend()
436 struct imx8qxp_adc *adc = iio_priv(indio_dev); in imx8qxp_adc_runtime_resume() local
439 ret = regulator_enable(adc->vref); in imx8qxp_adc_runtime_resume()
445 ret = clk_prepare_enable(adc->clk); in imx8qxp_adc_runtime_resume()
451 ret = clk_prepare_enable(adc->ipg_clk); in imx8qxp_adc_runtime_resume()
457 imx8qxp_adc_reset(adc); in imx8qxp_adc_runtime_resume()
462 clk_disable_unprepare(adc->clk); in imx8qxp_adc_runtime_resume()
465 regulator_disable(adc->vref); in imx8qxp_adc_runtime_resume()