Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp461403img; Thu, 21 Mar 2019 01:50:40 -0700 (PDT) X-Google-Smtp-Source: APXvYqw8NXtFzu39eXZ6o0cmGx4ongzNaBNbwI2Hw+w7r06W6QqzUM7aRUtg06SQOGSXedwgMuMK X-Received: by 2002:a65:50c8:: with SMTP id s8mr2278577pgp.308.1553158240462; Thu, 21 Mar 2019 01:50:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553158240; cv=none; d=google.com; s=arc-20160816; b=CWS5bxQTKrTxEJiskp65VsU4YHlrI16TbJSzvC1oIzBzoZi7NK820G1XqD17CfUeO4 7PzdN9Vkyk2Jn5Rkm7lxSnnGS5C7xrBYUCdpPIFH2tiz4NqGpvZQ6rR8mqhPpGO3q7E7 6xvMMS+zB0qYJVGecyoaDau7ybQA/YwKocaOd/u3GqzDQV/fFEoS8dSkq+6EuRmfeufm PfQ+26fQPUxBuuiqF4QSTGGhKVBYDx2kHelyGHDxS8C4APHtBZtTqb9aTZ2E8GlR2NRu uesFQJlThyjeaCLJTRgW50mHMHILjJKUuuqSfClskiVVDyAWfY3L5hxyrPRU2bHCDoBX /Uog== 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=4VXgaocDDJXO9NjJmv2yS3CbVhKxZXAcldMah+amloo=; b=AnjpLhZBDn+E41OrOY/NRBSXMw18ik/C9Hl4qvJd9XpuUI9z8LeQLW0cT5voYm7h6f Cr65M85AI971ypSktsXln3M36XMThaYpexpn5lHLybvofp0UFZgcJQnlpLdy55BgJEWc IIYla37/Ey+EnL/B3s7sAbY+cLgtR0A4j7qrs+mgWTZvwTLFuz09t6KfsCuitcz11ILD K9+a88QnGNj9/r7FlkgQQjsLe0pBB3cna4QTLDLTIeoVgnf/PYpbdTVjx1jZU48ap7JQ Pb3GGqJhRR6Y2pbRLsGtUCXpYxdzCJ1u7kDUv4SVhdtbkiXWdX+0t+HWIfVPScrCANx/ PdRw== 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 go16si3892904plb.132.2019.03.21.01.50.25; Thu, 21 Mar 2019 01:50:40 -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 S1728183AbfCUItd (ORCPT + 99 others); Thu, 21 Mar 2019 04:49:33 -0400 Received: from mirror2.csie.ntu.edu.tw ([140.112.30.76]:41500 "EHLO wens.csie.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728093AbfCUItF (ORCPT ); Thu, 21 Mar 2019 04:49:05 -0400 Received: by wens.csie.org (Postfix, from userid 1000) id 49F1B5FDF9; Thu, 21 Mar 2019 16:48:59 +0800 (CST) From: Chen-Yu Tsai To: Maxime Ripard , Lee Jones , Sebastian Reichel Cc: Quentin Schulz , devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sunxi@googlegroups.com, Hans de Goede , Chen-Yu Tsai Subject: [PATCH v3 5/9] power: supply: axp20x_usb_power: add function to get max current Date: Thu, 21 Mar 2019 16:48:46 +0800 Message-Id: <20190321084850.20769-6-wens@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190321084850.20769-1-wens@kernel.org> References: <20190321084850.20769-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 ac061bcdc056..90d06027bf98 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