From patchwork Fri Nov 10 21:58:42 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 10053849 X-Patchwork-Delegate: geert@linux-m68k.org 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 7815D6032D for ; Fri, 10 Nov 2017 21:59:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6C0042929B for ; Fri, 10 Nov 2017 21:59:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 60E2B2B11C; Fri, 10 Nov 2017 21:59:07 +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.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI autolearn=ham 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 0461A2929B for ; Fri, 10 Nov 2017 21:59:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754105AbdKJV7F (ORCPT ); Fri, 10 Nov 2017 16:59:05 -0500 Received: from mail-wm0-f65.google.com ([74.125.82.65]:37815 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750932AbdKJV7D (ORCPT ); Fri, 10 Nov 2017 16:59:03 -0500 Received: by mail-wm0-f65.google.com with SMTP id b14so5260908wme.2; Fri, 10 Nov 2017 13:59:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=veqGqBCOjFuTBaWkmv1ir08Suc4Q5a5QDIVkfQ5EwBY=; b=K/MvvFLa3zOLv1180zs7US2zccZcZeTYIXGaIgdA+adZey3TKVeYrzJGHJcgWSR84m eTL91lI5KuBqwzd57Ap9Sw5K1ZU4FlGp85C5nwSgOqO/DjZ2sZifEBBk3YweSr6cMmZP 5ptBXuhUU+BCtTrojR8eVkq2+VglHESlsoeFJxotd8jCBZmBFDi5ZcGYiFCPnQx6TVmA QYYl+LrILlldDSLq1efpZYQa9StulaPkLWKPq/wgYODFtLclGqETrc+T96tBeXzPDcEU MsIzm6fv0S4Sbt/faWHHE2ZQqIxCzW5ZRTB/mR3b2sW25EKAqaiDfVnvINvqBHseC9sK xHyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=veqGqBCOjFuTBaWkmv1ir08Suc4Q5a5QDIVkfQ5EwBY=; b=fwgrqVdvGI8jEM4eDjCrxfGQGP6mznhN48HeXrMjWiFZu1J7Wmk8SIu7ojLSX5C38R civxYuCjvD4Juv2oSOMpJyluKJpGlO3ynvATdLKhQ/bcygMM7FQioq0iqkN0UAqUNV7C +9vl9VI5/N8M8sAoQXcomURTovH7Rq+UetswQsDDI/zLvDzI1KiX94Y3JJMxfdpKX83u Swx31jTmHYrea+10S2YAxh0bmoOgLrsnmM79WftKySAA7k/N4ybkHNn54dHmICXkYeG2 gmO3UmH39SQ/tj5ld4yjrmxtR2n5ScHi3nFyRlD6Iem9MMXbX7reFdp25nFLpAqlTMEv Bj6w== X-Gm-Message-State: AJaThX5hnw4orUOWygs0y2BA1rPt3kCbNQ0sGw7r2Y4wrEjbaU3l6T4h lA+5TcP+uPm74Qpd2WpIhrzDIgn3 X-Google-Smtp-Source: AGs4zMYV8zVx0Ok2iZcWOJ7ezy8x+0thKcdHi2db9Ce4vEfVeLXJbXWzK37K+b1A8CfbMdX86kXlYg== X-Received: by 10.28.232.76 with SMTP id f73mr1228237wmh.45.1510351142078; Fri, 10 Nov 2017 13:59:02 -0800 (PST) Received: from kurokawa.lan (ip-86-49-107-50.net.upcbroadband.cz. [86.49.107.50]) by smtp.gmail.com with ESMTPSA id c3sm4560784wrd.44.2017.11.10.13.59.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 10 Nov 2017 13:59:01 -0800 (PST) From: Marek Vasut X-Google-Original-From: Marek Vasut To: linux-pci@vger.kernel.org Cc: Phil Edworthy , Marek Vasut , Geert Uytterhoeven , Simon Horman , Wolfram Sang , linux-renesas-soc@vger.kernel.org Subject: [PATCH V2 4/5] PCI: rcar: Support runtime PM, link state L1 handling Date: Fri, 10 Nov 2017 22:58:42 +0100 Message-Id: <20171110215843.432-5-marek.vasut+renesas@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171110215843.432-1-marek.vasut+renesas@gmail.com> References: <20171110215843.432-1-marek.vasut+renesas@gmail.com> Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Phil Edworthy Most PCIe host controllers support L0s and L1 power states via ASPM. The R-Car hardware only supports L0s, so when the system suspends and resumes we have to manually handle L1. When the system suspends, cards can put themselves into L1 and send a PM_ENTER_L1 DLLP to the host controller. At this point, we can no longer access the card's config registers. The R-Car host controller will handle taking cards out of L1 as long as the host controller has also been transitioned to L1 link state. Ideally, we would detect the PM_ENTER_L1 DLLP using an interrupt and transition the host to L1 immediately. However, this patch just ensures that we can talk to cards after they have gone into L1. When attempting a config access, it checks to see if the card has gone into L1, and if so, does the same for the host controller. This is based on a patch by Hien Dang Signed-off-by: Phil Edworthy Signed-off-by: Marek Vasut Cc: Geert Uytterhoeven Cc: Phil Edworthy Cc: Simon Horman Cc: Wolfram Sang Cc: linux-renesas-soc@vger.kernel.org Acked-by: Simon Horman --- V2: - Drop extra parenthesis - Use GENMASK() - Fix comment "The HW will handle coming of of L1.", s/of of/out of/ --- drivers/pci/host/pcie-rcar.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/drivers/pci/host/pcie-rcar.c b/drivers/pci/host/pcie-rcar.c index ab61829db389..068bf9067ec1 100644 --- a/drivers/pci/host/pcie-rcar.c +++ b/drivers/pci/host/pcie-rcar.c @@ -92,6 +92,13 @@ #define MACCTLR 0x011058 #define SPEED_CHANGE BIT(24) #define SCRAMBLE_DISABLE BIT(27) +#define PMSR 0x01105c +#define L1FAEG BIT(31) +#define PM_ENTER_L1RX BIT(23) +#define PMSTATE GENMASK(18, 16) +#define PMSTATE_L1 GENMASK(17, 16) +#define PMCTLR 0x011060 +#define L1_INIT BIT(31) #define MACS2R 0x011078 #define MACCGSPSETR 0x011084 #define SPCNGRSN BIT(31) @@ -191,6 +198,7 @@ static int rcar_pcie_config_access(struct rcar_pcie *pcie, unsigned int devfn, int where, u32 *data) { int dev, func, reg, index; + u32 val; dev = PCI_SLOT(devfn); func = PCI_FUNC(devfn); @@ -232,6 +240,22 @@ static int rcar_pcie_config_access(struct rcar_pcie *pcie, if (pcie->root_bus_nr < 0) return PCIBIOS_DEVICE_NOT_FOUND; + /* + * If we are not in L1 link state and we have received PM_ENTER_L1 DLLP, + * transition to L1 link state. The HW will handle coming out of L1. + */ + val = rcar_pci_read_reg(pcie, PMSR); + if (val & PM_ENTER_L1RX && (val & PMSTATE) != PMSTATE_L1) { + rcar_pci_write_reg(pcie, L1_INIT, PMCTLR); + + /* Wait until we are in L1 */ + while (!(val & L1FAEG)) + val = rcar_pci_read_reg(pcie, PMSR); + + /* Clear flags indicating link has transitioned to L1 */ + rcar_pci_write_reg(pcie, L1FAEG | PM_ENTER_L1RX, PMSR); + } + /* Clear errors */ rcar_pci_write_reg(pcie, rcar_pci_read_reg(pcie, PCIEERRFR), PCIEERRFR);