Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp241455imb; Thu, 28 Feb 2019 22:37:10 -0800 (PST) X-Google-Smtp-Source: APXvYqxvi6CC6omnqRW0J1HlRzPWwdA0Uzk1rZW7jAueggFRiWwI5Bg7XuK5LdGi/vMaeBp5kTMt X-Received: by 2002:a63:1044:: with SMTP id 4mr3360242pgq.324.1551422230893; Thu, 28 Feb 2019 22:37:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551422230; cv=none; d=google.com; s=arc-20160816; b=V04gn3ZqkUWRYZBoZdpqNEHB0t8zP5NPCe6/ihGdF1zZe3SV/YYkqxih/+pS2QQMTc TZXOU/3EPrJZZ7RlIrGCyywfnDL3Kt6UiMTsS44sTUGHMVm7YQV2Zxaa6TBFtHY2kGOl VSzur7bf8cxK0AeutWc1W4u1tCbQ65ZkAe6g+HMwT75EWtY1BCEdA/q+fCMDc6mo/VrF e+W8qDCyIMi7LjUgsjHUwrUOh5WDKHKAZaJ+Cc60TXK70MxyW7q8JaFF2WM0/DRobdPw lZDDbfO4g+7iHwRNyCKlnlA+JwXkX1avzOkj/QfweGlLRGBPdOmxbvnMSozDGiHOwrhR yWlw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=iAzg2Q8cWeZyhce41BRki32Gq8ebOPoAL0+7Mg9Sob4=; b=HuVPB4OvEihTBHIlFZCsSNKyiRSM/0GOQk/Ny+54uNCmOgNmaW1owI/zMBXWJ+uJyd r+nVy0/mwYlgzTZuRYEtXRs2gZgQSUFkvrd7GYjMfRf3bfbeRDyhnJaA2cAWhrop+i0+ /URrrb0n2GC73KDdx235pFox0y8AcFWN2WO3KTxNn6pMNo9aYeEykca1s7dMEHq85LUm 4BZ1ElYECdngpvR4Mee23s22cTky+M0epVQ3KJM9zZjwAJMu8tSUXIGsNcpuD5lWnTFS w2IZsDot7/5zEGggq7Jwbhr83zEaNXjqJJmAl0rG/0LJ3yN03wumGzi0oyi7GH5P5/xr Hq1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ingics-com.20150623.gappssmtp.com header.s=20150623 header.b=mz+kSZVu; 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 k189si17874043pgd.111.2019.02.28.22.36.55; Thu, 28 Feb 2019 22:37:10 -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=mz+kSZVu; 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 S1727374AbfCAGYu (ORCPT + 99 others); Fri, 1 Mar 2019 01:24:50 -0500 Received: from mail-pg1-f196.google.com ([209.85.215.196]:45884 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725290AbfCAGYt (ORCPT ); Fri, 1 Mar 2019 01:24:49 -0500 Received: by mail-pg1-f196.google.com with SMTP id y4so10914973pgc.12 for ; Thu, 28 Feb 2019 22:24:48 -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; bh=iAzg2Q8cWeZyhce41BRki32Gq8ebOPoAL0+7Mg9Sob4=; b=mz+kSZVuXvt167L8j4mG3bSf4m/BUUUfkb4D/dHUl6sm8l5XKJJKBZix3YSWOoWKFQ 82Kn8wuiDXfF/krH3D/94+3ci/3lWnfy6NWnw0k9xwE5RJvF9/7g8PL6lGiIhm+V1Vww TyA3+Qgh9Eu5sUdWwvcUjstUvmuEGHVfMRc5Y3fDyiifk6tBuUVPWmLethCEd+/7ugM9 hY/4+MYr9nie86V4nt8vtCOSHFAF/rXxeggihzf6VkC9e0vVJSTumhexFxYOSC8nzEuh k5QgRLiOhJo1FpTWDv4ZD+qEYUUFc9JOhOU21xKEtBU36QbCCzmRJ3Sx4HQOvvde6jeX 0gSA== 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; bh=iAzg2Q8cWeZyhce41BRki32Gq8ebOPoAL0+7Mg9Sob4=; b=enwmHS4sfoqAjkYJ1D6KE1P4H5fVvB5IJ0Pi1f5Ad5mVfg0IIJNt6Km2/91sLfL6WK 4E3pp6YqilVMBzLEwlu5xKw9K4CDiEc8f1Q3XfHe/HQExWaecntKvzkp7fy6g/d5UZZZ BtPbI42C9CqGXaZmYHfujYvJXlabh8HWZp+pJ+aFV7hemc+5KHI+setafm5tLJwKglfh r2FTo/0bUWcNRaWPN0PJU6SrJAOBK/pYw0JFUDnBzGK1HQu97P0qZBE3bMkBVkW40Ove wsE39/z4h831wGrMRRBEeuPjG139U7HDB+3959qq+3+NKRkmVWLE/7Sph8YDZQXpMTcw 3sOA== X-Gm-Message-State: AHQUAuZY/M7EFZfMYP2UI6HxSeWwWcpLmEVtTe+9e74IVhZPWm4J4gh6 SUXSemsR5o4xITrXVo/AcLPtQQ== X-Received: by 2002:aa7:9289:: with SMTP id j9mr3977806pfa.130.1551421488266; Thu, 28 Feb 2019 22:24:48 -0800 (PST) Received: from localhost.localdomain (2001-b400-e303-1426-0ded-295b-b15d-4a53.emome-ip6.hinet.net. [2001:b400:e303:1426:ded:295b:b15d:4a53]) by smtp.gmail.com with ESMTPSA id g67sm55484909pfg.13.2019.02.28.22.24.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Feb 2019 22:24:47 -0800 (PST) From: Axel Lin To: Mark Brown Cc: Keerthy , Liam Girdwood , linux-kernel@vger.kernel.org, Axel Lin Subject: [PATCH] regulator: lp87565: Convert to use regulator_set/get_current_limit_regmap Date: Fri, 1 Mar 2019 14:24:32 +0800 Message-Id: <20190301062432.2322-1-axel.lin@ingics.com> X-Mailer: git-send-email 2.17.1 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/lp87565-regulator.c | 47 ++++----------------------- 1 file changed, 7 insertions(+), 40 deletions(-) diff --git a/drivers/regulator/lp87565-regulator.c b/drivers/regulator/lp87565-regulator.c index 0418e478c6dc..81eb4b890c0c 100644 --- a/drivers/regulator/lp87565-regulator.c +++ b/drivers/regulator/lp87565-regulator.c @@ -34,6 +34,10 @@ .ramp_delay = _delay, \ .linear_ranges = _lr, \ .n_linear_ranges = ARRAY_SIZE(_lr), \ + .curr_table = lp87565_buck_uA, \ + .n_current_limits = ARRAY_SIZE(lp87565_buck_uA),\ + .csel_reg = (_cr), \ + .csel_mask = LP87565_BUCK_CTRL_2_ILIM, \ }, \ .ctrl2_reg = _cr, \ } @@ -102,44 +106,7 @@ static int lp87565_buck_set_ramp_delay(struct regulator_dev *rdev, return 0; } -static int lp87565_buck_set_current_limit(struct regulator_dev *rdev, - int min_uA, int max_uA) -{ - int id = rdev_get_id(rdev); - struct lp87565 *lp87565 = rdev_get_drvdata(rdev); - int i; - - for (i = ARRAY_SIZE(lp87565_buck_uA) - 1; i >= 0; i--) { - if (lp87565_buck_uA[i] >= min_uA && - lp87565_buck_uA[i] <= max_uA) - return regmap_update_bits(lp87565->regmap, - regulators[id].ctrl2_reg, - LP87565_BUCK_CTRL_2_ILIM, - i << __ffs(LP87565_BUCK_CTRL_2_ILIM)); - } - - return -EINVAL; -} - -static int lp87565_buck_get_current_limit(struct regulator_dev *rdev) -{ - int id = rdev_get_id(rdev); - struct lp87565 *lp87565 = rdev_get_drvdata(rdev); - int ret; - unsigned int val; - - ret = regmap_read(lp87565->regmap, regulators[id].ctrl2_reg, &val); - if (ret) - return ret; - - val = (val & LP87565_BUCK_CTRL_2_ILIM) >> - __ffs(LP87565_BUCK_CTRL_2_ILIM); - - return (val < ARRAY_SIZE(lp87565_buck_uA)) ? - lp87565_buck_uA[val] : -EINVAL; -} - -/* Operations permitted on BUCK0, BUCK1 */ +/* Operations permitted on BUCKs */ static const struct regulator_ops lp87565_buck_ops = { .is_enabled = regulator_is_enabled_regmap, .enable = regulator_enable_regmap, @@ -150,8 +117,8 @@ static const struct regulator_ops lp87565_buck_ops = { .map_voltage = regulator_map_voltage_linear_range, .set_voltage_time_sel = regulator_set_voltage_time_sel, .set_ramp_delay = lp87565_buck_set_ramp_delay, - .set_current_limit = lp87565_buck_set_current_limit, - .get_current_limit = lp87565_buck_get_current_limit, + .set_current_limit = regulator_set_current_limit_regmap, + .get_current_limit = regulator_get_current_limit_regmap, }; static const struct lp87565_regulator regulators[] = { -- 2.17.1