malta-setup.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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/pci.h>
  25. #include <linux/screen_info.h>
  26. #include <linux/time.h>
  27. #include <asm/fw/fw.h>
  28. #include <asm/mips-cm.h>
  29. #include <asm/mips-boards/generic.h>
  30. #include <asm/mips-boards/malta.h>
  31. #include <asm/mips-boards/maltaint.h>
  32. #include <asm/dma.h>
  33. #include <asm/traps.h>
  34. #ifdef CONFIG_VT
  35. #include <linux/console.h>
  36. #endif
  37. extern void malta_be_init(void);
  38. extern int malta_be_handler(struct pt_regs *regs, int is_fixup);
  39. static struct resource standard_io_resources[] = {
  40. {
  41. .name = "dma1",
  42. .start = 0x00,
  43. .end = 0x1f,
  44. .flags = IORESOURCE_BUSY
  45. },
  46. {
  47. .name = "timer",
  48. .start = 0x40,
  49. .end = 0x5f,
  50. .flags = IORESOURCE_BUSY
  51. },
  52. {
  53. .name = "keyboard",
  54. .start = 0x60,
  55. .end = 0x6f,
  56. .flags = IORESOURCE_BUSY
  57. },
  58. {
  59. .name = "dma page reg",
  60. .start = 0x80,
  61. .end = 0x8f,
  62. .flags = IORESOURCE_BUSY
  63. },
  64. {
  65. .name = "dma2",
  66. .start = 0xc0,
  67. .end = 0xdf,
  68. .flags = IORESOURCE_BUSY
  69. },
  70. };
  71. const char *get_system_type(void)
  72. {
  73. return "MIPS Malta";
  74. }
  75. const char display_string[] = " LINUX ON MALTA ";
  76. #ifdef CONFIG_BLK_DEV_FD
  77. static void __init fd_activate(void)
  78. {
  79. /*
  80. * Activate Floppy Controller in the SMSC FDC37M817 Super I/O
  81. * Controller.
  82. * Done by YAMON 2.00 onwards
  83. */
  84. /* Entering config state. */
  85. SMSC_WRITE(SMSC_CONFIG_ENTER, SMSC_CONFIG_REG);
  86. /* Activate floppy controller. */
  87. SMSC_WRITE(SMSC_CONFIG_DEVNUM, SMSC_CONFIG_REG);
  88. SMSC_WRITE(SMSC_CONFIG_DEVNUM_FLOPPY, SMSC_DATA_REG);
  89. SMSC_WRITE(SMSC_CONFIG_ACTIVATE, SMSC_CONFIG_REG);
  90. SMSC_WRITE(SMSC_CONFIG_ACTIVATE_ENABLE, SMSC_DATA_REG);
  91. /* Exit config state. */
  92. SMSC_WRITE(SMSC_CONFIG_EXIT, SMSC_CONFIG_REG);
  93. }
  94. #endif
  95. static int __init plat_enable_iocoherency(void)
  96. {
  97. int supported = 0;
  98. if (mips_revision_sconid == MIPS_REVISION_SCON_BONITO) {
  99. if (BONITO_PCICACHECTRL & BONITO_PCICACHECTRL_CPUCOH_PRES) {
  100. BONITO_PCICACHECTRL |= BONITO_PCICACHECTRL_CPUCOH_EN;
  101. pr_info("Enabled Bonito CPU coherency\n");
  102. supported = 1;
  103. }
  104. if (strstr(fw_getcmdline(), "iobcuncached")) {
  105. BONITO_PCICACHECTRL &= ~BONITO_PCICACHECTRL_IOBCCOH_EN;
  106. BONITO_PCIMEMBASECFG = BONITO_PCIMEMBASECFG &
  107. ~(BONITO_PCIMEMBASECFG_MEMBASE0_CACHED |
  108. BONITO_PCIMEMBASECFG_MEMBASE1_CACHED);
  109. pr_info("Disabled Bonito IOBC coherency\n");
  110. } else {
  111. BONITO_PCICACHECTRL |= BONITO_PCICACHECTRL_IOBCCOH_EN;
  112. BONITO_PCIMEMBASECFG |=
  113. (BONITO_PCIMEMBASECFG_MEMBASE0_CACHED |
  114. BONITO_PCIMEMBASECFG_MEMBASE1_CACHED);
  115. pr_info("Enabled Bonito IOBC coherency\n");
  116. }
  117. } else if (mips_cm_numiocu() != 0) {
  118. /* Nothing special needs to be done to enable coherency */
  119. pr_info("CMP IOCU detected\n");
  120. if ((*(unsigned int *)0xbf403000 & 0x81) != 0x81) {
  121. pr_crit("IOCU OPERATION DISABLED BY SWITCH - DEFAULTING TO SW IO COHERENCY\n");
  122. return 0;
  123. }
  124. supported = 1;
  125. }
  126. hw_coherentio = supported;
  127. return supported;
  128. }
  129. static void __init plat_setup_iocoherency(void)
  130. {
  131. #ifdef CONFIG_DMA_NONCOHERENT
  132. /*
  133. * Kernel has been configured with software coherency
  134. * but we might choose to turn it off and use hardware
  135. * coherency instead.
  136. */
  137. if (plat_enable_iocoherency()) {
  138. if (coherentio == 0)
  139. pr_info("Hardware DMA cache coherency disabled\n");
  140. else
  141. pr_info("Hardware DMA cache coherency enabled\n");
  142. } else {
  143. if (coherentio == 1)
  144. pr_info("Hardware DMA cache coherency unsupported, but enabled from command line!\n");
  145. else
  146. pr_info("Software DMA cache coherency enabled\n");
  147. }
  148. #else
  149. if (!plat_enable_iocoherency())
  150. panic("Hardware DMA cache coherency not supported!");
  151. #endif
  152. }
  153. static void __init pci_clock_check(void)
  154. {
  155. unsigned int __iomem *jmpr_p =
  156. (unsigned int *) ioremap(MALTA_JMPRS_REG, sizeof(unsigned int));
  157. int jmpr = (__raw_readl(jmpr_p) >> 2) & 0x07;
  158. static const int pciclocks[] __initconst = {
  159. 33, 20, 25, 30, 12, 16, 37, 10
  160. };
  161. int pciclock = pciclocks[jmpr];
  162. char *optptr, *argptr = fw_getcmdline();
  163. /*
  164. * If user passed a pci_clock= option, don't tack on another one
  165. */
  166. optptr = strstr(argptr, "pci_clock=");
  167. if (optptr && (optptr == argptr || optptr[-1] == ' '))
  168. return;
  169. if (pciclock != 33) {
  170. pr_warn("WARNING: PCI clock is %dMHz, setting pci_clock\n",
  171. pciclock);
  172. argptr += strlen(argptr);
  173. sprintf(argptr, " pci_clock=%d", pciclock);
  174. if (pciclock < 20 || pciclock > 66)
  175. pr_warn("WARNING: IDE timing calculations will be "
  176. "incorrect\n");
  177. }
  178. }
  179. #if defined(CONFIG_VT) && defined(CONFIG_VGA_CONSOLE)
  180. static void __init screen_info_setup(void)
  181. {
  182. screen_info = (struct screen_info) {
  183. .orig_x = 0,
  184. .orig_y = 25,
  185. .ext_mem_k = 0,
  186. .orig_video_page = 0,
  187. .orig_video_mode = 0,
  188. .orig_video_cols = 80,
  189. .unused2 = 0,
  190. .orig_video_ega_bx = 0,
  191. .unused3 = 0,
  192. .orig_video_lines = 25,
  193. .orig_video_isVGA = VIDEO_TYPE_VGAC,
  194. .orig_video_points = 16
  195. };
  196. }
  197. #endif
  198. static void __init bonito_quirks_setup(void)
  199. {
  200. char *argptr;
  201. argptr = fw_getcmdline();
  202. if (strstr(argptr, "debug")) {
  203. BONITO_BONGENCFG |= BONITO_BONGENCFG_DEBUGMODE;
  204. pr_info("Enabled Bonito debug mode\n");
  205. } else
  206. BONITO_BONGENCFG &= ~BONITO_BONGENCFG_DEBUGMODE;
  207. #ifdef CONFIG_DMA_COHERENT
  208. if (BONITO_PCICACHECTRL & BONITO_PCICACHECTRL_CPUCOH_PRES) {
  209. BONITO_PCICACHECTRL |= BONITO_PCICACHECTRL_CPUCOH_EN;
  210. pr_info("Enabled Bonito CPU coherency\n");
  211. argptr = fw_getcmdline();
  212. if (strstr(argptr, "iobcuncached")) {
  213. BONITO_PCICACHECTRL &= ~BONITO_PCICACHECTRL_IOBCCOH_EN;
  214. BONITO_PCIMEMBASECFG = BONITO_PCIMEMBASECFG &
  215. ~(BONITO_PCIMEMBASECFG_MEMBASE0_CACHED |
  216. BONITO_PCIMEMBASECFG_MEMBASE1_CACHED);
  217. pr_info("Disabled Bonito IOBC coherency\n");
  218. } else {
  219. BONITO_PCICACHECTRL |= BONITO_PCICACHECTRL_IOBCCOH_EN;
  220. BONITO_PCIMEMBASECFG |=
  221. (BONITO_PCIMEMBASECFG_MEMBASE0_CACHED |
  222. BONITO_PCIMEMBASECFG_MEMBASE1_CACHED);
  223. pr_info("Enabled Bonito IOBC coherency\n");
  224. }
  225. } else
  226. panic("Hardware DMA cache coherency not supported");
  227. #endif
  228. }
  229. void __init plat_mem_setup(void)
  230. {
  231. unsigned int i;
  232. if (config_enabled(CONFIG_EVA))
  233. /* EVA has already been configured in mach-malta/kernel-init.h */
  234. pr_info("Enhanced Virtual Addressing (EVA) activated\n");
  235. mips_pcibios_init();
  236. /* Request I/O space for devices used on the Malta board. */
  237. for (i = 0; i < ARRAY_SIZE(standard_io_resources); i++)
  238. request_resource(&ioport_resource, standard_io_resources+i);
  239. /*
  240. * Enable DMA channel 4 (cascade channel) in the PIIX4 south bridge.
  241. */
  242. enable_dma(4);
  243. #ifdef CONFIG_DMA_COHERENT
  244. if (mips_revision_sconid != MIPS_REVISION_SCON_BONITO)
  245. panic("Hardware DMA cache coherency not supported");
  246. #endif
  247. if (mips_revision_sconid == MIPS_REVISION_SCON_BONITO)
  248. bonito_quirks_setup();
  249. plat_setup_iocoherency();
  250. pci_clock_check();
  251. #ifdef CONFIG_BLK_DEV_FD
  252. fd_activate();
  253. #endif
  254. #if defined(CONFIG_VT) && defined(CONFIG_VGA_CONSOLE)
  255. screen_info_setup();
  256. #endif
  257. board_be_init = malta_be_init;
  258. board_be_handler = malta_be_handler;
  259. }