armadillo5x0.c 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  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 <linux/i2c.h>
  38. #include <mach/hardware.h>
  39. #include <asm/mach-types.h>
  40. #include <asm/mach/arch.h>
  41. #include <asm/mach/time.h>
  42. #include <asm/memory.h>
  43. #include <asm/mach/map.h>
  44. #include <mach/common.h>
  45. #include <mach/imx-uart.h>
  46. #include <mach/iomux-mx3.h>
  47. #include <mach/board-armadillo5x0.h>
  48. #include <mach/mmc.h>
  49. #include <mach/ipu.h>
  50. #include <mach/mx3fb.h>
  51. #include <mach/mxc_nand.h>
  52. #include "devices.h"
  53. #include "crm_regs.h"
  54. static int armadillo5x0_pins[] = {
  55. /* UART1 */
  56. MX31_PIN_CTS1__CTS1,
  57. MX31_PIN_RTS1__RTS1,
  58. MX31_PIN_TXD1__TXD1,
  59. MX31_PIN_RXD1__RXD1,
  60. /* UART2 */
  61. MX31_PIN_CTS2__CTS2,
  62. MX31_PIN_RTS2__RTS2,
  63. MX31_PIN_TXD2__TXD2,
  64. MX31_PIN_RXD2__RXD2,
  65. /* LAN9118_IRQ */
  66. IOMUX_MODE(MX31_PIN_GPIO1_0, IOMUX_CONFIG_GPIO),
  67. /* SDHC1 */
  68. MX31_PIN_SD1_DATA3__SD1_DATA3,
  69. MX31_PIN_SD1_DATA2__SD1_DATA2,
  70. MX31_PIN_SD1_DATA1__SD1_DATA1,
  71. MX31_PIN_SD1_DATA0__SD1_DATA0,
  72. MX31_PIN_SD1_CLK__SD1_CLK,
  73. MX31_PIN_SD1_CMD__SD1_CMD,
  74. /* Framebuffer */
  75. MX31_PIN_LD0__LD0,
  76. MX31_PIN_LD1__LD1,
  77. MX31_PIN_LD2__LD2,
  78. MX31_PIN_LD3__LD3,
  79. MX31_PIN_LD4__LD4,
  80. MX31_PIN_LD5__LD5,
  81. MX31_PIN_LD6__LD6,
  82. MX31_PIN_LD7__LD7,
  83. MX31_PIN_LD8__LD8,
  84. MX31_PIN_LD9__LD9,
  85. MX31_PIN_LD10__LD10,
  86. MX31_PIN_LD11__LD11,
  87. MX31_PIN_LD12__LD12,
  88. MX31_PIN_LD13__LD13,
  89. MX31_PIN_LD14__LD14,
  90. MX31_PIN_LD15__LD15,
  91. MX31_PIN_LD16__LD16,
  92. MX31_PIN_LD17__LD17,
  93. MX31_PIN_VSYNC3__VSYNC3,
  94. MX31_PIN_HSYNC__HSYNC,
  95. MX31_PIN_FPSHIFT__FPSHIFT,
  96. MX31_PIN_DRDY0__DRDY0,
  97. IOMUX_MODE(MX31_PIN_LCS1, IOMUX_CONFIG_GPIO), /*ADV7125_PSAVE*/
  98. /* I2C2 */
  99. MX31_PIN_CSPI2_MOSI__SCL,
  100. MX31_PIN_CSPI2_MISO__SDA,
  101. };
  102. /* RTC over I2C*/
  103. #define ARMADILLO5X0_RTC_GPIO IOMUX_TO_GPIO(MX31_PIN_SRXD4)
  104. static struct i2c_board_info armadillo5x0_i2c_rtc = {
  105. I2C_BOARD_INFO("s35390a", 0x30),
  106. };
  107. /* GPIO BUTTONS */
  108. static struct gpio_keys_button armadillo5x0_buttons[] = {
  109. {
  110. .code = KEY_ENTER, /*28*/
  111. .gpio = IOMUX_TO_GPIO(MX31_PIN_SCLK0),
  112. .active_low = 1,
  113. .desc = "menu",
  114. .wakeup = 1,
  115. }, {
  116. .code = KEY_BACK, /*158*/
  117. .gpio = IOMUX_TO_GPIO(MX31_PIN_SRST0),
  118. .active_low = 1,
  119. .desc = "back",
  120. .wakeup = 1,
  121. }
  122. };
  123. static struct gpio_keys_platform_data armadillo5x0_button_data = {
  124. .buttons = armadillo5x0_buttons,
  125. .nbuttons = ARRAY_SIZE(armadillo5x0_buttons),
  126. };
  127. static struct platform_device armadillo5x0_button_device = {
  128. .name = "gpio-keys",
  129. .id = -1,
  130. .num_resources = 0,
  131. .dev = {
  132. .platform_data = &armadillo5x0_button_data,
  133. }
  134. };
  135. /*
  136. * NAND Flash
  137. */
  138. static struct mxc_nand_platform_data armadillo5x0_nand_flash_pdata = {
  139. .width = 1,
  140. .hw_ecc = 1,
  141. };
  142. /*
  143. * MTD NOR Flash
  144. */
  145. static struct mtd_partition armadillo5x0_nor_flash_partitions[] = {
  146. {
  147. .name = "nor.bootloader",
  148. .offset = 0x00000000,
  149. .size = 4*32*1024,
  150. }, {
  151. .name = "nor.kernel",
  152. .offset = MTDPART_OFS_APPEND,
  153. .size = 16*128*1024,
  154. }, {
  155. .name = "nor.userland",
  156. .offset = MTDPART_OFS_APPEND,
  157. .size = 110*128*1024,
  158. }, {
  159. .name = "nor.config",
  160. .offset = MTDPART_OFS_APPEND,
  161. .size = 1*128*1024,
  162. },
  163. };
  164. static struct physmap_flash_data armadillo5x0_nor_flash_pdata = {
  165. .width = 2,
  166. .parts = armadillo5x0_nor_flash_partitions,
  167. .nr_parts = ARRAY_SIZE(armadillo5x0_nor_flash_partitions),
  168. };
  169. static struct resource armadillo5x0_nor_flash_resource = {
  170. .flags = IORESOURCE_MEM,
  171. .start = CS0_BASE_ADDR,
  172. .end = CS0_BASE_ADDR + SZ_64M - 1,
  173. };
  174. static struct platform_device armadillo5x0_nor_flash = {
  175. .name = "physmap-flash",
  176. .id = -1,
  177. .num_resources = 1,
  178. .resource = &armadillo5x0_nor_flash_resource,
  179. };
  180. /*
  181. * FB support
  182. */
  183. static const struct fb_videomode fb_modedb[] = {
  184. { /* 640x480 @ 60 Hz */
  185. .name = "CRT-VGA",
  186. .refresh = 60,
  187. .xres = 640,
  188. .yres = 480,
  189. .pixclock = 39721,
  190. .left_margin = 35,
  191. .right_margin = 115,
  192. .upper_margin = 43,
  193. .lower_margin = 1,
  194. .hsync_len = 10,
  195. .vsync_len = 1,
  196. .sync = FB_SYNC_OE_ACT_HIGH,
  197. .vmode = FB_VMODE_NONINTERLACED,
  198. .flag = 0,
  199. }, {/* 800x600 @ 56 Hz */
  200. .name = "CRT-SVGA",
  201. .refresh = 56,
  202. .xres = 800,
  203. .yres = 600,
  204. .pixclock = 30000,
  205. .left_margin = 30,
  206. .right_margin = 108,
  207. .upper_margin = 13,
  208. .lower_margin = 10,
  209. .hsync_len = 10,
  210. .vsync_len = 1,
  211. .sync = FB_SYNC_OE_ACT_HIGH | FB_SYNC_HOR_HIGH_ACT |
  212. FB_SYNC_VERT_HIGH_ACT,
  213. .vmode = FB_VMODE_NONINTERLACED,
  214. .flag = 0,
  215. },
  216. };
  217. static struct ipu_platform_data mx3_ipu_data = {
  218. .irq_base = MXC_IPU_IRQ_START,
  219. };
  220. static struct mx3fb_platform_data mx3fb_pdata = {
  221. .dma_dev = &mx3_ipu.dev,
  222. .name = "CRT-VGA",
  223. .mode = fb_modedb,
  224. .num_modes = ARRAY_SIZE(fb_modedb),
  225. };
  226. /*
  227. * SDHC 1
  228. * MMC support
  229. */
  230. static int armadillo5x0_sdhc1_get_ro(struct device *dev)
  231. {
  232. return gpio_get_value(IOMUX_TO_GPIO(MX31_PIN_ATA_RESET_B));
  233. }
  234. static int armadillo5x0_sdhc1_init(struct device *dev,
  235. irq_handler_t detect_irq, void *data)
  236. {
  237. int ret;
  238. int gpio_det, gpio_wp;
  239. gpio_det = IOMUX_TO_GPIO(MX31_PIN_ATA_DMACK);
  240. gpio_wp = IOMUX_TO_GPIO(MX31_PIN_ATA_RESET_B);
  241. ret = gpio_request(gpio_det, "sdhc-card-detect");
  242. if (ret)
  243. return ret;
  244. gpio_direction_input(gpio_det);
  245. ret = gpio_request(gpio_wp, "sdhc-write-protect");
  246. if (ret)
  247. goto err_gpio_free;
  248. gpio_direction_input(gpio_wp);
  249. /* When supported the trigger type have to be BOTH */
  250. ret = request_irq(IOMUX_TO_IRQ(MX31_PIN_ATA_DMACK), detect_irq,
  251. IRQF_DISABLED | IRQF_TRIGGER_FALLING,
  252. "sdhc-detect", data);
  253. if (ret)
  254. goto err_gpio_free_2;
  255. return 0;
  256. err_gpio_free_2:
  257. gpio_free(gpio_wp);
  258. err_gpio_free:
  259. gpio_free(gpio_det);
  260. return ret;
  261. }
  262. static void armadillo5x0_sdhc1_exit(struct device *dev, void *data)
  263. {
  264. free_irq(IOMUX_TO_IRQ(MX31_PIN_ATA_DMACK), data);
  265. gpio_free(IOMUX_TO_GPIO(MX31_PIN_ATA_DMACK));
  266. gpio_free(IOMUX_TO_GPIO(MX31_PIN_ATA_RESET_B));
  267. }
  268. static struct imxmmc_platform_data sdhc_pdata = {
  269. .get_ro = armadillo5x0_sdhc1_get_ro,
  270. .init = armadillo5x0_sdhc1_init,
  271. .exit = armadillo5x0_sdhc1_exit,
  272. };
  273. /*
  274. * SMSC 9118
  275. * Network support
  276. */
  277. static struct resource armadillo5x0_smc911x_resources[] = {
  278. {
  279. .start = CS3_BASE_ADDR,
  280. .end = CS3_BASE_ADDR + SZ_32M - 1,
  281. .flags = IORESOURCE_MEM,
  282. }, {
  283. .start = IOMUX_TO_IRQ(MX31_PIN_GPIO1_0),
  284. .end = IOMUX_TO_IRQ(MX31_PIN_GPIO1_0),
  285. .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_LOWLEVEL,
  286. },
  287. };
  288. static struct smsc911x_platform_config smsc911x_info = {
  289. .flags = SMSC911X_USE_16BIT,
  290. .irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,
  291. .irq_type = SMSC911X_IRQ_TYPE_PUSH_PULL,
  292. };
  293. static struct platform_device armadillo5x0_smc911x_device = {
  294. .name = "smsc911x",
  295. .id = -1,
  296. .num_resources = ARRAY_SIZE(armadillo5x0_smc911x_resources),
  297. .resource = armadillo5x0_smc911x_resources,
  298. .dev = {
  299. .platform_data = &smsc911x_info,
  300. },
  301. };
  302. /* UART device data */
  303. static struct imxuart_platform_data uart_pdata = {
  304. .flags = IMXUART_HAVE_RTSCTS,
  305. };
  306. static struct platform_device *devices[] __initdata = {
  307. &armadillo5x0_smc911x_device,
  308. &mxc_i2c_device1,
  309. &armadillo5x0_button_device,
  310. };
  311. /*
  312. * Perform board specific initializations
  313. */
  314. static void __init armadillo5x0_init(void)
  315. {
  316. mxc_iomux_setup_multiple_pins(armadillo5x0_pins,
  317. ARRAY_SIZE(armadillo5x0_pins), "armadillo5x0");
  318. platform_add_devices(devices, ARRAY_SIZE(devices));
  319. /* Register UART */
  320. mxc_register_device(&mxc_uart_device0, &uart_pdata);
  321. mxc_register_device(&mxc_uart_device1, &uart_pdata);
  322. /* SMSC9118 IRQ pin */
  323. gpio_direction_input(MX31_PIN_GPIO1_0);
  324. /* Register SDHC */
  325. mxc_register_device(&mxcsdhc_device0, &sdhc_pdata);
  326. /* Register FB */
  327. mxc_register_device(&mx3_ipu, &mx3_ipu_data);
  328. mxc_register_device(&mx3_fb, &mx3fb_pdata);
  329. /* Register NOR Flash */
  330. mxc_register_device(&armadillo5x0_nor_flash,
  331. &armadillo5x0_nor_flash_pdata);
  332. /* Register NAND Flash */
  333. mxc_register_device(&mxc_nand_device, &armadillo5x0_nand_flash_pdata);
  334. /* set NAND page size to 2k if not configured via boot mode pins */
  335. __raw_writel(__raw_readl(MXC_CCM_RCSR) | (1 << 30), MXC_CCM_RCSR);
  336. /* RTC */
  337. /* Get RTC IRQ and register the chip */
  338. if (gpio_request(ARMADILLO5X0_RTC_GPIO, "rtc") == 0) {
  339. if (gpio_direction_input(ARMADILLO5X0_RTC_GPIO) == 0)
  340. armadillo5x0_i2c_rtc.irq = gpio_to_irq(ARMADILLO5X0_RTC_GPIO);
  341. else
  342. gpio_free(ARMADILLO5X0_RTC_GPIO);
  343. }
  344. if (armadillo5x0_i2c_rtc.irq == 0)
  345. pr_warning("armadillo5x0_init: failed to get RTC IRQ\n");
  346. i2c_register_board_info(1, &armadillo5x0_i2c_rtc, 1);
  347. }
  348. static void __init armadillo5x0_timer_init(void)
  349. {
  350. mx31_clocks_init(26000000);
  351. }
  352. static struct sys_timer armadillo5x0_timer = {
  353. .init = armadillo5x0_timer_init,
  354. };
  355. MACHINE_START(ARMADILLO5X0, "Armadillo-500")
  356. /* Maintainer: Alberto Panizzo */
  357. .phys_io = AIPS1_BASE_ADDR,
  358. .io_pg_offst = ((AIPS1_BASE_ADDR_VIRT) >> 18) & 0xfffc,
  359. .boot_params = PHYS_OFFSET + 0x00000100,
  360. .map_io = mx31_map_io,
  361. .init_irq = mx31_init_irq,
  362. .timer = &armadillo5x0_timer,
  363. .init_machine = armadillo5x0_init,
  364. MACHINE_END