From patchwork Fri Nov 19 22:07:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jim Quinlan X-Patchwork-Id: 12629597 X-Patchwork-Delegate: lorenzo.pieralisi@arm.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 53F49C433F5 for ; Fri, 19 Nov 2021 22:08:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229675AbhKSWLI (ORCPT ); Fri, 19 Nov 2021 17:11:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234181AbhKSWLG (ORCPT ); Fri, 19 Nov 2021 17:11:06 -0500 Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3E1F7C061574; Fri, 19 Nov 2021 14:08:04 -0800 (PST) Received: by mail-pl1-x634.google.com with SMTP id y7so9221724plp.0; Fri, 19 Nov 2021 14:08:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=+zcuXFbqK8H0xdNFwVNSeclVkixsgVOiV/M+oI0ZGTY=; b=mdTN4XDtNAPQv/72+dhoCFCoxzdfJEdUOuV2E6IjFSHGq7ARXOXM+gVCLtD878WAuV 8eZDGyOkFVOSVG7IYqhgBthLvaYyx4aSunqvokXa4wkp2D3+GlqpQbFbg6x0n+PEiDMK c8xwjWMlUDSQQhbtB76wwk/nEQWLomvM5ckraA06dkwlqDXtkx28Z1YK8hh+IH9EMUao 3zoLQja652aZw8RwZh3EWaA/X3ld6CnyLl6xEGslq3PxWWPVtJrP9KmnwQ4b4/+J6ufo erpvIXtkld22/LCru4axk98shP1D0qxNpTqq+eiFjF55UJ9VmfeTEB8RikE8a/cUWEGI ltdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=+zcuXFbqK8H0xdNFwVNSeclVkixsgVOiV/M+oI0ZGTY=; b=uLOUEr9As3FXWoNmWUeqQjmELpATu5SU0GH/0ggC8C60GN+lNmgg7DxUZnSvubSZp5 pklxM4S7p33eMyT17OymRYQKiEIfu7eHCtRcojZD7GTfwqzTDMhYYgx4mxlNeCT1OCaL BnI7pOCkDCvvoP32VdP3m1dlafsz0PJqtfy2fzC7vjsOR6aBKG6vmJ1R/m4WuMWtLCBu H9uRq+F2OD3hsC/5Y1bCjxBtH25EjcmE1qeLwuh7D6VcjDBVeKmWqpW0k+tdgpCp+eml wqko10S6aXwZDTNX55P/bsQPtMFv7bBnqSynT5LgpT6FSZAYuerA/dUJUH1hXn4ViXKd 3dVA== X-Gm-Message-State: AOAM532iEicuLooFMpHDxt8h21zYfDnoBXluP4jeC9A9+DqKLtBpaaod dFyHCblHjee/7tYVbO6Kpsye+6HsDPc8yA== X-Google-Smtp-Source: ABdhPJzyF20Xa2xvnCY+FSmR4kmroEp3K2+l/gI1fE9Qa5W3WAlNK5vIJABvOyqRzIDhyXuv1sQvog== X-Received: by 2002:a17:902:7fc5:b0:143:6d84:88eb with SMTP id t5-20020a1709027fc500b001436d8488ebmr81623886plb.61.1637359683454; Fri, 19 Nov 2021 14:08:03 -0800 (PST) Received: from stbsrv-and-01.and.broadcom.net ([192.19.11.250]) by smtp.gmail.com with ESMTPSA id t2sm612940pfd.36.2021.11.19.14.08.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Nov 2021 14:08:03 -0800 (PST) From: Jim Quinlan To: linux-pci@vger.kernel.org, Bjorn Helgaas , Nicolas Saenz Julienne , Rob Herring , Mark Brown , bcm-kernel-feedback-list@broadcom.com, jim2101024@gmail.com, james.quinlan@broadcom.com Cc: Florian Fainelli , Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy?= =?utf-8?q?=C5=84ski?= , Philipp Zabel , linux-rpi-kernel@lists.infradead.org (moderated list:BROADCOM BCM2711/BCM2835 ARM ARCHITECTURE), linux-arm-kernel@lists.infradead.org (moderated list:BROADCOM BCM2711/BCM2835 ARM ARCHITECTURE), linux-kernel@vger.kernel.org (open list) Subject: [PATCH v9 1/7] PCI: brcmstb: Fix function return value handling Date: Fri, 19 Nov 2021 17:07:48 -0500 Message-Id: <20211119220756.18628-2-jim2101024@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211119220756.18628-1-jim2101024@gmail.com> References: <20211119220756.18628-1-jim2101024@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Do at least a dev_err() on some calls to reset_control_rearm() and brcm_phy_stop(). In some cases it may not make sense to return this error value "above" as doing so will cause more trouble than is warranted. Signed-off-by: Jim Quinlan --- drivers/pci/controller/pcie-brcmstb.c | 28 +++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/drivers/pci/controller/pcie-brcmstb.c b/drivers/pci/controller/pcie-brcmstb.c index 1fc7bd49a7ad..9ed79ddb6a83 100644 --- a/drivers/pci/controller/pcie-brcmstb.c +++ b/drivers/pci/controller/pcie-brcmstb.c @@ -1146,11 +1146,23 @@ static int brcm_pcie_suspend(struct device *dev) int ret; brcm_pcie_turn_off(pcie); - ret = brcm_phy_stop(pcie); - reset_control_rearm(pcie->rescal); + /* + * If brcm_phy_stop() returns an error, just dev_err(). If we + * return the error it will cause the suspend to fail and this is a + * forgivable offense that will probably be erased on resume. + */ + if (brcm_phy_stop(pcie)) + dev_err(dev, "Could not stop phy for suspend\n"); + + ret = reset_control_rearm(pcie->rescal); + if (ret) { + dev_err(dev, "Could not rearm rescal reset\n"); + return ret; + } + clk_disable_unprepare(pcie->clk); - return ret; + return 0; } static int brcm_pcie_resume(struct device *dev) @@ -1161,7 +1173,9 @@ static int brcm_pcie_resume(struct device *dev) int ret; base = pcie->base; - clk_prepare_enable(pcie->clk); + ret = clk_prepare_enable(pcie->clk); + if (ret) + return ret; ret = reset_control_reset(pcie->rescal); if (ret) @@ -1202,8 +1216,10 @@ static void __brcm_pcie_remove(struct brcm_pcie *pcie) { brcm_msi_remove(pcie); brcm_pcie_turn_off(pcie); - brcm_phy_stop(pcie); - reset_control_rearm(pcie->rescal); + if (brcm_phy_stop(pcie)) + dev_err(pcie->dev, "Could not stop phy\n"); + if (reset_control_rearm(pcie->rescal)) + dev_err(pcie->dev, "Could not rearm rescal reset\n"); clk_disable_unprepare(pcie->clk); } From patchwork Fri Nov 19 22:07:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jim Quinlan X-Patchwork-Id: 12629599 X-Patchwork-Delegate: lorenzo.pieralisi@arm.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 828F8C433EF for ; Fri, 19 Nov 2021 22:08:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234317AbhKSWLO (ORCPT ); Fri, 19 Nov 2021 17:11:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50614 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234286AbhKSWLI (ORCPT ); Fri, 19 Nov 2021 17:11:08 -0500 Received: from mail-pg1-x52a.google.com (mail-pg1-x52a.google.com [IPv6:2607:f8b0:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A9A1C061574; Fri, 19 Nov 2021 14:08:06 -0800 (PST) Received: by mail-pg1-x52a.google.com with SMTP id 28so9727198pgq.8; Fri, 19 Nov 2021 14:08:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=SdN+YJ62TXrTSxCxmD4U/e88GUhW9Xo7AMa+zjJB9y8=; b=OXp8MSbilwTmttnGLC/21f13Z6KyQ05Rx6hfbNx0hQlrVzvHAr7HYuQM6ERfKt2RlY uO6Qnd1JoKkEpq8OslqJONPW3DNXSM1Jhzp5CgGNEFlwZMCTWCf7FzqSamXk4sIe5Wll FuwAip0wibmXE2EleQyzDusP9eHVwzadCE6bm9LhQs82QkMWyS2NZ9b/ByvjZju8jlzW xwJCb7Dv9hlasCsLYQCUPmW8YiUogs/GWtQ5//F9o/3suayeJsRmJGAro9h+XwV4aePl PfGrtYBjSOaq6h3bDgn4J1HfYJmq6wZBiedugGK++gEOK0siS2e9DBfbE04Kt7SAIzRM wi5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=SdN+YJ62TXrTSxCxmD4U/e88GUhW9Xo7AMa+zjJB9y8=; b=DI2MUaHegtQ48gMVZHoOpcmpW4LvuTM5E3faD7EiU1QuMxOQeT4NW1TKEyrtywpYJX t0zsYJiAJxw83X9u9eByLFcDkHfn+saltMqrkVYednBEA9ZOgX7vUAn6YSLDDx6srrud vsSWOLK0LbTiGXYwPeToChc4GCLCoWx7Gy3tTpjlQJ9Ru16DhkYSWGXnDSHUKhRMiy1C f1++OLdSJuxZPAM0zjwm7DGfENe/iR2KuDfXpyALif4gZKhgaIo1chZWWi6BPDtWqErs dxN7MG7HgibPo5ZRr+27Ig44/29S9NIBS/x7IEFlauSAs6cRu5LsRiOZ8kwiEnZ17GCl XsCA== X-Gm-Message-State: AOAM5318k4Zsr5P0Y8zsU2mPlveY0gAjXEK7rWUM1PrRTc8CusYxQLc2 FWGvYb+3RctUIuxIAoZORe1zXAXqWnhjPw== X-Google-Smtp-Source: ABdhPJzH681ogPXuizx1FhR1dB0O3FWsPhf1C1SLgnj8C4S4k5xTzla+QD2tHL+WWWqgejCeApdhHg== X-Received: by 2002:a05:6a00:10d1:b0:47b:aa9b:1e7a with SMTP id d17-20020a056a0010d100b0047baa9b1e7amr26141445pfu.57.1637359685874; Fri, 19 Nov 2021 14:08:05 -0800 (PST) Received: from stbsrv-and-01.and.broadcom.net ([192.19.11.250]) by smtp.gmail.com with ESMTPSA id t2sm612940pfd.36.2021.11.19.14.08.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Nov 2021 14:08:05 -0800 (PST) From: Jim Quinlan To: linux-pci@vger.kernel.org, Bjorn Helgaas , Nicolas Saenz Julienne , Rob Herring , Mark Brown , bcm-kernel-feedback-list@broadcom.com, jim2101024@gmail.com, james.quinlan@broadcom.com Cc: Florian Fainelli , Rob Herring , Saenz Julienne , linux-arm-kernel@lists.infradead.org (moderated list:BROADCOM BCM7XXX ARM ARCHITECTURE), linux-rpi-kernel@lists.infradead.org (moderated list:BROADCOM BCM2711/BCM2835 ARM ARCHITECTURE), devicetree@vger.kernel.org (open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS), linux-kernel@vger.kernel.org (open list) Subject: [PATCH v9 2/7] dt-bindings: PCI: Correct brcmstb interrupts, interrupt-map. Date: Fri, 19 Nov 2021 17:07:49 -0500 Message-Id: <20211119220756.18628-3-jim2101024@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211119220756.18628-1-jim2101024@gmail.com> References: <20211119220756.18628-1-jim2101024@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org The "pcie" and "msi" interrupts were given the same interrupt when they are actually different. Interrupt-map only had the INTA entry; the INTB, INTC, and INTD entries are added. Signed-off-by: Jim Quinlan Acked-by: Florian Fainelli Acked-by: Rob Herring --- Documentation/devicetree/bindings/pci/brcm,stb-pcie.yaml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Documentation/devicetree/bindings/pci/brcm,stb-pcie.yaml b/Documentation/devicetree/bindings/pci/brcm,stb-pcie.yaml index 1fe102743f82..22f2ef446f18 100644 --- a/Documentation/devicetree/bindings/pci/brcm,stb-pcie.yaml +++ b/Documentation/devicetree/bindings/pci/brcm,stb-pcie.yaml @@ -143,11 +143,15 @@ examples: #address-cells = <3>; #size-cells = <2>; #interrupt-cells = <1>; - interrupts = , + interrupts = , ; interrupt-names = "pcie", "msi"; interrupt-map-mask = <0x0 0x0 0x0 0x7>; - interrupt-map = <0 0 0 1 &gicv2 GIC_SPI 143 IRQ_TYPE_LEVEL_HIGH>; + interrupt-map = <0 0 0 1 &gicv2 GIC_SPI 143 IRQ_TYPE_LEVEL_HIGH + 0 0 0 2 &gicv2 GIC_SPI 144 IRQ_TYPE_LEVEL_HIGH + 0 0 0 3 &gicv2 GIC_SPI 145 IRQ_TYPE_LEVEL_HIGH + 0 0 0 4 &gicv2 GIC_SPI 146 IRQ_TYPE_LEVEL_HIGH>; + msi-parent = <&pcie0>; msi-controller; ranges = <0x02000000 0x0 0xf8000000 0x6 0x00000000 0x0 0x04000000>; From patchwork Fri Nov 19 22:07:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jim Quinlan X-Patchwork-Id: 12629601 X-Patchwork-Delegate: lorenzo.pieralisi@arm.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B2E23C43219 for ; Fri, 19 Nov 2021 22:08:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234457AbhKSWLO (ORCPT ); Fri, 19 Nov 2021 17:11:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50630 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234391AbhKSWLM (ORCPT ); Fri, 19 Nov 2021 17:11:12 -0500 Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B8BBC061574; Fri, 19 Nov 2021 14:08:09 -0800 (PST) Received: by mail-pl1-x62d.google.com with SMTP id q17so9136384plr.11; Fri, 19 Nov 2021 14:08:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=7FMM33BgaDXx9wEJ77VEFyRdRiWrhK4qqNx3A3Rw4xQ=; b=qouy1VCikNtWXl5c1BkmoZhh8O9nxnXAYAo5ln/jrgF60O/mra9X8rvx2tUVctEWmv PZOounY6UlD3r5oI8cj1Vx0Y3DH/vsiWGQMqAqj6Vntbw8XMoz6O8yZuTuSw7+4NrdCJ K7IiCD1GW1LdhwUKLBLubhhHkYWGiKaXCUWV2H+qoZN3KeLs+4l/9BCsLL4ivzkrTJYb FTeyPzAkBIjj7lJBMfbDUVXM3t4k1vVt2AJpLvG/LuIizF3Rxr7rPr2MUEUQATscAy96 WQ1SysjIFPoGuXf3Z01VNdAzb5Mxw2ckdh4aol+nnlqf99QB3klXw7HPgl3OIKRKyaeJ CaYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=7FMM33BgaDXx9wEJ77VEFyRdRiWrhK4qqNx3A3Rw4xQ=; b=fMMJcI9B2cmb3aFhX1mUGVcKwsbT4gE/FkwiWxrI/cfo9h/AB7jHcOX4Y/C0r3s+WK 8m4FpUu16mnsdV0oIm89GyESy3oJ3pbdMNF/Xvb/r9LwSu/37HR7WWv3MF9EG5LXwwlD ovCjYss/HUNsrqGC1fveZGg1cn+gDzVEE40ygTB6pBLYqinCKHcNpRsRQu0lVGSpyZzm lp1jC4Ky9Ftktqfe3E7ySPEHIqjHF56nuxJt7GRW19vWGgmf7QvCY/Adfv8FJ2ZtbkVI UZwS07ACbH0HHkQt5l9vctNQY+lCAg5kbmByO1qL1xAoiQ9CUJ+nWReuV/UPmv7ovpx6 q4sQ== X-Gm-Message-State: AOAM533GuMetfhLMMzTdX7TS2ndeFEBuWZcMd1YF9LuA6yZgj+TfNIzX wPA/koXcCyUvPy24Xhb0y/8Wml4uTueAOQ== X-Google-Smtp-Source: ABdhPJxFy5pQVWOP/nGjpyJRTiOKzysS5T0HPsFOfuCrJFDcryBFXtNi/7ENHQg15+kOFjv5rHYWtQ== X-Received: by 2002:a17:902:b20a:b0:143:7add:5ab7 with SMTP id t10-20020a170902b20a00b001437add5ab7mr79967248plr.71.1637359688852; Fri, 19 Nov 2021 14:08:08 -0800 (PST) Received: from stbsrv-and-01.and.broadcom.net ([192.19.11.250]) by smtp.gmail.com with ESMTPSA id t2sm612940pfd.36.2021.11.19.14.08.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Nov 2021 14:08:07 -0800 (PST) From: Jim Quinlan To: linux-pci@vger.kernel.org, Bjorn Helgaas , Nicolas Saenz Julienne , Rob Herring , Mark Brown , bcm-kernel-feedback-list@broadcom.com, jim2101024@gmail.com, james.quinlan@broadcom.com Cc: Florian Fainelli , Rob Herring , Saenz Julienne , linux-arm-kernel@lists.infradead.org (moderated list:BROADCOM BCM7XXX ARM ARCHITECTURE), linux-rpi-kernel@lists.infradead.org (moderated list:BROADCOM BCM2711/BCM2835 ARM ARCHITECTURE), devicetree@vger.kernel.org (open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS), linux-kernel@vger.kernel.org (open list) Subject: [PATCH v9 3/7] dt-bindings: PCI: Add bindings for Brcmstb EP voltage regulators Date: Fri, 19 Nov 2021 17:07:50 -0500 Message-Id: <20211119220756.18628-4-jim2101024@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211119220756.18628-1-jim2101024@gmail.com> References: <20211119220756.18628-1-jim2101024@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Add bindings for Brcmstb EP voltage regulators. A new mechanism is to be added to the Linux PCI subsystem that will allocate and turn on/off regulators. These are standard regulators -- vpcie12v, vpcie3v3, and vpcie3v3aux -- placed in the DT in the bridge node under the host bridge device. The use of a regulator property in the pcie EP subnode such as "vpcie12v-supply" depends on a pending pullreq to the pci-bus.yaml file at https://github.com/devicetree-org/dt-schema/pull/63 Signed-off-by: Jim Quinlan --- .../bindings/pci/brcm,stb-pcie.yaml | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Documentation/devicetree/bindings/pci/brcm,stb-pcie.yaml b/Documentation/devicetree/bindings/pci/brcm,stb-pcie.yaml index 22f2ef446f18..7113a7f726e7 100644 --- a/Documentation/devicetree/bindings/pci/brcm,stb-pcie.yaml +++ b/Documentation/devicetree/bindings/pci/brcm,stb-pcie.yaml @@ -159,5 +159,28 @@ examples: <0x42000000 0x1 0x80000000 0x3 0x00000000 0x0 0x80000000>; brcm,enable-ssc; brcm,scb-sizes = <0x0000000080000000 0x0000000080000000>; + + /* PCIe bridge */ + pci@0,0 { + #address-cells = <3>; + #size-cells = <2>; + reg = <0x0 0x0 0x0 0x0 0x0>; + compatible = "pciclass,0604"; + device_type = "pci"; + vpcie3v3-supply = <&vreg7>; + ranges; + + /* PCIe endpoint */ + pci-ep@0,0 { + assigned-addresses = + <0x82010000 0x0 0xf8000000 0x6 0x00000000 0x0 0x2000>; + reg = <0x0 0x0 0x0 0x0 0x0>; + compatible = "pci14e4,1688"; + #address-cells = <3>; + #size-cells = <2>; + + ranges; + }; + }; }; }; From patchwork Fri Nov 19 22:07:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jim Quinlan X-Patchwork-Id: 12629603 X-Patchwork-Delegate: lorenzo.pieralisi@arm.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 405E8C433EF for ; Fri, 19 Nov 2021 22:08:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234391AbhKSWLT (ORCPT ); Fri, 19 Nov 2021 17:11:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50638 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234141AbhKSWLO (ORCPT ); Fri, 19 Nov 2021 17:11:14 -0500 Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D51F0C061574; Fri, 19 Nov 2021 14:08:11 -0800 (PST) Received: by mail-pl1-x635.google.com with SMTP id k4so9135571plx.8; Fri, 19 Nov 2021 14:08:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=HMfxv0VUowhSTWkfqtHKWA4mWDsGxDgikeURaapabM0=; b=jtRK2sa7R1NiANAOx9RPHIgaf1WH0XTUv4r4S8jXtjeDE+Vex7spv97KOHyQxZ8HaV /vvc3cXBAduY8Z24asR/dVf+qug8LckKjQvP8K2FQmuTwsepUxEk2BMsZRPRU4PzI+SG X/fNEOc0L1K3T4zYCwAytGJIeyJDPru36liSO95necS9tJx0AnWo0olrGDhegVBkZDhU 4OjTi570yMxQRh6ckp/I4sTkehRhsjd6FjH6DcxTZQQoWP1Gdxg2uVncqhrhbcLuhLpz 4UcPF056R2MEv4aZFieyfQDq242YhxoJN1q9ltn2Kp+KNEcbQ/0ntOYsayzZJrnxxKXH AXPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=HMfxv0VUowhSTWkfqtHKWA4mWDsGxDgikeURaapabM0=; b=iNZ9DxgkTy5qUMpeMx0f3iz4yBgJ7J26TlwaDt9k5JiNj71D+VnBRxzBDfVcaBykFK I0F/6rj3b9eJ8sIozFknLd6+dAdIbqM/YFVXka6356trIpy7nlka16iiVYdOCJYOZXuD C7bAbRuFvGfAYYK4cf601MReK4C2Moe0RiPJiY3/RUw0mo3MQ9RlVmnmFDorDorBh1gE pIjnR2PbehE0GW1GTd0kyds5SQ8076rRfxCTY0yjNwyyoU4altSVP9+Y17FcSMkwdlEK 6/aMxbdX/CGAZ7mBYN7f/dLdcjsPrPPrU+orx2Wz68+txszmbR2vELQ5i3fMco365XB/ 8uTA== X-Gm-Message-State: AOAM532eEi2pZJZqBTMrCuWTxrSXpCrBLpDXf0f651b2/rBTvj3CpDg0 0C9yQMXo/KImnu8F/QOhz4tcNx3tX3KV8A== X-Google-Smtp-Source: ABdhPJwNhGFNsvZUx5U4Z2ZIPDqPCBuIULtG+cpwMMEAHC2XewzpapLAgQpneDISgLGOMz1/yG5GLA== X-Received: by 2002:a17:90a:909:: with SMTP id n9mr3567058pjn.1.1637359690842; Fri, 19 Nov 2021 14:08:10 -0800 (PST) Received: from stbsrv-and-01.and.broadcom.net ([192.19.11.250]) by smtp.gmail.com with ESMTPSA id t2sm612940pfd.36.2021.11.19.14.08.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Nov 2021 14:08:10 -0800 (PST) From: Jim Quinlan To: linux-pci@vger.kernel.org, Bjorn Helgaas , Nicolas Saenz Julienne , Rob Herring , Mark Brown , bcm-kernel-feedback-list@broadcom.com, jim2101024@gmail.com, james.quinlan@broadcom.com Cc: linux-kernel@vger.kernel.org (open list) Subject: [PATCH v9 4/7] PCI: Add mechanism to turn on subdev regulators Date: Fri, 19 Nov 2021 17:07:51 -0500 Message-Id: <20211119220756.18628-5-jim2101024@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211119220756.18628-1-jim2101024@gmail.com> References: <20211119220756.18628-1-jim2101024@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Add a mechanism to identify standard PCIe regulators in the DT, allocate them, and turn them on before the rest of the bus is scanned during pci_host_probe(). A root complex driver can leverage this mechanism by setting the pci_ops methods add_bus and remove_bus to pci_subdev_regulators_{add,remove}_bus. If the root complex driver needs to control the regulators on suspend or resume, it must grab the regulator object pointer during the add_bus call by wrapping pci_subdev_regulators_bus() with its own add_bus function. The allocated structure that contains the regulators is stored in the port driver dev.driver_data field. Here is a point-by-point of how and when this mechanism is activated: If: -- PCIe RC driver sets pci_ops {add,remove)_bus to pci_subdev_regulators_{add,remove}_bus during its probe. -- There is a DT node "RB" under the host bridge DT node. -- During the RC driver's pci_host_probe() the add_bus callback is invoked where (bus->parent && pci_is_root_bus(bus->parent) is true Then: -- A struct subdev_regulators structure will be allocated and assigned to bus->dev.driver_data. -- regulator_bulk_{get,enable} will be invoked on &bus->dev and the former will search for and process any vpcie{12v,3v3,3v3aux}-supply properties that reside in node "RB". -- The regulators will be turned off/on for any unbind/bind operations. -- The regulators will be turned off/on for any suspend/resumes, but only if the RC driver handles this on its own. This will appear in a later commit for the pcie-brcmstb.c driver. The unabridged reason for doing this is as follows. We would like the Broadcom STB PCIe root complex driver (and others) to be able to turn off/on regulators[1] that provide power to endpoint[2] devices. Typically, the drivers of these endpoint devices are stock Linux drivers that are not aware that these regulator(s) exist and must be turned on for the driver to be probed. The simple solution of course is to turn these regulators on at boot and keep them on. However, this solution does not satisfy at least three of our usage modes: 1. For example, one customer uses multiple PCIe controllers, but wants the ability to, by script invoking and unbind, turn any or all of them by and their subdevices off to save power, e.g. when in battery mode. 2. Another example is when a watchdog script discovers that an endpoint device is in an unresponsive state and would like to unbind, power toggle, and re-bind just the PCIe endpoint and controller. 3. Of course we also want power turned off during suspend mode. However, some endpoint devices may be able to "wake" during suspend and we need to recognise this case and veto the nominal act of turning off its regulator. Such is the case with Wake-on-LAN and Wake-on-WLAN support where PCIe end-point device needs to be kept powered on in order to receive network packets and wake-up the system. In all of these cases it is advantageous for the PCIe controller to govern the turning off/on the regulators needed by the endpoint device. The first two cases can be done by simply unbinding and binding the PCIe controller, if the controller has control of these regulators. [1] These regulators typically govern the actual power supply to the endpoint chip. Sometimes they may be the official PCIe socket power -- such as 3.3v or aux-3.3v. Sometimes they are truly the regulator(s) that supply power to the EP chip. [2] The 99% configuration of our boards is a single endpoint device attached to the PCIe controller. I use the term endpoint but it could possibly mean a switch as well. Signed-off-by: Jim Quinlan --- drivers/pci/bus.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++ drivers/pci/pci.h | 8 ++++++ 2 files changed, 75 insertions(+) diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c index 3cef835b375f..c2d867d19491 100644 --- a/drivers/pci/bus.c +++ b/drivers/pci/bus.c @@ -419,3 +419,70 @@ void pci_bus_put(struct pci_bus *bus) if (bus) put_device(&bus->dev); } + +static void *alloc_subdev_regulators(struct device *dev) +{ + static const char * const supplies[] = { + "vpcie3v3", + "vpcie3v3aux", + "vpcie12v", + }; + const size_t size = sizeof(struct subdev_regulators) + + sizeof(struct regulator_bulk_data) * ARRAY_SIZE(supplies); + struct subdev_regulators *sr; + int i; + + sr = devm_kzalloc(dev, size, GFP_KERNEL); + if (sr) { + sr->num_supplies = ARRAY_SIZE(supplies); + for (i = 0; i < ARRAY_SIZE(supplies); i++) + sr->supplies[i].supply = supplies[i]; + } + + return sr; +} + +int pci_subdev_regulators_add_bus(struct pci_bus *bus) +{ + struct device *dev = &bus->dev; + struct subdev_regulators *sr; + int ret; + + if (!dev->of_node || !bus->parent || !pci_is_root_bus(bus->parent)) + return 0; + + if (dev->driver_data) + dev_err(dev, "dev.driver_data unexpectedly non-NULL\n"); + + sr = alloc_subdev_regulators(dev); + if (!sr) + return -ENOMEM; + + dev->driver_data = sr; + ret = regulator_bulk_get(dev, sr->num_supplies, sr->supplies); + if (ret) + return ret; + + ret = regulator_bulk_enable(sr->num_supplies, sr->supplies); + if (ret) { + dev_err(dev, "failed to enable regulators for downstream device\n"); + return ret; + } + + return 0; +} +EXPORT_SYMBOL_GPL(pci_subdev_regulators_add_bus); + +void pci_subdev_regulators_remove_bus(struct pci_bus *bus) +{ + struct device *dev = &bus->dev; + struct subdev_regulators *sr = dev->driver_data; + + if (!sr || !bus->parent || !pci_is_root_bus(bus->parent)) + return; + + if (regulator_bulk_disable(sr->num_supplies, sr->supplies)) + dev_err(dev, "failed to disable regulators for downstream device\n"); + dev->driver_data = NULL; +} +EXPORT_SYMBOL_GPL(pci_subdev_regulators_remove_bus); diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index 3d60cabde1a1..7798a5d65ad2 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -3,6 +3,7 @@ #define DRIVERS_PCI_H #include +#include /* Number of possible devfns: 0.0 to 1f.7 inclusive */ #define MAX_NR_DEVFNS 256 @@ -761,4 +762,11 @@ static inline pci_power_t mid_pci_get_power_state(struct pci_dev *pdev) } #endif +struct subdev_regulators { + unsigned int num_supplies; + struct regulator_bulk_data supplies[]; +}; +int pci_subdev_regulators_add_bus(struct pci_bus *bus); +void pci_subdev_regulators_remove_bus(struct pci_bus *bus); + #endif /* DRIVERS_PCI_H */ From patchwork Fri Nov 19 22:07:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jim Quinlan X-Patchwork-Id: 12629605 X-Patchwork-Delegate: lorenzo.pieralisi@arm.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 52453C433F5 for ; Fri, 19 Nov 2021 22:08:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234699AbhKSWLV (ORCPT ); Fri, 19 Nov 2021 17:11:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50650 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234583AbhKSWLQ (ORCPT ); Fri, 19 Nov 2021 17:11:16 -0500 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DF169C061574; Fri, 19 Nov 2021 14:08:13 -0800 (PST) Received: by mail-pj1-x1030.google.com with SMTP id gt5so8928861pjb.1; Fri, 19 Nov 2021 14:08:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=+Qzj5uM3WmTTnFaEKj5iKt+4OPXn0Lx6lUn5gyvkQ+E=; b=GDBt8g5Niq+zlRLNMjg3+WqhC86C2L43ATn6svv85dl6zQ56CsdkZMY3QzF8+H2qd9 gzdYAA4cvCRwImuoXceQ8k5VAeSwmxJq6eGi3A1a5VHCyxqi5Pn0+8mb2fdBEUjZdkjI TcOOyJgdkW+3y0M5aQeRpp7R2X7ELgxGQw1oUg4zH3ZGPIe6Fvwq7cY2SZyrpLrbIvKv orQyHhL9dGhY0JTDRH5ykJyaNhWwvbOv/LKkyLz+/BqFsMgQfSPUBCiiwl06xa8l+Lo/ 6E7XKDSjqGR1VfMKYRfBbYJH/awezZz7En/AxBRDOFmyvamtmMNuJ7ssCOUgvoiRg/j7 n8lA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=+Qzj5uM3WmTTnFaEKj5iKt+4OPXn0Lx6lUn5gyvkQ+E=; b=Q9VYPQp3rk0epDTzq8PONa1l6VqjfrLeKjRvPKxR9/2vemUkq+ZHoFwIKVCk7icowv eDkMQ1RMw9pthQ0u2pohNJEoeHBwtcg5msjTMOWzIxGDQb577do0jG0N1EJwt5SduMbp d4HjZKnwB8GitbDwCwriCb/qw6xEEyMv41mrYQk39+ee3qP0A/YQnfLkvJ4L55uaN/TT A19ebxZk4vvmNfFh7Co9SHOa2yINojcShrEsb+nkvgGg+3oZcYQF47JER/ZzS0e07kRx 9AVvLP1rO/FbCKbCIK3XJRxS3plouQi8FS/+aLb5lO+Xq3K8VKBl/5ByL9FjIQabHMOn FGcg== X-Gm-Message-State: AOAM530IHJFsvFgl/+wHV9rUZFwWYYWoD91aZxW4I1WJ50Akk568ZtLN C3lq9PfeJ2JESdkNJGtorKmlX9+70FbrKw== X-Google-Smtp-Source: ABdhPJxn0P0q6CY+GSX7H1+0FReMXcgaPqgEf8Ede+HaJV7J5IkSZmvYUO6EXrjDi+IyreLfEUSDOg== X-Received: by 2002:a17:90b:4a05:: with SMTP id kk5mr3796903pjb.142.1637359693167; Fri, 19 Nov 2021 14:08:13 -0800 (PST) Received: from stbsrv-and-01.and.broadcom.net ([192.19.11.250]) by smtp.gmail.com with ESMTPSA id t2sm612940pfd.36.2021.11.19.14.08.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Nov 2021 14:08:12 -0800 (PST) From: Jim Quinlan To: linux-pci@vger.kernel.org, Bjorn Helgaas , Nicolas Saenz Julienne , Rob Herring , Mark Brown , bcm-kernel-feedback-list@broadcom.com, jim2101024@gmail.com, james.quinlan@broadcom.com Cc: Florian Fainelli , Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy?= =?utf-8?q?=C5=84ski?= , linux-rpi-kernel@lists.infradead.org (moderated list:BROADCOM BCM2711/BCM2835 ARM ARCHITECTURE), linux-arm-kernel@lists.infradead.org (moderated list:BROADCOM BCM2711/BCM2835 ARM ARCHITECTURE), linux-kernel@vger.kernel.org (open list) Subject: [PATCH v9 5/7] PCI: brcmstb: Split brcm_pcie_setup() into two funcs Date: Fri, 19 Nov 2021 17:07:52 -0500 Message-Id: <20211119220756.18628-6-jim2101024@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211119220756.18628-1-jim2101024@gmail.com> References: <20211119220756.18628-1-jim2101024@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org We need to take some code in brcm_pcie_setup() and put it in a new function brcm_pcie_linkup(). In future commits the brcm_pcie_linkup() function will be called indirectly by pci_host_probe() as opposed to the host driver invoking it directly. Some code that was executed after the PCIe linkup is now placed so that it executes prior to linkup, since this code has to run prior to the invocation of pci_host_probe(). Signed-off-by: Jim Quinlan --- drivers/pci/controller/pcie-brcmstb.c | 65 ++++++++++++++++----------- 1 file changed, 39 insertions(+), 26 deletions(-) diff --git a/drivers/pci/controller/pcie-brcmstb.c b/drivers/pci/controller/pcie-brcmstb.c index 9ed79ddb6a83..5f373227aad6 100644 --- a/drivers/pci/controller/pcie-brcmstb.c +++ b/drivers/pci/controller/pcie-brcmstb.c @@ -863,16 +863,9 @@ static inline int brcm_pcie_get_rc_bar2_size_and_offset(struct brcm_pcie *pcie, static int brcm_pcie_setup(struct brcm_pcie *pcie) { - struct pci_host_bridge *bridge = pci_host_bridge_from_priv(pcie); u64 rc_bar2_offset, rc_bar2_size; void __iomem *base = pcie->base; - struct device *dev = pcie->dev; - struct resource_entry *entry; - bool ssc_good = false; - struct resource *res; - int num_out_wins = 0; - u16 nlw, cls, lnksta; - int i, ret, memc; + int ret, memc; u32 tmp, burst, aspm_support; /* Reset the bridge */ @@ -957,6 +950,40 @@ static int brcm_pcie_setup(struct brcm_pcie *pcie) if (pcie->gen) brcm_pcie_set_gen(pcie, pcie->gen); + /* Don't advertise L0s capability if 'aspm-no-l0s' */ + aspm_support = PCIE_LINK_STATE_L1; + if (!of_property_read_bool(pcie->np, "aspm-no-l0s")) + aspm_support |= PCIE_LINK_STATE_L0S; + tmp = readl(base + PCIE_RC_CFG_PRIV1_LINK_CAPABILITY); + u32p_replace_bits(&tmp, aspm_support, + PCIE_RC_CFG_PRIV1_LINK_CAPABILITY_ASPM_SUPPORT_MASK); + writel(tmp, base + PCIE_RC_CFG_PRIV1_LINK_CAPABILITY); + + /* + * For config space accesses on the RC, show the right class for + * a PCIe-PCIe bridge (the default setting is to be EP mode). + */ + tmp = readl(base + PCIE_RC_CFG_PRIV1_ID_VAL3); + u32p_replace_bits(&tmp, 0x060400, + PCIE_RC_CFG_PRIV1_ID_VAL3_CLASS_CODE_MASK); + writel(tmp, base + PCIE_RC_CFG_PRIV1_ID_VAL3); + + return 0; +} + +static int brcm_pcie_linkup(struct brcm_pcie *pcie) +{ + struct pci_host_bridge *bridge = pci_host_bridge_from_priv(pcie); + struct device *dev = pcie->dev; + void __iomem *base = pcie->base; + struct resource_entry *entry; + struct resource *res; + int num_out_wins = 0; + u16 nlw, cls, lnksta; + bool ssc_good = false; + u32 tmp; + int ret, i; + /* Unassert the fundamental reset */ pcie->perst_set(pcie, 0); @@ -994,24 +1021,6 @@ static int brcm_pcie_setup(struct brcm_pcie *pcie) num_out_wins++; } - /* Don't advertise L0s capability if 'aspm-no-l0s' */ - aspm_support = PCIE_LINK_STATE_L1; - if (!of_property_read_bool(pcie->np, "aspm-no-l0s")) - aspm_support |= PCIE_LINK_STATE_L0S; - tmp = readl(base + PCIE_RC_CFG_PRIV1_LINK_CAPABILITY); - u32p_replace_bits(&tmp, aspm_support, - PCIE_RC_CFG_PRIV1_LINK_CAPABILITY_ASPM_SUPPORT_MASK); - writel(tmp, base + PCIE_RC_CFG_PRIV1_LINK_CAPABILITY); - - /* - * For config space accesses on the RC, show the right class for - * a PCIe-PCIe bridge (the default setting is to be EP mode). - */ - tmp = readl(base + PCIE_RC_CFG_PRIV1_ID_VAL3); - u32p_replace_bits(&tmp, 0x060400, - PCIE_RC_CFG_PRIV1_ID_VAL3_CLASS_CODE_MASK); - writel(tmp, base + PCIE_RC_CFG_PRIV1_ID_VAL3); - if (pcie->ssc) { ret = brcm_pcie_set_ssc(pcie); if (ret == 0) @@ -1200,6 +1209,10 @@ static int brcm_pcie_resume(struct device *dev) if (ret) goto err_reset; + ret = brcm_pcie_linkup(pcie); + if (ret) + goto err_reset; + if (pcie->msi) brcm_msi_set_regs(pcie->msi); From patchwork Fri Nov 19 22:07:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jim Quinlan X-Patchwork-Id: 12629607 X-Patchwork-Delegate: lorenzo.pieralisi@arm.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 50910C433FE for ; Fri, 19 Nov 2021 22:10:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234752AbhKSWLW (ORCPT ); Fri, 19 Nov 2021 17:11:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50664 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234683AbhKSWLS (ORCPT ); Fri, 19 Nov 2021 17:11:18 -0500 Received: from mail-pg1-x52e.google.com (mail-pg1-x52e.google.com [IPv6:2607:f8b0:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 75A7EC061574; Fri, 19 Nov 2021 14:08:16 -0800 (PST) Received: by mail-pg1-x52e.google.com with SMTP id m15so9728000pgu.11; Fri, 19 Nov 2021 14:08:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=dZMcHb3UiJ34ZchDQTmKgC2WeBRqnz1j82a2xIWNX7w=; b=lu51B37sYJkJFff+4OCkUTLnA/V4MDjFmyQPR4U9Pln9/Y3p+vQ2aUKyEYLW8FSDOn 1+bKjMzPzfkb7vguoUrNQE3P/M19UcFi56ZBahJtXHXjw13M07zBwTrv6CuEjsEDj4Gh jqhcEyZm3eCxI1ozZDJgy0My2x/yb51EdzYGGuXxJrKZht4K73UPAyh/7R6Gsh/pwvOD Yo9dBIMF++AVYeY0n2C8szI5VZUehmKThdi1jOyJKqj1iy+VllTBP/+YO+z8fPH0hjb8 U9H7HgAn070B2jiTL2dZF6Sqs9/eUlQPEbFt0tHErfhA71jokMJqU5Dpp+jXa0N/1BAm NxFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=dZMcHb3UiJ34ZchDQTmKgC2WeBRqnz1j82a2xIWNX7w=; b=CShpHcYsBUepc8nrpSxhdrFgtLLhdmO/27SbLEyN8rgjb+GGaa6cdTFuGuQ4t9CjjT A0UdSGaHQEHK/QDurMJf7h0VkQncAbw8GGE4OOtw42qk+O8bKRXsg0+fCBjyFVmlfl/z D2ZLb0L7Yz3fYt1sY0wN/LHuoXxLwjm93MS7tel0x/8SGvHZ8Hejumjn7Lf8B30MLJGx UKs2XI5X4do3q2Q+dfmaEcri4cUIxG8SzEtp/qyV1KSjZGjfQTZzSU/xGQY4JxhgoHNX uM5EU/ntvdtw4GZ5oiYw/ZcELLBxLIDP6MjcpBRotspYmCoRpfVyPIaMWr5EJDPk4Li/ PPlQ== X-Gm-Message-State: AOAM532/z99nEEJ8+5lRUSV0qL2av03iz8AqbGccFr9HO5KG0vqIRcVD K8g3aSqC2bsAmPWuwZaMSQJQk0xKvbghag== X-Google-Smtp-Source: ABdhPJw6rrHXY3KSG+uA7dNZp1Vf6OmAYrr7871M3nftoCAxz8veEZvShrJI+j5PYP+AEEtWnO2CFA== X-Received: by 2002:a05:6a00:1399:b0:49f:ae7d:cda6 with SMTP id t25-20020a056a00139900b0049fae7dcda6mr25962290pfg.10.1637359695710; Fri, 19 Nov 2021 14:08:15 -0800 (PST) Received: from stbsrv-and-01.and.broadcom.net ([192.19.11.250]) by smtp.gmail.com with ESMTPSA id t2sm612940pfd.36.2021.11.19.14.08.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Nov 2021 14:08:15 -0800 (PST) From: Jim Quinlan To: linux-pci@vger.kernel.org, Bjorn Helgaas , Nicolas Saenz Julienne , Rob Herring , Mark Brown , bcm-kernel-feedback-list@broadcom.com, jim2101024@gmail.com, james.quinlan@broadcom.com Cc: Florian Fainelli , Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy?= =?utf-8?q?=C5=84ski?= , Philipp Zabel , linux-rpi-kernel@lists.infradead.org (moderated list:BROADCOM BCM2711/BCM2835 ARM ARCHITECTURE), linux-arm-kernel@lists.infradead.org (moderated list:BROADCOM BCM2711/BCM2835 ARM ARCHITECTURE), linux-kernel@vger.kernel.org (open list) Subject: [PATCH v9 6/7] PCI: brcmstb: Add control of subdevice voltage regulators Date: Fri, 19 Nov 2021 17:07:53 -0500 Message-Id: <20211119220756.18628-7-jim2101024@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211119220756.18628-1-jim2101024@gmail.com> References: <20211119220756.18628-1-jim2101024@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org This Broadcom STB PCIe RC driver has one port and connects directly to one device, be it a switch or an endpoint. We want to be able to leverage the recently added mechansim that allocates and turns on/off subdevice regulators. All that needs to be done is to put the regulator DT nodes in the bridge below host and to set the pci_ops methods add_bus and remove_bus. Note that the pci_subdev_regulators_add_bus() method is wrapped for two reasons: 1. To acheive linkup after the voltage regulators are turned on. 2. If, in the case of an unsuccessful linkup, to redirect any PCIe accesses to subdevices, e.g. the scan for DEV/ID. This redirection is needed because the Broadcom PCIe HW wil issue a CPU abort if such an access is made when there is no linkup. Signed-off-by: Jim Quinlan --- drivers/pci/controller/pcie-brcmstb.c | 81 +++++++++++++++++++++++++-- 1 file changed, 77 insertions(+), 4 deletions(-) diff --git a/drivers/pci/controller/pcie-brcmstb.c b/drivers/pci/controller/pcie-brcmstb.c index 5f373227aad6..9b4df253e79a 100644 --- a/drivers/pci/controller/pcie-brcmstb.c +++ b/drivers/pci/controller/pcie-brcmstb.c @@ -191,6 +191,7 @@ static inline void brcm_pcie_bridge_sw_init_set_generic(struct brcm_pcie *pcie, static inline void brcm_pcie_perst_set_4908(struct brcm_pcie *pcie, u32 val); static inline void brcm_pcie_perst_set_7278(struct brcm_pcie *pcie, u32 val); static inline void brcm_pcie_perst_set_generic(struct brcm_pcie *pcie, u32 val); +static int brcm_pcie_add_bus(struct pci_bus *bus); enum { RGR1_SW_INIT_1, @@ -295,6 +296,8 @@ struct brcm_pcie { u32 hw_rev; void (*perst_set)(struct brcm_pcie *pcie, u32 val); void (*bridge_sw_init_set)(struct brcm_pcie *pcie, u32 val); + bool refusal_mode; + struct subdev_regulators *sr; }; /* @@ -711,6 +714,18 @@ static void __iomem *brcm_pcie_map_conf(struct pci_bus *bus, unsigned int devfn, /* Accesses to the RC go right to the RC registers if slot==0 */ if (pci_is_root_bus(bus)) return PCI_SLOT(devfn) ? NULL : base + where; + if (pcie->refusal_mode) { + /* + * At this point we do not have link. There will be a CPU + * abort -- a quirk with this controller --if Linux tries + * to read any config-space registers besides those + * targeting the host bridge. To prevent this we hijack + * the address to point to a safe access that will return + * 0xffffffff. + */ + writel(0xffffffff, base + PCIE_MISC_RC_BAR2_CONFIG_HI); + return base + PCIE_MISC_RC_BAR2_CONFIG_HI + (where & 0x3); + } /* For devices, write to the config space index register */ idx = PCIE_ECAM_OFFSET(bus->number, devfn, 0); @@ -722,6 +737,8 @@ static struct pci_ops brcm_pcie_ops = { .map_bus = brcm_pcie_map_conf, .read = pci_generic_config_read, .write = pci_generic_config_write, + .add_bus = brcm_pcie_add_bus, + .remove_bus = pci_subdev_regulators_remove_bus, }; static inline void brcm_pcie_bridge_sw_init_set_generic(struct brcm_pcie *pcie, u32 val) @@ -1169,6 +1186,14 @@ static int brcm_pcie_suspend(struct device *dev) return ret; } + if (pcie->sr) { + ret = regulator_bulk_disable(pcie->sr->num_supplies, pcie->sr->supplies); + if (ret) { + dev_err(dev, "Could not turn off regulators\n"); + reset_control_reset(pcie->rescal); + return ret; + } + } clk_disable_unprepare(pcie->clk); return 0; @@ -1186,9 +1211,17 @@ static int brcm_pcie_resume(struct device *dev) if (ret) return ret; + if (pcie->sr) { + ret = regulator_bulk_enable(pcie->sr->num_supplies, pcie->sr->supplies); + if (ret) { + dev_err(dev, "Could not turn on regulators\n"); + goto err_disable_clk; + } + } + ret = reset_control_reset(pcie->rescal); if (ret) - goto err_disable_clk; + goto err_regulator; ret = brcm_phy_start(pcie); if (ret) @@ -1220,6 +1253,8 @@ static int brcm_pcie_resume(struct device *dev) err_reset: reset_control_rearm(pcie->rescal); +err_regulator: + regulator_bulk_disable(pcie->sr->num_supplies, pcie->sr->supplies); err_disable_clk: clk_disable_unprepare(pcie->clk); return ret; @@ -1258,6 +1293,34 @@ static const struct of_device_id brcm_pcie_match[] = { {}, }; +static int brcm_pcie_add_bus(struct pci_bus *bus) +{ + struct device *dev = &bus->dev; + struct brcm_pcie *pcie = (struct brcm_pcie *) bus->sysdata; + int ret; + + if (!dev->of_node || !bus->parent || !pci_is_root_bus(bus->parent)) + return 0; + + ret = pci_subdev_regulators_add_bus(bus); + if (ret) + return ret; + + /* Grab the regulators for suspend/resume */ + pcie->sr = bus->dev.driver_data; + + /* + * If we have failed linkup there is no point to return an error as + * currently it will cause a WARNING() from pci_alloc_child_bus(). + * We return 0 and turn on the "refusal_mode" so that any further + * accesses to the pci_dev just get 0xffffffff + */ + if (brcm_pcie_linkup(pcie) != 0) + pcie->refusal_mode = true; + + return 0; +} + static int brcm_pcie_probe(struct platform_device *pdev) { struct device_node *np = pdev->dev.of_node, *msi_np; @@ -1349,7 +1412,17 @@ static int brcm_pcie_probe(struct platform_device *pdev) platform_set_drvdata(pdev, pcie); - return pci_host_probe(bridge); + ret = pci_host_probe(bridge); + if (!ret && !brcm_pcie_link_up(pcie)) + ret = -ENODEV; + + if (ret) { + brcm_pcie_remove(pdev); + return ret; + } + + return 0; + fail: __brcm_pcie_remove(pcie); return ret; @@ -1358,8 +1431,8 @@ static int brcm_pcie_probe(struct platform_device *pdev) MODULE_DEVICE_TABLE(of, brcm_pcie_match); static const struct dev_pm_ops brcm_pcie_pm_ops = { - .suspend = brcm_pcie_suspend, - .resume = brcm_pcie_resume, + .suspend_noirq = brcm_pcie_suspend, + .resume_noirq = brcm_pcie_resume, }; static struct platform_driver brcm_pcie_driver = { From patchwork Fri Nov 19 22:07:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jim Quinlan X-Patchwork-Id: 12629609 X-Patchwork-Delegate: lorenzo.pieralisi@arm.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E5A6BC433EF for ; Fri, 19 Nov 2021 22:10:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234865AbhKSWLX (ORCPT ); Fri, 19 Nov 2021 17:11:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50682 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234676AbhKSWLV (ORCPT ); Fri, 19 Nov 2021 17:11:21 -0500 Received: from mail-pg1-x52a.google.com (mail-pg1-x52a.google.com [IPv6:2607:f8b0:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AC4AAC061756; Fri, 19 Nov 2021 14:08:18 -0800 (PST) Received: by mail-pg1-x52a.google.com with SMTP id 206so4702677pgb.4; Fri, 19 Nov 2021 14:08:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=1ejdtBcGu/O1Cxw2YS57FB14hxKmb2vB0wySR/Hf7zE=; b=jdKk9h0KGCz7rzKg7MWOpNLiwNJ+xR77xNz2Lxp2dg9w7GUe0LJGBzukoh9vYX6vZX 1D2J6dPOj7CrAIBuw5Iwep3uFzwg8/YkZgqNoW5OOL19QSCkrmdf3qpHqurRgL9OTAe7 xgGk5YkPXlhjKZ83iVhlC37YjNkit/aIb2fCMRvx6cmTHZD8Qi2IRh05HRGQzgWKtuf6 4VG75KaQ4B9pPt71kJsmMqWMeyaPEEg0eqjLIXc6+JQUHFoQF/LR+qEAKWwv0wsml8L/ KMO6G4As02e//7bphr0MS5/ZRo+KJ+IGtSG7RNOJ+1fc8hXDauiIBgRICwZcLWmtPkYU Nsag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=1ejdtBcGu/O1Cxw2YS57FB14hxKmb2vB0wySR/Hf7zE=; b=LT1d/sSbFKv1PRYPK9qiXRmbQeEMG+dR6XoDB1IEHZy+IEtcwvlPMCtWAlkBLhgCSY lyJeyR2yPziDT3JjwdAfa/Stm5MBK+X4FgSMAxNI64JGmymKiQCbqFEY6C6Zi4VbS5iv cEcIFxePgFCOnOQNbE87fBI5vzQHiQbijhCPSAAXJDysMoiXV9D9/c4heXVppR0Eif29 rq01Cm9p/Sz4P2d7LDw8M7ICsbeOm3833LVuzrd1b7JNfocv2sO2DL6cMx5kwrhxTKj2 vB/guV3AXVUHgK2/HCFKYvztP/OmStPHwEL+4yZjuZAssoxLZAiEL3H3V7MQCC8QPEgx rqAQ== X-Gm-Message-State: AOAM533qsCguAhwRwJBMofaZCBVyL3G3XoWwg+Le80tZ41emIKh8YYXx AZSszuQG29oCZIfMKtqeCG/YHjKbp3OPnA== X-Google-Smtp-Source: ABdhPJxfHsOlCGlDapHzJKdRp+W1ALfXhzzHf0u5YLalK3nbMWxxpORK+mLoBIIEPwEk6dmSgOWegA== X-Received: by 2002:a63:454:: with SMTP id 81mr19078349pge.24.1637359698006; Fri, 19 Nov 2021 14:08:18 -0800 (PST) Received: from stbsrv-and-01.and.broadcom.net ([192.19.11.250]) by smtp.gmail.com with ESMTPSA id t2sm612940pfd.36.2021.11.19.14.08.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Nov 2021 14:08:17 -0800 (PST) From: Jim Quinlan To: linux-pci@vger.kernel.org, Bjorn Helgaas , Nicolas Saenz Julienne , Rob Herring , Mark Brown , bcm-kernel-feedback-list@broadcom.com, jim2101024@gmail.com, james.quinlan@broadcom.com Cc: Florian Fainelli , Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy?= =?utf-8?q?=C5=84ski?= , Philipp Zabel , linux-rpi-kernel@lists.infradead.org (moderated list:BROADCOM BCM2711/BCM2835 ARM ARCHITECTURE), linux-arm-kernel@lists.infradead.org (moderated list:BROADCOM BCM2711/BCM2835 ARM ARCHITECTURE), linux-kernel@vger.kernel.org (open list) Subject: [PATCH v9 7/7] PCI: brcmstb: Do not turn off WOL regulators on suspend Date: Fri, 19 Nov 2021 17:07:54 -0500 Message-Id: <20211119220756.18628-8-jim2101024@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211119220756.18628-1-jim2101024@gmail.com> References: <20211119220756.18628-1-jim2101024@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org If any downstream device can be awoken do not turn off the regulators as the device will need them on. Signed-off-by: Jim Quinlan --- drivers/pci/controller/pcie-brcmstb.c | 53 ++++++++++++++++++++++----- 1 file changed, 44 insertions(+), 9 deletions(-) diff --git a/drivers/pci/controller/pcie-brcmstb.c b/drivers/pci/controller/pcie-brcmstb.c index 9b4df253e79a..8e5cbf6850cd 100644 --- a/drivers/pci/controller/pcie-brcmstb.c +++ b/drivers/pci/controller/pcie-brcmstb.c @@ -298,6 +298,7 @@ struct brcm_pcie { void (*bridge_sw_init_set)(struct brcm_pcie *pcie, u32 val); bool refusal_mode; struct subdev_regulators *sr; + bool ep_wakeup_capable; }; /* @@ -1166,9 +1167,21 @@ static void brcm_pcie_turn_off(struct brcm_pcie *pcie) pcie->bridge_sw_init_set(pcie, 1); } +static int pci_dev_may_wakeup(struct pci_dev *dev, void *data) +{ + bool *ret = data; + + if (device_may_wakeup(&dev->dev)) { + *ret = true; + dev_info(&dev->dev, "disable cancelled for wake-up device\n"); + } + return (int) *ret; +} + static int brcm_pcie_suspend(struct device *dev) { struct brcm_pcie *pcie = dev_get_drvdata(dev); + struct pci_host_bridge *bridge = pci_host_bridge_from_priv(pcie); int ret; brcm_pcie_turn_off(pcie); @@ -1187,11 +1200,22 @@ static int brcm_pcie_suspend(struct device *dev) } if (pcie->sr) { - ret = regulator_bulk_disable(pcie->sr->num_supplies, pcie->sr->supplies); - if (ret) { - dev_err(dev, "Could not turn off regulators\n"); - reset_control_reset(pcie->rescal); - return ret; + /* + * Now turn off the regulators, but if at least one + * downstream device is enabled as a wake-up source, do not + * turn off regulators. + */ + pcie->ep_wakeup_capable = false; + pci_walk_bus(bridge->bus, pci_dev_may_wakeup, + &pcie->ep_wakeup_capable); + if (!pcie->ep_wakeup_capable) { + ret = regulator_bulk_disable(pcie->sr->num_supplies, + pcie->sr->supplies); + if (ret) { + dev_err(dev, "Could not turn off regulators\n"); + reset_control_reset(pcie->rescal); + return ret; + } } } clk_disable_unprepare(pcie->clk); @@ -1212,10 +1236,21 @@ static int brcm_pcie_resume(struct device *dev) return ret; if (pcie->sr) { - ret = regulator_bulk_enable(pcie->sr->num_supplies, pcie->sr->supplies); - if (ret) { - dev_err(dev, "Could not turn on regulators\n"); - goto err_disable_clk; + if (pcie->ep_wakeup_capable) { + /* + * We are resuming from a suspend. In the suspend we + * did not disable the power supplies, so there is + * no need to enable them (and falsely increase their + * usage count). + */ + pcie->ep_wakeup_capable = false; + } else { + ret = regulator_bulk_enable(pcie->sr->num_supplies, + pcie->sr->supplies); + if (ret) { + dev_err(dev, "Could not turn on regulators\n"); + goto err_disable_clk; + } } }