From patchwork Mon Oct 12 17:04:18 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen-Yu Tsai X-Patchwork-Id: 7378071 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 056199F1B9 for ; Mon, 12 Oct 2015 17:07:03 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 04EDB208D3 for ; Mon, 12 Oct 2015 17:07:02 +0000 (UTC) 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.kernel.org (Postfix) with ESMTPS id F0716208D8 for ; Mon, 12 Oct 2015 17:07:00 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZlgXB-0007G1-PU; Mon, 12 Oct 2015 17:05:13 +0000 Received: from smtp.csie.ntu.edu.tw ([140.112.30.61]) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZlgWx-0006Km-TL for linux-arm-kernel@lists.infradead.org; Mon, 12 Oct 2015 17:05:01 +0000 Received: from mirror2.csie.ntu.edu.tw (mirror2.csie.ntu.edu.tw [140.112.30.76]) (Authenticated sender: b93043) by smtp.csie.ntu.edu.tw (Postfix) with ESMTPSA id 549AC20589; Tue, 13 Oct 2015 01:04:35 +0800 (CST) Received: by mirror2.csie.ntu.edu.tw (Postfix, from userid 1000) id 25B395F9F5; Tue, 13 Oct 2015 01:04:35 +0800 (CST) From: Chen-Yu Tsai To: Hans de Goede , Jean-Christophe Plagniol-Villard , Tomi Valkeinen , Rob Herring , Pawel Moll , Mark Rutland , Ian Campbell , Kumar Gala Subject: [PATCH RFC 2/2] simplefb: Claim and enable regulators Date: Tue, 13 Oct 2015 01:04:18 +0800 Message-Id: <1444669458-5588-3-git-send-email-wens@csie.org> X-Mailer: git-send-email 2.5.3 In-Reply-To: <1444669458-5588-1-git-send-email-wens@csie.org> References: <1444669458-5588-1-git-send-email-wens@csie.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20151012_100500_264130_0261400E X-CRM114-Status: GOOD ( 19.31 ) X-Spam-Score: -4.2 (----) 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: devicetree@vger.kernel.org, linux-fbdev@vger.kernel.org, linux-kernel@vger.kernel.org, Chen-Yu Tsai , Mark Brown , Maxime Ripard , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This claims and enables regulators listed in the simple framebuffer dt node. This is needed so that regulators powering the display pipeline and external hardware, described in the device node and known by the kernel code, will remain properly enabled. Signed-off-by: Chen-Yu Tsai --- drivers/video/fbdev/simplefb.c | 102 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 101 insertions(+), 1 deletion(-) diff --git a/drivers/video/fbdev/simplefb.c b/drivers/video/fbdev/simplefb.c index 52c5c7e63b52..b2e419d9be3d 100644 --- a/drivers/video/fbdev/simplefb.c +++ b/drivers/video/fbdev/simplefb.c @@ -28,7 +28,9 @@ #include #include #include +#include #include +#include static struct fb_fix_screeninfo simplefb_fix = { .id = "simple", @@ -174,6 +176,10 @@ struct simplefb_par { int clk_count; struct clk **clks; #endif +#if defined CONFIG_OF && defined CONFIG_REGULATOR + u32 regulator_count; + struct regulator **regulators; +#endif }; #if defined CONFIG_OF && defined CONFIG_COMMON_CLK @@ -269,6 +275,93 @@ static int simplefb_clocks_init(struct simplefb_par *par, static void simplefb_clocks_destroy(struct simplefb_par *par) { } #endif +#if defined CONFIG_OF && defined CONFIG_REGULATOR +/* + * Regulator handling code. + * + * Here we handle the num-supplies and vin*-supply properties of our + * "simple-framebuffer" dt node. This is necessary so that we can make sure + * that any regulators needed by the display hardware that the bootloader + * set up for us (and for which it provided a simplefb dt node), stay up, + * for the life of the simplefb driver. + * + * When the driver unloads, we cleanly disable, and then release the + * regulators. + * + * We only complain about errors here, no action is taken as the most likely + * error can only happen due to a mismatch between the bootloader which set + * up simplefb, and the regulator definitions in the device tree. Chances are + * that there are no adverse effects, and if there are, a clean teardown of + * 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) +{ + struct device_node *np = pdev->dev.of_node; + struct regulator *regulator; + int i, ret; + + if (dev_get_platdata(&pdev->dev) || !np) + return 0; + + ret = of_property_read_u32(np, "num-supplies", &par->regulator_count); + if (ret < 0) + return 0; + + par->regulators = devm_kcalloc(&pdev->dev, par->regulator_count, + sizeof(struct regulator *), GFP_KERNEL); + if (!par->regulators) + return -ENOMEM; + + for (i = 0; i < par->regulator_count; i++) { + char name[8]; + + snprintf(name, sizeof(name), "vin%d", i); + regulator = devm_regulator_get_optional(&pdev->dev, name); + if (IS_ERR(regulator)) { + if (PTR_ERR(regulator) == -EPROBE_DEFER) + return -EPROBE_DEFER; + dev_err(&pdev->dev, "%s: regulator %d not found: %ld\n", + __func__, i, PTR_ERR(regulator)); + continue; + } + par->regulators[i] = regulator; + } + + for (i = 0; i < par->regulator_count; i++) { + if (par->regulators[i]) { + ret = regulator_enable(par->regulators[i]); + if (ret) { + dev_err(&pdev->dev, + "%s: failed to enable regulator %d: %d\n", + __func__, i, ret); + devm_regulator_put(par->regulators[i]); + par->regulators[i] = NULL; + } + } + } + + return 0; +} + +static void simplefb_regulators_destroy(struct simplefb_par *par) +{ + int i; + + if (!par->regulators) + return; + + for (i = 0; i < par->regulator_count; i++) + if (par->regulators[i]) + regulator_disable(par->regulators[i]); +} +#else +static int simplefb_regulators_init(struct simplefb_par *par, + struct platform_device *pdev) { return 0; } +static void simplefb_regulators_destroy(struct simplefb_par *par) { } +#endif + static int simplefb_probe(struct platform_device *pdev) { int ret; @@ -340,6 +433,10 @@ static int simplefb_probe(struct platform_device *pdev) if (ret < 0) goto error_unmap; + ret = simplefb_regulators_init(par, pdev); + if (ret < 0) + goto error_clocks; + 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); @@ -351,13 +448,15 @@ static int simplefb_probe(struct platform_device *pdev) ret = register_framebuffer(info); if (ret < 0) { dev_err(&pdev->dev, "Unable to register simplefb: %d\n", ret); - goto error_clocks; + goto error_regulators; } dev_info(&pdev->dev, "fb%d: simplefb registered!\n", info->node); return 0; +error_regulators: + simplefb_regulators_destroy(par); error_clocks: simplefb_clocks_destroy(par); error_unmap: @@ -373,6 +472,7 @@ static int simplefb_remove(struct platform_device *pdev) struct simplefb_par *par = info->par; unregister_framebuffer(info); + simplefb_regulators_destroy(par); simplefb_clocks_destroy(par); framebuffer_release(info);