diff options
author | Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp> | 2007-05-11 08:18:48 -0400 |
---|---|---|
committer | Ralf Baechle <ralf@linux-mips.org> | 2007-07-12 12:41:15 -0400 |
commit | bd0765098bf22eb8b1319f649a4c3301b40ec04c (patch) | |
tree | 6c3960e12b9941c7fd73573081946bd7a16f5a5d /drivers | |
parent | 44173fb2e83183b585e137e6fee8ba32460f5645 (diff) |
[MIPS] separate platform_device registration for VR41xx RTC
Signed-off-by: Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/rtc/rtc-vr41xx.c | 186 |
1 files changed, 72 insertions, 114 deletions
diff --git a/drivers/rtc/rtc-vr41xx.c b/drivers/rtc/rtc-vr41xx.c index af7596ef29e2..ce2f78de7a80 100644 --- a/drivers/rtc/rtc-vr41xx.c +++ b/drivers/rtc/rtc-vr41xx.c | |||
@@ -17,10 +17,11 @@ | |||
17 | * along with this program; if not, write to the Free Software | 17 | * along with this program; if not, write to the Free Software |
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
19 | */ | 19 | */ |
20 | #include <linux/err.h> | ||
20 | #include <linux/fs.h> | 21 | #include <linux/fs.h> |
21 | #include <linux/init.h> | 22 | #include <linux/init.h> |
22 | #include <linux/ioport.h> | 23 | #include <linux/ioport.h> |
23 | #include <linux/irq.h> | 24 | #include <linux/interrupt.h> |
24 | #include <linux/module.h> | 25 | #include <linux/module.h> |
25 | #include <linux/platform_device.h> | 26 | #include <linux/platform_device.h> |
26 | #include <linux/rtc.h> | 27 | #include <linux/rtc.h> |
@@ -30,25 +31,11 @@ | |||
30 | #include <asm/div64.h> | 31 | #include <asm/div64.h> |
31 | #include <asm/io.h> | 32 | #include <asm/io.h> |
32 | #include <asm/uaccess.h> | 33 | #include <asm/uaccess.h> |
33 | #include <asm/vr41xx/irq.h> | ||
34 | 34 | ||
35 | MODULE_AUTHOR("Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>"); | 35 | MODULE_AUTHOR("Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>"); |
36 | MODULE_DESCRIPTION("NEC VR4100 series RTC driver"); | 36 | MODULE_DESCRIPTION("NEC VR4100 series RTC driver"); |
37 | MODULE_LICENSE("GPL"); | 37 | MODULE_LICENSE("GPL"); |
38 | 38 | ||
39 | #define RTC1_TYPE1_START 0x0b0000c0UL | ||
40 | #define RTC1_TYPE1_END 0x0b0000dfUL | ||
41 | #define RTC2_TYPE1_START 0x0b0001c0UL | ||
42 | #define RTC2_TYPE1_END 0x0b0001dfUL | ||
43 | |||
44 | #define RTC1_TYPE2_START 0x0f000100UL | ||
45 | #define RTC1_TYPE2_END 0x0f00011fUL | ||
46 | #define RTC2_TYPE2_START 0x0f000120UL | ||
47 | #define RTC2_TYPE2_END 0x0f00013fUL | ||
48 | |||
49 | #define RTC1_SIZE 0x20 | ||
50 | #define RTC2_SIZE 0x20 | ||
51 | |||
52 | /* RTC 1 registers */ | 39 | /* RTC 1 registers */ |
53 | #define ETIMELREG 0x00 | 40 | #define ETIMELREG 0x00 |
54 | #define ETIMEMREG 0x02 | 41 | #define ETIMEMREG 0x02 |
@@ -98,13 +85,8 @@ static char rtc_name[] = "RTC"; | |||
98 | static unsigned long periodic_frequency; | 85 | static unsigned long periodic_frequency; |
99 | static unsigned long periodic_count; | 86 | static unsigned long periodic_count; |
100 | static unsigned int alarm_enabled; | 87 | static unsigned int alarm_enabled; |
101 | 88 | static int aie_irq = -1; | |
102 | struct resource rtc_resource[2] = { | 89 | static int pie_irq = -1; |
103 | { .name = rtc_name, | ||
104 | .flags = IORESOURCE_MEM, }, | ||
105 | { .name = rtc_name, | ||
106 | .flags = IORESOURCE_MEM, }, | ||
107 | }; | ||
108 | 90 | ||
109 | static inline unsigned long read_elapsed_second(void) | 91 | static inline unsigned long read_elapsed_second(void) |
110 | { | 92 | { |
@@ -150,8 +132,8 @@ static void vr41xx_rtc_release(struct device *dev) | |||
150 | 132 | ||
151 | spin_unlock_irq(&rtc_lock); | 133 | spin_unlock_irq(&rtc_lock); |
152 | 134 | ||
153 | disable_irq(ELAPSEDTIME_IRQ); | 135 | disable_irq(aie_irq); |
154 | disable_irq(RTCLONG1_IRQ); | 136 | disable_irq(pie_irq); |
155 | } | 137 | } |
156 | 138 | ||
157 | static int vr41xx_rtc_read_time(struct device *dev, struct rtc_time *time) | 139 | static int vr41xx_rtc_read_time(struct device *dev, struct rtc_time *time) |
@@ -209,14 +191,14 @@ static int vr41xx_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *wkalrm) | |||
209 | spin_lock_irq(&rtc_lock); | 191 | spin_lock_irq(&rtc_lock); |
210 | 192 | ||
211 | if (alarm_enabled) | 193 | if (alarm_enabled) |
212 | disable_irq(ELAPSEDTIME_IRQ); | 194 | disable_irq(aie_irq); |
213 | 195 | ||
214 | rtc1_write(ECMPLREG, (uint16_t)(alarm_sec << 15)); | 196 | rtc1_write(ECMPLREG, (uint16_t)(alarm_sec << 15)); |
215 | rtc1_write(ECMPMREG, (uint16_t)(alarm_sec >> 1)); | 197 | rtc1_write(ECMPMREG, (uint16_t)(alarm_sec >> 1)); |
216 | rtc1_write(ECMPHREG, (uint16_t)(alarm_sec >> 17)); | 198 | rtc1_write(ECMPHREG, (uint16_t)(alarm_sec >> 17)); |
217 | 199 | ||
218 | if (wkalrm->enabled) | 200 | if (wkalrm->enabled) |
219 | enable_irq(ELAPSEDTIME_IRQ); | 201 | enable_irq(aie_irq); |
220 | 202 | ||
221 | alarm_enabled = wkalrm->enabled; | 203 | alarm_enabled = wkalrm->enabled; |
222 | 204 | ||
@@ -234,7 +216,7 @@ static int vr41xx_rtc_ioctl(struct device *dev, unsigned int cmd, unsigned long | |||
234 | spin_lock_irq(&rtc_lock); | 216 | spin_lock_irq(&rtc_lock); |
235 | 217 | ||
236 | if (!alarm_enabled) { | 218 | if (!alarm_enabled) { |
237 | enable_irq(ELAPSEDTIME_IRQ); | 219 | enable_irq(aie_irq); |
238 | alarm_enabled = 1; | 220 | alarm_enabled = 1; |
239 | } | 221 | } |
240 | 222 | ||
@@ -244,17 +226,17 @@ static int vr41xx_rtc_ioctl(struct device *dev, unsigned int cmd, unsigned long | |||
244 | spin_lock_irq(&rtc_lock); | 226 | spin_lock_irq(&rtc_lock); |
245 | 227 | ||
246 | if (alarm_enabled) { | 228 | if (alarm_enabled) { |
247 | disable_irq(ELAPSEDTIME_IRQ); | 229 | disable_irq(aie_irq); |
248 | alarm_enabled = 0; | 230 | alarm_enabled = 0; |
249 | } | 231 | } |
250 | 232 | ||
251 | spin_unlock_irq(&rtc_lock); | 233 | spin_unlock_irq(&rtc_lock); |
252 | break; | 234 | break; |
253 | case RTC_PIE_ON: | 235 | case RTC_PIE_ON: |
254 | enable_irq(RTCLONG1_IRQ); | 236 | enable_irq(pie_irq); |
255 | break; | 237 | break; |
256 | case RTC_PIE_OFF: | 238 | case RTC_PIE_OFF: |
257 | disable_irq(RTCLONG1_IRQ); | 239 | disable_irq(pie_irq); |
258 | break; | 240 | break; |
259 | case RTC_IRQP_READ: | 241 | case RTC_IRQP_READ: |
260 | return put_user(periodic_frequency, (unsigned long __user *)arg); | 242 | return put_user(periodic_frequency, (unsigned long __user *)arg); |
@@ -331,31 +313,37 @@ static const struct rtc_class_ops vr41xx_rtc_ops = { | |||
331 | 313 | ||
332 | static int __devinit rtc_probe(struct platform_device *pdev) | 314 | static int __devinit rtc_probe(struct platform_device *pdev) |
333 | { | 315 | { |
316 | struct resource *res; | ||
334 | struct rtc_device *rtc; | 317 | struct rtc_device *rtc; |
335 | unsigned int irq; | ||
336 | int retval; | 318 | int retval; |
337 | 319 | ||
338 | if (pdev->num_resources != 2) | 320 | if (pdev->num_resources != 4) |
339 | return -EBUSY; | 321 | return -EBUSY; |
340 | 322 | ||
341 | rtc1_base = ioremap(pdev->resource[0].start, RTC1_SIZE); | 323 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
342 | if (rtc1_base == NULL) | 324 | if (!res) |
343 | return -EBUSY; | 325 | return -EBUSY; |
344 | 326 | ||
345 | rtc2_base = ioremap(pdev->resource[1].start, RTC2_SIZE); | 327 | rtc1_base = ioremap(res->start, res->end - res->start + 1); |
346 | if (rtc2_base == NULL) { | 328 | if (!rtc1_base) |
347 | iounmap(rtc1_base); | ||
348 | rtc1_base = NULL; | ||
349 | return -EBUSY; | 329 | return -EBUSY; |
330 | |||
331 | res = platform_get_resource(pdev, IORESOURCE_MEM, 1); | ||
332 | if (!res) { | ||
333 | retval = -EBUSY; | ||
334 | goto err_rtc1_iounmap; | ||
335 | } | ||
336 | |||
337 | rtc2_base = ioremap(res->start, res->end - res->start + 1); | ||
338 | if (!rtc2_base) { | ||
339 | retval = -EBUSY; | ||
340 | goto err_rtc1_iounmap; | ||
350 | } | 341 | } |
351 | 342 | ||
352 | rtc = rtc_device_register(rtc_name, &pdev->dev, &vr41xx_rtc_ops, THIS_MODULE); | 343 | rtc = rtc_device_register(rtc_name, &pdev->dev, &vr41xx_rtc_ops, THIS_MODULE); |
353 | if (IS_ERR(rtc)) { | 344 | if (IS_ERR(rtc)) { |
354 | iounmap(rtc1_base); | 345 | retval = PTR_ERR(rtc); |
355 | iounmap(rtc2_base); | 346 | goto err_iounmap_all; |
356 | rtc1_base = NULL; | ||
357 | rtc2_base = NULL; | ||
358 | return PTR_ERR(rtc); | ||
359 | } | 347 | } |
360 | 348 | ||
361 | spin_lock_irq(&rtc_lock); | 349 | spin_lock_irq(&rtc_lock); |
@@ -368,35 +356,50 @@ static int __devinit rtc_probe(struct platform_device *pdev) | |||
368 | 356 | ||
369 | spin_unlock_irq(&rtc_lock); | 357 | spin_unlock_irq(&rtc_lock); |
370 | 358 | ||
371 | irq = ELAPSEDTIME_IRQ; | 359 | aie_irq = platform_get_irq(pdev, 0); |
372 | retval = request_irq(irq, elapsedtime_interrupt, IRQF_DISABLED, | 360 | if (aie_irq < 0 || aie_irq >= NR_IRQS) { |
373 | "elapsed_time", pdev); | 361 | retval = -EBUSY; |
374 | if (retval == 0) { | 362 | goto err_device_unregister; |
375 | irq = RTCLONG1_IRQ; | ||
376 | retval = request_irq(irq, rtclong1_interrupt, IRQF_DISABLED, | ||
377 | "rtclong1", pdev); | ||
378 | } | 363 | } |
379 | 364 | ||
380 | if (retval < 0) { | 365 | retval = request_irq(aie_irq, elapsedtime_interrupt, IRQF_DISABLED, |
381 | printk(KERN_ERR "rtc: IRQ%d is busy\n", irq); | 366 | "elapsed_time", pdev); |
382 | rtc_device_unregister(rtc); | 367 | if (retval < 0) |
383 | if (irq == RTCLONG1_IRQ) | 368 | goto err_device_unregister; |
384 | free_irq(ELAPSEDTIME_IRQ, NULL); | 369 | |
385 | iounmap(rtc1_base); | 370 | pie_irq = platform_get_irq(pdev, 1); |
386 | iounmap(rtc2_base); | 371 | if (pie_irq < 0 || pie_irq >= NR_IRQS) |
387 | rtc1_base = NULL; | 372 | goto err_free_irq; |
388 | rtc2_base = NULL; | 373 | |
389 | return retval; | 374 | retval = request_irq(pie_irq, rtclong1_interrupt, IRQF_DISABLED, |
390 | } | 375 | "rtclong1", pdev); |
376 | if (retval < 0) | ||
377 | goto err_free_irq; | ||
391 | 378 | ||
392 | platform_set_drvdata(pdev, rtc); | 379 | platform_set_drvdata(pdev, rtc); |
393 | 380 | ||
394 | disable_irq(ELAPSEDTIME_IRQ); | 381 | disable_irq(aie_irq); |
395 | disable_irq(RTCLONG1_IRQ); | 382 | disable_irq(pie_irq); |
396 | 383 | ||
397 | printk(KERN_INFO "rtc: Real Time Clock of NEC VR4100 series\n"); | 384 | printk(KERN_INFO "rtc: Real Time Clock of NEC VR4100 series\n"); |
398 | 385 | ||
399 | return 0; | 386 | return 0; |
387 | |||
388 | err_free_irq: | ||
389 | free_irq(aie_irq, pdev); | ||
390 | |||
391 | err_device_unregister: | ||
392 | rtc_device_unregister(rtc); | ||
393 | |||
394 | err_iounmap_all: | ||
395 | iounmap(rtc2_base); | ||
396 | rtc2_base = NULL; | ||
397 | |||
398 | err_rtc1_iounmap: | ||
399 | iounmap(rtc1_base); | ||
400 | rtc1_base = NULL; | ||
401 | |||
402 | return retval; | ||
400 | } | 403 | } |
401 | 404 | ||
402 | static int __devexit rtc_remove(struct platform_device *pdev) | 405 | static int __devexit rtc_remove(struct platform_device *pdev) |
@@ -404,23 +407,21 @@ static int __devexit rtc_remove(struct platform_device *pdev) | |||
404 | struct rtc_device *rtc; | 407 | struct rtc_device *rtc; |
405 | 408 | ||
406 | rtc = platform_get_drvdata(pdev); | 409 | rtc = platform_get_drvdata(pdev); |
407 | if (rtc != NULL) | 410 | if (rtc) |
408 | rtc_device_unregister(rtc); | 411 | rtc_device_unregister(rtc); |
409 | 412 | ||
410 | platform_set_drvdata(pdev, NULL); | 413 | platform_set_drvdata(pdev, NULL); |
411 | 414 | ||
412 | free_irq(ELAPSEDTIME_IRQ, NULL); | 415 | free_irq(aie_irq, pdev); |
413 | free_irq(RTCLONG1_IRQ, NULL); | 416 | free_irq(pie_irq, pdev); |
414 | if (rtc1_base != NULL) | 417 | if (rtc1_base) |
415 | iounmap(rtc1_base); | 418 | iounmap(rtc1_base); |
416 | if (rtc2_base != NULL) | 419 | if (rtc2_base) |
417 | iounmap(rtc2_base); | 420 | iounmap(rtc2_base); |
418 | 421 | ||
419 | return 0; | 422 | return 0; |
420 | } | 423 | } |
421 | 424 | ||
422 | static struct platform_device *rtc_platform_device; | ||
423 | |||
424 | static struct platform_driver rtc_platform_driver = { | 425 | static struct platform_driver rtc_platform_driver = { |
425 | .probe = rtc_probe, | 426 | .probe = rtc_probe, |
426 | .remove = __devexit_p(rtc_remove), | 427 | .remove = __devexit_p(rtc_remove), |
@@ -432,55 +433,12 @@ static struct platform_driver rtc_platform_driver = { | |||
432 | 433 | ||
433 | static int __init vr41xx_rtc_init(void) | 434 | static int __init vr41xx_rtc_init(void) |
434 | { | 435 | { |
435 | int retval; | 436 | return platform_driver_register(&rtc_platform_driver); |
436 | |||
437 | switch (current_cpu_data.cputype) { | ||
438 | case CPU_VR4111: | ||
439 | case CPU_VR4121: | ||
440 | rtc_resource[0].start = RTC1_TYPE1_START; | ||
441 | rtc_resource[0].end = RTC1_TYPE1_END; | ||
442 | rtc_resource[1].start = RTC2_TYPE1_START; | ||
443 | rtc_resource[1].end = RTC2_TYPE1_END; | ||
444 | break; | ||
445 | case CPU_VR4122: | ||
446 | case CPU_VR4131: | ||
447 | case CPU_VR4133: | ||
448 | rtc_resource[0].start = RTC1_TYPE2_START; | ||
449 | rtc_resource[0].end = RTC1_TYPE2_END; | ||
450 | rtc_resource[1].start = RTC2_TYPE2_START; | ||
451 | rtc_resource[1].end = RTC2_TYPE2_END; | ||
452 | break; | ||
453 | default: | ||
454 | return -ENODEV; | ||
455 | break; | ||
456 | } | ||
457 | |||
458 | rtc_platform_device = platform_device_alloc("RTC", -1); | ||
459 | if (rtc_platform_device == NULL) | ||
460 | return -ENOMEM; | ||
461 | |||
462 | retval = platform_device_add_resources(rtc_platform_device, | ||
463 | rtc_resource, ARRAY_SIZE(rtc_resource)); | ||
464 | |||
465 | if (retval == 0) | ||
466 | retval = platform_device_add(rtc_platform_device); | ||
467 | |||
468 | if (retval < 0) { | ||
469 | platform_device_put(rtc_platform_device); | ||
470 | return retval; | ||
471 | } | ||
472 | |||
473 | retval = platform_driver_register(&rtc_platform_driver); | ||
474 | if (retval < 0) | ||
475 | platform_device_unregister(rtc_platform_device); | ||
476 | |||
477 | return retval; | ||
478 | } | 437 | } |
479 | 438 | ||
480 | static void __exit vr41xx_rtc_exit(void) | 439 | static void __exit vr41xx_rtc_exit(void) |
481 | { | 440 | { |
482 | platform_driver_unregister(&rtc_platform_driver); | 441 | platform_driver_unregister(&rtc_platform_driver); |
483 | platform_device_unregister(rtc_platform_device); | ||
484 | } | 442 | } |
485 | 443 | ||
486 | module_init(vr41xx_rtc_init); | 444 | module_init(vr41xx_rtc_init); |