aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/rtc/rtc-ds1307.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/rtc/rtc-ds1307.c')
-rw-r--r--drivers/rtc/rtc-ds1307.c46
1 files changed, 33 insertions, 13 deletions
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