Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp4107879imu; Mon, 10 Dec 2018 13:16:30 -0800 (PST) X-Google-Smtp-Source: AFSGD/X41VPYDGuk6VshfuWL/lGbmLwLupgUp1e6cW3+6uJcUjIjeCRWhf2zMznmQoZct+Ym5J1C X-Received: by 2002:a17:902:2aaa:: with SMTP id j39mr13880349plb.335.1544476590097; Mon, 10 Dec 2018 13:16:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544476590; cv=none; d=google.com; s=arc-20160816; b=sW1Tjju56iJScQ/uyqHVRAH0DIfBxuIFSsdKPSCv7X6i3svibR1mKSKrBc+dUrvrHp NM++ijqarN9M6fwAWzucqZuYOrMK48UyJkcPNrmTST1GL0mKhHjT64GnDr+HNOM1OLt4 Zcgqz6BHBNLm5W3O444UHGzDNVNkaOqkTQKMEuPACnMj0LYwCjFBNLI8K/QTrsT/NcE3 lrkALA93wEQKJCb533msp/QWDVSDNXLDGf5y2tJkhsJCY61yzid3Ag52mY2bgmiVd3pL GZNMHzMix9t6LTc46d+UUg290rHxA1oJ2Qa5s0ZFWLIetDHF+9O17nvwESShDRZPWArQ eNxg== 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=swBCshXdU88jDHuUWpucEyoCgoeRd0FLOywR1zZXW8EfCthbv3JQTpdyZYRhV5G0xS ROokWx4ISVZssWclZgave4adL8Hb5tUbCIo4wfevcEge0xVPznjuHCkeCETu8dbQlGJ7 trBsRWyhXqLy/HDHcLitOmfwFcK7y8k0RM+7PtvtMBYm9HwQClhFkiSvfso+QMOJV4zv RBKVIjV6bjrAlIscRZynNftOEKlwSq8arrVSoFGIVTHckKf7Oa3PU2UoMR4wRAhfe2iX vzDvh2b4kl0gZYRzZP3WaWkIK1ayUx0wQ3181sr7aLsXXEVaDWBvyTcwC+QlNicx6FvB 43KA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@plaes.org header.s=mail header.b=TNhQU2+9; 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 16si11036155pgh.58.2018.12.10.13.16.15; Mon, 10 Dec 2018 13:16:30 -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=TNhQU2+9; 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 S1728867AbeLJSmw (ORCPT + 99 others); Mon, 10 Dec 2018 13:42:52 -0500 Received: from plaes.org ([188.166.43.21]:55146 "EHLO plaes.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726024AbeLJSm3 (ORCPT ); Mon, 10 Dec 2018 13:42:29 -0500 Received: from localhost (unknown [213.204.46.240]) by plaes.org (Postfix) with ESMTPSA id 085D9418DE; Mon, 10 Dec 2018 18:42:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=plaes.org; s=mail; t=1544467347; bh=kVazWeoBJTH1RfagB16nCXnVFLnAlX8uPnX2O4aNcZU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TNhQU2+9kiHzHr2r0eh6QDKGwUgrDmxrva4AMNBAcOfaUCyc53Kc4MyL6DYlXAh+A QRpeLQ5jXhGAebKYSttBEOGHFI9WhVhYVw4mvulJLtXH7YaWP63OzFu3XuphamuXxw XXLvsVzoL7SzkVanAn4f6lehF2h9HgihvTiKBl51R+wLJERaKZwxUWuwcCoVGBboQX IvVKNEf/pou53ZKd34DtVR8hoMCNS09NeMJ/yvJXcVYygSVhfyIaqkced1ATpsv/jl IVvYs87x6UQxJ7drFbtCnMFPveYLrqg6I0n5PQTONtsCt+SBFG7x0+z4ap30+McPS5 4+ncvWx5W5GHw== From: Priit Laes To: Lee Jones , Rob Herring , Mark Rutland , Chen-Yu Tsai , Maxime Ripard , Liam Girdwood , Mark Brown , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Olliver Schinagl , linux-sunxi Cc: Priit Laes Subject: [PATCH 4/8] regulator: axp20x: add software based soft_start for AXP209 LDO3 Date: Mon, 10 Dec 2018 20:42:15 +0200 Message-Id: X-Mailer: git-send-email 2.19.2 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