Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp24415imu; Mon, 26 Nov 2018 07:29:58 -0800 (PST) X-Google-Smtp-Source: AFSGD/X9Cfq7DLLCgYML1dL3G2sLtBq8mblN3QEV0uq5XGRSXwo7p9FFNBdvQddywCrY8d/iqIhN X-Received: by 2002:a63:b4c:: with SMTP id a12mr25799545pgl.131.1543246198775; Mon, 26 Nov 2018 07:29:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543246198; cv=none; d=google.com; s=arc-20160816; b=WbHr5IO54Mr35yzqBp5mBuOW7dJrtllQuDUf8PVgFTVaghEH9LXceWiRBevZiHxrrf GRJHQhBfjtXJw7ybhiWEDyYi+ts1GDWoOa8V1LzgzFU0B2o7iNjkdALCSq2bPEC5Gfzc /Rb4V+cCrE7/ePnKg0VwSZ/wsiwvcVFqIFfqnvMTNKPV42uB6K3N3WlrlcwhANi2QZkX bbsxRMI6WSilxkYuvu5bjimMYCbedq9oUZPC3h9lKzu0Oqv/SLE74kzTsKkTX/H4OonE J8K2vItNKWOy6D+zkNHr66nLNukSm8qOxeGE+wtOm8/T4Boo42BZJlTtIuIOT8IpT2qP 938A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=hWJpH5cobnneg/wjNhakAA6AMQKfGVddNSpP633FTnY=; b=hQgsgZ2m9PkK45MQiAMpCkrXc4XnhTSxAJT8iYfhFU/s3g6cv2RgdA5Xh2VA17RrSY dxp4NR6zzeeGxGNSlLDUi4gJgKYSp8JPzSf8R4tBclV5FcEbC979PiWY92OOOsGP/xB9 N6p1XZCJegVap0LYpX6o79lcTl1BvFo+EVyqs+yxbTuA1Fj7Rc7QtRWdrUBWM4fgvorx bJW6W2BUE93qMdw3mJip32kTuo+CT39XsgYAWDPceTXbAlI5vI1DrbRrllOvC1OEGMSl Wqqkyxg8LALCLaYTufLAhXh1xZ3sGMDTQjEjVLMRDc7zXDtJtMTpTqzzyKPUUx4+xL/k QwyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@plaes.org header.s=mail header.b=BnvInAGF; 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 h19si667149plr.67.2018.11.26.07.29.25; Mon, 26 Nov 2018 07:29:58 -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=BnvInAGF; 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 S1727111AbeK0CWq (ORCPT + 99 others); Mon, 26 Nov 2018 21:22:46 -0500 Received: from plaes.org ([188.166.43.21]:50010 "EHLO plaes.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726727AbeK0CWm (ORCPT ); Mon, 26 Nov 2018 21:22:42 -0500 Received: from localhost (85.253.196.132.cable.starman.ee [85.253.196.132]) by plaes.org (Postfix) with ESMTPSA id 0E8AA41891; Mon, 26 Nov 2018 15:28:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=plaes.org; s=mail; t=1543246093; bh=kVazWeoBJTH1RfagB16nCXnVFLnAlX8uPnX2O4aNcZU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BnvInAGFuT3I7vsqfxbfy3dJGSHqAckVpEIDkp1nstluUFR5ywjjJsdYbGEXFOR8f SHkdOR5sPhd5ESncja8zVkS3lF+URrb9FLAkOVqmcxVz7ORcDwhRCoqhNcnh2gn/Sa b0SVTNGfbfcaT/hGv+88T4IZBViHuq8ak3W6OgPLEjeb1ds2dq8eXOgklqIE2ZQRoD RFP+ugY6UUjSZz4sfVVkPz8gXavyvh03OpMH03TUui2L/Gw7eZHiLSjRnyqMEtelfa D1UUrLLXNwA46/jVAy16RqwsBKwenKyko0NEVb+QxzAubKrHiWRaATrE4APDs3LWEp Ws1ceBidSvs1g== From: Priit Laes To: Lee Jones , Rob Herring , Mark Rutland , Chen-Yu Tsai , Maxime Ripard , Sebastian Reichel , Hans de Goede , Liam Girdwood , Mark Brown , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-pm@vger.kernel.org Cc: Priit Laes , Olliver Schinagl Subject: [PATCH 06/14] regulator: axp20x: add software based soft_start for AXP209 LDO3 Date: Mon, 26 Nov 2018 17:27:47 +0200 Message-Id: <41cb1b4dac3a15595c89fa962b78d3f68f370021.1543245984.git-series.plaes@plaes.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Olliver Schinagl In the past, there have been words on various lists that if LDO3 is disabled in u-boot, but enabled in the DTS, the axp209 driver would fail to continue/hang. Several enable/disable patches have been issues to devicetree's in both the kernel and u-boot to address this issue. What really happened however, was that the AXP209 shuts down without a notice and without setting an interrupt. This is caused when LDO3 gets overloaded, for example with large capacitors on the LDO3 output. Normally, we would expect that AXP209 would source 200 mA as per datasheet and set and trigger an interrupt when being overloaded. For some reason however, this does not happen. As a work-around, we use the soft-start constraint of the regulator node to first bring up the LDO3 to the lowest possible voltage and then enable the LDO. After that, we can set the requested voltage as usual. Combining this setting with the regulator-ramp-delay allows LDO3 to enable voltage slowly and staggered, potentially reducing overall inrush current. Signed-off-by: Olliver Schinagl Signed-off-by: Priit Laes --- drivers/regulator/axp20x-regulator.c | 57 ++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/drivers/regulator/axp20x-regulator.c b/drivers/regulator/axp20x-regulator.c index 1d9fa62..e8a895b 100644 --- a/drivers/regulator/axp20x-regulator.c +++ b/drivers/regulator/axp20x-regulator.c @@ -14,6 +14,7 @@ */ #include +#include #include #include #include @@ -23,6 +24,7 @@ #include #include #include +#include #include #define AXP20X_GPIO0_FUNC_MASK GENMASK(3, 0) @@ -430,6 +432,59 @@ static int axp20x_set_ramp_delay(struct regulator_dev *rdev, int ramp) return regmap_update_bits(axp20x->regmap, reg, mask, cfg); } +static int axp20x_regulator_enable_regmap(struct regulator_dev *rdev) +{ + struct axp20x_dev *axp20x = rdev_get_drvdata(rdev); + const struct regulator_desc *desc = rdev->desc; + + if (!rdev) + return -EINVAL; + + switch (axp20x->variant) { + case AXP209_ID: + if ((desc->id == AXP20X_LDO3) && + rdev->constraints && rdev->constraints->soft_start) { + int v_out; + int ret; + + /* + * On some boards, the LDO3 can be overloaded when + * turning on, causing the entire PMIC to shutdown + * without warning. Turning it on at the minimal voltage + * and then setting the voltage to the requested value + * works reliably. + */ + if (regulator_is_enabled_regmap(rdev)) + break; + + v_out = regulator_get_voltage_sel_regmap(rdev); + if (v_out < 0) + return v_out; + + if (v_out == 0) + break; + + ret = regulator_set_voltage_sel_regmap(rdev, 0x00); + /* + * A small pause is needed between + * setting the voltage and enabling the LDO to give the + * internal state machine time to process the request. + */ + usleep_range(1000, 5000); + ret |= regulator_enable_regmap(rdev); + ret |= regulator_set_voltage_sel_regmap(rdev, v_out); + + return ret; + } + break; + default: + /* No quirks */ + break; + } + + return regulator_enable_regmap(rdev); +}; + static const struct regulator_ops axp20x_ops_fixed = { .list_voltage = regulator_list_voltage_linear, }; @@ -447,7 +502,7 @@ static const struct regulator_ops axp20x_ops = { .set_voltage_sel = regulator_set_voltage_sel_regmap, .get_voltage_sel = regulator_get_voltage_sel_regmap, .list_voltage = regulator_list_voltage_linear, - .enable = regulator_enable_regmap, + .enable = axp20x_regulator_enable_regmap, .disable = regulator_disable_regmap, .is_enabled = regulator_is_enabled_regmap, .set_ramp_delay = axp20x_set_ramp_delay, -- git-series 0.9.1