aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/rtc
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/rtc')
-rw-r--r--drivers/rtc/Kconfig11
-rw-r--r--drivers/rtc/Makefile1
-rw-r--r--drivers/rtc/interface.c12
-rw-r--r--drivers/rtc/rtc-dev.c6
-rw-r--r--drivers/rtc/rtc-ds1305.c3
-rw-r--r--drivers/rtc/rtc-ds1307.c46
-rw-r--r--drivers/rtc/rtc-ds1374.c5
-rw-r--r--drivers/rtc/rtc-ds1553.c3
-rw-r--r--drivers/rtc/rtc-ds1742.c31
-rw-r--r--drivers/rtc/rtc-ep93xx.c149
-rw-r--r--drivers/rtc/rtc-pl030.c2
-rw-r--r--drivers/rtc/rtc-pl031.c3
-rw-r--r--drivers/rtc/rtc-rx8025.c688
-rw-r--r--drivers/rtc/rtc-test.c2
-rw-r--r--drivers/rtc/rtc-tx4939.c4
15 files changed, 871 insertions, 95 deletions
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index 4e9851fc1746..81adbdbd5042 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -296,6 +296,15 @@ config RTC_DRV_RX8581
296 This driver can also be built as a module. If so the module 296 This driver can also be built as a module. If so the module
297 will be called rtc-rx8581. 297 will be called rtc-rx8581.
298 298
299config RTC_DRV_RX8025
300 tristate "Epson RX-8025SA/NB"
301 help
302 If you say yes here you get support for the Epson
303 RX-8025SA/NB RTC chips.
304
305 This driver can also be built as a module. If so, the module
306 will be called rtc-rx8025.
307
299endif # I2C 308endif # I2C
300 309
301comment "SPI RTC drivers" 310comment "SPI RTC drivers"
@@ -692,7 +701,7 @@ config RTC_DRV_GENERIC
692 tristate "Generic RTC support" 701 tristate "Generic RTC support"
693 # Please consider writing a new RTC driver instead of using the generic 702 # Please consider writing a new RTC driver instead of using the generic
694 # RTC abstraction 703 # RTC abstraction
695 depends on PARISC || M68K || PPC 704 depends on PARISC || M68K || PPC || SUPERH32
696 help 705 help
697 Say Y or M here to enable RTC support on systems using the generic 706 Say Y or M here to enable RTC support on systems using the generic
698 RTC abstraction. If you do not know what you are doing, you should 707 RTC abstraction. If you do not know what you are doing, you should
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index 6c0639a14f09..3c0f2b2ac927 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -62,6 +62,7 @@ obj-$(CONFIG_RTC_DRV_R9701) += rtc-r9701.o
62obj-$(CONFIG_RTC_DRV_RS5C313) += rtc-rs5c313.o 62obj-$(CONFIG_RTC_DRV_RS5C313) += rtc-rs5c313.o
63obj-$(CONFIG_RTC_DRV_RS5C348) += rtc-rs5c348.o 63obj-$(CONFIG_RTC_DRV_RS5C348) += rtc-rs5c348.o
64obj-$(CONFIG_RTC_DRV_RS5C372) += rtc-rs5c372.o 64obj-$(CONFIG_RTC_DRV_RS5C372) += rtc-rs5c372.o
65obj-$(CONFIG_RTC_DRV_RX8025) += rtc-rx8025.o
65obj-$(CONFIG_RTC_DRV_RX8581) += rtc-rx8581.o 66obj-$(CONFIG_RTC_DRV_RX8581) += rtc-rx8581.o
66obj-$(CONFIG_RTC_DRV_S35390A) += rtc-s35390a.o 67obj-$(CONFIG_RTC_DRV_S35390A) += rtc-s35390a.o
67obj-$(CONFIG_RTC_DRV_S3C) += rtc-s3c.o 68obj-$(CONFIG_RTC_DRV_S3C) += rtc-s3c.o
diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c
index 4348c4b0d453..4cdb31a362ca 100644
--- a/drivers/rtc/interface.c
+++ b/drivers/rtc/interface.c
@@ -371,19 +371,21 @@ EXPORT_SYMBOL_GPL(rtc_update_irq_enable);
371 * @rtc: the rtc device 371 * @rtc: the rtc device
372 * @num: how many irqs are being reported (usually one) 372 * @num: how many irqs are being reported (usually one)
373 * @events: mask of RTC_IRQF with one or more of RTC_PF, RTC_AF, RTC_UF 373 * @events: mask of RTC_IRQF with one or more of RTC_PF, RTC_AF, RTC_UF
374 * Context: in_interrupt(), irqs blocked 374 * Context: any
375 */ 375 */
376void rtc_update_irq(struct rtc_device *rtc, 376void rtc_update_irq(struct rtc_device *rtc,
377 unsigned long num, unsigned long events) 377 unsigned long num, unsigned long events)
378{ 378{
379 spin_lock(&rtc->irq_lock); 379 unsigned long flags;
380
381 spin_lock_irqsave(&rtc->irq_lock, flags);
380 rtc->irq_data = (rtc->irq_data + (num << 8)) | events; 382 rtc->irq_data = (rtc->irq_data + (num << 8)) | events;
381 spin_unlock(&rtc->irq_lock); 383 spin_unlock_irqrestore(&rtc->irq_lock, flags);
382 384
383 spin_lock(&rtc->irq_task_lock); 385 spin_lock_irqsave(&rtc->irq_task_lock, flags);
384 if (rtc->irq_task) 386 if (rtc->irq_task)
385 rtc->irq_task->func(rtc->irq_task->private_data); 387 rtc->irq_task->func(rtc->irq_task->private_data);
386 spin_unlock(&rtc->irq_task_lock); 388 spin_unlock_irqrestore(&rtc->irq_task_lock, flags);
387 389
388 wake_up_interruptible(&rtc->irq_queue); 390 wake_up_interruptible(&rtc->irq_queue);
389 kill_fasync(&rtc->async_queue, SIGIO, POLL_IN); 391 kill_fasync(&rtc->async_queue, SIGIO, POLL_IN);
diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
index 45152f4952d6..8a11de9552cd 100644
--- a/drivers/rtc/rtc-dev.c
+++ b/drivers/rtc/rtc-dev.c
@@ -60,8 +60,7 @@ static void rtc_uie_task(struct work_struct *work)
60 60
61 err = rtc_read_time(rtc, &tm); 61 err = rtc_read_time(rtc, &tm);
62 62
63 local_irq_disable(); 63 spin_lock_irq(&rtc->irq_lock);
64 spin_lock(&rtc->irq_lock);
65 if (rtc->stop_uie_polling || err) { 64 if (rtc->stop_uie_polling || err) {
66 rtc->uie_task_active = 0; 65 rtc->uie_task_active = 0;
67 } else if (rtc->oldsecs != tm.tm_sec) { 66 } else if (rtc->oldsecs != tm.tm_sec) {
@@ -74,10 +73,9 @@ static void rtc_uie_task(struct work_struct *work)
74 } else if (schedule_work(&rtc->uie_task) == 0) { 73 } else if (schedule_work(&rtc->uie_task) == 0) {
75 rtc->uie_task_active = 0; 74 rtc->uie_task_active = 0;
76 } 75 }
77 spin_unlock(&rtc->irq_lock); 76 spin_unlock_irq(&rtc->irq_lock);
78 if (num) 77 if (num)
79 rtc_update_irq(rtc, num, RTC_UF | RTC_IRQF); 78 rtc_update_irq(rtc, num, RTC_UF | RTC_IRQF);
80 local_irq_enable();
81} 79}
82static void rtc_uie_timer(unsigned long data) 80static void rtc_uie_timer(unsigned long data)
83{ 81{
diff --git a/drivers/rtc/rtc-ds1305.c b/drivers/rtc/rtc-ds1305.c
index fc372df6534b..8f410e59d9f5 100644
--- a/drivers/rtc/rtc-ds1305.c
+++ b/drivers/rtc/rtc-ds1305.c
@@ -499,10 +499,7 @@ static void ds1305_work(struct work_struct *work)
499 if (!test_bit(FLAG_EXITING, &ds1305->flags)) 499 if (!test_bit(FLAG_EXITING, &ds1305->flags))
500 enable_irq(spi->irq); 500 enable_irq(spi->irq);
501 501
502 /* rtc_update_irq() requires an IRQ-disabled context */
503 local_irq_disable();
504 rtc_update_irq(ds1305->rtc, 1, RTC_AF | RTC_IRQF); 502 rtc_update_irq(ds1305->rtc, 1, RTC_AF | RTC_IRQF);
505 local_irq_enable();
506} 503}
507 504
508/* 505/*
diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
index 2c4a65302a9d..47a93c022d91 100644
--- a/drivers/rtc/rtc-ds1307.c
+++ b/drivers/rtc/rtc-ds1307.c
@@ -31,6 +31,8 @@ enum ds_type {
31 ds_1338, 31 ds_1338,
32 ds_1339, 32 ds_1339,
33 ds_1340, 33 ds_1340,
34 ds_1388,
35 ds_3231,
34 m41t00, 36 m41t00,
35 rx_8025, 37 rx_8025,
36 // rs5c372 too? different address... 38 // rs5c372 too? different address...
@@ -66,6 +68,7 @@ enum ds_type {
66#define DS1337_REG_CONTROL 0x0e 68#define DS1337_REG_CONTROL 0x0e
67# define DS1337_BIT_nEOSC 0x80 69# define DS1337_BIT_nEOSC 0x80
68# define DS1339_BIT_BBSQI 0x20 70# define DS1339_BIT_BBSQI 0x20
71# define DS3231_BIT_BBSQW 0x40 /* same as BBSQI */
69# define DS1337_BIT_RS2 0x10 72# define DS1337_BIT_RS2 0x10
70# define DS1337_BIT_RS1 0x08 73# define DS1337_BIT_RS1 0x08
71# define DS1337_BIT_INTCN 0x04 74# define DS1337_BIT_INTCN 0x04
@@ -94,6 +97,7 @@ enum ds_type {
94 97
95 98
96struct ds1307 { 99struct ds1307 {
100 u8 offset; /* register's offset */
97 u8 regs[11]; 101 u8 regs[11];
98 enum ds_type type; 102 enum ds_type type;
99 unsigned long flags; 103 unsigned long flags;
@@ -128,6 +132,9 @@ static const struct chip_desc chips[] = {
128}, 132},
129[ds_1340] = { 133[ds_1340] = {
130}, 134},
135[ds_3231] = {
136 .alarm = 1,
137},
131[m41t00] = { 138[m41t00] = {
132}, 139},
133[rx_8025] = { 140[rx_8025] = {
@@ -138,7 +145,9 @@ static const struct i2c_device_id ds1307_id[] = {
138 { "ds1337", ds_1337 }, 145 { "ds1337", ds_1337 },
139 { "ds1338", ds_1338 }, 146 { "ds1338", ds_1338 },
140 { "ds1339", ds_1339 }, 147 { "ds1339", ds_1339 },
148 { "ds1388", ds_1388 },
141 { "ds1340", ds_1340 }, 149 { "ds1340", ds_1340 },
150 { "ds3231", ds_3231 },
142 { "m41t00", m41t00 }, 151 { "m41t00", m41t00 },
143 { "rx8025", rx_8025 }, 152 { "rx8025", rx_8025 },
144 { } 153 { }
@@ -258,12 +267,7 @@ static void ds1307_work(struct work_struct *work)
258 control &= ~DS1337_BIT_A1IE; 267 control &= ~DS1337_BIT_A1IE;
259 i2c_smbus_write_byte_data(client, DS1337_REG_CONTROL, control); 268 i2c_smbus_write_byte_data(client, DS1337_REG_CONTROL, control);
260 269
261 /* rtc_update_irq() assumes that it is called
262 * from IRQ-disabled context.
263 */
264 local_irq_disable();
265 rtc_update_irq(ds1307->rtc, 1, RTC_AF | RTC_IRQF); 270 rtc_update_irq(ds1307->rtc, 1, RTC_AF | RTC_IRQF);
266 local_irq_enable();
267 } 271 }
268 272
269out: 273out:
@@ -291,7 +295,7 @@ static int ds1307_get_time(struct device *dev, struct rtc_time *t)
291 295
292 /* read the RTC date and time registers all at once */ 296 /* read the RTC date and time registers all at once */
293 tmp = ds1307->read_block_data(ds1307->client, 297 tmp = ds1307->read_block_data(ds1307->client,
294 DS1307_REG_SECS, 7, ds1307->regs); 298 ds1307->offset, 7, ds1307->regs);
295 if (tmp != 7) { 299 if (tmp != 7) {
296 dev_err(dev, "%s error %d\n", "read", tmp); 300 dev_err(dev, "%s error %d\n", "read", tmp);
297 return -EIO; 301 return -EIO;
@@ -353,6 +357,7 @@ static int ds1307_set_time(struct device *dev, struct rtc_time *t)
353 switch (ds1307->type) { 357 switch (ds1307->type) {
354 case ds_1337: 358 case ds_1337:
355 case ds_1339: 359 case ds_1339:
360 case ds_3231:
356 buf[DS1307_REG_MONTH] |= DS1337_BIT_CENTURY; 361 buf[DS1307_REG_MONTH] |= DS1337_BIT_CENTURY;
357 break; 362 break;
358 case ds_1340: 363 case ds_1340:
@@ -367,7 +372,8 @@ static int ds1307_set_time(struct device *dev, struct rtc_time *t)
367 "write", buf[0], buf[1], buf[2], buf[3], 372 "write", buf[0], buf[1], buf[2], buf[3],
368 buf[4], buf[5], buf[6]); 373 buf[4], buf[5], buf[6]);
369 374
370 result = ds1307->write_block_data(ds1307->client, 0, 7, buf); 375 result = ds1307->write_block_data(ds1307->client,
376 ds1307->offset, 7, buf);
371 if (result < 0) { 377 if (result < 0) {
372 dev_err(dev, "%s error %d\n", "write", result); 378 dev_err(dev, "%s error %d\n", "write", result);
373 return result; 379 return result;
@@ -624,6 +630,11 @@ static int __devinit ds1307_probe(struct i2c_client *client,
624 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); 630 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
625 int want_irq = false; 631 int want_irq = false;
626 unsigned char *buf; 632 unsigned char *buf;
633 static const int bbsqi_bitpos[] = {
634 [ds_1337] = 0,
635 [ds_1339] = DS1339_BIT_BBSQI,
636 [ds_3231] = DS3231_BIT_BBSQW,
637 };
627 638
628 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA) 639 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)
629 && !i2c_check_functionality(adapter, I2C_FUNC_SMBUS_I2C_BLOCK)) 640 && !i2c_check_functionality(adapter, I2C_FUNC_SMBUS_I2C_BLOCK))
@@ -632,9 +643,12 @@ static int __devinit ds1307_probe(struct i2c_client *client,
632 if (!(ds1307 = kzalloc(sizeof(struct ds1307), GFP_KERNEL))) 643 if (!(ds1307 = kzalloc(sizeof(struct ds1307), GFP_KERNEL)))
633 return -ENOMEM; 644 return -ENOMEM;
634 645
635 ds1307->client = client;
636 i2c_set_clientdata(client, ds1307); 646 i2c_set_clientdata(client, ds1307);
637 ds1307->type = id->driver_data; 647
648 ds1307->client = client;
649 ds1307->type = id->driver_data;
650 ds1307->offset = 0;
651
638 buf = ds1307->regs; 652 buf = ds1307->regs;
639 if (i2c_check_functionality(adapter, I2C_FUNC_SMBUS_I2C_BLOCK)) { 653 if (i2c_check_functionality(adapter, I2C_FUNC_SMBUS_I2C_BLOCK)) {
640 ds1307->read_block_data = i2c_smbus_read_i2c_block_data; 654 ds1307->read_block_data = i2c_smbus_read_i2c_block_data;
@@ -647,6 +661,7 @@ static int __devinit ds1307_probe(struct i2c_client *client,
647 switch (ds1307->type) { 661 switch (ds1307->type) {
648 case ds_1337: 662 case ds_1337:
649 case ds_1339: 663 case ds_1339:
664 case ds_3231:
650 /* has IRQ? */ 665 /* has IRQ? */
651 if (ds1307->client->irq > 0 && chip->alarm) { 666 if (ds1307->client->irq > 0 && chip->alarm) {
652 INIT_WORK(&ds1307->work, ds1307_work); 667 INIT_WORK(&ds1307->work, ds1307_work);
@@ -666,12 +681,12 @@ static int __devinit ds1307_probe(struct i2c_client *client,
666 ds1307->regs[0] &= ~DS1337_BIT_nEOSC; 681 ds1307->regs[0] &= ~DS1337_BIT_nEOSC;
667 682
668 /* Using IRQ? Disable the square wave and both alarms. 683 /* Using IRQ? Disable the square wave and both alarms.
669 * For ds1339, be sure alarms can trigger when we're 684 * For some variants, be sure alarms can trigger when we're
670 * running on Vbackup (BBSQI); we assume ds1337 will 685 * running on Vbackup (BBSQI/BBSQW)
671 * ignore that bit
672 */ 686 */
673 if (want_irq) { 687 if (want_irq) {
674 ds1307->regs[0] |= DS1337_BIT_INTCN | DS1339_BIT_BBSQI; 688 ds1307->regs[0] |= DS1337_BIT_INTCN
689 | bbsqi_bitpos[ds1307->type];
675 ds1307->regs[0] &= ~(DS1337_BIT_A2IE | DS1337_BIT_A1IE); 690 ds1307->regs[0] &= ~(DS1337_BIT_A2IE | DS1337_BIT_A1IE);
676 } 691 }
677 692
@@ -751,6 +766,9 @@ static int __devinit ds1307_probe(struct i2c_client *client,
751 hour); 766 hour);
752 } 767 }
753 break; 768 break;
769 case ds_1388:
770 ds1307->offset = 1; /* Seconds starts at 1 */
771 break;
754 default: 772 default:
755 break; 773 break;
756 } 774 }
@@ -814,6 +832,8 @@ read_rtc:
814 case rx_8025: 832 case rx_8025:
815 case ds_1337: 833 case ds_1337:
816 case ds_1339: 834 case ds_1339:
835 case ds_1388:
836 case ds_3231:
817 break; 837 break;
818 } 838 }
819 839
diff --git a/drivers/rtc/rtc-ds1374.c b/drivers/rtc/rtc-ds1374.c
index 4d32e328f6cd..32b27739ec2a 100644
--- a/drivers/rtc/rtc-ds1374.c
+++ b/drivers/rtc/rtc-ds1374.c
@@ -296,12 +296,7 @@ static void ds1374_work(struct work_struct *work)
296 control &= ~(DS1374_REG_CR_WACE | DS1374_REG_CR_AIE); 296 control &= ~(DS1374_REG_CR_WACE | DS1374_REG_CR_AIE);
297 i2c_smbus_write_byte_data(client, DS1374_REG_CR, control); 297 i2c_smbus_write_byte_data(client, DS1374_REG_CR, control);
298 298
299 /* rtc_update_irq() assumes that it is called
300 * from IRQ-disabled context.
301 */
302 local_irq_disable();
303 rtc_update_irq(ds1374->rtc, 1, RTC_AF | RTC_IRQF); 299 rtc_update_irq(ds1374->rtc, 1, RTC_AF | RTC_IRQF);
304 local_irq_enable();
305 } 300 }
306 301
307out: 302out:
diff --git a/drivers/rtc/rtc-ds1553.c b/drivers/rtc/rtc-ds1553.c
index 38d472b63406..717288527c6b 100644
--- a/drivers/rtc/rtc-ds1553.c
+++ b/drivers/rtc/rtc-ds1553.c
@@ -329,8 +329,7 @@ static int __devinit ds1553_rtc_probe(struct platform_device *pdev)
329 if (pdata->irq > 0) { 329 if (pdata->irq > 0) {
330 writeb(0, ioaddr + RTC_INTERRUPTS); 330 writeb(0, ioaddr + RTC_INTERRUPTS);
331 if (request_irq(pdata->irq, ds1553_rtc_interrupt, 331 if (request_irq(pdata->irq, ds1553_rtc_interrupt,
332 IRQF_DISABLED | IRQF_SHARED, 332 IRQF_DISABLED, pdev->name, pdev) < 0) {
333 pdev->name, pdev) < 0) {
334 dev_warn(&pdev->dev, "interrupt not available.\n"); 333 dev_warn(&pdev->dev, "interrupt not available.\n");
335 pdata->irq = 0; 334 pdata->irq = 0;
336 } 335 }
diff --git a/drivers/rtc/rtc-ds1742.c b/drivers/rtc/rtc-ds1742.c
index 8bc8501bffc8..09249459e9a4 100644
--- a/drivers/rtc/rtc-ds1742.c
+++ b/drivers/rtc/rtc-ds1742.c
@@ -57,6 +57,7 @@ struct rtc_plat_data {
57 size_t size; 57 size_t size;
58 resource_size_t baseaddr; 58 resource_size_t baseaddr;
59 unsigned long last_jiffies; 59 unsigned long last_jiffies;
60 struct bin_attribute nvram_attr;
60}; 61};
61 62
62static int ds1742_rtc_set_time(struct device *dev, struct rtc_time *tm) 63static int ds1742_rtc_set_time(struct device *dev, struct rtc_time *tm)
@@ -157,18 +158,6 @@ static ssize_t ds1742_nvram_write(struct kobject *kobj,
157 return count; 158 return count;
158} 159}
159 160
160static struct bin_attribute ds1742_nvram_attr = {
161 .attr = {
162 .name = "nvram",
163 .mode = S_IRUGO | S_IWUSR,
164 },
165 .read = ds1742_nvram_read,
166 .write = ds1742_nvram_write,
167 /* REVISIT: size in sysfs won't match actual size... if it's
168 * not a constant, each RTC should have its own attribute.
169 */
170};
171
172static int __devinit ds1742_rtc_probe(struct platform_device *pdev) 161static int __devinit ds1742_rtc_probe(struct platform_device *pdev)
173{ 162{
174 struct rtc_device *rtc; 163 struct rtc_device *rtc;
@@ -199,6 +188,12 @@ static int __devinit ds1742_rtc_probe(struct platform_device *pdev)
199 pdata->size_nvram = pdata->size - RTC_SIZE; 188 pdata->size_nvram = pdata->size - RTC_SIZE;
200 pdata->ioaddr_rtc = ioaddr + pdata->size_nvram; 189 pdata->ioaddr_rtc = ioaddr + pdata->size_nvram;
201 190
191 pdata->nvram_attr.attr.name = "nvram";
192 pdata->nvram_attr.attr.mode = S_IRUGO | S_IWUSR;
193 pdata->nvram_attr.read = ds1742_nvram_read;
194 pdata->nvram_attr.write = ds1742_nvram_write;
195 pdata->nvram_attr.size = pdata->size_nvram;
196
202 /* turn RTC on if it was not on */ 197 /* turn RTC on if it was not on */
203 ioaddr = pdata->ioaddr_rtc; 198 ioaddr = pdata->ioaddr_rtc;
204 sec = readb(ioaddr + RTC_SECONDS); 199 sec = readb(ioaddr + RTC_SECONDS);
@@ -221,11 +216,13 @@ static int __devinit ds1742_rtc_probe(struct platform_device *pdev)
221 pdata->rtc = rtc; 216 pdata->rtc = rtc;
222 pdata->last_jiffies = jiffies; 217 pdata->last_jiffies = jiffies;
223 platform_set_drvdata(pdev, pdata); 218 platform_set_drvdata(pdev, pdata);
224 ds1742_nvram_attr.size = max(ds1742_nvram_attr.size, 219
225 pdata->size_nvram); 220 ret = sysfs_create_bin_file(&pdev->dev.kobj, &pdata->nvram_attr);
226 ret = sysfs_create_bin_file(&pdev->dev.kobj, &ds1742_nvram_attr); 221 if (ret) {
227 if (ret) 222 dev_err(&pdev->dev, "creating nvram file in sysfs failed\n");
228 goto out; 223 goto out;
224 }
225
229 return 0; 226 return 0;
230 out: 227 out:
231 if (pdata->rtc) 228 if (pdata->rtc)
@@ -242,7 +239,7 @@ static int __devexit ds1742_rtc_remove(struct platform_device *pdev)
242{ 239{
243 struct rtc_plat_data *pdata = platform_get_drvdata(pdev); 240 struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
244 241
245 sysfs_remove_bin_file(&pdev->dev.kobj, &ds1742_nvram_attr); 242 sysfs_remove_bin_file(&pdev->dev.kobj, &pdata->nvram_attr);
246 rtc_device_unregister(pdata->rtc); 243 rtc_device_unregister(pdata->rtc);
247 iounmap(pdata->ioaddr_nvram); 244 iounmap(pdata->ioaddr_nvram);
248 release_mem_region(pdata->baseaddr, pdata->size); 245 release_mem_region(pdata->baseaddr, pdata->size);
diff --git a/drivers/rtc/rtc-ep93xx.c b/drivers/rtc/rtc-ep93xx.c
index f7a3283dd029..551332e4ed02 100644
--- a/drivers/rtc/rtc-ep93xx.c
+++ b/drivers/rtc/rtc-ep93xx.c
@@ -12,32 +12,56 @@
12#include <linux/module.h> 12#include <linux/module.h>
13#include <linux/rtc.h> 13#include <linux/rtc.h>
14#include <linux/platform_device.h> 14#include <linux/platform_device.h>
15#include <mach/hardware.h> 15#include <linux/io.h>
16
17#define EP93XX_RTC_DATA 0x000
18#define EP93XX_RTC_MATCH 0x004
19#define EP93XX_RTC_STATUS 0x008
20#define EP93XX_RTC_STATUS_INTR (1<<0)
21#define EP93XX_RTC_LOAD 0x00C
22#define EP93XX_RTC_CONTROL 0x010
23#define EP93XX_RTC_CONTROL_MIE (1<<0)
24#define EP93XX_RTC_SWCOMP 0x108
25#define EP93XX_RTC_SWCOMP_DEL_MASK 0x001f0000
26#define EP93XX_RTC_SWCOMP_DEL_SHIFT 16
27#define EP93XX_RTC_SWCOMP_INT_MASK 0x0000ffff
28#define EP93XX_RTC_SWCOMP_INT_SHIFT 0
29
30#define DRV_VERSION "0.3"
16 31
17#define EP93XX_RTC_REG(x) (EP93XX_RTC_BASE + (x)) 32/*
18#define EP93XX_RTC_DATA EP93XX_RTC_REG(0x0000) 33 * struct device dev.platform_data is used to store our private data
19#define EP93XX_RTC_LOAD EP93XX_RTC_REG(0x000C) 34 * because struct rtc_device does not have a variable to hold it.
20#define EP93XX_RTC_SWCOMP EP93XX_RTC_REG(0x0108) 35 */
21 36struct ep93xx_rtc {
22#define DRV_VERSION "0.2" 37 void __iomem *mmio_base;
38};
23 39
24static int ep93xx_get_swcomp(struct device *dev, unsigned short *preload, 40static int ep93xx_rtc_get_swcomp(struct device *dev, unsigned short *preload,
25 unsigned short *delete) 41 unsigned short *delete)
26{ 42{
27 unsigned short comp = __raw_readl(EP93XX_RTC_SWCOMP); 43 struct ep93xx_rtc *ep93xx_rtc = dev->platform_data;
44 unsigned long comp;
45
46 comp = __raw_readl(ep93xx_rtc->mmio_base + EP93XX_RTC_SWCOMP);
28 47
29 if (preload) 48 if (preload)
30 *preload = comp & 0xffff; 49 *preload = (comp & EP93XX_RTC_SWCOMP_INT_MASK)
50 >> EP93XX_RTC_SWCOMP_INT_SHIFT;
31 51
32 if (delete) 52 if (delete)
33 *delete = (comp >> 16) & 0x1f; 53 *delete = (comp & EP93XX_RTC_SWCOMP_DEL_MASK)
54 >> EP93XX_RTC_SWCOMP_DEL_SHIFT;
34 55
35 return 0; 56 return 0;
36} 57}
37 58
38static int ep93xx_rtc_read_time(struct device *dev, struct rtc_time *tm) 59static int ep93xx_rtc_read_time(struct device *dev, struct rtc_time *tm)
39{ 60{
40 unsigned long time = __raw_readl(EP93XX_RTC_DATA); 61 struct ep93xx_rtc *ep93xx_rtc = dev->platform_data;
62 unsigned long time;
63
64 time = __raw_readl(ep93xx_rtc->mmio_base + EP93XX_RTC_DATA);
41 65
42 rtc_time_to_tm(time, tm); 66 rtc_time_to_tm(time, tm);
43 return 0; 67 return 0;
@@ -45,7 +69,9 @@ static int ep93xx_rtc_read_time(struct device *dev, struct rtc_time *tm)
45 69
46static int ep93xx_rtc_set_mmss(struct device *dev, unsigned long secs) 70static int ep93xx_rtc_set_mmss(struct device *dev, unsigned long secs)
47{ 71{
48 __raw_writel(secs + 1, EP93XX_RTC_LOAD); 72 struct ep93xx_rtc *ep93xx_rtc = dev->platform_data;
73
74 __raw_writel(secs + 1, ep93xx_rtc->mmio_base + EP93XX_RTC_LOAD);
49 return 0; 75 return 0;
50} 76}
51 77
@@ -53,7 +79,7 @@ static int ep93xx_rtc_proc(struct device *dev, struct seq_file *seq)
53{ 79{
54 unsigned short preload, delete; 80 unsigned short preload, delete;
55 81
56 ep93xx_get_swcomp(dev, &preload, &delete); 82 ep93xx_rtc_get_swcomp(dev, &preload, &delete);
57 83
58 seq_printf(seq, "preload\t\t: %d\n", preload); 84 seq_printf(seq, "preload\t\t: %d\n", preload);
59 seq_printf(seq, "delete\t\t: %d\n", delete); 85 seq_printf(seq, "delete\t\t: %d\n", delete);
@@ -67,54 +93,104 @@ static const struct rtc_class_ops ep93xx_rtc_ops = {
67 .proc = ep93xx_rtc_proc, 93 .proc = ep93xx_rtc_proc,
68}; 94};
69 95
70static ssize_t ep93xx_sysfs_show_comp_preload(struct device *dev, 96static ssize_t ep93xx_rtc_show_comp_preload(struct device *dev,
71 struct device_attribute *attr, char *buf) 97 struct device_attribute *attr, char *buf)
72{ 98{
73 unsigned short preload; 99 unsigned short preload;
74 100
75 ep93xx_get_swcomp(dev, &preload, NULL); 101 ep93xx_rtc_get_swcomp(dev, &preload, NULL);
76 102
77 return sprintf(buf, "%d\n", preload); 103 return sprintf(buf, "%d\n", preload);
78} 104}
79static DEVICE_ATTR(comp_preload, S_IRUGO, ep93xx_sysfs_show_comp_preload, NULL); 105static DEVICE_ATTR(comp_preload, S_IRUGO, ep93xx_rtc_show_comp_preload, NULL);
80 106
81static ssize_t ep93xx_sysfs_show_comp_delete(struct device *dev, 107static ssize_t ep93xx_rtc_show_comp_delete(struct device *dev,
82 struct device_attribute *attr, char *buf) 108 struct device_attribute *attr, char *buf)
83{ 109{
84 unsigned short delete; 110 unsigned short delete;
85 111
86 ep93xx_get_swcomp(dev, NULL, &delete); 112 ep93xx_rtc_get_swcomp(dev, NULL, &delete);
87 113
88 return sprintf(buf, "%d\n", delete); 114 return sprintf(buf, "%d\n", delete);
89} 115}
90static DEVICE_ATTR(comp_delete, S_IRUGO, ep93xx_sysfs_show_comp_delete, NULL); 116static DEVICE_ATTR(comp_delete, S_IRUGO, ep93xx_rtc_show_comp_delete, NULL);
91 117
92 118
93static int __devinit ep93xx_rtc_probe(struct platform_device *dev) 119static int __init ep93xx_rtc_probe(struct platform_device *pdev)
94{ 120{
95 struct rtc_device *rtc = rtc_device_register("ep93xx", 121 struct ep93xx_rtc *ep93xx_rtc;
96 &dev->dev, &ep93xx_rtc_ops, THIS_MODULE); 122 struct resource *res;
123 struct rtc_device *rtc;
124 int err;
125
126 ep93xx_rtc = kzalloc(sizeof(struct ep93xx_rtc), GFP_KERNEL);
127 if (ep93xx_rtc == NULL)
128 return -ENOMEM;
129
130 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
131 if (res == NULL)
132 return -ENXIO;
133
134 res = request_mem_region(res->start, resource_size(res), pdev->name);
135 if (res == NULL)
136 return -EBUSY;
137
138 ep93xx_rtc->mmio_base = ioremap(res->start, resource_size(res));
139 if (ep93xx_rtc->mmio_base == NULL) {
140 err = -ENXIO;
141 goto fail;
142 }
97 143
144 pdev->dev.platform_data = ep93xx_rtc;
145
146 rtc = rtc_device_register(pdev->name,
147 &pdev->dev, &ep93xx_rtc_ops, THIS_MODULE);
98 if (IS_ERR(rtc)) { 148 if (IS_ERR(rtc)) {
99 return PTR_ERR(rtc); 149 err = PTR_ERR(rtc);
150 goto fail;
100 } 151 }
101 152
102 platform_set_drvdata(dev, rtc); 153 platform_set_drvdata(pdev, rtc);
103 154
104 device_create_file(&dev->dev, &dev_attr_comp_preload); 155 err = device_create_file(&pdev->dev, &dev_attr_comp_preload);
105 device_create_file(&dev->dev, &dev_attr_comp_delete); 156 if (err)
157 goto fail;
158 err = device_create_file(&pdev->dev, &dev_attr_comp_delete);
159 if (err) {
160 device_remove_file(&pdev->dev, &dev_attr_comp_preload);
161 goto fail;
162 }
106 163
107 return 0; 164 return 0;
165
166fail:
167 if (ep93xx_rtc->mmio_base) {
168 iounmap(ep93xx_rtc->mmio_base);
169 pdev->dev.platform_data = NULL;
170 }
171 release_mem_region(res->start, resource_size(res));
172 return err;
108} 173}
109 174
110static int __devexit ep93xx_rtc_remove(struct platform_device *dev) 175static int __exit ep93xx_rtc_remove(struct platform_device *pdev)
111{ 176{
112 struct rtc_device *rtc = platform_get_drvdata(dev); 177 struct rtc_device *rtc = platform_get_drvdata(pdev);
178 struct ep93xx_rtc *ep93xx_rtc = pdev->dev.platform_data;
179 struct resource *res;
180
181 /* cleanup sysfs */
182 device_remove_file(&pdev->dev, &dev_attr_comp_delete);
183 device_remove_file(&pdev->dev, &dev_attr_comp_preload);
184
185 rtc_device_unregister(rtc);
186
187 iounmap(ep93xx_rtc->mmio_base);
188 pdev->dev.platform_data = NULL;
113 189
114 if (rtc) 190 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
115 rtc_device_unregister(rtc); 191 release_mem_region(res->start, resource_size(res));
116 192
117 platform_set_drvdata(dev, NULL); 193 platform_set_drvdata(pdev, NULL);
118 194
119 return 0; 195 return 0;
120} 196}
@@ -122,23 +198,22 @@ static int __devexit ep93xx_rtc_remove(struct platform_device *dev)
122/* work with hotplug and coldplug */ 198/* work with hotplug and coldplug */
123MODULE_ALIAS("platform:ep93xx-rtc"); 199MODULE_ALIAS("platform:ep93xx-rtc");
124 200
125static struct platform_driver ep93xx_rtc_platform_driver = { 201static struct platform_driver ep93xx_rtc_driver = {
126 .driver = { 202 .driver = {
127 .name = "ep93xx-rtc", 203 .name = "ep93xx-rtc",
128 .owner = THIS_MODULE, 204 .owner = THIS_MODULE,
129 }, 205 },
130 .probe = ep93xx_rtc_probe, 206 .remove = __exit_p(ep93xx_rtc_remove),
131 .remove = __devexit_p(ep93xx_rtc_remove),
132}; 207};
133 208
134static int __init ep93xx_rtc_init(void) 209static int __init ep93xx_rtc_init(void)
135{ 210{
136 return platform_driver_register(&ep93xx_rtc_platform_driver); 211 return platform_driver_probe(&ep93xx_rtc_driver, ep93xx_rtc_probe);
137} 212}
138 213
139static void __exit ep93xx_rtc_exit(void) 214static void __exit ep93xx_rtc_exit(void)
140{ 215{
141 platform_driver_unregister(&ep93xx_rtc_platform_driver); 216 platform_driver_unregister(&ep93xx_rtc_driver);
142} 217}
143 218
144MODULE_AUTHOR("Alessandro Zummo <a.zummo@towertech.it>"); 219MODULE_AUTHOR("Alessandro Zummo <a.zummo@towertech.it>");
diff --git a/drivers/rtc/rtc-pl030.c b/drivers/rtc/rtc-pl030.c
index aaf1f75fa293..457231bb1029 100644
--- a/drivers/rtc/rtc-pl030.c
+++ b/drivers/rtc/rtc-pl030.c
@@ -117,7 +117,7 @@ static int pl030_probe(struct amba_device *dev, struct amba_id *id)
117 goto err_rtc; 117 goto err_rtc;
118 } 118 }
119 119
120 rtc->base = ioremap(dev->res.start, SZ_4K); 120 rtc->base = ioremap(dev->res.start, resource_size(&dev->res));
121 if (!rtc->base) { 121 if (!rtc->base) {
122 ret = -ENOMEM; 122 ret = -ENOMEM;
123 goto err_map; 123 goto err_map;
diff --git a/drivers/rtc/rtc-pl031.c b/drivers/rtc/rtc-pl031.c
index 451fc13784d1..f41873f98f66 100644
--- a/drivers/rtc/rtc-pl031.c
+++ b/drivers/rtc/rtc-pl031.c
@@ -142,8 +142,7 @@ static int pl031_probe(struct amba_device *adev, struct amba_id *id)
142 goto out; 142 goto out;
143 } 143 }
144 144
145 ldata->base = ioremap(adev->res.start, 145 ldata->base = ioremap(adev->res.start, resource_size(&adev->res));
146 adev->res.end - adev->res.start + 1);
147 if (!ldata->base) { 146 if (!ldata->base) {
148 ret = -ENOMEM; 147 ret = -ENOMEM;
149 goto out_no_remap; 148 goto out_no_remap;
diff --git a/drivers/rtc/rtc-rx8025.c b/drivers/rtc/rtc-rx8025.c
new file mode 100644
index 000000000000..b1a29bcfdf13
--- /dev/null
+++ b/drivers/rtc/rtc-rx8025.c
@@ -0,0 +1,688 @@
1/*
2 * Driver for Epson's RTC module RX-8025 SA/NB
3 *
4 * Copyright (C) 2009 Wolfgang Grandegger <wg@grandegger.com>
5 *
6 * Copyright (C) 2005 by Digi International Inc.
7 * All rights reserved.
8 *
9 * Modified by fengjh at rising.com.cn
10 * <http://lists.lm-sensors.org/mailman/listinfo/lm-sensors>
11 * 2006.11
12 *
13 * Code cleanup by Sergei Poselenov, <sposelenov@emcraft.com>
14 * Converted to new style by Wolfgang Grandegger <wg@grandegger.com>
15 * Alarm and periodic interrupt added by Dmitry Rakhchev <rda@emcraft.com>
16 *
17 * This program is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU General Public License
19 * version 2 as published by the Free Software Foundation.
20 */
21#include <linux/kernel.h>
22#include <linux/module.h>
23#include <linux/init.h>
24#include <linux/bcd.h>
25#include <linux/i2c.h>
26#include <linux/list.h>
27#include <linux/rtc.h>
28
29/* Register definitions */
30#define RX8025_REG_SEC 0x00
31#define RX8025_REG_MIN 0x01
32#define RX8025_REG_HOUR 0x02
33#define RX8025_REG_WDAY 0x03
34#define RX8025_REG_MDAY 0x04
35#define RX8025_REG_MONTH 0x05
36#define RX8025_REG_YEAR 0x06
37#define RX8025_REG_DIGOFF 0x07
38#define RX8025_REG_ALWMIN 0x08
39#define RX8025_REG_ALWHOUR 0x09
40#define RX8025_REG_ALWWDAY 0x0a
41#define RX8025_REG_ALDMIN 0x0b
42#define RX8025_REG_ALDHOUR 0x0c
43/* 0x0d is reserved */
44#define RX8025_REG_CTRL1 0x0e
45#define RX8025_REG_CTRL2 0x0f
46
47#define RX8025_BIT_CTRL1_CT (7 << 0)
48/* 1 Hz periodic level irq */
49#define RX8025_BIT_CTRL1_CT_1HZ 4
50#define RX8025_BIT_CTRL1_TEST (1 << 3)
51#define RX8025_BIT_CTRL1_1224 (1 << 5)
52#define RX8025_BIT_CTRL1_DALE (1 << 6)
53#define RX8025_BIT_CTRL1_WALE (1 << 7)
54
55#define RX8025_BIT_CTRL2_DAFG (1 << 0)
56#define RX8025_BIT_CTRL2_WAFG (1 << 1)
57#define RX8025_BIT_CTRL2_CTFG (1 << 2)
58#define RX8025_BIT_CTRL2_PON (1 << 4)
59#define RX8025_BIT_CTRL2_XST (1 << 5)
60#define RX8025_BIT_CTRL2_VDET (1 << 6)
61
62/* Clock precision adjustment */
63#define RX8025_ADJ_RESOLUTION 3050 /* in ppb */
64#define RX8025_ADJ_DATA_MAX 62
65#define RX8025_ADJ_DATA_MIN -62
66
67static const struct i2c_device_id rx8025_id[] = {
68 { "rx8025", 0 },
69 { }
70};
71MODULE_DEVICE_TABLE(i2c, rx8025_id);
72
73struct rx8025_data {
74 struct i2c_client *client;
75 struct rtc_device *rtc;
76 struct work_struct work;
77 u8 ctrl1;
78 unsigned exiting:1;
79};
80
81static int rx8025_read_reg(struct i2c_client *client, int number, u8 *value)
82{
83 int ret = i2c_smbus_read_byte_data(client, (number << 4) | 0x08);
84
85 if (ret < 0) {
86 dev_err(&client->dev, "Unable to read register #%d\n", number);
87 return ret;
88 }
89
90 *value = ret;
91 return 0;
92}
93
94static int rx8025_read_regs(struct i2c_client *client,
95 int number, u8 length, u8 *values)
96{
97 int ret = i2c_smbus_read_i2c_block_data(client, (number << 4) | 0x08,
98 length, values);
99
100 if (ret != length) {
101 dev_err(&client->dev, "Unable to read registers #%d..#%d\n",
102 number, number + length - 1);
103 return ret < 0 ? ret : -EIO;
104 }
105
106 return 0;
107}
108
109static int rx8025_write_reg(struct i2c_client *client, int number, u8 value)
110{
111 int ret = i2c_smbus_write_byte_data(client, number << 4, value);
112
113 if (ret)
114 dev_err(&client->dev, "Unable to write register #%d\n",
115 number);
116
117 return ret;
118}
119
120static int rx8025_write_regs(struct i2c_client *client,
121 int number, u8 length, u8 *values)
122{
123 int ret = i2c_smbus_write_i2c_block_data(client, (number << 4) | 0x08,
124 length, values);
125
126 if (ret)
127 dev_err(&client->dev, "Unable to write registers #%d..#%d\n",
128 number, number + length - 1);
129
130 return ret;
131}
132
133static irqreturn_t rx8025_irq(int irq, void *dev_id)
134{
135 struct i2c_client *client = dev_id;
136 struct rx8025_data *rx8025 = i2c_get_clientdata(client);
137
138 disable_irq_nosync(irq);
139 schedule_work(&rx8025->work);
140 return IRQ_HANDLED;
141}
142
143static void rx8025_work(struct work_struct *work)
144{
145 struct rx8025_data *rx8025 = container_of(work, struct rx8025_data,
146 work);
147 struct i2c_client *client = rx8025->client;
148 struct mutex *lock = &rx8025->rtc->ops_lock;
149 u8 status;
150
151 mutex_lock(lock);
152
153 if (rx8025_read_reg(client, RX8025_REG_CTRL2, &status))
154 goto out;
155
156 if (!(status & RX8025_BIT_CTRL2_XST))
157 dev_warn(&client->dev, "Oscillation stop was detected,"
158 "you may have to readjust the clock\n");
159
160 if (status & RX8025_BIT_CTRL2_CTFG) {
161 /* periodic */
162 status &= ~RX8025_BIT_CTRL2_CTFG;
163 local_irq_disable();
164 rtc_update_irq(rx8025->rtc, 1, RTC_PF | RTC_IRQF);
165 local_irq_enable();
166 }
167
168 if (status & RX8025_BIT_CTRL2_DAFG) {
169 /* alarm */
170 status &= RX8025_BIT_CTRL2_DAFG;
171 if (rx8025_write_reg(client, RX8025_REG_CTRL1,
172 rx8025->ctrl1 & ~RX8025_BIT_CTRL1_DALE))
173 goto out;
174 local_irq_disable();
175 rtc_update_irq(rx8025->rtc, 1, RTC_AF | RTC_IRQF);
176 local_irq_enable();
177 }
178
179 /* acknowledge IRQ */
180 rx8025_write_reg(client, RX8025_REG_CTRL2,
181 status | RX8025_BIT_CTRL2_XST);
182
183out:
184 if (!rx8025->exiting)
185 enable_irq(client->irq);
186
187 mutex_unlock(lock);
188}
189
190static int rx8025_get_time(struct device *dev, struct rtc_time *dt)
191{
192 struct rx8025_data *rx8025 = dev_get_drvdata(dev);
193 u8 date[7];
194 int err;
195
196 err = rx8025_read_regs(rx8025->client, RX8025_REG_SEC, 7, date);
197 if (err)
198 return err;
199
200 dev_dbg(dev, "%s: read 0x%02x 0x%02x "
201 "0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n", __func__,
202 date[0], date[1], date[2], date[3], date[4],
203 date[5], date[6]);
204
205 dt->tm_sec = bcd2bin(date[RX8025_REG_SEC] & 0x7f);
206 dt->tm_min = bcd2bin(date[RX8025_REG_MIN] & 0x7f);
207 if (rx8025->ctrl1 & RX8025_BIT_CTRL1_1224)
208 dt->tm_hour = bcd2bin(date[RX8025_REG_HOUR] & 0x3f);
209 else
210 dt->tm_hour = bcd2bin(date[RX8025_REG_HOUR] & 0x1f) % 12
211 + (date[RX8025_REG_HOUR] & 0x20 ? 12 : 0);
212
213 dt->tm_mday = bcd2bin(date[RX8025_REG_MDAY] & 0x3f);
214 dt->tm_mon = bcd2bin(date[RX8025_REG_MONTH] & 0x1f) - 1;
215 dt->tm_year = bcd2bin(date[RX8025_REG_YEAR]);
216
217 if (dt->tm_year < 70)
218 dt->tm_year += 100;
219
220 dev_dbg(dev, "%s: date %ds %dm %dh %dmd %dm %dy\n", __func__,
221 dt->tm_sec, dt->tm_min, dt->tm_hour,
222 dt->tm_mday, dt->tm_mon, dt->tm_year);
223
224 return rtc_valid_tm(dt);
225}
226
227static int rx8025_set_time(struct device *dev, struct rtc_time *dt)
228{
229 struct rx8025_data *rx8025 = dev_get_drvdata(dev);
230 u8 date[7];
231
232 /*
233 * BUG: The HW assumes every year that is a multiple of 4 to be a leap
234 * year. Next time this is wrong is 2100, which will not be a leap
235 * year.
236 */
237
238 /*
239 * Here the read-only bits are written as "0". I'm not sure if that
240 * is sound.
241 */
242 date[RX8025_REG_SEC] = bin2bcd(dt->tm_sec);
243 date[RX8025_REG_MIN] = bin2bcd(dt->tm_min);
244 if (rx8025->ctrl1 & RX8025_BIT_CTRL1_1224)
245 date[RX8025_REG_HOUR] = bin2bcd(dt->tm_hour);
246 else
247 date[RX8025_REG_HOUR] = (dt->tm_hour >= 12 ? 0x20 : 0)
248 | bin2bcd((dt->tm_hour + 11) % 12 + 1);
249
250 date[RX8025_REG_WDAY] = bin2bcd(dt->tm_wday);
251 date[RX8025_REG_MDAY] = bin2bcd(dt->tm_mday);
252 date[RX8025_REG_MONTH] = bin2bcd(dt->tm_mon + 1);
253 date[RX8025_REG_YEAR] = bin2bcd(dt->tm_year % 100);
254
255 dev_dbg(dev,
256 "%s: write 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
257 __func__,
258 date[0], date[1], date[2], date[3], date[4], date[5], date[6]);
259
260 return rx8025_write_regs(rx8025->client, RX8025_REG_SEC, 7, date);
261}
262
263static int rx8025_init_client(struct i2c_client *client, int *need_reset)
264{
265 struct rx8025_data *rx8025 = i2c_get_clientdata(client);
266 u8 ctrl[2], ctrl2;
267 int need_clear = 0;
268 int err;
269
270 err = rx8025_read_regs(rx8025->client, RX8025_REG_CTRL1, 2, ctrl);
271 if (err)
272 goto out;
273
274 /* Keep test bit zero ! */
275 rx8025->ctrl1 = ctrl[0] & ~RX8025_BIT_CTRL1_TEST;
276
277 if (ctrl[1] & RX8025_BIT_CTRL2_PON) {
278 dev_warn(&client->dev, "power-on reset was detected, "
279 "you may have to readjust the clock\n");
280 *need_reset = 1;
281 }
282
283 if (ctrl[1] & RX8025_BIT_CTRL2_VDET) {
284 dev_warn(&client->dev, "a power voltage drop was detected, "
285 "you may have to readjust the clock\n");
286 *need_reset = 1;
287 }
288
289 if (!(ctrl[1] & RX8025_BIT_CTRL2_XST)) {
290 dev_warn(&client->dev, "Oscillation stop was detected,"
291 "you may have to readjust the clock\n");
292 *need_reset = 1;
293 }
294
295 if (ctrl[1] & (RX8025_BIT_CTRL2_DAFG | RX8025_BIT_CTRL2_WAFG)) {
296 dev_warn(&client->dev, "Alarm was detected\n");
297 need_clear = 1;
298 }
299
300 if (!(ctrl[1] & RX8025_BIT_CTRL2_CTFG))
301 need_clear = 1;
302
303 if (*need_reset || need_clear) {
304 ctrl2 = ctrl[0];
305 ctrl2 &= ~(RX8025_BIT_CTRL2_PON | RX8025_BIT_CTRL2_VDET |
306 RX8025_BIT_CTRL2_CTFG | RX8025_BIT_CTRL2_WAFG |
307 RX8025_BIT_CTRL2_DAFG);
308 ctrl2 |= RX8025_BIT_CTRL2_XST;
309
310 err = rx8025_write_reg(client, RX8025_REG_CTRL2, ctrl2);
311 }
312out:
313 return err;
314}
315
316/* Alarm support */
317static int rx8025_read_alarm(struct device *dev, struct rtc_wkalrm *t)
318{
319 struct rx8025_data *rx8025 = dev_get_drvdata(dev);
320 struct i2c_client *client = rx8025->client;
321 u8 ctrl2, ald[2];
322 int err;
323
324 if (client->irq <= 0)
325 return -EINVAL;
326
327 err = rx8025_read_regs(client, RX8025_REG_ALDMIN, 2, ald);
328 if (err)
329 return err;
330
331 err = rx8025_read_reg(client, RX8025_REG_CTRL2, &ctrl2);
332 if (err)
333 return err;
334
335 dev_dbg(dev, "%s: read alarm 0x%02x 0x%02x ctrl2 %02x\n",
336 __func__, ald[0], ald[1], ctrl2);
337
338 /* Hardware alarms precision is 1 minute! */
339 t->time.tm_sec = 0;
340 t->time.tm_min = bcd2bin(ald[0] & 0x7f);
341 if (rx8025->ctrl1 & RX8025_BIT_CTRL1_1224)
342 t->time.tm_hour = bcd2bin(ald[1] & 0x3f);
343 else
344 t->time.tm_hour = bcd2bin(ald[1] & 0x1f) % 12
345 + (ald[1] & 0x20 ? 12 : 0);
346
347 t->time.tm_wday = -1;
348 t->time.tm_mday = -1;
349 t->time.tm_mon = -1;
350 t->time.tm_year = -1;
351
352 dev_dbg(dev, "%s: date: %ds %dm %dh %dmd %dm %dy\n",
353 __func__,
354 t->time.tm_sec, t->time.tm_min, t->time.tm_hour,
355 t->time.tm_mday, t->time.tm_mon, t->time.tm_year);
356 t->enabled = !!(rx8025->ctrl1 & RX8025_BIT_CTRL1_DALE);
357 t->pending = (ctrl2 & RX8025_BIT_CTRL2_DAFG) && t->enabled;
358
359 return err;
360}
361
362static int rx8025_set_alarm(struct device *dev, struct rtc_wkalrm *t)
363{
364 struct i2c_client *client = to_i2c_client(dev);
365 struct rx8025_data *rx8025 = dev_get_drvdata(dev);
366 u8 ald[2];
367 int err;
368
369 if (client->irq <= 0)
370 return -EINVAL;
371
372 /* Hardware alarm precision is 1 minute! */
373 ald[0] = bin2bcd(t->time.tm_min);
374 if (rx8025->ctrl1 & RX8025_BIT_CTRL1_1224)
375 ald[1] = bin2bcd(t->time.tm_hour);
376 else
377 ald[1] = (t->time.tm_hour >= 12 ? 0x20 : 0)
378 | bin2bcd((t->time.tm_hour + 11) % 12 + 1);
379
380 dev_dbg(dev, "%s: write 0x%02x 0x%02x\n", __func__, ald[0], ald[1]);
381
382 if (rx8025->ctrl1 & RX8025_BIT_CTRL1_DALE) {
383 rx8025->ctrl1 &= ~RX8025_BIT_CTRL1_DALE;
384 err = rx8025_write_reg(rx8025->client, RX8025_REG_CTRL1,
385 rx8025->ctrl1);
386 if (err)
387 return err;
388 }
389 err = rx8025_write_regs(rx8025->client, RX8025_REG_ALDMIN, 2, ald);
390 if (err)
391 return err;
392
393 if (t->enabled) {
394 rx8025->ctrl1 |= RX8025_BIT_CTRL1_DALE;
395 err = rx8025_write_reg(rx8025->client, RX8025_REG_CTRL1,
396 rx8025->ctrl1);
397 if (err)
398 return err;
399 }
400
401 return 0;
402}
403
404static int rx8025_alarm_irq_enable(struct device *dev, unsigned int enabled)
405{
406 struct rx8025_data *rx8025 = dev_get_drvdata(dev);
407 u8 ctrl1;
408 int err;
409
410 ctrl1 = rx8025->ctrl1;
411 if (enabled)
412 ctrl1 |= RX8025_BIT_CTRL1_DALE;
413 else
414 ctrl1 &= ~RX8025_BIT_CTRL1_DALE;
415
416 if (ctrl1 != rx8025->ctrl1) {
417 rx8025->ctrl1 = ctrl1;
418 err = rx8025_write_reg(rx8025->client, RX8025_REG_CTRL1,
419 rx8025->ctrl1);
420 if (err)
421 return err;
422 }
423 return 0;
424}
425
426static int rx8025_irq_set_state(struct device *dev, int enabled)
427{
428 struct i2c_client *client = to_i2c_client(dev);
429 struct rx8025_data *rx8025 = i2c_get_clientdata(client);
430 int ctrl1;
431 int err;
432
433 if (client->irq <= 0)
434 return -ENXIO;
435
436 ctrl1 = rx8025->ctrl1 & ~RX8025_BIT_CTRL1_CT;
437 if (enabled)
438 ctrl1 |= RX8025_BIT_CTRL1_CT_1HZ;
439 if (ctrl1 != rx8025->ctrl1) {
440 rx8025->ctrl1 = ctrl1;
441 err = rx8025_write_reg(rx8025->client, RX8025_REG_CTRL1,
442 rx8025->ctrl1);
443 if (err)
444 return err;
445 }
446
447 return 0;
448}
449
450static struct rtc_class_ops rx8025_rtc_ops = {
451 .read_time = rx8025_get_time,
452 .set_time = rx8025_set_time,
453 .read_alarm = rx8025_read_alarm,
454 .set_alarm = rx8025_set_alarm,
455 .alarm_irq_enable = rx8025_alarm_irq_enable,
456 .irq_set_state = rx8025_irq_set_state,
457};
458
459/*
460 * Clock precision adjustment support
461 *
462 * According to the RX8025 SA/NB application manual the frequency and
463 * temperature charateristics can be approximated using the following
464 * equation:
465 *
466 * df = a * (ut - t)**2
467 *
468 * df: Frequency deviation in any temperature
469 * a : Coefficient = (-35 +-5) * 10**-9
470 * ut: Ultimate temperature in degree = +25 +-5 degree
471 * t : Any temperature in degree
472 *
473 * Note that the clock adjustment in ppb must be entered (which is
474 * the negative value of the deviation).
475 */
476static int rx8025_get_clock_adjust(struct device *dev, int *adj)
477{
478 struct i2c_client *client = to_i2c_client(dev);
479 u8 digoff;
480 int err;
481
482 err = rx8025_read_reg(client, RX8025_REG_DIGOFF, &digoff);
483 if (err)
484 return err;
485
486 *adj = digoff >= 64 ? digoff - 128 : digoff;
487 if (*adj > 0)
488 (*adj)--;
489 *adj *= -RX8025_ADJ_RESOLUTION;
490
491 return 0;
492}
493
494static int rx8025_set_clock_adjust(struct device *dev, int adj)
495{
496 struct i2c_client *client = to_i2c_client(dev);
497 u8 digoff;
498 int err;
499
500 adj /= -RX8025_ADJ_RESOLUTION;
501 if (adj > RX8025_ADJ_DATA_MAX)
502 adj = RX8025_ADJ_DATA_MAX;
503 else if (adj < RX8025_ADJ_DATA_MIN)
504 adj = RX8025_ADJ_DATA_MIN;
505 else if (adj > 0)
506 adj++;
507 else if (adj < 0)
508 adj += 128;
509 digoff = adj;
510
511 err = rx8025_write_reg(client, RX8025_REG_DIGOFF, digoff);
512 if (err)
513 return err;
514
515 dev_dbg(dev, "%s: write 0x%02x\n", __func__, digoff);
516
517 return 0;
518}
519
520static ssize_t rx8025_sysfs_show_clock_adjust(struct device *dev,
521 struct device_attribute *attr,
522 char *buf)
523{
524 int err, adj;
525
526 err = rx8025_get_clock_adjust(dev, &adj);
527 if (err)
528 return err;
529
530 return sprintf(buf, "%d\n", adj);
531}
532
533static ssize_t rx8025_sysfs_store_clock_adjust(struct device *dev,
534 struct device_attribute *attr,
535 const char *buf, size_t count)
536{
537 int adj, err;
538
539 if (sscanf(buf, "%i", &adj) != 1)
540 return -EINVAL;
541
542 err = rx8025_set_clock_adjust(dev, adj);
543
544 return err ? err : count;
545}
546
547static DEVICE_ATTR(clock_adjust_ppb, S_IRUGO | S_IWUSR,
548 rx8025_sysfs_show_clock_adjust,
549 rx8025_sysfs_store_clock_adjust);
550
551static int rx8025_sysfs_register(struct device *dev)
552{
553 return device_create_file(dev, &dev_attr_clock_adjust_ppb);
554}
555
556static void rx8025_sysfs_unregister(struct device *dev)
557{
558 device_remove_file(dev, &dev_attr_clock_adjust_ppb);
559}
560
561static int __devinit rx8025_probe(struct i2c_client *client,
562 const struct i2c_device_id *id)
563{
564 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
565 struct rx8025_data *rx8025;
566 int err, need_reset = 0;
567
568 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA
569 | I2C_FUNC_SMBUS_I2C_BLOCK)) {
570 dev_err(&adapter->dev,
571 "doesn't support required functionality\n");
572 err = -EIO;
573 goto errout;
574 }
575
576 rx8025 = kzalloc(sizeof(*rx8025), GFP_KERNEL);
577 if (!rx8025) {
578 dev_err(&adapter->dev, "failed to alloc memory\n");
579 err = -ENOMEM;
580 goto errout;
581 }
582
583 rx8025->client = client;
584 i2c_set_clientdata(client, rx8025);
585 INIT_WORK(&rx8025->work, rx8025_work);
586
587 err = rx8025_init_client(client, &need_reset);
588 if (err)
589 goto errout_free;
590
591 if (need_reset) {
592 struct rtc_time tm;
593 dev_info(&client->dev,
594 "bad conditions detected, resetting date\n");
595 rtc_time_to_tm(0, &tm); /* 1970/1/1 */
596 rx8025_set_time(&client->dev, &tm);
597 }
598
599 rx8025->rtc = rtc_device_register(client->name, &client->dev,
600 &rx8025_rtc_ops, THIS_MODULE);
601 if (IS_ERR(rx8025->rtc)) {
602 err = PTR_ERR(rx8025->rtc);
603 dev_err(&client->dev, "unable to register the class device\n");
604 goto errout_free;
605 }
606
607 if (client->irq > 0) {
608 dev_info(&client->dev, "IRQ %d supplied\n", client->irq);
609 err = request_irq(client->irq, rx8025_irq,
610 0, "rx8025", client);
611 if (err) {
612 dev_err(&client->dev, "unable to request IRQ\n");
613 goto errout_reg;
614 }
615 }
616
617 rx8025->rtc->irq_freq = 1;
618 rx8025->rtc->max_user_freq = 1;
619
620 err = rx8025_sysfs_register(&client->dev);
621 if (err)
622 goto errout_irq;
623
624 return 0;
625
626errout_irq:
627 if (client->irq > 0)
628 free_irq(client->irq, client);
629
630errout_reg:
631 rtc_device_unregister(rx8025->rtc);
632
633errout_free:
634 i2c_set_clientdata(client, NULL);
635 kfree(rx8025);
636
637errout:
638 dev_err(&adapter->dev, "probing for rx8025 failed\n");
639 return err;
640}
641
642static int __devexit rx8025_remove(struct i2c_client *client)
643{
644 struct rx8025_data *rx8025 = i2c_get_clientdata(client);
645 struct mutex *lock = &rx8025->rtc->ops_lock;
646
647 if (client->irq > 0) {
648 mutex_lock(lock);
649 rx8025->exiting = 1;
650 mutex_unlock(lock);
651
652 free_irq(client->irq, client);
653 flush_scheduled_work();
654 }
655
656 rx8025_sysfs_unregister(&client->dev);
657 rtc_device_unregister(rx8025->rtc);
658 i2c_set_clientdata(client, NULL);
659 kfree(rx8025);
660 return 0;
661}
662
663static struct i2c_driver rx8025_driver = {
664 .driver = {
665 .name = "rtc-rx8025",
666 .owner = THIS_MODULE,
667 },
668 .probe = rx8025_probe,
669 .remove = __devexit_p(rx8025_remove),
670 .id_table = rx8025_id,
671};
672
673static int __init rx8025_init(void)
674{
675 return i2c_add_driver(&rx8025_driver);
676}
677
678static void __exit rx8025_exit(void)
679{
680 i2c_del_driver(&rx8025_driver);
681}
682
683MODULE_AUTHOR("Wolfgang Grandegger <wg@grandegger.com>");
684MODULE_DESCRIPTION("RX-8025 SA/NB RTC driver");
685MODULE_LICENSE("GPL");
686
687module_init(rx8025_init);
688module_exit(rx8025_exit);
diff --git a/drivers/rtc/rtc-test.c b/drivers/rtc/rtc-test.c
index e478280ff628..51725f7755b0 100644
--- a/drivers/rtc/rtc-test.c
+++ b/drivers/rtc/rtc-test.c
@@ -93,7 +93,6 @@ static ssize_t test_irq_store(struct device *dev,
93 struct rtc_device *rtc = platform_get_drvdata(plat_dev); 93 struct rtc_device *rtc = platform_get_drvdata(plat_dev);
94 94
95 retval = count; 95 retval = count;
96 local_irq_disable();
97 if (strncmp(buf, "tick", 4) == 0) 96 if (strncmp(buf, "tick", 4) == 0)
98 rtc_update_irq(rtc, 1, RTC_PF | RTC_IRQF); 97 rtc_update_irq(rtc, 1, RTC_PF | RTC_IRQF);
99 else if (strncmp(buf, "alarm", 5) == 0) 98 else if (strncmp(buf, "alarm", 5) == 0)
@@ -102,7 +101,6 @@ static ssize_t test_irq_store(struct device *dev,
102 rtc_update_irq(rtc, 1, RTC_UF | RTC_IRQF); 101 rtc_update_irq(rtc, 1, RTC_UF | RTC_IRQF);
103 else 102 else
104 retval = -EINVAL; 103 retval = -EINVAL;
105 local_irq_enable();
106 104
107 return retval; 105 return retval;
108} 106}
diff --git a/drivers/rtc/rtc-tx4939.c b/drivers/rtc/rtc-tx4939.c
index 4ee4857ff207..4a6ed1104fbb 100644
--- a/drivers/rtc/rtc-tx4939.c
+++ b/drivers/rtc/rtc-tx4939.c
@@ -261,10 +261,8 @@ static int __init tx4939_rtc_probe(struct platform_device *pdev)
261 261
262 tx4939_rtc_cmd(pdata->rtcreg, TX4939_RTCCTL_COMMAND_NOP); 262 tx4939_rtc_cmd(pdata->rtcreg, TX4939_RTCCTL_COMMAND_NOP);
263 if (devm_request_irq(&pdev->dev, irq, tx4939_rtc_interrupt, 263 if (devm_request_irq(&pdev->dev, irq, tx4939_rtc_interrupt,
264 IRQF_DISABLED | IRQF_SHARED, 264 IRQF_DISABLED, pdev->name, &pdev->dev) < 0)
265 pdev->name, &pdev->dev) < 0) {
266 return -EBUSY; 265 return -EBUSY;
267 }
268 rtc = rtc_device_register(pdev->name, &pdev->dev, 266 rtc = rtc_device_register(pdev->name, &pdev->dev,
269 &tx4939_rtc_ops, THIS_MODULE); 267 &tx4939_rtc_ops, THIS_MODULE);
270 if (IS_ERR(rtc)) 268 if (IS_ERR(rtc))