All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v8 0/7] usb: add support for Intel dual role port mux
@ 2016-05-05  5:32 Lu Baolu
  2016-05-05  5:32 ` [PATCH v8 1/7] regulator: fixed: add support for ACPI interface Lu Baolu
                   ` (6 more replies)
  0 siblings, 7 replies; 15+ messages in thread
From: Lu Baolu @ 2016-05-05  5:32 UTC (permalink / raw)
  To: felipe.balbi, Mathias Nyman, Greg Kroah-Hartman, Lee Jones,
	Heikki Krogerus, Liam Girdwood, Mark Brown
  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 a USB gpio extcon device, a fixed regulator for gpio
    controlled USB VCC, 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 (7):
  regulator: fixed: add support for ACPI interface
  usb: mux: add generic code for 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
  usb: pci-quirks: add Intel USB drcfg mux device
  MAINTAINERS: add maintainer entry for Intel USB dual role mux drivers

Change log:

v7->v8:
 - In patch "regulator: fixed: add support for ACPI interface", the
   fixed regulator gpio name has been changed to "gpio".
 - In patch "MAINTAINERS: add maintainer entry for Intel USB dual role
   mux drivers", filenames have been updated.

v6->v7:
 - Two patches have been picked up by extcon maintainer. Hence,
   remove them since this version.
   - extcon: usb-gpio: add device binding for platform device
   - extcon: usb-gpio: add support for ACPI gpio interface
 - Below patch has been removed from this series because it's unnecessary.
   - regulator: fixed: add device binding for platform device
 - In patch "regulator: fixed: add support for ACPI interface",
   a static gpio name is used to get the regulator gpio.
 - In patch "mfd: intel_vuport: Add Intel virtual USB port MFD Driver",
   unnecessary "gpio-name" string property has been removed.

v5->v6:
 Work internally with Felipe to improve the whole patch series.
 Below changes have been made since last version.
 - rework the common code to make it a generic interface for mux devices;
 - split the vbus gpio handling to a fixed regulator device;
 - removed unnecessary filtering for state change;
 - removed unnecessary WARN statement;
 - removed globals in mux drivers;
 - removed unnecessary register polling and waiting in drcfg driver;

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 |  17 +++
 MAINTAINERS                                  |  10 ++
 drivers/mfd/Kconfig                          |   8 +
 drivers/mfd/Makefile                         |   1 +
 drivers/mfd/intel-vuport.c                   |  89 +++++++++++
 drivers/regulator/fixed.c                    |  46 ++++++
 drivers/usb/Kconfig                          |   2 +
 drivers/usb/Makefile                         |   1 +
 drivers/usb/host/pci-quirks.c                |  45 +++++-
 drivers/usb/host/xhci-ext-caps.h             |   2 +
 drivers/usb/mux/Kconfig                      |  30 ++++
 drivers/usb/mux/Makefile                     |   6 +
 drivers/usb/mux/portmux-core.c               | 217 +++++++++++++++++++++++++++
 drivers/usb/mux/portmux-intel-drcfg.c        | 171 +++++++++++++++++++++
 drivers/usb/mux/portmux-intel-gpio.c         | 149 ++++++++++++++++++
 include/linux/usb/portmux.h                  |  78 ++++++++++
 16 files changed, 870 insertions(+), 2 deletions(-)
 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/portmux-core.c
 create mode 100644 drivers/usb/mux/portmux-intel-drcfg.c
 create mode 100644 drivers/usb/mux/portmux-intel-gpio.c
 create mode 100644 include/linux/usb/portmux.h

-- 
2.1.4

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

* [PATCH v8 1/7] regulator: fixed: add support for ACPI interface
  2016-05-05  5:32 [PATCH v8 0/7] usb: add support for Intel dual role port mux Lu Baolu
@ 2016-05-05  5:32 ` Lu Baolu
  2016-05-13 11:17   ` Mark Brown
  2016-05-05  5:32 ` [PATCH v8 2/7] usb: mux: add generic code for dual role port mux Lu Baolu
                   ` (5 subsequent siblings)
  6 siblings, 1 reply; 15+ messages in thread
From: Lu Baolu @ 2016-05-05  5:32 UTC (permalink / raw)
  To: felipe.balbi, Mathias Nyman, Greg Kroah-Hartman, Lee Jones,
	Heikki Krogerus, Liam Girdwood, Mark Brown
  Cc: linux-usb, linux-kernel, Lu Baolu

Add support to retrieve fixed voltage configure information through
ACPI interface. This is needed for Intel Bay Trail devices, where a
GPIO is used to control the USB vbus.

Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
---
 drivers/regulator/fixed.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)

diff --git a/drivers/regulator/fixed.c b/drivers/regulator/fixed.c
index ff62d69..207ab40 100644
--- a/drivers/regulator/fixed.c
+++ b/drivers/regulator/fixed.c
@@ -30,6 +30,9 @@
 #include <linux/of_gpio.h>
 #include <linux/regulator/of_regulator.h>
 #include <linux/regulator/machine.h>
+#include <linux/acpi.h>
+#include <linux/property.h>
+#include <linux/gpio/consumer.h>
 
 struct fixed_voltage_data {
 	struct regulator_desc desc;
@@ -104,6 +107,44 @@ of_get_fixed_voltage_config(struct device *dev,
 	return config;
 }
 
+/**
+ * acpi_get_fixed_voltage_config - extract fixed_voltage_config structure info
+ * @dev: device requesting for fixed_voltage_config
+ * @desc: regulator description
+ *
+ * Populates fixed_voltage_config structure by extracting data through ACPI
+ * interface, returns a pointer to the populated structure of NULL if memory
+ * alloc fails.
+ */
+static struct fixed_voltage_config *
+acpi_get_fixed_voltage_config(struct device *dev,
+			      const struct regulator_desc *desc)
+{
+	struct fixed_voltage_config *config;
+	const char *supply_name;
+	struct gpio_desc *gpiod;
+	int ret;
+
+	config = devm_kzalloc(dev, sizeof(*config), GFP_KERNEL);
+	if (!config)
+		return ERR_PTR(-ENOMEM);
+
+	ret = device_property_read_string(dev, "supply-name", &supply_name);
+	if (!ret)
+		config->supply_name = supply_name;
+
+	gpiod = gpiod_get(dev, "gpio", GPIOD_ASIS);
+	if (IS_ERR(gpiod))
+		return ERR_PTR(-ENODEV);
+
+	config->gpio = desc_to_gpio(gpiod);
+	config->enable_high = device_property_read_bool(dev,
+							"enable-active-high");
+	gpiod_put(gpiod);
+
+	return config;
+}
+
 static struct regulator_ops fixed_voltage_ops = {
 };
 
@@ -124,6 +165,11 @@ static int reg_fixed_voltage_probe(struct platform_device *pdev)
 						     &drvdata->desc);
 		if (IS_ERR(config))
 			return PTR_ERR(config);
+	} else if (ACPI_HANDLE(&pdev->dev)) {
+		config = acpi_get_fixed_voltage_config(&pdev->dev,
+						       &drvdata->desc);
+		if (IS_ERR(config))
+			return PTR_ERR(config);
 	} else {
 		config = dev_get_platdata(&pdev->dev);
 	}
-- 
2.1.4

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

* [PATCH v8 2/7] usb: mux: add generic code for dual role port mux
  2016-05-05  5:32 [PATCH v8 0/7] usb: add support for Intel dual role port mux Lu Baolu
  2016-05-05  5:32 ` [PATCH v8 1/7] regulator: fixed: add support for ACPI interface Lu Baolu
@ 2016-05-05  5:32 ` Lu Baolu
  2016-05-25 11:06   ` Heikki Krogerus
  2016-05-05  5:32 ` [PATCH v8 3/7] usb: mux: add driver for Intel gpio controlled " Lu Baolu
                   ` (4 subsequent siblings)
  6 siblings, 1 reply; 15+ messages in thread
From: Lu Baolu @ 2016-05-05  5:32 UTC (permalink / raw)
  To: felipe.balbi, Mathias Nyman, Greg Kroah-Hartman, Lee Jones,
	Heikki Krogerus, Liam Girdwood, Mark Brown
  Cc: linux-usb, linux-kernel, Lu Baolu

Several Intel platforms implement USB dual role by having completely
separate xHCI and dwc3 IPs in PCH or SOC silicons. These two IPs share
a single USB port. There is another external port mux which controls
where the data lines should go. While the USB controllers are part of
the silicon, the port mux design are platform specific.

This patch adds the generic code to handle such usb port mux. It listens
to the USB HOST extcon cable, and switch the port by calling the port
switch ops provided by the individual port mux driver. It also registers
the mux device with sysfs, so that users can control the port mux from
user space.

Some other archs (e.g. Renesas R-Car gen2 SoCs) need an external mux to
swap usb roles as well. This code could be leveraged for those archs
as well.

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>
Reviewed-by: Chanwoo Choi <cw00.choi@samsung.com>
[baolu: extcon usage reviewed by Chanwoo Choi]
---
 Documentation/ABI/testing/sysfs-bus-platform |  17 +++
 drivers/usb/Kconfig                          |   2 +
 drivers/usb/Makefile                         |   1 +
 drivers/usb/mux/Kconfig                      |  11 ++
 drivers/usb/mux/Makefile                     |   4 +
 drivers/usb/mux/portmux-core.c               | 217 +++++++++++++++++++++++++++
 include/linux/usb/portmux.h                  |  78 ++++++++++
 7 files changed, 330 insertions(+)
 create mode 100644 drivers/usb/mux/Kconfig
 create mode 100644 drivers/usb/mux/Makefile
 create mode 100644 drivers/usb/mux/portmux-core.c
 create mode 100644 include/linux/usb/portmux.h

diff --git a/Documentation/ABI/testing/sysfs-bus-platform b/Documentation/ABI/testing/sysfs-bus-platform
index 5172a61..f33f0a5 100644
--- a/Documentation/ABI/testing/sysfs-bus-platform
+++ b/Documentation/ABI/testing/sysfs-bus-platform
@@ -18,3 +18,20 @@ 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/.../portmux.N/name
+		/sys/bus/platform/devices/.../portmux.N/state
+Date:		April 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. Read-only attribute "name" shows the name of
+		the port mux device. "state" 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/drivers/usb/Kconfig b/drivers/usb/Kconfig
index 8689dcb..328916e 100644
--- a/drivers/usb/Kconfig
+++ b/drivers/usb/Kconfig
@@ -148,6 +148,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 dca7856..9a92338 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..d91909f
--- /dev/null
+++ b/drivers/usb/mux/Kconfig
@@ -0,0 +1,11 @@
+#
+# USB port mux driver configuration
+#
+
+menu "USB Port MUX drivers"
+config USB_PORTMUX
+	select EXTCON
+	def_bool n
+	help
+	  Generic USB dual role port mux support.
+endmenu
diff --git a/drivers/usb/mux/Makefile b/drivers/usb/mux/Makefile
new file mode 100644
index 0000000..f85df92
--- /dev/null
+++ b/drivers/usb/mux/Makefile
@@ -0,0 +1,4 @@
+#
+# Makefile for USB port mux drivers
+#
+obj-$(CONFIG_USB_PORTMUX)		+= portmux-core.o
diff --git a/drivers/usb/mux/portmux-core.c b/drivers/usb/mux/portmux-core.c
new file mode 100644
index 0000000..0e3548b
--- /dev/null
+++ b/drivers/usb/mux/portmux-core.c
@@ -0,0 +1,217 @@
+/**
+ * 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>
+#include <linux/usb/portmux.h>
+
+static int usb_mux_change_state(struct portmux_dev *pdev, int state)
+{
+	int ret;
+	struct device *dev = &pdev->dev;
+
+	dev_WARN_ONCE(dev,
+		      !mutex_is_locked(&pdev->mux_mutex),
+		      "mutex is unlocked\n");
+
+	pdev->mux_state = state;
+
+	if (pdev->mux_state)
+		ret = pdev->desc->ops->cable_set_cb(pdev->dev.parent);
+	else
+		ret = pdev->desc->ops->cable_unset_cb(pdev->dev.parent);
+
+	return ret;
+}
+
+static int usb_mux_notifier(struct notifier_block *nb,
+			    unsigned long event, void *ptr)
+{
+	struct portmux_dev *pdev;
+	int state;
+	int ret = NOTIFY_DONE;
+
+	pdev = container_of(nb, struct portmux_dev, nb);
+
+	state = extcon_get_cable_state_(pdev->edev, EXTCON_USB_HOST);
+	if (state < 0)
+		return state;
+
+	mutex_lock(&pdev->mux_mutex);
+	ret = usb_mux_change_state(pdev, state);
+	mutex_unlock(&pdev->mux_mutex);
+
+	return ret;
+}
+
+static ssize_t state_show(struct device *dev,
+			  struct device_attribute *attr,
+			  char *buf)
+{
+	struct portmux_dev *pdev = dev_get_drvdata(dev);
+
+	return sprintf(buf, "%s\n", pdev->mux_state ? "host" : "peripheral");
+}
+
+static ssize_t state_store(struct device *dev,
+			   struct device_attribute *attr,
+			   const char *buf, size_t count)
+{
+	struct portmux_dev *pdev = dev_get_drvdata(dev);
+	int state;
+
+	if (sysfs_streq(buf, "peripheral"))
+		state = 0;
+	else if (sysfs_streq(buf, "host"))
+		state = 1;
+	else
+		return -EINVAL;
+
+	mutex_lock(&pdev->mux_mutex);
+	usb_mux_change_state(pdev, state);
+	mutex_unlock(&pdev->mux_mutex);
+
+	return count;
+}
+static DEVICE_ATTR_RW(state);
+
+static ssize_t name_show(struct device *dev,
+			 struct device_attribute *attr,
+			 char *buf)
+{
+	struct portmux_dev *pdev = dev_get_drvdata(dev);
+
+	return sprintf(buf, "%s\n", pdev->desc->name);
+}
+static DEVICE_ATTR_RO(name);
+
+static struct attribute *portmux_attrs[] = {
+	&dev_attr_state.attr,
+	&dev_attr_name.attr,
+	NULL,
+};
+
+static struct attribute_group portmux_attr_grp = {
+	.attrs = portmux_attrs,
+};
+
+static const struct attribute_group *portmux_group[] = {
+	&portmux_attr_grp,
+	NULL,
+};
+
+/**
+ * portmux_register - register a port mux
+ * @dev: device the mux belongs to
+ * @desc: the descriptor of this port mux
+ *
+ * Called by port mux drivers to register a mux.
+ * Returns a valid pointer to struct portmux_dev on success
+ * or an ERR_PTR() on error.
+ */
+struct portmux_dev *portmux_register(struct portmux_desc *desc)
+{
+	static atomic_t portmux_no = ATOMIC_INIT(-1);
+	struct portmux_dev *pdev;
+	struct extcon_dev *edev = NULL;
+	struct device *dev;
+	int ret;
+
+	/* parameter sanity check */
+	if (!desc || !desc->name || !desc->ops || !desc->dev ||
+	    !desc->ops->cable_set_cb || !desc->ops->cable_unset_cb)
+		return ERR_PTR(-EINVAL);
+
+	dev = desc->dev;
+
+	if (desc->extcon_name) {
+		edev = extcon_get_extcon_dev(desc->extcon_name);
+		if (IS_ERR_OR_NULL(edev))
+			return ERR_PTR(-EPROBE_DEFER);
+	}
+
+	pdev = kzalloc(sizeof(*pdev), GFP_KERNEL);
+	if (!pdev)
+		return ERR_PTR(-ENOMEM);
+
+	pdev->desc = desc;
+	pdev->edev = edev;
+	pdev->nb.notifier_call = usb_mux_notifier;
+	mutex_init(&pdev->mux_mutex);
+
+	pdev->dev.parent = dev;
+	dev_set_name(&pdev->dev, "portmux.%lu",
+		     (unsigned long)atomic_inc_return(&portmux_no));
+	pdev->dev.groups = portmux_group;
+	ret = device_register(&pdev->dev);
+	if (ret)
+		goto cleanup_mem;
+
+	dev_set_drvdata(&pdev->dev, pdev);
+
+	if (edev) {
+		ret = extcon_register_notifier(edev, EXTCON_USB_HOST,
+					       &pdev->nb);
+		if (ret < 0) {
+			dev_err(dev, "failed to register extcon notifier\n");
+			goto cleanup_dev;
+		}
+	}
+
+	if (desc->initial_state == -1) {
+		usb_mux_notifier(&pdev->nb, 0, NULL);
+	} else {
+		mutex_lock(&pdev->mux_mutex);
+		ret = usb_mux_change_state(pdev, !!desc->initial_state);
+		mutex_unlock(&pdev->mux_mutex);
+	}
+
+	return pdev;
+
+cleanup_dev:
+	device_unregister(&pdev->dev);
+cleanup_mem:
+	kfree(pdev);
+
+	return ERR_PTR(ret);
+}
+EXPORT_SYMBOL_GPL(portmux_register);
+
+/**
+ * portmux_unregister - unregister a port mux
+ * @pdev: the port mux device
+ *
+ * Called by port mux drivers to release a mux.
+ */
+void portmux_unregister(struct portmux_dev *pdev)
+{
+	extcon_unregister_notifier(pdev->edev, EXTCON_USB_HOST, &pdev->nb);
+	device_unregister(&pdev->dev);
+	kfree(pdev);
+}
+EXPORT_SYMBOL_GPL(portmux_unregister);
+
+#ifdef CONFIG_PM_SLEEP
+/**
+ * portmux_complete - refresh port state during system resumes back
+ * @pdev: the port mux device
+ *
+ * Called by port mux drivers to refresh port state during system
+ * resumes back.
+ */
+void portmux_complete(struct portmux_dev *pdev)
+{
+	usb_mux_notifier(&pdev->nb, 0, NULL);
+}
+EXPORT_SYMBOL_GPL(portmux_complete);
+#endif
diff --git a/include/linux/usb/portmux.h b/include/linux/usb/portmux.h
new file mode 100644
index 0000000..9250028
--- /dev/null
+++ b/include/linux/usb/portmux.h
@@ -0,0 +1,78 @@
+/**
+ * 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_PORTMUX_H
+#define __LINUX_USB_PORTMUX_H
+
+/**
+ * struct portmux_ops - ops two switch the port
+ *
+ * @cable_set_cb: function to switch port to host
+ * @cable_unset_cb: function to switch port to device
+ */
+struct portmux_ops {
+	int (*cable_set_cb)(struct device *dev);
+	int (*cable_unset_cb)(struct device *dev);
+};
+
+/**
+ * struct portmux_desc - port mux device descriptor
+ *
+ * @name: the name of the mux device
+ * @extcon_name: the name of extcon device, set to NULL if the mux
+ *               is not connected to any extcon cable  and control
+ *               purely by user through sysfs.
+ * @dev: the parent of the mux device
+ * @ops: ops to switch the port role
+ * @initial_state: the initial state of the mux, set to -1 if the
+ *                 initial state is unknown, set to 0 for device
+ *                 and 1 for host.
+ */
+struct portmux_desc {
+	const char *name;
+	const char *extcon_name;
+	struct device *dev;
+	const struct portmux_ops *ops;
+	int initial_state;
+};
+
+/**
+ * struct portmux_dev - A mux device
+ *
+ * @desc: the descriptor of the mux
+ * @dev: device of this mux
+ * @edev: the extcon device bound to this mux
+ * @nb: notifier of extcon state change
+ * @mux_mutex: lock to serialize port switch operation
+ * @mux_state: state of the mux, could be set to below values
+ *             -1: before initialization
+ *              0: port switched to device
+ *              1: port switched to host
+ */
+struct portmux_dev {
+	const struct portmux_desc *desc;
+	struct device dev;
+	struct extcon_dev *edev;
+	struct notifier_block nb;
+
+	 /* lock for mux_state */
+	struct mutex mux_mutex;
+	int mux_state;
+};
+
+struct portmux_dev *portmux_register(struct portmux_desc *desc);
+void portmux_unregister(struct portmux_dev *pdev);
+#ifdef CONFIG_PM_SLEEP
+void portmux_complete(struct portmux_dev *pdev);
+#endif
+
+#endif /* __LINUX_USB_PORTMUX_H */
-- 
2.1.4

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

* [PATCH v8 3/7] usb: mux: add driver for Intel gpio controlled port mux
  2016-05-05  5:32 [PATCH v8 0/7] usb: add support for Intel dual role port mux Lu Baolu
  2016-05-05  5:32 ` [PATCH v8 1/7] regulator: fixed: add support for ACPI interface Lu Baolu
  2016-05-05  5:32 ` [PATCH v8 2/7] usb: mux: add generic code for dual role port mux Lu Baolu
@ 2016-05-05  5:32 ` Lu Baolu
  2016-05-05  5:33 ` [PATCH v8 4/7] usb: mux: add driver for Intel drcfg " Lu Baolu
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 15+ messages in thread
From: Lu Baolu @ 2016-05-05  5:32 UTC (permalink / raw)
  To: felipe.balbi, Mathias Nyman, Greg Kroah-Hartman, Lee Jones,
	Heikki Krogerus, Liam Girdwood, Mark Brown
  Cc: linux-usb, linux-kernel, Lu Baolu, David Cohen

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.

[baolu: removed .owner per platform_no_drv_owner.cocci]
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>
---
 drivers/usb/mux/Kconfig              |  11 +++
 drivers/usb/mux/Makefile             |   1 +
 drivers/usb/mux/portmux-intel-gpio.c | 149 +++++++++++++++++++++++++++++++++++
 3 files changed, 161 insertions(+)
 create mode 100644 drivers/usb/mux/portmux-intel-gpio.c

diff --git a/drivers/usb/mux/Kconfig b/drivers/usb/mux/Kconfig
index d91909f..1dc1f33 100644
--- a/drivers/usb/mux/Kconfig
+++ b/drivers/usb/mux/Kconfig
@@ -8,4 +8,15 @@ config USB_PORTMUX
 	def_bool n
 	help
 	  Generic USB dual role port mux support.
+
+config INTEL_MUX_GPIO
+	tristate "Intel dual role port mux controlled by GPIOs"
+	depends on GPIOLIB
+	depends on REGULATOR
+	depends on X86 && ACPI
+	select USB_PORTMUX
+	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 f85df92..4eb5582 100644
--- a/drivers/usb/mux/Makefile
+++ b/drivers/usb/mux/Makefile
@@ -2,3 +2,4 @@
 # Makefile for USB port mux drivers
 #
 obj-$(CONFIG_USB_PORTMUX)		+= portmux-core.o
+obj-$(CONFIG_INTEL_MUX_GPIO)		+= portmux-intel-gpio.o
diff --git a/drivers/usb/mux/portmux-intel-gpio.c b/drivers/usb/mux/portmux-intel-gpio.c
new file mode 100644
index 0000000..b07ae2c
--- /dev/null
+++ b/drivers/usb/mux/portmux-intel-gpio.c
@@ -0,0 +1,149 @@
+/*
+ * 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/consumer.h>
+#include <linux/platform_device.h>
+#include <linux/usb/portmux.h>
+#include <linux/regulator/consumer.h>
+
+struct vuport {
+	struct portmux_desc desc;
+	struct portmux_dev *pdev;
+	struct regulator *regulator;
+	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 device *dev, int id)
+{
+	struct vuport *vup;
+
+	dev_dbg(dev, "USB PORT ID: %s\n", id ? "HOST" : "PERIPHERAL");
+
+	vup = dev_get_drvdata(dev);
+
+	gpiod_set_value_cansleep(vup->gpio_usb_mux, !id);
+
+	if (!id ^ regulator_is_enabled(vup->regulator))
+		return id ? regulator_disable(vup->regulator) :
+				regulator_enable(vup->regulator);
+
+	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 const struct portmux_ops vuport_ops = {
+	.cable_set_cb = vuport_cable_set,
+	.cable_unset_cb = vuport_cable_unset,
+};
+
+static int vuport_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct vuport *vup;
+
+	vup = devm_kzalloc(dev, sizeof(*vup), GFP_KERNEL);
+	if (!vup)
+		return -ENOMEM;
+
+	vup->regulator = devm_regulator_get_exclusive(dev,
+						      "regulator-usb-gpio");
+	if (IS_ERR(vup->regulator))
+		return -EPROBE_DEFER;
+
+	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->desc.dev = dev;
+	vup->desc.name = "intel-mux-gpio";
+	vup->desc.extcon_name = "extcon-usb-gpio";
+	vup->desc.ops = &vuport_ops;
+	vup->desc.initial_state = -1;
+	dev_set_drvdata(dev, vup);
+	vup->pdev = portmux_register(&vup->desc);
+
+	return PTR_ERR_OR_ZERO(vup->pdev);
+}
+
+static int vuport_remove(struct platform_device *pdev)
+{
+	struct vuport *vup;
+
+	vup = platform_get_drvdata(pdev);
+	portmux_unregister(vup->pdev);
+
+	return 0;
+}
+
+#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 void vuport_complete(struct device *dev)
+{
+	struct vuport *vup;
+
+	vup = dev_get_drvdata(dev);
+	portmux_complete(vup->pdev);
+}
+
+static const struct dev_pm_ops vuport_pm_ops = {
+	.complete = vuport_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] 15+ messages in thread

* [PATCH v8 4/7] usb: mux: add driver for Intel drcfg controlled port mux
  2016-05-05  5:32 [PATCH v8 0/7] usb: add support for Intel dual role port mux Lu Baolu
                   ` (2 preceding siblings ...)
  2016-05-05  5:32 ` [PATCH v8 3/7] usb: mux: add driver for Intel gpio controlled " Lu Baolu
@ 2016-05-05  5:33 ` Lu Baolu
  2016-05-05  5:33 ` [PATCH v8 5/7] mfd: intel_vuport: Add Intel virtual USB port MFD Driver Lu Baolu
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 15+ messages in thread
From: Lu Baolu @ 2016-05-05  5:33 UTC (permalink / raw)
  To: felipe.balbi, Mathias Nyman, Greg Kroah-Hartman, Lee Jones,
	Heikki Krogerus, Liam Girdwood, Mark Brown
  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>
---
 drivers/usb/mux/Kconfig               |   8 ++
 drivers/usb/mux/Makefile              |   1 +
 drivers/usb/mux/portmux-intel-drcfg.c | 171 ++++++++++++++++++++++++++++++++++
 3 files changed, 180 insertions(+)
 create mode 100644 drivers/usb/mux/portmux-intel-drcfg.c

diff --git a/drivers/usb/mux/Kconfig b/drivers/usb/mux/Kconfig
index 1dc1f33..ae3f746 100644
--- a/drivers/usb/mux/Kconfig
+++ b/drivers/usb/mux/Kconfig
@@ -19,4 +19,12 @@ 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 USB_PORTMUX
+	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 4eb5582..0f102b5 100644
--- a/drivers/usb/mux/Makefile
+++ b/drivers/usb/mux/Makefile
@@ -3,3 +3,4 @@
 #
 obj-$(CONFIG_USB_PORTMUX)		+= portmux-core.o
 obj-$(CONFIG_INTEL_MUX_GPIO)		+= portmux-intel-gpio.o
+obj-$(CONFIG_INTEL_MUX_DRCFG)		+= portmux-intel-drcfg.o
diff --git a/drivers/usb/mux/portmux-intel-drcfg.c b/drivers/usb/mux/portmux-intel-drcfg.c
new file mode 100644
index 0000000..0bb6b08
--- /dev/null
+++ b/drivers/usb/mux/portmux-intel-drcfg.c
@@ -0,0 +1,171 @@
+/**
+ * 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/portmux.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_MODE		BIT(29)
+
+struct intel_mux_drcfg {
+	struct portmux_desc desc;
+	struct device *dev;
+	void __iomem *regs;
+	struct portmux_dev *pdev;
+};
+
+static inline int intel_mux_drcfg_switch(struct device *dev, bool host)
+{
+	u32 data;
+	struct intel_mux_drcfg *mux;
+
+	mux = dev_get_drvdata(dev);
+
+	/* 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);
+
+	return 0;
+}
+
+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 const struct portmux_ops drcfg_ops = {
+	.cable_set_cb = intel_mux_drcfg_cable_set,
+	.cable_unset_cb = intel_mux_drcfg_cable_unset,
+};
+
+static int intel_mux_drcfg_probe(struct platform_device *pdev)
+{
+	struct intel_mux_drcfg *mux;
+	struct device *dev = &pdev->dev;
+	const char *extcon_name = NULL;
+	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);
+	if (ret)
+		return -ENODEV;
+
+	ret = device_property_read_string(dev, "extcon-name", &extcon_name);
+	if (!ret)
+		mux->desc.extcon_name = extcon_name;
+
+	mux->regs = devm_ioremap_nocache(dev, start, size);
+	if (!mux->regs)
+		return -ENOMEM;
+
+	mux->desc.dev = dev;
+	mux->desc.name = "intel-mux-drcfg";
+	mux->desc.ops = &drcfg_ops;
+	mux->desc.initial_state =
+			!!(readl(mux->regs + INTEL_MUX_CFG1) & CFG1_MODE);
+	dev_set_drvdata(dev, mux);
+	mux->pdev = portmux_register(&mux->desc);
+
+	return PTR_ERR_OR_ZERO(mux->pdev);
+}
+
+static int intel_mux_drcfg_remove(struct platform_device *pdev)
+{
+	struct intel_mux_drcfg *mux;
+
+	mux = platform_get_drvdata(pdev);
+	portmux_unregister(mux->pdev);
+
+	return 0;
+}
+
+#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 void intel_mux_drcfg_complete(struct device *dev)
+{
+	struct intel_mux_drcfg *mux;
+
+	mux = dev_get_drvdata(dev);
+	portmux_complete(mux->pdev);
+}
+
+static const struct dev_pm_ops intel_mux_drcfg_pm_ops = {
+	.complete = intel_mux_drcfg_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] 15+ messages in thread

* [PATCH v8 5/7] mfd: intel_vuport: Add Intel virtual USB port MFD Driver
  2016-05-05  5:32 [PATCH v8 0/7] usb: add support for Intel dual role port mux Lu Baolu
                   ` (3 preceding siblings ...)
  2016-05-05  5:33 ` [PATCH v8 4/7] usb: mux: add driver for Intel drcfg " Lu Baolu
@ 2016-05-05  5:33 ` Lu Baolu
  2016-05-09 14:26   ` Lee Jones
  2016-05-05  5:33 ` [PATCH v8 6/7] usb: pci-quirks: add Intel USB drcfg mux device Lu Baolu
  2016-05-05  5:33 ` [PATCH v8 7/7] MAINTAINERS: add maintainer entry for Intel USB dual role mux drivers Lu Baolu
  6 siblings, 1 reply; 15+ messages in thread
From: Lu Baolu @ 2016-05-05  5:33 UTC (permalink / raw)
  To: felipe.balbi, Mathias Nyman, Greg Kroah-Hartman, Lee Jones,
	Heikki Krogerus, Liam Girdwood, Mark Brown
  Cc: linux-usb, linux-kernel, Lu Baolu

Some Intel platforms have an USB port mux controlled by GPIOs.
There's a single ACPI platform device that provides 1) USB ID
extcon device; 2) USB vbus regulator device; and 3) USB port
switch device. This MFD driver will split these 3 devices for
their respective drivers.

[baolu: removed .owner per platform_no_drv_owner.cocci]
Suggested-by: David Cohen <david.a.cohen@linux.intel.com>
Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
Reviewed-by: Felipe Balbi <balbi@kernel.org>
---
 drivers/mfd/Kconfig        |  8 +++++
 drivers/mfd/Makefile       |  1 +
 drivers/mfd/intel-vuport.c | 89 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 98 insertions(+)
 create mode 100644 drivers/mfd/intel-vuport.c

diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index eea61e3..7e115ab 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -1578,5 +1578,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 5eaa6465d..65b0518 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -203,3 +203,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..fa84ed7
--- /dev/null
+++ b/drivers/mfd/intel-vuport.c
@@ -0,0 +1,89 @@
+/*
+ * 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/property.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 },
+	{ "gpio-gpios", &vbus_gpio, 1 },
+	{ "usb_mux-gpios", &mux_gpio, 1 },
+	{ },
+};
+
+static struct property_entry reg_properties[] = {
+	PROPERTY_ENTRY_STRING("supply-name", "regulator-usb-gpio"),
+	{ },
+};
+
+static const struct property_set reg_properties_pset = {
+	.properties = reg_properties,
+};
+
+static const struct mfd_cell intel_vuport_mfd_cells[] = {
+	{ .name = "extcon-usb-gpio", },
+	{
+		.name = "reg-fixed-voltage",
+		.pset = &reg_properties_pset,
+	},
+	{ .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, PLATFORM_DEVID_NONE,
+				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] 15+ messages in thread

* [PATCH v8 6/7] usb: pci-quirks: add Intel USB drcfg mux device
  2016-05-05  5:32 [PATCH v8 0/7] usb: add support for Intel dual role port mux Lu Baolu
                   ` (4 preceding siblings ...)
  2016-05-05  5:33 ` [PATCH v8 5/7] mfd: intel_vuport: Add Intel virtual USB port MFD Driver Lu Baolu
@ 2016-05-05  5:33 ` Lu Baolu
  2016-05-05  5:33 ` [PATCH v8 7/7] MAINTAINERS: add maintainer entry for Intel USB dual role mux drivers Lu Baolu
  6 siblings, 0 replies; 15+ messages in thread
From: Lu Baolu @ 2016-05-05  5:33 UTC (permalink / raw)
  To: felipe.balbi, Mathias Nyman, Greg Kroah-Hartman, Lee Jones,
	Heikki Krogerus, Liam Girdwood, Mark Brown
  Cc: linux-usb, linux-kernel, Lu Baolu

In some Intel platforms, a single usb port is shared between USB host
and device controllers. The shared port is under control of a switch
which is defined in the Intel vendor defined extended capability for
xHCI.

This patch adds the support to detect and create the platform device
for the port mux switch.

Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
Reviewed-by: Felipe Balbi <balbi@kernel.org>
---
 drivers/usb/host/pci-quirks.c    | 45 ++++++++++++++++++++++++++++++++++++++--
 drivers/usb/host/xhci-ext-caps.h |  2 ++
 2 files changed, 45 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/host/pci-quirks.c b/drivers/usb/host/pci-quirks.c
index 35af362..9bb7aa1 100644
--- a/drivers/usb/host/pci-quirks.c
+++ b/drivers/usb/host/pci-quirks.c
@@ -16,10 +16,11 @@
 #include <linux/export.h>
 #include <linux/acpi.h>
 #include <linux/dmi.h>
+#include <linux/platform_device.h>
+
 #include "pci-quirks.h"
 #include "xhci-ext-caps.h"
 
-
 #define UHCI_USBLEGSUP		0xc0		/* legacy support */
 #define UHCI_USBCMD		0		/* command register */
 #define UHCI_USBINTR		4		/* interrupt register */
@@ -78,6 +79,8 @@
 #define USB_INTEL_USB3_PSSEN   0xD8
 #define USB_INTEL_USB3PRM      0xDC
 
+#define DEVICE_ID_INTEL_BROXTON_P_XHCI		0x5aa8
+
 /*
  * amd_chipset_gen values represent AMD different chipset generations
  */
@@ -956,6 +959,41 @@ void usb_disable_xhci_ports(struct pci_dev *xhci_pdev)
 }
 EXPORT_SYMBOL_GPL(usb_disable_xhci_ports);
 
+static void create_intel_usb_mux_device(struct pci_dev *xhci_pdev,
+					void __iomem *base)
+{
+	struct platform_device *plat_dev;
+	struct property_set pset;
+	int ret;
+
+	struct property_entry pentry[] = {
+		PROPERTY_ENTRY_U64("reg-start",
+				   pci_resource_start(xhci_pdev, 0) + 0x80d8),
+		PROPERTY_ENTRY_U64("reg-size", 8),
+		{ },
+	};
+
+	if (!xhci_find_next_ext_cap(base, 0, XHCI_EXT_CAPS_INTEL_USB_MUX))
+		return;
+
+	plat_dev = platform_device_alloc("intel-mux-drcfg",
+					 PLATFORM_DEVID_NONE);
+	if (!plat_dev)
+		return;
+
+	plat_dev->dev.parent = &xhci_pdev->dev;
+	pset.properties = pentry;
+	platform_device_add_properties(plat_dev, &pset);
+
+	ret = platform_device_add(plat_dev);
+	if (ret) {
+		dev_warn(&xhci_pdev->dev,
+			 "failed to create mux device with error %d",
+				ret);
+		platform_device_put(plat_dev);
+	}
+}
+
 /**
  * PCI Quirks for xHCI.
  *
@@ -1022,8 +1060,11 @@ static void quirk_usb_handoff_xhci(struct pci_dev *pdev)
 	writel(val, base + ext_cap_offset + XHCI_LEGACY_CONTROL_OFFSET);
 
 hc_init:
-	if (pdev->vendor == PCI_VENDOR_ID_INTEL)
+	if (pdev->vendor == PCI_VENDOR_ID_INTEL) {
 		usb_enable_intel_xhci_ports(pdev);
+		if (pdev->device == DEVICE_ID_INTEL_BROXTON_P_XHCI)
+			create_intel_usb_mux_device(pdev, base);
+	}
 
 	op_reg_base = base + XHCI_HC_LENGTH(readl(base));
 
diff --git a/drivers/usb/host/xhci-ext-caps.h b/drivers/usb/host/xhci-ext-caps.h
index e0244fb..e368ccb 100644
--- a/drivers/usb/host/xhci-ext-caps.h
+++ b/drivers/usb/host/xhci-ext-caps.h
@@ -51,6 +51,8 @@
 #define XHCI_EXT_CAPS_ROUTE	5
 /* IDs 6-9 reserved */
 #define XHCI_EXT_CAPS_DEBUG	10
+/* Vendor defined 192-255 */
+#define XHCI_EXT_CAPS_INTEL_USB_MUX	192
 /* USB Legacy Support Capability - section 7.1.1 */
 #define XHCI_HC_BIOS_OWNED	(1 << 16)
 #define XHCI_HC_OS_OWNED	(1 << 24)
-- 
2.1.4

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

* [PATCH v8 7/7] MAINTAINERS: add maintainer entry for Intel USB dual role mux drivers
  2016-05-05  5:32 [PATCH v8 0/7] usb: add support for Intel dual role port mux Lu Baolu
                   ` (5 preceding siblings ...)
  2016-05-05  5:33 ` [PATCH v8 6/7] usb: pci-quirks: add Intel USB drcfg mux device Lu Baolu
@ 2016-05-05  5:33 ` Lu Baolu
  6 siblings, 0 replies; 15+ messages in thread
From: Lu Baolu @ 2016-05-05  5:33 UTC (permalink / raw)
  To: felipe.balbi, Mathias Nyman, Greg Kroah-Hartman, Lee Jones,
	Heikki Krogerus, Liam Girdwood, Mark Brown
  Cc: linux-usb, linux-kernel, Lu Baolu

Add a maintainer entry for Intel USB dual role mux drivers and
add myself as a maintainer.

Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
---
 MAINTAINERS | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 1d5b4be..6ab9e02 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -5879,6 +5879,16 @@ S:	Maintained
 F:	arch/x86/include/asm/intel_telemetry.h
 F:	drivers/platform/x86/intel_telemetry*
 
+INTEL USB DUAL ROLE PORT MUX DRIVERS
+M:	Lu Baolu <baolu.lu@linux.intel.com>
+L:	linux-usb@vger.kernel.org
+S:	Supported
+F:	include/linux/usb/portmux.h
+F:	drivers/usb/mux/portmux-core.c
+F:	drivers/usb/mux/portmux-intel-gpio.c
+F:	drivers/usb/mux/portmux-intel-drcfg.c
+F:	drivers/mfd/intel-vuport.c
+
 IOC3 ETHERNET DRIVER
 M:	Ralf Baechle <ralf@linux-mips.org>
 L:	linux-mips@linux-mips.org
-- 
2.1.4

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

* Re: [PATCH v8 5/7] mfd: intel_vuport: Add Intel virtual USB port MFD Driver
  2016-05-05  5:33 ` [PATCH v8 5/7] mfd: intel_vuport: Add Intel virtual USB port MFD Driver Lu Baolu
@ 2016-05-09 14:26   ` Lee Jones
  0 siblings, 0 replies; 15+ messages in thread
From: Lee Jones @ 2016-05-09 14:26 UTC (permalink / raw)
  To: Lu Baolu
  Cc: felipe.balbi, Mathias Nyman, Greg Kroah-Hartman, Heikki Krogerus,
	Liam Girdwood, Mark Brown, linux-usb, linux-kernel

On Thu, 05 May 2016, Lu Baolu wrote:

> Some Intel platforms have an USB port mux controlled by GPIOs.
> There's a single ACPI platform device that provides 1) USB ID
> extcon device; 2) USB vbus regulator device; and 3) USB port
> switch device. This MFD driver will split these 3 devices for
> their respective drivers.
> 
> [baolu: removed .owner per platform_no_drv_owner.cocci]
> Suggested-by: David Cohen <david.a.cohen@linux.intel.com>
> Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
> Reviewed-by: Felipe Balbi <balbi@kernel.org>
> ---
>  drivers/mfd/Kconfig        |  8 +++++
>  drivers/mfd/Makefile       |  1 +
>  drivers/mfd/intel-vuport.c | 89 ++++++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 98 insertions(+)
>  create mode 100644 drivers/mfd/intel-vuport.c

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

> diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
> index eea61e3..7e115ab 100644
> --- a/drivers/mfd/Kconfig
> +++ b/drivers/mfd/Kconfig
> @@ -1578,5 +1578,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 5eaa6465d..65b0518 100644
> --- a/drivers/mfd/Makefile
> +++ b/drivers/mfd/Makefile
> @@ -203,3 +203,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..fa84ed7
> --- /dev/null
> +++ b/drivers/mfd/intel-vuport.c
> @@ -0,0 +1,89 @@
> +/*
> + * 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/property.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 },
> +	{ "gpio-gpios", &vbus_gpio, 1 },
> +	{ "usb_mux-gpios", &mux_gpio, 1 },
> +	{ },
> +};
> +
> +static struct property_entry reg_properties[] = {
> +	PROPERTY_ENTRY_STRING("supply-name", "regulator-usb-gpio"),
> +	{ },
> +};
> +
> +static const struct property_set reg_properties_pset = {
> +	.properties = reg_properties,
> +};
> +
> +static const struct mfd_cell intel_vuport_mfd_cells[] = {
> +	{ .name = "extcon-usb-gpio", },
> +	{
> +		.name = "reg-fixed-voltage",
> +		.pset = &reg_properties_pset,
> +	},
> +	{ .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, PLATFORM_DEVID_NONE,
> +				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");

-- 
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] 15+ messages in thread

* Re: [PATCH v8 1/7] regulator: fixed: add support for ACPI interface
  2016-05-05  5:32 ` [PATCH v8 1/7] regulator: fixed: add support for ACPI interface Lu Baolu
@ 2016-05-13 11:17   ` Mark Brown
  2016-05-16  1:00     ` Lu Baolu
  0 siblings, 1 reply; 15+ messages in thread
From: Mark Brown @ 2016-05-13 11:17 UTC (permalink / raw)
  To: Lu Baolu
  Cc: felipe.balbi, Mathias Nyman, Greg Kroah-Hartman, Lee Jones,
	Heikki Krogerus, Liam Girdwood, linux-usb, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 517 bytes --]

On Thu, May 05, 2016 at 01:32:57PM +0800, Lu Baolu wrote:

> +	gpiod = gpiod_get(dev, "gpio", GPIOD_ASIS);
> +	if (IS_ERR(gpiod))
> +		return ERR_PTR(-ENODEV);

> +	config->gpio = desc_to_gpio(gpiod);
> +	config->enable_high = device_property_read_bool(dev,
> +							"enable-active-high");

> +	gpiod_put(gpiod);

This isn't going to work at all if the GPIO is shared between multiple
regulators but I can't immediately see a sensible way to fix that
without some surgery on the GPIO APIs so let's leave it for now.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

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

* Re: [PATCH v8 1/7] regulator: fixed: add support for ACPI interface
  2016-05-13 11:17   ` Mark Brown
@ 2016-05-16  1:00     ` Lu Baolu
  0 siblings, 0 replies; 15+ messages in thread
From: Lu Baolu @ 2016-05-16  1:00 UTC (permalink / raw)
  To: Mark Brown
  Cc: felipe.balbi, Mathias Nyman, Greg Kroah-Hartman, Lee Jones,
	Heikki Krogerus, Liam Girdwood, linux-usb, linux-kernel

Hi,

On 05/13/2016 07:17 PM, Mark Brown wrote:
> On Thu, May 05, 2016 at 01:32:57PM +0800, Lu Baolu wrote:
>
>> +	gpiod = gpiod_get(dev, "gpio", GPIOD_ASIS);
>> +	if (IS_ERR(gpiod))
>> +		return ERR_PTR(-ENODEV);
>> +	config->gpio = desc_to_gpio(gpiod);
>> +	config->enable_high = device_property_read_bool(dev,
>> +							"enable-active-high");
>> +	gpiod_put(gpiod);
> This isn't going to work at all if the GPIO is shared between multiple
> regulators but I can't immediately see a sensible way to fix that
> without some surgery on the GPIO APIs so let's leave it for now.

Okay. Thanks.

Best regards,
Lu Baolu

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

* Re: [PATCH v8 2/7] usb: mux: add generic code for dual role port mux
  2016-05-05  5:32 ` [PATCH v8 2/7] usb: mux: add generic code for dual role port mux Lu Baolu
@ 2016-05-25 11:06   ` Heikki Krogerus
  2016-05-26  1:03     ` Lu Baolu
  0 siblings, 1 reply; 15+ messages in thread
From: Heikki Krogerus @ 2016-05-25 11:06 UTC (permalink / raw)
  To: Lu Baolu
  Cc: felipe.balbi, Mathias Nyman, Greg Kroah-Hartman, Lee Jones,
	Liam Girdwood, Mark Brown, linux-usb, linux-kernel

Hi Baolu,

Sorry to comment this so late, but we got hardware that needs to
configure the mux in OS, and I noticed some problem. We are missing
means to bind a port to the correct mux on multiport systems. That we
need to solve later in any case, but there is an other issue related
to the fact that the notifiers now have to be extcon devices. It's
related, as extcon offers no means to solve the multiport issue, but
in any case..

> +struct portmux_dev *portmux_register(struct portmux_desc *desc)
> +{
> +	static atomic_t portmux_no = ATOMIC_INIT(-1);
> +	struct portmux_dev *pdev;
> +	struct extcon_dev *edev = NULL;
> +	struct device *dev;
> +	int ret;
> +
> +	/* parameter sanity check */
> +	if (!desc || !desc->name || !desc->ops || !desc->dev ||
> +	    !desc->ops->cable_set_cb || !desc->ops->cable_unset_cb)
> +		return ERR_PTR(-EINVAL);
> +
> +	dev = desc->dev;
> +
> +	if (desc->extcon_name) {
> +		edev = extcon_get_extcon_dev(desc->extcon_name);
> +		if (IS_ERR_OR_NULL(edev))
> +			return ERR_PTR(-EPROBE_DEFER);
> +	}
> +
> +	pdev = kzalloc(sizeof(*pdev), GFP_KERNEL);
> +	if (!pdev)
> +		return ERR_PTR(-ENOMEM);
> +
> +	pdev->desc = desc;
> +	pdev->edev = edev;
> +	pdev->nb.notifier_call = usb_mux_notifier;
> +	mutex_init(&pdev->mux_mutex);
> +
> +	pdev->dev.parent = dev;
> +	dev_set_name(&pdev->dev, "portmux.%lu",
> +		     (unsigned long)atomic_inc_return(&portmux_no));
> +	pdev->dev.groups = portmux_group;
> +	ret = device_register(&pdev->dev);
> +	if (ret)
> +		goto cleanup_mem;
> +
> +	dev_set_drvdata(&pdev->dev, pdev);
> +
> +	if (edev) {
> +		ret = extcon_register_notifier(edev, EXTCON_USB_HOST,
> +					       &pdev->nb);
> +		if (ret < 0) {
> +			dev_err(dev, "failed to register extcon notifier\n");
> +			goto cleanup_dev;
> +		}
> +	}

So I don't actually think this is correct approach. We are forcing the
notifying drivers, on top of depending on this framework, depend on
extcon too, and that simply is too much. I don't think a USB PHY or
charger detection driver should be forced to generate an extcon device
just to satisfy the mux in general.

Instead IMO, this framework should provide an API also for the
notifiers. The drivers that do the notification should not need to
depend on extcon at all. Instead they should be able to just request
an optional handle to a portmux, and use it with the function that you
already provide (usb_mux_change_state(), which of course needs to be
exported). That would make it much easier for us to make problems like
figuring out the correct mux for the correct port a problem for the
framework and not the drivers.

extcon does not really add any value here, but it does complicate
things a lot. We are even exposing new sysfs attributes to control the
mux, complete separate from extcon.


Thanks,

-- 
heikki

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

* Re: [PATCH v8 2/7] usb: mux: add generic code for dual role port mux
  2016-05-25 11:06   ` Heikki Krogerus
@ 2016-05-26  1:03     ` Lu Baolu
  2016-05-27  8:00       ` Heikki Krogerus
  0 siblings, 1 reply; 15+ messages in thread
From: Lu Baolu @ 2016-05-26  1:03 UTC (permalink / raw)
  To: Heikki Krogerus
  Cc: felipe.balbi, Mathias Nyman, Greg Kroah-Hartman, Lee Jones,
	Liam Girdwood, Mark Brown, linux-usb, linux-kernel

Hi Heikki,

On 05/25/2016 07:06 PM, Heikki Krogerus wrote:
> Hi Baolu,
>
> Sorry to comment this so late, but we got hardware that needs to
> configure the mux in OS, and I noticed some problem.

Comments are always welcome. :-)

> We are missing
> means to bind a port to the correct mux on multiport systems. That we
> need to solve later in any case, but there is an other issue related
> to the fact that the notifiers now have to be extcon devices. It's
> related, as extcon offers no means to solve the multiport issue, but
> in any case..
>
>> +struct portmux_dev *portmux_register(struct portmux_desc *desc)
>> +{
>> +	static atomic_t portmux_no = ATOMIC_INIT(-1);
>> +	struct portmux_dev *pdev;
>> +	struct extcon_dev *edev = NULL;
>> +	struct device *dev;
>> +	int ret;
>> +
>> +	/* parameter sanity check */
>> +	if (!desc || !desc->name || !desc->ops || !desc->dev ||
>> +	    !desc->ops->cable_set_cb || !desc->ops->cable_unset_cb)
>> +		return ERR_PTR(-EINVAL);
>> +
>> +	dev = desc->dev;
>> +
>> +	if (desc->extcon_name) {
>> +		edev = extcon_get_extcon_dev(desc->extcon_name);
>> +		if (IS_ERR_OR_NULL(edev))
>> +			return ERR_PTR(-EPROBE_DEFER);
>> +	}
>> +
>> +	pdev = kzalloc(sizeof(*pdev), GFP_KERNEL);
>> +	if (!pdev)
>> +		return ERR_PTR(-ENOMEM);
>> +
>> +	pdev->desc = desc;
>> +	pdev->edev = edev;
>> +	pdev->nb.notifier_call = usb_mux_notifier;
>> +	mutex_init(&pdev->mux_mutex);
>> +
>> +	pdev->dev.parent = dev;
>> +	dev_set_name(&pdev->dev, "portmux.%lu",
>> +		     (unsigned long)atomic_inc_return(&portmux_no));
>> +	pdev->dev.groups = portmux_group;
>> +	ret = device_register(&pdev->dev);
>> +	if (ret)
>> +		goto cleanup_mem;
>> +
>> +	dev_set_drvdata(&pdev->dev, pdev);
>> +
>> +	if (edev) {
>> +		ret = extcon_register_notifier(edev, EXTCON_USB_HOST,
>> +					       &pdev->nb);
>> +		if (ret < 0) {
>> +			dev_err(dev, "failed to register extcon notifier\n");
>> +			goto cleanup_dev;
>> +		}
>> +	}
> So I don't actually think this is correct approach. We are forcing the
> notifying drivers, on top of depending on this framework, depend on
> extcon too, and that simply is too much. I don't think a USB PHY or
> charger detection driver should be forced to generate an extcon device
> just to satisfy the mux in general.

Fair enough.

>
> Instead IMO, this framework should provide an API also for the
> notifiers. The drivers that do the notification should not need to
> depend on extcon at all. Instead they should be able to just request
> an optional handle to a portmux, and use it with the function that you
> already provide (usb_mux_change_state(), which of course needs to be
> exported). That would make it much easier for us to make problems like
> figuring out the correct mux for the correct port a problem for the
> framework and not the drivers.
>
> extcon does not really add any value here, but it does complicate
> things a lot. We are even exposing new sysfs attributes to control the
> mux, complete separate from extcon.

I agree with you that we should move extcon out of the framework.

In order to support multiport systems, I have below proposal.

Currently, we have below interfaces.

struct portmux_dev *portmux_register(struct portmux_desc *desc);
void portmux_unregister(struct portmux_dev *pdev);

I will add below ones.

struct portmux_dev *portmux_lookup_by_name(char *name);
int portmux_switch(struct portmux_dev *pdev, enum port_role);

The normal usage mode is
1) the mux device is registered as soon as a mux is detected with
    portmux_register();
2) In components like USB PHY or changer drivers, the mux could
    be retrieved with portmux_lookup_by_name() and controlled via
    portmux_switch().

Is this helpful?

Best regards,
Lu Baolu

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

* Re: [PATCH v8 2/7] usb: mux: add generic code for dual role port mux
  2016-05-26  1:03     ` Lu Baolu
@ 2016-05-27  8:00       ` Heikki Krogerus
  2016-05-27  8:07         ` Lu Baolu
  0 siblings, 1 reply; 15+ messages in thread
From: Heikki Krogerus @ 2016-05-27  8:00 UTC (permalink / raw)
  To: Lu Baolu
  Cc: felipe.balbi, Mathias Nyman, Greg Kroah-Hartman, Lee Jones,
	Liam Girdwood, Mark Brown, linux-usb, linux-kernel

On Thu, May 26, 2016 at 09:03:11AM +0800, Lu Baolu wrote:
> Hi Heikki,
> 
> On 05/25/2016 07:06 PM, Heikki Krogerus wrote:
> > Hi Baolu,
> >
> > Sorry to comment this so late, but we got hardware that needs to
> > configure the mux in OS, and I noticed some problem.
> 
> Comments are always welcome. :-)
> 
> > We are missing
> > means to bind a port to the correct mux on multiport systems. That we
> > need to solve later in any case, but there is an other issue related
> > to the fact that the notifiers now have to be extcon devices. It's
> > related, as extcon offers no means to solve the multiport issue, but
> > in any case..
> >
> >> +struct portmux_dev *portmux_register(struct portmux_desc *desc)
> >> +{
> >> +	static atomic_t portmux_no = ATOMIC_INIT(-1);
> >> +	struct portmux_dev *pdev;
> >> +	struct extcon_dev *edev = NULL;
> >> +	struct device *dev;
> >> +	int ret;
> >> +
> >> +	/* parameter sanity check */
> >> +	if (!desc || !desc->name || !desc->ops || !desc->dev ||
> >> +	    !desc->ops->cable_set_cb || !desc->ops->cable_unset_cb)
> >> +		return ERR_PTR(-EINVAL);
> >> +
> >> +	dev = desc->dev;
> >> +
> >> +	if (desc->extcon_name) {
> >> +		edev = extcon_get_extcon_dev(desc->extcon_name);
> >> +		if (IS_ERR_OR_NULL(edev))
> >> +			return ERR_PTR(-EPROBE_DEFER);
> >> +	}
> >> +
> >> +	pdev = kzalloc(sizeof(*pdev), GFP_KERNEL);
> >> +	if (!pdev)
> >> +		return ERR_PTR(-ENOMEM);
> >> +
> >> +	pdev->desc = desc;
> >> +	pdev->edev = edev;
> >> +	pdev->nb.notifier_call = usb_mux_notifier;
> >> +	mutex_init(&pdev->mux_mutex);
> >> +
> >> +	pdev->dev.parent = dev;
> >> +	dev_set_name(&pdev->dev, "portmux.%lu",
> >> +		     (unsigned long)atomic_inc_return(&portmux_no));
> >> +	pdev->dev.groups = portmux_group;
> >> +	ret = device_register(&pdev->dev);
> >> +	if (ret)
> >> +		goto cleanup_mem;
> >> +
> >> +	dev_set_drvdata(&pdev->dev, pdev);
> >> +
> >> +	if (edev) {
> >> +		ret = extcon_register_notifier(edev, EXTCON_USB_HOST,
> >> +					       &pdev->nb);
> >> +		if (ret < 0) {
> >> +			dev_err(dev, "failed to register extcon notifier\n");
> >> +			goto cleanup_dev;
> >> +		}
> >> +	}
> > So I don't actually think this is correct approach. We are forcing the
> > notifying drivers, on top of depending on this framework, depend on
> > extcon too, and that simply is too much. I don't think a USB PHY or
> > charger detection driver should be forced to generate an extcon device
> > just to satisfy the mux in general.
> 
> Fair enough.
> 
> >
> > Instead IMO, this framework should provide an API also for the
> > notifiers. The drivers that do the notification should not need to
> > depend on extcon at all. Instead they should be able to just request
> > an optional handle to a portmux, and use it with the function that you
> > already provide (usb_mux_change_state(), which of course needs to be
> > exported). That would make it much easier for us to make problems like
> > figuring out the correct mux for the correct port a problem for the
> > framework and not the drivers.
> >
> > extcon does not really add any value here, but it does complicate
> > things a lot. We are even exposing new sysfs attributes to control the
> > mux, complete separate from extcon.
> 
> I agree with you that we should move extcon out of the framework.
> 
> In order to support multiport systems, I have below proposal.
> 
> Currently, we have below interfaces.
> 
> struct portmux_dev *portmux_register(struct portmux_desc *desc);
> void portmux_unregister(struct portmux_dev *pdev);
> 
> I will add below ones.
> 
> struct portmux_dev *portmux_lookup_by_name(char *name);
> int portmux_switch(struct portmux_dev *pdev, enum port_role);
> 
> The normal usage mode is
> 1) the mux device is registered as soon as a mux is detected with
>     portmux_register();
> 2) In components like USB PHY or changer drivers, the mux could
>     be retrieved with portmux_lookup_by_name() and controlled via
>     portmux_switch().
> 
> Is this helpful?

It works for me, and we can improve it later if needed.


Thanks,

-- 
heikki

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

* Re: [PATCH v8 2/7] usb: mux: add generic code for dual role port mux
  2016-05-27  8:00       ` Heikki Krogerus
@ 2016-05-27  8:07         ` Lu Baolu
  0 siblings, 0 replies; 15+ messages in thread
From: Lu Baolu @ 2016-05-27  8:07 UTC (permalink / raw)
  To: Heikki Krogerus
  Cc: felipe.balbi, Mathias Nyman, Greg Kroah-Hartman, Lee Jones,
	Liam Girdwood, Mark Brown, linux-usb, linux-kernel

Hi,

On 05/27/2016 04:00 PM, Heikki Krogerus wrote:
>> I agree with you that we should move extcon out of the framework.
>> > 
>> > In order to support multiport systems, I have below proposal.
>> > 
>> > Currently, we have below interfaces.
>> > 
>> > struct portmux_dev *portmux_register(struct portmux_desc *desc);
>> > void portmux_unregister(struct portmux_dev *pdev);
>> > 
>> > I will add below ones.
>> > 
>> > struct portmux_dev *portmux_lookup_by_name(char *name);
>> > int portmux_switch(struct portmux_dev *pdev, enum port_role);
>> > 
>> > The normal usage mode is
>> > 1) the mux device is registered as soon as a mux is detected with
>> >     portmux_register();
>> > 2) In components like USB PHY or changer drivers, the mux could
>> >     be retrieved with portmux_lookup_by_name() and controlled via
>> >     portmux_switch().
>> > 
>> > Is this helpful?
> It works for me, and we can improve it later if needed.

Okay, thanks.

Best regards,
Lu Baolu

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

end of thread, other threads:[~2016-05-27  8:08 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-05  5:32 [PATCH v8 0/7] usb: add support for Intel dual role port mux Lu Baolu
2016-05-05  5:32 ` [PATCH v8 1/7] regulator: fixed: add support for ACPI interface Lu Baolu
2016-05-13 11:17   ` Mark Brown
2016-05-16  1:00     ` Lu Baolu
2016-05-05  5:32 ` [PATCH v8 2/7] usb: mux: add generic code for dual role port mux Lu Baolu
2016-05-25 11:06   ` Heikki Krogerus
2016-05-26  1:03     ` Lu Baolu
2016-05-27  8:00       ` Heikki Krogerus
2016-05-27  8:07         ` Lu Baolu
2016-05-05  5:32 ` [PATCH v8 3/7] usb: mux: add driver for Intel gpio controlled " Lu Baolu
2016-05-05  5:33 ` [PATCH v8 4/7] usb: mux: add driver for Intel drcfg " Lu Baolu
2016-05-05  5:33 ` [PATCH v8 5/7] mfd: intel_vuport: Add Intel virtual USB port MFD Driver Lu Baolu
2016-05-09 14:26   ` Lee Jones
2016-05-05  5:33 ` [PATCH v8 6/7] usb: pci-quirks: add Intel USB drcfg mux device Lu Baolu
2016-05-05  5:33 ` [PATCH v8 7/7] MAINTAINERS: add maintainer entry for Intel USB dual role mux drivers Lu Baolu

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.