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