cuboot-pq2.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. /*
  2. * Old U-boot compatibility for PowerQUICC II
  3. * (a.k.a. 82xx with CPM, not the 8240 family of chips)
  4. *
  5. * Author: Scott Wood <scottwood@freescale.com>
  6. *
  7. * Copyright (c) 2007 Freescale Semiconductor, Inc.
  8. *
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public License version 2 as published
  11. * by the Free Software Foundation.
  12. */
  13. #include "ops.h"
  14. #include "stdio.h"
  15. #include "cuboot.h"
  16. #include "io.h"
  17. #define TARGET_CPM2
  18. #define TARGET_HAS_ETH1
  19. #include "ppcboot.h"
  20. static bd_t bd;
  21. struct cs_range {
  22. u32 csnum;
  23. u32 base; /* must be zero */
  24. u32 addr;
  25. u32 size;
  26. };
  27. struct pci_range {
  28. u32 flags;
  29. u32 pci_addr[2];
  30. u32 phys_addr;
  31. u32 size[2];
  32. };
  33. struct cs_range cs_ranges_buf[MAX_PROP_LEN / sizeof(struct cs_range)];
  34. struct pci_range pci_ranges_buf[MAX_PROP_LEN / sizeof(struct pci_range)];
  35. /* Different versions of u-boot put the BCSR in different places, and
  36. * some don't set up the PCI PIC at all, so we assume the device tree is
  37. * sane and update the BRx registers appropriately.
  38. *
  39. * For any node defined as compatible with fsl,pq2-chipselect,
  40. * #address/#size must be 2/1 for chipselect bus, 1/1 for parent bus,
  41. * and ranges must be for whole chip selects.
  42. */
  43. static void update_cs_ranges(void)
  44. {
  45. u32 ctrl_ph;
  46. void *ctrl_node, *bus_node, *parent_node;
  47. u32 *ctrl_addr;
  48. unsigned long ctrl_size;
  49. u32 naddr, nsize;
  50. int len;
  51. int i;
  52. bus_node = finddevice("/chipselect");
  53. if (!bus_node || !dt_is_compatible(bus_node, "fsl,pq2-chipselect"))
  54. return;
  55. dt_get_reg_format(bus_node, &naddr, &nsize);
  56. if (naddr != 2 || nsize != 1)
  57. goto err;
  58. parent_node = get_parent(bus_node);
  59. if (!parent_node)
  60. goto err;
  61. dt_get_reg_format(parent_node, &naddr, &nsize);
  62. if (naddr != 1 || nsize != 1)
  63. goto err;
  64. len = getprop(bus_node, "fsl,ctrl", &ctrl_ph, 4);
  65. if (len != 4)
  66. goto err;
  67. ctrl_node = find_node_by_prop_value(NULL, "linux,phandle",
  68. (char *)&ctrl_ph, 4);
  69. if (!ctrl_node)
  70. goto err;
  71. if (!dt_is_compatible(ctrl_node, "fsl,pq2-chipselect-ctrl"))
  72. goto err;
  73. if (!dt_xlate_reg(ctrl_node, 0, (unsigned long *)&ctrl_addr,
  74. &ctrl_size))
  75. goto err;
  76. len = getprop(bus_node, "ranges", cs_ranges_buf, sizeof(cs_ranges_buf));
  77. for (i = 0; i < len / sizeof(struct cs_range); i++) {
  78. u32 base, option;
  79. int cs = cs_ranges_buf[i].csnum;
  80. if (cs >= ctrl_size / 8)
  81. goto err;
  82. if (cs_ranges_buf[i].base != 0)
  83. goto err;
  84. base = in_be32(&ctrl_addr[cs * 2]);
  85. /* If CS is already valid, use the existing flags.
  86. * Otherwise, guess a sane default.
  87. */
  88. if (base & 1) {
  89. base &= 0x7fff;
  90. option = in_be32(&ctrl_addr[cs * 2 + 1]) & 0x7fff;
  91. } else {
  92. base = 0x1801;
  93. option = 0x10;
  94. }
  95. out_be32(&ctrl_addr[cs * 2], 0);
  96. out_be32(&ctrl_addr[cs * 2 + 1],
  97. option | ~(cs_ranges_buf[i].size - 1));
  98. out_be32(&ctrl_addr[cs * 2], base | cs_ranges_buf[i].addr);
  99. }
  100. return;
  101. err:
  102. printf("Bad /chipselect or fsl,pq2-chipselect-ctrl node\r\n");
  103. }
  104. /* Older u-boots don't set PCI up properly. Update the hardware to match
  105. * the device tree. The prefetch mem region and non-prefetch mem region
  106. * must be contiguous in the host bus. As required by the PCI binding,
  107. * PCI #addr/#size must be 3/2. The parent bus must be 1/1. Only
  108. * 32-bit PCI is supported. All three region types (prefetchable mem,
  109. * non-prefetchable mem, and I/O) must be present.
  110. */
  111. static void fixup_pci(void)
  112. {
  113. struct pci_range *mem = NULL, *mmio = NULL,
  114. *io = NULL, *mem_base = NULL;
  115. u32 *pci_regs[3];
  116. u8 *soc_regs;
  117. int i, len;
  118. void *node, *parent_node, *soc_node;
  119. u32 naddr, nsize, mem_log2;
  120. node = finddevice("/pci");
  121. if (!node || !dt_is_compatible(node, "fsl,pq2-pci"))
  122. return;
  123. soc_node = finddevice("/soc");
  124. if (!soc_node || !dt_is_compatible(soc_node, "fsl,pq2-soc"))
  125. goto err;
  126. for (i = 0; i < 3; i++)
  127. if (!dt_xlate_reg(node, i,
  128. (unsigned long *)&pci_regs[i], NULL))
  129. goto err;
  130. if (!dt_xlate_reg(soc_node, 0, (unsigned long *)&soc_regs, NULL))
  131. goto err;
  132. dt_get_reg_format(node, &naddr, &nsize);
  133. if (naddr != 3 || nsize != 2)
  134. goto err;
  135. parent_node = get_parent(node);
  136. if (!parent_node)
  137. goto err;
  138. dt_get_reg_format(parent_node, &naddr, &nsize);
  139. if (naddr != 1 || nsize != 1)
  140. goto err;
  141. len = getprop(node, "ranges", pci_ranges_buf,
  142. sizeof(pci_ranges_buf));
  143. for (i = 0; i < len / sizeof(struct pci_range); i++) {
  144. u32 flags = pci_ranges_buf[i].flags & 0x43000000;
  145. if (flags == 0x42000000)
  146. mem = &pci_ranges_buf[i];
  147. else if (flags == 0x02000000)
  148. mmio = &pci_ranges_buf[i];
  149. else if (flags == 0x01000000)
  150. io = &pci_ranges_buf[i];
  151. }
  152. if (!mem || !mmio || !io)
  153. goto err;
  154. if (mem->phys_addr + mem->size[1] == mmio->phys_addr)
  155. mem_base = mem;
  156. else if (mmio->phys_addr + mmio->size[1] == mem->phys_addr)
  157. mem_base = mmio;
  158. else
  159. goto err;
  160. out_be32(&pci_regs[1][0], mem_base->phys_addr | 1);
  161. out_be32(&pci_regs[2][0], ~(mem->size[1] + mmio->size[1] - 1));
  162. out_be32(&pci_regs[1][1], io->phys_addr | 1);
  163. out_be32(&pci_regs[2][1], ~(io->size[1] - 1));
  164. out_le32(&pci_regs[0][0], mem->pci_addr[1] >> 12);
  165. out_le32(&pci_regs[0][2], mem->phys_addr >> 12);
  166. out_le32(&pci_regs[0][4], (~(mem->size[1] - 1) >> 12) | 0xa0000000);
  167. out_le32(&pci_regs[0][6], mmio->pci_addr[1] >> 12);
  168. out_le32(&pci_regs[0][8], mmio->phys_addr >> 12);
  169. out_le32(&pci_regs[0][10], (~(mmio->size[1] - 1) >> 12) | 0x80000000);
  170. out_le32(&pci_regs[0][12], io->pci_addr[1] >> 12);
  171. out_le32(&pci_regs[0][14], io->phys_addr >> 12);
  172. out_le32(&pci_regs[0][16], (~(io->size[1] - 1) >> 12) | 0xc0000000);
  173. /* Inbound translation */
  174. out_le32(&pci_regs[0][58], 0);
  175. out_le32(&pci_regs[0][60], 0);
  176. mem_log2 = 1 << (__ilog2_u32(bd.bi_memsize - 1) + 1);
  177. out_le32(&pci_regs[0][62], 0xa0000000 | ~((1 << (mem_log2 - 12)) - 1));
  178. /* If PCI is disabled, drive RST high to enable. */
  179. if (!(in_le32(&pci_regs[0][32]) & 1)) {
  180. /* Tpvrh (Power valid to RST# high) 100 ms */
  181. udelay(100000);
  182. out_le32(&pci_regs[0][32], 1);
  183. /* Trhfa (RST# high to first cfg access) 2^25 clocks */
  184. udelay(1020000);
  185. }
  186. /* Enable bus master and memory access */
  187. out_le32(&pci_regs[0][64], 0x80000004);
  188. out_le32(&pci_regs[0][65], in_le32(&pci_regs[0][65]) | 6);
  189. /* Park the bus on PCI, and elevate PCI's arbitration priority,
  190. * as required by section 9.6 of the user's manual.
  191. */
  192. out_8(&soc_regs[0x10028], 3);
  193. out_be32((u32 *)&soc_regs[0x1002c], 0x01236745);
  194. return;
  195. err:
  196. printf("Bad PCI node\r\n");
  197. }
  198. static void pq2_platform_fixups(void)
  199. {
  200. void *node;
  201. dt_fixup_memory(bd.bi_memstart, bd.bi_memsize);
  202. dt_fixup_mac_addresses(bd.bi_enetaddr, bd.bi_enet1addr);
  203. dt_fixup_cpu_clocks(bd.bi_intfreq, bd.bi_busfreq / 4, bd.bi_busfreq);
  204. node = finddevice("/soc/cpm");
  205. if (node)
  206. setprop(node, "clock-frequency", &bd.bi_cpmfreq, 4);
  207. node = finddevice("/soc/cpm/brg");
  208. if (node)
  209. setprop(node, "clock-frequency", &bd.bi_brgfreq, 4);
  210. update_cs_ranges();
  211. fixup_pci();
  212. }
  213. void platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
  214. unsigned long r6, unsigned long r7)
  215. {
  216. CUBOOT_INIT();
  217. ft_init(_dtb_start, _dtb_end - _dtb_start, 32);
  218. serial_console_init();
  219. platform_ops.fixups = pq2_platform_fixups;
  220. }