From patchwork Mon Dec 10 13:42:35 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Davide Ciminaghi X-Patchwork-Id: 1858231 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork2.kernel.org (Postfix) with ESMTP id 509E1DFB79 for ; Mon, 10 Dec 2012 13:47:51 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1Ti3f2-0000vV-WF; Mon, 10 Dec 2012 13:44:45 +0000 Received: from bombadil.infradead.org ([2001:4830:2446:ff00:4687:fcff:fea6:5117]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1Ti3eM-0000l4-7s for linux-arm-kernel@merlin.infradead.org; Mon, 10 Dec 2012 13:44:02 +0000 Received: from mail2.gnudd.com ([213.203.150.91] helo=mail.gnudd.com) by bombadil.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1Ti3eK-0004tn-L7 for linux-arm-kernel@lists.infradead.org; Mon, 10 Dec 2012 13:44:01 +0000 Received: from mail.gnudd.com (localhost [127.0.0.1]) by mail.gnudd.com (8.14.3/8.14.3/Debian-9.4) with ESMTP id qBADgqiW006084; Mon, 10 Dec 2012 14:42:52 +0100 Received: (from dciminaghi@localhost) by mail.gnudd.com (8.14.3/8.14.3/Submit) id qBADgpIO006083; Mon, 10 Dec 2012 14:42:51 +0100 From: Davide Ciminaghi To: jaswinder.singh@linaro.org, will.deacon@arm.com, linux@arm.linux.org.uk, tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, djbw@fb.com, vinod.koul@intel.com, grant.likely@secretlab.ca, linus.walleij@linaro.org, rubini@gnudd.com, wim@iguana.be, cjb@laptop.org, davidb@codeaurora.org, nico@fluxnic.net, ben-linux@fluff.org, viresh.linux@gmail.com, rajeev-dlh.kumar@st.com Subject: [PATCH v4 6/7] drivers/amba: add support for a PCI bridge Date: Mon, 10 Dec 2012 14:42:35 +0100 Message-Id: <1355146956-6009-7-git-send-email-ciminaghi@gnudd.com> X-Mailer: git-send-email 1.7.2.5 In-Reply-To: <1355146956-6009-1-git-send-email-ciminaghi@gnudd.com> References: <1355146956-6009-1-git-send-email-ciminaghi@gnudd.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20121210_084401_206118_5C814D99 X-CRM114-Status: GOOD ( 15.56 ) X-Spam-Note: SpamAssassin invocation failed Cc: giancarlo.asnaghi@st.com, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org From: Alessandro Rubini 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 Cc: Alan Cox --- drivers/Kconfig | 2 + drivers/amba/Kconfig | 10 +++++ drivers/amba/Makefile | 1 + drivers/amba/pci-amba.c | 93 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 106 insertions(+) create mode 100644 drivers/amba/Kconfig create mode 100644 drivers/amba/pci-amba.c diff --git a/drivers/Kconfig b/drivers/Kconfig index f5fb072..06838d5 100644 --- a/drivers/Kconfig +++ b/drivers/Kconfig @@ -158,4 +158,6 @@ source "drivers/irqchip/Kconfig" source "drivers/ipack/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..0b0a240 --- /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 __devinit 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 __devexit 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 = __devexit_p(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");