devices.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  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. static struct resource mxc_nand_resources[] = {
  135. {
  136. .start = NFC_BASE_ADDR,
  137. .end = NFC_BASE_ADDR + SZ_4K - 1,
  138. .flags = IORESOURCE_MEM,
  139. }, {
  140. .start = MX2x_INT_NANDFC,
  141. .end = MX2x_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 = MX2x_LCDC_BASE_ADDR,
  160. .end = MX2x_LCDC_BASE_ADDR + SZ_4K - 1,
  161. .flags = IORESOURCE_MEM,
  162. }, {
  163. .start = MX2x_INT_LCDC,
  164. .end = MX2x_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 = MX27_FEC_BASE_ADDR,
  182. .end = MX27_FEC_BASE_ADDR + SZ_4K - 1,
  183. .flags = IORESOURCE_MEM,
  184. }, {
  185. .start = MX27_INT_FEC,
  186. .end = MX27_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 = MX2x_PWM_BASE_ADDR,
  223. .end = MX2x_PWM_BASE_ADDR + SZ_4K - 1,
  224. .flags = IORESOURCE_MEM,
  225. }, {
  226. .start = MX2x_INT_PWM,
  227. .end = MX2x_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. #define DEFINE_MXC_MMC_DEVICE(n, baseaddr, irq, dmareq) \
  241. static struct resource mxc_sdhc_resources ## n[] = { \
  242. { \
  243. .start = baseaddr, \
  244. .end = baseaddr + SZ_4K - 1, \
  245. .flags = IORESOURCE_MEM, \
  246. }, { \
  247. .start = irq, \
  248. .end = irq, \
  249. .flags = IORESOURCE_IRQ, \
  250. }, { \
  251. .start = dmareq, \
  252. .end = dmareq, \
  253. .flags = IORESOURCE_DMA, \
  254. }, \
  255. }; \
  256. \
  257. static u64 mxc_sdhc ## n ## _dmamask = 0xffffffffUL; \
  258. \
  259. struct platform_device mxc_sdhc_device ## n = { \
  260. .name = "mxc-mmc", \
  261. .id = n, \
  262. .dev = { \
  263. .dma_mask = &mxc_sdhc ## n ## _dmamask, \
  264. .coherent_dma_mask = 0xffffffff, \
  265. }, \
  266. .num_resources = ARRAY_SIZE(mxc_sdhc_resources ## n), \
  267. .resource = mxc_sdhc_resources ## n, \
  268. }
  269. DEFINE_MXC_MMC_DEVICE(0, MX2x_SDHC1_BASE_ADDR, MX2x_INT_SDHC1, MX2x_DMA_REQ_SDHC1);
  270. DEFINE_MXC_MMC_DEVICE(1, MX2x_SDHC2_BASE_ADDR, MX2x_INT_SDHC2, MX2x_DMA_REQ_SDHC2);
  271. #ifdef CONFIG_MACH_MX27
  272. static struct resource otg_resources[] = {
  273. {
  274. .start = MX27_USBOTG_BASE_ADDR,
  275. .end = MX27_USBOTG_BASE_ADDR + 0x1ff,
  276. .flags = IORESOURCE_MEM,
  277. }, {
  278. .start = MX27_INT_USB3,
  279. .end = MX27_INT_USB3,
  280. .flags = IORESOURCE_IRQ,
  281. },
  282. };
  283. static u64 otg_dmamask = 0xffffffffUL;
  284. /* OTG gadget device */
  285. struct platform_device mxc_otg_udc_device = {
  286. .name = "fsl-usb2-udc",
  287. .id = -1,
  288. .dev = {
  289. .dma_mask = &otg_dmamask,
  290. .coherent_dma_mask = 0xffffffffUL,
  291. },
  292. .resource = otg_resources,
  293. .num_resources = ARRAY_SIZE(otg_resources),
  294. };
  295. /* OTG host */
  296. struct platform_device mxc_otg_host = {
  297. .name = "mxc-ehci",
  298. .id = 0,
  299. .dev = {
  300. .coherent_dma_mask = 0xffffffff,
  301. .dma_mask = &otg_dmamask,
  302. },
  303. .resource = otg_resources,
  304. .num_resources = ARRAY_SIZE(otg_resources),
  305. };
  306. /* USB host 1 */
  307. static u64 usbh1_dmamask = 0xffffffffUL;
  308. static struct resource mxc_usbh1_resources[] = {
  309. {
  310. .start = MX27_USBOTG_BASE_ADDR + 0x200,
  311. .end = MX27_USBOTG_BASE_ADDR + 0x3ff,
  312. .flags = IORESOURCE_MEM,
  313. }, {
  314. .start = MX27_INT_USB1,
  315. .end = MX27_INT_USB1,
  316. .flags = IORESOURCE_IRQ,
  317. },
  318. };
  319. struct platform_device mxc_usbh1 = {
  320. .name = "mxc-ehci",
  321. .id = 1,
  322. .dev = {
  323. .coherent_dma_mask = 0xffffffff,
  324. .dma_mask = &usbh1_dmamask,
  325. },
  326. .resource = mxc_usbh1_resources,
  327. .num_resources = ARRAY_SIZE(mxc_usbh1_resources),
  328. };
  329. /* USB host 2 */
  330. static u64 usbh2_dmamask = 0xffffffffUL;
  331. static struct resource mxc_usbh2_resources[] = {
  332. {
  333. .start = MX27_USBOTG_BASE_ADDR + 0x400,
  334. .end = MX27_USBOTG_BASE_ADDR + 0x5ff,
  335. .flags = IORESOURCE_MEM,
  336. }, {
  337. .start = MX27_INT_USB2,
  338. .end = MX27_INT_USB2,
  339. .flags = IORESOURCE_IRQ,
  340. },
  341. };
  342. struct platform_device mxc_usbh2 = {
  343. .name = "mxc-ehci",
  344. .id = 2,
  345. .dev = {
  346. .coherent_dma_mask = 0xffffffff,
  347. .dma_mask = &usbh2_dmamask,
  348. },
  349. .resource = mxc_usbh2_resources,
  350. .num_resources = ARRAY_SIZE(mxc_usbh2_resources),
  351. };
  352. #endif
  353. #define DEFINE_IMX_SSI_DMARES(_name, ssin, suffix) \
  354. { \
  355. .name = _name, \
  356. .start = MX2x_DMA_REQ_SSI ## ssin ## _ ## suffix, \
  357. .end = MX2x_DMA_REQ_SSI ## ssin ## _ ## suffix, \
  358. .flags = IORESOURCE_DMA, \
  359. }
  360. #define DEFINE_IMX_SSI_DEVICE(n, ssin, baseaddr, irq) \
  361. static struct resource imx_ssi_resources ## n[] = { \
  362. { \
  363. .start = MX2x_SSI ## ssin ## _BASE_ADDR, \
  364. .end = MX2x_SSI ## ssin ## _BASE_ADDR + 0x6f, \
  365. .flags = IORESOURCE_MEM, \
  366. }, { \
  367. .start = MX2x_INT_SSI1, \
  368. .end = MX2x_INT_SSI1, \
  369. .flags = IORESOURCE_IRQ, \
  370. }, \
  371. DEFINE_IMX_SSI_DMARES("tx0", ssin, TX0), \
  372. DEFINE_IMX_SSI_DMARES("rx0", ssin, RX0), \
  373. DEFINE_IMX_SSI_DMARES("tx1", ssin, TX1), \
  374. DEFINE_IMX_SSI_DMARES("rx1", ssin, RX1), \
  375. }; \
  376. \
  377. struct platform_device imx_ssi_device ## n = { \
  378. .name = "imx-ssi", \
  379. .id = n, \
  380. .num_resources = ARRAY_SIZE(imx_ssi_resources ## n), \
  381. .resource = imx_ssi_resources ## n, \
  382. }
  383. DEFINE_IMX_SSI_DEVICE(0, 1, MX2x_SSI1_BASE_ADDR, MX2x_INT_SSI1);
  384. DEFINE_IMX_SSI_DEVICE(1, 2, MX2x_SSI1_BASE_ADDR, MX2x_INT_SSI1);
  385. /* GPIO port description */
  386. static struct mxc_gpio_port imx_gpio_ports[] = {
  387. {
  388. .chip.label = "gpio-0",
  389. .irq = MX2x_INT_GPIO,
  390. .base = IO_ADDRESS(MX2x_GPIO_BASE_ADDR),
  391. .virtual_irq_start = MXC_GPIO_IRQ_START,
  392. }, {
  393. .chip.label = "gpio-1",
  394. .base = IO_ADDRESS(MX2x_GPIO_BASE_ADDR + 0x100),
  395. .virtual_irq_start = MXC_GPIO_IRQ_START + 32,
  396. }, {
  397. .chip.label = "gpio-2",
  398. .base = IO_ADDRESS(MX2x_GPIO_BASE_ADDR + 0x200),
  399. .virtual_irq_start = MXC_GPIO_IRQ_START + 64,
  400. }, {
  401. .chip.label = "gpio-3",
  402. .base = IO_ADDRESS(MX2x_GPIO_BASE_ADDR + 0x300),
  403. .virtual_irq_start = MXC_GPIO_IRQ_START + 96,
  404. }, {
  405. .chip.label = "gpio-4",
  406. .base = IO_ADDRESS(MX2x_GPIO_BASE_ADDR + 0x400),
  407. .virtual_irq_start = MXC_GPIO_IRQ_START + 128,
  408. }, {
  409. .chip.label = "gpio-5",
  410. .base = IO_ADDRESS(MX2x_GPIO_BASE_ADDR + 0x500),
  411. .virtual_irq_start = MXC_GPIO_IRQ_START + 160,
  412. }
  413. };
  414. int __init mxc_register_gpios(void)
  415. {
  416. return mxc_gpio_init(imx_gpio_ports, ARRAY_SIZE(imx_gpio_ports));
  417. }