Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp1305747rwi; Thu, 13 Oct 2022 11:46:48 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7upUteChtp/kFPw3Rr5zUAMHYeyU2mGIn7VIbJHJ+zpSPM44yIXvoYBpYKGOHv1xMBN1EF X-Received: by 2002:a17:90b:3845:b0:20d:ad62:bba1 with SMTP id nl5-20020a17090b384500b0020dad62bba1mr1241856pjb.183.1665686808488; Thu, 13 Oct 2022 11:46:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665686808; cv=none; d=google.com; s=arc-20160816; b=imozt/aF4AkvSCAtp7B0h45dw8aTC23ye7uq6UvLU9h2Q2DHr2eZdt7DlR65kGGY+F YQe/Xwl6T+jWKyONIljL8Feb/pCgttjfycXB4vJqRUdDAE49cMMCzIJRgTIapVdllDCI njcINDXSf72Nb9WEw3eGp9QLKsmigWbi2Xxqm33U9kGAZNnTK9hhMGdWAAMRL7VFOCcS jXU68fdDcRWYFBUI2bMHt4qIEOJBu7sqerNYzIpQyTnOQmzl/cOvEz9GF2ekI7cjmfeZ xeYKB8Sh0XCgHmPqhHg8vnlGdvk+w6NcZJWxFZLB+CfaLYm3bM1ttLWSg06NhbxbQfkO tdMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=znolENb3OtJtDAeY815NZh8WFppW/rGTYOWAnDN9JDk=; b=uhK2Sit7fxhxslu36QsbUqvpU1VUxs+XOMYCmQBoi1p9MBR9gbzebKNubxnlxdVgIy J+Ta+rw2LHF5pW4PC7u1jOv7vOHuaDacootWYiSKG3806PeDQthppy9IEQJHS+lIml7q 8RfROjKmQLYJeSletzmIpSoO/tAg6PhkmPLTc3fm+SWpBo1l5XTPM2DItWf7CNPZHgxd yaBVg+j+SyXbSzHlU7i4SYncEQKS/r2OHv22xhUI4fhb0nOCtAo8GixXSeEN8wSgYQlB OW94g5LNxlLooWH8/7pb5cxS4QHL00Rc4SoeBm0aqPC0TS6Ue20M4TJLN1jdXu0lxo25 U+kA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=O9gJDOBD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f10-20020a056a00238a00b0051bbbc5f0aasi110810pfc.261.2022.10.13.11.46.36; Thu, 13 Oct 2022 11:46:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=O9gJDOBD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231235AbiJMSQ0 (ORCPT + 99 others); Thu, 13 Oct 2022 14:16:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58216 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232065AbiJMSOD (ORCPT ); Thu, 13 Oct 2022 14:14:03 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 88448C696D; Thu, 13 Oct 2022 11:10:22 -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 ams.source.kernel.org (Postfix) with ESMTPS id 79FA5B8208A; Thu, 13 Oct 2022 18:01:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D9EF4C43140; Thu, 13 Oct 2022 18:01:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1665684071; bh=zRDyqTsvfv0HYuMdDsaBuYunJJDtyf5HIeyATqjvbEk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=O9gJDOBD4FHzP9GWlfszoUveJmA2x9/JHGe3KQZpFBobpbEomu1PFkrfVyXmr913b feXcDZ1ChxEas1YjWxIHpuHIT4YjDqyPJ8FaH7LwGXENfvje7+okvt88ytWzkvRmMN fgwKmiiG3lXNBIE8zHyKdJCG4ZElE26XU+uM4haU= 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 6.0 16/34] Revert "usb: dwc3: Dont switch OTG -> peripheral if extcon is present" Date: Thu, 13 Oct 2022 19:52:54 +0200 Message-Id: <20221013175146.942398236@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221013175146.507746257@linuxfoundation.org> References: <20221013175146.507746257@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 is 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@linux.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 == USB_DR_MODE_OTG && !dwc->edev && + if (mode == 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)) @@ -1668,51 +1667,6 @@ static void dwc3_check_params(struct dwc } } -static struct extcon_dev *dwc3_get_extcon(struct dwc3 *dwc) -{ - struct device *dev = dwc->dev; - struct device_node *np_phy; - struct extcon_dev *edev = 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) == 0) { - edev = 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 = of_parse_phandle(dev->of_node, "phys", 0); - if (of_graph_is_present(np_phy)) { - struct device_node *np_conn; - - np_conn = of_graph_get_remote_node(np_phy, -1, -1); - if (np_conn) - edev = 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 = &pdev->dev; @@ -1849,13 +1803,6 @@ static int dwc3_probe(struct platform_de goto err2; } - dwc->edev = dwc3_get_extcon(dwc); - if (IS_ERR(dwc->edev)) { - ret = PTR_ERR(dwc->edev); - dev_err_probe(dwc->dev, ret, "failed to get extcon\n"); - goto err3; - } - ret = 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 @@ */ #include +#include #include #include #include @@ -438,6 +439,51 @@ static int dwc3_drd_notifier(struct noti return NOTIFY_DONE; } +static struct extcon_dev *dwc3_get_extcon(struct dwc3 *dwc) +{ + struct device *dev = dwc->dev; + struct device_node *np_phy; + struct extcon_dev *edev = 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) == 0) { + edev = 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 = of_parse_phandle(dev->of_node, "phys", 0); + if (of_graph_is_present(np_phy)) { + struct device_node *np_conn; + + np_conn = of_graph_get_remote_node(np_phy, -1, -1); + if (np_conn) + edev = 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); + dwc->edev = dwc3_get_extcon(dwc); + if (IS_ERR(dwc->edev)) + return PTR_ERR(dwc->edev); + if (dwc->edev) { dwc->edev_nb.notifier_call = dwc3_drd_notifier; ret = extcon_register_notifier(dwc->edev, EXTCON_USB_HOST,