devices.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553
  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 = (void __iomem *)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 = (void __iomem *)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 = (void __iomem *)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 = (void __iomem *)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. static struct resource mxc_w1_master_resources[] = {
  253. {
  254. .start = MX2x_OWIRE_BASE_ADDR,
  255. .end = MX2x_OWIRE_BASE_ADDR + SZ_4K - 1,
  256. .flags = IORESOURCE_MEM,
  257. },
  258. };
  259. struct platform_device mxc_w1_master_device = {
  260. .name = "mxc_w1",
  261. .id = 0,
  262. .num_resources = ARRAY_SIZE(mxc_w1_master_resources),
  263. .resource = mxc_w1_master_resources,
  264. };
  265. /*
  266. * lcdc:
  267. * - i.MX1: the basic controller
  268. * - i.MX21: to be checked
  269. * - i.MX27: like i.MX1, with slightly variations
  270. */
  271. static struct resource mxc_fb[] = {
  272. {
  273. .start = MX2x_LCDC_BASE_ADDR,
  274. .end = MX2x_LCDC_BASE_ADDR + SZ_4K - 1,
  275. .flags = IORESOURCE_MEM,
  276. }, {
  277. .start = MX2x_INT_LCDC,
  278. .end = MX2x_INT_LCDC,
  279. .flags = IORESOURCE_IRQ,
  280. }
  281. };
  282. /* mxc lcd driver */
  283. struct platform_device mxc_fb_device = {
  284. .name = "imx-fb",
  285. .id = 0,
  286. .num_resources = ARRAY_SIZE(mxc_fb),
  287. .resource = mxc_fb,
  288. .dev = {
  289. .coherent_dma_mask = DMA_BIT_MASK(32),
  290. },
  291. };
  292. static struct resource mxc_pwm_resources[] = {
  293. {
  294. .start = MX2x_PWM_BASE_ADDR,
  295. .end = MX2x_PWM_BASE_ADDR + SZ_4K - 1,
  296. .flags = IORESOURCE_MEM,
  297. }, {
  298. .start = MX2x_INT_PWM,
  299. .end = MX2x_INT_PWM,
  300. .flags = IORESOURCE_IRQ,
  301. }
  302. };
  303. struct platform_device mxc_pwm_device = {
  304. .name = "mxc_pwm",
  305. .id = 0,
  306. .num_resources = ARRAY_SIZE(mxc_pwm_resources),
  307. .resource = mxc_pwm_resources,
  308. };
  309. #define DEFINE_MXC_MMC_DEVICE(n, baseaddr, irq, dmareq) \
  310. static struct resource mxc_sdhc_resources ## n[] = { \
  311. { \
  312. .start = baseaddr, \
  313. .end = baseaddr + SZ_4K - 1, \
  314. .flags = IORESOURCE_MEM, \
  315. }, { \
  316. .start = irq, \
  317. .end = irq, \
  318. .flags = IORESOURCE_IRQ, \
  319. }, { \
  320. .start = dmareq, \
  321. .end = dmareq, \
  322. .flags = IORESOURCE_DMA, \
  323. }, \
  324. }; \
  325. \
  326. static u64 mxc_sdhc ## n ## _dmamask = DMA_BIT_MASK(32); \
  327. \
  328. struct platform_device mxc_sdhc_device ## n = { \
  329. .name = "mxc-mmc", \
  330. .id = n, \
  331. .dev = { \
  332. .dma_mask = &mxc_sdhc ## n ## _dmamask, \
  333. .coherent_dma_mask = DMA_BIT_MASK(32), \
  334. }, \
  335. .num_resources = ARRAY_SIZE(mxc_sdhc_resources ## n), \
  336. .resource = mxc_sdhc_resources ## n, \
  337. }
  338. DEFINE_MXC_MMC_DEVICE(0, MX2x_SDHC1_BASE_ADDR, MX2x_INT_SDHC1, MX2x_DMA_REQ_SDHC1);
  339. DEFINE_MXC_MMC_DEVICE(1, MX2x_SDHC2_BASE_ADDR, MX2x_INT_SDHC2, MX2x_DMA_REQ_SDHC2);
  340. #ifdef CONFIG_MACH_MX27
  341. static struct resource otg_resources[] = {
  342. {
  343. .start = MX27_USBOTG_BASE_ADDR,
  344. .end = MX27_USBOTG_BASE_ADDR + 0x1ff,
  345. .flags = IORESOURCE_MEM,
  346. }, {
  347. .start = MX27_INT_USB3,
  348. .end = MX27_INT_USB3,
  349. .flags = IORESOURCE_IRQ,
  350. },
  351. };
  352. static u64 otg_dmamask = DMA_BIT_MASK(32);
  353. /* OTG gadget device */
  354. struct platform_device mxc_otg_udc_device = {
  355. .name = "fsl-usb2-udc",
  356. .id = -1,
  357. .dev = {
  358. .dma_mask = &otg_dmamask,
  359. .coherent_dma_mask = DMA_BIT_MASK(32),
  360. },
  361. .resource = otg_resources,
  362. .num_resources = ARRAY_SIZE(otg_resources),
  363. };
  364. /* OTG host */
  365. struct platform_device mxc_otg_host = {
  366. .name = "mxc-ehci",
  367. .id = 0,
  368. .dev = {
  369. .coherent_dma_mask = DMA_BIT_MASK(32),
  370. .dma_mask = &otg_dmamask,
  371. },
  372. .resource = otg_resources,
  373. .num_resources = ARRAY_SIZE(otg_resources),
  374. };
  375. /* USB host 1 */
  376. static u64 usbh1_dmamask = DMA_BIT_MASK(32);
  377. static struct resource mxc_usbh1_resources[] = {
  378. {
  379. .start = MX27_USBOTG_BASE_ADDR + 0x200,
  380. .end = MX27_USBOTG_BASE_ADDR + 0x3ff,
  381. .flags = IORESOURCE_MEM,
  382. }, {
  383. .start = MX27_INT_USB1,
  384. .end = MX27_INT_USB1,
  385. .flags = IORESOURCE_IRQ,
  386. },
  387. };
  388. struct platform_device mxc_usbh1 = {
  389. .name = "mxc-ehci",
  390. .id = 1,
  391. .dev = {
  392. .coherent_dma_mask = DMA_BIT_MASK(32),
  393. .dma_mask = &usbh1_dmamask,
  394. },
  395. .resource = mxc_usbh1_resources,
  396. .num_resources = ARRAY_SIZE(mxc_usbh1_resources),
  397. };
  398. /* USB host 2 */
  399. static u64 usbh2_dmamask = DMA_BIT_MASK(32);
  400. static struct resource mxc_usbh2_resources[] = {
  401. {
  402. .start = MX27_USBOTG_BASE_ADDR + 0x400,
  403. .end = MX27_USBOTG_BASE_ADDR + 0x5ff,
  404. .flags = IORESOURCE_MEM,
  405. }, {
  406. .start = MX27_INT_USB2,
  407. .end = MX27_INT_USB2,
  408. .flags = IORESOURCE_IRQ,
  409. },
  410. };
  411. struct platform_device mxc_usbh2 = {
  412. .name = "mxc-ehci",
  413. .id = 2,
  414. .dev = {
  415. .coherent_dma_mask = DMA_BIT_MASK(32),
  416. .dma_mask = &usbh2_dmamask,
  417. },
  418. .resource = mxc_usbh2_resources,
  419. .num_resources = ARRAY_SIZE(mxc_usbh2_resources),
  420. };
  421. #endif
  422. /* GPIO port description */
  423. #define DEFINE_MXC_GPIO_PORT_IRQ(SOC, n, _irq) \
  424. { \
  425. .chip.label = "gpio-" #n, \
  426. .irq = _irq, \
  427. .base = SOC ## _IO_ADDRESS(MX2x_GPIO_BASE_ADDR + \
  428. n * 0x100), \
  429. .virtual_irq_start = MXC_GPIO_IRQ_START + n * 32, \
  430. }
  431. #define DEFINE_MXC_GPIO_PORT(SOC, n) \
  432. { \
  433. .chip.label = "gpio-" #n, \
  434. .base = SOC ## _IO_ADDRESS(MX2x_GPIO_BASE_ADDR + \
  435. n * 0x100), \
  436. .virtual_irq_start = MXC_GPIO_IRQ_START + n * 32, \
  437. }
  438. #define DEFINE_MXC_GPIO_PORTS(SOC, pfx) \
  439. static struct mxc_gpio_port pfx ## _gpio_ports[] = { \
  440. DEFINE_MXC_GPIO_PORT_IRQ(SOC, 0, SOC ## _INT_GPIO), \
  441. DEFINE_MXC_GPIO_PORT(SOC, 1), \
  442. DEFINE_MXC_GPIO_PORT(SOC, 2), \
  443. DEFINE_MXC_GPIO_PORT(SOC, 3), \
  444. DEFINE_MXC_GPIO_PORT(SOC, 4), \
  445. DEFINE_MXC_GPIO_PORT(SOC, 5), \
  446. }
  447. #ifdef CONFIG_MACH_MX21
  448. DEFINE_MXC_GPIO_PORTS(MX21, imx21);
  449. int __init imx21_register_gpios(void)
  450. {
  451. return mxc_gpio_init(imx21_gpio_ports, ARRAY_SIZE(imx21_gpio_ports));
  452. }
  453. #endif
  454. #ifdef CONFIG_MACH_MX27
  455. DEFINE_MXC_GPIO_PORTS(MX27, imx27);
  456. int __init imx27_register_gpios(void)
  457. {
  458. return mxc_gpio_init(imx27_gpio_ports, ARRAY_SIZE(imx27_gpio_ports));
  459. }
  460. #endif
  461. #ifdef CONFIG_MACH_MX21
  462. static struct resource mx21_usbhc_resources[] = {
  463. {
  464. .start = MX21_USBOTG_BASE_ADDR,
  465. .end = MX21_USBOTG_BASE_ADDR + SZ_8K - 1,
  466. .flags = IORESOURCE_MEM,
  467. },
  468. {
  469. .start = MX21_INT_USBHOST,
  470. .end = MX21_INT_USBHOST,
  471. .flags = IORESOURCE_IRQ,
  472. },
  473. };
  474. struct platform_device mx21_usbhc_device = {
  475. .name = "imx21-hcd",
  476. .id = 0,
  477. .dev = {
  478. .dma_mask = &mx21_usbhc_device.dev.coherent_dma_mask,
  479. .coherent_dma_mask = DMA_BIT_MASK(32),
  480. },
  481. .num_resources = ARRAY_SIZE(mx21_usbhc_resources),
  482. .resource = mx21_usbhc_resources,
  483. };
  484. #endif
  485. static struct resource imx_kpp_resources[] = {
  486. {
  487. .start = MX2x_KPP_BASE_ADDR,
  488. .end = MX2x_KPP_BASE_ADDR + 0xf,
  489. .flags = IORESOURCE_MEM
  490. }, {
  491. .start = MX2x_INT_KPP,
  492. .end = MX2x_INT_KPP,
  493. .flags = IORESOURCE_IRQ,
  494. },
  495. };
  496. struct platform_device imx_kpp_device = {
  497. .name = "imx-keypad",
  498. .id = -1,
  499. .num_resources = ARRAY_SIZE(imx_kpp_resources),
  500. .resource = imx_kpp_resources,
  501. };
  502. #endif