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.c41
1 files changed, 33 insertions, 8 deletions
diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
index 2c4a65302a9d..8a6f9a9f9cb8 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 { }
@@ -291,7 +300,7 @@ static int ds1307_get_time(struct device *dev, struct rtc_time *t)
291 300
292 /* read the RTC date and time registers all at once */ 301 /* read the RTC date and time registers all at once */
293 tmp = ds1307->read_block_data(ds1307->client, 302 tmp = ds1307->read_block_data(ds1307->client,
294 DS1307_REG_SECS, 7, ds1307->regs); 303 ds1307->offset, 7, ds1307->regs);
295 if (tmp != 7) { 304 if (tmp != 7) {
296 dev_err(dev, "%s error %d\n", "read", tmp); 305 dev_err(dev, "%s error %d\n", "read", tmp);
297 return -EIO; 306 return -EIO;
@@ -353,6 +362,7 @@ static int ds1307_set_time(struct device *dev, struct rtc_time *t)
353 switch (ds1307->type) { 362 switch (ds1307->type) {
354 case ds_1337: 363 case ds_1337:
355 case ds_1339: 364 case ds_1339:
365 case ds_3231:
356 buf[DS1307_REG_MONTH] |= DS1337_BIT_CENTURY; 366 buf[DS1307_REG_MONTH] |= DS1337_BIT_CENTURY;
357 break; 367 break;
358 case ds_1340: 368 case ds_1340:
@@ -367,7 +377,8 @@ static int ds1307_set_time(struct device *dev, struct rtc_time *t)
367 "write", buf[0], buf[1], buf[2], buf[3], 377 "write", buf[0], buf[1], buf[2], buf[3],
368 buf[4], buf[5], buf[6]); 378 buf[4], buf[5], buf[6]);
369 379
370 result = ds1307->write_block_data(ds1307->client, 0, 7, buf); 380 result = ds1307->write_block_data(ds1307->client,
381 ds1307->offset, 7, buf);
371 if (result < 0) { 382 if (result < 0) {
372 dev_err(dev, "%s error %d\n", "write", result); 383 dev_err(dev, "%s error %d\n", "write", result);
373 return result; 384 return result;
@@ -624,6 +635,11 @@ static int __devinit ds1307_probe(struct i2c_client *client,
624 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); 635 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
625 int want_irq = false; 636 int want_irq = false;
626 unsigned char *buf; 637 unsigned char *buf;
638 static const int bbsqi_bitpos[] = {
639 [ds_1337] = 0,
640 [ds_1339] = DS1339_BIT_BBSQI,
641 [ds_3231] = DS3231_BIT_BBSQW,
642 };
627 643
628 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA) 644 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)
629 && !i2c_check_functionality(adapter, I2C_FUNC_SMBUS_I2C_BLOCK)) 645 && !i2c_check_functionality(adapter, I2C_FUNC_SMBUS_I2C_BLOCK))
@@ -632,9 +648,12 @@ static int __devinit ds1307_probe(struct i2c_client *client,
632 if (!(ds1307 = kzalloc(sizeof(struct ds1307), GFP_KERNEL))) 648 if (!(ds1307 = kzalloc(sizeof(struct ds1307), GFP_KERNEL)))
633 return -ENOMEM; 649 return -ENOMEM;
634 650
635 ds1307->client = client;
636 i2c_set_clientdata(client, ds1307); 651 i2c_set_clientdata(client, ds1307);
637 ds1307->type = id->driver_data; 652
653 ds1307->client = client;
654 ds1307->type = id->driver_data;
655 ds1307->offset = 0;
656
638 buf = ds1307->regs; 657 buf = ds1307->regs;
639 if (i2c_check_functionality(adapter, I2C_FUNC_SMBUS_I2C_BLOCK)) { 658 if (i2c_check_functionality(adapter, I2C_FUNC_SMBUS_I2C_BLOCK)) {
640 ds1307->read_block_data = i2c_smbus_read_i2c_block_data; 659 ds1307->read_block_data = i2c_smbus_read_i2c_block_data;
@@ -647,6 +666,7 @@ static int __devinit ds1307_probe(struct i2c_client *client,
647 switch (ds1307->type) { 666 switch (ds1307->type) {
648 case ds_1337: 667 case ds_1337:
649 case ds_1339: 668 case ds_1339:
669 case ds_3231:
650 /* has IRQ? */ 670 /* has IRQ? */
651 if (ds1307->client->irq > 0 && chip->alarm) { 671 if (ds1307->client->irq > 0 && chip->alarm) {
652 INIT_WORK(&ds1307->work, ds1307_work); 672 INIT_WORK(&ds1307->work, ds1307_work);
@@ -666,12 +686,12 @@ static int __devinit ds1307_probe(struct i2c_client *client,
666 ds1307->regs[0] &= ~DS1337_BIT_nEOSC; 686 ds1307->regs[0] &= ~DS1337_BIT_nEOSC;
667 687
668 /* Using IRQ? Disable the square wave and both alarms. 688 /* Using IRQ? Disable the square wave and both alarms.
669 * For ds1339, be sure alarms can trigger when we're 689 * For some variants, be sure alarms can trigger when we're
670 * running on Vbackup (BBSQI); we assume ds1337 will 690 * running on Vbackup (BBSQI/BBSQW)
671 * ignore that bit
672 */ 691 */
673 if (want_irq) { 692 if (want_irq) {
674 ds1307->regs[0] |= DS1337_BIT_INTCN | DS1339_BIT_BBSQI; 693 ds1307->regs[0] |= DS1337_BIT_INTCN
694 | bbsqi_bitpos[ds1307->type];
675 ds1307->regs[0] &= ~(DS1337_BIT_A2IE | DS1337_BIT_A1IE); 695 ds1307->regs[0] &= ~(DS1337_BIT_A2IE | DS1337_BIT_A1IE);
676 } 696 }
677 697
@@ -751,6 +771,9 @@ static int __devinit ds1307_probe(struct i2c_client *client,
751 hour); 771 hour);
752 } 772 }
753 break; 773 break;
774 case ds_1388:
775 ds1307->offset = 1; /* Seconds starts at 1 */
776 break;
754 default: 777 default:
755 break; 778 break;
756 } 779 }
@@ -814,6 +837,8 @@ read_rtc:
814 case rx_8025: 837 case rx_8025:
815 case ds_1337: 838 case ds_1337:
816 case ds_1339: 839 case ds_1339:
840 case ds_1388:
841 case ds_3231:
817 break; 842 break;
818 } 843 }
819 844