2 * linux/drivers/rtc/rtc-pl030.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/rtc.h>
12 #include <linux/init.h>
13 #include <linux/interrupt.h>
14 #include <linux/amba/bus.h>
16 #include <linux/slab.h>
24 #define RTC_CR_MIE (1 << 0)
27 struct rtc_device *rtc;
31 static irqreturn_t pl030_interrupt(int irq, void *dev_id)
33 struct pl030_rtc *rtc = dev_id;
34 writel(0, rtc->base + RTC_EOI);
38 static int pl030_ioctl(struct device *dev, unsigned int cmd, unsigned long arg)
43 static int pl030_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
45 struct pl030_rtc *rtc = dev_get_drvdata(dev);
47 rtc_time_to_tm(readl(rtc->base + RTC_MR), &alrm->time);
51 static int pl030_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
53 struct pl030_rtc *rtc = dev_get_drvdata(dev);
58 * At the moment, we can only deal with non-wildcarded alarm times.
60 ret = rtc_valid_tm(&alrm->time);
62 ret = rtc_tm_to_time(&alrm->time, &time);
64 writel(time, rtc->base + RTC_MR);
68 static int pl030_read_time(struct device *dev, struct rtc_time *tm)
70 struct pl030_rtc *rtc = dev_get_drvdata(dev);
72 rtc_time_to_tm(readl(rtc->base + RTC_DR), tm);
78 * Set the RTC time. Unfortunately, we can't accurately set
79 * the point at which the counter updates.
81 * Also, since RTC_LR is transferred to RTC_CR on next rising
82 * edge of the 1Hz clock, we must write the time one second
85 static int pl030_set_time(struct device *dev, struct rtc_time *tm)
87 struct pl030_rtc *rtc = dev_get_drvdata(dev);
91 ret = rtc_tm_to_time(tm, &time);
93 writel(time + 1, rtc->base + RTC_LR);
98 static const struct rtc_class_ops pl030_ops = {
100 .read_time = pl030_read_time,
101 .set_time = pl030_set_time,
102 .read_alarm = pl030_read_alarm,
103 .set_alarm = pl030_set_alarm,
106 static int pl030_probe(struct amba_device *dev, struct amba_id *id)
108 struct pl030_rtc *rtc;
111 ret = amba_request_regions(dev, NULL);
115 rtc = kmalloc(sizeof(*rtc), GFP_KERNEL);
121 rtc->base = ioremap(dev->res.start, resource_size(&dev->res));
127 __raw_writel(0, rtc->base + RTC_CR);
128 __raw_writel(0, rtc->base + RTC_EOI);
130 amba_set_drvdata(dev, rtc);
132 ret = request_irq(dev->irq[0], pl030_interrupt, IRQF_DISABLED,
137 rtc->rtc = rtc_device_register("pl030", &dev->dev, &pl030_ops,
139 if (IS_ERR(rtc->rtc)) {
140 ret = PTR_ERR(rtc->rtc);
147 free_irq(dev->irq[0], rtc);
153 amba_release_regions(dev);
158 static int pl030_remove(struct amba_device *dev)
160 struct pl030_rtc *rtc = amba_get_drvdata(dev);
162 amba_set_drvdata(dev, NULL);
164 writel(0, rtc->base + RTC_CR);
166 free_irq(dev->irq[0], rtc);
167 rtc_device_unregister(rtc->rtc);
170 amba_release_regions(dev);
175 static struct amba_id pl030_ids[] = {
183 static struct amba_driver pl030_driver = {
187 .probe = pl030_probe,
188 .remove = pl030_remove,
189 .id_table = pl030_ids,
192 static int __init pl030_init(void)
194 return amba_driver_register(&pl030_driver);
197 static void __exit pl030_exit(void)
199 amba_driver_unregister(&pl030_driver);
202 module_init(pl030_init);
203 module_exit(pl030_exit);
205 MODULE_AUTHOR("Russell King <rmk@arm.linux.org.uk>");
206 MODULE_DESCRIPTION("ARM AMBA PL030 RTC Driver");
207 MODULE_LICENSE("GPL");