cds_pci_ft.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright 2004 Freescale Semiconductor.
  4. */
  5. #include <common.h>
  6. #include <linux/libfdt.h>
  7. #include <fdt_support.h>
  8. #include "cadmus.h"
  9. #if defined(CONFIG_OF_BOARD_SETUP)
  10. static void cds_pci_fixup(void *blob)
  11. {
  12. int node;
  13. const char *path;
  14. int len, slot, i;
  15. u32 *map = NULL, *piccells = NULL;
  16. int off, cells;
  17. node = fdt_path_offset(blob, "/aliases");
  18. if (node >= 0) {
  19. path = fdt_getprop(blob, node, "pci0", NULL);
  20. if (path) {
  21. node = fdt_path_offset(blob, path);
  22. if (node >= 0) {
  23. map = fdt_getprop_w(blob, node, "interrupt-map", &len);
  24. }
  25. /* Each item in "interrupt-map" property is translated with
  26. * following cells:
  27. * PCI #address-cells, PCI #interrupt-cells,
  28. * PIC address, PIC #address-cells, PIC #interrupt-cells.
  29. */
  30. cells = fdt_getprop_u32_default(blob, path, "#address-cells", 1);
  31. cells += fdt_getprop_u32_default(blob, path, "#interrupt-cells", 1);
  32. off = fdt_node_offset_by_phandle(blob, fdt32_to_cpu(*(map+cells)));
  33. if (off <= 0)
  34. return;
  35. cells += 1;
  36. piccells = (u32 *)fdt_getprop(blob, off, "#address-cells", NULL);
  37. if (piccells == NULL)
  38. return;
  39. cells += *piccells;
  40. piccells = (u32 *)fdt_getprop(blob, off, "#interrupt-cells", NULL);
  41. if (piccells == NULL)
  42. return;
  43. cells += *piccells;
  44. }
  45. }
  46. if (map) {
  47. len /= sizeof(u32);
  48. slot = get_pci_slot();
  49. for (i=0;i<len;i+=cells) {
  50. /* We rotate the interrupt pins so that the mapping
  51. * changes depending on the slot the carrier card is in.
  52. */
  53. map[3] = ((map[3] + slot - 2) % 4) + 1;
  54. map+=cells;
  55. }
  56. }
  57. }
  58. int ft_board_setup(void *blob, bd_t *bd)
  59. {
  60. ft_cpu_setup(blob, bd);
  61. #ifdef CONFIG_PCI
  62. ft_pci_setup(blob, bd);
  63. cds_pci_fixup(blob);
  64. #endif
  65. return 0;
  66. }
  67. #endif