Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp770224imu; Tue, 11 Dec 2018 07:19:22 -0800 (PST) X-Google-Smtp-Source: AFSGD/XU7XiUUfah078PdTSntHFYgUamohux+Z7OPAf+IDjud6MLiHwfZfj/MeegGOXlFFCzA3c2 X-Received: by 2002:a17:902:12f:: with SMTP id 44mr16612353plb.74.1544541562554; Tue, 11 Dec 2018 07:19:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544541562; cv=none; d=google.com; s=arc-20160816; b=OhgKlmA5IuwhZ8CdZ74LLsIf5JZkNKCJP6zc6GcClaTLGf/5wyd/ECBulQJbYqAJ8f tN8lJ8v2jG3hp6uV4WzzAWUsWOcMMMudOttO6QpYt1Wt8H3GkgGdd7wIrjjbYk++SmL0 olMqjgIN4TZcMxnvEiLpfYAa26UvGia9uq0uSqWJ0m6+Z3u81GC+7YcDqNAzPgh6D7+u kFiipldzWkwY22cto6mhU6a4ZnOQulpGF3c77e1ErUdiKZevY/4WUo4F8O+ZZyj40IdL EhOclB8Szq65iC/88sjcdCyldK93KaQuL8tUzVx/tt25GtxaDa4wlmUvT97o34owDvc5 sOew== 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=OZpUviJWfotNTmPaOdglpjNGW2amw73FnIAbgOfVORyUiCCUIFr/aKD6KveJ13D7yd C14GIf3akREI4/DbAmioDloFsTTmSZRAZ/MwRx3U47kWW1VgzuB73R3ngvUWszVV8pFK UMlHNH2lUvBb4mEv9Z8NwMYKeAeGw9SPHPeY7JXwUolNAykUHdZEOADv0WLpAQpSx0v1 fd+RNwv72hWRLEpNXKHQ4xlPqOjR1zlxLIj0rFV+MGROKqaqf0wvxL9JERxmS3n+GLcm cHJGYD5e98myvHsIRY/jcF6eF3r+JYW57XEALSV6KUXaBIrBexe0RYf6mLHO4YA44nSD oaYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@plaes.org header.s=mail header.b=GtcjlpRB; 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 i2si11573033pgl.153.2018.12.11.07.18.45; Tue, 11 Dec 2018 07:19:22 -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=GtcjlpRB; 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 S1726787AbeLKPR1 (ORCPT + 99 others); Tue, 11 Dec 2018 10:17:27 -0500 Received: from plaes.org ([188.166.43.21]:59600 "EHLO plaes.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726329AbeLKPRX (ORCPT ); Tue, 11 Dec 2018 10:17:23 -0500 Received: from localhost (unknown [213.204.46.240]) by plaes.org (Postfix) with ESMTPSA id CA52D41105; Tue, 11 Dec 2018 15:17:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=plaes.org; s=mail; t=1544541440; bh=kVazWeoBJTH1RfagB16nCXnVFLnAlX8uPnX2O4aNcZU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GtcjlpRBTZ4y9PguNQWmWbzKsRcrLFg4ogxeJiGhrTmVi9OT57KO6Sxst26rWloxS 2ZnYCUB9NpAXabu5T06gr5rhoAH57n/X8VhZoRVgnfFqQ2YPlSV5fS3LcJ/rlj7KFO np0qfFuqgMG0mimMzu1HztPQ1OYAoV8npqyy6KFLG425RSp5RwlXzgG2HFsOwpMHzh adXXch8dvt+Q2RXw2i1aU8dawDQXeiXHBxQGytcvuVuTKszVxj4exj7x7MzyFI3zhX nu0yEUhWKHbvgFC4FCCydLoVx/Zns7cu8ZtDp6ivxsEMx+RUkU0D4q+5MwryAOj9+W XwDFdiS6m7tqg== 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 v2 4/8] regulator: axp20x: add software based soft_start for AXP209 LDO3 Date: Tue, 11 Dec 2018 17:17:08 +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