ox820.c 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. #include <common.h>
  2. #include <spl.h>
  3. #include <phy.h>
  4. #include <netdev.h>
  5. #include <ide.h>
  6. #include <nand.h>
  7. #include <asm/arch/spl.h>
  8. #include <asm/arch/pinmux.h>
  9. #include <asm/arch/clock.h>
  10. #include <asm/arch/sysctl.h>
  11. DECLARE_GLOBAL_DATA_PTR;
  12. #ifdef CONFIG_SPL_BUILD
  13. #ifdef DEBUG
  14. #define DILIGENCE (1048576/4)
  15. static int test_memory(u32 memory)
  16. {
  17. volatile u32 *read;
  18. volatile u32 *write;
  19. const u32 INIT_PATTERN = 0xAA55AA55;
  20. const u32 INC_PATTERN = 0x01030507;
  21. u32 pattern;
  22. int check;
  23. int i;
  24. check = 0;
  25. read = write = (volatile u32 *) memory;
  26. pattern = INIT_PATTERN;
  27. for (i = 0; i < DILIGENCE; i++) {
  28. *write++ = pattern;
  29. pattern += INC_PATTERN;
  30. }
  31. puts("testing\n");
  32. pattern = INIT_PATTERN;
  33. for (i = 0; i < DILIGENCE; i++) {
  34. check += (pattern == *read++) ? 1 : 0;
  35. pattern += INC_PATTERN;
  36. }
  37. return (check == DILIGENCE) ? 0 : -1;
  38. }
  39. #endif
  40. void uart_init(void)
  41. {
  42. /* Reset UART1 */
  43. reset_block(SYS_CTRL_RST_UART1, 1);
  44. udelay(100);
  45. reset_block(SYS_CTRL_RST_UART1, 0);
  46. udelay(100);
  47. /* Setup pin mux'ing for UART1 */
  48. pinmux_set(PINMUX_BANK_MFA, 30, PINMUX_UARTA_SIN);
  49. pinmux_set(PINMUX_BANK_MFA, 31, PINMUX_UARTA_SOUT);
  50. }
  51. extern void init_ddr(int mhz);
  52. void board_inithw(void)
  53. {
  54. int plla_freq;
  55. #ifdef DEBUG
  56. int i;
  57. #endif /* DEBUG */
  58. timer_init();
  59. uart_init();
  60. preloader_console_init();
  61. plla_freq = plla_set_config(CONFIG_PLLA_FREQ_MHZ);
  62. init_ddr(plla_freq);
  63. #ifdef DEBUG
  64. if(test_memory(CONFIG_SYS_SDRAM_BASE)) {
  65. puts("memory test failed\n");
  66. } else {
  67. puts("memory test done\n");
  68. }
  69. #endif /* DEBUG */
  70. #ifdef CONFIG_SPL_BSS_DRAM_START
  71. extern char __bss_dram_start[];
  72. extern char __bss_dram_end[];
  73. memset(&__bss_dram_start, 0, __bss_dram_end - __bss_dram_start);
  74. #endif
  75. }
  76. void board_init_f(ulong dummy)
  77. {
  78. /* Set the stack pointer. */
  79. asm volatile("mov sp, %0\n" : : "r"(CONFIG_SPL_STACK));
  80. /* Clear the BSS. */
  81. memset(__bss_start, 0, __bss_end - __bss_start);
  82. /* Set global data pointer. */
  83. gd = &gdata;
  84. board_inithw();
  85. board_init_r(NULL, 0);
  86. }
  87. u32 spl_boot_device(void)
  88. {
  89. return CONFIG_SPL_BOOT_DEVICE;
  90. }
  91. #ifdef CONFIG_SPL_BLOCK_SUPPORT
  92. void spl_block_device_init(void)
  93. {
  94. ide_init();
  95. }
  96. #endif
  97. #ifdef CONFIG_SPL_OS_BOOT
  98. int spl_start_uboot(void)
  99. {
  100. /* break into full u-boot on 'c' */
  101. return (serial_tstc() && serial_getc() == 'c');
  102. }
  103. #endif
  104. void spl_display_print(void)
  105. {
  106. /* print a hint, so that we will not use the wrong SPL by mistake */
  107. puts(" Boot device: " BOOT_DEVICE_TYPE "\n" );
  108. }
  109. void lowlevel_init(void)
  110. {
  111. }
  112. #ifdef USE_DL_PREFIX
  113. /* quick and dirty memory allocation */
  114. static ulong next_mem = CONFIG_SPL_MALLOC_START;
  115. void *memalign(size_t alignment, size_t bytes)
  116. {
  117. ulong mem = ALIGN(next_mem, alignment);
  118. next_mem = mem + bytes;
  119. if (next_mem > CONFIG_SYS_SDRAM_BASE + CONFIG_MIN_SDRAM_SIZE) {
  120. printf("spl: out of memory\n");
  121. hang();
  122. }
  123. return (void *)mem;
  124. }
  125. void free(void* mem)
  126. {
  127. }
  128. #endif
  129. #endif /* CONFIG_SPL_BUILD */
  130. int board_early_init_f(void)
  131. {
  132. return 0;
  133. }
  134. #define STATIC_CTL_BANK0 (STATIC_CONTROL_BASE + 4)
  135. #define STATIC_READ_CYCLE_SHIFT 0
  136. #define STATIC_DELAYED_OE (1 << 7)
  137. #define STATIC_WRITE_CYCLE_SHIFT 8
  138. #define STATIC_WRITE_PULSE_SHIFT 16
  139. #define STATIC_WRITE_BURST_EN (1 << 23)
  140. #define STATIC_TURN_AROUND_SHIFT 24
  141. #define STATIC_BUFFER_PRESENT (1 << 28)
  142. #define STATIC_READ_BURST_EN (1 << 29)
  143. #define STATIC_BUS_WIDTH8 (0 << 30)
  144. #define STATIC_BUS_WIDTH16 (1 << 30)
  145. #define STATIC_BUS_WIDTH32 (2 << 30)
  146. void nand_hwcontrol(struct mtd_info *mtd, int cmd, unsigned int ctrl)
  147. {
  148. struct nand_chip *this = mtd->priv;
  149. unsigned long nandaddr = (unsigned long) this->IO_ADDR_W;
  150. if (ctrl & NAND_CTRL_CHANGE) {
  151. nandaddr &= ~(BIT(NAND_ALE_ADDR_PIN) | BIT(NAND_CLE_ADDR_PIN));
  152. if (ctrl & NAND_CLE)
  153. nandaddr |= BIT(NAND_CLE_ADDR_PIN);
  154. else if (ctrl & NAND_ALE)
  155. nandaddr |= BIT(NAND_ALE_ADDR_PIN);
  156. this->IO_ADDR_W = (void __iomem *) nandaddr;
  157. }
  158. if (cmd != NAND_CMD_NONE)
  159. writeb(cmd, (void __iomem *) nandaddr);
  160. }
  161. #if defined(CONFIG_SPL_BUILD) && defined(CONFIG_BOOT_FROM_NAND)
  162. int nand_dev_ready(struct mtd_info *mtd)
  163. {
  164. struct nand_chip *chip = mtd->priv;
  165. udelay(chip->chip_delay);
  166. return 1;
  167. }
  168. void nand_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
  169. {
  170. int i;
  171. struct nand_chip *chip = mtd->priv;
  172. for (i = 0; i < len; i++)
  173. buf[i] = readb(chip->IO_ADDR_R);
  174. }
  175. void nand_dev_reset(struct nand_chip *chip)
  176. {
  177. writeb(NAND_CMD_RESET, chip->IO_ADDR_W + BIT(NAND_CLE_ADDR_PIN));
  178. udelay(chip->chip_delay);
  179. writeb(NAND_CMD_STATUS, chip->IO_ADDR_W + BIT(NAND_CLE_ADDR_PIN));
  180. while (!(readb(chip->IO_ADDR_R) & NAND_STATUS_READY)) {
  181. ;
  182. }
  183. }
  184. #else
  185. #define nand_dev_reset(chip) /* framework will reset the chip anyway */
  186. #define nand_read_buf NULL /* framework will provide a default one */
  187. #define nand_dev_ready NULL /* dev_ready is optional */
  188. #endif
  189. int board_nand_init(struct nand_chip *chip)
  190. {
  191. /* Block reset Static core */
  192. reset_block(SYS_CTRL_RST_STATIC, 1);
  193. reset_block(SYS_CTRL_RST_STATIC, 0);
  194. /* Enable clock to Static core */
  195. enable_clock(SYS_CTRL_CLK_STATIC);
  196. /* enable flash support on static bus.
  197. * Enable static bus onto GPIOs, only CS0 */
  198. pinmux_set(PINMUX_BANK_MFA, 12, PINMUX_STATIC_DATA0);
  199. pinmux_set(PINMUX_BANK_MFA, 13, PINMUX_STATIC_DATA1);
  200. pinmux_set(PINMUX_BANK_MFA, 14, PINMUX_STATIC_DATA2);
  201. pinmux_set(PINMUX_BANK_MFA, 15, PINMUX_STATIC_DATA3);
  202. pinmux_set(PINMUX_BANK_MFA, 16, PINMUX_STATIC_DATA4);
  203. pinmux_set(PINMUX_BANK_MFA, 17, PINMUX_STATIC_DATA5);
  204. pinmux_set(PINMUX_BANK_MFA, 18, PINMUX_STATIC_DATA6);
  205. pinmux_set(PINMUX_BANK_MFA, 19, PINMUX_STATIC_DATA7);
  206. pinmux_set(PINMUX_BANK_MFA, 20, PINMUX_STATIC_NWE);
  207. pinmux_set(PINMUX_BANK_MFA, 21, PINMUX_STATIC_NOE);
  208. pinmux_set(PINMUX_BANK_MFA, 22, PINMUX_STATIC_NCS);
  209. pinmux_set(PINMUX_BANK_MFA, 23, PINMUX_STATIC_ADDR18);
  210. pinmux_set(PINMUX_BANK_MFA, 24, PINMUX_STATIC_ADDR19);
  211. /* Setup the static bus CS0 to access FLASH */
  212. writel((0x3f << STATIC_READ_CYCLE_SHIFT)
  213. | (0x3f << STATIC_WRITE_CYCLE_SHIFT)
  214. | (0x1f << STATIC_WRITE_PULSE_SHIFT)
  215. | (0x03 << STATIC_TURN_AROUND_SHIFT) |
  216. STATIC_BUS_WIDTH16,
  217. STATIC_CTL_BANK0);
  218. chip->cmd_ctrl = nand_hwcontrol;
  219. chip->ecc.mode = NAND_ECC_SOFT;
  220. chip->chip_delay = 30;
  221. chip->dev_ready = nand_dev_ready;
  222. chip->read_buf = nand_read_buf;
  223. nand_dev_reset(chip);
  224. return 0;
  225. }
  226. int board_init(void)
  227. {
  228. gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
  229. gd->bd->bi_arch_number = MACH_TYPE_OXNAS;
  230. /* assume uart is already initialized by SPL */
  231. #if defined(CONFIG_START_IDE)
  232. puts("IDE: ");
  233. ide_init();
  234. #endif
  235. return 0;
  236. }
  237. /* copied from board/evb64260/sdram_init.c */
  238. /*
  239. * Check memory range for valid RAM. A simple memory test determines
  240. * the actually available RAM size between addresses `base' and
  241. * `base + maxsize'. Some (not all) hardware errors are detected:
  242. * - short between address lines
  243. * - short between data lines
  244. */
  245. static long int dram_size (long int *base, long int maxsize)
  246. {
  247. volatile long int *addr, *b = base;
  248. long int cnt, val, save1, save2;
  249. #define STARTVAL (CONFIG_MIN_SDRAM_SIZE / 2) /* start test at half size */
  250. for (cnt = STARTVAL / sizeof (long); cnt < maxsize / sizeof (long);
  251. cnt <<= 1) {
  252. addr = base + cnt; /* pointer arith! */
  253. save1 = *addr; /* save contents of addr */
  254. save2 = *b; /* save contents of base */
  255. *addr = cnt; /* write cnt to addr */
  256. *b = 0; /* put null at base */
  257. /* check at base address */
  258. if ((*b) != 0) {
  259. *addr = save1; /* restore *addr */
  260. *b = save2; /* restore *b */
  261. return (0);
  262. }
  263. val = *addr; /* read *addr */
  264. *addr = save1;
  265. *b = save2;
  266. if (val != cnt) {
  267. /* fix boundary condition.. STARTVAL means zero */
  268. if (cnt == STARTVAL / sizeof (long))
  269. cnt = 0;
  270. return (cnt * sizeof (long));
  271. }
  272. }
  273. return maxsize;
  274. }
  275. int dram_init(void)
  276. {
  277. gd->ram_size = dram_size((long int *)CONFIG_SYS_SDRAM_BASE,
  278. CONFIG_MAX_SDRAM_SIZE);
  279. return 0;
  280. }
  281. int board_eth_init(bd_t *bis)
  282. {
  283. u32 value;
  284. /* set the pin multiplexers to enable talking to Ethernent Phys */
  285. pinmux_set(PINMUX_BANK_MFA, 3, PINMUX_MACA_MDC);
  286. pinmux_set(PINMUX_BANK_MFA, 4, PINMUX_MACA_MDIO);
  287. // Ensure the MAC block is properly reset
  288. reset_block(SYS_CTRL_RST_MAC, 1);
  289. udelay(10);
  290. reset_block(SYS_CTRL_RST_MAC, 0);
  291. // Enable the clock to the MAC block
  292. enable_clock(SYS_CTRL_CLK_MAC);
  293. value = readl(SYS_CTRL_GMAC_CTRL);
  294. /* Use simple mux for 25/125 Mhz clock switching */
  295. value |= BIT(SYS_CTRL_GMAC_SIMPLE_MUX);
  296. /* Enable GMII_GTXCLK to follow GMII_REFCLK - required for gigabit PHY */
  297. value |= BIT(SYS_CTRL_GMAC_CKEN_GTX);
  298. /* set auto tx speed */
  299. value |= BIT(SYS_CTRL_GMAC_AUTOSPEED);
  300. writel(value, SYS_CTRL_GMAC_CTRL);
  301. return designware_initialize(MAC_BASE, PHY_INTERFACE_MODE_RGMII);
  302. }