From patchwork Fri Jun 5 18:42:49 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 49594 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 416DE2462C for ; Fri, 5 Jun 2015 18:43:38 +0000 (UTC) Received: by wizw5 with SMTP id w5sf925051wiz.2 for ; Fri, 05 Jun 2015 11:43:37 -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=crfdlCsxAaAWufBivcr60DQTjIhbywDcqguIf3sNww0=; b=P7/n+h4Me6EmLwnCE0e+InazicMXJ8ecYx2jWBu9eTDX+1r+3SBhulIlKMf/QyBDge sLf9STl/DwKm8aoRefh0/qiPjbxKkhQpc/PwYVCHimTAc6RPYtjwhYhRBNXU3bSxBF7T NJMbmEK1KZmt6+K+P8cxo1DPUSdjeqOCJHXJ4tVTHZGeXRDRROSQSIz6M5syAoSXoJEP jIENBiiPKeE84dUPlwJ5VJhi4pidQ3yGMHvELM8/Fx0Xh41wHjCqVYp//Pdx4Y4kySha OYV4rM5wJov7MBBcfhChzn6Ms4ae8sy1rQcouaYJFbH59SrUVMgCuRXbCGDfACbubtQB hyrQ== X-Gm-Message-State: ALoCoQl3oN4Jb72zE21ZDJgYfL3hdZKyUbv9RqSJM8ZAn/lTNj9at1V0hfPFEdRRRh+xBI2Z/vNx X-Received: by 10.112.166.137 with SMTP id zg9mr4359548lbb.11.1433529817553; Fri, 05 Jun 2015 11:43:37 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.29.7 with SMTP id f7ls377695lah.48.gmail; Fri, 05 Jun 2015 11:43:37 -0700 (PDT) X-Received: by 10.112.158.200 with SMTP id ww8mr4709241lbb.31.1433529817315; Fri, 05 Jun 2015 11:43:37 -0700 (PDT) Received: from mail-la0-f52.google.com (mail-la0-f52.google.com. [209.85.215.52]) by mx.google.com with ESMTPS id wd2si5471010lbb.123.2015.06.05.11.43.37 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 05 Jun 2015 11:43:37 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.52 as permitted sender) client-ip=209.85.215.52; Received: by laew7 with SMTP id w7so60274782lae.1 for ; Fri, 05 Jun 2015 11:43:37 -0700 (PDT) X-Received: by 10.112.209.106 with SMTP id ml10mr400323lbc.112.1433529817209; Fri, 05 Jun 2015 11:43:37 -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 hn6csp70936lbb; Fri, 5 Jun 2015 11:43:36 -0700 (PDT) X-Received: by 10.70.37.167 with SMTP id z7mr8127825pdj.55.1433529813508; Fri, 05 Jun 2015 11:43:33 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bm1si11870432pbd.212.2015.06.05.11.43.32; Fri, 05 Jun 2015 11:43:33 -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 S932822AbbFESnU (ORCPT + 28 others); Fri, 5 Jun 2015 14:43:20 -0400 Received: from mail-wi0-f176.google.com ([209.85.212.176]:33529 "EHLO mail-wi0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754742AbbFESnN (ORCPT ); Fri, 5 Jun 2015 14:43:13 -0400 Received: by wiwd19 with SMTP id d19so29656798wiw.0 for ; Fri, 05 Jun 2015 11:43:11 -0700 (PDT) X-Received: by 10.180.105.227 with SMTP id gp3mr20695705wib.56.1433529791822; Fri, 05 Jun 2015 11:43:11 -0700 (PDT) Received: from localhost.localdomain ([213.205.253.199]) by mx.google.com with ESMTPSA id be3sm4473541wib.21.2015.06.05.11.43.09 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 05 Jun 2015 11:43:11 -0700 (PDT) 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, Lee Jones Subject: [PATCH 6/8] regulator: pwm-regulator: Separate voltage-table initialisation Date: Fri, 5 Jun 2015 19:42:49 +0100 Message-Id: <1433529771-24496-7-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1433529771-24496-1-git-send-email-lee.jones@linaro.org> References: <1433529771-24496-1-git-send-email-lee.jones@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: 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.215.52 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(-) diff --git a/drivers/regulator/pwm-regulator.c b/drivers/regulator/pwm-regulator.c index 779ecf9..5a18437 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,21 +87,56 @@ 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) { const struct regulator_init_data *init_data; 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"); @@ -113,36 +147,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; - } - init_data = of_get_regulator_init_data(&pdev->dev, np, &pwm_regulator_desc); if (init_data)