cpu.c 9.4 KB

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