From: bigunclemax@gmail.com
Cc: bigunclemax@gmail.com,
Sebastian Reichel <sebastian.reichel@collabora.com>,
Marek Vasut <marex@denx.de>, Tom Rini <trini@konsulko.com>,
Wang Jie <dave.wang@rock-chips.com>,
Jonas Karlman <jonas@kwiboo.se>,
u-boot@lists.denx.de
Subject: [PATCH v1 2/3] usb: tcpm: fusb302: add support for set_vbus() callback.
Date: Fri, 1 Nov 2024 13:34:51 +0300 [thread overview]
Message-ID: <20241101103501.21432-3-bigunclemax@gmail.com> (raw)
In-Reply-To: <20241101103501.21432-1-bigunclemax@gmail.com>
From: Maksim Kiselev <bigunclemax@gmail.com>
Add support for VBUS supply regulator.
When our type-c port acts as a host(SRC), this regulator
used for control VBUS supply.
Signed-off-by: Maksim Kiselev <bigunclemax@gmail.com>
---
drivers/usb/tcpm/fusb302.c | 44 +++++++++++++++++++++++++++++++++++++-
1 file changed, 43 insertions(+), 1 deletion(-)
diff --git a/drivers/usb/tcpm/fusb302.c b/drivers/usb/tcpm/fusb302.c
index ee283782792..2a258d6429b 100644
--- a/drivers/usb/tcpm/fusb302.c
+++ b/drivers/usb/tcpm/fusb302.c
@@ -10,6 +10,7 @@
#include <asm/gpio.h>
#include <linux/delay.h>
#include <linux/err.h>
+#include <power/regulator.h>
#include <dm/device_compat.h>
#include <usb/tcpm.h>
#include "fusb302_reg.h"
@@ -50,10 +51,13 @@ struct fusb302_chip {
/* port status */
bool vconn_on;
+ bool vbus_on;
bool vbus_present;
enum typec_cc_polarity cc_polarity;
enum typec_cc_status cc1;
enum typec_cc_status cc2;
+
+ struct udevice *vbus;
};
static int fusb302_i2c_write(struct udevice *dev, u8 address, u8 data)
@@ -506,7 +510,28 @@ done:
static int fusb302_set_vbus(struct udevice *dev, bool on, bool charge)
{
- return 0;
+ struct fusb302_chip *chip = dev_get_priv(dev);
+ int ret = 0;
+
+ if (chip->vbus_on == on) {
+ dev_dbg(dev, "vbus is already %s\n", on ? "On" : "Off");
+ } else {
+ if (CONFIG_IS_ENABLED(DM_REGULATOR) && chip->vbus) {
+ if (on)
+ ret = regulator_set_enable(chip->vbus, true);
+ else
+ ret = regulator_set_enable(chip->vbus, false);
+ if (ret < 0) {
+ dev_dbg(dev, "cannot %s vbus regulator, ret=%d\n",
+ on ? "enable" : "disable", ret);
+ return ret;
+ }
+ }
+ chip->vbus_on = on;
+ dev_dbg(dev, "vbus := %s\n", on ? "On" : "Off");
+ }
+
+ return ret;
}
static int fusb302_pd_tx_flush(struct udevice *dev)
@@ -1293,6 +1318,22 @@ static int fusb302_get_connector_node(struct udevice *dev, ofnode *connector_nod
return 0;
}
+static int fusb302_probe(struct udevice *dev)
+{
+ struct fusb302_chip *chip = dev_get_priv(dev);
+ int ret;
+
+ if (CONFIG_IS_ENABLED(DM_REGULATOR)) {
+ ret = device_get_supply_regulator(dev, "vbus-supply", &chip->vbus);
+ if (ret && ret != -ENOENT) {
+ dev_err(dev, "Failed to get vbus-supply regulator\n");
+ return ret;
+ }
+ }
+
+ return 0;
+}
+
static struct dm_tcpm_ops fusb302_ops = {
.get_connector_node = fusb302_get_connector_node,
.init = fusb302_init,
@@ -1320,4 +1361,5 @@ U_BOOT_DRIVER(fusb302) = {
.of_match = fusb302_ids,
.ops = &fusb302_ops,
.priv_auto = sizeof(struct fusb302_chip),
+ .probe = fusb302_probe,
};
--
2.45.2
next prev parent reply other threads:[~2024-11-01 10:35 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-01 10:34 [PATCH v1 0/3] USB TCPM host (SRC) mode improvements bigunclemax
2024-11-01 10:34 ` [PATCH v1 1/3] usb: tcpm: fusb302: add missing newline character to debug output bigunclemax
2024-11-01 18:10 ` Sebastian Reichel
2024-11-01 10:34 ` bigunclemax [this message]
2024-11-01 18:17 ` [PATCH v1 2/3] usb: tcpm: fusb302: add support for set_vbus() callback Sebastian Reichel
2024-11-02 23:21 ` Jonas Karlman
2024-11-06 16:10 ` Maxim Kiselev
2024-11-01 10:34 ` [PATCH v1 3/3] usb: tcpm: fix toggling in host (SRC) mode bigunclemax
2024-11-01 18:31 ` Sebastian Reichel
2024-11-06 16:10 ` Maxim Kiselev
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=20241101103501.21432-3-bigunclemax@gmail.com \
--to=bigunclemax@gmail.com \
--cc=dave.wang@rock-chips.com \
--cc=jonas@kwiboo.se \
--cc=marex@denx.de \
--cc=sebastian.reichel@collabora.com \
--cc=trini@konsulko.com \
--cc=u-boot@lists.denx.de \
/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