cpu.c 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  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. 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. /*
  82. * kw_config_adr_windows - Configure address Windows
  83. *
  84. * There are 8 address windows supported by Kirkwood Soc to addess different
  85. * devices. Each window can be configured for size, BAR and remap addr
  86. * Below configuration is standard for most of the cases
  87. *
  88. * If remap function not used, remap_lo must be set as base
  89. *
  90. * Reference Documentation:
  91. * Mbus-L to Mbus Bridge Registers Configuration.
  92. * (Sec 25.1 and 25.3 of Datasheet)
  93. */
  94. int kw_config_adr_windows(void)
  95. {
  96. struct kwwin_registers *winregs =
  97. (struct kwwin_registers *)KW_CPU_WIN_BASE;
  98. /* Window 0: PCIE MEM address space */
  99. writel(KWCPU_WIN_CTRL_DATA(1024 * 1024 * 256, KWCPU_TARGET_PCIE,
  100. KWCPU_ATTR_PCIE_MEM, KWCPU_WIN_ENABLE), &winregs[0].ctrl);
  101. writel(KW_DEFADR_PCI_MEM, &winregs[0].base);
  102. writel(KW_DEFADR_PCI_MEM, &winregs[0].remap_lo);
  103. writel(0x0, &winregs[0].remap_hi);
  104. /* Window 1: PCIE IO address space */
  105. writel(KWCPU_WIN_CTRL_DATA(1024 * 64, KWCPU_TARGET_PCIE,
  106. KWCPU_ATTR_PCIE_IO, KWCPU_WIN_ENABLE), &winregs[1].ctrl);
  107. writel(KW_DEFADR_PCI_IO, &winregs[1].base);
  108. writel(KW_DEFADR_PCI_IO_REMAP, &winregs[1].remap_lo);
  109. writel(0x0, &winregs[1].remap_hi);
  110. /* Window 2: NAND Flash address space */
  111. writel(KWCPU_WIN_CTRL_DATA(1024 * 1024 * 128, KWCPU_TARGET_MEMORY,
  112. KWCPU_ATTR_NANDFLASH, KWCPU_WIN_ENABLE), &winregs[2].ctrl);
  113. writel(KW_DEFADR_NANDF, &winregs[2].base);
  114. writel(KW_DEFADR_NANDF, &winregs[2].remap_lo);
  115. writel(0x0, &winregs[2].remap_hi);
  116. /* Window 3: SPI Flash address space */
  117. writel(KWCPU_WIN_CTRL_DATA(1024 * 1024 * 128, KWCPU_TARGET_MEMORY,
  118. KWCPU_ATTR_SPIFLASH, KWCPU_WIN_ENABLE), &winregs[3].ctrl);
  119. writel(KW_DEFADR_SPIF, &winregs[3].base);
  120. writel(KW_DEFADR_SPIF, &winregs[3].remap_lo);
  121. writel(0x0, &winregs[3].remap_hi);
  122. /* Window 4: BOOT Memory address space */
  123. writel(KWCPU_WIN_CTRL_DATA(1024 * 1024 * 128, KWCPU_TARGET_MEMORY,
  124. KWCPU_ATTR_BOOTROM, KWCPU_WIN_ENABLE), &winregs[4].ctrl);
  125. writel(KW_DEFADR_BOOTROM, &winregs[4].base);
  126. /* Window 5: Security SRAM address space */
  127. writel(KWCPU_WIN_CTRL_DATA(1024 * 64, KWCPU_TARGET_SASRAM,
  128. KWCPU_ATTR_SASRAM, KWCPU_WIN_ENABLE), &winregs[5].ctrl);
  129. writel(KW_DEFADR_SASRAM, &winregs[5].base);
  130. /* Window 6-7: Disabled */
  131. writel(KWCPU_WIN_DISABLE, &winregs[6].ctrl);
  132. writel(KWCPU_WIN_DISABLE, &winregs[7].ctrl);
  133. return 0;
  134. }
  135. /*
  136. * kw_config_gpio - GPIO configuration
  137. */
  138. void kw_config_gpio(u32 gpp0_oe_val, u32 gpp1_oe_val, u32 gpp0_oe, u32 gpp1_oe)
  139. {
  140. struct kwgpio_registers *gpio0reg =
  141. (struct kwgpio_registers *)KW_GPIO0_BASE;
  142. struct kwgpio_registers *gpio1reg =
  143. (struct kwgpio_registers *)KW_GPIO1_BASE;
  144. /* Init GPIOS to default values as per board requirement */
  145. writel(gpp0_oe_val, &gpio0reg->dout);
  146. writel(gpp1_oe_val, &gpio1reg->dout);
  147. writel(gpp0_oe, &gpio0reg->oe);
  148. writel(gpp1_oe, &gpio1reg->oe);
  149. }
  150. /*
  151. * kw_config_mpp - Multi-Purpose Pins Functionality configuration
  152. *
  153. * Each MPP can be configured to different functionality through
  154. * MPP control register, ref (sec 6.1 of kirkwood h/w specification)
  155. *
  156. * There are maximum 64 Multi-Pourpose Pins on Kirkwood
  157. * Each MPP functionality can be configuration by a 4bit value
  158. * of MPP control reg, the value and associated functionality depends
  159. * upon used SoC varient
  160. */
  161. int kw_config_mpp(u32 mpp0_7, u32 mpp8_15, u32 mpp16_23, u32 mpp24_31,
  162. u32 mpp32_39, u32 mpp40_47, u32 mpp48_55)
  163. {
  164. u32 *mppreg = (u32 *) KW_MPP_BASE;
  165. /* program mpp registers */
  166. writel(mpp0_7, &mppreg[0]);
  167. writel(mpp8_15, &mppreg[1]);
  168. writel(mpp16_23, &mppreg[2]);
  169. writel(mpp24_31, &mppreg[3]);
  170. writel(mpp32_39, &mppreg[4]);
  171. writel(mpp40_47, &mppreg[5]);
  172. writel(mpp48_55, &mppreg[6]);
  173. return 0;
  174. }
  175. #if defined(CONFIG_DISPLAY_CPUINFO)
  176. int print_cpuinfo(void)
  177. {
  178. char *name = "Unknown";
  179. switch (readl(KW_REG_DEVICE_ID) & 0x03) {
  180. case 1:
  181. name = "88F6192_A0";
  182. break;
  183. case 2:
  184. name = "88F6281_A0";
  185. break;
  186. default:
  187. printf("SoC: Unsupported Kirkwood\n");
  188. return -1;
  189. }
  190. printf("SoC: Kirkwood %s\n", name);
  191. return 0;
  192. }
  193. #endif /* CONFIG_DISPLAY_CPUINFO */
  194. #ifdef CONFIG_ARCH_CPU_INIT
  195. int arch_cpu_init(void)
  196. {
  197. u32 reg;
  198. struct kwcpu_registers *cpureg =
  199. (struct kwcpu_registers *)KW_CPU_REG_BASE;
  200. /* Linux expects` the internal registers to be at 0xf1000000 */
  201. writel(KW_REGS_PHY_BASE, KW_OFFSET_REG);
  202. /* Enable and invalidate L2 cache in write through mode */
  203. writel(readl(&cpureg->l2_cfg) | 0x18, &cpureg->l2_cfg);
  204. invalidate_l2_cache();
  205. kw_config_adr_windows();
  206. #ifdef CONFIG_KIRKWOOD_RGMII_PAD_1V8
  207. /*
  208. * Configures the I/O voltage of the pads connected to Egigabit
  209. * Ethernet interface to 1.8V
  210. * By defult it is set to 3.3V
  211. */
  212. reg = readl(KW_REG_MPP_OUT_DRV_REG);
  213. reg |= (1 << 7);
  214. writel(reg, KW_REG_MPP_OUT_DRV_REG);
  215. #endif
  216. #ifdef CONFIG_KIRKWOOD_EGIGA_INIT
  217. /*
  218. * Set egiga port0/1 in normal functional mode
  219. * This is required becasue on kirkwood by default ports are in reset mode
  220. * OS egiga driver may not have provision to set them in normal mode
  221. * and if u-boot is build without network support, network may fail at OS level
  222. */
  223. reg = readl(KWGBE_PORT_SERIAL_CONTROL1_REG(0));
  224. reg &= ~(1 << 4); /* Clear PortReset Bit */
  225. writel(reg, (KWGBE_PORT_SERIAL_CONTROL1_REG(0)));
  226. reg = readl(KWGBE_PORT_SERIAL_CONTROL1_REG(1));
  227. reg &= ~(1 << 4); /* Clear PortReset Bit */
  228. writel(reg, (KWGBE_PORT_SERIAL_CONTROL1_REG(1)));
  229. #endif
  230. #ifdef CONFIG_KIRKWOOD_PCIE_INIT
  231. /*
  232. * Enable PCI Express Port0
  233. */
  234. reg = readl(&cpureg->ctrl_stat);
  235. reg |= (1 << 0); /* Set PEX0En Bit */
  236. writel(reg, &cpureg->ctrl_stat);
  237. #endif
  238. return 0;
  239. }
  240. #endif /* CONFIG_ARCH_CPU_INIT */
  241. /*
  242. * SOC specific misc init
  243. */
  244. #if defined(CONFIG_ARCH_MISC_INIT)
  245. int arch_misc_init(void)
  246. {
  247. volatile u32 temp;
  248. /*CPU streaming & write allocate */
  249. temp = readfr_extra_feature_reg();
  250. temp &= ~(1 << 28); /* disable wr alloc */
  251. writefr_extra_feature_reg(temp);
  252. temp = readfr_extra_feature_reg();
  253. temp &= ~(1 << 29); /* streaming disabled */
  254. writefr_extra_feature_reg(temp);
  255. /* L2Cache settings */
  256. temp = readfr_extra_feature_reg();
  257. /* Disable L2C pre fetch - Set bit 24 */
  258. temp |= (1 << 24);
  259. /* enable L2C - Set bit 22 */
  260. temp |= (1 << 22);
  261. writefr_extra_feature_reg(temp);
  262. icache_enable();
  263. /* Change reset vector to address 0x0 */
  264. temp = get_cr();
  265. set_cr(temp & ~CR_V);
  266. return 0;
  267. }
  268. #endif /* CONFIG_ARCH_MISC_INIT */
  269. #ifdef CONFIG_KIRKWOOD_EGIGA
  270. int cpu_eth_init(bd_t *bis)
  271. {
  272. kirkwood_egiga_initialize(bis);
  273. return 0;
  274. }
  275. #endif