blob: 6f378c4e221ff7f6d22786d1c5b6701a6a2c8267 [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
Simon Glass97589732020-05-10 11:40:02 -06009#include <init.h>
Scott Wood2fa13912007-04-16 14:34:21 -050010#include <pci.h>
Simon Glass4dcacfc2020-05-10 11:40:13 -060011#include <asm/bitops.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060012#include <asm/global_data.h>
Simon Glassdbd79542020-05-10 11:40:11 -060013#include <linux/delay.h>
Kim Phillips3c6f3b72007-07-25 19:25:28 -050014
15#if defined(CONFIG_OF_LIBFDT)
Masahiro Yamada75f82d02018-03-05 01:20:11 +090016#include <linux/libfdt.h>
Kim Phillipsfd47a742007-12-20 14:09:22 -060017#include <fdt_support.h>
Kim Phillips3c6f3b72007-07-25 19:25:28 -050018#endif
19
Scott Wood2fa13912007-04-16 14:34:21 -050020#include <asm/mpc8349_pci.h>
21
Scott Wood2fa13912007-04-16 14:34:21 -050022#define MAX_BUSES 2
23
24DECLARE_GLOBAL_DATA_PTR;
25
26static struct pci_controller pci_hose[MAX_BUSES];
27static int pci_num_buses;
28
Kim Phillips3c6f3b72007-07-25 19:25:28 -050029#if defined(CONFIG_OF_LIBFDT)
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +090030void ft_pci_setup(void *blob, struct bd_info *bd)
Kim Phillips3c6f3b72007-07-25 19:25:28 -050031{
32 int nodeoffset;
Kim Phillips3c6f3b72007-07-25 19:25:28 -050033 int tmp[2];
Kim Phillipsfd47a742007-12-20 14:09:22 -060034 const char *path;
Kim Phillips3c6f3b72007-07-25 19:25:28 -050035
36 if (pci_num_buses < 1)
37 return;
38
Kim Phillipsfd47a742007-12-20 14:09:22 -060039 nodeoffset = fdt_path_offset(blob, "/aliases");
Kim Phillips3c6f3b72007-07-25 19:25:28 -050040 if (nodeoffset >= 0) {
Kim Phillipsfd47a742007-12-20 14:09:22 -060041 path = fdt_getprop(blob, nodeoffset, "pci0", NULL);
42 if (path) {
43 tmp[0] = cpu_to_be32(pci_hose[0].first_busno);
44 tmp[1] = cpu_to_be32(pci_hose[0].last_busno);
45 do_fixup_by_path(blob, path, "bus-range",
46 &tmp, sizeof(tmp), 1);
Kim Phillips21416812007-08-15 22:30:33 -050047
Kim Phillipsfd47a742007-12-20 14:09:22 -060048 tmp[0] = cpu_to_be32(gd->pci_clk);
49 do_fixup_by_path(blob, path, "clock-frequency",
50 &tmp, sizeof(tmp[0]), 1);
51 }
Scott Wood2fa13912007-04-16 14:34:21 -050052
Kim Phillipsfd47a742007-12-20 14:09:22 -060053 if (pci_num_buses < 2)
54 return;
Scott Wood2fa13912007-04-16 14:34:21 -050055
Kim Phillipsfd47a742007-12-20 14:09:22 -060056 path = fdt_getprop(blob, nodeoffset, "pci1", NULL);
57 if (path) {
Anton Vorontsov7c785472009-02-19 18:20:46 +030058 tmp[0] = cpu_to_be32(pci_hose[1].first_busno);
59 tmp[1] = cpu_to_be32(pci_hose[1].last_busno);
Kim Phillipsfd47a742007-12-20 14:09:22 -060060 do_fixup_by_path(blob, path, "bus-range",
61 &tmp, sizeof(tmp), 1);
Scott Wood2fa13912007-04-16 14:34:21 -050062
Kim Phillipsfd47a742007-12-20 14:09:22 -060063 tmp[0] = cpu_to_be32(gd->pci_clk);
64 do_fixup_by_path(blob, path, "clock-frequency",
65 &tmp, sizeof(tmp[0]), 1);
66 }
Scott Wood2fa13912007-04-16 14:34:21 -050067 }
68}
Kim Phillipsfd47a742007-12-20 14:09:22 -060069#endif /* CONFIG_OF_LIBFDT */