From patchwork Wed Sep 21 18:20:43 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Francois Moine X-Patchwork-Id: 9347635 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 A884D601C2 for ; Fri, 23 Sep 2016 07:51:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9976A29F38 for ; Fri, 23 Sep 2016 07:51:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8E5D92A221; Fri, 23 Sep 2016 07:51:09 +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=-2.9 required=2.0 tests=BAYES_00, DATE_IN_PAST_24_48, FREEMAIL_FROM,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 348EE29F38 for ; Fri, 23 Sep 2016 07:51:09 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bnLF9-0004S1-G4; Fri, 23 Sep 2016 07:49:59 +0000 Received: from smtp2-g21.free.fr ([2a01:e0c:1:1599::11]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bnLEa-0004JI-EL for linux-arm-kernel@lists.infradead.org; Fri, 23 Sep 2016 07:49:25 +0000 Received: from localhost (unknown [37.161.93.240]) by smtp2-g21.free.fr (Postfix) with ESMTP id 47C87200388; Fri, 23 Sep 2016 09:49:00 +0200 (CEST) X-Mailbox-Line: From d3078ed4eefd4de48e4b5666a64f6123f8d72483 Mon Sep 17 00:00:00 2001 Message-Id: In-Reply-To: References: From: Jean-Francois Moine Date: Wed, 21 Sep 2016 20:20:43 +0200 Subject: [PATCH 3/3] regulator: axp20x: simplify device access To: Chen-Yu Tsai , Mark Rutland , Rob Herring X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160923_004924_857241_A1CAA280 X-CRM114-Status: GOOD ( 13.39 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, linux-sunxi@googlegroups.com, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Use the pointer to the main regulator device instead of the pointer to the child platform device. Signed-off-by: Jean-Francois Moine --- drivers/regulator/axp20x-regulator.c | 45 ++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/drivers/regulator/axp20x-regulator.c b/drivers/regulator/axp20x-regulator.c index 7405f5b..244ddc3 100644 --- a/drivers/regulator/axp20x-regulator.c +++ b/drivers/regulator/axp20x-regulator.c @@ -347,9 +347,9 @@ static const struct regulator_desc axp809_regulators[] = { AXP_DESC_SW(AXP809, SW, "sw", "swin", AXP22X_PWR_OUT_CTRL2, BIT(6)), }; -static int axp20x_set_dcdc_freq(struct platform_device *pdev, u32 dcdcfreq) +static int axp20x_set_dcdc_freq(struct device *dev, u32 dcdcfreq) { - struct axp20x_dev *axp20x = dev_get_drvdata(pdev->dev.parent); + struct axp20x_dev *axp20x = dev_get_drvdata(dev); unsigned int reg = AXP20X_DCDC_FREQ; u32 min, max, def, step; @@ -378,7 +378,7 @@ static int axp20x_set_dcdc_freq(struct platform_device *pdev, u32 dcdcfreq) step = 150; break; default: - dev_err(&pdev->dev, + dev_err(dev, "Setting DCDC frequency for unsupported AXP variant\n"); return -EINVAL; } @@ -388,13 +388,13 @@ static int axp20x_set_dcdc_freq(struct platform_device *pdev, u32 dcdcfreq) if (dcdcfreq < min) { dcdcfreq = min; - dev_warn(&pdev->dev, "DCDC frequency too low. Set to %ukHz\n", + dev_warn(dev, "DCDC frequency too low. Set to %ukHz\n", min); } if (dcdcfreq > max) { dcdcfreq = max; - dev_warn(&pdev->dev, "DCDC frequency too high. Set to %ukHz\n", + dev_warn(dev, "DCDC frequency too high. Set to %ukHz\n", max); } @@ -404,24 +404,24 @@ static int axp20x_set_dcdc_freq(struct platform_device *pdev, u32 dcdcfreq) AXP20X_FREQ_DCDC_MASK, dcdcfreq); } -static int axp20x_regulator_parse_dt(struct platform_device *pdev) +static int axp20x_regulator_parse_dt(struct device *dev) { struct device_node *np, *regulators; int ret; u32 dcdcfreq = 0; - np = of_node_get(pdev->dev.parent->of_node); + np = of_node_get(dev->of_node); if (!np) return 0; regulators = of_get_child_by_name(np, "regulators"); if (!regulators) { - dev_warn(&pdev->dev, "regulators node not found\n"); + dev_warn(dev, "regulators node not found\n"); } else { of_property_read_u32(regulators, "x-powers,dcdc-freq", &dcdcfreq); - ret = axp20x_set_dcdc_freq(pdev, dcdcfreq); + ret = axp20x_set_dcdc_freq(dev, dcdcfreq); if (ret < 0) { - dev_err(&pdev->dev, "Error setting dcdc frequency: %d\n", ret); + dev_err(dev, "Error setting dcdc frequency: %d\n", ret); return ret; } @@ -499,11 +499,12 @@ static u32 axp20x_polyphase_slave(struct axp20x_dev *axp20x) static int axp20x_regulator_probe(struct platform_device *pdev) { + struct device *dev = pdev->dev.parent; struct regulator_dev *rdev; - struct axp20x_dev *axp20x = dev_get_drvdata(pdev->dev.parent); + struct axp20x_dev *axp20x = dev_get_drvdata(dev); const struct regulator_desc *regulators; struct regulator_config config = { - .dev = pdev->dev.parent, + .dev = dev, .regmap = axp20x->regmap, .driver_data = axp20x, }; @@ -532,7 +533,7 @@ static int axp20x_regulator_probe(struct platform_device *pdev) dcdc5_ix = AXP22X_DCDC5; dc1sw_ix = AXP22X_DC1SW; dc5ldo_ix = AXP22X_DC5LDO; - drivevbus = of_property_read_bool(pdev->dev.parent->of_node, + drivevbus = of_property_read_bool(dev->of_node, "x-powers,drive-vbus-en"); break; case AXP806_ID: @@ -555,13 +556,13 @@ static int axp20x_regulator_probe(struct platform_device *pdev) dc5ldo_ix = AXP809_DC5LDO; break; default: - dev_err(&pdev->dev, "Unsupported AXP variant: %ld\n", + dev_err(dev, "Unsupported AXP variant: %ld\n", axp20x->variant); return -EINVAL; } /* This only sets the dcdc freq. Ignore any errors */ - axp20x_regulator_parse_dt(pdev); + axp20x_regulator_parse_dt(dev); for (i = 0; i < nregulators; i++) { const struct regulator_desc *desc = ®ulators[i]; @@ -580,7 +581,7 @@ static int axp20x_regulator_probe(struct platform_device *pdev) * name. */ if (i == dc1sw_ix && dcdc1_name) { - new_desc = devm_kzalloc(&pdev->dev, sizeof(*desc), + new_desc = devm_kzalloc(dev, sizeof(*desc), GFP_KERNEL); *new_desc = regulators[i]; new_desc->supply_name = dcdc1_name; @@ -588,16 +589,16 @@ static int axp20x_regulator_probe(struct platform_device *pdev) } if (i == dc5ldo_ix && dcdc5_name) { - new_desc = devm_kzalloc(&pdev->dev, sizeof(*desc), + new_desc = devm_kzalloc(dev, sizeof(*desc), GFP_KERNEL); *new_desc = regulators[i]; new_desc->supply_name = dcdc5_name; desc = new_desc; } - rdev = devm_regulator_register(&pdev->dev, desc, &config); + rdev = devm_regulator_register(dev, desc, &config); if (IS_ERR(rdev)) { - dev_err(&pdev->dev, "Failed to register %s\n", + dev_err(dev, "Failed to register %s\n", regulators[i].name); return PTR_ERR(rdev); @@ -608,7 +609,7 @@ static int axp20x_regulator_probe(struct platform_device *pdev) &workmode); if (!ret) { if (axp20x_set_dcdc_workmode(rdev, i, workmode)) - dev_err(&pdev->dev, "Failed to set workmode on %s\n", + dev_err(dev, "Failed to set workmode on %s\n", rdev->desc->name); } @@ -630,11 +631,11 @@ static int axp20x_regulator_probe(struct platform_device *pdev) /* Change N_VBUSEN sense pin to DRIVEVBUS output pin */ regmap_update_bits(axp20x->regmap, AXP20X_OVER_TMP, AXP22X_MISC_N_VBUSEN_FUNC, 0); - rdev = devm_regulator_register(&pdev->dev, + rdev = devm_regulator_register(dev, &axp22x_drivevbus_regulator, &config); if (IS_ERR(rdev)) { - dev_err(&pdev->dev, "Failed to register drivevbus\n"); + dev_err(dev, "Failed to register drivevbus\n"); return PTR_ERR(rdev); } }