Received: by 2002:ac0:8845:0:0:0:0:0 with SMTP id g63csp646833img; Thu, 28 Feb 2019 05:43:07 -0800 (PST) X-Google-Smtp-Source: AHgI3Ib0H/iuHNj0CbzRPnfbXauE9L5whPhbZUqMDkX7/CRvFw3BV9CHZe9PlkgeoZXDJq2bGb1r X-Received: by 2002:aa7:8b09:: with SMTP id f9mr7514861pfd.168.1551361387248; Thu, 28 Feb 2019 05:43:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551361387; cv=none; d=google.com; s=arc-20160816; b=FkpQJUi0ic8IJ4dzSLUuEqAiOIEQEN52h1JgKg/ZXPNnWtMrriWbCgmrZftQuR/JGO ijrq0MCF5C84PZYF3vDnHx9dP+61zcVE5PG/fX1tno5fgZNIgQ+jdGKnfE/Uj7dBKYI5 SKgaJuxxXXc3nURgdxKfZrVe7OBDws32ygCP19DrBxlVXl5A9gnFXk4B9sSleaUGHB8r BnEJdPAhRZUaasYF8gSPR0FpX5JhGrl6HPtQ4DzKI9L0zVilT30ddSuy2Suxoa8MwOWc jrdnMuZjb+4yuU3w+MQlx8RDTxML4lH1BNOdiEkC7heCbSg3w/CqvwYUeKgBB6eT6OZl mXLg== 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=Ln8GO4brHYR4ubNSWLkCcHdbPzz8XDjeNg4WSxm7Rcw=; b=wwxhb5Mi8iF9vvyeO6A72N+JWRqrIcZ54I/cyfWDHj4ktH6booFpOzdHBXQ9xznfn5 gYwcRvRfqmop0vHKpiX6RYMsSIv1N4LpyQ3gFWBbOxb3B8ounjcI9x16R1i1f5w2o6YY /YwjyUfaneNnhTEmnh3w/weCxWzb4069UgLCxwYk7dzSGVH/TrqWtnZrBwxbznFuULK3 hzYPq4r6bS7nQ3P1yBrecN/Upd4mdTSZvxYKACkBMftsQ6XBnRfiLEsQ17GzZ0hjR2ff 7ijioNMKiSRebg543TjMUaGz8cnEmfeERnnbecfxuJqwgP/RHs35PO/bxL5QPlRSAaMU zMRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ingics-com.20150623.gappssmtp.com header.s=20150623 header.b="0xz/rqkV"; 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 k72si16871767pge.188.2019.02.28.05.42.52; Thu, 28 Feb 2019 05:43:07 -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="0xz/rqkV"; 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 S1731375AbfB1Nk6 (ORCPT + 99 others); Thu, 28 Feb 2019 08:40:58 -0500 Received: from mail-pl1-f193.google.com ([209.85.214.193]:34370 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731313AbfB1Nk4 (ORCPT ); Thu, 28 Feb 2019 08:40:56 -0500 Received: by mail-pl1-f193.google.com with SMTP id d15so9796448plr.1 for ; Thu, 28 Feb 2019 05:40:56 -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=Ln8GO4brHYR4ubNSWLkCcHdbPzz8XDjeNg4WSxm7Rcw=; b=0xz/rqkV7ToW9nlSMZaPVqtPgwh6wyYb8Tb/W7JHcQCQRWdziR8jF7WJgoUkRjtWxA u19BsD2Zs8aBcz7/v4ccgDGJdpSXHBhQgxkj5PFIQw0Vlg6OiSBPaJ++zhAvzr8lTODS CdfhvWvAeLB0lAe0UALkh9zTtalVEuXGEMcnRQjNlWZX0iFvkOrMSb0r5xWtMam53hBm B30pOXNwGVdQZFIMob6lvQZsC0WGRtXanoR9u1DYBMNiHehaogQjmdWI0YDgIlaX6SpF mcQv20U6PURIuljHuiJNYuqixF7f5efk45GUzMyu9Cw697vUjUVVo7WwB5Q2+vLu5QY0 sARA== 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=Ln8GO4brHYR4ubNSWLkCcHdbPzz8XDjeNg4WSxm7Rcw=; b=T7bDFHob5ZyD1bSlxu83wBbi2jb8TM+d+cuJA4QlSYK0E4jmim/+vkqo5bzHRiAqi2 6kQl6AxBCfORsa7vlbsegqOXJNzfTOGpUKapzaDiPuyM3IA2IEu6xLRb07C/eTIBz6Zy yzVmm4bsQbOBTvXWVlkTmXNDp0QXw7CdsyTuyLoqqW6PMpNPGMdTIwmH3TDojKiuAz/p mUx/MTv2NpOhCGAYzZ4tcjz3k+MUAsns+kkgxpXeELGUKm8uEj1/mbxbjzK9Za5sR5Aa iD+62ibf3Prx0wkqNdDrJjeB6w8Mj40BiCErfVcpUYKAmhg3wvSo3bvCiLkmshLIV8ZS hT0Q== X-Gm-Message-State: AHQUAuanxyng6+TboIv/AtRZoxI+lAICyl3wrw9nGeDEky30R4VwipT7 LfnmbaTr49CcDlyv33hQWsN+FA== X-Received: by 2002:a17:902:505:: with SMTP id 5mr8202911plf.337.1551361256202; Thu, 28 Feb 2019 05:40:56 -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.40.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Feb 2019 05:40:55 -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 03/11] regulator: da9055: Convert to use regulator_set/get_current_limit_regmap Date: Thu, 28 Feb 2019 21:40:14 +0800 Message-Id: <20190228134022.32625-4-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/da9055-regulator.c | 45 ++++++---------------------- 1 file changed, 9 insertions(+), 36 deletions(-) diff --git a/drivers/regulator/da9055-regulator.c b/drivers/regulator/da9055-regulator.c index 417cafe2aba0..3c6fac793658 100644 --- a/drivers/regulator/da9055-regulator.c +++ b/drivers/regulator/da9055-regulator.c @@ -48,7 +48,9 @@ #define DA9055_ID_LDO6 7 /* DA9055 BUCK current limit */ -static const int da9055_current_limits[] = { 500000, 600000, 700000, 800000 }; +static const unsigned int da9055_current_limits[] = { + 500000, 600000, 700000, 800000 +}; struct da9055_conf_reg { int reg; @@ -169,39 +171,6 @@ static int da9055_ldo_set_mode(struct regulator_dev *rdev, unsigned int mode) val << volt.sl_shift); } -static int da9055_buck_get_current_limit(struct regulator_dev *rdev) -{ - struct da9055_regulator *regulator = rdev_get_drvdata(rdev); - struct da9055_regulator_info *info = regulator->info; - int ret; - - ret = da9055_reg_read(regulator->da9055, DA9055_REG_BUCK_LIM); - if (ret < 0) - return ret; - - ret &= info->mode.mask; - return da9055_current_limits[ret >> info->mode.shift]; -} - -static int da9055_buck_set_current_limit(struct regulator_dev *rdev, int min_uA, - int max_uA) -{ - struct da9055_regulator *regulator = rdev_get_drvdata(rdev); - struct da9055_regulator_info *info = regulator->info; - int i; - - for (i = ARRAY_SIZE(da9055_current_limits) - 1; i >= 0; i--) { - if ((min_uA <= da9055_current_limits[i]) && - (da9055_current_limits[i] <= max_uA)) - return da9055_reg_update(regulator->da9055, - DA9055_REG_BUCK_LIM, - info->mode.mask, - i << info->mode.shift); - } - - return -EINVAL; -} - static int da9055_regulator_get_voltage_sel(struct regulator_dev *rdev) { struct da9055_regulator *regulator = rdev_get_drvdata(rdev); @@ -329,8 +298,8 @@ static const struct regulator_ops da9055_buck_ops = { .get_mode = da9055_buck_get_mode, .set_mode = da9055_buck_set_mode, - .get_current_limit = da9055_buck_get_current_limit, - .set_current_limit = da9055_buck_set_current_limit, + .get_current_limit = regulator_get_current_limit_regmap, + .set_current_limit = regulator_set_current_limit_regmap, .get_voltage_sel = da9055_regulator_get_voltage_sel, .set_voltage_sel = da9055_regulator_set_voltage_sel, @@ -407,6 +376,10 @@ static const struct regulator_ops da9055_ldo_ops = { .uV_step = (step) * 1000,\ .linear_min_sel = (voffset),\ .owner = THIS_MODULE,\ + .curr_table = da9055_current_limits,\ + .n_current_limits = ARRAY_SIZE(da9055_current_limits),\ + .csel_reg = DA9055_REG_BUCK_LIM,\ + .csel_mask = (mbits),\ },\ .conf = {\ .reg = DA9055_REG_BCORE_CONT + DA9055_ID_##_id, \ -- 2.17.1