linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/7] Add USB remote wakeup driver
@ 2017-12-09  8:45 Chunfeng Yun
  2017-12-09  8:45 ` [PATCH 1/7] soc: mediatek: Add USB " Chunfeng Yun
                   ` (7 more replies)
  0 siblings, 8 replies; 12+ messages in thread
From: Chunfeng Yun @ 2017-12-09  8:45 UTC (permalink / raw)
  To: Rob Herring, Felipe Balbi, Matthias Brugger, Mathias Nyman
  Cc: Mark Rutland, Greg Kroah-Hartman, Catalin Marinas, Will Deacon,
	Chunfeng Yun, Jean Delvare, Sean Wang, devicetree, linux-kernel,
	linux-usb, linux-arm-kernel, linux-mediatek

    These patches introduce the SSUSB and SPM glue layer driver which is
used to support usb remote wakeup. Usually the glue layer is put into
a system controller, such as PERICFG module.
    The old way to support usb wakeup is put into SSUSB controller drivers,
including xhci-mtk driver and mtu3 driver, but there are some problems:
    1. can't disdinguish the relation between glue layer and SSUSB IP
       when SoCs supports multi SSUSB IPs;
    2. duplicated code for wakeup are put into both xhci-mtk and mtu3
       drivers;
    3. the glue layer may vary on different SoCs with SSUSB IP, and will
       make SSUSB controller drivers complicated;
    In order to resolve these problems, it's useful to make the glue layer
transparent by extracting a seperated driver, meanwhile to reduce the
duplicated code and simplify SSUSB controller drivers.

Changes from v1:
 * Introduce USB remote wakeup driver
 * Use the new way to support remote wakeup for SSUSB controller drivers
 * Add binding document for USB remote wakeup driver
 * Update binding documents of SSUSB controller drivers
 * Update DTS of MT8173 platform

Chunfeng Yun (7):
  soc: mediatek: Add USB wakeup driver
  dt-bindings: soc: mediatek: add bindings document for USB wakeup
  usb: xhci-mtk: use APIs of mtu_wakeup to support remote wakeup
  usb: mtu3: use APIs of mtu_wakeup to support remote wakeup
  dt-bindings: usb: mtk-xhci: add USB wakeup properties
  dt-bindings: usb: mtu3: add USB wakeup properties
  arm64: dts: mt8173: add uwk node and remove unused usb property

 .../bindings/soc/mediatek/usb-wakeup.txt           |  77 +++
 .../devicetree/bindings/usb/mediatek,mtk-xhci.txt  |  15 +-
 .../devicetree/bindings/usb/mediatek,mtu3.txt      |  14 +-
 arch/arm64/boot/dts/mediatek/mt8173-evb.dts        |  28 +-
 arch/arm64/boot/dts/mediatek/mt8173.dtsi           |  16 +-
 drivers/soc/mediatek/Kconfig                       |   8 +
 drivers/soc/mediatek/Makefile                      |   1 +
 drivers/soc/mediatek/mtk-usb-wakeup.c              | 519 +++++++++++++++++++++
 drivers/usb/host/xhci-mtk.c                        |  39 +-
 drivers/usb/host/xhci-mtk.h                        |   2 +
 drivers/usb/mtu3/mtu3.h                            |   2 +
 drivers/usb/mtu3/mtu3_host.c                       |  39 +-
 include/dt-bindings/soc/mediatek,usb-wakeup.h      |  15 +
 include/linux/soc/mediatek/usb-wakeup.h            |  88 ++++
 14 files changed, 803 insertions(+), 60 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/soc/mediatek/usb-wakeup.txt
 create mode 100644 drivers/soc/mediatek/mtk-usb-wakeup.c
 create mode 100644 include/dt-bindings/soc/mediatek,usb-wakeup.h
 create mode 100644 include/linux/soc/mediatek/usb-wakeup.h

-- 
1.9.1

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

* [PATCH 1/7] soc: mediatek: Add USB wakeup driver
  2017-12-09  8:45 [PATCH 0/7] Add USB remote wakeup driver Chunfeng Yun
@ 2017-12-09  8:45 ` Chunfeng Yun
  2017-12-15 20:55   ` Rob Herring
  2017-12-09  8:45 ` [PATCH 2/7] dt-bindings: soc: mediatek: add bindings document for USB wakeup Chunfeng Yun
                   ` (6 subsequent siblings)
  7 siblings, 1 reply; 12+ messages in thread
From: Chunfeng Yun @ 2017-12-09  8:45 UTC (permalink / raw)
  To: Rob Herring, Felipe Balbi, Matthias Brugger, Mathias Nyman
  Cc: Mark Rutland, Greg Kroah-Hartman, Catalin Marinas, Will Deacon,
	Chunfeng Yun, Jean Delvare, Sean Wang, devicetree, linux-kernel,
	linux-usb, linux-arm-kernel, linux-mediatek

This driver is used to support usb wakeup which is controlled by
the glue layer between SSUSB and SPM. Usually the glue layer is put
into a system controller, such as pericfg module, which is
represented by a syscon node in DTS.
Due to the glue layer may vary on different SoCs, it's useful to
extract a separated driver to simplify usb controller drivers.

Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com>
---
 drivers/soc/mediatek/Kconfig                  |   8 +
 drivers/soc/mediatek/Makefile                 |   1 +
 drivers/soc/mediatek/mtk-usb-wakeup.c         | 519 ++++++++++++++++++++++++++
 include/dt-bindings/soc/mediatek,usb-wakeup.h |  15 +
 include/linux/soc/mediatek/usb-wakeup.h       |  88 +++++
 5 files changed, 631 insertions(+)
 create mode 100644 drivers/soc/mediatek/mtk-usb-wakeup.c
 create mode 100644 include/dt-bindings/soc/mediatek,usb-wakeup.h
 create mode 100644 include/linux/soc/mediatek/usb-wakeup.h

diff --git a/drivers/soc/mediatek/Kconfig b/drivers/soc/mediatek/Kconfig
index a7d0667..30cd226 100644
--- a/drivers/soc/mediatek/Kconfig
+++ b/drivers/soc/mediatek/Kconfig
@@ -31,4 +31,12 @@ config MTK_SCPSYS
 	  Say yes here to add support for the MediaTek SCPSYS power domain
 	  driver.
 
+config MTK_UWK
+	bool "MediaTek USB Wakeup Support"
+	select REGMAP
+	help
+	  Say yes here to add support for the MediaTek SSUSB-SPM glue layer
+	  which supports some different type of USB wakeup, such as IP-SLEEP,
+	  LINESTATE, IDDIG etc, and it can support multi SSUSB controllers.
+
 endmenu
diff --git a/drivers/soc/mediatek/Makefile b/drivers/soc/mediatek/Makefile
index 12998b0..66fbb54f 100644
--- a/drivers/soc/mediatek/Makefile
+++ b/drivers/soc/mediatek/Makefile
@@ -1,3 +1,4 @@
 obj-$(CONFIG_MTK_INFRACFG) += mtk-infracfg.o
 obj-$(CONFIG_MTK_PMIC_WRAP) += mtk-pmic-wrap.o
 obj-$(CONFIG_MTK_SCPSYS) += mtk-scpsys.o
+obj-$(CONFIG_MTK_UWK) += mtk-usb-wakeup.o
diff --git a/drivers/soc/mediatek/mtk-usb-wakeup.c b/drivers/soc/mediatek/mtk-usb-wakeup.c
new file mode 100644
index 0000000..16539a6
--- /dev/null
+++ b/drivers/soc/mediatek/mtk-usb-wakeup.c
@@ -0,0 +1,519 @@
+/*
+ * Copyright (c) 2017 MediaTek Inc.
+ * Author: Chunfeng Yun <chunfeng.yun@mediatek.com>
+ *
+ * SPDX-License-Identifier: GPL-2.0
+ *
+ */
+
+#include <dt-bindings/soc/mediatek,usb-wakeup.h>
+#include <linux/kernel.h>
+#include <linux/mfd/syscon.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/of_platform.h>
+#include <linux/regmap.h>
+#include <linux/slab.h>
+#include <linux/soc/mediatek/usb-wakeup.h>
+
+/* mt8173, mt8176 etc */
+#define PERI_WK_CTRL1	0x4
+#define WC1_IS_C(x)	(((x) & 0xf) << 26) /* cycle debounce */
+#define WC1_IS_EN	BIT(25)
+#define WC1_IS_P	BIT(6)  /* polarity for ip sleep */
+
+/* mt2712 etc */
+#define PERI_SSUSB_SPM_CTRL	0x0
+#define SSC_LINE_STATE_CHG	GENMASK(11, 8)
+#define SSC_LINE_STATE_EN	GENMASK(6, 5)
+#define SSC_IP_SLEEP_EN	BIT(4)
+#define SSC_SPM_INT_EN		BIT(1)
+
+enum mtk_uwk_vers {
+	MTK_UWK_V1 = 1,
+	MTK_UWK_V2,
+};
+
+struct mtk_uwk_pdata {
+	enum mtk_uwk_vers vers;
+};
+
+/**
+ * @reg_base: register offset within a syscon @wkc (e.g. pericfg module)
+ * @type: the types of wakeup, such as IP-SLEEP, LINE-STATE etc
+ */
+struct mtk_uwk_instance {
+	struct mtu_wakeup uwk;
+	u32 reg_base;
+	u32 reg_len;
+	u32 type;
+};
+
+struct mtk_uwk {
+	struct device *dev;
+	struct regmap *wkc;
+	const struct mtk_uwk_pdata *data;
+	struct mtk_uwk_instance **inst;
+	int num_inst;
+};
+
+static LIST_HEAD(of_uwk_providers);
+static DEFINE_MUTEX(of_uwk_mutex);
+
+static struct mtu_wakeup_provider *of_uwk_provider_add(struct device *dev,
+		struct mtu_wakeup *(*of_xlate)(struct device *dev,
+		struct of_phandle_args *args))
+{
+	struct mtu_wakeup_provider *provider;
+
+	provider = kzalloc(sizeof(*provider), GFP_KERNEL);
+	if (!provider)
+		return ERR_PTR(-ENOMEM);
+
+	provider->dev = dev;
+	provider->of_node = of_node_get(dev->of_node);
+	provider->of_xlate = of_xlate;
+
+	mutex_lock(&of_uwk_mutex);
+	list_add_tail(&provider->list, &of_uwk_providers);
+	mutex_unlock(&of_uwk_mutex);
+
+	return provider;
+}
+
+static void of_uwk_provider_del(struct device_node *np)
+{
+	struct mtu_wakeup_provider *provider;
+
+	mutex_lock(&of_uwk_mutex);
+	list_for_each_entry(provider, &of_uwk_providers, list) {
+		if (provider->of_node == np) {
+			list_del(&provider->list);
+			of_node_put(provider->of_node);
+			kfree(provider);
+			break;
+		}
+	}
+	mutex_unlock(&of_uwk_mutex);
+}
+
+static struct mtu_wakeup *of_uwk_get_from_provider(
+		struct of_phandle_args *args)
+{
+	struct mtu_wakeup_provider *provider;
+	struct device_node *child_np;
+	struct mtu_wakeup *uwk;
+
+	mutex_lock(&of_uwk_mutex);
+	list_for_each_entry(provider, &of_uwk_providers, list) {
+		for_each_child_of_node(provider->of_node, child_np) {
+			if (child_np == args->np) {
+				uwk = provider->of_xlate(provider->dev, args);
+				mutex_unlock(&of_uwk_mutex);
+				return uwk;
+			}
+		}
+	}
+	mutex_unlock(&of_uwk_mutex);
+
+	return ERR_PTR(-EPROBE_DEFER);
+}
+
+static struct mtu_wakeup *of_uwk_get(struct device_node *np, int index)
+{
+	struct mtu_wakeup *uwk = NULL;
+	struct of_phandle_args args;
+	int ret;
+
+	ret = of_parse_phandle_with_args(np, "mediatek,uwks",
+				"#mediatek,uwk-cells", index, &args);
+	if (ret)
+		return ERR_PTR(-ENODEV);
+
+	if (!of_device_is_available(args.np)) {
+		dev_warn(uwk->parent, "Requested uwk is disabled\n");
+		uwk = ERR_PTR(-ENODEV);
+		goto put_node;
+	}
+
+	uwk = of_uwk_get_from_provider(&args);
+
+put_node:
+	of_node_put(args.np);
+	return uwk;
+}
+
+static void devm_uwk_release(struct device *dev, void *res)
+{
+	struct mtu_wakeup *uwk = *(struct mtu_wakeup **)res;
+
+	if (IS_ERR_OR_NULL(uwk))
+		return;
+
+	module_put(uwk->ops->owner);
+	put_device(uwk->parent);
+}
+
+struct mtu_wakeup *devm_of_uwk_get_by_index(
+		struct device *dev, struct device_node *np, int index)
+{
+	struct mtu_wakeup **ptr, *uwk;
+
+	ptr = devres_alloc(devm_uwk_release, sizeof(*ptr), GFP_KERNEL);
+	if (!ptr)
+		return ERR_PTR(-ENOMEM);
+
+	uwk = of_uwk_get(np, index);
+	if (IS_ERR(uwk)) {
+		devres_free(ptr);
+		return uwk;
+	}
+
+	if (!try_module_get(uwk->ops->owner)) {
+		devres_free(ptr);
+		return ERR_PTR(-EPROBE_DEFER);
+	}
+
+	get_device(uwk->parent);
+
+	*ptr = uwk;
+	devres_add(dev, ptr);
+
+	return uwk;
+}
+EXPORT_SYMBOL_GPL(devm_of_uwk_get_by_index);
+
+int mtu_wakeup_enable(struct mtu_wakeup *uwk)
+{
+	int ret = 0;
+
+	if (!uwk)
+		return 0;
+
+	mutex_lock(&uwk->mutex);
+	if (uwk->count == 0 && uwk->ops->enable) {
+		ret = uwk->ops->enable(uwk);
+		if (ret) {
+			dev_err(uwk->parent, "uwk enable failed(%d)\n", ret);
+			goto out;
+		}
+	}
+	++uwk->count;
+
+out:
+	mutex_unlock(&uwk->mutex);
+	return ret;
+}
+EXPORT_SYMBOL_GPL(mtu_wakeup_enable);
+
+int mtu_wakeup_disable(struct mtu_wakeup *uwk)
+{
+	int ret = 0;
+
+	if (!uwk)
+		return 0;
+
+	mutex_lock(&uwk->mutex);
+	if (uwk->count == 1 && uwk->ops->disable) {
+		ret =  uwk->ops->disable(uwk);
+		if (ret) {
+			dev_err(uwk->parent, "uwk disable failed(%d)\n", ret);
+			goto out;
+		}
+	}
+	--uwk->count;
+
+out:
+	mutex_unlock(&uwk->mutex);
+	return ret;
+}
+EXPORT_SYMBOL_GPL(mtu_wakeup_disable);
+
+static struct mtk_uwk_instance *to_mwk_inst(struct mtu_wakeup *uwk)
+{
+	return uwk ? container_of(uwk, struct mtk_uwk_instance, uwk) : NULL;
+}
+
+static int mwk_v1_enable(struct mtk_uwk *mwk, struct mtk_uwk_instance *inst)
+{
+	struct regmap *wkc = mwk->wkc;
+	u32 val;
+
+	/* Only IP-SLEEP is supported */
+	if (inst->type != MTU_WK_IP_SLEEP)
+		return 0;
+
+	regmap_read(wkc, PERI_WK_CTRL1, &val);
+	val &= ~(WC1_IS_P | WC1_IS_C(0xf));
+	val |= WC1_IS_EN | WC1_IS_C(0x8);
+	regmap_write(wkc, PERI_WK_CTRL1, val);
+	regmap_read(wkc, PERI_WK_CTRL1, &val);
+	dev_dbg(mwk->dev, "%s: WK_CTRL1=%#x, type=%d\n",
+		__func__, val, inst->type);
+
+	return 0;
+}
+
+static int mwk_v1_disable(struct mtk_uwk *mwk, struct mtk_uwk_instance *inst)
+{
+	if (inst->type == MTU_WK_IP_SLEEP)
+		regmap_update_bits(mwk->wkc, PERI_WK_CTRL1, WC1_IS_EN, 0);
+
+	return 0;
+}
+
+static int mwk_v2_enable(struct mtk_uwk *mwk, struct mtk_uwk_instance *inst)
+{
+	struct regmap *wkc = mwk->wkc;
+	u32 rbase = inst->reg_base;
+	u32 val;
+
+	regmap_read(wkc, rbase + PERI_SSUSB_SPM_CTRL, &val);
+	switch (inst->type) {
+	case MTU_WK_IP_SLEEP:
+		val |= SSC_IP_SLEEP_EN;
+		break;
+	case MTU_WK_LINE_STATE:
+		val |= SSC_LINE_STATE_EN | SSC_LINE_STATE_CHG;
+		break;
+	default:
+		/* checked by xlate, ignore the error */
+		break;
+	}
+	val |= SSC_SPM_INT_EN;
+	regmap_write(wkc, rbase + PERI_SSUSB_SPM_CTRL, val);
+	regmap_read(wkc, rbase + PERI_SSUSB_SPM_CTRL, &val);
+	dev_dbg(mwk->dev, "%s: CTRL=%#x, type=%d\n",
+		__func__, val, inst->type);
+
+	return 0;
+}
+
+static int mwk_v2_disable(struct mtk_uwk *mwk, struct mtk_uwk_instance *inst)
+{
+	struct regmap *wkc = mwk->wkc;
+	u32 rbase = inst->reg_base;
+	u32 val;
+
+	regmap_read(wkc, rbase + PERI_SSUSB_SPM_CTRL, &val);
+	switch (inst->type) {
+	case MTU_WK_IP_SLEEP:
+		val &= ~SSC_IP_SLEEP_EN;
+		break;
+	case MTU_WK_LINE_STATE:
+		val &= ~(SSC_LINE_STATE_EN | SSC_LINE_STATE_CHG);
+		break;
+	default:
+		break;
+	}
+	val &= ~SSC_SPM_INT_EN;
+	regmap_write(wkc, rbase + PERI_SSUSB_SPM_CTRL, val);
+	dev_dbg(mwk->dev, "%s: type=%d\n", __func__, inst->type);
+
+	return 0;
+}
+
+static int mwk_enable(struct mtu_wakeup *uwk)
+{
+	struct mtk_uwk_instance *inst = to_mwk_inst(uwk);
+	struct mtk_uwk *mwk = dev_get_drvdata(uwk->parent);
+	int ret = 0;
+
+	switch (mwk->data->vers) {
+	case MTK_UWK_V1:
+		ret = mwk_v1_enable(mwk, inst);
+		break;
+	case MTK_UWK_V2:
+		ret = mwk_v2_enable(mwk, inst);
+		break;
+	default:
+		break;
+	}
+	return ret;
+}
+
+static int mwk_disable(struct mtu_wakeup *uwk)
+{
+	struct mtk_uwk_instance *inst = to_mwk_inst(uwk);
+	struct mtk_uwk *mwk = dev_get_drvdata(uwk->parent);
+	int ret = 0;
+
+	switch (mwk->data->vers) {
+	case MTK_UWK_V1:
+		ret = mwk_v1_disable(mwk, inst);
+		break;
+	case MTK_UWK_V2:
+		ret = mwk_v2_disable(mwk, inst);
+		break;
+	default:
+		break;
+	}
+	return ret;
+}
+
+static struct mtk_uwk_instance *mwk_inst_create(struct device *dev,
+		struct device_node *np,
+		const struct mtu_wakeup_ops *ops)
+{
+	struct mtk_uwk_instance *inst;
+	struct mtu_wakeup *uwk;
+	u32 buf[2];
+	int ret;
+
+	inst = devm_kzalloc(dev, sizeof(*inst), GFP_KERNEL);
+	if (!inst)
+		return ERR_PTR(-ENOMEM);
+
+	ret = of_property_read_u32_array(np, "reg", buf, ARRAY_SIZE(buf));
+	if (ret) {
+		dev_err(dev, "fail to read reg\n");
+		return ERR_PTR(ret);
+	}
+
+	inst->reg_base = buf[0];
+	inst->reg_len = buf[1];
+	uwk = &inst->uwk;
+	uwk->node = np;
+	uwk->ops = ops;
+	uwk->parent = dev;
+	mutex_init(&uwk->mutex);
+	dev_dbg(dev, "reg: %#x/%#x\n", inst->reg_base, inst->reg_len);
+
+	return inst;
+}
+
+static struct mtu_wakeup *mwk_xlate(struct device *dev,
+		struct of_phandle_args *args)
+{
+	struct mtk_uwk *mwk = dev_get_drvdata(dev);
+	struct mtk_uwk_instance *inst = NULL;
+	struct device_node *uwk_np = args->np;
+	int index;
+
+	if (args->args_count != 1) {
+		dev_err(dev, "invalid number of cells in uwk property\n");
+		return ERR_PTR(-EINVAL);
+	}
+
+	for (index = 0; index < mwk->num_inst; index++)
+		if (uwk_np == mwk->inst[index]->uwk.node) {
+			inst = mwk->inst[index];
+			break;
+		}
+
+	if (!inst) {
+		dev_err(dev, "failed to find appropriate uwk\n");
+		return ERR_PTR(-EINVAL);
+	}
+
+	inst->type = args->args[0];
+	if (!(inst->type == MTU_WK_IP_SLEEP ||
+	      inst->type == MTU_WK_LINE_STATE)) {
+		dev_err(dev, "unsupported uwk type=%d\n", inst->type);
+		return ERR_PTR(-EINVAL);
+	}
+
+	return &inst->uwk;
+}
+
+static const struct mtu_wakeup_ops mwk_ops = {
+	.enable = mwk_enable,
+	.disable = mwk_disable,
+	.owner = THIS_MODULE,
+};
+
+static const struct mtk_uwk_pdata mwk_v1_pdata = {
+	.vers = MTK_UWK_V1,
+};
+
+static const struct mtk_uwk_pdata mwk_v2_pdata = {
+	.vers = MTK_UWK_V2,
+};
+
+static const struct of_device_id mwk_id_table[] = {
+	{ .compatible = "mediatek,usb-wk-v1", .data = &mwk_v1_pdata },
+	{ .compatible = "mediatek,usb-wk-v2", .data = &mwk_v2_pdata },
+	{ },
+};
+MODULE_DEVICE_TABLE(of, mwk_id_table);
+
+static int mtk_uwk_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct device_node *np = dev->of_node;
+	struct device_node *child_np;
+	struct mtu_wakeup_provider *provider;
+	struct mtk_uwk *mwk;
+	int index;
+	int ret;
+
+	mwk = devm_kzalloc(dev, sizeof(*mwk), GFP_KERNEL);
+	if (!mwk)
+		return -ENOMEM;
+
+	mwk->data = of_device_get_match_data(dev);
+	if (!mwk->data)
+		return -EINVAL;
+
+	mwk->num_inst = of_get_child_count(np);
+	mwk->inst = devm_kcalloc(dev, mwk->num_inst,
+				  sizeof(*mwk->inst), GFP_KERNEL);
+	if (!mwk->inst)
+		return -ENOMEM;
+
+	mwk->dev = dev;
+	platform_set_drvdata(pdev, mwk);
+
+	mwk->wkc = syscon_regmap_lookup_by_phandle(np, "mediatek,wkc");
+	if (IS_ERR(mwk->wkc)) {
+		dev_err(dev, "fail to get mediatek,wkc syscon\n");
+		return PTR_ERR(mwk->wkc);
+	}
+
+	index = 0;
+	for_each_child_of_node(np, child_np) {
+		struct mtk_uwk_instance *inst;
+
+		inst = mwk_inst_create(dev, child_np, &mwk_ops);
+		if (IS_ERR(inst)) {
+			dev_err(dev, "failed to create mwk instance\n");
+			ret = PTR_ERR(inst);
+			goto put_child;
+		}
+
+		mwk->inst[index] = inst;
+		index++;
+	}
+
+	provider = of_uwk_provider_add(dev, mwk_xlate);
+
+	return PTR_ERR_OR_ZERO(provider);
+
+put_child:
+	of_node_put(child_np);
+	return ret;
+}
+
+static int mtk_uwk_remove(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct device_node *np = dev->of_node;
+
+	of_uwk_provider_del(np);
+	return 0;
+}
+
+static struct platform_driver mtk_uwk_drv = {
+	.probe = mtk_uwk_probe,
+	.remove = mtk_uwk_remove,
+	.driver = {
+		.name = "mtk_uwk",
+		.owner = THIS_MODULE,
+		.of_match_table = mwk_id_table,
+	},
+};
+
+module_platform_driver(mtk_uwk_drv);
+MODULE_AUTHOR("Chunfeng Yun <chunfeng.yun@mediatek.com>");
+MODULE_DESCRIPTION("MediaTek USB Wakeup driver");
+MODULE_LICENSE("GPL v2");
diff --git a/include/dt-bindings/soc/mediatek,usb-wakeup.h b/include/dt-bindings/soc/mediatek,usb-wakeup.h
new file mode 100644
index 0000000..2461795
--- /dev/null
+++ b/include/dt-bindings/soc/mediatek,usb-wakeup.h
@@ -0,0 +1,15 @@
+/*
+ * Copyright (c) 2017 MediaTek Inc.
+ * Author: Chunfeng Yun <chunfeng.yun@mediatek.com>
+ *
+ * SPDX-License-Identifier: GPL-2.0
+ *
+ */
+
+#ifndef __DT_BINDINGS_MTK_USB_WK_H__
+#define __DT_BINDINGS_MTK_USB_WK_H__
+
+#define MTU_WK_IP_SLEEP	1
+#define MTU_WK_LINE_STATE	2
+
+#endif
diff --git a/include/linux/soc/mediatek/usb-wakeup.h b/include/linux/soc/mediatek/usb-wakeup.h
new file mode 100644
index 0000000..5697367
--- /dev/null
+++ b/include/linux/soc/mediatek/usb-wakeup.h
@@ -0,0 +1,88 @@
+/*
+ * Copyright (c) 2017 MediaTek Inc.
+ * Author: Chunfeng Yun <chunfeng.yun@mediatek.com>
+ *
+ * SPDX-License-Identifier: GPL-2.0
+ *
+ */
+
+#ifndef __MTK_USB_WAKEUP_H__
+#define __MTK_USB_WAKEUP_H__
+
+#include <linux/device.h>
+#include <linux/err.h>
+#include <linux/mutex.h>
+#include <linux/of.h>
+
+struct mtu_wakeup;
+
+/**
+ * struct mtu_wakeup_ops - set of function pointers for performing
+ *    mtu_wakeup operations
+ * @enable: enable a type of usb wakeup when system suspend
+ * @disable: disable a type of usb wakeup when system resume
+ * @owner: the module owner using the ops
+ */
+struct mtu_wakeup_ops {
+	int	(*enable)(struct mtu_wakeup *uwk);
+	int	(*disable)(struct mtu_wakeup *uwk);
+	struct module *owner;
+};
+
+/**
+ * struct mtu_wakeup - represents the MediaTek USB wakeup device
+ * @parent: the parent device of the mtu_wakeup
+ * @node: associated device tree node
+ * @ops: function pointers for performing mtu_wakeup operations
+ * @mutex: mutex to protect @ops
+ * @count: used to protect when the mtu_wakeup is used by multiple consumers
+ */
+struct mtu_wakeup {
+	struct device *parent;
+	struct device_node *node;
+	const struct mtu_wakeup_ops *ops;
+	struct mutex mutex;
+	int count;
+};
+
+/**
+ * struct mtu_wakeup_provider - represents the mtu_wakeup provider
+ * @dev: the parent device of the mtu_wakeup
+ * @list: to maintain a linked list of mtu_wakeup providers
+ * @of_node: associated device tree node
+ * @of_xlate: function pointer to obtain mtu_wakeup instance from
+ *	its tree node
+ */
+struct mtu_wakeup_provider {
+	struct device *dev;
+	struct list_head list;
+	struct device_node *of_node;
+	struct mtu_wakeup *(*of_xlate)(struct device *dev,
+		struct of_phandle_args *args);
+};
+
+#if IS_ENABLED(CONFIG_MTK_UWK)
+struct mtu_wakeup *devm_of_uwk_get_by_index(
+	struct device *dev, struct device_node *np, int index);
+int mtu_wakeup_enable(struct mtu_wakeup *uwk);
+int mtu_wakeup_disable(struct mtu_wakeup *uwk);
+
+#else
+struct mtu_wakeup *devm_of_uwk_get_by_index(
+	struct device *dev, struct device_node *np, int index)
+{
+	return ERR_PTR(-ENODEV);
+}
+
+int mtu_wakeup_enable(struct mtu_wakeup *uwk)
+{
+	return uwk ? -ENODEV : 0;
+}
+
+int mtu_wakeup_disable(struct mtu_wakeup *uwk)
+{
+	return uwk ? -ENODEV : 0;
+}
+#endif
+
+#endif	/* __MTK_USB_WAKEUP_H__ */
-- 
1.9.1

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

* [PATCH 2/7] dt-bindings: soc: mediatek: add bindings document for USB wakeup
  2017-12-09  8:45 [PATCH 0/7] Add USB remote wakeup driver Chunfeng Yun
  2017-12-09  8:45 ` [PATCH 1/7] soc: mediatek: Add USB " Chunfeng Yun
@ 2017-12-09  8:45 ` Chunfeng Yun
  2017-12-09  8:45 ` [PATCH 3/7] usb: xhci-mtk: use APIs of mtu_wakeup to support remote wakeup Chunfeng Yun
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 12+ messages in thread
From: Chunfeng Yun @ 2017-12-09  8:45 UTC (permalink / raw)
  To: Rob Herring, Felipe Balbi, Matthias Brugger, Mathias Nyman
  Cc: Mark Rutland, Greg Kroah-Hartman, Catalin Marinas, Will Deacon,
	Chunfeng Yun, Jean Delvare, Sean Wang, devicetree, linux-kernel,
	linux-usb, linux-arm-kernel, linux-mediatek

This adds bindings document for the SSUSB-SPM glue layer driver found
in MediaTek SoCs which is used to support usb remote wakeup.

Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com>
---
 .../bindings/soc/mediatek/usb-wakeup.txt           | 77 ++++++++++++++++++++++
 1 file changed, 77 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/soc/mediatek/usb-wakeup.txt

diff --git a/Documentation/devicetree/bindings/soc/mediatek/usb-wakeup.txt b/Documentation/devicetree/bindings/soc/mediatek/usb-wakeup.txt
new file mode 100644
index 0000000..313d927
--- /dev/null
+++ b/Documentation/devicetree/bindings/soc/mediatek/usb-wakeup.txt
@@ -0,0 +1,77 @@
+MediaTek USB Wakeup binding
+-----------------------------
+
+The SSUSB-SPM glue layer is used to control some signals of USB
+wakeup, such as IP-SLEEP, LINE-STATE, IDDIG etc, which are mutually
+exclusive.
+
+Required properties (controller (parent) node):
+- compatible: Should be one of:
+	- "mediatek,<soc-model>-uwk","mediatek,usb-wk-v1"
+		soc-model is the name of SoC, supports one of:
+		- mt8173, mt8176
+	- "mediatek,<soc-model>-uwk","mediatek,usb-wk-v2"
+		soc-model is the name of SoC, supports one of:
+		- mt2712
+
+- mediatek,wkc: must contain a syscon phandle, such as pericfg controller
+- #address-cells : should be '1'
+- #size-cells : should be '1'
+
+Required nodes: a sub-node is required for each glue layer provided for
+	each SSUSB IP. Address range information including the usual 'reg'
+	property is used inside these nodes to describe the controller's
+	topology.
+
+Required properties (glue layer (child) node):
+- reg: address and length of the register set within the syscon which is
+	assigned to @mediatek,wkc.
+- #mediatek,uwk-cells: should be 1 (see the second example), cell after
+	glue layer phandle is wakeup type from:
+		- MTU_WK_IP_SLEEP
+		- MTU_WK_LINE_STATE
+	The wakeup types defined in
+		- include/dt-bindings/soc/mediatek,usb-wakeup.h
+
+
+Example:
+
+usb_wakeup: uwk@0 {
+	compatible = "mediatek,mt2712-uwk","mediatek,usb-wk-v2";
+	mediatek,wkc = <&pericfg>;
+	#address-cells = <1>;
+	#size-cells = <1>;
+	status = "okay";
+
+	usb_wk0: uwk@510 {
+		reg = <0x510 0x4>;
+		#mediatek,uwk-cells = <1>;
+		status = "okay";
+	};
+
+	usb_wk1: uwk@514 {
+		reg = <0x514 0x4>;
+		#mediatek,uwk-cells = <1>;
+		status = "okay";
+	};
+};
+
+
+Specifying wakeup control of devices
+---------------------------------
+
+Device nodes should specify the configuration required in their
+"mediatek,uwks" property, containing a phandle to the glue layer
+node and a wakeup type, because each USB controller has just one
+glue layer for wakeup, so only one phandle is supported;
+
+Example:
+
+#include <dt-bindings/soc/mediatek,usb-wakeup.h>
+
+usb_host1: xhci@112c0000 {
+	...
+	mediatek,uwks = <&usb_wk2 MTU_WK_IP_SLEEP>;
+	...
+};
+
-- 
1.9.1

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

* [PATCH 3/7] usb: xhci-mtk: use APIs of mtu_wakeup to support remote wakeup
  2017-12-09  8:45 [PATCH 0/7] Add USB remote wakeup driver Chunfeng Yun
  2017-12-09  8:45 ` [PATCH 1/7] soc: mediatek: Add USB " Chunfeng Yun
  2017-12-09  8:45 ` [PATCH 2/7] dt-bindings: soc: mediatek: add bindings document for USB wakeup Chunfeng Yun
@ 2017-12-09  8:45 ` Chunfeng Yun
  2017-12-09  8:45 ` [PATCH 4/7] usb: mtu3: " Chunfeng Yun
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 12+ messages in thread
From: Chunfeng Yun @ 2017-12-09  8:45 UTC (permalink / raw)
  To: Rob Herring, Felipe Balbi, Matthias Brugger, Mathias Nyman
  Cc: Mark Rutland, Greg Kroah-Hartman, Catalin Marinas, Will Deacon,
	Chunfeng Yun, Jean Delvare, Sean Wang, devicetree, linux-kernel,
	linux-usb, linux-arm-kernel, linux-mediatek

On some platforms, there are two xHCI IPs, but the old way of
usb wakeup doesn't support it, so use the new APIs of mtu_wakeup
to support it.

Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com>
---
 drivers/usb/host/xhci-mtk.c | 39 +++++++++++++++++++++++----------------
 drivers/usb/host/xhci-mtk.h |  2 ++
 2 files changed, 25 insertions(+), 16 deletions(-)

diff --git a/drivers/usb/host/xhci-mtk.c b/drivers/usb/host/xhci-mtk.c
index b62a1d2..3176a10 100644
--- a/drivers/usb/host/xhci-mtk.c
+++ b/drivers/usb/host/xhci-mtk.c
@@ -19,6 +19,7 @@
 #include <linux/pm_runtime.h>
 #include <linux/regmap.h>
 #include <linux/regulator/consumer.h>
+#include <linux/soc/mediatek/usb-wakeup.h>
 
 #include "xhci.h"
 #include "xhci-mtk.h"
@@ -366,7 +367,9 @@ static void usb_wakeup_line_state_dis(struct xhci_hcd_mtk *mtk)
 
 static void usb_wakeup_enable(struct xhci_hcd_mtk *mtk)
 {
-	if (mtk->wakeup_src == SSUSB_WK_IP_SLEEP)
+	if (mtk->wakeup)
+		mtu_wakeup_enable(mtk->uwk);
+	else if (mtk->wakeup_src == SSUSB_WK_IP_SLEEP)
 		usb_wakeup_ip_sleep_en(mtk);
 	else if (mtk->wakeup_src == SSUSB_WK_LINE_STATE)
 		usb_wakeup_line_state_en(mtk);
@@ -374,7 +377,9 @@ static void usb_wakeup_enable(struct xhci_hcd_mtk *mtk)
 
 static void usb_wakeup_disable(struct xhci_hcd_mtk *mtk)
 {
-	if (mtk->wakeup_src == SSUSB_WK_IP_SLEEP)
+	if (mtk->wakeup)
+		mtu_wakeup_disable(mtk->uwk);
+	else if (mtk->wakeup_src == SSUSB_WK_IP_SLEEP)
 		usb_wakeup_ip_sleep_dis(mtk);
 	else if (mtk->wakeup_src == SSUSB_WK_LINE_STATE)
 		usb_wakeup_line_state_dis(mtk);
@@ -383,24 +388,26 @@ static void usb_wakeup_disable(struct xhci_hcd_mtk *mtk)
 static int usb_wakeup_of_property_parse(struct xhci_hcd_mtk *mtk,
 				struct device_node *dn)
 {
-	struct device *dev = mtk->dev;
+	/* try the new way first */
+	mtk->wakeup = of_property_read_bool(dn, "wakeup-source");
+	if (mtk->wakeup) {
+		mtk->uwk = devm_of_uwk_get_by_index(mtk->dev, dn, 0);
+		if (IS_ERR(mtk->uwk))
+			dev_err(mtk->dev, "fail to get uwk\n");
+
+		return PTR_ERR_OR_ZERO(mtk->uwk);
+	}
 
-	/*
-	* wakeup function is optional, so it is not an error if this property
-	* does not exist, and in such case, no need to get relative
-	* properties anymore.
-	*/
+	/* wakeup function is optional (deprecated, use the new way instead) */
 	of_property_read_u32(dn, "mediatek,wakeup-src", &mtk->wakeup_src);
-	if (!mtk->wakeup_src)
-		return 0;
-
-	mtk->pericfg = syscon_regmap_lookup_by_phandle(dn,
+	if (mtk->wakeup_src) {
+		mtk->pericfg = syscon_regmap_lookup_by_phandle(dn,
 						"mediatek,syscon-wakeup");
-	if (IS_ERR(mtk->pericfg)) {
-		dev_err(dev, "fail to get pericfg regs\n");
-		return PTR_ERR(mtk->pericfg);
+		if (IS_ERR(mtk->pericfg)) {
+			dev_err(mtk->dev, "fail to get pericfg regs\n");
+			return PTR_ERR(mtk->pericfg);
+		}
 	}
-
 	return 0;
 }
 
diff --git a/drivers/usb/host/xhci-mtk.h b/drivers/usb/host/xhci-mtk.h
index 6b74ce5..95bd6ca 100644
--- a/drivers/usb/host/xhci-mtk.h
+++ b/drivers/usb/host/xhci-mtk.h
@@ -124,6 +124,8 @@ struct xhci_hcd_mtk {
 	int num_phys;
 	int wakeup_src;
 	bool lpm_support;
+	struct mtu_wakeup *uwk;
+	bool wakeup;
 };
 
 static inline struct xhci_hcd_mtk *hcd_to_mtk(struct usb_hcd *hcd)
-- 
1.9.1

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

* [PATCH 4/7] usb: mtu3: use APIs of mtu_wakeup to support remote wakeup
  2017-12-09  8:45 [PATCH 0/7] Add USB remote wakeup driver Chunfeng Yun
                   ` (2 preceding siblings ...)
  2017-12-09  8:45 ` [PATCH 3/7] usb: xhci-mtk: use APIs of mtu_wakeup to support remote wakeup Chunfeng Yun
@ 2017-12-09  8:45 ` Chunfeng Yun
  2017-12-09  8:45 ` [PATCH 5/7] dt-bindings: usb: mtk-xhci: add USB wakeup properties Chunfeng Yun
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 12+ messages in thread
From: Chunfeng Yun @ 2017-12-09  8:45 UTC (permalink / raw)
  To: Rob Herring, Felipe Balbi, Matthias Brugger, Mathias Nyman
  Cc: Mark Rutland, Greg Kroah-Hartman, Catalin Marinas, Will Deacon,
	Chunfeng Yun, Jean Delvare, Sean Wang, devicetree, linux-kernel,
	linux-usb, linux-arm-kernel, linux-mediatek

On some platforms, there are two SSUSB IPs, but the old way of
usb wakeup doesn't support it, so use the new APIs of mtu_wakeup
to support it.

Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com>
---
 drivers/usb/mtu3/mtu3.h      |  2 ++
 drivers/usb/mtu3/mtu3_host.c | 39 +++++++++++++++++++++++----------------
 2 files changed, 25 insertions(+), 16 deletions(-)

diff --git a/drivers/usb/mtu3/mtu3.h b/drivers/usb/mtu3/mtu3.h
index 3c888d9..9f3eb79 100644
--- a/drivers/usb/mtu3/mtu3.h
+++ b/drivers/usb/mtu3/mtu3.h
@@ -255,6 +255,8 @@ struct ssusb_mtk {
 	/* usb wakeup for host mode */
 	bool wakeup_en;
 	struct regmap *pericfg;
+	struct mtu_wakeup *uwk;
+	bool new_wakeup;
 };
 
 /**
diff --git a/drivers/usb/mtu3/mtu3_host.c b/drivers/usb/mtu3/mtu3_host.c
index 7e948c0..f769b65 100644
--- a/drivers/usb/mtu3/mtu3_host.c
+++ b/drivers/usb/mtu3/mtu3_host.c
@@ -14,6 +14,7 @@
 #include <linux/mfd/syscon.h>
 #include <linux/of_device.h>
 #include <linux/regmap.h>
+#include <linux/soc/mediatek/usb-wakeup.h>
 
 #include "mtu3.h"
 #include "mtu3_dr.h"
@@ -56,24 +57,26 @@ static void ssusb_wakeup_ip_sleep_dis(struct ssusb_mtk *ssusb)
 int ssusb_wakeup_of_property_parse(struct ssusb_mtk *ssusb,
 				struct device_node *dn)
 {
-	struct device *dev = ssusb->dev;
+	/* try the new way first */
+	ssusb->new_wakeup = of_property_read_bool(dn, "wakeup-source");
+	if (ssusb->new_wakeup) {
+		ssusb->uwk = devm_of_uwk_get_by_index(ssusb->dev, dn, 0);
+		if (IS_ERR(ssusb->uwk))
+			dev_err(ssusb->dev, "fail to get mtu_wakeup\n");
+
+		return PTR_ERR_OR_ZERO(ssusb->uwk);
+	}
 
-	/*
-	 * Wakeup function is optional, so it is not an error if this property
-	 * does not exist, and in such case, no need to get relative
-	 * properties anymore.
-	 */
+	/* Wakeup function is optional. (deprecated, use the new way instead) */
 	ssusb->wakeup_en = of_property_read_bool(dn, "mediatek,enable-wakeup");
-	if (!ssusb->wakeup_en)
-		return 0;
-
-	ssusb->pericfg = syscon_regmap_lookup_by_phandle(dn,
+	if (ssusb->wakeup_en) {
+		ssusb->pericfg = syscon_regmap_lookup_by_phandle(dn,
 						"mediatek,syscon-wakeup");
-	if (IS_ERR(ssusb->pericfg)) {
-		dev_err(dev, "fail to get pericfg regs\n");
-		return PTR_ERR(ssusb->pericfg);
+		if (IS_ERR(ssusb->pericfg)) {
+			dev_err(ssusb->dev, "fail to get pericfg regs\n");
+			return PTR_ERR(ssusb->pericfg);
+		}
 	}
-
 	return 0;
 }
 
@@ -235,7 +238,9 @@ void ssusb_host_exit(struct ssusb_mtk *ssusb)
 
 int ssusb_wakeup_enable(struct ssusb_mtk *ssusb)
 {
-	if (ssusb->wakeup_en)
+	if (ssusb->new_wakeup)
+		mtu_wakeup_enable(ssusb->uwk);
+	else if (ssusb->wakeup_en)
 		ssusb_wakeup_ip_sleep_en(ssusb);
 
 	return 0;
@@ -243,6 +248,8 @@ int ssusb_wakeup_enable(struct ssusb_mtk *ssusb)
 
 void ssusb_wakeup_disable(struct ssusb_mtk *ssusb)
 {
-	if (ssusb->wakeup_en)
+	if (ssusb->new_wakeup)
+		mtu_wakeup_disable(ssusb->uwk);
+	else if (ssusb->wakeup_en)
 		ssusb_wakeup_ip_sleep_dis(ssusb);
 }
-- 
1.9.1

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

* [PATCH 5/7] dt-bindings: usb: mtk-xhci: add USB wakeup properties
  2017-12-09  8:45 [PATCH 0/7] Add USB remote wakeup driver Chunfeng Yun
                   ` (3 preceding siblings ...)
  2017-12-09  8:45 ` [PATCH 4/7] usb: mtu3: " Chunfeng Yun
@ 2017-12-09  8:45 ` Chunfeng Yun
  2017-12-09  8:45 ` [PATCH 6/7] dt-bindings: usb: mtu3: " Chunfeng Yun
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 12+ messages in thread
From: Chunfeng Yun @ 2017-12-09  8:45 UTC (permalink / raw)
  To: Rob Herring, Felipe Balbi, Matthias Brugger, Mathias Nyman
  Cc: Mark Rutland, Greg Kroah-Hartman, Catalin Marinas, Will Deacon,
	Chunfeng Yun, Jean Delvare, Sean Wang, devicetree, linux-kernel,
	linux-usb, linux-arm-kernel, linux-mediatek

Modify the properties of usb wakeup, and use the new way of mtu_wakeup
which is extracted from SSUSB controller dirver as a new one.

Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com>
---
 .../devicetree/bindings/usb/mediatek,mtk-xhci.txt         | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/Documentation/devicetree/bindings/usb/mediatek,mtk-xhci.txt b/Documentation/devicetree/bindings/usb/mediatek,mtk-xhci.txt
index 3059596..88984d8 100644
--- a/Documentation/devicetree/bindings/usb/mediatek,mtk-xhci.txt
+++ b/Documentation/devicetree/bindings/usb/mediatek,mtk-xhci.txt
@@ -35,10 +35,17 @@ Required properties:
  - phys : a list of phandle + phy specifier pairs
 
 Optional properties:
- - mediatek,wakeup-src : 1: ip sleep wakeup mode; 2: line state wakeup
-	mode;
- - mediatek,syscon-wakeup : phandle to syscon used to access USB wakeup
-	control register, it depends on "mediatek,wakeup-src".
+ - mediatek,uwks : a phandle to USB-Wakeup node to control the type of
+	wakeup, it's used to replace the old way which is realized by the
+	property of "mediatek,wakeup-src" and "mediatek,syscon-wakeup",
+	see: Documentation/devicetree/bindings/soc/mediatek/usb-wakeup.txt
+ - wakeup-source : Decides if the new way of USB wakeup is supported or
+	not, it depends on "mediatek,uwks" property.
+ - mediatek,wakeup-src : (deprecated) 1: ip sleep wakeup mode; 2: line
+	state wakeup mode; only supports mt8173 platform, use the property
+	of "mediatek,uwks" instead on other SoCs.
+ - mediatek,syscon-wakeup : (deprecated) phandle to syscon used to access
+	USB wakeup control register, depends on "mediatek,wakeup-src".
  - mediatek,u3p-dis-msk : mask to disable u3ports, bit0 for u3port0,
 	bit1 for u3port1, ... etc;
  - vbus-supply : reference to the VBUS regulator;
-- 
1.9.1

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

* [PATCH 6/7] dt-bindings: usb: mtu3: add USB wakeup properties
  2017-12-09  8:45 [PATCH 0/7] Add USB remote wakeup driver Chunfeng Yun
                   ` (4 preceding siblings ...)
  2017-12-09  8:45 ` [PATCH 5/7] dt-bindings: usb: mtk-xhci: add USB wakeup properties Chunfeng Yun
@ 2017-12-09  8:45 ` Chunfeng Yun
  2017-12-09  8:45 ` [PATCH 7/7] arm64: dts: mt8173: add uwk node and remove unused usb property Chunfeng Yun
  2017-12-15 20:55 ` [PATCH 0/7] Add USB remote wakeup driver Rob Herring
  7 siblings, 0 replies; 12+ messages in thread
From: Chunfeng Yun @ 2017-12-09  8:45 UTC (permalink / raw)
  To: Rob Herring, Felipe Balbi, Matthias Brugger, Mathias Nyman
  Cc: Mark Rutland, Greg Kroah-Hartman, Catalin Marinas, Will Deacon,
	Chunfeng Yun, Jean Delvare, Sean Wang, devicetree, linux-kernel,
	linux-usb, linux-arm-kernel, linux-mediatek

Modify the properties of usb wakeup, and use the new way of mtu_wakeup
which is extracted from SSUSB controller dirver as a new driver.

Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com>
---
 Documentation/devicetree/bindings/usb/mediatek,mtu3.txt | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/Documentation/devicetree/bindings/usb/mediatek,mtu3.txt b/Documentation/devicetree/bindings/usb/mediatek,mtu3.txt
index b2271d8..2ed546d 100644
--- a/Documentation/devicetree/bindings/usb/mediatek,mtu3.txt
+++ b/Documentation/devicetree/bindings/usb/mediatek,mtu3.txt
@@ -42,9 +42,17 @@ Optional properties:
  - enable-manual-drd : supports manual dual-role switch via debugfs; usually
 	used when receptacle is TYPE-A and also wants to support dual-role
 	mode.
- - mediatek,enable-wakeup : supports ip sleep wakeup used by host mode
- - mediatek,syscon-wakeup : phandle to syscon used to access USB wakeup
-	control register, it depends on "mediatek,enable-wakeup".
+ - mediatek,uwks : a phandle to USB-Wakeup node to control the type of wakeup,
+	it's used to replace the old way which is realized by the property of
+	"mediatek,wakeup-wakeup" and "mediatek,syscon-wakeup",
+	see: Documentation/devicetree/bindings/soc/mediatek/usb-wakeup.txt
+ - wakeup-source : Decides if the new way of USB wakeup is supported or
+	not, it depends on "mediatek,uwks" property.
+ - mediatek,enable-wakeup : (deprecated) supports ip sleep wakeup used by
+	host mode, only supports mt8173 platform, use the property of
+	"mediatek,uwks" instead on other SoCs.
+ - mediatek,syscon-wakeup : (deprecated) phandle to syscon used to access
+	USB wakeup control register, it depends on "mediatek,enable-wakeup".
  - mediatek,u3p-dis-msk : mask to disable u3ports, bit0 for u3port0,
 	bit1 for u3port1, ... etc;
 
-- 
1.9.1

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

* [PATCH 7/7] arm64: dts: mt8173: add uwk node and remove unused usb property
  2017-12-09  8:45 [PATCH 0/7] Add USB remote wakeup driver Chunfeng Yun
                   ` (5 preceding siblings ...)
  2017-12-09  8:45 ` [PATCH 6/7] dt-bindings: usb: mtu3: " Chunfeng Yun
@ 2017-12-09  8:45 ` Chunfeng Yun
  2017-12-15 20:55 ` [PATCH 0/7] Add USB remote wakeup driver Rob Herring
  7 siblings, 0 replies; 12+ messages in thread
From: Chunfeng Yun @ 2017-12-09  8:45 UTC (permalink / raw)
  To: Rob Herring, Felipe Balbi, Matthias Brugger, Mathias Nyman
  Cc: Mark Rutland, Greg Kroah-Hartman, Catalin Marinas, Will Deacon,
	Chunfeng Yun, Jean Delvare, Sean Wang, devicetree, linux-kernel,
	linux-usb, linux-arm-kernel, linux-mediatek

Add uwk node for new way of usb remote wakeup instead of old one,
and modify some usb properties according binding documents
of mediatek,mtu3.txt and mediatek,mtk-xhci.txt

Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com>
---
 arch/arm64/boot/dts/mediatek/mt8173-evb.dts | 28 ++++++++++++++++++----------
 arch/arm64/boot/dts/mediatek/mt8173.dtsi    | 16 +++++-----------
 2 files changed, 23 insertions(+), 21 deletions(-)

diff --git a/arch/arm64/boot/dts/mediatek/mt8173-evb.dts b/arch/arm64/boot/dts/mediatek/mt8173-evb.dts
index 1c3634f..08a323b 100644
--- a/arch/arm64/boot/dts/mediatek/mt8173-evb.dts
+++ b/arch/arm64/boot/dts/mediatek/mt8173-evb.dts
@@ -14,6 +14,7 @@
 
 /dts-v1/;
 #include <dt-bindings/gpio/gpio.h>
+#include <dt-bindings/soc/mediatek,usb-wakeup.h>
 #include "mt8173.dtsi"
 
 / {
@@ -68,6 +69,20 @@
 		gpio = <&pio 9 GPIO_ACTIVE_HIGH>;
 		enable-active-high;
 	};
+
+	usb_wakeup: uwk@0 {
+		compatible = "mediatek,mt8173-uwk","mediatek,usb-wk-v1";
+		mediatek,wkc = <&pericfg>;
+		#address-cells = <1>;
+		#size-cells = <1>;
+		status = "okay";
+
+		usb_wk0: uwk@400 {
+			reg = <0x400 0x8>;
+			#mediatek,uwk-cells = <1>;
+			status = "okay";
+		};
+	};
 };
 
 &cec {
@@ -268,12 +283,6 @@
 		};
 	};
 
-	usb_id_pins_ground: usb_iddig_pull_down {
-		pins_iddig {
-			pinmux = <MT8173_PIN_16_IDDIG__FUNC_IDDIG>;
-			bias-pull-down;
-		};
-	};
 };
 
 &pwm0 {
@@ -501,15 +510,14 @@
 };
 
 &ssusb {
+	mediatek,uwks = <&usb_wk0 MTU_WK_IP_SLEEP>;
 	vusb33-supply = <&mt6397_vusb_reg>;
 	vbus-supply = <&usb_p0_vbus>;
 	extcon = <&extcon_usb>;
 	dr_mode = "otg";
-	mediatek,enable-wakeup;
-	pinctrl-names = "default", "id_float", "id_ground";
+	wakeup-source;
+	pinctrl-names = "default";
 	pinctrl-0 = <&usb_id_pins_float>;
-	pinctrl-1 = <&usb_id_pins_float>;
-	pinctrl-2 = <&usb_id_pins_ground>;
 	status = "okay";
 };
 
diff --git a/arch/arm64/boot/dts/mediatek/mt8173.dtsi b/arch/arm64/boot/dts/mediatek/mt8173.dtsi
index 26396ef..818ead7 100644
--- a/arch/arm64/boot/dts/mediatek/mt8173.dtsi
+++ b/arch/arm64/boot/dts/mediatek/mt8173.dtsi
@@ -722,7 +722,7 @@
 		};
 
 		ssusb: usb@11271000 {
-			compatible = "mediatek,mt8173-mtu3";
+			compatible = "mediatek,mt8173-mtu3", "mediatek,mtu3";
 			reg = <0 0x11271000 0 0x3000>,
 			      <0 0x11280700 0 0x0100>;
 			reg-names = "mac", "ippc";
@@ -731,22 +731,16 @@
 			       <&u3port0 PHY_TYPE_USB3>,
 			       <&u2port1 PHY_TYPE_USB2>;
 			power-domains = <&scpsys MT8173_POWER_DOMAIN_USB>;
-			clocks = <&topckgen CLK_TOP_USB30_SEL>,
-				 <&clk26m>,
-				 <&pericfg CLK_PERI_USB0>,
-				 <&pericfg CLK_PERI_USB1>;
-			clock-names = "sys_ck",
-				      "ref_ck",
-				      "wakeup_deb_p0",
-				      "wakeup_deb_p1";
-			mediatek,syscon-wakeup = <&pericfg>;
+			clocks = <&topckgen CLK_TOP_USB30_SEL>, <&clk26m>;
+			clock-names = "sys_ck", "ref_ck";
 			#address-cells = <2>;
 			#size-cells = <2>;
 			ranges;
 			status = "disabled";
 
 			usb_host: xhci@11270000 {
-				compatible = "mediatek,mt8173-xhci";
+				compatible = "mediatek,mt8173-xhci",
+					     "mediatek,mtk-xhci";
 				reg = <0 0x11270000 0 0x1000>;
 				reg-names = "mac";
 				interrupts = <GIC_SPI 115 IRQ_TYPE_LEVEL_LOW>;
-- 
1.9.1

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

* Re: [PATCH 0/7] Add USB remote wakeup driver
  2017-12-09  8:45 [PATCH 0/7] Add USB remote wakeup driver Chunfeng Yun
                   ` (6 preceding siblings ...)
  2017-12-09  8:45 ` [PATCH 7/7] arm64: dts: mt8173: add uwk node and remove unused usb property Chunfeng Yun
@ 2017-12-15 20:55 ` Rob Herring
  2017-12-21  6:48   ` Chunfeng Yun
  7 siblings, 1 reply; 12+ messages in thread
From: Rob Herring @ 2017-12-15 20:55 UTC (permalink / raw)
  To: Chunfeng Yun
  Cc: Felipe Balbi, Matthias Brugger, Mathias Nyman, Mark Rutland,
	Greg Kroah-Hartman, Catalin Marinas, Will Deacon, Jean Delvare,
	Sean Wang, devicetree, linux-kernel, linux-usb, linux-arm-kernel,
	linux-mediatek

On Sat, Dec 09, 2017 at 04:45:29PM +0800, Chunfeng Yun wrote:
>     These patches introduce the SSUSB and SPM glue layer driver which is
> used to support usb remote wakeup. Usually the glue layer is put into
> a system controller, such as PERICFG module.
>     The old way to support usb wakeup is put into SSUSB controller drivers,
> including xhci-mtk driver and mtu3 driver, but there are some problems:
>     1. can't disdinguish the relation between glue layer and SSUSB IP
>        when SoCs supports multi SSUSB IPs;
>     2. duplicated code for wakeup are put into both xhci-mtk and mtu3
>        drivers;
>     3. the glue layer may vary on different SoCs with SSUSB IP, and will
>        make SSUSB controller drivers complicated;
>     In order to resolve these problems, it's useful to make the glue layer
> transparent by extracting a seperated driver, meanwhile to reduce the
> duplicated code and simplify SSUSB controller drivers.

Both the driver and binding look overly complicated to me when it looks 
like you just have 2 versions of enable/disable functions which modify 
a single register. The complexity may be justified if this was a common 
binding and driver, but it is not.

You already have a phandle to the system controller. Can't you add cells 
to it to handle any differences between instances? That and SoC specific 
compatible strings should be enough to handle differences.

Rob

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

* Re: [PATCH 1/7] soc: mediatek: Add USB wakeup driver
  2017-12-09  8:45 ` [PATCH 1/7] soc: mediatek: Add USB " Chunfeng Yun
@ 2017-12-15 20:55   ` Rob Herring
  2017-12-21  6:50     ` Chunfeng Yun
  0 siblings, 1 reply; 12+ messages in thread
From: Rob Herring @ 2017-12-15 20:55 UTC (permalink / raw)
  To: Chunfeng Yun
  Cc: Felipe Balbi, Matthias Brugger, Mathias Nyman, Mark Rutland,
	Greg Kroah-Hartman, Catalin Marinas, Will Deacon, Jean Delvare,
	Sean Wang, devicetree, linux-kernel, linux-usb, linux-arm-kernel,
	linux-mediatek

On Sat, Dec 09, 2017 at 04:45:30PM +0800, Chunfeng Yun wrote:
> This driver is used to support usb wakeup which is controlled by
> the glue layer between SSUSB and SPM. Usually the glue layer is put
> into a system controller, such as pericfg module, which is
> represented by a syscon node in DTS.
> Due to the glue layer may vary on different SoCs, it's useful to
> extract a separated driver to simplify usb controller drivers.
> 
> Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com>
> ---
>  drivers/soc/mediatek/Kconfig                  |   8 +
>  drivers/soc/mediatek/Makefile                 |   1 +
>  drivers/soc/mediatek/mtk-usb-wakeup.c         | 519 ++++++++++++++++++++++++++
>  include/dt-bindings/soc/mediatek,usb-wakeup.h |  15 +

This belongs in the binding patch and that should come first.

>  include/linux/soc/mediatek/usb-wakeup.h       |  88 +++++
>  5 files changed, 631 insertions(+)
>  create mode 100644 drivers/soc/mediatek/mtk-usb-wakeup.c
>  create mode 100644 include/dt-bindings/soc/mediatek,usb-wakeup.h
>  create mode 100644 include/linux/soc/mediatek/usb-wakeup.h

> +++ b/drivers/soc/mediatek/mtk-usb-wakeup.c
> @@ -0,0 +1,519 @@
> +/*
> + * Copyright (c) 2017 MediaTek Inc.
> + * Author: Chunfeng Yun <chunfeng.yun@mediatek.com>
> + *
> + * SPDX-License-Identifier: GPL-2.0

This should be the first line of the file and use a // style comment.

[...]

> diff --git a/include/dt-bindings/soc/mediatek,usb-wakeup.h b/include/dt-bindings/soc/mediatek,usb-wakeup.h
> new file mode 100644
> index 0000000..2461795
> --- /dev/null
> +++ b/include/dt-bindings/soc/mediatek,usb-wakeup.h
> @@ -0,0 +1,15 @@
> +/*
> + * Copyright (c) 2017 MediaTek Inc.
> + * Author: Chunfeng Yun <chunfeng.yun@mediatek.com>
> + *
> + * SPDX-License-Identifier: GPL-2.0

ditto. Except headers use /* */ comments...

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

* Re: [PATCH 0/7] Add USB remote wakeup driver
  2017-12-15 20:55 ` [PATCH 0/7] Add USB remote wakeup driver Rob Herring
@ 2017-12-21  6:48   ` Chunfeng Yun
  0 siblings, 0 replies; 12+ messages in thread
From: Chunfeng Yun @ 2017-12-21  6:48 UTC (permalink / raw)
  To: Rob Herring
  Cc: Felipe Balbi, Matthias Brugger, Mathias Nyman, Mark Rutland,
	Greg Kroah-Hartman, Catalin Marinas, Will Deacon, Jean Delvare,
	Sean Wang, devicetree, linux-kernel, linux-usb, linux-arm-kernel,
	linux-mediatek

On Fri, 2017-12-15 at 14:55 -0600, Rob Herring wrote:
> On Sat, Dec 09, 2017 at 04:45:29PM +0800, Chunfeng Yun wrote:
> >     These patches introduce the SSUSB and SPM glue layer driver which is
> > used to support usb remote wakeup. Usually the glue layer is put into
> > a system controller, such as PERICFG module.
> >     The old way to support usb wakeup is put into SSUSB controller drivers,
> > including xhci-mtk driver and mtu3 driver, but there are some problems:
> >     1. can't disdinguish the relation between glue layer and SSUSB IP
> >        when SoCs supports multi SSUSB IPs;
> >     2. duplicated code for wakeup are put into both xhci-mtk and mtu3
> >        drivers;
> >     3. the glue layer may vary on different SoCs with SSUSB IP, and will
> >        make SSUSB controller drivers complicated;
> >     In order to resolve these problems, it's useful to make the glue layer
> > transparent by extracting a seperated driver, meanwhile to reduce the
> > duplicated code and simplify SSUSB controller drivers.
> 
> Both the driver and binding look overly complicated to me when it looks 
> like you just have 2 versions of enable/disable functions which modify 
> a single register. The complexity may be justified if this was a common 
> binding and driver, but it is not.
> 
> You already have a phandle to the system controller. Can't you add cells 
> to it to handle any differences between instances? That and SoC specific 
> compatible strings should be enough to handle differences.
Yes, adding cells will also work well, I'll try it, thanks a lot
> 
> Rob

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

* Re: [PATCH 1/7] soc: mediatek: Add USB wakeup driver
  2017-12-15 20:55   ` Rob Herring
@ 2017-12-21  6:50     ` Chunfeng Yun
  0 siblings, 0 replies; 12+ messages in thread
From: Chunfeng Yun @ 2017-12-21  6:50 UTC (permalink / raw)
  To: Rob Herring
  Cc: Felipe Balbi, Matthias Brugger, Mathias Nyman, Mark Rutland,
	Greg Kroah-Hartman, Catalin Marinas, Will Deacon, Jean Delvare,
	Sean Wang, devicetree, linux-kernel, linux-usb, linux-arm-kernel,
	linux-mediatek

On Fri, 2017-12-15 at 14:55 -0600, Rob Herring wrote:
> On Sat, Dec 09, 2017 at 04:45:30PM +0800, Chunfeng Yun wrote:
> > This driver is used to support usb wakeup which is controlled by
> > the glue layer between SSUSB and SPM. Usually the glue layer is put
> > into a system controller, such as pericfg module, which is
> > represented by a syscon node in DTS.
> > Due to the glue layer may vary on different SoCs, it's useful to
> > extract a separated driver to simplify usb controller drivers.
> > 
> > Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com>
> > ---
> >  drivers/soc/mediatek/Kconfig                  |   8 +
> >  drivers/soc/mediatek/Makefile                 |   1 +
> >  drivers/soc/mediatek/mtk-usb-wakeup.c         | 519 ++++++++++++++++++++++++++
> >  include/dt-bindings/soc/mediatek,usb-wakeup.h |  15 +
> 
> This belongs in the binding patch and that should come first.
> 
> >  include/linux/soc/mediatek/usb-wakeup.h       |  88 +++++
> >  5 files changed, 631 insertions(+)
> >  create mode 100644 drivers/soc/mediatek/mtk-usb-wakeup.c
> >  create mode 100644 include/dt-bindings/soc/mediatek,usb-wakeup.h
> >  create mode 100644 include/linux/soc/mediatek/usb-wakeup.h
> 
> > +++ b/drivers/soc/mediatek/mtk-usb-wakeup.c
> > @@ -0,0 +1,519 @@
> > +/*
> > + * Copyright (c) 2017 MediaTek Inc.
> > + * Author: Chunfeng Yun <chunfeng.yun@mediatek.com>
> > + *
> > + * SPDX-License-Identifier: GPL-2.0
> 
> This should be the first line of the file and use a // style comment.
> 
> [...]
> 
> > diff --git a/include/dt-bindings/soc/mediatek,usb-wakeup.h b/include/dt-bindings/soc/mediatek,usb-wakeup.h
> > new file mode 100644
> > index 0000000..2461795
> > --- /dev/null
> > +++ b/include/dt-bindings/soc/mediatek,usb-wakeup.h
> > @@ -0,0 +1,15 @@
> > +/*
> > + * Copyright (c) 2017 MediaTek Inc.
> > + * Author: Chunfeng Yun <chunfeng.yun@mediatek.com>
> > + *
> > + * SPDX-License-Identifier: GPL-2.0
> 
> ditto. Except headers use /* */ comments...
modify it next version. Thanks

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

end of thread, other threads:[~2017-12-21  6:50 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-09  8:45 [PATCH 0/7] Add USB remote wakeup driver Chunfeng Yun
2017-12-09  8:45 ` [PATCH 1/7] soc: mediatek: Add USB " Chunfeng Yun
2017-12-15 20:55   ` Rob Herring
2017-12-21  6:50     ` Chunfeng Yun
2017-12-09  8:45 ` [PATCH 2/7] dt-bindings: soc: mediatek: add bindings document for USB wakeup Chunfeng Yun
2017-12-09  8:45 ` [PATCH 3/7] usb: xhci-mtk: use APIs of mtu_wakeup to support remote wakeup Chunfeng Yun
2017-12-09  8:45 ` [PATCH 4/7] usb: mtu3: " Chunfeng Yun
2017-12-09  8:45 ` [PATCH 5/7] dt-bindings: usb: mtk-xhci: add USB wakeup properties Chunfeng Yun
2017-12-09  8:45 ` [PATCH 6/7] dt-bindings: usb: mtu3: " Chunfeng Yun
2017-12-09  8:45 ` [PATCH 7/7] arm64: dts: mt8173: add uwk node and remove unused usb property Chunfeng Yun
2017-12-15 20:55 ` [PATCH 0/7] Add USB remote wakeup driver Rob Herring
2017-12-21  6:48   ` Chunfeng Yun

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).