Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Scott Wood | 2fa1391 | 2007-04-16 14:34:21 -0500 | [diff] [blame] | 2 | /* |
| 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 Wood | 2fa1391 | 2007-04-16 14:34:21 -0500 | [diff] [blame] | 7 | */ |
| 8 | |
Simon Glass | 9758973 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 9 | #include <init.h> |
Scott Wood | 2fa1391 | 2007-04-16 14:34:21 -0500 | [diff] [blame] | 10 | #include <pci.h> |
Simon Glass | 4dcacfc | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 11 | #include <asm/bitops.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 12 | #include <asm/global_data.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 13 | #include <linux/delay.h> |
Kim Phillips | 3c6f3b7 | 2007-07-25 19:25:28 -0500 | [diff] [blame] | 14 | |
| 15 | #if defined(CONFIG_OF_LIBFDT) |
Masahiro Yamada | 75f82d0 | 2018-03-05 01:20:11 +0900 | [diff] [blame] | 16 | #include <linux/libfdt.h> |
Kim Phillips | fd47a74 | 2007-12-20 14:09:22 -0600 | [diff] [blame] | 17 | #include <fdt_support.h> |
Kim Phillips | 3c6f3b7 | 2007-07-25 19:25:28 -0500 | [diff] [blame] | 18 | #endif |
| 19 | |
Scott Wood | 2fa1391 | 2007-04-16 14:34:21 -0500 | [diff] [blame] | 20 | #include <asm/mpc8349_pci.h> |
| 21 | |
Scott Wood | 2fa1391 | 2007-04-16 14:34:21 -0500 | [diff] [blame] | 22 | #define MAX_BUSES 2 |
| 23 | |
| 24 | DECLARE_GLOBAL_DATA_PTR; |
| 25 | |
| 26 | static struct pci_controller pci_hose[MAX_BUSES]; |
| 27 | static int pci_num_buses; |
| 28 | |
Kim Phillips | 3c6f3b7 | 2007-07-25 19:25:28 -0500 | [diff] [blame] | 29 | #if defined(CONFIG_OF_LIBFDT) |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 30 | void ft_pci_setup(void *blob, struct bd_info *bd) |
Kim Phillips | 3c6f3b7 | 2007-07-25 19:25:28 -0500 | [diff] [blame] | 31 | { |
| 32 | int nodeoffset; |
Kim Phillips | 3c6f3b7 | 2007-07-25 19:25:28 -0500 | [diff] [blame] | 33 | int tmp[2]; |
Kim Phillips | fd47a74 | 2007-12-20 14:09:22 -0600 | [diff] [blame] | 34 | const char *path; |
Kim Phillips | 3c6f3b7 | 2007-07-25 19:25:28 -0500 | [diff] [blame] | 35 | |
| 36 | if (pci_num_buses < 1) |
| 37 | return; |
| 38 | |
Kim Phillips | fd47a74 | 2007-12-20 14:09:22 -0600 | [diff] [blame] | 39 | nodeoffset = fdt_path_offset(blob, "/aliases"); |
Kim Phillips | 3c6f3b7 | 2007-07-25 19:25:28 -0500 | [diff] [blame] | 40 | if (nodeoffset >= 0) { |
Kim Phillips | fd47a74 | 2007-12-20 14:09:22 -0600 | [diff] [blame] | 41 | 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 Phillips | 2141681 | 2007-08-15 22:30:33 -0500 | [diff] [blame] | 47 | |
Kim Phillips | fd47a74 | 2007-12-20 14:09:22 -0600 | [diff] [blame] | 48 | 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 Wood | 2fa1391 | 2007-04-16 14:34:21 -0500 | [diff] [blame] | 52 | |
Kim Phillips | fd47a74 | 2007-12-20 14:09:22 -0600 | [diff] [blame] | 53 | if (pci_num_buses < 2) |
| 54 | return; |
Scott Wood | 2fa1391 | 2007-04-16 14:34:21 -0500 | [diff] [blame] | 55 | |
Kim Phillips | fd47a74 | 2007-12-20 14:09:22 -0600 | [diff] [blame] | 56 | path = fdt_getprop(blob, nodeoffset, "pci1", NULL); |
| 57 | if (path) { |
Anton Vorontsov | 7c78547 | 2009-02-19 18:20:46 +0300 | [diff] [blame] | 58 | tmp[0] = cpu_to_be32(pci_hose[1].first_busno); |
| 59 | tmp[1] = cpu_to_be32(pci_hose[1].last_busno); |
Kim Phillips | fd47a74 | 2007-12-20 14:09:22 -0600 | [diff] [blame] | 60 | do_fixup_by_path(blob, path, "bus-range", |
| 61 | &tmp, sizeof(tmp), 1); |
Scott Wood | 2fa1391 | 2007-04-16 14:34:21 -0500 | [diff] [blame] | 62 | |
Kim Phillips | fd47a74 | 2007-12-20 14:09:22 -0600 | [diff] [blame] | 63 | 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 Wood | 2fa1391 | 2007-04-16 14:34:21 -0500 | [diff] [blame] | 67 | } |
| 68 | } |
Kim Phillips | fd47a74 | 2007-12-20 14:09:22 -0600 | [diff] [blame] | 69 | #endif /* CONFIG_OF_LIBFDT */ |