blob: 65ef0497c2a13a247347ae0b1288e54dc4d3871e [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Scott Wood2fa13912007-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 Wood2fa13912007-04-16 14:34:21 -05007 */
8
Tom Riniabb9a042024-05-18 20:20:43 -06009#include <common.h>
Simon Glass97589732020-05-10 11:40:02 -060010#include <init.h>
Scott Wood2fa13912007-04-16 14:34:21 -050011#include <pci.h>
Simon Glass4dcacfc2020-05-10 11:40:13 -060012#include <asm/bitops.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060013#include <asm/global_data.h>
Simon Glassdbd79542020-05-10 11:40:11 -060014#include <linux/delay.h>
Kim Phillips3c6f3b72007-07-25 19:25:28 -050015
16#if defined(CONFIG_OF_LIBFDT)
Masahiro Yamada75f82d02018-03-05 01:20:11 +090017#include <linux/libfdt.h>
Kim Phillipsfd47a742007-12-20 14:09:22 -060018#include <fdt_support.h>
Kim Phillips3c6f3b72007-07-25 19:25:28 -050019#endif
20
Scott Wood2fa13912007-04-16 14:34:21 -050021#include <asm/mpc8349_pci.h>
22
Scott Wood2fa13912007-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 Phillips3c6f3b72007-07-25 19:25:28 -050030#if defined(CONFIG_OF_LIBFDT)
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +090031void ft_pci_setup(void *blob, struct bd_info *bd)
Kim Phillips3c6f3b72007-07-25 19:25:28 -050032{
33 int nodeoffset;
Kim Phillips3c6f3b72007-07-25 19:25:28 -050034 int tmp[2];
Kim Phillipsfd47a742007-12-20 14:09:22 -060035 const char *path;
Kim Phillips3c6f3b72007-07-25 19:25:28 -050036
37 if (pci_num_buses < 1)
38 return;
39
Kim Phillipsfd47a742007-12-20 14:09:22 -060040 nodeoffset = fdt_path_offset(blob, "/aliases");
Kim Phillips3c6f3b72007-07-25 19:25:28 -050041 if (nodeoffset >= 0) {
Kim Phillipsfd47a742007-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 Phillips21416812007-08-15 22:30:33 -050048
Kim Phillipsfd47a742007-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 }
Scott Wood2fa13912007-04-16 14:34:21 -050053
Kim Phillipsfd47a742007-12-20 14:09:22 -060054 if (pci_num_buses < 2)
55 return;
Scott Wood2fa13912007-04-16 14:34:21 -050056
Kim Phillipsfd47a742007-12-20 14:09:22 -060057 path = fdt_getprop(blob, nodeoffset, "pci1", NULL);
58 if (path) {
Anton Vorontsov7c785472009-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 Phillipsfd47a742007-12-20 14:09:22 -060061 do_fixup_by_path(blob, path, "bus-range",
62 &tmp, sizeof(tmp), 1);
Scott Wood2fa13912007-04-16 14:34:21 -050063
Kim Phillipsfd47a742007-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 }
Scott Wood2fa13912007-04-16 14:34:21 -050068 }
69}
Kim Phillipsfd47a742007-12-20 14:09:22 -060070#endif /* CONFIG_OF_LIBFDT */