devices.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538
  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. * Copyright 2008 Sascha Hauer, kernel@pengutronix.de
  15. * Copyright (c) 2008 Paulius Zaleckas <paulius.zaleckas@teltonika.lt>
  16. * Copyright (c) 2008 Darius Augulis <darius.augulis@teltonika.lt>
  17. *
  18. * This program is free software; you can redistribute it and/or
  19. * modify it under the terms of the GNU General Public License
  20. * as published by the Free Software Foundation; either version 2
  21. * of the License, or (at your option) any later version.
  22. * This program is distributed in the hope that it will be useful,
  23. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. * GNU General Public License for more details.
  26. *
  27. * You should have received a copy of the GNU General Public License
  28. * along with this program; if not, write to the Free Software
  29. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  30. * MA 02110-1301, USA.
  31. */
  32. #include <linux/module.h>
  33. #include <linux/kernel.h>
  34. #include <linux/init.h>
  35. #include <linux/platform_device.h>
  36. #include <linux/gpio.h>
  37. #include <linux/dma-mapping.h>
  38. #include <linux/serial.h>
  39. #include <mach/irqs.h>
  40. #include <mach/hardware.h>
  41. #include <mach/common.h>
  42. #include <mach/mmc.h>
  43. #include "devices.h"
  44. #if defined(CONFIG_ARCH_MX1)
  45. static struct resource imx1_camera_resources[] = {
  46. {
  47. .start = 0x00224000,
  48. .end = 0x00224010,
  49. .flags = IORESOURCE_MEM,
  50. }, {
  51. .start = MX1_CSI_INT,
  52. .end = MX1_CSI_INT,
  53. .flags = IORESOURCE_IRQ,
  54. },
  55. };
  56. static u64 imx1_camera_dmamask = DMA_BIT_MASK(32);
  57. struct platform_device imx1_camera_device = {
  58. .name = "mx1-camera",
  59. .id = 0, /* This is used to put cameras on this interface */
  60. .dev = {
  61. .dma_mask = &imx1_camera_dmamask,
  62. .coherent_dma_mask = DMA_BIT_MASK(32),
  63. },
  64. .resource = imx1_camera_resources,
  65. .num_resources = ARRAY_SIZE(imx1_camera_resources),
  66. };
  67. static struct resource imx_rtc_resources[] = {
  68. {
  69. .start = 0x00204000,
  70. .end = 0x00204024,
  71. .flags = IORESOURCE_MEM,
  72. }, {
  73. .start = MX1_RTC_INT,
  74. .end = MX1_RTC_INT,
  75. .flags = IORESOURCE_IRQ,
  76. }, {
  77. .start = MX1_RTC_SAMINT,
  78. .end = MX1_RTC_SAMINT,
  79. .flags = IORESOURCE_IRQ,
  80. },
  81. };
  82. struct platform_device imx_rtc_device = {
  83. .name = "rtc-imx",
  84. .id = 0,
  85. .resource = imx_rtc_resources,
  86. .num_resources = ARRAY_SIZE(imx_rtc_resources),
  87. };
  88. static struct resource imx_wdt_resources[] = {
  89. {
  90. .start = 0x00201000,
  91. .end = 0x00201008,
  92. .flags = IORESOURCE_MEM,
  93. }, {
  94. .start = MX1_WDT_INT,
  95. .end = MX1_WDT_INT,
  96. .flags = IORESOURCE_IRQ,
  97. },
  98. };
  99. struct platform_device imx_wdt_device = {
  100. .name = "imx-wdt",
  101. .id = 0,
  102. .resource = imx_wdt_resources,
  103. .num_resources = ARRAY_SIZE(imx_wdt_resources),
  104. };
  105. static struct resource imx_usb_resources[] = {
  106. {
  107. .start = 0x00212000,
  108. .end = 0x00212148,
  109. .flags = IORESOURCE_MEM,
  110. }, {
  111. .start = MX1_USBD_INT0,
  112. .end = MX1_USBD_INT0,
  113. .flags = IORESOURCE_IRQ,
  114. }, {
  115. .start = MX1_USBD_INT1,
  116. .end = MX1_USBD_INT1,
  117. .flags = IORESOURCE_IRQ,
  118. }, {
  119. .start = MX1_USBD_INT2,
  120. .end = MX1_USBD_INT2,
  121. .flags = IORESOURCE_IRQ,
  122. }, {
  123. .start = MX1_USBD_INT3,
  124. .end = MX1_USBD_INT3,
  125. .flags = IORESOURCE_IRQ,
  126. }, {
  127. .start = MX1_USBD_INT4,
  128. .end = MX1_USBD_INT4,
  129. .flags = IORESOURCE_IRQ,
  130. }, {
  131. .start = MX1_USBD_INT5,
  132. .end = MX1_USBD_INT5,
  133. .flags = IORESOURCE_IRQ,
  134. }, {
  135. .start = MX1_USBD_INT6,
  136. .end = MX1_USBD_INT6,
  137. .flags = IORESOURCE_IRQ,
  138. },
  139. };
  140. struct platform_device imx_usb_device = {
  141. .name = "imx_udc",
  142. .id = 0,
  143. .num_resources = ARRAY_SIZE(imx_usb_resources),
  144. .resource = imx_usb_resources,
  145. };
  146. /* GPIO port description */
  147. static struct mxc_gpio_port imx_gpio_ports[] = {
  148. {
  149. .chip.label = "gpio-0",
  150. .base = MX1_IO_ADDRESS(MX1_GPIO_BASE_ADDR),
  151. .irq = MX1_GPIO_INT_PORTA,
  152. .virtual_irq_start = MXC_GPIO_IRQ_START,
  153. }, {
  154. .chip.label = "gpio-1",
  155. .base = MX1_IO_ADDRESS(MX1_GPIO_BASE_ADDR + 0x100),
  156. .irq = MX1_GPIO_INT_PORTB,
  157. .virtual_irq_start = MXC_GPIO_IRQ_START + 32,
  158. }, {
  159. .chip.label = "gpio-2",
  160. .base = MX1_IO_ADDRESS(MX1_GPIO_BASE_ADDR + 0x200),
  161. .irq = MX1_GPIO_INT_PORTC,
  162. .virtual_irq_start = MXC_GPIO_IRQ_START + 64,
  163. }, {
  164. .chip.label = "gpio-3",
  165. .base = MX1_IO_ADDRESS(MX1_GPIO_BASE_ADDR + 0x300),
  166. .irq = MX1_GPIO_INT_PORTD,
  167. .virtual_irq_start = MXC_GPIO_IRQ_START + 96,
  168. }
  169. };
  170. int __init imx1_register_gpios(void)
  171. {
  172. return mxc_gpio_init(imx_gpio_ports, ARRAY_SIZE(imx_gpio_ports));
  173. }
  174. #endif
  175. #if defined(CONFIG_MACH_MX21) || defined(CONFIG_MACH_MX27)
  176. #ifdef CONFIG_MACH_MX27
  177. static struct resource mx27_camera_resources[] = {
  178. {
  179. .start = MX27_CSI_BASE_ADDR,
  180. .end = MX27_CSI_BASE_ADDR + 0x1f,
  181. .flags = IORESOURCE_MEM,
  182. }, {
  183. .start = MX27_EMMA_PRP_BASE_ADDR,
  184. .end = MX27_EMMA_PRP_BASE_ADDR + 0x1f,
  185. .flags = IORESOURCE_MEM,
  186. }, {
  187. .start = MX27_INT_CSI,
  188. .end = MX27_INT_CSI,
  189. .flags = IORESOURCE_IRQ,
  190. },{
  191. .start = MX27_INT_EMMAPRP,
  192. .end = MX27_INT_EMMAPRP,
  193. .flags = IORESOURCE_IRQ,
  194. },
  195. };
  196. struct platform_device mx27_camera_device = {
  197. .name = "mx2-camera",
  198. .id = 0,
  199. .num_resources = ARRAY_SIZE(mx27_camera_resources),
  200. .resource = mx27_camera_resources,
  201. .dev = {
  202. .coherent_dma_mask = 0xffffffff,
  203. },
  204. };
  205. #endif
  206. /*
  207. * General Purpose Timer
  208. * - i.MX21: 3 timers
  209. * - i.MX27: 6 timers
  210. */
  211. #define DEFINE_IMX_GPT_DEVICE(n, baseaddr, irq) \
  212. static struct resource timer ## n ##_resources[] = { \
  213. { \
  214. .start = baseaddr, \
  215. .end = baseaddr + SZ_4K - 1, \
  216. .flags = IORESOURCE_MEM, \
  217. }, { \
  218. .start = irq, \
  219. .end = irq, \
  220. .flags = IORESOURCE_IRQ, \
  221. } \
  222. }; \
  223. \
  224. struct platform_device mxc_gpt ## n = { \
  225. .name = "imx_gpt", \
  226. .id = n, \
  227. .num_resources = ARRAY_SIZE(timer ## n ## _resources), \
  228. .resource = timer ## n ## _resources, \
  229. }
  230. /* We use gpt1 as system timer, so do not add a device for this one */
  231. DEFINE_IMX_GPT_DEVICE(1, MX2x_GPT2_BASE_ADDR, MX2x_INT_GPT2);
  232. DEFINE_IMX_GPT_DEVICE(2, MX2x_GPT3_BASE_ADDR, MX2x_INT_GPT3);
  233. #ifdef CONFIG_MACH_MX27
  234. DEFINE_IMX_GPT_DEVICE(3, MX27_GPT4_BASE_ADDR, MX27_INT_GPT4);
  235. DEFINE_IMX_GPT_DEVICE(4, MX27_GPT5_BASE_ADDR, MX27_INT_GPT5);
  236. DEFINE_IMX_GPT_DEVICE(5, MX27_GPT6_BASE_ADDR, MX27_INT_GPT6);
  237. #endif
  238. /* Watchdog: i.MX1 has seperate driver, i.MX21 and i.MX27 are equal */
  239. static struct resource mxc_wdt_resources[] = {
  240. {
  241. .start = MX2x_WDOG_BASE_ADDR,
  242. .end = MX2x_WDOG_BASE_ADDR + SZ_4K - 1,
  243. .flags = IORESOURCE_MEM,
  244. },
  245. };
  246. struct platform_device mxc_wdt = {
  247. .name = "imx2-wdt",
  248. .id = 0,
  249. .num_resources = ARRAY_SIZE(mxc_wdt_resources),
  250. .resource = mxc_wdt_resources,
  251. };
  252. /*
  253. * lcdc:
  254. * - i.MX1: the basic controller
  255. * - i.MX21: to be checked
  256. * - i.MX27: like i.MX1, with slightly variations
  257. */
  258. static struct resource mxc_fb[] = {
  259. {
  260. .start = MX2x_LCDC_BASE_ADDR,
  261. .end = MX2x_LCDC_BASE_ADDR + SZ_4K - 1,
  262. .flags = IORESOURCE_MEM,
  263. }, {
  264. .start = MX2x_INT_LCDC,
  265. .end = MX2x_INT_LCDC,
  266. .flags = IORESOURCE_IRQ,
  267. }
  268. };
  269. /* mxc lcd driver */
  270. struct platform_device mxc_fb_device = {
  271. .name = "imx-fb",
  272. .id = 0,
  273. .num_resources = ARRAY_SIZE(mxc_fb),
  274. .resource = mxc_fb,
  275. .dev = {
  276. .coherent_dma_mask = DMA_BIT_MASK(32),
  277. },
  278. };
  279. static struct resource mxc_pwm_resources[] = {
  280. {
  281. .start = MX2x_PWM_BASE_ADDR,
  282. .end = MX2x_PWM_BASE_ADDR + SZ_4K - 1,
  283. .flags = IORESOURCE_MEM,
  284. }, {
  285. .start = MX2x_INT_PWM,
  286. .end = MX2x_INT_PWM,
  287. .flags = IORESOURCE_IRQ,
  288. }
  289. };
  290. struct platform_device mxc_pwm_device = {
  291. .name = "mxc_pwm",
  292. .id = 0,
  293. .num_resources = ARRAY_SIZE(mxc_pwm_resources),
  294. .resource = mxc_pwm_resources,
  295. };
  296. #define DEFINE_MXC_MMC_DEVICE(n, baseaddr, irq, dmareq) \
  297. static struct resource mxc_sdhc_resources ## n[] = { \
  298. { \
  299. .start = baseaddr, \
  300. .end = baseaddr + SZ_4K - 1, \
  301. .flags = IORESOURCE_MEM, \
  302. }, { \
  303. .start = irq, \
  304. .end = irq, \
  305. .flags = IORESOURCE_IRQ, \
  306. }, { \
  307. .start = dmareq, \
  308. .end = dmareq, \
  309. .flags = IORESOURCE_DMA, \
  310. }, \
  311. }; \
  312. \
  313. static u64 mxc_sdhc ## n ## _dmamask = DMA_BIT_MASK(32); \
  314. \
  315. struct platform_device mxc_sdhc_device ## n = { \
  316. .name = "mxc-mmc", \
  317. .id = n, \
  318. .dev = { \
  319. .dma_mask = &mxc_sdhc ## n ## _dmamask, \
  320. .coherent_dma_mask = DMA_BIT_MASK(32), \
  321. }, \
  322. .num_resources = ARRAY_SIZE(mxc_sdhc_resources ## n), \
  323. .resource = mxc_sdhc_resources ## n, \
  324. }
  325. DEFINE_MXC_MMC_DEVICE(0, MX2x_SDHC1_BASE_ADDR, MX2x_INT_SDHC1, MX2x_DMA_REQ_SDHC1);
  326. DEFINE_MXC_MMC_DEVICE(1, MX2x_SDHC2_BASE_ADDR, MX2x_INT_SDHC2, MX2x_DMA_REQ_SDHC2);
  327. #ifdef CONFIG_MACH_MX27
  328. static struct resource otg_resources[] = {
  329. {
  330. .start = MX27_USBOTG_BASE_ADDR,
  331. .end = MX27_USBOTG_BASE_ADDR + 0x1ff,
  332. .flags = IORESOURCE_MEM,
  333. }, {
  334. .start = MX27_INT_USB3,
  335. .end = MX27_INT_USB3,
  336. .flags = IORESOURCE_IRQ,
  337. },
  338. };
  339. static u64 otg_dmamask = DMA_BIT_MASK(32);
  340. /* OTG gadget device */
  341. struct platform_device mxc_otg_udc_device = {
  342. .name = "fsl-usb2-udc",
  343. .id = -1,
  344. .dev = {
  345. .dma_mask = &otg_dmamask,
  346. .coherent_dma_mask = DMA_BIT_MASK(32),
  347. },
  348. .resource = otg_resources,
  349. .num_resources = ARRAY_SIZE(otg_resources),
  350. };
  351. /* OTG host */
  352. struct platform_device mxc_otg_host = {
  353. .name = "mxc-ehci",
  354. .id = 0,
  355. .dev = {
  356. .coherent_dma_mask = DMA_BIT_MASK(32),
  357. .dma_mask = &otg_dmamask,
  358. },
  359. .resource = otg_resources,
  360. .num_resources = ARRAY_SIZE(otg_resources),
  361. };
  362. /* USB host 1 */
  363. static u64 usbh1_dmamask = DMA_BIT_MASK(32);
  364. static struct resource mxc_usbh1_resources[] = {
  365. {
  366. .start = MX27_USBOTG_BASE_ADDR + 0x200,
  367. .end = MX27_USBOTG_BASE_ADDR + 0x3ff,
  368. .flags = IORESOURCE_MEM,
  369. }, {
  370. .start = MX27_INT_USB1,
  371. .end = MX27_INT_USB1,
  372. .flags = IORESOURCE_IRQ,
  373. },
  374. };
  375. struct platform_device mxc_usbh1 = {
  376. .name = "mxc-ehci",
  377. .id = 1,
  378. .dev = {
  379. .coherent_dma_mask = DMA_BIT_MASK(32),
  380. .dma_mask = &usbh1_dmamask,
  381. },
  382. .resource = mxc_usbh1_resources,
  383. .num_resources = ARRAY_SIZE(mxc_usbh1_resources),
  384. };
  385. /* USB host 2 */
  386. static u64 usbh2_dmamask = DMA_BIT_MASK(32);
  387. static struct resource mxc_usbh2_resources[] = {
  388. {
  389. .start = MX27_USBOTG_BASE_ADDR + 0x400,
  390. .end = MX27_USBOTG_BASE_ADDR + 0x5ff,
  391. .flags = IORESOURCE_MEM,
  392. }, {
  393. .start = MX27_INT_USB2,
  394. .end = MX27_INT_USB2,
  395. .flags = IORESOURCE_IRQ,
  396. },
  397. };
  398. struct platform_device mxc_usbh2 = {
  399. .name = "mxc-ehci",
  400. .id = 2,
  401. .dev = {
  402. .coherent_dma_mask = DMA_BIT_MASK(32),
  403. .dma_mask = &usbh2_dmamask,
  404. },
  405. .resource = mxc_usbh2_resources,
  406. .num_resources = ARRAY_SIZE(mxc_usbh2_resources),
  407. };
  408. #endif
  409. /* GPIO port description */
  410. #define DEFINE_MXC_GPIO_PORT_IRQ(SOC, n, _irq) \
  411. { \
  412. .chip.label = "gpio-" #n, \
  413. .irq = _irq, \
  414. .base = SOC ## _IO_ADDRESS(MX2x_GPIO_BASE_ADDR + \
  415. n * 0x100), \
  416. .virtual_irq_start = MXC_GPIO_IRQ_START + n * 32, \
  417. }
  418. #define DEFINE_MXC_GPIO_PORT(SOC, n) \
  419. { \
  420. .chip.label = "gpio-" #n, \
  421. .base = SOC ## _IO_ADDRESS(MX2x_GPIO_BASE_ADDR + \
  422. n * 0x100), \
  423. .virtual_irq_start = MXC_GPIO_IRQ_START + n * 32, \
  424. }
  425. #define DEFINE_MXC_GPIO_PORTS(SOC, pfx) \
  426. static struct mxc_gpio_port pfx ## _gpio_ports[] = { \
  427. DEFINE_MXC_GPIO_PORT_IRQ(SOC, 0, SOC ## _INT_GPIO), \
  428. DEFINE_MXC_GPIO_PORT(SOC, 1), \
  429. DEFINE_MXC_GPIO_PORT(SOC, 2), \
  430. DEFINE_MXC_GPIO_PORT(SOC, 3), \
  431. DEFINE_MXC_GPIO_PORT(SOC, 4), \
  432. DEFINE_MXC_GPIO_PORT(SOC, 5), \
  433. }
  434. #ifdef CONFIG_MACH_MX21
  435. DEFINE_MXC_GPIO_PORTS(MX21, imx21);
  436. int __init imx21_register_gpios(void)
  437. {
  438. return mxc_gpio_init(imx21_gpio_ports, ARRAY_SIZE(imx21_gpio_ports));
  439. }
  440. #endif
  441. #ifdef CONFIG_MACH_MX27
  442. DEFINE_MXC_GPIO_PORTS(MX27, imx27);
  443. int __init imx27_register_gpios(void)
  444. {
  445. return mxc_gpio_init(imx27_gpio_ports, ARRAY_SIZE(imx27_gpio_ports));
  446. }
  447. #endif
  448. #ifdef CONFIG_MACH_MX21
  449. static struct resource mx21_usbhc_resources[] = {
  450. {
  451. .start = MX21_USBOTG_BASE_ADDR,
  452. .end = MX21_USBOTG_BASE_ADDR + SZ_8K - 1,
  453. .flags = IORESOURCE_MEM,
  454. },
  455. {
  456. .start = MX21_INT_USBHOST,
  457. .end = MX21_INT_USBHOST,
  458. .flags = IORESOURCE_IRQ,
  459. },
  460. };
  461. struct platform_device mx21_usbhc_device = {
  462. .name = "imx21-hcd",
  463. .id = 0,
  464. .dev = {
  465. .dma_mask = &mx21_usbhc_device.dev.coherent_dma_mask,
  466. .coherent_dma_mask = DMA_BIT_MASK(32),
  467. },
  468. .num_resources = ARRAY_SIZE(mx21_usbhc_resources),
  469. .resource = mx21_usbhc_resources,
  470. };
  471. #endif
  472. static struct resource imx_kpp_resources[] = {
  473. {
  474. .start = MX2x_KPP_BASE_ADDR,
  475. .end = MX2x_KPP_BASE_ADDR + 0xf,
  476. .flags = IORESOURCE_MEM
  477. }, {
  478. .start = MX2x_INT_KPP,
  479. .end = MX2x_INT_KPP,
  480. .flags = IORESOURCE_IRQ,
  481. },
  482. };
  483. struct platform_device imx_kpp_device = {
  484. .name = "imx-keypad",
  485. .id = -1,
  486. .num_resources = ARRAY_SIZE(imx_kpp_resources),
  487. .resource = imx_kpp_resources,
  488. };
  489. #endif