arm/mach-integrator/time.c, mwave: revert portions of recent irq cleanups
[linux-2.6/mini2440.git] / arch / arm / mach-integrator / time.c
blob8508a0db3eaf53ce213a5190ac0877c057e2f791
1 /*
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.
9 */
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>
17 #include <linux/amba/bus.h>
19 #include <asm/hardware.h>
20 #include <asm/io.h>
21 #include <asm/uaccess.h>
22 #include <asm/rtc.h>
24 #include <asm/mach/time.h>
26 #define RTC_DR (0)
27 #define RTC_MR (4)
28 #define RTC_STAT (8)
29 #define RTC_EOI (8)
30 #define RTC_LR (12)
31 #define RTC_CR (16)
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);
40 return 1;
43 static int integrator_rtc_read_alarm(struct rtc_wkalrm *alrm)
45 rtc_time_to_tm(readl(rtc_base + RTC_MR), &alrm->time);
46 return 0;
49 static inline int integrator_rtc_set_alarm(struct rtc_wkalrm *alrm)
51 unsigned long time;
52 int ret;
55 * At the moment, we can only deal with non-wildcarded alarm times.
57 ret = rtc_valid_tm(&alrm->time);
58 if (ret == 0)
59 ret = rtc_tm_to_time(&alrm->time, &time);
60 if (ret == 0)
61 writel(time, rtc_base + RTC_MR);
62 return ret;
65 static int integrator_rtc_read_time(struct rtc_time *tm)
67 rtc_time_to_tm(readl(rtc_base + RTC_DR), tm);
68 return 0;
72 * Set the RTC time. Unfortunately, we can't accurately set
73 * the point at which the counter updates.
75 * Also, since RTC_LR is transferred to RTC_CR on next rising
76 * edge of the 1Hz clock, we must write the time one second
77 * in advance.
79 static inline int integrator_rtc_set_time(struct rtc_time *tm)
81 unsigned long time;
82 int ret;
84 ret = rtc_tm_to_time(tm, &time);
85 if (ret == 0)
86 writel(time + 1, rtc_base + RTC_LR);
88 return ret;
91 static struct rtc_ops rtc_ops = {
92 .owner = THIS_MODULE,
93 .read_time = integrator_rtc_read_time,
94 .set_time = integrator_rtc_set_time,
95 .read_alarm = integrator_rtc_read_alarm,
96 .set_alarm = integrator_rtc_set_alarm,
99 static irqreturn_t arm_rtc_interrupt(int irq, void *dev_id)
101 writel(0, rtc_base + RTC_EOI);
102 return IRQ_HANDLED;
105 static int rtc_probe(struct amba_device *dev, void *id)
107 int ret;
109 if (rtc_base)
110 return -EBUSY;
112 ret = amba_request_regions(dev, NULL);
113 if (ret)
114 goto out;
116 rtc_base = ioremap(dev->res.start, SZ_4K);
117 if (!rtc_base) {
118 ret = -ENOMEM;
119 goto res_out;
122 __raw_writel(0, rtc_base + RTC_CR);
123 __raw_writel(0, rtc_base + RTC_EOI);
125 xtime.tv_sec = __raw_readl(rtc_base + RTC_DR);
127 /* note that 'dev' is merely used for irq disambiguation;
128 * it is not actually referenced in the irq handler
130 ret = request_irq(dev->irq[0], arm_rtc_interrupt, IRQF_DISABLED,
131 "rtc-pl030", dev);
132 if (ret)
133 goto map_out;
135 ret = register_rtc(&rtc_ops);
136 if (ret)
137 goto irq_out;
139 set_rtc = integrator_set_rtc;
140 return 0;
142 irq_out:
143 free_irq(dev->irq[0], dev);
144 map_out:
145 iounmap(rtc_base);
146 rtc_base = NULL;
147 res_out:
148 amba_release_regions(dev);
149 out:
150 return ret;
153 static int rtc_remove(struct amba_device *dev)
155 set_rtc = NULL;
157 writel(0, rtc_base + RTC_CR);
159 free_irq(dev->irq[0], dev);
160 unregister_rtc(&rtc_ops);
162 iounmap(rtc_base);
163 rtc_base = NULL;
164 amba_release_regions(dev);
166 return 0;
169 static struct timespec rtc_delta;
171 static int rtc_suspend(struct amba_device *dev, pm_message_t state)
173 struct timespec rtc;
175 rtc.tv_sec = readl(rtc_base + RTC_DR);
176 rtc.tv_nsec = 0;
177 save_time_delta(&rtc_delta, &rtc);
179 return 0;
182 static int rtc_resume(struct amba_device *dev)
184 struct timespec rtc;
186 rtc.tv_sec = readl(rtc_base + RTC_DR);
187 rtc.tv_nsec = 0;
188 restore_time_delta(&rtc_delta, &rtc);
190 return 0;
193 static struct amba_id rtc_ids[] = {
195 .id = 0x00041030,
196 .mask = 0x000fffff,
198 { 0, 0 },
201 static struct amba_driver rtc_driver = {
202 .drv = {
203 .name = "rtc-pl030",
205 .probe = rtc_probe,
206 .remove = rtc_remove,
207 .suspend = rtc_suspend,
208 .resume = rtc_resume,
209 .id_table = rtc_ids,
212 static int __init integrator_rtc_init(void)
214 return amba_driver_register(&rtc_driver);
217 static void __exit integrator_rtc_exit(void)
219 amba_driver_unregister(&rtc_driver);
222 module_init(integrator_rtc_init);
223 module_exit(integrator_rtc_exit);