From patchwork Mon Oct 12 06:23:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Fan X-Patchwork-Id: 317610 Delivered-To: patch@linaro.org Received: by 2002:a92:d603:0:0:0:0:0 with SMTP id w3csp4324415ilm; Sun, 11 Oct 2020 22:58:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw51/FEFkL3mgAC4fWy7CQtUq7gmGoV3nYPirE3R83JSI5gAWy7saGfCO2qTAAx8Q5u0s/R X-Received: by 2002:a17:906:745:: with SMTP id z5mr5382460ejb.408.1602482283523; Sun, 11 Oct 2020 22:58:03 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1602482283; cv=pass; d=google.com; s=arc-20160816; b=cXjU4I+Ri3Vh+rgoaECHH20qR1tqC8ZCwMoO7WaXYMJnzsQBI4fpGCC9gqWeizr7UC 4PZwkDYM30dNhNlFTO5jtXjP9c78NKcC4KFonkcde22rECnsGmiY0vvV4Zi+SzdTGqhd keIzAmJrRH0GPrXtgHrx6Vrxz1Cxsjkofs9CpQ87WfWJzcORXAWNnaCXPAy5D/OLcQtf AxGPAhT3YXbt7q650p7ZrFwRlKbBMQ94/83hQgDQwcxI1lvD3ZQpH/d996SmYh0PqyPy 6fWzUzeg7akoVZYFpt1w9MY7oUu0flkIwh2gK9htkAUWL65E3dlr2e/YFDxIEsP2gtE4 UTfA== 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=KCdGIA5dox83cNP+ZWhQvpAKiy8fxfIqfUKV91g08DA=; b=SzG1BP+Wo+uyqejKHYO4YxN3qU0EIhqjgxtz99ADsELpvek6wJr7S6ylcTLM/ijBGf PtjTiKomatfIiEMroGGXPo05Jaat3Mzo5CeSCRK0V8oCmHOeFEilbQJOz5WbqYaG1Tb8 fBzgI6V/PNaNisGOXTFiUXrCEVwSjAww+eKOTGMhM4TWeUY07Jn/0NoUDrIlz3Wo7zMS lAje/qA2VNZ93T7L4MCoGnmlzArnKUjugUZJ0hgkP7YBHP4iWNHuej9FsHP7iYphaiHC NAsQagfVCG/yQ9Wtv4PHVGmk5m21ozclvspWhtdSEoQM7UYD1MHfIj0FJF+YrFXEd3ts BAcQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@nxp.com header.s=selector2 header.b=iVICRaYT; 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 dd21si11577583edb.91.2020.10.11.22.58.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 11 Oct 2020 22:58:03 -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=iVICRaYT; 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 B2A19824AB; Mon, 12 Oct 2020 07:57:30 +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="iVICRaYT"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 2A40B824A9; Mon, 12 Oct 2020 07:57:29 +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=-0.9 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 EUR01-DB5-obe.outbound.protection.outlook.com (mail-db5eur01on060e.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe02::60e]) (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 0E9DB82479 for ; Mon, 12 Oct 2020 07:57:26 +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=BG4hE+IPbr+R+HL9QUwWQjobKTv29ob4R4yJcpEquIkxZi0mjASSrKgl5lNAi1yrzDp8O70/J06tk9wuoKOMFMrZircgIq7XDN977qbqV/SDLdfspsyGpQwvMe/9kNtyY2+Q44we3tMr9ULWW0R2pOfEZvYcuwBJ/ERiQncDPXngOsPHXxJ1v5rdInG13xbaq6hsAScofgT7LkUoXzX3BB5z/i3LjixPnXLs2NZAwhJgbITwhoo3aYEXN5NR73h6y2cvUvfkjr0QCDhvDC9z7u24lWrmctaP3AeSPk8qog3YHrz02Z+chyv6Yy+p4M6wAdElUNXK2EgelD+NVwC1fA== 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=KCdGIA5dox83cNP+ZWhQvpAKiy8fxfIqfUKV91g08DA=; b=MWFMtB+5KjHtXB/oq91tCjeRzUE4ZEYMnx5y8U8Iuda4NT4EwEPseuiawL/aja58z4PT7E+9+f6QX7auA4oAe4JUPvWl8uwmuYFvZKXaAhzlfVPTtbXFJOotl11ib/TpxquMcwV6kHbxopzzWtJo9PBz9JA2/ti3ek0BQJVdkQFg+GflIykpLZaQBrmHUNtUPctAER23AoKcx3Hn2fwAv/dsu/AeeJJLBrnvfhI6IaYsfOyHvvXNfwokBuQPx62dB37ER67vh8x/xMdpEC5e4VY76uPIPw9HFHgYm8B6/G57x05d49JNtmkraHRtTFsC3Ny7tn0IC2qVQS0s41ssOQ== 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=KCdGIA5dox83cNP+ZWhQvpAKiy8fxfIqfUKV91g08DA=; b=iVICRaYTaMAS/E8Bqjqbv2yc8Qgv+hsDYyiGEskR/7b1WWmGUNpZKLBhzHPQdfSLzcCa1lSH+OpLzQxU9ByMEZtxxIBGweTM2E3ePLP1I6WqKeDlCIqKy9XYCVx9Gfrplc0ANFEsUsQRZejFqOF7m3T7gwMQEJCnYD8oCw89dow= 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 DB7PR04MB4235.eurprd04.prod.outlook.com (2603:10a6:5:22::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3455.26; Mon, 12 Oct 2020 05:57:25 +0000 Received: from DB6PR0402MB2760.eurprd04.prod.outlook.com ([fe80::35c5:8c71:91f3:6bc6]) by DB6PR0402MB2760.eurprd04.prod.outlook.com ([fe80::35c5:8c71:91f3:6bc6%12]) with mapi id 15.20.3455.029; Mon, 12 Oct 2020 05:57:24 +0000 From: Peng Fan To: sbabic@denx.de, festevam@gmail.com, marex@denx.de, lukma@denx.de Cc: uboot-imx@nxp.com, u-boot@lists.denx.de, Peng Fan Subject: [PATCH 4/8] usb: imx: add i.MX usb ehci driver Date: Mon, 12 Oct 2020 14:23:50 +0800 Message-Id: <20201012062354.3743-5-peng.fan@nxp.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201012062354.3743-1-peng.fan@nxp.com> References: <20201012062354.3743-1-peng.fan@nxp.com> X-Originating-IP: [119.31.174.71] X-ClientProxiedBy: SG2PR01CA0105.apcprd01.prod.exchangelabs.com (2603:1096:3:15::31) 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 SG2PR01CA0105.apcprd01.prod.exchangelabs.com (2603:1096:3:15::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3455.22 via Frontend Transport; Mon, 12 Oct 2020 05:57:22 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: c3eb2cbc-81b1-42a2-757b-08d86e73b111 X-MS-TrafficTypeDiagnostic: DB7PR04MB4235: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1060; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +bKr5UE33kb7KsS9ZLFLRz/7K+Jd/BxS5JmKyBCWY23KQhG8KfcXZM/H0MptUzrLuR34D7ecU8dXEOoqcRIbce4u/DTErlP8GwwKorhC61d1gNMxuJF0YA0AS8lweWWAWZ4LS2bcK7+3goT05M0Vj8haY9bK0hod1SMsQ7gmWwpDH14OmSpj0npoSDv17TwDpT0EgcCe8GhG8h0/FJvRqqDjojaCBsKQ7+t43m6kv9D8NRDEtnvMysBoudV56nE53JpeZEFJgZyVVsCK5v6F1shYr0mxn9XD8/SQrnJoD0LxYXDQIzJQufviPgVOjWfeG29mSk6T0KwG1deOV6CSpA== 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)(396003)(39860400002)(376002)(346002)(366004)(136003)(52116002)(83380400001)(8936002)(6506007)(4326008)(8676002)(44832011)(30864003)(6512007)(1076003)(6486002)(86362001)(5660300002)(6666004)(66476007)(66946007)(66556008)(316002)(36756003)(2616005)(956004)(2906002)(186003)(26005)(478600001)(16526019); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 7ZYQ6/u09qugnNZHlm3OhzZBAaV/Agzf6umLO5NuVr8atzn3pb9AprkGc9ehOByO9NTNHCRItZL4fl9qJRLBJXyLSv13OpyOESWF1J+79xKuy77nsz3VZYlf1yHCdZA6nFoFMTI90pEcHCRR7WAqVDG2j3G+7m/GgZxiYG/R3oxYKNSwzpMEcyUZjlYEtPQpVKGvWWYtIdQ5bzKsFAmZ7/4NOmKSpM7z72zpU/ijqFlMOv3LGqY3RwD9KqSxFOxLHawKIwtZJynejve6VYp8CkhtFdQszqTrB2Ps+r74V8VpKOT1P7MaeEORw6Itq+bYXOBsKwqsGI2KlDba92pPEhbwM8FqFrXNvpFu5BXX3NIHv70hB8xf0E9g9UscvnXGaWqorCRUSbUiavLaU7Ft/JhswiyYYvQ0x6V2teVBOpXAFn83zaKHUbqdmf5hKYlEFB6FoHVBXNEXUjkMpVi8mvk3pPI9vaRHgN0SU0Fo3J9Rq3VBZXxAFPj3j+yYaz9C0cQo3oe+QzQwD265OB1hoQ4Z6hTwPH9L8nsbjVBitgDLuWboPZR/Lwej4VgJxeGTkw3pEaQjpWrGEMq+hcJNMRNR8CyZgbI2BdnZvWxI+PmAfkePHZ+K5H7aL/J8mygTEv18yXlh87G4Y13idkL5kg== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: c3eb2cbc-81b1-42a2-757b-08d86e73b111 X-MS-Exchange-CrossTenant-AuthSource: DB6PR0402MB2760.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Oct 2020 05:57:24.7519 (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: b56eQ2/HtALBRO5Kmn0XkEPSL8278e+b4LHPY2NQHrYiphOsbKWuEHUIXm3B7RU7VF6tNWYUM23Eo+Dv2APEBw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB7PR04MB4235 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 This driver is a modifed and cleaned-up version of drivers/usb/host/ehci-mx6.c, it is to replace the original ehci-mx6.c driver. It dropped the hardcoding code and only support driver model with phy/clk/regulator/etc enabled. The usbmisc code is handling "fsl,usbmisc" related driver code, similar with Linux Kernel. Signed-off-by: Peng Fan --- Makefile | 1 + arch/arm/include/asm/mach-imx/regs-usbphy.h | 5 + arch/arm/include/asm/mach-imx/sys_proto.h | 2 + drivers/Makefile | 1 + drivers/usb/Kconfig | 2 + drivers/usb/imx/Kconfig | 10 + drivers/usb/imx/Makefile | 5 + drivers/usb/imx/ehci-imx.c | 406 ++++++++++++++++++++ drivers/usb/imx/imx-usb-misc.c | 47 +++ 9 files changed, 479 insertions(+) create mode 100644 drivers/usb/imx/Kconfig create mode 100644 drivers/usb/imx/Makefile create mode 100644 drivers/usb/imx/ehci-imx.c create mode 100644 drivers/usb/imx/imx-usb-misc.c -- 2.28.0 diff --git a/Makefile b/Makefile index 1de1f384e5..d1e9b19f34 100644 --- a/Makefile +++ b/Makefile @@ -799,6 +799,7 @@ libs-y += drivers/usb/musb/ libs-y += drivers/usb/musb-new/ libs-y += drivers/usb/phy/ libs-y += drivers/usb/ulpi/ +libs-y += drivers/usb/imx/ libs-y += cmd/ libs-y += common/ libs-y += env/ diff --git a/arch/arm/include/asm/mach-imx/regs-usbphy.h b/arch/arm/include/asm/mach-imx/regs-usbphy.h index 2b18ec20f3..c1f0a3264c 100644 --- a/arch/arm/include/asm/mach-imx/regs-usbphy.h +++ b/arch/arm/include/asm/mach-imx/regs-usbphy.h @@ -7,6 +7,8 @@ #ifndef __REGS_USBPHY_H__ #define __REGS_USBPHY_H__ +#include + #define USBPHY_CTRL 0x00000030 #define USBPHY_CTRL_SET 0x00000034 #define USBPHY_CTRL_CLR 0x00000038 @@ -22,4 +24,7 @@ #define USBPHY_CTRL_CLKGATE (1 << 30) #define USBPHY_CTRL_SFTRST (1 << 31) +#define USBNC_PHY_STATUS_OFFSET 0x23C +#define USBNC_PHYSTATUS_ID_DIG BIT(4) + #endif /* __REGS_USBPHY_H__ */ diff --git a/arch/arm/include/asm/mach-imx/sys_proto.h b/arch/arm/include/asm/mach-imx/sys_proto.h index 5f0c1ae218..c1e3cdcd88 100644 --- a/arch/arm/include/asm/mach-imx/sys_proto.h +++ b/arch/arm/include/asm/mach-imx/sys_proto.h @@ -212,4 +212,6 @@ unsigned long call_imx_sip_ret2(unsigned long id, unsigned long reg0, unsigned long reg3); void imx_get_mac_from_fuse(int dev_id, unsigned char *mac); + +int usbmisc_init(void __iomem *addr, int index); #endif diff --git a/drivers/Makefile b/drivers/Makefile index 9eb51453e5..f566217399 100644 --- a/drivers/Makefile +++ b/drivers/Makefile @@ -58,6 +58,7 @@ obj-$(CONFIG_SPL_USB_GADGET) += usb/common/ obj-$(CONFIG_SPL_USB_GADGET) += usb/gadget/udc/ obj-$(CONFIG_SPL_WATCHDOG_SUPPORT) += watchdog/ obj-$(CONFIG_SPL_USB_HOST_SUPPORT) += usb/host/ +obj-$(CONFIG_SPL_USB_HOST_SUPPORT) += usb/imx/ obj-$(CONFIG_OMAP_USB_PHY) += usb/phy/ obj-$(CONFIG_SPL_SATA_SUPPORT) += ata/ scsi/ obj-$(CONFIG_HAVE_BLOCK_DEVICE) += block/ diff --git a/drivers/usb/Kconfig b/drivers/usb/Kconfig index 34881a12b8..18c266a900 100644 --- a/drivers/usb/Kconfig +++ b/drivers/usb/Kconfig @@ -68,6 +68,8 @@ config SPL_DM_USB_GADGET source "drivers/usb/host/Kconfig" +source "drivers/usb/imx/Kconfig" + source "drivers/usb/cdns3/Kconfig" source "drivers/usb/dwc3/Kconfig" diff --git a/drivers/usb/imx/Kconfig b/drivers/usb/imx/Kconfig new file mode 100644 index 0000000000..5ccf5282fc --- /dev/null +++ b/drivers/usb/imx/Kconfig @@ -0,0 +1,10 @@ +if USB_EHCI_HCD + +config USB_EHCI_IMX + bool "Support for i.MX on-chip EHCI USB controller" + depends on IMX8MM || IMX8MN + ---help--- + Enables support for the on-chip EHCI controller on i.MX SoCs. + This is to replace ehci-mx6.c + +endif diff --git a/drivers/usb/imx/Makefile b/drivers/usb/imx/Makefile new file mode 100644 index 0000000000..9e50882719 --- /dev/null +++ b/drivers/usb/imx/Makefile @@ -0,0 +1,5 @@ +# SPDX-License-Identifier: GPL-2.0+ +# +# Copyright 2020 NXP + +obj-$(CONFIG_USB_EHCI_IMX) += ehci-imx.o imx-usb-misc.o diff --git a/drivers/usb/imx/ehci-imx.c b/drivers/usb/imx/ehci-imx.c new file mode 100644 index 0000000000..66ea8a1ab4 --- /dev/null +++ b/drivers/usb/imx/ehci-imx.c @@ -0,0 +1,406 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright 2020 NXP + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "../host/ehci.h" + +DECLARE_GLOBAL_DATA_PTR; + +static void ehci_imx_powerup_fixup(struct ehci_ctrl *ctrl, uint32_t *status_reg, uint32_t *reg) +{ + u32 result; + int ret; + + mdelay(50); + + ret = read_poll_timeout(ehci_readl, status_reg, result, !(result & EHCI_PS_PR), 5, 20000); + if (ret) + printf("%s timeout\n", __func__); + + *reg = ehci_readl(status_reg); +} + +/** + * board_ehci_hcd_init - set usb vbus voltage + * @port: usb otg port + * + * Target board specific, setup iomux pad to setup supply vbus voltage + * for usb otg port. Machine board file overrides board_ehci_hcd_init + * + * Return: 0 Success + */ +int __weak board_ehci_hcd_init(int port) +{ + return 0; +} + +#define USB_INIT_UNKNOWN (USB_INIT_DEVICE + 1) + +struct ehci_imx_priv_data { + struct ehci_ctrl ctrl; + struct usb_ehci *ehci; + struct udevice *vbus_supply; + enum usb_init_type init_type; + void *__iomem phy_base; + int portnr; + int clock_count; + struct clk_bulk clks; + void *__iomem usbmisc_addr; + int usbmisc_index; + struct phy phy; +}; + +static int imx_init_after_reset(struct ehci_ctrl *dev) +{ + struct ehci_imx_priv_data *priv = dev->priv; + enum usb_init_type type = priv->init_type; + struct usb_ehci *ehci = priv->ehci; + int ret; + + ret = board_usb_init(priv->portnr, priv->init_type); + if (ret) { + printf("Failed to initialize board for USB\n"); + return ret; + } + + /* Do board specific initialization */ + ret = board_ehci_hcd_init(priv->portnr); + if (ret) { + dev_err(dev, "board_ehci_hcd_init failed %d\n", ret); + return ret; + } + + ret = usbmisc_init(priv->usbmisc_addr, priv->usbmisc_index); + if (ret) { + dev_err(dev, "usbmisc_init %d\n", ret); + return ret; + } + + if (CONFIG_IS_ENABLED(DM_REGULATOR) && priv->vbus_supply) { + ret = regulator_set_enable(priv->vbus_supply, (type == USB_INIT_DEVICE) ? + false : true); + if (ret && ret != -ENOSYS) { + printf("Error enabling VBUS supply (ret=%i)\n", ret); + return ret; + } + } + + if (type == USB_INIT_DEVICE) + return 0; + + setbits_le32(&ehci->usbmode, CM_HOST); + writel(CONFIG_MXC_USB_PORTSC, &ehci->portsc); + setbits_le32(&ehci->portsc, USB_EN); + + mdelay(10); + + return 0; +} + +static const struct ehci_ops imx_ehci_ops = { + .powerup_fixup = ehci_imx_powerup_fixup, + .init_after_reset = imx_init_after_reset +}; + +/** + * board_ehci_usb_phy_mode - override usb phy mode + * @port: usb host/otg port + * + * Target board specific, override usb_phy_mode. + * When usb-otg is used as usb host port, iomux pad usb_otg_id can be + * left disconnected in this case usb_phy_mode will not be able to identify + * the phy mode that usb port is used. + * Machine file overrides board_usb_phy_mode. + * When the extcon property is set in DTB, machine must provide this function, otherwise + * it will default return HOST. + * + * Return: USB_INIT_DEVICE or USB_INIT_HOST + */ +int __weak board_ehci_usb_phy_mode(struct udevice *dev) +{ + return USB_INIT_HOST; +} + +static int ehci_usb_phy_mode(struct udevice *dev) +{ + struct ehci_imx_priv_data *priv = dev_get_priv(dev); + void *__iomem phy_status; + u32 val; + + if (is_imx8mm() || is_imx8mn()) { + phy_status = (void __iomem *)(priv->phy_base + + USBNC_PHY_STATUS_OFFSET); + val = readl(phy_status); + + if (val & USBNC_PHYSTATUS_ID_DIG) + priv->init_type = USB_INIT_DEVICE; + else + priv->init_type = USB_INIT_HOST; + } else { + return -EINVAL; + } + + return 0; +} + +static int ehci_get_usb_phy(struct udevice *dev) +{ + struct ehci_imx_priv_data *priv = dev_get_priv(dev); + void *__iomem addr = (void *__iomem)devfdt_get_addr(dev); + + if (is_imx8mm() || is_imx8mn()) + priv->phy_base = addr; + else + return -EINVAL; + + return 0; +} + +static int ehci_get_usbmisc(struct udevice *dev) +{ + struct ehci_imx_priv_data *priv = dev_get_priv(dev); + struct ofnode_phandle_args args; + int ret; + + /* + * About fsl,usbmisc, Refer to + * Documentation/devicetree/bindings/usb/ci-hdrc-usb2.txt. + */ + if (!ofnode_get_property(dev_ofnode(dev), "fsl,usbmisc", NULL)) + return 0; + + ret = ofnode_parse_phandle_with_args(dev_ofnode(dev), "fsl,usbmisc", "#index-cells", + 0, 0, &args); + if (ret) { + dev_err(dev, "failed ofnode_parse_phandle_with_args %d\n", ret); + return ret; + } + + if (!ofnode_valid(args.node)) { + dev_err(dev, "%s: unable to find node\n", __func__); + return -ENOENT; + } + + priv->usbmisc_addr = (void __iomem *)ofnode_get_addr(args.node); + if ((fdt_addr_t)priv->usbmisc_addr == FDT_ADDR_T_NONE) { + dev_err(dev, "failed ofnode_get_addr %d\n", ret); + return -EINVAL; + } + + priv->usbmisc_index = args.args[0]; + + return 0; +} + +static int ehci_usb_ofdata_to_platdata(struct udevice *dev) +{ + struct usb_platdata *plat = dev_get_platdata(dev); + struct ehci_imx_priv_data *priv = dev_get_priv(dev); + enum usb_dr_mode dr_mode; + const void *extcon; + + extcon = ofnode_get_property(dev->node, "extcon", NULL); + if (extcon) { + 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: + priv->init_type = USB_INIT_HOST; + break; + case USB_DR_MODE_PERIPHERAL: + priv->init_type = USB_INIT_DEVICE; + break; + case USB_DR_MODE_OTG: + case USB_DR_MODE_UNKNOWN: + 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; +} + +static int ehci_usb_probe(struct udevice *dev) +{ + struct usb_platdata *plat = dev_get_platdata(dev); + struct usb_ehci *ehci = dev_read_addr_ptr(dev); + struct ehci_imx_priv_data *priv = dev_get_priv(dev); + enum usb_init_type type = plat->init_type; + struct ehci_hccr *hccr; + struct ehci_hcor *hcor; + int ret, alias_id; + u32 portsc; + + ret = dev_read_alias_seq(dev, &alias_id); + if (ret < 0) { + dev_err(dev, "%s: Could not get alias id: %d\n", __func__, ret); + return ret; + } + + priv->ehci = ehci; + priv->portnr = dev->req_seq; + + /* 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; + } + + if (CONFIG_IS_ENABLED(DM_REGULATOR)) { + ret = device_get_supply_regulator(dev, "vbus-supply", &priv->vbus_supply); + if (ret) + debug("%s: No vbus supply\n", dev->name); + } + + ret = ehci_get_usb_phy(dev); + if (ret) { + debug("%s: fail to get USB PHY base\n", dev->name); + return ret; + } + + ret = ehci_get_usbmisc(dev); + if (ret) { + dev_err(dev, "fail to get USB misc, %d\n", ret); + return ret; + } + + ret = clk_get_bulk(dev, &priv->clks); + if (ret) { + dev_err(dev, "clk_get_bulk failed %d\n", ret); + return ret; + } + + ret = clk_enable_bulk(&priv->clks); + if (ret) { + dev_err(dev, "clk_enable_bulkj falied, %d\n", ret); + return ret; + } + + mdelay(1); + + portsc = readl(&ehci->portsc); + if (portsc & PORT_PTS_PHCD) { + debug("suspended: portsc %x, enabled it.\n", portsc); + clrbits_le32(&ehci->portsc, PORT_PTS_PHCD); + } + + /* Do board specific initialization */ + ret = board_ehci_hcd_init(priv->portnr); + if (ret) { + dev_err(dev, "board_ehci_hcd_init failed %d\n", ret); + goto release_clk; + } + + ret = usbmisc_init(priv->usbmisc_addr, priv->usbmisc_index); + if (ret) { + dev_err(dev, "usbmisc_init %d\n", ret); + goto release_clk; + } + + ret = ehci_setup_phy(dev, &priv->phy, 0); + if (ret < 0 && ret != -ENOSYS) { + dev_err(dev, "fail to setup USB PHY, %d\n", 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) && priv->vbus_supply) { + ret = regulator_set_enable(priv->vbus_supply, + (priv->init_type == USB_INIT_DEVICE) ? + false : true); + if (ret && ret != -ENOSYS) { + printf("Error enabling VBUS supply (ret=%i)\n", ret); + return ret; + } + } + + if (priv->init_type == USB_INIT_HOST) { + setbits_le32(&ehci->usbmode, CM_HOST); + writel(CONFIG_MXC_USB_PORTSC, &ehci->portsc); + setbits_le32(&ehci->portsc, USB_EN); + } + + mdelay(10); + + hccr = (struct ehci_hccr *)((uintptr_t)&ehci->caplength); + hcor = (struct ehci_hcor *)((uintptr_t)hccr + + HC_LENGTH(ehci_readl(&(hccr)->cr_capbase))); + + return ehci_register(dev, hccr, hcor, &imx_ehci_ops, 0, priv->init_type); + +release_clk: + clk_release_bulk(&priv->clks); + + return ret; +} + +int ehci_usb_remove(struct udevice *dev) +{ + struct ehci_imx_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); +} + +static const struct udevice_id imx_usb_ids[] = { + { .compatible = "fsl,imx8mm-usb" }, + { } +}; + +U_BOOT_DRIVER(usb_imx) = { + .name = "ehci_imx", + .id = UCLASS_USB, + .of_match = imx_usb_ids, + .ofdata_to_platdata = ehci_usb_ofdata_to_platdata, + .probe = ehci_usb_probe, + .remove = ehci_usb_remove, + .ops = &ehci_usb_ops, + .platdata_auto_alloc_size = sizeof(struct usb_platdata), + .priv_auto_alloc_size = sizeof(struct ehci_imx_priv_data), + .flags = DM_FLAG_ALLOC_PRIV_DMA, +}; diff --git a/drivers/usb/imx/imx-usb-misc.c b/drivers/usb/imx/imx-usb-misc.c new file mode 100644 index 0000000000..a9db71fdb1 --- /dev/null +++ b/drivers/usb/imx/imx-usb-misc.c @@ -0,0 +1,47 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright 2020 NXP + * Peng Fan + */ + +#include +#include +#include + +#define MX7D_USB_OTG_PHY_CFG2 0x34 + +#define USBNC_PHYCFG2_ACAENB (1 << 4) /* otg_id detection enable */ +#define UCTRL_PWR_POL (1 << 9) /* OTG Polarity of Power Pin */ +#define UCTRL_OVER_CUR_POL (1 << 8) /* OTG Polarity of Overcurrent */ +#define UCTRL_OVER_CUR_DIS (1 << 7) /* Disable OTG Overcurrent Detection */ + +int usbmisc_init(void __iomem *addr, int index) +{ + void __iomem *ctrl; + + if (is_mx7() || is_imx8mm() || is_imx8mn()) + clrbits_le32(addr + MX7D_USB_OTG_PHY_CFG2, USBNC_PHYCFG2_ACAENB); + + if (is_mx6()) + ctrl = addr + index * 4; + else + ctrl = addr; + +#if CONFIG_MACH_TYPE == MACH_TYPE_MX6Q_ARM2 + /* mx6qarm2 seems to required a different setting*/ + clrbits_le32(ctrl, UCTRL_OVER_CUR_POL); +#else + setbits_le32(ctrl, UCTRL_OVER_CUR_POL); +#endif + + setbits_le32(ctrl, UCTRL_OVER_CUR_DIS); + + /* Set power polarity to high active */ +#ifdef CONFIG_MXC_USB_OTG_HACTIVE + setbits_le32(ctrl, UCTRL_PWR_POL); +#else + clrbits_le32(ctrl, UCTRL_PWR_POL); +#endif + + return 0; +}