From patchwork Thu Mar 23 22:27:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Helgaas X-Patchwork-Id: 9642115 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4E9CC601E9 for ; Thu, 23 Mar 2017 22:27:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3C92828433 for ; Thu, 23 Mar 2017 22:27:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2E2F328447; Thu, 23 Mar 2017 22:27:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id BE1E428433 for ; Thu, 23 Mar 2017 22:27:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=LuS+huNM56p92NZbDKPEmvFIA0AAyD5jNsV1IVqkr2w=; b=un2FuctEJPKRLy 60JGiBoQDFu1cOGi4/C8+evXqfsuj7L3805RVDEqCB+YlsQPp3HCOX1yWB8IXdMhHbydq2v114Tpt tDz5hWzxKQd9e47LHExshHJywSS7s7PeT2aiMzN3CQrTjMcteyJ9u+RLbThzHpdxfFfq1aHrAVbXb nCUpi8VqCljhUa8zcDxitFCaRA8C0y83PEeTWLCeJAVkEr9LNDB/GsEuBuTb3h2xRzvwkSZzLPIHt BEhpRT8SGcLwbCDYtlWBbk5WK3DyH/V0cbGCydsuF/gm8FKHXSHpN1BUt8Lt+tf5x+Wo1+pLxLFyz BesIRWvHKg/9ipHko4wQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1crBCs-0003LK-IY; Thu, 23 Mar 2017 22:27:46 +0000 Received: from mail.kernel.org ([198.145.29.136]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1crBCn-0003JB-6F for linux-rockchip@lists.infradead.org; Thu, 23 Mar 2017 22:27:44 +0000 Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B88F9202B8; Thu, 23 Mar 2017 22:27:19 +0000 (UTC) Received: from localhost (unknown [69.55.156.165]) (using TLSv1.2 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 86325202E5; Thu, 23 Mar 2017 22:27:18 +0000 (UTC) Date: Thu, 23 Mar 2017 17:27:17 -0500 From: Bjorn Helgaas To: Brian Norris Subject: Re: [PATCH v2 1/5] PCI: rockchip: fix sign issues for current limits Message-ID: <20170323222717.GD23612@bhelgaas-glaptop.roam.corp.google.com> References: <20170310024617.67303-1-briannorris@chromium.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20170310024617.67303-1-briannorris@chromium.org> User-Agent: Mutt/1.5.21 (2010-09-15) X-Virus-Scanned: ClamAV using ClamSMTP X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170323_152741_278544_0540AF6B X-CRM114-Status: GOOD ( 24.50 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jeffy Chen , linux-pci@vger.kernel.org, Shawn Lin , Wenrui Li , linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, Bjorn Helgaas Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP On Thu, Mar 09, 2017 at 06:46:13PM -0800, Brian Norris wrote: > The regulator framework can return negative error codes via > regulator_get_current_limit() for regulators that don't provide current > information. The subsequent check for postive values isn't very useful, > if the variable is unsigned. > > Let's just match the signedness of the return value. > > Prevents error messages like this, seen on Samsung Chromebook Plus: > > [ 1.069372] rockchip-pcie f8000000.pcie: invalid power supply > > Fixes: 4816c4c7b82b ("PCI: rockchip: Provide captured slot power limit and scale") > Signed-off-by: Brian Norris > Acked-by: Shawn Lin I applied the first two patches (this already has Shawn's ack and the second is trivially obvious) to pci/host-rockchip. I'm not sure what the current state of the others is. I also applied the appended trivial indentation patch. > --- > v2: add Shawn's ack > --- > drivers/pci/host/pcie-rockchip.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/drivers/pci/host/pcie-rockchip.c b/drivers/pci/host/pcie-rockchip.c > index 26ddd3535272..d785f64ec03b 100644 > --- a/drivers/pci/host/pcie-rockchip.c > +++ b/drivers/pci/host/pcie-rockchip.c > @@ -425,7 +425,8 @@ static struct pci_ops rockchip_pcie_ops = { > > static void rockchip_pcie_set_power_limit(struct rockchip_pcie *rockchip) > { > - u32 status, curr, scale, power; > + int curr; > + u32 status, scale, power; > > if (IS_ERR(rockchip->vpcie3v3)) > return; > -- > 2.12.0.246.ga2ecc84866-goog > commit 73edd2b180a18024605c599074596a9e22d745d6 Author: Bjorn Helgaas Date: Thu Mar 23 17:21:26 2017 -0500 PCI: rockchip: Unindent rockchip_pcie_set_power_limit() If regulator_get_current_limit() returns 0 or error, return early so the body of the function doesn't have to be indented as the body of an "if" statement. No functional change intended. Signed-off-by: Bjorn Helgaas Acked-by: Shawn Lin for pcie-rockchip. diff --git a/drivers/pci/host/pcie-rockchip.c b/drivers/pci/host/pcie-rockchip.c index d785f64ec03b..7f76ff6af0ba 100644 --- a/drivers/pci/host/pcie-rockchip.c +++ b/drivers/pci/host/pcie-rockchip.c @@ -438,24 +438,25 @@ static void rockchip_pcie_set_power_limit(struct rockchip_pcie *rockchip) * to the actual power supply. */ curr = regulator_get_current_limit(rockchip->vpcie3v3); - if (curr > 0) { - scale = 3; /* 0.001x */ - curr = curr / 1000; /* convert to mA */ - power = (curr * 3300) / 1000; /* milliwatt */ - while (power > PCIE_RC_CONFIG_DCR_CSPL_LIMIT) { - if (!scale) { - dev_warn(rockchip->dev, "invalid power supply\n"); - return; - } - scale--; - power = power / 10; - } + if (curr <= 0) + return; - status = rockchip_pcie_read(rockchip, PCIE_RC_CONFIG_DCR); - status |= (power << PCIE_RC_CONFIG_DCR_CSPL_SHIFT) | - (scale << PCIE_RC_CONFIG_DCR_CPLS_SHIFT); - rockchip_pcie_write(rockchip, status, PCIE_RC_CONFIG_DCR); + scale = 3; /* 0.001x */ + curr = curr / 1000; /* convert to mA */ + power = (curr * 3300) / 1000; /* milliwatt */ + while (power > PCIE_RC_CONFIG_DCR_CSPL_LIMIT) { + if (!scale) { + dev_warn(rockchip->dev, "invalid power supply\n"); + return; + } + scale--; + power = power / 10; } + + status = rockchip_pcie_read(rockchip, PCIE_RC_CONFIG_DCR); + status |= (power << PCIE_RC_CONFIG_DCR_CSPL_SHIFT) | + (scale << PCIE_RC_CONFIG_DCR_CPLS_SHIFT); + rockchip_pcie_write(rockchip, status, PCIE_RC_CONFIG_DCR); } /**