From: Chen-Yu Tsai <wens@kernel.org>
To: Maxime Ripard <maxime.ripard@bootlin.com>,
Sebastian Reichel <sre@kernel.org>
Cc: devicetree@vger.kernel.org,
Quentin Schulz <quentin.schulz@bootlin.com>,
linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org,
Hans de Goede <hdegoede@redhat.com>,
linux-sunxi@googlegroups.com, Chen-Yu Tsai <wens@csie.org>,
linux-arm-kernel@lists.infradead.org
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 [thread overview]
Message-ID: <20190416064024.20414-5-wens@kernel.org> (raw)
In-Reply-To: <20190416064024.20414-1-wens@kernel.org>
From: Quentin Schulz <quentin.schulz@bootlin.com>
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 <quentin.schulz@bootlin.com>
Signed-off-by: Chen-Yu Tsai <wens@csie.org>
---
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
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2019-04-16 6:40 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-16 6:40 [PATCH v4 0/7] ARM: sun8i: a83t: Enable USB OTG Chen-Yu Tsai
2019-04-16 6:40 ` [PATCH v4 1/7] dt-bindings: power: supply: axp20x_usb_power: add axp813 compatible Chen-Yu Tsai
2019-04-16 6:40 ` [PATCH v4 2/7] power: supply: axp20x_usb_power: Fix typo in VBUS current limit macros Chen-Yu Tsai
2019-04-16 6:40 ` [PATCH v4 3/7] power: supply: axp20x_usb_power: use polling to detect vbus status change Chen-Yu Tsai
2019-04-16 6:40 ` Chen-Yu Tsai [this message]
2019-04-16 6:40 ` [PATCH v4 5/7] power: supply: axp20x_usb_power: add support for AXP813 Chen-Yu Tsai
2019-04-16 6:40 ` [PATCH v4 6/7] ARM: dtsi: axp81x: add USB power supply node Chen-Yu Tsai
2019-04-16 6:40 ` [PATCH v4 7/7] ARM: dts: sun8i: a83t: Enable USB OTG controller on some boards Chen-Yu Tsai
2019-04-17 21:27 ` [PATCH v4 0/7] ARM: sun8i: a83t: Enable USB OTG Sebastian Reichel
2019-04-18 15:49 ` Maxime Ripard
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190416064024.20414-5-wens@kernel.org \
--to=wens@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=hdegoede@redhat.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=linux-sunxi@googlegroups.com \
--cc=maxime.ripard@bootlin.com \
--cc=quentin.schulz@bootlin.com \
--cc=sre@kernel.org \
--cc=wens@csie.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).