ramips: register ethernet device on the WHR-G300N and V22RW-2x2 boards
[openwrt.git] / target / linux / goldfish / patches-2.6.30 / 0127--ARM-goldfish-RTC-Add-RTC-driver-for-goldfish.patch
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.
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=utf-8
7 Content-Transfer-Encoding: 8bit
8
9 Gets the current time from the host.
10 Alarms are not supported yet.
11
12 Signed-off-by: Mike A. Chan <mikechan@google.com>
13 Signed-off-by: Arve Hjønnevåg <arve@android.com>
14 ---
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
20
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.
26
27 +config RTC_DRV_GOLDFISH
28 + tristate "GOLDFISH"
29 + depends on ARCH_GOLDFISH
30 + help
31 + RTC driver for Goldfish Virtual Platform
32 +
33 config RTC_DRV_RS5C313
34 tristate "Ricoh RS5C313"
35 depends on SH_LANDISK
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
46 --- /dev/null
47 +++ b/drivers/rtc/rtc-goldfish.c
48 @@ -0,0 +1,138 @@
49 +/* drivers/rtc/rtc-goldfish.c
50 +**
51 +** Copyright (C) 2007 Google, Inc.
52 +**
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.
56 +**
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.
61 +**
62 +*/
63 +
64 +#include <linux/interrupt.h>
65 +#include <linux/irq.h>
66 +#include <linux/platform_device.h>
67 +#include <linux/rtc.h>
68 +
69 +#include <mach/timer.h>
70 +#include <mach/hardware.h>
71 +#include <asm/io.h>
72 +
73 +struct goldfish_rtc {
74 + uint32_t base;
75 + uint32_t irq;
76 + struct rtc_device *rtc;
77 +};
78 +
79 +static irqreturn_t
80 +goldfish_rtc_interrupt(int irq, void *dev_id)
81 +{
82 + struct goldfish_rtc *qrtc = dev_id;
83 + unsigned long events = 0;
84 +
85 + writel(1, qrtc->base + TIMER_CLEAR_INTERRUPT);
86 + events = RTC_IRQF | RTC_AF;
87 +
88 + rtc_update_irq(qrtc->rtc, 1, events);
89 +
90 + return IRQ_HANDLED;
91 +}
92 +
93 +static int goldfish_rtc_read_time(struct device *dev, struct rtc_time *tm)
94 +{
95 + int64_t time;
96 + struct goldfish_rtc *qrtc = platform_get_drvdata(to_platform_device(dev));
97 +
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);
101 +
102 + rtc_time_to_tm(time, tm);
103 + return 0;
104 +}
105 +
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,
112 +};
113 +
114 +
115 +static int goldfish_rtc_probe(struct platform_device *pdev)
116 +{
117 + int ret;
118 + struct resource *r;
119 + struct goldfish_rtc *qrtc;
120 +
121 + qrtc = kzalloc(sizeof(*qrtc), GFP_KERNEL);
122 + if(qrtc == NULL) {
123 + ret = -ENOMEM;
124 + goto err_qrtc_alloc_failed;
125 + }
126 + platform_set_drvdata(pdev, qrtc);
127 +
128 + r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
129 + if(r == NULL) {
130 + ret = -ENODEV;
131 + goto err_no_io_base;
132 + }
133 + qrtc->base = IO_ADDRESS(r->start - IO_START);
134 + qrtc->irq = platform_get_irq(pdev, 0);
135 + if(qrtc->irq < 0) {
136 + ret = -ENODEV;
137 + goto err_no_irq;
138 + }
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;
144 + }
145 +
146 + ret = request_irq(qrtc->irq, goldfish_rtc_interrupt, 0, pdev->name, qrtc);
147 + if(ret)
148 + goto request_irq;
149 +
150 + return 0;
151 +
152 + free_irq(qrtc->irq, qrtc);
153 +request_irq:
154 + rtc_device_unregister(qrtc->rtc);
155 +err_rtc_device_register_failed:
156 +err_no_irq:
157 +err_no_io_base:
158 + kfree(qrtc);
159 +err_qrtc_alloc_failed:
160 + return ret;
161 +}
162 +
163 +static int goldfish_rtc_remove(struct platform_device *pdev)
164 +{
165 + struct goldfish_rtc *qrtc = platform_get_drvdata(pdev);
166 + free_irq(qrtc->irq, qrtc);
167 + rtc_device_unregister(qrtc->rtc);
168 + kfree(qrtc);
169 + return 0;
170 +}
171 +
172 +static struct platform_driver goldfish_timer = {
173 + .probe = goldfish_rtc_probe,
174 + .remove = goldfish_rtc_remove,
175 + .driver = {
176 + .name = "goldfish_rtc"
177 + }
178 +};
179 +
180 +static int __init goldfish_rtc_init(void)
181 +{
182 + return platform_driver_register(&goldfish_timer);
183 +}
184 +
185 +module_init(goldfish_rtc_init);
186 +
This page took 0.056455 seconds and 5 git commands to generate.