diff options
Diffstat (limited to 'drivers/rtc')
-rw-r--r-- | drivers/rtc/Kconfig | 50 | ||||
-rw-r--r-- | drivers/rtc/Makefile | 5 | ||||
-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-generic.c | 84 | ||||
-rw-r--r-- | drivers/rtc/rtc-lib.c | 7 | ||||
-rw-r--r-- | drivers/rtc/rtc-m41t80.c | 18 | ||||
-rw-r--r-- | drivers/rtc/rtc-mv.c | 11 | ||||
-rw-r--r-- | drivers/rtc/rtc-parisc.c | 112 | ||||
-rw-r--r-- | drivers/rtc/rtc-ppc.c | 69 | ||||
-rw-r--r-- | drivers/rtc/rtc-proc.c | 10 | ||||
-rw-r--r-- | drivers/rtc/rtc-ps3.c | 104 | ||||
-rw-r--r-- | drivers/rtc/rtc-sa1100.c | 3 | ||||
-rw-r--r-- | drivers/rtc/rtc-v3020.c | 230 | ||||
-rw-r--r-- | drivers/rtc/rtc-wm8350.c | 43 |
16 files changed, 877 insertions, 299 deletions
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig index 81450fbd8b12..ffe34a12f446 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 |
@@ -224,11 +225,11 @@ config RTC_DRV_PCF8583 | |||
224 | will be called rtc-pcf8583. | 225 | will be called rtc-pcf8583. |
225 | 226 | ||
226 | config RTC_DRV_M41T80 | 227 | config RTC_DRV_M41T80 |
227 | tristate "ST M41T65/M41T80/81/82/83/84/85/87" | 228 | tristate "ST M41T62/65/M41T80/81/82/83/84/85/87" |
228 | help | 229 | help |
229 | If you say Y here you will get support for the ST M41T60 | 230 | If you say Y here you will get support for the ST M41T60 |
230 | and M41T80 RTC chips series. Currently, the following chips are | 231 | and M41T80 RTC chips series. Currently, the following chips are |
231 | supported: M41T65, M41T80, M41T81, M41T82, M41T83, M41ST84, | 232 | supported: M41T62, M41T65, M41T80, M41T81, M41T82, M41T83, M41ST84, |
232 | M41ST85, and M41ST87. | 233 | M41ST85, and M41ST87. |
233 | 234 | ||
234 | This driver can also be built as a module. If so, the module | 235 | This driver can also be built as a module. If so, the module |
@@ -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 |
@@ -677,22 +688,16 @@ config RTC_DRV_RS5C313 | |||
677 | help | 688 | help |
678 | If you say yes here you get support for the Ricoh RS5C313 RTC chips. | 689 | If you say yes here you get support for the Ricoh RS5C313 RTC chips. |
679 | 690 | ||
680 | config RTC_DRV_PARISC | 691 | config RTC_DRV_GENERIC |
681 | tristate "PA-RISC firmware RTC support" | 692 | tristate "Generic RTC support" |
682 | depends on PARISC | 693 | # Please consider writing a new RTC driver instead of using the generic |
694 | # RTC abstraction | ||
695 | depends on PARISC || M68K || PPC | ||
683 | help | 696 | help |
684 | Say Y or M here to enable RTC support on PA-RISC systems using | 697 | Say Y or M here to enable RTC support on systems using the generic |
685 | firmware calls. If you do not know what you are doing, you should | 698 | RTC abstraction. If you do not know what you are doing, you should |
686 | just say Y. | 699 | just say Y. |
687 | 700 | ||
688 | config RTC_DRV_PPC | ||
689 | tristate "PowerPC machine dependent RTC support" | ||
690 | depends on PPC | ||
691 | help | ||
692 | The PowerPC kernel has machine-specific functions for accessing | ||
693 | the RTC. This exposes that functionality through the generic RTC | ||
694 | class. | ||
695 | |||
696 | config RTC_DRV_PXA | 701 | config RTC_DRV_PXA |
697 | tristate "PXA27x/PXA3xx" | 702 | tristate "PXA27x/PXA3xx" |
698 | depends on ARCH_PXA | 703 | depends on ARCH_PXA |
@@ -736,4 +741,13 @@ config RTC_DRV_MV | |||
736 | This driver can also be built as a module. If so, the module | 741 | This driver can also be built as a module. If so, the module |
737 | will be called rtc-mv. | 742 | will be called rtc-mv. |
738 | 743 | ||
744 | config RTC_DRV_PS3 | ||
745 | tristate "PS3 RTC" | ||
746 | depends on PPC_PS3 | ||
747 | help | ||
748 | If you say yes here you will get support for the RTC on PS3. | ||
749 | |||
750 | This driver can also be built as a module. If so, the module | ||
751 | will be called rtc-ps3. | ||
752 | |||
739 | endif # RTC_CLASS | 753 | endif # RTC_CLASS |
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile index 0e697aa51caa..6c0639a14f09 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 |
@@ -55,8 +56,7 @@ obj-$(CONFIG_RTC_DRV_PCF8563) += rtc-pcf8563.o | |||
55 | obj-$(CONFIG_RTC_DRV_PCF8583) += rtc-pcf8583.o | 56 | obj-$(CONFIG_RTC_DRV_PCF8583) += rtc-pcf8583.o |
56 | obj-$(CONFIG_RTC_DRV_PL030) += rtc-pl030.o | 57 | obj-$(CONFIG_RTC_DRV_PL030) += rtc-pl030.o |
57 | obj-$(CONFIG_RTC_DRV_PL031) += rtc-pl031.o | 58 | obj-$(CONFIG_RTC_DRV_PL031) += rtc-pl031.o |
58 | obj-$(CONFIG_RTC_DRV_PARISC) += rtc-parisc.o | 59 | obj-$(CONFIG_RTC_DRV_GENERIC) += rtc-generic.o |
59 | obj-$(CONFIG_RTC_DRV_PPC) += rtc-ppc.o | ||
60 | obj-$(CONFIG_RTC_DRV_PXA) += rtc-pxa.o | 60 | obj-$(CONFIG_RTC_DRV_PXA) += rtc-pxa.o |
61 | obj-$(CONFIG_RTC_DRV_R9701) += rtc-r9701.o | 61 | obj-$(CONFIG_RTC_DRV_R9701) += rtc-r9701.o |
62 | obj-$(CONFIG_RTC_DRV_RS5C313) += rtc-rs5c313.o | 62 | obj-$(CONFIG_RTC_DRV_RS5C313) += rtc-rs5c313.o |
@@ -76,3 +76,4 @@ obj-$(CONFIG_RTC_DRV_VR41XX) += rtc-vr41xx.o | |||
76 | obj-$(CONFIG_RTC_DRV_WM8350) += rtc-wm8350.o | 76 | obj-$(CONFIG_RTC_DRV_WM8350) += rtc-wm8350.o |
77 | obj-$(CONFIG_RTC_DRV_X1205) += rtc-x1205.o | 77 | obj-$(CONFIG_RTC_DRV_X1205) += rtc-x1205.o |
78 | obj-$(CONFIG_RTC_DRV_PCF50633) += rtc-pcf50633.o | 78 | obj-$(CONFIG_RTC_DRV_PCF50633) += rtc-pcf50633.o |
79 | obj-$(CONFIG_RTC_DRV_PS3) += rtc-ps3.o | ||
diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c index 7e5155e88ac7..2c4a65302a9d 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 a5b0fc09f0c6..4d32e328f6cd 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 000000000000..550292304b0f --- /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-generic.c b/drivers/rtc/rtc-generic.c new file mode 100644 index 000000000000..98322004ad2e --- /dev/null +++ b/drivers/rtc/rtc-generic.c | |||
@@ -0,0 +1,84 @@ | |||
1 | /* rtc-generic: RTC driver using the generic RTC abstraction | ||
2 | * | ||
3 | * Copyright (C) 2008 Kyle McMartin <kyle@mcmartin.ca> | ||
4 | */ | ||
5 | |||
6 | #include <linux/kernel.h> | ||
7 | #include <linux/module.h> | ||
8 | #include <linux/time.h> | ||
9 | #include <linux/platform_device.h> | ||
10 | #include <linux/rtc.h> | ||
11 | |||
12 | #include <asm/rtc.h> | ||
13 | |||
14 | static int generic_get_time(struct device *dev, struct rtc_time *tm) | ||
15 | { | ||
16 | unsigned int ret = get_rtc_time(tm); | ||
17 | |||
18 | if (ret & RTC_BATT_BAD) | ||
19 | return -EOPNOTSUPP; | ||
20 | |||
21 | return rtc_valid_tm(tm); | ||
22 | } | ||
23 | |||
24 | static int generic_set_time(struct device *dev, struct rtc_time *tm) | ||
25 | { | ||
26 | if (set_rtc_time(tm) < 0) | ||
27 | return -EOPNOTSUPP; | ||
28 | |||
29 | return 0; | ||
30 | } | ||
31 | |||
32 | static const struct rtc_class_ops generic_rtc_ops = { | ||
33 | .read_time = generic_get_time, | ||
34 | .set_time = generic_set_time, | ||
35 | }; | ||
36 | |||
37 | static int __init generic_rtc_probe(struct platform_device *dev) | ||
38 | { | ||
39 | struct rtc_device *rtc; | ||
40 | |||
41 | rtc = rtc_device_register("rtc-generic", &dev->dev, &generic_rtc_ops, | ||
42 | THIS_MODULE); | ||
43 | if (IS_ERR(rtc)) | ||
44 | return PTR_ERR(rtc); | ||
45 | |||
46 | platform_set_drvdata(dev, rtc); | ||
47 | |||
48 | return 0; | ||
49 | } | ||
50 | |||
51 | static int __exit generic_rtc_remove(struct platform_device *dev) | ||
52 | { | ||
53 | struct rtc_device *rtc = platform_get_drvdata(dev); | ||
54 | |||
55 | rtc_device_unregister(rtc); | ||
56 | |||
57 | return 0; | ||
58 | } | ||
59 | |||
60 | static struct platform_driver generic_rtc_driver = { | ||
61 | .driver = { | ||
62 | .name = "rtc-generic", | ||
63 | .owner = THIS_MODULE, | ||
64 | }, | ||
65 | .remove = __exit_p(generic_rtc_remove), | ||
66 | }; | ||
67 | |||
68 | static int __init generic_rtc_init(void) | ||
69 | { | ||
70 | return platform_driver_probe(&generic_rtc_driver, generic_rtc_probe); | ||
71 | } | ||
72 | |||
73 | static void __exit generic_rtc_fini(void) | ||
74 | { | ||
75 | platform_driver_unregister(&generic_rtc_driver); | ||
76 | } | ||
77 | |||
78 | module_init(generic_rtc_init); | ||
79 | module_exit(generic_rtc_fini); | ||
80 | |||
81 | MODULE_AUTHOR("Kyle McMartin <kyle@mcmartin.ca>"); | ||
82 | MODULE_LICENSE("GPL"); | ||
83 | MODULE_DESCRIPTION("Generic RTC driver"); | ||
84 | MODULE_ALIAS("platform:rtc-generic"); | ||
diff --git a/drivers/rtc/rtc-lib.c b/drivers/rtc/rtc-lib.c index dd70bf73ce9d..773851f338b8 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-m41t80.c b/drivers/rtc/rtc-m41t80.c index 893f7dece239..60fe266f0f49 100644 --- a/drivers/rtc/rtc-m41t80.c +++ b/drivers/rtc/rtc-m41t80.c | |||
@@ -64,10 +64,12 @@ | |||
64 | #define M41T80_FEATURE_BL (1 << 1) /* Battery low indicator */ | 64 | #define M41T80_FEATURE_BL (1 << 1) /* Battery low indicator */ |
65 | #define M41T80_FEATURE_SQ (1 << 2) /* Squarewave feature */ | 65 | #define M41T80_FEATURE_SQ (1 << 2) /* Squarewave feature */ |
66 | #define M41T80_FEATURE_WD (1 << 3) /* Extra watchdog resolution */ | 66 | #define M41T80_FEATURE_WD (1 << 3) /* Extra watchdog resolution */ |
67 | #define M41T80_FEATURE_SQ_ALT (1 << 4) /* RSx bits are in reg 4 */ | ||
67 | 68 | ||
68 | #define DRV_VERSION "0.05" | 69 | #define DRV_VERSION "0.05" |
69 | 70 | ||
70 | static const struct i2c_device_id m41t80_id[] = { | 71 | static const struct i2c_device_id m41t80_id[] = { |
72 | { "m41t62", M41T80_FEATURE_SQ | M41T80_FEATURE_SQ_ALT }, | ||
71 | { "m41t65", M41T80_FEATURE_HT | M41T80_FEATURE_WD }, | 73 | { "m41t65", M41T80_FEATURE_HT | M41T80_FEATURE_WD }, |
72 | { "m41t80", M41T80_FEATURE_SQ }, | 74 | { "m41t80", M41T80_FEATURE_SQ }, |
73 | { "m41t81", M41T80_FEATURE_HT | M41T80_FEATURE_SQ}, | 75 | { "m41t81", M41T80_FEATURE_HT | M41T80_FEATURE_SQ}, |
@@ -393,12 +395,15 @@ static ssize_t m41t80_sysfs_show_sqwfreq(struct device *dev, | |||
393 | { | 395 | { |
394 | struct i2c_client *client = to_i2c_client(dev); | 396 | struct i2c_client *client = to_i2c_client(dev); |
395 | struct m41t80_data *clientdata = i2c_get_clientdata(client); | 397 | struct m41t80_data *clientdata = i2c_get_clientdata(client); |
396 | int val; | 398 | int val, reg_sqw; |
397 | 399 | ||
398 | if (!(clientdata->features & M41T80_FEATURE_SQ)) | 400 | if (!(clientdata->features & M41T80_FEATURE_SQ)) |
399 | return -EINVAL; | 401 | return -EINVAL; |
400 | 402 | ||
401 | val = i2c_smbus_read_byte_data(client, M41T80_REG_SQW); | 403 | reg_sqw = M41T80_REG_SQW; |
404 | if (clientdata->features & M41T80_FEATURE_SQ_ALT) | ||
405 | reg_sqw = M41T80_REG_WDAY; | ||
406 | val = i2c_smbus_read_byte_data(client, reg_sqw); | ||
402 | if (val < 0) | 407 | if (val < 0) |
403 | return -EIO; | 408 | return -EIO; |
404 | val = (val >> 4) & 0xf; | 409 | val = (val >> 4) & 0xf; |
@@ -419,7 +424,7 @@ static ssize_t m41t80_sysfs_set_sqwfreq(struct device *dev, | |||
419 | { | 424 | { |
420 | struct i2c_client *client = to_i2c_client(dev); | 425 | struct i2c_client *client = to_i2c_client(dev); |
421 | struct m41t80_data *clientdata = i2c_get_clientdata(client); | 426 | struct m41t80_data *clientdata = i2c_get_clientdata(client); |
422 | int almon, sqw; | 427 | int almon, sqw, reg_sqw; |
423 | int val = simple_strtoul(buf, NULL, 0); | 428 | int val = simple_strtoul(buf, NULL, 0); |
424 | 429 | ||
425 | if (!(clientdata->features & M41T80_FEATURE_SQ)) | 430 | if (!(clientdata->features & M41T80_FEATURE_SQ)) |
@@ -440,13 +445,16 @@ static ssize_t m41t80_sysfs_set_sqwfreq(struct device *dev, | |||
440 | almon = i2c_smbus_read_byte_data(client, M41T80_REG_ALARM_MON); | 445 | almon = i2c_smbus_read_byte_data(client, M41T80_REG_ALARM_MON); |
441 | if (almon < 0) | 446 | if (almon < 0) |
442 | return -EIO; | 447 | return -EIO; |
443 | sqw = i2c_smbus_read_byte_data(client, M41T80_REG_SQW); | 448 | reg_sqw = M41T80_REG_SQW; |
449 | if (clientdata->features & M41T80_FEATURE_SQ_ALT) | ||
450 | reg_sqw = M41T80_REG_WDAY; | ||
451 | sqw = i2c_smbus_read_byte_data(client, reg_sqw); | ||
444 | if (sqw < 0) | 452 | if (sqw < 0) |
445 | return -EIO; | 453 | return -EIO; |
446 | sqw = (sqw & 0x0f) | (val << 4); | 454 | sqw = (sqw & 0x0f) | (val << 4); |
447 | if (i2c_smbus_write_byte_data(client, M41T80_REG_ALARM_MON, | 455 | if (i2c_smbus_write_byte_data(client, M41T80_REG_ALARM_MON, |
448 | almon & ~M41T80_ALMON_SQWE) < 0 || | 456 | almon & ~M41T80_ALMON_SQWE) < 0 || |
449 | i2c_smbus_write_byte_data(client, M41T80_REG_SQW, sqw) < 0) | 457 | i2c_smbus_write_byte_data(client, reg_sqw, sqw) < 0) |
450 | return -EIO; | 458 | return -EIO; |
451 | if (val && i2c_smbus_write_byte_data(client, M41T80_REG_ALARM_MON, | 459 | if (val && i2c_smbus_write_byte_data(client, M41T80_REG_ALARM_MON, |
452 | almon | M41T80_ALMON_SQWE) < 0) | 460 | almon | M41T80_ALMON_SQWE) < 0) |
diff --git a/drivers/rtc/rtc-mv.c b/drivers/rtc/rtc-mv.c index 45f12dcd3716..e0263d2005ee 100644 --- a/drivers/rtc/rtc-mv.c +++ b/drivers/rtc/rtc-mv.c | |||
@@ -12,6 +12,7 @@ | |||
12 | #include <linux/bcd.h> | 12 | #include <linux/bcd.h> |
13 | #include <linux/io.h> | 13 | #include <linux/io.h> |
14 | #include <linux/platform_device.h> | 14 | #include <linux/platform_device.h> |
15 | #include <linux/delay.h> | ||
15 | 16 | ||
16 | 17 | ||
17 | #define RTC_TIME_REG_OFFS 0 | 18 | #define RTC_TIME_REG_OFFS 0 |
@@ -119,6 +120,16 @@ static int __init mv_rtc_probe(struct platform_device *pdev) | |||
119 | return -EINVAL; | 120 | return -EINVAL; |
120 | } | 121 | } |
121 | 122 | ||
123 | /* make sure it is actually functional */ | ||
124 | if (rtc_time == 0x01000000) { | ||
125 | ssleep(1); | ||
126 | rtc_time = readl(pdata->ioaddr + RTC_TIME_REG_OFFS); | ||
127 | if (rtc_time == 0x01000000) { | ||
128 | dev_err(&pdev->dev, "internal RTC not ticking\n"); | ||
129 | return -ENODEV; | ||
130 | } | ||
131 | } | ||
132 | |||
122 | platform_set_drvdata(pdev, pdata); | 133 | platform_set_drvdata(pdev, pdata); |
123 | pdata->rtc = rtc_device_register(pdev->name, &pdev->dev, | 134 | pdata->rtc = rtc_device_register(pdev->name, &pdev->dev, |
124 | &mv_rtc_ops, THIS_MODULE); | 135 | &mv_rtc_ops, THIS_MODULE); |
diff --git a/drivers/rtc/rtc-parisc.c b/drivers/rtc/rtc-parisc.c deleted file mode 100644 index c6bfa6fe1a2a..000000000000 --- a/drivers/rtc/rtc-parisc.c +++ /dev/null | |||
@@ -1,112 +0,0 @@ | |||
1 | /* rtc-parisc: RTC for HP PA-RISC firmware | ||
2 | * | ||
3 | * Copyright (C) 2008 Kyle McMartin <kyle@mcmartin.ca> | ||
4 | */ | ||
5 | |||
6 | #include <linux/kernel.h> | ||
7 | #include <linux/module.h> | ||
8 | #include <linux/time.h> | ||
9 | #include <linux/platform_device.h> | ||
10 | |||
11 | #include <asm/rtc.h> | ||
12 | |||
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) | ||
20 | { | ||
21 | struct parisc_rtc *p = dev_get_drvdata(dev); | ||
22 | unsigned long flags, ret; | ||
23 | |||
24 | spin_lock_irqsave(&p->lock, flags); | ||
25 | ret = get_rtc_time(tm); | ||
26 | spin_unlock_irqrestore(&p->lock, flags); | ||
27 | |||
28 | if (ret & RTC_BATT_BAD) | ||
29 | return -EOPNOTSUPP; | ||
30 | |||
31 | return 0; | ||
32 | } | ||
33 | |||
34 | static int parisc_set_time(struct device *dev, struct rtc_time *tm) | ||
35 | { | ||
36 | struct parisc_rtc *p = dev_get_drvdata(dev); | ||
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; | ||
46 | |||
47 | return 0; | ||
48 | } | ||
49 | |||
50 | static const struct rtc_class_ops parisc_rtc_ops = { | ||
51 | .read_time = parisc_get_time, | ||
52 | .set_time = parisc_set_time, | ||
53 | }; | ||
54 | |||
55 | static int __devinit parisc_rtc_probe(struct platform_device *dev) | ||
56 | { | ||
57 | struct parisc_rtc *p; | ||
58 | |||
59 | p = kzalloc(sizeof (*p), GFP_KERNEL); | ||
60 | if (!p) | ||
61 | return -ENOMEM; | ||
62 | |||
63 | spin_lock_init(&p->lock); | ||
64 | |||
65 | p->rtc = rtc_device_register("rtc-parisc", &dev->dev, &parisc_rtc_ops, | ||
66 | THIS_MODULE); | ||
67 | if (IS_ERR(p->rtc)) { | ||
68 | int err = PTR_ERR(p->rtc); | ||
69 | kfree(p); | ||
70 | return err; | ||
71 | } | ||
72 | |||
73 | platform_set_drvdata(dev, p); | ||
74 | |||
75 | return 0; | ||
76 | } | ||
77 | |||
78 | static int __devexit parisc_rtc_remove(struct platform_device *dev) | ||
79 | { | ||
80 | struct parisc_rtc *p = platform_get_drvdata(dev); | ||
81 | |||
82 | rtc_device_unregister(p->rtc); | ||
83 | kfree(p); | ||
84 | |||
85 | return 0; | ||
86 | } | ||
87 | |||
88 | static struct platform_driver parisc_rtc_driver = { | ||
89 | .driver = { | ||
90 | .name = "rtc-parisc", | ||
91 | .owner = THIS_MODULE, | ||
92 | }, | ||
93 | .probe = parisc_rtc_probe, | ||
94 | .remove = __devexit_p(parisc_rtc_remove), | ||
95 | }; | ||
96 | |||
97 | static int __init parisc_rtc_init(void) | ||
98 | { | ||
99 | return platform_driver_register(&parisc_rtc_driver); | ||
100 | } | ||
101 | |||
102 | static void __exit parisc_rtc_fini(void) | ||
103 | { | ||
104 | platform_driver_unregister(&parisc_rtc_driver); | ||
105 | } | ||
106 | |||
107 | module_init(parisc_rtc_init); | ||
108 | module_exit(parisc_rtc_fini); | ||
109 | |||
110 | MODULE_AUTHOR("Kyle McMartin <kyle@mcmartin.ca>"); | ||
111 | MODULE_LICENSE("GPL"); | ||
112 | MODULE_DESCRIPTION("HP PA-RISC RTC driver"); | ||
diff --git a/drivers/rtc/rtc-ppc.c b/drivers/rtc/rtc-ppc.c deleted file mode 100644 index c8e97e25ef7e..000000000000 --- a/drivers/rtc/rtc-ppc.c +++ /dev/null | |||
@@ -1,69 +0,0 @@ | |||
1 | /* | ||
2 | * RTC driver for ppc_md RTC functions | ||
3 | * | ||
4 | * © 2007 Red Hat, Inc. | ||
5 | * | ||
6 | * Author: David Woodhouse <dwmw2@infradead.org> | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify | ||
9 | * it under the terms of the GNU General Public License version 2 as | ||
10 | * published by the Free Software Foundation. | ||
11 | */ | ||
12 | |||
13 | |||
14 | #include <linux/module.h> | ||
15 | #include <linux/err.h> | ||
16 | #include <linux/rtc.h> | ||
17 | #include <linux/platform_device.h> | ||
18 | #include <asm/machdep.h> | ||
19 | |||
20 | static int ppc_rtc_read_time(struct device *dev, struct rtc_time *tm) | ||
21 | { | ||
22 | ppc_md.get_rtc_time(tm); | ||
23 | return 0; | ||
24 | } | ||
25 | |||
26 | static int ppc_rtc_set_time(struct device *dev, struct rtc_time *tm) | ||
27 | { | ||
28 | return ppc_md.set_rtc_time(tm); | ||
29 | } | ||
30 | |||
31 | static const struct rtc_class_ops ppc_rtc_ops = { | ||
32 | .set_time = ppc_rtc_set_time, | ||
33 | .read_time = ppc_rtc_read_time, | ||
34 | }; | ||
35 | |||
36 | static struct rtc_device *rtc; | ||
37 | static struct platform_device *ppc_rtc_pdev; | ||
38 | |||
39 | static int __init ppc_rtc_init(void) | ||
40 | { | ||
41 | if (!ppc_md.get_rtc_time || !ppc_md.set_rtc_time) | ||
42 | return -ENODEV; | ||
43 | |||
44 | ppc_rtc_pdev = platform_device_register_simple("ppc-rtc", 0, NULL, 0); | ||
45 | if (IS_ERR(ppc_rtc_pdev)) | ||
46 | return PTR_ERR(ppc_rtc_pdev); | ||
47 | |||
48 | rtc = rtc_device_register("ppc_md", &ppc_rtc_pdev->dev, | ||
49 | &ppc_rtc_ops, THIS_MODULE); | ||
50 | if (IS_ERR(rtc)) { | ||
51 | platform_device_unregister(ppc_rtc_pdev); | ||
52 | return PTR_ERR(rtc); | ||
53 | } | ||
54 | |||
55 | return 0; | ||
56 | } | ||
57 | |||
58 | static void __exit ppc_rtc_exit(void) | ||
59 | { | ||
60 | rtc_device_unregister(rtc); | ||
61 | platform_device_unregister(ppc_rtc_pdev); | ||
62 | } | ||
63 | |||
64 | module_init(ppc_rtc_init); | ||
65 | module_exit(ppc_rtc_exit); | ||
66 | |||
67 | MODULE_LICENSE("GPL"); | ||
68 | MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>"); | ||
69 | MODULE_DESCRIPTION("Generic RTC class driver for PowerPC"); | ||
diff --git a/drivers/rtc/rtc-proc.c b/drivers/rtc/rtc-proc.c index 0c6257a034ff..c086fc30a84c 100644 --- a/drivers/rtc/rtc-proc.c +++ b/drivers/rtc/rtc-proc.c | |||
@@ -105,14 +105,8 @@ static const struct file_operations rtc_proc_fops = { | |||
105 | 105 | ||
106 | void rtc_proc_add_device(struct rtc_device *rtc) | 106 | void rtc_proc_add_device(struct rtc_device *rtc) |
107 | { | 107 | { |
108 | if (rtc->id == 0) { | 108 | if (rtc->id == 0) |
109 | struct proc_dir_entry *ent; | 109 | proc_create_data("driver/rtc", 0, NULL, &rtc_proc_fops, rtc); |
110 | |||
111 | ent = proc_create_data("driver/rtc", 0, NULL, | ||
112 | &rtc_proc_fops, rtc); | ||
113 | if (ent) | ||
114 | ent->owner = rtc->owner; | ||
115 | } | ||
116 | } | 110 | } |
117 | 111 | ||
118 | void rtc_proc_del_device(struct rtc_device *rtc) | 112 | void rtc_proc_del_device(struct rtc_device *rtc) |
diff --git a/drivers/rtc/rtc-ps3.c b/drivers/rtc/rtc-ps3.c new file mode 100644 index 000000000000..968133ce1ee8 --- /dev/null +++ b/drivers/rtc/rtc-ps3.c | |||
@@ -0,0 +1,104 @@ | |||
1 | /* | ||
2 | * PS3 RTC Driver | ||
3 | * | ||
4 | * Copyright 2009 Sony Corporation | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License as published by | ||
8 | * the Free Software Foundation; version 2 of the License. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program. | ||
17 | * If not, see <http://www.gnu.org/licenses/>. | ||
18 | */ | ||
19 | |||
20 | #include <linux/kernel.h> | ||
21 | #include <linux/module.h> | ||
22 | #include <linux/platform_device.h> | ||
23 | #include <linux/rtc.h> | ||
24 | |||
25 | #include <asm/lv1call.h> | ||
26 | #include <asm/ps3.h> | ||
27 | |||
28 | |||
29 | static u64 read_rtc(void) | ||
30 | { | ||
31 | int result; | ||
32 | u64 rtc_val; | ||
33 | u64 tb_val; | ||
34 | |||
35 | result = lv1_get_rtc(&rtc_val, &tb_val); | ||
36 | BUG_ON(result); | ||
37 | |||
38 | return rtc_val; | ||
39 | } | ||
40 | |||
41 | static int ps3_get_time(struct device *dev, struct rtc_time *tm) | ||
42 | { | ||
43 | rtc_time_to_tm(read_rtc() + ps3_os_area_get_rtc_diff(), tm); | ||
44 | return rtc_valid_tm(tm); | ||
45 | } | ||
46 | |||
47 | static int ps3_set_time(struct device *dev, struct rtc_time *tm) | ||
48 | { | ||
49 | unsigned long now; | ||
50 | |||
51 | rtc_tm_to_time(tm, &now); | ||
52 | ps3_os_area_set_rtc_diff(now - read_rtc()); | ||
53 | return 0; | ||
54 | } | ||
55 | |||
56 | static const struct rtc_class_ops ps3_rtc_ops = { | ||
57 | .read_time = ps3_get_time, | ||
58 | .set_time = ps3_set_time, | ||
59 | }; | ||
60 | |||
61 | static int __init ps3_rtc_probe(struct platform_device *dev) | ||
62 | { | ||
63 | struct rtc_device *rtc; | ||
64 | |||
65 | rtc = rtc_device_register("rtc-ps3", &dev->dev, &ps3_rtc_ops, | ||
66 | THIS_MODULE); | ||
67 | if (IS_ERR(rtc)) | ||
68 | return PTR_ERR(rtc); | ||
69 | |||
70 | platform_set_drvdata(dev, rtc); | ||
71 | return 0; | ||
72 | } | ||
73 | |||
74 | static int __exit ps3_rtc_remove(struct platform_device *dev) | ||
75 | { | ||
76 | rtc_device_unregister(platform_get_drvdata(dev)); | ||
77 | return 0; | ||
78 | } | ||
79 | |||
80 | static struct platform_driver ps3_rtc_driver = { | ||
81 | .driver = { | ||
82 | .name = "rtc-ps3", | ||
83 | .owner = THIS_MODULE, | ||
84 | }, | ||
85 | .remove = __exit_p(ps3_rtc_remove), | ||
86 | }; | ||
87 | |||
88 | static int __init ps3_rtc_init(void) | ||
89 | { | ||
90 | return platform_driver_probe(&ps3_rtc_driver, ps3_rtc_probe); | ||
91 | } | ||
92 | |||
93 | static void __exit ps3_rtc_fini(void) | ||
94 | { | ||
95 | platform_driver_unregister(&ps3_rtc_driver); | ||
96 | } | ||
97 | |||
98 | module_init(ps3_rtc_init); | ||
99 | module_exit(ps3_rtc_fini); | ||
100 | |||
101 | MODULE_AUTHOR("Sony Corporation"); | ||
102 | MODULE_LICENSE("GPL"); | ||
103 | MODULE_DESCRIPTION("ps3 RTC driver"); | ||
104 | MODULE_ALIAS("platform:rtc-ps3"); | ||
diff --git a/drivers/rtc/rtc-sa1100.c b/drivers/rtc/rtc-sa1100.c index d26a5f82aaba..4f247e4dd3f9 100644 --- a/drivers/rtc/rtc-sa1100.c +++ b/drivers/rtc/rtc-sa1100.c | |||
@@ -35,7 +35,8 @@ | |||
35 | #include <asm/irq.h> | 35 | #include <asm/irq.h> |
36 | 36 | ||
37 | #ifdef CONFIG_ARCH_PXA | 37 | #ifdef CONFIG_ARCH_PXA |
38 | #include <mach/pxa-regs.h> | 38 | #include <mach/regs-rtc.h> |
39 | #include <mach/regs-ost.h> | ||
39 | #endif | 40 | #endif |
40 | 41 | ||
41 | #define RTC_DEF_DIVIDER 32768 - 1 | 42 | #define RTC_DEF_DIVIDER 32768 - 1 |
diff --git a/drivers/rtc/rtc-v3020.c b/drivers/rtc/rtc-v3020.c index 14d4f036a768..ad164056feb6 100644 --- a/drivers/rtc/rtc-v3020.c +++ b/drivers/rtc/rtc-v3020.c | |||
@@ -27,17 +27,162 @@ | |||
27 | #include <linux/bcd.h> | 27 | #include <linux/bcd.h> |
28 | #include <linux/rtc-v3020.h> | 28 | #include <linux/rtc-v3020.h> |
29 | #include <linux/delay.h> | 29 | #include <linux/delay.h> |
30 | #include <linux/gpio.h> | ||
30 | 31 | ||
31 | #include <asm/io.h> | 32 | #include <linux/io.h> |
32 | 33 | ||
33 | #undef DEBUG | 34 | #undef DEBUG |
34 | 35 | ||
36 | struct v3020; | ||
37 | |||
38 | struct v3020_chip_ops { | ||
39 | int (*map_io)(struct v3020 *chip, struct platform_device *pdev, | ||
40 | struct v3020_platform_data *pdata); | ||
41 | void (*unmap_io)(struct v3020 *chip); | ||
42 | unsigned char (*read_bit)(struct v3020 *chip); | ||
43 | void (*write_bit)(struct v3020 *chip, unsigned char bit); | ||
44 | }; | ||
45 | |||
46 | #define V3020_CS 0 | ||
47 | #define V3020_WR 1 | ||
48 | #define V3020_RD 2 | ||
49 | #define V3020_IO 3 | ||
50 | |||
51 | struct v3020_gpio { | ||
52 | const char *name; | ||
53 | unsigned int gpio; | ||
54 | }; | ||
55 | |||
35 | struct v3020 { | 56 | struct v3020 { |
57 | /* MMIO access */ | ||
36 | void __iomem *ioaddress; | 58 | void __iomem *ioaddress; |
37 | int leftshift; | 59 | int leftshift; |
60 | |||
61 | /* GPIO access */ | ||
62 | struct v3020_gpio *gpio; | ||
63 | |||
64 | struct v3020_chip_ops *ops; | ||
65 | |||
38 | struct rtc_device *rtc; | 66 | struct rtc_device *rtc; |
39 | }; | 67 | }; |
40 | 68 | ||
69 | |||
70 | static int v3020_mmio_map(struct v3020 *chip, struct platform_device *pdev, | ||
71 | struct v3020_platform_data *pdata) | ||
72 | { | ||
73 | if (pdev->num_resources != 1) | ||
74 | return -EBUSY; | ||
75 | |||
76 | if (pdev->resource[0].flags != IORESOURCE_MEM) | ||
77 | return -EBUSY; | ||
78 | |||
79 | chip->leftshift = pdata->leftshift; | ||
80 | chip->ioaddress = ioremap(pdev->resource[0].start, 1); | ||
81 | if (chip->ioaddress == NULL) | ||
82 | return -EBUSY; | ||
83 | |||
84 | return 0; | ||
85 | } | ||
86 | |||
87 | static void v3020_mmio_unmap(struct v3020 *chip) | ||
88 | { | ||
89 | iounmap(chip->ioaddress); | ||
90 | } | ||
91 | |||
92 | static void v3020_mmio_write_bit(struct v3020 *chip, unsigned char bit) | ||
93 | { | ||
94 | writel(bit << chip->leftshift, chip->ioaddress); | ||
95 | } | ||
96 | |||
97 | static unsigned char v3020_mmio_read_bit(struct v3020 *chip) | ||
98 | { | ||
99 | return readl(chip->ioaddress) & (1 << chip->leftshift); | ||
100 | } | ||
101 | |||
102 | static struct v3020_chip_ops v3020_mmio_ops = { | ||
103 | .map_io = v3020_mmio_map, | ||
104 | .unmap_io = v3020_mmio_unmap, | ||
105 | .read_bit = v3020_mmio_read_bit, | ||
106 | .write_bit = v3020_mmio_write_bit, | ||
107 | }; | ||
108 | |||
109 | static struct v3020_gpio v3020_gpio[] = { | ||
110 | { "RTC CS", 0 }, | ||
111 | { "RTC WR", 0 }, | ||
112 | { "RTC RD", 0 }, | ||
113 | { "RTC IO", 0 }, | ||
114 | }; | ||
115 | |||
116 | static int v3020_gpio_map(struct v3020 *chip, struct platform_device *pdev, | ||
117 | struct v3020_platform_data *pdata) | ||
118 | { | ||
119 | int i, err; | ||
120 | |||
121 | v3020_gpio[V3020_CS].gpio = pdata->gpio_cs; | ||
122 | v3020_gpio[V3020_WR].gpio = pdata->gpio_wr; | ||
123 | v3020_gpio[V3020_RD].gpio = pdata->gpio_rd; | ||
124 | v3020_gpio[V3020_IO].gpio = pdata->gpio_io; | ||
125 | |||
126 | for (i = 0; i < ARRAY_SIZE(v3020_gpio); i++) { | ||
127 | err = gpio_request(v3020_gpio[i].gpio, v3020_gpio[i].name); | ||
128 | if (err) | ||
129 | goto err_request; | ||
130 | |||
131 | gpio_direction_output(v3020_gpio[i].gpio, 1); | ||
132 | } | ||
133 | |||
134 | chip->gpio = v3020_gpio; | ||
135 | |||
136 | return 0; | ||
137 | |||
138 | err_request: | ||
139 | while (--i >= 0) | ||
140 | gpio_free(v3020_gpio[i].gpio); | ||
141 | |||
142 | return err; | ||
143 | } | ||
144 | |||
145 | static void v3020_gpio_unmap(struct v3020 *chip) | ||
146 | { | ||
147 | int i; | ||
148 | |||
149 | for (i = 0; i < ARRAY_SIZE(v3020_gpio); i++) | ||
150 | gpio_free(v3020_gpio[i].gpio); | ||
151 | } | ||
152 | |||
153 | static void v3020_gpio_write_bit(struct v3020 *chip, unsigned char bit) | ||
154 | { | ||
155 | gpio_direction_output(chip->gpio[V3020_IO].gpio, bit); | ||
156 | gpio_set_value(chip->gpio[V3020_CS].gpio, 0); | ||
157 | gpio_set_value(chip->gpio[V3020_WR].gpio, 0); | ||
158 | udelay(1); | ||
159 | gpio_set_value(chip->gpio[V3020_WR].gpio, 1); | ||
160 | gpio_set_value(chip->gpio[V3020_CS].gpio, 1); | ||
161 | } | ||
162 | |||
163 | static unsigned char v3020_gpio_read_bit(struct v3020 *chip) | ||
164 | { | ||
165 | int bit; | ||
166 | |||
167 | gpio_direction_input(chip->gpio[V3020_IO].gpio); | ||
168 | gpio_set_value(chip->gpio[V3020_CS].gpio, 0); | ||
169 | gpio_set_value(chip->gpio[V3020_RD].gpio, 0); | ||
170 | udelay(1); | ||
171 | bit = !!gpio_get_value(chip->gpio[V3020_IO].gpio); | ||
172 | udelay(1); | ||
173 | gpio_set_value(chip->gpio[V3020_RD].gpio, 1); | ||
174 | gpio_set_value(chip->gpio[V3020_CS].gpio, 1); | ||
175 | |||
176 | return bit; | ||
177 | } | ||
178 | |||
179 | static struct v3020_chip_ops v3020_gpio_ops = { | ||
180 | .map_io = v3020_gpio_map, | ||
181 | .unmap_io = v3020_gpio_unmap, | ||
182 | .read_bit = v3020_gpio_read_bit, | ||
183 | .write_bit = v3020_gpio_write_bit, | ||
184 | }; | ||
185 | |||
41 | static void v3020_set_reg(struct v3020 *chip, unsigned char address, | 186 | static void v3020_set_reg(struct v3020 *chip, unsigned char address, |
42 | unsigned char data) | 187 | unsigned char data) |
43 | { | 188 | { |
@@ -46,7 +191,7 @@ static void v3020_set_reg(struct v3020 *chip, unsigned char address, | |||
46 | 191 | ||
47 | tmp = address; | 192 | tmp = address; |
48 | for (i = 0; i < 4; i++) { | 193 | for (i = 0; i < 4; i++) { |
49 | writel((tmp & 1) << chip->leftshift, chip->ioaddress); | 194 | chip->ops->write_bit(chip, (tmp & 1)); |
50 | tmp >>= 1; | 195 | tmp >>= 1; |
51 | udelay(1); | 196 | udelay(1); |
52 | } | 197 | } |
@@ -54,7 +199,7 @@ static void v3020_set_reg(struct v3020 *chip, unsigned char address, | |||
54 | /* Commands dont have data */ | 199 | /* Commands dont have data */ |
55 | if (!V3020_IS_COMMAND(address)) { | 200 | if (!V3020_IS_COMMAND(address)) { |
56 | for (i = 0; i < 8; i++) { | 201 | for (i = 0; i < 8; i++) { |
57 | writel((data & 1) << chip->leftshift, chip->ioaddress); | 202 | chip->ops->write_bit(chip, (data & 1)); |
58 | data >>= 1; | 203 | data >>= 1; |
59 | udelay(1); | 204 | udelay(1); |
60 | } | 205 | } |
@@ -63,18 +208,18 @@ static void v3020_set_reg(struct v3020 *chip, unsigned char address, | |||
63 | 208 | ||
64 | static unsigned char v3020_get_reg(struct v3020 *chip, unsigned char address) | 209 | static unsigned char v3020_get_reg(struct v3020 *chip, unsigned char address) |
65 | { | 210 | { |
66 | unsigned int data=0; | 211 | unsigned int data = 0; |
67 | int i; | 212 | int i; |
68 | 213 | ||
69 | for (i = 0; i < 4; i++) { | 214 | for (i = 0; i < 4; i++) { |
70 | writel((address & 1) << chip->leftshift, chip->ioaddress); | 215 | chip->ops->write_bit(chip, (address & 1)); |
71 | address >>= 1; | 216 | address >>= 1; |
72 | udelay(1); | 217 | udelay(1); |
73 | } | 218 | } |
74 | 219 | ||
75 | for (i = 0; i < 8; i++) { | 220 | for (i = 0; i < 8; i++) { |
76 | data >>= 1; | 221 | data >>= 1; |
77 | if (readl(chip->ioaddress) & (1 << chip->leftshift)) | 222 | if (chip->ops->read_bit(chip)) |
78 | data |= 0x80; | 223 | data |= 0x80; |
79 | udelay(1); | 224 | udelay(1); |
80 | } | 225 | } |
@@ -106,16 +251,14 @@ static int v3020_read_time(struct device *dev, struct rtc_time *dt) | |||
106 | tmp = v3020_get_reg(chip, V3020_YEAR); | 251 | tmp = v3020_get_reg(chip, V3020_YEAR); |
107 | dt->tm_year = bcd2bin(tmp)+100; | 252 | dt->tm_year = bcd2bin(tmp)+100; |
108 | 253 | ||
109 | #ifdef DEBUG | 254 | dev_dbg(dev, "\n%s : Read RTC values\n", __func__); |
110 | printk("\n%s : Read RTC values\n",__func__); | 255 | dev_dbg(dev, "tm_hour: %i\n", dt->tm_hour); |
111 | printk("tm_hour: %i\n",dt->tm_hour); | 256 | dev_dbg(dev, "tm_min : %i\n", dt->tm_min); |
112 | printk("tm_min : %i\n",dt->tm_min); | 257 | dev_dbg(dev, "tm_sec : %i\n", dt->tm_sec); |
113 | printk("tm_sec : %i\n",dt->tm_sec); | 258 | dev_dbg(dev, "tm_year: %i\n", dt->tm_year); |
114 | printk("tm_year: %i\n",dt->tm_year); | 259 | dev_dbg(dev, "tm_mon : %i\n", dt->tm_mon); |
115 | printk("tm_mon : %i\n",dt->tm_mon); | 260 | dev_dbg(dev, "tm_mday: %i\n", dt->tm_mday); |
116 | printk("tm_mday: %i\n",dt->tm_mday); | 261 | dev_dbg(dev, "tm_wday: %i\n", dt->tm_wday); |
117 | printk("tm_wday: %i\n",dt->tm_wday); | ||
118 | #endif | ||
119 | 262 | ||
120 | return 0; | 263 | return 0; |
121 | } | 264 | } |
@@ -125,15 +268,13 @@ static int v3020_set_time(struct device *dev, struct rtc_time *dt) | |||
125 | { | 268 | { |
126 | struct v3020 *chip = dev_get_drvdata(dev); | 269 | struct v3020 *chip = dev_get_drvdata(dev); |
127 | 270 | ||
128 | #ifdef DEBUG | 271 | dev_dbg(dev, "\n%s : Setting RTC values\n", __func__); |
129 | printk("\n%s : Setting RTC values\n",__func__); | 272 | dev_dbg(dev, "tm_sec : %i\n", dt->tm_sec); |
130 | printk("tm_sec : %i\n",dt->tm_sec); | 273 | dev_dbg(dev, "tm_min : %i\n", dt->tm_min); |
131 | printk("tm_min : %i\n",dt->tm_min); | 274 | dev_dbg(dev, "tm_hour: %i\n", dt->tm_hour); |
132 | printk("tm_hour: %i\n",dt->tm_hour); | 275 | dev_dbg(dev, "tm_mday: %i\n", dt->tm_mday); |
133 | printk("tm_mday: %i\n",dt->tm_mday); | 276 | dev_dbg(dev, "tm_wday: %i\n", dt->tm_wday); |
134 | printk("tm_wday: %i\n",dt->tm_wday); | 277 | dev_dbg(dev, "tm_year: %i\n", dt->tm_year); |
135 | printk("tm_year: %i\n",dt->tm_year); | ||
136 | #endif | ||
137 | 278 | ||
138 | /* Write all the values to ram... */ | 279 | /* Write all the values to ram... */ |
139 | v3020_set_reg(chip, V3020_SECONDS, bin2bcd(dt->tm_sec)); | 280 | v3020_set_reg(chip, V3020_SECONDS, bin2bcd(dt->tm_sec)); |
@@ -168,30 +309,28 @@ static int rtc_probe(struct platform_device *pdev) | |||
168 | int i; | 309 | int i; |
169 | int temp; | 310 | int temp; |
170 | 311 | ||
171 | if (pdev->num_resources != 1) | ||
172 | return -EBUSY; | ||
173 | |||
174 | if (pdev->resource[0].flags != IORESOURCE_MEM) | ||
175 | return -EBUSY; | ||
176 | |||
177 | chip = kzalloc(sizeof *chip, GFP_KERNEL); | 312 | chip = kzalloc(sizeof *chip, GFP_KERNEL); |
178 | if (!chip) | 313 | if (!chip) |
179 | return -ENOMEM; | 314 | return -ENOMEM; |
180 | 315 | ||
181 | chip->leftshift = pdata->leftshift; | 316 | if (pdata->use_gpio) |
182 | chip->ioaddress = ioremap(pdev->resource[0].start, 1); | 317 | chip->ops = &v3020_gpio_ops; |
183 | if (chip->ioaddress == NULL) | 318 | else |
319 | chip->ops = &v3020_mmio_ops; | ||
320 | |||
321 | retval = chip->ops->map_io(chip, pdev, pdata); | ||
322 | if (retval) | ||
184 | goto err_chip; | 323 | goto err_chip; |
185 | 324 | ||
186 | /* Make sure the v3020 expects a communication cycle | 325 | /* Make sure the v3020 expects a communication cycle |
187 | * by reading 8 times */ | 326 | * by reading 8 times */ |
188 | for (i = 0; i < 8; i++) | 327 | for (i = 0; i < 8; i++) |
189 | temp = readl(chip->ioaddress); | 328 | temp = chip->ops->read_bit(chip); |
190 | 329 | ||
191 | /* Test chip by doing a write/read sequence | 330 | /* Test chip by doing a write/read sequence |
192 | * to the chip ram */ | 331 | * to the chip ram */ |
193 | v3020_set_reg(chip, V3020_SECONDS, 0x33); | 332 | v3020_set_reg(chip, V3020_SECONDS, 0x33); |
194 | if(v3020_get_reg(chip, V3020_SECONDS) != 0x33) { | 333 | if (v3020_get_reg(chip, V3020_SECONDS) != 0x33) { |
195 | retval = -ENODEV; | 334 | retval = -ENODEV; |
196 | goto err_io; | 335 | goto err_io; |
197 | } | 336 | } |
@@ -200,10 +339,17 @@ static int rtc_probe(struct platform_device *pdev) | |||
200 | * are all disabled */ | 339 | * are all disabled */ |
201 | v3020_set_reg(chip, V3020_STATUS_0, 0x0); | 340 | v3020_set_reg(chip, V3020_STATUS_0, 0x0); |
202 | 341 | ||
203 | dev_info(&pdev->dev, "Chip available at physical address 0x%llx," | 342 | if (pdata->use_gpio) |
204 | "data connected to D%d\n", | 343 | dev_info(&pdev->dev, "Chip available at GPIOs " |
205 | (unsigned long long)pdev->resource[0].start, | 344 | "%d, %d, %d, %d\n", |
206 | chip->leftshift); | 345 | chip->gpio[V3020_CS].gpio, chip->gpio[V3020_WR].gpio, |
346 | chip->gpio[V3020_RD].gpio, chip->gpio[V3020_IO].gpio); | ||
347 | else | ||
348 | dev_info(&pdev->dev, "Chip available at " | ||
349 | "physical address 0x%llx," | ||
350 | "data connected to D%d\n", | ||
351 | (unsigned long long)pdev->resource[0].start, | ||
352 | chip->leftshift); | ||
207 | 353 | ||
208 | platform_set_drvdata(pdev, chip); | 354 | platform_set_drvdata(pdev, chip); |
209 | 355 | ||
@@ -218,7 +364,7 @@ static int rtc_probe(struct platform_device *pdev) | |||
218 | return 0; | 364 | return 0; |
219 | 365 | ||
220 | err_io: | 366 | err_io: |
221 | iounmap(chip->ioaddress); | 367 | chip->ops->unmap_io(chip); |
222 | err_chip: | 368 | err_chip: |
223 | kfree(chip); | 369 | kfree(chip); |
224 | 370 | ||
@@ -233,7 +379,7 @@ static int rtc_remove(struct platform_device *dev) | |||
233 | if (rtc) | 379 | if (rtc) |
234 | rtc_device_unregister(rtc); | 380 | rtc_device_unregister(rtc); |
235 | 381 | ||
236 | iounmap(chip->ioaddress); | 382 | chip->ops->unmap_io(chip); |
237 | kfree(chip); | 383 | kfree(chip); |
238 | 384 | ||
239 | return 0; | 385 | return 0; |
diff --git a/drivers/rtc/rtc-wm8350.c b/drivers/rtc/rtc-wm8350.c index 5c5e3aa91385..c91edc572eb6 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"); |