giu.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. * NEC VR4100 series GIU 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/giu.h>
  26. #include <asm/vr41xx/irq.h>
  27. static struct resource giu_50pins_pullupdown_resource[] __initdata = {
  28. {
  29. .start = 0x0b000100,
  30. .end = 0x0b00011f,
  31. .flags = IORESOURCE_MEM,
  32. },
  33. {
  34. .start = 0x0b0002e0,
  35. .end = 0x0b0002e3,
  36. .flags = IORESOURCE_MEM,
  37. },
  38. {
  39. .start = GIUINT_IRQ,
  40. .end = GIUINT_IRQ,
  41. .flags = IORESOURCE_IRQ,
  42. },
  43. };
  44. static struct resource giu_36pins_resource[] __initdata = {
  45. {
  46. .start = 0x0f000140,
  47. .end = 0x0f00015f,
  48. .flags = IORESOURCE_MEM,
  49. },
  50. {
  51. .start = GIUINT_IRQ,
  52. .end = GIUINT_IRQ,
  53. .flags = IORESOURCE_IRQ,
  54. },
  55. };
  56. static struct resource giu_48pins_resource[] __initdata = {
  57. {
  58. .start = 0x0f000140,
  59. .end = 0x0f000167,
  60. .flags = IORESOURCE_MEM,
  61. },
  62. {
  63. .start = GIUINT_IRQ,
  64. .end = GIUINT_IRQ,
  65. .flags = IORESOURCE_IRQ,
  66. },
  67. };
  68. static int __init vr41xx_giu_add(void)
  69. {
  70. struct platform_device *pdev;
  71. struct resource *res;
  72. unsigned int num;
  73. int retval;
  74. pdev = platform_device_alloc("GIU", -1);
  75. if (!pdev)
  76. return -ENOMEM;
  77. switch (current_cpu_type()) {
  78. case CPU_VR4111:
  79. case CPU_VR4121:
  80. pdev->id = GPIO_50PINS_PULLUPDOWN;
  81. res = giu_50pins_pullupdown_resource;
  82. num = ARRAY_SIZE(giu_50pins_pullupdown_resource);
  83. break;
  84. case CPU_VR4122:
  85. case CPU_VR4131:
  86. pdev->id = GPIO_36PINS;
  87. res = giu_36pins_resource;
  88. num = ARRAY_SIZE(giu_36pins_resource);
  89. break;
  90. case CPU_VR4133:
  91. pdev->id = GPIO_48PINS_EDGE_SELECT;
  92. res = giu_48pins_resource;
  93. num = ARRAY_SIZE(giu_48pins_resource);
  94. break;
  95. default:
  96. retval = -ENODEV;
  97. goto err_free_device;
  98. }
  99. retval = platform_device_add_resources(pdev, res, num);
  100. if (retval)
  101. goto err_free_device;
  102. retval = platform_device_add(pdev);
  103. if (retval)
  104. goto err_free_device;
  105. return 0;
  106. err_free_device:
  107. platform_device_put(pdev);
  108. return retval;
  109. }
  110. device_initcall(vr41xx_giu_add);