evb64260.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  1. /*
  2. * (C) Copyright 2001
  3. * Josh Huber <huber@mclx.com>, Mission Critical Linux, Inc.
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. /*
  24. * evb64260.c - main board support/init for the Galileo Eval board.
  25. */
  26. #include <common.h>
  27. #include <74xx_7xx.h>
  28. #include <galileo/memory.h>
  29. #include <galileo/pci.h>
  30. #include <galileo/gt64260R.h>
  31. #include <net.h>
  32. #include <asm/io.h>
  33. #include "eth.h"
  34. #include "mpsc.h"
  35. #include "i2c.h"
  36. #include "64260.h"
  37. DECLARE_GLOBAL_DATA_PTR;
  38. #ifdef CONFIG_ZUMA_V2
  39. extern void zuma_mbox_init(void);
  40. #endif
  41. #undef DEBUG
  42. #define MAP_PCI
  43. #ifdef DEBUG
  44. #define DP(x) x
  45. #else
  46. #define DP(x)
  47. #endif
  48. /* ------------------------------------------------------------------------- */
  49. /* this is the current GT register space location */
  50. /* it starts at CFG_DFL_GT_REGS but moves later to CFG_GT_REGS */
  51. /* Unfortunately, we cant change it while we are in flash, so we initialize it
  52. * to the "final" value. This means that any debug_led calls before
  53. * board_early_init_f wont work right (like in cpu_init_f).
  54. * See also my_remap_gt_regs below. (NTL)
  55. */
  56. unsigned int INTERNAL_REG_BASE_ADDR = CFG_GT_REGS;
  57. /* ------------------------------------------------------------------------- */
  58. /*
  59. * This is a version of the GT register space remapping function that
  60. * doesn't touch globals (meaning, it's ok to run from flash.)
  61. *
  62. * Unfortunately, this has the side effect that a writable
  63. * INTERNAL_REG_BASE_ADDR is impossible. Oh well.
  64. */
  65. void
  66. my_remap_gt_regs(u32 cur_loc, u32 new_loc)
  67. {
  68. u32 temp;
  69. /* check and see if it's already moved */
  70. temp = in_le32((u32 *)(new_loc + INTERNAL_SPACE_DECODE));
  71. if ((temp & 0xffff) == new_loc >> 20)
  72. return;
  73. temp = (in_le32((u32 *)(cur_loc + INTERNAL_SPACE_DECODE)) &
  74. 0xffff0000) | (new_loc >> 20);
  75. out_le32((u32 *)(cur_loc + INTERNAL_SPACE_DECODE), temp);
  76. while (GTREGREAD(INTERNAL_SPACE_DECODE) != temp);
  77. }
  78. static void
  79. gt_pci_config(void)
  80. {
  81. /* move PCI stuff out of the way - NTL */
  82. /* map PCI Host 0 */
  83. pciMapSpace(PCI_HOST0, PCI_REGION0, CFG_PCI0_0_MEM_SPACE,
  84. CFG_PCI0_0_MEM_SPACE, CFG_PCI0_MEM_SIZE);
  85. pciMapSpace(PCI_HOST0, PCI_REGION1, 0, 0, 0);
  86. pciMapSpace(PCI_HOST0, PCI_REGION2, 0, 0, 0);
  87. pciMapSpace(PCI_HOST0, PCI_REGION3, 0, 0, 0);
  88. pciMapSpace(PCI_HOST0, PCI_IO, CFG_PCI0_IO_SPACE_PCI,
  89. CFG_PCI0_IO_SPACE, CFG_PCI0_IO_SIZE);
  90. /* map PCI Host 1 */
  91. pciMapSpace(PCI_HOST1, PCI_REGION0, CFG_PCI1_0_MEM_SPACE,
  92. CFG_PCI1_0_MEM_SPACE, CFG_PCI1_MEM_SIZE);
  93. pciMapSpace(PCI_HOST1, PCI_REGION1, 0, 0, 0);
  94. pciMapSpace(PCI_HOST1, PCI_REGION2, 0, 0, 0);
  95. pciMapSpace(PCI_HOST1, PCI_REGION3, 0, 0, 0);
  96. pciMapSpace(PCI_HOST1, PCI_IO, CFG_PCI1_IO_SPACE_PCI,
  97. CFG_PCI1_IO_SPACE, CFG_PCI1_IO_SIZE);
  98. /* PCI interface settings */
  99. GT_REG_WRITE(PCI_0TIMEOUT_RETRY, 0xffff);
  100. GT_REG_WRITE(PCI_1TIMEOUT_RETRY, 0xffff);
  101. GT_REG_WRITE(PCI_0BASE_ADDRESS_REGISTERS_ENABLE, 0xfffff80e);
  102. GT_REG_WRITE(PCI_1BASE_ADDRESS_REGISTERS_ENABLE, 0xfffff80e);
  103. }
  104. /* Setup CPU interface paramaters */
  105. static void
  106. gt_cpu_config(void)
  107. {
  108. cpu_t cpu = get_cpu_type();
  109. ulong tmp;
  110. /* cpu configuration register */
  111. tmp = GTREGREAD(CPU_CONFIGURATION);
  112. /* set the AACK delay bit
  113. * see Res#14 */
  114. tmp |= CPU_CONF_AACK_DELAY;
  115. tmp &= ~CPU_CONF_AACK_DELAY_2; /* New RGF */
  116. /* Galileo claims this is necessary for all busses >= 100 MHz */
  117. tmp |= CPU_CONF_FAST_CLK;
  118. if (cpu == CPU_750CX) {
  119. tmp &= ~CPU_CONF_DP_VALID; /* Safer, needed for CXe. RGF */
  120. tmp &= ~CPU_CONF_AP_VALID;
  121. } else {
  122. tmp |= CPU_CONF_DP_VALID;
  123. tmp |= CPU_CONF_AP_VALID;
  124. }
  125. /* this only works with the MPX bus */
  126. tmp &= ~CPU_CONF_RD_OOO; /* Safer RGF */
  127. tmp |= CPU_CONF_PIPELINE;
  128. tmp |= CPU_CONF_TA_DELAY;
  129. GT_REG_WRITE(CPU_CONFIGURATION, tmp);
  130. /* CPU master control register */
  131. tmp = GTREGREAD(CPU_MASTER_CONTROL);
  132. tmp |= CPU_MAST_CTL_ARB_EN;
  133. if ((cpu == CPU_7400) ||
  134. (cpu == CPU_7410) ||
  135. (cpu == CPU_7450)) {
  136. tmp |= CPU_MAST_CTL_CLEAN_BLK;
  137. tmp |= CPU_MAST_CTL_FLUSH_BLK;
  138. } else {
  139. /* cleanblock must be cleared for CPUs
  140. * that do not support this command
  141. * see Res#1 */
  142. tmp &= ~CPU_MAST_CTL_CLEAN_BLK;
  143. tmp &= ~CPU_MAST_CTL_FLUSH_BLK;
  144. }
  145. GT_REG_WRITE(CPU_MASTER_CONTROL, tmp);
  146. }
  147. /*
  148. * board_early_init_f.
  149. *
  150. * set up gal. device mappings, etc.
  151. */
  152. int board_early_init_f (void)
  153. {
  154. uchar sram_boot = 0;
  155. /*
  156. * set up the GT the way the kernel wants it
  157. * the call to move the GT register space will obviously
  158. * fail if it has already been done, but we're going to assume
  159. * that if it's not at the power-on location, it's where we put
  160. * it last time. (huber)
  161. */
  162. my_remap_gt_regs(CFG_DFL_GT_REGS, CFG_GT_REGS);
  163. gt_pci_config();
  164. /* mask all external interrupt sources */
  165. GT_REG_WRITE(CPU_INTERRUPT_MASK_REGISTER_LOW, 0);
  166. GT_REG_WRITE(CPU_INTERRUPT_MASK_REGISTER_HIGH, 0);
  167. GT_REG_WRITE(PCI_0INTERRUPT_CAUSE_MASK_REGISTER_LOW, 0);
  168. GT_REG_WRITE(PCI_0INTERRUPT_CAUSE_MASK_REGISTER_HIGH, 0);
  169. GT_REG_WRITE(PCI_1INTERRUPT_CAUSE_MASK_REGISTER_LOW, 0);
  170. GT_REG_WRITE(PCI_1INTERRUPT_CAUSE_MASK_REGISTER_HIGH, 0);
  171. GT_REG_WRITE(CPU_INT_0_MASK, 0);
  172. GT_REG_WRITE(CPU_INT_1_MASK, 0);
  173. GT_REG_WRITE(CPU_INT_2_MASK, 0);
  174. GT_REG_WRITE(CPU_INT_3_MASK, 0);
  175. /* now, onto the configuration */
  176. GT_REG_WRITE(SDRAM_CONFIGURATION, CFG_SDRAM_CONFIG);
  177. /* ----- DEVICE BUS SETTINGS ------ */
  178. /*
  179. * EVB
  180. * 0 - SRAM
  181. * 1 - RTC
  182. * 2 - UART
  183. * 3 - Flash
  184. * boot - BootCS
  185. *
  186. * Zuma
  187. * 0 - Flash
  188. * boot - BootCS
  189. */
  190. /*
  191. * the dual 7450 module requires burst access to the boot
  192. * device, so the serial rom copies the boot device to the
  193. * on-board sram on the eval board, and updates the correct
  194. * registers to boot from the sram. (device0)
  195. */
  196. #if defined(CONFIG_ZUMA_V2) || defined(CONFIG_P3G4)
  197. /* Zuma has no SRAM */
  198. sram_boot = 0;
  199. #else
  200. if (memoryGetDeviceBaseAddress(DEVICE0) && 0xfff00000 == CFG_MONITOR_BASE)
  201. sram_boot = 1;
  202. #endif
  203. if (!sram_boot)
  204. memoryMapDeviceSpace(DEVICE0, CFG_DEV0_SPACE, CFG_DEV0_SIZE);
  205. memoryMapDeviceSpace(DEVICE1, CFG_DEV1_SPACE, CFG_DEV1_SIZE);
  206. memoryMapDeviceSpace(DEVICE2, CFG_DEV2_SPACE, CFG_DEV2_SIZE);
  207. memoryMapDeviceSpace(DEVICE3, CFG_DEV3_SPACE, CFG_DEV3_SIZE);
  208. /* configure device timing */
  209. #ifdef CFG_DEV0_PAR
  210. if (!sram_boot)
  211. GT_REG_WRITE(DEVICE_BANK0PARAMETERS, CFG_DEV0_PAR);
  212. #endif
  213. #ifdef CFG_DEV1_PAR
  214. GT_REG_WRITE(DEVICE_BANK1PARAMETERS, CFG_DEV1_PAR);
  215. #endif
  216. #ifdef CFG_DEV2_PAR
  217. GT_REG_WRITE(DEVICE_BANK2PARAMETERS, CFG_DEV2_PAR);
  218. #endif
  219. #ifdef CONFIG_EVB64260
  220. #ifdef CFG_32BIT_BOOT_PAR
  221. /* detect if we are booting from the 32 bit flash */
  222. if (GTREGREAD(DEVICE_BOOT_BANK_PARAMETERS) & (0x3 << 20)) {
  223. /* 32 bit boot flash */
  224. GT_REG_WRITE(DEVICE_BANK3PARAMETERS, CFG_8BIT_BOOT_PAR);
  225. GT_REG_WRITE(DEVICE_BOOT_BANK_PARAMETERS, CFG_32BIT_BOOT_PAR);
  226. } else {
  227. /* 8 bit boot flash */
  228. GT_REG_WRITE(DEVICE_BANK3PARAMETERS, CFG_32BIT_BOOT_PAR);
  229. GT_REG_WRITE(DEVICE_BOOT_BANK_PARAMETERS, CFG_8BIT_BOOT_PAR);
  230. }
  231. #else
  232. /* 8 bit boot flash only */
  233. GT_REG_WRITE(DEVICE_BOOT_BANK_PARAMETERS, CFG_8BIT_BOOT_PAR);
  234. #endif
  235. #else /* CONFIG_EVB64260 not defined */
  236. /* We are booting from 16-bit flash.
  237. */
  238. GT_REG_WRITE(DEVICE_BOOT_BANK_PARAMETERS, CFG_16BIT_BOOT_PAR);
  239. #endif
  240. gt_cpu_config();
  241. /* MPP setup */
  242. GT_REG_WRITE(MPP_CONTROL0, CFG_MPP_CONTROL_0);
  243. GT_REG_WRITE(MPP_CONTROL1, CFG_MPP_CONTROL_1);
  244. GT_REG_WRITE(MPP_CONTROL2, CFG_MPP_CONTROL_2);
  245. GT_REG_WRITE(MPP_CONTROL3, CFG_MPP_CONTROL_3);
  246. GT_REG_WRITE(GPP_LEVEL_CONTROL, CFG_GPP_LEVEL_CONTROL);
  247. GT_REG_WRITE(SERIAL_PORT_MULTIPLEX, CFG_SERIAL_PORT_MUX);
  248. return 0;
  249. }
  250. /* various things to do after relocation */
  251. int misc_init_r (void)
  252. {
  253. icache_enable();
  254. #ifdef CFG_L2
  255. l2cache_enable();
  256. #endif
  257. #ifdef CONFIG_MPSC
  258. mpsc_init2();
  259. #endif
  260. #ifdef CONFIG_ZUMA_V2
  261. zuma_mbox_init();
  262. #endif
  263. return (0);
  264. }
  265. void
  266. after_reloc(ulong dest_addr)
  267. {
  268. /* check to see if we booted from the sram. If so, move things
  269. * back to the way they should be. (we're running from main
  270. * memory at this point now */
  271. if (memoryGetDeviceBaseAddress(DEVICE0) == CFG_MONITOR_BASE) {
  272. memoryMapDeviceSpace(DEVICE0, CFG_DEV0_SPACE, CFG_DEV0_SIZE);
  273. memoryMapDeviceSpace(BOOT_DEVICE, CFG_FLASH_BASE, _1M);
  274. }
  275. /* now, jump to the main U-Boot board init code */
  276. board_init_r ((gd_t *)gd, dest_addr);
  277. /* NOTREACHED */
  278. }
  279. /* ------------------------------------------------------------------------- */
  280. /*
  281. * Check Board Identity:
  282. */
  283. int
  284. checkboard (void)
  285. {
  286. puts ("Board: " CFG_BOARD_NAME "\n");
  287. return (0);
  288. }
  289. /* utility functions */
  290. void
  291. debug_led(int led, int mode)
  292. {
  293. #if !defined(CONFIG_ZUMA_V2) && !defined(CONFIG_P3G4)
  294. volatile int *addr = NULL;
  295. int dummy;
  296. if (mode == 1) {
  297. switch (led) {
  298. case 0:
  299. addr = (int *)((unsigned int)CFG_DEV1_SPACE | 0x08000);
  300. break;
  301. case 1:
  302. addr = (int *)((unsigned int)CFG_DEV1_SPACE | 0x0c000);
  303. break;
  304. case 2:
  305. addr = (int *)((unsigned int)CFG_DEV1_SPACE | 0x10000);
  306. break;
  307. }
  308. } else if (mode == 0) {
  309. switch (led) {
  310. case 0:
  311. addr = (int *)((unsigned int)CFG_DEV1_SPACE | 0x14000);
  312. break;
  313. case 1:
  314. addr = (int *)((unsigned int)CFG_DEV1_SPACE | 0x18000);
  315. break;
  316. case 2:
  317. addr = (int *)((unsigned int)CFG_DEV1_SPACE | 0x1c000);
  318. break;
  319. }
  320. }
  321. WRITE_CHAR(addr, 0);
  322. dummy = *addr;
  323. #endif /* CONFIG_ZUMA_V2 */
  324. }
  325. void
  326. display_mem_map(void)
  327. {
  328. int i,j;
  329. unsigned int base,size,width;
  330. /* SDRAM */
  331. printf("SDRAM\n");
  332. for(i=0;i<=BANK3;i++) {
  333. base = memoryGetBankBaseAddress(i);
  334. size = memoryGetBankSize(i);
  335. if(size !=0)
  336. {
  337. printf("BANK%d: base - 0x%08x\tsize - %dM bytes\n",i,base,size>>20);
  338. }
  339. }
  340. /* CPU's PCI windows */
  341. for(i=0;i<=PCI_HOST1;i++) {
  342. printf("\nCPU's PCI %d windows\n", i);
  343. base=pciGetSpaceBase(i,PCI_IO);
  344. size=pciGetSpaceSize(i,PCI_IO);
  345. printf(" IO: base - 0x%08x\tsize - %dM bytes\n",base,size>>20);
  346. for(j=0;j<=PCI_REGION3;j++) {
  347. base = pciGetSpaceBase(i,j);
  348. size = pciGetSpaceSize(i,j);
  349. printf("MEMORY %d: base - 0x%08x\tsize - %dM bytes\n",j,base,
  350. size>>20);
  351. }
  352. }
  353. /* Devices */
  354. printf("\nDEVICES\n");
  355. for(i=0;i<=DEVICE3;i++) {
  356. base = memoryGetDeviceBaseAddress(i);
  357. size = memoryGetDeviceSize(i);
  358. width= memoryGetDeviceWidth(i) * 8;
  359. printf("DEV %d: base - 0x%08x\tsize - %dM bytes\twidth - %d bits\n",
  360. i, base, size>>20, width);
  361. }
  362. /* Bootrom */
  363. base = memoryGetDeviceBaseAddress(BOOT_DEVICE); /* Boot */
  364. size = memoryGetDeviceSize(BOOT_DEVICE);
  365. width= memoryGetDeviceWidth(BOOT_DEVICE) * 8;
  366. printf(" BOOT: base - 0x%08x\tsize - %dM bytes\twidth - %d bits\n",
  367. base, size>>20, width);
  368. }