From patchwork Wed Nov 8 09:28:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 835740 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="tPoC1Zsx"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3yX1FG2gqKz9s7c for ; Wed, 8 Nov 2017 20:28:34 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751944AbdKHJ20 (ORCPT ); Wed, 8 Nov 2017 04:28:26 -0500 Received: from mail-wr0-f196.google.com ([209.85.128.196]:56138 "EHLO mail-wr0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751900AbdKHJ2W (ORCPT ); Wed, 8 Nov 2017 04:28:22 -0500 Received: by mail-wr0-f196.google.com with SMTP id l8so1763330wre.12; Wed, 08 Nov 2017 01:28:21 -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=XvEodv5rCJKoTH1awI1RrNGsrC87UyNr0MnA5Uk33XU=; b=tPoC1ZsxydSibSroqZRiPN9Wbrgg5Oty9gGemk9NoXekQtuavMjrVeb9S2DuejtgGr vdtmeMF3KHlxJmn2Pov7xhej/Ftv6NVftcSI+YGiaZ5W2O4+b+fHfTPWr97RI9zSSHVt koi8plj1lDdVKTmDlE+CILZC/6i9mcjX7Hb8k9FTPjMO7G2R7JbbfghQwt73zoCgSsc+ DNu+NdGj2MZcFfP4XE4vBhejj26x3RatVex+g2tDDKMK4IAqW6IHqu0Z4rWLn/YdXGjf OCBQNdbyCRbAbnpZFXeJP5lhE3MGcOLuszHNzGi8OHXSH99QTIaXxYZLICn1+JK/JVDB 4w5g== 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=XvEodv5rCJKoTH1awI1RrNGsrC87UyNr0MnA5Uk33XU=; b=b5s7LJzejJ5K1BdSHpsEHrdJwxoKF3Kmadma5cAEl8o1yROFMZAr6fwJKlcKrsyeTU fKxs/Nuo+JDsKtiu7bM3antZdujTNr7PnDwHLifMoeVnw1P1JrBeNOrJm0Qiw3zYvmxN PP2S9N29+BTdWzfovAgS5ZM8YTIIahrSlDWMK485m9EJOqPusaS3Jwp1vQ9J8H2T380m it7maM9OEKNTXYbPs8fg1forj10D6hwmUqwjrTOEldMAPqiTQg80dvuuZyk+hksOF6Iq x4AI3U0dBDdS+xu4slL4/gdcZgBJM8E4gvUensY9WPMG+/bsgNCiBME7prZbRxl5Nrct RIeg== X-Gm-Message-State: AJaThX59axND6yv/DgYx8nQ80W5SVErJ5RF115I9Ax4Z7HFFpn4oGmNn am5F+lm6D1PmjQAgf93Zv9w6Z4uU X-Google-Smtp-Source: ABhQp+Sq26Dg/mWeQdJhL88P68b1L8hVEowthOkCs6SMuPSFjYz5o21qpRNnm75EibpI3yHsShEePw== X-Received: by 10.223.150.68 with SMTP id c4mr352872wra.255.1510133300716; Wed, 08 Nov 2017 01:28:20 -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 o135sm4489691wmg.1.2017.11.08.01.28.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Nov 2017 01:28:19 -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 2/3] PCI: rcar: Support runtime PM, link state L1 handling Date: Wed, 8 Nov 2017 10:28:05 +0100 Message-Id: <20171108092806.10335-2-marek.vasut+renesas@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171108092806.10335-1-marek.vasut+renesas@gmail.com> References: <20171108092806.10335-1-marek.vasut+renesas@gmail.com> Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org 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: Simon Horman Cc: Wolfram Sang Cc: linux-renesas-soc@vger.kernel.org Acked-by: Simon Horman --- 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 aa588a7d4811..2b28292de93a 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 (1 << 24) #define SCRAMBLE_DISABLE (1 << 27) +#define PMSR 0x01105c +#define L1FAEG (1 << 31) +#define PM_ENTER_L1RX (1 << 23) +#define PMSTATE (7 << 16) +#define PMSTATE_L1 (3 << 16) +#define PMCTLR 0x011060 +#define L1_INIT (1 << 31) #define MACS2R 0x011078 #define MACCGSPSETR 0x011084 #define SPCNGRSN (1 << 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 of 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);