cpu.c 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. /*
  2. * (C) Copyright 2009
  3. * Marvell Semiconductor <www.marvell.com>
  4. * Written-by: Prafulla Wadaskar <prafulla@marvell.com>
  5. *
  6. * See file CREDITS for list of people who contributed to this
  7. * project.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation; either version 2 of
  12. * the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  22. * MA 02110-1301 USA
  23. */
  24. #include <common.h>
  25. #include <netdev.h>
  26. #include <asm/cache.h>
  27. #include <u-boot/md5.h>
  28. #include <asm/arch/kirkwood.h>
  29. #define BUFLEN 16
  30. void reset_cpu(unsigned long ignored)
  31. {
  32. struct kwcpu_registers *cpureg =
  33. (struct kwcpu_registers *)KW_CPU_REG_BASE;
  34. writel(readl(&cpureg->rstoutn_mask) | (1 << 2),
  35. &cpureg->rstoutn_mask);
  36. writel(readl(&cpureg->sys_soft_rst) | 1,
  37. &cpureg->sys_soft_rst);
  38. while (1) ;
  39. }
  40. /*
  41. * Generates Ramdom hex number reading some time varient system registers
  42. * and using md5 algorithm
  43. */
  44. unsigned char get_random_hex(void)
  45. {
  46. int i;
  47. u32 inbuf[BUFLEN];
  48. u8 outbuf[BUFLEN];
  49. /*
  50. * in case of 88F6281/88F6192 A0,
  51. * Bit7 need to reset to generate random values in KW_REG_UNDOC_0x1470
  52. * Soc reg offsets KW_REG_UNDOC_0x1470 and KW_REG_UNDOC_0x1478 are reserved regs and
  53. * Does not have names at this moment (no errata available)
  54. */
  55. writel(readl(KW_REG_UNDOC_0x1478) & ~(1 << 7), KW_REG_UNDOC_0x1478);
  56. for (i = 0; i < BUFLEN; i++) {
  57. inbuf[i] = readl(KW_REG_UNDOC_0x1470);
  58. }
  59. md5((u8 *) inbuf, (BUFLEN * sizeof(u32)), outbuf);
  60. return outbuf[outbuf[7] % 0x0f];
  61. }
  62. /*
  63. * Window Size
  64. * Used with the Base register to set the address window size and location.
  65. * Must be programmed from LSB to MSB as sequence of ones followed by
  66. * sequence of zeros. The number of ones specifies the size of the window in
  67. * 64 KByte granularity (e.g., a value of 0x00FF specifies 256 = 16 MByte).
  68. * NOTE: A value of 0x0 specifies 64-KByte size.
  69. */
  70. static unsigned int kw_winctrl_calcsize(unsigned int sizeval)
  71. {
  72. int i;
  73. unsigned int j = 0;
  74. u32 val = sizeval >> 1;
  75. for (i = 0; val > 0x10000; i++) {
  76. j |= (1 << i);
  77. val = val >> 1;
  78. }
  79. return (0x0000ffff & j);
  80. }
  81. /* prepares data to be loaded in win_Ctrl register */
  82. #define KWCPU_WIN_CTRL_DATA(size, target, attr, en) (en | (target << 4) \
  83. | (attr << 8) | (kw_winctrl_calcsize(size) << 16))
  84. /*
  85. * kw_config_adr_windows - Configure address Windows
  86. *
  87. * There are 8 address windows supported by Kirkwood Soc to addess different
  88. * devices. Each window can be configured for size, BAR and remap addr
  89. * Below configuration is standard for most of the cases
  90. *
  91. * If remap function not used, remap_lo must be set as base
  92. *
  93. * Reference Documentation:
  94. * Mbus-L to Mbus Bridge Registers Configuration.
  95. * (Sec 25.1 and 25.3 of Datasheet)
  96. */
  97. int kw_config_adr_windows(void)
  98. {
  99. struct kwwin_registers *winregs =
  100. (struct kwwin_registers *)KW_CPU_WIN_BASE;
  101. /* Window 0: PCIE MEM address space */
  102. writel(KWCPU_WIN_CTRL_DATA(1024 * 1024 * 256, KWCPU_TARGET_PCIE,
  103. KWCPU_ATTR_PCIE_MEM, KWCPU_WIN_ENABLE), &winregs[0].ctrl);
  104. writel(KW_DEFADR_PCI_MEM, &winregs[0].base);
  105. writel(KW_DEFADR_PCI_MEM, &winregs[0].remap_lo);
  106. writel(0x0, &winregs[0].remap_hi);
  107. /* Window 1: PCIE IO address space */
  108. writel(KWCPU_WIN_CTRL_DATA(1024 * 64, KWCPU_TARGET_PCIE,
  109. KWCPU_ATTR_PCIE_IO, KWCPU_WIN_ENABLE), &winregs[1].ctrl);
  110. writel(KW_DEFADR_PCI_IO, &winregs[1].base);
  111. writel(KW_DEFADR_PCI_IO_REMAP, &winregs[1].remap_lo);
  112. writel(0x0, &winregs[1].remap_hi);
  113. /* Window 2: NAND Flash address space */
  114. writel(KWCPU_WIN_CTRL_DATA(1024 * 1024 * 128, KWCPU_TARGET_MEMORY,
  115. KWCPU_ATTR_NANDFLASH, KWCPU_WIN_ENABLE), &winregs[2].ctrl);
  116. writel(KW_DEFADR_NANDF, &winregs[2].base);
  117. writel(KW_DEFADR_NANDF, &winregs[2].remap_lo);
  118. writel(0x0, &winregs[2].remap_hi);
  119. /* Window 3: SPI Flash address space */
  120. writel(KWCPU_WIN_CTRL_DATA(1024 * 1024 * 128, KWCPU_TARGET_MEMORY,
  121. KWCPU_ATTR_SPIFLASH, KWCPU_WIN_ENABLE), &winregs[3].ctrl);
  122. writel(KW_DEFADR_SPIF, &winregs[3].base);
  123. writel(KW_DEFADR_SPIF, &winregs[3].remap_lo);
  124. writel(0x0, &winregs[3].remap_hi);
  125. /* Window 4: BOOT Memory address space */
  126. writel(KWCPU_WIN_CTRL_DATA(1024 * 1024 * 128, KWCPU_TARGET_MEMORY,
  127. KWCPU_ATTR_BOOTROM, KWCPU_WIN_ENABLE), &winregs[4].ctrl);
  128. writel(KW_DEFADR_BOOTROM, &winregs[4].base);
  129. /* Window 5: Security SRAM address space */
  130. writel(KWCPU_WIN_CTRL_DATA(1024 * 64, KWCPU_TARGET_SASRAM,
  131. KWCPU_ATTR_SASRAM, KWCPU_WIN_ENABLE), &winregs[5].ctrl);
  132. writel(KW_DEFADR_SASRAM, &winregs[5].base);
  133. /* Window 6-7: Disabled */
  134. writel(KWCPU_WIN_DISABLE, &winregs[6].ctrl);
  135. writel(KWCPU_WIN_DISABLE, &winregs[7].ctrl);
  136. return 0;
  137. }
  138. /*
  139. * kw_config_gpio - GPIO configuration
  140. */
  141. void kw_config_gpio(u32 gpp0_oe_val, u32 gpp1_oe_val, u32 gpp0_oe, u32 gpp1_oe)
  142. {
  143. struct kwgpio_registers *gpio0reg =
  144. (struct kwgpio_registers *)KW_GPIO0_BASE;
  145. struct kwgpio_registers *gpio1reg =
  146. (struct kwgpio_registers *)KW_GPIO1_BASE;
  147. /* Init GPIOS to default values as per board requirement */
  148. writel(gpp0_oe_val, &gpio0reg->dout);
  149. writel(gpp1_oe_val, &gpio1reg->dout);
  150. writel(gpp0_oe, &gpio0reg->oe);
  151. writel(gpp1_oe, &gpio1reg->oe);
  152. }
  153. /*
  154. * kw_config_mpp - Multi-Purpose Pins Functionality configuration
  155. *
  156. * Each MPP can be configured to different functionality through
  157. * MPP control register, ref (sec 6.1 of kirkwood h/w specification)
  158. *
  159. * There are maximum 64 Multi-Pourpose Pins on Kirkwood
  160. * Each MPP functionality can be configuration by a 4bit value
  161. * of MPP control reg, the value and associated functionality depends
  162. * upon used SoC varient
  163. */
  164. int kw_config_mpp(u32 mpp0_7, u32 mpp8_15, u32 mpp16_23, u32 mpp24_31,
  165. u32 mpp32_39, u32 mpp40_47, u32 mpp48_55)
  166. {
  167. u32 *mppreg = (u32 *) KW_MPP_BASE;
  168. /* program mpp registers */
  169. writel(mpp0_7, &mppreg[0]);
  170. writel(mpp8_15, &mppreg[1]);
  171. writel(mpp16_23, &mppreg[2]);
  172. writel(mpp24_31, &mppreg[3]);
  173. writel(mpp32_39, &mppreg[4]);
  174. writel(mpp40_47, &mppreg[5]);
  175. writel(mpp48_55, &mppreg[6]);
  176. return 0;
  177. }
  178. #if defined(CONFIG_DISPLAY_CPUINFO)
  179. int print_cpuinfo(void)
  180. {
  181. char *name = "Unknown";
  182. switch (readl(KW_REG_DEVICE_ID) & 0x03) {
  183. case 1:
  184. name = "88F6192_A0";
  185. break;
  186. case 2:
  187. name = "88F6281_A0";
  188. break;
  189. default:
  190. printf("SoC: Unsupported Kirkwood\n");
  191. return -1;
  192. }
  193. printf("SoC: Kirkwood %s\n", name);
  194. return 0;
  195. }
  196. #endif /* CONFIG_DISPLAY_CPUINFO */
  197. #ifdef CONFIG_ARCH_CPU_INIT
  198. int arch_cpu_init(void)
  199. {
  200. u32 reg;
  201. struct kwcpu_registers *cpureg =
  202. (struct kwcpu_registers *)KW_CPU_REG_BASE;
  203. /* Linux expects` the internal registers to be at 0xf1000000 */
  204. writel(KW_REGS_PHY_BASE, KW_OFFSET_REG);
  205. /* Enable and invalidate L2 cache in write through mode */
  206. writel(readl(&cpureg->l2_cfg) | 0x18, &cpureg->l2_cfg);
  207. invalidate_l2_cache();
  208. kw_config_adr_windows();
  209. #ifdef CONFIG_KIRKWOOD_RGMII_PAD_1V8
  210. /*
  211. * Configures the I/O voltage of the pads connected to Egigabit
  212. * Ethernet interface to 1.8V
  213. * By defult it is set to 3.3V
  214. */
  215. reg = readl(KW_REG_MPP_OUT_DRV_REG);
  216. reg |= (1 << 7);
  217. writel(reg, KW_REG_MPP_OUT_DRV_REG);
  218. #endif
  219. #ifdef CONFIG_KIRKWOOD_EGIGA_INIT
  220. /*
  221. * Set egiga port0/1 in normal functional mode
  222. * This is required becasue on kirkwood by default ports are in reset mode
  223. * OS egiga driver may not have provision to set them in normal mode
  224. * and if u-boot is build without network support, network may fail at OS level
  225. */
  226. reg = readl(KWGBE_PORT_SERIAL_CONTROL1_REG(0));
  227. reg &= ~(1 << 4); /* Clear PortReset Bit */
  228. writel(reg, (KWGBE_PORT_SERIAL_CONTROL1_REG(0)));
  229. reg = readl(KWGBE_PORT_SERIAL_CONTROL1_REG(1));
  230. reg &= ~(1 << 4); /* Clear PortReset Bit */
  231. writel(reg, (KWGBE_PORT_SERIAL_CONTROL1_REG(1)));
  232. #endif
  233. #ifdef CONFIG_KIRKWOOD_PCIE_INIT
  234. /*
  235. * Enable PCI Express Port0
  236. */
  237. reg = readl(&cpureg->ctrl_stat);
  238. reg |= (1 << 0); /* Set PEX0En Bit */
  239. writel(reg, &cpureg->ctrl_stat);
  240. #endif
  241. return 0;
  242. }
  243. #endif /* CONFIG_ARCH_CPU_INIT */
  244. /*
  245. * SOC specific misc init
  246. */
  247. #if defined(CONFIG_ARCH_MISC_INIT)
  248. int arch_misc_init(void)
  249. {
  250. volatile u32 temp;
  251. /*CPU streaming & write allocate */
  252. temp = readfr_extra_feature_reg();
  253. temp &= ~(1 << 28); /* disable wr alloc */
  254. writefr_extra_feature_reg(temp);
  255. temp = readfr_extra_feature_reg();
  256. temp &= ~(1 << 29); /* streaming disabled */
  257. writefr_extra_feature_reg(temp);
  258. /* L2Cache settings */
  259. temp = readfr_extra_feature_reg();
  260. /* Disable L2C pre fetch - Set bit 24 */
  261. temp |= (1 << 24);
  262. /* enable L2C - Set bit 22 */
  263. temp |= (1 << 22);
  264. writefr_extra_feature_reg(temp);
  265. icache_enable();
  266. /* Change reset vector to address 0x0 */
  267. temp = get_cr();
  268. set_cr(temp & ~CR_V);
  269. return 0;
  270. }
  271. #endif /* CONFIG_ARCH_MISC_INIT */
  272. #ifdef CONFIG_KIRKWOOD_EGIGA
  273. int cpu_eth_init(bd_t *bis)
  274. {
  275. kirkwood_egiga_initialize(bis);
  276. return 0;
  277. }
  278. #endif