Patch "rtc: ds1307: Fix relying on reset value for weekday" has been added to the 4.7-stable tree
Subsystems (2)
This is a note to let you know that I've just added the patch titled
rtc: ds1307: Fix relying on reset value for weekday
to the 4.7-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
The filename of the patch is:
rtc-ds1307-fix-relying-on-reset-value-for-weekday.patch
and it can be found in the queue-4.7 subdirectory.
If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.
Quoted 1 line
From
e29385fab0bf94017fac130ee32f5bb2daf74417Mon Sep 17 00:00:00 2001
From: Keerthy <[email protected]>
Date: Wed, 1 Jun 2016 16:19:07 +0530
Subject: rtc: ds1307: Fix relying on reset value for weekday
From: Keerthy <[email protected]>
commit e29385fab0bf94017fac130ee32f5bb2daf74417 upstream.
The reset value of weekday is 0x1. This is wrong since the reset values of the day/month/year make up to Jan 1 2001. When computed weekday comes out to be Monday. On a scale of 1-7(Sunday - Saturday) it should be 0x2. So we should not be relying on the reset value.
Hence compute the wday using the current date/month/year values. Check if reset wday is any different from the computed wday, If different then set the wday which we computed using date/month/year values.
Document Referred:
http://ww1.microchip.com/downloads/en/DeviceDoc/20002266F.pdf
--- drivers/rtc/rtc-ds1307.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-)
drivers/rtc/rtc-ds1307.c +27 -1
@@ -602,6 +602,8 @@ static const struct rtc_class_ops ds13xx* Alarm support for mcp794xx devices. */ +#define MCP794XX_REG_WEEKDAY 0x3 +#define MCP794XX_REG_WEEKDAY_WDAY_MASK 0x7#define MCP794XX_REG_CONTROL 0x07# define MCP794XX_BIT_ALM0_EN 0x10# define MCP794XX_BIT_ALM1_EN 0x20
@@ -1231,13 +1233,16 @@ static int ds1307_probe(struct i2c_clien {struct ds1307 *ds1307;int err = -ENODEV ; -int tmp; +int tmp, wday;struct chip_desc *chip = &chips[id->driver_data];struct i2c_adapter *adapter =to_i2c_adapter (client->dev.parent);bool want_irq = false;bool ds1307_can_wakeup_device = false;unsigned char *buf;struct ds1307_platform_data *pdata =dev_get_platdata (&client->dev); +struct rtc_time tm; +unsigned long timestamp; +irq_handler_t irq_handler = ds1307_irq;static const int bbsqi_bitpos[] = {
@@ -1526,6 +1531,27 @@ read_rtc: bin2bcd(tmp)); } +/* +* Some IPs have weekday reset value = 0x1 which might not correct +* hence compute the wday using the current date/month/year values +*/ +ds1307_get_time (&client->dev, &tm); + wday = tm.tm_wday; + timestamp =rtc_tm_to_time64 (&tm); +rtc_time64_to_tm (timestamp, &tm); + +/* +* Check if reset wday is different from the computed wday +* If different then set the wday which we computed using +* timestamp +*/ +if (wday != tm.tm_wday) { + wday =i2c_smbus_read_byte_data (client,MCP794XX_REG_WEEKDAY ); + wday = wday & ~MCP794XX_REG_WEEKDAY_WDAY_MASK ; + wday = wday | (tm.tm_wday +1 ); +i2c_smbus_write_byte_data (client,MCP794XX_REG_WEEKDAY , wday); + } +if (want_irq) {device_set_wakeup_capable (&client->dev, true);set_bit (HAS_ALARM , &ds1307->flags);
Patches currently in stable-queue which might be from [email protected] are
queue-4.7/rtc-ds1307-fix-relying-on-reset-value-for-weekday.patch