From patchwork Thu Jul 16 18:16:56 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vaibhav Hiremath X-Patchwork-Id: 51197 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f197.google.com (mail-wi0-f197.google.com [209.85.212.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 97F1D22A8A for ; Thu, 16 Jul 2015 18:20:16 +0000 (UTC) Received: by widic2 with SMTP id ic2sf6476337wid.1 for ; Thu, 16 Jul 2015 11:20:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=ZK54MmsG5womT/4lCqkprRu+tD6cATgguTiEeW8elCY=; b=kFksKyaByFxRsl4YwWZdt/UuaC07GvHyKyf68gNlO+a5TecfnA2wh3fX2JIKfKk6rq iOLEBb6sYCk6pfUrZDwqOUj1itdkM4WdzdnmUH0Bv6X1Y6N+b4J01NJlDbOt9Abdrmva GgIb1WkVTlI5Vf2kADgVxOx/fbLPTDxEe7M+q1thx6DRE/MCr/NVWQFJc5e7duu4VqRx 1FFLX0CzMQDrxXxTorLkRscxoPMcQwgvpITRgSTfElc44OS115ugqPr5v2ZAu32zhORh NT1LF27w0pmlGQ59e6h0a7WIQmPfZNiuUzWJnfVd4vv+ZJzgNIt4V2ypbiM4nSBz1XPk ApQQ== X-Gm-Message-State: ALoCoQku2jmwsOxBDeW+l878awWmA1iJPJ+0m6EkB0qpSu87cE+vTRdWgdbJUhnVbdrz/ulAEV6M X-Received: by 10.152.8.110 with SMTP id q14mr5441454laa.3.1437070815897; Thu, 16 Jul 2015 11:20:15 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.153.5.9 with SMTP id ci9ls428552lad.69.gmail; Thu, 16 Jul 2015 11:20:15 -0700 (PDT) X-Received: by 10.112.129.131 with SMTP id nw3mr10799248lbb.34.1437070815718; Thu, 16 Jul 2015 11:20:15 -0700 (PDT) Received: from mail-la0-f51.google.com (mail-la0-f51.google.com. [209.85.215.51]) by mx.google.com with ESMTPS id l9si2164037laf.134.2015.07.16.11.20.15 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 Jul 2015 11:20:15 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.51 as permitted sender) client-ip=209.85.215.51; Received: by laem6 with SMTP id m6so48420729lae.0 for ; Thu, 16 Jul 2015 11:20:15 -0700 (PDT) X-Received: by 10.112.209.106 with SMTP id ml10mr10426674lbc.112.1437070815432; Thu, 16 Jul 2015 11:20:15 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.108.230 with SMTP id hn6csp422195lbb; Thu, 16 Jul 2015 11:20:14 -0700 (PDT) X-Received: by 10.70.40.164 with SMTP id y4mr21319745pdk.25.1437070813336; Thu, 16 Jul 2015 11:20:13 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v2si902426pbz.201.2015.07.16.11.20.12; Thu, 16 Jul 2015 11:20:13 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756005AbbGPSTs (ORCPT + 28 others); Thu, 16 Jul 2015 14:19:48 -0400 Received: from mail-pd0-f172.google.com ([209.85.192.172]:35881 "EHLO mail-pd0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753154AbbGPSTq (ORCPT ); Thu, 16 Jul 2015 14:19:46 -0400 Received: by pdjr16 with SMTP id r16so48407370pdj.3 for ; Thu, 16 Jul 2015 11:19:46 -0700 (PDT) X-Received: by 10.68.197.102 with SMTP id it6mr21394438pbc.65.1437070786055; Thu, 16 Jul 2015 11:19:46 -0700 (PDT) Received: from localhost.localdomain ([202.62.77.106]) by smtp.gmail.com with ESMTPSA id k5sm8679182pda.34.2015.07.16.11.19.42 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 16 Jul 2015 11:19:45 -0700 (PDT) From: Vaibhav Hiremath To: linux-arm-kernel@lists.infradead.org Cc: broonie@kernel.org, lgirdwood@gmail.com, sameo@linux.intel.com, lee.jones@linaro.org, linux-kernel@vger.kernel.org, Vaibhav Hiremath Subject: [PATCH 3/5] regulator: 88pm800: Use regulator_nodes/of_match in the descriptor Date: Thu, 16 Jul 2015 23:46:56 +0530 Message-Id: <1437070618-21330-4-git-send-email-vaibhav.hiremath@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1437070618-21330-1-git-send-email-vaibhav.hiremath@linaro.org> References: <1437070618-21330-1-git-send-email-vaibhav.hiremath@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: vaibhav.hiremath@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.51 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , This patch is add regulator_nodes/of_match in the regulator descriptor for using information from DT instead of specific codes. With this patch, driver gets simplified, - No need to maintain "struct of_regulator_match" table and call of_regulator_match() fn. - No need for pm800_regulator_dt_init() fn, as it was only used for of_regulator_match(). - probe() fn got simplified around regulator_config and regulator_desc initialization. Signed-off-by: Vaibhav Hiremath --- drivers/regulator/88pm800.c | 143 ++++++++++++++------------------------------ 1 file changed, 44 insertions(+), 99 deletions(-) diff --git a/drivers/regulator/88pm800.c b/drivers/regulator/88pm800.c index 3b37170..26c277f 100644 --- a/drivers/regulator/88pm800.c +++ b/drivers/regulator/88pm800.c @@ -91,10 +91,12 @@ struct pm800_regulators { * not the constant voltage table. * n_volt - Number of available selectors */ -#define PM800_BUCK(vreg, ereg, ebit, amax, volt_ranges, n_volt) \ +#define PM800_BUCK(match, vreg, ereg, ebit, amax, volt_ranges, n_volt) \ { \ .desc = { \ .name = #vreg, \ + .of_match = of_match_ptr(#match), \ + .regulators_node = of_match_ptr("regulators"), \ .ops = &pm800_volt_range_ops, \ .type = REGULATOR_VOLTAGE, \ .id = PM800_ID_##vreg, \ @@ -119,10 +121,12 @@ struct pm800_regulators { * For all the LDOes, there are too many ranges. Using volt_table will be * simpler and faster. */ -#define PM800_LDO(vreg, ereg, ebit, amax, ldo_volt_table) \ +#define PM800_LDO(match, vreg, ereg, ebit, amax, ldo_volt_table) \ { \ .desc = { \ .name = #vreg, \ + .of_match = of_match_ptr(#match), \ + .regulators_node = of_match_ptr("regulators"), \ .ops = &pm800_volt_table_ops, \ .type = REGULATOR_VOLTAGE, \ .id = PM800_ID_##vreg, \ @@ -200,99 +204,43 @@ static struct regulator_ops pm800_volt_table_ops = { /* The array is indexed by id(PM800_ID_XXX) */ static struct pm800_regulator_info pm800_regulator_info[] = { - PM800_BUCK(BUCK1, BUCK_ENA, 0, 3000000, buck1_volt_range, 0x55), - PM800_BUCK(BUCK2, BUCK_ENA, 1, 1200000, buck2_5_volt_range, 0x73), - PM800_BUCK(BUCK3, BUCK_ENA, 2, 1200000, buck2_5_volt_range, 0x73), - PM800_BUCK(BUCK4, BUCK_ENA, 3, 1200000, buck2_5_volt_range, 0x73), - PM800_BUCK(BUCK5, BUCK_ENA, 4, 1200000, buck2_5_volt_range, 0x73), - - PM800_LDO(LDO1, LDO_ENA1_1, 0, 200000, ldo1_volt_table), - PM800_LDO(LDO2, LDO_ENA1_1, 1, 10000, ldo2_volt_table), - PM800_LDO(LDO3, LDO_ENA1_1, 2, 300000, ldo3_17_volt_table), - PM800_LDO(LDO4, LDO_ENA1_1, 3, 300000, ldo3_17_volt_table), - PM800_LDO(LDO5, LDO_ENA1_1, 4, 300000, ldo3_17_volt_table), - PM800_LDO(LDO6, LDO_ENA1_1, 5, 300000, ldo3_17_volt_table), - PM800_LDO(LDO7, LDO_ENA1_1, 6, 300000, ldo3_17_volt_table), - PM800_LDO(LDO8, LDO_ENA1_1, 7, 300000, ldo3_17_volt_table), - PM800_LDO(LDO9, LDO_ENA1_2, 0, 300000, ldo3_17_volt_table), - PM800_LDO(LDO10, LDO_ENA1_2, 1, 300000, ldo3_17_volt_table), - PM800_LDO(LDO11, LDO_ENA1_2, 2, 300000, ldo3_17_volt_table), - PM800_LDO(LDO12, LDO_ENA1_2, 3, 300000, ldo3_17_volt_table), - PM800_LDO(LDO13, LDO_ENA1_2, 4, 300000, ldo3_17_volt_table), - PM800_LDO(LDO14, LDO_ENA1_2, 5, 300000, ldo3_17_volt_table), - PM800_LDO(LDO15, LDO_ENA1_2, 6, 300000, ldo3_17_volt_table), - PM800_LDO(LDO16, LDO_ENA1_2, 7, 300000, ldo3_17_volt_table), - PM800_LDO(LDO17, LDO_ENA1_3, 0, 300000, ldo3_17_volt_table), - PM800_LDO(LDO18, LDO_ENA1_3, 1, 200000, ldo18_19_volt_table), - PM800_LDO(LDO19, LDO_ENA1_3, 2, 200000, ldo18_19_volt_table), + PM800_BUCK(buck1, BUCK1, BUCK_ENA, 0, 3000000, buck1_volt_range, 0x55), + PM800_BUCK(buck2, BUCK2, BUCK_ENA, 1, 1200000, buck2_5_volt_range, 0x73), + PM800_BUCK(buck3, BUCK3, BUCK_ENA, 2, 1200000, buck2_5_volt_range, 0x73), + PM800_BUCK(buck4, BUCK4, BUCK_ENA, 3, 1200000, buck2_5_volt_range, 0x73), + PM800_BUCK(buck5, BUCK5, BUCK_ENA, 4, 1200000, buck2_5_volt_range, 0x73), + + PM800_LDO(ldo1, LDO1, LDO_ENA1_1, 0, 200000, ldo1_volt_table), + PM800_LDO(ldo2, LDO2, LDO_ENA1_1, 1, 10000, ldo2_volt_table), + PM800_LDO(ldo3, LDO3, LDO_ENA1_1, 2, 300000, ldo3_17_volt_table), + PM800_LDO(ldo4, LDO4, LDO_ENA1_1, 3, 300000, ldo3_17_volt_table), + PM800_LDO(ldo5, LDO5, LDO_ENA1_1, 4, 300000, ldo3_17_volt_table), + PM800_LDO(ldo6, LDO6, LDO_ENA1_1, 5, 300000, ldo3_17_volt_table), + PM800_LDO(ldo7, LDO7, LDO_ENA1_1, 6, 300000, ldo3_17_volt_table), + PM800_LDO(ldo8, LDO8, LDO_ENA1_1, 7, 300000, ldo3_17_volt_table), + PM800_LDO(ldo9, LDO9, LDO_ENA1_2, 0, 300000, ldo3_17_volt_table), + PM800_LDO(ldo10, LDO10, LDO_ENA1_2, 1, 300000, ldo3_17_volt_table), + PM800_LDO(ldo11, LDO11, LDO_ENA1_2, 2, 300000, ldo3_17_volt_table), + PM800_LDO(ldo12, LDO12, LDO_ENA1_2, 3, 300000, ldo3_17_volt_table), + PM800_LDO(ldo13, LDO13, LDO_ENA1_2, 4, 300000, ldo3_17_volt_table), + PM800_LDO(ldo14, LDO14, LDO_ENA1_2, 5, 300000, ldo3_17_volt_table), + PM800_LDO(ldo15, LDO15, LDO_ENA1_2, 6, 300000, ldo3_17_volt_table), + PM800_LDO(ldo16, LDO16, LDO_ENA1_2, 7, 300000, ldo3_17_volt_table), + PM800_LDO(ldo17, LDO17, LDO_ENA1_3, 0, 300000, ldo3_17_volt_table), + PM800_LDO(ldo18, LDO18, LDO_ENA1_3, 1, 200000, ldo18_19_volt_table), + PM800_LDO(ldo19, LDO19, LDO_ENA1_3, 2, 200000, ldo18_19_volt_table), }; -#define PM800_REGULATOR_OF_MATCH(_name, _id) \ - [PM800_ID_##_id] = { \ - .name = #_name, \ - .driver_data = &pm800_regulator_info[PM800_ID_##_id], \ - } - -static struct of_regulator_match pm800_regulator_matches[] = { - PM800_REGULATOR_OF_MATCH(buck1, BUCK1), - PM800_REGULATOR_OF_MATCH(buck2, BUCK2), - PM800_REGULATOR_OF_MATCH(buck3, BUCK3), - PM800_REGULATOR_OF_MATCH(buck4, BUCK4), - PM800_REGULATOR_OF_MATCH(buck5, BUCK5), - PM800_REGULATOR_OF_MATCH(ldo1, LDO1), - PM800_REGULATOR_OF_MATCH(ldo2, LDO2), - PM800_REGULATOR_OF_MATCH(ldo3, LDO3), - PM800_REGULATOR_OF_MATCH(ldo4, LDO4), - PM800_REGULATOR_OF_MATCH(ldo5, LDO5), - PM800_REGULATOR_OF_MATCH(ldo6, LDO6), - PM800_REGULATOR_OF_MATCH(ldo7, LDO7), - PM800_REGULATOR_OF_MATCH(ldo8, LDO8), - PM800_REGULATOR_OF_MATCH(ldo9, LDO9), - PM800_REGULATOR_OF_MATCH(ldo10, LDO10), - PM800_REGULATOR_OF_MATCH(ldo11, LDO11), - PM800_REGULATOR_OF_MATCH(ldo12, LDO12), - PM800_REGULATOR_OF_MATCH(ldo13, LDO13), - PM800_REGULATOR_OF_MATCH(ldo14, LDO14), - PM800_REGULATOR_OF_MATCH(ldo15, LDO15), - PM800_REGULATOR_OF_MATCH(ldo16, LDO16), - PM800_REGULATOR_OF_MATCH(ldo17, LDO17), - PM800_REGULATOR_OF_MATCH(ldo18, LDO18), - PM800_REGULATOR_OF_MATCH(ldo19, LDO19), -}; - -static int pm800_regulator_dt_init(struct platform_device *pdev) -{ - struct device_node *np = pdev->dev.of_node; - int ret; - - ret = of_regulator_match(&pdev->dev, np, - pm800_regulator_matches, - ARRAY_SIZE(pm800_regulator_matches)); - if (ret < 0) - return ret; - - return 0; -} - static int pm800_regulator_probe(struct platform_device *pdev) { struct pm80x_chip *chip = dev_get_drvdata(pdev->dev.parent); struct pm80x_platform_data *pdata = dev_get_platdata(pdev->dev.parent); struct pm800_regulators *pm800_data; - struct pm800_regulator_info *info; struct regulator_config config = { }; struct regulator_init_data *init_data; int i, ret; - if (!pdata || pdata->num_regulators == 0) { - if (IS_ENABLED(CONFIG_OF)) { - ret = pm800_regulator_dt_init(pdev); - if (ret) - return ret; - } else { - return -ENODEV; - } - } else if (pdata->num_regulators) { + if (pdata && pdata->num_regulators) { unsigned int count = 0; /* Check whether num_regulator is valid. */ @@ -302,8 +250,6 @@ static int pm800_regulator_probe(struct platform_device *pdev) } if (count != pdata->num_regulators) return -EINVAL; - } else { - return -EINVAL; } pm800_data = devm_kzalloc(&pdev->dev, sizeof(*pm800_data), @@ -316,28 +262,27 @@ static int pm800_regulator_probe(struct platform_device *pdev) platform_set_drvdata(pdev, pm800_data); + config.dev = chip->dev; + config.regmap = pm800_data->map; for (i = 0; i < PM800_ID_RG_MAX; i++) { struct regulator_dev *regulator; - if (!pdata || pdata->num_regulators == 0) - init_data = pm800_regulator_matches[i].init_data; - else + if (pdata && pdata->num_regulators) { init_data = pdata->regulators[i]; - if (!init_data) - continue; - info = pm800_regulator_matches[i].driver_data; - config.dev = &pdev->dev; - config.init_data = init_data; - config.driver_data = info; - config.regmap = pm800_data->map; - config.of_node = pm800_regulator_matches[i].of_node; + if (!init_data) + continue; + + config.init_data = init_data; + } + + config.driver_data = &pm800_regulator_info[i]; regulator = devm_regulator_register(&pdev->dev, - &info->desc, &config); + &pm800_regulator_info[i].desc, &config); if (IS_ERR(regulator)) { ret = PTR_ERR(regulator); dev_err(&pdev->dev, "Failed to register %s\n", - info->desc.name); + pm800_regulator_info[i].desc.name); return ret; } }