From patchwork Sun Mar 7 18:58:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ying-Chun Liu X-Patchwork-Id: 395152 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp1145768jai; Sun, 7 Mar 2021 10:58:58 -0800 (PST) X-Google-Smtp-Source: ABdhPJwVWLtSwGQuWPM1MVKpVh2A2p/X0yRazrcXn/k0sP4awYj+Jn0OmVIm+mn+hGS8uV8DlgjT X-Received: by 2002:a17:906:1182:: with SMTP id n2mr11975881eja.234.1615143537960; Sun, 07 Mar 2021 10:58:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615143537; cv=none; d=google.com; s=arc-20160816; b=HdKmaRGxkVDg4nSPoHDEfUiWesf5wyOyyQiT5oQc2S9gjOx/oxIZ31+kmAWYAEzcjF +KiV3qIC+19SCG3szk0FuRYNpmM8mgugonRhJlysK03WU3FcndHsveGPIW9KjknLA6jm Jf0Tgb6lMTvhKqw1igkjyYrWUV/kqqXRvq5aFOedgpPPSrMCudcw0cBGESgstBgNd1My hPbUdn5P2UgqiW1bOnNkh7+xy1ByY0aJPRVd9nL061oB7wPXeAYDpwITDxr7dDRq5QbU HotZe3XeatpWkgFMhJz4qmQ2sS5eDWf6PEsufC+NRVIRa1iybYRn/dytkzbcrZme8hzh DjiA== ARC-Message-Signature: i=1; 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=+iEmaVAFiF0zMhH/z6ndKwrGnwH7coMIetTB2us2we4=; b=G8Wbj8MPS7uJ3GOjRcO4FP0DbO0JMfSSdyaG2lh+8p9lp8foJjafxLiX++0dABapO3 niWftDBoY3GdLyuwjSxtsjHkoqu8Hhp+57AzhpFmZ4YgKhjAH5zgPQnWOms3u0dWQbDI +688De7nC8tNEjDzKGloiRj9tc9I4aR/9p/gxQU4UQHkPi5YGCruWFXBFgjL0rAE7BDM xTnuZelZGpqngsHrZZG7z8cbSTz3DJ6DtPdZBweToc2h9XY4aoZ0oQydt8UQacDpd4P/ Uq2vzAfLm2a0RdbKod7VDWVBJyg/PvJKA8uGXX/TaNbP51yEius/oDEJCRhbGrfCMq66 EyBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=SsBFoejN; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id cf6si5553914ejb.272.2021.03.07.10.58.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Mar 2021 10:58:57 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=SsBFoejN; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 858318278B; Sun, 7 Mar 2021 19:58:47 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="SsBFoejN"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id B501C8279C; Sun, 7 Mar 2021 19:58:45 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id F281982699 for ; Sun, 7 Mar 2021 19:58:41 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=grandpaul@gmail.com Received: by mail-pf1-x434.google.com with SMTP id a188so5766823pfb.4 for ; Sun, 07 Mar 2021 10:58:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+iEmaVAFiF0zMhH/z6ndKwrGnwH7coMIetTB2us2we4=; b=SsBFoejNska80f5TgUaTt4Uy+MIr69GNtYpPb006dJ5uZFv70PPs5UD21NzsNJgXP2 RgfwMOycCjxk0xWEQEabY9kWWgyvmcSN8PKGkPV9iiqiUoW7dBdwLAzymioere/7pefW 6uNbmxe3rYb9Tr0wan7JqiO5URn1L8t5LbQfOiJI6jCNwFwx1jvTdWpDglE6hsMplir0 JQCSzptf/L0+OQRrkI+EspbEu1cUgUGv/saD8nH7aZqZQxP/IN9hzt2zq/HL9Ie1q/ak z5w/jHZKWrjfh4iyHYG3GMswSx/smjKJsVC3WBu9zXtd9Tn91fHtsJeV4fJks2H+ZMOl 5DJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+iEmaVAFiF0zMhH/z6ndKwrGnwH7coMIetTB2us2we4=; b=QShvFEhGPiPoUWc7ZlF0crrBBUiwQHRsbwJeY6yx+iblKF0wvVEnbjeYh0oUNjbcha hWe50O9fwoffwKxkB3rk0DMYA/oohcRKTXk5CLSbgevhlSwQCbJvO31XfkiqzbsEGVJw 15kaNrgLQl2LwILNOyBplmaPL28CwbC9aXcva6zqM0zGYQVrbQCpvjzTj8Daz4/Ns85b +xcGTZuy8YEWcMFwQr8McKBv2yUWp+r2Q9+S/6/sceTggO70Ot8al7pqV4+8SAbouYB5 4xXHQxOtPcgYgBAVdqc4asiJAAZQuOTG7S1cyMj08CufHAv2XAFl2D3NJeOQtgC1scTU 2yZQ== X-Gm-Message-State: AOAM533HP8A6dveiaSlNiOlK9Pm+QiqooW/MlhGoQu+ItnbDnZ7Qq3PA G9NPj+wHUWyodjRjb9s7o11apMx5st0= X-Received: by 2002:a63:ab05:: with SMTP id p5mr1521263pgf.149.1615143519985; Sun, 07 Mar 2021 10:58:39 -0800 (PST) Received: from localhost (host-111-184-129-17.dynamic.kbtelecom.net. [111.184.129.17]) by smtp.gmail.com with ESMTPSA id i7sm7836702pfq.184.2021.03.07.10.58.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Mar 2021 10:58:39 -0800 (PST) From: Ying-Chun Liu To: u-boot@lists.denx.de Cc: "Ying-Chun Liu (PaulLiu)" Subject: [PATCH 1/2] drivers: usb: phy: add driver for usb-nop-xceiv Date: Mon, 8 Mar 2021 02:58:28 +0800 Message-Id: <20210307185829.97583-2-grandpaul@gmail.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210307185829.97583-1-grandpaul@gmail.com> References: <20210307185829.97583-1-grandpaul@gmail.com> MIME-Version: 1.0 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.4 at phobos.denx.de X-Virus-Status: Clean From: "Ying-Chun Liu (PaulLiu)" implement the generic NOP USB transceiver for all USB transceiver which are either built-in into USB IP or which are mostly autonomous. Signed-off-by: Ying-Chun Liu (PaulLiu) --- drivers/usb/phy/Kconfig | 8 ++ drivers/usb/phy/Makefile | 1 + drivers/usb/phy/usb_nop_phy.c | 137 ++++++++++++++++++++++++++++++++++ 3 files changed, 146 insertions(+) create mode 100644 drivers/usb/phy/usb_nop_phy.c -- 2.30.1 diff --git a/drivers/usb/phy/Kconfig b/drivers/usb/phy/Kconfig index 8741553d09..663b50a937 100644 --- a/drivers/usb/phy/Kconfig +++ b/drivers/usb/phy/Kconfig @@ -13,3 +13,11 @@ config OMAP_USB_PHY config ROCKCHIP_USB2_PHY bool "Rockchip USB2 PHY" + +config NOP_USB_XCEIV + bool "NOP USB Transceiver Driver" + depends on PHY + help + This driver is to be used by all the usb transceiver which are either + built-in with usb ip or which are autonomous and doesn't require any + phy programming such as ISP1x04 etc. diff --git a/drivers/usb/phy/Makefile b/drivers/usb/phy/Makefile index 20f7edf48d..079e24770f 100644 --- a/drivers/usb/phy/Makefile +++ b/drivers/usb/phy/Makefile @@ -6,3 +6,4 @@ obj-$(CONFIG_TWL4030_USB) += twl4030.o obj-$(CONFIG_OMAP_USB_PHY) += omap_usb_phy.o obj-$(CONFIG_ROCKCHIP_USB2_PHY) += rockchip_usb2_phy.o +obj-$(CONFIG_NOP_USB_XCEIV) += usb_nop_phy.o diff --git a/drivers/usb/phy/usb_nop_phy.c b/drivers/usb/phy/usb_nop_phy.c new file mode 100644 index 0000000000..7f4133af39 --- /dev/null +++ b/drivers/usb/phy/usb_nop_phy.c @@ -0,0 +1,137 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * NOP USB transceiver for all USB transceiver which are either built-in + * into USB IP or which are mostly autonomous. + * + * Copyright (C) 2009 Texas Instruments Inc + * Copyright (C) 2017 Texas Instruments Incorporated - http://www.ti.com/ + * Copyright (C) 2021 Linaro + * Author: Ajay Kumar Gupta + * Jean-Jacques Hiblot + * Ying-Chun Liu (PaulLiu) + * Current status: + * This provides a "nop" transceiver for PHYs which are + * autonomous such as isp1504, isp1707, etc. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +struct usb_nop_phy_priv { + struct clk_bulk bulk; + struct udevice *vcc; + struct gpio_desc *gpiod_reset; + struct gpio_desc *gpiod_vbus; +}; + +static int usb_nop_phy_reset(struct phy *phy) +{ + int ret = 0; + struct usb_nop_phy_priv *priv = dev_get_priv(phy->dev); + + if (!priv->gpiod_reset) + return ret; + + ret = dm_gpio_set_value(priv->gpiod_reset, 1); + mdelay(20); + ret = dm_gpio_set_value(priv->gpiod_reset, 0); + + return ret; +} + +static int usb_nop_phy_init(struct phy *phy) +{ + struct usb_nop_phy_priv *priv = dev_get_priv(phy->dev); + int ret = 0; + + if (CONFIG_IS_ENABLED(DM_REGULATOR) && priv->vcc) { + ret = regulator_set_enable(priv->vcc, true); + if (ret < 0) { + dev_err(phy->dev, "Failed to enable power: %d\n", ret); + return ret; + } + } + + if (CONFIG_IS_ENABLED(CLK)) { + ret = clk_enable_bulk(&priv->bulk); + if (ret < 0) { + dev_err(phy->dev, "Failed to enable clk: %d\n", ret); + return ret; + } + } + + return ret; +} + +static int usb_nop_phy_probe(struct udevice *dev) +{ + struct usb_nop_phy_priv *priv = dev_get_priv(dev); + u32 clk_rate = 0; + int i, ret = 0; + + /* Get all clocks. Actually only main_clk should be assigned */ + if (CONFIG_IS_ENABLED(CLK)) { + ret = clk_get_bulk(dev, &priv->bulk); + if (ret < 0) + dev_info(dev, "failed to get clock: %d\n", ret); + } + + /* Get vcc-supply */ + if (CONFIG_IS_ENABLED(DM_REGULATOR)) { + ret = device_get_supply_regulator(dev, "vcc-supply", &priv->vcc); + if (ret < 0) { + dev_info(dev, "failed to get vcc-supply: %d\n", ret); + priv->vcc = NULL; + } + } + + ret = ofnode_read_u32(dev_ofnode(dev), "clock-frequency", &clk_rate); + if (ret < 0) + clk_rate = 0; + + priv->gpiod_reset = devm_gpiod_get_optional(dev, "reset", 0); + if (priv->gpiod_reset) + priv->gpiod_vbus = devm_gpiod_get_optional(dev, + "vbus-detect", + 0); + + if (clk_rate) + for (i = 0; i < priv->bulk.count; i++) { + ret = clk_set_rate(&priv->bulk.clks[i], clk_rate); + if (ret < 0) { + dev_err(dev, + "Failed to set clk rate %d: %d\n", + clk_rate, + ret); + return ret; + } + } + + return 0; +} + +static const struct udevice_id usb_nop_phy_ids[] = { + { .compatible = "usb-nop-xceiv" }, + { } +}; + +static struct phy_ops usb_nop_phy_ops = { + .init = usb_nop_phy_init, + .reset = usb_nop_phy_reset, +}; + +U_BOOT_DRIVER(usb_nop_phy) = { + .name = "usb_nop_phy", + .id = UCLASS_PHY, + .of_match = usb_nop_phy_ids, + .ops = &usb_nop_phy_ops, + .probe = usb_nop_phy_probe, + .priv_auto = sizeof(struct usb_nop_phy_priv), +};