From patchwork Fri Nov 4 14:45:07 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 9412705 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7077460722 for ; Fri, 4 Nov 2016 14:46:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 62EF428B96 for ; Fri, 4 Nov 2016 14:46:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 57B322B19B; Fri, 4 Nov 2016 14:46:53 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A22CA28B96 for ; Fri, 4 Nov 2016 14:46:52 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1c2fkQ-000689-Ii; Fri, 04 Nov 2016 14:45:38 +0000 Received: from mx1.redhat.com ([209.132.183.28]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1c2fkL-0005Fx-7p for linux-arm-kernel@lists.infradead.org; Fri, 04 Nov 2016 14:45:35 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D3D23C04B955; Fri, 4 Nov 2016 14:45:11 +0000 (UTC) Received: from shalem.localdomain.com (vpn1-5-239.ams2.redhat.com [10.36.5.239]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id uA4Ej8Ud018633; Fri, 4 Nov 2016 10:45:09 -0400 From: Hans de Goede To: Tomi Valkeinen Subject: [PATCH] simplefb: Separate clk / regulator get and enable steps Date: Fri, 4 Nov 2016 15:45:07 +0100 Message-Id: <20161104144507.18072-1-hdegoede@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 04 Nov 2016 14:45:11 +0000 (UTC) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20161104_074533_488014_55189E30 X-CRM114-Status: GOOD ( 19.59 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Hans de Goede , Chen-Yu Tsai , linux-fbdev@vger.kernel.org, linux-arm-kernel@lists.infradead.org, David Herrmann MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Currently when a simplefb needs both clocks and regulators and one of the regulators returns -EPROBE_DEFER when we try to get it, we end up disabling the clocks. This causes the screen to go blank; and in some cases my cause hardware state to be lost resulting in the framebuffer not working at all. This commit splits the get and enable steps and only enables clocks and regulators after successfully getting all of them, fixing the disabling of the clocks which were left enabled by the firmware setting up the simplefb. Signed-off-by: Hans de Goede --- drivers/video/fbdev/simplefb.c | 56 ++++++++++++++++++++++++++++++------------ 1 file changed, 40 insertions(+), 16 deletions(-) diff --git a/drivers/video/fbdev/simplefb.c b/drivers/video/fbdev/simplefb.c index 61f799a..a3c44ec 100644 --- a/drivers/video/fbdev/simplefb.c +++ b/drivers/video/fbdev/simplefb.c @@ -180,10 +180,12 @@ static int simplefb_parse_pd(struct platform_device *pdev, struct simplefb_par { u32 palette[PSEUDO_PALETTE_SIZE]; #if defined CONFIG_OF && defined CONFIG_COMMON_CLK + bool clks_enabled; unsigned int clk_count; struct clk **clks; #endif #if defined CONFIG_OF && defined CONFIG_REGULATOR + bool regulators_enabled; u32 regulator_count; struct regulator **regulators; #endif @@ -208,12 +210,12 @@ struct simplefb_par { * the fb probe will not help us much either. So just complain and carry on, * and hope that the user actually gets a working fb at the end of things. */ -static int simplefb_clocks_init(struct simplefb_par *par, - struct platform_device *pdev) +static int simplefb_clocks_get(struct simplefb_par *par, + struct platform_device *pdev) { struct device_node *np = pdev->dev.of_node; struct clk *clock; - int i, ret; + int i; if (dev_get_platdata(&pdev->dev) || !np) return 0; @@ -244,6 +246,14 @@ static int simplefb_clocks_init(struct simplefb_par *par, par->clks[i] = clock; } + return 0; +} + +static void simplefb_clocks_enable(struct simplefb_par *par, + struct platform_device *pdev) +{ + int i, ret; + for (i = 0; i < par->clk_count; i++) { if (par->clks[i]) { ret = clk_prepare_enable(par->clks[i]); @@ -256,8 +266,7 @@ static int simplefb_clocks_init(struct simplefb_par *par, } } } - - return 0; + par->clks_enabled = true; } static void simplefb_clocks_destroy(struct simplefb_par *par) @@ -269,7 +278,8 @@ static void simplefb_clocks_destroy(struct simplefb_par *par) for (i = 0; i < par->clk_count; i++) { if (par->clks[i]) { - clk_disable_unprepare(par->clks[i]); + if (par->clks_enabled) + clk_disable_unprepare(par->clks[i]); clk_put(par->clks[i]); } } @@ -277,8 +287,10 @@ static void simplefb_clocks_destroy(struct simplefb_par *par) kfree(par->clks); } #else -static int simplefb_clocks_init(struct simplefb_par *par, +static int simplefb_clocks_get(struct simplefb_par *par, struct platform_device *pdev) { return 0; } +static void simplefb_clocks_enable(struct simplefb_par *par, + struct platform_device *pdev) { } static void simplefb_clocks_destroy(struct simplefb_par *par) { } #endif @@ -305,14 +317,14 @@ static void simplefb_clocks_destroy(struct simplefb_par *par) { } * the fb probe will not help us much either. So just complain and carry on, * and hope that the user actually gets a working fb at the end of things. */ -static int simplefb_regulators_init(struct simplefb_par *par, - struct platform_device *pdev) +static int simplefb_regulators_get(struct simplefb_par *par, + struct platform_device *pdev) { struct device_node *np = pdev->dev.of_node; struct property *prop; struct regulator *regulator; const char *p; - int count = 0, i = 0, ret; + int count = 0, i = 0; if (dev_get_platdata(&pdev->dev) || !np) return 0; @@ -354,6 +366,14 @@ static int simplefb_regulators_init(struct simplefb_par *par, } par->regulator_count = i; + return 0; +} + +static void simplefb_regulators_enable(struct simplefb_par *par, + struct platform_device *pdev) +{ + int i, ret; + /* Enable all the regulators */ for (i = 0; i < par->regulator_count; i++) { ret = regulator_enable(par->regulators[i]); @@ -365,15 +385,14 @@ static int simplefb_regulators_init(struct simplefb_par *par, par->regulators[i] = NULL; } } - - return 0; + par->regulators_enabled = true; } static void simplefb_regulators_destroy(struct simplefb_par *par) { int i; - if (!par->regulators) + if (!par->regulators || !par->regulators_enabled) return; for (i = 0; i < par->regulator_count; i++) @@ -381,8 +400,10 @@ static void simplefb_regulators_destroy(struct simplefb_par *par) regulator_disable(par->regulators[i]); } #else -static int simplefb_regulators_init(struct simplefb_par *par, +static int simplefb_regulators_get(struct simplefb_par *par, struct platform_device *pdev) { return 0; } +static void simplefb_regulators_enable(struct simplefb_par *par, + struct platform_device *pdev) { } static void simplefb_regulators_destroy(struct simplefb_par *par) { } #endif @@ -453,14 +474,17 @@ static int simplefb_probe(struct platform_device *pdev) } info->pseudo_palette = par->palette; - ret = simplefb_clocks_init(par, pdev); + ret = simplefb_clocks_get(par, pdev); if (ret < 0) goto error_unmap; - ret = simplefb_regulators_init(par, pdev); + ret = simplefb_regulators_get(par, pdev); if (ret < 0) goto error_clocks; + simplefb_clocks_enable(par, pdev); + simplefb_regulators_enable(par, pdev); + dev_info(&pdev->dev, "framebuffer at 0x%lx, 0x%x bytes, mapped to 0x%p\n", info->fix.smem_start, info->fix.smem_len, info->screen_base);