mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Kishon Vijay Abraham I <kishon@ti.com>
To: <gregkh@linuxfoundation.org>
Cc: <kishon@ti.com>, <linux-kernel@vger.kernel.org>
Subject: [PATCH 04/19] phy-sun4i-usb: Add extcon support for the otg phy (phy0)
Date: Tue, 11 Aug 2015 21:27:03 +0530	[thread overview]
Message-ID: <1439308638-14582-5-git-send-email-kishon@ti.com> (raw)
In-Reply-To: <1439308638-14582-1-git-send-email-kishon@ti.com>

From: Hans de Goede <hdegoede@redhat.com>

The sunxi musb glue needs to know if a host or normal usb cable is plugged
in, add extcon support so that the musb glue can monitor the host status.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Acked-by: Chanwoo Choi <cw00.choi@samsung.com>
Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
---
 drivers/phy/Kconfig         |    1 +
 drivers/phy/phy-sun4i-usb.c |   32 +++++++++++++++++++++++++++++++-
 2 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
index e2f2a4d..c0c1ad2 100644
--- a/drivers/phy/Kconfig
+++ b/drivers/phy/Kconfig
@@ -208,6 +208,7 @@ config PHY_SUN4I_USB
 	tristate "Allwinner sunxi SoC USB PHY driver"
 	depends on ARCH_SUNXI && HAS_IOMEM && OF
 	depends on RESET_CONTROLLER
+	depends on EXTCON
 	select GENERIC_PHY
 	help
 	  Enable this to support the transceiver that is part of Allwinner
diff --git a/drivers/phy/phy-sun4i-usb.c b/drivers/phy/phy-sun4i-usb.c
index 37f52f7..a6ea2e6 100644
--- a/drivers/phy/phy-sun4i-usb.c
+++ b/drivers/phy/phy-sun4i-usb.c
@@ -23,6 +23,7 @@
 
 #include <linux/clk.h>
 #include <linux/err.h>
+#include <linux/extcon.h>
 #include <linux/io.h>
 #include <linux/interrupt.h>
 #include <linux/kernel.h>
@@ -99,6 +100,7 @@ struct sun4i_usb_phy_data {
 		int index;
 	} phys[MAX_PHYS];
 	/* phy0 / otg related variables */
+	struct extcon_dev *extcon;
 	bool phy0_init;
 	bool phy0_poll;
 	struct gpio_desc *id_det_gpio;
@@ -343,7 +345,7 @@ static void sun4i_usb_phy0_id_vbus_det_scan(struct work_struct *work)
 	struct sun4i_usb_phy_data *data =
 		container_of(work, struct sun4i_usb_phy_data, detect.work);
 	struct phy *phy0 = data->phys[0].phy;
-	int id_det, vbus_det;
+	int id_det, vbus_det, id_notify = 0, vbus_notify = 0;
 
 	id_det = gpiod_get_value_cansleep(data->id_det_gpio);
 	vbus_det = gpiod_get_value_cansleep(data->vbus_det_gpio);
@@ -358,15 +360,24 @@ static void sun4i_usb_phy0_id_vbus_det_scan(struct work_struct *work)
 	if (id_det != data->id_det) {
 		sun4i_usb_phy0_set_id_detect(phy0, id_det);
 		data->id_det = id_det;
+		id_notify = 1;
 	}
 
 	if (vbus_det != data->vbus_det) {
 		sun4i_usb_phy0_set_vbus_detect(phy0, vbus_det);
 		data->vbus_det = vbus_det;
+		vbus_notify = 1;
 	}
 
 	mutex_unlock(&phy0->mutex);
 
+	if (id_notify)
+		extcon_set_cable_state_(data->extcon, EXTCON_USB_HOST,
+					!id_det);
+
+	if (vbus_notify)
+		extcon_set_cable_state_(data->extcon, EXTCON_USB, vbus_det);
+
 	if (data->phy0_poll)
 		queue_delayed_work(system_wq, &data->detect, POLL_TIME);
 }
@@ -407,6 +418,12 @@ static int sun4i_usb_phy_remove(struct platform_device *pdev)
 	return 0;
 }
 
+static const unsigned int sun4i_usb_phy0_cable[] = {
+	EXTCON_USB,
+	EXTCON_USB_HOST,
+	EXTCON_NONE,
+};
+
 static int sun4i_usb_phy_probe(struct platform_device *pdev)
 {
 	struct sun4i_usb_phy_data *data;
@@ -466,6 +483,19 @@ static int sun4i_usb_phy_probe(struct platform_device *pdev)
 		return -ENODEV;
 	}
 
+	if (data->id_det_gpio) {
+		data->extcon = devm_extcon_dev_allocate(dev,
+							sun4i_usb_phy0_cable);
+		if (IS_ERR(data->extcon))
+			return PTR_ERR(data->extcon);
+
+		ret = devm_extcon_dev_register(dev, data->extcon);
+		if (ret) {
+			dev_err(dev, "failed to register extcon: %d\n", ret);
+			return ret;
+		}
+	}
+
 	for (i = 0; i < data->num_phys; i++) {
 		struct sun4i_usb_phy *phy = data->phys + i;
 		char name[16];
-- 
1.7.9.5


  parent reply	other threads:[~2015-08-11 15:57 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-11 15:56 [GIT PULL 00/19] phy: for 4.3 Kishon Vijay Abraham I
2015-08-11 15:57 ` [PATCH 01/19] phy: add lpc18xx usb otg phy driver Kishon Vijay Abraham I
2015-08-11 15:57 ` [PATCH 02/19] phy: dt bindings: add NXP LPC18xx/43xx USB OTG PHY bindings Kishon Vijay Abraham I
2015-08-11 15:57 ` [PATCH 03/19] phy-sun4i-usb: Add id and vbus detection support for the otg phy (phy0) Kishon Vijay Abraham I
2015-08-11 15:57 ` Kishon Vijay Abraham I [this message]
2015-08-11 15:57 ` [PATCH 05/19] phy-sun4i-usb: Swap check for disconnect threshold Kishon Vijay Abraham I
2015-08-11 15:57 ` [PATCH 06/19] phy-sun4i-usb: Add support for the usb-phys on the sun8i-a23 SoC Kishon Vijay Abraham I
2015-08-11 15:57 ` [PATCH 07/19] phy-sun4i-usb: Add support for the usb-phys on the sun8i-a33 SoC Kishon Vijay Abraham I
2015-08-11 15:57 ` [PATCH 08/19] phy-sun4i-usb: Add support for boards with broken Vusb-detection Kishon Vijay Abraham I
2015-08-11 15:57 ` [PATCH 09/19] phy-sun4i-usb: Add support for monitoring vbus via a power-supply Kishon Vijay Abraham I
2015-08-11 15:57 ` [PATCH 10/19] phy: berlin: .owner field is setup by core Kishon Vijay Abraham I
2015-08-11 15:57 ` [PATCH 11/19] phy: berlin: Do not use sata name in usb phy driver Kishon Vijay Abraham I
2015-08-11 15:57 ` [PATCH 12/19] phy: berlin: Trivial coding style cleanup Kishon Vijay Abraham I
2015-08-11 15:57 ` [PATCH 13/19] phy: Drop owner assignment from i2c_driver Kishon Vijay Abraham I
2015-08-11 15:57 ` [PATCH 14/19] phy: Drop owner assignment from platform_driver Kishon Vijay Abraham I
2015-08-11 15:57 ` [PATCH 15/19] phy-sun4i-sub: Move vbus-detect helper functions up in the file Kishon Vijay Abraham I
2015-08-11 15:57 ` [PATCH 16/19] phy-sun4i-usb: Only check vbus-det on power-on on boards with vbus-det Kishon Vijay Abraham I
2015-08-11 15:57 ` [PATCH 17/19] phy: ulpi_phy: Add const qualifier to ops Kishon Vijay Abraham I
2015-08-11 15:57 ` [PATCH 18/19] phy: Constify struct phy_ops variables Kishon Vijay Abraham I
2015-08-11 15:57 ` [PATCH 19/19] phy: lpc18xx-usb-otg: fix clock order in phy init Kishon Vijay Abraham I
2015-08-14 23:47 ` [GIT PULL 00/19] phy: for 4.3 Greg KH

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=1439308638-14582-5-git-send-email-kishon@ti.com \
    --to=kishon@ti.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    /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

all inboxes | Powered by JetHome®