[PATCH 1/4] usb: otg: Add function to set dr_mode
Sascha Hauer
s.hauer at pengutronix.de
Mon Apr 20 02:02:17 PDT 2026
So far we can only set the dr_mode on the command line. Add a function
for it.
Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
drivers/usb/otg/otgdev.c | 20 ++++++++++++++++++++
include/linux/usb/usb.h | 1 +
2 files changed, 21 insertions(+)
diff --git a/drivers/usb/otg/otgdev.c b/drivers/usb/otg/otgdev.c
index 5a86263430..50d8105be3 100644
--- a/drivers/usb/otg/otgdev.c
+++ b/drivers/usb/otg/otgdev.c
@@ -74,6 +74,26 @@ int otg_device_get_mode(struct device *dev)
return otg->cur_mode;
}
+int otg_device_set_dr_mode(struct device *dev, enum usb_dr_mode mode)
+{
+ struct otg_mode *otg;
+ int ret;
+
+ if (dev->bus != &otg_bus_type)
+ return -ENODEV;
+
+ otg = dev->priv;
+
+ ret = otg->set_mode_callback(otg->ctx, mode);
+ if (ret)
+ return ret;
+
+ otg->cur_mode = mode;
+ otg->var_mode = mode;
+
+ return 0;
+}
+
int usb_register_otg_device(struct device *parent,
int (*set_mode)(void *ctx, enum usb_dr_mode mode), void *ctx)
{
diff --git a/include/linux/usb/usb.h b/include/linux/usb/usb.h
index c25f3d73c3..6aa9e55cc9 100644
--- a/include/linux/usb/usb.h
+++ b/include/linux/usb/usb.h
@@ -477,6 +477,7 @@ int usb_register_otg_device(struct device *parent,
int (*set_mode)(void *ctx, enum usb_dr_mode mode), void *ctx);
int otg_device_get_mode(struct device *dev);
+int otg_device_set_dr_mode(struct device *dev, enum usb_dr_mode mode);
extern struct bus_type otg_bus_type;
--
2.47.3
More information about the barebox
mailing list