devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Krzysztof Kozlowski <krzk@kernel.org>
To: Shubhi Garg <shgarg@nvidia.com>
Cc: jonathanh@nvidia.com, lee@kernel.org, robh@kernel.org,
	 alexandre.belloni@bootlin.com, thierry.reding@gmail.com,
	devicetree@vger.kernel.org,  linux-tegra@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH V2 4/6] rtc: nvvrs: add NVIDIA VRS PSEQ RTC device driver
Date: Wed, 21 May 2025 11:14:13 +0200	[thread overview]
Message-ID: <20250521-dazzling-myrtle-flounder-a9e57d@kuoka> (raw)
In-Reply-To: <20250520090832.3564104-5-shgarg@nvidia.com>

On Tue, May 20, 2025 at 09:08:30AM GMT, Shubhi Garg wrote:
> Add support for NVIDIA VRS (Voltage Regulator Specification) Power
> Sequencer RTC device driver. This RTC can be used to get/set system
> time, retain system time across boot, wake system from suspend and
> shutdown state.
> 
> Signed-off-by: Shubhi Garg <shgarg@nvidia.com>
> ---
> 
> v2:
> - removed regmap struct since it is not required
> - removed rtc_map definition to directly use register definition
> - removed unnecessary dev_err logs
> - fixed dev_err logs to dev_dbg
> - used rtc_lock/unlock in irq handler
> - changed RTC allocation and register APIs as per latest kernel
> - removed nvvrs_rtc_remove function since it's not required
> 
>  drivers/rtc/Kconfig               |  10 +
>  drivers/rtc/Makefile              |   1 +
>  drivers/rtc/rtc-nvidia-vrs-pseq.c | 456 ++++++++++++++++++++++++++++++
>  3 files changed, 467 insertions(+)
>  create mode 100644 drivers/rtc/rtc-nvidia-vrs-pseq.c
> 
> diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
> index 838bdc138ffe..3b6dc27a50af 100644
> --- a/drivers/rtc/Kconfig
> +++ b/drivers/rtc/Kconfig
> @@ -406,6 +406,16 @@ config RTC_DRV_MAX77686
>  	  This driver can also be built as a module. If so, the module
>  	  will be called rtc-max77686.
>  
> +config RTC_DRV_NVVRS_PSEQ
> +	tristate "NVIDIA VRS Power Sequencer RTC device"
> +	depends on MFD_NVVRS_PSEQ

I bet this fails when MFD_NVVRS_PSEQ is a module.

> +	help
> +	  If you say yes here you will get support for the battery backed RTC device
> +	  of NVIDIA VRS Power Sequencer. The RTC is connected via I2C interface and
> +	  supports alarm functionality.
> +	  This driver can also be built as a module. If so, the module will be called
> +	  rtc-nvidia-vrs-pseq.
> +

...

> +static int nvvrs_rtc_probe(struct platform_device *pdev)
> +{
> +	struct nvvrs_rtc_info *info;
> +	struct device *parent;
> +	struct i2c_client *client;
> +	int ret;
> +
> +	info = devm_kzalloc(&pdev->dev, sizeof(struct nvvrs_rtc_info), GFP_KERNEL);

sizeof(*)

> +	if (!info)
> +		return -ENOMEM;
> +
> +	mutex_init(&info->lock);
> +
> +	ret = platform_get_irq(pdev, 0);
> +	if (ret < 0) {
> +		dev_err(&pdev->dev, "Failed to get irq\n");

return dev_err_probe

> +		return ret;
> +	}
> +	info->rtc_irq = ret;
> +
> +	info->dev = &pdev->dev;
> +	parent = info->dev->parent;
> +	client = to_i2c_client(parent);
> +	client->flags |= I2C_CLIENT_PEC;
> +	i2c_set_clientdata(client, info);
> +	info->client = client;
> +	info->rtc_irq_chip = &nvvrs_rtc_irq_chip;
> +	platform_set_drvdata(pdev, info);
> +
> +	/* Allocate RTC device */
> +	info->rtc_dev = devm_rtc_allocate_device(info->dev);
> +	if (IS_ERR(info->rtc_dev))
> +		return PTR_ERR(info->rtc_dev);
> +
> +	info->rtc_dev->ops = &nvvrs_rtc_ops;
> +	info->rtc_dev->range_min = RTC_TIMESTAMP_BEGIN_2000;
> +	info->rtc_dev->range_max = RTC_TIMESTAMP_END_2099;
> +
> +	ret = devm_request_threaded_irq(info->dev, info->rtc_irq, NULL,
> +					nvvrs_rtc_irq_handler, 0, "rtc-alarm", info);
> +	if (ret < 0)
> +		dev_err(&pdev->dev, "Failed to request alarm IRQ: %d: %d\n",
> +			info->rtc_irq, ret);
> +
> +	/* RTC as a wakeup source */
> +	device_init_wakeup(info->dev, true);

You leak wakeup.

> +
> +	return devm_rtc_register_device(info->rtc_dev);
> +}
> +
> +#ifdef CONFIG_PM_SLEEP
> +static int nvvrs_rtc_suspend(struct device *dev)
> +{
> +	struct nvvrs_rtc_info *info = dev_get_drvdata(dev);
> +	int ret = 0;
> +
> +	if (device_may_wakeup(dev)) {
> +		/* Set RTC_WAKE bit for auto wake system from suspend state */
> +		ret = nvvrs_update_bits(info, NVVRS_PSEQ_REG_CTL_2,
> +					NVVRS_PSEQ_REG_CTL_2_RTC_WAKE,
> +					NVVRS_PSEQ_REG_CTL_2_RTC_WAKE);
> +		if (ret < 0) {
> +			dev_err(info->dev, "Failed to set RTC_WAKE bit (%d)\n", ret);
> +			return ret;
> +		}
> +
> +		ret = enable_irq_wake(info->rtc_irq);
> +	}
> +
> +	return ret;
> +}
> +
> +static int nvvrs_rtc_resume(struct device *dev)
> +{
> +	struct nvvrs_rtc_info *info = dev_get_drvdata(dev);
> +	int ret;
> +
> +	if (device_may_wakeup(dev)) {
> +		/* Clear FORCE_ACT bit */
> +		ret = nvvrs_update_bits(info, NVVRS_PSEQ_REG_CTL_1,
> +					NVVRS_PSEQ_REG_CTL_1_FORCE_ACT, 0);
> +		if (ret < 0) {
> +			dev_err(info->dev, "Failed to clear FORCE_ACT bit (%d)\n", ret);
> +			return ret;
> +		}
> +
> +		return disable_irq_wake(info->rtc_irq);
> +	}
> +
> +	return 0;
> +}
> +
> +#endif
> +static SIMPLE_DEV_PM_OPS(nvvrs_rtc_pm_ops, nvvrs_rtc_suspend, nvvrs_rtc_resume);
> +
> +static const struct platform_device_id nvvrs_rtc_id[] = {
> +	{ "nvvrs-pseq-rtc", },
> +	{ },
> +};
> +MODULE_DEVICE_TABLE(platform, nvvrs_rtc_id);
> +
> +static struct platform_driver nvvrs_rtc_driver = {
> +	.driver		= {
> +		.name   = "nvvrs-pseq-rtc",
> +		.pm     = &nvvrs_rtc_pm_ops,
> +	},
> +	.probe		= nvvrs_rtc_probe,
> +	.id_table       = nvvrs_rtc_id,
> +};
> +
> +module_platform_driver(nvvrs_rtc_driver);
> +
> +MODULE_AUTHOR("Shubhi Garg <shgarg@nvidia.com>");
> +MODULE_DESCRIPTION("NVVRS PSEQ RTC driver");
> +MODULE_LICENSE("GPL");
> \ No newline at end of file

You have patch warnings.

> -- 
> 2.43.0
> 

  reply	other threads:[~2025-05-21  9:14 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-20  9:08 [PATCH V2 0/6] Add NVIDIA VRS PSEQ support Shubhi Garg
2025-05-20  9:08 ` [PATCH V2 1/6] dt-bindings: mfd: add bindings for NVIDIA VRS PSEQ Shubhi Garg
2025-05-21  9:09   ` Krzysztof Kozlowski
2025-05-20  9:08 ` [PATCH V2 2/6] arm64: tegra: Add device-tree node for NVVRS PSEQ Shubhi Garg
2025-05-20  9:08 ` [PATCH V2 3/6] mfd: nvvrs: add NVVRS PSEQ MFD driver Shubhi Garg
2025-05-21  9:12   ` Krzysztof Kozlowski
2025-05-20  9:08 ` [PATCH V2 4/6] rtc: nvvrs: add NVIDIA VRS PSEQ RTC device driver Shubhi Garg
2025-05-21  9:14   ` Krzysztof Kozlowski [this message]
2025-06-02 14:47     ` Jon Hunter
2025-05-20  9:08 ` [PATCH V2 5/6] arm64: defconfig: enable NVIDIA VRS PSEQ Shubhi Garg
2025-05-20  9:12   ` Krzysztof Kozlowski
2025-05-20  9:08 ` [PATCH V2 6/6] MAINTAINERS: Add NVIDIA VRS PSEQ driver entry Shubhi Garg

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=20250521-dazzling-myrtle-flounder-a9e57d@kuoka \
    --to=krzk@kernel.org \
    --cc=alexandre.belloni@bootlin.com \
    --cc=devicetree@vger.kernel.org \
    --cc=jonathanh@nvidia.com \
    --cc=lee@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tegra@vger.kernel.org \
    --cc=robh@kernel.org \
    --cc=shgarg@nvidia.com \
    --cc=thierry.reding@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).