cpu.c 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  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. * Window Size
  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 KByte granularity (e.g., a value of 0x00FF specifies 256 = 16 MByte).
  51. * NOTE: A value of 0x0 specifies 64-KByte size.
  52. */
  53. unsigned int orion5x_winctrl_calcsize(unsigned int sizeval)
  54. {
  55. int i;
  56. unsigned int j = 0;
  57. u32 val = sizeval >> 1;
  58. for (i = 0; val >= 0x10000; i++) {
  59. j |= (1 << i);
  60. val = val >> 1;
  61. }
  62. return 0x0000ffff & j;
  63. }
  64. /*
  65. * orion5x_config_adr_windows - Configure address Windows
  66. *
  67. * There are 8 address windows supported by Orion5x Soc to addess different
  68. * devices. Each window can be configured for size, BAR and remap addr
  69. * Below configuration is standard for most of the cases
  70. *
  71. * If remap function not used, remap_lo must be set as base
  72. *
  73. * NOTES:
  74. *
  75. * 1) in order to avoid windows with inconsistent control and base values
  76. * (which could prevent access to BOOTCS and hence execution from FLASH)
  77. * always disable window before writing the base value then reenable it
  78. * by writing the control value.
  79. *
  80. * 2) in order to avoid losing access to BOOTCS when disabling window 7,
  81. * first configure window 6 for BOOTCS, then configure window 7 for BOOTCS,
  82. * then configure windows 6 for its own target.
  83. *
  84. * Reference Documentation:
  85. * Mbus-L to Mbus Bridge Registers Configuration.
  86. * (Sec 25.1 and 25.3 of Datasheet)
  87. */
  88. int orion5x_config_adr_windows(void)
  89. {
  90. struct orion5x_win_registers *winregs =
  91. (struct orion5x_win_registers *)ORION5X_CPU_WIN_BASE;
  92. /* Disable window 0, configure it for its intended target, enable it. */
  93. writel(0, &winregs[0].ctrl);
  94. writel(ORION5X_ADR_PCIE_MEM, &winregs[0].base);
  95. writel(ORION5X_ADR_PCIE_MEM_REMAP_LO, &winregs[0].remap_lo);
  96. writel(ORION5X_ADR_PCIE_MEM_REMAP_HI, &winregs[0].remap_hi);
  97. writel(ORION5X_CPU_WIN_CTRL_DATA(ORION5X_SZ_PCIE_MEM,
  98. ORION5X_TARGET_PCIE, ORION5X_ATTR_PCIE_MEM,
  99. ORION5X_WIN_ENABLE), &winregs[0].ctrl);
  100. /* Disable window 1, configure it for its intended target, enable it. */
  101. writel(0, &winregs[1].ctrl);
  102. writel(ORION5X_ADR_PCIE_IO, &winregs[1].base);
  103. writel(ORION5X_ADR_PCIE_IO_REMAP_LO, &winregs[1].remap_lo);
  104. writel(ORION5X_ADR_PCIE_IO_REMAP_HI, &winregs[1].remap_hi);
  105. writel(ORION5X_CPU_WIN_CTRL_DATA(ORION5X_SZ_PCIE_IO,
  106. ORION5X_TARGET_PCIE, ORION5X_ATTR_PCIE_IO,
  107. ORION5X_WIN_ENABLE), &winregs[1].ctrl);
  108. /* Disable window 2, configure it for its intended target, enable it. */
  109. writel(0, &winregs[2].ctrl);
  110. writel(ORION5X_ADR_PCI_MEM, &winregs[2].base);
  111. writel(ORION5X_CPU_WIN_CTRL_DATA(ORION5X_SZ_PCI_MEM,
  112. ORION5X_TARGET_PCI, ORION5X_ATTR_PCI_MEM,
  113. ORION5X_WIN_ENABLE), &winregs[2].ctrl);
  114. /* Disable window 3, configure it for its intended target, enable it. */
  115. writel(0, &winregs[3].ctrl);
  116. writel(ORION5X_ADR_PCI_IO, &winregs[3].base);
  117. writel(ORION5X_CPU_WIN_CTRL_DATA(ORION5X_SZ_PCI_IO,
  118. ORION5X_TARGET_PCI, ORION5X_ATTR_PCI_IO,
  119. ORION5X_WIN_ENABLE), &winregs[3].ctrl);
  120. /* Disable window 4, configure it for its intended target, enable it. */
  121. writel(0, &winregs[4].ctrl);
  122. writel(ORION5X_ADR_DEV_CS0, &winregs[4].base);
  123. writel(ORION5X_CPU_WIN_CTRL_DATA(ORION5X_SZ_DEV_CS0,
  124. ORION5X_TARGET_DEVICE, ORION5X_ATTR_DEV_CS0,
  125. ORION5X_WIN_ENABLE), &winregs[4].ctrl);
  126. /* Disable window 5, configure it for its intended target, enable it. */
  127. writel(0, &winregs[5].ctrl);
  128. writel(ORION5X_ADR_DEV_CS1, &winregs[5].base);
  129. writel(ORION5X_CPU_WIN_CTRL_DATA(ORION5X_SZ_DEV_CS1,
  130. ORION5X_TARGET_DEVICE, ORION5X_ATTR_DEV_CS1,
  131. ORION5X_WIN_ENABLE), &winregs[5].ctrl);
  132. /* Disable window 6, configure it for FLASH, enable it. */
  133. writel(0, &winregs[6].ctrl);
  134. writel(ORION5X_ADR_BOOTROM, &winregs[6].base);
  135. writel(ORION5X_CPU_WIN_CTRL_DATA(ORION5X_SZ_BOOTROM,
  136. ORION5X_TARGET_DEVICE, ORION5X_ATTR_BOOTROM,
  137. ORION5X_WIN_ENABLE), &winregs[6].ctrl);
  138. /* Disable window 7, configure it for FLASH, enable it. */
  139. writel(0, &winregs[7].ctrl);
  140. writel(ORION5X_ADR_BOOTROM, &winregs[7].base);
  141. writel(ORION5X_CPU_WIN_CTRL_DATA(ORION5X_SZ_BOOTROM,
  142. ORION5X_TARGET_DEVICE, ORION5X_ATTR_BOOTROM,
  143. ORION5X_WIN_ENABLE), &winregs[7].ctrl);
  144. /* Disable window 6, configure it for its intended target, enable it. */
  145. writel(0, &winregs[6].ctrl);
  146. writel(ORION5X_ADR_DEV_CS2, &winregs[6].base);
  147. writel(ORION5X_CPU_WIN_CTRL_DATA(ORION5X_SZ_DEV_CS2,
  148. ORION5X_TARGET_DEVICE, ORION5X_ATTR_DEV_CS2,
  149. ORION5X_WIN_ENABLE), &winregs[6].ctrl);
  150. return 0;
  151. }
  152. /*
  153. * Orion5x identification is done through PCIE space.
  154. */
  155. u32 orion5x_device_id(void)
  156. {
  157. return readl(PCIE_DEV_ID_OFF) >> 16;
  158. }
  159. u32 orion5x_device_rev(void)
  160. {
  161. return readl(PCIE_DEV_REV_OFF) & 0xff;
  162. }
  163. #if defined(CONFIG_DISPLAY_CPUINFO)
  164. /* Display device and revision IDs.
  165. * This function must cover all known device/revision
  166. * combinations, not only the one for which u-boot is
  167. * compiled; this way, one can identify actual HW in
  168. * case of a mismatch.
  169. */
  170. int print_cpuinfo(void)
  171. {
  172. char dev_str[] = "0x0000";
  173. char rev_str[] = "0x00";
  174. char *dev_name = NULL;
  175. char *rev_name = NULL;
  176. u32 dev = orion5x_device_id();
  177. u32 rev = orion5x_device_rev();
  178. if (dev == MV88F5181_DEV_ID) {
  179. dev_name = "MV88F5181";
  180. if (rev == MV88F5181_REV_B1)
  181. rev_name = "B1";
  182. else if (rev == MV88F5181L_REV_A1) {
  183. dev_name = "MV88F5181L";
  184. rev_name = "A1";
  185. } else if (rev == MV88F5181L_REV_A0) {
  186. dev_name = "MV88F5181L";
  187. rev_name = "A0";
  188. }
  189. } else if (dev == MV88F5182_DEV_ID) {
  190. dev_name = "MV88F5182";
  191. if (rev == MV88F5182_REV_A2)
  192. rev_name = "A2";
  193. } else if (dev == MV88F5281_DEV_ID) {
  194. dev_name = "MV88F5281";
  195. if (rev == MV88F5281_REV_D2)
  196. rev_name = "D2";
  197. else if (rev == MV88F5281_REV_D1)
  198. rev_name = "D1";
  199. else if (rev == MV88F5281_REV_D0)
  200. rev_name = "D0";
  201. } else if (dev == MV88F6183_DEV_ID) {
  202. dev_name = "MV88F6183";
  203. if (rev == MV88F6183_REV_B0)
  204. rev_name = "B0";
  205. }
  206. if (dev_name == NULL) {
  207. sprintf(dev_str, "0x%04x", dev);
  208. dev_name = dev_str;
  209. }
  210. if (rev_name == NULL) {
  211. sprintf(rev_str, "0x%02x", rev);
  212. rev_name = rev_str;
  213. }
  214. printf("SoC: Orion5x %s-%s\n", dev_name, rev_name);
  215. return 0;
  216. }
  217. #endif /* CONFIG_DISPLAY_CPUINFO */
  218. #ifdef CONFIG_ARCH_CPU_INIT
  219. int arch_cpu_init(void)
  220. {
  221. /* Enable and invalidate L2 cache in write through mode */
  222. invalidate_l2_cache();
  223. orion5x_config_adr_windows();
  224. return 0;
  225. }
  226. #endif /* CONFIG_ARCH_CPU_INIT */
  227. /*
  228. * SOC specific misc init
  229. */
  230. #if defined(CONFIG_ARCH_MISC_INIT)
  231. int arch_misc_init(void)
  232. {
  233. u32 temp;
  234. /*CPU streaming & write allocate */
  235. temp = readfr_extra_feature_reg();
  236. temp &= ~(1 << 28); /* disable wr alloc */
  237. writefr_extra_feature_reg(temp);
  238. temp = readfr_extra_feature_reg();
  239. temp &= ~(1 << 29); /* streaming disabled */
  240. writefr_extra_feature_reg(temp);
  241. /* L2Cache settings */
  242. temp = readfr_extra_feature_reg();
  243. /* Disable L2C pre fetch - Set bit 24 */
  244. temp |= (1 << 24);
  245. /* enable L2C - Set bit 22 */
  246. temp |= (1 << 22);
  247. writefr_extra_feature_reg(temp);
  248. icache_enable();
  249. /* Change reset vector to address 0x0 */
  250. temp = get_cr();
  251. set_cr(temp & ~CR_V);
  252. /* Set CPIOs and MPPs - values provided by board
  253. include file */
  254. writel(ORION5X_MPP0_7, ORION5X_MPP_BASE+0x00);
  255. writel(ORION5X_MPP8_15, ORION5X_MPP_BASE+0x04);
  256. writel(ORION5X_MPP16_23, ORION5X_MPP_BASE+0x50);
  257. writel(ORION5X_GPIO_OUT_ENABLE, ORION5X_GPIO_BASE+0x04);
  258. /* initialize timer */
  259. timer_init_r();
  260. return 0;
  261. }
  262. #endif /* CONFIG_ARCH_MISC_INIT */
  263. #ifdef CONFIG_MVGBE
  264. int cpu_eth_init(bd_t *bis)
  265. {
  266. mvgbe_initialize(bis);
  267. return 0;
  268. }
  269. #endif