[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <2023100121204914ad7c28@mail.local>
Date: Sun, 1 Oct 2023 23:20:49 +0200
From: Alexandre Belloni <alexandre.belloni@...tlin.com>
To: Esteban Blanc <eblanc@...libre.com>
Cc: linus.walleij@...aro.org, a.zummo@...ertech.it,
linux-kernel@...r.kernel.org, linux-gpio@...r.kernel.org,
linux-rtc@...r.kernel.org, jpanis@...libre.com,
jneanne@...libre.com, aseketeli@...libre.com, u-kumar1@...com
Subject: Re: [PATCH v7 1/2] rtc: tps6594: Add driver for TPS6594 RTC
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@...tlin.com>
--
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
Powered by blists - more mailing lists