From nobody Fri Dec 19 19:07:41 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C8C2FC433FE for ; Thu, 13 Oct 2022 18:07:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231552AbiJMSHL (ORCPT ); Thu, 13 Oct 2022 14:07:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58142 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231249AbiJMSDx (ORCPT ); Thu, 13 Oct 2022 14:03:53 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A0E78152C45; Thu, 13 Oct 2022 11:03:39 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 177F561950; Thu, 13 Oct 2022 18:00:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 23272C433D6; Thu, 13 Oct 2022 18:00:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1665684043; bh=dAi356NZYKsu2332PoP+xSDiNtF2zzin39/QY3Yol/8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ex3RTcvwDtEp2nkN0Y5bQMkeoy5vBc86AOr9Io3YrjfSHbdv4GKD81QFUkae3i0+E KhqU2DyboPBnyJXBVcT1tNyT7vRXusNfcXILvi2+3StrmrLdwF4Ntba4R3KIiISmx4 WNoy8eyM8tB51PYZJmnQZZtLasrRjJ9yaQXa1vlU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ferry Toth , Andy Shevchenko , Sven Peter Subject: [PATCH 5.19 15/33] Revert "usb: dwc3: Dont switch OTG -> peripheral if extcon is present" Date: Thu, 13 Oct 2022 19:52:47 +0200 Message-Id: <20221013175145.789903173@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221013175145.236739253@linuxfoundation.org> References: <20221013175145.236739253@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Andy Shevchenko commit 7a84e7353e23202d4f82b05093af4db2b26e6768 upstream. This reverts commit 0f01017191384e3962fa31520a9fd9846c3d352f. As pointed out by Ferry this breaks Dual Role support on Intel Merrifield platforms. Fixes: 0f0101719138 ("usb: dwc3: Don't switch OTG -> peripheral if extcon i= s present") Reported-by: Ferry Toth Cc: stable@vger.kernel.org Signed-off-by: Andy Shevchenko Tested-by: Ferry Toth # for Merrifield Reviewed-by: Sven Peter Link: https://lore.kernel.org/r/20220927155332.10762-3-andriy.shevchenko@li= nux.intel.com Signed-off-by: Greg Kroah-Hartman --- drivers/usb/dwc3/core.c | 55 -------------------------------------------= ----- drivers/usb/dwc3/drd.c | 50 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 54 deletions(-) --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -23,7 +23,6 @@ #include #include #include -#include #include #include #include @@ -86,7 +85,7 @@ static int dwc3_get_dr_mode(struct dwc3 * mode. If the controller supports DRD but the dr_mode is not * specified or set to OTG, then set the mode to peripheral. */ - if (mode =3D=3D USB_DR_MODE_OTG && !dwc->edev && + if (mode =3D=3D USB_DR_MODE_OTG && (!IS_ENABLED(CONFIG_USB_ROLE_SWITCH) || !device_property_read_bool(dwc->dev, "usb-role-switch")) && !DWC3_VER_IS_PRIOR(DWC3, 330A)) @@ -1634,51 +1633,6 @@ static void dwc3_check_params(struct dwc } } =20 -static struct extcon_dev *dwc3_get_extcon(struct dwc3 *dwc) -{ - struct device *dev =3D dwc->dev; - struct device_node *np_phy; - struct extcon_dev *edev =3D NULL; - const char *name; - - if (device_property_read_bool(dev, "extcon")) - return extcon_get_edev_by_phandle(dev, 0); - - /* - * Device tree platforms should get extcon via phandle. - * On ACPI platforms, we get the name from a device property. - * This device property is for kernel internal use only and - * is expected to be set by the glue code. - */ - if (device_property_read_string(dev, "linux,extcon-name", &name) =3D=3D 0= ) { - edev =3D extcon_get_extcon_dev(name); - if (!edev) - return ERR_PTR(-EPROBE_DEFER); - - return edev; - } - - /* - * Try to get an extcon device from the USB PHY controller's "port" - * node. Check if it has the "port" node first, to avoid printing the - * error message from underlying code, as it's a valid case: extcon - * device (and "port" node) may be missing in case of "usb-role-switch" - * or OTG mode. - */ - np_phy =3D of_parse_phandle(dev->of_node, "phys", 0); - if (of_graph_is_present(np_phy)) { - struct device_node *np_conn; - - np_conn =3D of_graph_get_remote_node(np_phy, -1, -1); - if (np_conn) - edev =3D extcon_find_edev_by_node(np_conn); - of_node_put(np_conn); - } - of_node_put(np_phy); - - return edev; -} - static int dwc3_probe(struct platform_device *pdev) { struct device *dev =3D &pdev->dev; @@ -1815,13 +1769,6 @@ static int dwc3_probe(struct platform_de goto err2; } =20 - dwc->edev =3D dwc3_get_extcon(dwc); - if (IS_ERR(dwc->edev)) { - ret =3D PTR_ERR(dwc->edev); - dev_err_probe(dwc->dev, ret, "failed to get extcon\n"); - goto err3; - } - ret =3D dwc3_get_dr_mode(dwc); if (ret) goto err3; --- a/drivers/usb/dwc3/drd.c +++ b/drivers/usb/dwc3/drd.c @@ -8,6 +8,7 @@ */ =20 #include +#include #include #include #include @@ -438,6 +439,51 @@ static int dwc3_drd_notifier(struct noti return NOTIFY_DONE; } =20 +static struct extcon_dev *dwc3_get_extcon(struct dwc3 *dwc) +{ + struct device *dev =3D dwc->dev; + struct device_node *np_phy; + struct extcon_dev *edev =3D NULL; + const char *name; + + if (device_property_read_bool(dev, "extcon")) + return extcon_get_edev_by_phandle(dev, 0); + + /* + * Device tree platforms should get extcon via phandle. + * On ACPI platforms, we get the name from a device property. + * This device property is for kernel internal use only and + * is expected to be set by the glue code. + */ + if (device_property_read_string(dev, "linux,extcon-name", &name) =3D=3D 0= ) { + edev =3D extcon_get_extcon_dev(name); + if (!edev) + return ERR_PTR(-EPROBE_DEFER); + + return edev; + } + + /* + * Try to get an extcon device from the USB PHY controller's "port" + * node. Check if it has the "port" node first, to avoid printing the + * error message from underlying code, as it's a valid case: extcon + * device (and "port" node) may be missing in case of "usb-role-switch" + * or OTG mode. + */ + np_phy =3D of_parse_phandle(dev->of_node, "phys", 0); + if (of_graph_is_present(np_phy)) { + struct device_node *np_conn; + + np_conn =3D of_graph_get_remote_node(np_phy, -1, -1); + if (np_conn) + edev =3D extcon_find_edev_by_node(np_conn); + of_node_put(np_conn); + } + of_node_put(np_phy); + + return edev; +} + #if IS_ENABLED(CONFIG_USB_ROLE_SWITCH) #define ROLE_SWITCH 1 static int dwc3_usb_role_switch_set(struct usb_role_switch *sw, @@ -542,6 +588,10 @@ int dwc3_drd_init(struct dwc3 *dwc) device_property_read_bool(dwc->dev, "usb-role-switch")) return dwc3_setup_role_switch(dwc); =20 + dwc->edev =3D dwc3_get_extcon(dwc); + if (IS_ERR(dwc->edev)) + return PTR_ERR(dwc->edev); + if (dwc->edev) { dwc->edev_nb.notifier_call =3D dwc3_drd_notifier; ret =3D extcon_register_notifier(dwc->edev, EXTCON_USB_HOST,