From patchwork Wed Aug 13 07:17:19 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Verhaegen X-Patchwork-Id: 4716641 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.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 27D479F375 for ; Wed, 13 Aug 2014 07:21:31 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3238D201C0 for ; Wed, 13 Aug 2014 07:21:30 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 32F512018B for ; Wed, 13 Aug 2014 07:21:29 +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 1XHSpY-0004KH-5b; Wed, 13 Aug 2014 07:18:44 +0000 Received: from mail-out.m-online.net ([212.18.0.10]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XHSpG-00045a-MC for linux-arm-kernel@lists.infradead.org; Wed, 13 Aug 2014 07:18:27 +0000 Received: from frontend1.mail.m-online.net (frontend1.mail.intern.m-online.net [192.168.8.180]) by mail-out.m-online.net (Postfix) with ESMTP id 3hY2LG0zqlz3hhqp; Wed, 13 Aug 2014 09:17:42 +0200 (CEST) Received: from localhost (dynscan1.mnet-online.de [192.168.6.68]) by mail.m-online.net (Postfix) with ESMTP id 3hY2LG0fx2z7S6ST; Wed, 13 Aug 2014 09:17:42 +0200 (CEST) X-Virus-Scanned: amavisd-new at mnet-online.de Received: from mail.mnet-online.de ([192.168.8.180]) by localhost (dynscan1.mail.m-online.net [192.168.6.68]) (amavisd-new, port 10024) with ESMTP id EdaePfB5kC0r; Wed, 13 Aug 2014 09:17:37 +0200 (CEST) Received: from quoth.libv (ppp-188-174-145-148.dynamic.mnet-online.de [188.174.145.148]) by mail.mnet-online.de (Postfix) with ESMTP; Wed, 13 Aug 2014 09:17:37 +0200 (CEST) From: Luc Verhaegen To: linux-fbdev@vger.kernel.org Subject: [PATCH 4/4] simplefb: add clock handling code Date: Wed, 13 Aug 2014 09:17:19 +0200 Message-Id: <1407914239-12054-5-git-send-email-libv@skynet.be> X-Mailer: git-send-email 1.7.7 In-Reply-To: <1407914239-12054-1-git-send-email-libv@skynet.be> References: <1407914239-12054-1-git-send-email-libv@skynet.be> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140813_001827_049346_44FFF7A9 X-CRM114-Status: GOOD ( 20.02 ) X-Spam-Score: 1.0 (+) Cc: Stephen Warren , linux-sunxi@googlegroups.com, Tomi Valkeinen , Maxime Ripard , Jean-Christophe Plagniol-Villard , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , 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=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, 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 clocks listed in the simple framebuffer dt node. This is needed so that the display engine, in case the required clocks are known by the kernel code and are described in the dt, will remain properly enabled. Signed-off-by: Luc Verhaegen --- drivers/video/fbdev/simplefb.c | 103 +++++++++++++++++++++++++++++++++++++++- 1 files changed, 101 insertions(+), 2 deletions(-) diff --git a/drivers/video/fbdev/simplefb.c b/drivers/video/fbdev/simplefb.c index 74c4b2a..481dbfd 100644 --- a/drivers/video/fbdev/simplefb.c +++ b/drivers/video/fbdev/simplefb.c @@ -26,6 +26,7 @@ #include #include #include +#include static struct fb_fix_screeninfo simplefb_fix = { .id = "simple", @@ -191,8 +192,101 @@ static int simplefb_parse_pd(struct platform_device *pdev, return 0; } +/* + * Clock handling code. + * + * Here we handle the clocks property of our "simple-framebuffer" dt node. + * This is necessary so that we can make sure that any clocks needed by + * the display engine 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 clocks. + */ +struct simplefb_clock { + struct list_head list; + struct clk *clock; +}; + +/* + * 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 clock 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 void +simplefb_clocks_init(struct platform_device *pdev, struct list_head *list) +{ + struct device_node *np = pdev->dev.of_node; + int clock_count, i; + + INIT_LIST_HEAD(list); + + if (dev_get_platdata(&pdev->dev) || !np) + return; + + clock_count = of_clk_get_parent_count(np); + for (i = 0; i < clock_count; i++) { + struct simplefb_clock *entry; + struct clk *clock = of_clk_get(np, i); + int ret; + + if (IS_ERR(clock)) { + dev_err(&pdev->dev, "%s: clock %d not found: %ld\n", + __func__, i, PTR_ERR(clock)); + continue; + } + + ret = clk_prepare_enable(clock); + if (ret) { + dev_err(&pdev->dev, + "%s: failed to enable clock %d: %d\n", + __func__, i, ret); + clk_put(clock); + continue; + } + + entry = kzalloc(sizeof(struct simplefb_clock), GFP_KERNEL); + if (!entry) { + dev_err(&pdev->dev, + "%s: failed to alloc clock %d list entry.\n", + __func__, i); + clk_disable_unprepare(clock); + clk_put(clock); + continue; + } + + entry->clock = clock; + /* + * add to the front of the list, so we disable clocks in the + * correct order. + */ + list_add(&entry->list, list); + } +} + +static void +simplefb_clocks_destroy(struct list_head *list) +{ + struct list_head *pos, *n; + + list_for_each_safe(pos, n, list) { + struct simplefb_clock *entry = + container_of(pos, struct simplefb_clock, list); + + list_del(&entry->list); + + clk_disable_unprepare(entry->clock); + clk_put(entry->clock); + kfree(entry); + } +} + struct simplefb_par { u32 palette[PSEUDO_PALETTE_SIZE]; + struct list_head clock_list[1]; }; static int simplefb_probe(struct platform_device *pdev) @@ -265,6 +359,8 @@ static int simplefb_probe(struct platform_device *pdev) } info->pseudo_palette = (void *) par->palette; + simplefb_clocks_init(pdev, par->clock_list); + 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); @@ -276,14 +372,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_unmap; + goto error_clocks; } dev_info(&pdev->dev, "fb%d: simplefb registered!\n", info->node); return 0; - error_unmap: + error_clocks: + simplefb_clocks_destroy(par->clock_list); iounmap(info->screen_base); error_fb_release: @@ -299,8 +396,10 @@ static int simplefb_probe(struct platform_device *pdev) static int simplefb_remove(struct platform_device *pdev) { struct fb_info *info = platform_get_drvdata(pdev); + struct simplefb_par *par = info->par; unregister_framebuffer(info); + simplefb_clocks_destroy(par->clock_list); framebuffer_release(info); if (!dev_get_platdata(&pdev->dev) && pdev->dev.of_node) simplefb_dt_disable(pdev);