setup.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. /*
  2. * Renesas Technology Sales RTS7751R2D Support.
  3. *
  4. * Copyright (C) 2002 - 2006 Atom Create Engineering Co., Ltd.
  5. * Copyright (C) 2004 - 2007 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/pata_platform.h>
  14. #include <linux/serial_8250.h>
  15. #include <linux/sm501.h>
  16. #include <linux/sm501-regs.h>
  17. #include <linux/pm.h>
  18. #include <linux/fb.h>
  19. #include <linux/spi/spi.h>
  20. #include <linux/spi/spi_bitbang.h>
  21. #include <asm/machvec.h>
  22. #include <asm/rts7751r2d.h>
  23. #include <asm/io.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. ctrl_outw(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. #ifdef CONFIG_MFD_SM501
  101. static struct plat_serial8250_port uart_platform_data[] = {
  102. {
  103. .membase = (void __iomem *)0xb3e30000,
  104. .mapbase = 0xb3e30000,
  105. .iotype = UPIO_MEM,
  106. .irq = IRQ_VOYAGER,
  107. .flags = UPF_BOOT_AUTOCONF | UPF_SHARE_IRQ,
  108. .regshift = 2,
  109. .uartclk = (9600 * 16),
  110. },
  111. { 0 },
  112. };
  113. static struct platform_device uart_device = {
  114. .name = "serial8250",
  115. .id = PLAT8250_DEV_PLATFORM,
  116. .dev = {
  117. .platform_data = uart_platform_data,
  118. },
  119. };
  120. static struct resource sm501_resources[] = {
  121. [0] = {
  122. .start = 0x10000000,
  123. .end = 0x13e00000 - 1,
  124. .flags = IORESOURCE_MEM,
  125. },
  126. [1] = {
  127. .start = 0x13e00000,
  128. .end = 0x13ffffff,
  129. .flags = IORESOURCE_MEM,
  130. },
  131. [2] = {
  132. .start = IRQ_VOYAGER,
  133. .flags = IORESOURCE_IRQ,
  134. },
  135. };
  136. static struct fb_videomode sm501_default_mode = {
  137. .pixclock = 35714,
  138. .xres = 640,
  139. .yres = 480,
  140. .left_margin = 105,
  141. .right_margin = 50,
  142. .upper_margin = 35,
  143. .lower_margin = 0,
  144. .hsync_len = 96,
  145. .vsync_len = 2,
  146. .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  147. };
  148. static struct sm501_platdata_fbsub sm501_pdata_fbsub_pnl = {
  149. .def_bpp = 16,
  150. .def_mode = &sm501_default_mode,
  151. .flags = SM501FB_FLAG_USE_INIT_MODE |
  152. SM501FB_FLAG_USE_HWCURSOR |
  153. SM501FB_FLAG_USE_HWACCEL |
  154. SM501FB_FLAG_DISABLE_AT_EXIT,
  155. };
  156. static struct sm501_platdata_fbsub sm501_pdata_fbsub_crt = {
  157. .flags = (SM501FB_FLAG_USE_INIT_MODE |
  158. SM501FB_FLAG_USE_HWCURSOR |
  159. SM501FB_FLAG_USE_HWACCEL |
  160. SM501FB_FLAG_DISABLE_AT_EXIT),
  161. };
  162. static struct sm501_platdata_fb sm501_fb_pdata = {
  163. .fb_route = SM501_FB_OWN,
  164. .fb_crt = &sm501_pdata_fbsub_crt,
  165. .fb_pnl = &sm501_pdata_fbsub_pnl,
  166. .flags = SM501_FBPD_SWAP_FB_ENDIAN,
  167. };
  168. static struct sm501_initdata sm501_initdata = {
  169. .gpio_high = {
  170. .set = 0x00001fe0,
  171. .mask = 0x0,
  172. },
  173. .devices = SM501_USE_USB_HOST,
  174. };
  175. static struct sm501_platdata sm501_platform_data = {
  176. .init = &sm501_initdata,
  177. .fb = &sm501_fb_pdata,
  178. };
  179. static struct platform_device sm501_device = {
  180. .name = "sm501",
  181. .id = -1,
  182. .dev = {
  183. .platform_data = &sm501_platform_data,
  184. },
  185. .num_resources = ARRAY_SIZE(sm501_resources),
  186. .resource = sm501_resources,
  187. };
  188. #endif /* CONFIG_MFD_SM501 */
  189. static struct platform_device *rts7751r2d_devices[] __initdata = {
  190. #ifdef CONFIG_MFD_SM501
  191. &uart_device,
  192. &sm501_device,
  193. #endif
  194. &cf_ide_device,
  195. &heartbeat_device,
  196. &spi_sh_sci_device,
  197. };
  198. static int __init rts7751r2d_devices_setup(void)
  199. {
  200. spi_register_board_info(spi_bus, ARRAY_SIZE(spi_bus));
  201. return platform_add_devices(rts7751r2d_devices,
  202. ARRAY_SIZE(rts7751r2d_devices));
  203. }
  204. __initcall(rts7751r2d_devices_setup);
  205. static void rts7751r2d_power_off(void)
  206. {
  207. ctrl_outw(0x0001, PA_POWOFF);
  208. }
  209. static inline unsigned char is_ide_ioaddr(unsigned long addr)
  210. {
  211. return ((cf_ide_resources[0].start <= addr &&
  212. addr <= cf_ide_resources[0].end) ||
  213. (cf_ide_resources[1].start <= addr &&
  214. addr <= cf_ide_resources[1].end));
  215. }
  216. void rts7751r2d_writeb(u8 b, void __iomem *addr)
  217. {
  218. unsigned long tmp = (unsigned long __force)addr;
  219. if (is_ide_ioaddr(tmp))
  220. ctrl_outw((u16)b, tmp);
  221. else
  222. ctrl_outb(b, tmp);
  223. }
  224. u8 rts7751r2d_readb(void __iomem *addr)
  225. {
  226. unsigned long tmp = (unsigned long __force)addr;
  227. if (is_ide_ioaddr(tmp))
  228. return ctrl_inw(tmp) & 0xff;
  229. else
  230. return ctrl_inb(tmp);
  231. }
  232. /*
  233. * Initialize the board
  234. */
  235. static void __init rts7751r2d_setup(char **cmdline_p)
  236. {
  237. void __iomem *sm501_reg;
  238. u16 ver = ctrl_inw(PA_VERREG);
  239. printk(KERN_INFO "Renesas Technology Sales RTS7751R2D support.\n");
  240. printk(KERN_INFO "FPGA version:%d (revision:%d)\n",
  241. (ver >> 4) & 0xf, ver & 0xf);
  242. ctrl_outw(0x0000, PA_OUTPORT);
  243. pm_power_off = rts7751r2d_power_off;
  244. /* sm501 dram configuration:
  245. * ColSizeX = 11 - External Memory Column Size: 256 words.
  246. * APX = 1 - External Memory Active to Pre-Charge Delay: 7 clocks.
  247. * RstX = 1 - External Memory Reset: Normal.
  248. * Rfsh = 1 - Local Memory Refresh to Command Delay: 12 clocks.
  249. * BwC = 1 - Local Memory Block Write Cycle Time: 2 clocks.
  250. * BwP = 1 - Local Memory Block Write to Pre-Charge Delay: 1 clock.
  251. * AP = 1 - Internal Memory Active to Pre-Charge Delay: 7 clocks.
  252. * Rst = 1 - Internal Memory Reset: Normal.
  253. * RA = 1 - Internal Memory Remain in Active State: Do not remain.
  254. */
  255. sm501_reg = (void __iomem *)0xb3e00000 + SM501_DRAM_CONTROL;
  256. writel(readl(sm501_reg) | 0x00f107c0, sm501_reg);
  257. /*
  258. * Power Mode Gate - Enable UART0
  259. */
  260. sm501_reg = (void __iomem *)0xb3e00000 + SM501_POWER_MODE_0_GATE;
  261. writel(readl(sm501_reg) | (1 << SM501_GATE_UART0), sm501_reg);
  262. sm501_reg = (void __iomem *)0xb3e00000 + SM501_POWER_MODE_1_GATE;
  263. writel(readl(sm501_reg) | (1 << SM501_GATE_UART0), sm501_reg);
  264. }
  265. /*
  266. * The Machine Vector
  267. */
  268. static struct sh_machine_vector mv_rts7751r2d __initmv = {
  269. .mv_name = "RTS7751R2D",
  270. .mv_setup = rts7751r2d_setup,
  271. .mv_init_irq = init_rts7751r2d_IRQ,
  272. .mv_irq_demux = rts7751r2d_irq_demux,
  273. .mv_writeb = rts7751r2d_writeb,
  274. .mv_readb = rts7751r2d_readb,
  275. };