rtc.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. * NEC VR4100 series RTC platform device.
  3. *
  4. * Copyright (C) 2007 Yoichi Yuasa <yuasa@linux-mips.org>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #include <linux/errno.h>
  21. #include <linux/init.h>
  22. #include <linux/smp.h>
  23. #include <linux/ioport.h>
  24. #include <linux/platform_device.h>
  25. #include <asm/cpu.h>
  26. #include <asm/vr41xx/irq.h>
  27. static struct resource rtc_type1_resource[] __initdata = {
  28. {
  29. .start = 0x0b0000c0,
  30. .end = 0x0b0000df,
  31. .flags = IORESOURCE_MEM,
  32. },
  33. {
  34. .start = 0x0b0001c0,
  35. .end = 0x0b0001df,
  36. .flags = IORESOURCE_MEM,
  37. },
  38. {
  39. .start = ELAPSEDTIME_IRQ,
  40. .end = ELAPSEDTIME_IRQ,
  41. .flags = IORESOURCE_IRQ,
  42. },
  43. {
  44. .start = RTCLONG1_IRQ,
  45. .end = RTCLONG1_IRQ,
  46. .flags = IORESOURCE_IRQ,
  47. },
  48. };
  49. static struct resource rtc_type2_resource[] __initdata = {
  50. {
  51. .start = 0x0f000100,
  52. .end = 0x0f00011f,
  53. .flags = IORESOURCE_MEM,
  54. },
  55. {
  56. .start = 0x0f000120,
  57. .end = 0x0f00013f,
  58. .flags = IORESOURCE_MEM,
  59. },
  60. {
  61. .start = ELAPSEDTIME_IRQ,
  62. .end = ELAPSEDTIME_IRQ,
  63. .flags = IORESOURCE_IRQ,
  64. },
  65. {
  66. .start = RTCLONG1_IRQ,
  67. .end = RTCLONG1_IRQ,
  68. .flags = IORESOURCE_IRQ,
  69. },
  70. };
  71. static int __init vr41xx_rtc_add(void)
  72. {
  73. struct platform_device *pdev;
  74. struct resource *res;
  75. unsigned int num;
  76. int retval;
  77. pdev = platform_device_alloc("RTC", -1);
  78. if (!pdev)
  79. return -ENOMEM;
  80. switch (current_cpu_type()) {
  81. case CPU_VR4111:
  82. case CPU_VR4121:
  83. res = rtc_type1_resource;
  84. num = ARRAY_SIZE(rtc_type1_resource);
  85. break;
  86. case CPU_VR4122:
  87. case CPU_VR4131:
  88. case CPU_VR4133:
  89. res = rtc_type2_resource;
  90. num = ARRAY_SIZE(rtc_type2_resource);
  91. break;
  92. default:
  93. retval = -ENODEV;
  94. goto err_free_device;
  95. }
  96. retval = platform_device_add_resources(pdev, res, num);
  97. if (retval)
  98. goto err_free_device;
  99. retval = platform_device_add(pdev);
  100. if (retval)
  101. goto err_free_device;
  102. return 0;
  103. err_free_device:
  104. platform_device_put(pdev);
  105. return retval;
  106. }
  107. device_initcall(vr41xx_rtc_add);