Lines Matching +full:tsadc +full:- +full:apb

1 // SPDX-License-Identifier: GPL-2.0-or-later
89 writel_relaxed(8, info->regs + SARADC_DLY_PU_SOC); in rockchip_saradc_start_v1()
92 SARADC_CTRL_IRQ_ENABLE, info->regs + SARADC_CTRL); in rockchip_saradc_start_v1()
99 if (info->reset) in rockchip_saradc_start_v2()
100 rockchip_saradc_reset_controller(info->reset); in rockchip_saradc_start_v2()
102 writel_relaxed(0xc, info->regs + SARADC_T_DAS_SOC); in rockchip_saradc_start_v2()
103 writel_relaxed(0x20, info->regs + SARADC_T_PD_SOC); in rockchip_saradc_start_v2()
106 writel_relaxed(val, info->regs + SARADC2_END_INT_EN); in rockchip_saradc_start_v2()
111 writel(val, info->regs + SARADC2_CONV_CON); in rockchip_saradc_start_v2()
116 info->data->start(info, chn); in rockchip_saradc_start()
121 return readl_relaxed(info->regs + SARADC_DATA); in rockchip_saradc_read_v1()
129 writel_relaxed(0x1, info->regs + SARADC2_END_INT_ST); in rockchip_saradc_read_v2()
131 offset = SARADC2_DATA_BASE + info->last_chan->channel * 0x4; in rockchip_saradc_read_v2()
133 return readl_relaxed(info->regs + offset); in rockchip_saradc_read_v2()
138 return info->data->read(info); in rockchip_saradc_read()
143 writel_relaxed(0, info->regs + SARADC_CTRL); in rockchip_saradc_power_down_v1()
148 if (info->data->power_down) in rockchip_saradc_power_down()
149 info->data->power_down(info); in rockchip_saradc_power_down()
155 reinit_completion(&info->completion); in rockchip_saradc_conversion()
157 info->last_chan = chan; in rockchip_saradc_conversion()
158 rockchip_saradc_start(info, chan->channel); in rockchip_saradc_conversion()
160 if (!wait_for_completion_timeout(&info->completion, SARADC_TIMEOUT)) in rockchip_saradc_conversion()
161 return -ETIMEDOUT; in rockchip_saradc_conversion()
175 mutex_lock(&info->lock); in rockchip_saradc_read_raw()
180 mutex_unlock(&info->lock); in rockchip_saradc_read_raw()
184 *val = info->last_val; in rockchip_saradc_read_raw()
185 mutex_unlock(&info->lock); in rockchip_saradc_read_raw()
188 *val = info->uv_vref / 1000; in rockchip_saradc_read_raw()
189 *val2 = chan->scan_type.realbits; in rockchip_saradc_read_raw()
192 return -EINVAL; in rockchip_saradc_read_raw()
201 info->last_val = rockchip_saradc_read(info); in rockchip_saradc_isr()
202 info->last_val &= GENMASK(info->last_chan->scan_type.realbits - 1, 0); in rockchip_saradc_isr()
206 complete(&info->completion); in rockchip_saradc_isr()
322 .compatible = "rockchip,rk3066-tsadc",
325 .compatible = "rockchip,rk3399-saradc",
328 .compatible = "rockchip,rk3568-saradc",
331 .compatible = "rockchip,rk3588-saradc",
352 regulator_disable(info->vref); in rockchip_saradc_regulator_disable()
358 struct iio_dev *i_dev = pf->indio_dev; in rockchip_saradc_trigger_handler()
362 * @timestamp: will be 8-byte aligned automatically in rockchip_saradc_trigger_handler()
373 mutex_lock(&info->lock); in rockchip_saradc_trigger_handler()
376 const struct iio_chan_spec *chan = &i_dev->channels[i]; in rockchip_saradc_trigger_handler()
384 data.values[j] = info->last_val; in rockchip_saradc_trigger_handler()
390 mutex_unlock(&info->lock); in rockchip_saradc_trigger_handler()
392 iio_trigger_notify_done(i_dev->trig); in rockchip_saradc_trigger_handler()
404 info->uv_vref = (unsigned long)data; in rockchip_saradc_volt_notify()
413 regulator_unregister_notifier(info->vref, &info->nb); in rockchip_saradc_regulator_unreg_notifier()
420 struct device_node *np = pdev->dev.of_node; in rockchip_saradc_probe()
426 return -ENODEV; in rockchip_saradc_probe()
428 indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*info)); in rockchip_saradc_probe()
430 return dev_err_probe(&pdev->dev, -ENOMEM, in rockchip_saradc_probe()
435 match_data = of_device_get_match_data(&pdev->dev); in rockchip_saradc_probe()
437 return dev_err_probe(&pdev->dev, -ENODEV, in rockchip_saradc_probe()
440 info->data = match_data; in rockchip_saradc_probe()
443 if (info->data->num_channels > SARADC_MAX_CHANNELS) in rockchip_saradc_probe()
444 return dev_err_probe(&pdev->dev, -EINVAL, in rockchip_saradc_probe()
447 info->regs = devm_platform_ioremap_resource(pdev, 0); in rockchip_saradc_probe()
448 if (IS_ERR(info->regs)) in rockchip_saradc_probe()
449 return PTR_ERR(info->regs); in rockchip_saradc_probe()
455 info->reset = devm_reset_control_get_optional_exclusive(&pdev->dev, in rockchip_saradc_probe()
456 "saradc-apb"); in rockchip_saradc_probe()
457 if (IS_ERR(info->reset)) { in rockchip_saradc_probe()
458 ret = PTR_ERR(info->reset); in rockchip_saradc_probe()
459 return dev_err_probe(&pdev->dev, ret, "failed to get saradc-apb\n"); in rockchip_saradc_probe()
462 init_completion(&info->completion); in rockchip_saradc_probe()
468 ret = devm_request_irq(&pdev->dev, irq, rockchip_saradc_isr, in rockchip_saradc_probe()
469 0, dev_name(&pdev->dev), info); in rockchip_saradc_probe()
471 dev_err(&pdev->dev, "failed requesting irq %d\n", irq); in rockchip_saradc_probe()
475 info->vref = devm_regulator_get(&pdev->dev, "vref"); in rockchip_saradc_probe()
476 if (IS_ERR(info->vref)) in rockchip_saradc_probe()
477 return dev_err_probe(&pdev->dev, PTR_ERR(info->vref), in rockchip_saradc_probe()
480 if (info->reset) in rockchip_saradc_probe()
481 rockchip_saradc_reset_controller(info->reset); in rockchip_saradc_probe()
485 * This may become user-configurable in the future. in rockchip_saradc_probe()
487 ret = clk_set_rate(info->clk, info->data->clk_rate); in rockchip_saradc_probe()
489 return dev_err_probe(&pdev->dev, ret, in rockchip_saradc_probe()
492 ret = regulator_enable(info->vref); in rockchip_saradc_probe()
494 return dev_err_probe(&pdev->dev, ret, in rockchip_saradc_probe()
497 ret = devm_add_action_or_reset(&pdev->dev, in rockchip_saradc_probe()
500 return dev_err_probe(&pdev->dev, ret, in rockchip_saradc_probe()
503 ret = regulator_get_voltage(info->vref); in rockchip_saradc_probe()
507 info->uv_vref = ret; in rockchip_saradc_probe()
509 info->pclk = devm_clk_get_enabled(&pdev->dev, "apb_pclk"); in rockchip_saradc_probe()
510 if (IS_ERR(info->pclk)) in rockchip_saradc_probe()
511 return dev_err_probe(&pdev->dev, PTR_ERR(info->pclk), in rockchip_saradc_probe()
514 info->clk = devm_clk_get_enabled(&pdev->dev, "saradc"); in rockchip_saradc_probe()
515 if (IS_ERR(info->clk)) in rockchip_saradc_probe()
516 return dev_err_probe(&pdev->dev, PTR_ERR(info->clk), in rockchip_saradc_probe()
521 indio_dev->name = dev_name(&pdev->dev); in rockchip_saradc_probe()
522 indio_dev->info = &rockchip_saradc_iio_info; in rockchip_saradc_probe()
523 indio_dev->modes = INDIO_DIRECT_MODE; in rockchip_saradc_probe()
525 indio_dev->channels = info->data->channels; in rockchip_saradc_probe()
526 indio_dev->num_channels = info->data->num_channels; in rockchip_saradc_probe()
527 ret = devm_iio_triggered_buffer_setup(&indio_dev->dev, indio_dev, NULL, in rockchip_saradc_probe()
533 info->nb.notifier_call = rockchip_saradc_volt_notify; in rockchip_saradc_probe()
534 ret = regulator_register_notifier(info->vref, &info->nb); in rockchip_saradc_probe()
538 ret = devm_add_action_or_reset(&pdev->dev, in rockchip_saradc_probe()
544 mutex_init(&info->lock); in rockchip_saradc_probe()
546 return devm_iio_device_register(&pdev->dev, indio_dev); in rockchip_saradc_probe()
554 clk_disable_unprepare(info->clk); in rockchip_saradc_suspend()
555 clk_disable_unprepare(info->pclk); in rockchip_saradc_suspend()
556 regulator_disable(info->vref); in rockchip_saradc_suspend()
567 ret = regulator_enable(info->vref); in rockchip_saradc_resume()
571 ret = clk_prepare_enable(info->pclk); in rockchip_saradc_resume()
575 ret = clk_prepare_enable(info->clk); in rockchip_saradc_resume()
577 clk_disable_unprepare(info->pclk); in rockchip_saradc_resume()
589 .name = "rockchip-saradc",