2 * linux/arch/arm/mach-integrator/time.c
4 * Copyright (C) 2000-2001 Deep Blue Solutions Ltd.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
10 #include <linux/module.h>
11 #include <linux/kernel.h>
12 #include <linux/time.h>
13 #include <linux/mc146818rtc.h>
14 #include <linux/interrupt.h>
15 #include <linux/init.h>
16 #include <linux/device.h>
18 #include <asm/hardware/amba.h>
19 #include <asm/hardware.h>
21 #include <asm/uaccess.h>
24 #include <asm/mach/time.h>
32 #define RTC_CR_MIE (1 << 0)
34 extern int (*set_rtc
)(void);
35 static void __iomem
*rtc_base
;
37 static int integrator_set_rtc(void)
39 __raw_writel(xtime
.tv_sec
, rtc_base
+ RTC_LR
);
43 static void rtc_read_alarm(struct rtc_wkalrm
*alrm
)
45 rtc_time_to_tm(readl(rtc_base
+ RTC_MR
), &alrm
->time
);
48 static int rtc_set_alarm(struct rtc_wkalrm
*alrm
)
53 ret
= rtc_tm_to_time(&alrm
->time
, &time
);
55 writel(time
, rtc_base
+ RTC_MR
);
59 static void rtc_read_time(struct rtc_time
*tm
)
61 rtc_time_to_tm(readl(rtc_base
+ RTC_DR
), tm
);
65 * Set the RTC time. Unfortunately, we can't accurately set
66 * the point at which the counter updates.
68 * Also, since RTC_LR is transferred to RTC_CR on next rising
69 * edge of the 1Hz clock, we must write the time one second
72 static int rtc_set_time(struct rtc_time
*tm
)
77 ret
= rtc_tm_to_time(tm
, &time
);
79 writel(time
+ 1, rtc_base
+ RTC_LR
);
84 static struct rtc_ops rtc_ops
= {
86 .read_time
= rtc_read_time
,
87 .set_time
= rtc_set_time
,
88 .read_alarm
= rtc_read_alarm
,
89 .set_alarm
= rtc_set_alarm
,
92 static irqreturn_t
rtc_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
94 writel(0, rtc_base
+ RTC_EOI
);
98 static int rtc_probe(struct amba_device
*dev
, void *id
)
105 ret
= amba_request_regions(dev
, NULL
);
109 rtc_base
= ioremap(dev
->res
.start
, SZ_4K
);
115 __raw_writel(0, rtc_base
+ RTC_CR
);
116 __raw_writel(0, rtc_base
+ RTC_EOI
);
118 xtime
.tv_sec
= __raw_readl(rtc_base
+ RTC_DR
);
120 ret
= request_irq(dev
->irq
[0], rtc_interrupt
, SA_INTERRUPT
,
125 ret
= register_rtc(&rtc_ops
);
129 set_rtc
= integrator_set_rtc
;
133 free_irq(dev
->irq
[0], dev
);
138 amba_release_regions(dev
);
143 static int rtc_remove(struct amba_device
*dev
)
147 writel(0, rtc_base
+ RTC_CR
);
149 free_irq(dev
->irq
[0], dev
);
150 unregister_rtc(&rtc_ops
);
154 amba_release_regions(dev
);
159 static struct timespec rtc_delta
;
161 static int rtc_suspend(struct amba_device
*dev
, pm_message_t state
)
165 rtc
.tv_sec
= readl(rtc_base
+ RTC_DR
);
167 save_time_delta(&rtc_delta
, &rtc
);
172 static int rtc_resume(struct amba_device
*dev
)
176 rtc
.tv_sec
= readl(rtc_base
+ RTC_DR
);
178 restore_time_delta(&rtc_delta
, &rtc
);
183 static struct amba_id rtc_ids
[] = {
191 static struct amba_driver rtc_driver
= {
196 .remove
= rtc_remove
,
197 .suspend
= rtc_suspend
,
198 .resume
= rtc_resume
,
202 static int __init
integrator_rtc_init(void)
204 return amba_driver_register(&rtc_driver
);
207 static void __exit
integrator_rtc_exit(void)
209 amba_driver_unregister(&rtc_driver
);
212 module_init(integrator_rtc_init
);
213 module_exit(integrator_rtc_exit
);