diff options
Diffstat (limited to 'drivers/rtc')
-rw-r--r-- | drivers/rtc/interface.c | 102 | ||||
-rw-r--r-- | drivers/rtc/rtc-at32ap700x.c | 3 | ||||
-rw-r--r-- | drivers/rtc/rtc-dev.c | 12 | ||||
-rw-r--r-- | drivers/rtc/rtc-fm3130.c | 2 | ||||
-rw-r--r-- | drivers/rtc/rtc-m41t80.c | 7 | ||||
-rw-r--r-- | drivers/rtc/rtc-pcf8563.c | 1 | ||||
-rw-r--r-- | drivers/rtc/rtc-x1205.c | 111 |
7 files changed, 202 insertions, 36 deletions
diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c index 7e3ad4f3b343..58b7336640ff 100644 --- a/drivers/rtc/interface.c +++ b/drivers/rtc/interface.c | |||
@@ -126,12 +126,25 @@ int rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm) | |||
126 | int err; | 126 | int err; |
127 | struct rtc_time before, now; | 127 | struct rtc_time before, now; |
128 | int first_time = 1; | 128 | int first_time = 1; |
129 | unsigned long t_now, t_alm; | ||
130 | enum { none, day, month, year } missing = none; | ||
131 | unsigned days; | ||
129 | 132 | ||
130 | /* The lower level RTC driver may not be capable of filling | 133 | /* The lower level RTC driver may return -1 in some fields, |
131 | * in all fields of the rtc_time struct (eg. rtc-cmos), | 134 | * creating invalid alarm->time values, for reasons like: |
132 | * and so might instead return -1 in some fields. | 135 | * |
133 | * We deal with that here by grabbing a current RTC timestamp | 136 | * - The hardware may not be capable of filling them in; |
134 | * and using values from that for any missing (-1) values. | 137 | * many alarms match only on time-of-day fields, not |
138 | * day/month/year calendar data. | ||
139 | * | ||
140 | * - Some hardware uses illegal values as "wildcard" match | ||
141 | * values, which non-Linux firmware (like a BIOS) may try | ||
142 | * to set up as e.g. "alarm 15 minutes after each hour". | ||
143 | * Linux uses only oneshot alarms. | ||
144 | * | ||
145 | * When we see that here, we deal with it by using values from | ||
146 | * a current RTC timestamp for any missing (-1) values. The | ||
147 | * RTC driver prevents "periodic alarm" modes. | ||
135 | * | 148 | * |
136 | * But this can be racey, because some fields of the RTC timestamp | 149 | * But this can be racey, because some fields of the RTC timestamp |
137 | * may have wrapped in the interval since we read the RTC alarm, | 150 | * may have wrapped in the interval since we read the RTC alarm, |
@@ -174,6 +187,10 @@ int rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm) | |||
174 | if (!alarm->enabled) | 187 | if (!alarm->enabled) |
175 | return 0; | 188 | return 0; |
176 | 189 | ||
190 | /* full-function RTCs won't have such missing fields */ | ||
191 | if (rtc_valid_tm(&alarm->time) == 0) | ||
192 | return 0; | ||
193 | |||
177 | /* get the "after" timestamp, to detect wrapped fields */ | 194 | /* get the "after" timestamp, to detect wrapped fields */ |
178 | err = rtc_read_time(rtc, &now); | 195 | err = rtc_read_time(rtc, &now); |
179 | if (err < 0) | 196 | if (err < 0) |
@@ -183,22 +200,85 @@ int rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm) | |||
183 | } while ( before.tm_min != now.tm_min | 200 | } while ( before.tm_min != now.tm_min |
184 | || before.tm_hour != now.tm_hour | 201 | || before.tm_hour != now.tm_hour |
185 | || before.tm_mon != now.tm_mon | 202 | || before.tm_mon != now.tm_mon |
186 | || before.tm_year != now.tm_year | 203 | || before.tm_year != now.tm_year); |
187 | || before.tm_isdst != now.tm_isdst); | ||
188 | 204 | ||
189 | /* Fill in any missing alarm fields using the timestamp */ | 205 | /* Fill in the missing alarm fields using the timestamp; we |
206 | * know there's at least one since alarm->time is invalid. | ||
207 | */ | ||
190 | if (alarm->time.tm_sec == -1) | 208 | if (alarm->time.tm_sec == -1) |
191 | alarm->time.tm_sec = now.tm_sec; | 209 | alarm->time.tm_sec = now.tm_sec; |
192 | if (alarm->time.tm_min == -1) | 210 | if (alarm->time.tm_min == -1) |
193 | alarm->time.tm_min = now.tm_min; | 211 | alarm->time.tm_min = now.tm_min; |
194 | if (alarm->time.tm_hour == -1) | 212 | if (alarm->time.tm_hour == -1) |
195 | alarm->time.tm_hour = now.tm_hour; | 213 | alarm->time.tm_hour = now.tm_hour; |
196 | if (alarm->time.tm_mday == -1) | 214 | |
215 | /* For simplicity, only support date rollover for now */ | ||
216 | if (alarm->time.tm_mday == -1) { | ||
197 | alarm->time.tm_mday = now.tm_mday; | 217 | alarm->time.tm_mday = now.tm_mday; |
198 | if (alarm->time.tm_mon == -1) | 218 | missing = day; |
219 | } | ||
220 | if (alarm->time.tm_mon == -1) { | ||
199 | alarm->time.tm_mon = now.tm_mon; | 221 | alarm->time.tm_mon = now.tm_mon; |
200 | if (alarm->time.tm_year == -1) | 222 | if (missing == none) |
223 | missing = month; | ||
224 | } | ||
225 | if (alarm->time.tm_year == -1) { | ||
201 | alarm->time.tm_year = now.tm_year; | 226 | alarm->time.tm_year = now.tm_year; |
227 | if (missing == none) | ||
228 | missing = year; | ||
229 | } | ||
230 | |||
231 | /* with luck, no rollover is needed */ | ||
232 | rtc_tm_to_time(&now, &t_now); | ||
233 | rtc_tm_to_time(&alarm->time, &t_alm); | ||
234 | if (t_now < t_alm) | ||
235 | goto done; | ||
236 | |||
237 | switch (missing) { | ||
238 | |||
239 | /* 24 hour rollover ... if it's now 10am Monday, an alarm that | ||
240 | * that will trigger at 5am will do so at 5am Tuesday, which | ||
241 | * could also be in the next month or year. This is a common | ||
242 | * case, especially for PCs. | ||
243 | */ | ||
244 | case day: | ||
245 | dev_dbg(&rtc->dev, "alarm rollover: %s\n", "day"); | ||
246 | t_alm += 24 * 60 * 60; | ||
247 | rtc_time_to_tm(t_alm, &alarm->time); | ||
248 | break; | ||
249 | |||
250 | /* Month rollover ... if it's the 31th, an alarm on the 3rd will | ||
251 | * be next month. An alarm matching on the 30th, 29th, or 28th | ||
252 | * may end up in the month after that! Many newer PCs support | ||
253 | * this type of alarm. | ||
254 | */ | ||
255 | case month: | ||
256 | dev_dbg(&rtc->dev, "alarm rollover: %s\n", "month"); | ||
257 | do { | ||
258 | if (alarm->time.tm_mon < 11) | ||
259 | alarm->time.tm_mon++; | ||
260 | else { | ||
261 | alarm->time.tm_mon = 0; | ||
262 | alarm->time.tm_year++; | ||
263 | } | ||
264 | days = rtc_month_days(alarm->time.tm_mon, | ||
265 | alarm->time.tm_year); | ||
266 | } while (days < alarm->time.tm_mday); | ||
267 | break; | ||
268 | |||
269 | /* Year rollover ... easy except for leap years! */ | ||
270 | case year: | ||
271 | dev_dbg(&rtc->dev, "alarm rollover: %s\n", "year"); | ||
272 | do { | ||
273 | alarm->time.tm_year++; | ||
274 | } while (!rtc_valid_tm(&alarm->time)); | ||
275 | break; | ||
276 | |||
277 | default: | ||
278 | dev_warn(&rtc->dev, "alarm rollover not handled\n"); | ||
279 | } | ||
280 | |||
281 | done: | ||
202 | return 0; | 282 | return 0; |
203 | } | 283 | } |
204 | EXPORT_SYMBOL_GPL(rtc_read_alarm); | 284 | EXPORT_SYMBOL_GPL(rtc_read_alarm); |
diff --git a/drivers/rtc/rtc-at32ap700x.c b/drivers/rtc/rtc-at32ap700x.c index 2ef8cdfda4a7..90b9a6503e15 100644 --- a/drivers/rtc/rtc-at32ap700x.c +++ b/drivers/rtc/rtc-at32ap700x.c | |||
@@ -265,6 +265,7 @@ static int __init at32_rtc_probe(struct platform_device *pdev) | |||
265 | } | 265 | } |
266 | 266 | ||
267 | platform_set_drvdata(pdev, rtc); | 267 | platform_set_drvdata(pdev, rtc); |
268 | device_init_wakeup(&pdev->dev, 1); | ||
268 | 269 | ||
269 | dev_info(&pdev->dev, "Atmel RTC for AT32AP700x at %08lx irq %ld\n", | 270 | dev_info(&pdev->dev, "Atmel RTC for AT32AP700x at %08lx irq %ld\n", |
270 | (unsigned long)rtc->regs, rtc->irq); | 271 | (unsigned long)rtc->regs, rtc->irq); |
@@ -284,6 +285,8 @@ static int __exit at32_rtc_remove(struct platform_device *pdev) | |||
284 | { | 285 | { |
285 | struct rtc_at32ap700x *rtc = platform_get_drvdata(pdev); | 286 | struct rtc_at32ap700x *rtc = platform_get_drvdata(pdev); |
286 | 287 | ||
288 | device_init_wakeup(&pdev->dev, 0); | ||
289 | |||
287 | free_irq(rtc->irq, rtc); | 290 | free_irq(rtc->irq, rtc); |
288 | iounmap(rtc->regs); | 291 | iounmap(rtc->regs); |
289 | rtc_device_unregister(rtc->rtc); | 292 | rtc_device_unregister(rtc->rtc); |
diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c index 90dfa0df747a..0114a78b7cbb 100644 --- a/drivers/rtc/rtc-dev.c +++ b/drivers/rtc/rtc-dev.c | |||
@@ -13,6 +13,7 @@ | |||
13 | 13 | ||
14 | #include <linux/module.h> | 14 | #include <linux/module.h> |
15 | #include <linux/rtc.h> | 15 | #include <linux/rtc.h> |
16 | #include <linux/smp_lock.h> | ||
16 | #include "rtc-core.h" | 17 | #include "rtc-core.h" |
17 | 18 | ||
18 | static dev_t rtc_devt; | 19 | static dev_t rtc_devt; |
@@ -26,8 +27,11 @@ static int rtc_dev_open(struct inode *inode, struct file *file) | |||
26 | struct rtc_device, char_dev); | 27 | struct rtc_device, char_dev); |
27 | const struct rtc_class_ops *ops = rtc->ops; | 28 | const struct rtc_class_ops *ops = rtc->ops; |
28 | 29 | ||
29 | if (test_and_set_bit_lock(RTC_DEV_BUSY, &rtc->flags)) | 30 | lock_kernel(); |
30 | return -EBUSY; | 31 | if (test_and_set_bit_lock(RTC_DEV_BUSY, &rtc->flags)) { |
32 | err = -EBUSY; | ||
33 | goto out; | ||
34 | } | ||
31 | 35 | ||
32 | file->private_data = rtc; | 36 | file->private_data = rtc; |
33 | 37 | ||
@@ -37,11 +41,13 @@ static int rtc_dev_open(struct inode *inode, struct file *file) | |||
37 | rtc->irq_data = 0; | 41 | rtc->irq_data = 0; |
38 | spin_unlock_irq(&rtc->irq_lock); | 42 | spin_unlock_irq(&rtc->irq_lock); |
39 | 43 | ||
40 | return 0; | 44 | goto out; |
41 | } | 45 | } |
42 | 46 | ||
43 | /* something has gone wrong */ | 47 | /* something has gone wrong */ |
44 | clear_bit_unlock(RTC_DEV_BUSY, &rtc->flags); | 48 | clear_bit_unlock(RTC_DEV_BUSY, &rtc->flags); |
49 | out: | ||
50 | unlock_kernel(); | ||
45 | return err; | 51 | return err; |
46 | } | 52 | } |
47 | 53 | ||
diff --git a/drivers/rtc/rtc-fm3130.c b/drivers/rtc/rtc-fm3130.c index 11644c8fca82..abfdfcbaa059 100644 --- a/drivers/rtc/rtc-fm3130.c +++ b/drivers/rtc/rtc-fm3130.c | |||
@@ -55,7 +55,7 @@ struct fm3130 { | |||
55 | int alarm; | 55 | int alarm; |
56 | }; | 56 | }; |
57 | static const struct i2c_device_id fm3130_id[] = { | 57 | static const struct i2c_device_id fm3130_id[] = { |
58 | { "fm3130-rtc", 0 }, | 58 | { "fm3130", 0 }, |
59 | { } | 59 | { } |
60 | }; | 60 | }; |
61 | MODULE_DEVICE_TABLE(i2c, fm3130_id); | 61 | MODULE_DEVICE_TABLE(i2c, fm3130_id); |
diff --git a/drivers/rtc/rtc-m41t80.c b/drivers/rtc/rtc-m41t80.c index a3e0880b38fb..0a19c06019be 100644 --- a/drivers/rtc/rtc-m41t80.c +++ b/drivers/rtc/rtc-m41t80.c | |||
@@ -17,6 +17,7 @@ | |||
17 | #include <linux/init.h> | 17 | #include <linux/init.h> |
18 | #include <linux/kernel.h> | 18 | #include <linux/kernel.h> |
19 | #include <linux/slab.h> | 19 | #include <linux/slab.h> |
20 | #include <linux/smp_lock.h> | ||
20 | #include <linux/string.h> | 21 | #include <linux/string.h> |
21 | #include <linux/i2c.h> | 22 | #include <linux/i2c.h> |
22 | #include <linux/rtc.h> | 23 | #include <linux/rtc.h> |
@@ -655,12 +656,16 @@ static int wdt_ioctl(struct inode *inode, struct file *file, unsigned int cmd, | |||
655 | static int wdt_open(struct inode *inode, struct file *file) | 656 | static int wdt_open(struct inode *inode, struct file *file) |
656 | { | 657 | { |
657 | if (MINOR(inode->i_rdev) == WATCHDOG_MINOR) { | 658 | if (MINOR(inode->i_rdev) == WATCHDOG_MINOR) { |
658 | if (test_and_set_bit(0, &wdt_is_open)) | 659 | lock_kernel(); |
660 | if (test_and_set_bit(0, &wdt_is_open)) { | ||
661 | unlock_kernel(); | ||
659 | return -EBUSY; | 662 | return -EBUSY; |
663 | } | ||
660 | /* | 664 | /* |
661 | * Activate | 665 | * Activate |
662 | */ | 666 | */ |
663 | wdt_is_open = 1; | 667 | wdt_is_open = 1; |
668 | unlock_kernel(); | ||
664 | return 0; | 669 | return 0; |
665 | } | 670 | } |
666 | return -ENODEV; | 671 | return -ENODEV; |
diff --git a/drivers/rtc/rtc-pcf8563.c b/drivers/rtc/rtc-pcf8563.c index 0fc4c3630780..748a502a6355 100644 --- a/drivers/rtc/rtc-pcf8563.c +++ b/drivers/rtc/rtc-pcf8563.c | |||
@@ -302,6 +302,7 @@ static int pcf8563_remove(struct i2c_client *client) | |||
302 | 302 | ||
303 | static const struct i2c_device_id pcf8563_id[] = { | 303 | static const struct i2c_device_id pcf8563_id[] = { |
304 | { "pcf8563", 0 }, | 304 | { "pcf8563", 0 }, |
305 | { "rtc8564", 0 }, | ||
305 | { } | 306 | { } |
306 | }; | 307 | }; |
307 | MODULE_DEVICE_TABLE(i2c, pcf8563_id); | 308 | MODULE_DEVICE_TABLE(i2c, pcf8563_id); |
diff --git a/drivers/rtc/rtc-x1205.c b/drivers/rtc/rtc-x1205.c index eaf55945f21b..7dcfba1bbfe1 100644 --- a/drivers/rtc/rtc-x1205.c +++ b/drivers/rtc/rtc-x1205.c | |||
@@ -71,6 +71,7 @@ | |||
71 | #define X1205_SR_RTCF 0x01 /* Clock failure */ | 71 | #define X1205_SR_RTCF 0x01 /* Clock failure */ |
72 | #define X1205_SR_WEL 0x02 /* Write Enable Latch */ | 72 | #define X1205_SR_WEL 0x02 /* Write Enable Latch */ |
73 | #define X1205_SR_RWEL 0x04 /* Register Write Enable */ | 73 | #define X1205_SR_RWEL 0x04 /* Register Write Enable */ |
74 | #define X1205_SR_AL0 0x20 /* Alarm 0 match */ | ||
74 | 75 | ||
75 | #define X1205_DTR_DTR0 0x01 | 76 | #define X1205_DTR_DTR0 0x01 |
76 | #define X1205_DTR_DTR1 0x02 | 77 | #define X1205_DTR_DTR1 0x02 |
@@ -78,6 +79,8 @@ | |||
78 | 79 | ||
79 | #define X1205_HR_MIL 0x80 /* Set in ccr.hour for 24 hr mode */ | 80 | #define X1205_HR_MIL 0x80 /* Set in ccr.hour for 24 hr mode */ |
80 | 81 | ||
82 | #define X1205_INT_AL0E 0x20 /* Alarm 0 enable */ | ||
83 | |||
81 | static struct i2c_driver x1205_driver; | 84 | static struct i2c_driver x1205_driver; |
82 | 85 | ||
83 | /* | 86 | /* |
@@ -89,8 +92,8 @@ static int x1205_get_datetime(struct i2c_client *client, struct rtc_time *tm, | |||
89 | unsigned char reg_base) | 92 | unsigned char reg_base) |
90 | { | 93 | { |
91 | unsigned char dt_addr[2] = { 0, reg_base }; | 94 | unsigned char dt_addr[2] = { 0, reg_base }; |
92 | |||
93 | unsigned char buf[8]; | 95 | unsigned char buf[8]; |
96 | int i; | ||
94 | 97 | ||
95 | struct i2c_msg msgs[] = { | 98 | struct i2c_msg msgs[] = { |
96 | { client->addr, 0, 2, dt_addr }, /* setup read ptr */ | 99 | { client->addr, 0, 2, dt_addr }, /* setup read ptr */ |
@@ -98,7 +101,7 @@ static int x1205_get_datetime(struct i2c_client *client, struct rtc_time *tm, | |||
98 | }; | 101 | }; |
99 | 102 | ||
100 | /* read date registers */ | 103 | /* read date registers */ |
101 | if ((i2c_transfer(client->adapter, &msgs[0], 2)) != 2) { | 104 | if (i2c_transfer(client->adapter, &msgs[0], 2) != 2) { |
102 | dev_err(&client->dev, "%s: read error\n", __func__); | 105 | dev_err(&client->dev, "%s: read error\n", __func__); |
103 | return -EIO; | 106 | return -EIO; |
104 | } | 107 | } |
@@ -110,6 +113,11 @@ static int x1205_get_datetime(struct i2c_client *client, struct rtc_time *tm, | |||
110 | buf[0], buf[1], buf[2], buf[3], | 113 | buf[0], buf[1], buf[2], buf[3], |
111 | buf[4], buf[5], buf[6], buf[7]); | 114 | buf[4], buf[5], buf[6], buf[7]); |
112 | 115 | ||
116 | /* Mask out the enable bits if these are alarm registers */ | ||
117 | if (reg_base < X1205_CCR_BASE) | ||
118 | for (i = 0; i <= 4; i++) | ||
119 | buf[i] &= 0x7F; | ||
120 | |||
113 | tm->tm_sec = BCD2BIN(buf[CCR_SEC]); | 121 | tm->tm_sec = BCD2BIN(buf[CCR_SEC]); |
114 | tm->tm_min = BCD2BIN(buf[CCR_MIN]); | 122 | tm->tm_min = BCD2BIN(buf[CCR_MIN]); |
115 | tm->tm_hour = BCD2BIN(buf[CCR_HOUR] & 0x3F); /* hr is 0-23 */ | 123 | tm->tm_hour = BCD2BIN(buf[CCR_HOUR] & 0x3F); /* hr is 0-23 */ |
@@ -138,7 +146,7 @@ static int x1205_get_status(struct i2c_client *client, unsigned char *sr) | |||
138 | }; | 146 | }; |
139 | 147 | ||
140 | /* read status register */ | 148 | /* read status register */ |
141 | if ((i2c_transfer(client->adapter, &msgs[0], 2)) != 2) { | 149 | if (i2c_transfer(client->adapter, &msgs[0], 2) != 2) { |
142 | dev_err(&client->dev, "%s: read error\n", __func__); | 150 | dev_err(&client->dev, "%s: read error\n", __func__); |
143 | return -EIO; | 151 | return -EIO; |
144 | } | 152 | } |
@@ -147,10 +155,11 @@ static int x1205_get_status(struct i2c_client *client, unsigned char *sr) | |||
147 | } | 155 | } |
148 | 156 | ||
149 | static int x1205_set_datetime(struct i2c_client *client, struct rtc_time *tm, | 157 | static int x1205_set_datetime(struct i2c_client *client, struct rtc_time *tm, |
150 | int datetoo, u8 reg_base) | 158 | int datetoo, u8 reg_base, unsigned char alm_enable) |
151 | { | 159 | { |
152 | int i, xfer; | 160 | int i, xfer, nbytes; |
153 | unsigned char buf[8]; | 161 | unsigned char buf[8]; |
162 | unsigned char rdata[10] = { 0, reg_base }; | ||
154 | 163 | ||
155 | static const unsigned char wel[3] = { 0, X1205_REG_SR, | 164 | static const unsigned char wel[3] = { 0, X1205_REG_SR, |
156 | X1205_SR_WEL }; | 165 | X1205_SR_WEL }; |
@@ -189,6 +198,11 @@ static int x1205_set_datetime(struct i2c_client *client, struct rtc_time *tm, | |||
189 | buf[CCR_Y2K] = BIN2BCD(tm->tm_year / 100); | 198 | buf[CCR_Y2K] = BIN2BCD(tm->tm_year / 100); |
190 | } | 199 | } |
191 | 200 | ||
201 | /* If writing alarm registers, set compare bits on registers 0-4 */ | ||
202 | if (reg_base < X1205_CCR_BASE) | ||
203 | for (i = 0; i <= 4; i++) | ||
204 | buf[i] |= 0x80; | ||
205 | |||
192 | /* this sequence is required to unlock the chip */ | 206 | /* this sequence is required to unlock the chip */ |
193 | if ((xfer = i2c_master_send(client, wel, 3)) != 3) { | 207 | if ((xfer = i2c_master_send(client, wel, 3)) != 3) { |
194 | dev_err(&client->dev, "%s: wel - %d\n", __func__, xfer); | 208 | dev_err(&client->dev, "%s: wel - %d\n", __func__, xfer); |
@@ -200,19 +214,57 @@ static int x1205_set_datetime(struct i2c_client *client, struct rtc_time *tm, | |||
200 | return -EIO; | 214 | return -EIO; |
201 | } | 215 | } |
202 | 216 | ||
217 | |||
203 | /* write register's data */ | 218 | /* write register's data */ |
204 | for (i = 0; i < (datetoo ? 8 : 3); i++) { | 219 | if (datetoo) |
205 | unsigned char rdata[3] = { 0, reg_base + i, buf[i] }; | 220 | nbytes = 8; |
221 | else | ||
222 | nbytes = 3; | ||
223 | for (i = 0; i < nbytes; i++) | ||
224 | rdata[2+i] = buf[i]; | ||
225 | |||
226 | xfer = i2c_master_send(client, rdata, nbytes+2); | ||
227 | if (xfer != nbytes+2) { | ||
228 | dev_err(&client->dev, | ||
229 | "%s: result=%d addr=%02x, data=%02x\n", | ||
230 | __func__, | ||
231 | xfer, rdata[1], rdata[2]); | ||
232 | return -EIO; | ||
233 | } | ||
234 | |||
235 | /* If we wrote to the nonvolatile region, wait 10msec for write cycle*/ | ||
236 | if (reg_base < X1205_CCR_BASE) { | ||
237 | unsigned char al0e[3] = { 0, X1205_REG_INT, 0 }; | ||
238 | |||
239 | msleep(10); | ||
206 | 240 | ||
207 | xfer = i2c_master_send(client, rdata, 3); | 241 | /* ...and set or clear the AL0E bit in the INT register */ |
242 | |||
243 | /* Need to set RWEL again as the write has cleared it */ | ||
244 | xfer = i2c_master_send(client, rwel, 3); | ||
208 | if (xfer != 3) { | 245 | if (xfer != 3) { |
209 | dev_err(&client->dev, | 246 | dev_err(&client->dev, |
210 | "%s: xfer=%d addr=%02x, data=%02x\n", | 247 | "%s: aloe rwel - %d\n", |
211 | __func__, | 248 | __func__, |
212 | xfer, rdata[1], rdata[2]); | 249 | xfer); |
250 | return -EIO; | ||
251 | } | ||
252 | |||
253 | if (alm_enable) | ||
254 | al0e[2] = X1205_INT_AL0E; | ||
255 | |||
256 | xfer = i2c_master_send(client, al0e, 3); | ||
257 | if (xfer != 3) { | ||
258 | dev_err(&client->dev, | ||
259 | "%s: al0e - %d\n", | ||
260 | __func__, | ||
261 | xfer); | ||
213 | return -EIO; | 262 | return -EIO; |
214 | } | 263 | } |
215 | }; | 264 | |
265 | /* and wait 10msec again for this write to complete */ | ||
266 | msleep(10); | ||
267 | } | ||
216 | 268 | ||
217 | /* disable further writes */ | 269 | /* disable further writes */ |
218 | if ((xfer = i2c_master_send(client, diswe, 3)) != 3) { | 270 | if ((xfer = i2c_master_send(client, diswe, 3)) != 3) { |
@@ -230,9 +282,9 @@ static int x1205_fix_osc(struct i2c_client *client) | |||
230 | 282 | ||
231 | tm.tm_hour = tm.tm_min = tm.tm_sec = 0; | 283 | tm.tm_hour = tm.tm_min = tm.tm_sec = 0; |
232 | 284 | ||
233 | if ((err = x1205_set_datetime(client, &tm, 0, X1205_CCR_BASE)) < 0) | 285 | err = x1205_set_datetime(client, &tm, 0, X1205_CCR_BASE, 0); |
234 | dev_err(&client->dev, | 286 | if (err < 0) |
235 | "unable to restart the oscillator\n"); | 287 | dev_err(&client->dev, "unable to restart the oscillator\n"); |
236 | 288 | ||
237 | return err; | 289 | return err; |
238 | } | 290 | } |
@@ -248,7 +300,7 @@ static int x1205_get_dtrim(struct i2c_client *client, int *trim) | |||
248 | }; | 300 | }; |
249 | 301 | ||
250 | /* read dtr register */ | 302 | /* read dtr register */ |
251 | if ((i2c_transfer(client->adapter, &msgs[0], 2)) != 2) { | 303 | if (i2c_transfer(client->adapter, &msgs[0], 2) != 2) { |
252 | dev_err(&client->dev, "%s: read error\n", __func__); | 304 | dev_err(&client->dev, "%s: read error\n", __func__); |
253 | return -EIO; | 305 | return -EIO; |
254 | } | 306 | } |
@@ -280,7 +332,7 @@ static int x1205_get_atrim(struct i2c_client *client, int *trim) | |||
280 | }; | 332 | }; |
281 | 333 | ||
282 | /* read atr register */ | 334 | /* read atr register */ |
283 | if ((i2c_transfer(client->adapter, &msgs[0], 2)) != 2) { | 335 | if (i2c_transfer(client->adapter, &msgs[0], 2) != 2) { |
284 | dev_err(&client->dev, "%s: read error\n", __func__); | 336 | dev_err(&client->dev, "%s: read error\n", __func__); |
285 | return -EIO; | 337 | return -EIO; |
286 | } | 338 | } |
@@ -403,14 +455,33 @@ static int x1205_validate_client(struct i2c_client *client) | |||
403 | 455 | ||
404 | static int x1205_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) | 456 | static int x1205_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) |
405 | { | 457 | { |
406 | return x1205_get_datetime(to_i2c_client(dev), | 458 | int err; |
407 | &alrm->time, X1205_ALM0_BASE); | 459 | unsigned char intreg, status; |
460 | static unsigned char int_addr[2] = { 0, X1205_REG_INT }; | ||
461 | struct i2c_client *client = to_i2c_client(dev); | ||
462 | struct i2c_msg msgs[] = { | ||
463 | { client->addr, 0, 2, int_addr }, /* setup read ptr */ | ||
464 | { client->addr, I2C_M_RD, 1, &intreg }, /* read INT register */ | ||
465 | }; | ||
466 | |||
467 | /* read interrupt register and status register */ | ||
468 | if (i2c_transfer(client->adapter, &msgs[0], 2) != 2) { | ||
469 | dev_err(&client->dev, "%s: read error\n", __func__); | ||
470 | return -EIO; | ||
471 | } | ||
472 | err = x1205_get_status(client, &status); | ||
473 | if (err == 0) { | ||
474 | alrm->pending = (status & X1205_SR_AL0) ? 1 : 0; | ||
475 | alrm->enabled = (intreg & X1205_INT_AL0E) ? 1 : 0; | ||
476 | err = x1205_get_datetime(client, &alrm->time, X1205_ALM0_BASE); | ||
477 | } | ||
478 | return err; | ||
408 | } | 479 | } |
409 | 480 | ||
410 | static int x1205_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) | 481 | static int x1205_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) |
411 | { | 482 | { |
412 | return x1205_set_datetime(to_i2c_client(dev), | 483 | return x1205_set_datetime(to_i2c_client(dev), |
413 | &alrm->time, 1, X1205_ALM0_BASE); | 484 | &alrm->time, 1, X1205_ALM0_BASE, alrm->enabled); |
414 | } | 485 | } |
415 | 486 | ||
416 | static int x1205_rtc_read_time(struct device *dev, struct rtc_time *tm) | 487 | static int x1205_rtc_read_time(struct device *dev, struct rtc_time *tm) |
@@ -422,7 +493,7 @@ static int x1205_rtc_read_time(struct device *dev, struct rtc_time *tm) | |||
422 | static int x1205_rtc_set_time(struct device *dev, struct rtc_time *tm) | 493 | static int x1205_rtc_set_time(struct device *dev, struct rtc_time *tm) |
423 | { | 494 | { |
424 | return x1205_set_datetime(to_i2c_client(dev), | 495 | return x1205_set_datetime(to_i2c_client(dev), |
425 | tm, 1, X1205_CCR_BASE); | 496 | tm, 1, X1205_CCR_BASE, 0); |
426 | } | 497 | } |
427 | 498 | ||
428 | static int x1205_rtc_proc(struct device *dev, struct seq_file *seq) | 499 | static int x1205_rtc_proc(struct device *dev, struct seq_file *seq) |