From patchwork Tue Apr 16 06:40:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen-Yu Tsai X-Patchwork-Id: 10902023 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0F0E71515 for ; Tue, 16 Apr 2019 06:41:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E17862892B for ; Tue, 16 Apr 2019 06:40:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D18412892D; Tue, 16 Apr 2019 06:40:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6A0FC2892B for ; Tue, 16 Apr 2019 06:40:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=7peyhCe+OEqRplFTgQL2FFMGqvPIOdFXYC8I2ipX9bI=; b=SKafrpj4l2/dtF SOLR6kFldtIs7diq2Rq8cC8MavmavLJKQ8MF2t3Y/FgCUpbXrhkucnbvoCY0uex8FozMuI45bz5ku BElnzIc5/oji9jSjxJPluAWyMg+ANTNaWxFThUOrS5lwAHjfwG8s06pddINzQZLFJ51XE+KGyngsm EmbWsTx8s6MH45tJqdIrrTqhhhgNor0NJtyDe2WzIMdK0zUj1aA4j4tR7PfNauQ1OZrkerOYeGBuy K7CQLdsGjTRg8j9bfa6Ob+T2gbqzLRCVE5j2AAqyJusTlSJfvOiGr/QAiO3RlUctG4RwZW2Evc58Z bTXvTg0rqVeZboM9fOlQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hGHm1-0000xL-QO; Tue, 16 Apr 2019 06:40:53 +0000 Received: from mirror2.csie.ntu.edu.tw ([140.112.30.76] helo=wens.csie.org) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hGHlg-0000XI-20 for linux-arm-kernel@lists.infradead.org; Tue, 16 Apr 2019 06:40:34 +0000 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 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190415_234032_222285_62F06E09 X-CRM114-Status: GOOD ( 11.71 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, Quentin Schulz , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Hans de Goede , linux-sunxi@googlegroups.com, Chen-Yu Tsai , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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,