blob: 3ff2fa416bccf220cfd1cfa32e40dbec77c06c03 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Matthew McClintock3d403172006-06-28 10:43:36 -05002/*
3 * Copyright 2004 Freescale Semiconductor.
Matthew McClintock3d403172006-06-28 10:43:36 -05004 */
5
6#include <common.h>
Masahiro Yamada75f82d02018-03-05 01:20:11 +09007#include <linux/libfdt.h>
Kumar Galad28ced32007-11-29 00:11:44 -06008#include <fdt_support.h>
Andy Fleming96367a32006-09-13 10:33:56 -05009#include "cadmus.h"
10
Kumar Galad28ced32007-11-29 00:11:44 -060011#if defined(CONFIG_OF_BOARD_SETUP)
Andy Fleming96367a32006-09-13 10:33:56 -050012static void cds_pci_fixup(void *blob)
13{
Kumar Gala3ea6cee2011-11-09 10:01:06 -060014 int node;
Kumar Galad28ced32007-11-29 00:11:44 -060015 const char *path;
16 int len, slot, i;
Jiang Binb0d202c2012-11-19 22:31:24 +000017 u32 *map = NULL, *piccells = NULL;
18 int off, cells;
Andy Fleming96367a32006-09-13 10:33:56 -050019
Kumar Galad28ced32007-11-29 00:11:44 -060020 node = fdt_path_offset(blob, "/aliases");
Kumar Galad28ced32007-11-29 00:11:44 -060021 if (node >= 0) {
22 path = fdt_getprop(blob, node, "pci0", NULL);
23 if (path) {
24 node = fdt_path_offset(blob, path);
25 if (node >= 0) {
26 map = fdt_getprop_w(blob, node, "interrupt-map", &len);
27 }
Jiang Binb0d202c2012-11-19 22:31:24 +000028 /* Each item in "interrupt-map" property is translated with
29 * following cells:
30 * PCI #address-cells, PCI #interrupt-cells,
31 * PIC address, PIC #address-cells, PIC #interrupt-cells.
32 */
33 cells = fdt_getprop_u32_default(blob, path, "#address-cells", 1);
34 cells += fdt_getprop_u32_default(blob, path, "#interrupt-cells", 1);
35 off = fdt_node_offset_by_phandle(blob, fdt32_to_cpu(*(map+cells)));
36 if (off <= 0)
37 return;
38 cells += 1;
39 piccells = (u32 *)fdt_getprop(blob, off, "#address-cells", NULL);
40 if (piccells == NULL)
41 return;
42 cells += *piccells;
43 piccells = (u32 *)fdt_getprop(blob, off, "#interrupt-cells", NULL);
44 if (piccells == NULL)
45 return;
46 cells += *piccells;
Kumar Galad28ced32007-11-29 00:11:44 -060047 }
48 }
Matthew McClintock3d403172006-06-28 10:43:36 -050049
Kumar Galabbeac312007-10-11 00:29:18 -050050 if (map) {
51 len /= sizeof(u32);
Andy Fleming96367a32006-09-13 10:33:56 -050052
Kumar Galabbeac312007-10-11 00:29:18 -050053 slot = get_pci_slot();
54
Jiang Binb0d202c2012-11-19 22:31:24 +000055 for (i=0;i<len;i+=cells) {
Kumar Galabbeac312007-10-11 00:29:18 -050056 /* We rotate the interrupt pins so that the mapping
57 * changes depending on the slot the carrier card is in.
58 */
59 map[3] = ((map[3] + slot - 2) % 4) + 1;
Jiang Binb0d202c2012-11-19 22:31:24 +000060 map+=cells;
Kumar Galabbeac312007-10-11 00:29:18 -050061 }
Andy Fleming96367a32006-09-13 10:33:56 -050062 }
63}
Matthew McClintock3d403172006-06-28 10:43:36 -050064
Simon Glass2aec3cc2014-10-23 18:58:47 -060065int ft_board_setup(void *blob, bd_t *bd)
Matthew McClintock3d403172006-06-28 10:43:36 -050066{
Kumar Galad28ced32007-11-29 00:11:44 -060067 ft_cpu_setup(blob, bd);
Matthew McClintockaa6dd062006-06-28 10:46:13 -050068#ifdef CONFIG_PCI
69 ft_pci_setup(blob, bd);
Andy Fleming96367a32006-09-13 10:33:56 -050070 cds_pci_fixup(blob);
Kumar Galad28ced32007-11-29 00:11:44 -060071#endif
Simon Glass2aec3cc2014-10-23 18:58:47 -060072
73 return 0;
Matthew McClintock3d403172006-06-28 10:43:36 -050074}
75#endif