Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B5C85C433F5 for ; Sat, 29 Jan 2022 13:28:12 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 3D1B9820FE; Sat, 29 Jan 2022 14:28:10 +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="SibtWC8p"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5AA0E83675; Sat, 29 Jan 2022 14:28:09 +0100 (CET) Received: from mail-il1-x12c.google.com (mail-il1-x12c.google.com [IPv6:2607:f8b0:4864:20::12c]) (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 A0D97811B3 for ; Sat, 29 Jan 2022 14:28:06 +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=aford173@gmail.com Received: by mail-il1-x12c.google.com with SMTP id d3so7741377ilr.10 for ; Sat, 29 Jan 2022 05:28:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=yob3dweHkIJMYj+dJ5Dmgu13lnO1W/ZSvJHbHvjJXYE=; b=SibtWC8pqvb55JV5sYQXDW/CpndKdDg+lh3zrPJMhqxXAv7Efh07tvG3U1al44TKHp l5NLwLuShzlBESSMNCf6SZ1CqjhJaK/gZBbVzAAP2K7SUes1Lkr/wcmdMWZ6rnlZQabV gD8EIRaM2uNvo/BuuHcjlfeXHXdbIaQ1j7oNoecSnvD+MPhXDkafhrB9Ng94gn9UhQ+c GVahzvohlnbRdyqOlehGpGlxrDbNfx62+BFDyUUyCS7T0cyK2wcMdQoDjNmZY8r/6E1I IXLzTECmfOr9TTyD9dRLhqsAllTCcd27Mva6cFVg8Ido9Iw0yYZTpap+hYll6azJ6oxz 4rfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=yob3dweHkIJMYj+dJ5Dmgu13lnO1W/ZSvJHbHvjJXYE=; b=rJGmt6/HA3yIW1X4zrVZTOlaAzIOyPAFK6MC+1STL0+iZEGEFpk96J1N+t7KHwp2oe 0SXMuis0zp3SFD9NQgKB6jrYtTZeGw+zeGtkTgrKM0mOAAwuBVgjgZaIYYd4PXOR3uAP VaRvkQ/W1/MHjBOf0zgL0dXGR9sII5kldfoppmKtb7HZTCpflXt/OwdevaRBrX2rUMF+ VNLKGmDPY6aziXH8GsS4sf3zLYGZVKp9aFZVTZfPLJxCepvPw4jJVb9SPkdvEpYea8Gw I03N2XOwE10vGsb4Oo6jYHY7n2rep5GHYleTufrABzwij6Jl/BvJRYScEsTD6YjXm2fk yKwQ== X-Gm-Message-State: AOAM533tWHgjwl1q+0soItDL4MV5r2nHyNqr2xoWdR/k3/6pPw4rmnvn /5lrH8Y1FXcpwLYccqvKLkicM1XP0hE= X-Google-Smtp-Source: ABdhPJwYNW+K6l9pYGGGfQ3qOSXJIh7br3xn5mku8cHmxo3eTl3Igm6XeaqwMZOKoI3O6gYldyQUOQ== X-Received: by 2002:a05:6e02:1786:: with SMTP id y6mr9111874ilu.97.1643462884797; Sat, 29 Jan 2022 05:28:04 -0800 (PST) Received: from aford-IdeaCentre-A730.lan ([2601:448:8400:9e8:af81:6db7:3bb:335a]) by smtp.gmail.com with ESMTPSA id x13sm14382074ilu.0.2022.01.29.05.28.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 29 Jan 2022 05:28:04 -0800 (PST) From: Adam Ford To: u-boot@lists.denx.de Cc: trini@konsulko.com, Adam Ford Subject: [PATCH V4] phy: nop-phy: Enable reset-gpios support Date: Sat, 29 Jan 2022 07:27:47 -0600 Message-Id: <20220129132747.2533461-1-aford173@gmail.com> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.103.5 at phobos.denx.de X-Virus-Status: Clean Some usb-nop-xceiv devices use a gpio take them out of reset. Add a reset function to put them into that state. This is similar to how Linux handles the usb-nop-xceiv driver. Signed-off-by: Adam Ford --- V4: Fix build errors on k2e_evm V3: Encapsulate the nop_phy_ops reference to nop_phy_reset in an if-def so it doesn't appear when DM_GPIO is not enabled. V2: Only use the GPIO functions when DM_GPIO is enabled Add error handling so if the GPIO fails, it will shutdown the clocks and return with the error code. Call nop_phy_reset() instead of repeating the same code. diff --git a/drivers/phy/nop-phy.c b/drivers/phy/nop-phy.c index 9f12ebc062..b08eedd4d4 100644 --- a/drivers/phy/nop-phy.c +++ b/drivers/phy/nop-phy.c @@ -10,25 +10,54 @@ #include #include #include +#include struct nop_phy_priv { struct clk_bulk bulk; +#if CONFIG_IS_ENABLED(DM_GPIO) + struct gpio_desc reset_gpio; +#endif }; +#if CONFIG_IS_ENABLED(DM_GPIO) +static int nop_phy_reset(struct phy *phy) +{ + struct nop_phy_priv *priv = dev_get_priv(phy->dev); + + /* Return if there is no gpio since it's optional */ + if (!dm_gpio_is_valid(&priv->reset_gpio)) + return 0; + + return dm_gpio_set_value(&priv->reset_gpio, false); +} +#endif + static int nop_phy_init(struct phy *phy) { struct nop_phy_priv *priv = dev_get_priv(phy->dev); + int ret = 0; - if (CONFIG_IS_ENABLED(CLK)) - return clk_enable_bulk(&priv->bulk); + if (CONFIG_IS_ENABLED(CLK)) { + ret = clk_enable_bulk(&priv->bulk); + if (ret) + return ret; + } +#if CONFIG_IS_ENABLED(DM_GPIO) + ret = nop_phy_reset(phy); + if (ret) { + if (CONFIG_IS_ENABLED(CLK)) + clk_disable_bulk(&priv->bulk); + return ret; + } +#endif return 0; } static int nop_phy_probe(struct udevice *dev) { struct nop_phy_priv *priv = dev_get_priv(dev); - int ret; + int ret = 0; if (CONFIG_IS_ENABLED(CLK)) { ret = clk_get_bulk(dev, &priv->bulk); @@ -37,6 +66,13 @@ static int nop_phy_probe(struct udevice *dev) return ret; } } +#if CONFIG_IS_ENABLED(DM_GPIO) + ret = gpio_request_by_name(dev, "reset-gpios", 0, + &priv->reset_gpio, + GPIOD_IS_OUT); +#endif + if (ret != -ENOENT) + return ret; return 0; } @@ -49,6 +85,9 @@ static const struct udevice_id nop_phy_ids[] = { static struct phy_ops nop_phy_ops = { .init = nop_phy_init, +#if CONFIG_IS_ENABLED(DM_GPIO) + .reset = nop_phy_reset, +#endif }; U_BOOT_DRIVER(nop_phy) = { -- 2.32.0