From patchwork Tue Apr 18 10:43:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Fitzgerald X-Patchwork-Id: 9685331 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 C2DCF602C2 for ; Tue, 18 Apr 2017 10:44:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ABF47283E8 for ; Tue, 18 Apr 2017 10:44:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A0B172840B; Tue, 18 Apr 2017 10:44:35 +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=ham 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 2F2E228414 for ; Tue, 18 Apr 2017 10:44:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756143AbdDRKoc (ORCPT ); Tue, 18 Apr 2017 06:44:32 -0400 Received: from mx0b-001ae601.pphosted.com ([67.231.152.168]:60151 "EHLO mx0b-001ae601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756016AbdDRKo1 (ORCPT ); Tue, 18 Apr 2017 06:44:27 -0400 Received: from pps.filterd (m0077474.ppops.net [127.0.0.1]) by mx0b-001ae601.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v3IAhves026602; Tue, 18 Apr 2017 05:43:58 -0500 Authentication-Results: ppops.net; spf=none smtp.mailfrom=rf@opensource.wolfsonmicro.com Received: from mail2.cirrus.com (mail1.cirrus.com [141.131.3.20]) by mx0b-001ae601.pphosted.com with ESMTP id 29w9yugw7e-1; Tue, 18 Apr 2017 05:43:58 -0500 Received: from EX17.ad.cirrus.com (unknown [172.20.9.81]) by mail2.cirrus.com (Postfix) with ESMTP id 3BF426121AEA; Tue, 18 Apr 2017 05:43:58 -0500 (CDT) Received: from imbe.wolfsonmicro.main (198.61.95.81) by EX17.ad.cirrus.com (172.20.9.81) with Microsoft SMTP Server id 14.3.301.0; Tue, 18 Apr 2017 11:43:56 +0100 Received: from rf-debian.ad.cirrus.com (rf-debian.ad.cirrus.com [198.90.223.7]) by imbe.wolfsonmicro.main (8.14.4/8.14.4) with ESMTP id v3IAh9sD011508; Tue, 18 Apr 2017 11:43:10 +0100 From: Richard Fitzgerald To: , , , CC: , , , Subject: [PATCH 7/7] regulator: arizona-ldo1: Factor out generic initialization Date: Tue, 18 Apr 2017 11:43:54 +0100 Message-ID: <1492512234-19210-9-git-send-email-rf@opensource.wolfsonmicro.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1492512234-19210-1-git-send-email-rf@opensource.wolfsonmicro.com> References: <1492512234-19210-1-git-send-email-rf@opensource.wolfsonmicro.com> MIME-Version: 1.0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1702020001 definitions=main-1704180087 Sender: linux-samsung-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP In preparation for sharing this driver with Madera codecs, factor out the parts of initialization that aren't dependent on struct arizona. Signed-off-by: Richard Fitzgerald --- drivers/regulator/arizona-ldo1.c | 114 ++++++++++++++++++++++----------------- 1 file changed, 66 insertions(+), 48 deletions(-) diff --git a/drivers/regulator/arizona-ldo1.c b/drivers/regulator/arizona-ldo1.c index 678f81f..96fddff 100644 --- a/drivers/regulator/arizona-ldo1.c +++ b/drivers/regulator/arizona-ldo1.c @@ -234,67 +234,40 @@ static int arizona_ldo1_of_get_pdata(struct arizona_ldo1_pdata *pdata, return 0; } -static int arizona_ldo1_probe(struct platform_device *pdev) +static int arizona_ldo1_common_init(struct platform_device *pdev, + struct arizona_ldo1 *ldo1, + const struct regulator_desc *desc, + struct arizona_ldo1_pdata *pdata, + bool *external_dcvdd) { - struct arizona *arizona = dev_get_drvdata(pdev->dev.parent); - const struct regulator_desc *desc; + struct device *parent_dev = pdev->dev.parent; struct regulator_config config = { }; - struct arizona_ldo1 *ldo1; - bool external_dcvdd = false; int ret; - ldo1 = devm_kzalloc(&pdev->dev, sizeof(*ldo1), GFP_KERNEL); - if (!ldo1) - return -ENOMEM; - - ldo1->regmap = arizona->regmap; - - /* - * Since the chip usually supplies itself we provide some - * default init_data for it. This will be overridden with - * platform data if provided. - */ - switch (arizona->type) { - case WM5102: - case WM8997: - case WM8998: - case WM1814: - desc = &arizona_ldo1_hc; - ldo1->init_data = arizona_ldo1_dvfs; - break; - case WM5110: - case WM8280: - desc = &arizona_ldo1; - ldo1->init_data = arizona_ldo1_wm5110; - break; - default: - desc = &arizona_ldo1; - ldo1->init_data = arizona_ldo1_default; - break; - } + *external_dcvdd = false; - ldo1->init_data.consumer_supplies = &ldo1->supply; ldo1->supply.supply = "DCVDD"; - ldo1->supply.dev_name = dev_name(arizona->dev); + ldo1->init_data.consumer_supplies = &ldo1->supply; + ldo1->supply.dev_name = dev_name(parent_dev); - config.dev = arizona->dev; + config.dev = parent_dev; config.driver_data = ldo1; - config.regmap = arizona->regmap; + config.regmap = ldo1->regmap; if (IS_ENABLED(CONFIG_OF)) { - if (!dev_get_platdata(arizona->dev)) { - ret = arizona_ldo1_of_get_pdata(&arizona->pdata.ldo1, + if (!dev_get_platdata(parent_dev)) { + ret = arizona_ldo1_of_get_pdata(pdata, &config, desc, - &external_dcvdd); + external_dcvdd); if (ret < 0) return ret; } } - config.ena_gpio = arizona->pdata.ldo1.ldoena; + config.ena_gpio = pdata->ldoena; - if (arizona->pdata.ldo1.init_data) - config.init_data = arizona->pdata.ldo1.init_data; + if (pdata->init_data) + config.init_data = pdata->init_data; else config.init_data = &ldo1->init_data; @@ -303,9 +276,7 @@ static int arizona_ldo1_probe(struct platform_device *pdev) * consumers then DCVDD is supplied externally. */ if (config.init_data->num_consumer_supplies == 0) - arizona->external_dcvdd = true; - else - arizona->external_dcvdd = external_dcvdd; + *external_dcvdd = true; ldo1->regulator = devm_regulator_register(&pdev->dev, desc, &config); @@ -313,7 +284,7 @@ static int arizona_ldo1_probe(struct platform_device *pdev) if (IS_ERR(ldo1->regulator)) { ret = PTR_ERR(ldo1->regulator); - dev_err(arizona->dev, "Failed to register LDO1 supply: %d\n", + dev_err(&pdev->dev, "Failed to register LDO1 supply: %d\n", ret); return ret; } @@ -323,6 +294,53 @@ static int arizona_ldo1_probe(struct platform_device *pdev) return 0; } +static int arizona_ldo1_probe(struct platform_device *pdev) +{ + struct arizona *arizona = dev_get_drvdata(pdev->dev.parent); + struct arizona_ldo1 *ldo1; + const struct regulator_desc *desc; + bool external_dcvdd; + int ret; + + ldo1 = devm_kzalloc(&pdev->dev, sizeof(*ldo1), GFP_KERNEL); + if (!ldo1) + return -ENOMEM; + + ldo1->regmap = arizona->regmap; + + /* + * Since the chip usually supplies itself we provide some + * default init_data for it. This will be overridden with + * platform data if provided. + */ + switch (arizona->type) { + case WM5102: + case WM8997: + case WM8998: + case WM1814: + desc = &arizona_ldo1_hc; + ldo1->init_data = arizona_ldo1_dvfs; + break; + case WM5110: + case WM8280: + desc = &arizona_ldo1; + ldo1->init_data = arizona_ldo1_wm5110; + break; + default: + desc = &arizona_ldo1; + ldo1->init_data = arizona_ldo1_default; + break; + } + + ret = arizona_ldo1_common_init(pdev, ldo1, desc, + &arizona->pdata.ldo1, + &external_dcvdd); + if (ret == 0) + arizona->external_dcvdd = external_dcvdd; + + return ret; +} + static struct platform_driver arizona_ldo1_driver = { .probe = arizona_ldo1_probe, .driver = {