devices.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529
  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. *
  15. * This program is free software; you can redistribute it and/or
  16. * modify it under the terms of the GNU General Public License
  17. * as published by the Free Software Foundation; either version 2
  18. * of the License, or (at your option) any later version.
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, write to the Free Software
  26. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  27. * MA 02110-1301, USA.
  28. */
  29. #include <linux/module.h>
  30. #include <linux/kernel.h>
  31. #include <linux/init.h>
  32. #include <linux/platform_device.h>
  33. #include <linux/gpio.h>
  34. #include <linux/dma-mapping.h>
  35. #include <linux/serial.h>
  36. #include <mach/irqs.h>
  37. #include <mach/hardware.h>
  38. #include <mach/common.h>
  39. #include <mach/mmc.h>
  40. #include <mach/imx-uart.h>
  41. #include "devices.h"
  42. /*
  43. * SPI master controller
  44. *
  45. * - i.MX1: 2 channel (slighly different register setting)
  46. * - i.MX21: 2 channel
  47. * - i.MX27: 3 channel
  48. */
  49. #define DEFINE_IMX_SPI_DEVICE(n, baseaddr, irq) \
  50. static struct resource mxc_spi_resources ## n[] = { \
  51. { \
  52. .start = baseaddr, \
  53. .end = baseaddr + SZ_4K - 1, \
  54. .flags = IORESOURCE_MEM, \
  55. }, { \
  56. .start = irq, \
  57. .end = irq, \
  58. .flags = IORESOURCE_IRQ, \
  59. }, \
  60. }; \
  61. \
  62. struct platform_device mxc_spi_device ## n = { \
  63. .name = "spi_imx", \
  64. .id = n, \
  65. .num_resources = ARRAY_SIZE(mxc_spi_resources ## n), \
  66. .resource = mxc_spi_resources ## n, \
  67. }
  68. DEFINE_IMX_SPI_DEVICE(0, MX2x_CSPI1_BASE_ADDR, MX2x_INT_CSPI1);
  69. DEFINE_IMX_SPI_DEVICE(1, MX2x_CSPI2_BASE_ADDR, MX2x_INT_CSPI2);
  70. #ifdef CONFIG_MACH_MX27
  71. DEFINE_IMX_SPI_DEVICE(2, MX27_CSPI3_BASE_ADDR, MX27_INT_CSPI3);
  72. #endif
  73. /*
  74. * General Purpose Timer
  75. * - i.MX21: 3 timers
  76. * - i.MX27: 6 timers
  77. */
  78. #define DEFINE_IMX_GPT_DEVICE(n, baseaddr, irq) \
  79. static struct resource timer ## n ##_resources[] = { \
  80. { \
  81. .start = baseaddr, \
  82. .end = baseaddr + SZ_4K - 1, \
  83. .flags = IORESOURCE_MEM, \
  84. }, { \
  85. .start = irq, \
  86. .end = irq, \
  87. .flags = IORESOURCE_IRQ, \
  88. } \
  89. }; \
  90. \
  91. struct platform_device mxc_gpt ## n = { \
  92. .name = "imx_gpt", \
  93. .id = n, \
  94. .num_resources = ARRAY_SIZE(timer ## n ## _resources), \
  95. .resource = timer ## n ## _resources, \
  96. }
  97. /* We use gpt1 as system timer, so do not add a device for this one */
  98. DEFINE_IMX_GPT_DEVICE(1, MX2x_GPT2_BASE_ADDR, MX2x_INT_GPT2);
  99. DEFINE_IMX_GPT_DEVICE(2, MX2x_GPT3_BASE_ADDR, MX2x_INT_GPT3);
  100. #ifdef CONFIG_MACH_MX27
  101. DEFINE_IMX_GPT_DEVICE(3, MX27_GPT4_BASE_ADDR, MX27_INT_GPT4);
  102. DEFINE_IMX_GPT_DEVICE(4, MX27_GPT5_BASE_ADDR, MX27_INT_GPT5);
  103. DEFINE_IMX_GPT_DEVICE(5, MX27_GPT6_BASE_ADDR, MX27_INT_GPT6);
  104. #endif
  105. /* Watchdog: i.MX1 has seperate driver, i.MX21 and i.MX27 are equal */
  106. static struct resource mxc_wdt_resources[] = {
  107. {
  108. .start = MX2x_WDOG_BASE_ADDR,
  109. .end = MX2x_WDOG_BASE_ADDR + SZ_4K - 1,
  110. .flags = IORESOURCE_MEM,
  111. },
  112. };
  113. struct platform_device mxc_wdt = {
  114. .name = "imx2-wdt",
  115. .id = 0,
  116. .num_resources = ARRAY_SIZE(mxc_wdt_resources),
  117. .resource = mxc_wdt_resources,
  118. };
  119. static struct resource mxc_w1_master_resources[] = {
  120. {
  121. .start = MX2x_OWIRE_BASE_ADDR,
  122. .end = MX2x_OWIRE_BASE_ADDR + SZ_4K - 1,
  123. .flags = IORESOURCE_MEM,
  124. },
  125. };
  126. struct platform_device mxc_w1_master_device = {
  127. .name = "mxc_w1",
  128. .id = 0,
  129. .num_resources = ARRAY_SIZE(mxc_w1_master_resources),
  130. .resource = mxc_w1_master_resources,
  131. };
  132. #define DEFINE_MXC_NAND_DEVICE(pfx, baseaddr, irq) \
  133. static struct resource pfx ## _nand_resources[] = { \
  134. { \
  135. .start = baseaddr, \
  136. .end = baseaddr + SZ_4K - 1, \
  137. .flags = IORESOURCE_MEM, \
  138. }, { \
  139. .start = irq, \
  140. .end = irq, \
  141. .flags = IORESOURCE_IRQ, \
  142. }, \
  143. }; \
  144. \
  145. struct platform_device pfx ## _nand_device = { \
  146. .name = "mxc_nand", \
  147. .id = 0, \
  148. .num_resources = ARRAY_SIZE(pfx ## _nand_resources), \
  149. .resource = pfx ## _nand_resources, \
  150. }
  151. #ifdef CONFIG_MACH_MX21
  152. DEFINE_MXC_NAND_DEVICE(imx21, MX21_NFC_BASE_ADDR, MX21_INT_NANDFC);
  153. #endif
  154. #ifdef CONFIG_MACH_MX27
  155. DEFINE_MXC_NAND_DEVICE(imx27, MX27_NFC_BASE_ADDR, MX27_INT_NANDFC);
  156. #endif
  157. /*
  158. * lcdc:
  159. * - i.MX1: the basic controller
  160. * - i.MX21: to be checked
  161. * - i.MX27: like i.MX1, with slightly variations
  162. */
  163. static struct resource mxc_fb[] = {
  164. {
  165. .start = MX2x_LCDC_BASE_ADDR,
  166. .end = MX2x_LCDC_BASE_ADDR + SZ_4K - 1,
  167. .flags = IORESOURCE_MEM,
  168. }, {
  169. .start = MX2x_INT_LCDC,
  170. .end = MX2x_INT_LCDC,
  171. .flags = IORESOURCE_IRQ,
  172. }
  173. };
  174. /* mxc lcd driver */
  175. struct platform_device mxc_fb_device = {
  176. .name = "imx-fb",
  177. .id = 0,
  178. .num_resources = ARRAY_SIZE(mxc_fb),
  179. .resource = mxc_fb,
  180. .dev = {
  181. .coherent_dma_mask = DMA_BIT_MASK(32),
  182. },
  183. };
  184. #ifdef CONFIG_MACH_MX27
  185. static struct resource mxc_fec_resources[] = {
  186. {
  187. .start = MX27_FEC_BASE_ADDR,
  188. .end = MX27_FEC_BASE_ADDR + SZ_4K - 1,
  189. .flags = IORESOURCE_MEM,
  190. }, {
  191. .start = MX27_INT_FEC,
  192. .end = MX27_INT_FEC,
  193. .flags = IORESOURCE_IRQ,
  194. },
  195. };
  196. struct platform_device mxc_fec_device = {
  197. .name = "fec",
  198. .id = 0,
  199. .num_resources = ARRAY_SIZE(mxc_fec_resources),
  200. .resource = mxc_fec_resources,
  201. };
  202. #endif
  203. #define DEFINE_IMX_I2C_DEVICE(n, baseaddr, irq) \
  204. static struct resource mxc_i2c_resources ## n[] = { \
  205. { \
  206. .start = baseaddr, \
  207. .end = baseaddr + SZ_4K - 1, \
  208. .flags = IORESOURCE_MEM, \
  209. }, { \
  210. .start = irq, \
  211. .end = irq, \
  212. .flags = IORESOURCE_IRQ, \
  213. } \
  214. }; \
  215. \
  216. struct platform_device mxc_i2c_device ## n = { \
  217. .name = "imx-i2c", \
  218. .id = n, \
  219. .num_resources = ARRAY_SIZE(mxc_i2c_resources ## n), \
  220. .resource = mxc_i2c_resources ## n, \
  221. }
  222. DEFINE_IMX_I2C_DEVICE(0, MX2x_I2C_BASE_ADDR, MX2x_INT_I2C);
  223. #ifdef CONFIG_MACH_MX27
  224. DEFINE_IMX_I2C_DEVICE(1, MX27_I2C2_BASE_ADDR, MX27_INT_I2C2);
  225. #endif
  226. static struct resource mxc_pwm_resources[] = {
  227. {
  228. .start = MX2x_PWM_BASE_ADDR,
  229. .end = MX2x_PWM_BASE_ADDR + SZ_4K - 1,
  230. .flags = IORESOURCE_MEM,
  231. }, {
  232. .start = MX2x_INT_PWM,
  233. .end = MX2x_INT_PWM,
  234. .flags = IORESOURCE_IRQ,
  235. }
  236. };
  237. struct platform_device mxc_pwm_device = {
  238. .name = "mxc_pwm",
  239. .id = 0,
  240. .num_resources = ARRAY_SIZE(mxc_pwm_resources),
  241. .resource = mxc_pwm_resources,
  242. };
  243. #define DEFINE_MXC_MMC_DEVICE(n, baseaddr, irq, dmareq) \
  244. static struct resource mxc_sdhc_resources ## n[] = { \
  245. { \
  246. .start = baseaddr, \
  247. .end = baseaddr + SZ_4K - 1, \
  248. .flags = IORESOURCE_MEM, \
  249. }, { \
  250. .start = irq, \
  251. .end = irq, \
  252. .flags = IORESOURCE_IRQ, \
  253. }, { \
  254. .start = dmareq, \
  255. .end = dmareq, \
  256. .flags = IORESOURCE_DMA, \
  257. }, \
  258. }; \
  259. \
  260. static u64 mxc_sdhc ## n ## _dmamask = DMA_BIT_MASK(32); \
  261. \
  262. struct platform_device mxc_sdhc_device ## n = { \
  263. .name = "mxc-mmc", \
  264. .id = n, \
  265. .dev = { \
  266. .dma_mask = &mxc_sdhc ## n ## _dmamask, \
  267. .coherent_dma_mask = DMA_BIT_MASK(32), \
  268. }, \
  269. .num_resources = ARRAY_SIZE(mxc_sdhc_resources ## n), \
  270. .resource = mxc_sdhc_resources ## n, \
  271. }
  272. DEFINE_MXC_MMC_DEVICE(0, MX2x_SDHC1_BASE_ADDR, MX2x_INT_SDHC1, MX2x_DMA_REQ_SDHC1);
  273. DEFINE_MXC_MMC_DEVICE(1, MX2x_SDHC2_BASE_ADDR, MX2x_INT_SDHC2, MX2x_DMA_REQ_SDHC2);
  274. #ifdef CONFIG_MACH_MX27
  275. static struct resource otg_resources[] = {
  276. {
  277. .start = MX27_USBOTG_BASE_ADDR,
  278. .end = MX27_USBOTG_BASE_ADDR + 0x1ff,
  279. .flags = IORESOURCE_MEM,
  280. }, {
  281. .start = MX27_INT_USB3,
  282. .end = MX27_INT_USB3,
  283. .flags = IORESOURCE_IRQ,
  284. },
  285. };
  286. static u64 otg_dmamask = DMA_BIT_MASK(32);
  287. /* OTG gadget device */
  288. struct platform_device mxc_otg_udc_device = {
  289. .name = "fsl-usb2-udc",
  290. .id = -1,
  291. .dev = {
  292. .dma_mask = &otg_dmamask,
  293. .coherent_dma_mask = DMA_BIT_MASK(32),
  294. },
  295. .resource = otg_resources,
  296. .num_resources = ARRAY_SIZE(otg_resources),
  297. };
  298. /* OTG host */
  299. struct platform_device mxc_otg_host = {
  300. .name = "mxc-ehci",
  301. .id = 0,
  302. .dev = {
  303. .coherent_dma_mask = DMA_BIT_MASK(32),
  304. .dma_mask = &otg_dmamask,
  305. },
  306. .resource = otg_resources,
  307. .num_resources = ARRAY_SIZE(otg_resources),
  308. };
  309. /* USB host 1 */
  310. static u64 usbh1_dmamask = DMA_BIT_MASK(32);
  311. static struct resource mxc_usbh1_resources[] = {
  312. {
  313. .start = MX27_USBOTG_BASE_ADDR + 0x200,
  314. .end = MX27_USBOTG_BASE_ADDR + 0x3ff,
  315. .flags = IORESOURCE_MEM,
  316. }, {
  317. .start = MX27_INT_USB1,
  318. .end = MX27_INT_USB1,
  319. .flags = IORESOURCE_IRQ,
  320. },
  321. };
  322. struct platform_device mxc_usbh1 = {
  323. .name = "mxc-ehci",
  324. .id = 1,
  325. .dev = {
  326. .coherent_dma_mask = DMA_BIT_MASK(32),
  327. .dma_mask = &usbh1_dmamask,
  328. },
  329. .resource = mxc_usbh1_resources,
  330. .num_resources = ARRAY_SIZE(mxc_usbh1_resources),
  331. };
  332. /* USB host 2 */
  333. static u64 usbh2_dmamask = DMA_BIT_MASK(32);
  334. static struct resource mxc_usbh2_resources[] = {
  335. {
  336. .start = MX27_USBOTG_BASE_ADDR + 0x400,
  337. .end = MX27_USBOTG_BASE_ADDR + 0x5ff,
  338. .flags = IORESOURCE_MEM,
  339. }, {
  340. .start = MX27_INT_USB2,
  341. .end = MX27_INT_USB2,
  342. .flags = IORESOURCE_IRQ,
  343. },
  344. };
  345. struct platform_device mxc_usbh2 = {
  346. .name = "mxc-ehci",
  347. .id = 2,
  348. .dev = {
  349. .coherent_dma_mask = DMA_BIT_MASK(32),
  350. .dma_mask = &usbh2_dmamask,
  351. },
  352. .resource = mxc_usbh2_resources,
  353. .num_resources = ARRAY_SIZE(mxc_usbh2_resources),
  354. };
  355. #endif
  356. #define DEFINE_IMX_SSI_DMARES(_name, ssin, suffix) \
  357. { \
  358. .name = _name, \
  359. .start = MX2x_DMA_REQ_SSI ## ssin ## _ ## suffix, \
  360. .end = MX2x_DMA_REQ_SSI ## ssin ## _ ## suffix, \
  361. .flags = IORESOURCE_DMA, \
  362. }
  363. #define DEFINE_IMX_SSI_DEVICE(n, ssin, baseaddr, irq) \
  364. static struct resource imx_ssi_resources ## n[] = { \
  365. { \
  366. .start = MX2x_SSI ## ssin ## _BASE_ADDR, \
  367. .end = MX2x_SSI ## ssin ## _BASE_ADDR + 0x6f, \
  368. .flags = IORESOURCE_MEM, \
  369. }, { \
  370. .start = MX2x_INT_SSI1, \
  371. .end = MX2x_INT_SSI1, \
  372. .flags = IORESOURCE_IRQ, \
  373. }, \
  374. DEFINE_IMX_SSI_DMARES("tx0", ssin, TX0), \
  375. DEFINE_IMX_SSI_DMARES("rx0", ssin, RX0), \
  376. DEFINE_IMX_SSI_DMARES("tx1", ssin, TX1), \
  377. DEFINE_IMX_SSI_DMARES("rx1", ssin, RX1), \
  378. }; \
  379. \
  380. struct platform_device imx_ssi_device ## n = { \
  381. .name = "imx-ssi", \
  382. .id = n, \
  383. .num_resources = ARRAY_SIZE(imx_ssi_resources ## n), \
  384. .resource = imx_ssi_resources ## n, \
  385. }
  386. DEFINE_IMX_SSI_DEVICE(0, 1, MX2x_SSI1_BASE_ADDR, MX2x_INT_SSI1);
  387. DEFINE_IMX_SSI_DEVICE(1, 2, MX2x_SSI1_BASE_ADDR, MX2x_INT_SSI1);
  388. #define DEFINE_IMX_UART_DEVICE(n, baseaddr, irq) \
  389. static struct resource imx2x_uart_resources ## n[] = { \
  390. { \
  391. .start = baseaddr, \
  392. .end = baseaddr + 0xb5, \
  393. .flags = IORESOURCE_MEM, \
  394. }, { \
  395. .start = irq, \
  396. .end = irq, \
  397. .flags = IORESOURCE_IRQ, \
  398. }, \
  399. }; \
  400. \
  401. struct platform_device mxc_uart_device ## n = { \
  402. .name = "imx-uart", \
  403. .id = n, \
  404. .num_resources = ARRAY_SIZE(imx2x_uart_resources ## n), \
  405. .resource = imx2x_uart_resources ## n, \
  406. }
  407. DEFINE_IMX_UART_DEVICE(0, MX2x_UART1_BASE_ADDR, MX2x_INT_UART1);
  408. DEFINE_IMX_UART_DEVICE(1, MX2x_UART2_BASE_ADDR, MX2x_INT_UART2);
  409. DEFINE_IMX_UART_DEVICE(2, MX2x_UART3_BASE_ADDR, MX2x_INT_UART3);
  410. DEFINE_IMX_UART_DEVICE(3, MX2x_UART4_BASE_ADDR, MX2x_INT_UART4);
  411. #ifdef CONFIG_MACH_MX27
  412. DEFINE_IMX_UART_DEVICE(4, MX27_UART5_BASE_ADDR, MX27_INT_UART5);
  413. DEFINE_IMX_UART_DEVICE(5, MX27_UART6_BASE_ADDR, MX27_INT_UART6);
  414. #endif
  415. /* GPIO port description */
  416. #define DEFINE_MXC_GPIO_PORT_IRQ(SOC, n, _irq) \
  417. { \
  418. .chip.label = "gpio-" #n, \
  419. .irq = _irq, \
  420. .base = SOC ## _IO_ADDRESS(MX2x_GPIO_BASE_ADDR + \
  421. n * 0x100), \
  422. .virtual_irq_start = MXC_GPIO_IRQ_START + n * 32, \
  423. }
  424. #define DEFINE_MXC_GPIO_PORT(SOC, n) \
  425. { \
  426. .chip.label = "gpio-" #n, \
  427. .base = SOC ## _IO_ADDRESS(MX2x_GPIO_BASE_ADDR + \
  428. n * 0x100), \
  429. .virtual_irq_start = MXC_GPIO_IRQ_START + n * 32, \
  430. }
  431. #define DEFINE_MXC_GPIO_PORTS(SOC, pfx) \
  432. static struct mxc_gpio_port pfx ## _gpio_ports[] = { \
  433. DEFINE_MXC_GPIO_PORT_IRQ(SOC, 0, SOC ## _INT_GPIO), \
  434. DEFINE_MXC_GPIO_PORT(SOC, 1), \
  435. DEFINE_MXC_GPIO_PORT(SOC, 2), \
  436. DEFINE_MXC_GPIO_PORT(SOC, 3), \
  437. DEFINE_MXC_GPIO_PORT(SOC, 4), \
  438. DEFINE_MXC_GPIO_PORT(SOC, 5), \
  439. }
  440. #ifdef CONFIG_MACH_MX21
  441. DEFINE_MXC_GPIO_PORTS(MX21, imx21);
  442. int __init imx21_register_gpios(void)
  443. {
  444. return mxc_gpio_init(imx21_gpio_ports, ARRAY_SIZE(imx21_gpio_ports));
  445. }
  446. #endif
  447. #ifdef CONFIG_MACH_MX27
  448. DEFINE_MXC_GPIO_PORTS(MX27, imx27);
  449. int __init imx27_register_gpios(void)
  450. {
  451. return mxc_gpio_init(imx27_gpio_ports, ARRAY_SIZE(imx27_gpio_ports));
  452. }
  453. #endif
  454. #ifdef CONFIG_MACH_MX21
  455. static struct resource mx21_usbhc_resources[] = {
  456. {
  457. .start = MX21_USBOTG_BASE_ADDR,
  458. .end = MX21_USBOTG_BASE_ADDR + SZ_8K - 1,
  459. .flags = IORESOURCE_MEM,
  460. },
  461. {
  462. .start = MX21_INT_USBHOST,
  463. .end = MX21_INT_USBHOST,
  464. .flags = IORESOURCE_IRQ,
  465. },
  466. };
  467. struct platform_device mx21_usbhc_device = {
  468. .name = "imx21-hcd",
  469. .id = 0,
  470. .dev = {
  471. .dma_mask = &mx21_usbhc_device.dev.coherent_dma_mask,
  472. .coherent_dma_mask = DMA_BIT_MASK(32),
  473. },
  474. .num_resources = ARRAY_SIZE(mx21_usbhc_resources),
  475. .resource = mx21_usbhc_resources,
  476. };
  477. #endif