Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp1499517rwb; Wed, 28 Sep 2022 20:30:42 -0700 (PDT) X-Google-Smtp-Source: AMsMyM77CbCoRSOdw5gyIBKP4PnxR8eR6QWvuwJs+RBriPeD7XgEehrBgef+ErTTYs/WcHSpXBBT X-Received: by 2002:a17:902:848e:b0:178:2773:12d0 with SMTP id c14-20020a170902848e00b00178277312d0mr1277032plo.166.1664422242624; Wed, 28 Sep 2022 20:30:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664422242; cv=none; d=google.com; s=arc-20160816; b=IbnmT1drbNY1pejxoAcz+V3onL9/8nTYLAwLFcL2IY2FXh31lnHCUKxwwcsk7oHOFy N2UftBWo1KqudhNj4RwnqLukRGfMhDyUNWqwh6d+5A74dTAG7PG001pLpUWsajuHNyra iLeMVjUSXLz6ge9OWwQ+5QQ42dlw8LFxWl1OWZKPZkJ02Nu6aQpVBfLaVL1iNCmkJbZx FIDKtFv+pk66WXvt6mY+ozg6J0ao8SKI8YGmI/TtKBmLLzMzSgi49aEIwXvMV9oiSEEz GyPOuM1ypveAFv0OU6FgsfQSx5oRmOXXKoepUtvs9xUAdUGIIBGQ1z5SOJdDcZUWKVvr D5aA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=GYfljbXoE6Tk4WZKsjAzhovTCQfBmAj2N2aZXhkbCOc=; b=HWOTIaCGY7Fv2b289cykmm4yWk8Gi4sE09iJmHKmWFQbIvNg5JMT6Hsq5XEAD3jX+N jpiRboDnEE8v3FcVM4+h9IzUxJXnnqcHuhYB4MsovHAt5986lMn1ozow7+OTsx9cNoTE iBrCKM7OGG3Pxmna5k7nL+zfCfuptQbyjwFyL+0petuciRjsJ4FTI3M9/al91EldZzWc yOhcQyILrUMOrtUHsPnNCONC2ZvxCFHggsj3uVdlNUGUrGrgtoQeiyHQnu1jhc3d+snk roSLy0Hkwgx07Q4XfMbNI4glmqb1uBX2bqWK2Q9+Shsh5DeRx+sU2hOQIhx/g+pJYUVP vnqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=cDVzgBE+; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r124-20020a632b82000000b00434c05007d5si7201586pgr.845.2022.09.28.20.30.30; Wed, 28 Sep 2022 20:30:42 -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=@gmail.com header.s=20210112 header.b=cDVzgBE+; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234640AbiI2DBm (ORCPT + 99 others); Wed, 28 Sep 2022 23:01:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48640 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234676AbiI2DB0 (ORCPT ); Wed, 28 Sep 2022 23:01:26 -0400 Received: from mail-ed1-x531.google.com (mail-ed1-x531.google.com [IPv6:2a00:1450:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E7783EDD24; Wed, 28 Sep 2022 20:01:24 -0700 (PDT) Received: by mail-ed1-x531.google.com with SMTP id 29so222374edv.7; Wed, 28 Sep 2022 20:01:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date; bh=GYfljbXoE6Tk4WZKsjAzhovTCQfBmAj2N2aZXhkbCOc=; b=cDVzgBE+7b+T9K6lwCnJryYRotZ0kEAXmaxodCvYUhoOlhxBVrygrNARmUPoTk30j8 skZwpjuvKmY5QBZ4wRW3xYzOb/ogPPhGlKuERho3cYP16XG7M1kGNgnTtdKDU0Ku0gKo w28fZnEDK4HDhJSGlMrwnpuMHmGzvGV567kWhUO1D0KPqg3aNvpWMGzJWd8vYVaf4ooS YqdnXFWClbMTpkD8b1WvoQ3MHf/sN9z7zVTAWbbeJj70wCeNnH3iww3mrgsflNDWBSr0 Il63nPCBQDu1aCbAuKnBZGmuoB8ZBEgKSB7S89fos5gPVLDxqceZkjJXfspV+6f8d30d beUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date; bh=GYfljbXoE6Tk4WZKsjAzhovTCQfBmAj2N2aZXhkbCOc=; b=m32FPiGF8BZu4tb53KNShVsBLqs0ZZkHWDzLeojF5SH9U8WxoQs7CRKjt9vdUudZhM jqb6bdKvQx6EdxgWXhn/V4fRfaZ7+SPs9pOGe2wNuSWeUCQHTs9ePgYeP4d99TJ11tfI OSQIpa3Zk/SYPFrKXHkF4OrK9g9zQfdEPsDf2DhrstDnVWaf19oUCUXAwTVW2zCcSUlS LNUPpt5IhwDy00eFnbr3OL2AZcUXuQBzy/CY4XrE3H+SFL381sTfkCBXXHQ6/LqZ5B2D FIHdWlQvr/R4UuIs195uR2zcSqTQUrKKw6cGxKJn7sgpiLsjHEJ7Ih8N9Mcg3AzTBww7 vrVQ== X-Gm-Message-State: ACrzQf3FV1ruMJTMhswAmEj3kco2dPyRPKaCB3jxs4lXehXndCIo9s85 vszfh4UfU/FSzY5vWb+tatZ8JHXNFvD7zqJrbme1zpW1 X-Received: by 2002:a05:6402:909:b0:435:a8b:5232 with SMTP id g9-20020a056402090900b004350a8b5232mr1109413edz.240.1664420483239; Wed, 28 Sep 2022 20:01:23 -0700 (PDT) MIME-Version: 1.0 References: <20220927155332.10762-1-andriy.shevchenko@linux.intel.com> <20220927155332.10762-3-andriy.shevchenko@linux.intel.com> In-Reply-To: <20220927155332.10762-3-andriy.shevchenko@linux.intel.com> From: Andrey Smirnov Date: Wed, 28 Sep 2022 20:01:11 -0700 Message-ID: Subject: Re: [PATCH v2 2/2] Revert "usb: dwc3: Don't switch OTG -> peripheral if extcon is present" To: Sven Peter Cc: Greg Kroah-Hartman , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Felipe Balbi , Ferry Toth , stable@vger.kernel.org, Andy Shevchenko Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, 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 On Tue, Sep 27, 2022 at 8:53 AM Andy Shevchenko wrote: > > 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 Sven can you check that this also fixes the regression of your fix? > --- > drivers/usb/dwc3/core.c | 55 +---------------------------------------- > drivers/usb/dwc3/drd.c | 50 +++++++++++++++++++++++++++++++++++++ > 2 files changed, 51 insertions(+), 54 deletions(-) > > diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c > index c2b463469d51..219d797e2230 100644 > --- 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 *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 && !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 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) { > - 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_device *pdev) > 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; > diff --git a/drivers/usb/dwc3/drd.c b/drivers/usb/dwc3/drd.c > index 039bf241769a..8cad9e7d3368 100644 > --- 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 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, > @@ -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, > -- > 2.35.1 >