public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Lu Baolu <baolu.lu@linux.intel.com>
To: Felipe Balbi <balbi@kernel.org>,
	Mathias Nyman <mathias.nyman@intel.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Lee Jones <lee.jones@linaro.org>,
	Heikki Krogerus <heikki.krogerus@linux.intel.com>,
	MyungJoo Ham <myungjoo.ham@samsung.com>,
	Chanwoo Choi <cw00.choi@samsung.com>
Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
	Lu Baolu <baolu.lu@linux.intel.com>,
	David Cohen <david.a.cohen@linux.intel.com>
Subject: [PATCH 4/7] usb: misc: add driver for Intel gpio controlled port mux
Date: Thu,  3 Mar 2016 14:37:41 +0800	[thread overview]
Message-ID: <1456987064-3365-5-git-send-email-baolu.lu@linux.intel.com> (raw)
In-Reply-To: <1456987064-3365-1-git-send-email-baolu.lu@linux.intel.com>

In some Intel platforms, a single usb port is shared between USB host
and device controller. The shared port is under control of GPIO pins.

This patch adds the support for USB GPIO controlled port mux.

Signed-off-by: David Cohen <david.a.cohen@linux.intel.com>
Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Reviewed-by: Felipe Balbi <balbi@kernel.org>
---
 MAINTAINERS                       |   1 +
 drivers/usb/misc/Kconfig          |   9 +++
 drivers/usb/misc/Makefile         |   1 +
 drivers/usb/misc/intel-mux-gpio.c | 126 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 137 insertions(+)
 create mode 100644 drivers/usb/misc/intel-mux-gpio.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 45f1e1e..0f321e4 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -11395,6 +11395,7 @@ L:	linux-usb@vger.kernel.org
 S:	Supported
 F:	drivers/usb/misc/mux.c
 F:	include/linux/usb/mux.h
+F:	drivers/usb/misc/intel-mux-gpio.c
 
 USB PRINTER DRIVER (usblp)
 M:	Pete Zaitcev <zaitcev@redhat.com>
diff --git a/drivers/usb/misc/Kconfig b/drivers/usb/misc/Kconfig
index 6496d17..33e6386 100644
--- a/drivers/usb/misc/Kconfig
+++ b/drivers/usb/misc/Kconfig
@@ -272,3 +272,12 @@ config USB_CHAOSKEY
 
 	  To compile this driver as a module, choose M here: the
 	  module will be called chaoskey.
+
+config INTEL_MUX_GPIO
+	tristate "Intel dual role port mux controlled by GPIOs"
+	depends on GPIOLIB
+	depends on ACPI
+	select USB_MUX
+	help
+	  Say Y here to enable support for Intel dual role port mux
+	  controlled by GPIOs.
diff --git a/drivers/usb/misc/Makefile b/drivers/usb/misc/Makefile
index fd79dd5..da4fb4e 100644
--- a/drivers/usb/misc/Makefile
+++ b/drivers/usb/misc/Makefile
@@ -31,3 +31,4 @@ obj-$(CONFIG_USB_SISUSBVGA)		+= sisusbvga/
 obj-$(CONFIG_USB_LINK_LAYER_TEST)	+= lvstest.o
 
 obj-$(CONFIG_USB_MUX)			+= mux.o
+obj-$(CONFIG_INTEL_MUX_GPIO)		+= intel-mux-gpio.o
diff --git a/drivers/usb/misc/intel-mux-gpio.c b/drivers/usb/misc/intel-mux-gpio.c
new file mode 100644
index 0000000..ae109e3
--- /dev/null
+++ b/drivers/usb/misc/intel-mux-gpio.c
@@ -0,0 +1,126 @@
+/*
+ * USB Dual Role Port Mux driver controlled by gpios
+ *
+ * Copyright (c) 2016, Intel Corporation.
+ * Author: David Cohen <david.a.cohen@linux.intel.com>
+ * Author: Lu Baolu <baolu.lu@linux.intel.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/acpi.h>
+#include <linux/gpio.h>
+#include <linux/platform_device.h>
+#include <linux/usb/mux.h>
+
+struct vuport {
+	struct usb_mux_dev umdev;
+	struct gpio_desc *gpio_vbus_en;
+	struct gpio_desc *gpio_usb_mux;
+};
+
+/*
+ * id == 0, HOST connected, USB port should be set to peripheral
+ * id == 1, HOST disconnected, USB port should be set to host
+ *
+ * Peripheral: set USB mux to peripheral and disable VBUS
+ * Host: set USB mux to host and enable VBUS
+ */
+static inline int vuport_set_port(struct usb_mux_dev *umdev, int id)
+{
+	struct vuport *vup = container_of(umdev, struct vuport, umdev);
+
+	dev_dbg(umdev->dev, "USB PORT ID: %s\n", id ? "HOST" : "PERIPHERAL");
+
+	gpiod_set_value_cansleep(vup->gpio_usb_mux, !id);
+	gpiod_set_value_cansleep(vup->gpio_vbus_en, id);
+
+	return 0;
+}
+
+static int vuport_cable_set(struct usb_mux_dev *umdev)
+{
+	return vuport_set_port(umdev, 1);
+}
+
+static int vuport_cable_unset(struct usb_mux_dev *umdev)
+{
+	return vuport_set_port(umdev, 0);
+}
+
+static int vuport_probe(struct platform_device *pdev)
+{
+	struct usb_mux_dev *umdev;
+	struct device *dev = &pdev->dev;
+	struct vuport *vup;
+
+	vup = devm_kzalloc(dev, sizeof(*vup), GFP_KERNEL);
+	if (!vup)
+		return -ENOMEM;
+
+	/* retrieve vbus and mux gpios */
+	vup->gpio_vbus_en = devm_gpiod_get_optional(dev,
+				"vbus_en", GPIOD_ASIS);
+	if (IS_ERR(vup->gpio_vbus_en))
+		return PTR_ERR(vup->gpio_vbus_en);
+
+	vup->gpio_usb_mux = devm_gpiod_get_optional(dev,
+				"usb_mux", GPIOD_ASIS);
+	if (IS_ERR(vup->gpio_usb_mux))
+		return PTR_ERR(vup->gpio_usb_mux);
+
+	/* populate the mux generic structure */
+	umdev = &vup->umdev;
+	umdev->dev = dev;
+	umdev->cable_name = "USB-HOST";
+	umdev->cable_set_cb = vuport_cable_set;
+	umdev->cable_unset_cb = vuport_cable_unset;
+
+	return usb_mux_register(umdev);
+}
+
+static int vuport_remove(struct platform_device *pdev)
+{
+	return usb_mux_unregister(&pdev->dev);
+}
+
+#ifdef CONFIG_PM_SLEEP
+/*
+ * In case a micro A cable was plugged in while device was sleeping,
+ * we missed the interrupt. We need to poll usb id gpio when waking the
+ * driver to detect the missed event.
+ * We use 'complete' callback to give time to all extcon listeners to
+ * resume before we send new events.
+ */
+static const struct dev_pm_ops vuport_pm_ops = {
+	.complete = usb_mux_complete,
+};
+#endif
+
+static const struct platform_device_id vuport_platform_ids[] = {
+	{ .name = "intel-mux-gpio", },
+	{ /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(platform, vuport_platform_ids);
+
+static struct platform_driver vuport_driver = {
+	.driver = {
+		.name = "intel-mux-gpio",
+		.owner = THIS_MODULE,
+#ifdef CONFIG_PM_SLEEP
+		.pm = &vuport_pm_ops,
+#endif
+	},
+	.probe = vuport_probe,
+	.remove = vuport_remove,
+	.id_table = vuport_platform_ids,
+};
+
+module_platform_driver(vuport_driver);
+
+MODULE_AUTHOR("David Cohen <david.a.cohen@linux.intel.com>");
+MODULE_AUTHOR("Lu Baolu <baolu.lu@linux.intel.com>");
+MODULE_DESCRIPTION("Intel USB gpio mux driver");
+MODULE_LICENSE("GPL v2");
-- 
2.1.4

  parent reply	other threads:[~2016-03-03  6:39 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-03  6:37 [PATCH 0/7] usb: add support for Intel dual role port mux Lu Baolu
2016-03-03  6:37 ` [PATCH 1/7] extcon: usb-gpio: add device binding for platform device Lu Baolu
2016-03-03  7:24   ` Chanwoo Choi
2016-03-03  7:35     ` Lu Baolu
2016-03-03  6:37 ` [PATCH 2/7] extcon: usb-gpio: add support for ACPI gpio interface Lu Baolu
2016-03-03  7:24   ` Chanwoo Choi
2016-03-03  7:35     ` Lu Baolu
2016-03-03  6:37 ` [PATCH 3/7] usb: misc: add common code for Intel dual role port mux Lu Baolu
2016-03-03 16:10   ` Greg Kroah-Hartman
2016-03-04  1:11     ` Lu Baolu
2016-03-03 16:15   ` Greg Kroah-Hartman
2016-03-04  1:25     ` Lu Baolu
2016-03-03  6:37 ` Lu Baolu [this message]
2016-03-03  8:16   ` [PATCH 4/7] usb: misc: add driver for Intel gpio controlled " kbuild test robot
2016-03-03  8:16   ` [PATCH] usb: misc: fix platform_no_drv_owner.cocci warnings kbuild test robot
2016-03-03  6:37 ` [PATCH 5/7] usb: misc: add driver for Intel drcfg controlled port mux Lu Baolu
2016-03-03 15:20   ` kbuild test robot
2016-03-03 16:12   ` Greg Kroah-Hartman
2016-03-04  1:41     ` Lu Baolu
2016-03-03 16:14   ` Greg Kroah-Hartman
2016-03-04  1:38     ` Lu Baolu
2016-03-04  1:44       ` Greg Kroah-Hartman
2016-03-04  1:58         ` Lu Baolu
2016-03-03  6:37 ` [PATCH 6/7] usb: pci-quirks: add Intel USB drcfg mux device Lu Baolu
2016-03-03  6:37 ` [PATCH 7/7] mfd: intel_vuport: Add Intel virtual USB port MFD Driver Lu Baolu
2016-03-03  8:16   ` [PATCH] mfd: intel_vuport: fix platform_no_drv_owner.cocci warnings kbuild test robot
2016-03-03  8:16   ` [PATCH 7/7] mfd: intel_vuport: Add Intel virtual USB port MFD Driver kbuild test robot
2016-03-03 11:35   ` kbuild test robot
2016-03-03 17:26   ` kbuild test robot
2016-03-03 19:57   ` kbuild test robot

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=1456987064-3365-5-git-send-email-baolu.lu@linux.intel.com \
    --to=baolu.lu@linux.intel.com \
    --cc=balbi@kernel.org \
    --cc=cw00.choi@samsung.com \
    --cc=david.a.cohen@linux.intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=heikki.krogerus@linux.intel.com \
    --cc=lee.jones@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=mathias.nyman@intel.com \
    --cc=myungjoo.ham@samsung.com \
    /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