Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1714838imu; Wed, 12 Dec 2018 03:05:46 -0800 (PST) X-Google-Smtp-Source: AFSGD/XHWSnomoW/7ZoaLp8j4YJWoWHat1eQYdrpBl/qaD/h+1ei7cbhBRNF0AIyBrs5I5TksY/z X-Received: by 2002:a62:399b:: with SMTP id u27mr20528096pfj.181.1544612746627; Wed, 12 Dec 2018 03:05:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544612746; cv=none; d=google.com; s=arc-20160816; b=g+0p25qcx2hOFwSepRLNFUkzZ24OmdRrgrLa1rLjp/nugM7Htoo7fQn17IWZUG20AL BwfyZsUCbH/iOHAzCIMn9VzqDntm+8KgyOQOHjoOgCSAVKZ0HD/muotnnjDsRa0LSjcY A8Dyql01yWGupZF4sS4CxvXvQ8gqWgELr+dUNdQwZJjEkeYNXFqJC6DWpgDOPhkX+71w zkBJJTw5g8O53/a1gTXDr/WBpJNDuvhb1FqvqX0ryhBv5/0cdOM0V3LypdsiZ6CBugfH upAMPn0QmQ3qhyG/J/c4oOey200RonZHJJ0HpN1o/PiBJ/dgRj+jy8vznbrX4FSlsPzU 0MVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=W7L4vRxcA4WLc67gQgdMfBHKWAg+i9SX4yPy7HNzob4=; b=yQiHS5flvOKFYLCm9XJ9/CB4HmXaeohcK41eOzV85yqWR839ylr5VXmthXmAU5Oixy 4BU47fDrWB/y5M4KUPalbqDCMMEIOoADMFRjjqKiGGyxrQDv85corQiJDfctcoaafEK1 gGBzZda87m0YtX3PEk1EyMgXaFI3FRHs2RCPNFFd4qeL11zmhcpdvns7iGEl7pf8ldc2 fhpEFQ0PUYnBwhTp/WTun0wO+SUvNqHC+ySeA0+0g3KjvwGsq6Fd6S282HEcNO6sKcWm 8T7c/D4DDf1DalZGSMaGlgnJk7c6dirEDO/g2rriJH8s57/IxpWgS+YEremRJ7hIynXz 7iIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@plaes.org header.s=mail header.b="BKjpZ/3V"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 59si14851003plf.18.2018.12.12.03.05.30; Wed, 12 Dec 2018 03:05:46 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@plaes.org header.s=mail header.b="BKjpZ/3V"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727235AbeLLLCp (ORCPT + 99 others); Wed, 12 Dec 2018 06:02:45 -0500 Received: from plaes.org ([188.166.43.21]:35550 "EHLO plaes.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726878AbeLLLCo (ORCPT ); Wed, 12 Dec 2018 06:02:44 -0500 Received: from plaes.org (localhost [127.0.0.1]) by plaes.org (Postfix) with ESMTPSA id 11B5B4002F; Wed, 12 Dec 2018 11:02:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=plaes.org; s=mail; t=1544612561; bh=+m/J/LdEoB7yH5+0QKj58UFvsrQ/4y3ZgsEYLt8GLLU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=BKjpZ/3VdeqxA5BcXQ96MHI+NXYHzMmoD4RQdZgEYmkz+hakWnSg9RjKqWsYdf5To yPcwwsGgw+tvIwdWle3Cg9M86hid2SW1GHLbJRO/2/cIwIbkOnp9g4jhquHltWojSs Km8ENaH68YM7Ctv05EOFN0S5C6HnxUkeyC3Oc9dSa1g0Nt+YJCDCvChgiuwoVT8G5l hnX4uyf/Ks6dpsQQ89PpU8FyyXE7uVAQD1mMx1cZHMom2/IxdZ4HY8craDlJZ2x7Vl S0UzNDlhYbnooEN45F4C1sK66sKQeoJv/DdTn+MhHfCMJDI9e6yi+hIZxD91qHXE+r uODAwqAxt0mpQ== Date: Wed, 12 Dec 2018 11:02:40 +0000 From: Priit Laes To: Julian Calaby Cc: Olliver Schinagl , Lee Jones , Rob Herring , Mark Rutland , Chen-Yu Tsai , Maxime Ripard , Liam Girdwood , Mark Brown , devicetree , "linux-kernel@vger.kernel.org" , "Mailing List, Arm" , linux-sunxi Subject: Re: [linux-sunxi] [PATCH 2/8] regulator: axp20x: add support for set_ramp_delay for AXP209 Message-ID: <20181212110239.uizmnldvluf4dlng@plaes.org> References: <2bfe47f173fe72a30b0036dcdeebc2123962ff33.1544466940.git-series.plaes@plaes.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Dec 12, 2018 at 12:14:57AM +1100, Julian Calaby wrote: > Hi Priit and Olliver, > > On Tue, Dec 11, 2018 at 5:42 AM Priit Laes wrote: > > > > From: Olliver Schinagl > > > > The AXP209 supports ramping up voltages on several regulators such as > > DCDC2 and LDO3. > > > > This patch adds preliminary support for the regulator-ramp-delay property > > for these 2 regulators. Note that the voltage ramp only works when > > regulator is already enabled. E.g. when going from say 0.7 V to 3.6 V. > > > > When turning on the regulator, no voltage ramp is performed in hardware. > > > > What this means, is that if the bootloader brings up the voltage at 0.7 V, > > the ramp delay property is properly applied. If however, the bootloader > > leaves the power off, no ramp delay is applied when the power is > > enabled by the regulator framework. > > > > Signed-off-by: Olliver Schinagl > > Signed-off-by: Priit Laes > > --- > > drivers/regulator/axp20x-regulator.c | 85 +++++++++++++++++++++++++++++- > > 1 file changed, 85 insertions(+) > > > > diff --git a/drivers/regulator/axp20x-regulator.c b/drivers/regulator/axp20x-regulator.c > > index 9a2db28..1d9fa62 100644 > > --- a/drivers/regulator/axp20x-regulator.c > > +++ b/drivers/regulator/axp20x-regulator.c > > @@ -346,6 +357,79 @@ > > .ops = &axp20x_ops_range, \ > > } > > > > +static const int axp209_dcdc2_ldo3_slew_rates[] = { > > + 1600, > > + 800, > > +}; > > + > > +static int axp20x_set_ramp_delay(struct regulator_dev *rdev, int ramp) > > +{ > > + struct axp20x_dev *axp20x = rdev_get_drvdata(rdev); > > + const struct regulator_desc *desc = rdev->desc; > > + u8 reg, mask, enable, cfg = 0xff; > > + const int *slew_rates; > > + int rate_count = 0; > > + > > + if (!rdev) > > + return -EINVAL; > > + > > + switch (axp20x->variant) { > > + case AXP209_ID: > > + if (desc->id == AXP20X_DCDC2) { > > Is slew_rates supposed to be set here? Yes, nice catch. > > > + rate_count = ARRAY_SIZE(axp209_dcdc2_ldo3_slew_rates); > > + reg = AXP20X_DCDC2_LDO3_V_RAMP; > > + mask = AXP20X_DCDC2_LDO3_V_RAMP_DCDC2_RATE_MASK | > > + AXP20X_DCDC2_LDO3_V_RAMP_DCDC2_EN_MASK; > > + enable = (ramp > 0) ? > > + AXP20X_DCDC2_LDO3_V_RAMP_DCDC2_EN : > > + !AXP20X_DCDC2_LDO3_V_RAMP_DCDC2_EN; > > + break; > > + } > > + > > + if (desc->id == AXP20X_LDO3) { > > + slew_rates = axp209_dcdc2_ldo3_slew_rates; > > + rate_count = ARRAY_SIZE(axp209_dcdc2_ldo3_slew_rates); > > + reg = AXP20X_DCDC2_LDO3_V_RAMP; > > + mask = AXP20X_DCDC2_LDO3_V_RAMP_LDO3_RATE_MASK | > > + AXP20X_DCDC2_LDO3_V_RAMP_LDO3_EN_MASK; > > + enable = (ramp > 0) ? > > + AXP20X_DCDC2_LDO3_V_RAMP_LDO3_EN : > > + !AXP20X_DCDC2_LDO3_V_RAMP_LDO3_EN; > > + break; > > + } > > + > > + if (rate_count > 0) > > + break; > > You could save one to two tests by combining the above three if statements, i.e. > > if (DCDC2) { > // set DCDC2 stuff > > break; > } else if (LDO3) { > // set LDO3 stuff > > break; > } OK, will look into it. > > As written, the rate_count > 0 test will never be true as every block > that sets rate_count breaks out of the switch block. Yes, it is somewhat superfluous, as each regulator which supports ramping should break out of the switch itself. > You could then calculate rate_count below the switch block. > > > + > > + /* fall through */ > > + default: > > + /* Not supported for this regulator */ > > + return -ENOTSUPP; > > + } > > + > > + if (ramp == 0) { > > + cfg = enable; > > + } else { > > + int i; > > + > > + for (i = 0; i < rate_count; i++) { > > + if (ramp <= slew_rates[i]) > > + cfg = AXP20X_DCDC2_LDO3_V_RAMP_LDO3_RATE(i); > > + else > > + break; > > + } > > + > > + if (cfg == 0xff) { > > + dev_err(axp20x->dev, "unsupported ramp value %d", ramp); > > + return -EINVAL; > > + } > > + > > + cfg |= enable; > > + } > > + > > + return regmap_update_bits(axp20x->regmap, reg, mask, cfg); > > +} > > + > > > > -- > Julian Calaby > > Email: julian.calaby@gmail.com > Profile: http://www.google.com/profiles/julian.calaby/