blob: 571dfbbaada6e6607ebd1f416259a2dd43d16470 [file] [log] [blame]
Matthew McClintock0e163872006-06-28 10:43:36 -05001/*
2 * Copyright 2004 Freescale Semiconductor.
3 *
Wolfgang Denk3765b3e2013-10-07 13:07:26 +02004 * SPDX-License-Identifier: GPL-2.0+
Matthew McClintock0e163872006-06-28 10:43:36 -05005 */
6
7#include <common.h>
Kumar Galab90d2542007-11-29 00:11:44 -06008#include <libfdt.h>
9#include <fdt_support.h>
Andy Fleming084d6482006-09-13 10:33:56 -050010#include "cadmus.h"
Matthew McClintock0e163872006-06-28 10:43:36 -050011
Kumar Galab90d2542007-11-29 00:11:44 -060012#if defined(CONFIG_OF_BOARD_SETUP)
Andy Fleming084d6482006-09-13 10:33:56 -050013static void cds_pci_fixup(void *blob)
14{
Kumar Gala67926c22011-11-09 10:01:06 -060015 int node;
Kumar Galab90d2542007-11-29 00:11:44 -060016 const char *path;
17 int len, slot, i;
Jiang Binacac0752012-11-19 22:31:24 +000018 u32 *map = NULL, *piccells = NULL;
19 int off, cells;
Andy Fleming084d6482006-09-13 10:33:56 -050020
Kumar Galab90d2542007-11-29 00:11:44 -060021 node = fdt_path_offset(blob, "/aliases");
Kumar Galab90d2542007-11-29 00:11:44 -060022 if (node >= 0) {
23 path = fdt_getprop(blob, node, "pci0", NULL);
24 if (path) {
25 node = fdt_path_offset(blob, path);
26 if (node >= 0) {
27 map = fdt_getprop_w(blob, node, "interrupt-map", &len);
28 }
Jiang Binacac0752012-11-19 22:31:24 +000029 /* Each item in "interrupt-map" property is translated with
30 * following cells:
31 * PCI #address-cells, PCI #interrupt-cells,
32 * PIC address, PIC #address-cells, PIC #interrupt-cells.
33 */
34 cells = fdt_getprop_u32_default(blob, path, "#address-cells", 1);
35 cells += fdt_getprop_u32_default(blob, path, "#interrupt-cells", 1);
36 off = fdt_node_offset_by_phandle(blob, fdt32_to_cpu(*(map+cells)));
37 if (off <= 0)
38 return;
39 cells += 1;
40 piccells = (u32 *)fdt_getprop(blob, off, "#address-cells", NULL);
41 if (piccells == NULL)
42 return;
43 cells += *piccells;
44 piccells = (u32 *)fdt_getprop(blob, off, "#interrupt-cells", NULL);
45 if (piccells == NULL)
46 return;
47 cells += *piccells;
Kumar Galab90d2542007-11-29 00:11:44 -060048 }
49 }
Andy Fleming084d6482006-09-13 10:33:56 -050050
Kumar Gala7600d472007-10-11 00:29:18 -050051 if (map) {
52 len /= sizeof(u32);
Andy Fleming084d6482006-09-13 10:33:56 -050053
Kumar Gala7600d472007-10-11 00:29:18 -050054 slot = get_pci_slot();
Andy Fleming084d6482006-09-13 10:33:56 -050055
Jiang Binacac0752012-11-19 22:31:24 +000056 for (i=0;i<len;i+=cells) {
Kumar Gala7600d472007-10-11 00:29:18 -050057 /* We rotate the interrupt pins so that the mapping
58 * changes depending on the slot the carrier card is in.
59 */
60 map[3] = ((map[3] + slot - 2) % 4) + 1;
Jiang Binacac0752012-11-19 22:31:24 +000061 map+=cells;
Kumar Gala7600d472007-10-11 00:29:18 -050062 }
Andy Fleming084d6482006-09-13 10:33:56 -050063 }
64}
Matthew McClintock0e163872006-06-28 10:43:36 -050065
Simon Glasse895a4b2014-10-23 18:58:47 -060066int ft_board_setup(void *blob, bd_t *bd)
Matthew McClintock0e163872006-06-28 10:43:36 -050067{
Kumar Galab90d2542007-11-29 00:11:44 -060068 ft_cpu_setup(blob, bd);
Matthew McClintockbf1dfff2006-06-28 10:46:13 -050069#ifdef CONFIG_PCI
70 ft_pci_setup(blob, bd);
Andy Fleming084d6482006-09-13 10:33:56 -050071 cds_pci_fixup(blob);
Kumar Galab90d2542007-11-29 00:11:44 -060072#endif
Simon Glasse895a4b2014-10-23 18:58:47 -060073
74 return 0;
Matthew McClintock0e163872006-06-28 10:43:36 -050075}
76#endif