devices.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540
  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. static struct resource mxc_i2c_1_resources[] = {
  198. {
  199. .start = I2C_BASE_ADDR,
  200. .end = I2C_BASE_ADDR + 0x0fff,
  201. .flags = IORESOURCE_MEM,
  202. }, {
  203. .start = MXC_INT_I2C,
  204. .end = MXC_INT_I2C,
  205. .flags = IORESOURCE_IRQ,
  206. }
  207. };
  208. struct platform_device mxc_i2c_device0 = {
  209. .name = "imx-i2c",
  210. .id = 0,
  211. .num_resources = ARRAY_SIZE(mxc_i2c_1_resources),
  212. .resource = mxc_i2c_1_resources,
  213. };
  214. #ifdef CONFIG_MACH_MX27
  215. static struct resource mxc_i2c_2_resources[] = {
  216. {
  217. .start = I2C2_BASE_ADDR,
  218. .end = I2C2_BASE_ADDR + 0x0fff,
  219. .flags = IORESOURCE_MEM,
  220. }, {
  221. .start = MXC_INT_I2C2,
  222. .end = MXC_INT_I2C2,
  223. .flags = IORESOURCE_IRQ,
  224. }
  225. };
  226. struct platform_device mxc_i2c_device1 = {
  227. .name = "imx-i2c",
  228. .id = 1,
  229. .num_resources = ARRAY_SIZE(mxc_i2c_2_resources),
  230. .resource = mxc_i2c_2_resources,
  231. };
  232. #endif
  233. static struct resource mxc_pwm_resources[] = {
  234. {
  235. .start = PWM_BASE_ADDR,
  236. .end = PWM_BASE_ADDR + 0x0fff,
  237. .flags = IORESOURCE_MEM,
  238. }, {
  239. .start = MXC_INT_PWM,
  240. .end = MXC_INT_PWM,
  241. .flags = IORESOURCE_IRQ,
  242. }
  243. };
  244. struct platform_device mxc_pwm_device = {
  245. .name = "mxc_pwm",
  246. .id = 0,
  247. .num_resources = ARRAY_SIZE(mxc_pwm_resources),
  248. .resource = mxc_pwm_resources,
  249. };
  250. /*
  251. * Resource definition for the MXC SDHC
  252. */
  253. static struct resource mxc_sdhc1_resources[] = {
  254. {
  255. .start = SDHC1_BASE_ADDR,
  256. .end = SDHC1_BASE_ADDR + SZ_4K - 1,
  257. .flags = IORESOURCE_MEM,
  258. }, {
  259. .start = MXC_INT_SDHC1,
  260. .end = MXC_INT_SDHC1,
  261. .flags = IORESOURCE_IRQ,
  262. }, {
  263. .start = DMA_REQ_SDHC1,
  264. .end = DMA_REQ_SDHC1,
  265. .flags = IORESOURCE_DMA,
  266. },
  267. };
  268. static u64 mxc_sdhc1_dmamask = 0xffffffffUL;
  269. struct platform_device mxc_sdhc_device0 = {
  270. .name = "mxc-mmc",
  271. .id = 0,
  272. .dev = {
  273. .dma_mask = &mxc_sdhc1_dmamask,
  274. .coherent_dma_mask = 0xffffffff,
  275. },
  276. .num_resources = ARRAY_SIZE(mxc_sdhc1_resources),
  277. .resource = mxc_sdhc1_resources,
  278. };
  279. static struct resource mxc_sdhc2_resources[] = {
  280. {
  281. .start = SDHC2_BASE_ADDR,
  282. .end = SDHC2_BASE_ADDR + SZ_4K - 1,
  283. .flags = IORESOURCE_MEM,
  284. }, {
  285. .start = MXC_INT_SDHC2,
  286. .end = MXC_INT_SDHC2,
  287. .flags = IORESOURCE_IRQ,
  288. }, {
  289. .start = DMA_REQ_SDHC2,
  290. .end = DMA_REQ_SDHC2,
  291. .flags = IORESOURCE_DMA,
  292. },
  293. };
  294. static u64 mxc_sdhc2_dmamask = 0xffffffffUL;
  295. struct platform_device mxc_sdhc_device1 = {
  296. .name = "mxc-mmc",
  297. .id = 1,
  298. .dev = {
  299. .dma_mask = &mxc_sdhc2_dmamask,
  300. .coherent_dma_mask = 0xffffffff,
  301. },
  302. .num_resources = ARRAY_SIZE(mxc_sdhc2_resources),
  303. .resource = mxc_sdhc2_resources,
  304. };
  305. #ifdef CONFIG_MACH_MX27
  306. static struct resource otg_resources[] = {
  307. {
  308. .start = OTG_BASE_ADDR,
  309. .end = OTG_BASE_ADDR + 0x1ff,
  310. .flags = IORESOURCE_MEM,
  311. }, {
  312. .start = MXC_INT_USB3,
  313. .end = MXC_INT_USB3,
  314. .flags = IORESOURCE_IRQ,
  315. },
  316. };
  317. static u64 otg_dmamask = 0xffffffffUL;
  318. /* OTG gadget device */
  319. struct platform_device mxc_otg_udc_device = {
  320. .name = "fsl-usb2-udc",
  321. .id = -1,
  322. .dev = {
  323. .dma_mask = &otg_dmamask,
  324. .coherent_dma_mask = 0xffffffffUL,
  325. },
  326. .resource = otg_resources,
  327. .num_resources = ARRAY_SIZE(otg_resources),
  328. };
  329. /* OTG host */
  330. struct platform_device mxc_otg_host = {
  331. .name = "mxc-ehci",
  332. .id = 0,
  333. .dev = {
  334. .coherent_dma_mask = 0xffffffff,
  335. .dma_mask = &otg_dmamask,
  336. },
  337. .resource = otg_resources,
  338. .num_resources = ARRAY_SIZE(otg_resources),
  339. };
  340. /* USB host 1 */
  341. static u64 usbh1_dmamask = 0xffffffffUL;
  342. static struct resource mxc_usbh1_resources[] = {
  343. {
  344. .start = OTG_BASE_ADDR + 0x200,
  345. .end = OTG_BASE_ADDR + 0x3ff,
  346. .flags = IORESOURCE_MEM,
  347. }, {
  348. .start = MXC_INT_USB1,
  349. .end = MXC_INT_USB1,
  350. .flags = IORESOURCE_IRQ,
  351. },
  352. };
  353. struct platform_device mxc_usbh1 = {
  354. .name = "mxc-ehci",
  355. .id = 1,
  356. .dev = {
  357. .coherent_dma_mask = 0xffffffff,
  358. .dma_mask = &usbh1_dmamask,
  359. },
  360. .resource = mxc_usbh1_resources,
  361. .num_resources = ARRAY_SIZE(mxc_usbh1_resources),
  362. };
  363. /* USB host 2 */
  364. static u64 usbh2_dmamask = 0xffffffffUL;
  365. static struct resource mxc_usbh2_resources[] = {
  366. {
  367. .start = OTG_BASE_ADDR + 0x400,
  368. .end = OTG_BASE_ADDR + 0x5ff,
  369. .flags = IORESOURCE_MEM,
  370. }, {
  371. .start = MXC_INT_USB2,
  372. .end = MXC_INT_USB2,
  373. .flags = IORESOURCE_IRQ,
  374. },
  375. };
  376. struct platform_device mxc_usbh2 = {
  377. .name = "mxc-ehci",
  378. .id = 2,
  379. .dev = {
  380. .coherent_dma_mask = 0xffffffff,
  381. .dma_mask = &usbh2_dmamask,
  382. },
  383. .resource = mxc_usbh2_resources,
  384. .num_resources = ARRAY_SIZE(mxc_usbh2_resources),
  385. };
  386. #endif
  387. static struct resource imx_ssi_resources0[] = {
  388. {
  389. .start = SSI1_BASE_ADDR,
  390. .end = SSI1_BASE_ADDR + 0x6F,
  391. .flags = IORESOURCE_MEM,
  392. }, {
  393. .start = MXC_INT_SSI1,
  394. .end = MXC_INT_SSI1,
  395. .flags = IORESOURCE_IRQ,
  396. }, {
  397. .name = "tx0",
  398. .start = DMA_REQ_SSI1_TX0,
  399. .end = DMA_REQ_SSI1_TX0,
  400. .flags = IORESOURCE_DMA,
  401. }, {
  402. .name = "rx0",
  403. .start = DMA_REQ_SSI1_RX0,
  404. .end = DMA_REQ_SSI1_RX0,
  405. .flags = IORESOURCE_DMA,
  406. }, {
  407. .name = "tx1",
  408. .start = DMA_REQ_SSI1_TX1,
  409. .end = DMA_REQ_SSI1_TX1,
  410. .flags = IORESOURCE_DMA,
  411. }, {
  412. .name = "rx1",
  413. .start = DMA_REQ_SSI1_RX1,
  414. .end = DMA_REQ_SSI1_RX1,
  415. .flags = IORESOURCE_DMA,
  416. },
  417. };
  418. static struct resource imx_ssi_resources1[] = {
  419. {
  420. .start = SSI2_BASE_ADDR,
  421. .end = SSI2_BASE_ADDR + 0x6F,
  422. .flags = IORESOURCE_MEM,
  423. }, {
  424. .start = MXC_INT_SSI2,
  425. .end = MXC_INT_SSI2,
  426. .flags = IORESOURCE_IRQ,
  427. }, {
  428. .name = "tx0",
  429. .start = DMA_REQ_SSI2_TX0,
  430. .end = DMA_REQ_SSI2_TX0,
  431. .flags = IORESOURCE_DMA,
  432. }, {
  433. .name = "rx0",
  434. .start = DMA_REQ_SSI2_RX0,
  435. .end = DMA_REQ_SSI2_RX0,
  436. .flags = IORESOURCE_DMA,
  437. }, {
  438. .name = "tx1",
  439. .start = DMA_REQ_SSI2_TX1,
  440. .end = DMA_REQ_SSI2_TX1,
  441. .flags = IORESOURCE_DMA,
  442. }, {
  443. .name = "rx1",
  444. .start = DMA_REQ_SSI2_RX1,
  445. .end = DMA_REQ_SSI2_RX1,
  446. .flags = IORESOURCE_DMA,
  447. },
  448. };
  449. struct platform_device imx_ssi_device0 = {
  450. .name = "imx-ssi",
  451. .id = 0,
  452. .num_resources = ARRAY_SIZE(imx_ssi_resources0),
  453. .resource = imx_ssi_resources0,
  454. };
  455. struct platform_device imx_ssi_device1 = {
  456. .name = "imx-ssi",
  457. .id = 1,
  458. .num_resources = ARRAY_SIZE(imx_ssi_resources1),
  459. .resource = imx_ssi_resources1,
  460. };
  461. /* GPIO port description */
  462. static struct mxc_gpio_port imx_gpio_ports[] = {
  463. {
  464. .chip.label = "gpio-0",
  465. .irq = MXC_INT_GPIO,
  466. .base = IO_ADDRESS(GPIO_BASE_ADDR),
  467. .virtual_irq_start = MXC_GPIO_IRQ_START,
  468. }, {
  469. .chip.label = "gpio-1",
  470. .base = IO_ADDRESS(GPIO_BASE_ADDR + 0x100),
  471. .virtual_irq_start = MXC_GPIO_IRQ_START + 32,
  472. }, {
  473. .chip.label = "gpio-2",
  474. .base = IO_ADDRESS(GPIO_BASE_ADDR + 0x200),
  475. .virtual_irq_start = MXC_GPIO_IRQ_START + 64,
  476. }, {
  477. .chip.label = "gpio-3",
  478. .base = IO_ADDRESS(GPIO_BASE_ADDR + 0x300),
  479. .virtual_irq_start = MXC_GPIO_IRQ_START + 96,
  480. }, {
  481. .chip.label = "gpio-4",
  482. .base = IO_ADDRESS(GPIO_BASE_ADDR + 0x400),
  483. .virtual_irq_start = MXC_GPIO_IRQ_START + 128,
  484. }, {
  485. .chip.label = "gpio-5",
  486. .base = IO_ADDRESS(GPIO_BASE_ADDR + 0x500),
  487. .virtual_irq_start = MXC_GPIO_IRQ_START + 160,
  488. }
  489. };
  490. int __init mxc_register_gpios(void)
  491. {
  492. return mxc_gpio_init(imx_gpio_ports, ARRAY_SIZE(imx_gpio_ports));
  493. }