Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp4682177ybb; Tue, 24 Mar 2020 03:23:21 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvd4rqutDEAU5DRQ4B10YNMSdXWcBukt/x2GdGKgcpxyonjAyPL8AxUHIKKy+nfwBG2ntGM X-Received: by 2002:a05:6830:2415:: with SMTP id j21mr21281809ots.93.1585045401390; Tue, 24 Mar 2020 03:23:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585045401; cv=none; d=google.com; s=arc-20160816; b=gZm7D0+IXgI5N6k/nubg6XMfw53PxB3PNlyWu3dCQNluy0QOGng0GaypVZ7M8aj7Se PdZggvcplCpCcHR5YQ1H2255T/t9BvjgW5d3hLsQEUIbMCQ9w7JDEmSpMp+gJf24A/LV fa9y9avlcng3SXBM73+UmfXUxJ/uy9pCgb5RuHivZIvheFA8FptsblJ/gu5c9Lb3XtId 7BzeR5d5fMCpBBSX9UNwp+qSL/tB91UeElNoMGVK9if8Z3c9ZaDyoIaGjZFUyFurlHS0 LjvlP/SRVxZjYJm0BFiO09zNV9RWgOsve/Qfa5ViZyHezemNR3Mo/Gzet2iMvj9AkJFV B+Og== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=LAt+HdDto2gFeGUw4ztWf5Rpdip/FjGrs7cpqwQNhSQ=; b=1GwckLg9qJyFY0w0JYfvuUON07BNatx0IWzrt8RensxdIxzLibg6oufK2rAKC4zxRo /lYlN7qjls/EZ0vEjSJVmQzBaZpw7j9E9wiMSW1q8IoVzv2Y5poK/3VOYaKnh33jvdDi bFDTbAWIrzJb5YBtyNXTSLuS6BRwf2cgB06cgQs2M3+6fbcxQDUJ71zOegBjwIvDcUUp 8f5ck4hTHhA00NblkMdtmF6MNS0joIr0Ys1eOwK3WOfRZ/XdK4mXLbahezTB7Cw0dbF5 6dICBFK/iA8RX+BOpSMPORf+pSvB1AcwrI5Ph0LSXW9R86HOsH6j7Ep9xuVkFIUUnPCs k7Gw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=r3YYIIXW; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f82si7331525oia.58.2020.03.24.03.23.08; Tue, 24 Mar 2020 03:23:21 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=r3YYIIXW; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727556AbgCXKVV (ORCPT + 99 others); Tue, 24 Mar 2020 06:21:21 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:50874 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727402AbgCXKUt (ORCPT ); Tue, 24 Mar 2020 06:20:49 -0400 Received: by mail-wm1-f67.google.com with SMTP id d198so2551197wmd.0 for ; Tue, 24 Mar 2020 03:20:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=LAt+HdDto2gFeGUw4ztWf5Rpdip/FjGrs7cpqwQNhSQ=; b=r3YYIIXWo1CNzzCPPmO7j+2H6A7TCKHz2xQF9BT6aNiJNQ8RnNBzd1UxrAJccxqmmk krIOaubpkJtZtcEKW8weSa+9ZCtrw01enYSCqjI96lWPli3kDnvRBiosdpVYa4j4IYoQ VmvuGozP58hTOxpei3Y8J+b1AJuh3hd3s4ZsGeeCGGFlYtkZrv75/eV2NY3moeurf8uy ARM+QHrd8igOo7/Z3ZAgte1CJeEdhrm4ne90Gb5CMhkoNRYulqj2hnZrtUCtQ2PfAztS 7yks/oclmXesLLhZyFAvyAhKM7HxS1KuICQXwpPx5ASEhBmLm99Pu4ux4DBCreOCuEfR ktOA== 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:mime-version:content-transfer-encoding; bh=LAt+HdDto2gFeGUw4ztWf5Rpdip/FjGrs7cpqwQNhSQ=; b=RB4CA/q8cOPbrQ3YMBj2wdC6g9HzKbWBYDcC33ZUpPG/RfPuwhM0/Xc+LEj2J5EEtX NK80CzurxiX5mhNyNXAdQvnzAtE5u5m8aWXT3X7r2zV5LxlEPwcIoZk+cwoGhqnrr5UT 5SFU2B3OwopN9nhGq1HYxpSfmLzFXAVfqRKDiaFqwb/xrZxpwOda5kvMrhaavC80cBNO 75pNUUYokguIgXaHj0ugE4HUZ0uTlOcSOOd8tXWk5QKWaECTk2eNCM/RUR0zq2dp77pL sVStI52SDidrsDOOMxVo6v2yUyOgcJQYbMaSUpubjVWcqSdCb6d1onbASs4mOejIWH6N sVeQ== X-Gm-Message-State: ANhLgQ32YX5/PkASbUzl4zo8RIQWliCDvZ4pEWLpyFgzd44JjBB18gzU 2by6sCvz4NzGm8jqH8W8ibfL+WdLh0ueEg== X-Received: by 2002:a05:600c:1:: with SMTP id g1mr4434252wmc.49.1585045247270; Tue, 24 Mar 2020 03:20:47 -0700 (PDT) Received: from bender.baylibre.local ([2a01:e35:2ec0:82b0:5c5f:613e:f775:b6a2]) by smtp.gmail.com with ESMTPSA id h5sm2879527wro.83.2020.03.24.03.20.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Mar 2020 03:20:46 -0700 (PDT) From: Neil Armstrong To: kishon@ti.com, balbi@kernel.org, khilman@baylibre.com, martin.blumenstingl@googlemail.com Cc: Neil Armstrong , linux-amlogic@lists.infradead.org, linux-usb@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 07/13] usb: dwc3: meson-g12a: support the GXL/GXM DWC3 host phy disconnect Date: Tue, 24 Mar 2020 11:20:24 +0100 Message-Id: <20200324102030.31000-8-narmstrong@baylibre.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20200324102030.31000-1-narmstrong@baylibre.com> References: <20200324102030.31000-1-narmstrong@baylibre.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On the Amlogic GXL/GXM SoCs, the OTG PHY status signals are always connected to the DWC3 controller, thus crashing the controller when switching to OTG mode when port is not populated with a device/cable to Host. Amlogic added a bit to disconnect the OTG PHY status signals from the DWC3 to be used when switching the OTG PHY as Device to the DWC2 controller. The drawback is that it makes the DWC3 port state machine stall and needs a full reset of the DWC3 controller to get connect status to the port connected to the OTG PHY, but not the other one. Signed-off-by: Neil Armstrong --- drivers/usb/dwc3/dwc3-meson-g12a.c | 34 ++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/drivers/usb/dwc3/dwc3-meson-g12a.c b/drivers/usb/dwc3/dwc3-meson-g12a.c index 65c220b577d0..04ef70661711 100644 --- a/drivers/usb/dwc3/dwc3-meson-g12a.c +++ b/drivers/usb/dwc3/dwc3-meson-g12a.c @@ -123,6 +123,7 @@ struct dwc3_meson_g12a; struct dwc3_meson_g12a_drvdata { bool otg_switch_supported; + bool otg_phy_host_port_disable; struct clk_bulk_data *clks; int num_clks; const char **phy_names; @@ -147,6 +148,19 @@ static int dwc3_meson_g12a_set_phy_mode(struct dwc3_meson_g12a *priv, static int dwc3_meson_g12a_usb_init(struct dwc3_meson_g12a *priv); +/* + * For GXL and GXM SoCs: + * USB Phy muxing between the DWC2 Device controller and the DWC3 Host + * controller is buggy when switching from Device to Host when USB port + * is unpopulated, it causes the DWC3 to hard crash. + * When populated (including OTG switching with ID pin), the switch works + * like a charm like on the G12A platforms. + * In order to still switch from Host to Device on an USB Type-A port, + * an U2_PORT_DISABLE bit has been added to disconnect the DWC3 Host + * controller from the port, but when used the DWC3 controller must be + * reset to recover usage of the port. + */ + static struct dwc3_meson_g12a_drvdata g12a_drvdata = { .otg_switch_supported = true, .clks = meson_g12a_clocks, @@ -282,6 +296,13 @@ static void dwc3_meson_g12a_usb_otg_apply_mode(struct dwc3_meson_g12a *priv, enum phy_mode mode) { if (mode == PHY_MODE_USB_DEVICE) { + if (priv->otg_mode != USB_DR_MODE_OTG && + priv->drvdata->otg_phy_host_port_disable) + /* Isolate the OTG PHY port from the Host Controller */ + regmap_update_bits(priv->usb_glue_regmap, USB_R1, + USB_R1_U3H_HOST_U2_PORT_DISABLE_MASK, + FIELD_PREP(USB_R1_U3H_HOST_U2_PORT_DISABLE_MASK, + BIT(USB2_OTG_PHY))); regmap_update_bits(priv->usb_glue_regmap, USB_R0, USB_R0_U2D_ACT, USB_R0_U2D_ACT); regmap_update_bits(priv->usb_glue_regmap, USB_R0, @@ -289,6 +310,12 @@ static void dwc3_meson_g12a_usb_otg_apply_mode(struct dwc3_meson_g12a *priv, regmap_update_bits(priv->usb_glue_regmap, USB_R4, USB_R4_P21_SLEEP_M0, USB_R4_P21_SLEEP_M0); } else { + if (priv->otg_mode != USB_DR_MODE_OTG && + priv->drvdata->otg_phy_host_port_disable) { + regmap_update_bits(priv->usb_glue_regmap, USB_R1, + USB_R1_U3H_HOST_U2_PORT_DISABLE_MASK, 0); + msleep(500); + } regmap_update_bits(priv->usb_glue_regmap, USB_R0, USB_R0_U2D_ACT, 0); regmap_update_bits(priv->usb_glue_regmap, USB_R4, @@ -421,6 +448,13 @@ static int dwc3_meson_g12a_role_set(struct device *dev, enum usb_role role) if (mode == priv->otg_phy_mode) return 0; + if (priv->drvdata->otg_phy_host_port_disable) + dev_warn_once(priv->dev, "Manual OTG switch is broken on this "\ + "SoC, when manual switching from "\ + "Host to device, DWC3 controller "\ + "will need to be resetted in order "\ + "to recover usage of the Host port"); + return dwc3_meson_g12a_otg_mode_set(priv, mode); } -- 2.22.0