1 From fce981438497199217ed19f14c4d0f1a1aa309f3 Mon Sep 17 00:00:00 2001
2 From: =?utf-8?q?Arve=20Hj=C3=B8nnev=C3=A5g?= <arve@google.com>
3 Date: Fri, 29 Jun 2007 21:46:31 -0700
4 Subject: [PATCH 127/134] [ARM] goldfish: RTC: Add RTC driver for goldfish.
6 Content-Type: text/plain; charset=utf-8
7 Content-Transfer-Encoding: 8bit
9 Gets the current time from the host.
10 Alarms are not supported yet.
12 Signed-off-by: Mike A. Chan <mikechan@google.com>
13 Signed-off-by: Arve Hjønnevåg <arve@android.com>
15 drivers/rtc/Kconfig | 6 ++
16 drivers/rtc/Makefile | 1 +
17 drivers/rtc/rtc-goldfish.c | 138 ++++++++++++++++++++++++++++++++++++++++++++
18 3 files changed, 145 insertions(+), 0 deletions(-)
19 create mode 100644 drivers/rtc/rtc-goldfish.c
21 --- a/drivers/rtc/Kconfig
22 +++ b/drivers/rtc/Kconfig
23 @@ -691,6 +691,12 @@ config RTC_DRV_BFIN
24 This driver can also be built as a module. If so, the module
25 will be called rtc-bfin.
27 +config RTC_DRV_GOLDFISH
29 + depends on ARCH_GOLDFISH
31 + RTC driver for Goldfish Virtual Platform
33 config RTC_DRV_RS5C313
34 tristate "Ricoh RS5C313"
36 --- a/drivers/rtc/Makefile
37 +++ b/drivers/rtc/Makefile
38 @@ -39,6 +39,7 @@ obj-$(CONFIG_RTC_DRV_DS3234) += rtc-ds32
39 obj-$(CONFIG_RTC_DRV_EFI) += rtc-efi.o
40 obj-$(CONFIG_RTC_DRV_EP93XX) += rtc-ep93xx.o
41 obj-$(CONFIG_RTC_DRV_FM3130) += rtc-fm3130.o
42 +obj-$(CONFIG_RTC_DRV_GOLDFISH) += rtc-goldfish.o
43 obj-$(CONFIG_RTC_DRV_ISL1208) += rtc-isl1208.o
44 obj-$(CONFIG_RTC_DRV_M41T80) += rtc-m41t80.o
45 obj-$(CONFIG_RTC_DRV_M41T94) += rtc-m41t94.o
47 +++ b/drivers/rtc/rtc-goldfish.c
49 +/* drivers/rtc/rtc-goldfish.c
51 +** Copyright (C) 2007 Google, Inc.
53 +** This software is licensed under the terms of the GNU General Public
54 +** License version 2, as published by the Free Software Foundation, and
55 +** may be copied, distributed, and modified under those terms.
57 +** This program is distributed in the hope that it will be useful,
58 +** but WITHOUT ANY WARRANTY; without even the implied warranty of
59 +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
60 +** GNU General Public License for more details.
64 +#include <linux/interrupt.h>
65 +#include <linux/irq.h>
66 +#include <linux/platform_device.h>
67 +#include <linux/rtc.h>
69 +#include <mach/timer.h>
70 +#include <mach/hardware.h>
73 +struct goldfish_rtc {
76 + struct rtc_device *rtc;
80 +goldfish_rtc_interrupt(int irq, void *dev_id)
82 + struct goldfish_rtc *qrtc = dev_id;
83 + unsigned long events = 0;
85 + writel(1, qrtc->base + TIMER_CLEAR_INTERRUPT);
86 + events = RTC_IRQF | RTC_AF;
88 + rtc_update_irq(qrtc->rtc, 1, events);
93 +static int goldfish_rtc_read_time(struct device *dev, struct rtc_time *tm)
96 + struct goldfish_rtc *qrtc = platform_get_drvdata(to_platform_device(dev));
98 + time = readl(qrtc->base + TIMER_TIME_LOW);
99 + time |= (int64_t)readl(qrtc->base + TIMER_TIME_HIGH) << 32;
100 + do_div(time, NSEC_PER_SEC);
102 + rtc_time_to_tm(time, tm);
106 +static struct rtc_class_ops goldfish_rtc_ops = {
107 +// .ioctl = goldfish_rtc_ioctl,
108 + .read_time = goldfish_rtc_read_time,
109 +// .set_time = goldfish_rtc_set_time,
110 +// .read_alarm = goldfish_rtc_read_alarm,
111 +// .set_alarm = goldfish_rtc_set_alarm,
115 +static int goldfish_rtc_probe(struct platform_device *pdev)
118 + struct resource *r;
119 + struct goldfish_rtc *qrtc;
121 + qrtc = kzalloc(sizeof(*qrtc), GFP_KERNEL);
124 + goto err_qrtc_alloc_failed;
126 + platform_set_drvdata(pdev, qrtc);
128 + r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
131 + goto err_no_io_base;
133 + qrtc->base = IO_ADDRESS(r->start - IO_START);
134 + qrtc->irq = platform_get_irq(pdev, 0);
135 + if(qrtc->irq < 0) {
139 + qrtc->rtc = rtc_device_register(pdev->name, &pdev->dev,
140 + &goldfish_rtc_ops, THIS_MODULE);
141 + if (IS_ERR(qrtc->rtc)) {
142 + ret = PTR_ERR(qrtc->rtc);
143 + goto err_rtc_device_register_failed;
146 + ret = request_irq(qrtc->irq, goldfish_rtc_interrupt, 0, pdev->name, qrtc);
152 + free_irq(qrtc->irq, qrtc);
154 + rtc_device_unregister(qrtc->rtc);
155 +err_rtc_device_register_failed:
159 +err_qrtc_alloc_failed:
163 +static int goldfish_rtc_remove(struct platform_device *pdev)
165 + struct goldfish_rtc *qrtc = platform_get_drvdata(pdev);
166 + free_irq(qrtc->irq, qrtc);
167 + rtc_device_unregister(qrtc->rtc);
172 +static struct platform_driver goldfish_timer = {
173 + .probe = goldfish_rtc_probe,
174 + .remove = goldfish_rtc_remove,
176 + .name = "goldfish_rtc"
180 +static int __init goldfish_rtc_init(void)
182 + return platform_driver_register(&goldfish_timer);
185 +module_init(goldfish_rtc_init);