diff options
author | Sergey Yanovich <ynvich@gmail.com> | 2013-07-03 18:07:46 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2013-07-03 19:07:59 -0400 |
commit | dfc657b1330990213a3865aaef9d8af563ccad51 (patch) | |
tree | 412b7c83788b31c5448376c3663acd17390fa869 /drivers/rtc | |
parent | 25d053cf1040e6430fff679854b3710edb0b7fee (diff) |
drivers/rtc/rtc-ds1302.c: handle write protection
This chip has a control register and can prevent altering saved clock.
Without this patch we could have:
(arm)root@pac14:~# date
Tue May 21 03:08:27 MSK 2013
(arm)root@pac14:~# /etc/init.d/hwclock.sh show
Tue May 21 11:13:58 2013 -0.067322 seconds
(arm)root@pac14:~# /etc/init.d/hwclock.sh stop
[info] Saving the system clock.
[info] Hardware Clock updated to Tue May 21 03:09:01 MSK 2013.
(arm)root@pac14:~# /etc/init.d/hwclock.sh show
Tue May 21 11:14:15 2013 -0.624272 seconds
The patch enables write access to rtc before the driver tries to write
time and re-disables when time data is written.
Signed-off-by: Sergey Yanovich <ynvich@gmail.com>
Acked-by: Marc Zyngier <maz@misterjones.org>
Cc: Alessandro Zummo <a.zummo@towertech.it>
Cc: Sachin Kamat <sachin.kamat@linaro.org>
Cc: Jingoo Han <jg1.han@samsung.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/rtc')
-rw-r--r-- | drivers/rtc/rtc-ds1302.c | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/drivers/rtc/rtc-ds1302.c b/drivers/rtc/rtc-ds1302.c index 7533b723082d..07e8d79b4a09 100644 --- a/drivers/rtc/rtc-ds1302.c +++ b/drivers/rtc/rtc-ds1302.c | |||
@@ -23,8 +23,12 @@ | |||
23 | #define RTC_CMD_READ 0x81 /* Read command */ | 23 | #define RTC_CMD_READ 0x81 /* Read command */ |
24 | #define RTC_CMD_WRITE 0x80 /* Write command */ | 24 | #define RTC_CMD_WRITE 0x80 /* Write command */ |
25 | 25 | ||
26 | #define RTC_CMD_WRITE_ENABLE 0x00 /* Write enable */ | ||
27 | #define RTC_CMD_WRITE_DISABLE 0x80 /* Write disable */ | ||
28 | |||
26 | #define RTC_ADDR_RAM0 0x20 /* Address of RAM0 */ | 29 | #define RTC_ADDR_RAM0 0x20 /* Address of RAM0 */ |
27 | #define RTC_ADDR_TCR 0x08 /* Address of trickle charge register */ | 30 | #define RTC_ADDR_TCR 0x08 /* Address of trickle charge register */ |
31 | #define RTC_ADDR_CTRL 0x07 /* Address of control register */ | ||
28 | #define RTC_ADDR_YEAR 0x06 /* Address of year register */ | 32 | #define RTC_ADDR_YEAR 0x06 /* Address of year register */ |
29 | #define RTC_ADDR_DAY 0x05 /* Address of day of week register */ | 33 | #define RTC_ADDR_DAY 0x05 /* Address of day of week register */ |
30 | #define RTC_ADDR_MON 0x04 /* Address of month register */ | 34 | #define RTC_ADDR_MON 0x04 /* Address of month register */ |
@@ -161,6 +165,7 @@ static int ds1302_rtc_read_time(struct device *dev, struct rtc_time *tm) | |||
161 | 165 | ||
162 | static int ds1302_rtc_set_time(struct device *dev, struct rtc_time *tm) | 166 | static int ds1302_rtc_set_time(struct device *dev, struct rtc_time *tm) |
163 | { | 167 | { |
168 | ds1302_writebyte(RTC_ADDR_CTRL, RTC_CMD_WRITE_ENABLE); | ||
164 | /* Stop RTC */ | 169 | /* Stop RTC */ |
165 | ds1302_writebyte(RTC_ADDR_SEC, ds1302_readbyte(RTC_ADDR_SEC) | 0x80); | 170 | ds1302_writebyte(RTC_ADDR_SEC, ds1302_readbyte(RTC_ADDR_SEC) | 0x80); |
166 | 171 | ||
@@ -175,6 +180,8 @@ static int ds1302_rtc_set_time(struct device *dev, struct rtc_time *tm) | |||
175 | /* Start RTC */ | 180 | /* Start RTC */ |
176 | ds1302_writebyte(RTC_ADDR_SEC, ds1302_readbyte(RTC_ADDR_SEC) & ~0x80); | 181 | ds1302_writebyte(RTC_ADDR_SEC, ds1302_readbyte(RTC_ADDR_SEC) & ~0x80); |
177 | 182 | ||
183 | ds1302_writebyte(RTC_ADDR_CTRL, RTC_CMD_WRITE_DISABLE); | ||
184 | |||
178 | return 0; | 185 | return 0; |
179 | } | 186 | } |
180 | 187 | ||