All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v5 0/6] usb: add support for Intel dual role port mux
@ 2016-03-18  6:32 Lu Baolu
  2016-03-18  6:32 ` [PATCH v5 1/6] extcon: usb-gpio: add device binding for platform device Lu Baolu
                   ` (5 more replies)
  0 siblings, 6 replies; 12+ messages in thread
From: Lu Baolu @ 2016-03-18  6:32 UTC (permalink / raw)
  To: Felipe Balbi, Mathias Nyman, Greg Kroah-Hartman, Lee Jones,
	Heikki Krogerus, MyungJoo Ham, Chanwoo Choi
  Cc: linux-usb, linux-kernel, Lu Baolu

Intel SOC chips are featured with USB dual role. The host role is
provided by Intel xHCI IP, and the gadget role is provided by IP
from designware. Tablet platform designs always share a single
port for both host and gadget controllers. There is a mux to
switch the port to the right controller according to the cable
type. OS needs to provide the callback to control the mux when
a plug-in event raises. The method to control the mux is platform
dependent. At least three types of implementation can be found
across current devices. 1) GPIO pins; 2) a unit which can be
controlled by memory mapped registers; 3) ACPI ASL code.

This patch series adds supports for Intel dual role port mux.
It includes:
(1) A helper layer on top of extcon for individual mux driver.
    It listens to the USB-HOST extcon cable and call the switch
    call-back when the cable state changes.
(2) Drivers for GPIO controlled port mux which could be found on
    Baytrail devices. A mfd driver is used to split the GPIOs into
    USB gpio extcon device and a USB mux device. Driver for USB
    gpio extcon device is already in upstream Linux. This patch
    series includes a driver for GPIO USB mux.
(3) Drivers for USB port mux controlled through memory mapped
    registers and the logic to create the mux device. This type
    of dual role port mux could be found in Cherry Trail and
    Broxton devices.

Lu Baolu (6):
  extcon: usb-gpio: add device binding for platform device
  extcon: usb-gpio: add support for ACPI gpio interface
  usb: mux: add common code for Intel dual role port mux
  usb: mux: add driver for Intel gpio controlled port mux
  usb: mux: add driver for Intel drcfg controlled port mux
  mfd: intel_vuport: Add Intel virtual USB port MFD Driver

Change log:
v4->v5:
 - Change the extcon interfaces with the new ones suggested by
   2a9de9c0f08d6 (extcon: Use the unique id for external connector
   instead of string)
 - remove patch "usb: pci-quirks: add Intel USB drcfg mux device"
   from this serial due to that it's not driver staff. Will be
   submitted seperately.

v3->v4:
 - Check all patches with "checkpatch.pl --strict", and fix all
   CHECKs;
 - Change sysfs node from "intel_mux" to "port_mux";
 - Refines below confusing functions:
   intel_usb_mux_register() -> intel_usb_mux_bind_cable()
   intel_usb_mux_unregister() -> intel_usb_mux_unbind_cable();
 - Remove unnecessary struct intel_mux_dev.

v2->v3:
 - uvport mfd driver got reviewed by Lee Jones, the following
   changes were made accordingly.
 - seperate uvport driver from the mux drivers in MAINTAINERS file
 - refine the description in Kconfig
 - refine the mfd_cell structure data

v1->v2:
 - move mux driver from drivers/usb/misc to drivers/usb/mux;
 - replace debugfs with sysfs for user level mux control;
 - remove unnecessary register restore if mux registeration failed;
 - Add "Acked-by: Chanwoo Choi <cw00.choi@samsung.com>" to extcon changes;
 - Make the file names and exported function names more specific;
 - Remove the usb_mux_get_dev() interface;
 - Move "struct intel_usb_mux" from .h to .c file;
 - Fix various kbuild robot warnings.

 Documentation/ABI/testing/sysfs-bus-platform |  15 +++
 MAINTAINERS                                  |  15 +++
 drivers/extcon/extcon-usb-gpio.c             |  10 +-
 drivers/mfd/Kconfig                          |   8 ++
 drivers/mfd/Makefile                         |   1 +
 drivers/mfd/intel-vuport.c                   |  74 +++++++++++
 drivers/usb/Kconfig                          |   2 +
 drivers/usb/Makefile                         |   1 +
 drivers/usb/mux/Kconfig                      |  28 +++++
 drivers/usb/mux/Makefile                     |   6 +
 drivers/usb/mux/intel-mux-drcfg.c            | 159 ++++++++++++++++++++++++
 drivers/usb/mux/intel-mux-gpio.c             | 122 +++++++++++++++++++
 drivers/usb/mux/intel-mux.c                  | 175 +++++++++++++++++++++++++++
 include/linux/usb/intel-mux.h                |  40 ++++++
 14 files changed, 655 insertions(+), 1 deletion(-)
 create mode 100644 drivers/mfd/intel-vuport.c
 create mode 100644 drivers/usb/mux/Kconfig
 create mode 100644 drivers/usb/mux/Makefile
 create mode 100644 drivers/usb/mux/intel-mux-drcfg.c
 create mode 100644 drivers/usb/mux/intel-mux-gpio.c
 create mode 100644 drivers/usb/mux/intel-mux.c
 create mode 100644 include/linux/usb/intel-mux.h

-- 
2.1.4

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v5 1/6] extcon: usb-gpio: add device binding for platform device
  2016-03-18  6:32 [PATCH v5 0/6] usb: add support for Intel dual role port mux Lu Baolu
@ 2016-03-18  6:32 ` Lu Baolu
  2016-03-18  6:32 ` [PATCH v5 2/6] extcon: usb-gpio: add support for ACPI gpio interface Lu Baolu
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 12+ messages in thread
From: Lu Baolu @ 2016-03-18  6:32 UTC (permalink / raw)
  To: Felipe Balbi, Mathias Nyman, Greg Kroah-Hartman, Lee Jones,
	Heikki Krogerus, MyungJoo Ham, Chanwoo Choi
  Cc: linux-usb, linux-kernel, Lu Baolu

This is needed to handle the GPIO connected USB ID pin found on
Intel Baytrail devices.

Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
Reviewed-by: Felipe Balbi <balbi@kernel.org>
Acked-by: Chanwoo Choi <cw00.choi@samsung.com>
---
 drivers/extcon/extcon-usb-gpio.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/drivers/extcon/extcon-usb-gpio.c b/drivers/extcon/extcon-usb-gpio.c
index 2b2fecf..af9c8b0 100644
--- a/drivers/extcon/extcon-usb-gpio.c
+++ b/drivers/extcon/extcon-usb-gpio.c
@@ -206,6 +206,12 @@ static const struct of_device_id usb_extcon_dt_match[] = {
 };
 MODULE_DEVICE_TABLE(of, usb_extcon_dt_match);
 
+static const struct platform_device_id usb_extcon_platform_ids[] = {
+	{ .name = "extcon-usb-gpio", },
+	{ /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(platform, usb_extcon_platform_ids);
+
 static struct platform_driver usb_extcon_driver = {
 	.probe		= usb_extcon_probe,
 	.remove		= usb_extcon_remove,
@@ -214,6 +220,7 @@ static struct platform_driver usb_extcon_driver = {
 		.pm	= &usb_extcon_pm_ops,
 		.of_match_table = usb_extcon_dt_match,
 	},
+	.id_table = usb_extcon_platform_ids,
 };
 
 module_platform_driver(usb_extcon_driver);
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v5 2/6] extcon: usb-gpio: add support for ACPI gpio interface
  2016-03-18  6:32 [PATCH v5 0/6] usb: add support for Intel dual role port mux Lu Baolu
  2016-03-18  6:32 ` [PATCH v5 1/6] extcon: usb-gpio: add device binding for platform device Lu Baolu
@ 2016-03-18  6:32 ` Lu Baolu
  2016-03-18  6:32 ` [PATCH v5 3/6] usb: mux: add common code for Intel dual role port mux Lu Baolu
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 12+ messages in thread
From: Lu Baolu @ 2016-03-18  6:32 UTC (permalink / raw)
  To: Felipe Balbi, Mathias Nyman, Greg Kroah-Hartman, Lee Jones,
	Heikki Krogerus, MyungJoo Ham, Chanwoo Choi
  Cc: linux-usb, linux-kernel, Lu Baolu

GPIO resource could be retrieved through APCI as well.

Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
Reviewed-by: Felipe Balbi <balbi@kernel.org>
Acked-by: Chanwoo Choi <cw00.choi@samsung.com>
---
 drivers/extcon/extcon-usb-gpio.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/extcon/extcon-usb-gpio.c b/drivers/extcon/extcon-usb-gpio.c
index af9c8b0..472c431 100644
--- a/drivers/extcon/extcon-usb-gpio.c
+++ b/drivers/extcon/extcon-usb-gpio.c
@@ -26,6 +26,7 @@
 #include <linux/platform_device.h>
 #include <linux/slab.h>
 #include <linux/workqueue.h>
+#include <linux/acpi.h>
 
 #define USB_GPIO_DEBOUNCE_MS	20	/* ms */
 
@@ -91,7 +92,7 @@ static int usb_extcon_probe(struct platform_device *pdev)
 	struct usb_extcon_info *info;
 	int ret;
 
-	if (!np)
+	if (!np && !ACPI_HANDLE(dev))
 		return -EINVAL;
 
 	info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL);
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v5 3/6] usb: mux: add common code for Intel dual role port mux
  2016-03-18  6:32 [PATCH v5 0/6] usb: add support for Intel dual role port mux Lu Baolu
  2016-03-18  6:32 ` [PATCH v5 1/6] extcon: usb-gpio: add device binding for platform device Lu Baolu
  2016-03-18  6:32 ` [PATCH v5 2/6] extcon: usb-gpio: add support for ACPI gpio interface Lu Baolu
@ 2016-03-18  6:32 ` Lu Baolu
  2016-03-18  7:52   ` Chanwoo Choi
  2016-03-18  6:32 ` [PATCH v5 4/6] usb: mux: add driver for Intel gpio controlled " Lu Baolu
                   ` (2 subsequent siblings)
  5 siblings, 1 reply; 12+ messages in thread
From: Lu Baolu @ 2016-03-18  6:32 UTC (permalink / raw)
  To: Felipe Balbi, Mathias Nyman, Greg Kroah-Hartman, Lee Jones,
	Heikki Krogerus, MyungJoo Ham, Chanwoo Choi
  Cc: linux-usb, linux-kernel, Lu Baolu

Several Intel PCHs and SOCs have an internal mux that is used to
share one USB port between device controller and host controller.

A usb port mux could be abstracted as the following elements:
1) mux state: HOST or PERIPHERAL;
2) an extcon cable which triggers the change of mux state between
   HOST and PERIPHERAL;
3) The required action to do the real port switch.

This patch adds the common code to handle usb port mux. With this
common code, the individual mux driver, which always is platform
dependent, could focus on the real operation of mux switch.

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>
---
 Documentation/ABI/testing/sysfs-bus-platform |  15 +++
 MAINTAINERS                                  |   7 ++
 drivers/usb/Kconfig                          |   2 +
 drivers/usb/Makefile                         |   1 +
 drivers/usb/mux/Kconfig                      |  12 ++
 drivers/usb/mux/Makefile                     |   4 +
 drivers/usb/mux/intel-mux.c                  | 175 +++++++++++++++++++++++++++
 include/linux/usb/intel-mux.h                |  40 ++++++
 8 files changed, 256 insertions(+)
 create mode 100644 drivers/usb/mux/Kconfig
 create mode 100644 drivers/usb/mux/Makefile
 create mode 100644 drivers/usb/mux/intel-mux.c
 create mode 100644 include/linux/usb/intel-mux.h

diff --git a/Documentation/ABI/testing/sysfs-bus-platform b/Documentation/ABI/testing/sysfs-bus-platform
index 5172a61..23bf76e 100644
--- a/Documentation/ABI/testing/sysfs-bus-platform
+++ b/Documentation/ABI/testing/sysfs-bus-platform
@@ -18,3 +18,18 @@ Description:
 		devices to opt-out of driver binding using a driver_override
 		name such as "none".  Only a single driver may be specified in
 		the override, there is no support for parsing delimiters.
+
+What:		/sys/bus/platform/devices/.../port_mux
+Date:		Febuary 2016
+Contact:	Lu Baolu <baolu.lu@linux.intel.com>
+Description:
+		In some platforms, a single USB port is shared between a USB host
+		controller and a device controller. A USB mux driver is needed to
+		handle the port mux. port_mux attribute shows and stores the mux
+		state.
+		For read:
+		'peripheral' - mux switched to PERIPHERAL controller;
+		'host'       - mux switched to HOST controller.
+		For write:
+		'peripheral' - mux will be switched to PERIPHERAL controller;
+		'host'       - mux will be switched to HOST controller.
diff --git a/MAINTAINERS b/MAINTAINERS
index da3e4d8..0dbee11 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -11399,6 +11399,13 @@ T:	git git://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb.git
 S:	Maintained
 F:	drivers/usb/phy/
 
+USB PORT MUX DRIVER
+M:	Lu Baolu <baolu.lu@linux.intel.com>
+L:	linux-usb@vger.kernel.org
+S:	Supported
+F:	include/linux/usb/intel-mux.h
+F:	drivers/usb/mux/intel-mux.c
+
 USB PRINTER DRIVER (usblp)
 M:	Pete Zaitcev <zaitcev@redhat.com>
 L:	linux-usb@vger.kernel.org
diff --git a/drivers/usb/Kconfig b/drivers/usb/Kconfig
index 8ed451d..dbd6620 100644
--- a/drivers/usb/Kconfig
+++ b/drivers/usb/Kconfig
@@ -149,6 +149,8 @@ endif # USB
 
 source "drivers/usb/phy/Kconfig"
 
+source "drivers/usb/mux/Kconfig"
+
 source "drivers/usb/gadget/Kconfig"
 
 config USB_LED_TRIG
diff --git a/drivers/usb/Makefile b/drivers/usb/Makefile
index d5c57f1..6433f0c 100644
--- a/drivers/usb/Makefile
+++ b/drivers/usb/Makefile
@@ -6,6 +6,7 @@
 
 obj-$(CONFIG_USB)		+= core/
 obj-$(CONFIG_USB_SUPPORT)	+= phy/
+obj-$(CONFIG_USB_SUPPORT)	+= mux/
 
 obj-$(CONFIG_USB_DWC3)		+= dwc3/
 obj-$(CONFIG_USB_DWC2)		+= dwc2/
diff --git a/drivers/usb/mux/Kconfig b/drivers/usb/mux/Kconfig
new file mode 100644
index 0000000..62e2cc3
--- /dev/null
+++ b/drivers/usb/mux/Kconfig
@@ -0,0 +1,12 @@
+#
+# USB port mux driver configuration
+#
+menu "USB Port MUX drivers"
+config INTEL_USB_MUX
+	select EXTCON
+	def_bool n
+	help
+	  Common code for all Intel dual role port mux drivers. All Intel
+	  usb port mux drivers should select it.
+
+endmenu
diff --git a/drivers/usb/mux/Makefile b/drivers/usb/mux/Makefile
new file mode 100644
index 0000000..84f0ae8
--- /dev/null
+++ b/drivers/usb/mux/Makefile
@@ -0,0 +1,4 @@
+#
+# Makefile for USB port mux drivers
+#
+obj-$(CONFIG_INTEL_USB_MUX)		+= intel-mux.o
diff --git a/drivers/usb/mux/intel-mux.c b/drivers/usb/mux/intel-mux.c
new file mode 100644
index 0000000..d18b96f
--- /dev/null
+++ b/drivers/usb/mux/intel-mux.c
@@ -0,0 +1,175 @@
+/**
+ * intel_mux.c - USB Port Mux support
+ *
+ * Copyright (C) 2016 Intel Corporation
+ *
+ * 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/slab.h>
+#include <linux/notifier.h>
+#include <linux/extcon.h>
+#include <linux/err.h>
+
+struct intel_usb_mux {
+	struct device *dev;
+	struct extcon_dev *edev;
+	int (*cable_set_cb)(struct device *dev);
+	int (*cable_unset_cb)(struct device *dev);
+
+	struct notifier_block nb;
+
+	/*
+	 * The state of the mux.
+	 * 0, 1 - mux switch state
+	 * -1   - uninitialized state
+	 */
+	int mux_state;
+
+	 /* lock for mux_state */
+	struct mutex mux_mutex;
+};
+
+static int usb_mux_change_state(struct intel_usb_mux *mux, int state)
+{
+	int ret;
+	struct device *dev = mux->dev;
+
+	dev_WARN_ONCE(dev,
+		      !mutex_is_locked(&mux->mux_mutex),
+		      "mutex is unlocked\n");
+
+	mux->mux_state = state;
+
+	if (mux->mux_state)
+		ret = mux->cable_set_cb(dev);
+	else
+		ret = mux->cable_unset_cb(dev);
+
+	return ret;
+}
+
+static int usb_mux_notifier(struct notifier_block *nb,
+			    unsigned long event, void *ptr)
+{
+	struct intel_usb_mux *mux;
+	int state;
+	int ret = NOTIFY_DONE;
+
+	mux = container_of(nb, struct intel_usb_mux, nb);
+
+	state = extcon_get_cable_state_(mux->edev, EXTCON_USB_HOST);
+
+	if (mux->mux_state == -1 || mux->mux_state != state) {
+		mutex_lock(&mux->mux_mutex);
+		ret = usb_mux_change_state(mux, state);
+		mutex_unlock(&mux->mux_mutex);
+	}
+
+	return ret;
+}
+
+static ssize_t port_mux_show(struct device *dev,
+			     struct device_attribute *attr, char *buf)
+{
+	struct intel_usb_mux *mux = dev_get_drvdata(dev);
+
+	if (dev_WARN_ONCE(dev, !mux, "mux without data structure\n"))
+		return 0;
+
+	return sprintf(buf, "%s\n", mux->mux_state ? "host" : "peripheral");
+}
+
+static ssize_t port_mux_store(struct device *dev,
+			      struct device_attribute *attr,
+			      const char *buf, size_t count)
+{
+	struct intel_usb_mux *mux = dev_get_drvdata(dev);
+	int state;
+
+	if (dev_WARN_ONCE(dev, !mux, "mux without data structure\n"))
+		return -EINVAL;
+
+	if (sysfs_streq(buf, "peripheral"))
+		state = 0;
+	else if (sysfs_streq(buf, "host"))
+		state = 1;
+	else
+		return -EINVAL;
+
+	mutex_lock(&mux->mux_mutex);
+	usb_mux_change_state(mux, state);
+	mutex_unlock(&mux->mux_mutex);
+
+	return count;
+}
+static DEVICE_ATTR_RW(port_mux);
+
+int intel_usb_mux_bind_cable(struct device *dev, const char *extcon_name,
+			     int (*cable_set_cb)(struct device *dev),
+			     int (*cable_unset_cb)(struct device *dev))
+{
+	int ret;
+	struct intel_usb_mux *mux;
+	struct extcon_dev *edev;
+
+	edev = extcon_get_extcon_dev(extcon_name);
+	if (IS_ERR_OR_NULL(edev))
+		return -ENODEV;
+
+	mux = devm_kzalloc(dev, sizeof(*mux), GFP_KERNEL);
+	if (!mux)
+		return -ENOMEM;
+
+	mux->dev = dev;
+	mux->edev = edev;
+	mux->cable_set_cb = cable_set_cb;
+	mux->cable_unset_cb = cable_unset_cb;
+	mux->nb.notifier_call = usb_mux_notifier;
+	mutex_init(&mux->mux_mutex);
+	mux->mux_state = -1;
+
+	dev_set_drvdata(dev, mux);
+	ret = extcon_register_notifier(edev, EXTCON_USB_HOST, &mux->nb);
+	if (ret < 0) {
+		dev_err(dev, "failed to register extcon notifier\n");
+		return -ENODEV;
+	}
+
+	usb_mux_notifier(&mux->nb, 0, NULL);
+
+	/* register the sysfs interface */
+	ret = device_create_file(dev, &dev_attr_port_mux);
+	if (ret) {
+		extcon_unregister_notifier(edev, EXTCON_USB_HOST, &mux->nb);
+		dev_err(dev, "failed to create sysfs attribute\n");
+		return -ENODEV;
+	}
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(intel_usb_mux_bind_cable);
+
+int intel_usb_mux_unbind_cable(struct device *dev)
+{
+	struct intel_usb_mux *mux = dev_get_drvdata(dev);
+
+	device_remove_file(dev, &dev_attr_port_mux);
+	extcon_unregister_notifier(mux->edev, EXTCON_USB_HOST, &mux->nb);
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(intel_usb_mux_unbind_cable);
+
+#ifdef CONFIG_PM_SLEEP
+void intel_usb_mux_complete(struct device *dev)
+{
+	struct intel_usb_mux *mux = dev_get_drvdata(dev);
+
+	usb_mux_notifier(&mux->nb, 0, NULL);
+}
+EXPORT_SYMBOL_GPL(intel_usb_mux_complete);
+#endif
diff --git a/include/linux/usb/intel-mux.h b/include/linux/usb/intel-mux.h
new file mode 100644
index 0000000..b00975a
--- /dev/null
+++ b/include/linux/usb/intel-mux.h
@@ -0,0 +1,40 @@
+/**
+ * intel_mux.h - USB Port Mux definitions
+ *
+ * Copyright (C) 2016 Intel Corporation
+ *
+ * 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.
+ */
+
+#ifndef __LINUX_USB_INTEL_MUX_H
+#define __LINUX_USB_INTEL_MUX_H
+
+#if IS_ENABLED(CONFIG_INTEL_USB_MUX)
+int intel_usb_mux_bind_cable(struct device *dev, const char *extcon_name,
+			     int (*cable_set_cb)(struct device *dev),
+			     int (*cable_unset_cb)(struct device *dev));
+int intel_usb_mux_unbind_cable(struct device *dev);
+#ifdef CONFIG_PM_SLEEP
+void intel_usb_mux_complete(struct device *dev);
+#endif
+
+#else
+static inline int
+int intel_usb_mux_bind_cable(struct device *dev, const char *extcon_name,
+			     int (*cable_set_cb)(struct device *dev),
+			     int (*cable_unset_cb)(struct device *dev))
+{
+	return -ENODEV;
+}
+
+static inline int intel_usb_mux_unbind_cable(struct device *dev)
+{
+	return 0;
+}
+#endif /* CONFIG_INTEL_USB_MUX */
+
+#endif /* __LINUX_USB_INTEL_MUX_H */
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v5 4/6] usb: mux: add driver for Intel gpio controlled port mux
  2016-03-18  6:32 [PATCH v5 0/6] usb: add support for Intel dual role port mux Lu Baolu
                   ` (2 preceding siblings ...)
  2016-03-18  6:32 ` [PATCH v5 3/6] usb: mux: add common code for Intel dual role port mux Lu Baolu
@ 2016-03-18  6:32 ` Lu Baolu
  2016-03-18  6:32 ` [PATCH v5 5/6] usb: mux: add driver for Intel drcfg " Lu Baolu
  2016-03-18  6:32 ` [PATCH v5 6/6] mfd: intel_vuport: Add Intel virtual USB port MFD Driver Lu Baolu
  5 siblings, 0 replies; 12+ messages in thread
From: Lu Baolu @ 2016-03-18  6:32 UTC (permalink / raw)
  To: Felipe Balbi, Mathias Nyman, Greg Kroah-Hartman, Lee Jones,
	Heikki Krogerus, MyungJoo Ham, Chanwoo Choi
  Cc: linux-usb, linux-kernel, Lu Baolu, David Cohen, Fengguang Wu

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>
Signed-off-by: Fengguang Wu <fengguang.wu@intel.com>
---
 MAINTAINERS                      |   1 +
 drivers/usb/mux/Kconfig          |   9 +++
 drivers/usb/mux/Makefile         |   1 +
 drivers/usb/mux/intel-mux-gpio.c | 122 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 133 insertions(+)
 create mode 100644 drivers/usb/mux/intel-mux-gpio.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 0dbee11..99bc198 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -11405,6 +11405,7 @@ L:	linux-usb@vger.kernel.org
 S:	Supported
 F:	include/linux/usb/intel-mux.h
 F:	drivers/usb/mux/intel-mux.c
+F:	drivers/usb/mux/intel-mux-gpio.c
 
 USB PRINTER DRIVER (usblp)
 M:	Pete Zaitcev <zaitcev@redhat.com>
diff --git a/drivers/usb/mux/Kconfig b/drivers/usb/mux/Kconfig
index 62e2cc3..2b197c1 100644
--- a/drivers/usb/mux/Kconfig
+++ b/drivers/usb/mux/Kconfig
@@ -9,4 +9,13 @@ config INTEL_USB_MUX
 	  Common code for all Intel dual role port mux drivers. All Intel
 	  usb port mux drivers should select it.
 
+config INTEL_MUX_GPIO
+	tristate "Intel dual role port mux controlled by GPIOs"
+	depends on GPIOLIB
+	depends on X86 && ACPI
+	select INTEL_USB_MUX
+	help
+	  Say Y here to enable support for Intel dual role port mux
+	  controlled by GPIOs.
+
 endmenu
diff --git a/drivers/usb/mux/Makefile b/drivers/usb/mux/Makefile
index 84f0ae8..66f765c 100644
--- a/drivers/usb/mux/Makefile
+++ b/drivers/usb/mux/Makefile
@@ -2,3 +2,4 @@
 # Makefile for USB port mux drivers
 #
 obj-$(CONFIG_INTEL_USB_MUX)		+= intel-mux.o
+obj-$(CONFIG_INTEL_MUX_GPIO)		+= intel-mux-gpio.o
diff --git a/drivers/usb/mux/intel-mux-gpio.c b/drivers/usb/mux/intel-mux-gpio.c
new file mode 100644
index 0000000..5705b8d
--- /dev/null
+++ b/drivers/usb/mux/intel-mux-gpio.c
@@ -0,0 +1,122 @@
+/*
+ * 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/intel-mux.h>
+
+struct vuport {
+	struct device *dev;
+	struct gpio_desc *gpio_vbus_en;
+	struct gpio_desc *gpio_usb_mux;
+};
+
+static struct vuport *vup;
+
+#define VUPORT_EXTCON_DEV_NAME	"extcon-usb-gpio.0"
+
+/*
+ * 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 device *dev, int id)
+{
+	dev_dbg(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 device *dev)
+{
+	return vuport_set_port(dev, 1);
+}
+
+static int vuport_cable_unset(struct device *dev)
+{
+	return vuport_set_port(dev, 0);
+}
+
+static int vuport_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+
+	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);
+
+	vup->dev = dev;
+
+	return intel_usb_mux_bind_cable(dev, VUPORT_EXTCON_DEV_NAME,
+					vuport_cable_set,
+					vuport_cable_unset);
+}
+
+static int vuport_remove(struct platform_device *pdev)
+{
+	return intel_usb_mux_unbind_cable(&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 = intel_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",
+#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

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v5 5/6] usb: mux: add driver for Intel drcfg controlled port mux
  2016-03-18  6:32 [PATCH v5 0/6] usb: add support for Intel dual role port mux Lu Baolu
                   ` (3 preceding siblings ...)
  2016-03-18  6:32 ` [PATCH v5 4/6] usb: mux: add driver for Intel gpio controlled " Lu Baolu
@ 2016-03-18  6:32 ` Lu Baolu
  2016-03-18  6:32 ` [PATCH v5 6/6] mfd: intel_vuport: Add Intel virtual USB port MFD Driver Lu Baolu
  5 siblings, 0 replies; 12+ messages in thread
From: Lu Baolu @ 2016-03-18  6:32 UTC (permalink / raw)
  To: Felipe Balbi, Mathias Nyman, Greg Kroah-Hartman, Lee Jones,
	Heikki Krogerus, MyungJoo Ham, Chanwoo Choi
  Cc: linux-usb, linux-kernel, Lu Baolu, Wu Hao

Several Intel PCHs and SOCs have an internal mux that is used to
share one USB port between device controller and host controller.
The mux is handled through the Dual Role Configuration Register.

Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
Signed-off-by: Wu Hao <hao.wu@intel.com>
Reviewed-by: Felipe Balbi <balbi@kernel.org>
---
 MAINTAINERS                       |   1 +
 drivers/usb/mux/Kconfig           |   7 ++
 drivers/usb/mux/Makefile          |   1 +
 drivers/usb/mux/intel-mux-drcfg.c | 159 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 168 insertions(+)
 create mode 100644 drivers/usb/mux/intel-mux-drcfg.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 99bc198..1d0f090 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -11406,6 +11406,7 @@ S:	Supported
 F:	include/linux/usb/intel-mux.h
 F:	drivers/usb/mux/intel-mux.c
 F:	drivers/usb/mux/intel-mux-gpio.c
+F:	drivers/usb/mux/intel-mux-drcfg.c
 
 USB PRINTER DRIVER (usblp)
 M:	Pete Zaitcev <zaitcev@redhat.com>
diff --git a/drivers/usb/mux/Kconfig b/drivers/usb/mux/Kconfig
index 2b197c1..975c5a0 100644
--- a/drivers/usb/mux/Kconfig
+++ b/drivers/usb/mux/Kconfig
@@ -18,4 +18,11 @@ config INTEL_MUX_GPIO
 	  Say Y here to enable support for Intel dual role port mux
 	  controlled by GPIOs.
 
+config INTEL_MUX_DRCFG
+	tristate "Intel dual role port mux controlled by register"
+	depends on X86
+	select INTEL_USB_MUX
+	help
+	  Say Y here to enable support for Intel dual role port mux
+	  controlled by the Dual Role Configuration Register.
 endmenu
diff --git a/drivers/usb/mux/Makefile b/drivers/usb/mux/Makefile
index 66f765c..3179909 100644
--- a/drivers/usb/mux/Makefile
+++ b/drivers/usb/mux/Makefile
@@ -3,3 +3,4 @@
 #
 obj-$(CONFIG_INTEL_USB_MUX)		+= intel-mux.o
 obj-$(CONFIG_INTEL_MUX_GPIO)		+= intel-mux-gpio.o
+obj-$(CONFIG_INTEL_MUX_DRCFG)		+= intel-mux-drcfg.o
diff --git a/drivers/usb/mux/intel-mux-drcfg.c b/drivers/usb/mux/intel-mux-drcfg.c
new file mode 100644
index 0000000..4b6c2d1
--- /dev/null
+++ b/drivers/usb/mux/intel-mux-drcfg.c
@@ -0,0 +1,159 @@
+/**
+ * intel-mux-drcfg.c - Driver for Intel USB mux via register
+ *
+ * Copyright (C) 2016 Intel Corporation
+ * Author: Heikki Krogerus <heikki.krogerus@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/slab.h>
+#include <linux/module.h>
+#include <linux/property.h>
+#include <linux/platform_device.h>
+#include <linux/usb.h>
+#include <linux/usb/intel-mux.h>
+
+#define INTEL_MUX_CFG0		0x00
+#define INTEL_MUX_CFG1		0x04
+#define CFG0_SW_IDPIN		BIT(20)
+#define CFG0_SW_IDPIN_EN	BIT(21)
+#define CFG0_SW_VBUS_VALID	BIT(24)
+#define CFG1_SW_MODE		BIT(29)
+#define CFG1_POLL_TIMEOUT	1000
+
+struct intel_mux_drcfg {
+	struct device *dev;
+	void __iomem *regs;
+};
+
+static struct intel_mux_drcfg *mux;
+
+static inline int intel_mux_drcfg_switch(struct device *dev, bool host)
+{
+	unsigned long timeout;
+	u32 data;
+
+	/* Check and set mux to SW controlled mode */
+	data = readl(mux->regs + INTEL_MUX_CFG0);
+	if (!(data & CFG0_SW_IDPIN_EN)) {
+		data |= CFG0_SW_IDPIN_EN;
+		writel(data, mux->regs + INTEL_MUX_CFG0);
+	}
+
+	/*
+	 * Configure CFG0 to switch the mux and VBUS_VALID bit is
+	 * required for device mode.
+	 */
+	data = readl(mux->regs + INTEL_MUX_CFG0);
+	if (host)
+		data &= ~(CFG0_SW_IDPIN | CFG0_SW_VBUS_VALID);
+	else
+		data |= (CFG0_SW_IDPIN | CFG0_SW_VBUS_VALID);
+	writel(data, mux->regs + INTEL_MUX_CFG0);
+
+	/*
+	 * Polling CFG1 for safety, most case it takes about 600ms
+	 * to finish mode switching, set TIMEOUT long enough.
+	 */
+	timeout = jiffies + msecs_to_jiffies(CFG1_POLL_TIMEOUT);
+
+	/* Polling on CFG1 register to confirm mode switch. */
+	while (!time_after(jiffies, timeout)) {
+		data = readl(mux->regs + INTEL_MUX_CFG1);
+		if (!(host ^ (data & CFG1_SW_MODE)))
+			return 0;
+		/* interval for polling is set to about 5ms */
+		usleep_range(5000, 5100);
+	}
+
+	return -ETIMEDOUT;
+}
+
+static int intel_mux_drcfg_cable_set(struct device *dev)
+{
+	dev_dbg(dev, "drcfg mux switch to HOST\n");
+
+	return intel_mux_drcfg_switch(dev, true);
+}
+
+static int intel_mux_drcfg_cable_unset(struct device *dev)
+{
+	dev_dbg(dev, "drcfg mux switch to DEVICE\n");
+
+	return intel_mux_drcfg_switch(dev, false);
+}
+
+static int intel_mux_drcfg_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	const char *extcon_name;
+	u64 start, size;
+	int ret;
+
+	mux = devm_kzalloc(dev, sizeof(*mux), GFP_KERNEL);
+	if (!mux)
+		return -ENOMEM;
+
+	ret = device_property_read_u64(dev, "reg-start", &start);
+	ret |= device_property_read_u64(dev, "reg-size", &size);
+	ret |= device_property_read_string(dev, "extcon-name", &extcon_name);
+	if (ret)
+		return -ENODEV;
+
+	mux->regs = devm_ioremap_nocache(dev, start, size);
+	if (!mux->regs)
+		return -ENOMEM;
+
+	mux->dev = dev;
+
+	return intel_usb_mux_bind_cable(dev, extcon_name,
+					intel_mux_drcfg_cable_set,
+					intel_mux_drcfg_cable_unset);
+}
+
+static int intel_mux_drcfg_remove(struct platform_device *pdev)
+{
+	return intel_usb_mux_unbind_cable(&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 state 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 intel_mux_drcfg_pm_ops = {
+	.complete = intel_usb_mux_complete,
+};
+#endif
+
+static const struct platform_device_id intel_mux_drcfg_platform_ids[] = {
+	{ .name = "intel-mux-drcfg", },
+	{ /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(platform, intel_mux_drcfg_platform_ids);
+
+static struct platform_driver intel_mux_drcfg_driver = {
+	.probe		= intel_mux_drcfg_probe,
+	.remove		= intel_mux_drcfg_remove,
+	.driver		= {
+		.name	= "intel-mux-drcfg",
+#ifdef CONFIG_PM_SLEEP
+		.pm	= &intel_mux_drcfg_pm_ops,
+#endif
+	},
+	.id_table = intel_mux_drcfg_platform_ids,
+};
+
+module_platform_driver(intel_mux_drcfg_driver);
+
+MODULE_AUTHOR("Heikki Krogerus <heikki.krogerus@linux.intel.com>");
+MODULE_AUTHOR("Lu Baolu <baolu.lu@linux.intel.com>");
+MODULE_DESCRIPTION("Intel USB drcfg mux driver");
+MODULE_LICENSE("GPL v2");
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v5 6/6] mfd: intel_vuport: Add Intel virtual USB port MFD Driver
  2016-03-18  6:32 [PATCH v5 0/6] usb: add support for Intel dual role port mux Lu Baolu
                   ` (4 preceding siblings ...)
  2016-03-18  6:32 ` [PATCH v5 5/6] usb: mux: add driver for Intel drcfg " Lu Baolu
@ 2016-03-18  6:32 ` Lu Baolu
  2016-03-18  8:09   ` Lee Jones
  5 siblings, 1 reply; 12+ messages in thread
From: Lu Baolu @ 2016-03-18  6:32 UTC (permalink / raw)
  To: Felipe Balbi, Mathias Nyman, Greg Kroah-Hartman, Lee Jones,
	Heikki Krogerus, MyungJoo Ham, Chanwoo Choi
  Cc: linux-usb, linux-kernel, Lu Baolu, Fengguang Wu

Some Intel platforms have an USB port mux controlled by GPIOs.
There's a single ACPI platform device that provides both USB ID
extcon device and a USB port mux device. This MFD driver will
split the 2 devices for their respective drivers.

Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
Suggested-by: David Cohen <david.a.cohen@linux.intel.com>
Reviewed-by: Felipe Balbi <balbi@kernel.org>
Signed-off-by: Fengguang Wu <fengguang.wu@intel.com>
Reviewed-by: Lee Jones <lee.jones@linaro.org>
---
 MAINTAINERS                |  6 ++++
 drivers/mfd/Kconfig        |  8 +++++
 drivers/mfd/Makefile       |  1 +
 drivers/mfd/intel-vuport.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 89 insertions(+)
 create mode 100644 drivers/mfd/intel-vuport.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 1d0f090..0a932b3 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -5599,6 +5599,12 @@ L:	linux-pm@vger.kernel.org
 S:	Supported
 F:	drivers/cpufreq/intel_pstate.c
 
+INTEL VIRTUAL USB PORT DRIVER
+M:	Lu Baolu <baolu.lu@linux.intel.com>
+L:	linux-usb@vger.kernel.org
+S:	Supported
+F:	drivers/mfd/intel-vuport.c
+
 INTEL FRAMEBUFFER DRIVER (excluding 810 and 815)
 M:	Maik Broemme <mbroemme@plusserver.de>
 L:	linux-fbdev@vger.kernel.org
diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index 9ca66de..48933d4 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -1534,5 +1534,13 @@ config MFD_VEXPRESS_SYSREG
 	  System Registers are the platform configuration block
 	  on the ARM Ltd. Versatile Express board.
 
+config MFD_INTEL_VUPORT
+	tristate "Intel virtual USB port controller"
+	select MFD_CORE
+	depends on X86 && ACPI
+	help
+	  Say Y here to enable support for Intel's dual role port mux
+	  controlled by GPIOs.
+
 endmenu
 endif
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index 0f230a6..0ccd107 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -198,3 +198,4 @@ intel-soc-pmic-objs		:= intel_soc_pmic_core.o intel_soc_pmic_crc.o
 intel-soc-pmic-$(CONFIG_INTEL_PMC_IPC)	+= intel_soc_pmic_bxtwc.o
 obj-$(CONFIG_INTEL_SOC_PMIC)	+= intel-soc-pmic.o
 obj-$(CONFIG_MFD_MT6397)	+= mt6397-core.o
+obj-$(CONFIG_MFD_INTEL_VUPORT)	+= intel-vuport.o
diff --git a/drivers/mfd/intel-vuport.c b/drivers/mfd/intel-vuport.c
new file mode 100644
index 0000000..a07920f
--- /dev/null
+++ b/drivers/mfd/intel-vuport.c
@@ -0,0 +1,74 @@
+/*
+ * MFD driver for Intel virtual USB port
+ *
+ * Copyright(c) 2016 Intel Corporation.
+ * 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/mfd/core.h>
+#include <linux/platform_device.h>
+
+/* ACPI GPIO Mappings */
+static const struct acpi_gpio_params id_gpio = { 0, 0, false };
+static const struct acpi_gpio_params vbus_gpio = { 1, 0, false };
+static const struct acpi_gpio_params mux_gpio = { 2, 0, false };
+static const struct acpi_gpio_mapping acpi_usb_gpios[] = {
+	{ "id-gpios", &id_gpio, 1 },
+	{ "vbus_en-gpios", &vbus_gpio, 1 },
+	{ "usb_mux-gpios", &mux_gpio, 1 },
+	{ },
+};
+
+static const struct mfd_cell intel_vuport_mfd_cells[] = {
+	{ .name = "extcon-usb-gpio", },
+	{ .name = "intel-mux-gpio", },
+};
+
+static int vuport_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	int ret;
+
+	ret = acpi_dev_add_driver_gpios(ACPI_COMPANION(dev), acpi_usb_gpios);
+	if (ret)
+		return ret;
+
+	return mfd_add_devices(&pdev->dev, 0, intel_vuport_mfd_cells,
+			ARRAY_SIZE(intel_vuport_mfd_cells), NULL, 0,
+			NULL);
+}
+
+static int vuport_remove(struct platform_device *pdev)
+{
+	mfd_remove_devices(&pdev->dev);
+	acpi_dev_remove_driver_gpios(ACPI_COMPANION(&pdev->dev));
+
+	return 0;
+}
+
+static struct acpi_device_id vuport_acpi_match[] = {
+	{ "INT3496" },
+	{ }
+};
+MODULE_DEVICE_TABLE(acpi, vuport_acpi_match);
+
+static struct platform_driver vuport_driver = {
+	.driver = {
+		.name = "intel-vuport",
+		.acpi_match_table = ACPI_PTR(vuport_acpi_match),
+	},
+	.probe = vuport_probe,
+	.remove = vuport_remove,
+};
+
+module_platform_driver(vuport_driver);
+
+MODULE_AUTHOR("Lu Baolu <baolu.lu@linux.intel.com>");
+MODULE_DESCRIPTION("Intel virtual USB port");
+MODULE_LICENSE("GPL v2");
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH v5 3/6] usb: mux: add common code for Intel dual role port mux
  2016-03-18  6:32 ` [PATCH v5 3/6] usb: mux: add common code for Intel dual role port mux Lu Baolu
@ 2016-03-18  7:52   ` Chanwoo Choi
  2016-03-18  8:23     ` Lu Baolu
  0 siblings, 1 reply; 12+ messages in thread
From: Chanwoo Choi @ 2016-03-18  7:52 UTC (permalink / raw)
  To: Lu Baolu, Felipe Balbi, Mathias Nyman, Greg Kroah-Hartman,
	Lee Jones, Heikki Krogerus, MyungJoo Ham
  Cc: linux-usb, linux-kernel

Hi Baolu,

On 2016년 03월 18일 15:32, Lu Baolu wrote:
> Several Intel PCHs and SOCs have an internal mux that is used to
> share one USB port between device controller and host controller.
> 
> A usb port mux could be abstracted as the following elements:
> 1) mux state: HOST or PERIPHERAL;
> 2) an extcon cable which triggers the change of mux state between
>    HOST and PERIPHERAL;
> 3) The required action to do the real port switch.
> 
> This patch adds the common code to handle usb port mux. With this
> common code, the individual mux driver, which always is platform
> dependent, could focus on the real operation of mux switch.
> 
> 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>

Looks good to me about extcon usage.

For extcon usage,
Reviewed-by: Chanwoo Choi <cw00.choi@samsung.com>

Best Regards,
Chanwoo Choi


> ---
>  Documentation/ABI/testing/sysfs-bus-platform |  15 +++
>  MAINTAINERS                                  |   7 ++
>  drivers/usb/Kconfig                          |   2 +
>  drivers/usb/Makefile                         |   1 +
>  drivers/usb/mux/Kconfig                      |  12 ++
>  drivers/usb/mux/Makefile                     |   4 +
>  drivers/usb/mux/intel-mux.c                  | 175 +++++++++++++++++++++++++++
>  include/linux/usb/intel-mux.h                |  40 ++++++
>  8 files changed, 256 insertions(+)
>  create mode 100644 drivers/usb/mux/Kconfig
>  create mode 100644 drivers/usb/mux/Makefile
>  create mode 100644 drivers/usb/mux/intel-mux.c
>  create mode 100644 include/linux/usb/intel-mux.h
> 
> diff --git a/Documentation/ABI/testing/sysfs-bus-platform b/Documentation/ABI/testing/sysfs-bus-platform
> index 5172a61..23bf76e 100644
> --- a/Documentation/ABI/testing/sysfs-bus-platform
> +++ b/Documentation/ABI/testing/sysfs-bus-platform
> @@ -18,3 +18,18 @@ Description:
>  		devices to opt-out of driver binding using a driver_override
>  		name such as "none".  Only a single driver may be specified in
>  		the override, there is no support for parsing delimiters.
> +
> +What:		/sys/bus/platform/devices/.../port_mux
> +Date:		Febuary 2016
> +Contact:	Lu Baolu <baolu.lu@linux.intel.com>
> +Description:
> +		In some platforms, a single USB port is shared between a USB host
> +		controller and a device controller. A USB mux driver is needed to
> +		handle the port mux. port_mux attribute shows and stores the mux
> +		state.
> +		For read:
> +		'peripheral' - mux switched to PERIPHERAL controller;
> +		'host'       - mux switched to HOST controller.
> +		For write:
> +		'peripheral' - mux will be switched to PERIPHERAL controller;
> +		'host'       - mux will be switched to HOST controller.
> diff --git a/MAINTAINERS b/MAINTAINERS
> index da3e4d8..0dbee11 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -11399,6 +11399,13 @@ T:	git git://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb.git
>  S:	Maintained
>  F:	drivers/usb/phy/
>  
> +USB PORT MUX DRIVER
> +M:	Lu Baolu <baolu.lu@linux.intel.com>
> +L:	linux-usb@vger.kernel.org
> +S:	Supported
> +F:	include/linux/usb/intel-mux.h
> +F:	drivers/usb/mux/intel-mux.c
> +
>  USB PRINTER DRIVER (usblp)
>  M:	Pete Zaitcev <zaitcev@redhat.com>
>  L:	linux-usb@vger.kernel.org
> diff --git a/drivers/usb/Kconfig b/drivers/usb/Kconfig
> index 8ed451d..dbd6620 100644
> --- a/drivers/usb/Kconfig
> +++ b/drivers/usb/Kconfig
> @@ -149,6 +149,8 @@ endif # USB
>  
>  source "drivers/usb/phy/Kconfig"
>  
> +source "drivers/usb/mux/Kconfig"
> +
>  source "drivers/usb/gadget/Kconfig"
>  
>  config USB_LED_TRIG
> diff --git a/drivers/usb/Makefile b/drivers/usb/Makefile
> index d5c57f1..6433f0c 100644
> --- a/drivers/usb/Makefile
> +++ b/drivers/usb/Makefile
> @@ -6,6 +6,7 @@
>  
>  obj-$(CONFIG_USB)		+= core/
>  obj-$(CONFIG_USB_SUPPORT)	+= phy/
> +obj-$(CONFIG_USB_SUPPORT)	+= mux/
>  
>  obj-$(CONFIG_USB_DWC3)		+= dwc3/
>  obj-$(CONFIG_USB_DWC2)		+= dwc2/
> diff --git a/drivers/usb/mux/Kconfig b/drivers/usb/mux/Kconfig
> new file mode 100644
> index 0000000..62e2cc3
> --- /dev/null
> +++ b/drivers/usb/mux/Kconfig
> @@ -0,0 +1,12 @@
> +#
> +# USB port mux driver configuration
> +#
> +menu "USB Port MUX drivers"
> +config INTEL_USB_MUX
> +	select EXTCON
> +	def_bool n
> +	help
> +	  Common code for all Intel dual role port mux drivers. All Intel
> +	  usb port mux drivers should select it.
> +
> +endmenu
> diff --git a/drivers/usb/mux/Makefile b/drivers/usb/mux/Makefile
> new file mode 100644
> index 0000000..84f0ae8
> --- /dev/null
> +++ b/drivers/usb/mux/Makefile
> @@ -0,0 +1,4 @@
> +#
> +# Makefile for USB port mux drivers
> +#
> +obj-$(CONFIG_INTEL_USB_MUX)		+= intel-mux.o
> diff --git a/drivers/usb/mux/intel-mux.c b/drivers/usb/mux/intel-mux.c
> new file mode 100644
> index 0000000..d18b96f
> --- /dev/null
> +++ b/drivers/usb/mux/intel-mux.c
> @@ -0,0 +1,175 @@
> +/**
> + * intel_mux.c - USB Port Mux support
> + *
> + * Copyright (C) 2016 Intel Corporation
> + *
> + * 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/slab.h>
> +#include <linux/notifier.h>
> +#include <linux/extcon.h>
> +#include <linux/err.h>
> +
> +struct intel_usb_mux {
> +	struct device *dev;
> +	struct extcon_dev *edev;
> +	int (*cable_set_cb)(struct device *dev);
> +	int (*cable_unset_cb)(struct device *dev);
> +
> +	struct notifier_block nb;
> +
> +	/*
> +	 * The state of the mux.
> +	 * 0, 1 - mux switch state
> +	 * -1   - uninitialized state
> +	 */
> +	int mux_state;
> +
> +	 /* lock for mux_state */
> +	struct mutex mux_mutex;
> +};
> +
> +static int usb_mux_change_state(struct intel_usb_mux *mux, int state)
> +{
> +	int ret;
> +	struct device *dev = mux->dev;
> +
> +	dev_WARN_ONCE(dev,
> +		      !mutex_is_locked(&mux->mux_mutex),
> +		      "mutex is unlocked\n");
> +
> +	mux->mux_state = state;
> +
> +	if (mux->mux_state)
> +		ret = mux->cable_set_cb(dev);
> +	else
> +		ret = mux->cable_unset_cb(dev);
> +
> +	return ret;
> +}
> +
> +static int usb_mux_notifier(struct notifier_block *nb,
> +			    unsigned long event, void *ptr)
> +{
> +	struct intel_usb_mux *mux;
> +	int state;
> +	int ret = NOTIFY_DONE;
> +
> +	mux = container_of(nb, struct intel_usb_mux, nb);
> +
> +	state = extcon_get_cable_state_(mux->edev, EXTCON_USB_HOST);
> +
> +	if (mux->mux_state == -1 || mux->mux_state != state) {
> +		mutex_lock(&mux->mux_mutex);
> +		ret = usb_mux_change_state(mux, state);
> +		mutex_unlock(&mux->mux_mutex);
> +	}
> +
> +	return ret;
> +}
> +
> +static ssize_t port_mux_show(struct device *dev,
> +			     struct device_attribute *attr, char *buf)
> +{
> +	struct intel_usb_mux *mux = dev_get_drvdata(dev);
> +
> +	if (dev_WARN_ONCE(dev, !mux, "mux without data structure\n"))
> +		return 0;
> +
> +	return sprintf(buf, "%s\n", mux->mux_state ? "host" : "peripheral");
> +}
> +
> +static ssize_t port_mux_store(struct device *dev,
> +			      struct device_attribute *attr,
> +			      const char *buf, size_t count)
> +{
> +	struct intel_usb_mux *mux = dev_get_drvdata(dev);
> +	int state;
> +
> +	if (dev_WARN_ONCE(dev, !mux, "mux without data structure\n"))
> +		return -EINVAL;
> +
> +	if (sysfs_streq(buf, "peripheral"))
> +		state = 0;
> +	else if (sysfs_streq(buf, "host"))
> +		state = 1;
> +	else
> +		return -EINVAL;
> +
> +	mutex_lock(&mux->mux_mutex);
> +	usb_mux_change_state(mux, state);
> +	mutex_unlock(&mux->mux_mutex);
> +
> +	return count;
> +}
> +static DEVICE_ATTR_RW(port_mux);
> +
> +int intel_usb_mux_bind_cable(struct device *dev, const char *extcon_name,
> +			     int (*cable_set_cb)(struct device *dev),
> +			     int (*cable_unset_cb)(struct device *dev))
> +{
> +	int ret;
> +	struct intel_usb_mux *mux;
> +	struct extcon_dev *edev;
> +
> +	edev = extcon_get_extcon_dev(extcon_name);
> +	if (IS_ERR_OR_NULL(edev))
> +		return -ENODEV;
> +
> +	mux = devm_kzalloc(dev, sizeof(*mux), GFP_KERNEL);
> +	if (!mux)
> +		return -ENOMEM;
> +
> +	mux->dev = dev;
> +	mux->edev = edev;
> +	mux->cable_set_cb = cable_set_cb;
> +	mux->cable_unset_cb = cable_unset_cb;
> +	mux->nb.notifier_call = usb_mux_notifier;
> +	mutex_init(&mux->mux_mutex);
> +	mux->mux_state = -1;
> +
> +	dev_set_drvdata(dev, mux);
> +	ret = extcon_register_notifier(edev, EXTCON_USB_HOST, &mux->nb);
> +	if (ret < 0) {
> +		dev_err(dev, "failed to register extcon notifier\n");
> +		return -ENODEV;
> +	}
> +
> +	usb_mux_notifier(&mux->nb, 0, NULL);
> +
> +	/* register the sysfs interface */
> +	ret = device_create_file(dev, &dev_attr_port_mux);
> +	if (ret) {
> +		extcon_unregister_notifier(edev, EXTCON_USB_HOST, &mux->nb);
> +		dev_err(dev, "failed to create sysfs attribute\n");
> +		return -ENODEV;
> +	}
> +
> +	return 0;
> +}
> +EXPORT_SYMBOL_GPL(intel_usb_mux_bind_cable);
> +
> +int intel_usb_mux_unbind_cable(struct device *dev)
> +{
> +	struct intel_usb_mux *mux = dev_get_drvdata(dev);
> +
> +	device_remove_file(dev, &dev_attr_port_mux);
> +	extcon_unregister_notifier(mux->edev, EXTCON_USB_HOST, &mux->nb);
> +
> +	return 0;
> +}
> +EXPORT_SYMBOL_GPL(intel_usb_mux_unbind_cable);
> +
> +#ifdef CONFIG_PM_SLEEP
> +void intel_usb_mux_complete(struct device *dev)
> +{
> +	struct intel_usb_mux *mux = dev_get_drvdata(dev);
> +
> +	usb_mux_notifier(&mux->nb, 0, NULL);
> +}
> +EXPORT_SYMBOL_GPL(intel_usb_mux_complete);
> +#endif
> diff --git a/include/linux/usb/intel-mux.h b/include/linux/usb/intel-mux.h
> new file mode 100644
> index 0000000..b00975a
> --- /dev/null
> +++ b/include/linux/usb/intel-mux.h
> @@ -0,0 +1,40 @@
> +/**
> + * intel_mux.h - USB Port Mux definitions
> + *
> + * Copyright (C) 2016 Intel Corporation
> + *
> + * 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.
> + */
> +
> +#ifndef __LINUX_USB_INTEL_MUX_H
> +#define __LINUX_USB_INTEL_MUX_H
> +
> +#if IS_ENABLED(CONFIG_INTEL_USB_MUX)
> +int intel_usb_mux_bind_cable(struct device *dev, const char *extcon_name,
> +			     int (*cable_set_cb)(struct device *dev),
> +			     int (*cable_unset_cb)(struct device *dev));
> +int intel_usb_mux_unbind_cable(struct device *dev);
> +#ifdef CONFIG_PM_SLEEP
> +void intel_usb_mux_complete(struct device *dev);
> +#endif
> +
> +#else
> +static inline int
> +int intel_usb_mux_bind_cable(struct device *dev, const char *extcon_name,
> +			     int (*cable_set_cb)(struct device *dev),
> +			     int (*cable_unset_cb)(struct device *dev))
> +{
> +	return -ENODEV;
> +}
> +
> +static inline int intel_usb_mux_unbind_cable(struct device *dev)
> +{
> +	return 0;
> +}
> +#endif /* CONFIG_INTEL_USB_MUX */
> +
> +#endif /* __LINUX_USB_INTEL_MUX_H */
> 

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v5 6/6] mfd: intel_vuport: Add Intel virtual USB port MFD Driver
  2016-03-18  6:32 ` [PATCH v5 6/6] mfd: intel_vuport: Add Intel virtual USB port MFD Driver Lu Baolu
@ 2016-03-18  8:09   ` Lee Jones
  2016-03-18  8:43     ` Lu Baolu
  0 siblings, 1 reply; 12+ messages in thread
From: Lee Jones @ 2016-03-18  8:09 UTC (permalink / raw)
  To: Lu Baolu
  Cc: Felipe Balbi, Mathias Nyman, Greg Kroah-Hartman, Heikki Krogerus,
	MyungJoo Ham, Chanwoo Choi, linux-usb, linux-kernel,
	Fengguang Wu

On Fri, 18 Mar 2016, Lu Baolu wrote:

> Some Intel platforms have an USB port mux controlled by GPIOs.
> There's a single ACPI platform device that provides both USB ID
> extcon device and a USB port mux device. This MFD driver will
> split the 2 devices for their respective drivers.
> 
> Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
> Suggested-by: David Cohen <david.a.cohen@linux.intel.com>

This should be at the top.

You couldn't have written the patch before it was suggested.

> Reviewed-by: Felipe Balbi <balbi@kernel.org>
> Signed-off-by: Fengguang Wu <fengguang.wu@intel.com>

What is this sign-off meant to indicate?

> Reviewed-by: Lee Jones <lee.jones@linaro.org>

Why is this here?

a) I don't provide "Reviewed-by:" tags #alarmbells
b) I have never signed this patch off

> ---
>  MAINTAINERS                |  6 ++++

Seperate patch.

>  drivers/mfd/Kconfig        |  8 +++++
>  drivers/mfd/Makefile       |  1 +
>  drivers/mfd/intel-vuport.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++
>  4 files changed, 89 insertions(+)
>  create mode 100644 drivers/mfd/intel-vuport.c

[...]

-- 
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v5 3/6] usb: mux: add common code for Intel dual role port mux
  2016-03-18  7:52   ` Chanwoo Choi
@ 2016-03-18  8:23     ` Lu Baolu
  0 siblings, 0 replies; 12+ messages in thread
From: Lu Baolu @ 2016-03-18  8:23 UTC (permalink / raw)
  To: Chanwoo Choi, Felipe Balbi, Mathias Nyman, Greg Kroah-Hartman,
	Lee Jones, Heikki Krogerus, MyungJoo Ham
  Cc: linux-usb, linux-kernel

Hi Chanwoo,

On 03/18/2016 03:52 PM, Chanwoo Choi wrote:
> Hi Baolu,
>
> On 2016년 03월 18일 15:32, Lu Baolu wrote:
>> Several Intel PCHs and SOCs have an internal mux that is used to
>> share one USB port between device controller and host controller.
>>
>> A usb port mux could be abstracted as the following elements:
>> 1) mux state: HOST or PERIPHERAL;
>> 2) an extcon cable which triggers the change of mux state between
>>    HOST and PERIPHERAL;
>> 3) The required action to do the real port switch.
>>
>> This patch adds the common code to handle usb port mux. With this
>> common code, the individual mux driver, which always is platform
>> dependent, could focus on the real operation of mux switch.
>>
>> 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>
> Looks good to me about extcon usage.
>
> For extcon usage,
> Reviewed-by: Chanwoo Choi <cw00.choi@samsung.com>

Thank you!

>
> Best Regards,
> Chanwoo Choi
>
>
>> ---
>>  Documentation/ABI/testing/sysfs-bus-platform |  15 +++
>>  MAINTAINERS                                  |   7 ++
>>  drivers/usb/Kconfig                          |   2 +
>>  drivers/usb/Makefile                         |   1 +
>>  drivers/usb/mux/Kconfig                      |  12 ++
>>  drivers/usb/mux/Makefile                     |   4 +
>>  drivers/usb/mux/intel-mux.c                  | 175 +++++++++++++++++++++++++++
>>  include/linux/usb/intel-mux.h                |  40 ++++++
>>  8 files changed, 256 insertions(+)
>>  create mode 100644 drivers/usb/mux/Kconfig
>>  create mode 100644 drivers/usb/mux/Makefile
>>  create mode 100644 drivers/usb/mux/intel-mux.c
>>  create mode 100644 include/linux/usb/intel-mux.h
>>
>> diff --git a/Documentation/ABI/testing/sysfs-bus-platform b/Documentation/ABI/testing/sysfs-bus-platform
>> index 5172a61..23bf76e 100644
>> --- a/Documentation/ABI/testing/sysfs-bus-platform
>> +++ b/Documentation/ABI/testing/sysfs-bus-platform
>> @@ -18,3 +18,18 @@ Description:
>>  		devices to opt-out of driver binding using a driver_override
>>  		name such as "none".  Only a single driver may be specified in
>>  		the override, there is no support for parsing delimiters.
>> +
>> +What:		/sys/bus/platform/devices/.../port_mux
>> +Date:		Febuary 2016
>> +Contact:	Lu Baolu <baolu.lu@linux.intel.com>
>> +Description:
>> +		In some platforms, a single USB port is shared between a USB host
>> +		controller and a device controller. A USB mux driver is needed to
>> +		handle the port mux. port_mux attribute shows and stores the mux
>> +		state.
>> +		For read:
>> +		'peripheral' - mux switched to PERIPHERAL controller;
>> +		'host'       - mux switched to HOST controller.
>> +		For write:
>> +		'peripheral' - mux will be switched to PERIPHERAL controller;
>> +		'host'       - mux will be switched to HOST controller.
>> diff --git a/MAINTAINERS b/MAINTAINERS
>> index da3e4d8..0dbee11 100644
>> --- a/MAINTAINERS
>> +++ b/MAINTAINERS
>> @@ -11399,6 +11399,13 @@ T:	git git://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb.git
>>  S:	Maintained
>>  F:	drivers/usb/phy/
>>  
>> +USB PORT MUX DRIVER
>> +M:	Lu Baolu <baolu.lu@linux.intel.com>
>> +L:	linux-usb@vger.kernel.org
>> +S:	Supported
>> +F:	include/linux/usb/intel-mux.h
>> +F:	drivers/usb/mux/intel-mux.c
>> +
>>  USB PRINTER DRIVER (usblp)
>>  M:	Pete Zaitcev <zaitcev@redhat.com>
>>  L:	linux-usb@vger.kernel.org
>> diff --git a/drivers/usb/Kconfig b/drivers/usb/Kconfig
>> index 8ed451d..dbd6620 100644
>> --- a/drivers/usb/Kconfig
>> +++ b/drivers/usb/Kconfig
>> @@ -149,6 +149,8 @@ endif # USB
>>  
>>  source "drivers/usb/phy/Kconfig"
>>  
>> +source "drivers/usb/mux/Kconfig"
>> +
>>  source "drivers/usb/gadget/Kconfig"
>>  
>>  config USB_LED_TRIG
>> diff --git a/drivers/usb/Makefile b/drivers/usb/Makefile
>> index d5c57f1..6433f0c 100644
>> --- a/drivers/usb/Makefile
>> +++ b/drivers/usb/Makefile
>> @@ -6,6 +6,7 @@
>>  
>>  obj-$(CONFIG_USB)		+= core/
>>  obj-$(CONFIG_USB_SUPPORT)	+= phy/
>> +obj-$(CONFIG_USB_SUPPORT)	+= mux/
>>  
>>  obj-$(CONFIG_USB_DWC3)		+= dwc3/
>>  obj-$(CONFIG_USB_DWC2)		+= dwc2/
>> diff --git a/drivers/usb/mux/Kconfig b/drivers/usb/mux/Kconfig
>> new file mode 100644
>> index 0000000..62e2cc3
>> --- /dev/null
>> +++ b/drivers/usb/mux/Kconfig
>> @@ -0,0 +1,12 @@
>> +#
>> +# USB port mux driver configuration
>> +#
>> +menu "USB Port MUX drivers"
>> +config INTEL_USB_MUX
>> +	select EXTCON
>> +	def_bool n
>> +	help
>> +	  Common code for all Intel dual role port mux drivers. All Intel
>> +	  usb port mux drivers should select it.
>> +
>> +endmenu
>> diff --git a/drivers/usb/mux/Makefile b/drivers/usb/mux/Makefile
>> new file mode 100644
>> index 0000000..84f0ae8
>> --- /dev/null
>> +++ b/drivers/usb/mux/Makefile
>> @@ -0,0 +1,4 @@
>> +#
>> +# Makefile for USB port mux drivers
>> +#
>> +obj-$(CONFIG_INTEL_USB_MUX)		+= intel-mux.o
>> diff --git a/drivers/usb/mux/intel-mux.c b/drivers/usb/mux/intel-mux.c
>> new file mode 100644
>> index 0000000..d18b96f
>> --- /dev/null
>> +++ b/drivers/usb/mux/intel-mux.c
>> @@ -0,0 +1,175 @@
>> +/**
>> + * intel_mux.c - USB Port Mux support
>> + *
>> + * Copyright (C) 2016 Intel Corporation
>> + *
>> + * 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/slab.h>
>> +#include <linux/notifier.h>
>> +#include <linux/extcon.h>
>> +#include <linux/err.h>
>> +
>> +struct intel_usb_mux {
>> +	struct device *dev;
>> +	struct extcon_dev *edev;
>> +	int (*cable_set_cb)(struct device *dev);
>> +	int (*cable_unset_cb)(struct device *dev);
>> +
>> +	struct notifier_block nb;
>> +
>> +	/*
>> +	 * The state of the mux.
>> +	 * 0, 1 - mux switch state
>> +	 * -1   - uninitialized state
>> +	 */
>> +	int mux_state;
>> +
>> +	 /* lock for mux_state */
>> +	struct mutex mux_mutex;
>> +};
>> +
>> +static int usb_mux_change_state(struct intel_usb_mux *mux, int state)
>> +{
>> +	int ret;
>> +	struct device *dev = mux->dev;
>> +
>> +	dev_WARN_ONCE(dev,
>> +		      !mutex_is_locked(&mux->mux_mutex),
>> +		      "mutex is unlocked\n");
>> +
>> +	mux->mux_state = state;
>> +
>> +	if (mux->mux_state)
>> +		ret = mux->cable_set_cb(dev);
>> +	else
>> +		ret = mux->cable_unset_cb(dev);
>> +
>> +	return ret;
>> +}
>> +
>> +static int usb_mux_notifier(struct notifier_block *nb,
>> +			    unsigned long event, void *ptr)
>> +{
>> +	struct intel_usb_mux *mux;
>> +	int state;
>> +	int ret = NOTIFY_DONE;
>> +
>> +	mux = container_of(nb, struct intel_usb_mux, nb);
>> +
>> +	state = extcon_get_cable_state_(mux->edev, EXTCON_USB_HOST);
>> +
>> +	if (mux->mux_state == -1 || mux->mux_state != state) {
>> +		mutex_lock(&mux->mux_mutex);
>> +		ret = usb_mux_change_state(mux, state);
>> +		mutex_unlock(&mux->mux_mutex);
>> +	}
>> +
>> +	return ret;
>> +}
>> +
>> +static ssize_t port_mux_show(struct device *dev,
>> +			     struct device_attribute *attr, char *buf)
>> +{
>> +	struct intel_usb_mux *mux = dev_get_drvdata(dev);
>> +
>> +	if (dev_WARN_ONCE(dev, !mux, "mux without data structure\n"))
>> +		return 0;
>> +
>> +	return sprintf(buf, "%s\n", mux->mux_state ? "host" : "peripheral");
>> +}
>> +
>> +static ssize_t port_mux_store(struct device *dev,
>> +			      struct device_attribute *attr,
>> +			      const char *buf, size_t count)
>> +{
>> +	struct intel_usb_mux *mux = dev_get_drvdata(dev);
>> +	int state;
>> +
>> +	if (dev_WARN_ONCE(dev, !mux, "mux without data structure\n"))
>> +		return -EINVAL;
>> +
>> +	if (sysfs_streq(buf, "peripheral"))
>> +		state = 0;
>> +	else if (sysfs_streq(buf, "host"))
>> +		state = 1;
>> +	else
>> +		return -EINVAL;
>> +
>> +	mutex_lock(&mux->mux_mutex);
>> +	usb_mux_change_state(mux, state);
>> +	mutex_unlock(&mux->mux_mutex);
>> +
>> +	return count;
>> +}
>> +static DEVICE_ATTR_RW(port_mux);
>> +
>> +int intel_usb_mux_bind_cable(struct device *dev, const char *extcon_name,
>> +			     int (*cable_set_cb)(struct device *dev),
>> +			     int (*cable_unset_cb)(struct device *dev))
>> +{
>> +	int ret;
>> +	struct intel_usb_mux *mux;
>> +	struct extcon_dev *edev;
>> +
>> +	edev = extcon_get_extcon_dev(extcon_name);
>> +	if (IS_ERR_OR_NULL(edev))
>> +		return -ENODEV;
>> +
>> +	mux = devm_kzalloc(dev, sizeof(*mux), GFP_KERNEL);
>> +	if (!mux)
>> +		return -ENOMEM;
>> +
>> +	mux->dev = dev;
>> +	mux->edev = edev;
>> +	mux->cable_set_cb = cable_set_cb;
>> +	mux->cable_unset_cb = cable_unset_cb;
>> +	mux->nb.notifier_call = usb_mux_notifier;
>> +	mutex_init(&mux->mux_mutex);
>> +	mux->mux_state = -1;
>> +
>> +	dev_set_drvdata(dev, mux);
>> +	ret = extcon_register_notifier(edev, EXTCON_USB_HOST, &mux->nb);
>> +	if (ret < 0) {
>> +		dev_err(dev, "failed to register extcon notifier\n");
>> +		return -ENODEV;
>> +	}
>> +
>> +	usb_mux_notifier(&mux->nb, 0, NULL);
>> +
>> +	/* register the sysfs interface */
>> +	ret = device_create_file(dev, &dev_attr_port_mux);
>> +	if (ret) {
>> +		extcon_unregister_notifier(edev, EXTCON_USB_HOST, &mux->nb);
>> +		dev_err(dev, "failed to create sysfs attribute\n");
>> +		return -ENODEV;
>> +	}
>> +
>> +	return 0;
>> +}
>> +EXPORT_SYMBOL_GPL(intel_usb_mux_bind_cable);
>> +
>> +int intel_usb_mux_unbind_cable(struct device *dev)
>> +{
>> +	struct intel_usb_mux *mux = dev_get_drvdata(dev);
>> +
>> +	device_remove_file(dev, &dev_attr_port_mux);
>> +	extcon_unregister_notifier(mux->edev, EXTCON_USB_HOST, &mux->nb);
>> +
>> +	return 0;
>> +}
>> +EXPORT_SYMBOL_GPL(intel_usb_mux_unbind_cable);
>> +
>> +#ifdef CONFIG_PM_SLEEP
>> +void intel_usb_mux_complete(struct device *dev)
>> +{
>> +	struct intel_usb_mux *mux = dev_get_drvdata(dev);
>> +
>> +	usb_mux_notifier(&mux->nb, 0, NULL);
>> +}
>> +EXPORT_SYMBOL_GPL(intel_usb_mux_complete);
>> +#endif
>> diff --git a/include/linux/usb/intel-mux.h b/include/linux/usb/intel-mux.h
>> new file mode 100644
>> index 0000000..b00975a
>> --- /dev/null
>> +++ b/include/linux/usb/intel-mux.h
>> @@ -0,0 +1,40 @@
>> +/**
>> + * intel_mux.h - USB Port Mux definitions
>> + *
>> + * Copyright (C) 2016 Intel Corporation
>> + *
>> + * 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.
>> + */
>> +
>> +#ifndef __LINUX_USB_INTEL_MUX_H
>> +#define __LINUX_USB_INTEL_MUX_H
>> +
>> +#if IS_ENABLED(CONFIG_INTEL_USB_MUX)
>> +int intel_usb_mux_bind_cable(struct device *dev, const char *extcon_name,
>> +			     int (*cable_set_cb)(struct device *dev),
>> +			     int (*cable_unset_cb)(struct device *dev));
>> +int intel_usb_mux_unbind_cable(struct device *dev);
>> +#ifdef CONFIG_PM_SLEEP
>> +void intel_usb_mux_complete(struct device *dev);
>> +#endif
>> +
>> +#else
>> +static inline int
>> +int intel_usb_mux_bind_cable(struct device *dev, const char *extcon_name,
>> +			     int (*cable_set_cb)(struct device *dev),
>> +			     int (*cable_unset_cb)(struct device *dev))
>> +{
>> +	return -ENODEV;
>> +}
>> +
>> +static inline int intel_usb_mux_unbind_cable(struct device *dev)
>> +{
>> +	return 0;
>> +}
>> +#endif /* CONFIG_INTEL_USB_MUX */
>> +
>> +#endif /* __LINUX_USB_INTEL_MUX_H */
>>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-usb" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v5 6/6] mfd: intel_vuport: Add Intel virtual USB port MFD Driver
  2016-03-18  8:09   ` Lee Jones
@ 2016-03-18  8:43     ` Lu Baolu
  2016-03-18 15:30       ` Greg Kroah-Hartman
  0 siblings, 1 reply; 12+ messages in thread
From: Lu Baolu @ 2016-03-18  8:43 UTC (permalink / raw)
  To: Lee Jones
  Cc: Felipe Balbi, Mathias Nyman, Greg Kroah-Hartman, Heikki Krogerus,
	MyungJoo Ham, Chanwoo Choi, linux-usb, linux-kernel,
	Fengguang Wu



On 03/18/2016 04:09 PM, Lee Jones wrote:
> On Fri, 18 Mar 2016, Lu Baolu wrote:
>
>> Some Intel platforms have an USB port mux controlled by GPIOs.
>> There's a single ACPI platform device that provides both USB ID
>> extcon device and a USB port mux device. This MFD driver will
>> split the 2 devices for their respective drivers.
>>
>> Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
>> Suggested-by: David Cohen <david.a.cohen@linux.intel.com>
> This should be at the top.
>
> You couldn't have written the patch before it was suggested.

Yes. I will change this.

>
>> Reviewed-by: Felipe Balbi <balbi@kernel.org>
>> Signed-off-by: Fengguang Wu <fengguang.wu@intel.com>
> What is this sign-off meant to indicate?

Fengguang's sign-off was added due to folding a patch contributed by
his kbuild robot.

https://lkml.org/lkml/2016/3/3/118

I will add this in commit message.

>
>> Reviewed-by: Lee Jones <lee.jones@linaro.org>
> Why is this here?
>
> a) I don't provide "Reviewed-by:" tags #alarmbells
> b) I have never signed this patch off

Sorry about this. I will remove this line.

>
>> ---
>>  MAINTAINERS                |  6 ++++
> Seperate patch.

If I make it in a separate patch, checkpatch.pl will give me below warning.

"
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
#51:
new file mode 100644
"

Is it forgivable?

Best regards,
Baolu

>
>>  drivers/mfd/Kconfig        |  8 +++++
>>  drivers/mfd/Makefile       |  1 +
>>  drivers/mfd/intel-vuport.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++
>>  4 files changed, 89 insertions(+)
>>  create mode 100644 drivers/mfd/intel-vuport.c
> [...]
>

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v5 6/6] mfd: intel_vuport: Add Intel virtual USB port MFD Driver
  2016-03-18  8:43     ` Lu Baolu
@ 2016-03-18 15:30       ` Greg Kroah-Hartman
  0 siblings, 0 replies; 12+ messages in thread
From: Greg Kroah-Hartman @ 2016-03-18 15:30 UTC (permalink / raw)
  To: Lu Baolu
  Cc: Lee Jones, Felipe Balbi, Mathias Nyman, Heikki Krogerus,
	MyungJoo Ham, Chanwoo Choi, linux-usb, linux-kernel,
	Fengguang Wu

On Fri, Mar 18, 2016 at 04:43:21PM +0800, Lu Baolu wrote:
> 
> 
> On 03/18/2016 04:09 PM, Lee Jones wrote:
> > On Fri, 18 Mar 2016, Lu Baolu wrote:
> >
> >> Some Intel platforms have an USB port mux controlled by GPIOs.
> >> There's a single ACPI platform device that provides both USB ID
> >> extcon device and a USB port mux device. This MFD driver will
> >> split the 2 devices for their respective drivers.
> >>
> >> Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
> >> Suggested-by: David Cohen <david.a.cohen@linux.intel.com>
> > This should be at the top.
> >
> > You couldn't have written the patch before it was suggested.
> 
> Yes. I will change this.
> 
> >
> >> Reviewed-by: Felipe Balbi <balbi@kernel.org>
> >> Signed-off-by: Fengguang Wu <fengguang.wu@intel.com>
> > What is this sign-off meant to indicate?
> 
> Fengguang's sign-off was added due to folding a patch contributed by
> his kbuild robot.

No, you can't do that, he only signed off on his fixup patch, not your
overall larger patch!

I'm going to stop you now and require you to get this properly reviewed,
and signed-off-by some experienced Intel kernel developers before I look
at this at all.  Take advantage of the resources you have, don't force
the community to point out these basic mistakes.

Also, you know I'm not looking at new patches until after -rc1 is out,
so please wait until then before resending.

greg k-h

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2016-03-18 15:30 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-03-18  6:32 [PATCH v5 0/6] usb: add support for Intel dual role port mux Lu Baolu
2016-03-18  6:32 ` [PATCH v5 1/6] extcon: usb-gpio: add device binding for platform device Lu Baolu
2016-03-18  6:32 ` [PATCH v5 2/6] extcon: usb-gpio: add support for ACPI gpio interface Lu Baolu
2016-03-18  6:32 ` [PATCH v5 3/6] usb: mux: add common code for Intel dual role port mux Lu Baolu
2016-03-18  7:52   ` Chanwoo Choi
2016-03-18  8:23     ` Lu Baolu
2016-03-18  6:32 ` [PATCH v5 4/6] usb: mux: add driver for Intel gpio controlled " Lu Baolu
2016-03-18  6:32 ` [PATCH v5 5/6] usb: mux: add driver for Intel drcfg " Lu Baolu
2016-03-18  6:32 ` [PATCH v5 6/6] mfd: intel_vuport: Add Intel virtual USB port MFD Driver Lu Baolu
2016-03-18  8:09   ` Lee Jones
2016-03-18  8:43     ` Lu Baolu
2016-03-18 15:30       ` Greg Kroah-Hartman

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.