cpu.c 8.5 KB

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