From patchwork Thu Sep 17 09:13:39 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Minghuan Lian X-Patchwork-Id: 7204191 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id B3DF19F32B for ; Thu, 17 Sep 2015 09:24:41 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8C2CE207E7 for ; Thu, 17 Sep 2015 09:24:40 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 36D05207E4 for ; Thu, 17 Sep 2015 09:24:39 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZcVOn-0001F3-UC; Thu, 17 Sep 2015 09:22:37 +0000 Received: from casper.infradead.org ([2001:770:15f::2]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZcVOl-0001EE-Lp for linux-arm-kernel@bombadil.infradead.org; Thu, 17 Sep 2015 09:22:35 +0000 Received: from mail-bn1on0137.outbound.protection.outlook.com ([157.56.110.137] helo=na01-bn1-obe.outbound.protection.outlook.com) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZcVFy-0002Gf-9Z for linux-arm-kernel@lists.infradead.org; Thu, 17 Sep 2015 09:13:32 +0000 Received: from DM2PR03MB574.namprd03.prod.outlook.com (10.141.84.150) by DM2PR03MB591.namprd03.prod.outlook.com (10.141.85.27) with Microsoft SMTP Server (TLS) id 15.1.268.17; Thu, 17 Sep 2015 09:13:06 +0000 Received: from CO2PR03CA0026.namprd03.prod.outlook.com (10.141.194.153) by DM2PR03MB574.namprd03.prod.outlook.com (10.141.84.150) with Microsoft SMTP Server (TLS) id 15.1.274.16; Thu, 17 Sep 2015 09:13:04 +0000 Received: from BL2FFO11FD021.protection.gbl (2a01:111:f400:7c09::140) by CO2PR03CA0026.outlook.office365.com (2a01:111:e400:1414::25) with Microsoft SMTP Server (TLS) id 15.1.280.12 via Frontend Transport; Thu, 17 Sep 2015 09:13:03 +0000 Authentication-Results: spf=fail (sender IP is 192.88.158.2) smtp.mailfrom=freescale.com; freescale.mail.onmicrosoft.com; dkim=none (message not signed) header.d=none; freescale.mail.onmicrosoft.com; dmarc=none action=none header.from=freescale.com; Received-SPF: Fail (protection.outlook.com: domain of freescale.com does not designate 192.88.158.2 as permitted sender) receiver=protection.outlook.com; client-ip=192.88.158.2; helo=az84smr01.freescale.net; Received: from az84smr01.freescale.net (192.88.158.2) by BL2FFO11FD021.mail.protection.outlook.com (10.173.161.100) with Microsoft SMTP Server (TLS) id 15.1.274.4 via Frontend Transport; Thu, 17 Sep 2015 09:13:02 +0000 Received: from lmh.ap.freescale.net (lmh.ap.freescale.net [10.193.20.20]) by az84smr01.freescale.net (8.14.3/8.14.0) with ESMTP id t8H9CvJU023755; Thu, 17 Sep 2015 02:12:58 -0700 From: Minghuan Lian To: Subject: [PATCH v2] PCI: layerscape: Add PCIe support for LS1043a and LS2080a Date: Thu, 17 Sep 2015 17:13:39 +0800 Message-ID: <1442481219-28299-1-git-send-email-Minghuan.Lian@freescale.com> X-Mailer: git-send-email 1.9.1 X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1; BL2FFO11FD021; 1:JwpWXdfL2ZOBmCBPA18UvABVAm6re8nyQZe4m/XFLzzeNtU6JpxCjnqVAgMlm8UqMx9Dw2a+mQWNSkwoYsYmqIk4hYb8vvz1dxeaKIZ/Lh7oEuaz9OnOHyJJ2Haca1//GP/PaZMznEEY2fHZXx1N0gQ60o96AhbxKKZMmuE4bzU/Flg0dRnxBZCaxmYc+AvhLHqW5XNXm5W2HsD4SqRU/DSkThRCNJvvV7cvDgwBHT7SYtUkLQ0hHipJcji0F4Xnuydz4/cDDNAEoeQH3dzQeAiPIX+rXtvvozNDLTkm11D2m+w03h++27JPjc18Pg0kSLw5Nk3Y9PPPoAlBuErHR+rseu4i6jCk4KeUd2FC3rEQR3YTSxO02wd/rKfax0UzWjRfEAXOcPCqEGGvV4DZXA== X-Forefront-Antispam-Report: CIP:192.88.158.2; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10019020)(6009001)(2980300002)(1110001)(1109001)(339900001)(189002)(54534003)(199003)(86362001)(5007970100001)(92566002)(77096005)(69596002)(6806004)(46102003)(62966003)(77156002)(19580405001)(19580395003)(68736005)(50466002)(107886002)(5001960100002)(110136002)(50226001)(87936001)(105606002)(5003940100001)(48376002)(36756003)(104016003)(2351001)(50986999)(97736004)(5001830100001)(5001860100001)(4001540100001)(64706001)(106466001)(81156007)(47776003)(85426001)(189998001)(229853001)(4001430100001); DIR:OUT; SFP:1102; SCL:1; SRVR:DM2PR03MB574; H:az84smr01.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; MIME-Version: 1.0 X-Microsoft-Exchange-Diagnostics: 1; DM2PR03MB574; 2:vbVqmSO6PJ6A2K7g/eP2xma7inPk7aCqo7fq6R2aJr+PMnEVRUZ9/OfN83XOY3RP02h8416Mlud1ZxikiXhIlE/6AUf+W5zuSD16gtrQE4zN218bdkHBuhbFp8f++UF3nO+T8GWpSqWK0uJA/sWVMRs3B38MAobDgY8tFfCr7fQ=; 3:rHPl83KeMfNh/Cx5VdePFwOuqKOGtrDbDRZNT/8kLvDQxLB9md39JL5cGPziYpbCljI8QRwerH4xjo/P3JVXZA3zmpmK/6mnmWl3eRVVEJFViER4Z4MEjfr4h4eOBF3zAtjSLYPGJx2EpTK4APtf/Hzv7oV9ukPdnqBVszy2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KHQN8RvZ9jYAesmE64eqGSOZzTtgQuTiAVxu5ZQ1wfRyI3TFUrMA== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(8121501046)(5005006)(520078)(3002001); SRVR:DM2PR03MB574; BCL:0; PCL:0; RULEID:; SRVR:DM2PR03MB574; X-Forefront-PRVS: 07025866F6 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DM2PR03MB574; 23:6YR0k8LnUJpRBbZMUeHf1VenpuWv0LEACup2Q65osf?= =?us-ascii?Q?OyIIdCD2v1/niSl91ldYENNx2fXFKVRi/nFZ7HGsoYtedhuGFv0eFH50QGx7?= =?us-ascii?Q?TDjPga7PaCJajvkkF4Jj/myIzPHCTvaYopmrO7RdxS8VQfGoSIIXdV4wPtzd?= =?us-ascii?Q?DLBiK1zInvt4D7SXujGnokLkDVUg1TDJbJ74IkFosdTR/6aCA6wok97jSWcv?= =?us-ascii?Q?0CwEoKdShXd8Qw4HQObZbq7OpH2IqqwwKCAhCetZ86KQ0/RXrlYvoiTQHuqu?= =?us-ascii?Q?Yp9794Yzn1IjrRg3/Vae8X+upDHVRypmoeWW/Q15Odw4hvnAz3RrpdL44nnE?= =?us-ascii?Q?PlWFJII2gRPZ/NFIr9IqUlBe9AfM9xRKwGwTPo4h3E8SFxv0ChBUm2z/JY4P?= =?us-ascii?Q?kbbl3vnxK5IstDia8+19bQ2Rion60tNmZpUqK8BFNI7c63VfH0Fj/vV+TcGk?= =?us-ascii?Q?pO0RVN3SAQ80tZ0YSsjz3ggxsyVa3SRrOjJnW9/VLkB+MWRFp4q+bhl1w+kg?= =?us-ascii?Q?A+IgRp1Sgk8WaFnaTfuRYSf17A5KnpVf1M3vWxPkI+I9Z01b4mYPHjX4/ENw?= =?us-ascii?Q?bQhT/V6VVQm8mWMB14AsHA3Q5C1eZdDaB8ypNZoUIxICWuJXLm5b5BGPAE3a?= =?us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PtMnsSLhPq6Q3w== X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Sep 2015 09:13:02.9850 (UTC) X-MS-Exchange-CrossTenant-Id: 710a03f5-10f6-4d38-9ff4-a80b81da590d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=710a03f5-10f6-4d38-9ff4-a80b81da590d; Ip=[192.88.158.2]; Helo=[az84smr01.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM2PR03MB574 X-Microsoft-Exchange-Diagnostics: 1; DM2PR03MB591; 2:nfseZH8S5W3G00Ra+sp1qD0leA+Le69oue/+3KAbqnMbCXIVANF7aEFwYqhKL5zZh2tLj8T25ZUdC+KteoxdJpPanNAIpSm52feed3xCVKDex+puSJ8IVZ6WGn5CA75wfTjcM/vEdAqYGQPdDHodNTuoKV5lSp24GsezWWB4sjA=; 23:uhnFL/ehS8Lf4XCXnrfntrMKGwBpP8U2Dkwa3xwq3RoHVzDlYsWOB5BYkBrjv2kHMpvFP6CsANpcrky7Nmi2gYcVXQjDcw8oNXnjhm1BRTJt/ahs2oY1m/vxEQrPB6zQgqZv9Z0dwssK20rFXfrihDlP9/qzTk5nbDNbwt0Cf7zm6VceVt7sWB4AW1dXv1Zq X-OriginatorOrg: freescale.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150917_101330_978612_55BF43D9 X-CRM114-Status: GOOD ( 27.92 ) X-Spam-Score: -1.9 (-) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Arnd Bergmann , Jingoo Han , Hu Mingkai-B21284 , Zang Roy-R61911 , Yoder Stuart-B08248 , Minghuan Lian , Zhou Wang , Bjorn Helgaas , Li Yang , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAD_ENC_HEADER,BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The patch adds PCIe support for LS1043a and LS2080a. Signed-off-by: Minghuan Lian --- This patch is based on v4.3-rc1 and [PATCH v9 0/6] PCI: hisi: Add PCIe host support for HiSilicon SoC Hip05 patchset from Zhou Wang. change log v2: 1. rename ls2085a to ls2080a 2. Add ls_pcie_msi_host_init() drivers/pci/host/Kconfig | 2 +- drivers/pci/host/pci-layerscape.c | 227 ++++++++++++++++++++++++++------------ 2 files changed, 157 insertions(+), 72 deletions(-) diff --git a/drivers/pci/host/Kconfig b/drivers/pci/host/Kconfig index ae873be..38fe8a8 100644 --- a/drivers/pci/host/Kconfig +++ b/drivers/pci/host/Kconfig @@ -105,7 +105,7 @@ config PCI_XGENE_MSI config PCI_LAYERSCAPE bool "Freescale Layerscape PCIe controller" - depends on OF && ARM + depends on OF && (ARM || ARM64) select PCIE_DW select MFD_SYSCON help diff --git a/drivers/pci/host/pci-layerscape.c b/drivers/pci/host/pci-layerscape.c index b2328ea1..cdb8737 100644 --- a/drivers/pci/host/pci-layerscape.c +++ b/drivers/pci/host/pci-layerscape.c @@ -11,7 +11,6 @@ */ #include -#include #include #include #include @@ -32,27 +31,68 @@ #define LTSSM_STATE_MASK 0x3f #define LTSSM_PCIE_L0 0x11 /* L0 state */ -/* Symbol Timer Register and Filter Mask Register 1 */ -#define PCIE_STRFMR1 0x71c +/* PEX Internal Configuration Registers */ +#define PCIE_STRFMR1 0x71c /* Symbol Timer & Filter Mask Register1 */ +#define PCIE_DBI_RO_WR_EN 0x8bc /* DBI Read-Only Write Enable Register */ + +/* PEX LUT registers */ +#define PCIE_LUT_DBG 0x7FC /* PEX LUT Debug Register */ + +struct ls_pcie_drvdata { + u32 lut_offset; + u32 ltssm_shift; + struct pcie_host_ops *ops; +}; struct ls_pcie { - struct list_head node; - struct device *dev; - struct pci_bus *bus; - void __iomem *dbi; - struct regmap *scfg; struct pcie_port pp; + const struct ls_pcie_drvdata *drvdata; + void __iomem *regs; + void __iomem *lut; + struct regmap *scfg; int index; - int msi_irq; }; #define to_ls_pcie(x) container_of(x, struct ls_pcie, pp) -static int ls_pcie_link_up(struct pcie_port *pp) +static bool ls_pcie_is_bridge(struct ls_pcie *pcie) +{ + u32 header_type; + + header_type = ioread32(pcie->regs + (PCI_HEADER_TYPE & ~0x3)); + header_type = (header_type >> (8 * (PCI_HEADER_TYPE & 0x3))) & 0x7f; + + return header_type == PCI_HEADER_TYPE_BRIDGE; +} + +/* Clean multi-function bit */ +static void ls_pcie_clean_multifunction(struct ls_pcie *pcie) +{ + u32 val; + + val = ioread32(pcie->regs + (PCI_HEADER_TYPE & ~0x3)); + val &= ~(1 << 23); + iowrite32(val, pcie->regs + (PCI_HEADER_TYPE & ~0x3)); +} + +/* Fix class value */ +static void ls_pcie_fix_class(struct ls_pcie *pcie) +{ + u32 val; + + val = ioread32(pcie->regs + PCI_CLASS_REVISION); + val = (val & 0x0000ffff) | (PCI_CLASS_BRIDGE_PCI << 16); + iowrite32(val, pcie->regs + PCI_CLASS_REVISION); +} + +static int ls1021_pcie_link_up(struct pcie_port *pp) { u32 state; struct ls_pcie *pcie = to_ls_pcie(pp); + if (!pcie->scfg) + return 0; + regmap_read(pcie->scfg, SCFG_PEXMSCPORTSR(pcie->index), &state); state = (state >> LTSSM_STATE_SHIFT) & LTSSM_STATE_MASK; @@ -62,110 +102,155 @@ static int ls_pcie_link_up(struct pcie_port *pp) return 1; } -static int ls_pcie_establish_link(struct pcie_port *pp) +static void ls1021_pcie_host_init(struct pcie_port *pp) { - unsigned int retries; + struct ls_pcie *pcie = to_ls_pcie(pp); + u32 val, index[2]; - for (retries = 0; retries < 200; retries++) { - if (dw_pcie_link_up(pp)) - return 0; - usleep_range(100, 1000); + pcie->scfg = syscon_regmap_lookup_by_phandle(pp->dev->of_node, + "fsl,pcie-scfg"); + if (IS_ERR(pcie->scfg)) { + dev_err(pp->dev, "No syscfg phandle specified\n"); + pcie->scfg = NULL; + return; + } + + if (of_property_read_u32_array(pp->dev->of_node, + "fsl,pcie-scfg", index, 2)) { + pcie->scfg = NULL; + return; } + pcie->index = index[1]; - dev_err(pp->dev, "phy link never came up\n"); - return -EINVAL; + /* + * LS1021A Workaround for internal TKT228622 + * to fix the INTx hang issue + */ + val = ioread32(pcie->regs + PCIE_STRFMR1); + val &= 0xffff; + iowrite32(val, pcie->regs + PCIE_STRFMR1); +} + +static int ls_pcie_link_up(struct pcie_port *pp) +{ + struct ls_pcie *pcie = to_ls_pcie(pp); + u32 state; + + state = (ioread32(pcie->lut + PCIE_LUT_DBG) >> + pcie->drvdata->ltssm_shift) & + LTSSM_STATE_MASK; + + if (state < LTSSM_PCIE_L0) + return 0; + + return 1; } static void ls_pcie_host_init(struct pcie_port *pp) { struct ls_pcie *pcie = to_ls_pcie(pp); - u32 val; - dw_pcie_setup_rc(pp); - ls_pcie_establish_link(pp); + iowrite32(1, pcie->regs + PCIE_DBI_RO_WR_EN); + ls_pcie_fix_class(pcie); + ls_pcie_clean_multifunction(pcie); + iowrite32(0, pcie->regs + PCIE_DBI_RO_WR_EN); +} - /* - * LS1021A Workaround for internal TKT228622 - * to fix the INTx hang issue - */ - val = ioread32(pcie->dbi + PCIE_STRFMR1); - val &= 0xffff; - iowrite32(val, pcie->dbi + PCIE_STRFMR1); +static int ls_pcie_msi_host_init(struct pcie_port *pp, + struct msi_controller *chip) +{ + struct device_node *msi_node; + struct device_node *np = pp->dev->of_node; + + msi_node = of_parse_phandle(np, "msi-parent", 0); + if (!msi_node) { + dev_err(pp->dev, "failed to find msi-parent\n"); + return -EINVAL; + } + + return 0; } +static struct pcie_host_ops ls1021_pcie_host_ops = { + .link_up = ls1021_pcie_link_up, + .host_init = ls1021_pcie_host_init, + .msi_host_init = ls_pcie_msi_host_init, +}; + static struct pcie_host_ops ls_pcie_host_ops = { .link_up = ls_pcie_link_up, .host_init = ls_pcie_host_init, + .msi_host_init = ls_pcie_msi_host_init, }; -static int ls_add_pcie_port(struct ls_pcie *pcie) -{ - struct pcie_port *pp; - int ret; +static struct ls_pcie_drvdata ls1021_drvdata = { + .ops = &ls1021_pcie_host_ops, +}; - pp = &pcie->pp; - pp->dev = pcie->dev; - pp->dbi_base = pcie->dbi; - pp->root_bus_nr = -1; - pp->ops = &ls_pcie_host_ops; +static struct ls_pcie_drvdata ls1043_drvdata = { + .lut_offset = 0x10000, + .ltssm_shift = 24, + .ops = &ls_pcie_host_ops, +}; - ret = dw_pcie_host_init(pp); - if (ret) { - dev_err(pp->dev, "failed to initialize host\n"); - return ret; - } +static struct ls_pcie_drvdata ls2080_drvdata = { + .lut_offset = 0x80000, + .ltssm_shift = 0, + .ops = &ls_pcie_host_ops, +}; - return 0; -} +static const struct of_device_id ls_pcie_of_match[] = { + { .compatible = "fsl,ls1021a-pcie", .data = &ls1021_drvdata }, + { .compatible = "fsl,ls1043a-pcie", .data = &ls1043_drvdata }, + { .compatible = "fsl,ls2080a-pcie", .data = &ls2080_drvdata }, + { }, +}; +MODULE_DEVICE_TABLE(of, ls_pcie_of_match); static int __init ls_pcie_probe(struct platform_device *pdev) { + const struct of_device_id *match; struct ls_pcie *pcie; - struct resource *dbi_base; - u32 index[2]; + struct pcie_port *pp; + struct resource *res; int ret; + match = of_match_device(ls_pcie_of_match, &pdev->dev); + if (!match) + return -ENODEV; + pcie = devm_kzalloc(&pdev->dev, sizeof(*pcie), GFP_KERNEL); if (!pcie) return -ENOMEM; - pcie->dev = &pdev->dev; - - dbi_base = platform_get_resource_byname(pdev, IORESOURCE_MEM, "regs"); - pcie->dbi = devm_ioremap_resource(&pdev->dev, dbi_base); - if (IS_ERR(pcie->dbi)) { + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "regs"); + pcie->regs = devm_ioremap_resource(&pdev->dev, res); + if (IS_ERR(pcie->regs)) { dev_err(&pdev->dev, "missing *regs* space\n"); - return PTR_ERR(pcie->dbi); + return PTR_ERR(pcie->regs); } - pcie->scfg = syscon_regmap_lookup_by_phandle(pdev->dev.of_node, - "fsl,pcie-scfg"); - if (IS_ERR(pcie->scfg)) { - dev_err(&pdev->dev, "No syscfg phandle specified\n"); - return PTR_ERR(pcie->scfg); - } + pcie->drvdata = match->data; + pcie->lut = pcie->regs + pcie->drvdata->lut_offset; + pp = &pcie->pp; + pp->dev = &pdev->dev; + pp->dbi_base = pcie->regs; + pp->ops = pcie->drvdata->ops; - ret = of_property_read_u32_array(pdev->dev.of_node, - "fsl,pcie-scfg", index, 2); - if (ret) - return ret; - pcie->index = index[1]; + if (!ls_pcie_is_bridge(pcie)) + return -ENODEV; - ret = ls_add_pcie_port(pcie); - if (ret < 0) + ret = dw_pcie_host_init(pp); + if (ret) { + dev_err(&pdev->dev, "failed to initialize host\n"); return ret; + } platform_set_drvdata(pdev, pcie); return 0; } -static const struct of_device_id ls_pcie_of_match[] = { - { .compatible = "fsl,ls1021a-pcie" }, - { }, -}; -MODULE_DEVICE_TABLE(of, ls_pcie_of_match); - static struct platform_driver ls_pcie_driver = { .driver = { .name = "layerscape-pcie",