Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6DE90C433F5 for ; Tue, 10 May 2022 12:49:50 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 1BE0884284; Tue, 10 May 2022 14:49:48 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=xs4all.nl Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id E204C8429F; Tue, 10 May 2022 14:49:45 +0200 (CEST) Received: from sibelius.xs4all.nl (80-61-163-207.fixed.kpn.net [80.61.163.207]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id ECEF684128 for ; Tue, 10 May 2022 14:49:41 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=xs4all.nl Authentication-Results: phobos.denx.de; spf=fail smtp.mailfrom=mark.kettenis@xs4all.nl Received: from localhost (bloch.sibelius.xs4all.nl [local]) by bloch.sibelius.xs4all.nl (OpenSMTPD) with ESMTPA id 1aa59d7e; Tue, 10 May 2022 14:49:41 +0200 (CEST) Date: Tue, 10 May 2022 14:49:41 +0200 (CEST) From: Mark Kettenis To: Mark Kettenis Cc: u-boot@lists.denx.de, marex@denx.de, bmeng.cn@gmail.com, kettenis@openbsd.org In-Reply-To: <20220419190633.4514-1-kettenis@openbsd.org> (message from Mark Kettenis on Tue, 19 Apr 2022 21:06:33 +0200) Subject: Re: [PATCH] usb: xhci-dwc3: Support role switch default role References: <20220419190633.4514-1-kettenis@openbsd.org> Message-ID: X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.5 at phobos.denx.de X-Virus-Status: Clean > From: Mark Kettenis > 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 > --- > 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 > >