Lines Matching +full:vref +full:- +full:p

1 // SPDX-License-Identifier: GPL-2.0-or-later
73 struct regulator *vref; member
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()
355 static irqreturn_t rockchip_saradc_trigger_handler(int irq, void *p) in rockchip_saradc_trigger_handler() argument
357 struct iio_poll_func *pf = p; in rockchip_saradc_trigger_handler()
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()
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_optional_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 return dev_err_probe(&pdev->dev, ret, "failed to get saradc-apb\n"); in rockchip_saradc_probe()
460 init_completion(&info->completion); in rockchip_saradc_probe()
466 ret = devm_request_irq(&pdev->dev, irq, rockchip_saradc_isr, in rockchip_saradc_probe()
467 0, dev_name(&pdev->dev), info); in rockchip_saradc_probe()
469 dev_err(&pdev->dev, "failed requesting irq %d\n", irq); in rockchip_saradc_probe()
473 info->vref = devm_regulator_get(&pdev->dev, "vref"); in rockchip_saradc_probe()
474 if (IS_ERR(info->vref)) in rockchip_saradc_probe()
475 return dev_err_probe(&pdev->dev, PTR_ERR(info->vref), in rockchip_saradc_probe()
478 if (info->reset) in rockchip_saradc_probe()
479 rockchip_saradc_reset_controller(info->reset); in rockchip_saradc_probe()
483 * This may become user-configurable in the future. in rockchip_saradc_probe()
485 ret = clk_set_rate(info->clk, info->data->clk_rate); in rockchip_saradc_probe()
487 return dev_err_probe(&pdev->dev, ret, in rockchip_saradc_probe()
490 ret = regulator_enable(info->vref); in rockchip_saradc_probe()
492 return dev_err_probe(&pdev->dev, ret, in rockchip_saradc_probe()
493 "failed to enable vref regulator\n"); in rockchip_saradc_probe()
495 ret = devm_add_action_or_reset(&pdev->dev, in rockchip_saradc_probe()
498 return dev_err_probe(&pdev->dev, ret, in rockchip_saradc_probe()
501 ret = regulator_get_voltage(info->vref); in rockchip_saradc_probe()
505 info->uv_vref = ret; in rockchip_saradc_probe()
507 info->pclk = devm_clk_get_enabled(&pdev->dev, "apb_pclk"); in rockchip_saradc_probe()
508 if (IS_ERR(info->pclk)) in rockchip_saradc_probe()
509 return dev_err_probe(&pdev->dev, PTR_ERR(info->pclk), in rockchip_saradc_probe()
512 info->clk = devm_clk_get_enabled(&pdev->dev, "saradc"); in rockchip_saradc_probe()
513 if (IS_ERR(info->clk)) in rockchip_saradc_probe()
514 return dev_err_probe(&pdev->dev, PTR_ERR(info->clk), in rockchip_saradc_probe()
519 indio_dev->name = dev_name(&pdev->dev); in rockchip_saradc_probe()
520 indio_dev->info = &rockchip_saradc_iio_info; in rockchip_saradc_probe()
521 indio_dev->modes = INDIO_DIRECT_MODE; in rockchip_saradc_probe()
523 indio_dev->channels = info->data->channels; in rockchip_saradc_probe()
524 indio_dev->num_channels = info->data->num_channels; in rockchip_saradc_probe()
525 ret = devm_iio_triggered_buffer_setup(&indio_dev->dev, indio_dev, NULL, in rockchip_saradc_probe()
531 info->nb.notifier_call = rockchip_saradc_volt_notify; in rockchip_saradc_probe()
532 ret = regulator_register_notifier(info->vref, &info->nb); in rockchip_saradc_probe()
536 ret = devm_add_action_or_reset(&pdev->dev, in rockchip_saradc_probe()
542 mutex_init(&info->lock); in rockchip_saradc_probe()
544 return devm_iio_device_register(&pdev->dev, indio_dev); in rockchip_saradc_probe()
552 clk_disable_unprepare(info->clk); in rockchip_saradc_suspend()
553 clk_disable_unprepare(info->pclk); in rockchip_saradc_suspend()
554 regulator_disable(info->vref); in rockchip_saradc_suspend()
565 ret = regulator_enable(info->vref); in rockchip_saradc_resume()
569 ret = clk_prepare_enable(info->pclk); in rockchip_saradc_resume()
573 ret = clk_prepare_enable(info->clk); in rockchip_saradc_resume()
575 clk_disable_unprepare(info->pclk); in rockchip_saradc_resume()
587 .name = "rockchip-saradc",