aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/rtc
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/rtc')
-rw-r--r--drivers/rtc/Kconfig2
-rw-r--r--drivers/rtc/rtc-bfin.c60
-rw-r--r--drivers/rtc/rtc-cmos.c38
-rw-r--r--drivers/rtc/rtc-dev.c5
-rw-r--r--drivers/rtc/rtc-ds1374.c10
-rw-r--r--drivers/rtc/rtc-lib.c5
-rw-r--r--drivers/rtc/rtc-max6902.c2
-rw-r--r--drivers/rtc/rtc-r9701.c1
8 files changed, 73 insertions, 50 deletions
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index 90ab73825401..9a9755c92fad 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -561,7 +561,7 @@ config RTC_DRV_AT91SAM9_GPBR
561 561
562config RTC_DRV_BFIN 562config RTC_DRV_BFIN
563 tristate "Blackfin On-Chip RTC" 563 tristate "Blackfin On-Chip RTC"
564 depends on BLACKFIN 564 depends on BLACKFIN && !BF561
565 help 565 help
566 If you say yes here you will get support for the 566 If you say yes here you will get support for the
567 Blackfin On-Chip Real Time Clock. 567 Blackfin On-Chip Real Time Clock.
diff --git a/drivers/rtc/rtc-bfin.c b/drivers/rtc/rtc-bfin.c
index a1af4c27939b..34439ce3967e 100644
--- a/drivers/rtc/rtc-bfin.c
+++ b/drivers/rtc/rtc-bfin.c
@@ -218,26 +218,6 @@ static irqreturn_t bfin_rtc_interrupt(int irq, void *dev_id)
218 return IRQ_NONE; 218 return IRQ_NONE;
219} 219}
220 220
221static int bfin_rtc_open(struct device *dev)
222{
223 int ret;
224
225 dev_dbg_stamp(dev);
226
227 ret = request_irq(IRQ_RTC, bfin_rtc_interrupt, IRQF_SHARED, to_platform_device(dev)->name, dev);
228 if (!ret)
229 bfin_rtc_reset(dev, RTC_ISTAT_WRITE_COMPLETE);
230
231 return ret;
232}
233
234static void bfin_rtc_release(struct device *dev)
235{
236 dev_dbg_stamp(dev);
237 bfin_rtc_reset(dev, 0);
238 free_irq(IRQ_RTC, dev);
239}
240
241static void bfin_rtc_int_set(u16 rtc_int) 221static void bfin_rtc_int_set(u16 rtc_int)
242{ 222{
243 bfin_write_RTC_ISTAT(rtc_int); 223 bfin_write_RTC_ISTAT(rtc_int);
@@ -370,8 +350,6 @@ static int bfin_rtc_proc(struct device *dev, struct seq_file *seq)
370} 350}
371 351
372static struct rtc_class_ops bfin_rtc_ops = { 352static struct rtc_class_ops bfin_rtc_ops = {
373 .open = bfin_rtc_open,
374 .release = bfin_rtc_release,
375 .ioctl = bfin_rtc_ioctl, 353 .ioctl = bfin_rtc_ioctl,
376 .read_time = bfin_rtc_read_time, 354 .read_time = bfin_rtc_read_time,
377 .set_time = bfin_rtc_set_time, 355 .set_time = bfin_rtc_set_time,
@@ -383,29 +361,44 @@ static struct rtc_class_ops bfin_rtc_ops = {
383static int __devinit bfin_rtc_probe(struct platform_device *pdev) 361static int __devinit bfin_rtc_probe(struct platform_device *pdev)
384{ 362{
385 struct bfin_rtc *rtc; 363 struct bfin_rtc *rtc;
364 struct device *dev = &pdev->dev;
386 int ret = 0; 365 int ret = 0;
366 unsigned long timeout;
387 367
388 dev_dbg_stamp(&pdev->dev); 368 dev_dbg_stamp(dev);
389 369
370 /* Allocate memory for our RTC struct */
390 rtc = kzalloc(sizeof(*rtc), GFP_KERNEL); 371 rtc = kzalloc(sizeof(*rtc), GFP_KERNEL);
391 if (unlikely(!rtc)) 372 if (unlikely(!rtc))
392 return -ENOMEM; 373 return -ENOMEM;
374 platform_set_drvdata(pdev, rtc);
375 device_init_wakeup(dev, 1);
393 376
394 rtc->rtc_dev = rtc_device_register(pdev->name, &pdev->dev, &bfin_rtc_ops, THIS_MODULE); 377 /* Grab the IRQ and init the hardware */
395 if (IS_ERR(rtc)) { 378 ret = request_irq(IRQ_RTC, bfin_rtc_interrupt, IRQF_SHARED, pdev->name, dev);
396 ret = PTR_ERR(rtc->rtc_dev); 379 if (unlikely(ret))
397 goto err; 380 goto err;
398 } 381 /* sometimes the bootloader touched things, but the write complete was not
399 382 * enabled, so let's just do a quick timeout here since the IRQ will not fire ...
400 /* see comment at top of file about stopwatch/PIE */ 383 */
384 timeout = jiffies + HZ;
385 while (bfin_read_RTC_ISTAT() & RTC_ISTAT_WRITE_PENDING)
386 if (time_after(jiffies, timeout))
387 break;
388 bfin_rtc_reset(dev, RTC_ISTAT_WRITE_COMPLETE);
401 bfin_write_RTC_SWCNT(0); 389 bfin_write_RTC_SWCNT(0);
402 390
403 platform_set_drvdata(pdev, rtc); 391 /* Register our RTC with the RTC framework */
404 392 rtc->rtc_dev = rtc_device_register(pdev->name, dev, &bfin_rtc_ops, THIS_MODULE);
405 device_init_wakeup(&pdev->dev, 1); 393 if (unlikely(IS_ERR(rtc))) {
394 ret = PTR_ERR(rtc->rtc_dev);
395 goto err_irq;
396 }
406 397
407 return 0; 398 return 0;
408 399
400 err_irq:
401 free_irq(IRQ_RTC, dev);
409 err: 402 err:
410 kfree(rtc); 403 kfree(rtc);
411 return ret; 404 return ret;
@@ -414,7 +407,10 @@ static int __devinit bfin_rtc_probe(struct platform_device *pdev)
414static int __devexit bfin_rtc_remove(struct platform_device *pdev) 407static int __devexit bfin_rtc_remove(struct platform_device *pdev)
415{ 408{
416 struct bfin_rtc *rtc = platform_get_drvdata(pdev); 409 struct bfin_rtc *rtc = platform_get_drvdata(pdev);
410 struct device *dev = &pdev->dev;
417 411
412 bfin_rtc_reset(dev, 0);
413 free_irq(IRQ_RTC, dev);
418 rtc_device_unregister(rtc->rtc_dev); 414 rtc_device_unregister(rtc->rtc_dev);
419 platform_set_drvdata(pdev, NULL); 415 platform_set_drvdata(pdev, NULL);
420 kfree(rtc); 416 kfree(rtc);
diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
index 6ea349aba3ba..b184367637d0 100644
--- a/drivers/rtc/rtc-cmos.c
+++ b/drivers/rtc/rtc-cmos.c
@@ -800,7 +800,6 @@ static void __exit cmos_do_remove(struct device *dev)
800static int cmos_suspend(struct device *dev, pm_message_t mesg) 800static int cmos_suspend(struct device *dev, pm_message_t mesg)
801{ 801{
802 struct cmos_rtc *cmos = dev_get_drvdata(dev); 802 struct cmos_rtc *cmos = dev_get_drvdata(dev);
803 int do_wake = device_may_wakeup(dev);
804 unsigned char tmp; 803 unsigned char tmp;
805 804
806 /* only the alarm might be a wakeup event source */ 805 /* only the alarm might be a wakeup event source */
@@ -809,7 +808,7 @@ static int cmos_suspend(struct device *dev, pm_message_t mesg)
809 if (tmp & (RTC_PIE|RTC_AIE|RTC_UIE)) { 808 if (tmp & (RTC_PIE|RTC_AIE|RTC_UIE)) {
810 unsigned char mask; 809 unsigned char mask;
811 810
812 if (do_wake) 811 if (device_may_wakeup(dev))
813 mask = RTC_IRQMASK & ~RTC_AIE; 812 mask = RTC_IRQMASK & ~RTC_AIE;
814 else 813 else
815 mask = RTC_IRQMASK; 814 mask = RTC_IRQMASK;
@@ -837,6 +836,17 @@ static int cmos_suspend(struct device *dev, pm_message_t mesg)
837 return 0; 836 return 0;
838} 837}
839 838
839/* We want RTC alarms to wake us from e.g. ACPI G2/S5 "soft off", even
840 * after a detour through G3 "mechanical off", although the ACPI spec
841 * says wakeup should only work from G1/S4 "hibernate". To most users,
842 * distinctions between S4 and S5 are pointless. So when the hardware
843 * allows, don't draw that distinction.
844 */
845static inline int cmos_poweroff(struct device *dev)
846{
847 return cmos_suspend(dev, PMSG_HIBERNATE);
848}
849
840static int cmos_resume(struct device *dev) 850static int cmos_resume(struct device *dev)
841{ 851{
842 struct cmos_rtc *cmos = dev_get_drvdata(dev); 852 struct cmos_rtc *cmos = dev_get_drvdata(dev);
@@ -884,6 +894,12 @@ static int cmos_resume(struct device *dev)
884#else 894#else
885#define cmos_suspend NULL 895#define cmos_suspend NULL
886#define cmos_resume NULL 896#define cmos_resume NULL
897
898static inline int cmos_poweroff(struct device *dev)
899{
900 return -ENOSYS;
901}
902
887#endif 903#endif
888 904
889/*----------------------------------------------------------------*/ 905/*----------------------------------------------------------------*/
@@ -903,10 +919,6 @@ static int cmos_resume(struct device *dev)
903static int __devinit 919static int __devinit
904cmos_pnp_probe(struct pnp_dev *pnp, const struct pnp_device_id *id) 920cmos_pnp_probe(struct pnp_dev *pnp, const struct pnp_device_id *id)
905{ 921{
906 /* REVISIT paranoia argues for a shutdown notifier, since PNP
907 * drivers can't provide shutdown() methods to disable IRQs.
908 * Or better yet, fix PNP to allow those methods...
909 */
910 if (pnp_port_start(pnp,0) == 0x70 && !pnp_irq_valid(pnp,0)) 922 if (pnp_port_start(pnp,0) == 0x70 && !pnp_irq_valid(pnp,0))
911 /* Some machines contain a PNP entry for the RTC, but 923 /* Some machines contain a PNP entry for the RTC, but
912 * don't define the IRQ. It should always be safe to 924 * don't define the IRQ. It should always be safe to
@@ -942,6 +954,13 @@ static int cmos_pnp_resume(struct pnp_dev *pnp)
942#define cmos_pnp_resume NULL 954#define cmos_pnp_resume NULL
943#endif 955#endif
944 956
957static void cmos_pnp_shutdown(struct device *pdev)
958{
959 if (system_state == SYSTEM_POWER_OFF && !cmos_poweroff(pdev))
960 return;
961
962 cmos_do_shutdown();
963}
945 964
946static const struct pnp_device_id rtc_ids[] = { 965static const struct pnp_device_id rtc_ids[] = {
947 { .id = "PNP0b00", }, 966 { .id = "PNP0b00", },
@@ -961,6 +980,10 @@ static struct pnp_driver cmos_pnp_driver = {
961 .flags = PNP_DRIVER_RES_DO_NOT_CHANGE, 980 .flags = PNP_DRIVER_RES_DO_NOT_CHANGE,
962 .suspend = cmos_pnp_suspend, 981 .suspend = cmos_pnp_suspend,
963 .resume = cmos_pnp_resume, 982 .resume = cmos_pnp_resume,
983 .driver = {
984 .name = (char *)driver_name,
985 .shutdown = cmos_pnp_shutdown,
986 }
964}; 987};
965 988
966#endif /* CONFIG_PNP */ 989#endif /* CONFIG_PNP */
@@ -986,6 +1009,9 @@ static int __exit cmos_platform_remove(struct platform_device *pdev)
986 1009
987static void cmos_platform_shutdown(struct platform_device *pdev) 1010static void cmos_platform_shutdown(struct platform_device *pdev)
988{ 1011{
1012 if (system_state == SYSTEM_POWER_OFF && !cmos_poweroff(&pdev->dev))
1013 return;
1014
989 cmos_do_shutdown(); 1015 cmos_do_shutdown();
990} 1016}
991 1017
diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
index 35dcc06eb3e2..f118252f3a9f 100644
--- a/drivers/rtc/rtc-dev.c
+++ b/drivers/rtc/rtc-dev.c
@@ -403,11 +403,14 @@ static long rtc_dev_ioctl(struct file *file,
403 403
404#ifdef CONFIG_RTC_INTF_DEV_UIE_EMUL 404#ifdef CONFIG_RTC_INTF_DEV_UIE_EMUL
405 case RTC_UIE_OFF: 405 case RTC_UIE_OFF:
406 mutex_unlock(&rtc->ops_lock);
406 clear_uie(rtc); 407 clear_uie(rtc);
407 break; 408 return 0;
408 409
409 case RTC_UIE_ON: 410 case RTC_UIE_ON:
411 mutex_unlock(&rtc->ops_lock);
410 err = set_uie(rtc); 412 err = set_uie(rtc);
413 return err;
411#endif 414#endif
412 default: 415 default:
413 err = -ENOTTY; 416 err = -ENOTTY;
diff --git a/drivers/rtc/rtc-ds1374.c b/drivers/rtc/rtc-ds1374.c
index 640acd20fdde..a150418fba76 100644
--- a/drivers/rtc/rtc-ds1374.c
+++ b/drivers/rtc/rtc-ds1374.c
@@ -173,7 +173,7 @@ static int ds1374_read_alarm(struct device *dev, struct rtc_wkalrm *alarm)
173 int cr, sr; 173 int cr, sr;
174 int ret = 0; 174 int ret = 0;
175 175
176 if (client->irq < 0) 176 if (client->irq <= 0)
177 return -EINVAL; 177 return -EINVAL;
178 178
179 mutex_lock(&ds1374->mutex); 179 mutex_lock(&ds1374->mutex);
@@ -212,7 +212,7 @@ static int ds1374_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
212 int cr; 212 int cr;
213 int ret = 0; 213 int ret = 0;
214 214
215 if (client->irq < 0) 215 if (client->irq <= 0)
216 return -EINVAL; 216 return -EINVAL;
217 217
218 ret = ds1374_read_time(dev, &now); 218 ret = ds1374_read_time(dev, &now);
@@ -381,7 +381,7 @@ static int ds1374_probe(struct i2c_client *client,
381 if (ret) 381 if (ret)
382 goto out_free; 382 goto out_free;
383 383
384 if (client->irq >= 0) { 384 if (client->irq > 0) {
385 ret = request_irq(client->irq, ds1374_irq, 0, 385 ret = request_irq(client->irq, ds1374_irq, 0,
386 "ds1374", client); 386 "ds1374", client);
387 if (ret) { 387 if (ret) {
@@ -401,7 +401,7 @@ static int ds1374_probe(struct i2c_client *client,
401 return 0; 401 return 0;
402 402
403out_irq: 403out_irq:
404 if (client->irq >= 0) 404 if (client->irq > 0)
405 free_irq(client->irq, client); 405 free_irq(client->irq, client);
406 406
407out_free: 407out_free:
@@ -414,7 +414,7 @@ static int __devexit ds1374_remove(struct i2c_client *client)
414{ 414{
415 struct ds1374 *ds1374 = i2c_get_clientdata(client); 415 struct ds1374 *ds1374 = i2c_get_clientdata(client);
416 416
417 if (client->irq >= 0) { 417 if (client->irq > 0) {
418 mutex_lock(&ds1374->mutex); 418 mutex_lock(&ds1374->mutex);
419 ds1374->exiting = 1; 419 ds1374->exiting = 1;
420 mutex_unlock(&ds1374->mutex); 420 mutex_unlock(&ds1374->mutex);
diff --git a/drivers/rtc/rtc-lib.c b/drivers/rtc/rtc-lib.c
index 9f996ec881ce..dd70bf73ce9d 100644
--- a/drivers/rtc/rtc-lib.c
+++ b/drivers/rtc/rtc-lib.c
@@ -51,10 +51,11 @@ EXPORT_SYMBOL(rtc_year_days);
51 */ 51 */
52void rtc_time_to_tm(unsigned long time, struct rtc_time *tm) 52void rtc_time_to_tm(unsigned long time, struct rtc_time *tm)
53{ 53{
54 unsigned int days, month, year; 54 unsigned int month, year;
55 int days;
55 56
56 days = time / 86400; 57 days = time / 86400;
57 time -= days * 86400; 58 time -= (unsigned int) days * 86400;
58 59
59 /* day of the week, 1970-01-01 was a Thursday */ 60 /* day of the week, 1970-01-01 was a Thursday */
60 tm->tm_wday = (days + 4) % 7; 61 tm->tm_wday = (days + 4) % 7;
diff --git a/drivers/rtc/rtc-max6902.c b/drivers/rtc/rtc-max6902.c
index 12f0310ae89c..78b2551fb19d 100644
--- a/drivers/rtc/rtc-max6902.c
+++ b/drivers/rtc/rtc-max6902.c
@@ -20,8 +20,6 @@
20 */ 20 */
21 21
22#include <linux/module.h> 22#include <linux/module.h>
23#include <linux/version.h>
24
25#include <linux/kernel.h> 23#include <linux/kernel.h>
26#include <linux/platform_device.h> 24#include <linux/platform_device.h>
27#include <linux/init.h> 25#include <linux/init.h>
diff --git a/drivers/rtc/rtc-r9701.c b/drivers/rtc/rtc-r9701.c
index b35f9bfa2af4..395985b339c9 100644
--- a/drivers/rtc/rtc-r9701.c
+++ b/drivers/rtc/rtc-r9701.c
@@ -14,7 +14,6 @@
14 */ 14 */
15 15
16#include <linux/module.h> 16#include <linux/module.h>
17#include <linux/version.h>
18#include <linux/kernel.h> 17#include <linux/kernel.h>
19#include <linux/platform_device.h> 18#include <linux/platform_device.h>
20#include <linux/device.h> 19#include <linux/device.h>