board-sh7785lcr.c 8.4 KB

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