From: Samuel Holland <samuel@sholland.org>
To: Chen-Yu Tsai <wens@csie.org>, Sebastian Reichel <sre@kernel.org>,
Lee Jones <lee.jones@linaro.org>,
Hans de Goede <hdegoede@redhat.com>,
Oskari Lemmela <oskari@lemmela.net>,
Quentin Schulz <quentin.schulz@bootlin.com>
Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-sunxi@googlegroups.com,
Samuel Holland <samuel@sholland.org>
Subject: [PATCH v2 7/9] power: supply: axp20x_usb_power: Allow offlining
Date: Sat, 4 Jan 2020 19:24:14 -0600 [thread overview]
Message-ID: <20200105012416.23296-8-samuel@sholland.org> (raw)
In-Reply-To: <20200105012416.23296-1-samuel@sholland.org>
AXP803/AXP813 have a flag that enables/disables the USB power supply
input. Allow control of this flag via the ONLINE property on those
variants.
It may be necessary to offline the USB power supply input when using
the USB port in OTG mode, or to allow userspace to disable charging.
When the USB VBUS input is disabled via the PATH_SEL bit, the VBUS_USED
bit in PWR_INPUT_STATUS is cleared, so there is no change needed when
getting the property.
Signed-off-by: Samuel Holland <samuel@sholland.org>
---
drivers/power/supply/axp20x_usb_power.c | 27 +++++++++++++++++++++++++
1 file changed, 27 insertions(+)
diff --git a/drivers/power/supply/axp20x_usb_power.c b/drivers/power/supply/axp20x_usb_power.c
index 2d7272e19a87..68443f264dff 100644
--- a/drivers/power/supply/axp20x_usb_power.c
+++ b/drivers/power/supply/axp20x_usb_power.c
@@ -29,6 +29,9 @@
#define AXP20X_USB_STATUS_VBUS_VALID BIT(2)
+#define AXP20X_VBUS_PATH_SEL BIT(7)
+#define AXP20X_VBUS_PATH_SEL_OFFSET 7
+
#define AXP20X_VBUS_VHOLD_uV(b) (4000000 + (((b) >> 3) & 7) * 100000)
#define AXP20X_VBUS_VHOLD_MASK GENMASK(5, 3)
#define AXP20X_VBUS_VHOLD_OFFSET 3
@@ -263,6 +266,16 @@ static int axp20x_usb_power_get_property(struct power_supply *psy,
return 0;
}
+static int axp813_usb_power_set_online(struct axp20x_usb_power *power,
+ int intval)
+{
+ int val = !intval << AXP20X_VBUS_PATH_SEL_OFFSET;
+
+ return regmap_update_bits(power->regmap,
+ AXP20X_VBUS_IPSOUT_MGMT,
+ AXP20X_VBUS_PATH_SEL, val);
+}
+
static int axp20x_usb_power_set_voltage_min(struct axp20x_usb_power *power,
int intval)
{
@@ -344,6 +357,9 @@ static int axp20x_usb_power_set_property(struct power_supply *psy,
struct axp20x_usb_power *power = power_supply_get_drvdata(psy);
switch (psp) {
+ case POWER_SUPPLY_PROP_ONLINE:
+ return axp813_usb_power_set_online(power, val->intval);
+
case POWER_SUPPLY_PROP_VOLTAGE_MIN:
return axp20x_usb_power_set_voltage_min(power, val->intval);
@@ -363,6 +379,17 @@ static int axp20x_usb_power_set_property(struct power_supply *psy,
static int axp20x_usb_power_prop_writeable(struct power_supply *psy,
enum power_supply_property psp)
{
+ struct axp20x_usb_power *power = power_supply_get_drvdata(psy);
+
+ /*
+ * Both AXP2xx and AXP8xx have a VBUS path select flag.
+ * On AXP2xx, setting the flag enables VBUS (ignoring N_VBUSEN).
+ * On AXP8xx, setting the flag disables VBUS (ignoring N_VBUSEN).
+ * So we only expose the control on AXP8xx where it is meaningful.
+ */
+ if (psp == POWER_SUPPLY_PROP_ONLINE)
+ return power->axp20x_id == AXP813_ID;
+
return psp == POWER_SUPPLY_PROP_VOLTAGE_MIN ||
psp == POWER_SUPPLY_PROP_CURRENT_MAX;
}
--
2.23.0
next prev parent reply other threads:[~2020-01-05 1:24 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-05 1:24 [PATCH v2 0/9] X-Powers Power Supply Improvements Samuel Holland
2020-01-05 1:24 ` [PATCH v2 1/9] mfd: axp20x: Mark AXP20X_VBUS_IPSOUT_MGMT as volatile Samuel Holland
2020-01-05 10:07 ` Chen-Yu Tsai
2020-01-06 8:36 ` Lee Jones
2020-01-05 1:24 ` [PATCH v2 2/9] power: supply: axp20x_ac_power: Fix reporting online status Samuel Holland
2020-01-05 10:09 ` [linux-sunxi] " Chen-Yu Tsai
2020-01-05 13:00 ` Julian Calaby
2020-01-05 15:27 ` Samuel Holland
2020-01-05 1:24 ` [PATCH v2 3/9] power: supply: axp20x_ac_power: Allow offlining Samuel Holland
2020-01-05 10:11 ` [linux-sunxi] " Chen-Yu Tsai
2020-01-05 1:24 ` [PATCH v2 4/9] power: supply: axp20x_ac_power: Add wakeup control Samuel Holland
2020-01-05 10:24 ` [linux-sunxi] " Chen-Yu Tsai
2020-01-05 10:44 ` Chen-Yu Tsai
2020-01-05 1:24 ` [PATCH v2 5/9] power: supply: axp20x_usb_power: Remove unused device_node Samuel Holland
2020-01-05 10:25 ` Chen-Yu Tsai
2020-01-05 1:24 ` [PATCH v2 6/9] power: supply: axp20x_usb_power: Use a match structure Samuel Holland
2020-01-05 10:34 ` [linux-sunxi] " Chen-Yu Tsai
2020-01-05 17:58 ` Samuel Holland
2020-01-06 2:24 ` Chen-Yu Tsai
2020-01-05 1:24 ` Samuel Holland [this message]
2020-01-05 10:40 ` [linux-sunxi] [PATCH v2 7/9] power: supply: axp20x_usb_power: Allow offlining Chen-Yu Tsai
2020-01-05 17:47 ` Samuel Holland
2020-01-06 2:22 ` Chen-Yu Tsai
2020-01-05 1:24 ` [PATCH v2 8/9] power: supply: axp20x_usb_power: Add wakeup control Samuel Holland
2020-01-05 10:47 ` [linux-sunxi] " Chen-Yu Tsai
2020-01-05 1:24 ` [PATCH v2 9/9] power: supply: axp20x_usb_power: Only poll while offline Samuel Holland
2020-01-06 4:27 ` [linux-sunxi] " Chen-Yu Tsai
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=20200105012416.23296-8-samuel@sholland.org \
--to=samuel@sholland.org \
--cc=hdegoede@redhat.com \
--cc=lee.jones@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=linux-sunxi@googlegroups.com \
--cc=oskari@lemmela.net \
--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