From patchwork Tue Feb 6 14:25:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jagan Teki X-Patchwork-Id: 869807 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; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="BRXsj/Bk"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3zbRx3362Xz9s8J for ; Wed, 7 Feb 2018 01:41:43 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id E382FC21E37; Tue, 6 Feb 2018 14:33:59 +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=FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H2, 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 45DFFC21E67; Tue, 6 Feb 2018 14:32:18 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 3704CC21C3F; Tue, 6 Feb 2018 14:31:57 +0000 (UTC) Received: from mail-pf0-f193.google.com (mail-pf0-f193.google.com [209.85.192.193]) by lists.denx.de (Postfix) with ESMTPS id 2A266C21DA1 for ; Tue, 6 Feb 2018 14:31:52 +0000 (UTC) Received: by mail-pf0-f193.google.com with SMTP id l9so669037pfi.6 for ; Tue, 06 Feb 2018 06:31:52 -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; bh=GJAIxx0xSS8KGpDHpxHYKjW60dJ5+yYRwu7OCSdel/M=; b=BRXsj/BkC6pe7SPBH4/E1xXDjgBdyin9SozXsNqfz544nue4VxcyC5Ptz/aT90jNQe TTjgbw5G+LfVp0Qq4kS0BTU0F11bW43iYfhAi559beb/bSW/oSSpnFg3z3wS8WZKgDWR Mudg82FsVoPA4FAXNIJ1SEgV+NNSbJhaspzXRNfegFYLL3zy+4V2pRAEtfA5rrYeiyqi jEAQDZOJzGdg3wTSG+XVej2/qIDYJUMjKw1beQmAzsGM0rVA1tCRCtb5vGCRq5wQiwsk NNS3TR4UDarnVBrvgpEbkwRCYDHEu0U1mQ2FnQSJ/KZEWKfBnIcpptGi5YU7Psz25fV9 TM0w== 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=GJAIxx0xSS8KGpDHpxHYKjW60dJ5+yYRwu7OCSdel/M=; b=X5w3uKh7Cy7A9IZqQx3+8PNKgYxq2lu0nGCVxTvCrXNWTbwDb0H4vx+UvncjGE76jM XqsnWnwG9Ww98xYunHXSx9r4dY8DHtolc3yomEyNXgaAv6nulLFsjeoO/1xwRLHRrobd JpafcAysykh/oj4fqrKiYgMwJjup2Lsq/Am5uQC3oOIitX7Eluy6z2UhapklDSl7JEUd qL9XKVXlOWysW5J6u1BsIDZTOKWyqp2VSm67doEhtbLX1q5wD+1wvCymW8gjMGljP8LP ni2Wg50A7/LskcTQfL2C4jl6BQnMXRnrc7sWa4K99fjBsnuBZRYwC3xCFv+Z0KJp0zCy 0GHg== X-Gm-Message-State: APf1xPBCu/mmGi6ZLN02TzWubeGvdasehXJZxVofFvEz/OLLW+kf35KE Vu24e6S6TuUFNE26bgJv4XK+0Vf7 X-Google-Smtp-Source: AH8x224yfa6wZflRrS0RbzPdhUK71aYFEfF3MwhX6MLAbBaBefanrCQWQhOeI029aCUCRmQbdXPV7w== X-Received: by 10.99.50.66 with SMTP id y63mr2099546pgy.157.1517927510421; Tue, 06 Feb 2018 06:31:50 -0800 (PST) Received: from localhost.localdomain ([115.97.187.51]) by smtp.gmail.com with ESMTPSA id h2sm17457613pgp.65.2018.02.06.06.31.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 06 Feb 2018 06:31:49 -0800 (PST) From: Jagan Teki X-Google-Original-From: Jagan Teki To: u-boot@lists.denx.de Date: Tue, 6 Feb 2018 19:55:40 +0530 Message-Id: <1517927164-18197-11-git-send-email-jagan@amarulasolutions.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1517927164-18197-1-git-send-email-jagan@amarulasolutions.com> References: <1517927164-18197-1-git-send-email-jagan@amarulasolutions.com> Cc: Marek Vasut , Maxime Ripard Subject: [U-Boot] [PATCH v4 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 78304c1..7f2970b 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 0000000..040e9d3 --- /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 */