diff options
Diffstat (limited to 'drivers/rtc')
-rw-r--r-- | drivers/rtc/Kconfig | 17 | ||||
-rw-r--r-- | drivers/rtc/Makefile | 1 | ||||
-rw-r--r-- | drivers/rtc/rtc-ds1307.c | 189 | ||||
-rw-r--r-- | drivers/rtc/rtc-ds1374.c | 6 | ||||
-rw-r--r-- | drivers/rtc/rtc-efi.c | 235 | ||||
-rw-r--r-- | drivers/rtc/rtc-lib.c | 7 | ||||
-rw-r--r-- | drivers/rtc/rtc-parisc.c | 56 | ||||
-rw-r--r-- | drivers/rtc/rtc-v3020.c | 40 | ||||
-rw-r--r-- | drivers/rtc/rtc-wm8350.c | 43 |
9 files changed, 486 insertions, 108 deletions
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig index 81450fbd8b1..09d5cd33a3f 100644 --- a/drivers/rtc/Kconfig +++ b/drivers/rtc/Kconfig | |||
@@ -129,13 +129,14 @@ comment "I2C RTC drivers" | |||
129 | if I2C | 129 | if I2C |
130 | 130 | ||
131 | config RTC_DRV_DS1307 | 131 | config RTC_DRV_DS1307 |
132 | tristate "Dallas/Maxim DS1307/37/38/39/40, ST M41T00" | 132 | tristate "Dallas/Maxim DS1307/37/38/39/40, ST M41T00, EPSON RX-8025" |
133 | help | 133 | help |
134 | If you say yes here you get support for various compatible RTC | 134 | If you say yes here you get support for various compatible RTC |
135 | chips (often with battery backup) connected with I2C. This driver | 135 | chips (often with battery backup) connected with I2C. This driver |
136 | should handle DS1307, DS1337, DS1338, DS1339, DS1340, ST M41T00, | 136 | should handle DS1307, DS1337, DS1338, DS1339, DS1340, ST M41T00, |
137 | and probably other chips. In some cases the RTC must already | 137 | EPSON RX-8025 and probably other chips. In some cases the RTC |
138 | have been initialized (by manufacturing or a bootloader). | 138 | must already have been initialized (by manufacturing or a |
139 | bootloader). | ||
139 | 140 | ||
140 | The first seven registers on these chips hold an RTC, and other | 141 | The first seven registers on these chips hold an RTC, and other |
141 | registers may add features such as NVRAM, a trickle charger for | 142 | registers may add features such as NVRAM, a trickle charger for |
@@ -440,6 +441,16 @@ config RTC_DRV_DS1742 | |||
440 | This driver can also be built as a module. If so, the module | 441 | This driver can also be built as a module. If so, the module |
441 | will be called rtc-ds1742. | 442 | will be called rtc-ds1742. |
442 | 443 | ||
444 | config RTC_DRV_EFI | ||
445 | tristate "EFI RTC" | ||
446 | depends on IA64 | ||
447 | help | ||
448 | If you say yes here you will get support for the EFI | ||
449 | Real Time Clock. | ||
450 | |||
451 | This driver can also be built as a module. If so, the module | ||
452 | will be called rtc-efi. | ||
453 | |||
443 | config RTC_DRV_STK17TA8 | 454 | config RTC_DRV_STK17TA8 |
444 | tristate "Simtek STK17TA8" | 455 | tristate "Simtek STK17TA8" |
445 | depends on RTC_CLASS | 456 | depends on RTC_CLASS |
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile index 0e697aa51ca..e7b09986d26 100644 --- a/drivers/rtc/Makefile +++ b/drivers/rtc/Makefile | |||
@@ -36,6 +36,7 @@ obj-$(CONFIG_RTC_DRV_DS1553) += rtc-ds1553.o | |||
36 | obj-$(CONFIG_RTC_DRV_DS1672) += rtc-ds1672.o | 36 | obj-$(CONFIG_RTC_DRV_DS1672) += rtc-ds1672.o |
37 | obj-$(CONFIG_RTC_DRV_DS1742) += rtc-ds1742.o | 37 | obj-$(CONFIG_RTC_DRV_DS1742) += rtc-ds1742.o |
38 | obj-$(CONFIG_RTC_DRV_DS3234) += rtc-ds3234.o | 38 | obj-$(CONFIG_RTC_DRV_DS3234) += rtc-ds3234.o |
39 | obj-$(CONFIG_RTC_DRV_EFI) += rtc-efi.o | ||
39 | obj-$(CONFIG_RTC_DRV_EP93XX) += rtc-ep93xx.o | 40 | obj-$(CONFIG_RTC_DRV_EP93XX) += rtc-ep93xx.o |
40 | obj-$(CONFIG_RTC_DRV_FM3130) += rtc-fm3130.o | 41 | obj-$(CONFIG_RTC_DRV_FM3130) += rtc-fm3130.o |
41 | obj-$(CONFIG_RTC_DRV_ISL1208) += rtc-isl1208.o | 42 | obj-$(CONFIG_RTC_DRV_ISL1208) += rtc-isl1208.o |
diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c index 7e5155e88ac..2c4a65302a9 100644 --- a/drivers/rtc/rtc-ds1307.c +++ b/drivers/rtc/rtc-ds1307.c | |||
@@ -3,6 +3,7 @@ | |||
3 | * | 3 | * |
4 | * Copyright (C) 2005 James Chapman (ds1337 core) | 4 | * Copyright (C) 2005 James Chapman (ds1337 core) |
5 | * Copyright (C) 2006 David Brownell | 5 | * Copyright (C) 2006 David Brownell |
6 | * Copyright (C) 2009 Matthias Fuchs (rx8025 support) | ||
6 | * | 7 | * |
7 | * This program is free software; you can redistribute it and/or modify | 8 | * This program is free software; you can redistribute it and/or modify |
8 | * it under the terms of the GNU General Public License version 2 as | 9 | * it under the terms of the GNU General Public License version 2 as |
@@ -31,6 +32,7 @@ enum ds_type { | |||
31 | ds_1339, | 32 | ds_1339, |
32 | ds_1340, | 33 | ds_1340, |
33 | m41t00, | 34 | m41t00, |
35 | rx_8025, | ||
34 | // rs5c372 too? different address... | 36 | // rs5c372 too? different address... |
35 | }; | 37 | }; |
36 | 38 | ||
@@ -83,6 +85,12 @@ enum ds_type { | |||
83 | #define DS1339_REG_ALARM1_SECS 0x07 | 85 | #define DS1339_REG_ALARM1_SECS 0x07 |
84 | #define DS1339_REG_TRICKLE 0x10 | 86 | #define DS1339_REG_TRICKLE 0x10 |
85 | 87 | ||
88 | #define RX8025_REG_CTRL1 0x0e | ||
89 | # define RX8025_BIT_2412 0x20 | ||
90 | #define RX8025_REG_CTRL2 0x0f | ||
91 | # define RX8025_BIT_PON 0x10 | ||
92 | # define RX8025_BIT_VDET 0x40 | ||
93 | # define RX8025_BIT_XST 0x20 | ||
86 | 94 | ||
87 | 95 | ||
88 | struct ds1307 { | 96 | struct ds1307 { |
@@ -94,6 +102,10 @@ struct ds1307 { | |||
94 | struct i2c_client *client; | 102 | struct i2c_client *client; |
95 | struct rtc_device *rtc; | 103 | struct rtc_device *rtc; |
96 | struct work_struct work; | 104 | struct work_struct work; |
105 | s32 (*read_block_data)(struct i2c_client *client, u8 command, | ||
106 | u8 length, u8 *values); | ||
107 | s32 (*write_block_data)(struct i2c_client *client, u8 command, | ||
108 | u8 length, const u8 *values); | ||
97 | }; | 109 | }; |
98 | 110 | ||
99 | struct chip_desc { | 111 | struct chip_desc { |
@@ -117,6 +129,8 @@ static const struct chip_desc chips[] = { | |||
117 | [ds_1340] = { | 129 | [ds_1340] = { |
118 | }, | 130 | }, |
119 | [m41t00] = { | 131 | [m41t00] = { |
132 | }, | ||
133 | [rx_8025] = { | ||
120 | }, }; | 134 | }, }; |
121 | 135 | ||
122 | static const struct i2c_device_id ds1307_id[] = { | 136 | static const struct i2c_device_id ds1307_id[] = { |
@@ -126,12 +140,86 @@ static const struct i2c_device_id ds1307_id[] = { | |||
126 | { "ds1339", ds_1339 }, | 140 | { "ds1339", ds_1339 }, |
127 | { "ds1340", ds_1340 }, | 141 | { "ds1340", ds_1340 }, |
128 | { "m41t00", m41t00 }, | 142 | { "m41t00", m41t00 }, |
143 | { "rx8025", rx_8025 }, | ||
129 | { } | 144 | { } |
130 | }; | 145 | }; |
131 | MODULE_DEVICE_TABLE(i2c, ds1307_id); | 146 | MODULE_DEVICE_TABLE(i2c, ds1307_id); |
132 | 147 | ||
133 | /*----------------------------------------------------------------------*/ | 148 | /*----------------------------------------------------------------------*/ |
134 | 149 | ||
150 | #define BLOCK_DATA_MAX_TRIES 10 | ||
151 | |||
152 | static s32 ds1307_read_block_data_once(struct i2c_client *client, u8 command, | ||
153 | u8 length, u8 *values) | ||
154 | { | ||
155 | s32 i, data; | ||
156 | |||
157 | for (i = 0; i < length; i++) { | ||
158 | data = i2c_smbus_read_byte_data(client, command + i); | ||
159 | if (data < 0) | ||
160 | return data; | ||
161 | values[i] = data; | ||
162 | } | ||
163 | return i; | ||
164 | } | ||
165 | |||
166 | static s32 ds1307_read_block_data(struct i2c_client *client, u8 command, | ||
167 | u8 length, u8 *values) | ||
168 | { | ||
169 | u8 oldvalues[I2C_SMBUS_BLOCK_MAX]; | ||
170 | s32 ret; | ||
171 | int tries = 0; | ||
172 | |||
173 | dev_dbg(&client->dev, "ds1307_read_block_data (length=%d)\n", length); | ||
174 | ret = ds1307_read_block_data_once(client, command, length, values); | ||
175 | if (ret < 0) | ||
176 | return ret; | ||
177 | do { | ||
178 | if (++tries > BLOCK_DATA_MAX_TRIES) { | ||
179 | dev_err(&client->dev, | ||
180 | "ds1307_read_block_data failed\n"); | ||
181 | return -EIO; | ||
182 | } | ||
183 | memcpy(oldvalues, values, length); | ||
184 | ret = ds1307_read_block_data_once(client, command, length, | ||
185 | values); | ||
186 | if (ret < 0) | ||
187 | return ret; | ||
188 | } while (memcmp(oldvalues, values, length)); | ||
189 | return length; | ||
190 | } | ||
191 | |||
192 | static s32 ds1307_write_block_data(struct i2c_client *client, u8 command, | ||
193 | u8 length, const u8 *values) | ||
194 | { | ||
195 | u8 currvalues[I2C_SMBUS_BLOCK_MAX]; | ||
196 | int tries = 0; | ||
197 | |||
198 | dev_dbg(&client->dev, "ds1307_write_block_data (length=%d)\n", length); | ||
199 | do { | ||
200 | s32 i, ret; | ||
201 | |||
202 | if (++tries > BLOCK_DATA_MAX_TRIES) { | ||
203 | dev_err(&client->dev, | ||
204 | "ds1307_write_block_data failed\n"); | ||
205 | return -EIO; | ||
206 | } | ||
207 | for (i = 0; i < length; i++) { | ||
208 | ret = i2c_smbus_write_byte_data(client, command + i, | ||
209 | values[i]); | ||
210 | if (ret < 0) | ||
211 | return ret; | ||
212 | } | ||
213 | ret = ds1307_read_block_data_once(client, command, length, | ||
214 | currvalues); | ||
215 | if (ret < 0) | ||
216 | return ret; | ||
217 | } while (memcmp(currvalues, values, length)); | ||
218 | return length; | ||
219 | } | ||
220 | |||
221 | /*----------------------------------------------------------------------*/ | ||
222 | |||
135 | /* | 223 | /* |
136 | * The IRQ logic includes a "real" handler running in IRQ context just | 224 | * The IRQ logic includes a "real" handler running in IRQ context just |
137 | * long enough to schedule this workqueue entry. We need a task context | 225 | * long enough to schedule this workqueue entry. We need a task context |
@@ -202,7 +290,7 @@ static int ds1307_get_time(struct device *dev, struct rtc_time *t) | |||
202 | int tmp; | 290 | int tmp; |
203 | 291 | ||
204 | /* read the RTC date and time registers all at once */ | 292 | /* read the RTC date and time registers all at once */ |
205 | tmp = i2c_smbus_read_i2c_block_data(ds1307->client, | 293 | tmp = ds1307->read_block_data(ds1307->client, |
206 | DS1307_REG_SECS, 7, ds1307->regs); | 294 | DS1307_REG_SECS, 7, ds1307->regs); |
207 | if (tmp != 7) { | 295 | if (tmp != 7) { |
208 | dev_err(dev, "%s error %d\n", "read", tmp); | 296 | dev_err(dev, "%s error %d\n", "read", tmp); |
@@ -279,7 +367,7 @@ static int ds1307_set_time(struct device *dev, struct rtc_time *t) | |||
279 | "write", buf[0], buf[1], buf[2], buf[3], | 367 | "write", buf[0], buf[1], buf[2], buf[3], |
280 | buf[4], buf[5], buf[6]); | 368 | buf[4], buf[5], buf[6]); |
281 | 369 | ||
282 | result = i2c_smbus_write_i2c_block_data(ds1307->client, 0, 7, buf); | 370 | result = ds1307->write_block_data(ds1307->client, 0, 7, buf); |
283 | if (result < 0) { | 371 | if (result < 0) { |
284 | dev_err(dev, "%s error %d\n", "write", result); | 372 | dev_err(dev, "%s error %d\n", "write", result); |
285 | return result; | 373 | return result; |
@@ -297,7 +385,7 @@ static int ds1337_read_alarm(struct device *dev, struct rtc_wkalrm *t) | |||
297 | return -EINVAL; | 385 | return -EINVAL; |
298 | 386 | ||
299 | /* read all ALARM1, ALARM2, and status registers at once */ | 387 | /* read all ALARM1, ALARM2, and status registers at once */ |
300 | ret = i2c_smbus_read_i2c_block_data(client, | 388 | ret = ds1307->read_block_data(client, |
301 | DS1339_REG_ALARM1_SECS, 9, ds1307->regs); | 389 | DS1339_REG_ALARM1_SECS, 9, ds1307->regs); |
302 | if (ret != 9) { | 390 | if (ret != 9) { |
303 | dev_err(dev, "%s error %d\n", "alarm read", ret); | 391 | dev_err(dev, "%s error %d\n", "alarm read", ret); |
@@ -356,7 +444,7 @@ static int ds1337_set_alarm(struct device *dev, struct rtc_wkalrm *t) | |||
356 | t->enabled, t->pending); | 444 | t->enabled, t->pending); |
357 | 445 | ||
358 | /* read current status of both alarms and the chip */ | 446 | /* read current status of both alarms and the chip */ |
359 | ret = i2c_smbus_read_i2c_block_data(client, | 447 | ret = ds1307->read_block_data(client, |
360 | DS1339_REG_ALARM1_SECS, 9, buf); | 448 | DS1339_REG_ALARM1_SECS, 9, buf); |
361 | if (ret != 9) { | 449 | if (ret != 9) { |
362 | dev_err(dev, "%s error %d\n", "alarm write", ret); | 450 | dev_err(dev, "%s error %d\n", "alarm write", ret); |
@@ -391,7 +479,7 @@ static int ds1337_set_alarm(struct device *dev, struct rtc_wkalrm *t) | |||
391 | } | 479 | } |
392 | buf[8] = status & ~(DS1337_BIT_A1I | DS1337_BIT_A2I); | 480 | buf[8] = status & ~(DS1337_BIT_A1I | DS1337_BIT_A2I); |
393 | 481 | ||
394 | ret = i2c_smbus_write_i2c_block_data(client, | 482 | ret = ds1307->write_block_data(client, |
395 | DS1339_REG_ALARM1_SECS, 9, buf); | 483 | DS1339_REG_ALARM1_SECS, 9, buf); |
396 | if (ret < 0) { | 484 | if (ret < 0) { |
397 | dev_err(dev, "can't set alarm time\n"); | 485 | dev_err(dev, "can't set alarm time\n"); |
@@ -479,7 +567,7 @@ ds1307_nvram_read(struct kobject *kobj, struct bin_attribute *attr, | |||
479 | if (unlikely(!count)) | 567 | if (unlikely(!count)) |
480 | return count; | 568 | return count; |
481 | 569 | ||
482 | result = i2c_smbus_read_i2c_block_data(client, 8 + off, count, buf); | 570 | result = ds1307->read_block_data(client, 8 + off, count, buf); |
483 | if (result < 0) | 571 | if (result < 0) |
484 | dev_err(&client->dev, "%s error %d\n", "nvram read", result); | 572 | dev_err(&client->dev, "%s error %d\n", "nvram read", result); |
485 | return result; | 573 | return result; |
@@ -490,9 +578,11 @@ ds1307_nvram_write(struct kobject *kobj, struct bin_attribute *attr, | |||
490 | char *buf, loff_t off, size_t count) | 578 | char *buf, loff_t off, size_t count) |
491 | { | 579 | { |
492 | struct i2c_client *client; | 580 | struct i2c_client *client; |
581 | struct ds1307 *ds1307; | ||
493 | int result; | 582 | int result; |
494 | 583 | ||
495 | client = kobj_to_i2c_client(kobj); | 584 | client = kobj_to_i2c_client(kobj); |
585 | ds1307 = i2c_get_clientdata(client); | ||
496 | 586 | ||
497 | if (unlikely(off >= NVRAM_SIZE)) | 587 | if (unlikely(off >= NVRAM_SIZE)) |
498 | return -EFBIG; | 588 | return -EFBIG; |
@@ -501,7 +591,7 @@ ds1307_nvram_write(struct kobject *kobj, struct bin_attribute *attr, | |||
501 | if (unlikely(!count)) | 591 | if (unlikely(!count)) |
502 | return count; | 592 | return count; |
503 | 593 | ||
504 | result = i2c_smbus_write_i2c_block_data(client, 8 + off, count, buf); | 594 | result = ds1307->write_block_data(client, 8 + off, count, buf); |
505 | if (result < 0) { | 595 | if (result < 0) { |
506 | dev_err(&client->dev, "%s error %d\n", "nvram write", result); | 596 | dev_err(&client->dev, "%s error %d\n", "nvram write", result); |
507 | return result; | 597 | return result; |
@@ -535,9 +625,8 @@ static int __devinit ds1307_probe(struct i2c_client *client, | |||
535 | int want_irq = false; | 625 | int want_irq = false; |
536 | unsigned char *buf; | 626 | unsigned char *buf; |
537 | 627 | ||
538 | if (!i2c_check_functionality(adapter, | 628 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA) |
539 | I2C_FUNC_SMBUS_WRITE_BYTE_DATA | | 629 | && !i2c_check_functionality(adapter, I2C_FUNC_SMBUS_I2C_BLOCK)) |
540 | I2C_FUNC_SMBUS_I2C_BLOCK)) | ||
541 | return -EIO; | 630 | return -EIO; |
542 | 631 | ||
543 | if (!(ds1307 = kzalloc(sizeof(struct ds1307), GFP_KERNEL))) | 632 | if (!(ds1307 = kzalloc(sizeof(struct ds1307), GFP_KERNEL))) |
@@ -547,6 +636,13 @@ static int __devinit ds1307_probe(struct i2c_client *client, | |||
547 | i2c_set_clientdata(client, ds1307); | 636 | i2c_set_clientdata(client, ds1307); |
548 | ds1307->type = id->driver_data; | 637 | ds1307->type = id->driver_data; |
549 | buf = ds1307->regs; | 638 | buf = ds1307->regs; |
639 | if (i2c_check_functionality(adapter, I2C_FUNC_SMBUS_I2C_BLOCK)) { | ||
640 | ds1307->read_block_data = i2c_smbus_read_i2c_block_data; | ||
641 | ds1307->write_block_data = i2c_smbus_write_i2c_block_data; | ||
642 | } else { | ||
643 | ds1307->read_block_data = ds1307_read_block_data; | ||
644 | ds1307->write_block_data = ds1307_write_block_data; | ||
645 | } | ||
550 | 646 | ||
551 | switch (ds1307->type) { | 647 | switch (ds1307->type) { |
552 | case ds_1337: | 648 | case ds_1337: |
@@ -557,7 +653,7 @@ static int __devinit ds1307_probe(struct i2c_client *client, | |||
557 | want_irq = true; | 653 | want_irq = true; |
558 | } | 654 | } |
559 | /* get registers that the "rtc" read below won't read... */ | 655 | /* get registers that the "rtc" read below won't read... */ |
560 | tmp = i2c_smbus_read_i2c_block_data(ds1307->client, | 656 | tmp = ds1307->read_block_data(ds1307->client, |
561 | DS1337_REG_CONTROL, 2, buf); | 657 | DS1337_REG_CONTROL, 2, buf); |
562 | if (tmp != 2) { | 658 | if (tmp != 2) { |
563 | pr_debug("read error %d\n", tmp); | 659 | pr_debug("read error %d\n", tmp); |
@@ -589,13 +685,79 @@ static int __devinit ds1307_probe(struct i2c_client *client, | |||
589 | dev_warn(&client->dev, "SET TIME!\n"); | 685 | dev_warn(&client->dev, "SET TIME!\n"); |
590 | } | 686 | } |
591 | break; | 687 | break; |
688 | |||
689 | case rx_8025: | ||
690 | tmp = i2c_smbus_read_i2c_block_data(ds1307->client, | ||
691 | RX8025_REG_CTRL1 << 4 | 0x08, 2, buf); | ||
692 | if (tmp != 2) { | ||
693 | pr_debug("read error %d\n", tmp); | ||
694 | err = -EIO; | ||
695 | goto exit_free; | ||
696 | } | ||
697 | |||
698 | /* oscillator off? turn it on, so clock can tick. */ | ||
699 | if (!(ds1307->regs[1] & RX8025_BIT_XST)) { | ||
700 | ds1307->regs[1] |= RX8025_BIT_XST; | ||
701 | i2c_smbus_write_byte_data(client, | ||
702 | RX8025_REG_CTRL2 << 4 | 0x08, | ||
703 | ds1307->regs[1]); | ||
704 | dev_warn(&client->dev, | ||
705 | "oscillator stop detected - SET TIME!\n"); | ||
706 | } | ||
707 | |||
708 | if (ds1307->regs[1] & RX8025_BIT_PON) { | ||
709 | ds1307->regs[1] &= ~RX8025_BIT_PON; | ||
710 | i2c_smbus_write_byte_data(client, | ||
711 | RX8025_REG_CTRL2 << 4 | 0x08, | ||
712 | ds1307->regs[1]); | ||
713 | dev_warn(&client->dev, "power-on detected\n"); | ||
714 | } | ||
715 | |||
716 | if (ds1307->regs[1] & RX8025_BIT_VDET) { | ||
717 | ds1307->regs[1] &= ~RX8025_BIT_VDET; | ||
718 | i2c_smbus_write_byte_data(client, | ||
719 | RX8025_REG_CTRL2 << 4 | 0x08, | ||
720 | ds1307->regs[1]); | ||
721 | dev_warn(&client->dev, "voltage drop detected\n"); | ||
722 | } | ||
723 | |||
724 | /* make sure we are running in 24hour mode */ | ||
725 | if (!(ds1307->regs[0] & RX8025_BIT_2412)) { | ||
726 | u8 hour; | ||
727 | |||
728 | /* switch to 24 hour mode */ | ||
729 | i2c_smbus_write_byte_data(client, | ||
730 | RX8025_REG_CTRL1 << 4 | 0x08, | ||
731 | ds1307->regs[0] | | ||
732 | RX8025_BIT_2412); | ||
733 | |||
734 | tmp = i2c_smbus_read_i2c_block_data(ds1307->client, | ||
735 | RX8025_REG_CTRL1 << 4 | 0x08, 2, buf); | ||
736 | if (tmp != 2) { | ||
737 | pr_debug("read error %d\n", tmp); | ||
738 | err = -EIO; | ||
739 | goto exit_free; | ||
740 | } | ||
741 | |||
742 | /* correct hour */ | ||
743 | hour = bcd2bin(ds1307->regs[DS1307_REG_HOUR]); | ||
744 | if (hour == 12) | ||
745 | hour = 0; | ||
746 | if (ds1307->regs[DS1307_REG_HOUR] & DS1307_BIT_PM) | ||
747 | hour += 12; | ||
748 | |||
749 | i2c_smbus_write_byte_data(client, | ||
750 | DS1307_REG_HOUR << 4 | 0x08, | ||
751 | hour); | ||
752 | } | ||
753 | break; | ||
592 | default: | 754 | default: |
593 | break; | 755 | break; |
594 | } | 756 | } |
595 | 757 | ||
596 | read_rtc: | 758 | read_rtc: |
597 | /* read RTC registers */ | 759 | /* read RTC registers */ |
598 | tmp = i2c_smbus_read_i2c_block_data(ds1307->client, 0, 8, buf); | 760 | tmp = ds1307->read_block_data(ds1307->client, 0, 8, buf); |
599 | if (tmp != 8) { | 761 | if (tmp != 8) { |
600 | pr_debug("read error %d\n", tmp); | 762 | pr_debug("read error %d\n", tmp); |
601 | err = -EIO; | 763 | err = -EIO; |
@@ -649,6 +811,7 @@ read_rtc: | |||
649 | dev_warn(&client->dev, "SET TIME!\n"); | 811 | dev_warn(&client->dev, "SET TIME!\n"); |
650 | } | 812 | } |
651 | break; | 813 | break; |
814 | case rx_8025: | ||
652 | case ds_1337: | 815 | case ds_1337: |
653 | case ds_1339: | 816 | case ds_1339: |
654 | break; | 817 | break; |
@@ -662,6 +825,8 @@ read_rtc: | |||
662 | * systems that will run through year 2100. | 825 | * systems that will run through year 2100. |
663 | */ | 826 | */ |
664 | break; | 827 | break; |
828 | case rx_8025: | ||
829 | break; | ||
665 | default: | 830 | default: |
666 | if (!(tmp & DS1307_BIT_12HR)) | 831 | if (!(tmp & DS1307_BIT_12HR)) |
667 | break; | 832 | break; |
diff --git a/drivers/rtc/rtc-ds1374.c b/drivers/rtc/rtc-ds1374.c index a5b0fc09f0c..4d32e328f6c 100644 --- a/drivers/rtc/rtc-ds1374.c +++ b/drivers/rtc/rtc-ds1374.c | |||
@@ -222,16 +222,16 @@ static int ds1374_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) | |||
222 | rtc_tm_to_time(&alarm->time, &new_alarm); | 222 | rtc_tm_to_time(&alarm->time, &new_alarm); |
223 | rtc_tm_to_time(&now, &itime); | 223 | rtc_tm_to_time(&now, &itime); |
224 | 224 | ||
225 | new_alarm -= itime; | ||
226 | |||
227 | /* This can happen due to races, in addition to dates that are | 225 | /* This can happen due to races, in addition to dates that are |
228 | * truly in the past. To avoid requiring the caller to check for | 226 | * truly in the past. To avoid requiring the caller to check for |
229 | * races, dates in the past are assumed to be in the recent past | 227 | * races, dates in the past are assumed to be in the recent past |
230 | * (i.e. not something that we'd rather the caller know about via | 228 | * (i.e. not something that we'd rather the caller know about via |
231 | * an error), and the alarm is set to go off as soon as possible. | 229 | * an error), and the alarm is set to go off as soon as possible. |
232 | */ | 230 | */ |
233 | if (new_alarm <= 0) | 231 | if (time_before_eq(new_alarm, itime)) |
234 | new_alarm = 1; | 232 | new_alarm = 1; |
233 | else | ||
234 | new_alarm -= itime; | ||
235 | 235 | ||
236 | mutex_lock(&ds1374->mutex); | 236 | mutex_lock(&ds1374->mutex); |
237 | 237 | ||
diff --git a/drivers/rtc/rtc-efi.c b/drivers/rtc/rtc-efi.c new file mode 100644 index 00000000000..550292304b0 --- /dev/null +++ b/drivers/rtc/rtc-efi.c | |||
@@ -0,0 +1,235 @@ | |||
1 | /* | ||
2 | * rtc-efi: RTC Class Driver for EFI-based systems | ||
3 | * | ||
4 | * Copyright (C) 2009 Hewlett-Packard Development Company, L.P. | ||
5 | * | ||
6 | * Author: dann frazier <dannf@hp.com> | ||
7 | * Based on efirtc.c by Stephane Eranian | ||
8 | * | ||
9 | * This program is free software; you can redistribute it and/or modify it | ||
10 | * under the terms of the GNU General Public License as published by the | ||
11 | * Free Software Foundation; either version 2 of the License, or (at your | ||
12 | * option) any later version. | ||
13 | * | ||
14 | */ | ||
15 | |||
16 | #include <linux/kernel.h> | ||
17 | #include <linux/module.h> | ||
18 | #include <linux/time.h> | ||
19 | #include <linux/platform_device.h> | ||
20 | #include <linux/rtc.h> | ||
21 | #include <linux/efi.h> | ||
22 | |||
23 | #define EFI_ISDST (EFI_TIME_ADJUST_DAYLIGHT|EFI_TIME_IN_DAYLIGHT) | ||
24 | /* | ||
25 | * EFI Epoch is 1/1/1998 | ||
26 | */ | ||
27 | #define EFI_RTC_EPOCH 1998 | ||
28 | |||
29 | /* | ||
30 | * returns day of the year [0-365] | ||
31 | */ | ||
32 | static inline int | ||
33 | compute_yday(efi_time_t *eft) | ||
34 | { | ||
35 | /* efi_time_t.month is in the [1-12] so, we need -1 */ | ||
36 | return rtc_year_days(eft->day - 1, eft->month - 1, eft->year); | ||
37 | } | ||
38 | /* | ||
39 | * returns day of the week [0-6] 0=Sunday | ||
40 | * | ||
41 | * Don't try to provide a year that's before 1998, please ! | ||
42 | */ | ||
43 | static int | ||
44 | compute_wday(efi_time_t *eft) | ||
45 | { | ||
46 | int y; | ||
47 | int ndays = 0; | ||
48 | |||
49 | if (eft->year < 1998) { | ||
50 | printk(KERN_ERR "efirtc: EFI year < 1998, invalid date\n"); | ||
51 | return -1; | ||
52 | } | ||
53 | |||
54 | for (y = EFI_RTC_EPOCH; y < eft->year; y++) | ||
55 | ndays += 365 + (is_leap_year(y) ? 1 : 0); | ||
56 | |||
57 | ndays += compute_yday(eft); | ||
58 | |||
59 | /* | ||
60 | * 4=1/1/1998 was a Thursday | ||
61 | */ | ||
62 | return (ndays + 4) % 7; | ||
63 | } | ||
64 | |||
65 | static void | ||
66 | convert_to_efi_time(struct rtc_time *wtime, efi_time_t *eft) | ||
67 | { | ||
68 | eft->year = wtime->tm_year + 1900; | ||
69 | eft->month = wtime->tm_mon + 1; | ||
70 | eft->day = wtime->tm_mday; | ||
71 | eft->hour = wtime->tm_hour; | ||
72 | eft->minute = wtime->tm_min; | ||
73 | eft->second = wtime->tm_sec; | ||
74 | eft->nanosecond = 0; | ||
75 | eft->daylight = wtime->tm_isdst ? EFI_ISDST : 0; | ||
76 | eft->timezone = EFI_UNSPECIFIED_TIMEZONE; | ||
77 | } | ||
78 | |||
79 | static void | ||
80 | convert_from_efi_time(efi_time_t *eft, struct rtc_time *wtime) | ||
81 | { | ||
82 | memset(wtime, 0, sizeof(*wtime)); | ||
83 | wtime->tm_sec = eft->second; | ||
84 | wtime->tm_min = eft->minute; | ||
85 | wtime->tm_hour = eft->hour; | ||
86 | wtime->tm_mday = eft->day; | ||
87 | wtime->tm_mon = eft->month - 1; | ||
88 | wtime->tm_year = eft->year - 1900; | ||
89 | |||
90 | /* day of the week [0-6], Sunday=0 */ | ||
91 | wtime->tm_wday = compute_wday(eft); | ||
92 | |||
93 | /* day in the year [1-365]*/ | ||
94 | wtime->tm_yday = compute_yday(eft); | ||
95 | |||
96 | |||
97 | switch (eft->daylight & EFI_ISDST) { | ||
98 | case EFI_ISDST: | ||
99 | wtime->tm_isdst = 1; | ||
100 | break; | ||
101 | case EFI_TIME_ADJUST_DAYLIGHT: | ||
102 | wtime->tm_isdst = 0; | ||
103 | break; | ||
104 | default: | ||
105 | wtime->tm_isdst = -1; | ||
106 | } | ||
107 | } | ||
108 | |||
109 | static int efi_read_alarm(struct device *dev, struct rtc_wkalrm *wkalrm) | ||
110 | { | ||
111 | efi_time_t eft; | ||
112 | efi_status_t status; | ||
113 | |||
114 | /* | ||
115 | * As of EFI v1.10, this call always returns an unsupported status | ||
116 | */ | ||
117 | status = efi.get_wakeup_time((efi_bool_t *)&wkalrm->enabled, | ||
118 | (efi_bool_t *)&wkalrm->pending, &eft); | ||
119 | |||
120 | if (status != EFI_SUCCESS) | ||
121 | return -EINVAL; | ||
122 | |||
123 | convert_from_efi_time(&eft, &wkalrm->time); | ||
124 | |||
125 | return rtc_valid_tm(&wkalrm->time); | ||
126 | } | ||
127 | |||
128 | static int efi_set_alarm(struct device *dev, struct rtc_wkalrm *wkalrm) | ||
129 | { | ||
130 | efi_time_t eft; | ||
131 | efi_status_t status; | ||
132 | |||
133 | convert_to_efi_time(&wkalrm->time, &eft); | ||
134 | |||
135 | /* | ||
136 | * XXX Fixme: | ||
137 | * As of EFI 0.92 with the firmware I have on my | ||
138 | * machine this call does not seem to work quite | ||
139 | * right | ||
140 | * | ||
141 | * As of v1.10, this call always returns an unsupported status | ||
142 | */ | ||
143 | status = efi.set_wakeup_time((efi_bool_t)wkalrm->enabled, &eft); | ||
144 | |||
145 | printk(KERN_WARNING "write status is %d\n", (int)status); | ||
146 | |||
147 | return status == EFI_SUCCESS ? 0 : -EINVAL; | ||
148 | } | ||
149 | |||
150 | static int efi_read_time(struct device *dev, struct rtc_time *tm) | ||
151 | { | ||
152 | efi_status_t status; | ||
153 | efi_time_t eft; | ||
154 | efi_time_cap_t cap; | ||
155 | |||
156 | status = efi.get_time(&eft, &cap); | ||
157 | |||
158 | if (status != EFI_SUCCESS) { | ||
159 | /* should never happen */ | ||
160 | printk(KERN_ERR "efitime: can't read time\n"); | ||
161 | return -EINVAL; | ||
162 | } | ||
163 | |||
164 | convert_from_efi_time(&eft, tm); | ||
165 | |||
166 | return rtc_valid_tm(tm); | ||
167 | } | ||
168 | |||
169 | static int efi_set_time(struct device *dev, struct rtc_time *tm) | ||
170 | { | ||
171 | efi_status_t status; | ||
172 | efi_time_t eft; | ||
173 | |||
174 | convert_to_efi_time(tm, &eft); | ||
175 | |||
176 | status = efi.set_time(&eft); | ||
177 | |||
178 | return status == EFI_SUCCESS ? 0 : -EINVAL; | ||
179 | } | ||
180 | |||
181 | static const struct rtc_class_ops efi_rtc_ops = { | ||
182 | .read_time = efi_read_time, | ||
183 | .set_time = efi_set_time, | ||
184 | .read_alarm = efi_read_alarm, | ||
185 | .set_alarm = efi_set_alarm, | ||
186 | }; | ||
187 | |||
188 | static int __init efi_rtc_probe(struct platform_device *dev) | ||
189 | { | ||
190 | struct rtc_device *rtc; | ||
191 | |||
192 | rtc = rtc_device_register("rtc-efi", &dev->dev, &efi_rtc_ops, | ||
193 | THIS_MODULE); | ||
194 | if (IS_ERR(rtc)) | ||
195 | return PTR_ERR(rtc); | ||
196 | |||
197 | platform_set_drvdata(dev, rtc); | ||
198 | |||
199 | return 0; | ||
200 | } | ||
201 | |||
202 | static int __exit efi_rtc_remove(struct platform_device *dev) | ||
203 | { | ||
204 | struct rtc_device *rtc = platform_get_drvdata(dev); | ||
205 | |||
206 | rtc_device_unregister(rtc); | ||
207 | |||
208 | return 0; | ||
209 | } | ||
210 | |||
211 | static struct platform_driver efi_rtc_driver = { | ||
212 | .driver = { | ||
213 | .name = "rtc-efi", | ||
214 | .owner = THIS_MODULE, | ||
215 | }, | ||
216 | .probe = efi_rtc_probe, | ||
217 | .remove = __exit_p(efi_rtc_remove), | ||
218 | }; | ||
219 | |||
220 | static int __init efi_rtc_init(void) | ||
221 | { | ||
222 | return platform_driver_probe(&efi_rtc_driver, efi_rtc_probe); | ||
223 | } | ||
224 | |||
225 | static void __exit efi_rtc_exit(void) | ||
226 | { | ||
227 | platform_driver_unregister(&efi_rtc_driver); | ||
228 | } | ||
229 | |||
230 | module_init(efi_rtc_init); | ||
231 | module_exit(efi_rtc_exit); | ||
232 | |||
233 | MODULE_AUTHOR("dann frazier <dannf@hp.com>"); | ||
234 | MODULE_LICENSE("GPL"); | ||
235 | MODULE_DESCRIPTION("EFI RTC driver"); | ||
diff --git a/drivers/rtc/rtc-lib.c b/drivers/rtc/rtc-lib.c index dd70bf73ce9..773851f338b 100644 --- a/drivers/rtc/rtc-lib.c +++ b/drivers/rtc/rtc-lib.c | |||
@@ -26,14 +26,13 @@ static const unsigned short rtc_ydays[2][13] = { | |||
26 | }; | 26 | }; |
27 | 27 | ||
28 | #define LEAPS_THRU_END_OF(y) ((y)/4 - (y)/100 + (y)/400) | 28 | #define LEAPS_THRU_END_OF(y) ((y)/4 - (y)/100 + (y)/400) |
29 | #define LEAP_YEAR(year) ((!(year % 4) && (year % 100)) || !(year % 400)) | ||
30 | 29 | ||
31 | /* | 30 | /* |
32 | * The number of days in the month. | 31 | * The number of days in the month. |
33 | */ | 32 | */ |
34 | int rtc_month_days(unsigned int month, unsigned int year) | 33 | int rtc_month_days(unsigned int month, unsigned int year) |
35 | { | 34 | { |
36 | return rtc_days_in_month[month] + (LEAP_YEAR(year) && month == 1); | 35 | return rtc_days_in_month[month] + (is_leap_year(year) && month == 1); |
37 | } | 36 | } |
38 | EXPORT_SYMBOL(rtc_month_days); | 37 | EXPORT_SYMBOL(rtc_month_days); |
39 | 38 | ||
@@ -42,7 +41,7 @@ EXPORT_SYMBOL(rtc_month_days); | |||
42 | */ | 41 | */ |
43 | int rtc_year_days(unsigned int day, unsigned int month, unsigned int year) | 42 | int rtc_year_days(unsigned int day, unsigned int month, unsigned int year) |
44 | { | 43 | { |
45 | return rtc_ydays[LEAP_YEAR(year)][month] + day-1; | 44 | return rtc_ydays[is_leap_year(year)][month] + day-1; |
46 | } | 45 | } |
47 | EXPORT_SYMBOL(rtc_year_days); | 46 | EXPORT_SYMBOL(rtc_year_days); |
48 | 47 | ||
@@ -66,7 +65,7 @@ void rtc_time_to_tm(unsigned long time, struct rtc_time *tm) | |||
66 | - LEAPS_THRU_END_OF(1970 - 1); | 65 | - LEAPS_THRU_END_OF(1970 - 1); |
67 | if (days < 0) { | 66 | if (days < 0) { |
68 | year -= 1; | 67 | year -= 1; |
69 | days += 365 + LEAP_YEAR(year); | 68 | days += 365 + is_leap_year(year); |
70 | } | 69 | } |
71 | tm->tm_year = year - 1900; | 70 | tm->tm_year = year - 1900; |
72 | tm->tm_yday = days + 1; | 71 | tm->tm_yday = days + 1; |
diff --git a/drivers/rtc/rtc-parisc.c b/drivers/rtc/rtc-parisc.c index c6bfa6fe1a2..b966f56da97 100644 --- a/drivers/rtc/rtc-parisc.c +++ b/drivers/rtc/rtc-parisc.c | |||
@@ -7,41 +7,25 @@ | |||
7 | #include <linux/module.h> | 7 | #include <linux/module.h> |
8 | #include <linux/time.h> | 8 | #include <linux/time.h> |
9 | #include <linux/platform_device.h> | 9 | #include <linux/platform_device.h> |
10 | #include <linux/rtc.h> | ||
10 | 11 | ||
11 | #include <asm/rtc.h> | 12 | #include <asm/rtc.h> |
12 | 13 | ||
13 | /* as simple as can be, and no simpler. */ | ||
14 | struct parisc_rtc { | ||
15 | struct rtc_device *rtc; | ||
16 | spinlock_t lock; | ||
17 | }; | ||
18 | |||
19 | static int parisc_get_time(struct device *dev, struct rtc_time *tm) | 14 | static int parisc_get_time(struct device *dev, struct rtc_time *tm) |
20 | { | 15 | { |
21 | struct parisc_rtc *p = dev_get_drvdata(dev); | 16 | unsigned long ret; |
22 | unsigned long flags, ret; | ||
23 | 17 | ||
24 | spin_lock_irqsave(&p->lock, flags); | ||
25 | ret = get_rtc_time(tm); | 18 | ret = get_rtc_time(tm); |
26 | spin_unlock_irqrestore(&p->lock, flags); | ||
27 | 19 | ||
28 | if (ret & RTC_BATT_BAD) | 20 | if (ret & RTC_BATT_BAD) |
29 | return -EOPNOTSUPP; | 21 | return -EOPNOTSUPP; |
30 | 22 | ||
31 | return 0; | 23 | return rtc_valid_tm(tm); |
32 | } | 24 | } |
33 | 25 | ||
34 | static int parisc_set_time(struct device *dev, struct rtc_time *tm) | 26 | static int parisc_set_time(struct device *dev, struct rtc_time *tm) |
35 | { | 27 | { |
36 | struct parisc_rtc *p = dev_get_drvdata(dev); | 28 | if (set_rtc_time(tm) < 0) |
37 | unsigned long flags; | ||
38 | int ret; | ||
39 | |||
40 | spin_lock_irqsave(&p->lock, flags); | ||
41 | ret = set_rtc_time(tm); | ||
42 | spin_unlock_irqrestore(&p->lock, flags); | ||
43 | |||
44 | if (ret < 0) | ||
45 | return -EOPNOTSUPP; | 29 | return -EOPNOTSUPP; |
46 | 30 | ||
47 | return 0; | 31 | return 0; |
@@ -52,35 +36,25 @@ static const struct rtc_class_ops parisc_rtc_ops = { | |||
52 | .set_time = parisc_set_time, | 36 | .set_time = parisc_set_time, |
53 | }; | 37 | }; |
54 | 38 | ||
55 | static int __devinit parisc_rtc_probe(struct platform_device *dev) | 39 | static int __init parisc_rtc_probe(struct platform_device *dev) |
56 | { | 40 | { |
57 | struct parisc_rtc *p; | 41 | struct rtc_device *rtc; |
58 | |||
59 | p = kzalloc(sizeof (*p), GFP_KERNEL); | ||
60 | if (!p) | ||
61 | return -ENOMEM; | ||
62 | |||
63 | spin_lock_init(&p->lock); | ||
64 | 42 | ||
65 | p->rtc = rtc_device_register("rtc-parisc", &dev->dev, &parisc_rtc_ops, | 43 | rtc = rtc_device_register("rtc-parisc", &dev->dev, &parisc_rtc_ops, |
66 | THIS_MODULE); | 44 | THIS_MODULE); |
67 | if (IS_ERR(p->rtc)) { | 45 | if (IS_ERR(rtc)) |
68 | int err = PTR_ERR(p->rtc); | 46 | return PTR_ERR(rtc); |
69 | kfree(p); | ||
70 | return err; | ||
71 | } | ||
72 | 47 | ||
73 | platform_set_drvdata(dev, p); | 48 | platform_set_drvdata(dev, rtc); |
74 | 49 | ||
75 | return 0; | 50 | return 0; |
76 | } | 51 | } |
77 | 52 | ||
78 | static int __devexit parisc_rtc_remove(struct platform_device *dev) | 53 | static int __exit parisc_rtc_remove(struct platform_device *dev) |
79 | { | 54 | { |
80 | struct parisc_rtc *p = platform_get_drvdata(dev); | 55 | struct rtc_device *rtc = platform_get_drvdata(dev); |
81 | 56 | ||
82 | rtc_device_unregister(p->rtc); | 57 | rtc_device_unregister(rtc); |
83 | kfree(p); | ||
84 | 58 | ||
85 | return 0; | 59 | return 0; |
86 | } | 60 | } |
@@ -96,7 +70,7 @@ static struct platform_driver parisc_rtc_driver = { | |||
96 | 70 | ||
97 | static int __init parisc_rtc_init(void) | 71 | static int __init parisc_rtc_init(void) |
98 | { | 72 | { |
99 | return platform_driver_register(&parisc_rtc_driver); | 73 | return platform_driver_probe(&parisc_rtc_driver, parisc_rtc_probe); |
100 | } | 74 | } |
101 | 75 | ||
102 | static void __exit parisc_rtc_fini(void) | 76 | static void __exit parisc_rtc_fini(void) |
diff --git a/drivers/rtc/rtc-v3020.c b/drivers/rtc/rtc-v3020.c index 14d4f036a76..66955cc9c74 100644 --- a/drivers/rtc/rtc-v3020.c +++ b/drivers/rtc/rtc-v3020.c | |||
@@ -28,7 +28,7 @@ | |||
28 | #include <linux/rtc-v3020.h> | 28 | #include <linux/rtc-v3020.h> |
29 | #include <linux/delay.h> | 29 | #include <linux/delay.h> |
30 | 30 | ||
31 | #include <asm/io.h> | 31 | #include <linux/io.h> |
32 | 32 | ||
33 | #undef DEBUG | 33 | #undef DEBUG |
34 | 34 | ||
@@ -63,7 +63,7 @@ static void v3020_set_reg(struct v3020 *chip, unsigned char address, | |||
63 | 63 | ||
64 | static unsigned char v3020_get_reg(struct v3020 *chip, unsigned char address) | 64 | static unsigned char v3020_get_reg(struct v3020 *chip, unsigned char address) |
65 | { | 65 | { |
66 | unsigned int data=0; | 66 | unsigned int data = 0; |
67 | int i; | 67 | int i; |
68 | 68 | ||
69 | for (i = 0; i < 4; i++) { | 69 | for (i = 0; i < 4; i++) { |
@@ -106,16 +106,14 @@ static int v3020_read_time(struct device *dev, struct rtc_time *dt) | |||
106 | tmp = v3020_get_reg(chip, V3020_YEAR); | 106 | tmp = v3020_get_reg(chip, V3020_YEAR); |
107 | dt->tm_year = bcd2bin(tmp)+100; | 107 | dt->tm_year = bcd2bin(tmp)+100; |
108 | 108 | ||
109 | #ifdef DEBUG | 109 | dev_dbg(dev, "\n%s : Read RTC values\n", __func__); |
110 | printk("\n%s : Read RTC values\n",__func__); | 110 | dev_dbg(dev, "tm_hour: %i\n", dt->tm_hour); |
111 | printk("tm_hour: %i\n",dt->tm_hour); | 111 | dev_dbg(dev, "tm_min : %i\n", dt->tm_min); |
112 | printk("tm_min : %i\n",dt->tm_min); | 112 | dev_dbg(dev, "tm_sec : %i\n", dt->tm_sec); |
113 | printk("tm_sec : %i\n",dt->tm_sec); | 113 | dev_dbg(dev, "tm_year: %i\n", dt->tm_year); |
114 | printk("tm_year: %i\n",dt->tm_year); | 114 | dev_dbg(dev, "tm_mon : %i\n", dt->tm_mon); |
115 | printk("tm_mon : %i\n",dt->tm_mon); | 115 | dev_dbg(dev, "tm_mday: %i\n", dt->tm_mday); |
116 | printk("tm_mday: %i\n",dt->tm_mday); | 116 | dev_dbg(dev, "tm_wday: %i\n", dt->tm_wday); |
117 | printk("tm_wday: %i\n",dt->tm_wday); | ||
118 | #endif | ||
119 | 117 | ||
120 | return 0; | 118 | return 0; |
121 | } | 119 | } |
@@ -125,15 +123,13 @@ static int v3020_set_time(struct device *dev, struct rtc_time *dt) | |||
125 | { | 123 | { |
126 | struct v3020 *chip = dev_get_drvdata(dev); | 124 | struct v3020 *chip = dev_get_drvdata(dev); |
127 | 125 | ||
128 | #ifdef DEBUG | 126 | dev_dbg(dev, "\n%s : Setting RTC values\n", __func__); |
129 | printk("\n%s : Setting RTC values\n",__func__); | 127 | dev_dbg(dev, "tm_sec : %i\n", dt->tm_sec); |
130 | printk("tm_sec : %i\n",dt->tm_sec); | 128 | dev_dbg(dev, "tm_min : %i\n", dt->tm_min); |
131 | printk("tm_min : %i\n",dt->tm_min); | 129 | dev_dbg(dev, "tm_hour: %i\n", dt->tm_hour); |
132 | printk("tm_hour: %i\n",dt->tm_hour); | 130 | dev_dbg(dev, "tm_mday: %i\n", dt->tm_mday); |
133 | printk("tm_mday: %i\n",dt->tm_mday); | 131 | dev_dbg(dev, "tm_wday: %i\n", dt->tm_wday); |
134 | printk("tm_wday: %i\n",dt->tm_wday); | 132 | dev_dbg(dev, "tm_year: %i\n", dt->tm_year); |
135 | printk("tm_year: %i\n",dt->tm_year); | ||
136 | #endif | ||
137 | 133 | ||
138 | /* Write all the values to ram... */ | 134 | /* Write all the values to ram... */ |
139 | v3020_set_reg(chip, V3020_SECONDS, bin2bcd(dt->tm_sec)); | 135 | v3020_set_reg(chip, V3020_SECONDS, bin2bcd(dt->tm_sec)); |
@@ -191,7 +187,7 @@ static int rtc_probe(struct platform_device *pdev) | |||
191 | /* Test chip by doing a write/read sequence | 187 | /* Test chip by doing a write/read sequence |
192 | * to the chip ram */ | 188 | * to the chip ram */ |
193 | v3020_set_reg(chip, V3020_SECONDS, 0x33); | 189 | v3020_set_reg(chip, V3020_SECONDS, 0x33); |
194 | if(v3020_get_reg(chip, V3020_SECONDS) != 0x33) { | 190 | if (v3020_get_reg(chip, V3020_SECONDS) != 0x33) { |
195 | retval = -ENODEV; | 191 | retval = -ENODEV; |
196 | goto err_io; | 192 | goto err_io; |
197 | } | 193 | } |
diff --git a/drivers/rtc/rtc-wm8350.c b/drivers/rtc/rtc-wm8350.c index 5c5e3aa9138..c91edc572eb 100644 --- a/drivers/rtc/rtc-wm8350.c +++ b/drivers/rtc/rtc-wm8350.c | |||
@@ -122,7 +122,7 @@ static int wm8350_rtc_settime(struct device *dev, struct rtc_time *tm) | |||
122 | do { | 122 | do { |
123 | rtc_ctrl = wm8350_reg_read(wm8350, WM8350_RTC_TIME_CONTROL); | 123 | rtc_ctrl = wm8350_reg_read(wm8350, WM8350_RTC_TIME_CONTROL); |
124 | schedule_timeout_uninterruptible(msecs_to_jiffies(1)); | 124 | schedule_timeout_uninterruptible(msecs_to_jiffies(1)); |
125 | } while (retries-- && !(rtc_ctrl & WM8350_RTC_STS)); | 125 | } while (--retries && !(rtc_ctrl & WM8350_RTC_STS)); |
126 | 126 | ||
127 | if (!retries) { | 127 | if (!retries) { |
128 | dev_err(dev, "timed out on set confirmation\n"); | 128 | dev_err(dev, "timed out on set confirmation\n"); |
@@ -236,6 +236,17 @@ static int wm8350_rtc_start_alarm(struct wm8350 *wm8350) | |||
236 | return 0; | 236 | return 0; |
237 | } | 237 | } |
238 | 238 | ||
239 | static int wm8350_rtc_alarm_irq_enable(struct device *dev, | ||
240 | unsigned int enabled) | ||
241 | { | ||
242 | struct wm8350 *wm8350 = dev_get_drvdata(dev); | ||
243 | |||
244 | if (enabled) | ||
245 | return wm8350_rtc_start_alarm(wm8350); | ||
246 | else | ||
247 | return wm8350_rtc_stop_alarm(wm8350); | ||
248 | } | ||
249 | |||
239 | static int wm8350_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm) | 250 | static int wm8350_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm) |
240 | { | 251 | { |
241 | struct wm8350 *wm8350 = dev_get_drvdata(dev); | 252 | struct wm8350 *wm8350 = dev_get_drvdata(dev); |
@@ -291,30 +302,15 @@ static int wm8350_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm) | |||
291 | return ret; | 302 | return ret; |
292 | } | 303 | } |
293 | 304 | ||
294 | /* | 305 | static int wm8350_rtc_update_irq_enable(struct device *dev, |
295 | * Handle commands from user-space | 306 | unsigned int enabled) |
296 | */ | ||
297 | static int wm8350_rtc_ioctl(struct device *dev, unsigned int cmd, | ||
298 | unsigned long arg) | ||
299 | { | 307 | { |
300 | struct wm8350 *wm8350 = dev_get_drvdata(dev); | 308 | struct wm8350 *wm8350 = dev_get_drvdata(dev); |
301 | 309 | ||
302 | switch (cmd) { | 310 | if (enabled) |
303 | case RTC_AIE_OFF: | ||
304 | return wm8350_rtc_stop_alarm(wm8350); | ||
305 | case RTC_AIE_ON: | ||
306 | return wm8350_rtc_start_alarm(wm8350); | ||
307 | |||
308 | case RTC_UIE_OFF: | ||
309 | wm8350_mask_irq(wm8350, WM8350_IRQ_RTC_SEC); | ||
310 | break; | ||
311 | case RTC_UIE_ON: | ||
312 | wm8350_unmask_irq(wm8350, WM8350_IRQ_RTC_SEC); | 311 | wm8350_unmask_irq(wm8350, WM8350_IRQ_RTC_SEC); |
313 | break; | 312 | else |
314 | 313 | wm8350_mask_irq(wm8350, WM8350_IRQ_RTC_SEC); | |
315 | default: | ||
316 | return -ENOIOCTLCMD; | ||
317 | } | ||
318 | 314 | ||
319 | return 0; | 315 | return 0; |
320 | } | 316 | } |
@@ -345,11 +341,12 @@ static void wm8350_rtc_update_handler(struct wm8350 *wm8350, int irq, | |||
345 | } | 341 | } |
346 | 342 | ||
347 | static const struct rtc_class_ops wm8350_rtc_ops = { | 343 | static const struct rtc_class_ops wm8350_rtc_ops = { |
348 | .ioctl = wm8350_rtc_ioctl, | ||
349 | .read_time = wm8350_rtc_readtime, | 344 | .read_time = wm8350_rtc_readtime, |
350 | .set_time = wm8350_rtc_settime, | 345 | .set_time = wm8350_rtc_settime, |
351 | .read_alarm = wm8350_rtc_readalarm, | 346 | .read_alarm = wm8350_rtc_readalarm, |
352 | .set_alarm = wm8350_rtc_setalarm, | 347 | .set_alarm = wm8350_rtc_setalarm, |
348 | .alarm_irq_enable = wm8350_rtc_alarm_irq_enable, | ||
349 | .update_irq_enable = wm8350_rtc_update_irq_enable, | ||
353 | }; | 350 | }; |
354 | 351 | ||
355 | #ifdef CONFIG_PM | 352 | #ifdef CONFIG_PM |
@@ -440,7 +437,7 @@ static int wm8350_rtc_probe(struct platform_device *pdev) | |||
440 | do { | 437 | do { |
441 | timectl = wm8350_reg_read(wm8350, | 438 | timectl = wm8350_reg_read(wm8350, |
442 | WM8350_RTC_TIME_CONTROL); | 439 | WM8350_RTC_TIME_CONTROL); |
443 | } while (timectl & WM8350_RTC_STS && retries--); | 440 | } while (timectl & WM8350_RTC_STS && --retries); |
444 | 441 | ||
445 | if (retries == 0) { | 442 | if (retries == 0) { |
446 | dev_err(&pdev->dev, "failed to start: timeout\n"); | 443 | dev_err(&pdev->dev, "failed to start: timeout\n"); |