cuboot-c2k.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /*
  2. * GEFanuc C2K platform code.
  3. *
  4. * Author: Remi Machet <rmachet@slac.stanford.edu>
  5. *
  6. * Originated from prpmc2800.c
  7. *
  8. * 2008 (c) Stanford University
  9. * 2007 (c) MontaVista, Software, Inc.
  10. *
  11. * This program is free software; you can redistribute it and/or modify it
  12. * under the terms of the GNU General Public License version 2 as published
  13. * by the Free Software Foundation.
  14. */
  15. #include "types.h"
  16. #include "stdio.h"
  17. #include "io.h"
  18. #include "ops.h"
  19. #include "elf.h"
  20. #include "gunzip_util.h"
  21. #include "mv64x60.h"
  22. #include "cuboot.h"
  23. #include "ppcboot.h"
  24. static u8 *bridge_base;
  25. static void c2k_bridge_setup(u32 mem_size)
  26. {
  27. u32 i, v[30], enables, acc_bits;
  28. u32 pci_base_hi, pci_base_lo, size, buf[2];
  29. unsigned long cpu_base;
  30. int rc;
  31. void *devp, *mv64x60_devp;
  32. u8 *bridge_pbase, is_coherent;
  33. struct mv64x60_cpu2pci_win *tbl;
  34. int bus;
  35. bridge_pbase = mv64x60_get_bridge_pbase();
  36. is_coherent = mv64x60_is_coherent();
  37. if (is_coherent)
  38. acc_bits = MV64x60_PCI_ACC_CNTL_SNOOP_WB
  39. | MV64x60_PCI_ACC_CNTL_SWAP_NONE
  40. | MV64x60_PCI_ACC_CNTL_MBURST_32_BYTES
  41. | MV64x60_PCI_ACC_CNTL_RDSIZE_32_BYTES;
  42. else
  43. acc_bits = MV64x60_PCI_ACC_CNTL_SNOOP_NONE
  44. | MV64x60_PCI_ACC_CNTL_SWAP_NONE
  45. | MV64x60_PCI_ACC_CNTL_MBURST_128_BYTES
  46. | MV64x60_PCI_ACC_CNTL_RDSIZE_256_BYTES;
  47. mv64x60_config_ctlr_windows(bridge_base, bridge_pbase, is_coherent);
  48. mv64x60_devp = find_node_by_compatible(NULL, "marvell,mv64360");
  49. if (mv64x60_devp == NULL)
  50. fatal("Error: Missing marvell,mv64360 device tree node\n\r");
  51. enables = in_le32((u32 *)(bridge_base + MV64x60_CPU_BAR_ENABLE));
  52. enables |= 0x007ffe00; /* Disable all cpu->pci windows */
  53. out_le32((u32 *)(bridge_base + MV64x60_CPU_BAR_ENABLE), enables);
  54. /* Get the cpu -> pci i/o & mem mappings from the device tree */
  55. devp = NULL;
  56. for (bus = 0; ; bus++) {
  57. char name[] = "pci ";
  58. name[strlen(name)-1] = bus+'0';
  59. devp = find_node_by_alias(name);
  60. if (devp == NULL)
  61. break;
  62. if (bus >= 2)
  63. fatal("Error: Only 2 PCI controllers are supported at" \
  64. " this time.\n");
  65. mv64x60_config_pci_windows(bridge_base, bridge_pbase, bus, 0,
  66. mem_size, acc_bits);
  67. rc = getprop(devp, "ranges", v, sizeof(v));
  68. if (rc == 0)
  69. fatal("Error: Can't find marvell,mv64360-pci ranges"
  70. " property\n\r");
  71. /* Get the cpu -> pci i/o & mem mappings from the device tree */
  72. for (i = 0; i < rc; i += 6) {
  73. switch (v[i] & 0xff000000) {
  74. case 0x01000000: /* PCI I/O Space */
  75. tbl = mv64x60_cpu2pci_io;
  76. break;
  77. case 0x02000000: /* PCI MEM Space */
  78. tbl = mv64x60_cpu2pci_mem;
  79. break;
  80. default:
  81. continue;
  82. }
  83. pci_base_hi = v[i+1];
  84. pci_base_lo = v[i+2];
  85. cpu_base = v[i+3];
  86. size = v[i+5];
  87. buf[0] = cpu_base;
  88. buf[1] = size;
  89. if (!dt_xlate_addr(devp, buf, sizeof(buf), &cpu_base))
  90. fatal("Error: Can't translate PCI address " \
  91. "0x%x\n\r", (u32)cpu_base);
  92. mv64x60_config_cpu2pci_window(bridge_base, bus,
  93. pci_base_hi, pci_base_lo, cpu_base, size, tbl);
  94. }
  95. enables &= ~(3<<(9+bus*5)); /* Enable cpu->pci<bus> i/o,
  96. cpu->pci<bus> mem0 */
  97. out_le32((u32 *)(bridge_base + MV64x60_CPU_BAR_ENABLE),
  98. enables);
  99. };
  100. }
  101. static void c2k_fixups(void)
  102. {
  103. u32 mem_size;
  104. mem_size = mv64x60_get_mem_size(bridge_base);
  105. c2k_bridge_setup(mem_size); /* Do necessary bridge setup */
  106. }
  107. #define MV64x60_MPP_CNTL_0 0xf000
  108. #define MV64x60_MPP_CNTL_2 0xf008
  109. #define MV64x60_GPP_IO_CNTL 0xf100
  110. #define MV64x60_GPP_LEVEL_CNTL 0xf110
  111. #define MV64x60_GPP_VALUE_SET 0xf118
  112. static void c2k_reset(void)
  113. {
  114. u32 temp;
  115. udelay(5000000);
  116. if (bridge_base != 0) {
  117. temp = in_le32((u32 *)(bridge_base + MV64x60_MPP_CNTL_0));
  118. temp &= 0xFFFF0FFF;
  119. out_le32((u32 *)(bridge_base + MV64x60_MPP_CNTL_0), temp);
  120. temp = in_le32((u32 *)(bridge_base + MV64x60_GPP_LEVEL_CNTL));
  121. temp |= 0x00000004;
  122. out_le32((u32 *)(bridge_base + MV64x60_GPP_LEVEL_CNTL), temp);
  123. temp = in_le32((u32 *)(bridge_base + MV64x60_GPP_IO_CNTL));
  124. temp |= 0x00000004;
  125. out_le32((u32 *)(bridge_base + MV64x60_GPP_IO_CNTL), temp);
  126. temp = in_le32((u32 *)(bridge_base + MV64x60_MPP_CNTL_2));
  127. temp &= 0xFFFF0FFF;
  128. out_le32((u32 *)(bridge_base + MV64x60_MPP_CNTL_2), temp);
  129. temp = in_le32((u32 *)(bridge_base + MV64x60_GPP_LEVEL_CNTL));
  130. temp |= 0x00080000;
  131. out_le32((u32 *)(bridge_base + MV64x60_GPP_LEVEL_CNTL), temp);
  132. temp = in_le32((u32 *)(bridge_base + MV64x60_GPP_IO_CNTL));
  133. temp |= 0x00080000;
  134. out_le32((u32 *)(bridge_base + MV64x60_GPP_IO_CNTL), temp);
  135. out_le32((u32 *)(bridge_base + MV64x60_GPP_VALUE_SET),
  136. 0x00080004);
  137. }
  138. for (;;);
  139. }
  140. static bd_t bd;
  141. void platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
  142. unsigned long r6, unsigned long r7)
  143. {
  144. CUBOOT_INIT();
  145. fdt_init(_dtb_start);
  146. bridge_base = mv64x60_get_bridge_base();
  147. platform_ops.fixups = c2k_fixups;
  148. platform_ops.exit = c2k_reset;
  149. if (serial_console_init() < 0)
  150. exit();
  151. }