From patchwork Wed Jun 10 07:57:50 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 49677 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f72.google.com (mail-wg0-f72.google.com [74.125.82.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id CEB1C20C81 for ; Wed, 10 Jun 2015 07:58:39 +0000 (UTC) Received: by wgla2 with SMTP id a2sf10068686wgl.1 for ; Wed, 10 Jun 2015 00:58:39 -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=ZXhdNm2IWCb49Ifc09z/TUSuXKYaAdHQSr6396cHmIs=; b=Gk9s/1dxfG6Ltd2jNCm2lZGpjA1V+PFOUYS1686wA558UGK8Kl2IS0ZEMnCaqeXJZi PU3xd4O47aS88QecumiGMDQ/toh2xdFfVKRC3upE2RdLIJ7j17+OJvuVFiw4dnwUzJoP EPLxpnCpP+VATDGE5lCA4ngSSgy6LGPn2jEzQpFN2QCZYcj9//hoK7tDbSLYRcM0CEjp aXhvehqh+NUu/7JORlP/Mqy7g7QXg7QMhBTU/Amd+5U2d1DUML10dhovX7YXrkgi/BzR g6E6wJSgzALWxfqcIK7ZgEGljP8QOE3v/O5j/AM5eeE6Pbn8i9b8Q4GUvah6gRsOoJjg +lkw== X-Gm-Message-State: ALoCoQkSYzY3rqB1VmIou5mZIelUfoqbr9ci4zeToqgc2TVh54VpaNEAaPuXFWgi1QG4W8wBzAWW X-Received: by 10.152.37.101 with SMTP id x5mr1846922laj.5.1433923118958; Wed, 10 Jun 2015 00:58:38 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.36.227 with SMTP id t3ls188697laj.72.gmail; Wed, 10 Jun 2015 00:58:38 -0700 (PDT) X-Received: by 10.112.9.104 with SMTP id y8mr1864825lba.49.1433923118779; Wed, 10 Jun 2015 00:58:38 -0700 (PDT) Received: from mail-la0-f43.google.com (mail-la0-f43.google.com. [209.85.215.43]) by mx.google.com with ESMTPS id xd3si8050651lbb.166.2015.06.10.00.58.38 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 10 Jun 2015 00:58:38 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.43 as permitted sender) client-ip=209.85.215.43; Received: by labpy14 with SMTP id py14so27375066lab.0 for ; Wed, 10 Jun 2015 00:58:38 -0700 (PDT) X-Received: by 10.152.37.228 with SMTP id b4mr1872529lak.117.1433923118660; Wed, 10 Jun 2015 00:58:38 -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 hn6csp3155848lbb; Wed, 10 Jun 2015 00:58:37 -0700 (PDT) X-Received: by 10.68.57.164 with SMTP id j4mr3533988pbq.63.1433923115247; Wed, 10 Jun 2015 00:58:35 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id uv9si12654887pac.126.2015.06.10.00.58.34; Wed, 10 Jun 2015 00:58:35 -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 S964824AbbFJH6a (ORCPT + 28 others); Wed, 10 Jun 2015 03:58:30 -0400 Received: from mail-wi0-f174.google.com ([209.85.212.174]:34378 "EHLO mail-wi0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933212AbbFJH6E (ORCPT ); Wed, 10 Jun 2015 03:58:04 -0400 Received: by wibut5 with SMTP id ut5so39646102wib.1 for ; Wed, 10 Jun 2015 00:58:02 -0700 (PDT) X-Received: by 10.180.206.211 with SMTP id lq19mr16681415wic.81.1433923082433; Wed, 10 Jun 2015 00:58:02 -0700 (PDT) Received: from localhost.localdomain (host81-129-170-231.range81-129.btcentralplus.com. [81.129.170.231]) by mx.google.com with ESMTPSA id c3sm13135187wja.3.2015.06.10.00.58.00 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 10 Jun 2015 00:58:01 -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: [REBASED 2/5] regulator: pwm-regulator: Separate voltage-table initialisation Date: Wed, 10 Jun 2015 08:57:50 +0100 Message-Id: <1433923073-907-3-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1433923073-907-1-git-send-email-lee.jones@linaro.org> References: <1433923073-907-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.43 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/mfd/mfd-child.c | 47 ++++++++++++++++++++++++ drivers/regulator/pwm-regulator.c | 77 +++++++++++++++++++++++---------------- 2 files changed, 92 insertions(+), 32 deletions(-) create mode 100644 drivers/mfd/mfd-child.c diff --git a/drivers/mfd/mfd-child.c b/drivers/mfd/mfd-child.c new file mode 100644 index 0000000..f233add --- /dev/null +++ b/drivers/mfd/mfd-child.c @@ -0,0 +1,47 @@ +#include +#include +#include +#include + +static int simple_mfd_child_probe(struct platform_device *pdev) +{ + struct resource *res; + void __iomem *base; + int irq; + + printk("LEE: %s %s()[%d]: Enter\n", __FILE__, __func__, __LINE__); + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + dev_err(&pdev->dev, "Phys: %x: %x\n", res->start, resource_size(res)); + + base = devm_ioremap_resource(&pdev->dev, res); + if (IS_ERR(base)) + return PTR_ERR(base); + + dev_err(&pdev->dev, "Virt: %p\n", base); + + irq = platform_get_irq(pdev, 0); + if (irq < 0) { + dev_err(&pdev->dev, "failed to get IRQ: %d\n", irq); + return irq; + } + + dev_err(&pdev->dev, "IRQ: %d\n", irq); + + return 0; +} + +static const struct of_device_id simple_mfd_child_of_match[] = { + { .compatible = "simple-mfd-child" }, + { } +}; +MODULE_DEVICE_TABLE(of, simple_mfd_child_of_match); + +static struct platform_driver simple_mfd_child_driver = { + .probe = simple_mfd_child_probe, + .driver = { + .name = "simple-mfd-child", + .of_match_table = of_match_ptr(simple_mfd_child_of_match), + }, +}; +module_platform_driver(simple_mfd_child_driver); 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)