From patchwork Sat Apr 21 12:19:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jagan Teki X-Patchwork-Id: 902396 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=amarulasolutions.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=amarulasolutions.com header.i=@amarulasolutions.com header.b="dmx3GVxX"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 40SsXs0TSVz9s1t for ; Sat, 21 Apr 2018 22:31:40 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id A1EEDC21DB5; Sat, 21 Apr 2018 12:21:45 +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, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, 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 A19C0C21DB6; Sat, 21 Apr 2018 12:20:42 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 99E78C21C93; Sat, 21 Apr 2018 12:20:31 +0000 (UTC) Received: from mail-pg0-f67.google.com (mail-pg0-f67.google.com [74.125.83.67]) by lists.denx.de (Postfix) with ESMTPS id 01922C21E1B for ; Sat, 21 Apr 2018 12:20:25 +0000 (UTC) Received: by mail-pg0-f67.google.com with SMTP id p10so5223777pgn.1 for ; Sat, 21 Apr 2018 05:20:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Jt9v3QN/qbyxlfwvzHXp9H5Q4uQX9vrUKdjGU3hFx9g=; b=dmx3GVxX/z/zxY9uRTqDz/WWux0+aENRDVt333jeKjhiZBsx5vvhkaoVVBcWfrd1o0 6G5/kHmZfnq6DLEMU64Kt7qNNMiHWEcxVrZjXrHwFFQr/8ADJM6UyVx+2b3v4Utye5cw w1cIslj0zcACkQGXHsuNhLXustdwPulgbhI1Y= 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; bh=Jt9v3QN/qbyxlfwvzHXp9H5Q4uQX9vrUKdjGU3hFx9g=; b=FK2zOsJFYXy/HfYE1wtHOYi1Qhqm/cX6wh6xSfnZX2Zka7Uxil6GNYKETjbFxT4cPW QIJiwWytY7nBrhJakImQxvRkoLm8JNNGCVnMG+wpxVS7Bf2NkLYifNnYiX5jR8NMV/Jg vmsz0lNCX/Zb6slg3uR7uE7MHwhXrovM4oV0/uMqc1lc8mwyT6WhjWqiqfyRFKJ0x1Pd YBc9ydQUZVSVA479jmuwhanKxAyNGx3QJTai6Dj30Pt2D+zckLwBN/CFl+5a6drQ0haY VCBozXviOINMcYOKeQ4BYBhJ4Mp3mjsqaS0Xcfe6NghdRj6lV6OgHfs1zAQD+4nymD33 f/fw== X-Gm-Message-State: ALQs6tCMe+eF4Kv+TbI1Lwt7XIOILB1m9GbPZQ4uYfhs35puj/f54ZRo KRhZ90HmDJQ82UawmqCjv0Yi0R97h+E= X-Google-Smtp-Source: AIpwx4/1SnOQLGdZjEHLopajIdbfWrpWut9n1u4BJrMGtQRUQgD3mVFT0EBM8Izde6mHYicbgA0PAg== X-Received: by 10.101.91.204 with SMTP id o12mr9315001pgr.81.1524313223366; Sat, 21 Apr 2018 05:20:23 -0700 (PDT) Received: from localhost.localdomain ([183.82.224.40]) by smtp.gmail.com with ESMTPSA id b3sm13985172pfi.54.2018.04.21.05.20.20 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 21 Apr 2018 05:20:22 -0700 (PDT) From: Jagan Teki To: u-boot@lists.denx.de Date: Sat, 21 Apr 2018 17:49:21 +0530 Message-Id: <20180421121945.12864-11-jagan@amarulasolutions.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180421121945.12864-1-jagan@amarulasolutions.com> References: <20180421121945.12864-1-jagan@amarulasolutions.com> Cc: Maxime Ripard Subject: [U-Boot] [PATCH v5 10/34] phy: sun4i-usb: Add id_detect and vbus_detect ops 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: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" ID and VBUS detection code require when musb changing between Host and/or Peripheral modes. Signed-off-by: Jagan Teki --- drivers/phy/allwinner/phy-sun4i-usb.c | 39 +++++++++++++++++++++++++++++++++++ include/phy-sun4i-usb.h | 26 +++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 include/phy-sun4i-usb.h diff --git a/drivers/phy/allwinner/phy-sun4i-usb.c b/drivers/phy/allwinner/phy-sun4i-usb.c index 78304c1f22..7f2970b96b 100644 --- a/drivers/phy/allwinner/phy-sun4i-usb.c +++ b/drivers/phy/allwinner/phy-sun4i-usb.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -295,6 +296,44 @@ static int sun4i_usb_phy_xlate(struct phy *phy, return 0; } +int sun4i_usb_phy_vbus_detect(struct phy *phy) +{ + struct sun4i_usb_phy_data *data = dev_get_priv(phy->dev); + struct sun4i_usb_phy_plat *usb_phy = &data->usb_phy[phy->id]; + int err, retries = 3; + + debug("%s: id_det = %d\n", __func__, usb_phy->gpio_id_det); + + if (usb_phy->gpio_vbus_det < 0) + return usb_phy->gpio_vbus_det; + + err = gpio_get_value(usb_phy->gpio_vbus_det); + /* + * Vbus may have been provided by the board and just been turned of + * some milliseconds ago on reset, what we're measuring then is a + * residual charge on Vbus, sleep a bit and try again. + */ + while (err > 0 && retries--) { + mdelay(100); + err = gpio_get_value(usb_phy->gpio_vbus_det); + } + + return err; +} + +int sun4i_usb_phy_id_detect(struct phy *phy) +{ + struct sun4i_usb_phy_data *data = dev_get_priv(phy->dev); + struct sun4i_usb_phy_plat *usb_phy = &data->usb_phy[phy->id]; + + debug("%s: id_det = %d\n", __func__, usb_phy->gpio_id_det); + + if (usb_phy->gpio_id_det < 0) + return usb_phy->gpio_id_det; + + return gpio_get_value(usb_phy->gpio_id_det); +} + static struct phy_ops sun4i_usb_phy_ops = { .of_xlate = sun4i_usb_phy_xlate, .init = sun4i_usb_phy_init, diff --git a/include/phy-sun4i-usb.h b/include/phy-sun4i-usb.h new file mode 100644 index 0000000000..040e9d3750 --- /dev/null +++ b/include/phy-sun4i-usb.h @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2017 Jagan Teki + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#ifndef __GENERIC_PHY_SUN4I_USB_H +#define __GENERIC_PHY_SUN4I_USB_H + +/** + * sun4i_usb_phy_id_detect - detect ID pin of USB PHY + * + * @phy: USB PHY port to detect ID pin + * @return 0 if OK, or a negative error code + */ +int sun4i_usb_phy_id_detect(struct phy *phy); + +/** + * sun4i_usb_phy_vbus_detect - detect VBUS pin of USB PHY + * + * @phy: USB PHY port to detect VBUS pin + * @return 0 if OK, or a negative error code + */ +int sun4i_usb_phy_vbus_detect(struct phy *phy); + +#endif /*__GENERIC_PHY_SUN4I_USB_H */