board-kzm9g.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  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/gpio_keys.h>
  22. #include <linux/io.h>
  23. #include <linux/irq.h>
  24. #include <linux/i2c.h>
  25. #include <linux/i2c/pcf857x.h>
  26. #include <linux/input.h>
  27. #include <linux/mmc/host.h>
  28. #include <linux/mmc/sh_mmcif.h>
  29. #include <linux/mmc/sh_mobile_sdhi.h>
  30. #include <linux/mfd/tmio.h>
  31. #include <linux/platform_device.h>
  32. #include <linux/smsc911x.h>
  33. #include <linux/usb/r8a66597.h>
  34. #include <linux/videodev2.h>
  35. #include <mach/irqs.h>
  36. #include <mach/sh73a0.h>
  37. #include <mach/common.h>
  38. #include <asm/hardware/cache-l2x0.h>
  39. #include <asm/hardware/gic.h>
  40. #include <asm/mach-types.h>
  41. #include <asm/mach/arch.h>
  42. #include <video/sh_mobile_lcdc.h>
  43. /*
  44. * external GPIO
  45. */
  46. #define GPIO_PCF8575_BASE (GPIO_NR)
  47. #define GPIO_PCF8575_PORT10 (GPIO_NR + 8)
  48. #define GPIO_PCF8575_PORT11 (GPIO_NR + 9)
  49. #define GPIO_PCF8575_PORT12 (GPIO_NR + 10)
  50. #define GPIO_PCF8575_PORT13 (GPIO_NR + 11)
  51. #define GPIO_PCF8575_PORT14 (GPIO_NR + 12)
  52. #define GPIO_PCF8575_PORT15 (GPIO_NR + 13)
  53. #define GPIO_PCF8575_PORT16 (GPIO_NR + 14)
  54. /* SMSC 9221 */
  55. static struct resource smsc9221_resources[] = {
  56. [0] = {
  57. .start = 0x10000000, /* CS4 */
  58. .end = 0x100000ff,
  59. .flags = IORESOURCE_MEM,
  60. },
  61. [1] = {
  62. .start = intcs_evt2irq(0x260), /* IRQ3 */
  63. .flags = IORESOURCE_IRQ,
  64. },
  65. };
  66. static struct smsc911x_platform_config smsc9221_platdata = {
  67. .flags = SMSC911X_USE_32BIT | SMSC911X_SAVE_MAC_ADDRESS,
  68. .phy_interface = PHY_INTERFACE_MODE_MII,
  69. .irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,
  70. .irq_type = SMSC911X_IRQ_TYPE_PUSH_PULL,
  71. };
  72. static struct platform_device smsc_device = {
  73. .name = "smsc911x",
  74. .dev = {
  75. .platform_data = &smsc9221_platdata,
  76. },
  77. .resource = smsc9221_resources,
  78. .num_resources = ARRAY_SIZE(smsc9221_resources),
  79. };
  80. /* USB external chip */
  81. static struct r8a66597_platdata usb_host_data = {
  82. .on_chip = 0,
  83. .xtal = R8A66597_PLATDATA_XTAL_48MHZ,
  84. };
  85. static struct resource usb_resources[] = {
  86. [0] = {
  87. .start = 0x10010000,
  88. .end = 0x1001ffff - 1,
  89. .flags = IORESOURCE_MEM,
  90. },
  91. [1] = {
  92. .start = intcs_evt2irq(0x220), /* IRQ1 */
  93. .flags = IORESOURCE_IRQ,
  94. },
  95. };
  96. static struct platform_device usb_host_device = {
  97. .name = "r8a66597_hcd",
  98. .dev = {
  99. .platform_data = &usb_host_data,
  100. .dma_mask = NULL,
  101. .coherent_dma_mask = 0xffffffff,
  102. },
  103. .num_resources = ARRAY_SIZE(usb_resources),
  104. .resource = usb_resources,
  105. };
  106. /* LCDC */
  107. static struct fb_videomode kzm_lcdc_mode = {
  108. .name = "WVGA Panel",
  109. .xres = 800,
  110. .yres = 480,
  111. .left_margin = 220,
  112. .right_margin = 110,
  113. .hsync_len = 70,
  114. .upper_margin = 20,
  115. .lower_margin = 5,
  116. .vsync_len = 5,
  117. .sync = 0,
  118. };
  119. static struct sh_mobile_lcdc_info lcdc_info = {
  120. .clock_source = LCDC_CLK_BUS,
  121. .ch[0] = {
  122. .chan = LCDC_CHAN_MAINLCD,
  123. .fourcc = V4L2_PIX_FMT_RGB565,
  124. .interface_type = RGB24,
  125. .lcd_modes = &kzm_lcdc_mode,
  126. .num_modes = 1,
  127. .clock_divider = 5,
  128. .flags = 0,
  129. .panel_cfg = {
  130. .width = 152,
  131. .height = 91,
  132. },
  133. }
  134. };
  135. static struct resource lcdc_resources[] = {
  136. [0] = {
  137. .name = "LCDC",
  138. .start = 0xfe940000,
  139. .end = 0xfe943fff,
  140. .flags = IORESOURCE_MEM,
  141. },
  142. [1] = {
  143. .start = intcs_evt2irq(0x580),
  144. .flags = IORESOURCE_IRQ,
  145. },
  146. };
  147. static struct platform_device lcdc_device = {
  148. .name = "sh_mobile_lcdc_fb",
  149. .num_resources = ARRAY_SIZE(lcdc_resources),
  150. .resource = lcdc_resources,
  151. .dev = {
  152. .platform_data = &lcdc_info,
  153. .coherent_dma_mask = ~0,
  154. },
  155. };
  156. /* MMCIF */
  157. static struct resource sh_mmcif_resources[] = {
  158. [0] = {
  159. .name = "MMCIF",
  160. .start = 0xe6bd0000,
  161. .end = 0xe6bd00ff,
  162. .flags = IORESOURCE_MEM,
  163. },
  164. [1] = {
  165. .start = gic_spi(141),
  166. .flags = IORESOURCE_IRQ,
  167. },
  168. [2] = {
  169. .start = gic_spi(140),
  170. .flags = IORESOURCE_IRQ,
  171. },
  172. };
  173. static struct sh_mmcif_plat_data sh_mmcif_platdata = {
  174. .ocr = MMC_VDD_165_195,
  175. .caps = MMC_CAP_8_BIT_DATA | MMC_CAP_NONREMOVABLE,
  176. };
  177. static struct platform_device mmc_device = {
  178. .name = "sh_mmcif",
  179. .dev = {
  180. .dma_mask = NULL,
  181. .coherent_dma_mask = 0xffffffff,
  182. .platform_data = &sh_mmcif_platdata,
  183. },
  184. .num_resources = ARRAY_SIZE(sh_mmcif_resources),
  185. .resource = sh_mmcif_resources,
  186. };
  187. /* SDHI */
  188. static struct sh_mobile_sdhi_info sdhi0_info = {
  189. .tmio_flags = TMIO_MMC_HAS_IDLE_WAIT,
  190. .tmio_caps = MMC_CAP_SD_HIGHSPEED,
  191. .tmio_ocr_mask = MMC_VDD_27_28 | MMC_VDD_28_29,
  192. };
  193. static struct resource sdhi0_resources[] = {
  194. [0] = {
  195. .name = "SDHI0",
  196. .start = 0xee100000,
  197. .end = 0xee1000ff,
  198. .flags = IORESOURCE_MEM,
  199. },
  200. [1] = {
  201. .name = SH_MOBILE_SDHI_IRQ_CARD_DETECT,
  202. .start = gic_spi(83),
  203. .flags = IORESOURCE_IRQ,
  204. },
  205. [2] = {
  206. .name = SH_MOBILE_SDHI_IRQ_SDCARD,
  207. .start = gic_spi(84),
  208. .flags = IORESOURCE_IRQ,
  209. },
  210. [3] = {
  211. .name = SH_MOBILE_SDHI_IRQ_SDIO,
  212. .start = gic_spi(85),
  213. .flags = IORESOURCE_IRQ,
  214. },
  215. };
  216. static struct platform_device sdhi0_device = {
  217. .name = "sh_mobile_sdhi",
  218. .num_resources = ARRAY_SIZE(sdhi0_resources),
  219. .resource = sdhi0_resources,
  220. .dev = {
  221. .platform_data = &sdhi0_info,
  222. },
  223. };
  224. /* KEY */
  225. #define GPIO_KEY(c, g, d) { .code = c, .gpio = g, .desc = d, .active_low = 1 }
  226. static struct gpio_keys_button gpio_buttons[] = {
  227. GPIO_KEY(KEY_BACK, GPIO_PCF8575_PORT10, "SW3"),
  228. GPIO_KEY(KEY_RIGHT, GPIO_PCF8575_PORT11, "SW2-R"),
  229. GPIO_KEY(KEY_LEFT, GPIO_PCF8575_PORT12, "SW2-L"),
  230. GPIO_KEY(KEY_ENTER, GPIO_PCF8575_PORT13, "SW2-P"),
  231. GPIO_KEY(KEY_UP, GPIO_PCF8575_PORT14, "SW2-U"),
  232. GPIO_KEY(KEY_DOWN, GPIO_PCF8575_PORT15, "SW2-D"),
  233. GPIO_KEY(KEY_HOME, GPIO_PCF8575_PORT16, "SW1"),
  234. };
  235. static struct gpio_keys_platform_data gpio_key_info = {
  236. .buttons = gpio_buttons,
  237. .nbuttons = ARRAY_SIZE(gpio_buttons),
  238. .poll_interval = 250, /* poling at this point */
  239. };
  240. static struct platform_device gpio_keys_device = {
  241. /* gpio-pcf857x.c driver doesn't support gpio_to_irq() */
  242. .name = "gpio-keys-polled",
  243. .dev = {
  244. .platform_data = &gpio_key_info,
  245. },
  246. };
  247. /* I2C */
  248. static struct pcf857x_platform_data pcf8575_pdata = {
  249. .gpio_base = GPIO_PCF8575_BASE,
  250. };
  251. static struct i2c_board_info i2c1_devices[] = {
  252. {
  253. I2C_BOARD_INFO("st1232-ts", 0x55),
  254. .irq = intcs_evt2irq(0x300), /* IRQ8 */
  255. },
  256. };
  257. static struct i2c_board_info i2c3_devices[] = {
  258. {
  259. I2C_BOARD_INFO("pcf8575", 0x20),
  260. .platform_data = &pcf8575_pdata,
  261. },
  262. };
  263. static struct platform_device *kzm_devices[] __initdata = {
  264. &smsc_device,
  265. &usb_host_device,
  266. &lcdc_device,
  267. &mmc_device,
  268. &sdhi0_device,
  269. &gpio_keys_device,
  270. };
  271. /*
  272. * FIXME
  273. *
  274. * This is quick hack for enabling LCDC backlight
  275. */
  276. static int __init as3711_enable_lcdc_backlight(void)
  277. {
  278. struct i2c_adapter *a = i2c_get_adapter(0);
  279. struct i2c_msg msg;
  280. int i, ret;
  281. __u8 magic[] = {
  282. 0x40, 0x2a,
  283. 0x43, 0x3c,
  284. 0x44, 0x3c,
  285. 0x45, 0x3c,
  286. 0x54, 0x03,
  287. 0x51, 0x00,
  288. 0x51, 0x01,
  289. 0xff, 0x00, /* wait */
  290. 0x43, 0xf0,
  291. 0x44, 0xf0,
  292. 0x45, 0xf0,
  293. };
  294. if (!machine_is_kzm9g())
  295. return 0;
  296. if (!a)
  297. return 0;
  298. msg.addr = 0x40;
  299. msg.len = 2;
  300. msg.flags = 0;
  301. for (i = 0; i < ARRAY_SIZE(magic); i += 2) {
  302. msg.buf = magic + i;
  303. if (0xff == msg.buf[0]) {
  304. udelay(500);
  305. continue;
  306. }
  307. ret = i2c_transfer(a, &msg, 1);
  308. if (ret < 0) {
  309. pr_err("i2c transfer fail\n");
  310. break;
  311. }
  312. }
  313. return 0;
  314. }
  315. device_initcall(as3711_enable_lcdc_backlight);
  316. static void __init kzm_init(void)
  317. {
  318. sh73a0_pinmux_init();
  319. /* enable SCIFA4 */
  320. gpio_request(GPIO_FN_SCIFA4_TXD, NULL);
  321. gpio_request(GPIO_FN_SCIFA4_RXD, NULL);
  322. gpio_request(GPIO_FN_SCIFA4_RTS_, NULL);
  323. gpio_request(GPIO_FN_SCIFA4_CTS_, NULL);
  324. /* CS4 for SMSC/USB */
  325. gpio_request(GPIO_FN_CS4_, NULL); /* CS4 */
  326. /* SMSC */
  327. gpio_request(GPIO_PORT224, NULL); /* IRQ3 */
  328. gpio_direction_input(GPIO_PORT224);
  329. /* LCDC */
  330. gpio_request(GPIO_FN_LCDD23, NULL);
  331. gpio_request(GPIO_FN_LCDD22, NULL);
  332. gpio_request(GPIO_FN_LCDD21, NULL);
  333. gpio_request(GPIO_FN_LCDD20, NULL);
  334. gpio_request(GPIO_FN_LCDD19, NULL);
  335. gpio_request(GPIO_FN_LCDD18, NULL);
  336. gpio_request(GPIO_FN_LCDD17, NULL);
  337. gpio_request(GPIO_FN_LCDD16, NULL);
  338. gpio_request(GPIO_FN_LCDD15, NULL);
  339. gpio_request(GPIO_FN_LCDD14, NULL);
  340. gpio_request(GPIO_FN_LCDD13, NULL);
  341. gpio_request(GPIO_FN_LCDD12, NULL);
  342. gpio_request(GPIO_FN_LCDD11, NULL);
  343. gpio_request(GPIO_FN_LCDD10, NULL);
  344. gpio_request(GPIO_FN_LCDD9, NULL);
  345. gpio_request(GPIO_FN_LCDD8, NULL);
  346. gpio_request(GPIO_FN_LCDD7, NULL);
  347. gpio_request(GPIO_FN_LCDD6, NULL);
  348. gpio_request(GPIO_FN_LCDD5, NULL);
  349. gpio_request(GPIO_FN_LCDD4, NULL);
  350. gpio_request(GPIO_FN_LCDD3, NULL);
  351. gpio_request(GPIO_FN_LCDD2, NULL);
  352. gpio_request(GPIO_FN_LCDD1, NULL);
  353. gpio_request(GPIO_FN_LCDD0, NULL);
  354. gpio_request(GPIO_FN_LCDDISP, NULL);
  355. gpio_request(GPIO_FN_LCDDCK, NULL);
  356. gpio_request(GPIO_PORT222, NULL); /* LCDCDON */
  357. gpio_request(GPIO_PORT226, NULL); /* SC */
  358. gpio_direction_output(GPIO_PORT222, 1);
  359. gpio_direction_output(GPIO_PORT226, 1);
  360. /* Touchscreen */
  361. gpio_request(GPIO_PORT223, NULL); /* IRQ8 */
  362. gpio_direction_input(GPIO_PORT223);
  363. /* enable MMCIF */
  364. gpio_request(GPIO_FN_MMCCLK0, NULL);
  365. gpio_request(GPIO_FN_MMCCMD0_PU, NULL);
  366. gpio_request(GPIO_FN_MMCD0_0_PU, NULL);
  367. gpio_request(GPIO_FN_MMCD0_1_PU, NULL);
  368. gpio_request(GPIO_FN_MMCD0_2_PU, NULL);
  369. gpio_request(GPIO_FN_MMCD0_3_PU, NULL);
  370. gpio_request(GPIO_FN_MMCD0_4_PU, NULL);
  371. gpio_request(GPIO_FN_MMCD0_5_PU, NULL);
  372. gpio_request(GPIO_FN_MMCD0_6_PU, NULL);
  373. gpio_request(GPIO_FN_MMCD0_7_PU, NULL);
  374. /* enable SD */
  375. gpio_request(GPIO_FN_SDHIWP0, NULL);
  376. gpio_request(GPIO_FN_SDHICD0, NULL);
  377. gpio_request(GPIO_FN_SDHICMD0, NULL);
  378. gpio_request(GPIO_FN_SDHICLK0, NULL);
  379. gpio_request(GPIO_FN_SDHID0_3, NULL);
  380. gpio_request(GPIO_FN_SDHID0_2, NULL);
  381. gpio_request(GPIO_FN_SDHID0_1, NULL);
  382. gpio_request(GPIO_FN_SDHID0_0, NULL);
  383. gpio_request(GPIO_FN_SDHI0_VCCQ_MC0_ON, NULL);
  384. gpio_request(GPIO_PORT15, NULL);
  385. gpio_direction_output(GPIO_PORT15, 1); /* power */
  386. /* I2C 3 */
  387. gpio_request(GPIO_FN_PORT27_I2C_SCL3, NULL);
  388. gpio_request(GPIO_FN_PORT28_I2C_SDA3, NULL);
  389. #ifdef CONFIG_CACHE_L2X0
  390. /* Early BRESP enable, Shared attribute override enable, 64K*8way */
  391. l2x0_init(IOMEM(0xf0100000), 0x40460000, 0x82000fff);
  392. #endif
  393. i2c_register_board_info(1, i2c1_devices, ARRAY_SIZE(i2c1_devices));
  394. i2c_register_board_info(3, i2c3_devices, ARRAY_SIZE(i2c3_devices));
  395. sh73a0_add_standard_devices();
  396. platform_add_devices(kzm_devices, ARRAY_SIZE(kzm_devices));
  397. }
  398. static const char *kzm9g_boards_compat_dt[] __initdata = {
  399. "renesas,kzm9g",
  400. NULL,
  401. };
  402. DT_MACHINE_START(KZM9G_DT, "kzm9g")
  403. .map_io = sh73a0_map_io,
  404. .init_early = sh73a0_add_early_devices,
  405. .nr_irqs = NR_IRQS_LEGACY,
  406. .init_irq = sh73a0_init_irq,
  407. .handle_irq = gic_handle_irq,
  408. .init_machine = kzm_init,
  409. .timer = &shmobile_timer,
  410. .dt_compat = kzm9g_boards_compat_dt,
  411. MACHINE_END