From patchwork Thu Jun 9 09:44:19 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 9166637 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 1C9A76048F for ; Thu, 9 Jun 2016 09:52:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0BA002830C for ; Thu, 9 Jun 2016 09:52:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0038128336; Thu, 9 Jun 2016 09:52:07 +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=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7F9392830C for ; Thu, 9 Jun 2016 09:52:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933398AbcFIJo7 (ORCPT ); Thu, 9 Jun 2016 05:44:59 -0400 Received: from mailout2.w1.samsung.com ([210.118.77.12]:55257 "EHLO mailout2.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932752AbcFIJow (ORCPT ); Thu, 9 Jun 2016 05:44:52 -0400 Received: from eucpsbgm1.samsung.com (unknown [203.254.199.244]) by mailout2.w1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0O8I001N70EO5I90@mailout2.w1.samsung.com>; Thu, 09 Jun 2016 10:44:48 +0100 (BST) X-AuditID: cbfec7f4-f796c6d000001486-80-57593a8f27df Received: from eusync1.samsung.com ( [203.254.199.211]) by eucpsbgm1.samsung.com (EUCPMTA) with SMTP id DB.D6.05254.F8A39575; Thu, 9 Jun 2016 10:44:47 +0100 (BST) Received: from AMDC2174.DIGITAL.local ([106.120.53.17]) by eusync1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0O8I006RA0EHZZ10@eusync1.samsung.com>; Thu, 09 Jun 2016 10:44:47 +0100 (BST) From: Krzysztof Kozlowski To: Ulf Hansson , Rob Herring , Pawel Moll , Mark Rutland , Ian Campbell , Kumar Gala , Krzysztof Kozlowski , Sebastian Reichel , Dmitry Eremin-Solenikov , David Woodhouse , Liam Girdwood , Mark Brown , Greg Kroah-Hartman , Hans de Goede , Jean-Christophe Plagniol-Villard , Tomi Valkeinen , Heiko Stuebner , linux-mmc@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, linux-pm@vger.kernel.org, linux-usb@vger.kernel.org, linux-fbdev@vger.kernel.org, hzpeterchen@gmail.com Cc: Bartlomiej Zolnierkiewicz Subject: [RFC v4 02/14] simplefb: Use new devm_of_regulator_all_get helper and bulk API Date: Thu, 09 Jun 2016 11:44:19 +0200 Message-id: <1465465471-28740-3-git-send-email-k.kozlowski@samsung.com> X-Mailer: git-send-email 1.9.1 In-reply-to: <1465465471-28740-1-git-send-email-k.kozlowski@samsung.com> References: <1465465471-28740-1-git-send-email-k.kozlowski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrKIsWRmVeSWpSXmKPExsVy+t/xy7r9VpHhBmdv2VhsnLGe1WLqwyds FpOevGe2mH/kHKvFxJWTmS363yxktWhevJ7N4s3x6UwW/x+9ZrXourqJzeLcq5WMFq9fGFp8 u9LBZLHp8TVWixN9H1gtLu+aw2Zx5H8/o8Xn3iOMFjPO72OyWLSsldli6fWLTBYTpq9lsVj3 8AWTReveI+wWp3eXWKyff4vN4vjacAdpjzXz1jB6XO7rZfLYOesuu8fK5V/YPDav0PJ4deEO i8emVZ1sHneu7WHz2D93DbvH5iX1Hu/3XWXz6NuyitFj+7V5zB7Hb2xn8vi8SS6AP4rLJiU1 J7MstUjfLoEro+33ffaCPfIVt95eY21gPCTZxcjJISFgInH08HxWCFtM4sK99WxdjFwcQgJL GSX6O48zQTiNTBLfL85hAqliEzCW2Lx8CViViMAldokbl7aDJZgFLCS2bl3NDmILC0RKPNzw iBHEZhFQlfh09TlQnIODV8Bd4vDyVIhtchInj00G28wp4CHx6N5jZhBbCKhk7+LJbBMYeRcw MqxiFE0tTS4oTkrPNdQrTswtLs1L10vOz93ECIm8LzsYFx+zOsQowMGoxMOrmRIRLsSaWFZc mXuIUYKDWUmE94d5ZLgQb0piZVVqUX58UWlOavEhRmkOFiVx3rm73ocICaQnlqRmp6YWpBbB ZJk4OKUaGK3f8k3zbLjz5bKkqvrF3OS1uwOb6n62rTBOspWX2rXglN6KhV/i9h2pfmu5TVWi Sjxo/qPKoKv7YqIS9wb37F749bGR0kt2I6UsL/9d21N929yC43pOh788v1pn9cHHf6anvI0t 7jtXKLSr/b4uQwIz+yKvd/btPUkXY4yyhdsdC342MvvGKbEUZyQaajEXFScCAFSp5Ze4AgAA Sender: linux-fbdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fbdev@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Switch from manual way of getting all regulators to usage of devm_of_regulator_all_get(). Additionally use the regulator bulk API which changes the logic in case of failure of regulator enable. Before if regulator_enable() returned error for one regulator, rest of them were still enabled. The bulk API does everything atomically. Signed-off-by: Krzysztof Kozlowski --- Not tested. --- drivers/video/fbdev/simplefb.c | 71 +++++++++--------------------------------- 1 file changed, 14 insertions(+), 57 deletions(-) diff --git a/drivers/video/fbdev/simplefb.c b/drivers/video/fbdev/simplefb.c index e9cf19977285..897b95efa40d 100644 --- a/drivers/video/fbdev/simplefb.c +++ b/drivers/video/fbdev/simplefb.c @@ -32,6 +32,7 @@ #include #include #include +#include static struct fb_fix_screeninfo simplefb_fix = { .id = "simple", @@ -178,8 +179,8 @@ struct simplefb_par { struct clk **clks; #endif #if defined CONFIG_OF && defined CONFIG_REGULATOR - u32 regulator_count; - struct regulator **regulators; + unsigned int regulator_count; + struct regulator_bulk_data *regulators; #endif }; @@ -278,8 +279,6 @@ static void simplefb_clocks_destroy(struct simplefb_par *par) { } #if defined CONFIG_OF && defined CONFIG_REGULATOR -#define SUPPLY_SUFFIX "-supply" - /* * Regulator handling code. * @@ -303,61 +302,23 @@ static int simplefb_regulators_init(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 ret; if (dev_get_platdata(&pdev->dev) || !np) return 0; - /* Count the number of regulator supplies */ - for_each_property_of_node(np, prop) { - p = strstr(prop->name, SUPPLY_SUFFIX); - if (p && p != prop->name) - count++; - } - - if (!count) + ret = devm_of_regulator_all_get(&pdev->dev, &par->regulator_count, &par->regulators); + if (ret) + return ret; + else if (!par->regulator_count) return 0; - par->regulators = devm_kcalloc(&pdev->dev, count, - sizeof(struct regulator *), GFP_KERNEL); - if (!par->regulators) - return -ENOMEM; - - /* Get all the regulators */ - for_each_property_of_node(np, prop) { - char name[32]; /* 32 is max size of property name */ - - p = strstr(prop->name, SUPPLY_SUFFIX); - if (!p || p == prop->name) - continue; - - strlcpy(name, prop->name, - strlen(prop->name) - strlen(SUPPLY_SUFFIX) + 1); - 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, "regulator %s not found: %ld\n", - name, PTR_ERR(regulator)); - continue; - } - par->regulators[i++] = regulator; - } - par->regulator_count = i; - /* Enable all the regulators */ - for (i = 0; i < par->regulator_count; i++) { - ret = regulator_enable(par->regulators[i]); - if (ret) { - dev_err(&pdev->dev, - "failed to enable regulator %d: %d\n", - i, ret); - devm_regulator_put(par->regulators[i]); - par->regulators[i] = NULL; - } + ret = regulator_bulk_enable(par->regulator_count, par->regulators); + if (ret) { + dev_err(&pdev->dev, + "failed to enable regulators: %d\n", ret); + return ret; } return 0; @@ -365,14 +326,10 @@ static int simplefb_regulators_init(struct simplefb_par *par, 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]); + regulator_bulk_disable(par->regulator_count, par->regulators); } #else static int simplefb_regulators_init(struct simplefb_par *par,