Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp5306825rwi; Mon, 17 Oct 2022 19:17:09 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6RUSGzg1kxaqN3eqO9rFDkTIVLsVeyaI4alfMgqBk1OdXfEeLm81mTi3ynRR4e8yyXRC80 X-Received: by 2002:a17:907:760c:b0:78d:b37f:5ce4 with SMTP id jx12-20020a170907760c00b0078db37f5ce4mr527176ejc.50.1666059429087; Mon, 17 Oct 2022 19:17:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666059429; cv=none; d=google.com; s=arc-20160816; b=p8ZmDowOsO4kPn9+inagDGhdY8cqRghPTwMid7BwHJwtsUn4N8TOHZMjQYmzdSTbBd TGQknwlMbPf9BEblgOuU5hAynA3P9Qvk/r0gcIq30VMtrlM1qI4ROyj3PpnqwARjUt+I FnYcb9LnnRwYzjeyKv5wiN2cxhJhH0wzl3nTEHYcNlaonr9d50WXQYCl8VR0LwwwkG/C MTtv07k9YtbbdJgv5WdPg+YiofcOpBF2AkP3tm9CaMWeUVtivcaFCBMXpBXjp0xv3VQy YNPctWa6CAz/B8r7GyHVb6Z0Yd/Qlvkr5SWQZcTKX2G+V3W1J34fHFks9XdTjQsxCvus AOSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=RPr95JmTZyyYVeLmfyOCTRL73nJAu3g8auu0MHNBHp4=; b=TXkBFTZ7YV7QFN+vG/iqxQDBgV+uG/+76GtbsfdaTAcN526qGoWUvu2GhOpIz+aMGX +dM6LtI+fZYXYKPRJ7dtaOt67R2HliPbl2POkzA+60PPUYePtqzpZe2XWz/jXLBQ+dnC IKh695N6KugvFUntPUW1vRizOz0FzejJOCJ6QHCM+t5/8OApZi5vi/9H1ZppoKu8XMJT j4yw49XUP8fvoj1HJQlJnPQ4XzQsEDlwyk47M0vqfn7qVz1yh3IsGd0W7DCUnnUngE86 pkJ4GN2Cht3howhX7ZZUwlFPnYTM0E5/yHvEYxOMzfX9pQsTWqe70gMjl5jVJEOSHNw6 p3qg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kali.org header.s=google header.b=MgI9kMCX; 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=kali.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b11-20020a056402084b00b0045b265a1712si12549505edz.595.2022.10.17.19.16.43; Mon, 17 Oct 2022 19:17:09 -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=@kali.org header.s=google header.b=MgI9kMCX; 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=kali.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231281AbiJRCHE (ORCPT + 99 others); Mon, 17 Oct 2022 22:07:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44264 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231277AbiJRCGr (ORCPT ); Mon, 17 Oct 2022 22:06:47 -0400 Received: from mail-oa1-x34.google.com (mail-oa1-x34.google.com [IPv6:2001:4860:4864:20::34]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 74BAF8C460 for ; Mon, 17 Oct 2022 19:05:52 -0700 (PDT) Received: by mail-oa1-x34.google.com with SMTP id 586e51a60fabf-1324e7a1284so15345075fac.10 for ; Mon, 17 Oct 2022 19:05:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kali.org; s=google; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=RPr95JmTZyyYVeLmfyOCTRL73nJAu3g8auu0MHNBHp4=; b=MgI9kMCXMFiIEdJjvVtVZ+Q/Ds/cbUyhGtsK/Jy7GJuMLk0LuWbQW39ZgspDZH8zWP vjXL8GR1VKyho4vpwuEKg1knkPuc7bfURtjHoUZ3L4zgMsY3yjfxmS9SRerEX7hBXuML 8UflCd4aOX2ZQkRgOXkcdMraVQnRcROfvU6chvifW4rrFK8O/3CgyZKITFak2wan4Xni FRYbjWVsKgLnnwlNWnAASCf1ZJa1zvLtSJPDfsu4TzLPJvdRkWMoMQXQubNHzrlJfrPx MWXapWTXbETWDoSTFv5iLgoYwM84B6NUL1Ddh23ZiJyf5F+z4eY2WghDQJljRFYWQIfH 4DeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=RPr95JmTZyyYVeLmfyOCTRL73nJAu3g8auu0MHNBHp4=; b=7N7nviKwUqgdbSWg+gUt+x+qCub/vprcLFd+CA8XCmFbgPvOtQOAC/OsnzDQCdB1mI ELgPzqhKmaLw39ucNkoyC6OPXGBLm3uzOy6U4hzp9+4QjRQwZ8lGhXnIVDfYxTXTfgq2 RwsysrGdiMMIj6G84W+ZezvLzg0/f6QeEbqNpsEZui2myX/Sh2ZQvuH32OLgOIekAoIJ 97aZlmbXZBwYWUJ/q50YiDCdgaHP9rE0or/5kaQx0eFJGNJz6IY56w9gqt82+L6aj/HW LZadJNp4fLJKgH7jx3B4ATKZ9CO89XgSdWmNdRTNqR0Uo/HbYSswkoWkUljDfH/olCxD Qnjg== X-Gm-Message-State: ACrzQf14dnoWcgTLiJ5pCPB08bdS0FXx8rY1gX3+zFc70kE3lS85F7aH lwX950Ay39r05xCbuhW2kL9GHw== X-Received: by 2002:a05:6870:2108:b0:132:f883:2378 with SMTP id f8-20020a056870210800b00132f8832378mr360890oae.77.1666058680760; Mon, 17 Oct 2022 19:04:40 -0700 (PDT) Received: from [192.168.11.16] (cpe-173-173-107-246.satx.res.rr.com. [173.173.107.246]) by smtp.gmail.com with ESMTPSA id w10-20020a056870a2ca00b00127ba61535fsm5547004oak.15.2022.10.17.19.04.39 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 17 Oct 2022 19:04:40 -0700 (PDT) Message-ID: <913b1eb9-8bf4-2c3a-b0bd-96975d338c8d@kali.org> Date: Mon, 17 Oct 2022 21:04:38 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.13.1 Subject: Re: [PATCH v1 1/1] usb: dwc3: Don't switch OTG -> peripheral if extcon is present Content-Language: en-US To: Andy Shevchenko , Greg Kroah-Hartman , Andrey Smirnov , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Thinh Nguyen References: <20221017233510.53336-1-andriy.shevchenko@linux.intel.com> From: Steev Klimaszewski In-Reply-To: <20221017233510.53336-1-andriy.shevchenko@linux.intel.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_NONE, 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 Hi Andy, On 10/17/22 6:35 PM, Andy Shevchenko wrote: > From: Andrey Smirnov > > If the extcon device exists, get the mode from the extcon device. If > the controller is DRD and the driver is unable to determine the mode, > only then default the dr_mode to USB_DR_MODE_PERIPHERAL. > > Reported-by: Steev Klimaszewski > Fixes: 7a84e7353e23 ("Revert "usb: dwc3: Don't switch OTG -> peripheral if extcon is present"") > Reviewed-by: Thinh Nguyen > Signed-off-by: Andrey Smirnov > Signed-off-by: Andy Shevchenko > --- > drivers/usb/dwc3/core.c | 49 +++++++++++++++++++++++++++++++++++++++- > drivers/usb/dwc3/drd.c | 50 ----------------------------------------- > 2 files changed, 48 insertions(+), 51 deletions(-) > > diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c > index ea51624461b5..c0e7c76dc5c8 100644 > --- a/drivers/usb/dwc3/core.c > +++ b/drivers/usb/dwc3/core.c > @@ -23,6 +23,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -85,7 +86,7 @@ static int dwc3_get_dr_mode(struct dwc3 *dwc) > * 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 && > + if (mode == USB_DR_MODE_OTG && !dwc->edev && > (!IS_ENABLED(CONFIG_USB_ROLE_SWITCH) || > !device_property_read_bool(dwc->dev, "usb-role-switch")) && > !DWC3_VER_IS_PRIOR(DWC3, 330A)) > @@ -1690,6 +1691,46 @@ static void dwc3_check_params(struct dwc3 *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) > + return extcon_get_extcon_dev(name); > + > + /* > + * 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; > @@ -1840,6 +1881,12 @@ static int dwc3_probe(struct platform_device *pdev) > goto err2; > } > > + dwc->edev = dwc3_get_extcon(dwc); > + if (IS_ERR(dwc->edev)) { > + ret = dev_err_probe(dwc->dev, PTR_ERR(dwc->edev), "failed to get extcon\n"); > + goto err3; > + } > + > ret = dwc3_get_dr_mode(dwc); > if (ret) > goto err3; > diff --git a/drivers/usb/dwc3/drd.c b/drivers/usb/dwc3/drd.c > index 8cad9e7d3368..039bf241769a 100644 > --- a/drivers/usb/dwc3/drd.c > +++ b/drivers/usb/dwc3/drd.c > @@ -8,7 +8,6 @@ > */ > > #include > -#include > #include > #include > #include > @@ -439,51 +438,6 @@ static int dwc3_drd_notifier(struct notifier_block *nb, > 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, > @@ -588,10 +542,6 @@ 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, Thank you for the quick fix! Confirmed that this works for me on my Lenovo Yoga C630 Tested-by: Steev Klimaszewski