From patchwork Thu Nov 8 13:13:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 994874 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=none (p=none dis=none) header.from=nic.cz Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; secure) header.d=nic.cz header.i=@nic.cz header.b="dKcGBvSB"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 42rNys5mgbz9s55 for ; Fri, 9 Nov 2018 00:13:57 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 68059C2250D; Thu, 8 Nov 2018 13:13:55 +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=RCVD_IN_DNSWL_BLOCKED, 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 D5274C21F62; Thu, 8 Nov 2018 13:13:45 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id F0DD4C21F62; Thu, 8 Nov 2018 13:13:44 +0000 (UTC) Received: from mail.nic.cz (mail.nic.cz [217.31.204.67]) by lists.denx.de (Postfix) with ESMTPS id 4F36FC21F60 for ; Thu, 8 Nov 2018 13:13:44 +0000 (UTC) Received: from dellmb.labs.office.nic.cz (unknown [IPv6:2001:1488:fffe:6:cac7:3539:7f1f:463]) by mail.nic.cz (Postfix) with ESMTP id EA54C62CDA; Thu, 8 Nov 2018 14:13:43 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=nic.cz; s=default; t=1541682824; bh=JaCcvzquh+gfX6hacyFP2VdxTH33FgeMcWSPKnFar7Q=; h=From:To:Date; b=dKcGBvSBTk/gxqM/dzUyJkd5+PWYZyE+cDCspA/qgTRBxOeAHSCWc2Qu2mewA/IE8 Yw/69sSWGNK3m+AkHuC3e/AiT7JJbTqEve4ymGSaQjc7SdsRhrKH/glMpWXSEazz5K qrmuPmhlIzUJ2kzV4La2dAuCRXkWa9dfQ0YZ/uvs= From: =?utf-8?q?Marek_Beh=C3=BAn?= To: u-boot@lists.denx.de Date: Thu, 8 Nov 2018 14:13:43 +0100 Message-Id: <20181108131343.8193-1-marek.behun@nic.cz> X-Mailer: git-send-email 2.18.1 MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.99.2 at mail X-Virus-Status: Clean Cc: Tom Rini , Stefan Roese Subject: [U-Boot] [PATCH usb RFC] usb: Make vbus-supply code common 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 code for vbus-supply regulator enabling/disabling is repeated in several drivers. Create a header file with static inline definitions of the funtions and use them in some of those drivers. Signed-off-by: Marek BehĂșn --- drivers/usb/host/dwc2.c | 61 ++++----------------------------- drivers/usb/host/ehci-generic.c | 51 +++------------------------ drivers/usb/host/vbus-supply.h | 49 ++++++++++++++++++++++++++ drivers/usb/host/xhci-mvebu.c | 28 +++++++++------ 4 files changed, 76 insertions(+), 113 deletions(-) create mode 100644 drivers/usb/host/vbus-supply.h diff --git a/drivers/usb/host/dwc2.c b/drivers/usb/host/dwc2.c index b6f008a400..51a2e21a6b 100644 --- a/drivers/usb/host/dwc2.c +++ b/drivers/usb/host/dwc2.c @@ -14,9 +14,9 @@ #include #include #include -#include #include +#include "vbus-supply.h" #include "dwc2.h" /* Use only HC channel 0. */ @@ -168,57 +168,6 @@ static void dwc_otg_core_reset(struct dwc2_core_regs *regs) mdelay(100); } -#if defined(CONFIG_DM_USB) && defined(CONFIG_DM_REGULATOR) -static int dwc_vbus_supply_init(struct udevice *dev) -{ - struct dwc2_priv *priv = dev_get_priv(dev); - int ret; - - ret = device_get_supply_regulator(dev, "vbus-supply", - &priv->vbus_supply); - if (ret) { - debug("%s: No vbus supply\n", dev->name); - return 0; - } - - ret = regulator_set_enable(priv->vbus_supply, true); - if (ret) { - dev_err(dev, "Error enabling vbus supply\n"); - return ret; - } - - return 0; -} - -static int dwc_vbus_supply_exit(struct udevice *dev) -{ - struct dwc2_priv *priv = dev_get_priv(dev); - int ret; - - if (priv->vbus_supply) { - ret = regulator_set_enable(priv->vbus_supply, false); - if (ret) { - dev_err(dev, "Error disabling vbus supply\n"); - return ret; - } - } - - return 0; -} -#else -static int dwc_vbus_supply_init(struct udevice *dev) -{ - return 0; -} - -#if defined(CONFIG_DM_USB) -static int dwc_vbus_supply_exit(struct udevice *dev) -{ - return 0; -} -#endif -#endif - /* * This function initializes the DWC_otg controller registers for * host mode. @@ -311,8 +260,10 @@ static void dwc_otg_core_host_init(struct udevice *dev, } } - if (dev) - dwc_vbus_supply_init(dev); + if (dev) { + struct dwc2_priv *priv = dev_get_priv(dev); + enable_vbus_supply(dev, &priv->vbus_supply); + } } /* @@ -1332,7 +1283,7 @@ static int dwc2_usb_remove(struct udevice *dev) struct dwc2_priv *priv = dev_get_priv(dev); int ret; - ret = dwc_vbus_supply_exit(dev); + ret = disable_vbus_supply(priv->vbus_supply); if (ret) return ret; diff --git a/drivers/usb/host/ehci-generic.c b/drivers/usb/host/ehci-generic.c index 0270f3bc95..e47263ba58 100644 --- a/drivers/usb/host/ehci-generic.c +++ b/drivers/usb/host/ehci-generic.c @@ -11,7 +11,7 @@ #include #include #include "ehci.h" -#include +#include "vbus-supply.h" /* * Even though here we don't explicitly use "struct ehci_ctrl" @@ -30,49 +30,6 @@ struct generic_ehci { int reset_count; }; -#ifdef CONFIG_DM_REGULATOR -static int ehci_enable_vbus_supply(struct udevice *dev) -{ - struct generic_ehci *priv = dev_get_priv(dev); - int ret; - - ret = device_get_supply_regulator(dev, "vbus-supply", - &priv->vbus_supply); - if (ret && ret != -ENOENT) - return ret; - - if (priv->vbus_supply) { - ret = regulator_set_enable(priv->vbus_supply, true); - if (ret) { - dev_err(dev, "Error enabling VBUS supply\n"); - return ret; - } - } else { - dev_dbg(dev, "No vbus supply\n"); - } - - return 0; -} - -static int ehci_disable_vbus_supply(struct generic_ehci *priv) -{ - if (priv->vbus_supply) - return regulator_set_enable(priv->vbus_supply, false); - else - return 0; -} -#else -static int ehci_enable_vbus_supply(struct udevice *dev) -{ - return 0; -} - -static int ehci_disable_vbus_supply(struct generic_ehci *priv) -{ - return 0; -} -#endif - static int ehci_usb_probe(struct udevice *dev) { struct generic_ehci *priv = dev_get_priv(dev); @@ -142,7 +99,7 @@ static int ehci_usb_probe(struct udevice *dev) } } - err = ehci_enable_vbus_supply(dev); + err = enable_vbus_supply(dev, &priv->vbus_supply); if (err) goto reset_err; @@ -166,7 +123,7 @@ phy_err: dev_err(dev, "failed to shutdown usb phy\n"); regulator_err: - ret = ehci_disable_vbus_supply(priv); + ret = disable_vbus_supply(priv->vbus_supply); if (ret) dev_err(dev, "failed to disable VBUS supply\n"); @@ -195,7 +152,7 @@ static int ehci_usb_remove(struct udevice *dev) if (ret) return ret; - ret = ehci_disable_vbus_supply(priv); + ret = disable_vbus_supply(priv->vbus_supply); if (ret) return ret; diff --git a/drivers/usb/host/vbus-supply.h b/drivers/usb/host/vbus-supply.h new file mode 100644 index 0000000000..dcd48ab86d --- /dev/null +++ b/drivers/usb/host/vbus-supply.h @@ -0,0 +1,49 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright (C) 2015 Alexey Brodkin + * Copyright (C) 2018 Marek Behun + */ + +#ifndef _VBUS_SUPPLY_H_ +#define _VBUS_SUPPLY_H_ + +#include +#include +#include + +#ifdef CONFIG_DM_REGULATOR +static inline int enable_vbus_supply(struct udevice *dev, + struct udevice **vbus_supply) +{ + int ret; + + ret = device_get_supply_regulator(dev, "vbus-supply", vbus_supply); + if (ret && ret != -ENOENT) + return ret; + + if (*vbus_supply) { + ret = regulator_set_enable(*vbus_supply, true); + if (ret) { + dev_err(dev, "Error enabling VBUS supply\n"); + return ret; + } + } else { + dev_dbg(dev, "No vbus supply\n"); + } + + return 0; +} + +static inline int disable_vbus_supply(struct udevice *vbus_supply) +{ + if (vbus_supply) + return regulator_set_enable(vbus_supply, false); + else + return 0; +} +#else +#define enable_vbus_supply(dev,supply) 0 +#define disable_vbus_supply(supply) 0 +#endif + +#endif /* _VBUS_SUPPLY_H_ */ diff --git a/drivers/usb/host/xhci-mvebu.c b/drivers/usb/host/xhci-mvebu.c index b6c6aaf78e..11aea269d0 100644 --- a/drivers/usb/host/xhci-mvebu.c +++ b/drivers/usb/host/xhci-mvebu.c @@ -9,9 +9,9 @@ #include #include #include -#include #include +#include "vbus-supply.h" #include "xhci.h" struct mvebu_xhci_platdata { @@ -26,6 +26,9 @@ struct mvebu_xhci { struct xhci_ctrl ctrl; /* Needs to come first in this struct! */ struct usb_platdata usb_plat; struct xhci_hccr *hcd; +#ifdef CONFIG_DM_REGULATOR + struct udevice *vbus_supply; +#endif }; /* @@ -43,20 +46,14 @@ static int xhci_usb_probe(struct udevice *dev) struct mvebu_xhci *ctx = dev_get_priv(dev); struct xhci_hcor *hcor; int len, ret; - struct udevice *regulator; ctx->hcd = (struct xhci_hccr *)plat->hcd_base; len = HC_LENGTH(xhci_readl(&ctx->hcd->cr_capbase)); hcor = (struct xhci_hcor *)((uintptr_t)ctx->hcd + len); - ret = device_get_supply_regulator(dev, "vbus-supply", ®ulator); - if (!ret) { - ret = regulator_set_enable(regulator, true); - if (ret) { - printf("Failed to turn ON the VBUS regulator\n"); - return ret; - } - } + ret = enable_vbus_supply(dev, &ctx->vbus_supply); + if (ret < 0) + return ret; /* Enable USB xHCI (VBUS, reset etc) in board specific code */ board_xhci_enable(devfdt_get_addr_index(dev, 1)); @@ -64,6 +61,15 @@ static int xhci_usb_probe(struct udevice *dev) return xhci_register(dev, ctx->hcd, hcor); } +static int xhci_usb_remove(struct udevice *dev) +{ + struct mvebu_xhci *ctx = dev_get_priv(dev); + + disable_vbus_supply(ctx->vbus_supply); + + return xhci_deregister(dev); +} + static int xhci_usb_ofdata_to_platdata(struct udevice *dev) { struct mvebu_xhci_platdata *plat = dev_get_platdata(dev); @@ -93,7 +99,7 @@ U_BOOT_DRIVER(usb_xhci) = { .of_match = xhci_usb_ids, .ofdata_to_platdata = xhci_usb_ofdata_to_platdata, .probe = xhci_usb_probe, - .remove = xhci_deregister, + .remove = xhci_usb_remove, .ops = &xhci_usb_ops, .platdata_auto_alloc_size = sizeof(struct mvebu_xhci_platdata), .priv_auto_alloc_size = sizeof(struct mvebu_xhci),