* [PATCH] usb: xhci-dwc3: Support role switch default role
@ 2022-04-19 19:06 Mark Kettenis
2022-05-10 12:49 ` Mark Kettenis
0 siblings, 1 reply; 2+ messages in thread
From: Mark Kettenis @ 2022-04-19 19:06 UTC (permalink / raw)
To: u-boot; +Cc: marex, bmeng.cn, Mark Kettenis
When the device tree indicates support for role switching through
the "usb-role-switch" property, take the "role-switch-default-mode"
property into account when deciding which role to put the
controller into.
This makes USB devices work on Apple M1 systems where the device
tree may include a "dr_mode" property that is set to "otg", but
where we need to put the controller into "host" mode to see
devices connected to the type-C ports.
Signed-off-by: Mark Kettenis <kettenis@openbsd.org>
---
drivers/usb/common/common.c | 16 ++++++++++++++++
drivers/usb/host/xhci-dwc3.c | 6 ++++++
include/linux/usb/otg.h | 10 ++++++++++
3 files changed, 32 insertions(+)
diff --git a/drivers/usb/common/common.c b/drivers/usb/common/common.c
index ee0c064f1f..cff86a51ae 100644
--- a/drivers/usb/common/common.c
+++ b/drivers/usb/common/common.c
@@ -40,6 +40,22 @@ enum usb_dr_mode usb_get_dr_mode(ofnode node)
return USB_DR_MODE_UNKNOWN;
}
+enum usb_dr_mode usb_get_role_switch_default_mode(ofnode node)
+{
+ const char *dr_mode;
+ int i;
+
+ dr_mode = ofnode_read_string(node, "role-switch-default-mode");
+ if (!dr_mode)
+ return USB_DR_MODE_UNKNOWN;
+
+ for (i = 0; i < ARRAY_SIZE(usb_dr_modes); i++)
+ if (!strcmp(dr_mode, usb_dr_modes[i]))
+ return i;
+
+ return USB_DR_MODE_UNKNOWN;
+}
+
static const char *const speed_names[] = {
[USB_SPEED_UNKNOWN] = "UNKNOWN",
[USB_SPEED_LOW] = "low-speed",
diff --git a/drivers/usb/host/xhci-dwc3.c b/drivers/usb/host/xhci-dwc3.c
index bec0d98081..1dbd65dfaa 100644
--- a/drivers/usb/host/xhci-dwc3.c
+++ b/drivers/usb/host/xhci-dwc3.c
@@ -209,6 +209,12 @@ static int xhci_dwc3_probe(struct udevice *dev)
writel(reg, &dwc3_reg->g_usb2phycfg[0]);
dr_mode = usb_get_dr_mode(dev_ofnode(dev));
+ if (dr_mode == USB_DR_MODE_OTG &&
+ dev_read_bool(dev, "usb-role-switch")) {
+ dr_mode = usb_get_role_switch_default_mode(dev_ofnode(dev));
+ if (dr_mode == USB_DR_MODE_UNKNOWN)
+ dr_mode = USB_DR_MODE_OTG;
+ }
if (dr_mode == USB_DR_MODE_UNKNOWN)
/* by default set dual role mode to HOST */
dr_mode = USB_DR_MODE_HOST;
diff --git a/include/linux/usb/otg.h b/include/linux/usb/otg.h
index c19b916be9..5d0dac950e 100644
--- a/include/linux/usb/otg.h
+++ b/include/linux/usb/otg.h
@@ -27,6 +27,16 @@ enum usb_dr_mode {
*/
enum usb_dr_mode usb_get_dr_mode(ofnode node);
+/**
+ * usb_get_dr_mode() - Get dual role mode for given device
+ * @node: ofnode of the given device
+ *
+ * The function gets phy interface string from property
+ * 'role-switch-defaulr-mode', and returns the correspondig enum
+ * usb_dr_mode
+ */
+enum usb_dr_mode usb_get_role_switch_default_mode(ofnode node);
+
/**
* usb_get_maximum_speed() - Get maximum speed for given device
* @node: ofnode of the given device
--
2.35.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] usb: xhci-dwc3: Support role switch default role
2022-04-19 19:06 [PATCH] usb: xhci-dwc3: Support role switch default role Mark Kettenis
@ 2022-05-10 12:49 ` Mark Kettenis
0 siblings, 0 replies; 2+ messages in thread
From: Mark Kettenis @ 2022-05-10 12:49 UTC (permalink / raw)
To: Mark Kettenis; +Cc: u-boot, marex, bmeng.cn, kettenis
> From: Mark Kettenis <kettenis@openbsd.org>
> Date: Tue, 19 Apr 2022 21:06:33 +0200
>
> When the device tree indicates support for role switching through
> the "usb-role-switch" property, take the "role-switch-default-mode"
> property into account when deciding which role to put the
> controller into.
>
> This makes USB devices work on Apple M1 systems where the device
> tree may include a "dr_mode" property that is set to "otg", but
> where we need to put the controller into "host" mode to see
> devices connected to the type-C ports.
>
> Signed-off-by: Mark Kettenis <kettenis@openbsd.org>
> ---
> drivers/usb/common/common.c | 16 ++++++++++++++++
> drivers/usb/host/xhci-dwc3.c | 6 ++++++
> include/linux/usb/otg.h | 10 ++++++++++
> 3 files changed, 32 insertions(+)
Ping?
> diff --git a/drivers/usb/common/common.c b/drivers/usb/common/common.c
> index ee0c064f1f..cff86a51ae 100644
> --- a/drivers/usb/common/common.c
> +++ b/drivers/usb/common/common.c
> @@ -40,6 +40,22 @@ enum usb_dr_mode usb_get_dr_mode(ofnode node)
> return USB_DR_MODE_UNKNOWN;
> }
>
> +enum usb_dr_mode usb_get_role_switch_default_mode(ofnode node)
> +{
> + const char *dr_mode;
> + int i;
> +
> + dr_mode = ofnode_read_string(node, "role-switch-default-mode");
> + if (!dr_mode)
> + return USB_DR_MODE_UNKNOWN;
> +
> + for (i = 0; i < ARRAY_SIZE(usb_dr_modes); i++)
> + if (!strcmp(dr_mode, usb_dr_modes[i]))
> + return i;
> +
> + return USB_DR_MODE_UNKNOWN;
> +}
> +
> static const char *const speed_names[] = {
> [USB_SPEED_UNKNOWN] = "UNKNOWN",
> [USB_SPEED_LOW] = "low-speed",
> diff --git a/drivers/usb/host/xhci-dwc3.c b/drivers/usb/host/xhci-dwc3.c
> index bec0d98081..1dbd65dfaa 100644
> --- a/drivers/usb/host/xhci-dwc3.c
> +++ b/drivers/usb/host/xhci-dwc3.c
> @@ -209,6 +209,12 @@ static int xhci_dwc3_probe(struct udevice *dev)
> writel(reg, &dwc3_reg->g_usb2phycfg[0]);
>
> dr_mode = usb_get_dr_mode(dev_ofnode(dev));
> + if (dr_mode == USB_DR_MODE_OTG &&
> + dev_read_bool(dev, "usb-role-switch")) {
> + dr_mode = usb_get_role_switch_default_mode(dev_ofnode(dev));
> + if (dr_mode == USB_DR_MODE_UNKNOWN)
> + dr_mode = USB_DR_MODE_OTG;
> + }
> if (dr_mode == USB_DR_MODE_UNKNOWN)
> /* by default set dual role mode to HOST */
> dr_mode = USB_DR_MODE_HOST;
> diff --git a/include/linux/usb/otg.h b/include/linux/usb/otg.h
> index c19b916be9..5d0dac950e 100644
> --- a/include/linux/usb/otg.h
> +++ b/include/linux/usb/otg.h
> @@ -27,6 +27,16 @@ enum usb_dr_mode {
> */
> enum usb_dr_mode usb_get_dr_mode(ofnode node);
>
> +/**
> + * usb_get_dr_mode() - Get dual role mode for given device
> + * @node: ofnode of the given device
> + *
> + * The function gets phy interface string from property
> + * 'role-switch-defaulr-mode', and returns the correspondig enum
> + * usb_dr_mode
> + */
> +enum usb_dr_mode usb_get_role_switch_default_mode(ofnode node);
> +
> /**
> * usb_get_maximum_speed() - Get maximum speed for given device
> * @node: ofnode of the given device
> --
> 2.35.1
>
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-05-10 12:49 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-19 19:06 [PATCH] usb: xhci-dwc3: Support role switch default role Mark Kettenis
2022-05-10 12:49 ` Mark Kettenis
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.