board-ag5evm.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491
  1. /*
  2. * arch/arm/mach-shmobile/board-ag5evm.c
  3. *
  4. * Copyright (C) 2010 Takashi Yoshii <yoshii.takashi.zj@renesas.com>
  5. * Copyright (C) 2009 Yoshihiro Shimoda <shimoda.yoshihiro@renesas.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; version 2 of the License.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  19. *
  20. */
  21. #include <linux/kernel.h>
  22. #include <linux/init.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/irq.h>
  25. #include <linux/platform_device.h>
  26. #include <linux/delay.h>
  27. #include <linux/io.h>
  28. #include <linux/dma-mapping.h>
  29. #include <linux/serial_sci.h>
  30. #include <linux/smsc911x.h>
  31. #include <linux/gpio.h>
  32. #include <linux/input.h>
  33. #include <linux/input/sh_keysc.h>
  34. #include <linux/mmc/host.h>
  35. #include <linux/mmc/sh_mmcif.h>
  36. #include <linux/sh_clk.h>
  37. #include <video/sh_mobile_lcdc.h>
  38. #include <video/sh_mipi_dsi.h>
  39. #include <sound/sh_fsi.h>
  40. #include <mach/hardware.h>
  41. #include <mach/sh73a0.h>
  42. #include <mach/common.h>
  43. #include <asm/mach-types.h>
  44. #include <asm/mach/arch.h>
  45. #include <asm/mach/map.h>
  46. #include <asm/mach/time.h>
  47. #include <asm/hardware/gic.h>
  48. #include <asm/hardware/cache-l2x0.h>
  49. #include <asm/traps.h>
  50. static struct resource smsc9220_resources[] = {
  51. [0] = {
  52. .start = 0x14000000,
  53. .end = 0x14000000 + SZ_64K - 1,
  54. .flags = IORESOURCE_MEM,
  55. },
  56. [1] = {
  57. .start = gic_spi(33), /* PINT1 */
  58. .flags = IORESOURCE_IRQ,
  59. },
  60. };
  61. static struct smsc911x_platform_config smsc9220_platdata = {
  62. .flags = SMSC911X_USE_32BIT | SMSC911X_SAVE_MAC_ADDRESS,
  63. .phy_interface = PHY_INTERFACE_MODE_MII,
  64. .irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,
  65. .irq_type = SMSC911X_IRQ_TYPE_PUSH_PULL,
  66. };
  67. static struct platform_device eth_device = {
  68. .name = "smsc911x",
  69. .id = 0,
  70. .dev = {
  71. .platform_data = &smsc9220_platdata,
  72. },
  73. .resource = smsc9220_resources,
  74. .num_resources = ARRAY_SIZE(smsc9220_resources),
  75. };
  76. static struct sh_keysc_info keysc_platdata = {
  77. .mode = SH_KEYSC_MODE_6,
  78. .scan_timing = 3,
  79. .delay = 100,
  80. .keycodes = {
  81. KEY_A, KEY_B, KEY_C, KEY_D, KEY_E, KEY_F, KEY_G,
  82. KEY_H, KEY_I, KEY_J, KEY_K, KEY_L, KEY_M, KEY_N,
  83. KEY_O, KEY_P, KEY_Q, KEY_R, KEY_S, KEY_T, KEY_U,
  84. KEY_V, KEY_W, KEY_X, KEY_Y, KEY_Z, KEY_HOME, KEY_SLEEP,
  85. KEY_SPACE, KEY_9, KEY_6, KEY_3, KEY_WAKEUP, KEY_RIGHT, \
  86. KEY_COFFEE,
  87. KEY_0, KEY_8, KEY_5, KEY_2, KEY_DOWN, KEY_ENTER, KEY_UP,
  88. KEY_KPASTERISK, KEY_7, KEY_4, KEY_1, KEY_STOP, KEY_LEFT, \
  89. KEY_COMPUTER,
  90. },
  91. };
  92. static struct resource keysc_resources[] = {
  93. [0] = {
  94. .name = "KEYSC",
  95. .start = 0xe61b0000,
  96. .end = 0xe61b0098 - 1,
  97. .flags = IORESOURCE_MEM,
  98. },
  99. [1] = {
  100. .start = gic_spi(71),
  101. .flags = IORESOURCE_IRQ,
  102. },
  103. };
  104. static struct platform_device keysc_device = {
  105. .name = "sh_keysc",
  106. .id = 0,
  107. .num_resources = ARRAY_SIZE(keysc_resources),
  108. .resource = keysc_resources,
  109. .dev = {
  110. .platform_data = &keysc_platdata,
  111. },
  112. };
  113. /* FSI A */
  114. static struct sh_fsi_platform_info fsi_info = {
  115. .porta_flags = SH_FSI_OUT_SLAVE_MODE |
  116. SH_FSI_IN_SLAVE_MODE |
  117. SH_FSI_OFMT(I2S) |
  118. SH_FSI_IFMT(I2S),
  119. };
  120. static struct resource fsi_resources[] = {
  121. [0] = {
  122. .name = "FSI",
  123. .start = 0xEC230000,
  124. .end = 0xEC230400 - 1,
  125. .flags = IORESOURCE_MEM,
  126. },
  127. [1] = {
  128. .start = gic_spi(146),
  129. .flags = IORESOURCE_IRQ,
  130. },
  131. };
  132. static struct platform_device fsi_device = {
  133. .name = "sh_fsi2",
  134. .id = -1,
  135. .num_resources = ARRAY_SIZE(fsi_resources),
  136. .resource = fsi_resources,
  137. .dev = {
  138. .platform_data = &fsi_info,
  139. },
  140. };
  141. static struct resource sh_mmcif_resources[] = {
  142. [0] = {
  143. .name = "MMCIF",
  144. .start = 0xe6bd0000,
  145. .end = 0xe6bd00ff,
  146. .flags = IORESOURCE_MEM,
  147. },
  148. [1] = {
  149. .start = gic_spi(141),
  150. .flags = IORESOURCE_IRQ,
  151. },
  152. [2] = {
  153. .start = gic_spi(140),
  154. .flags = IORESOURCE_IRQ,
  155. },
  156. };
  157. static struct sh_mmcif_plat_data sh_mmcif_platdata = {
  158. .sup_pclk = 0,
  159. .ocr = MMC_VDD_165_195,
  160. .caps = MMC_CAP_8_BIT_DATA | MMC_CAP_NONREMOVABLE,
  161. };
  162. static struct platform_device mmc_device = {
  163. .name = "sh_mmcif",
  164. .id = 0,
  165. .dev = {
  166. .dma_mask = NULL,
  167. .coherent_dma_mask = 0xffffffff,
  168. .platform_data = &sh_mmcif_platdata,
  169. },
  170. .num_resources = ARRAY_SIZE(sh_mmcif_resources),
  171. .resource = sh_mmcif_resources,
  172. };
  173. /* IrDA */
  174. static struct resource irda_resources[] = {
  175. [0] = {
  176. .start = 0xE6D00000,
  177. .end = 0xE6D01FD4 - 1,
  178. .flags = IORESOURCE_MEM,
  179. },
  180. [1] = {
  181. .start = gic_spi(95),
  182. .flags = IORESOURCE_IRQ,
  183. },
  184. };
  185. static struct platform_device irda_device = {
  186. .name = "sh_irda",
  187. .id = 0,
  188. .resource = irda_resources,
  189. .num_resources = ARRAY_SIZE(irda_resources),
  190. };
  191. static unsigned char lcd_backlight_seq[3][2] = {
  192. { 0x04, 0x07 },
  193. { 0x23, 0x80 },
  194. { 0x03, 0x01 },
  195. };
  196. static void lcd_backlight_on(void)
  197. {
  198. struct i2c_adapter *a;
  199. struct i2c_msg msg;
  200. int k;
  201. a = i2c_get_adapter(1);
  202. for (k = 0; a && k < 3; k++) {
  203. msg.addr = 0x6d;
  204. msg.buf = &lcd_backlight_seq[k][0];
  205. msg.len = 2;
  206. msg.flags = 0;
  207. if (i2c_transfer(a, &msg, 1) != 1)
  208. break;
  209. }
  210. }
  211. static void lcd_backlight_reset(void)
  212. {
  213. gpio_set_value(GPIO_PORT235, 0);
  214. mdelay(24);
  215. gpio_set_value(GPIO_PORT235, 1);
  216. }
  217. static void lcd_on(void *board_data, struct fb_info *info)
  218. {
  219. lcd_backlight_on();
  220. }
  221. static void lcd_off(void *board_data)
  222. {
  223. lcd_backlight_reset();
  224. }
  225. /* LCDC0 */
  226. static const struct fb_videomode lcdc0_modes[] = {
  227. {
  228. .name = "R63302(QHD)",
  229. .xres = 544,
  230. .yres = 961,
  231. .left_margin = 72,
  232. .right_margin = 600,
  233. .hsync_len = 16,
  234. .upper_margin = 8,
  235. .lower_margin = 8,
  236. .vsync_len = 2,
  237. .sync = FB_SYNC_VERT_HIGH_ACT | FB_SYNC_HOR_HIGH_ACT,
  238. },
  239. };
  240. static struct sh_mobile_lcdc_info lcdc0_info = {
  241. .clock_source = LCDC_CLK_PERIPHERAL,
  242. .ch[0] = {
  243. .chan = LCDC_CHAN_MAINLCD,
  244. .interface_type = RGB24,
  245. .clock_divider = 1,
  246. .flags = LCDC_FLAGS_DWPOL,
  247. .lcd_size_cfg.width = 44,
  248. .lcd_size_cfg.height = 79,
  249. .bpp = 16,
  250. .lcd_cfg = lcdc0_modes,
  251. .num_cfg = ARRAY_SIZE(lcdc0_modes),
  252. .board_cfg = {
  253. .display_on = lcd_on,
  254. .display_off = lcd_off,
  255. },
  256. }
  257. };
  258. static struct resource lcdc0_resources[] = {
  259. [0] = {
  260. .name = "LCDC0",
  261. .start = 0xfe940000, /* P4-only space */
  262. .end = 0xfe943fff,
  263. .flags = IORESOURCE_MEM,
  264. },
  265. [1] = {
  266. .start = intcs_evt2irq(0x580),
  267. .flags = IORESOURCE_IRQ,
  268. },
  269. };
  270. static struct platform_device lcdc0_device = {
  271. .name = "sh_mobile_lcdc_fb",
  272. .num_resources = ARRAY_SIZE(lcdc0_resources),
  273. .resource = lcdc0_resources,
  274. .id = 0,
  275. .dev = {
  276. .platform_data = &lcdc0_info,
  277. .coherent_dma_mask = ~0,
  278. },
  279. };
  280. /* MIPI-DSI */
  281. static struct resource mipidsi0_resources[] = {
  282. [0] = {
  283. .start = 0xfeab0000,
  284. .end = 0xfeab3fff,
  285. .flags = IORESOURCE_MEM,
  286. },
  287. [1] = {
  288. .start = 0xfeab4000,
  289. .end = 0xfeab7fff,
  290. .flags = IORESOURCE_MEM,
  291. },
  292. };
  293. static struct sh_mipi_dsi_info mipidsi0_info = {
  294. .data_format = MIPI_RGB888,
  295. .lcd_chan = &lcdc0_info.ch[0],
  296. .vsynw_offset = 20,
  297. .clksrc = 1,
  298. .flags = SH_MIPI_DSI_HSABM,
  299. };
  300. static struct platform_device mipidsi0_device = {
  301. .name = "sh-mipi-dsi",
  302. .num_resources = ARRAY_SIZE(mipidsi0_resources),
  303. .resource = mipidsi0_resources,
  304. .id = 0,
  305. .dev = {
  306. .platform_data = &mipidsi0_info,
  307. },
  308. };
  309. static struct platform_device *ag5evm_devices[] __initdata = {
  310. &eth_device,
  311. &keysc_device,
  312. &fsi_device,
  313. &mmc_device,
  314. &irda_device,
  315. &lcdc0_device,
  316. &mipidsi0_device,
  317. };
  318. static struct map_desc ag5evm_io_desc[] __initdata = {
  319. /* create a 1:1 entity map for 0xe6xxxxxx
  320. * used by CPGA, INTC and PFC.
  321. */
  322. {
  323. .virtual = 0xe6000000,
  324. .pfn = __phys_to_pfn(0xe6000000),
  325. .length = 256 << 20,
  326. .type = MT_DEVICE_NONSHARED
  327. },
  328. };
  329. static void __init ag5evm_map_io(void)
  330. {
  331. iotable_init(ag5evm_io_desc, ARRAY_SIZE(ag5evm_io_desc));
  332. /* setup early devices and console here as well */
  333. sh73a0_add_early_devices();
  334. shmobile_setup_console();
  335. }
  336. #define PINTC_ADDR 0xe6900000
  337. #define PINTER0A (PINTC_ADDR + 0xa0)
  338. #define PINTCR0A (PINTC_ADDR + 0xb0)
  339. void __init ag5evm_init_irq(void)
  340. {
  341. sh73a0_init_irq();
  342. /* setup PINT: enable PINTA2 as active low */
  343. __raw_writel(__raw_readl(PINTER0A) | (1<<29), PINTER0A);
  344. __raw_writew(__raw_readw(PINTCR0A) | (2<<10), PINTCR0A);
  345. }
  346. #define DSI0PHYCR 0xe615006c
  347. static void __init ag5evm_init(void)
  348. {
  349. sh73a0_pinmux_init();
  350. /* enable SCIFA2 */
  351. gpio_request(GPIO_FN_SCIFA2_TXD1, NULL);
  352. gpio_request(GPIO_FN_SCIFA2_RXD1, NULL);
  353. gpio_request(GPIO_FN_SCIFA2_RTS1_, NULL);
  354. gpio_request(GPIO_FN_SCIFA2_CTS1_, NULL);
  355. /* enable KEYSC */
  356. gpio_request(GPIO_FN_KEYIN0_PU, NULL);
  357. gpio_request(GPIO_FN_KEYIN1_PU, NULL);
  358. gpio_request(GPIO_FN_KEYIN2_PU, NULL);
  359. gpio_request(GPIO_FN_KEYIN3_PU, NULL);
  360. gpio_request(GPIO_FN_KEYIN4_PU, NULL);
  361. gpio_request(GPIO_FN_KEYIN5_PU, NULL);
  362. gpio_request(GPIO_FN_KEYIN6_PU, NULL);
  363. gpio_request(GPIO_FN_KEYIN7_PU, NULL);
  364. gpio_request(GPIO_FN_KEYOUT0, NULL);
  365. gpio_request(GPIO_FN_KEYOUT1, NULL);
  366. gpio_request(GPIO_FN_KEYOUT2, NULL);
  367. gpio_request(GPIO_FN_KEYOUT3, NULL);
  368. gpio_request(GPIO_FN_KEYOUT4, NULL);
  369. gpio_request(GPIO_FN_KEYOUT5, NULL);
  370. gpio_request(GPIO_FN_PORT59_KEYOUT6, NULL);
  371. gpio_request(GPIO_FN_PORT58_KEYOUT7, NULL);
  372. gpio_request(GPIO_FN_KEYOUT8, NULL);
  373. gpio_request(GPIO_FN_PORT149_KEYOUT9, NULL);
  374. /* enable I2C channel 2 and 3 */
  375. gpio_request(GPIO_FN_PORT236_I2C_SDA2, NULL);
  376. gpio_request(GPIO_FN_PORT237_I2C_SCL2, NULL);
  377. gpio_request(GPIO_FN_PORT248_I2C_SCL3, NULL);
  378. gpio_request(GPIO_FN_PORT249_I2C_SDA3, NULL);
  379. /* enable MMCIF */
  380. gpio_request(GPIO_FN_MMCCLK0, NULL);
  381. gpio_request(GPIO_FN_MMCCMD0_PU, NULL);
  382. gpio_request(GPIO_FN_MMCD0_0, NULL);
  383. gpio_request(GPIO_FN_MMCD0_1, NULL);
  384. gpio_request(GPIO_FN_MMCD0_2, NULL);
  385. gpio_request(GPIO_FN_MMCD0_3, NULL);
  386. gpio_request(GPIO_FN_MMCD0_4, NULL);
  387. gpio_request(GPIO_FN_MMCD0_5, NULL);
  388. gpio_request(GPIO_FN_MMCD0_6, NULL);
  389. gpio_request(GPIO_FN_MMCD0_7, NULL);
  390. gpio_request(GPIO_PORT208, NULL); /* Reset */
  391. gpio_direction_output(GPIO_PORT208, 1);
  392. /* enable SMSC911X */
  393. gpio_request(GPIO_PORT144, NULL); /* PINTA2 */
  394. gpio_direction_input(GPIO_PORT144);
  395. gpio_request(GPIO_PORT145, NULL); /* RESET */
  396. gpio_direction_output(GPIO_PORT145, 1);
  397. /* FSI A */
  398. gpio_request(GPIO_FN_FSIACK, NULL);
  399. gpio_request(GPIO_FN_FSIAILR, NULL);
  400. gpio_request(GPIO_FN_FSIAIBT, NULL);
  401. gpio_request(GPIO_FN_FSIAISLD, NULL);
  402. gpio_request(GPIO_FN_FSIAOSLD, NULL);
  403. /* IrDA */
  404. gpio_request(GPIO_FN_PORT241_IRDA_OUT, NULL);
  405. gpio_request(GPIO_FN_PORT242_IRDA_IN, NULL);
  406. gpio_request(GPIO_FN_PORT243_IRDA_FIRSEL, NULL);
  407. /* LCD panel */
  408. gpio_request(GPIO_PORT217, NULL); /* RESET */
  409. gpio_direction_output(GPIO_PORT217, 0);
  410. mdelay(1);
  411. gpio_set_value(GPIO_PORT217, 1);
  412. /* LCD backlight controller */
  413. gpio_request(GPIO_PORT235, NULL); /* RESET */
  414. gpio_direction_output(GPIO_PORT235, 0);
  415. lcd_backlight_reset();
  416. /* MIPI-DSI clock setup */
  417. __raw_writel(0x2a809010, DSI0PHYCR);
  418. #ifdef CONFIG_CACHE_L2X0
  419. /* Shared attribute override enable, 64K*8way */
  420. l2x0_init(__io(0xf0100000), 0x00460000, 0xc2000fff);
  421. #endif
  422. sh73a0_add_standard_devices();
  423. platform_add_devices(ag5evm_devices, ARRAY_SIZE(ag5evm_devices));
  424. }
  425. static void __init ag5evm_timer_init(void)
  426. {
  427. sh73a0_clock_init();
  428. shmobile_timer.init();
  429. return;
  430. }
  431. struct sys_timer ag5evm_timer = {
  432. .init = ag5evm_timer_init,
  433. };
  434. MACHINE_START(AG5EVM, "ag5evm")
  435. .map_io = ag5evm_map_io,
  436. .init_irq = ag5evm_init_irq,
  437. .handle_irq = shmobile_handle_irq_gic,
  438. .init_machine = ag5evm_init,
  439. .timer = &ag5evm_timer,
  440. MACHINE_END