From patchwork Mon Nov 30 21:11:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jim Quinlan X-Patchwork-Id: 11941311 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, T_TVD_MIME_NO_HEADERS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9E2B1C64E7B for ; Mon, 30 Nov 2020 21:13:55 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2359F206A5 for ; Mon, 30 Nov 2020 21:13:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="z/sx7j1+"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b="huWSdInE" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2359F206A5 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=broadcom.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Type:MIME-Version: Cc:List-Subscribe:List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: References:In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=3ONOHxn2x7Mq2BfW9IE9K2FCyEinBFN3E1WLXSaL8dE=; b=z/sx7j1+I0BcfKSME9xrNyg1L 2wCj5pHRMSMiGw6vVfU+RddEGSEgtZ0WeX2POa3BtI+9fABh8E6JKJvDqIfJNHlEt5eHz54vI97fT IYgrvLVdY0jM622fhQo7EFPY7g95xRTZ8o/GsG6Oj+Aaxr6PahM/XipzpDeCsR2grrQIk8G3qx/+T Zag/+pL3NUo5f/dAP4zc2s/6NOS9BuvbyMRjDrjPg0UKx5OnW19ScrI7IRB4TZr0/6cbDcW+E8rbV c9zrYhsj7zc1zE4RYPj068QH7oODIbTLYVjAItbSQsRCSKxrvavwZzy9GisLzzkLmSns9gAfOySuk 92ALibItw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kjqT4-00036H-U7; Mon, 30 Nov 2020 21:12:19 +0000 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kjqSo-00030j-Vn for linux-arm-kernel@lists.infradead.org; Mon, 30 Nov 2020 21:12:04 +0000 Received: by mail-pg1-x544.google.com with SMTP id w4so10834307pgg.13 for ; Mon, 30 Nov 2020 13:12:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=3VJjLa38ZI0rgPu3uhSRdR5Mh/QW3d4o9OdCq9IPY7U=; b=huWSdInESiGzjYgjqPlJXI8P1LTazuO9gZ0E4HJRxCQDuFVo/yL3qEp/RagfmvOTMR 3sCWs25jNPvoKE0ad4bBZp5gsXwVaK74S8jkACjbryeqNlUyjgMWM8ISVhA25yCTfavR UNWDd/V8ev3nXG3odCXhM5i7zeba1rcOrlMVI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=3VJjLa38ZI0rgPu3uhSRdR5Mh/QW3d4o9OdCq9IPY7U=; b=FmcAxraZ/5GcC8UukG/CZ/FvuFQ2enlUNd594XV8XFQekHPuD26BXs1MlkZ2h3nKbU TOXhpDXJMaqpTIxD4gWeSmRVx8BdKrz78ZfxCaekoStz3xwrCh9ok5XS30XgGcP+tnZE xkl6ONnNWl84hFuQOI0SEoOGU6J2H2kEcrUGnibr/Eu0H1ROQZe1CbthPIs6GAN+ebix 10Ha8CTSGPG5V7aJcgD+OtQJc5WEj6QZIErk1gIMsjXkHj9atg1jIpI48gRrVyV0f58t onrFCohbkD8cjGdo600xC34Q+drymWTWHO8pTqNDqvbSP1YYg1WQqf6v9aRbv2GyLHaU UHvQ== X-Gm-Message-State: AOAM533rISgsfSNFvqvPpnWVBVFCw6eqtX1mkMO6SKOM3Ot3edduMlXe xYs2sh3cc1FXG4h7AJwj5V9S4g== X-Google-Smtp-Source: ABdhPJyHBCo7iM248BtvpqWTbsJ0GkYgf/jABwj6sSm8Vv9BQUDHDXCYGUikE3aZ3W10dMjC8J8+ZQ== X-Received: by 2002:a63:1d55:: with SMTP id d21mr19699914pgm.324.1606770720817; Mon, 30 Nov 2020 13:12:00 -0800 (PST) Received: from stbsrv-and-01.and.broadcom.net ([192.19.231.250]) by smtp.gmail.com with ESMTPSA id m7sm18320441pfh.72.2020.11.30.13.11.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2020 13:12:00 -0800 (PST) From: Jim Quinlan To: linux-pci@vger.kernel.org, Nicolas Saenz Julienne , broonie@kernel.org, bcm-kernel-feedback-list@broadcom.com, james.quinlan@broadcom.com Subject: [PATCH v2 2/6] PCI: brcmstb: Add control of EP voltage regulator(s) Date: Mon, 30 Nov 2020 16:11:39 -0500 Message-Id: <20201130211145.3012-3-james.quinlan@broadcom.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201130211145.3012-1-james.quinlan@broadcom.com> References: <20201130211145.3012-1-james.quinlan@broadcom.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201130_161203_112012_43310EB3 X-CRM114-Status: GOOD ( 17.65 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Rob Herring , Lorenzo Pieralisi , open list , Florian Fainelli , "moderated list:BROADCOM BCM2711/BCM2835 ARM ARCHITECTURE" , Bjorn Helgaas , "moderated list:BROADCOM BCM2711/BCM2835 ARM ARCHITECTURE" MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Control of EP regulators by the RC is needed because of the chicken-and-egg situation: although the regulator is "owned" by the EP and would be best handled on its driver, the EP cannot be discovered and probed unless its regulator is already turned on. Signed-off-by: Jim Quinlan --- drivers/pci/controller/pcie-brcmstb.c | 38 ++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/drivers/pci/controller/pcie-brcmstb.c b/drivers/pci/controller/pcie-brcmstb.c index bea86899bd5d..9d4ac42b3bee 100644 --- a/drivers/pci/controller/pcie-brcmstb.c +++ b/drivers/pci/controller/pcie-brcmstb.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -210,6 +211,10 @@ enum pcie_type { BCM2711, }; +static const char * const ep_regulator_names[] = { + "vpcie12v", "vpcie3v3", "vpcie1v8", "vpcie0v9", +}; + struct pcie_cfg_data { const int *offsets; const enum pcie_type type; @@ -287,8 +292,25 @@ 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(ep_regulator_names)]; }; +static void brcm_set_regulators(struct brcm_pcie *pcie, bool on) +{ + struct device *dev = pcie->dev; + int ret; + + if (on) + ret = regulator_bulk_enable(ARRAY_SIZE(ep_regulator_names), + pcie->supplies); + else + ret = regulator_bulk_disable(ARRAY_SIZE(ep_regulator_names), + pcie->supplies); + if (ret) + dev_err(dev, "failed to %s EP regulators\n", + on ? "enable" : "disable"); +} + /* * 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 @@ -1139,6 +1161,7 @@ static int brcm_pcie_suspend(struct device *dev) brcm_pcie_turn_off(pcie); ret = brcm_phy_stop(pcie); clk_disable_unprepare(pcie->clk); + brcm_set_regulators(pcie, false); return ret; } @@ -1151,6 +1174,7 @@ static int brcm_pcie_resume(struct device *dev) int ret; base = pcie->base; + brcm_set_regulators(pcie, true); clk_prepare_enable(pcie->clk); ret = brcm_phy_start(pcie); @@ -1189,6 +1213,7 @@ static void __brcm_pcie_remove(struct brcm_pcie *pcie) brcm_phy_stop(pcie); reset_control_assert(pcie->rescal); clk_disable_unprepare(pcie->clk); + brcm_set_regulators(pcie, false); } static int brcm_pcie_remove(struct platform_device *pdev) @@ -1218,7 +1243,7 @@ static int brcm_pcie_probe(struct platform_device *pdev) struct pci_host_bridge *bridge; const struct pcie_cfg_data *data; struct brcm_pcie *pcie; - int ret; + int ret, i; bridge = devm_pci_alloc_host_bridge(&pdev->dev, sizeof(*pcie)); if (!bridge) @@ -1246,6 +1271,16 @@ static int brcm_pcie_probe(struct platform_device *pdev) if (IS_ERR(pcie->clk)) return PTR_ERR(pcie->clk); + for (i = 0; i < ARRAY_SIZE(ep_regulator_names); i++) + pcie->supplies[i].supply = ep_regulator_names[i]; + + ret = devm_regulator_bulk_get(pcie->dev, ARRAY_SIZE(ep_regulator_names), + pcie->supplies); + if (ret) { + dev_err(pcie->dev, "failed to get regulators\n"); + return ret; + } + ret = of_pci_get_max_link_speed(np); pcie->gen = (ret < 0) ? 0 : ret; @@ -1273,6 +1308,7 @@ static int brcm_pcie_probe(struct platform_device *pdev) return ret; } + brcm_set_regulators(pcie, true); ret = brcm_pcie_setup(pcie); if (ret) goto fail;