cds_pci_ft.c 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * Copyright 2004 Freescale Semiconductor.
  3. *
  4. * See file CREDITS for list of people who contributed to this
  5. * project.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  20. * MA 02111-1307 USA
  21. */
  22. #include <common.h>
  23. #include <libfdt.h>
  24. #include <fdt_support.h>
  25. #include "cadmus.h"
  26. #if defined(CONFIG_OF_BOARD_SETUP)
  27. static void cds_pci_fixup(void *blob)
  28. {
  29. int node;
  30. const char *path;
  31. int len, slot, i;
  32. u32 *map = NULL, *piccells = NULL;
  33. int off, cells;
  34. node = fdt_path_offset(blob, "/aliases");
  35. if (node >= 0) {
  36. path = fdt_getprop(blob, node, "pci0", NULL);
  37. if (path) {
  38. node = fdt_path_offset(blob, path);
  39. if (node >= 0) {
  40. map = fdt_getprop_w(blob, node, "interrupt-map", &len);
  41. }
  42. /* Each item in "interrupt-map" property is translated with
  43. * following cells:
  44. * PCI #address-cells, PCI #interrupt-cells,
  45. * PIC address, PIC #address-cells, PIC #interrupt-cells.
  46. */
  47. cells = fdt_getprop_u32_default(blob, path, "#address-cells", 1);
  48. cells += fdt_getprop_u32_default(blob, path, "#interrupt-cells", 1);
  49. off = fdt_node_offset_by_phandle(blob, fdt32_to_cpu(*(map+cells)));
  50. if (off <= 0)
  51. return;
  52. cells += 1;
  53. piccells = (u32 *)fdt_getprop(blob, off, "#address-cells", NULL);
  54. if (piccells == NULL)
  55. return;
  56. cells += *piccells;
  57. piccells = (u32 *)fdt_getprop(blob, off, "#interrupt-cells", NULL);
  58. if (piccells == NULL)
  59. return;
  60. cells += *piccells;
  61. }
  62. }
  63. if (map) {
  64. len /= sizeof(u32);
  65. slot = get_pci_slot();
  66. for (i=0;i<len;i+=cells) {
  67. /* We rotate the interrupt pins so that the mapping
  68. * changes depending on the slot the carrier card is in.
  69. */
  70. map[3] = ((map[3] + slot - 2) % 4) + 1;
  71. map+=cells;
  72. }
  73. }
  74. }
  75. void
  76. ft_board_setup(void *blob, bd_t *bd)
  77. {
  78. ft_cpu_setup(blob, bd);
  79. #ifdef CONFIG_PCI
  80. ft_pci_setup(blob, bd);
  81. cds_pci_fixup(blob);
  82. #endif
  83. }
  84. #endif