Lines Matching +full:imx7d +full:- +full:adc
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Freescale i.MX7D ADC driver
24 /* ADC register */
181 info->adc_feature.clk_pre_div = IMX7D_ADC_ANALOG_CLK_PRE_DIV_4; in imx7d_adc_feature_config()
182 info->adc_feature.avg_num = IMX7D_ADC_AVERAGE_NUM_32; in imx7d_adc_feature_config()
183 info->adc_feature.core_time_unit = 1; in imx7d_adc_feature_config()
188 struct imx7d_adc_feature *adc_feature = &info->adc_feature; in imx7d_adc_sample_rate_set()
200 readl(info->regs + i * IMX7D_EACH_CHANNEL_REG_OFFSET); in imx7d_adc_sample_rate_set()
203 info->regs + i * IMX7D_EACH_CHANNEL_REG_OFFSET); in imx7d_adc_sample_rate_set()
206 adc_analogure_clk = imx7d_adc_analogue_clk[adc_feature->clk_pre_div]; in imx7d_adc_sample_rate_set()
208 info->pre_div_num = adc_analogure_clk.pre_div; in imx7d_adc_sample_rate_set()
210 sample_rate |= adc_feature->core_time_unit; in imx7d_adc_sample_rate_set()
211 writel(sample_rate, info->regs + IMX7D_REG_ADC_TIMER_UNIT); in imx7d_adc_sample_rate_set()
218 /* power up and enable adc analogue core */ in imx7d_adc_hw_init()
219 cfg = readl(info->regs + IMX7D_REG_ADC_ADC_CFG); in imx7d_adc_hw_init()
223 writel(cfg, info->regs + IMX7D_REG_ADC_ADC_CFG); in imx7d_adc_hw_init()
227 info->regs + IMX7D_REG_ADC_INT_SIG_EN); in imx7d_adc_hw_init()
229 info->regs + IMX7D_REG_ADC_INT_EN); in imx7d_adc_hw_init()
240 channel = info->channel; in imx7d_adc_channel_set()
259 cfg2 = readl(info->regs + IMX7D_EACH_CHANNEL_REG_OFFSET * channel + in imx7d_adc_channel_set()
262 cfg2 |= imx7d_adc_average_num[info->adc_feature.avg_num]; in imx7d_adc_channel_set()
268 writel(cfg2, info->regs + IMX7D_EACH_CHANNEL_REG_OFFSET * channel + in imx7d_adc_channel_set()
270 writel(cfg1, info->regs + IMX7D_EACH_CHANNEL_REG_OFFSET * channel); in imx7d_adc_channel_set()
276 u32 core_time_unit = info->adc_feature.core_time_unit; in imx7d_adc_get_sample_rate()
279 analogue_core_clk = IMX7D_ADC_INPUT_CLK / info->pre_div_num; in imx7d_adc_get_sample_rate()
298 mutex_lock(&info->lock); in imx7d_adc_read_raw()
299 reinit_completion(&info->completion); in imx7d_adc_read_raw()
301 channel = chan->channel & 0x03; in imx7d_adc_read_raw()
302 info->channel = channel; in imx7d_adc_read_raw()
306 (&info->completion, IMX7D_ADC_TIMEOUT); in imx7d_adc_read_raw()
308 mutex_unlock(&info->lock); in imx7d_adc_read_raw()
309 return -ETIMEDOUT; in imx7d_adc_read_raw()
312 mutex_unlock(&info->lock); in imx7d_adc_read_raw()
316 *val = info->value; in imx7d_adc_read_raw()
317 mutex_unlock(&info->lock); in imx7d_adc_read_raw()
321 info->vref_uv = regulator_get_voltage(info->vref); in imx7d_adc_read_raw()
322 *val = info->vref_uv / 1000; in imx7d_adc_read_raw()
331 return -EINVAL; in imx7d_adc_read_raw()
340 channel = info->channel & 0x03; in imx7d_adc_read_data()
349 value = readl(info->regs + IMX7D_REG_ADC_CHA_B_CNV_RSLT); in imx7d_adc_read_data()
351 value = readl(info->regs + IMX7D_REG_ADC_CHC_D_CNV_RSLT); in imx7d_adc_read_data()
365 status = readl(info->regs + IMX7D_REG_ADC_INT_STATUS); in imx7d_adc_isr()
367 info->value = imx7d_adc_read_data(info); in imx7d_adc_isr()
368 complete(&info->completion); in imx7d_adc_isr()
377 writel(status, info->regs + IMX7D_REG_ADC_INT_STATUS); in imx7d_adc_isr()
385 dev_err(info->dev, in imx7d_adc_isr()
386 "ADC got conversion time out interrupt: 0x%08x\n", in imx7d_adc_isr()
389 writel(status, info->regs + IMX7D_REG_ADC_INT_STATUS); in imx7d_adc_isr()
402 return -EINVAL; in imx7d_adc_reg_access()
404 *readval = readl(info->regs + reg); in imx7d_adc_reg_access()
415 { .compatible = "fsl,imx7d-adc", },
424 adc_cfg = readl(info->regs + IMX7D_REG_ADC_ADC_CFG); in imx7d_adc_power_down()
428 writel(adc_cfg, info->regs + IMX7D_REG_ADC_ADC_CFG); in imx7d_adc_power_down()
437 ret = regulator_enable(info->vref); in imx7d_adc_enable()
439 dev_err(info->dev, in imx7d_adc_enable()
440 "Can't enable adc reference top voltage, err = %d\n", in imx7d_adc_enable()
445 ret = clk_prepare_enable(info->clk); in imx7d_adc_enable()
447 dev_err(info->dev, in imx7d_adc_enable()
449 regulator_disable(info->vref); in imx7d_adc_enable()
465 clk_disable_unprepare(info->clk); in imx7d_adc_disable()
466 regulator_disable(info->vref); in imx7d_adc_disable()
480 struct device *dev = &pdev->dev; in imx7d_adc_probe()
486 dev_err(&pdev->dev, "Failed allocating iio device\n"); in imx7d_adc_probe()
487 return -ENOMEM; in imx7d_adc_probe()
491 info->dev = dev; in imx7d_adc_probe()
493 info->regs = devm_platform_ioremap_resource(pdev, 0); in imx7d_adc_probe()
494 if (IS_ERR(info->regs)) in imx7d_adc_probe()
495 return PTR_ERR(info->regs); in imx7d_adc_probe()
501 info->clk = devm_clk_get(dev, "adc"); in imx7d_adc_probe()
502 if (IS_ERR(info->clk)) in imx7d_adc_probe()
503 return dev_err_probe(dev, PTR_ERR(info->clk), "Failed getting clock\n"); in imx7d_adc_probe()
505 info->vref = devm_regulator_get(dev, "vref"); in imx7d_adc_probe()
506 if (IS_ERR(info->vref)) in imx7d_adc_probe()
507 return dev_err_probe(dev, PTR_ERR(info->vref), in imx7d_adc_probe()
512 init_completion(&info->completion); in imx7d_adc_probe()
514 indio_dev->name = dev_name(dev); in imx7d_adc_probe()
515 indio_dev->info = &imx7d_adc_iio_info; in imx7d_adc_probe()
516 indio_dev->modes = INDIO_DIRECT_MODE; in imx7d_adc_probe()
517 indio_dev->channels = imx7d_adc_iio_channels; in imx7d_adc_probe()
518 indio_dev->num_channels = ARRAY_SIZE(imx7d_adc_iio_channels); in imx7d_adc_probe()
536 mutex_init(&info->lock); in imx7d_adc_probe()
540 dev_err(&pdev->dev, "Couldn't register the device.\n"); in imx7d_adc_probe()
562 MODULE_DESCRIPTION("Freescale IMX7D ADC driver");