cip-dev.lists.cip-project.org archive mirror
 help / color / mirror / Atom feed
* [cip-dev] [PATCH 4.19.y-cip 00/12] Add USB Host support
@ 2019-07-15 14:01 Biju Das
  2019-07-15 14:01 ` [cip-dev] [PATCH 4.19.y-cip 01/12] phy: renesas: rcar-gen3-usb2: fix vbus_ctrl for role sysfs Biju Das
                   ` (12 more replies)
  0 siblings, 13 replies; 20+ messages in thread
From: Biju Das @ 2019-07-15 14:01 UTC (permalink / raw)
  To: cip-dev

This patch series add USB host support for EK874 platform.

This patch series is based on linux-4.19.y-cip and all the patches
in this series are cherry-picked from linux rc tree.

This patch series is depend on the below patch series
https://patchwork.kernel.org/project/cip-dev/list/?series=145929

Biju Das (2):
  phy: rcar-gen3-usb2: Add support for r8a77470
  arm64: dts: renesas: cat874: Add USB-HOST support

Yoshihiro Shimoda (10):
  phy: renesas: rcar-gen3-usb2: fix vbus_ctrl for role sysfs
  phy: renesas: rcar-gen3-usb2: Rename has_otg_pins to uses_otg_pins
  phy: renesas: rcar-gen3-usb2: Check a property to use otg pins
  phy: renesas: rcar-gen3-usb2: unify OBINTEN handling
  phy: renesas: rcar-gen3-usb2: add conditions for uses_otg_pins ==
    false
  phy: renesas: rcar-gen3-usb2: change a condition "dr_mode"
  phy: renesas: rcar-gen3-usb2: add is_otg_channel to use "role" sysfs
  phy: renesas: rcar-gen3-usb2: follow the hardware manual procedure
  phy: renesas: rcar-gen3-usb2: Use pdev's device pointer on dev_vdbg()
  phy: renesas: rcar-gen3-usb2: enable/disable independent irqs

 arch/arm64/boot/dts/renesas/r8a774c0-cat874.dts |  15 ++
 drivers/phy/renesas/Kconfig                     |   2 +-
 drivers/phy/renesas/phy-rcar-gen3-usb2.c        | 286 +++++++++++++++++++-----
 3 files changed, 250 insertions(+), 53 deletions(-)

-- 
2.7.4

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

* [cip-dev] [PATCH 4.19.y-cip 01/12] phy: renesas: rcar-gen3-usb2: fix vbus_ctrl for role sysfs
  2019-07-15 14:01 [cip-dev] [PATCH 4.19.y-cip 00/12] Add USB Host support Biju Das
@ 2019-07-15 14:01 ` Biju Das
  2019-07-15 14:01 ` [cip-dev] [PATCH 4.19.y-cip 02/12] phy: renesas: rcar-gen3-usb2: Rename has_otg_pins to uses_otg_pins Biju Das
                   ` (11 subsequent siblings)
  12 siblings, 0 replies; 20+ messages in thread
From: Biju Das @ 2019-07-15 14:01 UTC (permalink / raw)
  To: cip-dev

From: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>

commit 09938ea9d136243e8d1fed6d4d7a257764f28f6d upstream.

This patch fixes and issue that the vbus_ctrl is disabled by
rcar_gen3_init_from_a_peri_to_a_host(), so a usb host cannot
supply the vbus.

Note that this condition will exit when the otg irq happens
even if we don't apply this patch.

Fixes: 9bb86777fb71 ("phy: rcar-gen3-usb2: add sysfs for usb role swap")
Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Reviewed-by: Simon Horman <horms+renesas@verge.net.au>
Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Biju Das <biju.das@bp.renesas.com>
---
 drivers/phy/renesas/phy-rcar-gen3-usb2.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/phy/renesas/phy-rcar-gen3-usb2.c b/drivers/phy/renesas/phy-rcar-gen3-usb2.c
index fb8f05e..68bc979 100644
--- a/drivers/phy/renesas/phy-rcar-gen3-usb2.c
+++ b/drivers/phy/renesas/phy-rcar-gen3-usb2.c
@@ -198,7 +198,7 @@ static void rcar_gen3_init_from_a_peri_to_a_host(struct rcar_gen3_chan *ch)
 	val = readl(usb2_base + USB2_OBINTEN);
 	writel(val & ~USB2_OBINT_BITS, usb2_base + USB2_OBINTEN);
 
-	rcar_gen3_enable_vbus_ctrl(ch, 0);
+	rcar_gen3_enable_vbus_ctrl(ch, 1);
 	rcar_gen3_init_for_host(ch);
 
 	writel(val | USB2_OBINT_BITS, usb2_base + USB2_OBINTEN);
-- 
2.7.4

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

* [cip-dev] [PATCH 4.19.y-cip 02/12] phy: renesas: rcar-gen3-usb2: Rename has_otg_pins to uses_otg_pins
  2019-07-15 14:01 [cip-dev] [PATCH 4.19.y-cip 00/12] Add USB Host support Biju Das
  2019-07-15 14:01 ` [cip-dev] [PATCH 4.19.y-cip 01/12] phy: renesas: rcar-gen3-usb2: fix vbus_ctrl for role sysfs Biju Das
@ 2019-07-15 14:01 ` Biju Das
  2019-07-15 14:01 ` [cip-dev] [PATCH 4.19.y-cip 03/12] phy: renesas: rcar-gen3-usb2: Check a property to use otg pins Biju Das
                   ` (10 subsequent siblings)
  12 siblings, 0 replies; 20+ messages in thread
From: Biju Das @ 2019-07-15 14:01 UTC (permalink / raw)
  To: cip-dev

From: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>

commit cfdc66348eed22211f277c4bd668ac935b8b3470 upstream.

Since R-Car E3 and D3 have dedicated otg pins actually, "has_otg_pins"
is possible to misread in the future. So, this patch renames
has_otg_pins to uses_otg_pins.

Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Reviewed-by: Simon Horman <horms+renesas@verge.net.au>
Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Biju Das <biju.das@bp.renesas.com>
---
 drivers/phy/renesas/phy-rcar-gen3-usb2.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/phy/renesas/phy-rcar-gen3-usb2.c b/drivers/phy/renesas/phy-rcar-gen3-usb2.c
index 68bc979..975696b 100644
--- a/drivers/phy/renesas/phy-rcar-gen3-usb2.c
+++ b/drivers/phy/renesas/phy-rcar-gen3-usb2.c
@@ -90,7 +90,7 @@ struct rcar_gen3_chan {
 	struct regulator *vbus;
 	struct work_struct work;
 	bool extcon_host;
-	bool has_otg_pins;
+	bool uses_otg_pins;
 };
 
 static void rcar_gen3_phy_usb2_work(struct work_struct *work)
@@ -237,7 +237,7 @@ static ssize_t role_store(struct device *dev, struct device_attribute *attr,
 	bool is_b_device;
 	enum phy_mode cur_mode, new_mode;
 
-	if (!ch->has_otg_pins || !ch->phy->init_count)
+	if (!ch->uses_otg_pins || !ch->phy->init_count)
 		return -EIO;
 
 	if (!strncmp(buf, "host", strlen("host")))
@@ -275,7 +275,7 @@ static ssize_t role_show(struct device *dev, struct device_attribute *attr,
 {
 	struct rcar_gen3_chan *ch = dev_get_drvdata(dev);
 
-	if (!ch->has_otg_pins || !ch->phy->init_count)
+	if (!ch->uses_otg_pins || !ch->phy->init_count)
 		return -EIO;
 
 	return sprintf(buf, "%s\n", rcar_gen3_is_host(ch) ? "host" :
@@ -314,7 +314,7 @@ static int rcar_gen3_phy_usb2_init(struct phy *p)
 	writel(USB2_OC_TIMSET_INIT, usb2_base + USB2_OC_TIMSET);
 
 	/* Initialize otg part */
-	if (channel->has_otg_pins)
+	if (channel->uses_otg_pins)
 		rcar_gen3_init_otg(channel);
 
 	return 0;
@@ -448,7 +448,7 @@ static int rcar_gen3_phy_usb2_probe(struct platform_device *pdev)
 	if (of_usb_get_dr_mode_by_phy(dev->of_node, 0) == USB_DR_MODE_OTG) {
 		int ret;
 
-		channel->has_otg_pins = (uintptr_t)of_device_get_match_data(dev);
+		channel->uses_otg_pins = (uintptr_t)of_device_get_match_data(dev);
 		channel->extcon = devm_extcon_dev_allocate(dev,
 							rcar_gen3_phy_cable);
 		if (IS_ERR(channel->extcon))
@@ -490,7 +490,7 @@ static int rcar_gen3_phy_usb2_probe(struct platform_device *pdev)
 		dev_err(dev, "Failed to register PHY provider\n");
 		ret = PTR_ERR(provider);
 		goto error;
-	} else if (channel->has_otg_pins) {
+	} else if (channel->uses_otg_pins) {
 		int ret;
 
 		ret = device_create_file(dev, &dev_attr_role);
@@ -510,7 +510,7 @@ static int rcar_gen3_phy_usb2_remove(struct platform_device *pdev)
 {
 	struct rcar_gen3_chan *channel = platform_get_drvdata(pdev);
 
-	if (channel->has_otg_pins)
+	if (channel->uses_otg_pins)
 		device_remove_file(&pdev->dev, &dev_attr_role);
 
 	pm_runtime_disable(&pdev->dev);
-- 
2.7.4

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

* [cip-dev] [PATCH 4.19.y-cip 03/12] phy: renesas: rcar-gen3-usb2: Check a property to use otg pins
  2019-07-15 14:01 [cip-dev] [PATCH 4.19.y-cip 00/12] Add USB Host support Biju Das
  2019-07-15 14:01 ` [cip-dev] [PATCH 4.19.y-cip 01/12] phy: renesas: rcar-gen3-usb2: fix vbus_ctrl for role sysfs Biju Das
  2019-07-15 14:01 ` [cip-dev] [PATCH 4.19.y-cip 02/12] phy: renesas: rcar-gen3-usb2: Rename has_otg_pins to uses_otg_pins Biju Das
@ 2019-07-15 14:01 ` Biju Das
  2019-07-15 14:01 ` [cip-dev] [PATCH 4.19.y-cip 04/12] phy: renesas: rcar-gen3-usb2: unify OBINTEN handling Biju Das
                   ` (9 subsequent siblings)
  12 siblings, 0 replies; 20+ messages in thread
From: Biju Das @ 2019-07-15 14:01 UTC (permalink / raw)
  To: cip-dev

From: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>

commit 8dde0008ffc9e2e214ef916821959fe6706ff9f0 upstream.

Since All R-Car Gen3 SoCs have dedicated otg pins actually but
some boards don't use the otg pins (e.g. R-Car D3 Draak and R-Car E3
Ebisu), the driver should not choose SoC model base by using
rcar_gen3_phy_usb2_match_table's data. So, this patch checks a
"renesas,no-otg-pins" property to set the "uses_otg_pins".

Note that since r8a77995-draak.dts and r8a77990-ebisu.dts don't have
'dr_mode = "otg";' for now, if we apply this patch, no behavior
changes (the value of "uses_otg_pins" is false).

Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Reviewed-by: Simon Horman <horms+renesas@verge.net.au>
Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Biju Das <biju.das@bp.renesas.com>
---
 drivers/phy/renesas/phy-rcar-gen3-usb2.c | 24 ++++++------------------
 1 file changed, 6 insertions(+), 18 deletions(-)

diff --git a/drivers/phy/renesas/phy-rcar-gen3-usb2.c b/drivers/phy/renesas/phy-rcar-gen3-usb2.c
index 975696b..deb8484 100644
--- a/drivers/phy/renesas/phy-rcar-gen3-usb2.c
+++ b/drivers/phy/renesas/phy-rcar-gen3-usb2.c
@@ -81,8 +81,6 @@
 #define USB2_ADPCTRL_IDPULLUP		BIT(5)	/* 1 = ID sampling is enabled */
 #define USB2_ADPCTRL_DRVVBUS		BIT(4)
 
-#define RCAR_GEN3_PHY_HAS_DEDICATED_PINS	1
-
 struct rcar_gen3_chan {
 	void __iomem *base;
 	struct extcon_dev *extcon;
@@ -388,21 +386,10 @@ static irqreturn_t rcar_gen3_phy_usb2_irq(int irq, void *_ch)
 }
 
 static const struct of_device_id rcar_gen3_phy_usb2_match_table[] = {
-	{
-		.compatible = "renesas,usb2-phy-r8a7795",
-		.data = (void *)RCAR_GEN3_PHY_HAS_DEDICATED_PINS,
-	},
-	{
-		.compatible = "renesas,usb2-phy-r8a7796",
-		.data = (void *)RCAR_GEN3_PHY_HAS_DEDICATED_PINS,
-	},
-	{
-		.compatible = "renesas,usb2-phy-r8a77965",
-		.data = (void *)RCAR_GEN3_PHY_HAS_DEDICATED_PINS,
-	},
-	{
-		.compatible = "renesas,rcar-gen3-usb2-phy",
-	},
+	{ .compatible = "renesas,usb2-phy-r8a7795" },
+	{ .compatible = "renesas,usb2-phy-r8a7796" },
+	{ .compatible = "renesas,usb2-phy-r8a77965" },
+	{ .compatible = "renesas,rcar-gen3-usb2-phy" },
 	{ }
 };
 MODULE_DEVICE_TABLE(of, rcar_gen3_phy_usb2_match_table);
@@ -448,7 +435,8 @@ static int rcar_gen3_phy_usb2_probe(struct platform_device *pdev)
 	if (of_usb_get_dr_mode_by_phy(dev->of_node, 0) == USB_DR_MODE_OTG) {
 		int ret;
 
-		channel->uses_otg_pins = (uintptr_t)of_device_get_match_data(dev);
+		channel->uses_otg_pins = !of_property_read_bool(dev->of_node,
+							"renesas,no-otg-pins");
 		channel->extcon = devm_extcon_dev_allocate(dev,
 							rcar_gen3_phy_cable);
 		if (IS_ERR(channel->extcon))
-- 
2.7.4

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

* [cip-dev] [PATCH 4.19.y-cip 04/12] phy: renesas: rcar-gen3-usb2: unify OBINTEN handling
  2019-07-15 14:01 [cip-dev] [PATCH 4.19.y-cip 00/12] Add USB Host support Biju Das
                   ` (2 preceding siblings ...)
  2019-07-15 14:01 ` [cip-dev] [PATCH 4.19.y-cip 03/12] phy: renesas: rcar-gen3-usb2: Check a property to use otg pins Biju Das
@ 2019-07-15 14:01 ` Biju Das
  2019-07-16 12:03   ` Pavel Machek
  2019-07-15 14:01 ` [cip-dev] [PATCH 4.19.y-cip 05/12] phy: renesas: rcar-gen3-usb2: add conditions for uses_otg_pins == false Biju Das
                   ` (8 subsequent siblings)
  12 siblings, 1 reply; 20+ messages in thread
From: Biju Das @ 2019-07-15 14:01 UTC (permalink / raw)
  To: cip-dev

From: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>

commit 7ab0305d4d7725699169e21cdc4f6c8759c32feb upstream.

This patch unifies the OBINTEN handling to clean-up the code.

Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Reviewed-by: Simon Horman <horms+renesas@verge.net.au>
Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Biju Das <biju.das@bp.renesas.com>
---
 drivers/phy/renesas/phy-rcar-gen3-usb2.c | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)

diff --git a/drivers/phy/renesas/phy-rcar-gen3-usb2.c b/drivers/phy/renesas/phy-rcar-gen3-usb2.c
index deb8484..575b3d2 100644
--- a/drivers/phy/renesas/phy-rcar-gen3-usb2.c
+++ b/drivers/phy/renesas/phy-rcar-gen3-usb2.c
@@ -145,6 +145,18 @@ static void rcar_gen3_enable_vbus_ctrl(struct rcar_gen3_chan *ch, int vbus)
 	writel(val, usb2_base + USB2_ADPCTRL);
 }
 
+static void rcar_gen3_control_otg_irq(struct rcar_gen3_chan *ch, int enable)
+{
+	void __iomem *usb2_base = ch->base;
+	u32 val = readl(usb2_base + USB2_OBINTEN);
+
+	if (enable)
+		val |= USB2_OBINT_BITS;
+	else
+		val &= ~USB2_OBINT_BITS;
+	writel(val, usb2_base + USB2_OBINTEN);
+}
+
 static void rcar_gen3_init_for_host(struct rcar_gen3_chan *ch)
 {
 	rcar_gen3_set_linectrl(ch, 1, 1);
@@ -190,16 +202,12 @@ static void rcar_gen3_init_for_a_peri(struct rcar_gen3_chan *ch)
 
 static void rcar_gen3_init_from_a_peri_to_a_host(struct rcar_gen3_chan *ch)
 {
-	void __iomem *usb2_base = ch->base;
-	u32 val;
-
-	val = readl(usb2_base + USB2_OBINTEN);
-	writel(val & ~USB2_OBINT_BITS, usb2_base + USB2_OBINTEN);
+	rcar_gen3_control_otg_irq(ch, 0);
 
 	rcar_gen3_enable_vbus_ctrl(ch, 1);
 	rcar_gen3_init_for_host(ch);
 
-	writel(val | USB2_OBINT_BITS, usb2_base + USB2_OBINTEN);
+	rcar_gen3_control_otg_irq(ch, 1);
 }
 
 static bool rcar_gen3_check_id(struct rcar_gen3_chan *ch)
@@ -289,8 +297,7 @@ static void rcar_gen3_init_otg(struct rcar_gen3_chan *ch)
 	val = readl(usb2_base + USB2_VBCTRL);
 	writel(val | USB2_VBCTRL_DRVVBUSSEL, usb2_base + USB2_VBCTRL);
 	writel(USB2_OBINT_BITS, usb2_base + USB2_OBINTSTA);
-	val = readl(usb2_base + USB2_OBINTEN);
-	writel(val | USB2_OBINT_BITS, usb2_base + USB2_OBINTEN);
+	rcar_gen3_control_otg_irq(ch, 1);
 	val = readl(usb2_base + USB2_ADPCTRL);
 	writel(val | USB2_ADPCTRL_IDPULLUP, usb2_base + USB2_ADPCTRL);
 	val = readl(usb2_base + USB2_LINECTRL1);
-- 
2.7.4

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

* [cip-dev] [PATCH 4.19.y-cip 05/12] phy: renesas: rcar-gen3-usb2: add conditions for uses_otg_pins == false
  2019-07-15 14:01 [cip-dev] [PATCH 4.19.y-cip 00/12] Add USB Host support Biju Das
                   ` (3 preceding siblings ...)
  2019-07-15 14:01 ` [cip-dev] [PATCH 4.19.y-cip 04/12] phy: renesas: rcar-gen3-usb2: unify OBINTEN handling Biju Das
@ 2019-07-15 14:01 ` Biju Das
  2019-07-16 12:05   ` Pavel Machek
  2019-07-15 14:01 ` [cip-dev] [PATCH 4.19.y-cip 06/12] phy: renesas: rcar-gen3-usb2: change a condition "dr_mode" Biju Das
                   ` (7 subsequent siblings)
  12 siblings, 1 reply; 20+ messages in thread
From: Biju Das @ 2019-07-15 14:01 UTC (permalink / raw)
  To: cip-dev

From: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>

commit a602152c81a2c1c0daeae56d145d558d52a70dae upstream.

If uses_otg_pins is set to false, this driver 1) should disable otg
related interruptions, and 2) should not get ID pin signal, to avoid
unexpected behaviors. So, this patch adds conditions for it.

Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Reviewed-by: Simon Horman <horms+renesas@verge.net.au>
Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Biju Das <biju.das@bp.renesas.com>
---
 drivers/phy/renesas/phy-rcar-gen3-usb2.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/phy/renesas/phy-rcar-gen3-usb2.c b/drivers/phy/renesas/phy-rcar-gen3-usb2.c
index 575b3d2..4d5cfe5 100644
--- a/drivers/phy/renesas/phy-rcar-gen3-usb2.c
+++ b/drivers/phy/renesas/phy-rcar-gen3-usb2.c
@@ -150,7 +150,7 @@ static void rcar_gen3_control_otg_irq(struct rcar_gen3_chan *ch, int enable)
 	void __iomem *usb2_base = ch->base;
 	u32 val = readl(usb2_base + USB2_OBINTEN);
 
-	if (enable)
+	if (ch->uses_otg_pins && enable)
 		val |= USB2_OBINT_BITS;
 	else
 		val &= ~USB2_OBINT_BITS;
@@ -212,6 +212,9 @@ static void rcar_gen3_init_from_a_peri_to_a_host(struct rcar_gen3_chan *ch)
 
 static bool rcar_gen3_check_id(struct rcar_gen3_chan *ch)
 {
+	if (!ch->uses_otg_pins)
+		return (ch->dr_mode == USB_DR_MODE_HOST) ? false : true;
+
 	return !!(readl(ch->base + USB2_ADPCTRL) & USB2_ADPCTRL_IDDIG);
 }
 
-- 
2.7.4

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

* [cip-dev] [PATCH 4.19.y-cip 06/12] phy: renesas: rcar-gen3-usb2: change a condition "dr_mode"
  2019-07-15 14:01 [cip-dev] [PATCH 4.19.y-cip 00/12] Add USB Host support Biju Das
                   ` (4 preceding siblings ...)
  2019-07-15 14:01 ` [cip-dev] [PATCH 4.19.y-cip 05/12] phy: renesas: rcar-gen3-usb2: add conditions for uses_otg_pins == false Biju Das
@ 2019-07-15 14:01 ` Biju Das
  2019-07-15 14:01 ` [cip-dev] [PATCH 4.19.y-cip 07/12] phy: renesas: rcar-gen3-usb2: add is_otg_channel to use "role" sysfs Biju Das
                   ` (6 subsequent siblings)
  12 siblings, 0 replies; 20+ messages in thread
From: Biju Das @ 2019-07-15 14:01 UTC (permalink / raw)
  To: cip-dev

From: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>

commit 73801b90a38ff1ee89ad38c925fa37fbcb421bfc upstream.

This patch changes a condition about dr_mode. If a device node has
any dr_mode ("host", "peripheral" or "otg"), this driver allows to
set "is_otg_channel" to true. Also, this patch keeps the dr_mode
value for future use.

Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Reviewed-by: Simon Horman <horms+renesas@verge.net.au>
Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Biju Das <biju.das@bp.renesas.com>
---
 drivers/phy/renesas/phy-rcar-gen3-usb2.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/phy/renesas/phy-rcar-gen3-usb2.c b/drivers/phy/renesas/phy-rcar-gen3-usb2.c
index 4d5cfe5..272c9ec 100644
--- a/drivers/phy/renesas/phy-rcar-gen3-usb2.c
+++ b/drivers/phy/renesas/phy-rcar-gen3-usb2.c
@@ -87,6 +87,7 @@ struct rcar_gen3_chan {
 	struct phy *phy;
 	struct regulator *vbus;
 	struct work_struct work;
+	enum usb_dr_mode dr_mode;
 	bool extcon_host;
 	bool uses_otg_pins;
 };
@@ -442,7 +443,8 @@ static int rcar_gen3_phy_usb2_probe(struct platform_device *pdev)
 			dev_err(dev, "No irq handler (%d)\n", irq);
 	}
 
-	if (of_usb_get_dr_mode_by_phy(dev->of_node, 0) == USB_DR_MODE_OTG) {
+	channel->dr_mode = of_usb_get_dr_mode_by_phy(dev->of_node, 0);
+	if (channel->dr_mode != USB_DR_MODE_UNKNOWN) {
 		int ret;
 
 		channel->uses_otg_pins = !of_property_read_bool(dev->of_node,
-- 
2.7.4

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

* [cip-dev] [PATCH 4.19.y-cip 07/12] phy: renesas: rcar-gen3-usb2: add is_otg_channel to use "role" sysfs
  2019-07-15 14:01 [cip-dev] [PATCH 4.19.y-cip 00/12] Add USB Host support Biju Das
                   ` (5 preceding siblings ...)
  2019-07-15 14:01 ` [cip-dev] [PATCH 4.19.y-cip 06/12] phy: renesas: rcar-gen3-usb2: change a condition "dr_mode" Biju Das
@ 2019-07-15 14:01 ` Biju Das
  2019-07-15 14:01 ` [cip-dev] [PATCH 4.19.y-cip 08/12] phy: renesas: rcar-gen3-usb2: follow the hardware manual procedure Biju Das
                   ` (5 subsequent siblings)
  12 siblings, 0 replies; 20+ messages in thread
From: Biju Das @ 2019-07-15 14:01 UTC (permalink / raw)
  To: cip-dev

From: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>

commit 979b519c7a1bff56a212bf80cc04ae9b4131ea43 upstream.

Even if a board doesn't have otg pins connection, this hardware can
change the role by a register setting. So, this patch adds
"is_otg_channel" for it.

Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Reviewed-by: Simon Horman <horms+renesas@verge.net.au>
Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Biju Das <biju.das@bp.renesas.com>
---
 drivers/phy/renesas/phy-rcar-gen3-usb2.c | 23 ++++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)

diff --git a/drivers/phy/renesas/phy-rcar-gen3-usb2.c b/drivers/phy/renesas/phy-rcar-gen3-usb2.c
index 272c9ec..16481cfd 100644
--- a/drivers/phy/renesas/phy-rcar-gen3-usb2.c
+++ b/drivers/phy/renesas/phy-rcar-gen3-usb2.c
@@ -89,9 +89,21 @@ struct rcar_gen3_chan {
 	struct work_struct work;
 	enum usb_dr_mode dr_mode;
 	bool extcon_host;
+	bool is_otg_channel;
 	bool uses_otg_pins;
 };
 
+/*
+ * Combination about is_otg_channel and uses_otg_pins:
+ *
+ * Parameters				|| Behaviors
+ * is_otg_channel	| uses_otg_pins	|| irqs		| role sysfs
+ * ---------------------+---------------++--------------+------------
+ * true			| true		|| enabled	| enabled
+ * true                 | false		|| disabled	| enabled
+ * false                | any		|| disabled	| disabled
+ */
+
 static void rcar_gen3_phy_usb2_work(struct work_struct *work)
 {
 	struct rcar_gen3_chan *ch = container_of(work, struct rcar_gen3_chan,
@@ -247,7 +259,7 @@ static ssize_t role_store(struct device *dev, struct device_attribute *attr,
 	bool is_b_device;
 	enum phy_mode cur_mode, new_mode;
 
-	if (!ch->uses_otg_pins || !ch->phy->init_count)
+	if (!ch->is_otg_channel || !ch->phy->init_count)
 		return -EIO;
 
 	if (!strncmp(buf, "host", strlen("host")))
@@ -285,7 +297,7 @@ static ssize_t role_show(struct device *dev, struct device_attribute *attr,
 {
 	struct rcar_gen3_chan *ch = dev_get_drvdata(dev);
 
-	if (!ch->uses_otg_pins || !ch->phy->init_count)
+	if (!ch->is_otg_channel || !ch->phy->init_count)
 		return -EIO;
 
 	return sprintf(buf, "%s\n", rcar_gen3_is_host(ch) ? "host" :
@@ -323,7 +335,7 @@ static int rcar_gen3_phy_usb2_init(struct phy *p)
 	writel(USB2_OC_TIMSET_INIT, usb2_base + USB2_OC_TIMSET);
 
 	/* Initialize otg part */
-	if (channel->uses_otg_pins)
+	if (channel->is_otg_channel)
 		rcar_gen3_init_otg(channel);
 
 	return 0;
@@ -447,6 +459,7 @@ static int rcar_gen3_phy_usb2_probe(struct platform_device *pdev)
 	if (channel->dr_mode != USB_DR_MODE_UNKNOWN) {
 		int ret;
 
+		channel->is_otg_channel = true;
 		channel->uses_otg_pins = !of_property_read_bool(dev->of_node,
 							"renesas,no-otg-pins");
 		channel->extcon = devm_extcon_dev_allocate(dev,
@@ -490,7 +503,7 @@ static int rcar_gen3_phy_usb2_probe(struct platform_device *pdev)
 		dev_err(dev, "Failed to register PHY provider\n");
 		ret = PTR_ERR(provider);
 		goto error;
-	} else if (channel->uses_otg_pins) {
+	} else if (channel->is_otg_channel) {
 		int ret;
 
 		ret = device_create_file(dev, &dev_attr_role);
@@ -510,7 +523,7 @@ static int rcar_gen3_phy_usb2_remove(struct platform_device *pdev)
 {
 	struct rcar_gen3_chan *channel = platform_get_drvdata(pdev);
 
-	if (channel->uses_otg_pins)
+	if (channel->is_otg_channel)
 		device_remove_file(&pdev->dev, &dev_attr_role);
 
 	pm_runtime_disable(&pdev->dev);
-- 
2.7.4

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

* [cip-dev] [PATCH 4.19.y-cip 08/12] phy: renesas: rcar-gen3-usb2: follow the hardware manual procedure
  2019-07-15 14:01 [cip-dev] [PATCH 4.19.y-cip 00/12] Add USB Host support Biju Das
                   ` (6 preceding siblings ...)
  2019-07-15 14:01 ` [cip-dev] [PATCH 4.19.y-cip 07/12] phy: renesas: rcar-gen3-usb2: add is_otg_channel to use "role" sysfs Biju Das
@ 2019-07-15 14:01 ` Biju Das
  2019-07-16 12:18   ` Pavel Machek
  2019-07-15 14:01 ` [cip-dev] [PATCH 4.19.y-cip 09/12] phy: rcar-gen3-usb2: Add support for r8a77470 Biju Das
                   ` (4 subsequent siblings)
  12 siblings, 1 reply; 20+ messages in thread
From: Biju Das @ 2019-07-15 14:01 UTC (permalink / raw)
  To: cip-dev

From: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>

commit 72c0339c115b31b3c0b22b1809854136cadd49be upstream.

This patch modifies rcar_gen3_init_otg() procedure to follow Figure
73.4 of "R-Car Series, 3rd Generation User's Manual: Hardware Rev.1.00".

Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Biju Das <biju.das@bp.renesas.com>
---
 drivers/phy/renesas/phy-rcar-gen3-usb2.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/drivers/phy/renesas/phy-rcar-gen3-usb2.c b/drivers/phy/renesas/phy-rcar-gen3-usb2.c
index 16481cfd..685d56c 100644
--- a/drivers/phy/renesas/phy-rcar-gen3-usb2.c
+++ b/drivers/phy/renesas/phy-rcar-gen3-usb2.c
@@ -310,16 +310,21 @@ static void rcar_gen3_init_otg(struct rcar_gen3_chan *ch)
 	void __iomem *usb2_base = ch->base;
 	u32 val;
 
+	/* Should not use functions of read-modify-write a register */
+	val = readl(usb2_base + USB2_LINECTRL1);
+	val = (val & ~USB2_LINECTRL1_DP_RPD) | USB2_LINECTRL1_DPRPD_EN |
+	      USB2_LINECTRL1_DMRPD_EN | USB2_LINECTRL1_DM_RPD;
+	writel(val, usb2_base + USB2_LINECTRL1);
+
 	val = readl(usb2_base + USB2_VBCTRL);
 	writel(val | USB2_VBCTRL_DRVVBUSSEL, usb2_base + USB2_VBCTRL);
-	writel(USB2_OBINT_BITS, usb2_base + USB2_OBINTSTA);
-	rcar_gen3_control_otg_irq(ch, 1);
 	val = readl(usb2_base + USB2_ADPCTRL);
 	writel(val | USB2_ADPCTRL_IDPULLUP, usb2_base + USB2_ADPCTRL);
-	val = readl(usb2_base + USB2_LINECTRL1);
-	rcar_gen3_set_linectrl(ch, 0, 0);
-	writel(val | USB2_LINECTRL1_DPRPD_EN | USB2_LINECTRL1_DMRPD_EN,
-	       usb2_base + USB2_LINECTRL1);
+
+	msleep(20);
+
+	writel(0xffffffff, usb2_base + USB2_OBINTSTA);
+	writel(USB2_OBINT_BITS, usb2_base + USB2_OBINTEN);
 
 	rcar_gen3_device_recognition(ch);
 }
-- 
2.7.4

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

* [cip-dev] [PATCH 4.19.y-cip 09/12] phy: rcar-gen3-usb2: Add support for r8a77470
  2019-07-15 14:01 [cip-dev] [PATCH 4.19.y-cip 00/12] Add USB Host support Biju Das
                   ` (7 preceding siblings ...)
  2019-07-15 14:01 ` [cip-dev] [PATCH 4.19.y-cip 08/12] phy: renesas: rcar-gen3-usb2: follow the hardware manual procedure Biju Das
@ 2019-07-15 14:01 ` Biju Das
  2019-07-15 14:01 ` [cip-dev] [PATCH 4.19.y-cip 10/12] phy: renesas: rcar-gen3-usb2: Use pdev's device pointer on dev_vdbg() Biju Das
                   ` (3 subsequent siblings)
  12 siblings, 0 replies; 20+ messages in thread
From: Biju Das @ 2019-07-15 14:01 UTC (permalink / raw)
  To: cip-dev

commit 5d8042e95fd471d0e342cf14f127194f1a867a01 upstream.

This patch adds support for r8a77470 (RZ/G1C). We can reuse this driver for
initializing timing/interrupt generation registers.

Signed-off-by: Biju Das <biju.das@bp.renesas.com>
Reviewed-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
---
 drivers/phy/renesas/Kconfig              |  2 +-
 drivers/phy/renesas/phy-rcar-gen3-usb2.c | 39 +++++++++++++++++++++++++++-----
 2 files changed, 34 insertions(+), 7 deletions(-)

diff --git a/drivers/phy/renesas/Kconfig b/drivers/phy/renesas/Kconfig
index 4bd390c..7bc62d2 100644
--- a/drivers/phy/renesas/Kconfig
+++ b/drivers/phy/renesas/Kconfig
@@ -18,7 +18,7 @@ config PHY_RCAR_GEN3_PCIE
 config PHY_RCAR_GEN3_USB2
 	tristate "Renesas R-Car generation 3 USB 2.0 PHY driver"
 	depends on ARCH_RENESAS
-	depends on EXTCON
+	depends on EXTCON || !EXTCON # if EXTCON=m, this cannot be built-in
 	depends on USB_SUPPORT
 	select GENERIC_PHY
 	select USB_COMMON
diff --git a/drivers/phy/renesas/phy-rcar-gen3-usb2.c b/drivers/phy/renesas/phy-rcar-gen3-usb2.c
index 685d56c..37cb619 100644
--- a/drivers/phy/renesas/phy-rcar-gen3-usb2.c
+++ b/drivers/phy/renesas/phy-rcar-gen3-usb2.c
@@ -396,6 +396,12 @@ static const struct phy_ops rcar_gen3_phy_usb2_ops = {
 	.owner		= THIS_MODULE,
 };
 
+static const struct phy_ops rz_g1c_phy_usb2_ops = {
+	.init		= rcar_gen3_phy_usb2_init,
+	.exit		= rcar_gen3_phy_usb2_exit,
+	.owner		= THIS_MODULE,
+};
+
 static irqreturn_t rcar_gen3_phy_usb2_irq(int irq, void *_ch)
 {
 	struct rcar_gen3_chan *ch = _ch;
@@ -414,11 +420,27 @@ static irqreturn_t rcar_gen3_phy_usb2_irq(int irq, void *_ch)
 }
 
 static const struct of_device_id rcar_gen3_phy_usb2_match_table[] = {
-	{ .compatible = "renesas,usb2-phy-r8a7795" },
-	{ .compatible = "renesas,usb2-phy-r8a7796" },
-	{ .compatible = "renesas,usb2-phy-r8a77965" },
-	{ .compatible = "renesas,rcar-gen3-usb2-phy" },
-	{ }
+	{
+		.compatible = "renesas,usb2-phy-r8a77470",
+		.data = &rz_g1c_phy_usb2_ops,
+	},
+	{
+		.compatible = "renesas,usb2-phy-r8a7795",
+		.data = &rcar_gen3_phy_usb2_ops,
+	},
+	{
+		.compatible = "renesas,usb2-phy-r8a7796",
+		.data = &rcar_gen3_phy_usb2_ops,
+	},
+	{
+		.compatible = "renesas,usb2-phy-r8a77965",
+		.data = &rcar_gen3_phy_usb2_ops,
+	},
+	{
+		.compatible = "renesas,rcar-gen3-usb2-phy",
+		.data = &rcar_gen3_phy_usb2_ops,
+	},
+	{ /* sentinel */ },
 };
 MODULE_DEVICE_TABLE(of, rcar_gen3_phy_usb2_match_table);
 
@@ -434,6 +456,7 @@ static int rcar_gen3_phy_usb2_probe(struct platform_device *pdev)
 	struct rcar_gen3_chan *channel;
 	struct phy_provider *provider;
 	struct resource *res;
+	const struct phy_ops *phy_usb2_ops;
 	int irq, ret = 0;
 
 	if (!dev->of_node) {
@@ -484,7 +507,11 @@ static int rcar_gen3_phy_usb2_probe(struct platform_device *pdev)
 	 * And then, phy-core will manage runtime pm for this device.
 	 */
 	pm_runtime_enable(dev);
-	channel->phy = devm_phy_create(dev, NULL, &rcar_gen3_phy_usb2_ops);
+	phy_usb2_ops = of_device_get_match_data(dev);
+	if (!phy_usb2_ops)
+		return -EINVAL;
+
+	channel->phy = devm_phy_create(dev, NULL, phy_usb2_ops);
 	if (IS_ERR(channel->phy)) {
 		dev_err(dev, "Failed to create USB2 PHY\n");
 		ret = PTR_ERR(channel->phy);
-- 
2.7.4

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

* [cip-dev] [PATCH 4.19.y-cip 10/12] phy: renesas: rcar-gen3-usb2: Use pdev's device pointer on dev_vdbg()
  2019-07-15 14:01 [cip-dev] [PATCH 4.19.y-cip 00/12] Add USB Host support Biju Das
                   ` (8 preceding siblings ...)
  2019-07-15 14:01 ` [cip-dev] [PATCH 4.19.y-cip 09/12] phy: rcar-gen3-usb2: Add support for r8a77470 Biju Das
@ 2019-07-15 14:01 ` Biju Das
  2019-07-15 14:01 ` [cip-dev] [PATCH 4.19.y-cip 11/12] phy: renesas: rcar-gen3-usb2: enable/disable independent irqs Biju Das
                   ` (2 subsequent siblings)
  12 siblings, 0 replies; 20+ messages in thread
From: Biju Das @ 2019-07-15 14:01 UTC (permalink / raw)
  To: cip-dev

From: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>

commit 92fec1c27caa7b6f2a70566625425190e14c2204 upstream.

To implement multiple phy instances in the future, this patch uses
pdev's device pointer on dev_vdbg() instead of the phy's device
pointer.

Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Reviewed-by: Simon Horman <horms+renesas@verge.net.au>
Reviewed-by: Fabrizio Castro <fabrizio.castro@bp.renesas.com>
Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Biju Das <biju.das@bp.renesas.com>
---
 drivers/phy/renesas/phy-rcar-gen3-usb2.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/phy/renesas/phy-rcar-gen3-usb2.c b/drivers/phy/renesas/phy-rcar-gen3-usb2.c
index 37cb619..40378da 100644
--- a/drivers/phy/renesas/phy-rcar-gen3-usb2.c
+++ b/drivers/phy/renesas/phy-rcar-gen3-usb2.c
@@ -83,6 +83,7 @@
 
 struct rcar_gen3_chan {
 	void __iomem *base;
+	struct device *dev;	/* platform_device's device */
 	struct extcon_dev *extcon;
 	struct phy *phy;
 	struct regulator *vbus;
@@ -123,7 +124,7 @@ static void rcar_gen3_set_host_mode(struct rcar_gen3_chan *ch, int host)
 	void __iomem *usb2_base = ch->base;
 	u32 val = readl(usb2_base + USB2_COMMCTRL);
 
-	dev_vdbg(&ch->phy->dev, "%s: %08x, %d\n", __func__, val, host);
+	dev_vdbg(ch->dev, "%s: %08x, %d\n", __func__, val, host);
 	if (host)
 		val &= ~USB2_COMMCTRL_OTG_PERI;
 	else
@@ -136,7 +137,7 @@ static void rcar_gen3_set_linectrl(struct rcar_gen3_chan *ch, int dp, int dm)
 	void __iomem *usb2_base = ch->base;
 	u32 val = readl(usb2_base + USB2_LINECTRL1);
 
-	dev_vdbg(&ch->phy->dev, "%s: %08x, %d, %d\n", __func__, val, dp, dm);
+	dev_vdbg(ch->dev, "%s: %08x, %d, %d\n", __func__, val, dp, dm);
 	val &= ~(USB2_LINECTRL1_DP_RPD | USB2_LINECTRL1_DM_RPD);
 	if (dp)
 		val |= USB2_LINECTRL1_DP_RPD;
@@ -150,7 +151,7 @@ static void rcar_gen3_enable_vbus_ctrl(struct rcar_gen3_chan *ch, int vbus)
 	void __iomem *usb2_base = ch->base;
 	u32 val = readl(usb2_base + USB2_ADPCTRL);
 
-	dev_vdbg(&ch->phy->dev, "%s: %08x, %d\n", __func__, val, vbus);
+	dev_vdbg(ch->dev, "%s: %08x, %d\n", __func__, val, vbus);
 	if (vbus)
 		val |= USB2_ADPCTRL_DRVVBUS;
 	else
@@ -410,7 +411,7 @@ static irqreturn_t rcar_gen3_phy_usb2_irq(int irq, void *_ch)
 	irqreturn_t ret = IRQ_NONE;
 
 	if (status & USB2_OBINT_BITS) {
-		dev_vdbg(&ch->phy->dev, "%s: %08x\n", __func__, status);
+		dev_vdbg(ch->dev, "%s: %08x\n", __func__, status);
 		writel(USB2_OBINT_BITS, usb2_base + USB2_OBINTSTA);
 		rcar_gen3_device_recognition(ch);
 		ret = IRQ_HANDLED;
@@ -529,6 +530,7 @@ static int rcar_gen3_phy_usb2_probe(struct platform_device *pdev)
 
 	platform_set_drvdata(pdev, channel);
 	phy_set_drvdata(channel->phy, channel);
+	channel->dev = dev;
 
 	provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
 	if (IS_ERR(provider)) {
-- 
2.7.4

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

* [cip-dev] [PATCH 4.19.y-cip 11/12] phy: renesas: rcar-gen3-usb2: enable/disable independent irqs
  2019-07-15 14:01 [cip-dev] [PATCH 4.19.y-cip 00/12] Add USB Host support Biju Das
                   ` (9 preceding siblings ...)
  2019-07-15 14:01 ` [cip-dev] [PATCH 4.19.y-cip 10/12] phy: renesas: rcar-gen3-usb2: Use pdev's device pointer on dev_vdbg() Biju Das
@ 2019-07-15 14:01 ` Biju Das
  2019-07-15 14:01 ` [cip-dev] [PATCH 4.19.y-cip 12/12] arm64: dts: renesas: cat874: Add USB-HOST support Biju Das
  2019-07-16 16:46 ` [cip-dev] [PATCH 4.19.y-cip 00/12] Add USB Host support Pavel Machek
  12 siblings, 0 replies; 20+ messages in thread
From: Biju Das @ 2019-07-15 14:01 UTC (permalink / raw)
  To: cip-dev

From: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>

commit 549b6b55b00558183cef4af2c2bb61d4f2ffe508 upstream.

Since the previous code enabled/disabled the irqs both OHCI and EHCI,
it is possible to cause unexpected interruptions. To avoid this,
this patch creates multiple phy instances from phandle and
enables/disables independent irqs by the instances.

Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Reviewed-by: Simon Horman <horms+renesas@verge.net.au>
Reviewed-by: Fabrizio Castro <fabrizio.castro@bp.renesas.com>
Tested-by: Fabrizio Castro <fabrizio.castro@bp.renesas.com>
Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Biju Das <biju.das@bp.renesas.com>
---
 drivers/phy/renesas/phy-rcar-gen3-usb2.c | 185 ++++++++++++++++++++++++++-----
 1 file changed, 160 insertions(+), 25 deletions(-)

diff --git a/drivers/phy/renesas/phy-rcar-gen3-usb2.c b/drivers/phy/renesas/phy-rcar-gen3-usb2.c
index 40378da..132ca20 100644
--- a/drivers/phy/renesas/phy-rcar-gen3-usb2.c
+++ b/drivers/phy/renesas/phy-rcar-gen3-usb2.c
@@ -40,11 +40,8 @@
 
 /* INT_ENABLE */
 #define USB2_INT_ENABLE_UCOM_INTEN	BIT(3)
-#define USB2_INT_ENABLE_USBH_INTB_EN	BIT(2)
-#define USB2_INT_ENABLE_USBH_INTA_EN	BIT(1)
-#define USB2_INT_ENABLE_INIT		(USB2_INT_ENABLE_UCOM_INTEN | \
-					 USB2_INT_ENABLE_USBH_INTB_EN | \
-					 USB2_INT_ENABLE_USBH_INTA_EN)
+#define USB2_INT_ENABLE_USBH_INTB_EN	BIT(2)	/* For EHCI */
+#define USB2_INT_ENABLE_USBH_INTA_EN	BIT(1)	/* For OHCI */
 
 /* USBCTR */
 #define USB2_USBCTR_DIRPD	BIT(2)
@@ -81,11 +78,35 @@
 #define USB2_ADPCTRL_IDPULLUP		BIT(5)	/* 1 = ID sampling is enabled */
 #define USB2_ADPCTRL_DRVVBUS		BIT(4)
 
+#define NUM_OF_PHYS			4
+enum rcar_gen3_phy_index {
+	PHY_INDEX_BOTH_HC,
+	PHY_INDEX_OHCI,
+	PHY_INDEX_EHCI,
+	PHY_INDEX_HSUSB
+};
+
+static const u32 rcar_gen3_int_enable[NUM_OF_PHYS] = {
+	USB2_INT_ENABLE_USBH_INTB_EN | USB2_INT_ENABLE_USBH_INTA_EN,
+	USB2_INT_ENABLE_USBH_INTA_EN,
+	USB2_INT_ENABLE_USBH_INTB_EN,
+	0
+};
+
+struct rcar_gen3_phy {
+	struct phy *phy;
+	struct rcar_gen3_chan *ch;
+	u32 int_enable_bits;
+	bool initialized;
+	bool otg_initialized;
+	bool powered;
+};
+
 struct rcar_gen3_chan {
 	void __iomem *base;
 	struct device *dev;	/* platform_device's device */
 	struct extcon_dev *extcon;
-	struct phy *phy;
+	struct rcar_gen3_phy rphys[NUM_OF_PHYS];
 	struct regulator *vbus;
 	struct work_struct work;
 	enum usb_dr_mode dr_mode;
@@ -253,6 +274,42 @@ static enum phy_mode rcar_gen3_get_phy_mode(struct rcar_gen3_chan *ch)
 	return PHY_MODE_USB_DEVICE;
 }
 
+static bool rcar_gen3_is_any_rphy_initialized(struct rcar_gen3_chan *ch)
+{
+	int i;
+
+	for (i = 0; i < NUM_OF_PHYS; i++) {
+		if (ch->rphys[i].initialized)
+			return true;
+	}
+
+	return false;
+}
+
+static bool rcar_gen3_needs_init_otg(struct rcar_gen3_chan *ch)
+{
+	int i;
+
+	for (i = 0; i < NUM_OF_PHYS; i++) {
+		if (ch->rphys[i].otg_initialized)
+			return false;
+	}
+
+	return true;
+}
+
+static bool rcar_gen3_are_all_rphys_power_off(struct rcar_gen3_chan *ch)
+{
+	int i;
+
+	for (i = 0; i < NUM_OF_PHYS; i++) {
+		if (ch->rphys[i].powered)
+			return false;
+	}
+
+	return true;
+}
+
 static ssize_t role_store(struct device *dev, struct device_attribute *attr,
 			  const char *buf, size_t count)
 {
@@ -260,7 +317,7 @@ static ssize_t role_store(struct device *dev, struct device_attribute *attr,
 	bool is_b_device;
 	enum phy_mode cur_mode, new_mode;
 
-	if (!ch->is_otg_channel || !ch->phy->init_count)
+	if (!ch->is_otg_channel || !rcar_gen3_is_any_rphy_initialized(ch))
 		return -EIO;
 
 	if (!strncmp(buf, "host", strlen("host")))
@@ -298,7 +355,7 @@ static ssize_t role_show(struct device *dev, struct device_attribute *attr,
 {
 	struct rcar_gen3_chan *ch = dev_get_drvdata(dev);
 
-	if (!ch->is_otg_channel || !ch->phy->init_count)
+	if (!ch->is_otg_channel || !rcar_gen3_is_any_rphy_initialized(ch))
 		return -EIO;
 
 	return sprintf(buf, "%s\n", rcar_gen3_is_host(ch) ? "host" :
@@ -332,37 +389,62 @@ static void rcar_gen3_init_otg(struct rcar_gen3_chan *ch)
 
 static int rcar_gen3_phy_usb2_init(struct phy *p)
 {
-	struct rcar_gen3_chan *channel = phy_get_drvdata(p);
+	struct rcar_gen3_phy *rphy = phy_get_drvdata(p);
+	struct rcar_gen3_chan *channel = rphy->ch;
 	void __iomem *usb2_base = channel->base;
+	u32 val;
 
 	/* Initialize USB2 part */
-	writel(USB2_INT_ENABLE_INIT, usb2_base + USB2_INT_ENABLE);
+	val = readl(usb2_base + USB2_INT_ENABLE);
+	val |= USB2_INT_ENABLE_UCOM_INTEN | rphy->int_enable_bits;
+	writel(val, usb2_base + USB2_INT_ENABLE);
 	writel(USB2_SPD_RSM_TIMSET_INIT, usb2_base + USB2_SPD_RSM_TIMSET);
 	writel(USB2_OC_TIMSET_INIT, usb2_base + USB2_OC_TIMSET);
 
 	/* Initialize otg part */
-	if (channel->is_otg_channel)
-		rcar_gen3_init_otg(channel);
+	if (channel->is_otg_channel) {
+		if (rcar_gen3_needs_init_otg(channel))
+			rcar_gen3_init_otg(channel);
+		rphy->otg_initialized = true;
+	}
+
+	rphy->initialized = true;
 
 	return 0;
 }
 
 static int rcar_gen3_phy_usb2_exit(struct phy *p)
 {
-	struct rcar_gen3_chan *channel = phy_get_drvdata(p);
+	struct rcar_gen3_phy *rphy = phy_get_drvdata(p);
+	struct rcar_gen3_chan *channel = rphy->ch;
+	void __iomem *usb2_base = channel->base;
+	u32 val;
+
+	rphy->initialized = false;
 
-	writel(0, channel->base + USB2_INT_ENABLE);
+	if (channel->is_otg_channel)
+		rphy->otg_initialized = false;
+
+	val = readl(usb2_base + USB2_INT_ENABLE);
+	val &= ~rphy->int_enable_bits;
+	if (!rcar_gen3_is_any_rphy_initialized(channel))
+		val &= ~USB2_INT_ENABLE_UCOM_INTEN;
+	writel(val, usb2_base + USB2_INT_ENABLE);
 
 	return 0;
 }
 
 static int rcar_gen3_phy_usb2_power_on(struct phy *p)
 {
-	struct rcar_gen3_chan *channel = phy_get_drvdata(p);
+	struct rcar_gen3_phy *rphy = phy_get_drvdata(p);
+	struct rcar_gen3_chan *channel = rphy->ch;
 	void __iomem *usb2_base = channel->base;
 	u32 val;
 	int ret;
 
+	if (!rcar_gen3_are_all_rphys_power_off(channel))
+		return 0;
+
 	if (channel->vbus) {
 		ret = regulator_enable(channel->vbus);
 		if (ret)
@@ -375,14 +457,22 @@ static int rcar_gen3_phy_usb2_power_on(struct phy *p)
 	val &= ~USB2_USBCTR_PLL_RST;
 	writel(val, usb2_base + USB2_USBCTR);
 
+	rphy->powered = true;
+
 	return 0;
 }
 
 static int rcar_gen3_phy_usb2_power_off(struct phy *p)
 {
-	struct rcar_gen3_chan *channel = phy_get_drvdata(p);
+	struct rcar_gen3_phy *rphy = phy_get_drvdata(p);
+	struct rcar_gen3_chan *channel = rphy->ch;
 	int ret = 0;
 
+	rphy->powered = false;
+
+	if (!rcar_gen3_are_all_rphys_power_off(channel))
+		return 0;
+
 	if (channel->vbus)
 		ret = regulator_disable(channel->vbus);
 
@@ -451,6 +541,46 @@ static const unsigned int rcar_gen3_phy_cable[] = {
 	EXTCON_NONE,
 };
 
+static struct phy *rcar_gen3_phy_usb2_xlate(struct device *dev,
+					    struct of_phandle_args *args)
+{
+	struct rcar_gen3_chan *ch = dev_get_drvdata(dev);
+
+	if (args->args_count == 0)	/* For old version dts */
+		return ch->rphys[PHY_INDEX_BOTH_HC].phy;
+	else if (args->args_count > 1)	/* Prevent invalid args count */
+		return ERR_PTR(-ENODEV);
+
+	if (args->args[0] >= NUM_OF_PHYS)
+		return ERR_PTR(-ENODEV);
+
+	return ch->rphys[args->args[0]].phy;
+}
+
+static enum usb_dr_mode rcar_gen3_get_dr_mode(struct device_node *np)
+{
+	enum usb_dr_mode candidate = USB_DR_MODE_UNKNOWN;
+	int i;
+
+	/*
+	 * If one of device nodes has other dr_mode except UNKNOWN,
+	 * this function returns UNKNOWN. To achieve backward compatibility,
+	 * this loop starts the index as 0.
+	 */
+	for (i = 0; i < NUM_OF_PHYS; i++) {
+		enum usb_dr_mode mode = of_usb_get_dr_mode_by_phy(np, i);
+
+		if (mode != USB_DR_MODE_UNKNOWN) {
+			if (candidate == USB_DR_MODE_UNKNOWN)
+				candidate = mode;
+			else if (candidate != mode)
+				return USB_DR_MODE_UNKNOWN;
+		}
+	}
+
+	return candidate;
+}
+
 static int rcar_gen3_phy_usb2_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
@@ -458,7 +588,7 @@ static int rcar_gen3_phy_usb2_probe(struct platform_device *pdev)
 	struct phy_provider *provider;
 	struct resource *res;
 	const struct phy_ops *phy_usb2_ops;
-	int irq, ret = 0;
+	int irq, ret = 0, i;
 
 	if (!dev->of_node) {
 		dev_err(dev, "This driver needs device tree\n");
@@ -484,7 +614,7 @@ static int rcar_gen3_phy_usb2_probe(struct platform_device *pdev)
 			dev_err(dev, "No irq handler (%d)\n", irq);
 	}
 
-	channel->dr_mode = of_usb_get_dr_mode_by_phy(dev->of_node, 0);
+	channel->dr_mode = rcar_gen3_get_dr_mode(dev->of_node);
 	if (channel->dr_mode != USB_DR_MODE_UNKNOWN) {
 		int ret;
 
@@ -512,11 +642,17 @@ static int rcar_gen3_phy_usb2_probe(struct platform_device *pdev)
 	if (!phy_usb2_ops)
 		return -EINVAL;
 
-	channel->phy = devm_phy_create(dev, NULL, phy_usb2_ops);
-	if (IS_ERR(channel->phy)) {
-		dev_err(dev, "Failed to create USB2 PHY\n");
-		ret = PTR_ERR(channel->phy);
-		goto error;
+	for (i = 0; i < NUM_OF_PHYS; i++) {
+		channel->rphys[i].phy = devm_phy_create(dev, NULL,
+							phy_usb2_ops);
+		if (IS_ERR(channel->rphys[i].phy)) {
+			dev_err(dev, "Failed to create USB2 PHY\n");
+			ret = PTR_ERR(channel->rphys[i].phy);
+			goto error;
+		}
+		channel->rphys[i].ch = channel;
+		channel->rphys[i].int_enable_bits = rcar_gen3_int_enable[i];
+		phy_set_drvdata(channel->rphys[i].phy, &channel->rphys[i]);
 	}
 
 	channel->vbus = devm_regulator_get_optional(dev, "vbus");
@@ -529,10 +665,9 @@ static int rcar_gen3_phy_usb2_probe(struct platform_device *pdev)
 	}
 
 	platform_set_drvdata(pdev, channel);
-	phy_set_drvdata(channel->phy, channel);
 	channel->dev = dev;
 
-	provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
+	provider = devm_of_phy_provider_register(dev, rcar_gen3_phy_usb2_xlate);
 	if (IS_ERR(provider)) {
 		dev_err(dev, "Failed to register PHY provider\n");
 		ret = PTR_ERR(provider);
-- 
2.7.4

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

* [cip-dev] [PATCH 4.19.y-cip 12/12] arm64: dts: renesas: cat874: Add USB-HOST support
  2019-07-15 14:01 [cip-dev] [PATCH 4.19.y-cip 00/12] Add USB Host support Biju Das
                   ` (10 preceding siblings ...)
  2019-07-15 14:01 ` [cip-dev] [PATCH 4.19.y-cip 11/12] phy: renesas: rcar-gen3-usb2: enable/disable independent irqs Biju Das
@ 2019-07-15 14:01 ` Biju Das
  2019-07-16 16:46 ` [cip-dev] [PATCH 4.19.y-cip 00/12] Add USB Host support Pavel Machek
  12 siblings, 0 replies; 20+ messages in thread
From: Biju Das @ 2019-07-15 14:01 UTC (permalink / raw)
  To: cip-dev

commit ad68fa5fe8c12262cf4156b8e0726117aa3be8c8 upstream.

This patch adds USB 2.0 HOST support to the CAT874 board.

Signed-off-by: Fabrizio Castro <fabrizio.castro@bp.renesas.com>
Signed-off-by: Simon Horman <horms+renesas@verge.net.au>
Signed-off-by: Biju Das <biju.das@bp.renesas.com>
---
 arch/arm64/boot/dts/renesas/r8a774c0-cat874.dts | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/arch/arm64/boot/dts/renesas/r8a774c0-cat874.dts b/arch/arm64/boot/dts/renesas/r8a774c0-cat874.dts
index 96ee0d2c..4333af8 100644
--- a/arch/arm64/boot/dts/renesas/r8a774c0-cat874.dts
+++ b/arch/arm64/boot/dts/renesas/r8a774c0-cat874.dts
@@ -52,10 +52,20 @@
 	};
 };
 
+&ehci0 {
+	dr_mode = "host";
+	status = "okay";
+};
+
 &extal_clk {
 	clock-frequency = <48000000>;
 };
 
+&ohci0 {
+	dr_mode = "host";
+	status = "okay";
+};
+
 &pcie_bus_clk {
 	clock-frequency = <100000000>;
 };
@@ -104,3 +114,8 @@
 	sd-uhs-sdr104;
 	status = "okay";
 };
+
+&usb2_phy0 {
+	renesas,no-otg-pins;
+	status = "okay";
+};
-- 
2.7.4

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

* [cip-dev] [PATCH 4.19.y-cip 04/12] phy: renesas: rcar-gen3-usb2: unify OBINTEN handling
  2019-07-15 14:01 ` [cip-dev] [PATCH 4.19.y-cip 04/12] phy: renesas: rcar-gen3-usb2: unify OBINTEN handling Biju Das
@ 2019-07-16 12:03   ` Pavel Machek
  2019-07-16 12:57     ` Biju Das
  0 siblings, 1 reply; 20+ messages in thread
From: Pavel Machek @ 2019-07-16 12:03 UTC (permalink / raw)
  To: cip-dev

Hi!

> commit 7ab0305d4d7725699169e21cdc4f6c8759c32feb upstream.
> 
> This patch unifies the OBINTEN handling to clean-up the code.


> @@ -145,6 +145,18 @@ static void rcar_gen3_enable_vbus_ctrl(struct rcar_gen3_chan *ch, int vbus)
>  	writel(val, usb2_base + USB2_ADPCTRL);
>  }
>  
> +static void rcar_gen3_control_otg_irq(struct rcar_gen3_chan *ch, int enable)
> +{
> +	void __iomem *usb2_base = ch->base;
> +	u32 val = readl(usb2_base + USB2_OBINTEN);
> +
> +	if (enable)
> +		val |= USB2_OBINT_BITS;
> +	else
> +		val &= ~USB2_OBINT_BITS;
> +	writel(val, usb2_base + USB2_OBINTEN);
> +}
> +
>  
>  static void rcar_gen3_init_from_a_peri_to_a_host(struct rcar_gen3_chan *ch)
>  {
> -	void __iomem *usb2_base = ch->base;
> -	u32 val;
> -
> -	val = readl(usb2_base + USB2_OBINTEN);
> -	writel(val & ~USB2_OBINT_BITS, usb2_base + USB2_OBINTEN);
> +	rcar_gen3_control_otg_irq(ch, 0);
>  
>  	rcar_gen3_enable_vbus_ctrl(ch, 1);
>  	rcar_gen3_init_for_host(ch);
>  
> -	writel(val | USB2_OBINT_BITS, usb2_base + USB2_OBINTEN);
> +	rcar_gen3_control_otg_irq(ch, 1);
>  }

This actually removes optimalization: old code would avoid
reading USB2_OBINTEN twice. I guess it is not a problem.

Best regards,
									Pavel
-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <http://lists.cip-project.org/pipermail/cip-dev/attachments/20190716/f4dbd9c4/attachment.sig>

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

* [cip-dev] [PATCH 4.19.y-cip 05/12] phy: renesas: rcar-gen3-usb2: add conditions for uses_otg_pins == false
  2019-07-15 14:01 ` [cip-dev] [PATCH 4.19.y-cip 05/12] phy: renesas: rcar-gen3-usb2: add conditions for uses_otg_pins == false Biju Das
@ 2019-07-16 12:05   ` Pavel Machek
  2019-07-16 12:50     ` Biju Das
  0 siblings, 1 reply; 20+ messages in thread
From: Pavel Machek @ 2019-07-16 12:05 UTC (permalink / raw)
  To: cip-dev

Hi!

> @@ -212,6 +212,9 @@ static void rcar_gen3_init_from_a_peri_to_a_host(struct rcar_gen3_chan *ch)
>  
>  static bool rcar_gen3_check_id(struct rcar_gen3_chan *ch)
>  {
> +	if (!ch->uses_otg_pins)
> +		return (ch->dr_mode == USB_DR_MODE_HOST) ? false : true;

I'd write this as

    "return ch->dr_mode != USB_DR_MODE_HOST;"

I'll take the patch, anyway, but there's room for future cleanup.

Best regards,
									Pavel
-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <http://lists.cip-project.org/pipermail/cip-dev/attachments/20190716/1f9fc841/attachment.sig>

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

* [cip-dev] [PATCH 4.19.y-cip 08/12] phy: renesas: rcar-gen3-usb2: follow the hardware manual procedure
  2019-07-15 14:01 ` [cip-dev] [PATCH 4.19.y-cip 08/12] phy: renesas: rcar-gen3-usb2: follow the hardware manual procedure Biju Das
@ 2019-07-16 12:18   ` Pavel Machek
  2019-07-16 12:49     ` Biju Das
  0 siblings, 1 reply; 20+ messages in thread
From: Pavel Machek @ 2019-07-16 12:18 UTC (permalink / raw)
  To: cip-dev

Hi!

> From: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
> 
> commit 72c0339c115b31b3c0b22b1809854136cadd49be upstream.
> 
> This patch modifies rcar_gen3_init_otg() procedure to follow Figure
> 73.4 of "R-Car Series, 3rd Generation User's Manual: Hardware Rev.1.00".
> 

> @@ -310,16 +310,21 @@ static void rcar_gen3_init_otg(struct rcar_gen3_chan *ch)
>  	void __iomem *usb2_base = ch->base;
>  	u32 val;
>  
> +	/* Should not use functions of read-modify-write a register */
> +	val = readl(usb2_base + USB2_LINECTRL1);
> +	val = (val & ~USB2_LINECTRL1_DP_RPD) | USB2_LINECTRL1_DPRPD_EN |
> +	      USB2_LINECTRL1_DMRPD_EN | USB2_LINECTRL1_DM_RPD;
> +	writel(val, usb2_base + USB2_LINECTRL1);
> +

I don't understand the comment here. Actually having function to
set/clear bits in arbitrary register might be a nice cleanup.

While reviewing that I noticed:

static void rcar_gen3_init_otg(struct rcar_gen3_chan *ch)
...
        val = readl(usb2_base + USB2_LINECTRL1);
	rcar_gen3_set_linectrl(ch, 0, 0);
 	writel(val | USB2_LINECTRL1_DPRPD_EN | USB2_LINECTRL1_DMRPD_EN,
 		usb2_base + USB2_LINECTRL1);


AFAICT it modifies the register only to undo those chanes
immediately. Is it intentional? Is it worth a comment? Can the block
be replaced with

static void rcar_gen3_init_otg(struct rcar_gen3_chan *ch)
...
	rcar_gen3_set_linectrl(ch, 0, 0);
	rcar_gen3_set_linectrl(ch, 1, 1);

?

Thanks,
									Pavel
-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <http://lists.cip-project.org/pipermail/cip-dev/attachments/20190716/39db3e09/attachment.sig>

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

* [cip-dev] [PATCH 4.19.y-cip 08/12] phy: renesas: rcar-gen3-usb2: follow the hardware manual procedure
  2019-07-16 12:18   ` Pavel Machek
@ 2019-07-16 12:49     ` Biju Das
  0 siblings, 0 replies; 20+ messages in thread
From: Biju Das @ 2019-07-16 12:49 UTC (permalink / raw)
  To: cip-dev

Hi Pavel,

Thanks for the feedback.

> Subject: Re: [cip-dev] [PATCH 4.19.y-cip 08/12] phy: renesas: rcar-gen3-usb2:
> follow the hardware manual procedure
> 
> Hi!
> 
> > From: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
> >
> > commit 72c0339c115b31b3c0b22b1809854136cadd49be upstream.
> >
> > This patch modifies rcar_gen3_init_otg() procedure to follow Figure
> > 73.4 of "R-Car Series, 3rd Generation User's Manual: Hardware Rev.1.00".
> >
> 
> > @@ -310,16 +310,21 @@ static void rcar_gen3_init_otg(struct
> rcar_gen3_chan *ch)
> >  	void __iomem *usb2_base = ch->base;
> >  	u32 val;
> >
> > +	/* Should not use functions of read-modify-write a register */
> > +	val = readl(usb2_base + USB2_LINECTRL1);
> > +	val = (val & ~USB2_LINECTRL1_DP_RPD) |
> USB2_LINECTRL1_DPRPD_EN |
> > +	      USB2_LINECTRL1_DMRPD_EN | USB2_LINECTRL1_DM_RPD;
> > +	writel(val, usb2_base + USB2_LINECTRL1);
> > +
> 
> I don't understand the comment here. Actually having function to set/clear
> bits in arbitrary register might be a nice cleanup.

As mentioned in the commit message, "procedure to follow Figure
 73.4 of "R-Car Series, 3rd Generation User's Manual: Hardware Rev.1.00".

The hardware manual mentions about a flow chart(Figure 73.4) describing " OTG Initial Setting Procedure"
The patch is made according to the flow chart.

> 
> While reviewing that I noticed:
> 
> static void rcar_gen3_init_otg(struct rcar_gen3_chan *ch) ...
>         val = readl(usb2_base + USB2_LINECTRL1);
> 	rcar_gen3_set_linectrl(ch, 0, 0);
>  	writel(val | USB2_LINECTRL1_DPRPD_EN |
> USB2_LINECTRL1_DMRPD_EN,
>  		usb2_base + USB2_LINECTRL1);
> 
> 
> AFAICT it modifies the register only to undo those chanes immediately. Is it
> intentional? Is it worth a comment? Can the block be replaced with

The "rcar_gen3_init_otg "routine  has to be aligned with the procedure mentioned in the flow chart.
There is a Wait for at least 20 ms is mentioned in the flow chart.

> static void rcar_gen3_init_otg(struct rcar_gen3_chan *ch) ...
> 	rcar_gen3_set_linectrl(ch, 0, 0);
> 	rcar_gen3_set_linectrl(ch, 1, 1);
> 
> ?
> 

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

* [cip-dev] [PATCH 4.19.y-cip 05/12] phy: renesas: rcar-gen3-usb2: add conditions for uses_otg_pins == false
  2019-07-16 12:05   ` Pavel Machek
@ 2019-07-16 12:50     ` Biju Das
  0 siblings, 0 replies; 20+ messages in thread
From: Biju Das @ 2019-07-16 12:50 UTC (permalink / raw)
  To: cip-dev

HI Pavel,

Thanks for the feedback.

> -----Original Message-----
> From: Pavel Machek <pavel@denx.de>
> Sent: Tuesday, July 16, 2019 1:05 PM
> To: Biju Das <biju.das@bp.renesas.com>
> Cc: cip-dev at lists.cip-project.org
> Subject: Re: [cip-dev] [PATCH 4.19.y-cip 05/12] phy: renesas: rcar-gen3-usb2:
> add conditions for uses_otg_pins == false
> 
> Hi!
> 
> > @@ -212,6 +212,9 @@ static void
> > rcar_gen3_init_from_a_peri_to_a_host(struct rcar_gen3_chan *ch)
> >
> >  static bool rcar_gen3_check_id(struct rcar_gen3_chan *ch)  {
> > +	if (!ch->uses_otg_pins)
> > +		return (ch->dr_mode == USB_DR_MODE_HOST) ? false :
> true;
> 
> I'd write this as
> 
>     "return ch->dr_mode != USB_DR_MODE_HOST;"
> 
> I'll take the patch, anyway, but there's room for future cleanup.

Yes I agree.  There is a room for improvement in future.

Regards,
Biju

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

* [cip-dev] [PATCH 4.19.y-cip 04/12] phy: renesas: rcar-gen3-usb2: unify OBINTEN handling
  2019-07-16 12:03   ` Pavel Machek
@ 2019-07-16 12:57     ` Biju Das
  0 siblings, 0 replies; 20+ messages in thread
From: Biju Das @ 2019-07-16 12:57 UTC (permalink / raw)
  To: cip-dev

Hi Pavel,

Thanks for the feedback.

> -----Original Message-----
> From: Pavel Machek <pavel@denx.de>
> Sent: Tuesday, July 16, 2019 1:03 PM
> To: Biju Das <biju.das@bp.renesas.com>
> Cc: cip-dev at lists.cip-project.org
> Subject: Re: [cip-dev] [PATCH 4.19.y-cip 04/12] phy: renesas: rcar-gen3-usb2:
> unify OBINTEN handling
> 
> Hi!
> 
> > commit 7ab0305d4d7725699169e21cdc4f6c8759c32feb upstream.
> >
> > This patch unifies the OBINTEN handling to clean-up the code.
> 
> 
> > @@ -145,6 +145,18 @@ static void rcar_gen3_enable_vbus_ctrl(struct
> rcar_gen3_chan *ch, int vbus)
> >  	writel(val, usb2_base + USB2_ADPCTRL);  }
> >
> > +static void rcar_gen3_control_otg_irq(struct rcar_gen3_chan *ch, int
> > +enable) {
> > +	void __iomem *usb2_base = ch->base;
> > +	u32 val = readl(usb2_base + USB2_OBINTEN);
> > +
> > +	if (enable)
> > +		val |= USB2_OBINT_BITS;
> > +	else
> > +		val &= ~USB2_OBINT_BITS;
> > +	writel(val, usb2_base + USB2_OBINTEN); }
> > +
> >
> >  static void rcar_gen3_init_from_a_peri_to_a_host(struct
> > rcar_gen3_chan *ch)  {
> > -	void __iomem *usb2_base = ch->base;
> > -	u32 val;
> > -
> > -	val = readl(usb2_base + USB2_OBINTEN);
> > -	writel(val & ~USB2_OBINT_BITS, usb2_base + USB2_OBINTEN);
> > +	rcar_gen3_control_otg_irq(ch, 0);
> >
> >  	rcar_gen3_enable_vbus_ctrl(ch, 1);
> >  	rcar_gen3_init_for_host(ch);
> >
> > -	writel(val | USB2_OBINT_BITS, usb2_base + USB2_OBINTEN);
> > +	rcar_gen3_control_otg_irq(ch, 1);
> >  }
> 
> This actually removes optimalization: old code would avoid reading
> USB2_OBINTEN twice. I guess it is not a problem

I agree, it removes optimization compared to the old code, But on the hand, this code is not frequently used and  the code is much cleaner.

Regards,
Biju 

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

* [cip-dev] [PATCH 4.19.y-cip 00/12] Add USB Host support
  2019-07-15 14:01 [cip-dev] [PATCH 4.19.y-cip 00/12] Add USB Host support Biju Das
                   ` (11 preceding siblings ...)
  2019-07-15 14:01 ` [cip-dev] [PATCH 4.19.y-cip 12/12] arm64: dts: renesas: cat874: Add USB-HOST support Biju Das
@ 2019-07-16 16:46 ` Pavel Machek
  12 siblings, 0 replies; 20+ messages in thread
From: Pavel Machek @ 2019-07-16 16:46 UTC (permalink / raw)
  To: cip-dev

Hi!

> This patch series add USB host support for EK874 platform.
> 
> This patch series is based on linux-4.19.y-cip and all the patches
> in this series are cherry-picked from linux rc tree.
> 
> This patch series is depend on the below patch series
> https://patchwork.kernel.org/project/cip-dev/list/?series=145929

I'll note that english in comment in 11/12 could use some improvement,
too.

Thanks, applied, and I'll push it out soon.

Best regards,
									Pavel
-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <http://lists.cip-project.org/pipermail/cip-dev/attachments/20190716/6b422b89/attachment.sig>

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

end of thread, other threads:[~2019-07-16 16:46 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-15 14:01 [cip-dev] [PATCH 4.19.y-cip 00/12] Add USB Host support Biju Das
2019-07-15 14:01 ` [cip-dev] [PATCH 4.19.y-cip 01/12] phy: renesas: rcar-gen3-usb2: fix vbus_ctrl for role sysfs Biju Das
2019-07-15 14:01 ` [cip-dev] [PATCH 4.19.y-cip 02/12] phy: renesas: rcar-gen3-usb2: Rename has_otg_pins to uses_otg_pins Biju Das
2019-07-15 14:01 ` [cip-dev] [PATCH 4.19.y-cip 03/12] phy: renesas: rcar-gen3-usb2: Check a property to use otg pins Biju Das
2019-07-15 14:01 ` [cip-dev] [PATCH 4.19.y-cip 04/12] phy: renesas: rcar-gen3-usb2: unify OBINTEN handling Biju Das
2019-07-16 12:03   ` Pavel Machek
2019-07-16 12:57     ` Biju Das
2019-07-15 14:01 ` [cip-dev] [PATCH 4.19.y-cip 05/12] phy: renesas: rcar-gen3-usb2: add conditions for uses_otg_pins == false Biju Das
2019-07-16 12:05   ` Pavel Machek
2019-07-16 12:50     ` Biju Das
2019-07-15 14:01 ` [cip-dev] [PATCH 4.19.y-cip 06/12] phy: renesas: rcar-gen3-usb2: change a condition "dr_mode" Biju Das
2019-07-15 14:01 ` [cip-dev] [PATCH 4.19.y-cip 07/12] phy: renesas: rcar-gen3-usb2: add is_otg_channel to use "role" sysfs Biju Das
2019-07-15 14:01 ` [cip-dev] [PATCH 4.19.y-cip 08/12] phy: renesas: rcar-gen3-usb2: follow the hardware manual procedure Biju Das
2019-07-16 12:18   ` Pavel Machek
2019-07-16 12:49     ` Biju Das
2019-07-15 14:01 ` [cip-dev] [PATCH 4.19.y-cip 09/12] phy: rcar-gen3-usb2: Add support for r8a77470 Biju Das
2019-07-15 14:01 ` [cip-dev] [PATCH 4.19.y-cip 10/12] phy: renesas: rcar-gen3-usb2: Use pdev's device pointer on dev_vdbg() Biju Das
2019-07-15 14:01 ` [cip-dev] [PATCH 4.19.y-cip 11/12] phy: renesas: rcar-gen3-usb2: enable/disable independent irqs Biju Das
2019-07-15 14:01 ` [cip-dev] [PATCH 4.19.y-cip 12/12] arm64: dts: renesas: cat874: Add USB-HOST support Biju Das
2019-07-16 16:46 ` [cip-dev] [PATCH 4.19.y-cip 00/12] Add USB Host support Pavel Machek

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).