Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Matthew McClintock | 3d40317 | 2006-06-28 10:43:36 -0500 | [diff] [blame] | 2 | /* |
| 3 | * Copyright 2004 Freescale Semiconductor. |
Matthew McClintock | 3d40317 | 2006-06-28 10:43:36 -0500 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
Masahiro Yamada | 75f82d0 | 2018-03-05 01:20:11 +0900 | [diff] [blame] | 7 | #include <linux/libfdt.h> |
Kumar Gala | d28ced3 | 2007-11-29 00:11:44 -0600 | [diff] [blame] | 8 | #include <fdt_support.h> |
Andy Fleming | 96367a3 | 2006-09-13 10:33:56 -0500 | [diff] [blame] | 9 | #include "cadmus.h" |
| 10 | |
Kumar Gala | d28ced3 | 2007-11-29 00:11:44 -0600 | [diff] [blame] | 11 | #if defined(CONFIG_OF_BOARD_SETUP) |
Hou Zhiqiang | 1bec44f | 2019-08-27 11:05:16 +0000 | [diff] [blame] | 12 | #if defined(CONFIG_PCI) && !defined(CONFIG_DM_PCI) |
Andy Fleming | 96367a3 | 2006-09-13 10:33:56 -0500 | [diff] [blame] | 13 | static void cds_pci_fixup(void *blob) |
| 14 | { |
Kumar Gala | 3ea6cee | 2011-11-09 10:01:06 -0600 | [diff] [blame] | 15 | int node; |
Kumar Gala | d28ced3 | 2007-11-29 00:11:44 -0600 | [diff] [blame] | 16 | const char *path; |
| 17 | int len, slot, i; |
Jiang Bin | b0d202c | 2012-11-19 22:31:24 +0000 | [diff] [blame] | 18 | u32 *map = NULL, *piccells = NULL; |
| 19 | int off, cells; |
Andy Fleming | 96367a3 | 2006-09-13 10:33:56 -0500 | [diff] [blame] | 20 | |
Kumar Gala | d28ced3 | 2007-11-29 00:11:44 -0600 | [diff] [blame] | 21 | node = fdt_path_offset(blob, "/aliases"); |
Kumar Gala | d28ced3 | 2007-11-29 00:11:44 -0600 | [diff] [blame] | 22 | 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 Bin | b0d202c | 2012-11-19 22:31:24 +0000 | [diff] [blame] | 29 | /* 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 Gala | d28ced3 | 2007-11-29 00:11:44 -0600 | [diff] [blame] | 48 | } |
| 49 | } |
Matthew McClintock | 3d40317 | 2006-06-28 10:43:36 -0500 | [diff] [blame] | 50 | |
Kumar Gala | bbeac31 | 2007-10-11 00:29:18 -0500 | [diff] [blame] | 51 | if (map) { |
| 52 | len /= sizeof(u32); |
Andy Fleming | 96367a3 | 2006-09-13 10:33:56 -0500 | [diff] [blame] | 53 | |
Kumar Gala | bbeac31 | 2007-10-11 00:29:18 -0500 | [diff] [blame] | 54 | slot = get_pci_slot(); |
| 55 | |
Jiang Bin | b0d202c | 2012-11-19 22:31:24 +0000 | [diff] [blame] | 56 | for (i=0;i<len;i+=cells) { |
Kumar Gala | bbeac31 | 2007-10-11 00:29:18 -0500 | [diff] [blame] | 57 | /* 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 Bin | b0d202c | 2012-11-19 22:31:24 +0000 | [diff] [blame] | 61 | map+=cells; |
Kumar Gala | bbeac31 | 2007-10-11 00:29:18 -0500 | [diff] [blame] | 62 | } |
Andy Fleming | 96367a3 | 2006-09-13 10:33:56 -0500 | [diff] [blame] | 63 | } |
| 64 | } |
Hou Zhiqiang | 1bec44f | 2019-08-27 11:05:16 +0000 | [diff] [blame] | 65 | #endif |
Matthew McClintock | 3d40317 | 2006-06-28 10:43:36 -0500 | [diff] [blame] | 66 | |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame^] | 67 | int ft_board_setup(void *blob, struct bd_info *bd) |
Matthew McClintock | 3d40317 | 2006-06-28 10:43:36 -0500 | [diff] [blame] | 68 | { |
Kumar Gala | d28ced3 | 2007-11-29 00:11:44 -0600 | [diff] [blame] | 69 | ft_cpu_setup(blob, bd); |
Hou Zhiqiang | 1bec44f | 2019-08-27 11:05:16 +0000 | [diff] [blame] | 70 | #if defined(CONFIG_PCI) && !defined(CONFIG_DM_PCI) |
Matthew McClintock | aa6dd06 | 2006-06-28 10:46:13 -0500 | [diff] [blame] | 71 | ft_pci_setup(blob, bd); |
Andy Fleming | 96367a3 | 2006-09-13 10:33:56 -0500 | [diff] [blame] | 72 | cds_pci_fixup(blob); |
Kumar Gala | d28ced3 | 2007-11-29 00:11:44 -0600 | [diff] [blame] | 73 | #endif |
Simon Glass | 2aec3cc | 2014-10-23 18:58:47 -0600 | [diff] [blame] | 74 | |
| 75 | return 0; |
Matthew McClintock | 3d40317 | 2006-06-28 10:43:36 -0500 | [diff] [blame] | 76 | } |
| 77 | #endif |