From patchwork Wed Sep 16 12:57:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Fan X-Patchwork-Id: 312395 Delivered-To: patch@linaro.org Received: by 2002:a92:5ad1:0:0:0:0:0 with SMTP id b78csp415722ilg; Wed, 16 Sep 2020 05:33:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx5x2xFkTtowr00482QsJvMYCg7Ih6zgUBP780E5QRNnbB05H207jRxuJmMdjQk9ek3CAjP X-Received: by 2002:a17:906:2dd:: with SMTP id 29mr14508355ejk.31.1600259628790; Wed, 16 Sep 2020 05:33:48 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1600259628; cv=pass; d=google.com; s=arc-20160816; b=xE9D92O6jeztMAUssUwBQYa0P7Ylq39lz9Pi4BUs8ft8ifuIB/liUqjOINm8L+ilXL CgBDW/n8wzgpfyQ69rpLYRBV5ULUmx4YeuWbFtTSQIkPrccCsf1/+0V8RIlHS4ADntDR goLvzKfqSyCvbGB43wliX5xo+3GUdQf+4icxb5uB1BmottBjCBrY5JNNV9/Fv6Wq/fdF uS/XMB13cuKGN3zKh5e5vhp6yWjdiPB6FfeP2N6gV6br+dWI5czzcdAIEGXtQCzEyevv OfQwHRd0P1Ph79n3Vul1/mwp6WxkEE/IuumoAGVlHGCR0bBBIsEt4QlrlJ1bplEq+j2X TEig== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:mime-version :content-transfer-encoding:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=w3S+idgVjjXqNFwVGzux6yM0X6zOxt78yekRjf8rgBE=; b=Wje4LYQ9Q52hb+KumAEqtKNlT2Za7Cpqn5FQ/LKkXFA7nC7K4NCeGxYI0fWg1VeIoR rtQIXlZo0m09jflOHyObDDyez0ucMTy9gB2F2LTyI63Ljs1tB/Pwu2A01H4vcAid1Fw6 UZVYhDfGTRXIwFMgLfvENdmN/DU2xph8HgDBW+hGX3lL2DB3WKFR/EFga31ekyy6xmE5 Tp3qXhND3AQ3zrKSLARhVLxnWAw1f3EeEadEndP9MLTHUOhSvVx21MAkasTBltEe4zbl +7dHn09d3i905vqIC6klhy7JRaj6KJ9lKEOjlXuoeDZzDsNSt1uhIrk6qH1vkNTwQNC9 1p6g== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@nxp.com header.s=selector2 header.b=jRKGdh1C; arc=pass (i=1 spf=pass spfdomain=nxp.com dkim=pass dkdomain=nxp.com dmarc=pass fromdomain=nxp.com); spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id i19si11374387edy.150.2020.09.16.05.33.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Sep 2020 05:33:48 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@nxp.com header.s=selector2 header.b=jRKGdh1C; arc=pass (i=1 spf=pass spfdomain=nxp.com dkim=pass dkdomain=nxp.com dmarc=pass fromdomain=nxp.com); spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 9FC198237A; Wed, 16 Sep 2020 14:31:44 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=nxp.com header.i=@nxp.com header.b="jRKGdh1C"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id CFF008236C; Wed, 16 Sep 2020 14:31:37 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FORGED_SPF_HELO,MSGID_FROM_MTA_HEADER, SPF_HELO_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.2 Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on20620.outbound.protection.outlook.com [IPv6:2a01:111:f400:7d00::620]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id DA1C58235C for ; Wed, 16 Sep 2020 14:31:34 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=peng.fan@nxp.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Exd0sifN+v6Quq+Vr7OEujqxhbISCZXPZQ47dP0uB6Lb8jDAO1+luRdOppv4rk55DOXm+sXz477O4PPHRj7sr7oGLueaTjYckYvrV09gLnFIDMNQ6ROXJmDoLCHd/wD0hpPgGt2mZBHvM30c5H+QoSQpPK5GZl6YH3PoP9+UDX4kmjMxsMUAMVXk8aRtcnheOXcyqDl+0aH0Et2I2B/wMZZFwVhsVsnCfGLvsB9Z8jHw3hOS5Ol5g1f+uveal8vh7ocgAW4Q5EolFPMN6ncjcezdRkM964YMEfv4WETlKWkPRh8HM3bMx9BSXUQasVPHlsIMfNNm8xZ3gKouxRnKVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=w3S+idgVjjXqNFwVGzux6yM0X6zOxt78yekRjf8rgBE=; b=UzELr8e3iFZ9BYvee23x5sZ4jC4wrBWEGp3i8uERZeAJkzMoMxVF0hVncjMCvnVZ76yy4igqbPZOJ4grKUmQxR0zoq8KRpm+5hKAy0swb55Y9MFqiN69sx028Er6VwJDzEyodOKg8eoXZkXyMA2AGzwVmr0PLfmK6sdUE4U+2er3AgIxWeYaNzD0pukI2fBSi+nwlfrLweOr/+EPPf6nUAwblpI2+GPRQpJNhGQo9KruoEJj/4FAWm9uNMre1ogUxshX+X0wqVaaR8zkveO/K4adZDeRKcBKa0qCF43KiCbvtNF0fJe3qFl9NdZlx8il3dhMbqLQwQ6JQG6pB3wzgA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=w3S+idgVjjXqNFwVGzux6yM0X6zOxt78yekRjf8rgBE=; b=jRKGdh1CsRZgRGVDTLUadiGD+/cl0G4auWFug6e6J0W++fPDN0o5kSdbmt4t0LJyUnd/D3K3d7HM2uhzBepsiRAEbmc97gup0ZDjtc5DLjj8Gz7DTCT+oV8sGHF//XUUbxdOAdbsHcil3dAdPepdi9np5PJ/kUwL/LAWzD+Iq3M= Authentication-Results: denx.de; dkim=none (message not signed) header.d=none;denx.de; dmarc=none action=none header.from=nxp.com; Received: from DB6PR0402MB2760.eurprd04.prod.outlook.com (2603:10a6:4:a1::14) by DB3PR0402MB3915.eurprd04.prod.outlook.com (2603:10a6:8:e::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3370.17; Wed, 16 Sep 2020 12:31:33 +0000 Received: from DB6PR0402MB2760.eurprd04.prod.outlook.com ([fe80::39ff:13b4:4f28:1413]) by DB6PR0402MB2760.eurprd04.prod.outlook.com ([fe80::39ff:13b4:4f28:1413%10]) with mapi id 15.20.3370.019; Wed, 16 Sep 2020 12:31:33 +0000 From: peng.fan@nxp.com To: sbabic@denx.de, marex@denx.de Cc: uboot-imx@nxp.com, u-boot@lists.denx.de, Ye Li , Peng Fan Subject: [PATCH 11/13] usb: ehci-mx6: Fix usb type issue in DM driver Date: Wed, 16 Sep 2020 20:57:03 +0800 Message-Id: <20200916125705.4341-12-peng.fan@nxp.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200916125705.4341-1-peng.fan@nxp.com> References: <20200916125705.4341-1-peng.fan@nxp.com> X-ClientProxiedBy: SGBP274CA0023.SGPP274.PROD.OUTLOOK.COM (2603:1096:4:b0::35) To DB6PR0402MB2760.eurprd04.prod.outlook.com (2603:10a6:4:a1::14) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from linux-1xn6.ap.freescale.net (119.31.174.71) by SGBP274CA0023.SGPP274.PROD.OUTLOOK.COM (2603:1096:4:b0::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3391.13 via Frontend Transport; Wed, 16 Sep 2020 12:31:31 +0000 X-Mailer: git-send-email 2.28.0 X-Originating-IP: [119.31.174.71] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: e8208bb6-4420-4b23-c505-08d85a3c7255 X-MS-TrafficTypeDiagnostic: DB3PR0402MB3915: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4502; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: OVLqtraBm/nqOjMUKQ315rbxqhZ9jG0dXMUnJRtnufwe6rb+1g+vFtBibbkKOwTzgG23GZkgOluI7uDANdfPLtx+Zl0GrqKGbrR6J937f9nrdML9EXPh+PC2/R8NN/bGiOf4R+4HdmnozE6XQP0FGSoFYWkmYMv/Dl2BApmvIOVwxBO6CNMgLjw5HTK617uAOkg1w3qwdL9UKeISviRVuC7mZmG5Lm9kpyGWqNDHxtIlc/4JDIx74EBDLBUt+o6c+y0LS9DZqF2Efy9T1zDO0BcH6pcsD14i5hCXioXgoM2PSEOi+nod03AiInMC2/bx X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DB6PR0402MB2760.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(136003)(376002)(346002)(39860400002)(396003)(186003)(16526019)(6512007)(8936002)(54906003)(36756003)(6486002)(2906002)(1076003)(6506007)(478600001)(2616005)(956004)(5660300002)(6666004)(83380400001)(52116002)(316002)(86362001)(4326008)(26005)(66476007)(8676002)(9686003)(66946007)(66556008); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: ebT1gTO78dsScX4qjB72RmOICJ9IQO5wQwpdChbp8wS9zMKDad5PyJaalbbvXWkykn+nrHemt1tHvre3x3MZzC51aad1igHaeKi3M5K6o61NDI94GWBaM9LfkDLQ9bHz64imZt/+wbDnBlY47C4mySXLa8Saf/MQAbidO2ddd045AHeHeTbNddXGDace06+9pdoG2y02M6N8y4qYECetjqZRDVV84bx7+tJECfEjW7ysZDXWdZZWVdaAuPpzeLBTw8FwZctiCrjxt7+/z8EWRf53O0PCot8FVNTtWlHYt3jO5IzSN4NrYVhpTKgZXSR0AvKc8VtCV1i60DS02ygvqpa+KDoOxV6AvDPRTkpYFBvVg1+HA0jIxIi7VZJ7m6j3Wj17LzXyX2oNmvt9XiW3+WVKsQVf2e94BADgnxAbfBq0GpmEAl9mAat0KEyhJIC0AJP1UfWN1fsUCKFMvMjUEU6HqpgeWHIT0vdOiD9KpX2IdVtO2h5sYLxZqmp7Dcyi6op8h6udzIAU8PfVYKXHcLYWhKOpp/LMZcY4ILj5kDYMnvVgpxlMbAvTuS+lVWFGA+hGYo9lZREl2BmvSlXqEnMTV+C4qTqFmrEu+ks4V7qJMWZXtD6JN5Dey85b0xSHY+0s9eeN257Ckhxxc9dSpw== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: e8208bb6-4420-4b23-c505-08d85a3c7255 X-MS-Exchange-CrossTenant-AuthSource: DB6PR0402MB2760.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Sep 2020 12:31:33.8105 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: mCrKB8tZGyZ5qG1uN4bTgh9wIhNVrC4INAIeme9nftjJyA99BPmWbxw+y71VOMzkggA1/A59ibxtUGBwGs3Hzw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB3PR0402MB3915 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean From: Ye Li Currently the clocks and power of USB controller and USB PHY are both controlled by ehci-mx6 driver in device probe. However, the function "ehci_usb_ofdata_to_platdata" calls "ehci_usb_phy_mode" to access PHY registers when "dr_mode" is set to OTG, both "dr_mode" and "extcon" properties are not set in DTB. This may cause hang at accessing USB PHY registers if the power and clocks are not enabled. Change the usb type logic to more clear way: 1. plat->init_type: The requested USB mode type from uplayers 2. priv->init_type: The USB mode type specified by DTB or by the USB ID pin or by external controller like tcpc or GPIO. 3. If two init_type are not same, return failure. Align with non-DM driver. 4. USB PHY access is moved after power and clock enabled. Signed-off-by: Ye Li Signed-off-by: Peng Fan --- drivers/usb/host/ehci-mx6.c | 50 ++++++++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 14 deletions(-) -- 2.28.0 diff --git a/drivers/usb/host/ehci-mx6.c b/drivers/usb/host/ehci-mx6.c index 555a810953..7079750a93 100644 --- a/drivers/usb/host/ehci-mx6.c +++ b/drivers/usb/host/ehci-mx6.c @@ -510,6 +510,8 @@ int ehci_hcd_stop(int index) return 0; } #else +#define USB_INIT_UNKNOWN (USB_INIT_DEVICE + 1) + struct ehci_mx6_priv_data { struct ehci_ctrl ctrl; struct usb_ehci *ehci; @@ -589,7 +591,7 @@ int __weak board_ehci_usb_phy_mode(struct udevice *dev) static int ehci_usb_phy_mode(struct udevice *dev) { - struct usb_platdata *plat = dev_get_platdata(dev); + struct ehci_mx6_priv_data *priv = dev_get_priv(dev); void *__iomem addr = dev_read_addr_ptr(dev); void *__iomem phy_ctrl, *__iomem phy_status; const void *blob = gd->fdt_blob; @@ -630,18 +632,18 @@ static int ehci_usb_phy_mode(struct udevice *dev) val = readl(phy_ctrl); if (val & USBPHY_CTRL_OTG_ID) - plat->init_type = USB_INIT_DEVICE; + priv->init_type = USB_INIT_DEVICE; else - plat->init_type = USB_INIT_HOST; + priv->init_type = USB_INIT_HOST; } else if (is_mx7() || is_imx8mm() || is_imx8mn()) { phy_status = (void __iomem *)(addr + USBNC_PHY_STATUS_OFFSET); val = readl(phy_status); if (val & USBNC_PHYSTATUS_ID_DIG) - plat->init_type = USB_INIT_DEVICE; + priv->init_type = USB_INIT_DEVICE; else - plat->init_type = USB_INIT_HOST; + priv->init_type = USB_INIT_HOST; } else { return -EINVAL; } @@ -652,31 +654,39 @@ static int ehci_usb_phy_mode(struct udevice *dev) static int ehci_usb_ofdata_to_platdata(struct udevice *dev) { struct usb_platdata *plat = dev_get_platdata(dev); + struct ehci_mx6_priv_data *priv = dev_get_priv(dev); enum usb_dr_mode dr_mode; const struct fdt_property *extcon; extcon = fdt_get_property(gd->fdt_blob, dev_of_offset(dev), "extcon", NULL); if (extcon) { - plat->init_type = board_ehci_usb_phy_mode(dev); - - return 0; + priv->init_type = board_ehci_usb_phy_mode(dev); + goto check_type; } dr_mode = usb_get_dr_mode(dev->node); switch (dr_mode) { case USB_DR_MODE_HOST: - plat->init_type = USB_INIT_HOST; + priv->init_type = USB_INIT_HOST; break; case USB_DR_MODE_PERIPHERAL: - plat->init_type = USB_INIT_DEVICE; + priv->init_type = USB_INIT_DEVICE; break; case USB_DR_MODE_OTG: case USB_DR_MODE_UNKNOWN: - return ehci_usb_phy_mode(dev); + priv->init_type = USB_INIT_UNKNOWN; + break; }; +check_type: + if (priv->init_type != USB_INIT_UNKNOWN && priv->init_type != plat->init_type) { + debug("Request USB type is %u, board forced type is %u\n", + plat->init_type, priv->init_type); + return -ENODEV; + } + return 0; } @@ -741,9 +751,9 @@ static int ehci_usb_probe(struct udevice *dev) priv->ehci = ehci; priv->portnr = dev->req_seq; - priv->init_type = type; - ret = board_usb_init(priv->portnr, priv->init_type); + /* Init usb board level according to the requested init type */ + ret = board_usb_init(priv->portnr, type); if (ret) { printf("Failed to initialize board for USB\n"); return ret; @@ -759,10 +769,19 @@ static int ehci_usb_probe(struct udevice *dev) if (ret) return ret; + /* If the init_type is unknown due to it is not forced in DTB, we use USB ID to detect */ + if (priv->init_type == USB_INIT_UNKNOWN) { + ret = ehci_usb_phy_mode(dev); + if (ret) + return ret; + if (priv->init_type != type) + return -ENODEV; + } + #if CONFIG_IS_ENABLED(DM_REGULATOR) if (priv->vbus_supply) { ret = regulator_set_enable(priv->vbus_supply, - (type == USB_INIT_DEVICE) ? + (priv->init_type == USB_INIT_DEVICE) ? false : true); if (ret && ret != -ENOSYS) { printf("Error enabling VBUS supply (ret=%i)\n", ret); @@ -789,9 +808,12 @@ static int ehci_usb_probe(struct udevice *dev) int ehci_usb_remove(struct udevice *dev) { struct ehci_mx6_priv_data *priv = dev_get_priv(dev); + struct usb_platdata *plat = dev_get_platdata(dev); ehci_deregister(dev); + plat->init_type = 0; /* Clean the requested usb type to host mode */ + return board_usb_cleanup(dev->req_seq, priv->init_type); }