From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932665AbdBPRGp (ORCPT ); Thu, 16 Feb 2017 12:06:45 -0500 Received: from ec2-52-27-115-49.us-west-2.compute.amazonaws.com ([52.27.115.49]:50887 "EHLO osg.samsung.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932465AbdBPRGo (ORCPT ); Thu, 16 Feb 2017 12:06:44 -0500 From: Javier Martinez Canillas To: linux-kernel@vger.kernel.org Cc: Mauro Carvalho Chehab , Andi Shyti , Mark Brown , Shuah Khan , Inki Dae , Jon Hunter , Liam Girdwood , Javier Martinez Canillas Subject: [PATCH] regulator: core: Resolve supplies before disabling unused regulators Date: Thu, 16 Feb 2017 14:06:28 -0300 Message-Id: <20170216170629.19927-1-javier@osg.samsung.com> X-Mailer: git-send-email 2.9.3 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org After commit 66d228a2bf03 ("regulator: core: Don't use regulators as supplies until the parent is bound"), input supplies aren't resolved if the input supplies parent device has not been bound. This prevent regulators to hold an invalid reference if its supply parent device driver probe is deferred. But this causes issues on some boards where a PMIC's regulator use as input supply a regulator from another PMIC whose driver is registered after the driver for the former. In this case the regulators for the first PMIC will fail to resolve input supplies on regulators registration (since the other PMIC wasn't probed yet). And when the core attempts to resolve again latter when the other PMIC registers its own regulators, it will fail again since the parent device isn't bound yet. This will cause some parent supplies to never be resolved and wrongly be disabled on boot due taking them as unused. To solve this problem don't attempt to resolve the pending regulators input supplies on regulator registration, but instead do it just once before disabling the unused regulators. This also makes the regulator resolve logic more efficient since there is no need to attempt to resolve the input supplies on each regulator registration, and doing it once before disabling the unused is enough. Signed-off-by: Javier Martinez Canillas --- Hello, I found this issue since after the mentioned commit the Exynos5800 Peach Pi Chromebook was failing to boot as reported by kernelci: https://storage.kernelci.org/broonie-regulator/regulator-fix-v4.10-rc6-58-g3761de31e8aa/arm-exynos_defconfig/lab-collabora/boot-exynos5800-peach-pi.html This patch fixes the issue. Best regards, Javier drivers/regulator/core.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index cc68604ad97a..193e79a51ce8 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -4108,9 +4108,6 @@ regulator_register(const struct regulator_desc *regulator_desc, dev_set_drvdata(&rdev->dev, rdev); rdev_init_debugfs(rdev); - /* try to resolve regulators supply since a new one was registered */ - class_for_each_device(®ulator_class, NULL, NULL, - regulator_register_resolve_supply); kfree(config); return rdev; @@ -4556,6 +4553,16 @@ static int __init regulator_init_complete(void) if (of_have_populated_dt()) has_full_constraints = true; + /* + * Regulators may had failed to resolve their input supplies + * when were registered, either because the input supply was + * not registered yet or because its parent device was not + * bound yet. So attempt to resolve the input supplies for + * pending regulators before trying to disable unused ones. + */ + class_for_each_device(®ulator_class, NULL, NULL, + regulator_register_resolve_supply); + /* If we have a full configuration then disable any regulators * we have permission to change the status for and which are * not in use or always_on. This is effectively the default -- 2.9.3