board-kzm9g.c 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  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/platform_device.h>
  27. #include <linux/smsc911x.h>
  28. #include <linux/usb/r8a66597.h>
  29. #include <linux/videodev2.h>
  30. #include <mach/irqs.h>
  31. #include <mach/sh73a0.h>
  32. #include <mach/common.h>
  33. #include <asm/hardware/cache-l2x0.h>
  34. #include <asm/hardware/gic.h>
  35. #include <asm/mach-types.h>
  36. #include <asm/mach/arch.h>
  37. #include <video/sh_mobile_lcdc.h>
  38. /* SMSC 9221 */
  39. static struct resource smsc9221_resources[] = {
  40. [0] = {
  41. .start = 0x10000000, /* CS4 */
  42. .end = 0x100000ff,
  43. .flags = IORESOURCE_MEM,
  44. },
  45. [1] = {
  46. .start = intcs_evt2irq(0x260), /* IRQ3 */
  47. .flags = IORESOURCE_IRQ,
  48. },
  49. };
  50. static struct smsc911x_platform_config smsc9221_platdata = {
  51. .flags = SMSC911X_USE_32BIT | SMSC911X_SAVE_MAC_ADDRESS,
  52. .phy_interface = PHY_INTERFACE_MODE_MII,
  53. .irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,
  54. .irq_type = SMSC911X_IRQ_TYPE_PUSH_PULL,
  55. };
  56. static struct platform_device smsc_device = {
  57. .name = "smsc911x",
  58. .dev = {
  59. .platform_data = &smsc9221_platdata,
  60. },
  61. .resource = smsc9221_resources,
  62. .num_resources = ARRAY_SIZE(smsc9221_resources),
  63. };
  64. /* USB external chip */
  65. static struct r8a66597_platdata usb_host_data = {
  66. .on_chip = 0,
  67. .xtal = R8A66597_PLATDATA_XTAL_48MHZ,
  68. };
  69. static struct resource usb_resources[] = {
  70. [0] = {
  71. .start = 0x10010000,
  72. .end = 0x1001ffff - 1,
  73. .flags = IORESOURCE_MEM,
  74. },
  75. [1] = {
  76. .start = intcs_evt2irq(0x220), /* IRQ1 */
  77. .flags = IORESOURCE_IRQ,
  78. },
  79. };
  80. static struct platform_device usb_host_device = {
  81. .name = "r8a66597_hcd",
  82. .dev = {
  83. .platform_data = &usb_host_data,
  84. .dma_mask = NULL,
  85. .coherent_dma_mask = 0xffffffff,
  86. },
  87. .num_resources = ARRAY_SIZE(usb_resources),
  88. .resource = usb_resources,
  89. };
  90. /* LCDC */
  91. static struct fb_videomode kzm_lcdc_mode = {
  92. .name = "WVGA Panel",
  93. .xres = 800,
  94. .yres = 480,
  95. .left_margin = 220,
  96. .right_margin = 110,
  97. .hsync_len = 70,
  98. .upper_margin = 20,
  99. .lower_margin = 5,
  100. .vsync_len = 5,
  101. .sync = 0,
  102. };
  103. static struct sh_mobile_lcdc_info lcdc_info = {
  104. .clock_source = LCDC_CLK_BUS,
  105. .ch[0] = {
  106. .chan = LCDC_CHAN_MAINLCD,
  107. .fourcc = V4L2_PIX_FMT_RGB565,
  108. .interface_type = RGB24,
  109. .lcd_modes = &kzm_lcdc_mode,
  110. .num_modes = 1,
  111. .clock_divider = 5,
  112. .flags = 0,
  113. .panel_cfg = {
  114. .width = 152,
  115. .height = 91,
  116. },
  117. }
  118. };
  119. static struct resource lcdc_resources[] = {
  120. [0] = {
  121. .name = "LCDC",
  122. .start = 0xfe940000,
  123. .end = 0xfe943fff,
  124. .flags = IORESOURCE_MEM,
  125. },
  126. [1] = {
  127. .start = intcs_evt2irq(0x580),
  128. .flags = IORESOURCE_IRQ,
  129. },
  130. };
  131. static struct platform_device lcdc_device = {
  132. .name = "sh_mobile_lcdc_fb",
  133. .num_resources = ARRAY_SIZE(lcdc_resources),
  134. .resource = lcdc_resources,
  135. .dev = {
  136. .platform_data = &lcdc_info,
  137. .coherent_dma_mask = ~0,
  138. },
  139. };
  140. /* MMCIF */
  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. .ocr = MMC_VDD_165_195,
  159. .caps = MMC_CAP_8_BIT_DATA | MMC_CAP_NONREMOVABLE,
  160. };
  161. static struct platform_device mmc_device = {
  162. .name = "sh_mmcif",
  163. .dev = {
  164. .dma_mask = NULL,
  165. .coherent_dma_mask = 0xffffffff,
  166. .platform_data = &sh_mmcif_platdata,
  167. },
  168. .num_resources = ARRAY_SIZE(sh_mmcif_resources),
  169. .resource = sh_mmcif_resources,
  170. };
  171. static struct i2c_board_info i2c1_devices[] = {
  172. {
  173. I2C_BOARD_INFO("st1232-ts", 0x55),
  174. .irq = intcs_evt2irq(0x300), /* IRQ8 */
  175. },
  176. };
  177. static struct platform_device *kzm_devices[] __initdata = {
  178. &smsc_device,
  179. &usb_host_device,
  180. &lcdc_device,
  181. &mmc_device,
  182. };
  183. /*
  184. * FIXME
  185. *
  186. * This is quick hack for enabling LCDC backlight
  187. */
  188. static int __init as3711_enable_lcdc_backlight(void)
  189. {
  190. struct i2c_adapter *a = i2c_get_adapter(0);
  191. struct i2c_msg msg;
  192. int i, ret;
  193. __u8 magic[] = {
  194. 0x40, 0x2a,
  195. 0x43, 0x3c,
  196. 0x44, 0x3c,
  197. 0x45, 0x3c,
  198. 0x54, 0x03,
  199. 0x51, 0x00,
  200. 0x51, 0x01,
  201. 0xff, 0x00, /* wait */
  202. 0x43, 0xf0,
  203. 0x44, 0xf0,
  204. 0x45, 0xf0,
  205. };
  206. if (!machine_is_kzm9g())
  207. return 0;
  208. if (!a)
  209. return 0;
  210. msg.addr = 0x40;
  211. msg.len = 2;
  212. msg.flags = 0;
  213. for (i = 0; i < ARRAY_SIZE(magic); i += 2) {
  214. msg.buf = magic + i;
  215. if (0xff == msg.buf[0]) {
  216. udelay(500);
  217. continue;
  218. }
  219. ret = i2c_transfer(a, &msg, 1);
  220. if (ret < 0) {
  221. pr_err("i2c transfer fail\n");
  222. break;
  223. }
  224. }
  225. return 0;
  226. }
  227. device_initcall(as3711_enable_lcdc_backlight);
  228. static void __init kzm_init(void)
  229. {
  230. sh73a0_pinmux_init();
  231. /* enable SCIFA4 */
  232. gpio_request(GPIO_FN_SCIFA4_TXD, NULL);
  233. gpio_request(GPIO_FN_SCIFA4_RXD, NULL);
  234. gpio_request(GPIO_FN_SCIFA4_RTS_, NULL);
  235. gpio_request(GPIO_FN_SCIFA4_CTS_, NULL);
  236. /* CS4 for SMSC/USB */
  237. gpio_request(GPIO_FN_CS4_, NULL); /* CS4 */
  238. /* SMSC */
  239. gpio_request(GPIO_PORT224, NULL); /* IRQ3 */
  240. gpio_direction_input(GPIO_PORT224);
  241. /* LCDC */
  242. gpio_request(GPIO_FN_LCDD23, NULL);
  243. gpio_request(GPIO_FN_LCDD22, NULL);
  244. gpio_request(GPIO_FN_LCDD21, NULL);
  245. gpio_request(GPIO_FN_LCDD20, NULL);
  246. gpio_request(GPIO_FN_LCDD19, NULL);
  247. gpio_request(GPIO_FN_LCDD18, NULL);
  248. gpio_request(GPIO_FN_LCDD17, NULL);
  249. gpio_request(GPIO_FN_LCDD16, NULL);
  250. gpio_request(GPIO_FN_LCDD15, NULL);
  251. gpio_request(GPIO_FN_LCDD14, NULL);
  252. gpio_request(GPIO_FN_LCDD13, NULL);
  253. gpio_request(GPIO_FN_LCDD12, NULL);
  254. gpio_request(GPIO_FN_LCDD11, NULL);
  255. gpio_request(GPIO_FN_LCDD10, NULL);
  256. gpio_request(GPIO_FN_LCDD9, NULL);
  257. gpio_request(GPIO_FN_LCDD8, NULL);
  258. gpio_request(GPIO_FN_LCDD7, NULL);
  259. gpio_request(GPIO_FN_LCDD6, NULL);
  260. gpio_request(GPIO_FN_LCDD5, NULL);
  261. gpio_request(GPIO_FN_LCDD4, NULL);
  262. gpio_request(GPIO_FN_LCDD3, NULL);
  263. gpio_request(GPIO_FN_LCDD2, NULL);
  264. gpio_request(GPIO_FN_LCDD1, NULL);
  265. gpio_request(GPIO_FN_LCDD0, NULL);
  266. gpio_request(GPIO_FN_LCDDISP, NULL);
  267. gpio_request(GPIO_FN_LCDDCK, NULL);
  268. gpio_request(GPIO_PORT222, NULL); /* LCDCDON */
  269. gpio_request(GPIO_PORT226, NULL); /* SC */
  270. gpio_direction_output(GPIO_PORT222, 1);
  271. gpio_direction_output(GPIO_PORT226, 1);
  272. /* Touchscreen */
  273. gpio_request(GPIO_PORT223, NULL); /* IRQ8 */
  274. gpio_direction_input(GPIO_PORT223);
  275. /* enable MMCIF */
  276. gpio_request(GPIO_FN_MMCCLK0, NULL);
  277. gpio_request(GPIO_FN_MMCCMD0_PU, NULL);
  278. gpio_request(GPIO_FN_MMCD0_0_PU, NULL);
  279. gpio_request(GPIO_FN_MMCD0_1_PU, NULL);
  280. gpio_request(GPIO_FN_MMCD0_2_PU, NULL);
  281. gpio_request(GPIO_FN_MMCD0_3_PU, NULL);
  282. gpio_request(GPIO_FN_MMCD0_4_PU, NULL);
  283. gpio_request(GPIO_FN_MMCD0_5_PU, NULL);
  284. gpio_request(GPIO_FN_MMCD0_6_PU, NULL);
  285. gpio_request(GPIO_FN_MMCD0_7_PU, NULL);
  286. #ifdef CONFIG_CACHE_L2X0
  287. /* Early BRESP enable, Shared attribute override enable, 64K*8way */
  288. l2x0_init(IOMEM(0xf0100000), 0x40460000, 0x82000fff);
  289. #endif
  290. i2c_register_board_info(1, i2c1_devices, ARRAY_SIZE(i2c1_devices));
  291. sh73a0_add_standard_devices();
  292. platform_add_devices(kzm_devices, ARRAY_SIZE(kzm_devices));
  293. }
  294. MACHINE_START(KZM9G, "kzm9g")
  295. .map_io = sh73a0_map_io,
  296. .init_early = sh73a0_add_early_devices,
  297. .nr_irqs = NR_IRQS_LEGACY,
  298. .init_irq = sh73a0_init_irq,
  299. .handle_irq = gic_handle_irq,
  300. .init_machine = kzm_init,
  301. .timer = &shmobile_timer,
  302. MACHINE_END