From: Krzysztof Kozlowski <krzk@kernel.org>
To: CL Wang <cl634@andestech.com>,
alexandre.belloni@bootlin.com, linux-rtc@vger.kernel.org
Cc: tim609@andestech.com
Subject: Re: [PATCH V2 2/2] rtc: atcrtc100: Add andes atcrtc100 RTC driver
Date: Mon, 17 Jun 2024 10:54:48 +0200 [thread overview]
Message-ID: <f99e1b56-1870-49fb-ad6a-8d828548df02@kernel.org> (raw)
In-Reply-To: <20240617082507.3968910-3-cl634@andestech.com>
On 17/06/2024 10:25, CL Wang wrote:
> The atcrtc100 module includes a real time counter with alarm.
> Add a RTC driver for this function.
>
> Signed-off-by: CL Wang <cl634@andestech.com>
...
> +
> +static int atc_rtc_probe(struct platform_device *pdev)
> +{
> + struct atc_rtc *atc_rtc;
> + void __iomem *reg_base;
> + int ret = 0;
> +
> + atc_rtc = devm_kzalloc(&pdev->dev, sizeof(*atc_rtc), GFP_KERNEL);
> + if (!atc_rtc)
> + return -ENOMEM;
> + platform_set_drvdata(pdev, atc_rtc);
> + spin_lock_init(&atc_rtc->lock);
> +
> + reg_base = devm_platform_ioremap_resource(pdev, 0);
> + if (IS_ERR(reg_base)) {
> + dev_err(&pdev->dev, "couldn't map io space\n");
> + return PTR_ERR(atc_rtc->regmap);
> + }
> +
> + atc_rtc->regmap = devm_regmap_init_mmio(&pdev->dev, reg_base,
> + &atc_rtc_regmap_config);
> + if (IS_ERR(atc_rtc->regmap)) {
> + dev_err(&pdev->dev, "regmap init failed\n");
> + ret = PTR_ERR(atc_rtc->regmap);
> + }
> +
> + ret = atc_rtc_hw_init(atc_rtc);
> + if (ret) {
> + dev_err(&pdev->dev, "atc_rtc HW initialize failed\n");
> + return ret;
> + }
> +
> + atc_rtc->alarm_irq = platform_get_irq(pdev, 1);
> + if (atc_rtc->alarm_irq < 0) {
> + dev_err(&pdev->dev, "failed to get irq %d for alarm\n",
> + atc_rtc->alarm_irq);
> + }
> + atc_rtc->time_irq = platform_get_irq(pdev, 0);
> + if (atc_rtc->time_irq < 0) {
> + dev_err(&pdev->dev, "failed to get irq %d for RTC\n",
> + atc_rtc->time_irq);
> + }
> +
> + ret = devm_request_irq(&pdev->dev, atc_rtc->alarm_irq, rtc_alarm,
> + 0, "rtc alarm", atc_rtc);
> + if (ret) {
> + dev_err(&pdev->dev, "failed to request irq %d: %d for alarm\n",
> + atc_rtc->alarm_irq, ret);
> + return ret;
> + }
> +
> + ret = devm_request_irq(&pdev->dev, atc_rtc->time_irq, rtc_interrupt,
> + 0, "rtc time", atc_rtc);
> + if (ret) {
> + dev_err(&pdev->dev, "failed to request irq %d: %d\n",
> + atc_rtc->time_irq, ret);
> + return ret;
> + }
> +
> + atc_rtc->rtc_dev = devm_rtc_allocate_device(&pdev->dev);
> + if (IS_ERR(atc_rtc->rtc_dev)) {
> + dev_err(&pdev->dev, "Could not allocate rtc device\n");
> + return PTR_ERR(atc_rtc->rtc_dev);
> + }
> +
> + if (of_property_read_bool(pdev->dev.of_node, "wakeup-source")) {
Test your DTS (dtbs_check). This should fail.
> + device_init_wakeup(&pdev->dev, true);
> + ret = dev_pm_set_wake_irq(&pdev->dev, atc_rtc->alarm_irq);
> + if (ret) {
> + dev_err(&pdev->dev, "failed to enable irq wake\n");
> + device_init_wakeup(&pdev->dev, false);
> + atc_alarm_wakeup_enable(&pdev->dev, false);
> + clear_bit(RTC_FEATURE_ALARM, atc_rtc->rtc_dev->features);
> + } else {
> + atc_alarm_wakeup_enable(&pdev->dev, true);
> + set_bit(RTC_FEATURE_ALARM, atc_rtc->rtc_dev->features);
> + }
> + } else {
> + atc_alarm_wakeup_enable(&pdev->dev, false);
> + clear_bit(RTC_FEATURE_ALARM, atc_rtc->rtc_dev->features);
> + }
> + atc_rtc->rtc_dev->ops = &rtc_ops;
> + atc_rtc->rtc_dev->range_min = ATCRTC_RTC_TIMESTAMP_BEGIN_2000;
> + atc_rtc->rtc_dev->range_max = ATCRTC_RTC_TIMESTAMP_END_2089;
> +
> + return devm_rtc_register_device(atc_rtc->rtc_dev);
> +}
> +
> +#ifdef CONFIG_PM_SLEEP
> +static int atc_rtc_resume(struct device *dev)
> +{
> + struct atc_rtc *rtc = dev_get_drvdata(dev);
> +
> + if (device_may_wakeup(dev))
> + disable_irq_wake(rtc->alarm_irq);
> +
> + return 0;
> +}
> +
> +static int atc_rtc_suspend(struct device *dev)
> +{
> + struct atc_rtc *rtc = dev_get_drvdata(dev);
> +
> + if (device_may_wakeup(dev))
> + enable_irq_wake(rtc->alarm_irq);
> +
> + return 0;
> +}
> +#endif
> +static SIMPLE_DEV_PM_OPS(atc_rtc_pm_ops, atc_rtc_suspend, atc_rtc_resume);
> +
> +static const struct of_device_id atc_rtc_dt_match[] = {
> + { .compatible = "andestech,atcrtc100" },
> + { }
> +};
> +MODULE_DEVICE_TABLE(of, atc_rtc_dt_match);
> +
> +static struct platform_driver atc_rtc_platform_driver = {
> + .driver = {
> + .name = "atcrtc100",
> + .of_match_table = of_match_ptr(atc_rtc_dt_match),
Drop of_match_ptr(), leads to warnings.
> + .pm = &atc_rtc_pm_ops,
> + },
> + .probe = atc_rtc_probe,
> +};
> +
> +module_platform_driver(atc_rtc_platform_driver);
> +
> +MODULE_AUTHOR("CL Wang <cl634@andestech.com>");
> +MODULE_DESCRIPTION("Andes ATCRTC100 driver");
> +MODULE_LICENSE("GPL");
Best regards,
Krzysztof
prev parent reply other threads:[~2024-06-17 8:54 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-17 8:25 [PATCH V2 0/2] Add andes atcrtc100 RTC driver CL Wang
2024-06-17 8:25 ` [PATCH V2 1/2] dt-bindings: rtc: atcrtc100: Add atcrtc100 bindings CL Wang
2024-06-17 8:52 ` Krzysztof Kozlowski
2024-06-17 8:55 ` Krzysztof Kozlowski
2024-06-17 8:25 ` [PATCH V2 2/2] rtc: atcrtc100: Add andes atcrtc100 RTC driver CL Wang
2024-06-17 8:54 ` Krzysztof Kozlowski [this message]
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=f99e1b56-1870-49fb-ad6a-8d828548df02@kernel.org \
--to=krzk@kernel.org \
--cc=alexandre.belloni@bootlin.com \
--cc=cl634@andestech.com \
--cc=linux-rtc@vger.kernel.org \
--cc=tim609@andestech.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.