giu.c 2.8 KB

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