cpu.c 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2010 Albert ARIBAUD <albert.u.boot@aribaud.net>
  4. *
  5. * Based on original Kirkwood support which is
  6. * (C) Copyright 2009
  7. * Marvell Semiconductor <www.marvell.com>
  8. * Written-by: Prafulla Wadaskar <prafulla@marvell.com>
  9. */
  10. #include <common.h>
  11. #include <netdev.h>
  12. #include <asm/cache.h>
  13. #include <asm/io.h>
  14. #include <u-boot/md5.h>
  15. #include <asm/arch/cpu.h>
  16. #define BUFLEN 16
  17. void reset_cpu(unsigned long ignored)
  18. {
  19. struct orion5x_cpu_registers *cpureg =
  20. (struct orion5x_cpu_registers *)ORION5X_CPU_REG_BASE;
  21. writel(readl(&cpureg->rstoutn_mask) | (1 << 2),
  22. &cpureg->rstoutn_mask);
  23. writel(readl(&cpureg->sys_soft_rst) | 1,
  24. &cpureg->sys_soft_rst);
  25. while (1)
  26. ;
  27. }
  28. /*
  29. * Compute Window Size field value from size expressed in bytes
  30. * Used with the Base register to set the address window size and location.
  31. * Must be programmed from LSB to MSB as sequence of ones followed by
  32. * sequence of zeros. The number of ones specifies the size of the window in
  33. * 64 KiB granularity (e.g., a value of 0x00FF specifies 256 = 16 MiB).
  34. * NOTES:
  35. * 1) A sizeval equal to 0x0 specifies 4 GiB.
  36. * 2) A return value of 0x0 specifies 64 KiB.
  37. */
  38. unsigned int orion5x_winctrl_calcsize(unsigned int sizeval)
  39. {
  40. /*
  41. * Calculate the number of 64 KiB blocks needed minus one (rounding up).
  42. * For sizeval > 0 this is equivalent to:
  43. * sizeval = (u32) ceil((double) sizeval / 65536.0) - 1
  44. */
  45. sizeval = (sizeval - 1) >> 16;
  46. /*
  47. * Propagate 'one' bits to the right by 'oring' them.
  48. * We need only treat bits 15-0.
  49. */
  50. sizeval |= sizeval >> 1; /* 'Or' bit 15 onto bit 14 */
  51. sizeval |= sizeval >> 2; /* 'Or' bits 15-14 onto bits 13-12 */
  52. sizeval |= sizeval >> 4; /* 'Or' bits 15-12 onto bits 11-8 */
  53. sizeval |= sizeval >> 8; /* 'Or' bits 15-8 onto bits 7-0*/
  54. return sizeval;
  55. }
  56. /*
  57. * orion5x_config_adr_windows - Configure address Windows
  58. *
  59. * There are 8 address windows supported by Orion5x Soc to addess different
  60. * devices. Each window can be configured for size, BAR and remap addr
  61. * Below configuration is standard for most of the cases
  62. *
  63. * If remap function not used, remap_lo must be set as base
  64. *
  65. * NOTES:
  66. *
  67. * 1) in order to avoid windows with inconsistent control and base values
  68. * (which could prevent access to BOOTCS and hence execution from FLASH)
  69. * always disable window before writing the base value then reenable it
  70. * by writing the control value.
  71. *
  72. * 2) in order to avoid losing access to BOOTCS when disabling window 7,
  73. * first configure window 6 for BOOTCS, then configure window 7 for BOOTCS,
  74. * then configure windows 6 for its own target.
  75. *
  76. * Reference Documentation:
  77. * Mbus-L to Mbus Bridge Registers Configuration.
  78. * (Sec 25.1 and 25.3 of Datasheet)
  79. */
  80. int orion5x_config_adr_windows(void)
  81. {
  82. struct orion5x_win_registers *winregs =
  83. (struct orion5x_win_registers *)ORION5X_CPU_WIN_BASE;
  84. /* Disable window 0, configure it for its intended target, enable it. */
  85. writel(0, &winregs[0].ctrl);
  86. writel(ORION5X_ADR_PCIE_MEM, &winregs[0].base);
  87. writel(ORION5X_ADR_PCIE_MEM_REMAP_LO, &winregs[0].remap_lo);
  88. writel(ORION5X_ADR_PCIE_MEM_REMAP_HI, &winregs[0].remap_hi);
  89. writel(ORION5X_CPU_WIN_CTRL_DATA(ORION5X_SZ_PCIE_MEM,
  90. ORION5X_TARGET_PCIE, ORION5X_ATTR_PCIE_MEM,
  91. ORION5X_WIN_ENABLE), &winregs[0].ctrl);
  92. /* Disable window 1, configure it for its intended target, enable it. */
  93. writel(0, &winregs[1].ctrl);
  94. writel(ORION5X_ADR_PCIE_IO, &winregs[1].base);
  95. writel(ORION5X_ADR_PCIE_IO_REMAP_LO, &winregs[1].remap_lo);
  96. writel(ORION5X_ADR_PCIE_IO_REMAP_HI, &winregs[1].remap_hi);
  97. writel(ORION5X_CPU_WIN_CTRL_DATA(ORION5X_SZ_PCIE_IO,
  98. ORION5X_TARGET_PCIE, ORION5X_ATTR_PCIE_IO,
  99. ORION5X_WIN_ENABLE), &winregs[1].ctrl);
  100. /* Disable window 2, configure it for its intended target, enable it. */
  101. writel(0, &winregs[2].ctrl);
  102. writel(ORION5X_ADR_PCI_MEM, &winregs[2].base);
  103. writel(ORION5X_CPU_WIN_CTRL_DATA(ORION5X_SZ_PCI_MEM,
  104. ORION5X_TARGET_PCI, ORION5X_ATTR_PCI_MEM,
  105. ORION5X_WIN_ENABLE), &winregs[2].ctrl);
  106. /* Disable window 3, configure it for its intended target, enable it. */
  107. writel(0, &winregs[3].ctrl);
  108. writel(ORION5X_ADR_PCI_IO, &winregs[3].base);
  109. writel(ORION5X_CPU_WIN_CTRL_DATA(ORION5X_SZ_PCI_IO,
  110. ORION5X_TARGET_PCI, ORION5X_ATTR_PCI_IO,
  111. ORION5X_WIN_ENABLE), &winregs[3].ctrl);
  112. /* Disable window 4, configure it for its intended target, enable it. */
  113. writel(0, &winregs[4].ctrl);
  114. writel(ORION5X_ADR_DEV_CS0, &winregs[4].base);
  115. writel(ORION5X_CPU_WIN_CTRL_DATA(ORION5X_SZ_DEV_CS0,
  116. ORION5X_TARGET_DEVICE, ORION5X_ATTR_DEV_CS0,
  117. ORION5X_WIN_ENABLE), &winregs[4].ctrl);
  118. /* Disable window 5, configure it for its intended target, enable it. */
  119. writel(0, &winregs[5].ctrl);
  120. writel(ORION5X_ADR_DEV_CS1, &winregs[5].base);
  121. writel(ORION5X_CPU_WIN_CTRL_DATA(ORION5X_SZ_DEV_CS1,
  122. ORION5X_TARGET_DEVICE, ORION5X_ATTR_DEV_CS1,
  123. ORION5X_WIN_ENABLE), &winregs[5].ctrl);
  124. /* Disable window 6, configure it for FLASH, enable it. */
  125. writel(0, &winregs[6].ctrl);
  126. writel(ORION5X_ADR_BOOTROM, &winregs[6].base);
  127. writel(ORION5X_CPU_WIN_CTRL_DATA(ORION5X_SZ_BOOTROM,
  128. ORION5X_TARGET_DEVICE, ORION5X_ATTR_BOOTROM,
  129. ORION5X_WIN_ENABLE), &winregs[6].ctrl);
  130. /* Disable window 7, configure it for FLASH, enable it. */
  131. writel(0, &winregs[7].ctrl);
  132. writel(ORION5X_ADR_BOOTROM, &winregs[7].base);
  133. writel(ORION5X_CPU_WIN_CTRL_DATA(ORION5X_SZ_BOOTROM,
  134. ORION5X_TARGET_DEVICE, ORION5X_ATTR_BOOTROM,
  135. ORION5X_WIN_ENABLE), &winregs[7].ctrl);
  136. /* Disable window 6, configure it for its intended target, enable it. */
  137. writel(0, &winregs[6].ctrl);
  138. writel(ORION5X_ADR_DEV_CS2, &winregs[6].base);
  139. writel(ORION5X_CPU_WIN_CTRL_DATA(ORION5X_SZ_DEV_CS2,
  140. ORION5X_TARGET_DEVICE, ORION5X_ATTR_DEV_CS2,
  141. ORION5X_WIN_ENABLE), &winregs[6].ctrl);
  142. return 0;
  143. }
  144. /*
  145. * Orion5x identification is done through PCIE space.
  146. */
  147. u32 orion5x_device_id(void)
  148. {
  149. return readl(PCIE_DEV_ID_OFF) >> 16;
  150. }
  151. u32 orion5x_device_rev(void)
  152. {
  153. return readl(PCIE_DEV_REV_OFF) & 0xff;
  154. }
  155. #if defined(CONFIG_DISPLAY_CPUINFO)
  156. /* Display device and revision IDs.
  157. * This function must cover all known device/revision
  158. * combinations, not only the one for which u-boot is
  159. * compiled; this way, one can identify actual HW in
  160. * case of a mismatch.
  161. */
  162. int print_cpuinfo(void)
  163. {
  164. char dev_str[7]; /* room enough for 0x0000 plus null byte */
  165. char rev_str[5]; /* room enough for 0x00 plus null byte */
  166. char *dev_name = NULL;
  167. char *rev_name = NULL;
  168. u32 dev = orion5x_device_id();
  169. u32 rev = orion5x_device_rev();
  170. if (dev == MV88F5181_DEV_ID) {
  171. dev_name = "MV88F5181";
  172. if (rev == MV88F5181_REV_B1)
  173. rev_name = "B1";
  174. else if (rev == MV88F5181L_REV_A1) {
  175. dev_name = "MV88F5181L";
  176. rev_name = "A1";
  177. } else if (rev == MV88F5181L_REV_A0) {
  178. dev_name = "MV88F5181L";
  179. rev_name = "A0";
  180. }
  181. } else if (dev == MV88F5182_DEV_ID) {
  182. dev_name = "MV88F5182";
  183. if (rev == MV88F5182_REV_A2)
  184. rev_name = "A2";
  185. } else if (dev == MV88F5281_DEV_ID) {
  186. dev_name = "MV88F5281";
  187. if (rev == MV88F5281_REV_D2)
  188. rev_name = "D2";
  189. else if (rev == MV88F5281_REV_D1)
  190. rev_name = "D1";
  191. else if (rev == MV88F5281_REV_D0)
  192. rev_name = "D0";
  193. } else if (dev == MV88F6183_DEV_ID) {
  194. dev_name = "MV88F6183";
  195. if (rev == MV88F6183_REV_B0)
  196. rev_name = "B0";
  197. }
  198. if (dev_name == NULL) {
  199. sprintf(dev_str, "0x%04x", dev);
  200. dev_name = dev_str;
  201. }
  202. if (rev_name == NULL) {
  203. sprintf(rev_str, "0x%02x", rev);
  204. rev_name = rev_str;
  205. }
  206. printf("SoC: Orion5x %s-%s\n", dev_name, rev_name);
  207. return 0;
  208. }
  209. #endif /* CONFIG_DISPLAY_CPUINFO */
  210. #ifdef CONFIG_ARCH_CPU_INIT
  211. int arch_cpu_init(void)
  212. {
  213. /* Enable and invalidate L2 cache in write through mode */
  214. invalidate_l2_cache();
  215. #ifdef CONFIG_SPL_BUILD
  216. orion5x_config_adr_windows();
  217. #endif
  218. return 0;
  219. }
  220. #endif /* CONFIG_ARCH_CPU_INIT */
  221. /*
  222. * SOC specific misc init
  223. */
  224. #if defined(CONFIG_ARCH_MISC_INIT)
  225. int arch_misc_init(void)
  226. {
  227. u32 temp;
  228. /*CPU streaming & write allocate */
  229. temp = readfr_extra_feature_reg();
  230. temp &= ~(1 << 28); /* disable wr alloc */
  231. writefr_extra_feature_reg(temp);
  232. temp = readfr_extra_feature_reg();
  233. temp &= ~(1 << 29); /* streaming disabled */
  234. writefr_extra_feature_reg(temp);
  235. /* L2Cache settings */
  236. temp = readfr_extra_feature_reg();
  237. /* Disable L2C pre fetch - Set bit 24 */
  238. temp |= (1 << 24);
  239. /* enable L2C - Set bit 22 */
  240. temp |= (1 << 22);
  241. writefr_extra_feature_reg(temp);
  242. icache_enable();
  243. /* Change reset vector to address 0x0 */
  244. temp = get_cr();
  245. set_cr(temp & ~CR_V);
  246. /* Set CPIOs and MPPs - values provided by board
  247. include file */
  248. writel(ORION5X_MPP0_7, ORION5X_MPP_BASE+0x00);
  249. writel(ORION5X_MPP8_15, ORION5X_MPP_BASE+0x04);
  250. writel(ORION5X_MPP16_23, ORION5X_MPP_BASE+0x50);
  251. writel(ORION5X_GPIO_OUT_VALUE, ORION5X_GPIO_BASE+0x00);
  252. writel(ORION5X_GPIO_OUT_ENABLE, ORION5X_GPIO_BASE+0x04);
  253. writel(ORION5X_GPIO_IN_POLARITY, ORION5X_GPIO_BASE+0x0c);
  254. /* initialize timer */
  255. timer_init_r();
  256. return 0;
  257. }
  258. #endif /* CONFIG_ARCH_MISC_INIT */
  259. #ifdef CONFIG_MVGBE
  260. int cpu_eth_init(bd_t *bis)
  261. {
  262. mvgbe_initialize(bis);
  263. return 0;
  264. }
  265. #endif