From patchwork Fri May 25 09:32:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Jacques Hiblot X-Patchwork-Id: 920356 X-Patchwork-Delegate: marek.vasut@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=quarantine dis=none) header.from=ti.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ti.com header.i=@ti.com header.b="d0KK8vMz"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 40sh020NG9z9s08 for ; Fri, 25 May 2018 19:33:53 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id B5B93C21E2B; Fri, 25 May 2018 09:33:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 8EE68C21DB3; Fri, 25 May 2018 09:32:54 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id AE79AC21BE5; Fri, 25 May 2018 09:32:51 +0000 (UTC) Received: from fllnx209.ext.ti.com (fllnx209.ext.ti.com [198.47.19.16]) by lists.denx.de (Postfix) with ESMTPS id CD661C21BE5 for ; Fri, 25 May 2018 09:32:50 +0000 (UTC) Received: from dflxv15.itg.ti.com ([128.247.5.124]) by fllnx209.ext.ti.com (8.15.1/8.15.1) with ESMTP id w4P9Wk5l014861; Fri, 25 May 2018 04:32:46 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1527240766; bh=1vm76+cOJLLhtqcSZ2L+enL9bNeMH0997ZC4ZtG8KkM=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=d0KK8vMzC7o9N5RSAB1GvVed1RgUr2YjpKZarrd17UPLM57Yrcykmcjon+fnuitXI 8a0UMK/pNmO6w07DUQciyVqc418wtygpY33p44PPvXxorWNliA2EVgcw7WmYiY7zMT vQbw09WoTRxFJ5n/NX8jxfY9f5Z/hGU4ilZUNYYI= Received: from DFLE108.ent.ti.com (dfle108.ent.ti.com [10.64.6.29]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id w4P9Wjwi031664; Fri, 25 May 2018 04:32:45 -0500 Received: from DFLE112.ent.ti.com (10.64.6.33) by DFLE108.ent.ti.com (10.64.6.29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1466.3; Fri, 25 May 2018 04:32:45 -0500 Received: from dlep33.itg.ti.com (157.170.170.75) by DFLE112.ent.ti.com (10.64.6.33) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.1466.3 via Frontend Transport; Fri, 25 May 2018 04:32:45 -0500 Received: from localhost (ileax41-snat.itg.ti.com [10.172.224.153]) by dlep33.itg.ti.com (8.14.3/8.13.8) with ESMTP id w4P9Wige021779; Fri, 25 May 2018 04:32:45 -0500 From: Jean-Jacques Hiblot To: , Date: Fri, 25 May 2018 11:32:36 +0200 Message-ID: <1527240762-27114-2-git-send-email-jjhiblot@ti.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1527240762-27114-1-git-send-email-jjhiblot@ti.com> References: <1527240762-27114-1-git-send-email-jjhiblot@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Cc: Stefan Agner , u-boot@lists.denx.de, Fabio Estevam Subject: [U-Boot] [PATCH v1 1/7] usb: gadget: Do not call board_usb_xxx() directly in USB gadget drivers X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 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" Add 2 functions to wrap the calls to board_usb_init() and board_usb_cleanup(). Signed-off-by: Jean-Jacques Hiblot --- cmd/fastboot.c | 4 ++-- cmd/rockusb.c | 4 ++-- cmd/thordown.c | 4 ++-- cmd/usb_gadget_sdp.c | 4 ++-- cmd/usb_mass_storage.c | 4 ++-- common/dfu.c | 6 +++--- drivers/usb/gadget/ether.c | 38 +++++--------------------------------- include/linux/usb/gadget.h | 10 ++++++++++ 8 files changed, 28 insertions(+), 46 deletions(-) diff --git a/cmd/fastboot.c b/cmd/fastboot.c index a5ec5f4..93f97fd 100644 --- a/cmd/fastboot.c +++ b/cmd/fastboot.c @@ -24,7 +24,7 @@ static int do_fastboot(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) usb_controller = argv[1]; controller_index = simple_strtoul(usb_controller, NULL, 0); - ret = board_usb_init(controller_index, USB_INIT_DEVICE); + ret = usb_gadget_initialize(controller_index); if (ret) { pr_err("USB init failed: %d", ret); return CMD_RET_FAILURE; @@ -55,7 +55,7 @@ static int do_fastboot(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) exit: g_dnl_unregister(); g_dnl_clear_detach(); - board_usb_cleanup(controller_index, USB_INIT_DEVICE); + usb_gadget_release(controller_index); return ret; } diff --git a/cmd/rockusb.c b/cmd/rockusb.c index 8206643..e0c1480 100644 --- a/cmd/rockusb.c +++ b/cmd/rockusb.c @@ -33,7 +33,7 @@ static int do_rockusb(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) dev_index = simple_strtoul(devnum, NULL, 0); rockusb_dev_init(devtype, dev_index); - ret = board_usb_init(controller_index, USB_INIT_DEVICE); + ret = usb_gadget_initialize(controller_index); if (ret) { printf("USB init failed: %d\n", ret); return CMD_RET_FAILURE; @@ -62,7 +62,7 @@ static int do_rockusb(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) exit: g_dnl_unregister(); g_dnl_clear_detach(); - board_usb_cleanup(controller_index, USB_INIT_DEVICE); + usb_gadget_release(controller_index); return ret; } diff --git a/cmd/thordown.c b/cmd/thordown.c index e297de2..b7866d1 100644 --- a/cmd/thordown.c +++ b/cmd/thordown.c @@ -30,7 +30,7 @@ int do_thor_down(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) goto done; int controller_index = simple_strtoul(usb_controller, NULL, 0); - ret = board_usb_init(controller_index, USB_INIT_DEVICE); + ret = usb_gadget_initialize(controller_index); if (ret) { pr_err("USB init failed: %d", ret); ret = CMD_RET_FAILURE; @@ -55,7 +55,7 @@ int do_thor_down(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) exit: g_dnl_unregister(); - board_usb_cleanup(controller_index, USB_INIT_DEVICE); + usb_gadget_realease(controller_index); done: dfu_free_entities(); diff --git a/cmd/usb_gadget_sdp.c b/cmd/usb_gadget_sdp.c index ba1f66a..808ed97 100644 --- a/cmd/usb_gadget_sdp.c +++ b/cmd/usb_gadget_sdp.c @@ -20,7 +20,7 @@ static int do_sdp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) char *usb_controller = argv[1]; int controller_index = simple_strtoul(usb_controller, NULL, 0); - board_usb_init(controller_index, USB_INIT_DEVICE); + usb_gadget_initialize(controller_index); g_dnl_clear_detach(); g_dnl_register("usb_dnl_sdp"); @@ -37,7 +37,7 @@ static int do_sdp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) exit: g_dnl_unregister(); - board_usb_cleanup(controller_index, USB_INIT_DEVICE); + usb_gadget_release(controller_index); return ret; } diff --git a/cmd/usb_mass_storage.c b/cmd/usb_mass_storage.c index 89b9ddf..7c6d0c6 100644 --- a/cmd/usb_mass_storage.c +++ b/cmd/usb_mass_storage.c @@ -160,7 +160,7 @@ static int do_usb_mass_storage(cmd_tbl_t *cmdtp, int flag, controller_index = (unsigned int)(simple_strtoul( usb_controller, NULL, 0)); - if (board_usb_init(controller_index, USB_INIT_DEVICE)) { + if (usb_gadget_initialize(controller_index)) { pr_err("Couldn't init USB controller."); rc = CMD_RET_FAILURE; goto cleanup_ums_init; @@ -231,7 +231,7 @@ static int do_usb_mass_storage(cmd_tbl_t *cmdtp, int flag, cleanup_register: g_dnl_unregister(); cleanup_board: - board_usb_cleanup(controller_index, USB_INIT_DEVICE); + usb_gadget_release(controller_index); cleanup_ums_init: ums_fini(); diff --git a/common/dfu.c b/common/dfu.c index 2620d32..44d1484 100644 --- a/common/dfu.c +++ b/common/dfu.c @@ -23,9 +23,9 @@ int run_usb_dnl_gadget(int usbctrl_index, char *usb_dnl_gadget) bool dfu_reset = false; int ret, i = 0; - ret = board_usb_init(usbctrl_index, USB_INIT_DEVICE); + ret = usb_gadget_initialize(usbctrl_index); if (ret) { - pr_err("board usb init failed\n"); + pr_err("usb_gadget_initialize failed\n"); return CMD_RET_FAILURE; } g_dnl_clear_detach(); @@ -84,7 +84,7 @@ int run_usb_dnl_gadget(int usbctrl_index, char *usb_dnl_gadget) } exit: g_dnl_unregister(); - board_usb_cleanup(usbctrl_index, USB_INIT_DEVICE); + usb_gadget_release(usbctrl_index); if (dfu_reset) do_reset(NULL, 0, 0, NULL); diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c index 8ab9b9f..1c438c3 100644 --- a/drivers/usb/gadget/ether.c +++ b/drivers/usb/gadget/ether.c @@ -105,9 +105,6 @@ struct eth_dev { struct usb_gadget *gadget; struct usb_request *req; /* for control responses */ struct usb_request *stat_req; /* for cdc & rndis status */ -#ifdef CONFIG_DM_USB - struct udevice *usb_udev; -#endif u8 config; struct usb_ep *in_ep, *out_ep, *status_ep; @@ -2341,40 +2338,17 @@ fail: } /*-------------------------------------------------------------------------*/ - -#ifdef CONFIG_DM_USB -int dm_usb_init(struct eth_dev *e_dev) -{ - struct udevice *dev = NULL; - int ret; - - ret = uclass_first_device(UCLASS_USB_DEV_GENERIC, &dev); - if (!dev || ret) { - pr_err("No USB device found\n"); - return -ENODEV; - } - - e_dev->usb_udev = dev; - - return ret; -} -#endif - static int _usb_eth_init(struct ether_priv *priv) { struct eth_dev *dev = &priv->ethdev; struct usb_gadget *gadget; unsigned long ts; + int ret; unsigned long timeout = USB_CONNECT_TIMEOUT; -#ifdef CONFIG_DM_USB - if (dm_usb_init(dev)) { - pr_err("USB ether not found\n"); - return -ENODEV; - } -#else - board_usb_init(0, USB_INIT_DEVICE); -#endif + ret = usb_gadget_initialize(0); + if (ret) + return ret; /* Configure default mac-addresses for the USB ethernet device */ #ifdef CONFIG_USBNET_DEV_ADDR @@ -2546,9 +2520,7 @@ void _usb_eth_halt(struct ether_priv *priv) } usb_gadget_unregister_driver(&priv->eth_driver); -#ifndef CONFIG_DM_USB - board_usb_cleanup(0, USB_INIT_DEVICE); -#endif + usb_gadget_release(0); } #ifndef CONFIG_DM_ETH diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h index b824f13..40ca2d3 100644 --- a/include/linux/usb/gadget.h +++ b/include/linux/usb/gadget.h @@ -19,6 +19,7 @@ #define __LINUX_USB_GADGET_H #include +#include #include #include @@ -926,4 +927,13 @@ extern void usb_ep_autoconfig_reset(struct usb_gadget *); extern int usb_gadget_handle_interrupts(int index); +static inline int usb_gadget_initialize(int index) +{ + return board_usb_init(index, USB_INIT_DEVICE); +} + +static inline int usb_gadget_release(int index) +{ + return board_usb_cleanup(index, USB_INIT_DEVICE); +} #endif /* __LINUX_USB_GADGET_H */ From patchwork Fri May 25 09:32:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Jacques Hiblot X-Patchwork-Id: 920355 X-Patchwork-Delegate: marek.vasut@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=quarantine dis=none) header.from=ti.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ti.com header.i=@ti.com header.b="MJUYaTbA"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 40sgz148mDz9s08 for ; Fri, 25 May 2018 19:33:01 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 42AE3C21E2C; Fri, 25 May 2018 09:32:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id E2FD5C21C27; Fri, 25 May 2018 09:32:53 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id A2C6AC21C2C; Fri, 25 May 2018 09:32:51 +0000 (UTC) Received: from fllnx209.ext.ti.com (fllnx209.ext.ti.com [198.47.19.16]) by lists.denx.de (Postfix) with ESMTPS id CD67FC21C27 for ; Fri, 25 May 2018 09:32:50 +0000 (UTC) Received: from dflxv15.itg.ti.com ([128.247.5.124]) by fllnx209.ext.ti.com (8.15.1/8.15.1) with ESMTP id w4P9WlCx014867; Fri, 25 May 2018 04:32:47 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1527240767; bh=6wFuIhDDjHpyHbtJDMp6q/cdzaImAktMZXWdPD20c3w=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=MJUYaTbAUQu6so46RSr8DQ1u+xk9qjoHzv5KM5xoOcLUOZRYF0DgXWFZOOLe7VF5r TMDjbKpWoYpa2hoMR/Hz2KIYUaxzY0ydULOyxtvaDXvDbsXID12Fv8tEfvcH2Aqs5V oFbOIoOOukX08/Ce0CzDT+gSlL5maKyYzNjAK9Gw= Received: from DFLE104.ent.ti.com (dfle104.ent.ti.com [10.64.6.25]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id w4P9WleO031721; Fri, 25 May 2018 04:32:47 -0500 Received: from DFLE109.ent.ti.com (10.64.6.30) by DFLE104.ent.ti.com (10.64.6.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1466.3; Fri, 25 May 2018 04:32:46 -0500 Received: from dflp32.itg.ti.com (10.64.6.15) by DFLE109.ent.ti.com (10.64.6.30) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.1466.3 via Frontend Transport; Fri, 25 May 2018 04:32:47 -0500 Received: from localhost (ileax41-snat.itg.ti.com [10.172.224.153]) by dflp32.itg.ti.com (8.14.3/8.13.8) with ESMTP id w4P9Wkaw030150; Fri, 25 May 2018 04:32:46 -0500 From: Jean-Jacques Hiblot To: , Date: Fri, 25 May 2018 11:32:37 +0200 Message-ID: <1527240762-27114-3-git-send-email-jjhiblot@ti.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1527240762-27114-1-git-send-email-jjhiblot@ti.com> References: <1527240762-27114-1-git-send-email-jjhiblot@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Cc: u-boot@lists.denx.de Subject: [U-Boot] [PATCH v1 2/7] usb: introduce a separate config option for DM USB device X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 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" Using CONFIG_DM_USB for this purpose prevents using DM_USB for host and not for device. Signed-off-by: Jean-Jacques Hiblot --- drivers/usb/Kconfig | 6 ++++++ drivers/usb/dwc3/core.c | 2 +- drivers/usb/dwc3/dwc3-generic.c | 4 +++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/usb/Kconfig b/drivers/usb/Kconfig index 4fbe172..3587ba4 100644 --- a/drivers/usb/Kconfig +++ b/drivers/usb/Kconfig @@ -47,6 +47,12 @@ config DM_USB declared with the U_BOOT_USB_DEVICE() macro and will be automatically probed when found on the bus. +config DM_USB_DEV + bool "Enable driver model for USB (Peripheral mode)" + depends on DM_USB + help + Enable driver model for USB (Peripheral mode). + source "drivers/usb/host/Kconfig" source "drivers/usb/dwc3/Kconfig" diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index 1ab5cee..d5ee6d9 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -789,7 +789,7 @@ MODULE_AUTHOR("Felipe Balbi "); MODULE_LICENSE("GPL v2"); MODULE_DESCRIPTION("DesignWare USB3 DRD Controller Driver"); -#ifdef CONFIG_DM_USB +#ifdef CONFIG_DM_USB_DEV int dwc3_init(struct dwc3 *dwc) { diff --git a/drivers/usb/dwc3/dwc3-generic.c b/drivers/usb/dwc3/dwc3-generic.c index ca63eac..2c1e696 100644 --- a/drivers/usb/dwc3/dwc3-generic.c +++ b/drivers/usb/dwc3/dwc3-generic.c @@ -21,7 +21,7 @@ #include "gadget.h" #include "linux-compat.h" -DECLARE_GLOBAL_DATA_PTR; +#ifdef CONFIG_DM_USB_DEV int usb_gadget_handle_interrupts(int index) { @@ -98,6 +98,8 @@ U_BOOT_DRIVER(dwc3_generic_peripheral) = { .flags = DM_FLAG_ALLOC_PRIV_DMA, }; +#endif + static int dwc3_generic_bind(struct udevice *parent) { const void *fdt = gd->fdt_blob; From patchwork Fri May 25 09:32:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Jacques Hiblot X-Patchwork-Id: 920357 X-Patchwork-Delegate: marek.vasut@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=quarantine dis=none) header.from=ti.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ti.com header.i=@ti.com header.b="xhWEiJJt"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 40sh0q4Dc2z9s08 for ; Fri, 25 May 2018 19:34:35 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 3C68AC21BE5; Fri, 25 May 2018 09:33:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 8443BC21E13; Fri, 25 May 2018 09:32:57 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 43E07C21BE5; Fri, 25 May 2018 09:32:53 +0000 (UTC) Received: from fllnx210.ext.ti.com (fllnx210.ext.ti.com [198.47.19.17]) by lists.denx.de (Postfix) with ESMTPS id 9E017C21C27 for ; Fri, 25 May 2018 09:32:52 +0000 (UTC) Received: from dflxv15.itg.ti.com ([128.247.5.124]) by fllnx210.ext.ti.com (8.15.1/8.15.1) with ESMTP id w4P9WmFk028484; Fri, 25 May 2018 04:32:48 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1527240768; bh=5Dc/VHxzV0M/jsdxfq6fMOAfEqFe/WyZVdY00yJmmBU=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=xhWEiJJtPgq4IDqL4FVRMJAyyC/aKShbhXKKZUHubi+vRhG7nzdCYGzTeDKGfkj03 LJwwV9jhyAl9wTYVVbggyqXSY1iSHFvW43CqRPJW9DpsJ3TJ53xCY+AhXyeQRqyk6N h0JSEoivFj0ApzFJ66KTZqpt+eV3bnPDQRIURuFk= Received: from DFLE106.ent.ti.com (dfle106.ent.ti.com [10.64.6.27]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id w4P9WmSe031770; Fri, 25 May 2018 04:32:48 -0500 Received: from DFLE113.ent.ti.com (10.64.6.34) by DFLE106.ent.ti.com (10.64.6.27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1466.3; Fri, 25 May 2018 04:32:48 -0500 Received: from dlep32.itg.ti.com (157.170.170.100) by DFLE113.ent.ti.com (10.64.6.34) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.1466.3 via Frontend Transport; Fri, 25 May 2018 04:32:48 -0500 Received: from localhost (ileax41-snat.itg.ti.com [10.172.224.153]) by dlep32.itg.ti.com (8.14.3/8.13.8) with ESMTP id w4P9Wl71002734; Fri, 25 May 2018 04:32:47 -0500 From: Jean-Jacques Hiblot To: , Date: Fri, 25 May 2018 11:32:38 +0200 Message-ID: <1527240762-27114-4-git-send-email-jjhiblot@ti.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1527240762-27114-1-git-send-email-jjhiblot@ti.com> References: <1527240762-27114-1-git-send-email-jjhiblot@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Cc: u-boot@lists.denx.de Subject: [U-Boot] [PATCH v1 3/7] usb: udc: implement DM versions of usb_gadget_initialize()/_release()/_handle_interrupt() X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 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" When DM_USB_DEV the platform code for the USB device must be replaced by calls to a USB device driver. usb_gadget_initialize() probes the USB device driver. usb_gadget_release() removes the USB device driver. Signed-off-by: Jean-Jacques Hiblot Reviewed-by: Lukasz Majewski --- drivers/usb/dwc3/dwc3-generic.c | 14 ++----------- drivers/usb/gadget/udc/udc-core.c | 44 ++++++++++++++++++++++++++++++++++++++- include/linux/usb/gadget.h | 8 +++++++ 3 files changed, 53 insertions(+), 13 deletions(-) diff --git a/drivers/usb/dwc3/dwc3-generic.c b/drivers/usb/dwc3/dwc3-generic.c index 2c1e696..43e97be 100644 --- a/drivers/usb/dwc3/dwc3-generic.c +++ b/drivers/usb/dwc3/dwc3-generic.c @@ -23,19 +23,9 @@ #ifdef CONFIG_DM_USB_DEV -int usb_gadget_handle_interrupts(int index) +int dm_usb_gadget_handle_interrupts(struct udevice *dev) { - struct dwc3 *priv; - struct udevice *dev; - int ret; - - ret = uclass_first_device(UCLASS_USB_DEV_GENERIC, &dev); - if (!dev || ret) { - pr_err("No USB device found\n"); - return -ENODEV; - } - - priv = dev_get_priv(dev); + struct dwc3 *priv = dev_get_priv(dev); dwc3_gadget_uboot_handle_interrupt(priv); diff --git a/drivers/usb/gadget/udc/udc-core.c b/drivers/usb/gadget/udc/udc-core.c index f5c30dd..42c9ea9 100644 --- a/drivers/usb/gadget/udc/udc-core.c +++ b/drivers/usb/gadget/udc/udc-core.c @@ -18,7 +18,8 @@ #include #include #include - +#include +#include #include #include @@ -351,3 +352,44 @@ EXPORT_SYMBOL_GPL(usb_gadget_unregister_driver); MODULE_DESCRIPTION("UDC Framework"); MODULE_AUTHOR("Felipe Balbi "); MODULE_LICENSE("GPL v2"); + +#ifdef CONFIG_DM_USB_DEV +#define MAX_UDC_DEVICES 4 +static struct udevice *dev_array[MAX_UDC_DEVICES]; +int usb_gadget_initialize(int index) +{ + int ret; + struct udevice *dev = NULL; + + if (index < 0 || index >= ARRAY_SIZE(dev_array)) + return -EINVAL; + if (dev_array[index]) + return 0; + ret = uclass_get_device(UCLASS_USB_DEV_GENERIC, index, &dev); + if (!dev || ret) { + pr_err("No USB device found\n"); + return -ENODEV; + } + dev_array[index] = dev; + return 0; +} + +int usb_gadget_release(int index) +{ + int ret; + + if (index < 0 || index >= ARRAY_SIZE(dev_array)) + return -EINVAL; + ret = device_remove(dev_array[index], DM_REMOVE_NORMAL); + if (!ret) + dev_array[index] = NULL; + return ret; +} + +int usb_gadget_handle_interrupts(int index) +{ + if (index < 0 || index >= ARRAY_SIZE(dev_array)) + return -EINVAL; + return dm_usb_gadget_handle_interrupts(dev_array[index]); +} +#endif diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h index 40ca2d3..a094e31 100644 --- a/include/linux/usb/gadget.h +++ b/include/linux/usb/gadget.h @@ -927,6 +927,12 @@ extern void usb_ep_autoconfig_reset(struct usb_gadget *); extern int usb_gadget_handle_interrupts(int index); +#ifdef CONFIG_DM_USB_DEV +int usb_gadget_initialize(int index); +int usb_gadget_release(int index); +int dm_usb_gadget_handle_interrupts(struct udevice *dev); +#else +#include static inline int usb_gadget_initialize(int index) { return board_usb_init(index, USB_INIT_DEVICE); @@ -936,4 +942,6 @@ static inline int usb_gadget_release(int index) { return board_usb_cleanup(index, USB_INIT_DEVICE); } +#endif + #endif /* __LINUX_USB_GADGET_H */ From patchwork Fri May 25 09:32:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Jacques Hiblot X-Patchwork-Id: 920359 X-Patchwork-Delegate: marek.vasut@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=quarantine dis=none) header.from=ti.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ti.com header.i=@ti.com header.b="K2cD191m"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 40sh1C4kzvz9s08 for ; Fri, 25 May 2018 19:34:55 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 50212C21DD7; Fri, 25 May 2018 09:34:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 5B7DFC21DD9; Fri, 25 May 2018 09:32:58 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 78176C21BE5; Fri, 25 May 2018 09:32:53 +0000 (UTC) Received: from fllnx209.ext.ti.com (fllnx209.ext.ti.com [198.47.19.16]) by lists.denx.de (Postfix) with ESMTPS id E2FDEC21C2C for ; Fri, 25 May 2018 09:32:52 +0000 (UTC) Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by fllnx209.ext.ti.com (8.15.1/8.15.1) with ESMTP id w4P9Wols014901; Fri, 25 May 2018 04:32:50 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1527240770; bh=qApqXIbPHusYhjPm8unkO9GWX9MVX5Sxt6mIOWN/V9o=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=K2cD191mdRipaTk99FlZw8jWGcZY8qLqoVrq7uLVYzs1OQFoLAVFSFFTB8QFk/NUO 6W3O75l50UFv9EplskR6OQFv3vrPjBUxWNNHBfzMlbgmU4vD4QCYv9i3/ypNBR/krK L/x+/yS3q423cTTZaU/FBbd+Hmj+Hd1Ys2EEzxTo= Received: from DLEE104.ent.ti.com (dlee104.ent.ti.com [157.170.170.34]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id w4P9WnNr005263; Fri, 25 May 2018 04:32:49 -0500 Received: from DLEE100.ent.ti.com (157.170.170.30) by DLEE104.ent.ti.com (157.170.170.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1466.3; Fri, 25 May 2018 04:32:49 -0500 Received: from dflp32.itg.ti.com (10.64.6.15) by DLEE100.ent.ti.com (157.170.170.30) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.1466.3 via Frontend Transport; Fri, 25 May 2018 04:32:49 -0500 Received: from localhost (ileax41-snat.itg.ti.com [10.172.224.153]) by dflp32.itg.ti.com (8.14.3/8.13.8) with ESMTP id w4P9Wm5C030218; Fri, 25 May 2018 04:32:49 -0500 From: Jean-Jacques Hiblot To: , Date: Fri, 25 May 2018 11:32:39 +0200 Message-ID: <1527240762-27114-5-git-send-email-jjhiblot@ti.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1527240762-27114-1-git-send-email-jjhiblot@ti.com> References: <1527240762-27114-1-git-send-email-jjhiblot@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Cc: u-boot@lists.denx.de Subject: [U-Boot] [PATCH v1 4/7] dwc3_generic: do not probe the USB device driver when it's bound X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 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" The driver will be probed when usb_gadget_initialize() is called. Signed-off-by: Jean-Jacques Hiblot --- drivers/usb/dwc3/dwc3-generic.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/drivers/usb/dwc3/dwc3-generic.c b/drivers/usb/dwc3/dwc3-generic.c index 43e97be..3ec0c0e 100644 --- a/drivers/usb/dwc3/dwc3-generic.c +++ b/drivers/usb/dwc3/dwc3-generic.c @@ -71,21 +71,14 @@ static int dwc3_generic_peripheral_ofdata_to_platdata(struct udevice *dev) return 0; } -static int dwc3_generic_peripheral_bind(struct udevice *dev) -{ - return device_probe(dev); -} - U_BOOT_DRIVER(dwc3_generic_peripheral) = { .name = "dwc3-generic-peripheral", .id = UCLASS_USB_DEV_GENERIC, .ofdata_to_platdata = dwc3_generic_peripheral_ofdata_to_platdata, .probe = dwc3_generic_peripheral_probe, .remove = dwc3_generic_peripheral_remove, - .bind = dwc3_generic_peripheral_bind, .platdata_auto_alloc_size = sizeof(struct usb_platdata), .priv_auto_alloc_size = sizeof(struct dwc3), - .flags = DM_FLAG_ALLOC_PRIV_DMA, }; #endif From patchwork Fri May 25 09:32:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Jacques Hiblot X-Patchwork-Id: 920361 X-Patchwork-Delegate: marek.vasut@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=quarantine dis=none) header.from=ti.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ti.com header.i=@ti.com header.b="hZfs/tpb"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 40sh3s4WXrz9s0q for ; Fri, 25 May 2018 19:37:12 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 9213FC21DD3; Fri, 25 May 2018 09:34:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 8E0F6C21BE5; Fri, 25 May 2018 09:33:06 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id D074BC21E26; Fri, 25 May 2018 09:33:01 +0000 (UTC) Received: from lelnx194.ext.ti.com (lelnx194.ext.ti.com [198.47.27.80]) by lists.denx.de (Postfix) with ESMTPS id 18F6EC21BE5 for ; Fri, 25 May 2018 09:32:54 +0000 (UTC) Received: from dflxv15.itg.ti.com ([128.247.5.124]) by lelnx194.ext.ti.com (8.15.1/8.15.1) with ESMTP id w4P9WpUt030559; Fri, 25 May 2018 04:32:51 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1527240771; bh=PgWhQI/7snpH+A9A6Wa5NrDMAB/O6/JDI4HILewR0f4=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=hZfs/tpbNP/0SfDejuktp08OeUBoVJx2x6pTZBTZima3WV7r/HzuntHksE79HZG0r AqWKUWPwI3eCG0PhSxUC721A6dQjKwkhyIGovialhHnwT7cJRkina9B2J1pYSRkDiC t145muf6vN5Vxq1RUqbHIAISeeXrCQVUI3oP5LcE= Received: from DLEE104.ent.ti.com (dlee104.ent.ti.com [157.170.170.34]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id w4P9Wpln031907; Fri, 25 May 2018 04:32:51 -0500 Received: from DLEE100.ent.ti.com (157.170.170.30) by DLEE104.ent.ti.com (157.170.170.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1466.3; Fri, 25 May 2018 04:32:51 -0500 Received: from dflp33.itg.ti.com (10.64.6.16) by DLEE100.ent.ti.com (157.170.170.30) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.1466.3 via Frontend Transport; Fri, 25 May 2018 04:32:50 -0500 Received: from localhost (ileax41-snat.itg.ti.com [10.172.224.153]) by dflp33.itg.ti.com (8.14.3/8.13.8) with ESMTP id w4P9WoEv029059; Fri, 25 May 2018 04:32:50 -0500 From: Jean-Jacques Hiblot To: , Date: Fri, 25 May 2018 11:32:40 +0200 Message-ID: <1527240762-27114-6-git-send-email-jjhiblot@ti.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1527240762-27114-1-git-send-email-jjhiblot@ti.com> References: <1527240762-27114-1-git-send-email-jjhiblot@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Cc: u-boot@lists.denx.de Subject: [U-Boot] [PATCH v1 5/7] dwc3: move phy operation to core.c X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 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" Those operations can be used for peripheral operation as well as host operation. Signed-off-by: Jean-Jacques Hiblot --- drivers/usb/dwc3/core.c | 88 ++++++++++++++++++++++++++++++++++++++++- drivers/usb/dwc3/ep0.c | 1 - drivers/usb/host/xhci-dwc3.c | 93 +++----------------------------------------- include/dwc3-uboot.h | 7 ++++ 4 files changed, 99 insertions(+), 90 deletions(-) diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index d5ee6d9..538c603 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -19,7 +19,7 @@ #include #include #include - +#include #include #include @@ -789,8 +789,92 @@ MODULE_AUTHOR("Felipe Balbi "); MODULE_LICENSE("GPL v2"); MODULE_DESCRIPTION("DesignWare USB3 DRD Controller Driver"); -#ifdef CONFIG_DM_USB_DEV +#ifdef CONFIG_DM_USB +int dwc3_setup_phy(struct udevice *dev, struct phy **array, int *num_phys) +{ + int i, ret, count; + struct phy *usb_phys; + + /* Return if no phy declared */ + if (!dev_read_prop(dev, "phys", NULL)) + return 0; + + count = dev_count_phandle_with_args(dev, "phys", "#phy-cells"); + if (count <= 0) + return count; + + usb_phys = devm_kcalloc(dev, count, sizeof(struct phy), + GFP_KERNEL); + if (!usb_phys) + return -ENOMEM; + + for (i = 0; i < count; i++) { + ret = generic_phy_get_by_index(dev, i, &usb_phys[i]); + if (ret && ret != -ENOENT) { + pr_err("Failed to get USB PHY%d for %s\n", + i, dev->name); + return ret; + } + } + + for (i = 0; i < count; i++) { + ret = generic_phy_init(&usb_phys[i]); + if (ret) { + pr_err("Can't init USB PHY%d for %s\n", + i, dev->name); + goto phys_init_err; + } + } + + for (i = 0; i < count; i++) { + ret = generic_phy_power_on(&usb_phys[i]); + if (ret) { + pr_err("Can't power USB PHY%d for %s\n", + i, dev->name); + goto phys_poweron_err; + } + } + + *num_phys = count; + return 0; +phys_poweron_err: + for (i = count - 1; i >= 0; i--) + generic_phy_power_off(&usb_phys[i]); + + for (i = 0; i < count; i++) + generic_phy_exit(&usb_phys[i]); + + return ret; + +phys_init_err: + for (; i >= 0; i--) + generic_phy_exit(&usb_phys[i]); + + return ret; +} + +int dwc3_shutdown_phy(struct udevice *dev, struct phy *usb_phys, int num_phys) +{ + int i, ret; + + for (i = 0; i < num_phys; i++) { + if (!generic_phy_valid(&usb_phys[i])) + continue; + + ret = generic_phy_power_off(&usb_phys[i]); + ret |= generic_phy_exit(&usb_phys[i]); + if (ret) { + pr_err("Can't shutdown USB PHY%d for %s\n", + i, dev->name); + } + } + + return 0; +} +#endif + +#ifdef CONFIG_DM_USB_DEV int dwc3_init(struct dwc3 *dwc) { int ret; diff --git a/drivers/usb/dwc3/ep0.c b/drivers/usb/dwc3/ep0.c index 4f68887..433e5f6 100644 --- a/drivers/usb/dwc3/ep0.c +++ b/drivers/usb/dwc3/ep0.c @@ -19,7 +19,6 @@ #include #include #include - #include "core.h" #include "gadget.h" #include "io.h" diff --git a/drivers/usb/host/xhci-dwc3.c b/drivers/usb/host/xhci-dwc3.c index 80754d7..052e704 100644 --- a/drivers/usb/host/xhci-dwc3.c +++ b/drivers/usb/host/xhci-dwc3.c @@ -12,6 +12,7 @@ #include #include #include +#include #include "xhci.h" #include @@ -110,104 +111,20 @@ void dwc3_set_fladj(struct dwc3 *dwc3_reg, u32 val) } #ifdef CONFIG_DM_USB -static int xhci_dwc3_setup_phy(struct udevice *dev) -{ - struct xhci_dwc3_platdata *plat = dev_get_platdata(dev); - int i, ret, count; - - /* Return if no phy declared */ - if (!dev_read_prop(dev, "phys", NULL)) - return 0; - - count = dev_count_phandle_with_args(dev, "phys", "#phy-cells"); - if (count <= 0) - return count; - - plat->usb_phys = devm_kcalloc(dev, count, sizeof(struct phy), - GFP_KERNEL); - if (!plat->usb_phys) - return -ENOMEM; - - for (i = 0; i < count; i++) { - ret = generic_phy_get_by_index(dev, i, &plat->usb_phys[i]); - if (ret && ret != -ENOENT) { - pr_err("Failed to get USB PHY%d for %s\n", - i, dev->name); - return ret; - } - - ++plat->num_phys; - } - - for (i = 0; i < plat->num_phys; i++) { - ret = generic_phy_init(&plat->usb_phys[i]); - if (ret) { - pr_err("Can't init USB PHY%d for %s\n", - i, dev->name); - goto phys_init_err; - } - } - - for (i = 0; i < plat->num_phys; i++) { - ret = generic_phy_power_on(&plat->usb_phys[i]); - if (ret) { - pr_err("Can't power USB PHY%d for %s\n", - i, dev->name); - goto phys_poweron_err; - } - } - - return 0; - -phys_poweron_err: - for (; i >= 0; i--) - generic_phy_power_off(&plat->usb_phys[i]); - - for (i = 0; i < plat->num_phys; i++) - generic_phy_exit(&plat->usb_phys[i]); - - return ret; - -phys_init_err: - for (; i >= 0; i--) - generic_phy_exit(&plat->usb_phys[i]); - - return ret; -} - -static int xhci_dwc3_shutdown_phy(struct udevice *dev) -{ - struct xhci_dwc3_platdata *plat = dev_get_platdata(dev); - int i, ret; - - for (i = 0; i < plat->num_phys; i++) { - if (!generic_phy_valid(&plat->usb_phys[i])) - continue; - - ret = generic_phy_power_off(&plat->usb_phys[i]); - ret |= generic_phy_exit(&plat->usb_phys[i]); - if (ret) { - pr_err("Can't shutdown USB PHY%d for %s\n", - i, dev->name); - } - } - - return 0; -} - static int xhci_dwc3_probe(struct udevice *dev) { struct xhci_hcor *hcor; struct xhci_hccr *hccr; struct dwc3 *dwc3_reg; enum usb_dr_mode dr_mode; + struct xhci_dwc3_platdata *plat = dev_get_platdata(dev); int ret; hccr = (struct xhci_hccr *)((uintptr_t)dev_read_addr(dev)); hcor = (struct xhci_hcor *)((uintptr_t)hccr + HC_LENGTH(xhci_readl(&(hccr)->cr_capbase))); - ret = xhci_dwc3_setup_phy(dev); + ret = dwc3_setup_phy(dev, &plat->usb_phys, &plat->num_phys); if (ret) return ret; @@ -227,7 +144,9 @@ static int xhci_dwc3_probe(struct udevice *dev) static int xhci_dwc3_remove(struct udevice *dev) { - xhci_dwc3_shutdown_phy(dev); + struct xhci_dwc3_platdata *plat = dev_get_platdata(dev); + + dwc3_shutdown_phy(dev, plat->usb_phys, plat->num_phys); return xhci_deregister(dev); } diff --git a/include/dwc3-uboot.h b/include/dwc3-uboot.h index 228ab3b..a2da081 100644 --- a/include/dwc3-uboot.h +++ b/include/dwc3-uboot.h @@ -38,4 +38,11 @@ struct dwc3_device { int dwc3_uboot_init(struct dwc3_device *dev); void dwc3_uboot_exit(int index); void dwc3_uboot_handle_interrupt(int index); + +#ifdef CONFIG_DM_USB +struct phy; +int dwc3_setup_phy(struct udevice *dev, struct phy **array, int *num_phys); +int dwc3_shutdown_phy(struct udevice *dev, struct phy *usb_phys, int num_phys); +#endif + #endif /* __DWC3_UBOOT_H_ */ From patchwork Fri May 25 09:32:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Jacques Hiblot X-Patchwork-Id: 920362 X-Patchwork-Delegate: marek.vasut@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=quarantine dis=none) header.from=ti.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ti.com header.i=@ti.com header.b="IsYGz2RM"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 40sh3w3dPqz9s0q for ; Fri, 25 May 2018 19:37:16 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 26886C21DD9; Fri, 25 May 2018 09:34:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 7C8BBC21E2C; Fri, 25 May 2018 09:33:09 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 3149EC21E1B; Fri, 25 May 2018 09:33:02 +0000 (UTC) Received: from lelnx194.ext.ti.com (lelnx194.ext.ti.com [198.47.27.80]) by lists.denx.de (Postfix) with ESMTPS id 50C6FC21D8E for ; Fri, 25 May 2018 09:32:56 +0000 (UTC) Received: from dflxv15.itg.ti.com ([128.247.5.124]) by lelnx194.ext.ti.com (8.15.1/8.15.1) with ESMTP id w4P9WqHU030563; Fri, 25 May 2018 04:32:52 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1527240772; bh=rMJ4J/2AsxJzU4BWTwKoIBiZJqzdhy32nTJuDlhS9W4=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=IsYGz2RMEM8j8QwkqAZrEGH7kjgwTMsYL326dg9kWTrsKM5lEc+ClRrWDPYO0JyzW gihHBBbAiZ3/BwegxQN9woC+iV0t1E/AGqQqgMZNK8mvHG5+mKVVI8HuwdollNUqBl QkLEOThZKbBz3CksVhdq3x+lBQ3nEsPjpl79wciQ= Received: from DLEE105.ent.ti.com (dlee105.ent.ti.com [157.170.170.35]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id w4P9WqC5031950; Fri, 25 May 2018 04:32:52 -0500 Received: from DLEE112.ent.ti.com (157.170.170.23) by DLEE105.ent.ti.com (157.170.170.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1466.3; Fri, 25 May 2018 04:32:52 -0500 Received: from dlep33.itg.ti.com (157.170.170.75) by DLEE112.ent.ti.com (157.170.170.23) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.1466.3 via Frontend Transport; Fri, 25 May 2018 04:32:52 -0500 Received: from localhost (ileax41-snat.itg.ti.com [10.172.224.153]) by dlep33.itg.ti.com (8.14.3/8.13.8) with ESMTP id w4P9WpVi021935; Fri, 25 May 2018 04:32:51 -0500 From: Jean-Jacques Hiblot To: , Date: Fri, 25 May 2018 11:32:41 +0200 Message-ID: <1527240762-27114-7-git-send-email-jjhiblot@ti.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1527240762-27114-1-git-send-email-jjhiblot@ti.com> References: <1527240762-27114-1-git-send-email-jjhiblot@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Cc: u-boot@lists.denx.de Subject: [U-Boot] [PATCH v1 6/7] dwc3-generic: Handle the PHYs, the clocks and the reset lines X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 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" This make the driver more generic. At this point this driver can replace the dwc3-of-simple implementation. Make the description in the Kconfig more generic too. Signed-off-by: Jean-Jacques Hiblot --- drivers/usb/dwc3/Kconfig | 7 +- drivers/usb/dwc3/dwc3-generic.c | 159 +++++++++++++++++++++++++++++++++------- 2 files changed, 136 insertions(+), 30 deletions(-) diff --git a/drivers/usb/dwc3/Kconfig b/drivers/usb/dwc3/Kconfig index 943b763..bbd8105 100644 --- a/drivers/usb/dwc3/Kconfig +++ b/drivers/usb/dwc3/Kconfig @@ -38,10 +38,11 @@ config USB_DWC3_OMAP Say 'Y' here if you have one such device config USB_DWC3_GENERIC - bool "Xilinx ZynqMP and similar Platforms" - depends on DM_USB && USB_DWC3 + bool "Generic implementation of a DWC3 wrapper (aka dwc3 glue)" + depends on DM_USB && USB_DWC3 && MISC help - Some platforms can reuse this DWC3 generic implementation. + Select this for Xilinx ZynqMP and similar Platforms. + This wrapper supports Host and Peripheral operation modes. config USB_DWC3_UNIPHIER bool "DesignWare USB3 Host Support on UniPhier Platforms" diff --git a/drivers/usb/dwc3/dwc3-generic.c b/drivers/usb/dwc3/dwc3-generic.c index 3ec0c0e..977f310 100644 --- a/drivers/usb/dwc3/dwc3-generic.c +++ b/drivers/usb/dwc3/dwc3-generic.c @@ -11,59 +11,85 @@ #include #include #include -#include -#include +#include #include #include #include #include #include "core.h" #include "gadget.h" -#include "linux-compat.h" +#include +#include #ifdef CONFIG_DM_USB_DEV +struct dwc3_generic_peripheral { + struct dwc3 dwc3; + struct phy *phys; + int num_phys; +}; + int dm_usb_gadget_handle_interrupts(struct udevice *dev) { - struct dwc3 *priv = dev_get_priv(dev); + struct dwc3_generic_peripheral *priv = dev_get_priv(dev); + struct dwc3 *dwc3 = &priv->dwc3; - dwc3_gadget_uboot_handle_interrupt(priv); + dwc3_gadget_uboot_handle_interrupt(dwc3); return 0; } static int dwc3_generic_peripheral_probe(struct udevice *dev) { - struct dwc3 *priv = dev_get_priv(dev); + int rc; + struct dwc3_generic_peripheral *priv = dev_get_priv(dev); + struct dwc3 *dwc3 = &priv->dwc3; + + rc = dwc3_setup_phy(dev, &priv->phys, &priv->num_phys); + if (rc) + return rc; + + dwc3->regs = map_physmem(priv->base, DWC3_OTG_REGS_END, MAP_NOCACHE); + dwc3->regs += DWC3_GLOBALS_REGS_START; + dwc3->dev = dev; + + rc = dwc3_init(dwc3); + if (rc) { + unmap_physmem(dwc3->regs, MAP_NOCACHE); + return rc; + } - return dwc3_init(priv); + return 0; } static int dwc3_generic_peripheral_remove(struct udevice *dev) { - struct dwc3 *priv = dev_get_priv(dev); + struct dwc3_generic_peripheral *priv = dev_get_priv(dev); + struct dwc3 *dwc3 = &priv->dwc3; - dwc3_remove(priv); + dwc3_remove(dwc3); + dwc3_shutdown_phy(dev, priv->phys, priv->num_phys); + unmap_physmem(dwc3->regs, MAP_NOCACHE); return 0; } static int dwc3_generic_peripheral_ofdata_to_platdata(struct udevice *dev) { - struct dwc3 *priv = dev_get_priv(dev); + struct dwc3_generic_peripheral *priv = dev_get_priv(dev); + struct dwc3 *dwc3 = &priv->dwc3; int node = dev_of_offset(dev); - priv->regs = (void *)devfdt_get_addr(dev); - priv->regs += DWC3_GLOBALS_REGS_START; + priv->base = devfdt_get_addr(dev); - priv->maximum_speed = usb_get_maximum_speed(node); - if (priv->maximum_speed == USB_SPEED_UNKNOWN) { + dwc3->maximum_speed = usb_get_maximum_speed(node); + if (dwc3->maximum_speed == USB_SPEED_UNKNOWN) { pr_err("Invalid usb maximum speed\n"); return -ENODEV; } - priv->dr_mode = usb_get_dr_mode(node); - if (priv->dr_mode == USB_DR_MODE_UNKNOWN) { + dwc3->dr_mode = usb_get_dr_mode(node); + if (dwc3->dr_mode == USB_DR_MODE_UNKNOWN) { pr_err("Invalid usb mode setup\n"); return -ENODEV; } @@ -77,13 +103,16 @@ U_BOOT_DRIVER(dwc3_generic_peripheral) = { .ofdata_to_platdata = dwc3_generic_peripheral_ofdata_to_platdata, .probe = dwc3_generic_peripheral_probe, .remove = dwc3_generic_peripheral_remove, - .platdata_auto_alloc_size = sizeof(struct usb_platdata), - .priv_auto_alloc_size = sizeof(struct dwc3), + .priv_auto_alloc_size = sizeof(struct dwc3_generic_peripheral), }; - #endif -static int dwc3_generic_bind(struct udevice *parent) +struct dwc3_glue_data { + struct clk_bulk clks; + struct reset_ctl_bulk resets; +}; + +static int dwc3_glue_bind(struct udevice *parent) { const void *fdt = gd->fdt_blob; int node; @@ -94,29 +123,32 @@ static int dwc3_generic_bind(struct udevice *parent) const char *name = fdt_get_name(fdt, node, NULL); enum usb_dr_mode dr_mode; struct udevice *dev; - const char *driver; + const char *driver = NULL; debug("%s: subnode name: %s\n", __func__, name); - if (strncmp(name, "dwc3@", 4)) - continue; dr_mode = usb_get_dr_mode(node); switch (dr_mode) { case USB_DR_MODE_PERIPHERAL: case USB_DR_MODE_OTG: +#ifdef CONFIG_DM_USB_DEV debug("%s: dr_mode: OTG or Peripheral\n", __func__); driver = "dwc3-generic-peripheral"; +#endif break; case USB_DR_MODE_HOST: debug("%s: dr_mode: HOST\n", __func__); - driver = "dwc3-generic-host"; + driver = "xhci-dwc3"; break; default: debug("%s: unsupported dr_mode\n", __func__); return -ENODEV; }; + if (!driver) + continue; + ret = device_bind_driver_to_node(parent, driver, name, offset_to_ofnode(node), &dev); if (ret) { @@ -129,7 +161,76 @@ static int dwc3_generic_bind(struct udevice *parent) return 0; } -static const struct udevice_id dwc3_generic_ids[] = { +static int dwc3_glue_reset_init(struct udevice *dev, + struct dwc3_glue_data *glue) +{ + int ret; + + ret = reset_get_bulk(dev, &glue->resets); + if (ret == -ENOTSUPP) + return 0; + else if (ret) + return ret; + + ret = reset_deassert_bulk(&glue->resets); + if (ret) { + reset_release_bulk(&glue->resets); + return ret; + } + + return 0; +} + +static int dwc3_glue_clk_init(struct udevice *dev, + struct dwc3_glue_data *glue) +{ + int ret; + + ret = clk_get_bulk(dev, &glue->clks); + if (ret == -ENOSYS) + return 0; + if (ret) + return ret; + +#if CONFIG_IS_ENABLED(CLK) + ret = clk_enable_bulk(&glue->clks); + if (ret) { + clk_release_bulk(&glue->clks); + return ret; + } +#endif + + return 0; +} + +static int dwc3_glue_probe(struct udevice *dev) +{ + struct dwc3_glue_data *glue = dev_get_platdata(dev); + int ret; + + ret = dwc3_glue_clk_init(dev, glue); + if (ret) + return ret; + + ret = dwc3_glue_reset_init(dev, glue); + if (ret) + return ret; + + return 0; +} + +static int dwc3_glue_remove(struct udevice *dev) +{ + struct dwc3_glue_data *glue = dev_get_platdata(dev); + + reset_release_bulk(&glue->resets); + + clk_release_bulk(&glue->clks); + + return dm_scan_fdt_dev(dev); +} + +static const struct udevice_id dwc3_glue_ids[] = { { .compatible = "xlnx,zynqmp-dwc3" }, { } }; @@ -137,6 +238,10 @@ static const struct udevice_id dwc3_generic_ids[] = { U_BOOT_DRIVER(dwc3_generic_wrapper) = { .name = "dwc3-generic-wrapper", .id = UCLASS_MISC, - .of_match = dwc3_generic_ids, - .bind = dwc3_generic_bind, + .of_match = dwc3_glue_ids, + .bind = dwc3_glue_bind, + .probe = dwc3_glue_probe, + .remove = dwc3_glue_remove, + .platdata_auto_alloc_size = sizeof(struct dwc3_glue_data), + }; From patchwork Fri May 25 09:32:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Jacques Hiblot X-Patchwork-Id: 920363 X-Patchwork-Delegate: marek.vasut@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=quarantine dis=none) header.from=ti.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ti.com header.i=@ti.com header.b="in4YCPi0"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 40sh4H2v0Wz9s0q for ; Fri, 25 May 2018 19:37:35 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 05784C21E1A; Fri, 25 May 2018 09:35:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 681B9C21E1A; Fri, 25 May 2018 09:33:18 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 41DCFC21DDC; Fri, 25 May 2018 09:33:03 +0000 (UTC) Received: from lelnx194.ext.ti.com (lelnx194.ext.ti.com [198.47.27.80]) by lists.denx.de (Postfix) with ESMTPS id 2C5A6C21E26 for ; Fri, 25 May 2018 09:32:58 +0000 (UTC) Received: from dflxv15.itg.ti.com ([128.247.5.124]) by lelnx194.ext.ti.com (8.15.1/8.15.1) with ESMTP id w4P9WrWR030567; Fri, 25 May 2018 04:32:53 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1527240773; bh=E2Hg3xtBLyhz9+6rH579IZQaF5ND2W9gEmwkRZPl/P8=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=in4YCPi0ZkLQUXQQwc0No9Z2fKx4rUUQgpCDJdw2l2Y+AGuggWm/2OOVjCb+XN8ux jylTZxENb/Q1NSwUXhVjNCx8knVgQCKuHvnOGGvQ1iCHottZSQFosBrSUslLK6nqbo yOnopsR9SIVNAZCqOj4j0aYVAgFogdMVMKrRs7PQ= Received: from DFLE107.ent.ti.com (dfle107.ent.ti.com [10.64.6.28]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id w4P9WrXL032000; Fri, 25 May 2018 04:32:53 -0500 Received: from DFLE101.ent.ti.com (10.64.6.22) by DFLE107.ent.ti.com (10.64.6.28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1466.3; Fri, 25 May 2018 04:32:53 -0500 Received: from dflp33.itg.ti.com (10.64.6.16) by DFLE101.ent.ti.com (10.64.6.22) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.1466.3 via Frontend Transport; Fri, 25 May 2018 04:32:53 -0500 Received: from localhost (ileax41-snat.itg.ti.com [10.172.224.153]) by dflp33.itg.ti.com (8.14.3/8.13.8) with ESMTP id w4P9WqxW029145; Fri, 25 May 2018 04:32:53 -0500 From: Jean-Jacques Hiblot To: , Date: Fri, 25 May 2018 11:32:42 +0200 Message-ID: <1527240762-27114-8-git-send-email-jjhiblot@ti.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1527240762-27114-1-git-send-email-jjhiblot@ti.com> References: <1527240762-27114-1-git-send-email-jjhiblot@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Cc: u-boot@lists.denx.de Subject: [U-Boot] [PATCH v1 7/7] dwc3-generic: Add select_dr_mode operation X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 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" The select_dr_mode operation is executed when the glue driver is probed. The role of this optional function is to configure the operating mode of the controller at the glue level. Signed-off-by: Jean-Jacques Hiblot --- drivers/usb/dwc3/dwc3-generic.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/drivers/usb/dwc3/dwc3-generic.c b/drivers/usb/dwc3/dwc3-generic.c index 977f310..9227501 100644 --- a/drivers/usb/dwc3/dwc3-generic.c +++ b/drivers/usb/dwc3/dwc3-generic.c @@ -8,6 +8,7 @@ */ #include +#include #include #include #include @@ -110,6 +111,12 @@ U_BOOT_DRIVER(dwc3_generic_peripheral) = { struct dwc3_glue_data { struct clk_bulk clks; struct reset_ctl_bulk resets; + fdt_addr_t regs; +}; + +struct dwc3_glue_ops { + void (*select_dr_mode)(struct udevice *dev, int index, + enum usb_dr_mode mode); }; static int dwc3_glue_bind(struct udevice *parent) @@ -205,9 +212,14 @@ static int dwc3_glue_clk_init(struct udevice *dev, static int dwc3_glue_probe(struct udevice *dev) { + struct dwc3_glue_ops *ops = (struct dwc3_glue_ops *)dev_get_driver_data(dev); struct dwc3_glue_data *glue = dev_get_platdata(dev); + struct udevice *child = NULL; + int index = 0; int ret; + glue->regs = dev_read_addr(dev); + ret = dwc3_glue_clk_init(dev, glue); if (ret) return ret; @@ -216,6 +228,20 @@ static int dwc3_glue_probe(struct udevice *dev) if (ret) return ret; + ret = device_find_first_child(dev, &child); + if (ret) + return ret; + + while (child) { + enum usb_dr_mode dr_mode; + + dr_mode = usb_get_dr_mode(dev_of_offset(child)); + device_find_next_child(&child); + if (ops && ops->select_dr_mode) + ops->select_dr_mode(dev, index, dr_mode); + index++; + } + return 0; }