From patchwork Mon Mar 23 21:16:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= X-Patchwork-Id: 11454049 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7B7A8159A for ; Mon, 23 Mar 2020 21:16:57 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5BAB12070A for ; Mon, 23 Mar 2020 21:16:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="Mxba7/gU" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5BAB12070A Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:To :From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=o5LvL0BZrWlVT1U/lrFS4uUx4piVOwUVyDIBCm/BoxM=; b=Mxba7/gUh286wp z0pLROlhxCKFHQVMU0aBEpKAqV8jr96sDChZin0auMcxbeP0tiTOTJZ2rBXm+ZBy3X1NGjftQRVFF QOZltXwM7ZfjWPzAnE4+fwF9Vy+QLGbwKLjOfcpOyWnVp44WecIQE67hXANccOPTPhAipWRfJXTqX u1Xyc/I5Br4gTQYIpR/1JX+cduE3iA4Do23TmKEACO3uhTXzwZOPlZb8ueUDE7Pr0vbPJJldjlJpm odPS605GlwY5EjnJTtdmH6vw5gDKXaegcq+mAjZRm440xGKpq5Rxnu3W2PnPPpBPkXojLTiSgWinL ZrsDylkuDEiO2WyVCsIw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jGURL-00082K-Lf; Mon, 23 Mar 2020 21:16:55 +0000 Received: from metis.ext.pengutronix.de ([2001:67c:670:201:290:27ff:fe1d:cc33]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jGURF-0007yy-1L for linux-arm-kernel@lists.infradead.org; Mon, 23 Mar 2020 21:16:50 +0000 Received: from dude.hi.pengutronix.de ([2001:67c:670:100:1d::7]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jGUR6-0004GR-5B; Mon, 23 Mar 2020 22:16:40 +0100 Received: from ukl by dude.hi.pengutronix.de with local (Exim 4.92) (envelope-from ) id 1jGUR3-0006TG-DH; Mon, 23 Mar 2020 22:16:37 +0100 From: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= To: Sascha Hauer , Bartlomiej Zolnierkiewicz Subject: [PATCH] video: fbdev: imxfb: ensure balanced regulator usage Date: Mon, 23 Mar 2020 22:16:26 +0100 Message-Id: <20200323211626.24812-1-u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::7 X-SA-Exim-Mail-From: ukl@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-arm-kernel@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200323_141649_218254_38C3F594 X-CRM114-Status: GOOD ( 13.72 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.3 on bombadil.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-fbdev@vger.kernel.org, Shawn Guo , dri-devel@lists.freedesktop.org, NXP Linux Team , Pengutronix Kernel Team , Fabio Estevam , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org The fbdev framework doesn't care to call the .set_power callback only on changes. So the driver has to care for itself that the regulator doesn't get disabled more often than enabled. This fixes the regulator warning unbalanced disables for lcd supply which can be triggered by doing echo 4 > /sys/class/lcd/imxfb-lcd/lcd_power twice. Signed-off-by: Uwe Kleine-König --- drivers/video/fbdev/imxfb.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/drivers/video/fbdev/imxfb.c b/drivers/video/fbdev/imxfb.c index 370bf2553d43..884b16efa7e8 100644 --- a/drivers/video/fbdev/imxfb.c +++ b/drivers/video/fbdev/imxfb.c @@ -172,6 +172,7 @@ struct imxfb_info { int num_modes; struct regulator *lcd_pwr; + int lcd_pwr_enabled; }; static const struct platform_device_id imxfb_devtype[] = { @@ -801,16 +802,30 @@ static int imxfb_lcd_get_power(struct lcd_device *lcddev) return FB_BLANK_UNBLANK; } +static int imxfb_regulator_set(struct imxfb_info *fbi, int enable) +{ + int ret; + + if (enable == fbi->lcd_pwr_enabled) + return 0; + + if (enable) + ret = regulator_enable(fbi->lcd_pwr); + else + ret = regulator_disable(fbi->lcd_pwr); + + if (ret == 0) + fbi->lcd_pwr_enabled = enable; + + return ret; +} + static int imxfb_lcd_set_power(struct lcd_device *lcddev, int power) { struct imxfb_info *fbi = dev_get_drvdata(&lcddev->dev); - if (!IS_ERR(fbi->lcd_pwr)) { - if (power == FB_BLANK_UNBLANK) - return regulator_enable(fbi->lcd_pwr); - else - return regulator_disable(fbi->lcd_pwr); - } + if (!IS_ERR(fbi->lcd_pwr)) + return imxfb_regulator_set(fbi, power == FB_BLANK_UNBLANK); return 0; }