board-sh7785lcr.c 8.5 KB

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