cpu.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  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. #include <hush.h>
  30. #define BUFLEN 16
  31. void reset_cpu(unsigned long ignored)
  32. {
  33. struct kwcpu_registers *cpureg =
  34. (struct kwcpu_registers *)KW_CPU_REG_BASE;
  35. writel(readl(&cpureg->rstoutn_mask) | (1 << 2),
  36. &cpureg->rstoutn_mask);
  37. writel(readl(&cpureg->sys_soft_rst) | 1,
  38. &cpureg->sys_soft_rst);
  39. while (1) ;
  40. }
  41. /*
  42. * Generates Ramdom hex number reading some time varient system registers
  43. * and using md5 algorithm
  44. */
  45. unsigned char get_random_hex(void)
  46. {
  47. int i;
  48. u32 inbuf[BUFLEN];
  49. u8 outbuf[BUFLEN];
  50. /*
  51. * in case of 88F6281/88F6192 A0,
  52. * Bit7 need to reset to generate random values in KW_REG_UNDOC_0x1470
  53. * Soc reg offsets KW_REG_UNDOC_0x1470 and KW_REG_UNDOC_0x1478 are reserved regs and
  54. * Does not have names at this moment (no errata available)
  55. */
  56. writel(readl(KW_REG_UNDOC_0x1478) & ~(1 << 7), KW_REG_UNDOC_0x1478);
  57. for (i = 0; i < BUFLEN; i++) {
  58. inbuf[i] = readl(KW_REG_UNDOC_0x1470);
  59. }
  60. md5((u8 *) inbuf, (BUFLEN * sizeof(u32)), outbuf);
  61. return outbuf[outbuf[7] % 0x0f];
  62. }
  63. /*
  64. * Window Size
  65. * Used with the Base register to set the address window size and location.
  66. * Must be programmed from LSB to MSB as sequence of ones followed by
  67. * sequence of zeros. The number of ones specifies the size of the window in
  68. * 64 KByte granularity (e.g., a value of 0x00FF specifies 256 = 16 MByte).
  69. * NOTE: A value of 0x0 specifies 64-KByte size.
  70. */
  71. unsigned int kw_winctrl_calcsize(unsigned int sizeval)
  72. {
  73. int i;
  74. unsigned int j = 0;
  75. u32 val = sizeval >> 1;
  76. for (i = 0; val > 0x10000; i++) {
  77. j |= (1 << i);
  78. val = val >> 1;
  79. }
  80. return (0x0000ffff & j);
  81. }
  82. /*
  83. * kw_config_adr_windows - Configure address Windows
  84. *
  85. * There are 8 address windows supported by Kirkwood Soc to addess different
  86. * devices. Each window can be configured for size, BAR and remap addr
  87. * Below configuration is standard for most of the cases
  88. *
  89. * If remap function not used, remap_lo must be set as base
  90. *
  91. * Reference Documentation:
  92. * Mbus-L to Mbus Bridge Registers Configuration.
  93. * (Sec 25.1 and 25.3 of Datasheet)
  94. */
  95. int kw_config_adr_windows(void)
  96. {
  97. struct kwwin_registers *winregs =
  98. (struct kwwin_registers *)KW_CPU_WIN_BASE;
  99. /* Window 0: PCIE MEM address space */
  100. writel(KWCPU_WIN_CTRL_DATA(1024 * 1024 * 256, KWCPU_TARGET_PCIE,
  101. KWCPU_ATTR_PCIE_MEM, KWCPU_WIN_ENABLE), &winregs[0].ctrl);
  102. writel(KW_DEFADR_PCI_MEM, &winregs[0].base);
  103. writel(KW_DEFADR_PCI_MEM, &winregs[0].remap_lo);
  104. writel(0x0, &winregs[0].remap_hi);
  105. /* Window 1: PCIE IO address space */
  106. writel(KWCPU_WIN_CTRL_DATA(1024 * 64, KWCPU_TARGET_PCIE,
  107. KWCPU_ATTR_PCIE_IO, KWCPU_WIN_ENABLE), &winregs[1].ctrl);
  108. writel(KW_DEFADR_PCI_IO, &winregs[1].base);
  109. writel(KW_DEFADR_PCI_IO_REMAP, &winregs[1].remap_lo);
  110. writel(0x0, &winregs[1].remap_hi);
  111. /* Window 2: NAND Flash address space */
  112. writel(KWCPU_WIN_CTRL_DATA(1024 * 1024 * 128, KWCPU_TARGET_MEMORY,
  113. KWCPU_ATTR_NANDFLASH, KWCPU_WIN_ENABLE), &winregs[2].ctrl);
  114. writel(KW_DEFADR_NANDF, &winregs[2].base);
  115. writel(KW_DEFADR_NANDF, &winregs[2].remap_lo);
  116. writel(0x0, &winregs[2].remap_hi);
  117. /* Window 3: SPI Flash address space */
  118. writel(KWCPU_WIN_CTRL_DATA(1024 * 1024 * 128, KWCPU_TARGET_MEMORY,
  119. KWCPU_ATTR_SPIFLASH, KWCPU_WIN_ENABLE), &winregs[3].ctrl);
  120. writel(KW_DEFADR_SPIF, &winregs[3].base);
  121. writel(KW_DEFADR_SPIF, &winregs[3].remap_lo);
  122. writel(0x0, &winregs[3].remap_hi);
  123. /* Window 4: BOOT Memory address space */
  124. writel(KWCPU_WIN_CTRL_DATA(1024 * 1024 * 128, KWCPU_TARGET_MEMORY,
  125. KWCPU_ATTR_BOOTROM, KWCPU_WIN_ENABLE), &winregs[4].ctrl);
  126. writel(KW_DEFADR_BOOTROM, &winregs[4].base);
  127. /* Window 5: Security SRAM address space */
  128. writel(KWCPU_WIN_CTRL_DATA(1024 * 64, KWCPU_TARGET_SASRAM,
  129. KWCPU_ATTR_SASRAM, KWCPU_WIN_ENABLE), &winregs[5].ctrl);
  130. writel(KW_DEFADR_SASRAM, &winregs[5].base);
  131. /* Window 6-7: Disabled */
  132. writel(KWCPU_WIN_DISABLE, &winregs[6].ctrl);
  133. writel(KWCPU_WIN_DISABLE, &winregs[7].ctrl);
  134. return 0;
  135. }
  136. /*
  137. * kw_config_gpio - GPIO configuration
  138. */
  139. void kw_config_gpio(u32 gpp0_oe_val, u32 gpp1_oe_val, u32 gpp0_oe, u32 gpp1_oe)
  140. {
  141. struct kwgpio_registers *gpio0reg =
  142. (struct kwgpio_registers *)KW_GPIO0_BASE;
  143. struct kwgpio_registers *gpio1reg =
  144. (struct kwgpio_registers *)KW_GPIO1_BASE;
  145. /* Init GPIOS to default values as per board requirement */
  146. writel(gpp0_oe_val, &gpio0reg->dout);
  147. writel(gpp1_oe_val, &gpio1reg->dout);
  148. writel(gpp0_oe, &gpio0reg->oe);
  149. writel(gpp1_oe, &gpio1reg->oe);
  150. }
  151. /*
  152. * kw_config_mpp - Multi-Purpose Pins Functionality configuration
  153. *
  154. * Each MPP can be configured to different functionality through
  155. * MPP control register, ref (sec 6.1 of kirkwood h/w specification)
  156. *
  157. * There are maximum 64 Multi-Pourpose Pins on Kirkwood
  158. * Each MPP functionality can be configuration by a 4bit value
  159. * of MPP control reg, the value and associated functionality depends
  160. * upon used SoC varient
  161. */
  162. int kw_config_mpp(u32 mpp0_7, u32 mpp8_15, u32 mpp16_23, u32 mpp24_31,
  163. u32 mpp32_39, u32 mpp40_47, u32 mpp48_55)
  164. {
  165. u32 *mppreg = (u32 *) KW_MPP_BASE;
  166. /* program mpp registers */
  167. writel(mpp0_7, &mppreg[0]);
  168. writel(mpp8_15, &mppreg[1]);
  169. writel(mpp16_23, &mppreg[2]);
  170. writel(mpp24_31, &mppreg[3]);
  171. writel(mpp32_39, &mppreg[4]);
  172. writel(mpp40_47, &mppreg[5]);
  173. writel(mpp48_55, &mppreg[6]);
  174. return 0;
  175. }
  176. /*
  177. * SYSRSTn Duration Counter Support
  178. *
  179. * Kirkwood SoC implements a hardware-based SYSRSTn duration counter.
  180. * When SYSRSTn is asserted low, a SYSRSTn duration counter is running.
  181. * The SYSRSTn duration counter is useful for implementing a manufacturer
  182. * or factory reset. Upon a long reset assertion that is greater than a
  183. * pre-configured environment variable value for sysrstdelay,
  184. * The counter value is stored in the SYSRSTn Length Counter Register
  185. * The counter is based on the 25-MHz reference clock (40ns)
  186. * It is a 29-bit counter, yielding a maximum counting duration of
  187. * 2^29/25 MHz (21.4 seconds). When the counter reach its maximum value,
  188. * it remains at this value until counter reset is triggered by setting
  189. * bit 31 of KW_REG_SYSRST_CNT
  190. */
  191. static void kw_sysrst_action(void)
  192. {
  193. int ret;
  194. char *s = getenv("sysrstcmd");
  195. if (!s) {
  196. debug("Error.. %s failed, check sysrstcmd\n",
  197. __FUNCTION__);
  198. return;
  199. }
  200. debug("Starting %s process...\n", __FUNCTION__);
  201. #if !defined(CONFIG_SYS_HUSH_PARSER)
  202. ret = run_command (s, 0);
  203. #else
  204. ret = parse_string_outer(s, FLAG_PARSE_SEMICOLON
  205. | FLAG_EXIT_FROM_LOOP);
  206. #endif
  207. if (ret < 0)
  208. debug("Error.. %s failed\n", __FUNCTION__);
  209. else
  210. debug("%s process finished\n", __FUNCTION__);
  211. }
  212. static void kw_sysrst_check(void)
  213. {
  214. u32 sysrst_cnt, sysrst_dly;
  215. char *s;
  216. /*
  217. * no action if sysrstdelay environment variable is not defined
  218. */
  219. s = getenv("sysrstdelay");
  220. if (s == NULL)
  221. return;
  222. /* read sysrstdelay value */
  223. sysrst_dly = (u32) simple_strtoul(s, NULL, 10);
  224. /* read SysRst Length counter register (bits 28:0) */
  225. sysrst_cnt = (0x1fffffff & readl(KW_REG_SYSRST_CNT));
  226. debug("H/w Rst hold time: %d.%d secs\n",
  227. sysrst_cnt / SYSRST_CNT_1SEC_VAL,
  228. sysrst_cnt % SYSRST_CNT_1SEC_VAL);
  229. /* clear the counter for next valid read*/
  230. writel(1 << 31, KW_REG_SYSRST_CNT);
  231. /*
  232. * sysrst_action:
  233. * if H/w Reset key is pressed and hold for time
  234. * more than sysrst_dly in seconds
  235. */
  236. if (sysrst_cnt >= SYSRST_CNT_1SEC_VAL * sysrst_dly)
  237. kw_sysrst_action();
  238. }
  239. #if defined(CONFIG_DISPLAY_CPUINFO)
  240. int print_cpuinfo(void)
  241. {
  242. char *name = "Unknown";
  243. switch (readl(KW_REG_DEVICE_ID) & 0x03) {
  244. case 1:
  245. name = "88F6192_A0";
  246. break;
  247. case 2:
  248. name = "88F6281_A0";
  249. break;
  250. default:
  251. printf("SoC: Unsupported Kirkwood\n");
  252. return -1;
  253. }
  254. printf("SoC: Kirkwood %s\n", name);
  255. return 0;
  256. }
  257. #endif /* CONFIG_DISPLAY_CPUINFO */
  258. #ifdef CONFIG_ARCH_CPU_INIT
  259. int arch_cpu_init(void)
  260. {
  261. u32 reg;
  262. struct kwcpu_registers *cpureg =
  263. (struct kwcpu_registers *)KW_CPU_REG_BASE;
  264. /* Linux expects` the internal registers to be at 0xf1000000 */
  265. writel(KW_REGS_PHY_BASE, KW_OFFSET_REG);
  266. /* Enable and invalidate L2 cache in write through mode */
  267. writel(readl(&cpureg->l2_cfg) | 0x18, &cpureg->l2_cfg);
  268. invalidate_l2_cache();
  269. kw_config_adr_windows();
  270. #ifdef CONFIG_KIRKWOOD_RGMII_PAD_1V8
  271. /*
  272. * Configures the I/O voltage of the pads connected to Egigabit
  273. * Ethernet interface to 1.8V
  274. * By defult it is set to 3.3V
  275. */
  276. reg = readl(KW_REG_MPP_OUT_DRV_REG);
  277. reg |= (1 << 7);
  278. writel(reg, KW_REG_MPP_OUT_DRV_REG);
  279. #endif
  280. #ifdef CONFIG_KIRKWOOD_EGIGA_INIT
  281. /*
  282. * Set egiga port0/1 in normal functional mode
  283. * This is required becasue on kirkwood by default ports are in reset mode
  284. * OS egiga driver may not have provision to set them in normal mode
  285. * and if u-boot is build without network support, network may fail at OS level
  286. */
  287. reg = readl(KWGBE_PORT_SERIAL_CONTROL1_REG(0));
  288. reg &= ~(1 << 4); /* Clear PortReset Bit */
  289. writel(reg, (KWGBE_PORT_SERIAL_CONTROL1_REG(0)));
  290. reg = readl(KWGBE_PORT_SERIAL_CONTROL1_REG(1));
  291. reg &= ~(1 << 4); /* Clear PortReset Bit */
  292. writel(reg, (KWGBE_PORT_SERIAL_CONTROL1_REG(1)));
  293. #endif
  294. #ifdef CONFIG_KIRKWOOD_PCIE_INIT
  295. /*
  296. * Enable PCI Express Port0
  297. */
  298. reg = readl(&cpureg->ctrl_stat);
  299. reg |= (1 << 0); /* Set PEX0En Bit */
  300. writel(reg, &cpureg->ctrl_stat);
  301. #endif
  302. return 0;
  303. }
  304. #endif /* CONFIG_ARCH_CPU_INIT */
  305. /*
  306. * SOC specific misc init
  307. */
  308. #if defined(CONFIG_ARCH_MISC_INIT)
  309. int arch_misc_init(void)
  310. {
  311. volatile u32 temp;
  312. /*CPU streaming & write allocate */
  313. temp = readfr_extra_feature_reg();
  314. temp &= ~(1 << 28); /* disable wr alloc */
  315. writefr_extra_feature_reg(temp);
  316. temp = readfr_extra_feature_reg();
  317. temp &= ~(1 << 29); /* streaming disabled */
  318. writefr_extra_feature_reg(temp);
  319. /* L2Cache settings */
  320. temp = readfr_extra_feature_reg();
  321. /* Disable L2C pre fetch - Set bit 24 */
  322. temp |= (1 << 24);
  323. /* enable L2C - Set bit 22 */
  324. temp |= (1 << 22);
  325. writefr_extra_feature_reg(temp);
  326. icache_enable();
  327. /* Change reset vector to address 0x0 */
  328. temp = get_cr();
  329. set_cr(temp & ~CR_V);
  330. /* checks and execute resset to factory event */
  331. kw_sysrst_check();
  332. return 0;
  333. }
  334. #endif /* CONFIG_ARCH_MISC_INIT */
  335. #ifdef CONFIG_MVGBE
  336. int cpu_eth_init(bd_t *bis)
  337. {
  338. mvgbe_initialize(bis);
  339. return 0;
  340. }
  341. #endif