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: 11454051 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 8BCEE913 for ; Mon, 23 Mar 2020 21:35:38 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (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 760C92073E for ; Mon, 23 Mar 2020 21:35:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 760C92073E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 68B8189E0D; Mon, 23 Mar 2020 21:35:37 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org X-Greylist: delayed 1128 seconds by postgrey-1.36 at gabe; Mon, 23 Mar 2020 21:35:36 UTC Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [IPv6:2001:67c:670:201:290:27ff:fe1d:cc33]) by gabe.freedesktop.org (Postfix) with ESMTPS id F0E4C89E0D for ; Mon, 23 Mar 2020 21:35:36 +0000 (UTC) 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: dri-devel@lists.freedesktop.org X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development 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 , linux-arm-kernel@lists.infradead.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" 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; }