devices.c 13 KB

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