From patchwork Thu May 3 19:36:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergei Shtylyov X-Patchwork-Id: 10379027 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E338160159 for ; Thu, 3 May 2018 19:36:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D94D42920D for ; Thu, 3 May 2018 19:36:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CE25A29265; Thu, 3 May 2018 19:36:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0881229253 for ; Thu, 3 May 2018 19:36:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751178AbeECTgn (ORCPT ); Thu, 3 May 2018 15:36:43 -0400 Received: from mail-lf0-f68.google.com ([209.85.215.68]:45771 "EHLO mail-lf0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751246AbeECTgl (ORCPT ); Thu, 3 May 2018 15:36:41 -0400 Received: by mail-lf0-f68.google.com with SMTP id y14-v6so27301522lfy.12 for ; Thu, 03 May 2018 12:36:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cogentembedded-com.20150623.gappssmtp.com; s=20150623; h=subject:from:to:references:organization:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=ivbfWkxvxKVwyUxD7uT44hK/dFArMjOV0HYqK6XMjk8=; b=zZFY6xpcBTyoZq8uD493Q7VL0zl2xK7Sl3CxCWu1D72GVnX8Pi/nB31Uqv5oUhY+1r 21aTpI6ZfiE37CG5bDtM6N/5OJ/hVOx0v33XNQGiNiihBldz3O0fc/rvwXT1VFH1njju kWx+Qp8hdaOb/1aaBJiU2QomVHEhulPK/+X8g62SKhFdHS7efVlIZVjkYlxyaGZnXOxZ 8LhOTqTMq2G//CrQvq/do30MCJ365flXoU6PvSt7bFTuSBpMHXf0Zp/RXXCdNIIUltd6 5BiP6mHJ1d9svD1Nkfuktk5BCgoaCM2N74/roKyw2TBu0pHYZYp42Y0e0gZPZKvwsNYE eLSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:references:organization :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=ivbfWkxvxKVwyUxD7uT44hK/dFArMjOV0HYqK6XMjk8=; b=gMfffD2kWSafGOgCeXbuxQ9wVbR91RzfkIfmNC1b/d0Sy+eg1bX8periXc0KvE0tgv ZoQHfzB73iiG3gzqQdhFHPLpvB9amDat13KhVBHct6U0yRryGZJvIXzz1z+Y+zV1BW3u Wowc5nZ/mXORNCZdTmeV5mhIqW7HJWVLdI/j+9sSgJjd7UKVlX7/typbTF7KdT395/Ph TnTLw9FCHKUOjo4vlgWX6auR8voyMD6c17BYbjuiq7f9Z+8bR5pfDiCRIZf8R5Q7aEG/ 7gjIh1rkTnRCBr1VhZM78d/5ttu0YHFFs2nIjdfHrJVAxb7UOcKRpoH3PDLlSxxWiVJv kduQ== X-Gm-Message-State: ALQs6tBjb0Y27kDEoh3sO/Ew16L/BsU0Syd1uPvl7rA6jSMUAiyPRuCs PMkxR1rJBaQVwZKOQzh1iBCcXQ== X-Google-Smtp-Source: AB8JxZqryuNpb2Zula3V30lBlf+bVsju3wR0WNpgBNpPNGNFr24md0L63vp7L8JG2ZAuRlkAky+Opg== X-Received: by 2002:a2e:5442:: with SMTP id y2-v6mr16090957ljd.11.1525376199666; Thu, 03 May 2018 12:36:39 -0700 (PDT) Received: from wasted.cogentembedded.com ([31.173.85.138]) by smtp.gmail.com with ESMTPSA id h82-v6sm759665lfb.31.2018.05.03.12.36.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 03 May 2018 12:36:38 -0700 (PDT) Subject: [PATCH v3 1/5] pcie-rcar: poll PHYRDY in rcar_pcie_hw_init() From: Sergei Shtylyov To: horms@verge.net.au, bhelgaas@google.com, linux-pci@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Lorenzo Pieralisi References: Organization: Cogent Embedded Message-ID: <89f4bb11-918a-397d-0dd8-5a6e630504f7@cogentembedded.com> Date: Thu, 3 May 2018 22:36:37 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: Content-Language: en-MW Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP In all the R-Car gen1/2/3 manuals, we are instructed to poll PCIEPHYSR for PHYRDY=1 at an early stage of the PCIEC initialization -- while the driver only does this on R-Car H1 (polling a PHY specific register). Add the PHYRDY polling to rcar_pcie_hw_init(). Note that without the special PHY driver on the R-Car V3H (R8A77980) the PCIEC initialization just freezes the kernel -- adding the PHYRDY polling allows the init code to exit gracefully on timeout (PHY starts powered down after reset on this SoC). Signed-off-by: Sergei Shtylyov Reviewed-by: Rob Herring Reviewed-by: Simon Horman --- Changes in version 3: - used the BIT() macro in #define PHYRDY; - added the SoC model # to the patch description; - added Rob's and Simon's tags; - refreshed atop of Marek's patch. drivers/pci/host/pcie-rcar.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) Index: pci/drivers/pci/host/pcie-rcar.c =================================================================== --- pci.orig/drivers/pci/host/pcie-rcar.c +++ pci/drivers/pci/host/pcie-rcar.c @@ -37,6 +37,8 @@ #define PCIECDR 0x000020 #define PCIEMSR 0x000028 #define PCIEINTXR 0x000400 +#define PCIEPHYSR 0x0007f0 +#define PHYRDY BIT(0) #define PCIEMSITXR 0x000840 /* Transfer control */ @@ -527,6 +529,20 @@ static void phy_write_reg(struct rcar_pc phy_wait_for_ack(pcie); } +static int rcar_pcie_wait_for_phyrdy(struct rcar_pcie *pcie) +{ + unsigned int timeout = 10; + + while (timeout--) { + if (rcar_pci_read_reg(pcie, PCIEPHYSR) & PHYRDY) + return 0; + + msleep(5); + } + + return -ETIMEDOUT; +} + static int rcar_pcie_wait_for_dl(struct rcar_pcie *pcie) { unsigned int timeout = 10; @@ -551,6 +567,10 @@ static int rcar_pcie_hw_init(struct rcar /* Set mode */ rcar_pci_write_reg(pcie, 1, PCIEMSR); + err = rcar_pcie_wait_for_phyrdy(pcie); + if (err) + return err; + /* * Initial header for port config space is type 1, set the device * class to match. Hardware takes care of propagating the IDSETR