board-kzm9g.c 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. /*
  2. * KZM-A9-GT board support
  3. *
  4. * Copyright (C) 2012 Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; version 2 of the License.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  18. */
  19. #include <linux/delay.h>
  20. #include <linux/gpio.h>
  21. #include <linux/io.h>
  22. #include <linux/irq.h>
  23. #include <linux/i2c.h>
  24. #include <linux/mmc/host.h>
  25. #include <linux/mmc/sh_mmcif.h>
  26. #include <linux/mmc/sh_mobile_sdhi.h>
  27. #include <linux/mfd/tmio.h>
  28. #include <linux/platform_device.h>
  29. #include <linux/smsc911x.h>
  30. #include <linux/usb/r8a66597.h>
  31. #include <linux/videodev2.h>
  32. #include <mach/irqs.h>
  33. #include <mach/sh73a0.h>
  34. #include <mach/common.h>
  35. #include <asm/hardware/cache-l2x0.h>
  36. #include <asm/hardware/gic.h>
  37. #include <asm/mach-types.h>
  38. #include <asm/mach/arch.h>
  39. #include <video/sh_mobile_lcdc.h>
  40. /* SMSC 9221 */
  41. static struct resource smsc9221_resources[] = {
  42. [0] = {
  43. .start = 0x10000000, /* CS4 */
  44. .end = 0x100000ff,
  45. .flags = IORESOURCE_MEM,
  46. },
  47. [1] = {
  48. .start = intcs_evt2irq(0x260), /* IRQ3 */
  49. .flags = IORESOURCE_IRQ,
  50. },
  51. };
  52. static struct smsc911x_platform_config smsc9221_platdata = {
  53. .flags = SMSC911X_USE_32BIT | SMSC911X_SAVE_MAC_ADDRESS,
  54. .phy_interface = PHY_INTERFACE_MODE_MII,
  55. .irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,
  56. .irq_type = SMSC911X_IRQ_TYPE_PUSH_PULL,
  57. };
  58. static struct platform_device smsc_device = {
  59. .name = "smsc911x",
  60. .dev = {
  61. .platform_data = &smsc9221_platdata,
  62. },
  63. .resource = smsc9221_resources,
  64. .num_resources = ARRAY_SIZE(smsc9221_resources),
  65. };
  66. /* USB external chip */
  67. static struct r8a66597_platdata usb_host_data = {
  68. .on_chip = 0,
  69. .xtal = R8A66597_PLATDATA_XTAL_48MHZ,
  70. };
  71. static struct resource usb_resources[] = {
  72. [0] = {
  73. .start = 0x10010000,
  74. .end = 0x1001ffff - 1,
  75. .flags = IORESOURCE_MEM,
  76. },
  77. [1] = {
  78. .start = intcs_evt2irq(0x220), /* IRQ1 */
  79. .flags = IORESOURCE_IRQ,
  80. },
  81. };
  82. static struct platform_device usb_host_device = {
  83. .name = "r8a66597_hcd",
  84. .dev = {
  85. .platform_data = &usb_host_data,
  86. .dma_mask = NULL,
  87. .coherent_dma_mask = 0xffffffff,
  88. },
  89. .num_resources = ARRAY_SIZE(usb_resources),
  90. .resource = usb_resources,
  91. };
  92. /* LCDC */
  93. static struct fb_videomode kzm_lcdc_mode = {
  94. .name = "WVGA Panel",
  95. .xres = 800,
  96. .yres = 480,
  97. .left_margin = 220,
  98. .right_margin = 110,
  99. .hsync_len = 70,
  100. .upper_margin = 20,
  101. .lower_margin = 5,
  102. .vsync_len = 5,
  103. .sync = 0,
  104. };
  105. static struct sh_mobile_lcdc_info lcdc_info = {
  106. .clock_source = LCDC_CLK_BUS,
  107. .ch[0] = {
  108. .chan = LCDC_CHAN_MAINLCD,
  109. .fourcc = V4L2_PIX_FMT_RGB565,
  110. .interface_type = RGB24,
  111. .lcd_modes = &kzm_lcdc_mode,
  112. .num_modes = 1,
  113. .clock_divider = 5,
  114. .flags = 0,
  115. .panel_cfg = {
  116. .width = 152,
  117. .height = 91,
  118. },
  119. }
  120. };
  121. static struct resource lcdc_resources[] = {
  122. [0] = {
  123. .name = "LCDC",
  124. .start = 0xfe940000,
  125. .end = 0xfe943fff,
  126. .flags = IORESOURCE_MEM,
  127. },
  128. [1] = {
  129. .start = intcs_evt2irq(0x580),
  130. .flags = IORESOURCE_IRQ,
  131. },
  132. };
  133. static struct platform_device lcdc_device = {
  134. .name = "sh_mobile_lcdc_fb",
  135. .num_resources = ARRAY_SIZE(lcdc_resources),
  136. .resource = lcdc_resources,
  137. .dev = {
  138. .platform_data = &lcdc_info,
  139. .coherent_dma_mask = ~0,
  140. },
  141. };
  142. /* MMCIF */
  143. static struct resource sh_mmcif_resources[] = {
  144. [0] = {
  145. .name = "MMCIF",
  146. .start = 0xe6bd0000,
  147. .end = 0xe6bd00ff,
  148. .flags = IORESOURCE_MEM,
  149. },
  150. [1] = {
  151. .start = gic_spi(141),
  152. .flags = IORESOURCE_IRQ,
  153. },
  154. [2] = {
  155. .start = gic_spi(140),
  156. .flags = IORESOURCE_IRQ,
  157. },
  158. };
  159. static struct sh_mmcif_plat_data sh_mmcif_platdata = {
  160. .ocr = MMC_VDD_165_195,
  161. .caps = MMC_CAP_8_BIT_DATA | MMC_CAP_NONREMOVABLE,
  162. };
  163. static struct platform_device mmc_device = {
  164. .name = "sh_mmcif",
  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. /* SDHI */
  174. static struct sh_mobile_sdhi_info sdhi0_info = {
  175. .tmio_flags = TMIO_MMC_HAS_IDLE_WAIT,
  176. .tmio_caps = MMC_CAP_SD_HIGHSPEED,
  177. .tmio_ocr_mask = MMC_VDD_27_28 | MMC_VDD_28_29,
  178. };
  179. static struct resource sdhi0_resources[] = {
  180. [0] = {
  181. .name = "SDHI0",
  182. .start = 0xee100000,
  183. .end = 0xee1000ff,
  184. .flags = IORESOURCE_MEM,
  185. },
  186. [1] = {
  187. .name = SH_MOBILE_SDHI_IRQ_CARD_DETECT,
  188. .start = gic_spi(83),
  189. .flags = IORESOURCE_IRQ,
  190. },
  191. [2] = {
  192. .name = SH_MOBILE_SDHI_IRQ_SDCARD,
  193. .start = gic_spi(84),
  194. .flags = IORESOURCE_IRQ,
  195. },
  196. [3] = {
  197. .name = SH_MOBILE_SDHI_IRQ_SDIO,
  198. .start = gic_spi(85),
  199. .flags = IORESOURCE_IRQ,
  200. },
  201. };
  202. static struct platform_device sdhi0_device = {
  203. .name = "sh_mobile_sdhi",
  204. .num_resources = ARRAY_SIZE(sdhi0_resources),
  205. .resource = sdhi0_resources,
  206. .dev = {
  207. .platform_data = &sdhi0_info,
  208. },
  209. };
  210. /* I2C */
  211. static struct i2c_board_info i2c1_devices[] = {
  212. {
  213. I2C_BOARD_INFO("st1232-ts", 0x55),
  214. .irq = intcs_evt2irq(0x300), /* IRQ8 */
  215. },
  216. };
  217. static struct platform_device *kzm_devices[] __initdata = {
  218. &smsc_device,
  219. &usb_host_device,
  220. &lcdc_device,
  221. &mmc_device,
  222. &sdhi0_device,
  223. };
  224. /*
  225. * FIXME
  226. *
  227. * This is quick hack for enabling LCDC backlight
  228. */
  229. static int __init as3711_enable_lcdc_backlight(void)
  230. {
  231. struct i2c_adapter *a = i2c_get_adapter(0);
  232. struct i2c_msg msg;
  233. int i, ret;
  234. __u8 magic[] = {
  235. 0x40, 0x2a,
  236. 0x43, 0x3c,
  237. 0x44, 0x3c,
  238. 0x45, 0x3c,
  239. 0x54, 0x03,
  240. 0x51, 0x00,
  241. 0x51, 0x01,
  242. 0xff, 0x00, /* wait */
  243. 0x43, 0xf0,
  244. 0x44, 0xf0,
  245. 0x45, 0xf0,
  246. };
  247. if (!machine_is_kzm9g())
  248. return 0;
  249. if (!a)
  250. return 0;
  251. msg.addr = 0x40;
  252. msg.len = 2;
  253. msg.flags = 0;
  254. for (i = 0; i < ARRAY_SIZE(magic); i += 2) {
  255. msg.buf = magic + i;
  256. if (0xff == msg.buf[0]) {
  257. udelay(500);
  258. continue;
  259. }
  260. ret = i2c_transfer(a, &msg, 1);
  261. if (ret < 0) {
  262. pr_err("i2c transfer fail\n");
  263. break;
  264. }
  265. }
  266. return 0;
  267. }
  268. device_initcall(as3711_enable_lcdc_backlight);
  269. static void __init kzm_init(void)
  270. {
  271. sh73a0_pinmux_init();
  272. /* enable SCIFA4 */
  273. gpio_request(GPIO_FN_SCIFA4_TXD, NULL);
  274. gpio_request(GPIO_FN_SCIFA4_RXD, NULL);
  275. gpio_request(GPIO_FN_SCIFA4_RTS_, NULL);
  276. gpio_request(GPIO_FN_SCIFA4_CTS_, NULL);
  277. /* CS4 for SMSC/USB */
  278. gpio_request(GPIO_FN_CS4_, NULL); /* CS4 */
  279. /* SMSC */
  280. gpio_request(GPIO_PORT224, NULL); /* IRQ3 */
  281. gpio_direction_input(GPIO_PORT224);
  282. /* LCDC */
  283. gpio_request(GPIO_FN_LCDD23, NULL);
  284. gpio_request(GPIO_FN_LCDD22, NULL);
  285. gpio_request(GPIO_FN_LCDD21, NULL);
  286. gpio_request(GPIO_FN_LCDD20, NULL);
  287. gpio_request(GPIO_FN_LCDD19, NULL);
  288. gpio_request(GPIO_FN_LCDD18, NULL);
  289. gpio_request(GPIO_FN_LCDD17, NULL);
  290. gpio_request(GPIO_FN_LCDD16, NULL);
  291. gpio_request(GPIO_FN_LCDD15, NULL);
  292. gpio_request(GPIO_FN_LCDD14, NULL);
  293. gpio_request(GPIO_FN_LCDD13, NULL);
  294. gpio_request(GPIO_FN_LCDD12, NULL);
  295. gpio_request(GPIO_FN_LCDD11, NULL);
  296. gpio_request(GPIO_FN_LCDD10, NULL);
  297. gpio_request(GPIO_FN_LCDD9, NULL);
  298. gpio_request(GPIO_FN_LCDD8, NULL);
  299. gpio_request(GPIO_FN_LCDD7, NULL);
  300. gpio_request(GPIO_FN_LCDD6, NULL);
  301. gpio_request(GPIO_FN_LCDD5, NULL);
  302. gpio_request(GPIO_FN_LCDD4, NULL);
  303. gpio_request(GPIO_FN_LCDD3, NULL);
  304. gpio_request(GPIO_FN_LCDD2, NULL);
  305. gpio_request(GPIO_FN_LCDD1, NULL);
  306. gpio_request(GPIO_FN_LCDD0, NULL);
  307. gpio_request(GPIO_FN_LCDDISP, NULL);
  308. gpio_request(GPIO_FN_LCDDCK, NULL);
  309. gpio_request(GPIO_PORT222, NULL); /* LCDCDON */
  310. gpio_request(GPIO_PORT226, NULL); /* SC */
  311. gpio_direction_output(GPIO_PORT222, 1);
  312. gpio_direction_output(GPIO_PORT226, 1);
  313. /* Touchscreen */
  314. gpio_request(GPIO_PORT223, NULL); /* IRQ8 */
  315. gpio_direction_input(GPIO_PORT223);
  316. /* enable MMCIF */
  317. gpio_request(GPIO_FN_MMCCLK0, NULL);
  318. gpio_request(GPIO_FN_MMCCMD0_PU, NULL);
  319. gpio_request(GPIO_FN_MMCD0_0_PU, NULL);
  320. gpio_request(GPIO_FN_MMCD0_1_PU, NULL);
  321. gpio_request(GPIO_FN_MMCD0_2_PU, NULL);
  322. gpio_request(GPIO_FN_MMCD0_3_PU, NULL);
  323. gpio_request(GPIO_FN_MMCD0_4_PU, NULL);
  324. gpio_request(GPIO_FN_MMCD0_5_PU, NULL);
  325. gpio_request(GPIO_FN_MMCD0_6_PU, NULL);
  326. gpio_request(GPIO_FN_MMCD0_7_PU, NULL);
  327. /* enable SD */
  328. gpio_request(GPIO_FN_SDHIWP0, NULL);
  329. gpio_request(GPIO_FN_SDHICD0, NULL);
  330. gpio_request(GPIO_FN_SDHICMD0, NULL);
  331. gpio_request(GPIO_FN_SDHICLK0, NULL);
  332. gpio_request(GPIO_FN_SDHID0_3, NULL);
  333. gpio_request(GPIO_FN_SDHID0_2, NULL);
  334. gpio_request(GPIO_FN_SDHID0_1, NULL);
  335. gpio_request(GPIO_FN_SDHID0_0, NULL);
  336. gpio_request(GPIO_FN_SDHI0_VCCQ_MC0_ON, NULL);
  337. gpio_request(GPIO_PORT15, NULL);
  338. gpio_direction_output(GPIO_PORT15, 1); /* power */
  339. #ifdef CONFIG_CACHE_L2X0
  340. /* Early BRESP enable, Shared attribute override enable, 64K*8way */
  341. l2x0_init(IOMEM(0xf0100000), 0x40460000, 0x82000fff);
  342. #endif
  343. i2c_register_board_info(1, i2c1_devices, ARRAY_SIZE(i2c1_devices));
  344. sh73a0_add_standard_devices();
  345. platform_add_devices(kzm_devices, ARRAY_SIZE(kzm_devices));
  346. }
  347. MACHINE_START(KZM9G, "kzm9g")
  348. .map_io = sh73a0_map_io,
  349. .init_early = sh73a0_add_early_devices,
  350. .nr_irqs = NR_IRQS_LEGACY,
  351. .init_irq = sh73a0_init_irq,
  352. .handle_irq = gic_handle_irq,
  353. .init_machine = kzm_init,
  354. .timer = &shmobile_timer,
  355. MACHINE_END