blob: 65ef0497c2a13a247347ae0b1288e54dc4d3871e [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Scott Wood49ea3b62007-04-16 14:34:21 -05002/*
3 * Copyright (C) Freescale Semiconductor, Inc. 2007
4 *
5 * Author: Scott Wood <scottwood@freescale.com>,
6 * with some bits from older board-specific PCI initialization.
Scott Wood49ea3b62007-04-16 14:34:21 -05007 */
8
9#include <common.h>
Simon Glass691d7192020-05-10 11:40:02 -060010#include <init.h>
Scott Wood49ea3b62007-04-16 14:34:21 -050011#include <pci.h>
Simon Glasscd93d622020-05-10 11:40:13 -060012#include <asm/bitops.h>
Simon Glass401d1c42020-10-30 21:38:53 -060013#include <asm/global_data.h>
Simon Glassc05ed002020-05-10 11:40:11 -060014#include <linux/delay.h>
Kim Phillips343d9102007-07-25 19:25:28 -050015
16#if defined(CONFIG_OF_LIBFDT)
Masahiro Yamadab08c8c42018-03-05 01:20:11 +090017#include <linux/libfdt.h>
Kim Phillips5b8bc602007-12-20 14:09:22 -060018#include <fdt_support.h>
Kim Phillips343d9102007-07-25 19:25:28 -050019#endif
20
Scott Wood49ea3b62007-04-16 14:34:21 -050021#include <asm/mpc8349_pci.h>
22
Scott Wood49ea3b62007-04-16 14:34:21 -050023#define MAX_BUSES 2
24
25DECLARE_GLOBAL_DATA_PTR;
26
27static struct pci_controller pci_hose[MAX_BUSES];
28static int pci_num_buses;
29
Kim Phillips343d9102007-07-25 19:25:28 -050030#if defined(CONFIG_OF_LIBFDT)
Masahiro Yamadab75d8dc2020-06-26 15:13:33 +090031void ft_pci_setup(void *blob, struct bd_info *bd)
Kim Phillips343d9102007-07-25 19:25:28 -050032{
33 int nodeoffset;
Kim Phillips343d9102007-07-25 19:25:28 -050034 int tmp[2];
Kim Phillips5b8bc602007-12-20 14:09:22 -060035 const char *path;
Kim Phillips343d9102007-07-25 19:25:28 -050036
37 if (pci_num_buses < 1)
38 return;
39
Kim Phillips5b8bc602007-12-20 14:09:22 -060040 nodeoffset = fdt_path_offset(blob, "/aliases");
Kim Phillips343d9102007-07-25 19:25:28 -050041 if (nodeoffset >= 0) {
Kim Phillips5b8bc602007-12-20 14:09:22 -060042 path = fdt_getprop(blob, nodeoffset, "pci0", NULL);
43 if (path) {
44 tmp[0] = cpu_to_be32(pci_hose[0].first_busno);
45 tmp[1] = cpu_to_be32(pci_hose[0].last_busno);
46 do_fixup_by_path(blob, path, "bus-range",
47 &tmp, sizeof(tmp), 1);
Kim Phillips3fde9e82007-08-15 22:30:33 -050048
Kim Phillips5b8bc602007-12-20 14:09:22 -060049 tmp[0] = cpu_to_be32(gd->pci_clk);
50 do_fixup_by_path(blob, path, "clock-frequency",
51 &tmp, sizeof(tmp[0]), 1);
52 }
Kim Phillips343d9102007-07-25 19:25:28 -050053
Kim Phillips5b8bc602007-12-20 14:09:22 -060054 if (pci_num_buses < 2)
55 return;
Kim Phillips343d9102007-07-25 19:25:28 -050056
Kim Phillips5b8bc602007-12-20 14:09:22 -060057 path = fdt_getprop(blob, nodeoffset, "pci1", NULL);
58 if (path) {
Anton Vorontsova5878d42009-02-19 18:20:46 +030059 tmp[0] = cpu_to_be32(pci_hose[1].first_busno);
60 tmp[1] = cpu_to_be32(pci_hose[1].last_busno);
Kim Phillips5b8bc602007-12-20 14:09:22 -060061 do_fixup_by_path(blob, path, "bus-range",
62 &tmp, sizeof(tmp), 1);
Kim Phillips3fde9e82007-08-15 22:30:33 -050063
Kim Phillips5b8bc602007-12-20 14:09:22 -060064 tmp[0] = cpu_to_be32(gd->pci_clk);
65 do_fixup_by_path(blob, path, "clock-frequency",
66 &tmp, sizeof(tmp[0]), 1);
67 }
Kim Phillips343d9102007-07-25 19:25:28 -050068 }
69}
Kim Phillips5b8bc602007-12-20 14:09:22 -060070#endif /* CONFIG_OF_LIBFDT */