malta-setup.c 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. /*
  2. * Carsten Langgaard, carstenl@mips.com
  3. * Copyright (C) 2000 MIPS Technologies, Inc. All rights reserved.
  4. * Copyright (C) 2008 Dmitri Vorobiev
  5. *
  6. * This program is free software; you can distribute it and/or modify it
  7. * under the terms of the GNU General Public License (Version 2) as
  8. * published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  13. * for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program; if not, write to the Free Software Foundation, Inc.,
  17. * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
  18. */
  19. #include <linux/cpu.h>
  20. #include <linux/init.h>
  21. #include <linux/sched.h>
  22. #include <linux/ioport.h>
  23. #include <linux/irq.h>
  24. #include <linux/of_fdt.h>
  25. #include <linux/pci.h>
  26. #include <linux/screen_info.h>
  27. #include <linux/time.h>
  28. #include <asm/fw/fw.h>
  29. #include <asm/mach-malta/malta-dtshim.h>
  30. #include <asm/mips-cm.h>
  31. #include <asm/mips-boards/generic.h>
  32. #include <asm/mips-boards/malta.h>
  33. #include <asm/mips-boards/maltaint.h>
  34. #include <asm/dma.h>
  35. #include <asm/prom.h>
  36. #include <asm/traps.h>
  37. #ifdef CONFIG_VT
  38. #include <linux/console.h>
  39. #endif
  40. #define ROCIT_CONFIG_GEN0 0x1f403000
  41. #define ROCIT_CONFIG_GEN0_PCI_IOCU BIT(7)
  42. static struct resource standard_io_resources[] = {
  43. {
  44. .name = "dma1",
  45. .start = 0x00,
  46. .end = 0x1f,
  47. .flags = IORESOURCE_BUSY
  48. },
  49. {
  50. .name = "timer",
  51. .start = 0x40,
  52. .end = 0x5f,
  53. .flags = IORESOURCE_BUSY
  54. },
  55. {
  56. .name = "keyboard",
  57. .start = 0x60,
  58. .end = 0x6f,
  59. .flags = IORESOURCE_BUSY
  60. },
  61. {
  62. .name = "dma page reg",
  63. .start = 0x80,
  64. .end = 0x8f,
  65. .flags = IORESOURCE_BUSY
  66. },
  67. {
  68. .name = "dma2",
  69. .start = 0xc0,
  70. .end = 0xdf,
  71. .flags = IORESOURCE_BUSY
  72. },
  73. };
  74. const char *get_system_type(void)
  75. {
  76. return "MIPS Malta";
  77. }
  78. const char display_string[] = " LINUX ON MALTA ";
  79. #ifdef CONFIG_BLK_DEV_FD
  80. static void __init fd_activate(void)
  81. {
  82. /*
  83. * Activate Floppy Controller in the SMSC FDC37M817 Super I/O
  84. * Controller.
  85. * Done by YAMON 2.00 onwards
  86. */
  87. /* Entering config state. */
  88. SMSC_WRITE(SMSC_CONFIG_ENTER, SMSC_CONFIG_REG);
  89. /* Activate floppy controller. */
  90. SMSC_WRITE(SMSC_CONFIG_DEVNUM, SMSC_CONFIG_REG);
  91. SMSC_WRITE(SMSC_CONFIG_DEVNUM_FLOPPY, SMSC_DATA_REG);
  92. SMSC_WRITE(SMSC_CONFIG_ACTIVATE, SMSC_CONFIG_REG);
  93. SMSC_WRITE(SMSC_CONFIG_ACTIVATE_ENABLE, SMSC_DATA_REG);
  94. /* Exit config state. */
  95. SMSC_WRITE(SMSC_CONFIG_EXIT, SMSC_CONFIG_REG);
  96. }
  97. #endif
  98. static int __init plat_enable_iocoherency(void)
  99. {
  100. int supported = 0;
  101. u32 cfg;
  102. if (mips_revision_sconid == MIPS_REVISION_SCON_BONITO) {
  103. if (BONITO_PCICACHECTRL & BONITO_PCICACHECTRL_CPUCOH_PRES) {
  104. BONITO_PCICACHECTRL |= BONITO_PCICACHECTRL_CPUCOH_EN;
  105. pr_info("Enabled Bonito CPU coherency\n");
  106. supported = 1;
  107. }
  108. if (strstr(fw_getcmdline(), "iobcuncached")) {
  109. BONITO_PCICACHECTRL &= ~BONITO_PCICACHECTRL_IOBCCOH_EN;
  110. BONITO_PCIMEMBASECFG = BONITO_PCIMEMBASECFG &
  111. ~(BONITO_PCIMEMBASECFG_MEMBASE0_CACHED |
  112. BONITO_PCIMEMBASECFG_MEMBASE1_CACHED);
  113. pr_info("Disabled Bonito IOBC coherency\n");
  114. } else {
  115. BONITO_PCICACHECTRL |= BONITO_PCICACHECTRL_IOBCCOH_EN;
  116. BONITO_PCIMEMBASECFG |=
  117. (BONITO_PCIMEMBASECFG_MEMBASE0_CACHED |
  118. BONITO_PCIMEMBASECFG_MEMBASE1_CACHED);
  119. pr_info("Enabled Bonito IOBC coherency\n");
  120. }
  121. } else if (mips_cm_numiocu() != 0) {
  122. /* Nothing special needs to be done to enable coherency */
  123. pr_info("CMP IOCU detected\n");
  124. cfg = __raw_readl((u32 *)CKSEG1ADDR(ROCIT_CONFIG_GEN0));
  125. if (!(cfg & ROCIT_CONFIG_GEN0_PCI_IOCU)) {
  126. pr_crit("IOCU OPERATION DISABLED BY SWITCH - DEFAULTING TO SW IO COHERENCY\n");
  127. return 0;
  128. }
  129. supported = 1;
  130. }
  131. hw_coherentio = supported;
  132. return supported;
  133. }
  134. static void __init plat_setup_iocoherency(void)
  135. {
  136. #ifdef CONFIG_DMA_NONCOHERENT
  137. /*
  138. * Kernel has been configured with software coherency
  139. * but we might choose to turn it off and use hardware
  140. * coherency instead.
  141. */
  142. if (plat_enable_iocoherency()) {
  143. if (coherentio == IO_COHERENCE_DISABLED)
  144. pr_info("Hardware DMA cache coherency disabled\n");
  145. else
  146. pr_info("Hardware DMA cache coherency enabled\n");
  147. } else {
  148. if (coherentio == IO_COHERENCE_ENABLED)
  149. pr_info("Hardware DMA cache coherency unsupported, but enabled from command line!\n");
  150. else
  151. pr_info("Software DMA cache coherency enabled\n");
  152. }
  153. #else
  154. if (!plat_enable_iocoherency())
  155. panic("Hardware DMA cache coherency not supported!");
  156. #endif
  157. }
  158. static void __init pci_clock_check(void)
  159. {
  160. unsigned int __iomem *jmpr_p =
  161. (unsigned int *) ioremap(MALTA_JMPRS_REG, sizeof(unsigned int));
  162. int jmpr = (__raw_readl(jmpr_p) >> 2) & 0x07;
  163. static const int pciclocks[] __initconst = {
  164. 33, 20, 25, 30, 12, 16, 37, 10
  165. };
  166. int pciclock = pciclocks[jmpr];
  167. char *optptr, *argptr = fw_getcmdline();
  168. /*
  169. * If user passed a pci_clock= option, don't tack on another one
  170. */
  171. optptr = strstr(argptr, "pci_clock=");
  172. if (optptr && (optptr == argptr || optptr[-1] == ' '))
  173. return;
  174. if (pciclock != 33) {
  175. pr_warn("WARNING: PCI clock is %dMHz, setting pci_clock\n",
  176. pciclock);
  177. argptr += strlen(argptr);
  178. sprintf(argptr, " pci_clock=%d", pciclock);
  179. if (pciclock < 20 || pciclock > 66)
  180. pr_warn("WARNING: IDE timing calculations will be "
  181. "incorrect\n");
  182. }
  183. }
  184. #if defined(CONFIG_VT) && defined(CONFIG_VGA_CONSOLE)
  185. static void __init screen_info_setup(void)
  186. {
  187. screen_info = (struct screen_info) {
  188. .orig_x = 0,
  189. .orig_y = 25,
  190. .ext_mem_k = 0,
  191. .orig_video_page = 0,
  192. .orig_video_mode = 0,
  193. .orig_video_cols = 80,
  194. .unused2 = 0,
  195. .orig_video_ega_bx = 0,
  196. .unused3 = 0,
  197. .orig_video_lines = 25,
  198. .orig_video_isVGA = VIDEO_TYPE_VGAC,
  199. .orig_video_points = 16
  200. };
  201. }
  202. #endif
  203. static void __init bonito_quirks_setup(void)
  204. {
  205. char *argptr;
  206. argptr = fw_getcmdline();
  207. if (strstr(argptr, "debug")) {
  208. BONITO_BONGENCFG |= BONITO_BONGENCFG_DEBUGMODE;
  209. pr_info("Enabled Bonito debug mode\n");
  210. } else
  211. BONITO_BONGENCFG &= ~BONITO_BONGENCFG_DEBUGMODE;
  212. #ifdef CONFIG_DMA_COHERENT
  213. if (BONITO_PCICACHECTRL & BONITO_PCICACHECTRL_CPUCOH_PRES) {
  214. BONITO_PCICACHECTRL |= BONITO_PCICACHECTRL_CPUCOH_EN;
  215. pr_info("Enabled Bonito CPU coherency\n");
  216. argptr = fw_getcmdline();
  217. if (strstr(argptr, "iobcuncached")) {
  218. BONITO_PCICACHECTRL &= ~BONITO_PCICACHECTRL_IOBCCOH_EN;
  219. BONITO_PCIMEMBASECFG = BONITO_PCIMEMBASECFG &
  220. ~(BONITO_PCIMEMBASECFG_MEMBASE0_CACHED |
  221. BONITO_PCIMEMBASECFG_MEMBASE1_CACHED);
  222. pr_info("Disabled Bonito IOBC coherency\n");
  223. } else {
  224. BONITO_PCICACHECTRL |= BONITO_PCICACHECTRL_IOBCCOH_EN;
  225. BONITO_PCIMEMBASECFG |=
  226. (BONITO_PCIMEMBASECFG_MEMBASE0_CACHED |
  227. BONITO_PCIMEMBASECFG_MEMBASE1_CACHED);
  228. pr_info("Enabled Bonito IOBC coherency\n");
  229. }
  230. } else
  231. panic("Hardware DMA cache coherency not supported");
  232. #endif
  233. }
  234. void __init *plat_get_fdt(void)
  235. {
  236. return (void *)__dtb_start;
  237. }
  238. void __init plat_mem_setup(void)
  239. {
  240. unsigned int i;
  241. void *fdt = plat_get_fdt();
  242. fdt = malta_dt_shim(fdt);
  243. __dt_setup_arch(fdt);
  244. if (IS_ENABLED(CONFIG_EVA))
  245. /* EVA has already been configured in mach-malta/kernel-init.h */
  246. pr_info("Enhanced Virtual Addressing (EVA) activated\n");
  247. mips_pcibios_init();
  248. /* Request I/O space for devices used on the Malta board. */
  249. for (i = 0; i < ARRAY_SIZE(standard_io_resources); i++)
  250. request_resource(&ioport_resource, standard_io_resources+i);
  251. /*
  252. * Enable DMA channel 4 (cascade channel) in the PIIX4 south bridge.
  253. */
  254. enable_dma(4);
  255. #ifdef CONFIG_DMA_COHERENT
  256. if (mips_revision_sconid != MIPS_REVISION_SCON_BONITO)
  257. panic("Hardware DMA cache coherency not supported");
  258. #endif
  259. if (mips_revision_sconid == MIPS_REVISION_SCON_BONITO)
  260. bonito_quirks_setup();
  261. plat_setup_iocoherency();
  262. pci_clock_check();
  263. #ifdef CONFIG_BLK_DEV_FD
  264. fd_activate();
  265. #endif
  266. #if defined(CONFIG_VT) && defined(CONFIG_VGA_CONSOLE)
  267. screen_info_setup();
  268. #endif
  269. }