devices.c 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. /*
  2. * Author: MontaVista Software, Inc.
  3. * <source@mvista.com>
  4. *
  5. * Based on the OMAP devices.c
  6. *
  7. * 2005 (c) MontaVista Software, Inc. This file is licensed under the
  8. * terms of the GNU General Public License version 2. This program is
  9. * licensed "as is" without any warranty of any kind, whether express
  10. * or implied.
  11. *
  12. * Copyright 2006-2007 Freescale Semiconductor, Inc. All Rights Reserved.
  13. * Copyright 2008 Juergen Beisert, kernel@pengutronix.de
  14. * Copyright 2008 Sascha Hauer, kernel@pengutronix.de
  15. * Copyright (c) 2008 Paulius Zaleckas <paulius.zaleckas@teltonika.lt>
  16. * Copyright (c) 2008 Darius Augulis <darius.augulis@teltonika.lt>
  17. *
  18. * This program is free software; you can redistribute it and/or
  19. * modify it under the terms of the GNU General Public License
  20. * as published by the Free Software Foundation; either version 2
  21. * of the License, or (at your option) any later version.
  22. * This program is distributed in the hope that it will be useful,
  23. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. * GNU General Public License for more details.
  26. *
  27. * You should have received a copy of the GNU General Public License
  28. * along with this program; if not, write to the Free Software
  29. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  30. * MA 02110-1301, USA.
  31. */
  32. #include <linux/module.h>
  33. #include <linux/kernel.h>
  34. #include <linux/init.h>
  35. #include <linux/platform_device.h>
  36. #include <linux/gpio.h>
  37. #include <linux/dma-mapping.h>
  38. #include <linux/serial.h>
  39. #include <mach/irqs.h>
  40. #include <mach/hardware.h>
  41. #include <mach/common.h>
  42. #include <mach/mmc.h>
  43. #include "devices.h"
  44. #if defined(CONFIG_ARCH_MX1)
  45. /* GPIO port description */
  46. static struct mxc_gpio_port imx_gpio_ports[] = {
  47. {
  48. .chip.label = "gpio-0",
  49. .base = MX1_IO_ADDRESS(MX1_GPIO_BASE_ADDR),
  50. .irq = MX1_GPIO_INT_PORTA,
  51. .virtual_irq_start = MXC_GPIO_IRQ_START,
  52. }, {
  53. .chip.label = "gpio-1",
  54. .base = MX1_IO_ADDRESS(MX1_GPIO_BASE_ADDR + 0x100),
  55. .irq = MX1_GPIO_INT_PORTB,
  56. .virtual_irq_start = MXC_GPIO_IRQ_START + 32,
  57. }, {
  58. .chip.label = "gpio-2",
  59. .base = MX1_IO_ADDRESS(MX1_GPIO_BASE_ADDR + 0x200),
  60. .irq = MX1_GPIO_INT_PORTC,
  61. .virtual_irq_start = MXC_GPIO_IRQ_START + 64,
  62. }, {
  63. .chip.label = "gpio-3",
  64. .base = MX1_IO_ADDRESS(MX1_GPIO_BASE_ADDR + 0x300),
  65. .irq = MX1_GPIO_INT_PORTD,
  66. .virtual_irq_start = MXC_GPIO_IRQ_START + 96,
  67. }
  68. };
  69. int __init imx1_register_gpios(void)
  70. {
  71. return mxc_gpio_init(imx_gpio_ports, ARRAY_SIZE(imx_gpio_ports));
  72. }
  73. #endif
  74. #if defined(CONFIG_MACH_MX21) || defined(CONFIG_MACH_MX27)
  75. static struct resource mxc_pwm_resources[] = {
  76. {
  77. .start = MX2x_PWM_BASE_ADDR,
  78. .end = MX2x_PWM_BASE_ADDR + SZ_4K - 1,
  79. .flags = IORESOURCE_MEM,
  80. }, {
  81. .start = MX2x_INT_PWM,
  82. .end = MX2x_INT_PWM,
  83. .flags = IORESOURCE_IRQ,
  84. }
  85. };
  86. struct platform_device mxc_pwm_device = {
  87. .name = "mxc_pwm",
  88. .id = 0,
  89. .num_resources = ARRAY_SIZE(mxc_pwm_resources),
  90. .resource = mxc_pwm_resources,
  91. };
  92. #define DEFINE_MXC_MMC_DEVICE(n, baseaddr, irq, dmareq) \
  93. static struct resource mxc_sdhc_resources ## n[] = { \
  94. { \
  95. .start = baseaddr, \
  96. .end = baseaddr + SZ_4K - 1, \
  97. .flags = IORESOURCE_MEM, \
  98. }, { \
  99. .start = irq, \
  100. .end = irq, \
  101. .flags = IORESOURCE_IRQ, \
  102. }, { \
  103. .start = dmareq, \
  104. .end = dmareq, \
  105. .flags = IORESOURCE_DMA, \
  106. }, \
  107. }; \
  108. \
  109. static u64 mxc_sdhc ## n ## _dmamask = DMA_BIT_MASK(32); \
  110. \
  111. struct platform_device mxc_sdhc_device ## n = { \
  112. .name = "mxc-mmc", \
  113. .id = n, \
  114. .dev = { \
  115. .dma_mask = &mxc_sdhc ## n ## _dmamask, \
  116. .coherent_dma_mask = DMA_BIT_MASK(32), \
  117. }, \
  118. .num_resources = ARRAY_SIZE(mxc_sdhc_resources ## n), \
  119. .resource = mxc_sdhc_resources ## n, \
  120. }
  121. DEFINE_MXC_MMC_DEVICE(0, MX2x_SDHC1_BASE_ADDR, MX2x_INT_SDHC1, MX2x_DMA_REQ_SDHC1);
  122. DEFINE_MXC_MMC_DEVICE(1, MX2x_SDHC2_BASE_ADDR, MX2x_INT_SDHC2, MX2x_DMA_REQ_SDHC2);
  123. #ifdef CONFIG_MACH_MX27
  124. static struct resource otg_resources[] = {
  125. {
  126. .start = MX27_USBOTG_BASE_ADDR,
  127. .end = MX27_USBOTG_BASE_ADDR + 0x1ff,
  128. .flags = IORESOURCE_MEM,
  129. }, {
  130. .start = MX27_INT_USB3,
  131. .end = MX27_INT_USB3,
  132. .flags = IORESOURCE_IRQ,
  133. },
  134. };
  135. static u64 otg_dmamask = DMA_BIT_MASK(32);
  136. /* OTG gadget device */
  137. struct platform_device mxc_otg_udc_device = {
  138. .name = "fsl-usb2-udc",
  139. .id = -1,
  140. .dev = {
  141. .dma_mask = &otg_dmamask,
  142. .coherent_dma_mask = DMA_BIT_MASK(32),
  143. },
  144. .resource = otg_resources,
  145. .num_resources = ARRAY_SIZE(otg_resources),
  146. };
  147. /* OTG host */
  148. struct platform_device mxc_otg_host = {
  149. .name = "mxc-ehci",
  150. .id = 0,
  151. .dev = {
  152. .coherent_dma_mask = DMA_BIT_MASK(32),
  153. .dma_mask = &otg_dmamask,
  154. },
  155. .resource = otg_resources,
  156. .num_resources = ARRAY_SIZE(otg_resources),
  157. };
  158. /* USB host 1 */
  159. static u64 usbh1_dmamask = DMA_BIT_MASK(32);
  160. static struct resource mxc_usbh1_resources[] = {
  161. {
  162. .start = MX27_USBOTG_BASE_ADDR + 0x200,
  163. .end = MX27_USBOTG_BASE_ADDR + 0x3ff,
  164. .flags = IORESOURCE_MEM,
  165. }, {
  166. .start = MX27_INT_USB1,
  167. .end = MX27_INT_USB1,
  168. .flags = IORESOURCE_IRQ,
  169. },
  170. };
  171. struct platform_device mxc_usbh1 = {
  172. .name = "mxc-ehci",
  173. .id = 1,
  174. .dev = {
  175. .coherent_dma_mask = DMA_BIT_MASK(32),
  176. .dma_mask = &usbh1_dmamask,
  177. },
  178. .resource = mxc_usbh1_resources,
  179. .num_resources = ARRAY_SIZE(mxc_usbh1_resources),
  180. };
  181. /* USB host 2 */
  182. static u64 usbh2_dmamask = DMA_BIT_MASK(32);
  183. static struct resource mxc_usbh2_resources[] = {
  184. {
  185. .start = MX27_USBOTG_BASE_ADDR + 0x400,
  186. .end = MX27_USBOTG_BASE_ADDR + 0x5ff,
  187. .flags = IORESOURCE_MEM,
  188. }, {
  189. .start = MX27_INT_USB2,
  190. .end = MX27_INT_USB2,
  191. .flags = IORESOURCE_IRQ,
  192. },
  193. };
  194. struct platform_device mxc_usbh2 = {
  195. .name = "mxc-ehci",
  196. .id = 2,
  197. .dev = {
  198. .coherent_dma_mask = DMA_BIT_MASK(32),
  199. .dma_mask = &usbh2_dmamask,
  200. },
  201. .resource = mxc_usbh2_resources,
  202. .num_resources = ARRAY_SIZE(mxc_usbh2_resources),
  203. };
  204. #endif
  205. /* GPIO port description */
  206. #define DEFINE_MXC_GPIO_PORT_IRQ(SOC, n, _irq) \
  207. { \
  208. .chip.label = "gpio-" #n, \
  209. .irq = _irq, \
  210. .base = SOC ## _IO_ADDRESS(MX2x_GPIO_BASE_ADDR + \
  211. n * 0x100), \
  212. .virtual_irq_start = MXC_GPIO_IRQ_START + n * 32, \
  213. }
  214. #define DEFINE_MXC_GPIO_PORT(SOC, n) \
  215. { \
  216. .chip.label = "gpio-" #n, \
  217. .base = SOC ## _IO_ADDRESS(MX2x_GPIO_BASE_ADDR + \
  218. n * 0x100), \
  219. .virtual_irq_start = MXC_GPIO_IRQ_START + n * 32, \
  220. }
  221. #define DEFINE_MXC_GPIO_PORTS(SOC, pfx) \
  222. static struct mxc_gpio_port pfx ## _gpio_ports[] = { \
  223. DEFINE_MXC_GPIO_PORT_IRQ(SOC, 0, SOC ## _INT_GPIO), \
  224. DEFINE_MXC_GPIO_PORT(SOC, 1), \
  225. DEFINE_MXC_GPIO_PORT(SOC, 2), \
  226. DEFINE_MXC_GPIO_PORT(SOC, 3), \
  227. DEFINE_MXC_GPIO_PORT(SOC, 4), \
  228. DEFINE_MXC_GPIO_PORT(SOC, 5), \
  229. }
  230. #ifdef CONFIG_MACH_MX21
  231. DEFINE_MXC_GPIO_PORTS(MX21, imx21);
  232. int __init imx21_register_gpios(void)
  233. {
  234. return mxc_gpio_init(imx21_gpio_ports, ARRAY_SIZE(imx21_gpio_ports));
  235. }
  236. #endif
  237. #ifdef CONFIG_MACH_MX27
  238. DEFINE_MXC_GPIO_PORTS(MX27, imx27);
  239. int __init imx27_register_gpios(void)
  240. {
  241. return mxc_gpio_init(imx27_gpio_ports, ARRAY_SIZE(imx27_gpio_ports));
  242. }
  243. #endif
  244. #ifdef CONFIG_MACH_MX21
  245. static struct resource mx21_usbhc_resources[] = {
  246. {
  247. .start = MX21_USBOTG_BASE_ADDR,
  248. .end = MX21_USBOTG_BASE_ADDR + SZ_8K - 1,
  249. .flags = IORESOURCE_MEM,
  250. },
  251. {
  252. .start = MX21_INT_USBHOST,
  253. .end = MX21_INT_USBHOST,
  254. .flags = IORESOURCE_IRQ,
  255. },
  256. };
  257. struct platform_device mx21_usbhc_device = {
  258. .name = "imx21-hcd",
  259. .id = 0,
  260. .dev = {
  261. .dma_mask = &mx21_usbhc_device.dev.coherent_dma_mask,
  262. .coherent_dma_mask = DMA_BIT_MASK(32),
  263. },
  264. .num_resources = ARRAY_SIZE(mx21_usbhc_resources),
  265. .resource = mx21_usbhc_resources,
  266. };
  267. #endif
  268. static struct resource imx_kpp_resources[] = {
  269. {
  270. .start = MX2x_KPP_BASE_ADDR,
  271. .end = MX2x_KPP_BASE_ADDR + 0xf,
  272. .flags = IORESOURCE_MEM
  273. }, {
  274. .start = MX2x_INT_KPP,
  275. .end = MX2x_INT_KPP,
  276. .flags = IORESOURCE_IRQ,
  277. },
  278. };
  279. struct platform_device imx_kpp_device = {
  280. .name = "imx-keypad",
  281. .id = -1,
  282. .num_resources = ARRAY_SIZE(imx_kpp_resources),
  283. .resource = imx_kpp_resources,
  284. };
  285. #endif