Lines Matching refs:adc

93 static unsigned int rzg2l_adc_readl(struct rzg2l_adc *adc, u32 reg)  in rzg2l_adc_readl()  argument
95 return readl(adc->base + reg); in rzg2l_adc_readl()
98 static void rzg2l_adc_writel(struct rzg2l_adc *adc, unsigned int reg, u32 val) in rzg2l_adc_writel() argument
100 writel(val, adc->base + reg); in rzg2l_adc_writel()
103 static void rzg2l_adc_pwr(struct rzg2l_adc *adc, bool on) in rzg2l_adc_pwr() argument
107 reg = rzg2l_adc_readl(adc, RZG2L_ADM(0)); in rzg2l_adc_pwr()
112 rzg2l_adc_writel(adc, RZG2L_ADM(0), reg); in rzg2l_adc_pwr()
116 static void rzg2l_adc_start_stop(struct rzg2l_adc *adc, bool start) in rzg2l_adc_start_stop() argument
121 reg = rzg2l_adc_readl(adc, RZG2L_ADM(0)); in rzg2l_adc_start_stop()
126 rzg2l_adc_writel(adc, RZG2L_ADM(0), reg); in rzg2l_adc_start_stop()
133 reg = rzg2l_adc_readl(adc, RZG2L_ADM(0)); in rzg2l_adc_start_stop()
142 static void rzg2l_set_trigger(struct rzg2l_adc *adc) in rzg2l_set_trigger() argument
153 reg = rzg2l_adc_readl(adc, RZG2L_ADM(1)); in rzg2l_set_trigger()
158 rzg2l_adc_writel(adc, RZG2L_ADM(1), reg); in rzg2l_set_trigger()
161 static int rzg2l_adc_conversion_setup(struct rzg2l_adc *adc, u8 ch) in rzg2l_adc_conversion_setup() argument
165 if (rzg2l_adc_readl(adc, RZG2L_ADM(0)) & RZG2L_ADM0_ADBSY) in rzg2l_adc_conversion_setup()
168 rzg2l_set_trigger(adc); in rzg2l_adc_conversion_setup()
171 reg = rzg2l_adc_readl(adc, RZG2L_ADM(2)); in rzg2l_adc_conversion_setup()
174 rzg2l_adc_writel(adc, RZG2L_ADM(2), reg); in rzg2l_adc_conversion_setup()
182 reg = rzg2l_adc_readl(adc, RZG2L_ADINT); in rzg2l_adc_conversion_setup()
186 rzg2l_adc_writel(adc, RZG2L_ADINT, reg); in rzg2l_adc_conversion_setup()
201 static int rzg2l_adc_conversion(struct iio_dev *indio_dev, struct rzg2l_adc *adc, u8 ch) in rzg2l_adc_conversion() argument
209 ret = rzg2l_adc_conversion_setup(adc, ch); in rzg2l_adc_conversion()
215 reinit_completion(&adc->completion); in rzg2l_adc_conversion()
217 rzg2l_adc_start_stop(adc, true); in rzg2l_adc_conversion()
219 if (!wait_for_completion_timeout(&adc->completion, RZG2L_ADC_TIMEOUT)) { in rzg2l_adc_conversion()
220 rzg2l_adc_writel(adc, RZG2L_ADINT, in rzg2l_adc_conversion()
221 rzg2l_adc_readl(adc, RZG2L_ADINT) & ~RZG2L_ADINT_INTEN_MASK); in rzg2l_adc_conversion()
222 rzg2l_adc_start_stop(adc, false); in rzg2l_adc_conversion()
234 struct rzg2l_adc *adc = iio_priv(indio_dev); in rzg2l_adc_read_raw() local
243 mutex_lock(&adc->lock); in rzg2l_adc_read_raw()
245 ret = rzg2l_adc_conversion(indio_dev, adc, ch); in rzg2l_adc_read_raw()
247 mutex_unlock(&adc->lock); in rzg2l_adc_read_raw()
250 *val = adc->last_val[ch]; in rzg2l_adc_read_raw()
251 mutex_unlock(&adc->lock); in rzg2l_adc_read_raw()
274 struct rzg2l_adc *adc = dev_id; in rzg2l_adc_isr() local
279 reg = rzg2l_adc_readl(adc, RZG2L_ADSTS); in rzg2l_adc_isr()
283 rzg2l_adc_writel(adc, RZG2L_ADSTS, reg); in rzg2l_adc_isr()
292 adc->last_val[ch] = rzg2l_adc_readl(adc, RZG2L_ADCR(ch)) & RZG2L_ADCR_AD_MASK; in rzg2l_adc_isr()
295 rzg2l_adc_writel(adc, RZG2L_ADSTS, reg); in rzg2l_adc_isr()
297 complete(&adc->completion); in rzg2l_adc_isr()
302 static int rzg2l_adc_parse_properties(struct platform_device *pdev, struct rzg2l_adc *adc) in rzg2l_adc_parse_properties() argument
355 adc->data = data; in rzg2l_adc_parse_properties()
360 static int rzg2l_adc_hw_init(struct rzg2l_adc *adc) in rzg2l_adc_hw_init() argument
366 ret = clk_prepare_enable(adc->pclk); in rzg2l_adc_hw_init()
371 reg = rzg2l_adc_readl(adc, RZG2L_ADM(0)); in rzg2l_adc_hw_init()
373 rzg2l_adc_writel(adc, RZG2L_ADM(0), reg); in rzg2l_adc_hw_init()
375 while (!(rzg2l_adc_readl(adc, RZG2L_ADM(0)) & RZG2L_ADM0_SRESB)) { in rzg2l_adc_hw_init()
385 reg = rzg2l_adc_readl(adc, RZG2L_ADIVC); in rzg2l_adc_hw_init()
388 rzg2l_adc_writel(adc, RZG2L_ADIVC, reg); in rzg2l_adc_hw_init()
396 reg = rzg2l_adc_readl(adc, RZG2L_ADM(3)); in rzg2l_adc_hw_init()
401 rzg2l_adc_writel(adc, RZG2L_ADM(3), reg); in rzg2l_adc_hw_init()
404 clk_disable_unprepare(adc->pclk); in rzg2l_adc_hw_init()
432 struct rzg2l_adc *adc; in rzg2l_adc_probe() local
436 indio_dev = devm_iio_device_alloc(dev, sizeof(*adc)); in rzg2l_adc_probe()
440 adc = iio_priv(indio_dev); in rzg2l_adc_probe()
442 ret = rzg2l_adc_parse_properties(pdev, adc); in rzg2l_adc_probe()
446 mutex_init(&adc->lock); in rzg2l_adc_probe()
448 adc->base = devm_platform_ioremap_resource(pdev, 0); in rzg2l_adc_probe()
449 if (IS_ERR(adc->base)) in rzg2l_adc_probe()
450 return PTR_ERR(adc->base); in rzg2l_adc_probe()
452 adc->pclk = devm_clk_get(dev, "pclk"); in rzg2l_adc_probe()
453 if (IS_ERR(adc->pclk)) { in rzg2l_adc_probe()
455 return PTR_ERR(adc->pclk); in rzg2l_adc_probe()
458 adc->adclk = devm_clk_get(dev, "adclk"); in rzg2l_adc_probe()
459 if (IS_ERR(adc->adclk)) { in rzg2l_adc_probe()
461 return PTR_ERR(adc->adclk); in rzg2l_adc_probe()
464 adc->adrstn = devm_reset_control_get_exclusive(dev, "adrst-n"); in rzg2l_adc_probe()
465 if (IS_ERR(adc->adrstn)) { in rzg2l_adc_probe()
467 return PTR_ERR(adc->adrstn); in rzg2l_adc_probe()
470 adc->presetn = devm_reset_control_get_exclusive(dev, "presetn"); in rzg2l_adc_probe()
471 if (IS_ERR(adc->presetn)) { in rzg2l_adc_probe()
473 return PTR_ERR(adc->presetn); in rzg2l_adc_probe()
476 ret = reset_control_deassert(adc->adrstn); in rzg2l_adc_probe()
483 rzg2l_adc_reset_assert, adc->adrstn); in rzg2l_adc_probe()
490 ret = reset_control_deassert(adc->presetn); in rzg2l_adc_probe()
497 rzg2l_adc_reset_assert, adc->presetn); in rzg2l_adc_probe()
504 ret = rzg2l_adc_hw_init(adc); in rzg2l_adc_probe()
515 0, dev_name(dev), adc); in rzg2l_adc_probe()
519 init_completion(&adc->completion); in rzg2l_adc_probe()
526 indio_dev->channels = adc->data->channels; in rzg2l_adc_probe()
527 indio_dev->num_channels = adc->data->num_channels; in rzg2l_adc_probe()
553 struct rzg2l_adc *adc = iio_priv(indio_dev); in rzg2l_adc_pm_runtime_suspend() local
555 rzg2l_adc_pwr(adc, false); in rzg2l_adc_pm_runtime_suspend()
556 clk_disable_unprepare(adc->adclk); in rzg2l_adc_pm_runtime_suspend()
557 clk_disable_unprepare(adc->pclk); in rzg2l_adc_pm_runtime_suspend()
565 struct rzg2l_adc *adc = iio_priv(indio_dev); in rzg2l_adc_pm_runtime_resume() local
568 ret = clk_prepare_enable(adc->pclk); in rzg2l_adc_pm_runtime_resume()
572 ret = clk_prepare_enable(adc->adclk); in rzg2l_adc_pm_runtime_resume()
574 clk_disable_unprepare(adc->pclk); in rzg2l_adc_pm_runtime_resume()
578 rzg2l_adc_pwr(adc, true); in rzg2l_adc_pm_runtime_resume()