devices.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483
  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 = MX2x_WDOG_BASE_ADDR,
  111. .end = MX2x_WDOG_BASE_ADDR + SZ_4K - 1,
  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 = MX2x_OWIRE_BASE_ADDR,
  124. .end = MX2x_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. #define DEFINE_MXC_NAND_DEVICE(pfx, baseaddr, irq) \
  135. static struct resource pfx ## _nand_resources[] = { \
  136. { \
  137. .start = baseaddr, \
  138. .end = baseaddr + SZ_4K - 1, \
  139. .flags = IORESOURCE_MEM, \
  140. }, { \
  141. .start = irq, \
  142. .end = irq, \
  143. .flags = IORESOURCE_IRQ, \
  144. }, \
  145. }; \
  146. \
  147. struct platform_device pfx ## _nand_device = { \
  148. .name = "mxc_nand", \
  149. .id = 0, \
  150. .num_resources = ARRAY_SIZE(pfx ## _nand_resources), \
  151. .resource = pfx ## _nand_resources, \
  152. }
  153. #ifdef CONFIG_MACH_MX21
  154. DEFINE_MXC_NAND_DEVICE(imx21, MX21_NFC_BASE_ADDR, MX21_INT_NANDFC);
  155. #endif
  156. #ifdef CONFIG_MACH_MX27
  157. DEFINE_MXC_NAND_DEVICE(imx27, MX27_NFC_BASE_ADDR, MX27_INT_NANDFC);
  158. #endif
  159. /*
  160. * lcdc:
  161. * - i.MX1: the basic controller
  162. * - i.MX21: to be checked
  163. * - i.MX27: like i.MX1, with slightly variations
  164. */
  165. static struct resource mxc_fb[] = {
  166. {
  167. .start = MX2x_LCDC_BASE_ADDR,
  168. .end = MX2x_LCDC_BASE_ADDR + SZ_4K - 1,
  169. .flags = IORESOURCE_MEM,
  170. }, {
  171. .start = MX2x_INT_LCDC,
  172. .end = MX2x_INT_LCDC,
  173. .flags = IORESOURCE_IRQ,
  174. }
  175. };
  176. /* mxc lcd driver */
  177. struct platform_device mxc_fb_device = {
  178. .name = "imx-fb",
  179. .id = 0,
  180. .num_resources = ARRAY_SIZE(mxc_fb),
  181. .resource = mxc_fb,
  182. .dev = {
  183. .coherent_dma_mask = 0xFFFFFFFF,
  184. },
  185. };
  186. #ifdef CONFIG_MACH_MX27
  187. static struct resource mxc_fec_resources[] = {
  188. {
  189. .start = MX27_FEC_BASE_ADDR,
  190. .end = MX27_FEC_BASE_ADDR + SZ_4K - 1,
  191. .flags = IORESOURCE_MEM,
  192. }, {
  193. .start = MX27_INT_FEC,
  194. .end = MX27_INT_FEC,
  195. .flags = IORESOURCE_IRQ,
  196. },
  197. };
  198. struct platform_device mxc_fec_device = {
  199. .name = "fec",
  200. .id = 0,
  201. .num_resources = ARRAY_SIZE(mxc_fec_resources),
  202. .resource = mxc_fec_resources,
  203. };
  204. #endif
  205. #define DEFINE_IMX_I2C_DEVICE(n, baseaddr, irq) \
  206. static struct resource mxc_i2c_resources ## n[] = { \
  207. { \
  208. .start = baseaddr, \
  209. .end = baseaddr + SZ_4K - 1, \
  210. .flags = IORESOURCE_MEM, \
  211. }, { \
  212. .start = irq, \
  213. .end = irq, \
  214. .flags = IORESOURCE_IRQ, \
  215. } \
  216. }; \
  217. \
  218. struct platform_device mxc_i2c_device ## n = { \
  219. .name = "imx-i2c", \
  220. .id = n, \
  221. .num_resources = ARRAY_SIZE(mxc_i2c_resources ## n), \
  222. .resource = mxc_i2c_resources ## n, \
  223. }
  224. DEFINE_IMX_I2C_DEVICE(0, MX2x_I2C_BASE_ADDR, MX2x_INT_I2C);
  225. #ifdef CONFIG_MACH_MX27
  226. DEFINE_IMX_I2C_DEVICE(1, MX27_I2C2_BASE_ADDR, MX27_INT_I2C2);
  227. #endif
  228. static struct resource mxc_pwm_resources[] = {
  229. {
  230. .start = MX2x_PWM_BASE_ADDR,
  231. .end = MX2x_PWM_BASE_ADDR + SZ_4K - 1,
  232. .flags = IORESOURCE_MEM,
  233. }, {
  234. .start = MX2x_INT_PWM,
  235. .end = MX2x_INT_PWM,
  236. .flags = IORESOURCE_IRQ,
  237. }
  238. };
  239. struct platform_device mxc_pwm_device = {
  240. .name = "mxc_pwm",
  241. .id = 0,
  242. .num_resources = ARRAY_SIZE(mxc_pwm_resources),
  243. .resource = mxc_pwm_resources,
  244. };
  245. /*
  246. * Resource definition for the MXC SDHC
  247. */
  248. #define DEFINE_MXC_MMC_DEVICE(n, baseaddr, irq, dmareq) \
  249. static struct resource mxc_sdhc_resources ## n[] = { \
  250. { \
  251. .start = baseaddr, \
  252. .end = baseaddr + SZ_4K - 1, \
  253. .flags = IORESOURCE_MEM, \
  254. }, { \
  255. .start = irq, \
  256. .end = irq, \
  257. .flags = IORESOURCE_IRQ, \
  258. }, { \
  259. .start = dmareq, \
  260. .end = dmareq, \
  261. .flags = IORESOURCE_DMA, \
  262. }, \
  263. }; \
  264. \
  265. static u64 mxc_sdhc ## n ## _dmamask = 0xffffffffUL; \
  266. \
  267. struct platform_device mxc_sdhc_device ## n = { \
  268. .name = "mxc-mmc", \
  269. .id = n, \
  270. .dev = { \
  271. .dma_mask = &mxc_sdhc ## n ## _dmamask, \
  272. .coherent_dma_mask = 0xffffffff, \
  273. }, \
  274. .num_resources = ARRAY_SIZE(mxc_sdhc_resources ## n), \
  275. .resource = mxc_sdhc_resources ## n, \
  276. }
  277. DEFINE_MXC_MMC_DEVICE(0, MX2x_SDHC1_BASE_ADDR, MX2x_INT_SDHC1, MX2x_DMA_REQ_SDHC1);
  278. DEFINE_MXC_MMC_DEVICE(1, MX2x_SDHC2_BASE_ADDR, MX2x_INT_SDHC2, MX2x_DMA_REQ_SDHC2);
  279. #ifdef CONFIG_MACH_MX27
  280. static struct resource otg_resources[] = {
  281. {
  282. .start = MX27_USBOTG_BASE_ADDR,
  283. .end = MX27_USBOTG_BASE_ADDR + 0x1ff,
  284. .flags = IORESOURCE_MEM,
  285. }, {
  286. .start = MX27_INT_USB3,
  287. .end = MX27_INT_USB3,
  288. .flags = IORESOURCE_IRQ,
  289. },
  290. };
  291. static u64 otg_dmamask = 0xffffffffUL;
  292. /* OTG gadget device */
  293. struct platform_device mxc_otg_udc_device = {
  294. .name = "fsl-usb2-udc",
  295. .id = -1,
  296. .dev = {
  297. .dma_mask = &otg_dmamask,
  298. .coherent_dma_mask = 0xffffffffUL,
  299. },
  300. .resource = otg_resources,
  301. .num_resources = ARRAY_SIZE(otg_resources),
  302. };
  303. /* OTG host */
  304. struct platform_device mxc_otg_host = {
  305. .name = "mxc-ehci",
  306. .id = 0,
  307. .dev = {
  308. .coherent_dma_mask = 0xffffffff,
  309. .dma_mask = &otg_dmamask,
  310. },
  311. .resource = otg_resources,
  312. .num_resources = ARRAY_SIZE(otg_resources),
  313. };
  314. /* USB host 1 */
  315. static u64 usbh1_dmamask = 0xffffffffUL;
  316. static struct resource mxc_usbh1_resources[] = {
  317. {
  318. .start = MX27_USBOTG_BASE_ADDR + 0x200,
  319. .end = MX27_USBOTG_BASE_ADDR + 0x3ff,
  320. .flags = IORESOURCE_MEM,
  321. }, {
  322. .start = MX27_INT_USB1,
  323. .end = MX27_INT_USB1,
  324. .flags = IORESOURCE_IRQ,
  325. },
  326. };
  327. struct platform_device mxc_usbh1 = {
  328. .name = "mxc-ehci",
  329. .id = 1,
  330. .dev = {
  331. .coherent_dma_mask = 0xffffffff,
  332. .dma_mask = &usbh1_dmamask,
  333. },
  334. .resource = mxc_usbh1_resources,
  335. .num_resources = ARRAY_SIZE(mxc_usbh1_resources),
  336. };
  337. /* USB host 2 */
  338. static u64 usbh2_dmamask = 0xffffffffUL;
  339. static struct resource mxc_usbh2_resources[] = {
  340. {
  341. .start = MX27_USBOTG_BASE_ADDR + 0x400,
  342. .end = MX27_USBOTG_BASE_ADDR + 0x5ff,
  343. .flags = IORESOURCE_MEM,
  344. }, {
  345. .start = MX27_INT_USB2,
  346. .end = MX27_INT_USB2,
  347. .flags = IORESOURCE_IRQ,
  348. },
  349. };
  350. struct platform_device mxc_usbh2 = {
  351. .name = "mxc-ehci",
  352. .id = 2,
  353. .dev = {
  354. .coherent_dma_mask = 0xffffffff,
  355. .dma_mask = &usbh2_dmamask,
  356. },
  357. .resource = mxc_usbh2_resources,
  358. .num_resources = ARRAY_SIZE(mxc_usbh2_resources),
  359. };
  360. #endif
  361. #define DEFINE_IMX_SSI_DMARES(_name, ssin, suffix) \
  362. { \
  363. .name = _name, \
  364. .start = MX2x_DMA_REQ_SSI ## ssin ## _ ## suffix, \
  365. .end = MX2x_DMA_REQ_SSI ## ssin ## _ ## suffix, \
  366. .flags = IORESOURCE_DMA, \
  367. }
  368. #define DEFINE_IMX_SSI_DEVICE(n, ssin, baseaddr, irq) \
  369. static struct resource imx_ssi_resources ## n[] = { \
  370. { \
  371. .start = MX2x_SSI ## ssin ## _BASE_ADDR, \
  372. .end = MX2x_SSI ## ssin ## _BASE_ADDR + 0x6f, \
  373. .flags = IORESOURCE_MEM, \
  374. }, { \
  375. .start = MX2x_INT_SSI1, \
  376. .end = MX2x_INT_SSI1, \
  377. .flags = IORESOURCE_IRQ, \
  378. }, \
  379. DEFINE_IMX_SSI_DMARES("tx0", ssin, TX0), \
  380. DEFINE_IMX_SSI_DMARES("rx0", ssin, RX0), \
  381. DEFINE_IMX_SSI_DMARES("tx1", ssin, TX1), \
  382. DEFINE_IMX_SSI_DMARES("rx1", ssin, RX1), \
  383. }; \
  384. \
  385. struct platform_device imx_ssi_device ## n = { \
  386. .name = "imx-ssi", \
  387. .id = n, \
  388. .num_resources = ARRAY_SIZE(imx_ssi_resources ## n), \
  389. .resource = imx_ssi_resources ## n, \
  390. }
  391. DEFINE_IMX_SSI_DEVICE(0, 1, MX2x_SSI1_BASE_ADDR, MX2x_INT_SSI1);
  392. DEFINE_IMX_SSI_DEVICE(1, 2, MX2x_SSI1_BASE_ADDR, MX2x_INT_SSI1);
  393. /* GPIO port description */
  394. #define DEFINE_MXC_GPIO_PORT_IRQ(SOC, n, _irq) \
  395. { \
  396. .chip.label = "gpio-" #n, \
  397. .irq = _irq, \
  398. .base = SOC ## _IO_ADDRESS(MX2x_GPIO_BASE_ADDR + \
  399. n * 0x100), \
  400. .virtual_irq_start = MXC_GPIO_IRQ_START + n * 32, \
  401. }
  402. #define DEFINE_MXC_GPIO_PORT(SOC, n) \
  403. { \
  404. .chip.label = "gpio-" #n, \
  405. .base = SOC ## _IO_ADDRESS(MX2x_GPIO_BASE_ADDR + \
  406. n * 0x100), \
  407. .virtual_irq_start = MXC_GPIO_IRQ_START + n * 32, \
  408. }
  409. #define DEFINE_MXC_GPIO_PORTS(SOC, pfx) \
  410. static struct mxc_gpio_port pfx ## _gpio_ports[] = { \
  411. DEFINE_MXC_GPIO_PORT_IRQ(SOC, 0, SOC ## _INT_GPIO), \
  412. DEFINE_MXC_GPIO_PORT(SOC, 1), \
  413. DEFINE_MXC_GPIO_PORT(SOC, 2), \
  414. DEFINE_MXC_GPIO_PORT(SOC, 3), \
  415. DEFINE_MXC_GPIO_PORT(SOC, 4), \
  416. DEFINE_MXC_GPIO_PORT(SOC, 5), \
  417. }
  418. #ifdef CONFIG_MACH_MX21
  419. DEFINE_MXC_GPIO_PORTS(MX21, imx21);
  420. #endif
  421. #ifdef CONFIG_MACH_MX27
  422. DEFINE_MXC_GPIO_PORTS(MX27, imx27);
  423. #endif
  424. int __init mxc_register_gpios(void)
  425. {
  426. #ifdef CONFIG_MACH_MX21
  427. if (cpu_is_mx21())
  428. return mxc_gpio_init(imx21_gpio_ports, ARRAY_SIZE(imx21_gpio_ports));
  429. else
  430. #endif
  431. #ifdef CONFIG_MACH_MX27
  432. if (cpu_is_mx27())
  433. return mxc_gpio_init(imx27_gpio_ports, ARRAY_SIZE(imx27_gpio_ports));
  434. else
  435. #endif
  436. return 0;
  437. }