From patchwork Mon Oct 21 16:16:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Opaniuk X-Patchwork-Id: 11202657 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4954613BD for ; Mon, 21 Oct 2019 16:17:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1DAAE214B2 for ; Mon, 21 Oct 2019 16:17:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fJWoLzZ6" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728316AbfJUQRR (ORCPT ); Mon, 21 Oct 2019 12:17:17 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:39096 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726289AbfJUQRR (ORCPT ); Mon, 21 Oct 2019 12:17:17 -0400 Received: by mail-wm1-f66.google.com with SMTP id r141so3827187wme.4; Mon, 21 Oct 2019 09:17:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=jk6ZF8wcrRJTLUS9uAlYiz82fH05G0XIqpCiC2ocfFM=; b=fJWoLzZ6a+LlQjRWNuRitS+xH49t0zmke71CsU4929ekM46VTLeKMIxXvpEQhPB/vV 4ncBlWFH2k/kNXucS99pn0k24PF/LDoL/Z4Dvno9rEtmFXY4cErrUfR+rJaKbvMXtDJq aRErFriPnP5sJnCHxpovSWLyTbDnKpMQqZ9tUM7DxtepELbUlUeoCsU0et5DSuHksHpb EtR1rsYf2sBrjHI6LOT+KSXiMx1nuZ0cA1Abm2uoRL32Y4Ucy3KtD/MyUAQ4cqWRjnmF OQQdteO9bL/Iu0vBE2fy0J4mhuAlQWeLb3+FBa5WgLpIXXL2oOk538erIdzC/oAs6f48 HUzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=jk6ZF8wcrRJTLUS9uAlYiz82fH05G0XIqpCiC2ocfFM=; b=jF/YQw8kOIyNuFB58aPpKXccg4L7DaF06zrvMRYujGIeGEPpAi1QHQQDkzOrSV4Mot TzvyMVlrYHFBLpWxqrokIAl3VRGkeIIM46m+y0IVgOUgHzA2jI3CBQMON/4ALI0uSt12 udvX/XJXfbASITV8ZmbBrvuxeU8C9HnpGcYkwDo8uihVZrF1vwu9vACYtcnccSUKv8F+ B/lWn9vYpS4DNh7hT+2ITFDZh3ICbjVicAG0/B1Q7UP5nvLj2I8VB+O03VTrk7cX3N7V +ahwaY+2v50uszWUj1WckWyjvFACcv+eeeqpWk5aUqP5NxAk8Fc1xnhEG+WNno8bd1v7 CRtQ== X-Gm-Message-State: APjAAAV2bTKYzqW695mm/LU+51rCfJLTekYwXs/jsEoG4n1gPwdlJ1/b PsXsp45q2+ITl1MaqK70zOTcb13N6mI= X-Google-Smtp-Source: APXvYqygFPVbzSSqh3ZyVAIa/Dl8Di+XZC/dcgGcwvn0045pPG2FVsNEZizH7EjTqVyb/Kl7kBMPcA== X-Received: by 2002:a1c:dd06:: with SMTP id u6mr7987797wmg.109.1571674633421; Mon, 21 Oct 2019 09:17:13 -0700 (PDT) Received: from localhost ([194.105.145.90]) by smtp.gmail.com with ESMTPSA id a71sm14551087wme.11.2019.10.21.09.17.12 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 21 Oct 2019 09:17:12 -0700 (PDT) From: Igor Opaniuk To: linux-usb@vger.kernel.org Cc: Marcel Ziswiler , Philippe Schenker , Stefan Agner , Max Krummenacher , Oleksandr Suvorov , Sanchayan Maity , Igor Opaniuk , Greg Kroah-Hartman , Peter Chen , linux-kernel@vger.kernel.org Subject: [PATCH v1 1/2] usb: chipidea: use of extcon framework to work for non OTG case Date: Mon, 21 Oct 2019 19:16:53 +0300 Message-Id: <20191021161654.14353-1-igor.opaniuk@gmail.com> X-Mailer: git-send-email 2.17.1 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org From: Stefan Agner The existing usage of extcon in chipidea driver freezes the kernel presumably due to OTGSC register access. Prevent accessing any OTG registers for SoC with dual role devices but no true OTG support. Use the flag CI_HDRC_DUAL_ROLE_NOT_OTG for those devices and in case extcon is present, do the role switch using extcon only. Signed-off-by: Sanchayan Maity Signed-off-by: Stefan Agner Signed-off-by: Igor Opaniuk --- drivers/usb/chipidea/ci.h | 2 + drivers/usb/chipidea/core.c | 87 +++++++++++++++++++++++++++++++++---- 2 files changed, 80 insertions(+), 9 deletions(-) diff --git a/drivers/usb/chipidea/ci.h b/drivers/usb/chipidea/ci.h index cf9cc9402826..3a1a549ed39e 100644 --- a/drivers/usb/chipidea/ci.h +++ b/drivers/usb/chipidea/ci.h @@ -170,6 +170,7 @@ struct hw_bank { * @enabled_otg_timer_bits: bits of enabled otg timers * @next_otg_timer: next nearest enabled timer to be expired * @work: work for role changing + * @work_dr: work for role changing for non-OTG controllers * @wq: workqueue thread * @qh_pool: allocation pool for queue heads * @td_pool: allocation pool for transfer descriptors @@ -220,6 +221,7 @@ struct ci_hdrc { enum otg_fsm_timer next_otg_timer; struct usb_role_switch *role_switch; struct work_struct work; + struct work_struct work_dr; struct workqueue_struct *wq; struct dma_pool *qh_pool; diff --git a/drivers/usb/chipidea/core.c b/drivers/usb/chipidea/core.c index dce5db41501c..48ecc846735c 100644 --- a/drivers/usb/chipidea/core.c +++ b/drivers/usb/chipidea/core.c @@ -534,6 +534,46 @@ int hw_device_reset(struct ci_hdrc *ci) return 0; } +static void usb_roleswitch_workqueue(struct work_struct *work) +{ + struct ci_hdrc *ci = container_of(work, struct ci_hdrc, work_dr); + struct ci_hdrc_cable *id, *vbus; + int ret; + + pm_runtime_get_sync(ci->dev); + + id = &ci->platdata->id_extcon; + if (!IS_ERR(id->edev)) { + int new_role; + + ci_role_stop(ci); + hw_wait_phy_stable(); + + ret = extcon_get_state(id->edev, EXTCON_USB_HOST); + if (ret) { + new_role = CI_ROLE_HOST; + dev_info(ci->dev, "switching to host role\n"); + } else { + new_role = CI_ROLE_GADGET; + dev_info(ci->dev, "switching to gadget role\n"); + } + ci_role_start(ci, new_role); + } + + vbus = &ci->platdata->vbus_extcon; + if (!IS_ERR(vbus->edev)) { + ret = extcon_get_state(vbus->edev, EXTCON_USB); + if (ret) + usb_gadget_vbus_connect(&ci->gadget); + else + usb_gadget_vbus_disconnect(&ci->gadget); + } + + pm_runtime_put_sync(ci->dev); + + enable_irq(ci->irq); +} + static irqreturn_t ci_irq(int irq, void *data) { struct ci_hdrc *ci = data; @@ -593,10 +633,24 @@ static int ci_cable_notifier(struct notifier_block *nb, unsigned long event, struct ci_hdrc_cable *cbl = container_of(nb, struct ci_hdrc_cable, nb); struct ci_hdrc *ci = cbl->ci; - cbl->connected = event; - cbl->changed = true; + if (ci->platdata->flags & CI_HDRC_DUAL_ROLE_NOT_OTG) { + disable_irq_nosync(ci->irq); + + /* + * This notifier might get called twice in succession, + * once for the ID pin and once for the VBUS pin. Make + * sure we only disable irq in case we successfully add + * work to the work queue. + */ + if (!queue_work(system_power_efficient_wq, &ci->work_dr)) + enable_irq(ci->irq); + } else { + cbl->connected = event; + cbl->changed = true; + + ci_irq(ci->irq, ci); + } - ci_irq(ci->irq, ci); return NOTIFY_DONE; } @@ -765,6 +819,7 @@ static int ci_get_platdata(struct device *dev, ext_id = extcon_get_edev_by_phandle(dev, 1); if (IS_ERR(ext_id) && PTR_ERR(ext_id) != -ENODEV) return PTR_ERR(ext_id); + platdata->flags |= CI_HDRC_DUAL_ROLE_NOT_OTG; } cable = &platdata->vbus_extcon; @@ -1079,7 +1134,15 @@ static int ci_hdrc_probe(struct platform_device *pdev) ci_get_otg_capable(ci); + if (ci->platdata->flags & CI_HDRC_DUAL_ROLE_NOT_OTG) + INIT_WORK(&ci->work_dr, usb_roleswitch_workqueue); + + ret = ci_extcon_register(ci); + if (ret) + goto stop; + dr_mode = ci->platdata->dr_mode; + /* initialize role(s) before the interrupt is requested */ if (dr_mode == USB_DR_MODE_OTG || dr_mode == USB_DR_MODE_HOST) { ret = ci_hdrc_host_init(ci); @@ -1145,8 +1208,18 @@ static int ci_hdrc_probe(struct platform_device *pdev) if (!ci_otg_is_fsm_mode(ci)) { /* only update vbus status for peripheral */ - if (ci->role == CI_ROLE_GADGET) - ci_handle_vbus_change(ci); + if (dr_mode == USB_DR_MODE_PERIPHERAL) { + usb_gadget_vbus_connect(&ci->gadget); + } else if (ci->role == CI_ROLE_GADGET) { + struct ci_hdrc_cable *vbus = &ci->platdata->vbus_extcon; + + /* Use vbus state from extcon if provided */ + if (!IS_ERR(vbus->edev) && + extcon_get_state(vbus->edev, EXTCON_USB)) + usb_gadget_vbus_connect(&ci->gadget); + else + ci_handle_vbus_change(ci); + } ret = ci_role_start(ci, ci->role); if (ret) { @@ -1161,10 +1234,6 @@ static int ci_hdrc_probe(struct platform_device *pdev) if (ret) goto stop; - ret = ci_extcon_register(ci); - if (ret) - goto stop; - if (ci->supports_runtime_pm) { pm_runtime_set_active(&pdev->dev); pm_runtime_enable(&pdev->dev); From patchwork Mon Oct 21 16:16:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Opaniuk X-Patchwork-Id: 11202661 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7EB251515 for ; Mon, 21 Oct 2019 16:17:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5E386222C2 for ; Mon, 21 Oct 2019 16:17:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="NztH2lX/" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728570AbfJUQRS (ORCPT ); Mon, 21 Oct 2019 12:17:18 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:51994 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728305AbfJUQRR (ORCPT ); Mon, 21 Oct 2019 12:17:17 -0400 Received: by mail-wm1-f68.google.com with SMTP id q70so6833653wme.1; Mon, 21 Oct 2019 09:17:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=lkDRxLx0e64Dw8F83EKAXaoP6GxpGN0qeMyvz3hwbCs=; b=NztH2lX/cIvVrXrCMiwfb5TW5vyGJtlgX/seuc3mVoXS+8ENIlD59Yhxxj/C7aH6nc D+l9KX/juO+goIqOHhPocDMBmP6S0JVCbSCWIABAUsLNlkQHw9ii0yFiJpKtKYPm8u/7 VxSzHvKgHCei4sK4xixE4Ndh1b0yD4nfRgCS8xy9+a+zl9ZOM8DxmvVAixwpQaGhu8At uDqErRV911Yk4Q/tSfAeni6XtjJqhO18KQmOGl0FtMgK2lbDw4VYvWd0DXBCaV9O7wys qix7a+/+Gebgaqzv7lN9vZdHUw283LBYjW73y1J3olsct47xK4dec46+b/7LDAWCmZ0S 22+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=lkDRxLx0e64Dw8F83EKAXaoP6GxpGN0qeMyvz3hwbCs=; b=YNkqXxwijHdWzs+SrmaU8zukmYcgJr8L8a17hQ1QF5oMoyPf12+CsMWOqaGlizl/nV +oyoLLakcfFNPh54gRXDLUEpni4yEsC5qUSCHtc85RfHNWiv0fTC8JPUVZOrE1uR0ron Pf24/rhA/xExRkA1TowDs4YcMROsGpV523whTGgO+LBrkD8pMnEYL+W9VH3ukteDlhbN zpTr1aevF4aGBhcYKeJiSNQiyshNt26VRSk3zZ4+tlHs+qM3AP6YQKdy2qBgsezQ7TwR +SMwEOqYxxM/KqkQFHZoQIUEHOyRf7fMhYujAF84713RyWlfk2Zx8DEDQcr5O0TWeJUy Z0+A== X-Gm-Message-State: APjAAAW/HY5iJYtAKsNuvmRSDenJYLg6sIZ+VJEh9If+Zy1zhgivLdJP UyTZv7gfMFGx7vDL/K1RMgop498p0vI= X-Google-Smtp-Source: APXvYqz2VNVLwqP8eX2RHxP4bsTLipg6R6lxPysdf+/BDn6HVwxksnvhAJe3roQx/CZZZfh0pceirg== X-Received: by 2002:a05:600c:219:: with SMTP id 25mr6595987wmi.174.1571674634775; Mon, 21 Oct 2019 09:17:14 -0700 (PDT) Received: from localhost ([194.105.145.90]) by smtp.gmail.com with ESMTPSA id 79sm23848976wmb.7.2019.10.21.09.17.13 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 21 Oct 2019 09:17:14 -0700 (PDT) From: Igor Opaniuk To: linux-usb@vger.kernel.org Cc: Marcel Ziswiler , Philippe Schenker , Stefan Agner , Max Krummenacher , Oleksandr Suvorov , Igor Opaniuk , Fabio Estevam , Mark Rutland , NXP Linux Team , Pengutronix Kernel Team , Rob Herring , Sascha Hauer , Shawn Guo , devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 2/2] ARM: dts: colibri-imx6ull: add extcon for usbotg1 Date: Mon, 21 Oct 2019 19:16:54 +0300 Message-Id: <20191021161654.14353-2-igor.opaniuk@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191021161654.14353-1-igor.opaniuk@gmail.com> References: <20191021161654.14353-1-igor.opaniuk@gmail.com> Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org From: Igor Opaniuk Add extcon usb gpio configuration for support dual roles for usbotg1. USB host/gadget switching test (1. USB NIC emulation; 2. USB storage): [ 52.491957] ci_hdrc ci_hdrc.1: switching to gadget role [ 52.502911] mxs_phy 20c9000.usbphy: vbus is not valid [ 56.749160] using random self ethernet address [ 56.758637] using random host ethernet address [ 65.768968] usb0: HOST MAC 00:14:2d:ff:ff:fe [ 65.887980] usb0: MAC 00:14:2d:ff:ff:ff [ 66.294961] configfs-gadget gadget: high-speed config #1: c [ 78.741971] ci_hdrc ci_hdrc.1: switching to host role [ 78.747522] ci_hdrc ci_hdrc.1: EHCI Host Controller [ 78.790174] ci_hdrc ci_hdrc.1: new USB bus registered, assigned bus number 2 [ 78.868498] ci_hdrc ci_hdrc.1: USB 2.0 started, EHCI 1.00 Signed-off-by: Igor Opaniuk --- arch/arm/boot/dts/imx6ull-colibri-eval-v3.dtsi | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/arch/arm/boot/dts/imx6ull-colibri-eval-v3.dtsi b/arch/arm/boot/dts/imx6ull-colibri-eval-v3.dtsi index a78849fd2afa..988f1a800d5a 100644 --- a/arch/arm/boot/dts/imx6ull-colibri-eval-v3.dtsi +++ b/arch/arm/boot/dts/imx6ull-colibri-eval-v3.dtsi @@ -29,6 +29,14 @@ clock-frequency = <16000000>; }; + extcon_usbc_det: usbc_det { + compatible = "linux,extcon-usb-gpio"; + debounce = <25>; + id-gpio = <&gpio5 2 GPIO_ACTIVE_HIGH>; + pinctrl-names = "default"; + pinctrl-0 = <&pinctrl_snvs_usbc_det>; + }; + panel: panel { compatible = "edt,et057090dhu"; backlight = <&bl>; @@ -150,6 +158,7 @@ }; &usbotg1 { + extcon = <&extcon_usbc_det &extcon_usbc_det>; status = "okay"; };