devices.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /*
  2. * Copyright 2006-2007 Freescale Semiconductor, Inc. All Rights Reserved.
  3. * Copyright 2008 Sascha Hauer, kernel@pengutronix.de
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License
  7. * as published by the Free Software Foundation; either version 2
  8. * of the License, or (at your option) any later version.
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor,
  17. * Boston, MA 02110-1301, USA.
  18. */
  19. #include <linux/module.h>
  20. #include <linux/platform_device.h>
  21. #include <linux/serial.h>
  22. #include <linux/gpio.h>
  23. #include <asm/hardware.h>
  24. #include <asm/arch/imx-uart.h>
  25. static struct resource uart0[] = {
  26. {
  27. .start = UART1_BASE_ADDR,
  28. .end = UART1_BASE_ADDR + 0x0B5,
  29. .flags = IORESOURCE_MEM,
  30. }, {
  31. .start = MXC_INT_UART1,
  32. .end = MXC_INT_UART1,
  33. .flags = IORESOURCE_IRQ,
  34. },
  35. };
  36. static struct platform_device mxc_uart_device0 = {
  37. .name = "imx-uart",
  38. .id = 0,
  39. .resource = uart0,
  40. .num_resources = ARRAY_SIZE(uart0),
  41. };
  42. static struct resource uart1[] = {
  43. {
  44. .start = UART2_BASE_ADDR,
  45. .end = UART2_BASE_ADDR + 0x0B5,
  46. .flags = IORESOURCE_MEM,
  47. }, {
  48. .start = MXC_INT_UART2,
  49. .end = MXC_INT_UART2,
  50. .flags = IORESOURCE_IRQ,
  51. },
  52. };
  53. static struct platform_device mxc_uart_device1 = {
  54. .name = "imx-uart",
  55. .id = 1,
  56. .resource = uart1,
  57. .num_resources = ARRAY_SIZE(uart1),
  58. };
  59. static struct resource uart2[] = {
  60. {
  61. .start = UART3_BASE_ADDR,
  62. .end = UART3_BASE_ADDR + 0x0B5,
  63. .flags = IORESOURCE_MEM,
  64. }, {
  65. .start = MXC_INT_UART3,
  66. .end = MXC_INT_UART3,
  67. .flags = IORESOURCE_IRQ,
  68. },
  69. };
  70. static struct platform_device mxc_uart_device2 = {
  71. .name = "imx-uart",
  72. .id = 2,
  73. .resource = uart2,
  74. .num_resources = ARRAY_SIZE(uart2),
  75. };
  76. static struct resource uart3[] = {
  77. {
  78. .start = UART4_BASE_ADDR,
  79. .end = UART4_BASE_ADDR + 0x0B5,
  80. .flags = IORESOURCE_MEM,
  81. }, {
  82. .start = MXC_INT_UART4,
  83. .end = MXC_INT_UART4,
  84. .flags = IORESOURCE_IRQ,
  85. },
  86. };
  87. static struct platform_device mxc_uart_device3 = {
  88. .name = "imx-uart",
  89. .id = 3,
  90. .resource = uart3,
  91. .num_resources = ARRAY_SIZE(uart3),
  92. };
  93. static struct resource uart4[] = {
  94. {
  95. .start = UART5_BASE_ADDR,
  96. .end = UART5_BASE_ADDR + 0x0B5,
  97. .flags = IORESOURCE_MEM,
  98. }, {
  99. .start = MXC_INT_UART5,
  100. .end = MXC_INT_UART5,
  101. .flags = IORESOURCE_IRQ,
  102. },
  103. };
  104. static struct platform_device mxc_uart_device4 = {
  105. .name = "imx-uart",
  106. .id = 4,
  107. .resource = uart4,
  108. .num_resources = ARRAY_SIZE(uart4),
  109. };
  110. /*
  111. * Register only those UARTs that physically exist
  112. */
  113. int __init imx_init_uart(int uart_no, struct imxuart_platform_data *pdata)
  114. {
  115. switch (uart_no) {
  116. case 0:
  117. mxc_uart_device0.dev.platform_data = pdata;
  118. platform_device_register(&mxc_uart_device0);
  119. break;
  120. case 1:
  121. mxc_uart_device1.dev.platform_data = pdata;
  122. platform_device_register(&mxc_uart_device1);
  123. break;
  124. case 2:
  125. mxc_uart_device2.dev.platform_data = pdata;
  126. platform_device_register(&mxc_uart_device2);
  127. break;
  128. case 3:
  129. mxc_uart_device3.dev.platform_data = pdata;
  130. platform_device_register(&mxc_uart_device3);
  131. break;
  132. case 4:
  133. mxc_uart_device4.dev.platform_data = pdata;
  134. platform_device_register(&mxc_uart_device4);
  135. break;
  136. default:
  137. return -ENODEV;
  138. }
  139. return 0;
  140. }
  141. /* GPIO port description */
  142. static struct mxc_gpio_port imx_gpio_ports[] = {
  143. [0] = {
  144. .chip.label = "gpio-0",
  145. .base = IO_ADDRESS(GPIO1_BASE_ADDR),
  146. .irq = MXC_INT_GPIO1,
  147. .virtual_irq_start = MXC_GPIO_INT_BASE
  148. },
  149. [1] = {
  150. .chip.label = "gpio-1",
  151. .base = IO_ADDRESS(GPIO2_BASE_ADDR),
  152. .irq = MXC_INT_GPIO2,
  153. .virtual_irq_start = MXC_GPIO_INT_BASE + GPIO_NUM_PIN
  154. },
  155. [2] = {
  156. .chip.label = "gpio-2",
  157. .base = IO_ADDRESS(GPIO3_BASE_ADDR),
  158. .irq = MXC_INT_GPIO3,
  159. .virtual_irq_start = MXC_GPIO_INT_BASE + GPIO_NUM_PIN * 2
  160. }
  161. };
  162. int __init mxc_register_gpios(void)
  163. {
  164. return mxc_gpio_init(imx_gpio_ports, ARRAY_SIZE(imx_gpio_ports));
  165. }