armadillo5x0.c 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  1. /*
  2. * armadillo5x0.c
  3. *
  4. * Copyright 2009 Alberto Panizzo <maramaopercheseimorto@gmail.com>
  5. * updates in http://alberdroid.blogspot.com/
  6. *
  7. * Based on Atmark Techno, Inc. armadillo 500 BSP 2008
  8. * Based on mx31ads.c and pcm037.c Great Work!
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  23. * MA 02110-1301, USA.
  24. */
  25. #include <linux/types.h>
  26. #include <linux/init.h>
  27. #include <linux/clk.h>
  28. #include <linux/platform_device.h>
  29. #include <linux/gpio.h>
  30. #include <linux/smsc911x.h>
  31. #include <linux/interrupt.h>
  32. #include <linux/irq.h>
  33. #include <linux/mtd/physmap.h>
  34. #include <linux/io.h>
  35. #include <linux/input.h>
  36. #include <linux/gpio_keys.h>
  37. #include <mach/hardware.h>
  38. #include <asm/mach-types.h>
  39. #include <asm/mach/arch.h>
  40. #include <asm/mach/time.h>
  41. #include <asm/memory.h>
  42. #include <asm/mach/map.h>
  43. #include <mach/common.h>
  44. #include <mach/imx-uart.h>
  45. #include <mach/iomux-mx3.h>
  46. #include <mach/board-armadillo5x0.h>
  47. #include <mach/mmc.h>
  48. #include <mach/ipu.h>
  49. #include <mach/mx3fb.h>
  50. #include <mach/mxc_nand.h>
  51. #include "devices.h"
  52. #include "crm_regs.h"
  53. static int armadillo5x0_pins[] = {
  54. /* UART1 */
  55. MX31_PIN_CTS1__CTS1,
  56. MX31_PIN_RTS1__RTS1,
  57. MX31_PIN_TXD1__TXD1,
  58. MX31_PIN_RXD1__RXD1,
  59. /* UART2 */
  60. MX31_PIN_CTS2__CTS2,
  61. MX31_PIN_RTS2__RTS2,
  62. MX31_PIN_TXD2__TXD2,
  63. MX31_PIN_RXD2__RXD2,
  64. /* LAN9118_IRQ */
  65. IOMUX_MODE(MX31_PIN_GPIO1_0, IOMUX_CONFIG_GPIO),
  66. /* SDHC1 */
  67. MX31_PIN_SD1_DATA3__SD1_DATA3,
  68. MX31_PIN_SD1_DATA2__SD1_DATA2,
  69. MX31_PIN_SD1_DATA1__SD1_DATA1,
  70. MX31_PIN_SD1_DATA0__SD1_DATA0,
  71. MX31_PIN_SD1_CLK__SD1_CLK,
  72. MX31_PIN_SD1_CMD__SD1_CMD,
  73. /* Framebuffer */
  74. MX31_PIN_LD0__LD0,
  75. MX31_PIN_LD1__LD1,
  76. MX31_PIN_LD2__LD2,
  77. MX31_PIN_LD3__LD3,
  78. MX31_PIN_LD4__LD4,
  79. MX31_PIN_LD5__LD5,
  80. MX31_PIN_LD6__LD6,
  81. MX31_PIN_LD7__LD7,
  82. MX31_PIN_LD8__LD8,
  83. MX31_PIN_LD9__LD9,
  84. MX31_PIN_LD10__LD10,
  85. MX31_PIN_LD11__LD11,
  86. MX31_PIN_LD12__LD12,
  87. MX31_PIN_LD13__LD13,
  88. MX31_PIN_LD14__LD14,
  89. MX31_PIN_LD15__LD15,
  90. MX31_PIN_LD16__LD16,
  91. MX31_PIN_LD17__LD17,
  92. MX31_PIN_VSYNC3__VSYNC3,
  93. MX31_PIN_HSYNC__HSYNC,
  94. MX31_PIN_FPSHIFT__FPSHIFT,
  95. MX31_PIN_DRDY0__DRDY0,
  96. IOMUX_MODE(MX31_PIN_LCS1, IOMUX_CONFIG_GPIO), /*ADV7125_PSAVE*/
  97. };
  98. /* GPIO BUTTONS */
  99. static struct gpio_keys_button armadillo5x0_buttons[] = {
  100. {
  101. .code = KEY_ENTER, /*28*/
  102. .gpio = IOMUX_TO_GPIO(MX31_PIN_SCLK0),
  103. .active_low = 1,
  104. .desc = "menu",
  105. .wakeup = 1,
  106. }, {
  107. .code = KEY_BACK, /*158*/
  108. .gpio = IOMUX_TO_GPIO(MX31_PIN_SRST0),
  109. .active_low = 1,
  110. .desc = "back",
  111. .wakeup = 1,
  112. }
  113. };
  114. static struct gpio_keys_platform_data armadillo5x0_button_data = {
  115. .buttons = armadillo5x0_buttons,
  116. .nbuttons = ARRAY_SIZE(armadillo5x0_buttons),
  117. };
  118. static struct platform_device armadillo5x0_button_device = {
  119. .name = "gpio-keys",
  120. .id = -1,
  121. .num_resources = 0,
  122. .dev = {
  123. .platform_data = &armadillo5x0_button_data,
  124. }
  125. };
  126. /*
  127. * NAND Flash
  128. */
  129. static struct mxc_nand_platform_data armadillo5x0_nand_flash_pdata = {
  130. .width = 1,
  131. .hw_ecc = 1,
  132. };
  133. /*
  134. * MTD NOR Flash
  135. */
  136. static struct mtd_partition armadillo5x0_nor_flash_partitions[] = {
  137. {
  138. .name = "nor.bootloader",
  139. .offset = 0x00000000,
  140. .size = 4*32*1024,
  141. }, {
  142. .name = "nor.kernel",
  143. .offset = MTDPART_OFS_APPEND,
  144. .size = 16*128*1024,
  145. }, {
  146. .name = "nor.userland",
  147. .offset = MTDPART_OFS_APPEND,
  148. .size = 110*128*1024,
  149. }, {
  150. .name = "nor.config",
  151. .offset = MTDPART_OFS_APPEND,
  152. .size = 1*128*1024,
  153. },
  154. };
  155. static struct physmap_flash_data armadillo5x0_nor_flash_pdata = {
  156. .width = 2,
  157. .parts = armadillo5x0_nor_flash_partitions,
  158. .nr_parts = ARRAY_SIZE(armadillo5x0_nor_flash_partitions),
  159. };
  160. static struct resource armadillo5x0_nor_flash_resource = {
  161. .flags = IORESOURCE_MEM,
  162. .start = CS0_BASE_ADDR,
  163. .end = CS0_BASE_ADDR + SZ_64M - 1,
  164. };
  165. static struct platform_device armadillo5x0_nor_flash = {
  166. .name = "physmap-flash",
  167. .id = -1,
  168. .num_resources = 1,
  169. .resource = &armadillo5x0_nor_flash_resource,
  170. };
  171. /*
  172. * FB support
  173. */
  174. static const struct fb_videomode fb_modedb[] = {
  175. { /* 640x480 @ 60 Hz */
  176. .name = "CRT-VGA",
  177. .refresh = 60,
  178. .xres = 640,
  179. .yres = 480,
  180. .pixclock = 39721,
  181. .left_margin = 35,
  182. .right_margin = 115,
  183. .upper_margin = 43,
  184. .lower_margin = 1,
  185. .hsync_len = 10,
  186. .vsync_len = 1,
  187. .sync = FB_SYNC_OE_ACT_HIGH,
  188. .vmode = FB_VMODE_NONINTERLACED,
  189. .flag = 0,
  190. }, {/* 800x600 @ 56 Hz */
  191. .name = "CRT-SVGA",
  192. .refresh = 56,
  193. .xres = 800,
  194. .yres = 600,
  195. .pixclock = 30000,
  196. .left_margin = 30,
  197. .right_margin = 108,
  198. .upper_margin = 13,
  199. .lower_margin = 10,
  200. .hsync_len = 10,
  201. .vsync_len = 1,
  202. .sync = FB_SYNC_OE_ACT_HIGH | FB_SYNC_HOR_HIGH_ACT |
  203. FB_SYNC_VERT_HIGH_ACT,
  204. .vmode = FB_VMODE_NONINTERLACED,
  205. .flag = 0,
  206. },
  207. };
  208. static struct ipu_platform_data mx3_ipu_data = {
  209. .irq_base = MXC_IPU_IRQ_START,
  210. };
  211. static struct mx3fb_platform_data mx3fb_pdata = {
  212. .dma_dev = &mx3_ipu.dev,
  213. .name = "CRT-VGA",
  214. .mode = fb_modedb,
  215. .num_modes = ARRAY_SIZE(fb_modedb),
  216. };
  217. /*
  218. * SDHC 1
  219. * MMC support
  220. */
  221. static int armadillo5x0_sdhc1_get_ro(struct device *dev)
  222. {
  223. return gpio_get_value(IOMUX_TO_GPIO(MX31_PIN_ATA_RESET_B));
  224. }
  225. static int armadillo5x0_sdhc1_init(struct device *dev,
  226. irq_handler_t detect_irq, void *data)
  227. {
  228. int ret;
  229. int gpio_det, gpio_wp;
  230. gpio_det = IOMUX_TO_GPIO(MX31_PIN_ATA_DMACK);
  231. gpio_wp = IOMUX_TO_GPIO(MX31_PIN_ATA_RESET_B);
  232. ret = gpio_request(gpio_det, "sdhc-card-detect");
  233. if (ret)
  234. return ret;
  235. gpio_direction_input(gpio_det);
  236. ret = gpio_request(gpio_wp, "sdhc-write-protect");
  237. if (ret)
  238. goto err_gpio_free;
  239. gpio_direction_input(gpio_wp);
  240. /* When supported the trigger type have to be BOTH */
  241. ret = request_irq(IOMUX_TO_IRQ(MX31_PIN_ATA_DMACK), detect_irq,
  242. IRQF_DISABLED | IRQF_TRIGGER_FALLING,
  243. "sdhc-detect", data);
  244. if (ret)
  245. goto err_gpio_free_2;
  246. return 0;
  247. err_gpio_free_2:
  248. gpio_free(gpio_wp);
  249. err_gpio_free:
  250. gpio_free(gpio_det);
  251. return ret;
  252. }
  253. static void armadillo5x0_sdhc1_exit(struct device *dev, void *data)
  254. {
  255. free_irq(IOMUX_TO_IRQ(MX31_PIN_ATA_DMACK), data);
  256. gpio_free(IOMUX_TO_GPIO(MX31_PIN_ATA_DMACK));
  257. gpio_free(IOMUX_TO_GPIO(MX31_PIN_ATA_RESET_B));
  258. }
  259. static struct imxmmc_platform_data sdhc_pdata = {
  260. .get_ro = armadillo5x0_sdhc1_get_ro,
  261. .init = armadillo5x0_sdhc1_init,
  262. .exit = armadillo5x0_sdhc1_exit,
  263. };
  264. /*
  265. * SMSC 9118
  266. * Network support
  267. */
  268. static struct resource armadillo5x0_smc911x_resources[] = {
  269. {
  270. .start = CS3_BASE_ADDR,
  271. .end = CS3_BASE_ADDR + SZ_32M - 1,
  272. .flags = IORESOURCE_MEM,
  273. }, {
  274. .start = IOMUX_TO_IRQ(MX31_PIN_GPIO1_0),
  275. .end = IOMUX_TO_IRQ(MX31_PIN_GPIO1_0),
  276. .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_LOWLEVEL,
  277. },
  278. };
  279. static struct smsc911x_platform_config smsc911x_info = {
  280. .flags = SMSC911X_USE_32BIT,
  281. .irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,
  282. .irq_type = SMSC911X_IRQ_TYPE_PUSH_PULL,
  283. };
  284. static struct platform_device armadillo5x0_smc911x_device = {
  285. .name = "smsc911x",
  286. .id = -1,
  287. .num_resources = ARRAY_SIZE(armadillo5x0_smc911x_resources),
  288. .resource = armadillo5x0_smc911x_resources,
  289. .dev = {
  290. .platform_data = &smsc911x_info,
  291. },
  292. };
  293. /* UART device data */
  294. static struct imxuart_platform_data uart_pdata = {
  295. .flags = IMXUART_HAVE_RTSCTS,
  296. };
  297. static struct platform_device *devices[] __initdata = {
  298. &armadillo5x0_smc911x_device,
  299. &armadillo5x0_button_device,
  300. };
  301. /*
  302. * Perform board specific initializations
  303. */
  304. static void __init armadillo5x0_init(void)
  305. {
  306. mxc_iomux_setup_multiple_pins(armadillo5x0_pins,
  307. ARRAY_SIZE(armadillo5x0_pins), "armadillo5x0");
  308. platform_add_devices(devices, ARRAY_SIZE(devices));
  309. /* Register UART */
  310. mxc_register_device(&mxc_uart_device0, &uart_pdata);
  311. mxc_register_device(&mxc_uart_device1, &uart_pdata);
  312. /* SMSC9118 IRQ pin */
  313. gpio_direction_input(MX31_PIN_GPIO1_0);
  314. /* Register SDHC */
  315. mxc_register_device(&mxcsdhc_device0, &sdhc_pdata);
  316. /* Register FB */
  317. mxc_register_device(&mx3_ipu, &mx3_ipu_data);
  318. mxc_register_device(&mx3_fb, &mx3fb_pdata);
  319. /* Register NOR Flash */
  320. mxc_register_device(&armadillo5x0_nor_flash,
  321. &armadillo5x0_nor_flash_pdata);
  322. /* Register NAND Flash */
  323. mxc_register_device(&mxc_nand_device, &armadillo5x0_nand_flash_pdata);
  324. /* set NAND page size to 2k if not configured via boot mode pins */
  325. __raw_writel(__raw_readl(MXC_CCM_RCSR) | (1 << 30), MXC_CCM_RCSR);
  326. }
  327. static void __init armadillo5x0_timer_init(void)
  328. {
  329. mx31_clocks_init(26000000);
  330. }
  331. static struct sys_timer armadillo5x0_timer = {
  332. .init = armadillo5x0_timer_init,
  333. };
  334. MACHINE_START(ARMADILLO5X0, "Armadillo-500")
  335. /* Maintainer: Alberto Panizzo */
  336. .phys_io = AIPS1_BASE_ADDR,
  337. .io_pg_offst = ((AIPS1_BASE_ADDR_VIRT) >> 18) & 0xfffc,
  338. .boot_params = PHYS_OFFSET + 0x00000100,
  339. .map_io = mx31_map_io,
  340. .init_irq = mx31_init_irq,
  341. .timer = &armadillo5x0_timer,
  342. .init_machine = armadillo5x0_init,
  343. MACHINE_END