cpu.c 9.4 KB

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