cds_pci_ft.c 1.8 KB

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