devices.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526
  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 <mach/irqs.h>
  35. #include <mach/hardware.h>
  36. #include <mach/common.h>
  37. #include <mach/mmc.h>
  38. #include "devices.h"
  39. /*
  40. * SPI master controller
  41. *
  42. * - i.MX1: 2 channel (slighly different register setting)
  43. * - i.MX21: 2 channel
  44. * - i.MX27: 3 channel
  45. */
  46. #define DEFINE_IMX_SPI_DEVICE(n, baseaddr, irq) \
  47. static struct resource mxc_spi_resources ## n[] = { \
  48. { \
  49. .start = baseaddr, \
  50. .end = baseaddr + SZ_4K - 1, \
  51. .flags = IORESOURCE_MEM, \
  52. }, { \
  53. .start = irq, \
  54. .end = irq, \
  55. .flags = IORESOURCE_IRQ, \
  56. }, \
  57. }; \
  58. \
  59. struct platform_device mxc_spi_device ## n = { \
  60. .name = "spi_imx", \
  61. .id = n, \
  62. .num_resources = ARRAY_SIZE(mxc_spi_resources ## n), \
  63. .resource = mxc_spi_resources ## n, \
  64. }
  65. DEFINE_IMX_SPI_DEVICE(0, MX2x_CSPI1_BASE_ADDR, MX2x_INT_CSPI1);
  66. DEFINE_IMX_SPI_DEVICE(1, MX2x_CSPI2_BASE_ADDR, MX2x_INT_CSPI2);
  67. #ifdef CONFIG_MACH_MX27
  68. DEFINE_IMX_SPI_DEVICE(2, MX27_CSPI3_BASE_ADDR, MX27_INT_CSPI3);
  69. #endif
  70. /*
  71. * General Purpose Timer
  72. * - i.MX21: 3 timers
  73. * - i.MX27: 6 timers
  74. */
  75. #define DEFINE_IMX_GPT_DEVICE(n, baseaddr, irq) \
  76. static struct resource timer ## n ##_resources[] = { \
  77. { \
  78. .start = baseaddr, \
  79. .end = baseaddr + SZ_4K - 1, \
  80. .flags = IORESOURCE_MEM, \
  81. }, { \
  82. .start = irq, \
  83. .end = irq, \
  84. .flags = IORESOURCE_IRQ, \
  85. } \
  86. }; \
  87. \
  88. struct platform_device mxc_gpt ## n = { \
  89. .name = "imx_gpt", \
  90. .id = n, \
  91. .num_resources = ARRAY_SIZE(timer ## n ## _resources), \
  92. .resource = timer ## n ## _resources, \
  93. }
  94. /* We use gpt1 as system timer, so do not add a device for this one */
  95. DEFINE_IMX_GPT_DEVICE(1, MX2x_GPT2_BASE_ADDR, MX2x_INT_GPT2);
  96. DEFINE_IMX_GPT_DEVICE(2, MX2x_GPT3_BASE_ADDR, MX2x_INT_GPT3);
  97. #ifdef CONFIG_MACH_MX27
  98. DEFINE_IMX_GPT_DEVICE(3, MX27_GPT4_BASE_ADDR, MX27_INT_GPT4);
  99. DEFINE_IMX_GPT_DEVICE(4, MX27_GPT5_BASE_ADDR, MX27_INT_GPT5);
  100. DEFINE_IMX_GPT_DEVICE(5, MX27_GPT6_BASE_ADDR, MX27_INT_GPT6);
  101. #endif
  102. /*
  103. * Watchdog:
  104. * - i.MX1
  105. * - i.MX21
  106. * - i.MX27
  107. */
  108. static struct resource mxc_wdt_resources[] = {
  109. {
  110. .start = WDOG_BASE_ADDR,
  111. .end = WDOG_BASE_ADDR + 0x30,
  112. .flags = IORESOURCE_MEM,
  113. },
  114. };
  115. struct platform_device mxc_wdt = {
  116. .name = "mxc_wdt",
  117. .id = 0,
  118. .num_resources = ARRAY_SIZE(mxc_wdt_resources),
  119. .resource = mxc_wdt_resources,
  120. };
  121. static struct resource mxc_w1_master_resources[] = {
  122. {
  123. .start = OWIRE_BASE_ADDR,
  124. .end = OWIRE_BASE_ADDR + SZ_4K - 1,
  125. .flags = IORESOURCE_MEM,
  126. },
  127. };
  128. struct platform_device mxc_w1_master_device = {
  129. .name = "mxc_w1",
  130. .id = 0,
  131. .num_resources = ARRAY_SIZE(mxc_w1_master_resources),
  132. .resource = mxc_w1_master_resources,
  133. };
  134. static struct resource mxc_nand_resources[] = {
  135. {
  136. .start = NFC_BASE_ADDR,
  137. .end = NFC_BASE_ADDR + 0xfff,
  138. .flags = IORESOURCE_MEM,
  139. }, {
  140. .start = MXC_INT_NANDFC,
  141. .end = MXC_INT_NANDFC,
  142. .flags = IORESOURCE_IRQ,
  143. },
  144. };
  145. struct platform_device mxc_nand_device = {
  146. .name = "mxc_nand",
  147. .id = 0,
  148. .num_resources = ARRAY_SIZE(mxc_nand_resources),
  149. .resource = mxc_nand_resources,
  150. };
  151. /*
  152. * lcdc:
  153. * - i.MX1: the basic controller
  154. * - i.MX21: to be checked
  155. * - i.MX27: like i.MX1, with slightly variations
  156. */
  157. static struct resource mxc_fb[] = {
  158. {
  159. .start = LCDC_BASE_ADDR,
  160. .end = LCDC_BASE_ADDR + 0xFFF,
  161. .flags = IORESOURCE_MEM,
  162. }, {
  163. .start = MXC_INT_LCDC,
  164. .end = MXC_INT_LCDC,
  165. .flags = IORESOURCE_IRQ,
  166. }
  167. };
  168. /* mxc lcd driver */
  169. struct platform_device mxc_fb_device = {
  170. .name = "imx-fb",
  171. .id = 0,
  172. .num_resources = ARRAY_SIZE(mxc_fb),
  173. .resource = mxc_fb,
  174. .dev = {
  175. .coherent_dma_mask = 0xFFFFFFFF,
  176. },
  177. };
  178. #ifdef CONFIG_MACH_MX27
  179. static struct resource mxc_fec_resources[] = {
  180. {
  181. .start = FEC_BASE_ADDR,
  182. .end = FEC_BASE_ADDR + 0xfff,
  183. .flags = IORESOURCE_MEM,
  184. }, {
  185. .start = MXC_INT_FEC,
  186. .end = MXC_INT_FEC,
  187. .flags = IORESOURCE_IRQ,
  188. },
  189. };
  190. struct platform_device mxc_fec_device = {
  191. .name = "fec",
  192. .id = 0,
  193. .num_resources = ARRAY_SIZE(mxc_fec_resources),
  194. .resource = mxc_fec_resources,
  195. };
  196. #endif
  197. #define DEFINE_IMX_I2C_DEVICE(n, baseaddr, irq) \
  198. static struct resource mxc_i2c_resources ## n[] = { \
  199. { \
  200. .start = baseaddr, \
  201. .end = baseaddr + SZ_4K - 1, \
  202. .flags = IORESOURCE_MEM, \
  203. }, { \
  204. .start = irq, \
  205. .end = irq, \
  206. .flags = IORESOURCE_IRQ, \
  207. } \
  208. }; \
  209. \
  210. struct platform_device mxc_i2c_device ## n = { \
  211. .name = "imx-i2c", \
  212. .id = n, \
  213. .num_resources = ARRAY_SIZE(mxc_i2c_resources ## n), \
  214. .resource = mxc_i2c_resources ## n, \
  215. }
  216. DEFINE_IMX_I2C_DEVICE(0, MX2x_I2C_BASE_ADDR, MX2x_INT_I2C);
  217. #ifdef CONFIG_MACH_MX27
  218. DEFINE_IMX_I2C_DEVICE(1, MX27_I2C2_BASE_ADDR, MX27_INT_I2C2);
  219. #endif
  220. static struct resource mxc_pwm_resources[] = {
  221. {
  222. .start = PWM_BASE_ADDR,
  223. .end = PWM_BASE_ADDR + 0x0fff,
  224. .flags = IORESOURCE_MEM,
  225. }, {
  226. .start = MXC_INT_PWM,
  227. .end = MXC_INT_PWM,
  228. .flags = IORESOURCE_IRQ,
  229. }
  230. };
  231. struct platform_device mxc_pwm_device = {
  232. .name = "mxc_pwm",
  233. .id = 0,
  234. .num_resources = ARRAY_SIZE(mxc_pwm_resources),
  235. .resource = mxc_pwm_resources,
  236. };
  237. /*
  238. * Resource definition for the MXC SDHC
  239. */
  240. static struct resource mxc_sdhc1_resources[] = {
  241. {
  242. .start = SDHC1_BASE_ADDR,
  243. .end = SDHC1_BASE_ADDR + SZ_4K - 1,
  244. .flags = IORESOURCE_MEM,
  245. }, {
  246. .start = MXC_INT_SDHC1,
  247. .end = MXC_INT_SDHC1,
  248. .flags = IORESOURCE_IRQ,
  249. }, {
  250. .start = DMA_REQ_SDHC1,
  251. .end = DMA_REQ_SDHC1,
  252. .flags = IORESOURCE_DMA,
  253. },
  254. };
  255. static u64 mxc_sdhc1_dmamask = 0xffffffffUL;
  256. struct platform_device mxc_sdhc_device0 = {
  257. .name = "mxc-mmc",
  258. .id = 0,
  259. .dev = {
  260. .dma_mask = &mxc_sdhc1_dmamask,
  261. .coherent_dma_mask = 0xffffffff,
  262. },
  263. .num_resources = ARRAY_SIZE(mxc_sdhc1_resources),
  264. .resource = mxc_sdhc1_resources,
  265. };
  266. static struct resource mxc_sdhc2_resources[] = {
  267. {
  268. .start = SDHC2_BASE_ADDR,
  269. .end = SDHC2_BASE_ADDR + SZ_4K - 1,
  270. .flags = IORESOURCE_MEM,
  271. }, {
  272. .start = MXC_INT_SDHC2,
  273. .end = MXC_INT_SDHC2,
  274. .flags = IORESOURCE_IRQ,
  275. }, {
  276. .start = DMA_REQ_SDHC2,
  277. .end = DMA_REQ_SDHC2,
  278. .flags = IORESOURCE_DMA,
  279. },
  280. };
  281. static u64 mxc_sdhc2_dmamask = 0xffffffffUL;
  282. struct platform_device mxc_sdhc_device1 = {
  283. .name = "mxc-mmc",
  284. .id = 1,
  285. .dev = {
  286. .dma_mask = &mxc_sdhc2_dmamask,
  287. .coherent_dma_mask = 0xffffffff,
  288. },
  289. .num_resources = ARRAY_SIZE(mxc_sdhc2_resources),
  290. .resource = mxc_sdhc2_resources,
  291. };
  292. #ifdef CONFIG_MACH_MX27
  293. static struct resource otg_resources[] = {
  294. {
  295. .start = OTG_BASE_ADDR,
  296. .end = OTG_BASE_ADDR + 0x1ff,
  297. .flags = IORESOURCE_MEM,
  298. }, {
  299. .start = MXC_INT_USB3,
  300. .end = MXC_INT_USB3,
  301. .flags = IORESOURCE_IRQ,
  302. },
  303. };
  304. static u64 otg_dmamask = 0xffffffffUL;
  305. /* OTG gadget device */
  306. struct platform_device mxc_otg_udc_device = {
  307. .name = "fsl-usb2-udc",
  308. .id = -1,
  309. .dev = {
  310. .dma_mask = &otg_dmamask,
  311. .coherent_dma_mask = 0xffffffffUL,
  312. },
  313. .resource = otg_resources,
  314. .num_resources = ARRAY_SIZE(otg_resources),
  315. };
  316. /* OTG host */
  317. struct platform_device mxc_otg_host = {
  318. .name = "mxc-ehci",
  319. .id = 0,
  320. .dev = {
  321. .coherent_dma_mask = 0xffffffff,
  322. .dma_mask = &otg_dmamask,
  323. },
  324. .resource = otg_resources,
  325. .num_resources = ARRAY_SIZE(otg_resources),
  326. };
  327. /* USB host 1 */
  328. static u64 usbh1_dmamask = 0xffffffffUL;
  329. static struct resource mxc_usbh1_resources[] = {
  330. {
  331. .start = OTG_BASE_ADDR + 0x200,
  332. .end = OTG_BASE_ADDR + 0x3ff,
  333. .flags = IORESOURCE_MEM,
  334. }, {
  335. .start = MXC_INT_USB1,
  336. .end = MXC_INT_USB1,
  337. .flags = IORESOURCE_IRQ,
  338. },
  339. };
  340. struct platform_device mxc_usbh1 = {
  341. .name = "mxc-ehci",
  342. .id = 1,
  343. .dev = {
  344. .coherent_dma_mask = 0xffffffff,
  345. .dma_mask = &usbh1_dmamask,
  346. },
  347. .resource = mxc_usbh1_resources,
  348. .num_resources = ARRAY_SIZE(mxc_usbh1_resources),
  349. };
  350. /* USB host 2 */
  351. static u64 usbh2_dmamask = 0xffffffffUL;
  352. static struct resource mxc_usbh2_resources[] = {
  353. {
  354. .start = OTG_BASE_ADDR + 0x400,
  355. .end = OTG_BASE_ADDR + 0x5ff,
  356. .flags = IORESOURCE_MEM,
  357. }, {
  358. .start = MXC_INT_USB2,
  359. .end = MXC_INT_USB2,
  360. .flags = IORESOURCE_IRQ,
  361. },
  362. };
  363. struct platform_device mxc_usbh2 = {
  364. .name = "mxc-ehci",
  365. .id = 2,
  366. .dev = {
  367. .coherent_dma_mask = 0xffffffff,
  368. .dma_mask = &usbh2_dmamask,
  369. },
  370. .resource = mxc_usbh2_resources,
  371. .num_resources = ARRAY_SIZE(mxc_usbh2_resources),
  372. };
  373. #endif
  374. static struct resource imx_ssi_resources0[] = {
  375. {
  376. .start = SSI1_BASE_ADDR,
  377. .end = SSI1_BASE_ADDR + 0x6F,
  378. .flags = IORESOURCE_MEM,
  379. }, {
  380. .start = MXC_INT_SSI1,
  381. .end = MXC_INT_SSI1,
  382. .flags = IORESOURCE_IRQ,
  383. }, {
  384. .name = "tx0",
  385. .start = DMA_REQ_SSI1_TX0,
  386. .end = DMA_REQ_SSI1_TX0,
  387. .flags = IORESOURCE_DMA,
  388. }, {
  389. .name = "rx0",
  390. .start = DMA_REQ_SSI1_RX0,
  391. .end = DMA_REQ_SSI1_RX0,
  392. .flags = IORESOURCE_DMA,
  393. }, {
  394. .name = "tx1",
  395. .start = DMA_REQ_SSI1_TX1,
  396. .end = DMA_REQ_SSI1_TX1,
  397. .flags = IORESOURCE_DMA,
  398. }, {
  399. .name = "rx1",
  400. .start = DMA_REQ_SSI1_RX1,
  401. .end = DMA_REQ_SSI1_RX1,
  402. .flags = IORESOURCE_DMA,
  403. },
  404. };
  405. static struct resource imx_ssi_resources1[] = {
  406. {
  407. .start = SSI2_BASE_ADDR,
  408. .end = SSI2_BASE_ADDR + 0x6F,
  409. .flags = IORESOURCE_MEM,
  410. }, {
  411. .start = MXC_INT_SSI2,
  412. .end = MXC_INT_SSI2,
  413. .flags = IORESOURCE_IRQ,
  414. }, {
  415. .name = "tx0",
  416. .start = DMA_REQ_SSI2_TX0,
  417. .end = DMA_REQ_SSI2_TX0,
  418. .flags = IORESOURCE_DMA,
  419. }, {
  420. .name = "rx0",
  421. .start = DMA_REQ_SSI2_RX0,
  422. .end = DMA_REQ_SSI2_RX0,
  423. .flags = IORESOURCE_DMA,
  424. }, {
  425. .name = "tx1",
  426. .start = DMA_REQ_SSI2_TX1,
  427. .end = DMA_REQ_SSI2_TX1,
  428. .flags = IORESOURCE_DMA,
  429. }, {
  430. .name = "rx1",
  431. .start = DMA_REQ_SSI2_RX1,
  432. .end = DMA_REQ_SSI2_RX1,
  433. .flags = IORESOURCE_DMA,
  434. },
  435. };
  436. struct platform_device imx_ssi_device0 = {
  437. .name = "imx-ssi",
  438. .id = 0,
  439. .num_resources = ARRAY_SIZE(imx_ssi_resources0),
  440. .resource = imx_ssi_resources0,
  441. };
  442. struct platform_device imx_ssi_device1 = {
  443. .name = "imx-ssi",
  444. .id = 1,
  445. .num_resources = ARRAY_SIZE(imx_ssi_resources1),
  446. .resource = imx_ssi_resources1,
  447. };
  448. /* GPIO port description */
  449. static struct mxc_gpio_port imx_gpio_ports[] = {
  450. {
  451. .chip.label = "gpio-0",
  452. .irq = MXC_INT_GPIO,
  453. .base = IO_ADDRESS(GPIO_BASE_ADDR),
  454. .virtual_irq_start = MXC_GPIO_IRQ_START,
  455. }, {
  456. .chip.label = "gpio-1",
  457. .base = IO_ADDRESS(GPIO_BASE_ADDR + 0x100),
  458. .virtual_irq_start = MXC_GPIO_IRQ_START + 32,
  459. }, {
  460. .chip.label = "gpio-2",
  461. .base = IO_ADDRESS(GPIO_BASE_ADDR + 0x200),
  462. .virtual_irq_start = MXC_GPIO_IRQ_START + 64,
  463. }, {
  464. .chip.label = "gpio-3",
  465. .base = IO_ADDRESS(GPIO_BASE_ADDR + 0x300),
  466. .virtual_irq_start = MXC_GPIO_IRQ_START + 96,
  467. }, {
  468. .chip.label = "gpio-4",
  469. .base = IO_ADDRESS(GPIO_BASE_ADDR + 0x400),
  470. .virtual_irq_start = MXC_GPIO_IRQ_START + 128,
  471. }, {
  472. .chip.label = "gpio-5",
  473. .base = IO_ADDRESS(GPIO_BASE_ADDR + 0x500),
  474. .virtual_irq_start = MXC_GPIO_IRQ_START + 160,
  475. }
  476. };
  477. int __init mxc_register_gpios(void)
  478. {
  479. return mxc_gpio_init(imx_gpio_ports, ARRAY_SIZE(imx_gpio_ports));
  480. }