setup.c 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  1. /*
  2. * KFR2R09 board support code
  3. *
  4. * Copyright (C) 2009 Magnus Damm
  5. *
  6. * This file is subject to the terms and conditions of the GNU General Public
  7. * License. See the file "COPYING" in the main directory of this archive
  8. * for more details.
  9. */
  10. #include <linux/init.h>
  11. #include <linux/platform_device.h>
  12. #include <linux/interrupt.h>
  13. #include <linux/mtd/physmap.h>
  14. #include <linux/mtd/onenand.h>
  15. #include <linux/delay.h>
  16. #include <linux/clk.h>
  17. #include <linux/gpio.h>
  18. #include <linux/input.h>
  19. #include <linux/i2c.h>
  20. #include <linux/usb/r8a66597.h>
  21. #include <video/sh_mobile_lcdc.h>
  22. #include <asm/clock.h>
  23. #include <asm/machvec.h>
  24. #include <asm/io.h>
  25. #include <asm/sh_keysc.h>
  26. #include <cpu/sh7724.h>
  27. #include <mach/kfr2r09.h>
  28. static struct mtd_partition kfr2r09_nor_flash_partitions[] =
  29. {
  30. {
  31. .name = "boot",
  32. .offset = 0,
  33. .size = (4 * 1024 * 1024),
  34. .mask_flags = MTD_WRITEABLE, /* Read-only */
  35. },
  36. {
  37. .name = "other",
  38. .offset = MTDPART_OFS_APPEND,
  39. .size = MTDPART_SIZ_FULL,
  40. },
  41. };
  42. static struct physmap_flash_data kfr2r09_nor_flash_data = {
  43. .width = 2,
  44. .parts = kfr2r09_nor_flash_partitions,
  45. .nr_parts = ARRAY_SIZE(kfr2r09_nor_flash_partitions),
  46. };
  47. static struct resource kfr2r09_nor_flash_resources[] = {
  48. [0] = {
  49. .name = "NOR Flash",
  50. .start = 0x00000000,
  51. .end = 0x03ffffff,
  52. .flags = IORESOURCE_MEM,
  53. }
  54. };
  55. static struct platform_device kfr2r09_nor_flash_device = {
  56. .name = "physmap-flash",
  57. .resource = kfr2r09_nor_flash_resources,
  58. .num_resources = ARRAY_SIZE(kfr2r09_nor_flash_resources),
  59. .dev = {
  60. .platform_data = &kfr2r09_nor_flash_data,
  61. },
  62. };
  63. static struct resource kfr2r09_nand_flash_resources[] = {
  64. [0] = {
  65. .name = "NAND Flash",
  66. .start = 0x10000000,
  67. .end = 0x1001ffff,
  68. .flags = IORESOURCE_MEM,
  69. }
  70. };
  71. static struct platform_device kfr2r09_nand_flash_device = {
  72. .name = "onenand-flash",
  73. .resource = kfr2r09_nand_flash_resources,
  74. .num_resources = ARRAY_SIZE(kfr2r09_nand_flash_resources),
  75. };
  76. static struct sh_keysc_info kfr2r09_sh_keysc_info = {
  77. .mode = SH_KEYSC_MODE_1, /* KEYOUT0->4, KEYIN0->4 */
  78. .scan_timing = 3,
  79. .delay = 10,
  80. .keycodes = {
  81. KEY_PHONE, KEY_CLEAR, KEY_MAIL, KEY_WWW, KEY_ENTER,
  82. KEY_1, KEY_2, KEY_3, 0, KEY_UP,
  83. KEY_4, KEY_5, KEY_6, 0, KEY_LEFT,
  84. KEY_7, KEY_8, KEY_9, KEY_PROG1, KEY_RIGHT,
  85. KEY_S, KEY_0, KEY_P, KEY_PROG2, KEY_DOWN,
  86. 0, 0, 0, 0, 0
  87. },
  88. };
  89. static struct resource kfr2r09_sh_keysc_resources[] = {
  90. [0] = {
  91. .name = "KEYSC",
  92. .start = 0x044b0000,
  93. .end = 0x044b000f,
  94. .flags = IORESOURCE_MEM,
  95. },
  96. [1] = {
  97. .start = 79,
  98. .flags = IORESOURCE_IRQ,
  99. },
  100. };
  101. static struct platform_device kfr2r09_sh_keysc_device = {
  102. .name = "sh_keysc",
  103. .id = 0, /* "keysc0" clock */
  104. .num_resources = ARRAY_SIZE(kfr2r09_sh_keysc_resources),
  105. .resource = kfr2r09_sh_keysc_resources,
  106. .dev = {
  107. .platform_data = &kfr2r09_sh_keysc_info,
  108. },
  109. .archdata = {
  110. .hwblk_id = HWBLK_KEYSC,
  111. },
  112. };
  113. static struct sh_mobile_lcdc_info kfr2r09_sh_lcdc_info = {
  114. .clock_source = LCDC_CLK_BUS,
  115. .ch[0] = {
  116. .chan = LCDC_CHAN_MAINLCD,
  117. .bpp = 16,
  118. .interface_type = SYS18,
  119. .clock_divider = 6,
  120. .flags = LCDC_FLAGS_DWPOL,
  121. .lcd_cfg = {
  122. .name = "TX07D34VM0AAA",
  123. .xres = 240,
  124. .yres = 400,
  125. .left_margin = 0,
  126. .right_margin = 16,
  127. .hsync_len = 8,
  128. .upper_margin = 0,
  129. .lower_margin = 1,
  130. .vsync_len = 1,
  131. .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  132. },
  133. .lcd_size_cfg = {
  134. .width = 35,
  135. .height = 58,
  136. },
  137. .board_cfg = {
  138. .setup_sys = kfr2r09_lcd_setup,
  139. .display_on = kfr2r09_lcd_on,
  140. .display_off = kfr2r09_lcd_off,
  141. },
  142. .sys_bus_cfg = {
  143. .ldmt2r = 0x07010904,
  144. .ldmt3r = 0x14012914,
  145. /* set 1s delay to encourage fsync() */
  146. .deferred_io_msec = 1000,
  147. },
  148. }
  149. };
  150. static struct resource kfr2r09_sh_lcdc_resources[] = {
  151. [0] = {
  152. .name = "LCDC",
  153. .start = 0xfe940000, /* P4-only space */
  154. .end = 0xfe942fff,
  155. .flags = IORESOURCE_MEM,
  156. },
  157. [1] = {
  158. .start = 106,
  159. .flags = IORESOURCE_IRQ,
  160. },
  161. };
  162. static struct platform_device kfr2r09_sh_lcdc_device = {
  163. .name = "sh_mobile_lcdc_fb",
  164. .num_resources = ARRAY_SIZE(kfr2r09_sh_lcdc_resources),
  165. .resource = kfr2r09_sh_lcdc_resources,
  166. .dev = {
  167. .platform_data = &kfr2r09_sh_lcdc_info,
  168. },
  169. .archdata = {
  170. .hwblk_id = HWBLK_LCDC,
  171. },
  172. };
  173. static struct r8a66597_platdata kfr2r09_usb0_gadget_data = {
  174. .on_chip = 1,
  175. };
  176. static struct resource kfr2r09_usb0_gadget_resources[] = {
  177. [0] = {
  178. .start = 0x04d80000,
  179. .end = 0x04d80123,
  180. .flags = IORESOURCE_MEM,
  181. },
  182. [1] = {
  183. .start = 65,
  184. .end = 65,
  185. .flags = IORESOURCE_IRQ | IRQF_TRIGGER_LOW,
  186. },
  187. };
  188. static struct platform_device kfr2r09_usb0_gadget_device = {
  189. .name = "r8a66597_udc",
  190. .id = 0,
  191. .dev = {
  192. .dma_mask = NULL, /* not use dma */
  193. .coherent_dma_mask = 0xffffffff,
  194. .platform_data = &kfr2r09_usb0_gadget_data,
  195. },
  196. .num_resources = ARRAY_SIZE(kfr2r09_usb0_gadget_resources),
  197. .resource = kfr2r09_usb0_gadget_resources,
  198. };
  199. static struct platform_device *kfr2r09_devices[] __initdata = {
  200. &kfr2r09_nor_flash_device,
  201. &kfr2r09_nand_flash_device,
  202. &kfr2r09_sh_keysc_device,
  203. &kfr2r09_sh_lcdc_device,
  204. };
  205. #define BSC_CS0BCR 0xfec10004
  206. #define BSC_CS0WCR 0xfec10024
  207. #define BSC_CS4BCR 0xfec10010
  208. #define BSC_CS4WCR 0xfec10030
  209. #define PORT_MSELCRB 0xa4050182
  210. #ifdef CONFIG_I2C
  211. static int kfr2r09_usb0_gadget_i2c_setup(void)
  212. {
  213. struct i2c_adapter *a;
  214. struct i2c_msg msg;
  215. unsigned char buf[2];
  216. int ret;
  217. a = i2c_get_adapter(0);
  218. if (!a)
  219. return -ENODEV;
  220. /* set bit 1 (the second bit) of chip at 0x09, register 0x13 */
  221. buf[0] = 0x13;
  222. msg.addr = 0x09;
  223. msg.buf = buf;
  224. msg.len = 1;
  225. msg.flags = 0;
  226. ret = i2c_transfer(a, &msg, 1);
  227. if (ret != 1)
  228. return -ENODEV;
  229. buf[0] = 0;
  230. msg.addr = 0x09;
  231. msg.buf = buf;
  232. msg.len = 1;
  233. msg.flags = I2C_M_RD;
  234. ret = i2c_transfer(a, &msg, 1);
  235. if (ret != 1)
  236. return -ENODEV;
  237. buf[1] = buf[0] | (1 << 1);
  238. buf[0] = 0x13;
  239. msg.addr = 0x09;
  240. msg.buf = buf;
  241. msg.len = 2;
  242. msg.flags = 0;
  243. ret = i2c_transfer(a, &msg, 1);
  244. if (ret != 1)
  245. return -ENODEV;
  246. return 0;
  247. }
  248. #else
  249. static int kfr2r09_usb0_gadget_i2c_setup(void)
  250. {
  251. return -ENODEV;
  252. }
  253. #endif
  254. static int kfr2r09_usb0_gadget_setup(void)
  255. {
  256. int plugged_in;
  257. gpio_request(GPIO_PTN4, NULL); /* USB_DET */
  258. gpio_direction_input(GPIO_PTN4);
  259. plugged_in = gpio_get_value(GPIO_PTN4);
  260. if (!plugged_in)
  261. return -ENODEV; /* no cable plugged in */
  262. if (kfr2r09_usb0_gadget_i2c_setup() != 0)
  263. return -ENODEV; /* unable to configure using i2c */
  264. ctrl_outw((ctrl_inw(PORT_MSELCRB) & ~0xc000) | 0x8000, PORT_MSELCRB);
  265. gpio_request(GPIO_FN_PDSTATUS, NULL); /* R-standby disables USB clock */
  266. gpio_request(GPIO_PTV6, NULL); /* USBCLK_ON */
  267. gpio_direction_output(GPIO_PTV6, 1); /* USBCLK_ON = H */
  268. msleep(20); /* wait 20ms to let the clock settle */
  269. clk_enable(clk_get(NULL, "usb0"));
  270. ctrl_outw(0x0600, 0xa40501d4);
  271. return 0;
  272. }
  273. static int __init kfr2r09_devices_setup(void)
  274. {
  275. /* enable SCIF1 serial port for YC401 console support */
  276. gpio_request(GPIO_FN_SCIF1_RXD, NULL);
  277. gpio_request(GPIO_FN_SCIF1_TXD, NULL);
  278. /* setup NOR flash at CS0 */
  279. ctrl_outl(0x36db0400, BSC_CS0BCR);
  280. ctrl_outl(0x00000500, BSC_CS0WCR);
  281. /* setup NAND flash at CS4 */
  282. ctrl_outl(0x36db0400, BSC_CS4BCR);
  283. ctrl_outl(0x00000500, BSC_CS4WCR);
  284. /* setup KEYSC pins */
  285. gpio_request(GPIO_FN_KEYOUT0, NULL);
  286. gpio_request(GPIO_FN_KEYOUT1, NULL);
  287. gpio_request(GPIO_FN_KEYOUT2, NULL);
  288. gpio_request(GPIO_FN_KEYOUT3, NULL);
  289. gpio_request(GPIO_FN_KEYOUT4_IN6, NULL);
  290. gpio_request(GPIO_FN_KEYIN0, NULL);
  291. gpio_request(GPIO_FN_KEYIN1, NULL);
  292. gpio_request(GPIO_FN_KEYIN2, NULL);
  293. gpio_request(GPIO_FN_KEYIN3, NULL);
  294. gpio_request(GPIO_FN_KEYIN4, NULL);
  295. gpio_request(GPIO_FN_KEYOUT5_IN5, NULL);
  296. /* setup LCDC pins for SYS panel */
  297. gpio_request(GPIO_FN_LCDD17, NULL);
  298. gpio_request(GPIO_FN_LCDD16, NULL);
  299. gpio_request(GPIO_FN_LCDD15, NULL);
  300. gpio_request(GPIO_FN_LCDD14, NULL);
  301. gpio_request(GPIO_FN_LCDD13, NULL);
  302. gpio_request(GPIO_FN_LCDD12, NULL);
  303. gpio_request(GPIO_FN_LCDD11, NULL);
  304. gpio_request(GPIO_FN_LCDD10, NULL);
  305. gpio_request(GPIO_FN_LCDD9, NULL);
  306. gpio_request(GPIO_FN_LCDD8, NULL);
  307. gpio_request(GPIO_FN_LCDD7, NULL);
  308. gpio_request(GPIO_FN_LCDD6, NULL);
  309. gpio_request(GPIO_FN_LCDD5, NULL);
  310. gpio_request(GPIO_FN_LCDD4, NULL);
  311. gpio_request(GPIO_FN_LCDD3, NULL);
  312. gpio_request(GPIO_FN_LCDD2, NULL);
  313. gpio_request(GPIO_FN_LCDD1, NULL);
  314. gpio_request(GPIO_FN_LCDD0, NULL);
  315. gpio_request(GPIO_FN_LCDRS, NULL); /* LCD_RS */
  316. gpio_request(GPIO_FN_LCDCS, NULL); /* LCD_CS/ */
  317. gpio_request(GPIO_FN_LCDRD, NULL); /* LCD_RD/ */
  318. gpio_request(GPIO_FN_LCDWR, NULL); /* LCD_WR/ */
  319. gpio_request(GPIO_FN_LCDVSYN, NULL); /* LCD_VSYNC */
  320. gpio_request(GPIO_PTE4, NULL); /* LCD_RST/ */
  321. gpio_direction_output(GPIO_PTE4, 1);
  322. gpio_request(GPIO_PTF4, NULL); /* PROTECT/ */
  323. gpio_direction_output(GPIO_PTF4, 1);
  324. gpio_request(GPIO_PTU0, NULL); /* LEDSTDBY/ */
  325. gpio_direction_output(GPIO_PTU0, 1);
  326. /* setup USB function */
  327. if (kfr2r09_usb0_gadget_setup() == 0)
  328. platform_device_register(&kfr2r09_usb0_gadget_device);
  329. return platform_add_devices(kfr2r09_devices,
  330. ARRAY_SIZE(kfr2r09_devices));
  331. }
  332. device_initcall(kfr2r09_devices_setup);
  333. /* Return the board specific boot mode pin configuration */
  334. static int kfr2r09_mode_pins(void)
  335. {
  336. /* MD0=1, MD1=1, MD2=0: Clock Mode 3
  337. * MD3=0: 16-bit Area0 Bus Width
  338. * MD5=1: Little Endian
  339. * MD8=1: Test Mode Disabled
  340. */
  341. return MODE_PIN0 | MODE_PIN1 | MODE_PIN5 | MODE_PIN8;
  342. }
  343. /*
  344. * The Machine Vector
  345. */
  346. static struct sh_machine_vector mv_kfr2r09 __initmv = {
  347. .mv_name = "kfr2r09",
  348. .mv_mode_pins = kfr2r09_mode_pins,
  349. };