board-sh7785lcr.c 8.6 KB

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