board-sh7785lcr.c 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. /*
  2. * Renesas Technology Corp. R0P7785LC0011RL Support.
  3. *
  4. * Copyright (C) 2008 Yoshihiro Shimoda
  5. * Copyright (C) 2009 Paul Mundt
  6. *
  7. * This file is subject to the terms and conditions of the GNU General Public
  8. * License. See the file "COPYING" in the main directory of this archive
  9. * for more details.
  10. */
  11. #include <linux/init.h>
  12. #include <linux/platform_device.h>
  13. #include <linux/sm501.h>
  14. #include <linux/sm501-regs.h>
  15. #include <linux/fb.h>
  16. #include <linux/mtd/physmap.h>
  17. #include <linux/delay.h>
  18. #include <linux/interrupt.h>
  19. #include <linux/i2c.h>
  20. #include <linux/i2c-pca-platform.h>
  21. #include <linux/i2c-algo-pca.h>
  22. #include <linux/usb/r8a66597.h>
  23. #include <linux/irq.h>
  24. #include <linux/clk.h>
  25. #include <linux/errno.h>
  26. #include <mach/sh7785lcr.h>
  27. #include <cpu/sh7785.h>
  28. #include <asm/heartbeat.h>
  29. #include <asm/clock.h>
  30. /*
  31. * NOTE: This board has 2 physical memory maps.
  32. * Please look at include/asm-sh/sh7785lcr.h or hardware manual.
  33. */
  34. static struct resource heartbeat_resources[] = {
  35. [0] = {
  36. .start = PLD_LEDCR,
  37. .end = PLD_LEDCR,
  38. .flags = IORESOURCE_MEM,
  39. },
  40. };
  41. static struct heartbeat_data heartbeat_data = {
  42. .regsize = 8,
  43. };
  44. static struct platform_device heartbeat_device = {
  45. .name = "heartbeat",
  46. .id = -1,
  47. .dev = {
  48. .platform_data = &heartbeat_data,
  49. },
  50. .num_resources = ARRAY_SIZE(heartbeat_resources),
  51. .resource = heartbeat_resources,
  52. };
  53. static struct mtd_partition nor_flash_partitions[] = {
  54. {
  55. .name = "loader",
  56. .offset = 0x00000000,
  57. .size = 512 * 1024,
  58. },
  59. {
  60. .name = "bootenv",
  61. .offset = MTDPART_OFS_APPEND,
  62. .size = 512 * 1024,
  63. },
  64. {
  65. .name = "kernel",
  66. .offset = MTDPART_OFS_APPEND,
  67. .size = 4 * 1024 * 1024,
  68. },
  69. {
  70. .name = "data",
  71. .offset = MTDPART_OFS_APPEND,
  72. .size = MTDPART_SIZ_FULL,
  73. },
  74. };
  75. static struct physmap_flash_data nor_flash_data = {
  76. .width = 4,
  77. .parts = nor_flash_partitions,
  78. .nr_parts = ARRAY_SIZE(nor_flash_partitions),
  79. };
  80. static struct resource nor_flash_resources[] = {
  81. [0] = {
  82. .start = NOR_FLASH_ADDR,
  83. .end = NOR_FLASH_ADDR + NOR_FLASH_SIZE - 1,
  84. .flags = IORESOURCE_MEM,
  85. }
  86. };
  87. static struct platform_device nor_flash_device = {
  88. .name = "physmap-flash",
  89. .dev = {
  90. .platform_data = &nor_flash_data,
  91. },
  92. .num_resources = ARRAY_SIZE(nor_flash_resources),
  93. .resource = nor_flash_resources,
  94. };
  95. static struct r8a66597_platdata r8a66597_data = {
  96. .xtal = R8A66597_PLATDATA_XTAL_12MHZ,
  97. .vif = 1,
  98. };
  99. static struct resource r8a66597_usb_host_resources[] = {
  100. [0] = {
  101. .start = R8A66597_ADDR,
  102. .end = R8A66597_ADDR + R8A66597_SIZE - 1,
  103. .flags = IORESOURCE_MEM,
  104. },
  105. [1] = {
  106. .start = 2,
  107. .end = 2,
  108. .flags = IORESOURCE_IRQ | IRQF_TRIGGER_LOW,
  109. },
  110. };
  111. static struct platform_device r8a66597_usb_host_device = {
  112. .name = "r8a66597_hcd",
  113. .id = -1,
  114. .dev = {
  115. .dma_mask = NULL,
  116. .coherent_dma_mask = 0xffffffff,
  117. .platform_data = &r8a66597_data,
  118. },
  119. .num_resources = ARRAY_SIZE(r8a66597_usb_host_resources),
  120. .resource = r8a66597_usb_host_resources,
  121. };
  122. static struct resource sm501_resources[] = {
  123. [0] = {
  124. .start = SM107_MEM_ADDR,
  125. .end = SM107_MEM_ADDR + SM107_MEM_SIZE - 1,
  126. .flags = IORESOURCE_MEM,
  127. },
  128. [1] = {
  129. .start = SM107_REG_ADDR,
  130. .end = SM107_REG_ADDR + SM107_REG_SIZE - 1,
  131. .flags = IORESOURCE_MEM,
  132. },
  133. [2] = {
  134. .start = 10,
  135. .flags = IORESOURCE_IRQ,
  136. },
  137. };
  138. static struct fb_videomode sm501_default_mode_crt = {
  139. .pixclock = 35714, /* 28MHz */
  140. .xres = 640,
  141. .yres = 480,
  142. .left_margin = 105,
  143. .right_margin = 16,
  144. .upper_margin = 33,
  145. .lower_margin = 10,
  146. .hsync_len = 39,
  147. .vsync_len = 2,
  148. .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  149. };
  150. static struct fb_videomode sm501_default_mode_pnl = {
  151. .pixclock = 40000, /* 25MHz */
  152. .xres = 640,
  153. .yres = 480,
  154. .left_margin = 2,
  155. .right_margin = 16,
  156. .upper_margin = 33,
  157. .lower_margin = 10,
  158. .hsync_len = 39,
  159. .vsync_len = 2,
  160. .sync = 0,
  161. };
  162. static struct sm501_platdata_fbsub sm501_pdata_fbsub_pnl = {
  163. .def_bpp = 16,
  164. .def_mode = &sm501_default_mode_pnl,
  165. .flags = SM501FB_FLAG_USE_INIT_MODE |
  166. SM501FB_FLAG_USE_HWCURSOR |
  167. SM501FB_FLAG_USE_HWACCEL |
  168. SM501FB_FLAG_DISABLE_AT_EXIT |
  169. SM501FB_FLAG_PANEL_NO_VBIASEN,
  170. };
  171. static struct sm501_platdata_fbsub sm501_pdata_fbsub_crt = {
  172. .def_bpp = 16,
  173. .def_mode = &sm501_default_mode_crt,
  174. .flags = SM501FB_FLAG_USE_INIT_MODE |
  175. SM501FB_FLAG_USE_HWCURSOR |
  176. SM501FB_FLAG_USE_HWACCEL |
  177. SM501FB_FLAG_DISABLE_AT_EXIT,
  178. };
  179. static struct sm501_platdata_fb sm501_fb_pdata = {
  180. .fb_route = SM501_FB_OWN,
  181. .fb_crt = &sm501_pdata_fbsub_crt,
  182. .fb_pnl = &sm501_pdata_fbsub_pnl,
  183. };
  184. static struct sm501_initdata sm501_initdata = {
  185. .gpio_high = {
  186. .set = 0x00001fe0,
  187. .mask = 0x0,
  188. },
  189. .devices = 0,
  190. .mclk = 84 * 1000000,
  191. .m1xclk = 112 * 1000000,
  192. };
  193. static struct sm501_platdata sm501_platform_data = {
  194. .init = &sm501_initdata,
  195. .fb = &sm501_fb_pdata,
  196. };
  197. static struct platform_device sm501_device = {
  198. .name = "sm501",
  199. .id = -1,
  200. .dev = {
  201. .platform_data = &sm501_platform_data,
  202. },
  203. .num_resources = ARRAY_SIZE(sm501_resources),
  204. .resource = sm501_resources,
  205. };
  206. static struct resource i2c_resources[] = {
  207. [0] = {
  208. .start = PCA9564_ADDR,
  209. .end = PCA9564_ADDR + PCA9564_SIZE - 1,
  210. .flags = IORESOURCE_MEM | IORESOURCE_MEM_8BIT,
  211. },
  212. [1] = {
  213. .start = 12,
  214. .end = 12,
  215. .flags = IORESOURCE_IRQ,
  216. },
  217. };
  218. static struct i2c_pca9564_pf_platform_data i2c_platform_data = {
  219. .gpio = 0,
  220. .i2c_clock_speed = I2C_PCA_CON_330kHz,
  221. .timeout = HZ,
  222. };
  223. static struct platform_device i2c_device = {
  224. .name = "i2c-pca-platform",
  225. .id = -1,
  226. .dev = {
  227. .platform_data = &i2c_platform_data,
  228. },
  229. .num_resources = ARRAY_SIZE(i2c_resources),
  230. .resource = i2c_resources,
  231. };
  232. static struct platform_device *sh7785lcr_devices[] __initdata = {
  233. &heartbeat_device,
  234. &nor_flash_device,
  235. &r8a66597_usb_host_device,
  236. &sm501_device,
  237. &i2c_device,
  238. };
  239. static struct i2c_board_info __initdata sh7785lcr_i2c_devices[] = {
  240. {
  241. I2C_BOARD_INFO("r2025sd", 0x32),
  242. },
  243. };
  244. static int __init sh7785lcr_devices_setup(void)
  245. {
  246. i2c_register_board_info(0, sh7785lcr_i2c_devices,
  247. ARRAY_SIZE(sh7785lcr_i2c_devices));
  248. return platform_add_devices(sh7785lcr_devices,
  249. ARRAY_SIZE(sh7785lcr_devices));
  250. }
  251. __initcall(sh7785lcr_devices_setup);
  252. /* Initialize IRQ setting */
  253. void __init init_sh7785lcr_IRQ(void)
  254. {
  255. plat_irq_setup_pins(IRQ_MODE_IRQ7654);
  256. plat_irq_setup_pins(IRQ_MODE_IRQ3210);
  257. }
  258. static int sh7785lcr_clk_init(void)
  259. {
  260. struct clk *clk;
  261. int ret;
  262. clk = clk_get(NULL, "extal");
  263. if (!clk || IS_ERR(clk))
  264. return PTR_ERR(clk);
  265. ret = clk_set_rate(clk, 33333333);
  266. clk_put(clk);
  267. return ret;
  268. }
  269. static void sh7785lcr_power_off(void)
  270. {
  271. unsigned char *p;
  272. p = ioremap(PLD_POFCR, PLD_POFCR + 1);
  273. if (!p) {
  274. printk(KERN_ERR "%s: ioremap error.\n", __func__);
  275. return;
  276. }
  277. *p = 0x01;
  278. iounmap(p);
  279. set_bl_bit();
  280. while (1)
  281. cpu_relax();
  282. }
  283. /* Initialize the board */
  284. static void __init sh7785lcr_setup(char **cmdline_p)
  285. {
  286. void __iomem *sm501_reg;
  287. printk(KERN_INFO "Renesas Technology Corp. R0P7785LC0011RL support.\n");
  288. pm_power_off = sh7785lcr_power_off;
  289. /* sm501 DRAM configuration */
  290. sm501_reg = (void __iomem *)0xb3e00000 + SM501_DRAM_CONTROL;
  291. writel(0x000307c2, sm501_reg);
  292. }
  293. /* Return the board specific boot mode pin configuration */
  294. static int sh7785lcr_mode_pins(void)
  295. {
  296. int value = 0;
  297. /* These are the factory default settings of S1 and S2.
  298. * If you change these dip switches then you will need to
  299. * adjust the values below as well.
  300. */
  301. value |= MODE_PIN4; /* Clock Mode 16 */
  302. value |= MODE_PIN5; /* 32-bit Area0 bus width */
  303. value |= MODE_PIN6; /* 32-bit Area0 bus width */
  304. value |= MODE_PIN7; /* Area 0 SRAM interface [fixed] */
  305. value |= MODE_PIN8; /* Little Endian */
  306. value |= MODE_PIN9; /* Master Mode */
  307. value |= MODE_PIN14; /* No PLL step-up */
  308. return value;
  309. }
  310. /*
  311. * The Machine Vector
  312. */
  313. static struct sh_machine_vector mv_sh7785lcr __initmv = {
  314. .mv_name = "SH7785LCR",
  315. .mv_setup = sh7785lcr_setup,
  316. .mv_clk_init = sh7785lcr_clk_init,
  317. .mv_init_irq = init_sh7785lcr_IRQ,
  318. .mv_mode_pins = sh7785lcr_mode_pins,
  319. };