Received: by 2002:ac0:8845:0:0:0:0:0 with SMTP id g63csp647425img; Thu, 28 Feb 2019 05:43:48 -0800 (PST) X-Google-Smtp-Source: AHgI3IZRbWU7nwkQNzz8cvC8GYJeCdU1jusA0nLlFnVBtwlLkCKnYlKs+wlXNLYa5u5nWTZCN1Ue X-Received: by 2002:a63:1616:: with SMTP id w22mr8454373pgl.200.1551361427924; Thu, 28 Feb 2019 05:43:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551361427; cv=none; d=google.com; s=arc-20160816; b=UlvF4VkL29+rAPspN1C5o+ykBz7Vz9BgNp5u6oaHAiiH1q1DnCzXXFd1BlNHSThzs9 WLzB5arm+Fqpq8l3ApW3yLLEiUsyJpDgxXQKh9tSB4uCK0E99F9stjDuRvb59qJJBg8E TjBHmI4aL19rzkhmQWSADMS7xtl2oSfKbzrT16qDlHaCX9kWpUIZmsb2nrE/Ea2rB1XI fypyPgCsZJT6QrKdwz1c3U54jpu49x6wu9Fxw0zeq9NpgWdsw7YsG7hB66MJ91x0lBtA EsyL00iHZgxVgVr4VAMCHxZ8Cikwal0swh2UHoIbswr9XyqC5lRtbtWVpvUhdy+bJiPT TE3g== 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=yrseqgr1GN0kfQBtkZLhXupoJWeTWIVNctr3h8BfTG4=; b=CiTULL7XWS27p18WQp6sW4s2vjukSVvzQsgDLKpc2xRtHrqlxZsUSOg3+vY8LYT2+i 5c+QtmtZNbm4wQFlkXGgFWfHTjP2FSswtT0zmLPWJL5ZuNAJIETy2OlEJVh8j+U2YgiI 9Hl1UwsTbo8dAqXAlGg147aNzh8zmE2UyRkfLSKpYujogoI1lJA88YL56vBJyCwa8X1B Wr49HyOgKz+tcaMCPnl9qO/umV/FSsgRwuAg23LVGQEk7La8x/6st1CdBrobAy74b2Vb Fh/aAcM1VP9iqTfkPDtAXH0pfZKs4vNHf4ZPlLWNmcltj2m6FvwctKdI3gJDBa+QpLlo GdPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ingics-com.20150623.gappssmtp.com header.s=20150623 header.b=CBxxBVuB; 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 f73si18110825pff.184.2019.02.28.05.43.32; Thu, 28 Feb 2019 05:43:47 -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=CBxxBVuB; 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 S1731953AbfB1Nla (ORCPT + 99 others); Thu, 28 Feb 2019 08:41:30 -0500 Received: from mail-pg1-f196.google.com ([209.85.215.196]:39454 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725967AbfB1Nl3 (ORCPT ); Thu, 28 Feb 2019 08:41:29 -0500 Received: by mail-pg1-f196.google.com with SMTP id h8so9235146pgp.6 for ; Thu, 28 Feb 2019 05:41:28 -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=yrseqgr1GN0kfQBtkZLhXupoJWeTWIVNctr3h8BfTG4=; b=CBxxBVuBykn+63dyKq6uW1VpusRiTRaq/KEa/rVs+FN2Ts/lUeZNpgbAHad9OpfB79 Ru3k2flJxxabPiWkagqv8kPfyJKlIc3JADUTAv6uqud703YC84ro05DxsD/Z9xbjEqgq FDeZ8EasiwUosnDsoezHOxKDqjE/5WKL/3yjfO9lX8w3WQFx3EK8oMWq4RjKLEuCZBn1 pLr9tlhpWgd4XwCz+UaUrkpVHWuFHblNMk/LWNe2CmmBqhO8Mfelfgn+h2lrfVfbgFnG mbauvt/nq2oFXvkPxP8hDjxcU04oACagYAOTMfQ+V4hufB4a1WhWZB2k+vFh9njPIW6P E7dA== 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=yrseqgr1GN0kfQBtkZLhXupoJWeTWIVNctr3h8BfTG4=; b=QTYnFoQkSqQZ1pxyKZwRmiZgWpJkUeCDBIEbTf+KtsG1c3cbGeTq3uQHNtw+m6Rcgk qeuloouUOmwAVWSVV3rgFMnT0adVaBYDPFfDEjUILfhWZqzgX214Cto22CXyt9fcxRlS gUI5oqYW6TLxSEoiwc9qr7I7HaSCVk6PEMot3Ch+f5crttaMcrQ/8D0mIv1VlKqfYmT9 OI/3cY1j3UYwOPLNzSgzSrirAxNVK6ci/BVlWAnTwN3/k9cKdYD9aEuk3RN3xhef2ptw LhHg2OnRpIRr135hXfUX3p8uc9B++jiTpHNFxRV6NYJ2YRseVv0AddbZnGVn4KHzRiem 03qw== X-Gm-Message-State: AHQUAua5FpEoTnUnv1UKFoNiCnRHR5g/FqJYq2522v16phocvr+Lq4KI s86qflkruu3tAQz8woASJS6jjQ== X-Received: by 2002:a62:41cc:: with SMTP id g73mr7359463pfd.145.1551361287799; Thu, 28 Feb 2019 05:41:27 -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.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Feb 2019 05:41:27 -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 10/11] regulator: pv88090: Convert to use regulator_set/get_current_limit_regmap Date: Thu, 28 Feb 2019 21:40:21 +0800 Message-Id: <20190228134022.32625-11-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/pv88090-regulator.c | 53 ++++----------------------- 1 file changed, 8 insertions(+), 45 deletions(-) diff --git a/drivers/regulator/pv88090-regulator.c b/drivers/regulator/pv88090-regulator.c index 2302b0df7630..6e97cc6df2ee 100644 --- a/drivers/regulator/pv88090-regulator.c +++ b/drivers/regulator/pv88090-regulator.c @@ -42,10 +42,6 @@ enum { struct pv88090_regulator { struct regulator_desc desc; - /* Current limiting */ - unsigned int n_current_limits; - const int *current_limits; - unsigned int limit_mask; unsigned int conf; unsigned int conf2; }; @@ -71,14 +67,14 @@ static const struct regmap_config pv88090_regmap_config = { * Entry indexes corresponds to register values. */ -static const int pv88090_buck1_limits[] = { +static const unsigned int pv88090_buck1_limits[] = { 220000, 440000, 660000, 880000, 1100000, 1320000, 1540000, 1760000, 1980000, 2200000, 2420000, 2640000, 2860000, 3080000, 3300000, 3520000, 3740000, 3960000, 4180000, 4400000, 4620000, 4840000, 5060000, 5280000, 5500000, 5720000, 5940000, 6160000, 6380000, 6600000, 6820000, 7040000 }; -static const int pv88090_buck23_limits[] = { +static const unsigned int pv88090_buck23_limits[] = { 1496000, 2393000, 3291000, 4189000 }; @@ -150,40 +146,6 @@ static int pv88090_buck_set_mode(struct regulator_dev *rdev, PV88090_BUCK1_MODE_MASK, val); } -static int pv88090_set_current_limit(struct regulator_dev *rdev, int min, - int max) -{ - struct pv88090_regulator *info = rdev_get_drvdata(rdev); - int i; - - /* search for closest to maximum */ - for (i = info->n_current_limits - 1; i >= 0; i--) { - if (min <= info->current_limits[i] - && max >= info->current_limits[i]) { - return regmap_update_bits(rdev->regmap, - info->conf, - info->limit_mask, - i << PV88090_BUCK1_ILIM_SHIFT); - } - } - - return -EINVAL; -} - -static int pv88090_get_current_limit(struct regulator_dev *rdev) -{ - struct pv88090_regulator *info = rdev_get_drvdata(rdev); - unsigned int data; - int ret; - - ret = regmap_read(rdev->regmap, info->conf, &data); - if (ret < 0) - return ret; - - data = (data & info->limit_mask) >> PV88090_BUCK1_ILIM_SHIFT; - return info->current_limits[data]; -} - static const struct regulator_ops pv88090_buck_ops = { .get_mode = pv88090_buck_get_mode, .set_mode = pv88090_buck_set_mode, @@ -193,8 +155,8 @@ static const struct regulator_ops pv88090_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 = pv88090_set_current_limit, - .get_current_limit = pv88090_get_current_limit, + .set_current_limit = regulator_set_current_limit_regmap, + .get_current_limit = regulator_get_current_limit_regmap, }; static const struct regulator_ops pv88090_ldo_ops = { @@ -223,10 +185,11 @@ static const struct regulator_ops pv88090_ldo_ops = { .enable_mask = PV88090_##regl_name##_EN, \ .vsel_reg = PV88090_REG_##regl_name##_CONF0, \ .vsel_mask = PV88090_V##regl_name##_MASK, \ + .curr_table = limits_array, \ + .n_current_limits = ARRAY_SIZE(limits_array), \ + .csel_reg = PV88090_REG_##regl_name##_CONF1, \ + .csel_mask = PV88090_##regl_name##_ILIM_MASK, \ },\ - .current_limits = limits_array, \ - .n_current_limits = ARRAY_SIZE(limits_array), \ - .limit_mask = PV88090_##regl_name##_ILIM_MASK, \ .conf = PV88090_REG_##regl_name##_CONF1, \ .conf2 = PV88090_REG_##regl_name##_CONF2, \ } -- 2.17.1