Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2896624yba; Mon, 15 Apr 2019 23:44:02 -0700 (PDT) X-Google-Smtp-Source: APXvYqyIyh2pmIu5ImLXRbHashJtXdLWjTyWz2pZaNq3spFj3CmI7yepzhU3+eJHEIdHzL2vI9ng X-Received: by 2002:a63:1d5b:: with SMTP id d27mr73075352pgm.386.1555397041966; Mon, 15 Apr 2019 23:44:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555397041; cv=none; d=google.com; s=arc-20160816; b=Ty5Okrv/VqFvFzToz/qZQpIkhi4tC3n5J5W7WE+XsuXz8So4b0a6alvyzhAjKoohZo jRLAzdKcapuX8pdQ6o/ubkdJdlP+kz4AY23wCt1GhdtpvFerIcyU78T0LTuA7iYWDKTK x7AZ/CfkvAfRA5J4jHtX7mru8ls2cvgMcaNXrbBNANURKkb77TIsA5u2tSzXxXYsHUzl nyyr04b3uSi7liU9mW46IWIzUU8gbJ4ag1IQ0nwpjSf+4dUKQWSBYVp5ypN5aFRpJtLM qADw1tOn+PWJ3viR5YqKMGVg6EiC2fP4Ln2vfkxd74Dgd7mC/o2h+MbYezjPl8M1y3UR 0ixA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=i1BUhRDqFp1MS2ipd8O4VrZSc0n+wWH8XriCUeTlO3U=; b=G5bMpBbGy95SsSwJwLTEQUM+15E5cPJvqX331dj8Qc7r7EKU022ZQ+IIHiSyc9B6Na wr9hH+w9N/ka7s8qbvDOlbF4+QKAczL4ziW919IxwFpA9Dlvm9z914K4MqdIKHo0twVa 6DkKuKaJ272r8zM9jMDBwt2T1l/5R9faTj7PA6SdbvwRhVAskknjqW1jTIm9PRmnui6u XkP3YAcH+MfJmVl0BChwVde3S2DawvToWarzQG377sa3OpEHD27JJrT6z3E60ubi8FS0 iMhYCdfEHuG5ZQO6K3fSzsA8idZxl6+rU5O9E5duvdnQ+pnLloBF10GU1dLOwE+ByxSn gX/w== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p66si44014695pfp.228.2019.04.15.23.43.45; Mon, 15 Apr 2019 23:44:01 -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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728338AbfDPGk2 (ORCPT + 99 others); Tue, 16 Apr 2019 02:40:28 -0400 Received: from mirror2.csie.ntu.edu.tw ([140.112.30.76]:33988 "EHLO wens.csie.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727180AbfDPGk2 (ORCPT ); Tue, 16 Apr 2019 02:40:28 -0400 Received: by wens.csie.org (Postfix, from userid 1000) id 9AF5260292; Tue, 16 Apr 2019 14:40:25 +0800 (CST) From: Chen-Yu Tsai To: Maxime Ripard , Sebastian Reichel Cc: Quentin Schulz , linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-sunxi@googlegroups.com, Hans de Goede , Chen-Yu Tsai Subject: [PATCH v4 4/7] power: supply: axp20x_usb_power: add function to get max current Date: Tue, 16 Apr 2019 14:40:21 +0800 Message-Id: <20190416064024.20414-5-wens@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190416064024.20414-1-wens@kernel.org> References: <20190416064024.20414-1-wens@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Quentin Schulz To prepare for a new PMIC, factor out the code responsible of returning the maximum current to axp20x_get_current_max. Signed-off-by: Quentin Schulz Signed-off-by: Chen-Yu Tsai --- drivers/power/supply/axp20x_usb_power.c | 52 ++++++++++++++----------- 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/drivers/power/supply/axp20x_usb_power.c b/drivers/power/supply/axp20x_usb_power.c index 290028aed230..04c2cafbe8e6 100644 --- a/drivers/power/supply/axp20x_usb_power.c +++ b/drivers/power/supply/axp20x_usb_power.c @@ -102,6 +102,35 @@ static bool axp20x_usb_vbus_needs_polling(struct axp20x_usb_power *power) return false; } +static int axp20x_get_current_max(struct axp20x_usb_power *power, int *val) +{ + unsigned int v; + int ret = regmap_read(power->regmap, AXP20X_VBUS_IPSOUT_MGMT, &v); + + if (ret) + return ret; + + switch (v & AXP20X_VBUS_CLIMIT_MASK) { + case AXP20X_VBUS_CLIMIT_100mA: + if (power->axp20x_id == AXP221_ID) + *val = -1; /* No 100mA limit */ + else + *val = 100000; + break; + case AXP20X_VBUS_CLIMIT_500mA: + *val = 500000; + break; + case AXP20X_VBUS_CLIMIT_900mA: + *val = 900000; + break; + case AXP20X_VBUS_CLIMIT_NONE: + *val = -1; + break; + } + + return 0; +} + static int axp20x_usb_power_get_property(struct power_supply *psy, enum power_supply_property psp, union power_supply_propval *val) { @@ -140,28 +169,7 @@ static int axp20x_usb_power_get_property(struct power_supply *psy, val->intval = ret * 1700; /* 1 step = 1.7 mV */ return 0; case POWER_SUPPLY_PROP_CURRENT_MAX: - ret = regmap_read(power->regmap, AXP20X_VBUS_IPSOUT_MGMT, &v); - if (ret) - return ret; - - switch (v & AXP20X_VBUS_CLIMIT_MASK) { - case AXP20X_VBUS_CLIMIT_100mA: - if (power->axp20x_id == AXP221_ID) - val->intval = -1; /* No 100mA limit */ - else - val->intval = 100000; - break; - case AXP20X_VBUS_CLIMIT_500mA: - val->intval = 500000; - break; - case AXP20X_VBUS_CLIMIT_900mA: - val->intval = 900000; - break; - case AXP20X_VBUS_CLIMIT_NONE: - val->intval = -1; - break; - } - return 0; + return axp20x_get_current_max(power, &val->intval); case POWER_SUPPLY_PROP_CURRENT_NOW: if (IS_ENABLED(CONFIG_AXP20X_ADC)) { ret = iio_read_channel_processed(power->vbus_i, -- 2.20.1