Received: by 2002:ac0:950c:0:0:0:0:0 with SMTP id f12csp2235804imc; Tue, 12 Mar 2019 09:35:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqzpIF7iqc0K3R3ofNYUZL4D80UyGfe/Wlp/R3rcsaO8nVAGN09thkAWxX2GC5LRAeYINBLy X-Received: by 2002:a63:c60c:: with SMTP id w12mr6318815pgg.446.1552408521817; Tue, 12 Mar 2019 09:35:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552408521; cv=none; d=google.com; s=arc-20160816; b=SFRh/8maoOnlOxPo7QRlqjDtFPLyObbkgSMEEbwOtEHyZNDv+rbPxfl0kl/0/2Veil DHeTmXO0AX9EtZmh0hfo91SgOLYb8wgt3sjs0MPOMTCifhBCViL4YDRGM05Vi0cc416e CvsBAcRH5q34XLKBlMYfbIDRNJq6jIHxaKdWQVYx0JEc6s8hNQ5DG+MCzdAf7zSkBWeP bRIlPcXrjIsQKxGBPOkvY4rtEC1kCw9TKF5Et4wHsNJtlyvtXAUPazq4Op0+GjHTx9kn WAXCDi4hNne4XsQOFXKkN+wjECBkGrBvT6O1kn9rxNC7v+liSd/3TtAyYYBf8c+RIGSr vjVA== 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=f/zsEZeqMZdnHG0gnDPSHsocMzMCL9dk/SiJdqz46P0=; b=uv3YvhDCIh7lrpnWzKGFYFdjYhX1K69yRAHNKlhAeLJHHFA8j2yT0ZOC9QxIxDsHnU /6Rn//OvWXoyiMzOR/x1nflQA4LJK4k9vocoVq57YChwPPXzQ3KWc3G57fsayOGDnbyy Ala3R2Idl0PtsvzKndpeS8ZT6JV1xY3z4CivKU08RWLBiae7j1gi9+qi3qBT7BDoRUI5 RextU8RgIjMlC3AOUqLIK3Y5ffnSJ3/SUQ123phiGpk0gAMFEEYA+YP4P4H1yxTGWNJm Q7sLgaB66OC2upP3CaDkXkuO/QVAxqyfodpPO6Y5lEs/E0OhUlvXrPPC2e0T4s2xz/jC vo0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ingics-com.20150623.gappssmtp.com header.s=20150623 header.b=RFUocR9v; 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 p20si5442485plq.307.2019.03.12.09.35.02; Tue, 12 Mar 2019 09:35:21 -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; Authentication-Results: mx.google.com; dkim=pass header.i=@ingics-com.20150623.gappssmtp.com header.s=20150623 header.b=RFUocR9v; 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 S1726880AbfCLQeT (ORCPT + 99 others); Tue, 12 Mar 2019 12:34:19 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:38986 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725894AbfCLQeR (ORCPT ); Tue, 12 Mar 2019 12:34:17 -0400 Received: by mail-pg1-f193.google.com with SMTP id h8so2224532pgp.6 for ; Tue, 12 Mar 2019 09:34:17 -0700 (PDT) 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=f/zsEZeqMZdnHG0gnDPSHsocMzMCL9dk/SiJdqz46P0=; b=RFUocR9v8b7o3J64hVebo1qnGKNJEfpeU/KwhCpkewnpQwfwp2o2NmGrBXxxN0lQXN bYaMn7c+gVwKS9+8GSHyEov8dkG9fi1rmPbc9e6pRFrrSdzYgSdASkvxwH/1wFIiAfI/ Zh4p299WjZmEqWFoU1tPJjxSleG2X54ItZCCHvt06NQFkc1x1Tr8wcGFHR001Znzd8GL jw+hCFKWOrUcwfM+H0PWOJZgiGylMjzqF5ewrCIkA7ruqlC2ny/VSgDBVIrdrQdU2Y61 mHEbp4YjwoophLQzasS1Gh5FlLNWE2srns1FStCVzIs79tWQLhdjKCQxB+AW/hzMpUix rJQQ== 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=f/zsEZeqMZdnHG0gnDPSHsocMzMCL9dk/SiJdqz46P0=; b=bBLqRKqG6RSleprg5XrfHkjopnfjj3witwokWRGzaEOS8bkd3DIJyt7Kmp/DDSYfTT 9OPeLKjAb6EZtmp+HRlX3HOoiMCAQqZAL19JDE43iLQ9dlxn+RCQBY6HbkoaQ5uieORE qqa3ScKf3R3uFBLovPjPMm7jOdNkVxjaD2+7cjHbPtu+ATC/4OBJo2bJZ5mSyU22Byt/ 3wsn4TEK7zbGf9MuTcBopnpbIpPOFys0slAeFvtm4aw9lRzwXw+FUb9fK1bwzm+TvdPm 4wdWySvjHCkbhA8/OPRdyLXJsEAe1xKXfVHbkS4aVaoKZ6HQTieionBOdoiN6mGzSO2u tcyg== X-Gm-Message-State: APjAAAXCkFx4/JUZCf4cml3GYJxY+Y/JCnhf9+FQhgnWPAEEWIzF2F4Q LV9IqgT5lDtHhR60bqq59sJ7Aw== X-Received: by 2002:a17:902:a24:: with SMTP id 33mr28059314plo.275.1552408456646; Tue, 12 Mar 2019 09:34:16 -0700 (PDT) Received: from localhost.localdomain (220-133-186-239.HINET-IP.hinet.net. [220.133.186.239]) by smtp.gmail.com with ESMTPSA id s79sm17447467pfa.61.2019.03.12.09.34.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Mar 2019 09:34:15 -0700 (PDT) From: Axel Lin To: Mark Brown Cc: Charles Keepax , patches@opensource.cirrus.com, Liam Girdwood , linux-kernel@vger.kernel.org, Axel Lin Subject: [PATCH 3/4] regulator: wm831x-isink: Convert to use regulator_set/get_current_limit_regmap Date: Wed, 13 Mar 2019 00:33:56 +0800 Message-Id: <20190312163357.27785-3-axel.lin@ingics.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190312163357.27785-1-axel.lin@ingics.com> References: <20190312163357.27785-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/mfd/wm831x-core.c | 2 +- drivers/regulator/wm831x-isink.c | 45 +++++----------------------- include/linux/mfd/wm831x/regulator.h | 2 +- 3 files changed, 9 insertions(+), 40 deletions(-) diff --git a/drivers/mfd/wm831x-core.c b/drivers/mfd/wm831x-core.c index 25fbbaf39cb9..21bae64e0451 100644 --- a/drivers/mfd/wm831x-core.c +++ b/drivers/mfd/wm831x-core.c @@ -34,7 +34,7 @@ /* Current settings - values are 2*2^(reg_val/4) microamps. These are * exported since they are used by multiple drivers. */ -int wm831x_isinkv_values[WM831X_ISINK_MAX_ISEL + 1] = { +const unsigned int wm831x_isinkv_values[WM831X_ISINK_MAX_ISEL + 1] = { 2, 2, 3, diff --git a/drivers/regulator/wm831x-isink.c b/drivers/regulator/wm831x-isink.c index 676a4701c986..c4bc3d3361aa 100644 --- a/drivers/regulator/wm831x-isink.c +++ b/drivers/regulator/wm831x-isink.c @@ -92,48 +92,12 @@ static int wm831x_isink_is_enabled(struct regulator_dev *rdev) return 0; } -static int wm831x_isink_set_current(struct regulator_dev *rdev, - int min_uA, int max_uA) -{ - struct wm831x_isink *isink = rdev_get_drvdata(rdev); - struct wm831x *wm831x = isink->wm831x; - int ret, i; - - for (i = ARRAY_SIZE(wm831x_isinkv_values) - 1; i >= 0; i--) { - int val = wm831x_isinkv_values[i]; - if (min_uA <= val && val <= max_uA) { - ret = wm831x_set_bits(wm831x, isink->reg, - WM831X_CS1_ISEL_MASK, i); - return ret; - } - } - - return -EINVAL; -} - -static int wm831x_isink_get_current(struct regulator_dev *rdev) -{ - struct wm831x_isink *isink = rdev_get_drvdata(rdev); - struct wm831x *wm831x = isink->wm831x; - int ret; - - ret = wm831x_reg_read(wm831x, isink->reg); - if (ret < 0) - return ret; - - ret &= WM831X_CS1_ISEL_MASK; - if (ret > WM831X_ISINK_MAX_ISEL) - ret = WM831X_ISINK_MAX_ISEL; - - return wm831x_isinkv_values[ret]; -} - static const struct regulator_ops wm831x_isink_ops = { .is_enabled = wm831x_isink_is_enabled, .enable = wm831x_isink_enable, .disable = wm831x_isink_disable, - .set_current_limit = wm831x_isink_set_current, - .get_current_limit = wm831x_isink_get_current, + .set_current_limit = regulator_set_current_limit_regmap, + .get_current_limit = regulator_get_current_limit_regmap, }; static irqreturn_t wm831x_isink_irq(int irq, void *data) @@ -187,10 +151,15 @@ static int wm831x_isink_probe(struct platform_device *pdev) isink->desc.ops = &wm831x_isink_ops; isink->desc.type = REGULATOR_CURRENT; isink->desc.owner = THIS_MODULE; + isink->desc.curr_table = wm831x_isinkv_values, + isink->desc.n_current_limits = ARRAY_SIZE(wm831x_isinkv_values), + isink->desc.csel_reg = isink->reg, + isink->desc.csel_mask = WM831X_CS1_ISEL_MASK, config.dev = pdev->dev.parent; config.init_data = pdata->isink[id]; config.driver_data = isink; + config.regmap = wm831x->regmap; isink->regulator = devm_regulator_register(&pdev->dev, &isink->desc, &config); diff --git a/include/linux/mfd/wm831x/regulator.h b/include/linux/mfd/wm831x/regulator.h index 955d30fc6a27..30c587a0624c 100644 --- a/include/linux/mfd/wm831x/regulator.h +++ b/include/linux/mfd/wm831x/regulator.h @@ -1213,6 +1213,6 @@ #define WM831X_LDO1_OK_WIDTH 1 /* LDO1_OK */ #define WM831X_ISINK_MAX_ISEL 55 -extern int wm831x_isinkv_values[WM831X_ISINK_MAX_ISEL + 1]; +extern const unsigned int wm831x_isinkv_values[WM831X_ISINK_MAX_ISEL + 1]; #endif -- 2.17.1