rtc.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * NEC VR4100 series RTC platform device.
  3. *
  4. * Copyright (C) 2007 Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>
  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/ioport.h>
  23. #include <linux/platform_device.h>
  24. #include <asm/cpu.h>
  25. #include <asm/vr41xx/irq.h>
  26. static struct resource rtc_type1_resource[] __initdata = {
  27. {
  28. .start = 0x0b0000c0,
  29. .end = 0x0b0000df,
  30. .flags = IORESOURCE_MEM,
  31. },
  32. {
  33. .start = 0x0b0001c0,
  34. .end = 0x0b0001df,
  35. .flags = IORESOURCE_MEM,
  36. },
  37. {
  38. .start = ELAPSEDTIME_IRQ,
  39. .end = ELAPSEDTIME_IRQ,
  40. .flags = IORESOURCE_IRQ,
  41. },
  42. {
  43. .start = RTCLONG1_IRQ,
  44. .end = RTCLONG1_IRQ,
  45. .flags = IORESOURCE_IRQ,
  46. },
  47. };
  48. static struct resource rtc_type2_resource[] __initdata = {
  49. {
  50. .start = 0x0f000100,
  51. .end = 0x0f00011f,
  52. .flags = IORESOURCE_MEM,
  53. },
  54. {
  55. .start = 0x0f000120,
  56. .end = 0x0f00013f,
  57. .flags = IORESOURCE_MEM,
  58. },
  59. {
  60. .start = ELAPSEDTIME_IRQ,
  61. .end = ELAPSEDTIME_IRQ,
  62. .flags = IORESOURCE_IRQ,
  63. },
  64. {
  65. .start = RTCLONG1_IRQ,
  66. .end = RTCLONG1_IRQ,
  67. .flags = IORESOURCE_IRQ,
  68. },
  69. };
  70. static int __init vr41xx_rtc_add(void)
  71. {
  72. struct platform_device *pdev;
  73. struct resource *res;
  74. unsigned int num;
  75. int retval;
  76. pdev = platform_device_alloc("RTC", -1);
  77. if (!pdev)
  78. return -ENOMEM;
  79. switch (current_cpu_type()) {
  80. case CPU_VR4111:
  81. case CPU_VR4121:
  82. res = rtc_type1_resource;
  83. num = ARRAY_SIZE(rtc_type1_resource);
  84. break;
  85. case CPU_VR4122:
  86. case CPU_VR4131:
  87. case CPU_VR4133:
  88. res = rtc_type2_resource;
  89. num = ARRAY_SIZE(rtc_type2_resource);
  90. break;
  91. default:
  92. retval = -ENODEV;
  93. goto err_free_device;
  94. }
  95. retval = platform_device_add_resources(pdev, res, num);
  96. if (retval)
  97. goto err_free_device;
  98. retval = platform_device_add(pdev);
  99. if (retval)
  100. goto err_free_device;
  101. return 0;
  102. err_free_device:
  103. platform_device_put(pdev);
  104. return retval;
  105. }
  106. device_initcall(vr41xx_rtc_add);