[PATCH V3 2/2] rtc: Introduce ti-k3-rtc

Alexandre Belloni alexandre.belloni at bootlin.com
Tue May 17 15:00:08 PDT 2022


Hello Nishanth,

I have some very minor comments:

On 13/05/2022 14:44:57-0500, Nishanth Menon wrote:
> diff --git a/drivers/rtc/rtc-ti-k3.c b/drivers/rtc/rtc-ti-k3.c
> new file mode 100644
> index 000000000000..21a64051fd42
> --- /dev/null
> +++ b/drivers/rtc/rtc-ti-k3.c
> @@ -0,0 +1,695 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * Texas Instruments K3 RTC driver
> + *
> + * Copyright (C) 2021-2022 Texas Instruments Incorporated - https://www.ti.com/
> + */
> +
> +#define dev_fmt(fmt) "%s: " fmt, __func__

Are you sure you want to keep this line?

> +static int ti_k3_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
> +{
> +	struct ti_k3_rtc *priv = dev_get_drvdata(dev);
> +	time64_t seconds;
> +	int ret;
> +
> +	seconds = rtc_tm_to_time64(&alarm->time);
> +
> +	k3rtc_field_write(priv, K3RTC_ALM_S_CNT_LSW, seconds);
> +	k3rtc_field_write(priv, K3RTC_ALM_S_CNT_MSW, (seconds >> 32));
> +
> +	/* Make sure the alarm time is synced in */
> +	ret = k3rtc_fence(priv);
> +	if (ret) {
> +		dev_err(dev, "Failed to fence(%d)!\n", ret);

I'm not sure this message is useful because the only thing the user may
do would be trying to set the time again.

> +		return ret;
> +	}
> +
> +	/* Alarm irq enable will do a sync */
> +	return ti_k3_rtc_alarm_irq_enable(dev, alarm->enabled);
> +}
> +


> +
> +static int k3rtc_get_vbusclk(struct device *dev, struct ti_k3_rtc *priv)
> +{
> +	int ret;
> +	struct clk *clk;
> +
> +	/* Note: VBUS is'nt a context clock, it is needed for hardware operation */
typo ---------------^

> +	clk = devm_clk_get(dev, "vbus");
> +	if (IS_ERR(clk)) {
> +		dev_err(dev, "No input vbus clock\n");
> +		return PTR_ERR(clk);
> +	}
> +
> +	ret = clk_prepare_enable(clk);
> +	if (ret) {
> +		dev_err(dev, "Failed to enable the vbus clock(%d)\n", ret);

I would also remove those two dev_err

> +		return ret;
> +	}
> +
> +	ret = devm_add_action_or_reset(dev, (void (*)(void *))clk_disable_unprepare, clk);
> +	return ret;
> +}
> +
> +static int ti_k3_rtc_probe(struct platform_device *pdev)
> +{
> +	struct device *dev = &pdev->dev;
> +	struct ti_k3_rtc *priv;
> +	void __iomem *rtc_base;
> +	int ret;
> +
> +	priv = devm_kzalloc(dev, sizeof(struct ti_k3_rtc), GFP_KERNEL);
> +	if (!priv)
> +		return -ENOMEM;
> +
> +	rtc_base = devm_platform_ioremap_resource(pdev, 0);
> +	if (IS_ERR(rtc_base))
> +		return PTR_ERR(rtc_base);
> +
> +	priv->regmap = devm_regmap_init_mmio(dev, rtc_base, &ti_k3_rtc_regmap_config);
> +	if (IS_ERR(priv->regmap))
> +		return PTR_ERR(priv->regmap);
> +
> +	ret = devm_regmap_field_bulk_alloc(dev, priv->regmap, priv->r_fields,
> +					   ti_rtc_reg_fields, K3_RTC_MAX_FIELDS);
> +	if (ret)
> +		return ret;
> +
> +	ret = k3rtc_get_32kclk(dev, priv);
> +	if (ret)
> +		return ret;
> +	ret = k3rtc_get_vbusclk(dev, priv);
> +	if (ret)
> +		return ret;
> +
> +	ret = platform_get_irq(pdev, 0);
> +	if (ret < 0)
> +		return ret;
> +	priv->irq = (unsigned int)ret;
> +
> +	priv->rtc_dev = devm_rtc_allocate_device(dev);
> +	if (IS_ERR(priv->rtc_dev))
> +		return PTR_ERR(priv->rtc_dev);
> +
> +	priv->soc = of_device_get_match_data(dev);
> +
> +	priv->rtc_dev->ops = &ti_k3_rtc_ops;
> +	priv->rtc_dev->range_max = (1ULL << 48) - 1;	/* 48Bit seconds */
> +	ti_k3_rtc_nvmem_config.priv = priv;
> +
> +	ret = devm_request_threaded_irq(dev, priv->irq, NULL,
> +					ti_k3_rtc_interrupt,
> +					IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
> +					dev_name(dev), dev);
> +	if (ret) {
> +		dev_err(dev, "Could not request IRQ: %d\n", ret);
> +		return ret;
> +	}
> +
> +	platform_set_drvdata(pdev, priv);
> +
> +	ret = k3rtc_configure(dev);
> +	if (ret)
> +		return ret;
> +
> +	if (device_property_present(dev, "wakeup-source"))
> +		device_init_wakeup(dev, true);
> +	else
> +		device_set_wakeup_capable(dev, true);
> +
> +	ret = devm_rtc_register_device(priv->rtc_dev);
> +	if (ret)
> +		return ret;
> +
> +	ret = devm_rtc_nvmem_register(priv->rtc_dev, &ti_k3_rtc_nvmem_config);
> +	return ret;

You don't need ret here and if I take that, I'll soon get an
automatically generated patch.

> +}
> +
> +static const struct ti_k3_rtc_soc_data ti_k3_am62_data = {
> +	.unlock_irq_erratum = true,
> +};
> +
> +static const struct of_device_id ti_k3_rtc_of_match_table[] = {
> +	{.compatible = "ti,am62-rtc", .data = &ti_k3_am62_data},
> +	{}
> +};
> +MODULE_DEVICE_TABLE(of, ti_k3_rtc_of_match_table);
> +
> +static int __maybe_unused ti_k3_rtc_suspend(struct device *dev)
> +{
> +	struct ti_k3_rtc *priv = dev_get_drvdata(dev);
> +
> +	if (device_may_wakeup(dev))
> +		enable_irq_wake(priv->irq);
> +	return 0;
> +}
> +
> +static int __maybe_unused ti_k3_rtc_resume(struct device *dev)
> +{
> +	struct ti_k3_rtc *priv = dev_get_drvdata(dev);
> +
> +	if (device_may_wakeup(dev))
> +		disable_irq_wake(priv->irq);
> +	return 0;
> +}
> +
> +static SIMPLE_DEV_PM_OPS(ti_k3_rtc_pm_ops, ti_k3_rtc_suspend, ti_k3_rtc_resume);
> +
> +static struct platform_driver ti_k3_rtc_driver = {
> +	.probe = ti_k3_rtc_probe,
> +	.driver = {
> +		   .name = "rtc-ti-k3",
> +		   .of_match_table = ti_k3_rtc_of_match_table,
> +		   .pm = &ti_k3_rtc_pm_ops,
> +	},
> +};
> +module_platform_driver(ti_k3_rtc_driver);
> +
> +MODULE_LICENSE("GPL");
> +MODULE_DESCRIPTION("TI K3 RTC driver");
> +MODULE_AUTHOR("Nishanth Menon");
> -- 
> 2.31.1
> 

-- 
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com



More information about the linux-arm-kernel mailing list