126f6d6
From patchwork Mon Feb 24 14:07:48 2020
126f6d6
Content-Type: text/plain; charset="utf-8"
126f6d6
MIME-Version: 1.0
126f6d6
Content-Transfer-Encoding: 7bit
126f6d6
X-Patchwork-Submitter: Jon Hunter <jonathanh@nvidia.com>
126f6d6
X-Patchwork-Id: 1243112
126f6d6
Return-Path: <linux-tegra-owner@vger.kernel.org>
126f6d6
X-Original-To: incoming@patchwork.ozlabs.org
126f6d6
Delivered-To: patchwork-incoming@bilbo.ozlabs.org
126f6d6
Authentication-Results: ozlabs.org; spf=none (no SPF record)
126f6d6
 smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67;
126f6d6
 helo=vger.kernel.org;
126f6d6
 envelope-from=linux-tegra-owner@vger.kernel.org;
126f6d6
 receiver=<UNKNOWN>)
126f6d6
Authentication-Results: ozlabs.org;
126f6d6
 dmarc=pass (p=none dis=none) header.from=nvidia.com
126f6d6
Authentication-Results: ozlabs.org; dkim=pass (2048-bit key;
126f6d6
 unprotected) header.d=nvidia.com header.i=@nvidia.com
126f6d6
 header.a=rsa-sha256 header.s=n1 header.b=bnwYpe6i; 
126f6d6
 dkim-atps=neutral
126f6d6
Received: from vger.kernel.org (vger.kernel.org [209.132.180.67])
126f6d6
 by ozlabs.org (Postfix) with ESMTP id 48R3nG3y97z9sRQ
126f6d6
 for <incoming@patchwork.ozlabs.org>;
126f6d6
 Tue, 25 Feb 2020 01:08:18 +1100 (AEDT)
126f6d6
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
126f6d6
 id S1727539AbgBXOIR (ORCPT <rfc822;incoming@patchwork.ozlabs.org>);
126f6d6
 Mon, 24 Feb 2020 09:08:17 -0500
126f6d6
Received: from hqnvemgate24.nvidia.com ([216.228.121.143]:5063 "EHLO
126f6d6
 hqnvemgate24.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
126f6d6
 with ESMTP id S1727451AbgBXOIR (ORCPT
126f6d6
 <rfc822;linux-tegra@vger.kernel.org>);
126f6d6
 Mon, 24 Feb 2020 09:08:17 -0500
126f6d6
Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by
126f6d6
 hqnvemgate24.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA)
126f6d6
 id <B5e53d8840000>; Mon, 24 Feb 2020 06:07:00 -0800
126f6d6
Received: from hqmail.nvidia.com ([172.20.161.6])
126f6d6
 by hqpgpgate101.nvidia.com (PGP Universal service);
126f6d6
 Mon, 24 Feb 2020 06:08:16 -0800
126f6d6
X-PGP-Universal: processed;
126f6d6
 by hqpgpgate101.nvidia.com on Mon, 24 Feb 2020 06:08:16 -0800
126f6d6
Received: from HQMAIL105.nvidia.com (172.20.187.12) by HQMAIL107.nvidia.com
126f6d6
 (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3;
126f6d6
 Mon, 24 Feb 2020 14:08:16 +0000
126f6d6
Received: from rnnvemgw01.nvidia.com (10.128.109.123) by HQMAIL105.nvidia.com
126f6d6
 (172.20.187.12) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via
126f6d6
 Frontend Transport; Mon, 24 Feb 2020 14:08:15 +0000
126f6d6
Received: from thunderball.nvidia.com (Not Verified[10.21.140.91]) by
126f6d6
 rnnvemgw01.nvidia.com with Trustwave SEG (v7, 5, 8, 10121)
126f6d6
 id <B5e53d8cd0006>; Mon, 24 Feb 2020 06:08:15 -0800
126f6d6
From: Jon Hunter <jonathanh@nvidia.com>
126f6d6
To: Milo Kim <milo.kim@ti.com>, Lee Jones <lee.jones@linaro.org>,
126f6d6
 Daniel Thompson <daniel.thompson@linaro.org>,
126f6d6
 Jingoo Han <jingoohan1@gmail.com>
126f6d6
CC: <dri-devel@lists.freedesktop.org>, <linux-kernel@vger.kernel.org>,
126f6d6
 <linux-tegra@vger.kernel.org>, Jon Hunter <jonathanh@nvidia.com>
126f6d6
Subject: [PATCH] backlight: lp855x: Ensure regulators are disabled on probe
126f6d6
 failure
126f6d6
Date: Mon, 24 Feb 2020 14:07:48 +0000
126f6d6
Message-ID: <20200224140748.2182-1-jonathanh@nvidia.com>
126f6d6
X-Mailer: git-send-email 2.17.1
126f6d6
X-NVConfidentiality: public
126f6d6
MIME-Version: 1.0
126f6d6
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1;
126f6d6
 t=1582553220; bh=B1HKOxHeQwu3ZxgJLvSfafO1owYsd38lFNvB2Oh8gBc=;
126f6d6
 h=X-PGP-Universal:From:To:CC:Subject:Date:Message-ID:X-Mailer:
126f6d6
 X-NVConfidentiality:MIME-Version:Content-Type;
126f6d6
 b=bnwYpe6isaqG2Bp36VGI0VAYjd8jtznqNulwkVw85vf5zOMSfv809Oou4taz+1W9g
126f6d6
 /eTLeJozbJBXhllQfybYW8hX4fyWIjWNON8aQugt/0HrnKAjg5r9wLT5lTgmy+8n2B
126f6d6
 YrCJM3gob7XIi7l0cbONUTfyGssXmyEi+0SUamN4DDOnXIFxHBentnbyQdvOQ9+11P
126f6d6
 Dr5X+zeRff1B/SMt2pdNwrja2cVOPDRGAM+U4epkb2bICZZUiGv1fQLKa+KgJ7xMMS
126f6d6
 AwmdVrZ/6l2MAKwM+FuIqdF/x7mpCYg64MWX7TFFRwOSCFwNeq1fcK5TWItV01qcCa
126f6d6
 mFLwbcDwN/IQA==
126f6d6
Sender: linux-tegra-owner@vger.kernel.org
126f6d6
Precedence: bulk
126f6d6
List-ID: <linux-tegra.vger.kernel.org>
126f6d6
X-Mailing-List: linux-tegra@vger.kernel.org
126f6d6
126f6d6
If probing the LP885x backlight fails after the regulators have been
126f6d6
enabled, then the following warning is seen when releasing the
126f6d6
regulators ...
126f6d6
126f6d6
 WARNING: CPU: 1 PID: 289 at drivers/regulator/core.c:2051 _regulator_put.part.28+0x158/0x160
126f6d6
 Modules linked in: tegra_xudc lp855x_bl(+) host1x pwm_tegra ip_tables x_tables ipv6 nf_defrag_ipv6
126f6d6
 CPU: 1 PID: 289 Comm: systemd-udevd Not tainted 5.6.0-rc2-next-20200224 #1
126f6d6
 Hardware name: NVIDIA Jetson TX1 Developer Kit (DT)
126f6d6
126f6d6
 ...
126f6d6
126f6d6
 Call trace:
126f6d6
  _regulator_put.part.28+0x158/0x160
126f6d6
  regulator_put+0x34/0x50
126f6d6
  devm_regulator_release+0x10/0x18
126f6d6
  release_nodes+0x12c/0x230
126f6d6
  devres_release_all+0x34/0x50
126f6d6
  really_probe+0x1c0/0x370
126f6d6
  driver_probe_device+0x58/0x100
126f6d6
  device_driver_attach+0x6c/0x78
126f6d6
  __driver_attach+0xb0/0xf0
126f6d6
  bus_for_each_dev+0x68/0xc8
126f6d6
  driver_attach+0x20/0x28
126f6d6
  bus_add_driver+0x160/0x1f0
126f6d6
  driver_register+0x60/0x110
126f6d6
  i2c_register_driver+0x40/0x80
126f6d6
  lp855x_driver_init+0x20/0x1000 [lp855x_bl]
126f6d6
  do_one_initcall+0x58/0x1a0
126f6d6
  do_init_module+0x54/0x1d0
126f6d6
  load_module+0x1d80/0x21c8
126f6d6
  __do_sys_finit_module+0xe8/0x100
126f6d6
  __arm64_sys_finit_module+0x18/0x20
126f6d6
  el0_svc_common.constprop.3+0xb0/0x168
126f6d6
  do_el0_svc+0x20/0x98
126f6d6
  el0_sync_handler+0xf4/0x1b0
126f6d6
  el0_sync+0x140/0x180
126f6d6
126f6d6
Fix this by ensuring that the regulators are disabled, if enabled, on
126f6d6
probe failure.
126f6d6
126f6d6
Finally, ensure that the vddio regulator is disabled in the driver
126f6d6
remove handler.
126f6d6
126f6d6
Signed-off-by: Jon Hunter <jonathanh@nvidia.com>
126f6d6
Reviewed-by: Daniel Thompson <daniel.thompson@linaro.org>
126f6d6
---
126f6d6
 drivers/video/backlight/lp855x_bl.c | 20 ++++++++++++++++----
126f6d6
 1 file changed, 16 insertions(+), 4 deletions(-)
126f6d6
126f6d6
diff --git a/drivers/video/backlight/lp855x_bl.c b/drivers/video/backlight/lp855x_bl.c
126f6d6
index f68920131a4a..e94932c69f54 100644
126f6d6
--- a/drivers/video/backlight/lp855x_bl.c
126f6d6
+++ b/drivers/video/backlight/lp855x_bl.c
126f6d6
@@ -456,7 +456,7 @@ static int lp855x_probe(struct i2c_client *cl, const struct i2c_device_id *id)
126f6d6
 		ret = regulator_enable(lp->enable);
126f6d6
 		if (ret < 0) {
126f6d6
 			dev_err(lp->dev, "failed to enable vddio: %d\n", ret);
126f6d6
-			return ret;
126f6d6
+			goto disable_supply;
126f6d6
 		}
126f6d6
 
126f6d6
 		/*
126f6d6
@@ -471,24 +471,34 @@ static int lp855x_probe(struct i2c_client *cl, const struct i2c_device_id *id)
126f6d6
 	ret = lp855x_configure(lp);
126f6d6
 	if (ret) {
126f6d6
 		dev_err(lp->dev, "device config err: %d", ret);
126f6d6
-		return ret;
126f6d6
+		goto disable_vddio;
126f6d6
 	}
126f6d6
 
126f6d6
 	ret = lp855x_backlight_register(lp);
126f6d6
 	if (ret) {
126f6d6
 		dev_err(lp->dev,
126f6d6
 			"failed to register backlight. err: %d\n", ret);
126f6d6
-		return ret;
126f6d6
+		goto disable_vddio;
126f6d6
 	}
126f6d6
 
126f6d6
 	ret = sysfs_create_group(&lp->dev->kobj, &lp855x_attr_group);
126f6d6
 	if (ret) {
126f6d6
 		dev_err(lp->dev, "failed to register sysfs. err: %d\n", ret);
126f6d6
-		return ret;
126f6d6
+		goto disable_vddio;
126f6d6
 	}
126f6d6
 
126f6d6
 	backlight_update_status(lp->bl);
126f6d6
+
126f6d6
 	return 0;
126f6d6
+
126f6d6
+disable_vddio:
126f6d6
+	if (lp->enable)
126f6d6
+		regulator_disable(lp->enable);
126f6d6
+disable_supply:
126f6d6
+	if (lp->supply)
126f6d6
+		regulator_disable(lp->supply);
126f6d6
+
126f6d6
+	return ret;
126f6d6
 }
126f6d6
 
126f6d6
 static int lp855x_remove(struct i2c_client *cl)
126f6d6
@@ -497,6 +507,8 @@ static int lp855x_remove(struct i2c_client *cl)
126f6d6
 
126f6d6
 	lp->bl->props.brightness = 0;
126f6d6
 	backlight_update_status(lp->bl);
126f6d6
+	if (lp->enable)
126f6d6
+		regulator_disable(lp->enable);
126f6d6
 	if (lp->supply)
126f6d6
 		regulator_disable(lp->supply);
126f6d6
 	sysfs_remove_group(&lp->dev->kobj, &lp855x_attr_group);