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

1 // SPDX-License-Identifier: GPL-2.0-or-later
73 struct regulator *vref;
89 writel_relaxed(8, info->regs + SARADC_DLY_PU_SOC);
92 SARADC_CTRL_IRQ_ENABLE, info->regs + SARADC_CTRL);
99 if (info->reset)
100 rockchip_saradc_reset_controller(info->reset);
102 writel_relaxed(0xc, info->regs + SARADC_T_DAS_SOC);
103 writel_relaxed(0x20, info->regs + SARADC_T_PD_SOC);
106 writel_relaxed(val, info->regs + SARADC2_END_INT_EN);
111 writel(val, info->regs + SARADC2_CONV_CON);
116 info->data->start(info, chn);
121 return readl_relaxed(info->regs + SARADC_DATA);
129 writel_relaxed(0x1, info->regs + SARADC2_END_INT_ST);
131 offset = SARADC2_DATA_BASE + info->last_chan->channel * 0x4;
133 return readl_relaxed(info->regs + offset);
138 return info->data->read(info);
143 writel_relaxed(0, info->regs + SARADC_CTRL);
148 if (info->data->power_down)
149 info->data->power_down(info);
155 reinit_completion(&info->completion);
157 info->last_chan = chan;
158 rockchip_saradc_start(info, chan->channel);
160 if (!wait_for_completion_timeout(&info->completion, SARADC_TIMEOUT))
161 return -ETIMEDOUT;
175 mutex_lock(&info->lock);
180 mutex_unlock(&info->lock);
184 *val = info->last_val;
185 mutex_unlock(&info->lock);
188 *val = info->uv_vref / 1000;
189 *val2 = chan->scan_type.realbits;
192 return -EINVAL;
201 info->last_val = rockchip_saradc_read(info);
202 info->last_val &= GENMASK(info->last_chan->scan_type.realbits - 1, 0);
206 complete(&info->completion);
356 .compatible = "rockchip,rk3066-tsadc",
359 .compatible = "rockchip,rk3399-saradc",
362 .compatible = "rockchip,rk3528-saradc",
365 .compatible = "rockchip,rk3562-saradc",
368 .compatible = "rockchip,rk3568-saradc",
371 .compatible = "rockchip,rk3588-saradc",
392 regulator_disable(info->vref);
395 static irqreturn_t rockchip_saradc_trigger_handler(int irq, void *p)
397 struct iio_poll_func *pf = p;
398 struct iio_dev *i_dev = pf->indio_dev;
402 * @timestamp: will be 8-byte aligned automatically
413 mutex_lock(&info->lock);
416 const struct iio_chan_spec *chan = &i_dev->channels[i];
424 data.values[j] = info->last_val;
430 mutex_unlock(&info->lock);
432 iio_trigger_notify_done(i_dev->trig);
444 info->uv_vref = (unsigned long)data;
453 regulator_unregister_notifier(info->vref, &info->nb);
460 struct device_node *np = pdev->dev.of_node;
466 return -ENODEV;
468 indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*info));
470 return dev_err_probe(&pdev->dev, -ENOMEM,
475 match_data = of_device_get_match_data(&pdev->dev);
477 return dev_err_probe(&pdev->dev, -ENODEV,
480 info->data = match_data;
483 if (info->data->num_channels > SARADC_MAX_CHANNELS)
484 return dev_err_probe(&pdev->dev, -EINVAL,
487 info->regs = devm_platform_ioremap_resource(pdev, 0);
488 if (IS_ERR(info->regs))
489 return PTR_ERR(info->regs);
495 info->reset = devm_reset_control_get_optional_exclusive(&pdev->dev,
496 "saradc-apb");
497 if (IS_ERR(info->reset)) {
498 ret = PTR_ERR(info->reset);
499 return dev_err_probe(&pdev->dev, ret, "failed to get saradc-apb\n");
502 init_completion(&info->completion);
508 ret = devm_request_irq(&pdev->dev, irq, rockchip_saradc_isr,
509 0, dev_name(&pdev->dev), info);
511 dev_err(&pdev->dev, "failed requesting irq %d\n", irq);
515 info->vref = devm_regulator_get(&pdev->dev, "vref");
516 if (IS_ERR(info->vref))
517 return dev_err_probe(&pdev->dev, PTR_ERR(info->vref),
520 if (info->reset)
521 rockchip_saradc_reset_controller(info->reset);
525 * This may become user-configurable in the future.
527 ret = clk_set_rate(info->clk, info->data->clk_rate);
529 return dev_err_probe(&pdev->dev, ret,
532 ret = regulator_enable(info->vref);
534 return dev_err_probe(&pdev->dev, ret,
535 "failed to enable vref regulator\n");
537 ret = devm_add_action_or_reset(&pdev->dev,
540 return dev_err_probe(&pdev->dev, ret,
543 ret = regulator_get_voltage(info->vref);
547 info->uv_vref = ret;
549 info->pclk = devm_clk_get_enabled(&pdev->dev, "apb_pclk");
550 if (IS_ERR(info->pclk))
551 return dev_err_probe(&pdev->dev, PTR_ERR(info->pclk),
554 info->clk = devm_clk_get_enabled(&pdev->dev, "saradc");
555 if (IS_ERR(info->clk))
556 return dev_err_probe(&pdev->dev, PTR_ERR(info->clk),
561 indio_dev->name = dev_name(&pdev->dev);
562 indio_dev->info = &rockchip_saradc_iio_info;
563 indio_dev->modes = INDIO_DIRECT_MODE;
565 indio_dev->channels = info->data->channels;
566 indio_dev->num_channels = info->data->num_channels;
567 ret = devm_iio_triggered_buffer_setup(&indio_dev->dev, indio_dev, NULL,
573 info->nb.notifier_call = rockchip_saradc_volt_notify;
574 ret = regulator_register_notifier(info->vref, &info->nb);
578 ret = devm_add_action_or_reset(&pdev->dev,
584 mutex_init(&info->lock);
586 return devm_iio_device_register(&pdev->dev, indio_dev);
594 clk_disable_unprepare(info->clk);
595 clk_disable_unprepare(info->pclk);
596 regulator_disable(info->vref);
607 ret = regulator_enable(info->vref);
611 ret = clk_prepare_enable(info->pclk);
615 ret = clk_prepare_enable(info->clk);
617 clk_disable_unprepare(info->pclk);
629 .name = "rockchip-saradc",