cpu.c 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2009
  4. * Marvell Semiconductor <www.marvell.com>
  5. * Written-by: Prafulla Wadaskar <prafulla@marvell.com>
  6. */
  7. #include <common.h>
  8. #include <netdev.h>
  9. #include <asm/cache.h>
  10. #include <asm/io.h>
  11. #include <asm/arch/cpu.h>
  12. #include <asm/arch/soc.h>
  13. #include <mvebu_mmc.h>
  14. void reset_cpu(unsigned long ignored)
  15. {
  16. struct kwcpu_registers *cpureg =
  17. (struct kwcpu_registers *)KW_CPU_REG_BASE;
  18. writel(readl(&cpureg->rstoutn_mask) | (1 << 2),
  19. &cpureg->rstoutn_mask);
  20. writel(readl(&cpureg->sys_soft_rst) | 1,
  21. &cpureg->sys_soft_rst);
  22. while (1) ;
  23. }
  24. /*
  25. * Window Size
  26. * Used with the Base register to set the address window size and location.
  27. * Must be programmed from LSB to MSB as sequence of ones followed by
  28. * sequence of zeros. The number of ones specifies the size of the window in
  29. * 64 KByte granularity (e.g., a value of 0x00FF specifies 256 = 16 MByte).
  30. * NOTE: A value of 0x0 specifies 64-KByte size.
  31. */
  32. unsigned int kw_winctrl_calcsize(unsigned int sizeval)
  33. {
  34. int i;
  35. unsigned int j = 0;
  36. u32 val = sizeval >> 1;
  37. for (i = 0; val >= 0x10000; i++) {
  38. j |= (1 << i);
  39. val = val >> 1;
  40. }
  41. return (0x0000ffff & j);
  42. }
  43. /*
  44. * kw_config_adr_windows - Configure address Windows
  45. *
  46. * There are 8 address windows supported by Kirkwood Soc to addess different
  47. * devices. Each window can be configured for size, BAR and remap addr
  48. * Below configuration is standard for most of the cases
  49. *
  50. * If remap function not used, remap_lo must be set as base
  51. *
  52. * Reference Documentation:
  53. * Mbus-L to Mbus Bridge Registers Configuration.
  54. * (Sec 25.1 and 25.3 of Datasheet)
  55. */
  56. int kw_config_adr_windows(void)
  57. {
  58. struct kwwin_registers *winregs =
  59. (struct kwwin_registers *)KW_CPU_WIN_BASE;
  60. /* Window 0: PCIE MEM address space */
  61. writel(KWCPU_WIN_CTRL_DATA(1024 * 1024 * 256, KWCPU_TARGET_PCIE,
  62. KWCPU_ATTR_PCIE_MEM, KWCPU_WIN_ENABLE), &winregs[0].ctrl);
  63. writel(KW_DEFADR_PCI_MEM, &winregs[0].base);
  64. writel(KW_DEFADR_PCI_MEM, &winregs[0].remap_lo);
  65. writel(0x0, &winregs[0].remap_hi);
  66. /* Window 1: PCIE IO address space */
  67. writel(KWCPU_WIN_CTRL_DATA(1024 * 64, KWCPU_TARGET_PCIE,
  68. KWCPU_ATTR_PCIE_IO, KWCPU_WIN_ENABLE), &winregs[1].ctrl);
  69. writel(KW_DEFADR_PCI_IO, &winregs[1].base);
  70. writel(KW_DEFADR_PCI_IO_REMAP, &winregs[1].remap_lo);
  71. writel(0x0, &winregs[1].remap_hi);
  72. /* Window 2: NAND Flash address space */
  73. writel(KWCPU_WIN_CTRL_DATA(1024 * 1024 * 128, KWCPU_TARGET_MEMORY,
  74. KWCPU_ATTR_NANDFLASH, KWCPU_WIN_ENABLE), &winregs[2].ctrl);
  75. writel(KW_DEFADR_NANDF, &winregs[2].base);
  76. writel(KW_DEFADR_NANDF, &winregs[2].remap_lo);
  77. writel(0x0, &winregs[2].remap_hi);
  78. /* Window 3: SPI Flash address space */
  79. writel(KWCPU_WIN_CTRL_DATA(1024 * 1024 * 128, KWCPU_TARGET_MEMORY,
  80. KWCPU_ATTR_SPIFLASH, KWCPU_WIN_ENABLE), &winregs[3].ctrl);
  81. writel(KW_DEFADR_SPIF, &winregs[3].base);
  82. writel(KW_DEFADR_SPIF, &winregs[3].remap_lo);
  83. writel(0x0, &winregs[3].remap_hi);
  84. /* Window 4: BOOT Memory address space */
  85. writel(KWCPU_WIN_CTRL_DATA(1024 * 1024 * 128, KWCPU_TARGET_MEMORY,
  86. KWCPU_ATTR_BOOTROM, KWCPU_WIN_ENABLE), &winregs[4].ctrl);
  87. writel(KW_DEFADR_BOOTROM, &winregs[4].base);
  88. /* Window 5: Security SRAM address space */
  89. writel(KWCPU_WIN_CTRL_DATA(1024 * 64, KWCPU_TARGET_SASRAM,
  90. KWCPU_ATTR_SASRAM, KWCPU_WIN_ENABLE), &winregs[5].ctrl);
  91. writel(KW_DEFADR_SASRAM, &winregs[5].base);
  92. /* Window 6-7: Disabled */
  93. writel(KWCPU_WIN_DISABLE, &winregs[6].ctrl);
  94. writel(KWCPU_WIN_DISABLE, &winregs[7].ctrl);
  95. return 0;
  96. }
  97. /*
  98. * SYSRSTn Duration Counter Support
  99. *
  100. * Kirkwood SoC implements a hardware-based SYSRSTn duration counter.
  101. * When SYSRSTn is asserted low, a SYSRSTn duration counter is running.
  102. * The SYSRSTn duration counter is useful for implementing a manufacturer
  103. * or factory reset. Upon a long reset assertion that is greater than a
  104. * pre-configured environment variable value for sysrstdelay,
  105. * The counter value is stored in the SYSRSTn Length Counter Register
  106. * The counter is based on the 25-MHz reference clock (40ns)
  107. * It is a 29-bit counter, yielding a maximum counting duration of
  108. * 2^29/25 MHz (21.4 seconds). When the counter reach its maximum value,
  109. * it remains at this value until counter reset is triggered by setting
  110. * bit 31 of KW_REG_SYSRST_CNT
  111. */
  112. static void kw_sysrst_action(void)
  113. {
  114. int ret;
  115. char *s = env_get("sysrstcmd");
  116. if (!s) {
  117. debug("Error.. %s failed, check sysrstcmd\n",
  118. __FUNCTION__);
  119. return;
  120. }
  121. debug("Starting %s process...\n", __FUNCTION__);
  122. ret = run_command(s, 0);
  123. if (ret != 0)
  124. debug("Error.. %s failed\n", __FUNCTION__);
  125. else
  126. debug("%s process finished\n", __FUNCTION__);
  127. }
  128. static void kw_sysrst_check(void)
  129. {
  130. u32 sysrst_cnt, sysrst_dly;
  131. char *s;
  132. /*
  133. * no action if sysrstdelay environment variable is not defined
  134. */
  135. s = env_get("sysrstdelay");
  136. if (s == NULL)
  137. return;
  138. /* read sysrstdelay value */
  139. sysrst_dly = (u32) simple_strtoul(s, NULL, 10);
  140. /* read SysRst Length counter register (bits 28:0) */
  141. sysrst_cnt = (0x1fffffff & readl(KW_REG_SYSRST_CNT));
  142. debug("H/w Rst hold time: %d.%d secs\n",
  143. sysrst_cnt / SYSRST_CNT_1SEC_VAL,
  144. sysrst_cnt % SYSRST_CNT_1SEC_VAL);
  145. /* clear the counter for next valid read*/
  146. writel(1 << 31, KW_REG_SYSRST_CNT);
  147. /*
  148. * sysrst_action:
  149. * if H/w Reset key is pressed and hold for time
  150. * more than sysrst_dly in seconds
  151. */
  152. if (sysrst_cnt >= SYSRST_CNT_1SEC_VAL * sysrst_dly)
  153. kw_sysrst_action();
  154. }
  155. #if defined(CONFIG_DISPLAY_CPUINFO)
  156. int print_cpuinfo(void)
  157. {
  158. char *rev = "??";
  159. u16 devid = (readl(KW_REG_PCIE_DEVID) >> 16) & 0xffff;
  160. u8 revid = readl(KW_REG_PCIE_REVID) & 0xff;
  161. if ((readl(KW_REG_DEVICE_ID) & 0x03) > 2) {
  162. printf("Error.. %s:Unsupported Kirkwood SoC 88F%04x\n", __FUNCTION__, devid);
  163. return -1;
  164. }
  165. switch (revid) {
  166. case 0:
  167. if (devid == 0x6281)
  168. rev = "Z0";
  169. else if (devid == 0x6282)
  170. rev = "A0";
  171. break;
  172. case 1:
  173. rev = "A1";
  174. break;
  175. case 2:
  176. rev = "A0";
  177. break;
  178. case 3:
  179. rev = "A1";
  180. break;
  181. default:
  182. break;
  183. }
  184. printf("SoC: Kirkwood 88F%04x_%s\n", devid, rev);
  185. return 0;
  186. }
  187. #endif /* CONFIG_DISPLAY_CPUINFO */
  188. #ifdef CONFIG_ARCH_CPU_INIT
  189. int arch_cpu_init(void)
  190. {
  191. u32 reg;
  192. struct kwcpu_registers *cpureg =
  193. (struct kwcpu_registers *)KW_CPU_REG_BASE;
  194. /* Linux expects` the internal registers to be at 0xf1000000 */
  195. writel(KW_REGS_PHY_BASE, KW_OFFSET_REG);
  196. /* Enable and invalidate L2 cache in write through mode */
  197. writel(readl(&cpureg->l2_cfg) | 0x18, &cpureg->l2_cfg);
  198. invalidate_l2_cache();
  199. kw_config_adr_windows();
  200. #ifdef CONFIG_KIRKWOOD_RGMII_PAD_1V8
  201. /*
  202. * Configures the I/O voltage of the pads connected to Egigabit
  203. * Ethernet interface to 1.8V
  204. * By default it is set to 3.3V
  205. */
  206. reg = readl(KW_REG_MPP_OUT_DRV_REG);
  207. reg |= (1 << 7);
  208. writel(reg, KW_REG_MPP_OUT_DRV_REG);
  209. #endif
  210. #ifdef CONFIG_KIRKWOOD_EGIGA_INIT
  211. /*
  212. * Set egiga port0/1 in normal functional mode
  213. * This is required becasue on kirkwood by default ports are in reset mode
  214. * OS egiga driver may not have provision to set them in normal mode
  215. * and if u-boot is build without network support, network may fail at OS level
  216. */
  217. reg = readl(KWGBE_PORT_SERIAL_CONTROL1_REG(0));
  218. reg &= ~(1 << 4); /* Clear PortReset Bit */
  219. writel(reg, (KWGBE_PORT_SERIAL_CONTROL1_REG(0)));
  220. reg = readl(KWGBE_PORT_SERIAL_CONTROL1_REG(1));
  221. reg &= ~(1 << 4); /* Clear PortReset Bit */
  222. writel(reg, (KWGBE_PORT_SERIAL_CONTROL1_REG(1)));
  223. #endif
  224. #ifdef CONFIG_KIRKWOOD_PCIE_INIT
  225. /*
  226. * Enable PCI Express Port0
  227. */
  228. reg = readl(&cpureg->ctrl_stat);
  229. reg |= (1 << 0); /* Set PEX0En Bit */
  230. writel(reg, &cpureg->ctrl_stat);
  231. #endif
  232. return 0;
  233. }
  234. #endif /* CONFIG_ARCH_CPU_INIT */
  235. /*
  236. * SOC specific misc init
  237. */
  238. #if defined(CONFIG_ARCH_MISC_INIT)
  239. int arch_misc_init(void)
  240. {
  241. volatile u32 temp;
  242. /*CPU streaming & write allocate */
  243. temp = readfr_extra_feature_reg();
  244. temp &= ~(1 << 28); /* disable wr alloc */
  245. writefr_extra_feature_reg(temp);
  246. temp = readfr_extra_feature_reg();
  247. temp &= ~(1 << 29); /* streaming disabled */
  248. writefr_extra_feature_reg(temp);
  249. /* L2Cache settings */
  250. temp = readfr_extra_feature_reg();
  251. /* Disable L2C pre fetch - Set bit 24 */
  252. temp |= (1 << 24);
  253. /* enable L2C - Set bit 22 */
  254. temp |= (1 << 22);
  255. writefr_extra_feature_reg(temp);
  256. icache_enable();
  257. /* Change reset vector to address 0x0 */
  258. temp = get_cr();
  259. set_cr(temp & ~CR_V);
  260. /* checks and execute resset to factory event */
  261. kw_sysrst_check();
  262. return 0;
  263. }
  264. #endif /* CONFIG_ARCH_MISC_INIT */
  265. #ifdef CONFIG_MVGBE
  266. int cpu_eth_init(bd_t *bis)
  267. {
  268. mvgbe_initialize(bis);
  269. return 0;
  270. }
  271. #endif
  272. #ifdef CONFIG_MVEBU_MMC
  273. int board_mmc_init(bd_t *bis)
  274. {
  275. mvebu_mmc_init(bis);
  276. return 0;
  277. }
  278. #endif /* CONFIG_MVEBU_MMC */