From patchwork Wed Apr 15 09:48:35 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Minghuan Lian X-Patchwork-Id: 6219661 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: patchwork-linux-pci@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id A9615BF4A6 for ; Wed, 15 Apr 2015 10:01:56 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 75E852037A for ; Wed, 15 Apr 2015 10:01:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 34E8D2034F for ; Wed, 15 Apr 2015 10:01:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754452AbbDOKBu (ORCPT ); Wed, 15 Apr 2015 06:01:50 -0400 Received: from mail-bl2on0143.outbound.protection.outlook.com ([65.55.169.143]:5376 "EHLO na01-bl2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754256AbbDOKBt (ORCPT ); Wed, 15 Apr 2015 06:01:49 -0400 Received: from CO2PR03CA0036.namprd03.prod.outlook.com (10.141.194.163) by BY2PR0301MB0741.namprd03.prod.outlook.com (0.160.63.19) with Microsoft SMTP Server (TLS) id 15.1.136.25; Wed, 15 Apr 2015 09:46:59 +0000 Received: from BY2FFO11FD045.protection.gbl (2a01:111:f400:7c0c::135) by CO2PR03CA0036.outlook.office365.com (2a01:111:e400:1414::35) with Microsoft SMTP Server (TLS) id 15.1.118.21 via Frontend Transport; Wed, 15 Apr 2015 09:46:59 +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; 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 BY2FFO11FD045.mail.protection.outlook.com (10.1.15.177) with Microsoft SMTP Server (TLS) id 15.1.142.12 via Frontend Transport; Wed, 15 Apr 2015 09:46:59 +0000 Received: from lmh.ap.freescale.net (lmh.ap.freescale.net [10.193.20.53]) by az84smr01.freescale.net (8.14.3/8.14.0) with ESMTP id t3F9kiPZ007157; Wed, 15 Apr 2015 02:46:55 -0700 From: Minghuan Lian To: CC: , Zang Roy-R61911 , Hu Mingkai-B21284 , Scott Wood , Yoder Stuart-B08248 , Arnd Bergmann , Bjorn Helgaas , "Jingoo Han" , Minghuan Lian Subject: [PATCH v2 3/3] pci/layerscape: Add LS2085A PCIe support Date: Wed, 15 Apr 2015 17:48:35 +0800 Message-ID: <1429091315-31891-4-git-send-email-Minghuan.Lian@freescale.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1429091315-31891-1-git-send-email-Minghuan.Lian@freescale.com> References: <1429091315-31891-1-git-send-email-Minghuan.Lian@freescale.com> X-EOPAttributedMessage: 0 X-Forefront-Antispam-Report: CIP:192.88.158.2; CTRY:US; IPV:NLI; EFV:NLI; BMV:1; SFV:NSPM; SFS:(10019020)(6009001)(339900001)(199003)(189002)(92566002)(62966003)(77156002)(87936001)(47776003)(19580395003)(19580405001)(6806004)(85426001)(46102003)(50226001)(86362001)(575784001)(50986999)(76176999)(77096005)(104016003)(110136001)(2950100001)(2351001)(229853001)(105606002)(106466001)(50466002)(48376002)(36756003)(4001430100001); DIR:OUT; SFP:1102; SCL:1; SRVR:BY2PR0301MB0741; H:az84smr01.freescale.net; FPR:; SPF:Fail; MLV:sfv; A:1; MX:1; LANG:en; MIME-Version: 1.0 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BY2PR0301MB0741; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(5005006)(5002010); SRVR:BY2PR0301MB0741; BCL:0; PCL:0; RULEID:; SRVR:BY2PR0301MB0741; X-Forefront-PRVS: 0547116B72 X-OriginatorOrg: freescale.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Apr 2015 09:46:59.0527 (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: BY2PR0301MB0741 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, 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 LS2085a is based on arm64 architecture, however, currently, layerscape PCIe driver based on pci-desginware.c is not compatible with arm64 architecture. The patch changes code to reuse PCIe Designware Base driver and provides LS2085a PCIe support. Signed-off-by: Minghuan Lian --- change log: v1-v2: 1. remove unnecessary code pcie->lut = pp->dbi + PCIE_LUT_BASE drivers/pci/host/Kconfig | 4 +- drivers/pci/host/pci-layerscape.c | 184 +++++++++++++++++++------------- drivers/pci/host/pcie-designware-base.h | 3 + 3 files changed, 112 insertions(+), 79 deletions(-) diff --git a/drivers/pci/host/Kconfig b/drivers/pci/host/Kconfig index 2a697c0a..e59783a 100644 --- a/drivers/pci/host/Kconfig +++ b/drivers/pci/host/Kconfig @@ -99,8 +99,8 @@ config PCI_XGENE config PCI_LAYERSCAPE bool "Freescale Layerscape PCIe controller" - depends on OF && ARM - select PCIE_DW + depends on OF && (ARM || ARM64) + select PCIE_DW_BASE select MFD_SYSCON help Say Y here if you want PCIe controller support on Layerscape SoCs. diff --git a/drivers/pci/host/pci-layerscape.c b/drivers/pci/host/pci-layerscape.c index 4a6e62f..15c5e47 100644 --- a/drivers/pci/host/pci-layerscape.c +++ b/drivers/pci/host/pci-layerscape.c @@ -1,7 +1,7 @@ /* * PCIe host controller driver for Freescale Layerscape SoCs * - * Copyright (C) 2014 Freescale Semiconductor. + * Copyright (C) 2014 - 2015 Freescale Semiconductor. * * Author: Minghuan Lian * @@ -11,20 +11,16 @@ */ #include -#include -#include +#include #include #include #include -#include -#include #include #include -#include -#include #include +#include -#include "pcie-designware.h" +#include "pcie-designware-base.h" /* PEX1/2 Misc Ports Status Register */ #define SCFG_PEXMSCPORTSR(pex_idx) (0x94 + (pex_idx) * 4) @@ -32,26 +28,29 @@ #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 LUT registers */ +#define PCIE_LUT_BASE 0x80000 +#define PCIE_LUT_DBG 0x7FC /* PEX LUT Debug register */ + +#define PCIE_ATU_NUM 6 struct ls_pcie { - struct list_head node; - struct device *dev; - struct pci_bus *bus; - void __iomem *dbi; - struct regmap *scfg; - struct pcie_port pp; - int index; - int msi_irq; + struct dw_pcie_port pp; + void __iomem *regs; + void __iomem *lut; + struct regmap *scfg; + int index; }; #define to_ls_pcie(x) container_of(x, struct ls_pcie, pp) -static int ls_pcie_link_up(struct pcie_port *pp) +static int ls1_pcie_link_up(struct dw_pcie_port *pp) { - u32 state; struct ls_pcie *pcie = to_ls_pcie(pp); + u32 state; + + if (!pcie->scfg) + return 0; regmap_read(pcie->scfg, SCFG_PEXMSCPORTSR(pcie->index), &state); state = (state >> LTSSM_STATE_SHIFT) & LTSSM_STATE_MASK; @@ -62,91 +61,128 @@ static int ls_pcie_link_up(struct pcie_port *pp) return 1; } -static void ls_pcie_host_init(struct pcie_port *pp) +static int ls1_pcie_host_init(struct dw_pcie_port *pp) { struct ls_pcie *pcie = to_ls_pcie(pp); - int count = 0; - u32 val; - - dw_pcie_setup_rc(pp); + u32 val, index[2]; + int ret; - while (!ls_pcie_link_up(pp)) { - usleep_range(100, 1000); - count++; - if (count >= 200) { - dev_err(pp->dev, "phy link never came up\n"); - return; - } + 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"); + return PTR_ERR(pcie->scfg); } + ret = of_property_read_u32_array(pp->dev->of_node, + "fsl,pcie-scfg", index, 2); + if (ret) + return ret; + + pcie->index = index[1]; + /* * LS1021A Workaround for internal TKT228622 * to fix the INTx hang issue */ - val = ioread32(pcie->dbi + PCIE_STRFMR1); + val = dw_pcie_dbi_read(pp, PCIE_SYMBOL_TIMER_1); val &= 0xffff; - iowrite32(val, pcie->dbi + PCIE_STRFMR1); + dw_pcie_dbi_write(pp, val, PCIE_SYMBOL_TIMER_1); + + /* Fix class value */ + val = dw_pcie_dbi_read(pp, PCI_CLASS_REVISION); + val = (val & 0x0000ffff) | (PCI_CLASS_BRIDGE_PCI << 16); + dw_pcie_dbi_write(pp, val, PCI_CLASS_REVISION); + + if (!ls1_pcie_link_up(pp)) + dev_err(pp->dev, "phy link never came up\n"); + + return 0; } -static struct pcie_host_ops ls_pcie_host_ops = { - .link_up = ls_pcie_link_up, - .host_init = ls_pcie_host_init, +static struct dw_host_ops ls1_dw_host_ops = { + .link_up = ls1_pcie_link_up, + .host_init = ls1_pcie_host_init, }; -static int ls_add_pcie_port(struct ls_pcie *pcie) +static int ls2_pcie_link_up(struct dw_pcie_port *pp) { - struct pcie_port *pp; - int ret; + struct ls_pcie *pcie = to_ls_pcie(pp); + u32 state; - pp = &pcie->pp; - pp->dev = pcie->dev; - pp->dbi_base = pcie->dbi; - pp->root_bus_nr = -1; - pp->ops = &ls_pcie_host_ops; + if (!pcie->lut) + return 0; - ret = dw_pcie_host_init(pp); - if (ret) { - dev_err(pp->dev, "failed to initialize host\n"); - return ret; - } + state = ioread32(pcie->lut + PCIE_LUT_DBG) & LTSSM_STATE_MASK; + if (state < LTSSM_PCIE_L0) + return 0; + + return 1; +} + +static int ls2_pcie_host_init(struct dw_pcie_port *pp) +{ + struct ls_pcie *pcie = to_ls_pcie(pp); + u32 val; + + dw_pcie_dbi_write(pp, 1, PCIE_DBI_RO_WR_EN); + /* Fix class value */ + val = dw_pcie_dbi_read(pp, PCI_CLASS_REVISION); + val = (val & 0x0000ffff) | (PCI_CLASS_BRIDGE_PCI << 16); + dw_pcie_dbi_write(pp, val, PCI_CLASS_REVISION); + /* clean multi-func bit */ + val = dw_pcie_dbi_read(pp, PCI_HEADER_TYPE & ~0x3); + val &= ~(1 << 23); + dw_pcie_dbi_write(pp, val, PCI_HEADER_TYPE & ~0x3); + dw_pcie_dbi_write(pp, 0, PCIE_DBI_RO_WR_EN); + + if (!ls2_pcie_link_up(pp)) + dev_err(pp->dev, "phy link never came up\n"); return 0; } +static struct dw_host_ops ls2_dw_host_ops = { + .link_up = ls2_pcie_link_up, + .host_init = ls2_pcie_host_init, +}; + +static const struct of_device_id ls_pcie_of_match[] = { + { .compatible = "fsl,ls1021a-pcie", .data = &ls1_dw_host_ops }, + { .compatible = "fsl,ls2085a-pcie", .data = &ls2_dw_host_ops }, + { }, +}; +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 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); - } - - 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); + return PTR_ERR(pcie->regs); } - ret = of_property_read_u32_array(pdev->dev.of_node, - "fsl,pcie-scfg", index, 2); - if (ret) - return ret; - pcie->index = index[1]; + pcie->lut = pcie->regs + PCIE_LUT_BASE; + pcie->pp.dev = &pdev->dev; + pcie->pp.dbi = pcie->regs; + pcie->pp.dw_ops = (struct dw_host_ops *)match->data; + pcie->pp.atu_num = PCIE_ATU_NUM; - ret = ls_add_pcie_port(pcie); + ret = dw_pcie_port_init(&pcie->pp); if (ret < 0) return ret; @@ -155,12 +191,6 @@ static int __init ls_pcie_probe(struct platform_device *pdev) 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", diff --git a/drivers/pci/host/pcie-designware-base.h b/drivers/pci/host/pcie-designware-base.h index 60c82de..98b62d6 100644 --- a/drivers/pci/host/pcie-designware-base.h +++ b/drivers/pci/host/pcie-designware-base.h @@ -10,6 +10,9 @@ #define _PCIE_DESIGNWARE_BASE_H /* Synopsis specific PCIE configuration registers */ +#define PCIE_SYMBOL_TIMER_1 0x71c +#define PCIE_DBI_RO_WR_EN 0x8bc + #define PCIE_ATU_VIEWPORT 0x900 #define PCIE_ATU_REGION_INBOUND (0x1 << 31) #define PCIE_ATU_REGION_OUTBOUND (0x0 << 31)