linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Alexandre Belloni <alexandre.belloni@bootlin.com>
To: Kevin Hilman <khilman@kernel.org>
Cc: linux-rtc@vger.kernel.org, devicetree@vger.kernel.org,
	Neil Armstrong <narmstrong@baylibre.com>,
	Kevin Hilman <khilman@baylibre.com>,
	linux-kernel@vger.kernel.org, linux-amlogic@lists.infradead.org,
	linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH 2/2] rtc: Add Amlogic Virtual Wake RTC
Date: Thu, 20 Jun 2019 23:17:36 +0200	[thread overview]
Message-ID: <20190620211736.GF23549@piout.net> (raw)
In-Reply-To: <20190607194343.18359-2-khilman@kernel.org>

Hello Kevin,

On 07/06/2019 12:43:43-0700, Kevin Hilman wrote:
> +static int meson_vrtc_read_time(struct device *dev, struct rtc_time *tm)
> +{
> +	unsigned long local_time;
> +	struct timespec64 time;
> +
> +	ktime_get_raw_ts64(&time);
> +	local_time = time.tv_sec - (sys_tz.tz_minuteswest * 60);
The RTC is supposed to be set to UTC so the TZ adjustment is not
necessary.

> +	rtc_time_to_tm(local_time, tm);
> +

Please use the 64 bit version.

> +	return 0;
> +}
> +
> +static void meson_vrtc_set_wakeup_time(struct meson_vrtc_data *vrtc,
> +				       unsigned long time)
> +{
> +	writel_relaxed(time, vrtc->io_alarm);
> +
> +	dev_dbg(&vrtc->pdev->dev, "set_wakeup_time: %lu\n", time);
> +}
> +
> +static int meson_vrtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
> +{
> +	struct meson_vrtc_data *vrtc = dev_get_drvdata(dev);
> +	struct timespec64 time;
> +	unsigned long local_time;
> +	unsigned long alarm_secs;
> +	int ret;
> +
> +	if (alarm->enabled) {
> +		ret = rtc_tm_to_time(&alarm->time, &alarm_secs);
> +		if (ret)
> +			return ret;
> +

Use the 64bit version which makes it clear that it never fails (checking
ret is useless).

> +		ktime_get_raw_ts64(&time);
> +		local_time = time.tv_sec - (sys_tz.tz_minuteswest * 60);
> +
> +		vrtc->alarm_time = alarm_secs;
> +
> +		if (alarm_secs >= local_time) {

This is already ensured by the core so no need to check here.

> +			alarm_secs = alarm_secs - local_time;
> +
> +			meson_vrtc_set_wakeup_time(vrtc, alarm_secs);
> +
> +			pr_debug("system will wakeup %lus later\n", alarm_secs);
> +		}
> +	} else {
> +		vrtc->alarm_time = 0;
> +		meson_vrtc_set_wakeup_time(vrtc, 0);
> +	}
> +
> +	return 0;
> +}
> +
> +static int meson_vrtc_read_alarm(struct device *dev, struct rtc_wkalrm *alm)
> +{
> +	struct meson_vrtc_data *vrtc = dev_get_drvdata(dev);
> +
> +	if (!vrtc->alarm_time) {

I think this test is inverted.

> +		alm->enabled = true;
> +
> +		rtc_time_to_tm(vrtc->alarm_time, &alm->time);
> +	}
> +
> +	return 0;
> +}
> +
> +static const struct rtc_class_ops meson_vrtc_ops = {
> +	.read_time = meson_vrtc_read_time,
> +	.set_alarm = meson_vrtc_set_alarm,
> +	.read_alarm = meson_vrtc_read_alarm,
> +};
> +
> +static int meson_vrtc_probe(struct platform_device *pdev)
> +{
> +	struct meson_vrtc_data *vrtc;
> +	struct resource *res;
> +
> +	vrtc = devm_kzalloc(&pdev->dev, sizeof(*vrtc), GFP_KERNEL);
> +	if (!vrtc)
> +		return -ENOMEM;
> +
> +	vrtc->pdev = pdev;
> +
> +	/* Alarm registers */
> +	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> +	vrtc->io_alarm = devm_ioremap_resource(&pdev->dev, res);
> +	if (IS_ERR(vrtc->io_alarm))
> +		return PTR_ERR(vrtc->io_alarm);
> +
> +	device_init_wakeup(&pdev->dev, 1);
> +
> +	platform_set_drvdata(pdev, vrtc);
> +
> +	vrtc->rtc = devm_rtc_device_register(&pdev->dev, "meson-vrtc",
> +					     &meson_vrtc_ops, THIS_MODULE);
> +	if (IS_ERR(vrtc->rtc))
> +		return PTR_ERR(vrtc->rtc);
> +

Please use devm_rtc_allocate_device and rtc_register_device. This
doesn't help much but my plan is to get rid of devm_rtc_device_register.

I suppose you don't get any interrupt for the alarm?


-- 
Alexandre Belloni, 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:[~2019-06-20 21:18 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-07 19:43 [PATCH 1/2] dt-bindings: rtc: new binding for Amlogic VRTC Kevin Hilman
2019-06-07 19:43 ` [PATCH 2/2] rtc: Add Amlogic Virtual Wake RTC Kevin Hilman
2019-06-20 21:17   ` Alexandre Belloni [this message]
2019-07-09  2:07 ` [PATCH 1/2] dt-bindings: rtc: new binding for Amlogic VRTC Rob Herring

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=20190620211736.GF23549@piout.net \
    --to=alexandre.belloni@bootlin.com \
    --cc=devicetree@vger.kernel.org \
    --cc=khilman@baylibre.com \
    --cc=khilman@kernel.org \
    --cc=linux-amlogic@lists.infradead.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rtc@vger.kernel.org \
    --cc=narmstrong@baylibre.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).