Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932630Ab3HGKXy (ORCPT ); Wed, 7 Aug 2013 06:23:54 -0400 Received: from mail2.gnudd.com ([213.203.150.91]:56325 "EHLO mail.gnudd.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932491Ab3HGKXv (ORCPT ); Wed, 7 Aug 2013 06:23:51 -0400 Date: Wed, 7 Aug 2013 12:17:14 +0200 From: Alessandro Rubini To: linux-kernel@vger.kernel.org Cc: Davide Ciminaghi , Giancarlo Asnaghi , x86@kernel.org, "H. Peter Anvin" , Ingo Molnar , Russell King , Thomas Gleixner , devicetree@vger.kernel.org Subject: [PATCH 05/26] drivers/amba: add support for a PCI bridge Message-ID: <4de65075884a2e91111690e9b83882aefd0fa6d2.1375867291.git.rubini@gnudd.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Organization: GnuDD, Device Drivers, Embedded Systems, Courses References: In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4749 Lines: 158 This is a PCI driver that registers AMBA devices for the range of supported devices. It is currently used by STA2X11, which exports AMBA peripherals under PCIe. The original AMBA drivers work with no changes or minimal ones. Signed-off-by: Alessandro Rubini Acked-by: Giancarlo Asnaghi Cc: Russell King --- drivers/Kconfig | 2 + drivers/amba/Kconfig | 10 +++++ drivers/amba/Makefile | 1 + drivers/amba/pci-amba.c | 93 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 106 insertions(+), 0 deletions(-) create mode 100644 drivers/amba/Kconfig create mode 100644 drivers/amba/pci-amba.c diff --git a/drivers/Kconfig b/drivers/Kconfig index aa43b91..5603bc3 100644 --- a/drivers/Kconfig +++ b/drivers/Kconfig @@ -166,4 +166,6 @@ source "drivers/reset/Kconfig" source "drivers/fmc/Kconfig" +source "drivers/amba/Kconfig" + endmenu diff --git a/drivers/amba/Kconfig b/drivers/amba/Kconfig new file mode 100644 index 0000000..b5b5aca --- /dev/null +++ b/drivers/amba/Kconfig @@ -0,0 +1,10 @@ + +config PCI_AMBA + tristate "PCI-to-AMBA bridge" + depends on ARM_AMBA && PCI + ---help--- + This compiles a PCI driver that registers AMBA devices, so + the respective AMBA driver can be used unchanged if you have + a PCI to amba bridge. This is required for STA2X11 support. + + If uncertain, choose N. diff --git a/drivers/amba/Makefile b/drivers/amba/Makefile index 66e81c2..d30e947 100644 --- a/drivers/amba/Makefile +++ b/drivers/amba/Makefile @@ -1,2 +1,3 @@ obj-$(CONFIG_ARM_AMBA) += bus.o +obj-$(CONFIG_PCI_AMBA) += pci-amba.o obj-$(CONFIG_TEGRA_AHB) += tegra-ahb.o diff --git a/drivers/amba/pci-amba.c b/drivers/amba/pci-amba.c new file mode 100644 index 0000000..8ce526a --- /dev/null +++ b/drivers/amba/pci-amba.c @@ -0,0 +1,93 @@ +/* + * Support for AMBA devices (both APB and AHB) behind a PCI bridge + * Copyright 2012 ST Microelectronics (Alessandro Rubini) + * GNU GPL version 2. + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static int pci_amba_probe(struct pci_dev *pdev, + const struct pci_device_id *id) +{ + struct amba_device *adev; + char *name; + int ret; + + pci_enable_msi(pdev); + ret = pci_enable_device(pdev); + if (ret) + return ret; + + /* Create a name: each of them must be different */ + name = devm_kzalloc(&pdev->dev, strlen(dev_name(&pdev->dev)) + 6, + GFP_KERNEL); + sprintf(name, "amba-%s", dev_name(&pdev->dev)); + + /* Simply build an amba device and register it */ + adev = amba_device_alloc(name, pdev->resource[0].start, SZ_4K); + if (!adev) + return -ENOMEM; + adev->irq[0] = pdev->irq; + + /* This bridge can host both APB and AHB devices, so set master */ + pci_set_master(pdev); + if (pdev->vendor == PCI_VENDOR_ID_STMICRO) { + /* Under sta2x11, DMA is there but limited to 512M */ + adev->dma_mask = SZ_512M - 1; + adev->dev.coherent_dma_mask = SZ_512M - 1; + } + + adev->dev.platform_data = pdev->dev.platform_data; + pci_set_drvdata(pdev, adev); + + return amba_device_add(adev, &pdev->resource[0]); +}; + +static void pci_amba_remove(struct pci_dev *pdev) +{ + struct amba_device *adev = pci_get_drvdata(pdev); + amba_device_unregister(adev); + pci_disable_msi(pdev); +} + +static DEFINE_PCI_DEVICE_TABLE(pci_amba_table) = { + {PCI_VDEVICE(STMICRO, PCI_DEVICE_ID_STMICRO_UART_HWFC)}, + {PCI_VDEVICE(STMICRO, PCI_DEVICE_ID_STMICRO_UART_NO_HWFC)}, + {PCI_VDEVICE(STMICRO, PCI_DEVICE_ID_STMICRO_SOC_DMA)}, + {PCI_VDEVICE(STMICRO, PCI_DEVICE_ID_STMICRO_I2C)}, + {PCI_VDEVICE(STMICRO, PCI_DEVICE_ID_STMICRO_SPI_HS)}, + {PCI_VDEVICE(STMICRO, PCI_DEVICE_ID_STMICRO_SDIO_EMMC)}, + {PCI_VDEVICE(STMICRO, PCI_DEVICE_ID_STMICRO_SDIO)}, + {PCI_VDEVICE(STMICRO, PCI_DEVICE_ID_STMICRO_AUDIO_ROUTER_DMA)}, + {PCI_VDEVICE(STMICRO, PCI_DEVICE_ID_STMICRO_AUDIO_ROUTER_MSPS)}, + {0,} +}; + +static struct pci_driver pci_amba_driver = { + .name = "pci-amba", + .id_table = pci_amba_table, + .probe = pci_amba_probe, + .remove = pci_amba_remove, +}; + +static int __init pci_amba_init(void) +{ + return pci_register_driver(&pci_amba_driver); +} + +static void __exit pci_amba_exit(void) +{ + pci_unregister_driver(&pci_amba_driver); +} + +module_init(pci_amba_init); +module_exit(pci_amba_exit); + +MODULE_LICENSE("GPL"); -- 1.7.7.2 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/