diff options
author | Russell King <rmk@dyn-67.arm.linux.org.uk> | 2008-04-20 07:08:36 -0400 |
---|---|---|
committer | Russell King <rmk+kernel@arm.linux.org.uk> | 2008-05-22 09:56:38 -0400 |
commit | a190901c6b5f1f4a31681e8c69d811a4f9426e2b (patch) | |
tree | 146d286488cf0b838c9ea1789a00b18dcabd73b4 | |
parent | 2dba8518b7761aee3ba757b298efa15dd34eff18 (diff) |
[RTC] rtc-pl030: add driver, remove old non-rtc lib driver
Convert Integrator PL030 RTC driver to use the RTC class interfaces.
Acked-by: Alessandro Zummo <a.zummo@towertech.it>
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
-rw-r--r-- | arch/arm/mach-integrator/Makefile | 2 | ||||
-rw-r--r-- | arch/arm/mach-integrator/time.c | 223 | ||||
-rw-r--r-- | drivers/rtc/Kconfig | 10 | ||||
-rw-r--r-- | drivers/rtc/Makefile | 1 | ||||
-rw-r--r-- | drivers/rtc/rtc-pl030.c | 217 |
5 files changed, 229 insertions, 224 deletions
diff --git a/arch/arm/mach-integrator/Makefile b/arch/arm/mach-integrator/Makefile index 158daaf9e3b0..6a5ef8d30b10 100644 --- a/arch/arm/mach-integrator/Makefile +++ b/arch/arm/mach-integrator/Makefile | |||
@@ -4,7 +4,7 @@ | |||
4 | 4 | ||
5 | # Object file lists. | 5 | # Object file lists. |
6 | 6 | ||
7 | obj-y := clock.o core.o lm.o time.o | 7 | obj-y := clock.o core.o lm.o |
8 | obj-$(CONFIG_ARCH_INTEGRATOR_AP) += integrator_ap.o | 8 | obj-$(CONFIG_ARCH_INTEGRATOR_AP) += integrator_ap.o |
9 | obj-$(CONFIG_ARCH_INTEGRATOR_CP) += integrator_cp.o | 9 | obj-$(CONFIG_ARCH_INTEGRATOR_CP) += integrator_cp.o |
10 | 10 | ||
diff --git a/arch/arm/mach-integrator/time.c b/arch/arm/mach-integrator/time.c deleted file mode 100644 index 8508a0db3eaf..000000000000 --- a/arch/arm/mach-integrator/time.c +++ /dev/null | |||
@@ -1,223 +0,0 @@ | |||
1 | /* | ||
2 | * linux/arch/arm/mach-integrator/time.c | ||
3 | * | ||
4 | * Copyright (C) 2000-2001 Deep Blue Solutions Ltd. | ||
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 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> | ||
18 | |||
19 | #include <asm/hardware.h> | ||
20 | #include <asm/io.h> | ||
21 | #include <asm/uaccess.h> | ||
22 | #include <asm/rtc.h> | ||
23 | |||
24 | #include <asm/mach/time.h> | ||
25 | |||
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) | ||
33 | |||
34 | extern int (*set_rtc)(void); | ||
35 | static void __iomem *rtc_base; | ||
36 | |||
37 | static int integrator_set_rtc(void) | ||
38 | { | ||
39 | __raw_writel(xtime.tv_sec, rtc_base + RTC_LR); | ||
40 | return 1; | ||
41 | } | ||
42 | |||
43 | static int integrator_rtc_read_alarm(struct rtc_wkalrm *alrm) | ||
44 | { | ||
45 | rtc_time_to_tm(readl(rtc_base + RTC_MR), &alrm->time); | ||
46 | return 0; | ||
47 | } | ||
48 | |||
49 | static inline int integrator_rtc_set_alarm(struct rtc_wkalrm *alrm) | ||
50 | { | ||
51 | unsigned long time; | ||
52 | int ret; | ||
53 | |||
54 | /* | ||
55 | * At the moment, we can only deal with non-wildcarded alarm times. | ||
56 | */ | ||
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; | ||
63 | } | ||
64 | |||
65 | static int integrator_rtc_read_time(struct rtc_time *tm) | ||
66 | { | ||
67 | rtc_time_to_tm(readl(rtc_base + RTC_DR), tm); | ||
68 | return 0; | ||
69 | } | ||
70 | |||
71 | /* | ||
72 | * Set the RTC time. Unfortunately, we can't accurately set | ||
73 | * the point at which the counter updates. | ||
74 | * | ||
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. | ||
78 | */ | ||
79 | static inline int integrator_rtc_set_time(struct rtc_time *tm) | ||
80 | { | ||
81 | unsigned long time; | ||
82 | int ret; | ||
83 | |||
84 | ret = rtc_tm_to_time(tm, &time); | ||
85 | if (ret == 0) | ||
86 | writel(time + 1, rtc_base + RTC_LR); | ||
87 | |||
88 | return ret; | ||
89 | } | ||
90 | |||
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, | ||
97 | }; | ||
98 | |||
99 | static irqreturn_t arm_rtc_interrupt(int irq, void *dev_id) | ||
100 | { | ||
101 | writel(0, rtc_base + RTC_EOI); | ||
102 | return IRQ_HANDLED; | ||
103 | } | ||
104 | |||
105 | static int rtc_probe(struct amba_device *dev, void *id) | ||
106 | { | ||
107 | int ret; | ||
108 | |||
109 | if (rtc_base) | ||
110 | return -EBUSY; | ||
111 | |||
112 | ret = amba_request_regions(dev, NULL); | ||
113 | if (ret) | ||
114 | goto out; | ||
115 | |||
116 | rtc_base = ioremap(dev->res.start, SZ_4K); | ||
117 | if (!rtc_base) { | ||
118 | ret = -ENOMEM; | ||
119 | goto res_out; | ||
120 | } | ||
121 | |||
122 | __raw_writel(0, rtc_base + RTC_CR); | ||
123 | __raw_writel(0, rtc_base + RTC_EOI); | ||
124 | |||
125 | xtime.tv_sec = __raw_readl(rtc_base + RTC_DR); | ||
126 | |||
127 | /* note that 'dev' is merely used for irq disambiguation; | ||
128 | * it is not actually referenced in the irq handler | ||
129 | */ | ||
130 | ret = request_irq(dev->irq[0], arm_rtc_interrupt, IRQF_DISABLED, | ||
131 | "rtc-pl030", dev); | ||
132 | if (ret) | ||
133 | goto map_out; | ||
134 | |||
135 | ret = register_rtc(&rtc_ops); | ||
136 | if (ret) | ||
137 | goto irq_out; | ||
138 | |||
139 | set_rtc = integrator_set_rtc; | ||
140 | return 0; | ||
141 | |||
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; | ||
151 | } | ||
152 | |||
153 | static int rtc_remove(struct amba_device *dev) | ||
154 | { | ||
155 | set_rtc = NULL; | ||
156 | |||
157 | writel(0, rtc_base + RTC_CR); | ||
158 | |||
159 | free_irq(dev->irq[0], dev); | ||
160 | unregister_rtc(&rtc_ops); | ||
161 | |||
162 | iounmap(rtc_base); | ||
163 | rtc_base = NULL; | ||
164 | amba_release_regions(dev); | ||
165 | |||
166 | return 0; | ||
167 | } | ||
168 | |||
169 | static struct timespec rtc_delta; | ||
170 | |||
171 | static int rtc_suspend(struct amba_device *dev, pm_message_t state) | ||
172 | { | ||
173 | struct timespec rtc; | ||
174 | |||
175 | rtc.tv_sec = readl(rtc_base + RTC_DR); | ||
176 | rtc.tv_nsec = 0; | ||
177 | save_time_delta(&rtc_delta, &rtc); | ||
178 | |||
179 | return 0; | ||
180 | } | ||
181 | |||
182 | static int rtc_resume(struct amba_device *dev) | ||
183 | { | ||
184 | struct timespec rtc; | ||
185 | |||
186 | rtc.tv_sec = readl(rtc_base + RTC_DR); | ||
187 | rtc.tv_nsec = 0; | ||
188 | restore_time_delta(&rtc_delta, &rtc); | ||
189 | |||
190 | return 0; | ||
191 | } | ||
192 | |||
193 | static struct amba_id rtc_ids[] = { | ||
194 | { | ||
195 | .id = 0x00041030, | ||
196 | .mask = 0x000fffff, | ||
197 | }, | ||
198 | { 0, 0 }, | ||
199 | }; | ||
200 | |||
201 | static struct amba_driver rtc_driver = { | ||
202 | .drv = { | ||
203 | .name = "rtc-pl030", | ||
204 | }, | ||
205 | .probe = rtc_probe, | ||
206 | .remove = rtc_remove, | ||
207 | .suspend = rtc_suspend, | ||
208 | .resume = rtc_resume, | ||
209 | .id_table = rtc_ids, | ||
210 | }; | ||
211 | |||
212 | static int __init integrator_rtc_init(void) | ||
213 | { | ||
214 | return amba_driver_register(&rtc_driver); | ||
215 | } | ||
216 | |||
217 | static void __exit integrator_rtc_exit(void) | ||
218 | { | ||
219 | amba_driver_unregister(&rtc_driver); | ||
220 | } | ||
221 | |||
222 | module_init(integrator_rtc_init); | ||
223 | module_exit(integrator_rtc_exit); | ||
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig index 6cc2c0330230..1b26eeb52c97 100644 --- a/drivers/rtc/Kconfig +++ b/drivers/rtc/Kconfig | |||
@@ -458,6 +458,16 @@ config RTC_DRV_VR41XX | |||
458 | To compile this driver as a module, choose M here: the | 458 | To compile this driver as a module, choose M here: the |
459 | module will be called rtc-vr41xx. | 459 | module will be called rtc-vr41xx. |
460 | 460 | ||
461 | config RTC_DRV_PL030 | ||
462 | tristate "ARM AMBA PL030 RTC" | ||
463 | depends on ARM_AMBA | ||
464 | help | ||
465 | If you say Y here you will get access to ARM AMBA | ||
466 | PrimeCell PL030 RTC found on certain ARM SOCs. | ||
467 | |||
468 | To compile this driver as a module, choose M here: the | ||
469 | module will be called rtc-pl030. | ||
470 | |||
461 | config RTC_DRV_PL031 | 471 | config RTC_DRV_PL031 |
462 | tristate "ARM AMBA PL031 RTC" | 472 | tristate "ARM AMBA PL031 RTC" |
463 | depends on ARM_AMBA | 473 | depends on ARM_AMBA |
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile index 872f1218ff9f..af3ee6652ce5 100644 --- a/drivers/rtc/Makefile +++ b/drivers/rtc/Makefile | |||
@@ -40,6 +40,7 @@ obj-$(CONFIG_RTC_DRV_MAX6902) += rtc-max6902.o | |||
40 | obj-$(CONFIG_RTC_DRV_OMAP) += rtc-omap.o | 40 | obj-$(CONFIG_RTC_DRV_OMAP) += rtc-omap.o |
41 | obj-$(CONFIG_RTC_DRV_PCF8563) += rtc-pcf8563.o | 41 | obj-$(CONFIG_RTC_DRV_PCF8563) += rtc-pcf8563.o |
42 | obj-$(CONFIG_RTC_DRV_PCF8583) += rtc-pcf8583.o | 42 | obj-$(CONFIG_RTC_DRV_PCF8583) += rtc-pcf8583.o |
43 | obj-$(CONFIG_RTC_DRV_PL030) += rtc-pl030.o | ||
43 | obj-$(CONFIG_RTC_DRV_PL031) += rtc-pl031.o | 44 | obj-$(CONFIG_RTC_DRV_PL031) += rtc-pl031.o |
44 | obj-$(CONFIG_RTC_DRV_R9701) += rtc-r9701.o | 45 | obj-$(CONFIG_RTC_DRV_R9701) += rtc-r9701.o |
45 | obj-$(CONFIG_RTC_DRV_RS5C313) += rtc-rs5c313.o | 46 | obj-$(CONFIG_RTC_DRV_RS5C313) += rtc-rs5c313.o |
diff --git a/drivers/rtc/rtc-pl030.c b/drivers/rtc/rtc-pl030.c new file mode 100644 index 000000000000..8448eeb9d675 --- /dev/null +++ b/drivers/rtc/rtc-pl030.c | |||
@@ -0,0 +1,217 @@ | |||
1 | /* | ||
2 | * linux/drivers/rtc/rtc-pl030.c | ||
3 | * | ||
4 | * Copyright (C) 2000-2001 Deep Blue Solutions Ltd. | ||
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 version 2 as | ||
8 | * published by the Free Software Foundation. | ||
9 | */ | ||
10 | #include <linux/module.h> | ||
11 | #include <linux/rtc.h> | ||
12 | #include <linux/init.h> | ||
13 | #include <linux/interrupt.h> | ||
14 | #include <linux/amba/bus.h> | ||
15 | #include <linux/io.h> | ||
16 | |||
17 | #define RTC_DR (0) | ||
18 | #define RTC_MR (4) | ||
19 | #define RTC_STAT (8) | ||
20 | #define RTC_EOI (8) | ||
21 | #define RTC_LR (12) | ||
22 | #define RTC_CR (16) | ||
23 | #define RTC_CR_MIE (1 << 0) | ||
24 | |||
25 | struct pl030_rtc { | ||
26 | struct rtc_device *rtc; | ||
27 | void __iomem *base; | ||
28 | }; | ||
29 | |||
30 | static irqreturn_t pl030_interrupt(int irq, void *dev_id) | ||
31 | { | ||
32 | struct pl030_rtc *rtc = dev_id; | ||
33 | writel(0, rtc->base + RTC_EOI); | ||
34 | return IRQ_HANDLED; | ||
35 | } | ||
36 | |||
37 | static int pl030_open(struct device *dev) | ||
38 | { | ||
39 | return 0; | ||
40 | } | ||
41 | |||
42 | static void pl030_release(struct device *dev) | ||
43 | { | ||
44 | } | ||
45 | |||
46 | static int pl030_ioctl(struct device *dev, unsigned int cmd, unsigned long arg) | ||
47 | { | ||
48 | return -ENOIOCTLCMD; | ||
49 | } | ||
50 | |||
51 | static int pl030_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) | ||
52 | { | ||
53 | struct pl030_rtc *rtc = dev_get_drvdata(dev); | ||
54 | |||
55 | rtc_time_to_tm(readl(rtc->base + RTC_MR), &alrm->time); | ||
56 | return 0; | ||
57 | } | ||
58 | |||
59 | static int pl030_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) | ||
60 | { | ||
61 | struct pl030_rtc *rtc = dev_get_drvdata(dev); | ||
62 | unsigned long time; | ||
63 | int ret; | ||
64 | |||
65 | /* | ||
66 | * At the moment, we can only deal with non-wildcarded alarm times. | ||
67 | */ | ||
68 | ret = rtc_valid_tm(&alrm->time); | ||
69 | if (ret == 0) | ||
70 | ret = rtc_tm_to_time(&alrm->time, &time); | ||
71 | if (ret == 0) | ||
72 | writel(time, rtc->base + RTC_MR); | ||
73 | return ret; | ||
74 | } | ||
75 | |||
76 | static int pl030_read_time(struct device *dev, struct rtc_time *tm) | ||
77 | { | ||
78 | struct pl030_rtc *rtc = dev_get_drvdata(dev); | ||
79 | |||
80 | rtc_time_to_tm(readl(rtc->base + RTC_DR), tm); | ||
81 | |||
82 | return 0; | ||
83 | } | ||
84 | |||
85 | /* | ||
86 | * Set the RTC time. Unfortunately, we can't accurately set | ||
87 | * the point at which the counter updates. | ||
88 | * | ||
89 | * Also, since RTC_LR is transferred to RTC_CR on next rising | ||
90 | * edge of the 1Hz clock, we must write the time one second | ||
91 | * in advance. | ||
92 | */ | ||
93 | static int pl030_set_time(struct device *dev, struct rtc_time *tm) | ||
94 | { | ||
95 | struct pl030_rtc *rtc = dev_get_drvdata(dev); | ||
96 | unsigned long time; | ||
97 | int ret; | ||
98 | |||
99 | ret = rtc_tm_to_time(tm, &time); | ||
100 | if (ret == 0) | ||
101 | writel(time + 1, rtc->base + RTC_LR); | ||
102 | |||
103 | return ret; | ||
104 | } | ||
105 | |||
106 | static const struct rtc_class_ops pl030_ops = { | ||
107 | .open = pl030_open, | ||
108 | .release = pl030_release, | ||
109 | .ioctl = pl030_ioctl, | ||
110 | .read_time = pl030_read_time, | ||
111 | .set_time = pl030_set_time, | ||
112 | .read_alarm = pl030_read_alarm, | ||
113 | .set_alarm = pl030_set_alarm, | ||
114 | }; | ||
115 | |||
116 | static int pl030_probe(struct amba_device *dev, void *id) | ||
117 | { | ||
118 | struct pl030_rtc *rtc; | ||
119 | int ret; | ||
120 | |||
121 | ret = amba_request_regions(dev, NULL); | ||
122 | if (ret) | ||
123 | goto err_req; | ||
124 | |||
125 | rtc = kmalloc(sizeof(*rtc), GFP_KERNEL); | ||
126 | if (!rtc) { | ||
127 | ret = -ENOMEM; | ||
128 | goto err_rtc; | ||
129 | } | ||
130 | |||
131 | rtc->base = ioremap(dev->res.start, SZ_4K); | ||
132 | if (!rtc->base) { | ||
133 | ret = -ENOMEM; | ||
134 | goto err_map; | ||
135 | } | ||
136 | |||
137 | __raw_writel(0, rtc->base + RTC_CR); | ||
138 | __raw_writel(0, rtc->base + RTC_EOI); | ||
139 | |||
140 | amba_set_drvdata(dev, rtc); | ||
141 | |||
142 | ret = request_irq(dev->irq[0], pl030_interrupt, IRQF_DISABLED, | ||
143 | "rtc-pl030", rtc); | ||
144 | if (ret) | ||
145 | goto err_irq; | ||
146 | |||
147 | rtc->rtc = rtc_device_register("pl030", &dev->dev, &pl030_ops, | ||
148 | THIS_MODULE); | ||
149 | if (IS_ERR(rtc->rtc)) { | ||
150 | ret = PTR_ERR(rtc->rtc); | ||
151 | goto err_reg; | ||
152 | } | ||
153 | |||
154 | return 0; | ||
155 | |||
156 | err_reg: | ||
157 | free_irq(dev->irq[0], rtc); | ||
158 | err_irq: | ||
159 | iounmap(rtc->base); | ||
160 | err_map: | ||
161 | kfree(rtc); | ||
162 | err_rtc: | ||
163 | amba_release_regions(dev); | ||
164 | err_req: | ||
165 | return ret; | ||
166 | } | ||
167 | |||
168 | static int pl030_remove(struct amba_device *dev) | ||
169 | { | ||
170 | struct pl030_rtc *rtc = amba_get_drvdata(dev); | ||
171 | |||
172 | amba_set_drvdata(dev, NULL); | ||
173 | |||
174 | writel(0, rtc->base + RTC_CR); | ||
175 | |||
176 | free_irq(dev->irq[0], rtc); | ||
177 | rtc_device_unregister(rtc->rtc); | ||
178 | iounmap(rtc->base); | ||
179 | kfree(rtc); | ||
180 | amba_release_regions(dev); | ||
181 | |||
182 | return 0; | ||
183 | } | ||
184 | |||
185 | static struct amba_id pl030_ids[] = { | ||
186 | { | ||
187 | .id = 0x00041030, | ||
188 | .mask = 0x000fffff, | ||
189 | }, | ||
190 | { 0, 0 }, | ||
191 | }; | ||
192 | |||
193 | static struct amba_driver pl030_driver = { | ||
194 | .drv = { | ||
195 | .name = "rtc-pl030", | ||
196 | }, | ||
197 | .probe = pl030_probe, | ||
198 | .remove = pl030_remove, | ||
199 | .id_table = pl030_ids, | ||
200 | }; | ||
201 | |||
202 | static int __init pl030_init(void) | ||
203 | { | ||
204 | return amba_driver_register(&pl030_driver); | ||
205 | } | ||
206 | |||
207 | static void __exit pl030_exit(void) | ||
208 | { | ||
209 | amba_driver_unregister(&pl030_driver); | ||
210 | } | ||
211 | |||
212 | module_init(pl030_init); | ||
213 | module_exit(pl030_exit); | ||
214 | |||
215 | MODULE_AUTHOR("Russell King <rmk@arm.linux.org.uk>"); | ||
216 | MODULE_DESCRIPTION("ARM AMBA PL030 RTC Driver"); | ||
217 | MODULE_LICENSE("GPL"); | ||