public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Jagan Teki <jagan@amarulasolutions.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v10 11/35] phy: sun4i-usb: Add id_detect and vbus_detect ops
Date: Mon, 28 May 2018 16:48:22 +0530	[thread overview]
Message-ID: <20180528111846.14316-12-jagan@amarulasolutions.com> (raw)
In-Reply-To: <20180528111846.14316-1-jagan@amarulasolutions.com>

ID and VBUS detection code require when musb changing
between Host and/or Peripheral modes.

Signed-off-by: Jagan Teki <jagan@amarulasolutions.com>
Acked-by: Jun Nie <jun.nie@linaro.org>
---
 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 <dm.h>
 #include <dm/device.h>
 #include <generic-phy.h>
+#include <phy-sun4i-usb.h>
 #include <asm/gpio.h>
 #include <asm/io.h>
 #include <asm/arch/clock.h>
@@ -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 <jagan@amarulasolutions.com>
+ *
+ * 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 */
-- 
2.14.3

  parent reply	other threads:[~2018-05-28 11:18 UTC|newest]

Thread overview: 57+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-28 11:18 [U-Boot] [PATCH v10 00/35] phy: sunxi: Add Allwinner sun4i USB PHY Jagan Teki
2018-05-28 11:18 ` [U-Boot] [PATCH v10 01/35] usb: sunxi: Simplify ccm reg base code Jagan Teki
2018-05-28 11:18 ` [U-Boot] [PATCH v10 02/35] musb: sunxi: Add proper macros instead of numericals Jagan Teki
2018-05-28 11:18 ` [U-Boot] [PATCH v10 03/35] musb: sunxi: Use simple way to fill musb_hdrc pdata Jagan Teki
2018-05-28 11:18 ` [U-Boot] [PATCH v10 04/35] musb: sunxi: Add fifo config Jagan Teki
2018-05-28 11:18 ` [U-Boot] [PATCH v10 05/35] sunxi: clock: Fix clock gating for H3/H5/A64 Jagan Teki
2018-05-28 11:18 ` [U-Boot] [PATCH v10 06/35] musb: sunxi: Add OTG device clkgate and reset for H3/H5 Jagan Teki
2018-05-28 11:18 ` [U-Boot] [PATCH v10 07/35] musb: sunxi: Use BIT instead of numerical shift Jagan Teki
2018-05-28 11:18 ` [U-Boot] [PATCH v10 08/35] sunxi: clock: Fix OHCI clock gating for H3/H5 Jagan Teki
2018-05-28 11:18 ` [U-Boot] [PATCH v10 09/35] musb: sunxi: Add support for H3/H5/A64 Jagan Teki
2018-05-28 11:18 ` [U-Boot] [PATCH v10 10/35] phy: Add Allwinner A64 USB PHY driver Jagan Teki
2018-05-28 11:18 ` Jagan Teki [this message]
2018-05-28 11:18 ` [U-Boot] [PATCH v10 12/35] phy: sun4i-usb: Add H3/H5 PHY config Jagan Teki
2018-05-28 11:18 ` [U-Boot] [PATCH v10 13/35] phy: sun4i-usb: Add V3S " Jagan Teki
2018-05-28 11:18 ` [U-Boot] [PATCH v10 14/35] phy: sun4i-usb: Add A83T USB " Jagan Teki
2018-05-28 11:18 ` [U-Boot] [PATCH v10 15/35] phy: sun4i-usb: Add A10/A13/A20 " Jagan Teki
2018-05-28 11:18 ` [U-Boot] [PATCH v10 16/35] phy: sun4i-usb: Add A31 " Jagan Teki
2018-05-28 11:18 ` [U-Boot] [PATCH v10 17/35] phy: sun4i-usb: Add A33 USB " Jagan Teki
2018-05-28 11:18 ` [U-Boot] [PATCH v10 18/35] phy: sun4i-usb: Add A23 " Jagan Teki
2018-05-28 11:18 ` [U-Boot] [PATCH v10 19/35] device-tree-bindings: phy: Sync sun4i-usb-phy bindings Jagan Teki
2018-05-28 11:18 ` [U-Boot] [PATCH v10 20/35] board: sunxi: Use generic-phy for board_usb_cable_connected Jagan Teki
2018-05-28 11:18 ` [U-Boot] [PATCH v10 21/35] phy: sun4i-usb: Add a sunxi specific function for setting squelch-detect Jagan Teki
2018-05-28 11:18 ` [U-Boot] [PATCH v10 22/35] usb: sunxi: Switch to use generic-phy Jagan Teki
2018-06-27 23:09   ` [U-Boot] [linux-sunxi] " Adam Sampson
2018-06-28  0:54     ` Vasily Khoruzhick
2018-06-28  2:08     ` Jagan Teki
2018-05-28 11:18 ` [U-Boot] [PATCH v10 23/35] sunxi: Drop legacy usb_phy.c Jagan Teki
2018-05-28 11:18 ` [U-Boot] [PATCH v10 24/35] sunxi: h3: Sync OTG and HCI nodes from Linux DT Jagan Teki
2018-05-28 11:18 ` [U-Boot] [PATCH v10 25/35] arm64: allwinner: a64: bananapi-m64: Sync usb_otg node from Linux Jagan Teki
2018-05-28 11:18 ` [U-Boot] [PATCH v10 26/35] configs: bananapi-m64: Enable USB OTG peripheral mode Jagan Teki
2018-05-28 11:18 ` [U-Boot] [PATCH v10 27/35] ARM: dts: sun8i: a83t: Sync usbphy node from Linux Jagan Teki
2018-05-28 11:18 ` [U-Boot] [PATCH v10 28/35] arm64: allwinner: a64: bananapi-m64: Sync usb host nodes " Jagan Teki
2018-05-28 11:18 ` [U-Boot] [PATCH v10 29/35] ARM: dts: sun8i-h3: bananapi-m2-plus: Sync usb otg " Jagan Teki
2018-05-28 11:18 ` [U-Boot] [PATCH v10 30/35] configs: bananapi-m2-plus: Enable USB OTG peripheral mode Jagan Teki
2018-05-28 11:18 ` [U-Boot] [PATCH v10 31/35] arm64: allwinner: h5: orangepi-pc2: Order nodes in alphabetic Jagan Teki
2018-05-28 11:18 ` [U-Boot] [PATCH v10 32/35] arm64: allwinner: h5: orangepi-pc2: Sync usb otg nodes from Linux Jagan Teki
2018-05-28 11:18 ` [U-Boot] [PATCH v10 33/35] configs: orangepi-pc2: Enable USB OTG peripheral mode Jagan Teki
2018-05-28 11:18 ` [U-Boot] [PATCH v10 34/35] arm64: allwinner: h5: orangepi-prime: Sync usb otg nodes from Linux Jagan Teki
2018-05-28 11:18 ` [U-Boot] [PATCH v10 35/35] configs: orangepi-prime: Enable USB OTG peripheral mode Jagan Teki
2018-06-01 16:52 ` [U-Boot] [PATCH v10 00/35] phy: sunxi: Add Allwinner sun4i USB PHY Jagan Teki
2018-06-05  4:54   ` Vasily Khoruzhick
2018-06-05  5:11     ` Vasily Khoruzhick
2018-06-05  5:34       ` Jagan Teki
2018-06-05  5:38         ` Vasily Khoruzhick
2018-06-05  5:47           ` Vasily Khoruzhick
2018-06-05  5:51             ` Jagan Teki
2018-06-05  5:58               ` Vasily Khoruzhick
2018-06-05  6:31                 ` Vasily Khoruzhick
2018-06-05  7:02                   ` Vasily Khoruzhick
2018-06-05  7:04                     ` Jagan Teki
2018-06-06  3:39                       ` Vasily Khoruzhick
2018-06-16 18:04                         ` Vasily Khoruzhick
2018-06-18  5:19                           ` Jagan Teki
2018-06-18  5:48                             ` Vasily Khoruzhick
2018-06-18  6:04                               ` Jagan Teki
2018-06-18  6:13                                 ` Vasily Khoruzhick
2018-06-18 16:59                                   ` Tom Rini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180528111846.14316-12-jagan@amarulasolutions.com \
    --to=jagan@amarulasolutions.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox