board-kzm9g.c 13 KB

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