From patchwork Wed Jun 10 09:15:03 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 49683 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f199.google.com (mail-wi0-f199.google.com [209.85.212.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id D8AE1245D4 for ; Wed, 10 Jun 2015 09:15:22 +0000 (UTC) Received: by wifx6 with SMTP id x6sf10894269wif.1 for ; Wed, 10 Jun 2015 02:15:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:date:from:to:cc:subject:message-id :references:mime-version:content-type:content-disposition :in-reply-to:user-agent:sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=eMSjM2Yz/BzpnPLz/eFKULuh6xk0hvqGD0Tll6MEbVY=; b=QPH3MsBBldl3UlC7yOWsBKnjDYxzBiqY9o2Z2szOk2F64CT6N+ri2hWQaU0T6xuC88 IgEVLfSB3sKqAYEW3PuFMaNSJOasvtwVT8slVJeQoGY2TWDnFVEW9k/Y1h2cdf0293yu 0RFwChnUiTiv79A+XTdceZ3YQbkOAxCG9y+DGtLQvz7YCq6AluHrS7WCBc0HudBnBGVK YG2Rg5rELSKZPrRJX4TtPkmstP2S8HFAwrNOZvxZVykeDLhr00Qqz/UfTuSkwL2/cHvk svZSGITnuKJ7O20rO4DRzLlNe+E6ugRUATJ8dx3AXBMpBWy+Ujnga2R2B8py9SgZw1xj R6/w== X-Gm-Message-State: ALoCoQmJaRg3kqMZJrolc5pivMJ+AbQqw+kxtg452ybqOjwdGM6ZYB9HeuHNK0RvNpAM+K2xgD9I X-Received: by 10.181.11.197 with SMTP id ek5mr2985734wid.4.1433927722204; Wed, 10 Jun 2015 02:15:22 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.1.73 with SMTP id 9ls147052lak.17.gmail; Wed, 10 Jun 2015 02:15:22 -0700 (PDT) X-Received: by 10.112.41.196 with SMTP id h4mr2393185lbl.36.1433927722015; Wed, 10 Jun 2015 02:15:22 -0700 (PDT) Received: from mail-lb0-f180.google.com (mail-lb0-f180.google.com. [209.85.217.180]) by mx.google.com with ESMTPS id d9si8314767lad.19.2015.06.10.02.15.21 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 10 Jun 2015 02:15:21 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.180 as permitted sender) client-ip=209.85.217.180; Received: by lbbtu8 with SMTP id tu8so24852498lbb.2 for ; Wed, 10 Jun 2015 02:15:21 -0700 (PDT) X-Received: by 10.112.199.133 with SMTP id jk5mr2450279lbc.32.1433927721874; Wed, 10 Jun 2015 02:15:21 -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 hn6csp3198448lbb; Wed, 10 Jun 2015 02:15:20 -0700 (PDT) X-Received: by 10.68.224.35 with SMTP id qz3mr3975689pbc.165.1433927719992; Wed, 10 Jun 2015 02:15:19 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v9si13012904pdj.63.2015.06.10.02.15.19; Wed, 10 Jun 2015 02:15:19 -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 S1754213AbbFJJPN (ORCPT + 28 others); Wed, 10 Jun 2015 05:15:13 -0400 Received: from mail-wi0-f169.google.com ([209.85.212.169]:38419 "EHLO mail-wi0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752637AbbFJJPI (ORCPT ); Wed, 10 Jun 2015 05:15:08 -0400 Received: by wibdq8 with SMTP id dq8so40521546wib.1 for ; Wed, 10 Jun 2015 02:15:06 -0700 (PDT) X-Received: by 10.194.61.212 with SMTP id s20mr4365200wjr.18.1433927706742; Wed, 10 Jun 2015 02:15:06 -0700 (PDT) Received: from x1 (host81-129-170-231.range81-129.btcentralplus.com. [81.129.170.231]) by mx.google.com with ESMTPSA id n3sm6968751wix.1.2015.06.10.02.15.05 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 10 Jun 2015 02:15:05 -0700 (PDT) Date: Wed, 10 Jun 2015 10:15:03 +0100 From: Lee Jones To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: kernel@stlinux.com, broonie@kernel.org, lgirdwood@gmail.com, lw@karo-electronics.de Subject: [REBASED v1.1 2/5] regulator: pwm-regulator: Separate voltage-table initialisation Message-ID: <20150610091503.GC2982@x1> References: <1433923073-907-1-git-send-email-lee.jones@linaro.org> <1433923073-907-3-git-send-email-lee.jones@linaro.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1433923073-907-3-git-send-email-lee.jones@linaro.org> User-Agent: Mutt/1.5.21 (2010-09-15) 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: lee.jones@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.217.180 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: , Take this out of the main .probe() routine in order to facilitate the introduction of different ways to obtain 'duty cycle' information. Signed-off-by: Lee Jones --- drivers/regulator/pwm-regulator.c | 77 +++++++++++++++++++++++---------------- 1 file changed, 45 insertions(+), 32 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/ diff --git a/drivers/regulator/pwm-regulator.c b/drivers/regulator/pwm-regulator.c index ffa9612..25560fc 100644 --- a/drivers/regulator/pwm-regulator.c +++ b/drivers/regulator/pwm-regulator.c @@ -78,8 +78,7 @@ static int pwm_regulator_list_voltage(struct regulator_dev *rdev, return drvdata->duty_cycle_table[selector].uV; } - -static struct regulator_ops pwm_regulator_voltage_ops = { +static struct regulator_ops pwm_regulator_voltage_table_ops = { .set_voltage_sel = pwm_regulator_set_voltage_sel, .get_voltage_sel = pwm_regulator_get_voltage_sel, .list_voltage = pwm_regulator_list_voltage, @@ -88,20 +87,55 @@ static struct regulator_ops pwm_regulator_voltage_ops = { static struct regulator_desc pwm_regulator_desc = { .name = "pwm-regulator", - .ops = &pwm_regulator_voltage_ops, .type = REGULATOR_VOLTAGE, .owner = THIS_MODULE, .supply_name = "pwm", }; +static int pwm_regulator_init_table(struct platform_device *pdev, + struct pwm_regulator_data *drvdata) +{ + struct device_node *np = pdev->dev.of_node; + struct pwm_voltages *duty_cycle_table; + int length; + int ret; + + of_find_property(np, "voltage-table", &length); + + if ((length < sizeof(*duty_cycle_table)) || + (length % sizeof(*duty_cycle_table))) { + dev_err(&pdev->dev, + "voltage-table length(%d) is invalid\n", + length); + return -EINVAL; + } + + duty_cycle_table = devm_kzalloc(&pdev->dev, length, GFP_KERNEL); + if (!duty_cycle_table) + return -ENOMEM; + + ret = of_property_read_u32_array(np, "voltage-table", + (u32 *)duty_cycle_table, + length / sizeof(u32)); + if (ret) { + dev_err(&pdev->dev, "Failed to read voltage-table\n"); + return ret; + } + + drvdata->duty_cycle_table = duty_cycle_table; + pwm_regulator_desc.ops = &pwm_regulator_voltage_table_ops; + pwm_regulator_desc.n_voltages = length / sizeof(*duty_cycle_table); + + return 0; +} + static int pwm_regulator_probe(struct platform_device *pdev) { struct pwm_regulator_data *drvdata; - struct property *prop; struct regulator_dev *regulator; struct regulator_config config = { }; struct device_node *np = pdev->dev.of_node; - int length, ret; + int ret; if (!np) { dev_err(&pdev->dev, "Device Tree node missing\n"); @@ -112,36 +146,15 @@ static int pwm_regulator_probe(struct platform_device *pdev) if (!drvdata) return -ENOMEM; - /* determine the number of voltage-table */ - prop = of_find_property(np, "voltage-table", &length); - if (!prop) { - dev_err(&pdev->dev, "No voltage-table\n"); - return -EINVAL; - } - - if ((length < sizeof(*drvdata->duty_cycle_table)) || - (length % sizeof(*drvdata->duty_cycle_table))) { - dev_err(&pdev->dev, "voltage-table length(%d) is invalid\n", - length); + if (of_find_property(np, "voltage-table", NULL)) { + ret = pwm_regulator_init_table(pdev, drvdata); + if (ret) + return ret; + } else { + dev_err(&pdev->dev, "No \"voltage-table\" supplied\n"); return -EINVAL; } - pwm_regulator_desc.n_voltages = length / sizeof(*drvdata->duty_cycle_table); - - drvdata->duty_cycle_table = devm_kzalloc(&pdev->dev, - length, GFP_KERNEL); - if (!drvdata->duty_cycle_table) - return -ENOMEM; - - /* read voltage table from DT property */ - ret = of_property_read_u32_array(np, "voltage-table", - (u32 *)drvdata->duty_cycle_table, - length / sizeof(u32)); - if (ret < 0) { - dev_err(&pdev->dev, "read voltage-table failed\n"); - return ret; - } - config.init_data = of_get_regulator_init_data(&pdev->dev, np, &pwm_regulator_desc); if (!config.init_data)