From patchwork Tue Apr 19 19:06:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Kettenis X-Patchwork-Id: 1619206 X-Patchwork-Delegate: bmeng.cn@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=kpnmail.nl header.i=@kpnmail.nl header.a=rsa-sha256 header.s=kpnmail01 header.b=QXXXbBJn; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KjYFf2bKXz9sBJ for ; Wed, 20 Apr 2022 05:07:02 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id AA6ED83C13; Tue, 19 Apr 2022 21:06:53 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=openbsd.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; secure) header.d=kpnmail.nl header.i=@kpnmail.nl header.b="QXXXbBJn"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 45F5083C11; Tue, 19 Apr 2022 21:06:52 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_SOFTFAIL,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 Received: from ewsoutbound.kpnmail.nl (ewsoutbound.kpnmail.nl [195.121.94.185]) (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 5978B83C13 for ; Tue, 19 Apr 2022 21:06:49 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=openbsd.org Authentication-Results: phobos.denx.de; spf=fail smtp.mailfrom=kettenis@openbsd.org X-KPN-MessageId: acbf91a5-c013-11ec-b4ce-005056999439 Received: from smtp.kpnmail.nl (unknown [10.31.155.6]) by ewsoutbound.so.kpn.org (Halon) with ESMTPS id acbf91a5-c013-11ec-b4ce-005056999439; Tue, 19 Apr 2022 21:05:27 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kpnmail.nl; s=kpnmail01; h=mime-version:message-id:date:subject:to:from; bh=yD4I6gUdOe0gcSkoRt1Gdo6k+v+mx1cSn3xQ8MmIlvY=; b=QXXXbBJnS/qZ/1PIjimlSkAJTZSfGw6za/SmvU8DNbbHK7SaAh+o8hD+6Zk4sjXZmnGDOUY1O++lq UOq/v5ayFh/bJj74uX788V51Y4HT+CAMaWpcN2Ez1ooE46Mk+APuPQafbXHl3Uu9cYNJWjFkyNXQT/ 2JUIG8l4pXi/PEc0= X-KPN-MID: 33|8BFeHsILHlOefsGPP1MwMerrKKd9ewFNr+qxhbc/PTRP4xmvh7js1D9bUySqAwK a5Zp216Q+16qmyqG8bz6344RE4twILiV02vIqxO3Iz50= X-KPN-VerifiedSender: No X-CMASSUN: 33|ySS9BaKn0lccOrEdKeoyDu+Hu+J1l8z+NkslAbur71FxWtq7N+5uEk2hcTViLu8 fZ56JwMsrpfAGhkddOdoX5A== X-Originating-IP: 80.61.163.207 Received: from copland.sibelius.xs4all.nl (80-61-163-207.fixed.kpn.net [80.61.163.207]) by smtp.xs4all.nl (Halon) with ESMTPSA id db610811-c013-11ec-b208-00505699772e; Tue, 19 Apr 2022 21:06:46 +0200 (CEST) From: Mark Kettenis To: u-boot@lists.denx.de Cc: marex@denx.de, bmeng.cn@gmail.com, Mark Kettenis Subject: [PATCH] usb: xhci-dwc3: Support role switch default role Date: Tue, 19 Apr 2022 21:06:33 +0200 Message-Id: <20220419190633.4514-1-kettenis@openbsd.org> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 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 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(+) 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