Will Deacon | ce29299 | 2013-11-22 16:14:41 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Simple, generic PCI host controller driver targetting firmware-initialised |
| 3 | * systems and virtual machines (e.g. the PCI emulation provided by kvmtool). |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License version 2 as |
| 7 | * published by the Free Software Foundation. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | * |
| 17 | * Copyright (C) 2014 ARM Limited |
| 18 | * |
| 19 | * Author: Will Deacon <will.deacon@arm.com> |
| 20 | */ |
| 21 | |
| 22 | #include <linux/kernel.h> |
Paul Gortmaker | 99849bf | 2016-07-22 16:21:38 -0500 | [diff] [blame] | 23 | #include <linux/init.h> |
Will Deacon | ce29299 | 2013-11-22 16:14:41 +0000 | [diff] [blame] | 24 | #include <linux/of_address.h> |
| 25 | #include <linux/of_pci.h> |
Jayachandran C | 80955f9 | 2016-06-10 21:55:09 +0200 | [diff] [blame] | 26 | #include <linux/pci-ecam.h> |
Will Deacon | ce29299 | 2013-11-22 16:14:41 +0000 | [diff] [blame] | 27 | #include <linux/platform_device.h> |
| 28 | |
Jayachandran C | 1958e71 | 2016-05-11 17:34:46 -0500 | [diff] [blame] | 29 | static struct pci_ecam_ops gen_pci_cfg_cam_bus_ops = { |
Will Deacon | ce29299 | 2013-11-22 16:14:41 +0000 | [diff] [blame] | 30 | .bus_shift = 16, |
Jayachandran C | 1958e71 | 2016-05-11 17:34:46 -0500 | [diff] [blame] | 31 | .pci_ops = { |
| 32 | .map_bus = pci_ecam_map_bus, |
David Daney | 9a28033 | 2015-10-08 10:15:10 -0500 | [diff] [blame] | 33 | .read = pci_generic_config_read, |
| 34 | .write = pci_generic_config_write, |
| 35 | } |
Will Deacon | ce29299 | 2013-11-22 16:14:41 +0000 | [diff] [blame] | 36 | }; |
| 37 | |
| 38 | static const struct of_device_id gen_pci_of_match[] = { |
| 39 | { .compatible = "pci-host-cam-generic", |
| 40 | .data = &gen_pci_cfg_cam_bus_ops }, |
| 41 | |
| 42 | { .compatible = "pci-host-ecam-generic", |
Jayachandran C | 1958e71 | 2016-05-11 17:34:46 -0500 | [diff] [blame] | 43 | .data = &pci_generic_ecam_ops }, |
Will Deacon | ce29299 | 2013-11-22 16:14:41 +0000 | [diff] [blame] | 44 | |
| 45 | { }, |
| 46 | }; |
Jayachandran C | 1958e71 | 2016-05-11 17:34:46 -0500 | [diff] [blame] | 47 | |
David Daney | d51b3710 | 2016-03-11 15:25:13 -0600 | [diff] [blame] | 48 | static int gen_pci_probe(struct platform_device *pdev) |
| 49 | { |
David Daney | d51b3710 | 2016-03-11 15:25:13 -0600 | [diff] [blame] | 50 | const struct of_device_id *of_id; |
Jayachandran C | 1958e71 | 2016-05-11 17:34:46 -0500 | [diff] [blame] | 51 | struct pci_ecam_ops *ops; |
David Daney | d51b3710 | 2016-03-11 15:25:13 -0600 | [diff] [blame] | 52 | |
Jayachandran C | 1958e71 | 2016-05-11 17:34:46 -0500 | [diff] [blame] | 53 | of_id = of_match_node(gen_pci_of_match, pdev->dev.of_node); |
| 54 | ops = (struct pci_ecam_ops *)of_id->data; |
David Daney | d51b3710 | 2016-03-11 15:25:13 -0600 | [diff] [blame] | 55 | |
Jayachandran C | 1958e71 | 2016-05-11 17:34:46 -0500 | [diff] [blame] | 56 | return pci_host_common_probe(pdev, ops); |
David Daney | d51b3710 | 2016-03-11 15:25:13 -0600 | [diff] [blame] | 57 | } |
| 58 | |
Will Deacon | ce29299 | 2013-11-22 16:14:41 +0000 | [diff] [blame] | 59 | static struct platform_driver gen_pci_driver = { |
| 60 | .driver = { |
| 61 | .name = "pci-host-generic", |
Will Deacon | ce29299 | 2013-11-22 16:14:41 +0000 | [diff] [blame] | 62 | .of_match_table = gen_pci_of_match, |
Brian Norris | a5f40e8 | 2017-04-20 15:36:25 -0500 | [diff] [blame] | 63 | .suppress_bind_attrs = true, |
Will Deacon | ce29299 | 2013-11-22 16:14:41 +0000 | [diff] [blame] | 64 | }, |
| 65 | .probe = gen_pci_probe, |
| 66 | }; |
Paul Gortmaker | 99849bf | 2016-07-22 16:21:38 -0500 | [diff] [blame] | 67 | builtin_platform_driver(gen_pci_driver); |