Linux-RTC Archive mirror
 help / color / mirror / Atom feed
From: Alexandre Belloni <alexandre.belloni@bootlin.com>
To: Esteban Blanc <eblanc@baylibre.com>
Cc: linus.walleij@linaro.org, a.zummo@towertech.it,
	linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org,
	linux-rtc@vger.kernel.org, jpanis@baylibre.com,
	jneanne@baylibre.com, aseketeli@baylibre.com, u-kumar1@ti.com
Subject: Re: [PATCH v7 1/2] rtc: tps6594: Add driver for TPS6594 RTC
Date: Sun, 1 Oct 2023 23:20:49 +0200	[thread overview]
Message-ID: <2023100121204914ad7c28@mail.local> (raw)
In-Reply-To: <20230628133021.500477-2-eblanc@baylibre.com>

Hello,

What is the status of this series?

On 28/06/2023 15:30:20+0200, Esteban Blanc wrote:
> +static int tps6594_rtc_read_offset(struct device *dev, long *offset)
> +{
> +	int calibration;
> +	s64 tmp;
> +	int ret;
> +
> +	ret = tps6594_rtc_get_calibration(dev, &calibration);
> +	if (ret < 0)
> +		return ret;
> +
> +	// Convert from RTC calibration register format to ppb format.
> +	tmp = calibration * PPB_MULT;
> +
> +	if (tmp < 0)
> +		tmp -= TICKS_PER_HOUR / 2LL;
> +	else
> +		tmp += TICKS_PER_HOUR / 2LL;
> +	tmp = div_s64(tmp, TICKS_PER_HOUR);
> +
> +	/*
> +	 * SAFETY:
> +	 * Compution is the reverse operation of the one done in

Small typo -^

> +	 * `tps6594_rtc_set_offset`. The safety remarks applie here too.
> +	 */
> +
> +	/*
> +	 * Offset value operates in negative way, so swap sign.
> +	 * See 8.3.10.5, (32768 - COMP_REG).
> +	 */
> +	*offset = (long)-tmp;
> +
> +	return 0;
> +}
> +
> +static int tps6594_rtc_set_offset(struct device *dev, long offset)
> +{
> +	int calibration;
> +	s64 tmp;
> +
> +	// Make sure offset value is within supported range.
> +	if (offset < MIN_OFFSET || offset > MAX_OFFSET)
> +		return -ERANGE;
> +
> +	// Convert from ppb format to RTC calibration register format.
> +
> +	tmp = offset * TICKS_PER_HOUR;
> +	if (tmp < 0)
> +		tmp -= PPB_MULT / 2LL;
> +	else
> +		tmp += PPB_MULT / 2LL;
> +	tmp = div_s64(tmp, PPB_MULT);
> +
> +	/*
> +	 * SAFETY:
> +	 * - tmp = offset * TICK_PER_HOUR :
> +	 *	`offset` can't be more than 277774, so `tmp` can't exceed 277774000000000
> +	 *	which is lower than the maximum value in an `s64` (2^63-1). No overflow here.
> +	 *
> +	 * - tmp += TICK_PER_HOUR / 2LL :
> +	 *	tmp will have a maximum value of 277774117964800 which is still inferior to 2^63-1.
> +	 */
> +
> +	// Offset value operates in negative way, so swap sign.
> +	calibration = (int)-tmp;
> +
> +	return tps6594_rtc_set_calibration(dev, calibration);
> +}
> +
> +static irqreturn_t tps6594_rtc_interrupt(int irq, void *rtc)
> +{
> +	struct device *dev = rtc;
> +	unsigned long events = 0;
> +	struct tps6594 *tps = dev_get_drvdata(dev->parent);
> +	struct rtc_device *rtc_dev = dev_get_drvdata(dev);
> +	int ret;
> +	u32 rtc_reg;
> +
> +	ret = regmap_read(tps->regmap, TPS6594_REG_RTC_STATUS, &rtc_reg);
> +	if (ret)
> +		return IRQ_NONE;
> +
> +	if (rtc_reg & TPS6594_BIT_ALARM)
> +		events = RTC_IRQF | RTC_AF;
> +
> +	// Notify RTC core on event.

Nit: I don't feel like the events varialbe and the comment are
necessary.

> +	rtc_update_irq(rtc_dev, 1, events);
> +
> +	return IRQ_HANDLED;
> +}
> +

If you resend, you can add:

Acked-by: Alexandre Belloni <alexandre.belloni@bootlin.com>


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

  parent reply	other threads:[~2023-10-01 21:21 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-28 13:30 [PATCH v7 0/2] TI TPS6594 PMIC support (RTC, pinctrl, regulators) Esteban Blanc
2023-06-28 13:30 ` [PATCH v7 1/2] rtc: tps6594: Add driver for TPS6594 RTC Esteban Blanc
2023-07-05  9:45   ` andy.shevchenko
2023-10-01 21:20   ` Alexandre Belloni [this message]
2023-06-28 13:30 ` [PATCH v7 2/2] pinctrl: tps6594: Add driver for TPS6594 pinctrl and GPIOs Esteban Blanc
2023-06-29  7:00   ` Linus Walleij
2023-07-03 21:47   ` andy.shevchenko

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=2023100121204914ad7c28@mail.local \
    --to=alexandre.belloni@bootlin.com \
    --cc=a.zummo@towertech.it \
    --cc=aseketeli@baylibre.com \
    --cc=eblanc@baylibre.com \
    --cc=jneanne@baylibre.com \
    --cc=jpanis@baylibre.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rtc@vger.kernel.org \
    --cc=u-kumar1@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 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 read-only IMAP folder(s) and NNTP newsgroup(s).