diff options
author | Rob Herring <robh@kernel.org> | 2015-05-12 17:23:23 -0400 |
---|---|---|
committer | Alexandre Belloni <alexandre.belloni@free-electrons.com> | 2015-09-05 13:37:15 -0400 |
commit | 8c0961ba7c9356186a0606a391f08e2ecb491a57 (patch) | |
tree | dfcd9e54d61e118f2a805acbc240ec8143bd43e2 /drivers/rtc | |
parent | dc2280ebf45bfa4fbc4b1588a6642aa33454a9b8 (diff) |
rtc: sa1100: prepare to share sa1100_rtc_ops
Factor out the RTC initialization from the platform device specific
parts in order to share the RTC device ops with other drivers.
Specifically, it will be shared with rtc-pxa driver.
Signed-off-by: Rob Herring <robh@kernel.org>
Cc: Robert Jarzmik <robert.jarzmik@free.fr>
Cc: Russell King <linux@arm.linux.org.uk>
Cc: Alessandro Zummo <a.zummo@towertech.it>
Cc: Alexandre Belloni <alexandre.belloni@free-electrons.com>
Cc: rtc-linux@googlegroups.com
Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
Diffstat (limited to 'drivers/rtc')
-rw-r--r-- | drivers/rtc/rtc-sa1100.c | 59 | ||||
-rw-r--r-- | drivers/rtc/rtc-sa1100.h | 19 |
2 files changed, 49 insertions, 29 deletions
diff --git a/drivers/rtc/rtc-sa1100.c b/drivers/rtc/rtc-sa1100.c index b6e1ca08c2c0..abc19abd5f2d 100644 --- a/drivers/rtc/rtc-sa1100.c +++ b/drivers/rtc/rtc-sa1100.c | |||
@@ -42,17 +42,12 @@ | |||
42 | #include <mach/regs-rtc.h> | 42 | #include <mach/regs-rtc.h> |
43 | #endif | 43 | #endif |
44 | 44 | ||
45 | #include "rtc-sa1100.h" | ||
46 | |||
45 | #define RTC_DEF_DIVIDER (32768 - 1) | 47 | #define RTC_DEF_DIVIDER (32768 - 1) |
46 | #define RTC_DEF_TRIM 0 | 48 | #define RTC_DEF_TRIM 0 |
47 | #define RTC_FREQ 1024 | 49 | #define RTC_FREQ 1024 |
48 | 50 | ||
49 | struct sa1100_rtc { | ||
50 | spinlock_t lock; | ||
51 | int irq_1hz; | ||
52 | int irq_alarm; | ||
53 | struct rtc_device *rtc; | ||
54 | struct clk *clk; | ||
55 | }; | ||
56 | 51 | ||
57 | static irqreturn_t sa1100_rtc_interrupt(int irq, void *dev_id) | 52 | static irqreturn_t sa1100_rtc_interrupt(int irq, void *dev_id) |
58 | { | 53 | { |
@@ -223,29 +218,18 @@ static const struct rtc_class_ops sa1100_rtc_ops = { | |||
223 | .alarm_irq_enable = sa1100_rtc_alarm_irq_enable, | 218 | .alarm_irq_enable = sa1100_rtc_alarm_irq_enable, |
224 | }; | 219 | }; |
225 | 220 | ||
226 | static int sa1100_rtc_probe(struct platform_device *pdev) | 221 | int sa1100_rtc_init(struct platform_device *pdev, struct sa1100_rtc *info) |
227 | { | 222 | { |
228 | struct rtc_device *rtc; | 223 | struct rtc_device *rtc; |
229 | struct sa1100_rtc *info; | 224 | int ret; |
230 | int irq_1hz, irq_alarm, ret = 0; | ||
231 | 225 | ||
232 | irq_1hz = platform_get_irq_byname(pdev, "rtc 1Hz"); | 226 | spin_lock_init(&info->lock); |
233 | irq_alarm = platform_get_irq_byname(pdev, "rtc alarm"); | ||
234 | if (irq_1hz < 0 || irq_alarm < 0) | ||
235 | return -ENODEV; | ||
236 | 227 | ||
237 | info = devm_kzalloc(&pdev->dev, sizeof(struct sa1100_rtc), GFP_KERNEL); | ||
238 | if (!info) | ||
239 | return -ENOMEM; | ||
240 | info->clk = devm_clk_get(&pdev->dev, NULL); | 228 | info->clk = devm_clk_get(&pdev->dev, NULL); |
241 | if (IS_ERR(info->clk)) { | 229 | if (IS_ERR(info->clk)) { |
242 | dev_err(&pdev->dev, "failed to find rtc clock source\n"); | 230 | dev_err(&pdev->dev, "failed to find rtc clock source\n"); |
243 | return PTR_ERR(info->clk); | 231 | return PTR_ERR(info->clk); |
244 | } | 232 | } |
245 | info->irq_1hz = irq_1hz; | ||
246 | info->irq_alarm = irq_alarm; | ||
247 | spin_lock_init(&info->lock); | ||
248 | platform_set_drvdata(pdev, info); | ||
249 | 233 | ||
250 | ret = clk_prepare_enable(info->clk); | 234 | ret = clk_prepare_enable(info->clk); |
251 | if (ret) | 235 | if (ret) |
@@ -265,14 +249,11 @@ static int sa1100_rtc_probe(struct platform_device *pdev) | |||
265 | RCNR = 0; | 249 | RCNR = 0; |
266 | } | 250 | } |
267 | 251 | ||
268 | device_init_wakeup(&pdev->dev, 1); | ||
269 | |||
270 | rtc = devm_rtc_device_register(&pdev->dev, pdev->name, &sa1100_rtc_ops, | 252 | rtc = devm_rtc_device_register(&pdev->dev, pdev->name, &sa1100_rtc_ops, |
271 | THIS_MODULE); | 253 | THIS_MODULE); |
272 | |||
273 | if (IS_ERR(rtc)) { | 254 | if (IS_ERR(rtc)) { |
274 | ret = PTR_ERR(rtc); | 255 | clk_disable_unprepare(info->clk); |
275 | goto err_dev; | 256 | return PTR_ERR(rtc); |
276 | } | 257 | } |
277 | info->rtc = rtc; | 258 | info->rtc = rtc; |
278 | 259 | ||
@@ -301,9 +282,29 @@ static int sa1100_rtc_probe(struct platform_device *pdev) | |||
301 | RTSR = RTSR_AL | RTSR_HZ; | 282 | RTSR = RTSR_AL | RTSR_HZ; |
302 | 283 | ||
303 | return 0; | 284 | return 0; |
304 | err_dev: | 285 | } |
305 | clk_disable_unprepare(info->clk); | 286 | EXPORT_SYMBOL_GPL(sa1100_rtc_init); |
306 | return ret; | 287 | |
288 | static int sa1100_rtc_probe(struct platform_device *pdev) | ||
289 | { | ||
290 | struct sa1100_rtc *info; | ||
291 | int irq_1hz, irq_alarm; | ||
292 | |||
293 | irq_1hz = platform_get_irq_byname(pdev, "rtc 1Hz"); | ||
294 | irq_alarm = platform_get_irq_byname(pdev, "rtc alarm"); | ||
295 | if (irq_1hz < 0 || irq_alarm < 0) | ||
296 | return -ENODEV; | ||
297 | |||
298 | info = devm_kzalloc(&pdev->dev, sizeof(struct sa1100_rtc), GFP_KERNEL); | ||
299 | if (!info) | ||
300 | return -ENOMEM; | ||
301 | info->irq_1hz = irq_1hz; | ||
302 | info->irq_alarm = irq_alarm; | ||
303 | |||
304 | platform_set_drvdata(pdev, info); | ||
305 | device_init_wakeup(&pdev->dev, 1); | ||
306 | |||
307 | return sa1100_rtc_init(pdev, info); | ||
307 | } | 308 | } |
308 | 309 | ||
309 | static int sa1100_rtc_remove(struct platform_device *pdev) | 310 | static int sa1100_rtc_remove(struct platform_device *pdev) |
diff --git a/drivers/rtc/rtc-sa1100.h b/drivers/rtc/rtc-sa1100.h new file mode 100644 index 000000000000..665d054740a1 --- /dev/null +++ b/drivers/rtc/rtc-sa1100.h | |||
@@ -0,0 +1,19 @@ | |||
1 | #ifndef __RTC_SA1100_H__ | ||
2 | #define __RTC_SA1100_H__ | ||
3 | |||
4 | #include <linux/kernel.h> | ||
5 | |||
6 | struct clk; | ||
7 | struct platform_device; | ||
8 | |||
9 | struct sa1100_rtc { | ||
10 | spinlock_t lock; | ||
11 | int irq_1hz; | ||
12 | int irq_alarm; | ||
13 | struct rtc_device *rtc; | ||
14 | struct clk *clk; | ||
15 | }; | ||
16 | |||
17 | int sa1100_rtc_init(struct platform_device *pdev, struct sa1100_rtc *info); | ||
18 | |||
19 | #endif | ||