setup.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Renesas Technology Sales RTS7751R2D Support.
  4. *
  5. * Copyright (C) 2002 - 2006 Atom Create Engineering Co., Ltd.
  6. * Copyright (C) 2004 - 2007 Paul Mundt
  7. */
  8. #include <linux/init.h>
  9. #include <linux/platform_device.h>
  10. #include <linux/mtd/mtd.h>
  11. #include <linux/mtd/partitions.h>
  12. #include <linux/mtd/physmap.h>
  13. #include <linux/ata_platform.h>
  14. #include <linux/sm501.h>
  15. #include <linux/sm501-regs.h>
  16. #include <linux/pm.h>
  17. #include <linux/fb.h>
  18. #include <linux/spi/spi.h>
  19. #include <linux/spi/spi_bitbang.h>
  20. #include <asm/machvec.h>
  21. #include <mach/r2d.h>
  22. #include <asm/io.h>
  23. #include <asm/io_trapped.h>
  24. #include <asm/spi.h>
  25. static struct resource cf_ide_resources[] = {
  26. [0] = {
  27. .start = PA_AREA5_IO + 0x1000,
  28. .end = PA_AREA5_IO + 0x1000 + 0x10 - 0x2,
  29. .flags = IORESOURCE_MEM,
  30. },
  31. [1] = {
  32. .start = PA_AREA5_IO + 0x80c,
  33. .end = PA_AREA5_IO + 0x80c,
  34. .flags = IORESOURCE_MEM,
  35. },
  36. #ifndef CONFIG_RTS7751R2D_1 /* For R2D-1 polling is preferred */
  37. [2] = {
  38. .start = IRQ_CF_IDE,
  39. .flags = IORESOURCE_IRQ,
  40. },
  41. #endif
  42. };
  43. static struct pata_platform_info pata_info = {
  44. .ioport_shift = 1,
  45. };
  46. static struct platform_device cf_ide_device = {
  47. .name = "pata_platform",
  48. .id = -1,
  49. .num_resources = ARRAY_SIZE(cf_ide_resources),
  50. .resource = cf_ide_resources,
  51. .dev = {
  52. .platform_data = &pata_info,
  53. },
  54. };
  55. static struct spi_board_info spi_bus[] = {
  56. {
  57. .modalias = "rtc-r9701",
  58. .max_speed_hz = 1000000,
  59. .mode = SPI_MODE_3,
  60. },
  61. };
  62. static void r2d_chip_select(struct sh_spi_info *spi, int cs, int state)
  63. {
  64. BUG_ON(cs != 0); /* Single Epson RTC-9701JE attached on CS0 */
  65. __raw_writew(state == BITBANG_CS_ACTIVE, PA_RTCCE);
  66. }
  67. static struct sh_spi_info spi_info = {
  68. .num_chipselect = 1,
  69. .chip_select = r2d_chip_select,
  70. };
  71. static struct resource spi_sh_sci_resources[] = {
  72. {
  73. .start = 0xffe00000,
  74. .end = 0xffe0001f,
  75. .flags = IORESOURCE_MEM,
  76. },
  77. };
  78. static struct platform_device spi_sh_sci_device = {
  79. .name = "spi_sh_sci",
  80. .id = -1,
  81. .num_resources = ARRAY_SIZE(spi_sh_sci_resources),
  82. .resource = spi_sh_sci_resources,
  83. .dev = {
  84. .platform_data = &spi_info,
  85. },
  86. };
  87. static struct resource heartbeat_resources[] = {
  88. [0] = {
  89. .start = PA_OUTPORT,
  90. .end = PA_OUTPORT,
  91. .flags = IORESOURCE_MEM,
  92. },
  93. };
  94. static struct platform_device heartbeat_device = {
  95. .name = "heartbeat",
  96. .id = -1,
  97. .num_resources = ARRAY_SIZE(heartbeat_resources),
  98. .resource = heartbeat_resources,
  99. };
  100. static struct resource sm501_resources[] = {
  101. [0] = {
  102. .start = 0x10000000,
  103. .end = 0x13e00000 - 1,
  104. .flags = IORESOURCE_MEM,
  105. },
  106. [1] = {
  107. .start = 0x13e00000,
  108. .end = 0x13ffffff,
  109. .flags = IORESOURCE_MEM,
  110. },
  111. [2] = {
  112. .start = IRQ_VOYAGER,
  113. .flags = IORESOURCE_IRQ,
  114. },
  115. };
  116. static struct fb_videomode sm501_default_mode = {
  117. .pixclock = 35714,
  118. .xres = 640,
  119. .yres = 480,
  120. .left_margin = 105,
  121. .right_margin = 50,
  122. .upper_margin = 35,
  123. .lower_margin = 0,
  124. .hsync_len = 96,
  125. .vsync_len = 2,
  126. .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  127. };
  128. static struct sm501_platdata_fbsub sm501_pdata_fbsub_pnl = {
  129. .def_bpp = 16,
  130. .def_mode = &sm501_default_mode,
  131. .flags = SM501FB_FLAG_USE_INIT_MODE |
  132. SM501FB_FLAG_USE_HWCURSOR |
  133. SM501FB_FLAG_USE_HWACCEL |
  134. SM501FB_FLAG_DISABLE_AT_EXIT,
  135. };
  136. static struct sm501_platdata_fbsub sm501_pdata_fbsub_crt = {
  137. .flags = (SM501FB_FLAG_USE_INIT_MODE |
  138. SM501FB_FLAG_USE_HWCURSOR |
  139. SM501FB_FLAG_USE_HWACCEL |
  140. SM501FB_FLAG_DISABLE_AT_EXIT),
  141. };
  142. static struct sm501_platdata_fb sm501_fb_pdata = {
  143. .fb_route = SM501_FB_OWN,
  144. .fb_crt = &sm501_pdata_fbsub_crt,
  145. .fb_pnl = &sm501_pdata_fbsub_pnl,
  146. .flags = SM501_FBPD_SWAP_FB_ENDIAN,
  147. };
  148. static struct sm501_initdata sm501_initdata = {
  149. .devices = SM501_USE_USB_HOST | SM501_USE_UART0,
  150. };
  151. static struct sm501_platdata sm501_platform_data = {
  152. .init = &sm501_initdata,
  153. .fb = &sm501_fb_pdata,
  154. };
  155. static struct platform_device sm501_device = {
  156. .name = "sm501",
  157. .id = -1,
  158. .dev = {
  159. .platform_data = &sm501_platform_data,
  160. },
  161. .num_resources = ARRAY_SIZE(sm501_resources),
  162. .resource = sm501_resources,
  163. };
  164. static struct mtd_partition r2d_partitions[] = {
  165. {
  166. .name = "U-Boot",
  167. .offset = 0x00000000,
  168. .size = 0x00040000,
  169. .mask_flags = MTD_WRITEABLE,
  170. }, {
  171. .name = "Environment",
  172. .offset = MTDPART_OFS_NXTBLK,
  173. .size = 0x00040000,
  174. .mask_flags = MTD_WRITEABLE,
  175. }, {
  176. .name = "Kernel",
  177. .offset = MTDPART_OFS_NXTBLK,
  178. .size = 0x001c0000,
  179. }, {
  180. .name = "Flash_FS",
  181. .offset = MTDPART_OFS_NXTBLK,
  182. .size = MTDPART_SIZ_FULL,
  183. }
  184. };
  185. static struct physmap_flash_data flash_data = {
  186. .width = 2,
  187. .nr_parts = ARRAY_SIZE(r2d_partitions),
  188. .parts = r2d_partitions,
  189. };
  190. static struct resource flash_resource = {
  191. .start = 0x00000000,
  192. .end = 0x02000000,
  193. .flags = IORESOURCE_MEM,
  194. };
  195. static struct platform_device flash_device = {
  196. .name = "physmap-flash",
  197. .id = -1,
  198. .resource = &flash_resource,
  199. .num_resources = 1,
  200. .dev = {
  201. .platform_data = &flash_data,
  202. },
  203. };
  204. static struct platform_device *rts7751r2d_devices[] __initdata = {
  205. &sm501_device,
  206. &heartbeat_device,
  207. &spi_sh_sci_device,
  208. };
  209. /*
  210. * The CF is connected with a 16-bit bus where 8-bit operations are
  211. * unsupported. The linux ata driver is however using 8-bit operations, so
  212. * insert a trapped io filter to convert 8-bit operations into 16-bit.
  213. */
  214. static struct trapped_io cf_trapped_io = {
  215. .resource = cf_ide_resources,
  216. .num_resources = 2,
  217. .minimum_bus_width = 16,
  218. };
  219. static int __init rts7751r2d_devices_setup(void)
  220. {
  221. if (register_trapped_io(&cf_trapped_io) == 0)
  222. platform_device_register(&cf_ide_device);
  223. if (mach_is_r2d_plus())
  224. platform_device_register(&flash_device);
  225. spi_register_board_info(spi_bus, ARRAY_SIZE(spi_bus));
  226. return platform_add_devices(rts7751r2d_devices,
  227. ARRAY_SIZE(rts7751r2d_devices));
  228. }
  229. device_initcall(rts7751r2d_devices_setup);
  230. static void rts7751r2d_power_off(void)
  231. {
  232. __raw_writew(0x0001, PA_POWOFF);
  233. }
  234. /*
  235. * Initialize the board
  236. */
  237. static void __init rts7751r2d_setup(char **cmdline_p)
  238. {
  239. void __iomem *sm501_reg;
  240. u16 ver = __raw_readw(PA_VERREG);
  241. printk(KERN_INFO "Renesas Technology Sales RTS7751R2D support.\n");
  242. printk(KERN_INFO "FPGA version:%d (revision:%d)\n",
  243. (ver >> 4) & 0xf, ver & 0xf);
  244. __raw_writew(0x0000, PA_OUTPORT);
  245. pm_power_off = rts7751r2d_power_off;
  246. /* sm501 dram configuration:
  247. * ColSizeX = 11 - External Memory Column Size: 256 words.
  248. * APX = 1 - External Memory Active to Pre-Charge Delay: 7 clocks.
  249. * RstX = 1 - External Memory Reset: Normal.
  250. * Rfsh = 1 - Local Memory Refresh to Command Delay: 12 clocks.
  251. * BwC = 1 - Local Memory Block Write Cycle Time: 2 clocks.
  252. * BwP = 1 - Local Memory Block Write to Pre-Charge Delay: 1 clock.
  253. * AP = 1 - Internal Memory Active to Pre-Charge Delay: 7 clocks.
  254. * Rst = 1 - Internal Memory Reset: Normal.
  255. * RA = 1 - Internal Memory Remain in Active State: Do not remain.
  256. */
  257. sm501_reg = (void __iomem *)0xb3e00000 + SM501_DRAM_CONTROL;
  258. writel(readl(sm501_reg) | 0x00f107c0, sm501_reg);
  259. }
  260. /*
  261. * The Machine Vector
  262. */
  263. static struct sh_machine_vector mv_rts7751r2d __initmv = {
  264. .mv_name = "RTS7751R2D",
  265. .mv_setup = rts7751r2d_setup,
  266. .mv_init_irq = init_rts7751r2d_IRQ,
  267. .mv_irq_demux = rts7751r2d_irq_demux,
  268. };