Received: by 2002:ac0:8845:0:0:0:0:0 with SMTP id g63csp646006img; Thu, 28 Feb 2019 05:42:12 -0800 (PST) X-Google-Smtp-Source: AHgI3IbbQVqsiF+vgEB5WGc6slzV/oArKaU+poTxzOKV71KjFPmbfY13pCxF08D9sMphqAs3sI5a X-Received: by 2002:a63:cc05:: with SMTP id x5mr8460726pgf.31.1551361332901; Thu, 28 Feb 2019 05:42:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551361332; cv=none; d=google.com; s=arc-20160816; b=a3D/kdVq+FG4KGWDJXHmprx+LXU6b0MgiKK8YuaYHzZDXWcDaaQa/vi0y8pRvvw3Fp 8bPruVEmFW+4cRfbSlsKqASs39KqeQPeTOvfjYAx+76BrK8hLUy7YrovNvZcs5NjnY3L u9PSTMdJtcFgnM9QpzSU01mSsy5mBjXQ0nO6ffWF65Q42Usub8SMxbvXfc+4jwJJsq5m eQ+3I9bXNmKiuXWF50gVTqFGh+81RDun1MseU8hpJWd2GNHQEpB0u+JJtvVLbZ3GT6LJ UkeEt4vBDKmQIDfP6/GEDDfocl/DIci3ob1YSxEMn8MKN2HDrcwF+aUT/e+kMEd6bm+k L5TA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=Qbt1GrP2h2tIpdfGu6AGObhXiJawZKuHHC/4co7nvb4=; b=qcbz2j9A8o761BGMpxvYKDOCaDwmkw8ZGXZGvSnUZyxvJP7WDEqhAsmm6SjQkX5jj1 I/mO3r3EVaxoK3GRqSgtqpPBkPe9bFYLoy8GZjXqVN7KnR5jreMmhbBkI3gYRZpzITBK ZkKm0x26tE8mGBrtfE4sdDUF4nUSUV/RHbSxO7CK10zkEpmfiPUB+FWPAV21sSadl4E1 T3ZIZC+rRjj1qf5SontGdb/I3+v6jDODgou7V8a8FCWeW/dGKtLN326ce2qw1pPBBgvB UgaXMuzs4WvOoiXuyYDp8poGk8mVbm4gE8nffQ2bQx4wCSviuZsXZVboOr14jKbq787R OTDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ingics-com.20150623.gappssmtp.com header.s=20150623 header.b=Mal3AfZd; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d1si17331341pll.283.2019.02.28.05.41.57; Thu, 28 Feb 2019 05:42:12 -0800 (PST) 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; Authentication-Results: mx.google.com; dkim=pass header.i=@ingics-com.20150623.gappssmtp.com header.s=20150623 header.b=Mal3AfZd; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731781AbfB1NlQ (ORCPT + 99 others); Thu, 28 Feb 2019 08:41:16 -0500 Received: from mail-pf1-f193.google.com ([209.85.210.193]:46737 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725967AbfB1NlP (ORCPT ); Thu, 28 Feb 2019 08:41:15 -0500 Received: by mail-pf1-f193.google.com with SMTP id g6so9737756pfh.13 for ; Thu, 28 Feb 2019 05:41:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ingics-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Qbt1GrP2h2tIpdfGu6AGObhXiJawZKuHHC/4co7nvb4=; b=Mal3AfZdmdXYcpK2+OxGM+yIMr7NxxbCedjVmogId//dU1pxZw0yNrIkIb6SHV9fEd ESGw3AE6Pc9JHJd7nzchhfb+YXVYYxCGADusj78XW0jFyPE0lcU+fXJbpuZPq7DAND9I 9LWltcdmOJ0cRVqycaKgxXcI+SADs7Majt665jNEVDh5yFa/0d8m2jh1rjyUBXtOjGjm AwCSsJ0dh6gFGX6cSliNXp+6K930W3Oeg2qEUZnzBnd9WhHi4X3N5YLzZdUwkGA+Be0F mqUW46cE0RKHqaNMux2QfhEkelvwiqtyiq5fG1UiyY1udPbfrwiMTasAOMR9GaK4BfIY PJmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Qbt1GrP2h2tIpdfGu6AGObhXiJawZKuHHC/4co7nvb4=; b=Qs4qIFtdeTLPACG5CU9JR1nIyptmoyY3ZqAu0wEHALN0C2HBQXt33GXo2hAfoQlMpB RBzuzhmdSiMyiSCVRuEpzLWYUfws7S9mYuMl8k53VTzn46hQui6qfrP+OkI/S6j/XRh0 MKcZyV/3HRPmwbaQeXaJhIQiyFVVEsiCNRr08C6Alsjbc/qmx+C9Y3dyR3DNhGgjFYrw aZB6xbwRWfDBoe3dZmyPXFUj1S/eFtyYqbnPgNcEBX0gwpeSBNVpe9jiWr0GVeBhRgVu wU+u6/VtB2rUMq/JLZE3/ejQV7CB16oND/n5G6KsicWV63uEfdh0PznDh4MmIMNHyC0w fkEQ== X-Gm-Message-State: AHQUAuZuPYVcfKx39s3Hv9szBXsJvZlDnVn6M2b68m8zf+QsOVLaNriB rMRglxm7BMRIOr2QAXcrWG14jA== X-Received: by 2002:a65:4784:: with SMTP id e4mr8424129pgs.12.1551361274063; Thu, 28 Feb 2019 05:41:14 -0800 (PST) Received: from localhost.localdomain (2001-b400-e706-b6eb-8c00-6a08-1689-4d5a.emome-ip6.hinet.net. [2001:b400:e706:b6eb:8c00:6a08:1689:4d5a]) by smtp.gmail.com with ESMTPSA id 186sm36777133pga.36.2019.02.28.05.41.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Feb 2019 05:41:13 -0800 (PST) From: Axel Lin To: Mark Brown Cc: Support Opensource , patches@opensource.cirrus.com, Ashish Jangam , Steve Twiss , Paul Kocialkowski , Milo Kim , Keerthy , James Ban , Bartosz Golaszewski , Liam Girdwood , linux-kernel@vger.kernel.org, Axel Lin Subject: [PATCH 07/11] regulator: max77650: Convert to use regulator_set/get_current_limit_regmap Date: Thu, 28 Feb 2019 21:40:18 +0800 Message-Id: <20190228134022.32625-8-axel.lin@ingics.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190228134022.32625-1-axel.lin@ingics.com> References: <20190228134022.32625-1-axel.lin@ingics.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Use regulator_set/get_current_limit_regmap helpers to save some code. Signed-off-by: Axel Lin --- drivers/regulator/max77650-regulator.c | 74 +++++++++----------------- 1 file changed, 25 insertions(+), 49 deletions(-) diff --git a/drivers/regulator/max77650-regulator.c b/drivers/regulator/max77650-regulator.c index a1af414db751..31ebf34b01ec 100644 --- a/drivers/regulator/max77650-regulator.c +++ b/drivers/regulator/max77650-regulator.c @@ -26,9 +26,6 @@ #define MAX77650_REGULATOR_AD_ENABLED BIT(3) #define MAX77650_REGULATOR_CURR_LIM_MASK GENMASK(7, 6) -#define MAX77650_REGULATOR_CURR_LIM_BITS(_reg) \ - (((_reg) & MAX77650_REGULATOR_CURR_LIM_MASK) >> 6) -#define MAX77650_REGULATOR_CURR_LIM_SHIFT(_val) ((_val) << 6) enum { MAX77650_REGULATOR_ID_LDO = 0, @@ -82,7 +79,7 @@ static const u32 max77651_sbb1_regulator_volt_table[] = { _val = MAX77651_REGULATOR_SBB1_SEL_ENC(_val); \ } while (0) -static const int max77650_current_limit_table[] = { +static const unsigned int max77650_current_limit_table[] = { 1000000, 866000, 707000, 500000, }; @@ -220,47 +217,6 @@ static int max77651_regulator_sbb1_set_voltage_sel(struct regulator_dev *rdev, return 0; } -static int max77650_regulator_get_current_limit(struct regulator_dev *rdev) -{ - struct max77650_regulator_desc *rdesc; - struct regmap *map; - int val, rv, limit; - - rdesc = rdev_get_drvdata(rdev); - map = rdev_get_regmap(rdev); - - rv = regmap_read(map, rdesc->regA, &val); - if (rv) - return rv; - - limit = MAX77650_REGULATOR_CURR_LIM_BITS(val); - - return max77650_current_limit_table[limit]; -} - -static int max77650_regulator_set_current_limit(struct regulator_dev *rdev, - int min_uA, int max_uA) -{ - struct max77650_regulator_desc *rdesc; - struct regmap *map; - int i, limit; - - rdesc = rdev_get_drvdata(rdev); - map = rdev_get_regmap(rdev); - - for (i = 0; i < ARRAY_SIZE(max77650_current_limit_table); i++) { - limit = max77650_current_limit_table[i]; - - if (limit >= min_uA && limit <= max_uA) { - return regmap_update_bits(map, rdesc->regA, - MAX77650_REGULATOR_CURR_LIM_MASK, - MAX77650_REGULATOR_CURR_LIM_SHIFT(i)); - } - } - - return -EINVAL; -} - static const struct regulator_ops max77650_regulator_LDO_ops = { .is_enabled = max77650_regulator_is_enabled, .enable = max77650_regulator_enable, @@ -280,8 +236,8 @@ static const struct regulator_ops max77650_regulator_SBB_ops = { .map_voltage = regulator_map_voltage_linear, .get_voltage_sel = regulator_get_voltage_sel_regmap, .set_voltage_sel = max77650_regulator_set_voltage_sel, - .get_current_limit = max77650_regulator_get_current_limit, - .set_current_limit = max77650_regulator_set_current_limit, + .get_current_limit = regulator_get_current_limit_regmap, + .set_current_limit = regulator_set_current_limit_regmap, .set_active_discharge = regulator_set_active_discharge_regmap, }; @@ -293,8 +249,8 @@ static const struct regulator_ops max77651_SBB1_regulator_ops = { .list_voltage = regulator_list_voltage_table, .get_voltage_sel = regulator_get_voltage_sel_regmap, .set_voltage_sel = max77651_regulator_sbb1_set_voltage_sel, - .get_current_limit = max77650_regulator_get_current_limit, - .set_current_limit = max77650_regulator_set_current_limit, + .get_current_limit = regulator_get_current_limit_regmap, + .set_current_limit = regulator_set_current_limit_regmap, .set_active_discharge = regulator_set_active_discharge_regmap, }; @@ -343,6 +299,10 @@ static struct max77650_regulator_desc max77650_SBB0_desc = { .enable_time = 100, .type = REGULATOR_VOLTAGE, .owner = THIS_MODULE, + .csel_reg = MAX77650_REG_CNFG_SBB0_A, + .csel_mask = MAX77650_REGULATOR_CURR_LIM_MASK, + .curr_table = max77650_current_limit_table, + .n_current_limits = ARRAY_SIZE(max77650_current_limit_table), }, .regA = MAX77650_REG_CNFG_SBB0_A, .regB = MAX77650_REG_CNFG_SBB0_B, @@ -368,6 +328,10 @@ static struct max77650_regulator_desc max77650_SBB1_desc = { .enable_time = 100, .type = REGULATOR_VOLTAGE, .owner = THIS_MODULE, + .csel_reg = MAX77650_REG_CNFG_SBB1_A, + .csel_mask = MAX77650_REGULATOR_CURR_LIM_MASK, + .curr_table = max77650_current_limit_table, + .n_current_limits = ARRAY_SIZE(max77650_current_limit_table), }, .regA = MAX77650_REG_CNFG_SBB1_A, .regB = MAX77650_REG_CNFG_SBB1_B, @@ -392,6 +356,10 @@ static struct max77650_regulator_desc max77651_SBB1_desc = { .enable_time = 100, .type = REGULATOR_VOLTAGE, .owner = THIS_MODULE, + .csel_reg = MAX77650_REG_CNFG_SBB1_A, + .csel_mask = MAX77650_REGULATOR_CURR_LIM_MASK, + .curr_table = max77650_current_limit_table, + .n_current_limits = ARRAY_SIZE(max77650_current_limit_table), }, .regA = MAX77650_REG_CNFG_SBB1_A, .regB = MAX77650_REG_CNFG_SBB1_B, @@ -417,6 +385,10 @@ static struct max77650_regulator_desc max77650_SBB2_desc = { .enable_time = 100, .type = REGULATOR_VOLTAGE, .owner = THIS_MODULE, + .csel_reg = MAX77650_REG_CNFG_SBB2_A, + .csel_mask = MAX77650_REGULATOR_CURR_LIM_MASK, + .curr_table = max77650_current_limit_table, + .n_current_limits = ARRAY_SIZE(max77650_current_limit_table), }, .regA = MAX77650_REG_CNFG_SBB2_A, .regB = MAX77650_REG_CNFG_SBB2_B, @@ -442,6 +414,10 @@ static struct max77650_regulator_desc max77651_SBB2_desc = { .enable_time = 100, .type = REGULATOR_VOLTAGE, .owner = THIS_MODULE, + .csel_reg = MAX77650_REG_CNFG_SBB2_A, + .csel_mask = MAX77650_REGULATOR_CURR_LIM_MASK, + .curr_table = max77650_current_limit_table, + .n_current_limits = ARRAY_SIZE(max77650_current_limit_table), }, .regA = MAX77650_REG_CNFG_SBB2_A, .regB = MAX77650_REG_CNFG_SBB2_B, -- 2.17.1