All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alexandre Belloni <alexandre.belloni@bootlin.com>
To: Nishanth Menon <nm@ti.com>
Cc: Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
	Rob Herring <robh+dt@kernel.org>,
	Alessandro Zummo <a.zummo@towertech.it>,
	linux-kernel@vger.kernel.org, devicetree@vger.kernel.org,
	linux-rtc@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	Vignesh Raghavendra <vigneshr@ti.com>, Andrew Davis <afd@ti.com>
Subject: Re: [PATCH V3 2/2] rtc: Introduce ti-k3-rtc
Date: Wed, 18 May 2022 00:00:08 +0200	[thread overview]
Message-ID: <YoQa6FoJV5eoxloa@mail.local> (raw)
In-Reply-To: <20220513194457.25942-3-nm@ti.com>

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

WARNING: multiple messages have this Message-ID (diff)
From: Alexandre Belloni <alexandre.belloni@bootlin.com>
To: Nishanth Menon <nm@ti.com>
Cc: Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
	Rob Herring <robh+dt@kernel.org>,
	Alessandro Zummo <a.zummo@towertech.it>,
	linux-kernel@vger.kernel.org, devicetree@vger.kernel.org,
	linux-rtc@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	Vignesh Raghavendra <vigneshr@ti.com>, Andrew Davis <afd@ti.com>
Subject: Re: [PATCH V3 2/2] rtc: Introduce ti-k3-rtc
Date: Wed, 18 May 2022 00:00:08 +0200	[thread overview]
Message-ID: <YoQa6FoJV5eoxloa@mail.local> (raw)
In-Reply-To: <20220513194457.25942-3-nm@ti.com>

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

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2022-05-17 22:00 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-13 19:44 [PATCH V3 0/2] rtc: Introduce rtc-ti-k3 Nishanth Menon
2022-05-13 19:44 ` Nishanth Menon
2022-05-13 19:44 ` [PATCH V3 1/2] dt-bindings: rtc: Add TI K3 RTC description Nishanth Menon
2022-05-13 19:44   ` Nishanth Menon
2022-05-14 20:47   ` Krzysztof Kozlowski
2022-05-14 20:47     ` Krzysztof Kozlowski
2022-05-13 19:44 ` [PATCH V3 2/2] rtc: Introduce ti-k3-rtc Nishanth Menon
2022-05-13 19:44   ` Nishanth Menon
2022-05-17 22:00   ` Alexandre Belloni [this message]
2022-05-17 22:00     ` Alexandre Belloni
2022-05-17 23:17     ` Nishanth Menon
2022-05-17 23:17       ` Nishanth Menon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YoQa6FoJV5eoxloa@mail.local \
    --to=alexandre.belloni@bootlin.com \
    --cc=a.zummo@towertech.it \
    --cc=afd@ti.com \
    --cc=devicetree@vger.kernel.org \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rtc@vger.kernel.org \
    --cc=nm@ti.com \
    --cc=robh+dt@kernel.org \
    --cc=vigneshr@ti.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.