From patchwork Fri Oct 22 14:06: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: 12577885 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C56B1C433EF for ; Fri, 22 Oct 2021 14:07:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A7CEB60FC4 for ; Fri, 22 Oct 2021 14:07:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233056AbhJVOJy (ORCPT ); Fri, 22 Oct 2021 10:09:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49314 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232942AbhJVOJl (ORCPT ); Fri, 22 Oct 2021 10:09:41 -0400 Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 311D3C061764; Fri, 22 Oct 2021 07:07:24 -0700 (PDT) Received: by mail-pj1-x102b.google.com with SMTP id na16-20020a17090b4c1000b0019f5bb661f9so3188462pjb.0; Fri, 22 Oct 2021 07:07:24 -0700 (PDT) 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=Bsq6iuwj06pXXhljM7U8duGAiebZpibGfx/z6iMK0J4=; b=C3oxmrJLdQJyvbXE2u/UmMh56GtIKnVFUbbbek+adMcBUXo2Jsx5Bp0OK86COwfYjl 6oNXF6MQkJdRLBop4PBpT74JWoeLF6CvL77w1AqwE/EqQGfbzF8AV1ER1KQhE7e4e8E4 9HQYVZiaFnsb9tiT/nFRte1xEudbuvXxGc1c/kp9PZhRParOR8Dm/H8kAIUZjNJtuqew wdnEvZHd7XGsJnPIwIBEV8huYFWG37tomRsnZaK3ZxLT0kSZ4UNa2xoAXUPh6JhGDWng B+KYfUxxO3eVcyrSQ7blsSqSMF+/YPpT5qZT7FQJDHcGEFi6m4Gr2jXvDiqkoRMQZ3C9 zrTw== 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=Bsq6iuwj06pXXhljM7U8duGAiebZpibGfx/z6iMK0J4=; b=zM3IYlaXKeoduGevCkqzIj1fJtzsKpEPHFVq3L50rkoHvjslqWVpiV+94UvTNEjjtF MxPJ5I6oaSe43uc750mtwS32PHU8bXkmT23V4AtVLPqgxRIvLkn487shz3O/k/v2Otoe h2k4C4w5hEI6+ZEXDJQPqdPszDqNGE1rZYnt7jEaa1SI6/g6NANmlxvAOPPIl5cxrcB0 AIDN9yXq9ZovPBffGL1TDL0X7K6EkWewmq3lJeD5YjTG9gEYhEwMA6SQY7fIlxoVZlzu tN7iQCJAlKioyeGm8Lo5oVYXeeJXkzNAE+/X1cPvdSnnyQHv1UmjFOpwr/0urnWhMlWG B3+w== X-Gm-Message-State: AOAM530tW0R4RBwvtA3w110Dt92j8HF/fHU7JZtQnoQfBQVirOZIzkIV nU6SecwwqtbZP+9yCXEctcSW6VapTKswPQ== X-Google-Smtp-Source: ABdhPJxdUhmGq4ZRKzaK21X94AipnqDq19/Ap75RlGsTHAeeHI/6xlZ2h4zOKCpYrE7eNmTk8pBTBw== X-Received: by 2002:a17:902:7616:b0:13f:354a:114f with SMTP id k22-20020a170902761600b0013f354a114fmr52600pll.8.1634911642661; Fri, 22 Oct 2021 07:07:22 -0700 (PDT) Received: from stbsrv-and-01.and.broadcom.net ([192.19.11.250]) by smtp.gmail.com with ESMTPSA id e12sm9482990pfl.67.2021.10.22.07.07.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Oct 2021 07:07:22 -0700 (PDT) From: Jim Quinlan To: linux-pci@vger.kernel.org, Nicolas Saenz Julienne , Rob Herring , Mark Brown , bcm-kernel-feedback-list@broadcom.com, jim2101024@gmail.com, james.quinlan@broadcom.com Cc: Florian Fainelli , Bjorn Helgaas , 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 v5 1/6] dt-bindings: PCI: Add bindings for Brcmstb EP voltage regulators Date: Fri, 22 Oct 2021 10:06:54 -0400 Message-Id: <20211022140714.28767-2-jim2101024@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211022140714.28767-1-jim2101024@gmail.com> References: <20211022140714.28767-1-jim2101024@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Similar to the regulator bindings found in "rockchip-pcie-host.txt", this allows optional regulators to be attached and controlled by the PCIe RC driver. That being said, this driver searches in the DT subnode (the EP node, eg pci@0,0) for the regulator property. 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/54 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 b9589a0daa5c..fec13e4f6eda 100644 --- a/Documentation/devicetree/bindings/pci/brcm,stb-pcie.yaml +++ b/Documentation/devicetree/bindings/pci/brcm,stb-pcie.yaml @@ -154,5 +154,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>; + device_type = "pci"; + ranges; + + /* PCIe endpoint */ + pci@0,0 { + device_type = "pci"; + assigned-addresses = <0x82010000 0x0 0xf8000000 0x6 0x00000000 0x0 0x2000>; + reg = <0x0 0x0 0x0 0x0 0x0>; + compatible = "pci14e4,1688"; + vpcie3v3-supply = <&vreg7>; + + #address-cells = <3>; + #size-cells = <2>; + + ranges; + }; + }; }; }; From patchwork Fri Oct 22 14:06:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jim Quinlan X-Patchwork-Id: 12577887 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8048EC433EF for ; Fri, 22 Oct 2021 14:07:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5F8BD60FC4 for ; Fri, 22 Oct 2021 14:07:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233069AbhJVOJz (ORCPT ); Fri, 22 Oct 2021 10:09:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49330 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233000AbhJVOJr (ORCPT ); Fri, 22 Oct 2021 10:09:47 -0400 Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 61403C061766; Fri, 22 Oct 2021 07:07:28 -0700 (PDT) Received: by mail-pl1-x62c.google.com with SMTP id i1so2744179plr.13; Fri, 22 Oct 2021 07:07:28 -0700 (PDT) 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=duetiEhwSVYHkkfTTxUM0W/FKCKHqjSaMJJk7U7j23k=; b=bVC9gPQqE4Bjgv4jnXvQO7GDQK7llbwnwuwaLac4eINXKJbXUGTzdNWHoB4xt40FaF GdFni/gAVl9wJ0Z0wxAkIDyV1EwpQ8Bd+e/0naoOpSs4POOuCqYF9ICKaPvLLMO+RURt asAmcrnutEzwfxI39WZkdiIf6A/BPiXLEKZ2NtDuEa8NecV+pgNj/yBb9BGvTzSDAdio iUCIdZYI2nLA6GgwKraQHmWRKRHY3UsTOGiT7g0DiKlAdX+dWpDnVBMgrbgijp2jdmsr oEawzOaDpWTNWvtrCQZNIxGyRWaLQxuGgeXApa8ppgjy52YHlZ4YkZDX8MB9Zar0Ix0Y Z8Ag== 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=duetiEhwSVYHkkfTTxUM0W/FKCKHqjSaMJJk7U7j23k=; b=3tnLkm9/kmx0gZN27C2DIbWoFcckQ+FNWF7XDOwUbnWImPwNzU5WerorFY0e5/+bMR 2NOhxi1q8Mz6NgSzvbfbCVgQW3h98RZuao4yjvcJOlZrm8SDrS3sfmeCRZphf0IrPvfi TCSLo4m0Qi5axMlxt4UhvnvFa5u2tOn194S8ECjD9m8jYDeGCP9L8d3RxOKDg9WDN4IL 2tXD69hn6iLx80RNbswu6sJuH0x1gfKRTYsYBjOMAMxf3QyaNZywilXjI++RSIKSEiFR TMNk0UIkoq0ZOlTZhJi+8wGieJ3aWmCk1AaLVS1GOgHCYVkpoBlZ9G6/9FmsbBzjiFp+ KKLg== X-Gm-Message-State: AOAM530ep8m7kMfafd23WQvEZ+6khrlrCF+DhzVpILbJqTK+jfutW+q8 HomRp3Vnp+1ESn4DQywVEdAjpQXId/cw8Q== X-Google-Smtp-Source: ABdhPJyBFb8lfUSQnw4cFxMhJ77DSP5jR2lhKCfHtI2jejGGPqWEcEKODrJqbrYlNex2ihHM7OcUwg== X-Received: by 2002:a17:90a:6b0a:: with SMTP id v10mr14910616pjj.130.1634911647521; Fri, 22 Oct 2021 07:07:27 -0700 (PDT) Received: from stbsrv-and-01.and.broadcom.net ([192.19.11.250]) by smtp.gmail.com with ESMTPSA id e12sm9482990pfl.67.2021.10.22.07.07.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Oct 2021 07:07:26 -0700 (PDT) From: Jim Quinlan To: linux-pci@vger.kernel.org, Nicolas Saenz Julienne , Rob Herring , Mark Brown , bcm-kernel-feedback-list@broadcom.com, jim2101024@gmail.com, james.quinlan@broadcom.com Cc: Greg Kroah-Hartman , "Rafael J. Wysocki" , Bjorn Helgaas , Saravana Kannan , Thomas Gleixner , Konrad Rzeszutek Wilk , Rajat Jain , Bhaskar Chowdhury , Claire Chang , Andy Shevchenko , linux-kernel@vger.kernel.org (open list) Subject: [PATCH v5 2/6] PCI: allow for callback to prepare nascent subdev Date: Fri, 22 Oct 2021 10:06:55 -0400 Message-Id: <20211022140714.28767-3-jim2101024@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211022140714.28767-1-jim2101024@gmail.com> References: <20211022140714.28767-1-jim2101024@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org We would like the Broadcom STB PCIe root complex driver 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, 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. This commit solves the "chicken-and-egg" problem by providing a callback to the RC driver when a downstream device is "discovered" by inspecting its DT, and allowing said driver to allocate the device object prematurely in order to get the regulator(s) and turn them on before the device's ID is read. [1] These regulators typically govern the actual power supply to the endpoint chip. Sometimes they may be a 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 possible mean a switch as well. Signed-off-by: Jim Quinlan --- drivers/base/core.c | 5 +++++ drivers/pci/probe.c | 47 ++++++++++++++++++++++++++++++++---------- include/linux/device.h | 3 +++ include/linux/pci.h | 3 +++ 4 files changed, 47 insertions(+), 11 deletions(-) diff --git a/drivers/base/core.c b/drivers/base/core.c index 249da496581a..62d9ac123ae5 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -2864,6 +2864,10 @@ static void klist_children_put(struct klist_node *n) */ void device_initialize(struct device *dev) { + /* Return if this has been called already. */ + if (dev->device_initialized) + return; + dev->kobj.kset = devices_kset; kobject_init(&dev->kobj, &device_ktype); INIT_LIST_HEAD(&dev->dma_pools); @@ -2892,6 +2896,7 @@ void device_initialize(struct device *dev) #ifdef CONFIG_SWIOTLB dev->dma_io_tlb_mem = &io_tlb_default_mem; #endif + dev->device_initialized = true; } EXPORT_SYMBOL_GPL(device_initialize); diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index d9fc02a71baa..12947e972b7b 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -2372,27 +2372,52 @@ EXPORT_SYMBOL(pci_bus_read_dev_vendor_id); */ static struct pci_dev *pci_scan_device(struct pci_bus *bus, int devfn) { - struct pci_dev *dev; + struct pci_host_bridge *hb = pci_find_host_bridge(bus); + struct pci_dev *dev = NULL; u32 l; - if (!pci_bus_read_dev_vendor_id(bus, devfn, &l, 60*1000)) - return NULL; + /* + * If the host bridge has a pci_subdev_prepare() function, first + * call it with true as the first argument to see if it "cares" + * about this device. A non-zero return value indicates it cares, + * so in that case partially allocate some of the device and call + * pci_subdev_prepare() again, with false as the first argument. + * This tells it to allow the host bridge driver to pre-allocate + * some resources such as voltage regulators. + */ + if (hb->pci_subdev_prepare + && hb->pci_subdev_prepare(true, bus, devfn, NULL, NULL)) { + dev = pci_alloc_dev(bus); + if (!dev) + return NULL; - dev = pci_alloc_dev(bus); - if (!dev) - return NULL; + dev->devfn = devfn; + device_initialize(&dev->dev); + /* Call again, this time for actual prep work */ + if (hb->pci_subdev_prepare(false, bus, devfn, hb, dev) + || !pci_bus_read_dev_vendor_id(bus, devfn, &l, 60*1000)) + goto err_out; + } else { + if (!pci_bus_read_dev_vendor_id(bus, devfn, &l, 60*1000)) + return NULL; + dev = pci_alloc_dev(bus); + if (!dev) + return NULL; + } dev->devfn = devfn; dev->vendor = l & 0xffff; dev->device = (l >> 16) & 0xffff; - if (pci_setup_device(dev)) { - pci_bus_put(dev->bus); - kfree(dev); - return NULL; - } + if (pci_setup_device(dev)) + goto err_out; return dev; + +err_out: + pci_bus_put(dev->bus); + kfree(dev); + return NULL; } void pcie_report_downtraining(struct pci_dev *dev) diff --git a/include/linux/device.h b/include/linux/device.h index e270cb740b9e..cf175684a270 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -461,6 +461,8 @@ struct dev_links_info { * and optionall (if the coherent mask is large enough) also * for dma allocations. This flag is managed by the dma ops * instance from ->dma_supported. + * @device_initialized: true if device_initialize(dev) has already been + * invoked, false otherwise. * * At the lowest level, every device in a Linux system is represented by an * instance of struct device. The device structure contains the information @@ -575,6 +577,7 @@ struct device { #ifdef CONFIG_DMA_OPS_BYPASS bool dma_ops_bypass : 1; #endif + bool device_initialized : 1; }; /** diff --git a/include/linux/pci.h b/include/linux/pci.h index cd8aa6fce204..7a72b3af1e33 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -552,6 +552,9 @@ struct pci_host_bridge { u8 (*swizzle_irq)(struct pci_dev *, u8 *); /* Platform IRQ swizzler */ int (*map_irq)(const struct pci_dev *, u8, u8); void (*release_fn)(struct pci_host_bridge *); + int (*pci_subdev_prepare)(bool query, struct pci_bus *bus, int devfn, + struct pci_host_bridge *hb, + struct pci_dev *pdev); void *release_data; unsigned int ignore_reset_delay:1; /* For entire hierarchy */ unsigned int no_ext_tags:1; /* No Extended Tags */ From patchwork Fri Oct 22 14:06:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jim Quinlan X-Patchwork-Id: 12577895 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C7868C433F5 for ; Fri, 22 Oct 2021 14:07:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id ACBB361056 for ; Fri, 22 Oct 2021 14:07:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232349AbhJVOKE (ORCPT ); Fri, 22 Oct 2021 10:10:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49342 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233013AbhJVOJr (ORCPT ); Fri, 22 Oct 2021 10:09:47 -0400 Received: from mail-pg1-x52c.google.com (mail-pg1-x52c.google.com [IPv6:2607:f8b0:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7B411C061243; Fri, 22 Oct 2021 07:07:30 -0700 (PDT) Received: by mail-pg1-x52c.google.com with SMTP id s136so3427595pgs.4; Fri, 22 Oct 2021 07:07:30 -0700 (PDT) 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=+KIUczUS/ZsYc2yKqmHED/7x17icKPInYDTolIdaty0=; b=R5SGZu++CgAI53CDoFpKRRq5pfPpbRWzsDQhASS7V4vht2a8aJA26iGAM6WMSY8/DI iwh/3R/FvCGNziPaSgeMjNtmqoG//S/ugGtHwv7FzwaV+D/6Ts9VQFQ9SMA5cRZPe6A6 7bCbyu8IPjO4jLXNpe59zANpZ3tLFdg9fMiVg5ihOdFiexyP78XUVsCEXGblSkPCcLgK 8IupRQ+hjlwQKGX2iZaduGm4oFG6mwBl0J6c4U6KoUjhDpo6Oys3yb8U3VhSIpD6M4w4 HuNrJg14LPzjgVOWapzHaZbCk0EagD12edxAhjgpGv43/Fl8N1tq0EcBccWfaU35pGGH TIAA== 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=+KIUczUS/ZsYc2yKqmHED/7x17icKPInYDTolIdaty0=; b=8Gr+1KjcYnout5wk1RWkCjeq7dW3xkUlJL+DoQawHdh64iCBwjEY+0ntkdMNY/ZGYE 7K+rFKGVT1QX7LkVjJsMnWJ5igpRlOWGeS9j6CE3m13u2+2md2dYWRd1lzChnP5vIOMW KqPct3/vof2qxhfGLm7cHg2+Oa7ncMXHkl9MYjyx+2zTymMDaLjKTVWf4PTlqvGY58uD 6itCVzXYiFdlhISq1vLynw4SVmvr+fZ1sdbqt6gpXclBCWXn4BCF12ihZpcP0gt9AIGA WmPottSLkTd97QufVi6DRmyb7VAqgMzM30mP0OiddHjO4jWNOekmMXKWinpDVaT5zvK/ 3uww== X-Gm-Message-State: AOAM530j5bPAkCxwiAjVMx5BRrpXtVZ4eWFuLrZNqYe/SlR+4A66Dm2J tPR9C7+absIR7WqWqwgbgTKUaHOcB7xReg== X-Google-Smtp-Source: ABdhPJyEsS1l7Tar/HjbpqhXPB/7RZ8R0mvhJOIAjFQICeySHFB/Iw9Wd2lHo3yMnA7UWO/xk/F2AA== X-Received: by 2002:a05:6a00:1309:b0:44d:4d1e:c930 with SMTP id j9-20020a056a00130900b0044d4d1ec930mr12610806pfu.65.1634911649761; Fri, 22 Oct 2021 07:07:29 -0700 (PDT) Received: from stbsrv-and-01.and.broadcom.net ([192.19.11.250]) by smtp.gmail.com with ESMTPSA id e12sm9482990pfl.67.2021.10.22.07.07.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Oct 2021 07:07:29 -0700 (PDT) From: Jim Quinlan To: linux-pci@vger.kernel.org, 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?= , Bjorn Helgaas , 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 v5 3/6] PCI: brcmstb: split brcm_pcie_setup() into two funcs Date: Fri, 22 Oct 2021 10:06:56 -0400 Message-Id: <20211022140714.28767-4-jim2101024@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211022140714.28767-1-jim2101024@gmail.com> References: <20211022140714.28767-1-jim2101024@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org We need to split a function in two so that the driver can take advantage of the recently added function pci_subdev_prepare() which is a member of struct pci_host_bridge. Signed-off-by: Jim Quinlan --- drivers/pci/controller/pcie-brcmstb.c | 30 +++++++++++++++++++-------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/drivers/pci/controller/pcie-brcmstb.c b/drivers/pci/controller/pcie-brcmstb.c index cc30215f5a43..ba4d6daf312c 100644 --- a/drivers/pci/controller/pcie-brcmstb.c +++ b/drivers/pci/controller/pcie-brcmstb.c @@ -863,17 +863,10 @@ 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; - u32 tmp, burst, aspm_support; + int ret, memc; + u32 tmp, burst; /* Reset the bridge */ pcie->bridge_sw_init_set(pcie, 1); @@ -956,6 +949,21 @@ static int brcm_pcie_setup(struct brcm_pcie *pcie) if (pcie->gen) brcm_pcie_set_gen(pcie, pcie->gen); + 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 aspm_support, tmp; + int ret, i; /* Unassert the fundamental reset */ pcie->perst_set(pcie, 0); @@ -1186,6 +1194,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 Oct 22 14:06:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jim Quinlan X-Patchwork-Id: 12577889 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8A6AEC4332F for ; Fri, 22 Oct 2021 14:07:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 769CB60FBF for ; Fri, 22 Oct 2021 14:07:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231741AbhJVOJ4 (ORCPT ); Fri, 22 Oct 2021 10:09:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49356 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233010AbhJVOJu (ORCPT ); Fri, 22 Oct 2021 10:09:50 -0400 Received: from mail-pg1-x52f.google.com (mail-pg1-x52f.google.com [IPv6:2607:f8b0:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 16A00C061224; Fri, 22 Oct 2021 07:07:33 -0700 (PDT) Received: by mail-pg1-x52f.google.com with SMTP id 75so3433920pga.3; Fri, 22 Oct 2021 07:07:33 -0700 (PDT) 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=8+7GShJO/vFXregS3LjDBjs7+CHBjOeZ46IIUcz+82c=; b=aD3uV1d1rh3SsCQNd4/bjpuRFgXpnkRF1jXcLQqkp3tzCGhC6SHFtTkh3idy9iuakK 4By1yuPRVYMe9HZg/enPGNAXIF1vMCfuzhFRLKtZDC/+lM5OYQZcWflAHfJBQCmg4wMu PMQgpMXgnJeMVg58ymO2Jp7G0a1UNU8gq4uzADvyUJLRnWbJVVHn+kZE2Iusf3BhU6oT F460+zafzgY0kwlwnFqUNFg9MHFvns6aviYMmLHMIsnUetcDB79cXOX5hXHjhTgBpnlk 75rPhoO/aLsqLMIOyFjSxUOk7u3hQMtxuBqiGcVFPihB/Fs/RXv3e8hF0qveCIvjmmPd F1/A== 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=8+7GShJO/vFXregS3LjDBjs7+CHBjOeZ46IIUcz+82c=; b=UbPiyWFkRJ1E/D1oOtZjF2oQx4RCdP2WrzqOtGzZs4Nfizl9VHHgtZ3l036gcrV70P VctVUnlPjzMQagTrwzJV42d8Er7JMQRmFaabxNISunHrW5aPJbfSx8OTradtPlWzmCz1 is30m8VXEVFrqwxwwL4WBrvQpo3Lr+LkJomhkQEP9PMofODRwFE9dPFC7SYpsZlUQcYT UciJ4jpQXV2L3WxzvNrupYHd+2IyHxd2y94kpUlX3aNf4c4CesbS5SRXVYFdizZdNPPO is+7A/1K29Lb0mDluafQNRf92aW2C6whPQISgrgVMM+zUo9ikp8/b0Wb7KkYMvX3fZkl DGBw== X-Gm-Message-State: AOAM530e5cKRrn4EyZZPuhX7iufLIIMf/qcZyXsW3S5bbEEzz8h0Niqb EjXYWrqf6TQtAXIT6VjosAUdE0z883dUMw== X-Google-Smtp-Source: ABdhPJwQLhAuM9RJahLcrYBc+wH1UumKiFKoS2YMyYKRw9+SGSh7JIrnTm5XjsuFe2gT/b+99l7U0w== X-Received: by 2002:a63:2cd8:: with SMTP id s207mr9681631pgs.312.1634911652294; Fri, 22 Oct 2021 07:07:32 -0700 (PDT) Received: from stbsrv-and-01.and.broadcom.net ([192.19.11.250]) by smtp.gmail.com with ESMTPSA id e12sm9482990pfl.67.2021.10.22.07.07.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Oct 2021 07:07:31 -0700 (PDT) From: Jim Quinlan To: linux-pci@vger.kernel.org, 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?= , Bjorn Helgaas , 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 v5 4/6] PCI: brcmstb: Add control of subdevice voltage regulators Date: Fri, 22 Oct 2021 10:06:57 -0400 Message-Id: <20211022140714.28767-5-jim2101024@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211022140714.28767-1-jim2101024@gmail.com> References: <20211022140714.28767-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 turn on/off any regulators for that device. Control of regulators is needed because of the chicken-and-egg situation: although the regulator is "owned" by the device and would be best handled by its driver, the device cannot be discovered and probed unless its regulator is already turned on. Signed-off-by: Jim Quinlan --- drivers/pci/controller/pcie-brcmstb.c | 148 +++++++++++++++++++++++++- 1 file changed, 146 insertions(+), 2 deletions(-) diff --git a/drivers/pci/controller/pcie-brcmstb.c b/drivers/pci/controller/pcie-brcmstb.c index ba4d6daf312c..35924af1c3aa 100644 --- a/drivers/pci/controller/pcie-brcmstb.c +++ b/drivers/pci/controller/pcie-brcmstb.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -192,6 +193,13 @@ 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 const char * const supplies[] = { + "vpcie3v3-supply", + "vpcie3v3aux-supply", + "brcm-ep-a-supply", + "brcm-ep-b-supply", +}; + enum { RGR1_SW_INIT_1, EXT_CFG_INDEX, @@ -295,8 +303,27 @@ 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); + struct regulator_bulk_data supplies[ARRAY_SIZE(supplies)]; + unsigned int num_supplies; }; +static int brcm_set_regulators(struct brcm_pcie *pcie, bool on) +{ + struct device *dev = pcie->dev; + int ret; + + if (!pcie->num_supplies) + return 0; + if (on) + ret = regulator_bulk_enable(pcie->num_supplies, pcie->supplies); + else + ret = regulator_bulk_disable(pcie->num_supplies, pcie->supplies); + if (ret) + dev_err(dev, "failed to %s EP regulators\n", + on ? "enable" : "disable"); + return ret; +} + /* * This is to convert the size of the inbound "BAR" region to the * non-linear values of PCIE_X_MISC_RC_BAR[123]_CONFIG_LO.SIZE @@ -1148,6 +1175,55 @@ static void brcm_pcie_turn_off(struct brcm_pcie *pcie) pcie->bridge_sw_init_set(pcie, 1); } +static int brcm_pcie_get_regulators(struct brcm_pcie *pcie, struct pci_dev *dev) +{ + const unsigned int ns = ARRAY_SIZE(supplies); + struct device_node *dn; + struct property *pp; + unsigned int i; + int ret; + + /* This is for Broadcom STB/CM chips only */ + if (pcie->type == BCM2711) + return 0; + + pci_set_of_node(dev); + dn = dev->dev.of_node; + if (!dn) + return 0; + + for_each_property_of_node(dn, pp) { + for (i = 0; i < ns; i++) + if (strcmp(supplies[i], pp->name) == 0) + break; + if (i >= ns || pcie->num_supplies >= ARRAY_SIZE(supplies)) + continue; + + pcie->supplies[pcie->num_supplies++].supply = supplies[i]; + } + + if (pcie->num_supplies == 0) + return 0; + + /* + * We set the name ahead of time as the regulator core expects + * it to exist when regulator_bulk_get() is called. + */ + dev_set_name(&dev->dev, "%04x:%02x:%02x.%d", + pci_domain_nr(dev->bus), + dev->bus->number, PCI_SLOT(dev->devfn), + PCI_FUNC(dev->devfn)); + /* + * We cannot use devm_regulator_bulk_get() because the + * downstream device may be removed w/o the regulator + * first being disabled by the host bridge. + */ + ret = regulator_bulk_get(&dev->dev, pcie->num_supplies, + pcie->supplies); + + return ret; +} + static int brcm_pcie_suspend(struct device *dev) { struct brcm_pcie *pcie = dev_get_drvdata(dev); @@ -1158,7 +1234,7 @@ static int brcm_pcie_suspend(struct device *dev) reset_control_rearm(pcie->rescal); clk_disable_unprepare(pcie->clk); - return ret; + return brcm_set_regulators(pcie, false); } static int brcm_pcie_resume(struct device *dev) @@ -1174,6 +1250,9 @@ static int brcm_pcie_resume(struct device *dev) ret = reset_control_reset(pcie->rescal); if (ret) goto err_disable_clk; + ret = brcm_set_regulators(pcie, true); + if (ret) + goto err_reset; ret = brcm_phy_start(pcie); if (ret) @@ -1217,6 +1296,10 @@ static void __brcm_pcie_remove(struct brcm_pcie *pcie) brcm_phy_stop(pcie); reset_control_rearm(pcie->rescal); clk_disable_unprepare(pcie->clk); + if (pcie->num_supplies) { + (void)brcm_set_regulators(pcie, false); + regulator_bulk_free(pcie->num_supplies, pcie->supplies); + } } static int brcm_pcie_remove(struct platform_device *pdev) @@ -1241,6 +1324,56 @@ static const struct of_device_id brcm_pcie_match[] = { {}, }; +static int brcm_pcie_pci_subdev_prepare(bool query, struct pci_bus *bus, int devfn, + struct pci_host_bridge *bridge, + struct pci_dev *pdev) +{ + struct brcm_pcie *pcie; + int ret = 0; + + /* + * We only care about a device that is directly connected + * to the root complex, ie bus == 1 and slot == 0. + */ + if (query) + return (bus->number == 1 && PCI_SLOT(devfn) == 0); + + + pcie = (struct brcm_pcie *) bridge->sysdata; + ret = brcm_pcie_get_regulators(pcie, pdev); + if (ret) { + pcie->num_supplies = 0; + if (ret != -EPROBE_DEFER) + dev_err(pcie->dev, "failed to get regulators (err=%d)\n", ret); + return ret; + } + + ret = brcm_set_regulators(pcie, true); + if (ret) + goto err_out0; + + ret = brcm_pcie_linkup(pcie); + if (ret) + goto err_out1; + + /* + * dev_set_name() was called in brcm_set_regulators(). Free the + * string it allocated as it will be called again when + * pci_setup_device() is invoked. + */ + kfree_const(pdev->dev.kobj.name); + pdev->dev.kobj.name = NULL; + + return 0; + +err_out1: + brcm_set_regulators(pcie, false); +err_out0: + regulator_bulk_free(pcie->num_supplies, pcie->supplies); + pcie->num_supplies = 0; + return ret; +} + static int brcm_pcie_probe(struct platform_device *pdev) { struct device_node *np = pdev->dev.of_node, *msi_np; @@ -1327,12 +1460,23 @@ static int brcm_pcie_probe(struct platform_device *pdev) } } + bridge->pci_subdev_prepare = brcm_pcie_pci_subdev_prepare; bridge->ops = &brcm_pcie_ops; bridge->sysdata = pcie; platform_set_drvdata(pdev, pcie); - return pci_host_probe(bridge); + ret = pci_host_probe(bridge); + if (ret) + goto fail; + + if (!brcm_pcie_link_up(pcie)) { + brcm_pcie_remove(pdev); + return -ENODEV; + } + + return 0; + fail: __brcm_pcie_remove(pcie); return ret; From patchwork Fri Oct 22 14:06:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jim Quinlan X-Patchwork-Id: 12577891 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id ADF9AC433F5 for ; Fri, 22 Oct 2021 14:07:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 972A860FBF for ; Fri, 22 Oct 2021 14:07:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232842AbhJVOJ6 (ORCPT ); Fri, 22 Oct 2021 10:09:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49378 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233055AbhJVOJy (ORCPT ); Fri, 22 Oct 2021 10:09:54 -0400 Received: from mail-pg1-x535.google.com (mail-pg1-x535.google.com [IPv6:2607:f8b0:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A64AC061228; Fri, 22 Oct 2021 07:07:35 -0700 (PDT) Received: by mail-pg1-x535.google.com with SMTP id e65so3418348pgc.5; Fri, 22 Oct 2021 07:07:35 -0700 (PDT) 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=1OFqIrT+18a19n7objTdvw3Haq7UJKXHt+0jk9CGrew=; b=NhSB2bAHDpM6mMF01d5U0eL/0XiFzhOfpiCYIEyHu+ctod2WCJ9m/yRZ4wVCwUmO08 0xqarR1YZzFPtvT3Xk7EkOJ4TEvsgOfcFuyWHiyVucvPmSkiL5ZHihtqLjmF+Yr7hWhf R5YSYZt28A6h6iiu+QvFR2wrIZfspQX+msQbm7JQUB2C29zyCtJSb+fPTMdwZbI5OIXd leWMTdvIUbW7+kWg7KVNEtpKewqWRh+NciaP8z5psOfS0h5/C5yOaU4ab7jlA8p6POqQ LJdFPtmYSFbUaIcq6gATySfTseWlujhUPLBxNKRDHt8d51FgyDPb1d8c+4DaeJU5y67o rIsA== 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=1OFqIrT+18a19n7objTdvw3Haq7UJKXHt+0jk9CGrew=; b=oPywuVl6+jNVsWSOH+FOfFFakmsyVqtAEpqmks6YByorlL+h6RIIPluuyemezCZpDa DGDFfcKXRrLD5svZvxlzOZw+qUWGv+7N3M5N/ZhzGAA0NaMVoFgV96v2jzqtQkCFA8Jk dJajmjkKU/krWxLJudBpEZspLglcTY4pbB+BvTqzwLTZRa87u3peAcs7q88OLKiNO5bb ba671QKT5vWH/py8tZKgxd1NrcY3yhLFAU8B90ZVJp9cmIr5sdcluXFyt3ZzO6gUXJsH rO7g4tvP3mYMIOengmXqKjLUq4Y4Tnwu3OcCClhufwfly2y1RTyAfci68wBWz8iMd0eN LL4w== X-Gm-Message-State: AOAM532e1xeeuwG0ykq0x7qvEm30KtXXKLpeuCqr5V/Cpo0InOUeOGPK hnFPFHDd63Mcsi4ArBH0n9+4hrmC/26zJw== X-Google-Smtp-Source: ABdhPJxGxUjF1hom1kgQ2Wlvy0rCVgLkb5Yatk+nFFmu0vYBaqDoZMn4pg6f+ZsIfDDNpcsrdMSL2g== X-Received: by 2002:a05:6a00:2484:b0:44d:ce87:3627 with SMTP id c4-20020a056a00248400b0044dce873627mr258943pfv.48.1634911654640; Fri, 22 Oct 2021 07:07:34 -0700 (PDT) Received: from stbsrv-and-01.and.broadcom.net ([192.19.11.250]) by smtp.gmail.com with ESMTPSA id e12sm9482990pfl.67.2021.10.22.07.07.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Oct 2021 07:07:34 -0700 (PDT) From: Jim Quinlan To: linux-pci@vger.kernel.org, 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?= , Bjorn Helgaas , 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 v5 5/6] PCI: brcmstb: Do not turn off regulators if EP can wake up Date: Fri, 22 Oct 2021 10:06:58 -0400 Message-Id: <20211022140714.28767-6-jim2101024@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211022140714.28767-1-jim2101024@gmail.com> References: <20211022140714.28767-1-jim2101024@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org If any downstream device may wake up during S2/S3 suspend, we do not want to turn off its power when suspending. Signed-off-by: Jim Quinlan --- drivers/pci/controller/pcie-brcmstb.c | 59 +++++++++++++++++++++++---- 1 file changed, 52 insertions(+), 7 deletions(-) diff --git a/drivers/pci/controller/pcie-brcmstb.c b/drivers/pci/controller/pcie-brcmstb.c index 35924af1c3aa..505f74bd1a51 100644 --- a/drivers/pci/controller/pcie-brcmstb.c +++ b/drivers/pci/controller/pcie-brcmstb.c @@ -192,6 +192,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 bool brcm_pcie_link_up(struct brcm_pcie *pcie); static const char * const supplies[] = { "vpcie3v3-supply", @@ -305,22 +306,65 @@ struct brcm_pcie { void (*bridge_sw_init_set)(struct brcm_pcie *pcie, u32 val); struct regulator_bulk_data supplies[ARRAY_SIZE(supplies)]; unsigned int num_supplies; + bool ep_wakeup_capable; }; -static int brcm_set_regulators(struct brcm_pcie *pcie, bool on) +static int pci_dev_may_wakeup(struct pci_dev *dev, void *data) { + bool *ret = data; + + if (device_may_wakeup(&dev->dev)) { + *ret = true; + dev_dbg(&dev->dev, "disable cancelled for wake-up device\n"); + } + return (int) *ret; +} + +enum { + TURN_OFF, /* Turn regulators off, unless an EP is wakeup-capable */ + TURN_OFF_ALWAYS, /* Turn regulators off, no exceptions */ + TURN_ON, /* Turn regulators on, unless pcie->ep_wakeup_capable */ +}; + +static int brcm_set_regulators(struct brcm_pcie *pcie, int how) +{ + struct pci_host_bridge *bridge = pci_host_bridge_from_priv(pcie); struct device *dev = pcie->dev; int ret; if (!pcie->num_supplies) return 0; - if (on) + if (how == TURN_ON) { + if (pcie->ep_wakeup_capable) { + /* + * We are resuming from a suspend. In the + * previous 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; + return 0; + } + } else if (how == TURN_OFF) { + /* + * If at least one device on this bus is enabled as a + * wake-up source, do not turn off regulators. + */ + pcie->ep_wakeup_capable = false; + if (bridge->bus && brcm_pcie_link_up(pcie)) { + pci_walk_bus(bridge->bus, pci_dev_may_wakeup, &pcie->ep_wakeup_capable); + if (pcie->ep_wakeup_capable) + return 0; + } + } + + if (how == TURN_ON) ret = regulator_bulk_enable(pcie->num_supplies, pcie->supplies); else ret = regulator_bulk_disable(pcie->num_supplies, pcie->supplies); if (ret) dev_err(dev, "failed to %s EP regulators\n", - on ? "enable" : "disable"); + how == TURN_ON ? "enable" : "disable"); return ret; } @@ -1234,7 +1278,7 @@ static int brcm_pcie_suspend(struct device *dev) reset_control_rearm(pcie->rescal); clk_disable_unprepare(pcie->clk); - return brcm_set_regulators(pcie, false); + return brcm_set_regulators(pcie, TURN_OFF); } static int brcm_pcie_resume(struct device *dev) @@ -1250,7 +1294,8 @@ static int brcm_pcie_resume(struct device *dev) ret = reset_control_reset(pcie->rescal); if (ret) goto err_disable_clk; - ret = brcm_set_regulators(pcie, true); + + ret = brcm_set_regulators(pcie, TURN_ON); if (ret) goto err_reset; @@ -1297,7 +1342,7 @@ static void __brcm_pcie_remove(struct brcm_pcie *pcie) reset_control_rearm(pcie->rescal); clk_disable_unprepare(pcie->clk); if (pcie->num_supplies) { - (void)brcm_set_regulators(pcie, false); + (void)brcm_set_regulators(pcie, TURN_OFF_ALWAYS); regulator_bulk_free(pcie->num_supplies, pcie->supplies); } } @@ -1348,7 +1393,7 @@ static int brcm_pcie_pci_subdev_prepare(bool query, struct pci_bus *bus, int dev return ret; } - ret = brcm_set_regulators(pcie, true); + ret = brcm_set_regulators(pcie, TURN_ON); if (ret) goto err_out0; From patchwork Fri Oct 22 14:06:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jim Quinlan X-Patchwork-Id: 12577893 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 88C93C433EF for ; Fri, 22 Oct 2021 14:07:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7538C61056 for ; Fri, 22 Oct 2021 14:07:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232986AbhJVOKC (ORCPT ); Fri, 22 Oct 2021 10:10:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49354 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233061AbhJVOJz (ORCPT ); Fri, 22 Oct 2021 10:09:55 -0400 Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 138ECC061766; Fri, 22 Oct 2021 07:07:38 -0700 (PDT) Received: by mail-pl1-x631.google.com with SMTP id v20so2771167plo.7; Fri, 22 Oct 2021 07:07:38 -0700 (PDT) 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=kDRuxXTZJR6dlNhMjzpXR1CtF1FwgepiTBl4EHuvHhs=; b=HV8lT2/xwA8f8cEqJQw8e7GChJRSzrCwluVhEGLrpvqiNk8dpaLiC5YEE+AwjZQn68 NiVdi7dfPblxXo8m5KV/X5xi1CeQt7HqwDq4CdZPSISTms1+1ekp30q3M5wQKurgWD7c Ymt9644S+F4lTqRVNPwsVIplI4xD7WoEQBkGyrDw/cHT8L6U7tRxt5CG0BnjDc1LJhQt XXpKdXGzfUE+pBUoPaPO6CSDkCXqVSDSpdnufAvhmalozb0Ud457CLl/0SLWw10ys9+G 7gf/ek1aEbWxe8xSMIcCXYk+we+TsnOD72gOuCjIGGzSFnk37FqgN7A53csJIGxBZbn0 2Skw== 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=kDRuxXTZJR6dlNhMjzpXR1CtF1FwgepiTBl4EHuvHhs=; b=gBbleBumsb/j49+o9VLkV2JKDNHPSxv1O3iTlMkvyOQ1XWEJV6hSdpwOiWPSbLKipx hXKMSBRmb3dt1VpB4+KSsp9V8Pq6SX1PG/6PZQ2so2esh8ODJ62K7or7GATHPhHTUuPW rWl8xKjh23/f7KNMpNR4E/1nUAHLlHo3I0JTwKqHN0gmfwUgj/+LjllvwRclHX1bnro6 7lxIEG7OrE7XMOWCnav3X55+5NIeKA1gWH/XUsbEd3tVfTf/w1JYoSPgzZ1CKEQ4yB30 Ua2dL6M25GzJ3KAt0QnFuYUyLez+9hSsa2+zV4kueJbBasN1s3W6ZWxRqIIQjx/dzXdm Y+Xg== X-Gm-Message-State: AOAM532CGK/P9pjGfkH15fvrVbWj3aHQtAGTixhEKyv3xvosYEn7C7gm 2bskkp3cE8cl/cq+BL+XmIie9aI1+nCqAA== X-Google-Smtp-Source: ABdhPJx6mGnQbFIcb5PCo3TZyUYO50WkwimEZ8VOnm7FVbb6DqmQFH5jPTkKOosBn+OsAibbFK8lZw== X-Received: by 2002:a17:903:120e:b0:138:d732:3b01 with SMTP id l14-20020a170903120e00b00138d7323b01mr11525395plh.21.1634911656887; Fri, 22 Oct 2021 07:07:36 -0700 (PDT) Received: from stbsrv-and-01.and.broadcom.net ([192.19.11.250]) by smtp.gmail.com with ESMTPSA id e12sm9482990pfl.67.2021.10.22.07.07.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Oct 2021 07:07:36 -0700 (PDT) From: Jim Quinlan To: linux-pci@vger.kernel.org, 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?= , Bjorn Helgaas , 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 v5 6/6] PCI: brcmstb: change brcm_phy_stop() to return void Date: Fri, 22 Oct 2021 10:06:59 -0400 Message-Id: <20211022140714.28767-7-jim2101024@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211022140714.28767-1-jim2101024@gmail.com> References: <20211022140714.28767-1-jim2101024@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org We do not use the result of this function so make it void. Signed-off-by: Jim Quinlan --- drivers/pci/controller/pcie-brcmstb.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/pci/controller/pcie-brcmstb.c b/drivers/pci/controller/pcie-brcmstb.c index 505f74bd1a51..d3e6d9df67b5 100644 --- a/drivers/pci/controller/pcie-brcmstb.c +++ b/drivers/pci/controller/pcie-brcmstb.c @@ -1190,9 +1190,10 @@ static inline int brcm_phy_start(struct brcm_pcie *pcie) return pcie->rescal ? brcm_phy_cntl(pcie, 1) : 0; } -static inline int brcm_phy_stop(struct brcm_pcie *pcie) +static inline void brcm_phy_stop(struct brcm_pcie *pcie) { - return pcie->rescal ? brcm_phy_cntl(pcie, 0) : 0; + if (pcie->rescal) + brcm_phy_cntl(pcie, 0); } static void brcm_pcie_turn_off(struct brcm_pcie *pcie) @@ -1271,10 +1272,9 @@ static int brcm_pcie_get_regulators(struct brcm_pcie *pcie, struct pci_dev *dev) static int brcm_pcie_suspend(struct device *dev) { struct brcm_pcie *pcie = dev_get_drvdata(dev); - int ret; brcm_pcie_turn_off(pcie); - ret = brcm_phy_stop(pcie); + brcm_phy_stop(pcie); reset_control_rearm(pcie->rescal); clk_disable_unprepare(pcie->clk);