Received: by 2002:ac0:8845:0:0:0:0:0 with SMTP id g63csp645818img; Thu, 28 Feb 2019 05:42:01 -0800 (PST) X-Google-Smtp-Source: AHgI3IY9/k3Cw0jZuw8SsEvCpKI/kz3HkecLT+eCLvoO9kwma6yPRtZs2yUzgVwEMj/BrAQ9BCnb X-Received: by 2002:a63:d112:: with SMTP id k18mr8634670pgg.426.1551361321591; Thu, 28 Feb 2019 05:42:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551361321; cv=none; d=google.com; s=arc-20160816; b=TX9XoPdVhVkjieeiXRfZbRdfekLePbVyYP58qYXe0N16zBoF9L87mVTAbGhAMG+JFJ JR4WKimjsZEbgiVhx2swg/ge3b5fGOZJquB0OWIm6iobYALAAl+ZJZLOzRzk1ZivE7tH qtl2qnVorI/XlMaWNNUXvTLJvZ8N1fJAu/OvZthdioiglBCD58JFgcQx1mZCW1KTxMtS 8GbGe+rzbGtZlBdH/GhEme6MqlOHm1VUEXn66DjRrlZ3VidsyGAbC+GQxYDSRaAtdIlc tZK+EUqGd0RXGK3AHFUkbfGbIolL/3lXMB3557Jzg3QHGmVHazvPvdeSn1AO7r3LRpqe 30fg== 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=4qboQr5mj/MpLlzJSKMn+3syI3I3umISlClB03x9/+U=; b=eE/M3JoPBW0tXDP6pcthaGH+i4rAsAQxYa0NyG4F07ZVGXWEWNAjs/DQN+81XQaGZk ciTaCtRAdWeFAgT+j8pUEYPKnOx+yYHKKvVW0v3KpsYpThBxdHZMieFJRNQlk1Tpkpch N6Q8587wLcmC35HaFiALLCYLk0fzYyksAillj8K6vJyMzSE7YJEwYnoqdT2HRFt1b0YR 8pl8CfPQlJ8EXhNCB5tj9frRM9xnyeVU7KDgecNN4K0FHdjyZAQzEqPq5bRDPiHleFAb NCraQH5CiAqPrezaA0+IzoFql10Ndw7AOXbsEEeg+t3Q6/bMtxu1XS9uMnJ+ZdbvxVV1 8u2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ingics-com.20150623.gappssmtp.com header.s=20150623 header.b=RiIaCwhg; 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 bg8si17758761plb.109.2019.02.28.05.41.46; Thu, 28 Feb 2019 05:42:01 -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=RiIaCwhg; 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 S1731613AbfB1NlD (ORCPT + 99 others); Thu, 28 Feb 2019 08:41:03 -0500 Received: from mail-pl1-f196.google.com ([209.85.214.196]:40412 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731547AbfB1NlB (ORCPT ); Thu, 28 Feb 2019 08:41:01 -0500 Received: by mail-pl1-f196.google.com with SMTP id bj4so9773212plb.7 for ; Thu, 28 Feb 2019 05:41:01 -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=4qboQr5mj/MpLlzJSKMn+3syI3I3umISlClB03x9/+U=; b=RiIaCwhgd1CwaCDefg2WFV3xj8tEzhSAaJ2COLI2FHnjCV60YuirGxf5N3vYnWFbHn ybNlk6MRTvyufAWUgqJyMNMUy8LNAg5fH+l8UHUOrolV4kQOc9HnZ3jteJlxyd8b2r3B 36sWD2UffhEYtH3yX/sHy7GD+H0XkFInIc5IA62iqFz+h1jmdRDRZzqhu/QGxHB7w6EP YC8jXQztdxNnNux8noCLvGpftUxnsnPHJgWqMUtk5ZK6HQLXDeY1P6h2DHPONolf8IKv 3ATrNk7edJ5tmh/xGDD3AtwN575/6AY6WK7uZUMv2uuEe9qp6B/UlF+pA8AFaUMhv5RC X5Uw== 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=4qboQr5mj/MpLlzJSKMn+3syI3I3umISlClB03x9/+U=; b=tkBKCbkYp5UiT+Yz+zNAzATckGzqXBLG4oy6Cm67dvH5guD/T8EntM9mUMHE7xFk5c 4VTviV/LJ5Q4B18I/Z4ZV0mCG2f1f/2VWSyRO7Mm6Fyg1f7mxqDfhpmCR9kiGCWCqHUE 0Ki2+FARLbIHR+fTObzrBgiagtDrZGiWOxk3TGV+giffYPI1YkQkqL7KdZpsJEWV//jA jFmYegCT1LMzhDU5c4UE5QlbIPKjFZCY3CNdAcSzaVXQ5Yxj/qF24w+c6my3eRF6QD7s wRN+wV177LlrY/OBV9+58JL7sqoAlxyA9gQO7HGnZLWwEClwWFEgDNyjHurwnEbrFsV/ P9NQ== X-Gm-Message-State: AHQUAuaIGDpEYA+v7V7+xJv4DHOI1ftZhCK2BwdO33Tz6S+NmJ8uFtnS 8sMgmUiSODXAmGOVTKQ90HqpPQ== X-Received: by 2002:a17:902:1aa:: with SMTP id b39mr8065878plb.317.1551361260944; Thu, 28 Feb 2019 05:41:00 -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.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Feb 2019 05:41:00 -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 04/11] regulator: da9210: Convert to use regulator_set/get_current_limit_regmap Date: Thu, 28 Feb 2019 21:40:15 +0800 Message-Id: <20190228134022.32625-5-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/da9210-regulator.c | 53 ++++------------------------ 1 file changed, 7 insertions(+), 46 deletions(-) diff --git a/drivers/regulator/da9210-regulator.c b/drivers/regulator/da9210-regulator.c index 84dba64ed11e..528303771723 100644 --- a/drivers/regulator/da9210-regulator.c +++ b/drivers/regulator/da9210-regulator.c @@ -41,10 +41,6 @@ static const struct regmap_config da9210_regmap_config = { .val_bits = 8, }; -static int da9210_set_current_limit(struct regulator_dev *rdev, int min_uA, - int max_uA); -static int da9210_get_current_limit(struct regulator_dev *rdev); - static const struct regulator_ops da9210_buck_ops = { .enable = regulator_enable_regmap, .disable = regulator_disable_regmap, @@ -52,8 +48,8 @@ static const struct regulator_ops da9210_buck_ops = { .set_voltage_sel = regulator_set_voltage_sel_regmap, .get_voltage_sel = regulator_get_voltage_sel_regmap, .list_voltage = regulator_list_voltage_linear, - .set_current_limit = da9210_set_current_limit, - .get_current_limit = da9210_get_current_limit, + .set_current_limit = regulator_set_current_limit_regmap, + .get_current_limit = regulator_get_current_limit_regmap, }; /* Default limits measured in millivolts and milliamps */ @@ -62,7 +58,7 @@ static const struct regulator_ops da9210_buck_ops = { #define DA9210_STEP_MV 10 /* Current limits for buck (uA) indices corresponds with register values */ -static const int da9210_buck_limits[] = { +static const unsigned int da9210_buck_limits[] = { 1600000, 1800000, 2000000, 2200000, 2400000, 2600000, 2800000, 3000000, 3200000, 3400000, 3600000, 3800000, 4000000, 4200000, 4400000, 4600000 }; @@ -80,47 +76,12 @@ static const struct regulator_desc da9210_reg = { .enable_reg = DA9210_REG_BUCK_CONT, .enable_mask = DA9210_BUCK_EN, .owner = THIS_MODULE, + .curr_table = da9210_buck_limits, + .n_current_limits = ARRAY_SIZE(da9210_buck_limits), + .csel_reg = DA9210_REG_BUCK_ILIM, + .csel_mask = DA9210_BUCK_ILIM_MASK, }; -static int da9210_set_current_limit(struct regulator_dev *rdev, int min_uA, - int max_uA) -{ - struct da9210 *chip = rdev_get_drvdata(rdev); - unsigned int sel; - int i; - - /* search for closest to maximum */ - for (i = ARRAY_SIZE(da9210_buck_limits)-1; i >= 0; i--) { - if (min_uA <= da9210_buck_limits[i] && - max_uA >= da9210_buck_limits[i]) { - sel = i; - sel = sel << DA9210_BUCK_ILIM_SHIFT; - return regmap_update_bits(chip->regmap, - DA9210_REG_BUCK_ILIM, - DA9210_BUCK_ILIM_MASK, sel); - } - } - - return -EINVAL; -} - -static int da9210_get_current_limit(struct regulator_dev *rdev) -{ - struct da9210 *chip = rdev_get_drvdata(rdev); - unsigned int data; - unsigned int sel; - int ret; - - ret = regmap_read(chip->regmap, DA9210_REG_BUCK_ILIM, &data); - if (ret < 0) - return ret; - - /* select one of 16 values: 0000 (1600mA) to 1111 (4600mA) */ - sel = (data & DA9210_BUCK_ILIM_MASK) >> DA9210_BUCK_ILIM_SHIFT; - - return da9210_buck_limits[sel]; -} - static irqreturn_t da9210_irq_handler(int irq, void *data) { struct da9210 *chip = data; -- 2.17.1