armadillo5x0.c 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  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. /* I2C2 */
  98. MX31_PIN_CSPI2_MOSI__SCL,
  99. MX31_PIN_CSPI2_MISO__SDA,
  100. };
  101. /* GPIO BUTTONS */
  102. static struct gpio_keys_button armadillo5x0_buttons[] = {
  103. {
  104. .code = KEY_ENTER, /*28*/
  105. .gpio = IOMUX_TO_GPIO(MX31_PIN_SCLK0),
  106. .active_low = 1,
  107. .desc = "menu",
  108. .wakeup = 1,
  109. }, {
  110. .code = KEY_BACK, /*158*/
  111. .gpio = IOMUX_TO_GPIO(MX31_PIN_SRST0),
  112. .active_low = 1,
  113. .desc = "back",
  114. .wakeup = 1,
  115. }
  116. };
  117. static struct gpio_keys_platform_data armadillo5x0_button_data = {
  118. .buttons = armadillo5x0_buttons,
  119. .nbuttons = ARRAY_SIZE(armadillo5x0_buttons),
  120. };
  121. static struct platform_device armadillo5x0_button_device = {
  122. .name = "gpio-keys",
  123. .id = -1,
  124. .num_resources = 0,
  125. .dev = {
  126. .platform_data = &armadillo5x0_button_data,
  127. }
  128. };
  129. /*
  130. * NAND Flash
  131. */
  132. static struct mxc_nand_platform_data armadillo5x0_nand_flash_pdata = {
  133. .width = 1,
  134. .hw_ecc = 1,
  135. };
  136. /*
  137. * MTD NOR Flash
  138. */
  139. static struct mtd_partition armadillo5x0_nor_flash_partitions[] = {
  140. {
  141. .name = "nor.bootloader",
  142. .offset = 0x00000000,
  143. .size = 4*32*1024,
  144. }, {
  145. .name = "nor.kernel",
  146. .offset = MTDPART_OFS_APPEND,
  147. .size = 16*128*1024,
  148. }, {
  149. .name = "nor.userland",
  150. .offset = MTDPART_OFS_APPEND,
  151. .size = 110*128*1024,
  152. }, {
  153. .name = "nor.config",
  154. .offset = MTDPART_OFS_APPEND,
  155. .size = 1*128*1024,
  156. },
  157. };
  158. static struct physmap_flash_data armadillo5x0_nor_flash_pdata = {
  159. .width = 2,
  160. .parts = armadillo5x0_nor_flash_partitions,
  161. .nr_parts = ARRAY_SIZE(armadillo5x0_nor_flash_partitions),
  162. };
  163. static struct resource armadillo5x0_nor_flash_resource = {
  164. .flags = IORESOURCE_MEM,
  165. .start = CS0_BASE_ADDR,
  166. .end = CS0_BASE_ADDR + SZ_64M - 1,
  167. };
  168. static struct platform_device armadillo5x0_nor_flash = {
  169. .name = "physmap-flash",
  170. .id = -1,
  171. .num_resources = 1,
  172. .resource = &armadillo5x0_nor_flash_resource,
  173. };
  174. /*
  175. * FB support
  176. */
  177. static const struct fb_videomode fb_modedb[] = {
  178. { /* 640x480 @ 60 Hz */
  179. .name = "CRT-VGA",
  180. .refresh = 60,
  181. .xres = 640,
  182. .yres = 480,
  183. .pixclock = 39721,
  184. .left_margin = 35,
  185. .right_margin = 115,
  186. .upper_margin = 43,
  187. .lower_margin = 1,
  188. .hsync_len = 10,
  189. .vsync_len = 1,
  190. .sync = FB_SYNC_OE_ACT_HIGH,
  191. .vmode = FB_VMODE_NONINTERLACED,
  192. .flag = 0,
  193. }, {/* 800x600 @ 56 Hz */
  194. .name = "CRT-SVGA",
  195. .refresh = 56,
  196. .xres = 800,
  197. .yres = 600,
  198. .pixclock = 30000,
  199. .left_margin = 30,
  200. .right_margin = 108,
  201. .upper_margin = 13,
  202. .lower_margin = 10,
  203. .hsync_len = 10,
  204. .vsync_len = 1,
  205. .sync = FB_SYNC_OE_ACT_HIGH | FB_SYNC_HOR_HIGH_ACT |
  206. FB_SYNC_VERT_HIGH_ACT,
  207. .vmode = FB_VMODE_NONINTERLACED,
  208. .flag = 0,
  209. },
  210. };
  211. static struct ipu_platform_data mx3_ipu_data = {
  212. .irq_base = MXC_IPU_IRQ_START,
  213. };
  214. static struct mx3fb_platform_data mx3fb_pdata = {
  215. .dma_dev = &mx3_ipu.dev,
  216. .name = "CRT-VGA",
  217. .mode = fb_modedb,
  218. .num_modes = ARRAY_SIZE(fb_modedb),
  219. };
  220. /*
  221. * SDHC 1
  222. * MMC support
  223. */
  224. static int armadillo5x0_sdhc1_get_ro(struct device *dev)
  225. {
  226. return gpio_get_value(IOMUX_TO_GPIO(MX31_PIN_ATA_RESET_B));
  227. }
  228. static int armadillo5x0_sdhc1_init(struct device *dev,
  229. irq_handler_t detect_irq, void *data)
  230. {
  231. int ret;
  232. int gpio_det, gpio_wp;
  233. gpio_det = IOMUX_TO_GPIO(MX31_PIN_ATA_DMACK);
  234. gpio_wp = IOMUX_TO_GPIO(MX31_PIN_ATA_RESET_B);
  235. ret = gpio_request(gpio_det, "sdhc-card-detect");
  236. if (ret)
  237. return ret;
  238. gpio_direction_input(gpio_det);
  239. ret = gpio_request(gpio_wp, "sdhc-write-protect");
  240. if (ret)
  241. goto err_gpio_free;
  242. gpio_direction_input(gpio_wp);
  243. /* When supported the trigger type have to be BOTH */
  244. ret = request_irq(IOMUX_TO_IRQ(MX31_PIN_ATA_DMACK), detect_irq,
  245. IRQF_DISABLED | IRQF_TRIGGER_FALLING,
  246. "sdhc-detect", data);
  247. if (ret)
  248. goto err_gpio_free_2;
  249. return 0;
  250. err_gpio_free_2:
  251. gpio_free(gpio_wp);
  252. err_gpio_free:
  253. gpio_free(gpio_det);
  254. return ret;
  255. }
  256. static void armadillo5x0_sdhc1_exit(struct device *dev, void *data)
  257. {
  258. free_irq(IOMUX_TO_IRQ(MX31_PIN_ATA_DMACK), data);
  259. gpio_free(IOMUX_TO_GPIO(MX31_PIN_ATA_DMACK));
  260. gpio_free(IOMUX_TO_GPIO(MX31_PIN_ATA_RESET_B));
  261. }
  262. static struct imxmmc_platform_data sdhc_pdata = {
  263. .get_ro = armadillo5x0_sdhc1_get_ro,
  264. .init = armadillo5x0_sdhc1_init,
  265. .exit = armadillo5x0_sdhc1_exit,
  266. };
  267. /*
  268. * SMSC 9118
  269. * Network support
  270. */
  271. static struct resource armadillo5x0_smc911x_resources[] = {
  272. {
  273. .start = CS3_BASE_ADDR,
  274. .end = CS3_BASE_ADDR + SZ_32M - 1,
  275. .flags = IORESOURCE_MEM,
  276. }, {
  277. .start = IOMUX_TO_IRQ(MX31_PIN_GPIO1_0),
  278. .end = IOMUX_TO_IRQ(MX31_PIN_GPIO1_0),
  279. .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_LOWLEVEL,
  280. },
  281. };
  282. static struct smsc911x_platform_config smsc911x_info = {
  283. .flags = SMSC911X_USE_16BIT,
  284. .irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,
  285. .irq_type = SMSC911X_IRQ_TYPE_PUSH_PULL,
  286. };
  287. static struct platform_device armadillo5x0_smc911x_device = {
  288. .name = "smsc911x",
  289. .id = -1,
  290. .num_resources = ARRAY_SIZE(armadillo5x0_smc911x_resources),
  291. .resource = armadillo5x0_smc911x_resources,
  292. .dev = {
  293. .platform_data = &smsc911x_info,
  294. },
  295. };
  296. /* UART device data */
  297. static struct imxuart_platform_data uart_pdata = {
  298. .flags = IMXUART_HAVE_RTSCTS,
  299. };
  300. static struct platform_device *devices[] __initdata = {
  301. &armadillo5x0_smc911x_device,
  302. &mxc_i2c_device1,
  303. &armadillo5x0_button_device,
  304. };
  305. /*
  306. * Perform board specific initializations
  307. */
  308. static void __init armadillo5x0_init(void)
  309. {
  310. mxc_iomux_setup_multiple_pins(armadillo5x0_pins,
  311. ARRAY_SIZE(armadillo5x0_pins), "armadillo5x0");
  312. platform_add_devices(devices, ARRAY_SIZE(devices));
  313. /* Register UART */
  314. mxc_register_device(&mxc_uart_device0, &uart_pdata);
  315. mxc_register_device(&mxc_uart_device1, &uart_pdata);
  316. /* SMSC9118 IRQ pin */
  317. gpio_direction_input(MX31_PIN_GPIO1_0);
  318. /* Register SDHC */
  319. mxc_register_device(&mxcsdhc_device0, &sdhc_pdata);
  320. /* Register FB */
  321. mxc_register_device(&mx3_ipu, &mx3_ipu_data);
  322. mxc_register_device(&mx3_fb, &mx3fb_pdata);
  323. /* Register NOR Flash */
  324. mxc_register_device(&armadillo5x0_nor_flash,
  325. &armadillo5x0_nor_flash_pdata);
  326. /* Register NAND Flash */
  327. mxc_register_device(&mxc_nand_device, &armadillo5x0_nand_flash_pdata);
  328. /* set NAND page size to 2k if not configured via boot mode pins */
  329. __raw_writel(__raw_readl(MXC_CCM_RCSR) | (1 << 30), MXC_CCM_RCSR);
  330. }
  331. static void __init armadillo5x0_timer_init(void)
  332. {
  333. mx31_clocks_init(26000000);
  334. }
  335. static struct sys_timer armadillo5x0_timer = {
  336. .init = armadillo5x0_timer_init,
  337. };
  338. MACHINE_START(ARMADILLO5X0, "Armadillo-500")
  339. /* Maintainer: Alberto Panizzo */
  340. .phys_io = AIPS1_BASE_ADDR,
  341. .io_pg_offst = ((AIPS1_BASE_ADDR_VIRT) >> 18) & 0xfffc,
  342. .boot_params = PHYS_OFFSET + 0x00000100,
  343. .map_io = mx31_map_io,
  344. .init_irq = mx31_init_irq,
  345. .timer = &armadillo5x0_timer,
  346. .init_machine = armadillo5x0_init,
  347. MACHINE_END