[PATCH v2 2/8] rtc: pcf85063: adjust date format to adhere to the rtc_time spec

Sverdlin, Alexander alexander.sverdlin at siemens.com
Tue May 12 10:22:20 CEST 2026


On Mon, 2026-05-11 at 14:09 +0200, Alexander Feilke wrote:
> From: Alexander Feilke <alexander.feilke at ew.tq-group.com>
> 
> The rtc_time documentation in rtc_def.h notes a differences
> to the common "struct time" that specifies tm_mon as 1 ... 12
> and tm_year as year since 0. Also trim register values to valid bits.
> 
> Fixes: 1c2a2253f798 ("drivers: rtc: add PCF85063 support")
> 
> Signed-off-by: Alexander Feilke <alexander.feilke at ew.tq-group.com>

Reviewed-by: Alexander Sverdlin <alexander.sverdlin at siemens.com>

> ---
>  drivers/rtc/pcf85063.c | 19 +++++++++++++++----
>  1 file changed, 15 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/rtc/pcf85063.c b/drivers/rtc/pcf85063.c
> index 737d4547aca..21640b039c1 100644
> --- a/drivers/rtc/pcf85063.c
> +++ b/drivers/rtc/pcf85063.c
> @@ -35,7 +35,9 @@ static int pcf85063_get_time(struct udevice *dev, struct rtc_time *tm)
>  	tm->tm_hour = bcd2bin(regs[2] & 0x3f);
>  	tm->tm_mday = bcd2bin(regs[3] & 0x3f);
>  	tm->tm_wday = regs[4] & 0x07;
> -	tm->tm_mon = bcd2bin(regs[5] & 0x1f) - 1;
> +	/* rtc register and rtc_time spec uses 1 - 12 */
> +	tm->tm_mon = bcd2bin(regs[5] & 0x1f);
> +	/* adjust rtc_time (years since 0) to match register spec */
>  	tm->tm_year = bcd2bin(regs[6]) + 2000;
>  
>  	return 0;
> @@ -50,12 +52,21 @@ static int pcf85063_set_time(struct udevice *dev, const struct rtc_time *tm)
>  		return -EINVAL;
>  	}
>  
> -	regs[0] = bin2bcd(tm->tm_sec);
> +	/* hours, minutes and seconds */
> +	regs[0] = bin2bcd(tm->tm_sec) & (~PCF85063_REG_SC_OS);
> +
>  	regs[1] = bin2bcd(tm->tm_min);
>  	regs[2] = bin2bcd(tm->tm_hour);
> +
> +	/* Day of month, 1 - 31 */
>  	regs[3] = bin2bcd(tm->tm_mday);
> -	regs[4] = tm->tm_wday;
> -	regs[5] = bin2bcd(tm->tm_mon + 1);
> +
> +	/* Day of week 0 - 6 */
> +	regs[4] = tm->tm_wday & 0x07;
> +
> +	/* rtc register and rtc_time spec uses 1 - 12 */
> +	regs[5] = bin2bcd(tm->tm_mon);
> +	/* adjust register to match rtc_time spec */
>  	regs[6] = bin2bcd(tm->tm_year % 100);
>  
>  	return dm_i2c_write(dev, PCF85063_REG_SC, regs, sizeof(regs));

-- 
Alexander Sverdlin
Siemens AG
www.siemens.com


More information about the U-Boot mailing list