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()
371 mutex_lock(&info->lock); in rockchip_saradc_trigger_handler()
373 for_each_set_bit(i, i_dev->active_scan_mask, i_dev->masklength) { in rockchip_saradc_trigger_handler()
374 const struct iio_chan_spec *chan = &i_dev->channels[i]; in rockchip_saradc_trigger_handler()
382 data.values[j] = info->last_val; in rockchip_saradc_trigger_handler()
388 mutex_unlock(&info->lock); in rockchip_saradc_trigger_handler()
390 iio_trigger_notify_done(i_dev->trig); in rockchip_saradc_trigger_handler()
402 info->uv_vref = (unsigned long)data; in rockchip_saradc_volt_notify()
411 regulator_unregister_notifier(info->vref, &info->nb); in rockchip_saradc_regulator_unreg_notifier()
418 struct device_node *np = pdev->dev.of_node; in rockchip_saradc_probe()
424 return -ENODEV; in rockchip_saradc_probe()
426 indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*info)); in rockchip_saradc_probe()
428 return dev_err_probe(&pdev->dev, -ENOMEM, in rockchip_saradc_probe()
433 match_data = of_device_get_match_data(&pdev->dev); in rockchip_saradc_probe()
435 return dev_err_probe(&pdev->dev, -ENODEV, in rockchip_saradc_probe()
438 info->data = match_data; in rockchip_saradc_probe()
441 if (info->data->num_channels > SARADC_MAX_CHANNELS) in rockchip_saradc_probe()
442 return dev_err_probe(&pdev->dev, -EINVAL, in rockchip_saradc_probe()
445 info->regs = devm_platform_ioremap_resource(pdev, 0); in rockchip_saradc_probe()
446 if (IS_ERR(info->regs)) in rockchip_saradc_probe()
447 return PTR_ERR(info->regs); in rockchip_saradc_probe()
453 info->reset = devm_reset_control_get_exclusive(&pdev->dev, in rockchip_saradc_probe()
454 "saradc-apb"); in rockchip_saradc_probe()
455 if (IS_ERR(info->reset)) { in rockchip_saradc_probe()
456 ret = PTR_ERR(info->reset); in rockchip_saradc_probe()
457 if (ret != -ENOENT) in rockchip_saradc_probe()
458 return dev_err_probe(&pdev->dev, ret, in rockchip_saradc_probe()
459 "failed to get saradc-apb\n"); in rockchip_saradc_probe()
461 dev_dbg(&pdev->dev, "no reset control found\n"); in rockchip_saradc_probe()
462 info->reset = NULL; in rockchip_saradc_probe()
465 init_completion(&info->completion); in rockchip_saradc_probe()
471 ret = devm_request_irq(&pdev->dev, irq, rockchip_saradc_isr, in rockchip_saradc_probe()
472 0, dev_name(&pdev->dev), info); in rockchip_saradc_probe()
474 dev_err(&pdev->dev, "failed requesting irq %d\n", irq); in rockchip_saradc_probe()
478 info->vref = devm_regulator_get(&pdev->dev, "vref"); in rockchip_saradc_probe()
479 if (IS_ERR(info->vref)) in rockchip_saradc_probe()
480 return dev_err_probe(&pdev->dev, PTR_ERR(info->vref), in rockchip_saradc_probe()
483 if (info->reset) in rockchip_saradc_probe()
484 rockchip_saradc_reset_controller(info->reset); in rockchip_saradc_probe()
488 * This may become user-configurable in the future. in rockchip_saradc_probe()
490 ret = clk_set_rate(info->clk, info->data->clk_rate); in rockchip_saradc_probe()
492 return dev_err_probe(&pdev->dev, ret, in rockchip_saradc_probe()
495 ret = regulator_enable(info->vref); in rockchip_saradc_probe()
497 return dev_err_probe(&pdev->dev, ret, in rockchip_saradc_probe()
500 ret = devm_add_action_or_reset(&pdev->dev, in rockchip_saradc_probe()
503 return dev_err_probe(&pdev->dev, ret, in rockchip_saradc_probe()
506 ret = regulator_get_voltage(info->vref); in rockchip_saradc_probe()
510 info->uv_vref = ret; in rockchip_saradc_probe()
512 info->pclk = devm_clk_get_enabled(&pdev->dev, "apb_pclk"); in rockchip_saradc_probe()
513 if (IS_ERR(info->pclk)) in rockchip_saradc_probe()
514 return dev_err_probe(&pdev->dev, PTR_ERR(info->pclk), in rockchip_saradc_probe()
517 info->clk = devm_clk_get_enabled(&pdev->dev, "saradc"); in rockchip_saradc_probe()
518 if (IS_ERR(info->clk)) in rockchip_saradc_probe()
519 return dev_err_probe(&pdev->dev, PTR_ERR(info->clk), in rockchip_saradc_probe()
524 indio_dev->name = dev_name(&pdev->dev); in rockchip_saradc_probe()
525 indio_dev->info = &rockchip_saradc_iio_info; in rockchip_saradc_probe()
526 indio_dev->modes = INDIO_DIRECT_MODE; in rockchip_saradc_probe()
528 indio_dev->channels = info->data->channels; in rockchip_saradc_probe()
529 indio_dev->num_channels = info->data->num_channels; in rockchip_saradc_probe()
530 ret = devm_iio_triggered_buffer_setup(&indio_dev->dev, indio_dev, NULL, in rockchip_saradc_probe()
536 info->nb.notifier_call = rockchip_saradc_volt_notify; in rockchip_saradc_probe()
537 ret = regulator_register_notifier(info->vref, &info->nb); in rockchip_saradc_probe()
541 ret = devm_add_action_or_reset(&pdev->dev, in rockchip_saradc_probe()
547 mutex_init(&info->lock); in rockchip_saradc_probe()
549 return devm_iio_device_register(&pdev->dev, indio_dev); in rockchip_saradc_probe()
557 clk_disable_unprepare(info->clk); in rockchip_saradc_suspend()
558 clk_disable_unprepare(info->pclk); in rockchip_saradc_suspend()
559 regulator_disable(info->vref); in rockchip_saradc_suspend()
570 ret = regulator_enable(info->vref); in rockchip_saradc_resume()
574 ret = clk_prepare_enable(info->pclk); in rockchip_saradc_resume()
578 ret = clk_prepare_enable(info->clk); in rockchip_saradc_resume()
580 clk_disable_unprepare(info->pclk); in rockchip_saradc_resume()
592 .name = "rockchip-saradc",