malta-setup.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Carsten Langgaard, [email protected]
  4. * Copyright (C) 2000 MIPS Technologies, Inc. All rights reserved.
  5. * Copyright (C) 2008 Dmitri Vorobiev
  6. */
  7. #include <linux/cpu.h>
  8. #include <linux/init.h>
  9. #include <linux/sched.h>
  10. #include <linux/ioport.h>
  11. #include <linux/irq.h>
  12. #include <linux/of_fdt.h>
  13. #include <linux/pci.h>
  14. #include <linux/screen_info.h>
  15. #include <linux/time.h>
  16. #include <linux/dma-map-ops.h> /* for dma_default_coherent */
  17. #include <asm/fw/fw.h>
  18. #include <asm/mips-cps.h>
  19. #include <asm/mips-boards/generic.h>
  20. #include <asm/mips-boards/malta.h>
  21. #include <asm/mips-boards/maltaint.h>
  22. #include <asm/dma.h>
  23. #include <asm/prom.h>
  24. #include <asm/traps.h>
  25. #ifdef CONFIG_VT
  26. #include <linux/console.h>
  27. #endif
  28. #define ROCIT_CONFIG_GEN0 0x1f403000
  29. #define ROCIT_CONFIG_GEN0_PCI_IOCU BIT(7)
  30. static struct resource standard_io_resources[] = {
  31. {
  32. .name = "dma1",
  33. .start = 0x00,
  34. .end = 0x1f,
  35. .flags = IORESOURCE_IO | IORESOURCE_BUSY
  36. },
  37. {
  38. .name = "timer",
  39. .start = 0x40,
  40. .end = 0x5f,
  41. .flags = IORESOURCE_IO | IORESOURCE_BUSY
  42. },
  43. {
  44. .name = "keyboard",
  45. .start = 0x60,
  46. .end = 0x6f,
  47. .flags = IORESOURCE_IO | IORESOURCE_BUSY
  48. },
  49. {
  50. .name = "dma page reg",
  51. .start = 0x80,
  52. .end = 0x8f,
  53. .flags = IORESOURCE_IO | IORESOURCE_BUSY
  54. },
  55. {
  56. .name = "dma2",
  57. .start = 0xc0,
  58. .end = 0xdf,
  59. .flags = IORESOURCE_IO | IORESOURCE_BUSY
  60. },
  61. };
  62. const char *get_system_type(void)
  63. {
  64. return "MIPS Malta";
  65. }
  66. #ifdef CONFIG_BLK_DEV_FD
  67. static void __init fd_activate(void)
  68. {
  69. /*
  70. * Activate Floppy Controller in the SMSC FDC37M817 Super I/O
  71. * Controller.
  72. * Done by YAMON 2.00 onwards
  73. */
  74. /* Entering config state. */
  75. SMSC_WRITE(SMSC_CONFIG_ENTER, SMSC_CONFIG_REG);
  76. /* Activate floppy controller. */
  77. SMSC_WRITE(SMSC_CONFIG_DEVNUM, SMSC_CONFIG_REG);
  78. SMSC_WRITE(SMSC_CONFIG_DEVNUM_FLOPPY, SMSC_DATA_REG);
  79. SMSC_WRITE(SMSC_CONFIG_ACTIVATE, SMSC_CONFIG_REG);
  80. SMSC_WRITE(SMSC_CONFIG_ACTIVATE_ENABLE, SMSC_DATA_REG);
  81. /* Exit config state. */
  82. SMSC_WRITE(SMSC_CONFIG_EXIT, SMSC_CONFIG_REG);
  83. }
  84. #endif
  85. static void __init plat_setup_iocoherency(void)
  86. {
  87. u32 cfg;
  88. if (mips_revision_sconid == MIPS_REVISION_SCON_BONITO) {
  89. if (BONITO_PCICACHECTRL & BONITO_PCICACHECTRL_CPUCOH_PRES) {
  90. BONITO_PCICACHECTRL |= BONITO_PCICACHECTRL_CPUCOH_EN;
  91. pr_info("Enabled Bonito CPU coherency\n");
  92. dma_default_coherent = true;
  93. }
  94. if (strstr(fw_getcmdline(), "iobcuncached")) {
  95. BONITO_PCICACHECTRL &= ~BONITO_PCICACHECTRL_IOBCCOH_EN;
  96. BONITO_PCIMEMBASECFG = BONITO_PCIMEMBASECFG &
  97. ~(BONITO_PCIMEMBASECFG_MEMBASE0_CACHED |
  98. BONITO_PCIMEMBASECFG_MEMBASE1_CACHED);
  99. pr_info("Disabled Bonito IOBC coherency\n");
  100. } else {
  101. BONITO_PCICACHECTRL |= BONITO_PCICACHECTRL_IOBCCOH_EN;
  102. BONITO_PCIMEMBASECFG |=
  103. (BONITO_PCIMEMBASECFG_MEMBASE0_CACHED |
  104. BONITO_PCIMEMBASECFG_MEMBASE1_CACHED);
  105. pr_info("Enabled Bonito IOBC coherency\n");
  106. }
  107. } else if (mips_cps_numiocu(0) != 0) {
  108. /* Nothing special needs to be done to enable coherency */
  109. pr_info("CMP IOCU detected\n");
  110. cfg = __raw_readl((u32 *)CKSEG1ADDR(ROCIT_CONFIG_GEN0));
  111. if (cfg & ROCIT_CONFIG_GEN0_PCI_IOCU)
  112. dma_default_coherent = true;
  113. else
  114. pr_crit("IOCU OPERATION DISABLED BY SWITCH - DEFAULTING TO SW IO COHERENCY\n");
  115. }
  116. if (dma_default_coherent)
  117. pr_info("Hardware DMA cache coherency enabled\n");
  118. else
  119. pr_info("Software DMA cache coherency enabled\n");
  120. }
  121. static void __init pci_clock_check(void)
  122. {
  123. unsigned int __iomem *jmpr_p =
  124. (unsigned int *) ioremap(MALTA_JMPRS_REG, sizeof(unsigned int));
  125. int jmpr = (__raw_readl(jmpr_p) >> 2) & 0x07;
  126. static const int pciclocks[] __initconst = {
  127. 33, 20, 25, 30, 12, 16, 37, 10
  128. };
  129. int pciclock = pciclocks[jmpr];
  130. char *optptr, *argptr = fw_getcmdline();
  131. /*
  132. * If user passed a pci_clock= option, don't tack on another one
  133. */
  134. optptr = strstr(argptr, "pci_clock=");
  135. if (optptr && (optptr == argptr || optptr[-1] == ' '))
  136. return;
  137. if (pciclock != 33) {
  138. pr_warn("WARNING: PCI clock is %dMHz, setting pci_clock\n",
  139. pciclock);
  140. argptr += strlen(argptr);
  141. sprintf(argptr, " pci_clock=%d", pciclock);
  142. if (pciclock < 20 || pciclock > 66)
  143. pr_warn("WARNING: IDE timing calculations will be "
  144. "incorrect\n");
  145. }
  146. }
  147. #if defined(CONFIG_VT) && defined(CONFIG_VGA_CONSOLE)
  148. static void __init screen_info_setup(void)
  149. {
  150. screen_info = (struct screen_info) {
  151. .orig_x = 0,
  152. .orig_y = 25,
  153. .ext_mem_k = 0,
  154. .orig_video_page = 0,
  155. .orig_video_mode = 0,
  156. .orig_video_cols = 80,
  157. .unused2 = 0,
  158. .orig_video_ega_bx = 0,
  159. .unused3 = 0,
  160. .orig_video_lines = 25,
  161. .orig_video_isVGA = VIDEO_TYPE_VGAC,
  162. .orig_video_points = 16
  163. };
  164. }
  165. #endif
  166. static void __init bonito_quirks_setup(void)
  167. {
  168. char *argptr;
  169. argptr = fw_getcmdline();
  170. if (strstr(argptr, "debug")) {
  171. BONITO_BONGENCFG |= BONITO_BONGENCFG_DEBUGMODE;
  172. pr_info("Enabled Bonito debug mode\n");
  173. } else
  174. BONITO_BONGENCFG &= ~BONITO_BONGENCFG_DEBUGMODE;
  175. }
  176. void __init *plat_get_fdt(void)
  177. {
  178. return (void *)__dtb_start;
  179. }
  180. void __init plat_mem_setup(void)
  181. {
  182. unsigned int i;
  183. void *fdt = plat_get_fdt();
  184. fdt = malta_dt_shim(fdt);
  185. __dt_setup_arch(fdt);
  186. if (IS_ENABLED(CONFIG_EVA))
  187. /* EVA has already been configured in mach-malta/kernel-init.h */
  188. pr_info("Enhanced Virtual Addressing (EVA) activated\n");
  189. mips_pcibios_init();
  190. /* Request I/O space for devices used on the Malta board. */
  191. for (i = 0; i < ARRAY_SIZE(standard_io_resources); i++)
  192. request_resource(&ioport_resource, standard_io_resources+i);
  193. /*
  194. * Enable DMA channel 4 (cascade channel) in the PIIX4 south bridge.
  195. */
  196. enable_dma(4);
  197. if (mips_revision_sconid == MIPS_REVISION_SCON_BONITO)
  198. bonito_quirks_setup();
  199. plat_setup_iocoherency();
  200. pci_clock_check();
  201. #ifdef CONFIG_BLK_DEV_FD
  202. fd_activate();
  203. #endif
  204. #if defined(CONFIG_VT) && defined(CONFIG_VGA_CONSOLE)
  205. screen_info_setup();
  206. #endif
  207. }