linux-renesas-soc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 0/2] phy: renesas: rcar-gen3-usb2: fix an issue and minor update
@ 2020-07-17 11:44 Yoshihiro Shimoda
  2020-07-17 11:44 ` [PATCH v3 1/2] phy: renesas: rcar-gen3-usb2: move irq registration to init Yoshihiro Shimoda
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Yoshihiro Shimoda @ 2020-07-17 11:44 UTC (permalink / raw)
  To: kishon, vkoul
  Cc: wsa+renesas, geert+renesas, linux-renesas-soc, linux-kernel,
	Yoshihiro Shimoda

The patch 1 can fix an issue which SError happen if CONFIG_DEBUG_SHIRQ
is enabled.
The patch 2 is a incremental patch from patch 1. It's better to avoid
unexpected behaviors if request_irq() failed.

 Changes from v2:
 - [update] Minor fixes in patch 1.
 - [new] Exit if request_irq() failed in patch 2.
 https://patchwork.kernel.org/patch/11659547/

 Changes from v1:
 - Move the irq registration to rcar_gen3_phy_usb2_init() instead of
   add a condition into the irq handler.
 https://patchwork.kernel.org/patch/11654097/


Yoshihiro Shimoda (2):
  phy: renesas: rcar-gen3-usb2: move irq registration to init
  phy: renesas: rcar-gen3-usb2: exit if request_irq() failed

 drivers/phy/renesas/phy-rcar-gen3-usb2.c | 63 ++++++++++++++++++--------------
 1 file changed, 35 insertions(+), 28 deletions(-)

-- 
2.7.4


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

* [PATCH v3 1/2] phy: renesas: rcar-gen3-usb2: move irq registration to init
  2020-07-17 11:44 [PATCH v3 0/2] phy: renesas: rcar-gen3-usb2: fix an issue and minor update Yoshihiro Shimoda
@ 2020-07-17 11:44 ` Yoshihiro Shimoda
  2020-07-22  8:27   ` Wolfram Sang
  2020-07-17 11:44 ` [PATCH v3 2/2] phy: renesas: rcar-gen3-usb2: exit if request_irq() failed Yoshihiro Shimoda
  2020-07-20  6:33 ` [PATCH v3 0/2] phy: renesas: rcar-gen3-usb2: fix an issue and minor update Vinod Koul
  2 siblings, 1 reply; 6+ messages in thread
From: Yoshihiro Shimoda @ 2020-07-17 11:44 UTC (permalink / raw)
  To: kishon, vkoul
  Cc: wsa+renesas, geert+renesas, linux-renesas-soc, linux-kernel,
	Yoshihiro Shimoda

If CONFIG_DEBUG_SHIRQ was enabled, r8a77951-salvator-xs could boot
correctly. If we appended "earlycon keep_bootcon" to the kernel
command like, we could get kernel log like below.

    SError Interrupt on CPU0, code 0xbf000002 -- SError
    CPU: 0 PID: 1 Comm: swapper/0 Not tainted 5.8.0-rc3-salvator-x-00505-g6c843129e6faaf01 #785
    Hardware name: Renesas Salvator-X 2nd version board based on r8a77951 (DT)
    pstate: 60400085 (nZCv daIf +PAN -UAO BTYPE=--)
    pc : rcar_gen3_phy_usb2_irq+0x14/0x54
    lr : free_irq+0xf4/0x27c

This means free_irq() calls the interrupt handler while PM runtime
is not getting if DEBUG_SHIRQ is enabled and rcar_gen3_phy_usb2_probe()
failed. To fix the issue, move the irq registration place to
rcar_gen3_phy_usb2_init() which is ready to handle the interrupts.

Note that after the commit 549b6b55b005 ("phy: renesas: rcar-gen3-usb2:
enable/disable independent irqs") which is merged into v5.2, since this
driver creates multiple phy instances, needs to check whether one of
phy instances is initialized. However, if we backport this patch to v5.1
or less, we don't need to check it because such kernel have single
phy instance.

Reported-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Reported-by: Geert Uytterhoeven <geert+renesas@glider.be>
Fixes: 9f391c574efc ("phy: rcar-gen3-usb2: add runtime ID/VBUS pin detection")
Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
---
 drivers/phy/renesas/phy-rcar-gen3-usb2.c | 61 +++++++++++++++++---------------
 1 file changed, 33 insertions(+), 28 deletions(-)

diff --git a/drivers/phy/renesas/phy-rcar-gen3-usb2.c b/drivers/phy/renesas/phy-rcar-gen3-usb2.c
index bfb22f8..5087b7c 100644
--- a/drivers/phy/renesas/phy-rcar-gen3-usb2.c
+++ b/drivers/phy/renesas/phy-rcar-gen3-usb2.c
@@ -111,6 +111,7 @@ struct rcar_gen3_chan {
 	struct work_struct work;
 	struct mutex lock;	/* protects rphys[...].powered */
 	enum usb_dr_mode dr_mode;
+	int irq;
 	bool extcon_host;
 	bool is_otg_channel;
 	bool uses_otg_pins;
@@ -389,12 +390,38 @@ static void rcar_gen3_init_otg(struct rcar_gen3_chan *ch)
 	rcar_gen3_device_recognition(ch);
 }
 
+static irqreturn_t rcar_gen3_phy_usb2_irq(int irq, void *_ch)
+{
+	struct rcar_gen3_chan *ch = _ch;
+	void __iomem *usb2_base = ch->base;
+	u32 status = readl(usb2_base + USB2_OBINTSTA);
+	irqreturn_t ret = IRQ_NONE;
+
+	if (status & USB2_OBINT_BITS) {
+		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;
+	}
+
+	return ret;
+}
+
 static int rcar_gen3_phy_usb2_init(struct phy *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_is_any_rphy_initialized(channel) && channel->irq >= 0) {
+		INIT_WORK(&channel->work, rcar_gen3_phy_usb2_work);
+		ret = request_irq(channel->irq, rcar_gen3_phy_usb2_irq,
+				  IRQF_SHARED, dev_name(channel->dev), channel);
+		if (ret < 0)
+			dev_err(channel->dev, "No irq handler (%d)\n", channel->irq);
+	}
 
 	/* Initialize USB2 part */
 	val = readl(usb2_base + USB2_INT_ENABLE);
@@ -433,6 +460,9 @@ static int rcar_gen3_phy_usb2_exit(struct phy *p)
 		val &= ~USB2_INT_ENABLE_UCOM_INTEN;
 	writel(val, usb2_base + USB2_INT_ENABLE);
 
+	if (channel->irq >= 0 && !rcar_gen3_is_any_rphy_initialized(channel))
+		free_irq(channel->irq, channel);
+
 	return 0;
 }
 
@@ -503,23 +533,6 @@ static const struct phy_ops rz_g1c_phy_usb2_ops = {
 	.owner		= THIS_MODULE,
 };
 
-static irqreturn_t rcar_gen3_phy_usb2_irq(int irq, void *_ch)
-{
-	struct rcar_gen3_chan *ch = _ch;
-	void __iomem *usb2_base = ch->base;
-	u32 status = readl(usb2_base + USB2_OBINTSTA);
-	irqreturn_t ret = IRQ_NONE;
-
-	if (status & USB2_OBINT_BITS) {
-		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;
-	}
-
-	return ret;
-}
-
 static const struct of_device_id rcar_gen3_phy_usb2_match_table[] = {
 	{
 		.compatible = "renesas,usb2-phy-r8a77470",
@@ -598,7 +611,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, i;
+	int ret = 0, i;
 
 	if (!dev->of_node) {
 		dev_err(dev, "This driver needs device tree\n");
@@ -614,16 +627,8 @@ static int rcar_gen3_phy_usb2_probe(struct platform_device *pdev)
 	if (IS_ERR(channel->base))
 		return PTR_ERR(channel->base);
 
-	/* call request_irq for OTG */
-	irq = platform_get_irq_optional(pdev, 0);
-	if (irq >= 0) {
-		INIT_WORK(&channel->work, rcar_gen3_phy_usb2_work);
-		irq = devm_request_irq(dev, irq, rcar_gen3_phy_usb2_irq,
-				       IRQF_SHARED, dev_name(dev), channel);
-		if (irq < 0)
-			dev_err(dev, "No irq handler (%d)\n", irq);
-	}
-
+	/* get irq number here and request_irq for OTG in phy_init */
+	channel->irq = platform_get_irq_optional(pdev, 0);
 	channel->dr_mode = rcar_gen3_get_dr_mode(dev->of_node);
 	if (channel->dr_mode != USB_DR_MODE_UNKNOWN) {
 		int ret;
-- 
2.7.4


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

* [PATCH v3 2/2] phy: renesas: rcar-gen3-usb2: exit if request_irq() failed
  2020-07-17 11:44 [PATCH v3 0/2] phy: renesas: rcar-gen3-usb2: fix an issue and minor update Yoshihiro Shimoda
  2020-07-17 11:44 ` [PATCH v3 1/2] phy: renesas: rcar-gen3-usb2: move irq registration to init Yoshihiro Shimoda
@ 2020-07-17 11:44 ` Yoshihiro Shimoda
  2020-07-22  8:28   ` Wolfram Sang
  2020-07-20  6:33 ` [PATCH v3 0/2] phy: renesas: rcar-gen3-usb2: fix an issue and minor update Vinod Koul
  2 siblings, 1 reply; 6+ messages in thread
From: Yoshihiro Shimoda @ 2020-07-17 11:44 UTC (permalink / raw)
  To: kishon, vkoul
  Cc: wsa+renesas, geert+renesas, linux-renesas-soc, linux-kernel,
	Yoshihiro Shimoda

To avoid unexpected behaviors, it's better to exit if request_irq()
failed.

Suggested-by: Vinod Koul <vkoul@kernel.org>
Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@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 5087b7c..e34e447 100644
--- a/drivers/phy/renesas/phy-rcar-gen3-usb2.c
+++ b/drivers/phy/renesas/phy-rcar-gen3-usb2.c
@@ -419,8 +419,10 @@ static int rcar_gen3_phy_usb2_init(struct phy *p)
 		INIT_WORK(&channel->work, rcar_gen3_phy_usb2_work);
 		ret = request_irq(channel->irq, rcar_gen3_phy_usb2_irq,
 				  IRQF_SHARED, dev_name(channel->dev), channel);
-		if (ret < 0)
+		if (ret < 0) {
 			dev_err(channel->dev, "No irq handler (%d)\n", channel->irq);
+			return ret;
+		}
 	}
 
 	/* Initialize USB2 part */
-- 
2.7.4


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

* Re: [PATCH v3 0/2] phy: renesas: rcar-gen3-usb2: fix an issue and minor update
  2020-07-17 11:44 [PATCH v3 0/2] phy: renesas: rcar-gen3-usb2: fix an issue and minor update Yoshihiro Shimoda
  2020-07-17 11:44 ` [PATCH v3 1/2] phy: renesas: rcar-gen3-usb2: move irq registration to init Yoshihiro Shimoda
  2020-07-17 11:44 ` [PATCH v3 2/2] phy: renesas: rcar-gen3-usb2: exit if request_irq() failed Yoshihiro Shimoda
@ 2020-07-20  6:33 ` Vinod Koul
  2 siblings, 0 replies; 6+ messages in thread
From: Vinod Koul @ 2020-07-20  6:33 UTC (permalink / raw)
  To: Yoshihiro Shimoda
  Cc: kishon, wsa+renesas, geert+renesas, linux-renesas-soc, linux-kernel

On 17-07-20, 20:44, Yoshihiro Shimoda wrote:
> The patch 1 can fix an issue which SError happen if CONFIG_DEBUG_SHIRQ
> is enabled.
> The patch 2 is a incremental patch from patch 1. It's better to avoid
> unexpected behaviors if request_irq() failed.

Applied, thanks

-- 
~Vinod

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

* Re: [PATCH v3 1/2] phy: renesas: rcar-gen3-usb2: move irq registration to init
  2020-07-17 11:44 ` [PATCH v3 1/2] phy: renesas: rcar-gen3-usb2: move irq registration to init Yoshihiro Shimoda
@ 2020-07-22  8:27   ` Wolfram Sang
  0 siblings, 0 replies; 6+ messages in thread
From: Wolfram Sang @ 2020-07-22  8:27 UTC (permalink / raw)
  To: Yoshihiro Shimoda
  Cc: kishon, vkoul, geert+renesas, linux-renesas-soc, linux-kernel

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

On Fri, Jul 17, 2020 at 08:44:56PM +0900, Yoshihiro Shimoda wrote:
> If CONFIG_DEBUG_SHIRQ was enabled, r8a77951-salvator-xs could boot

"could not boot"

> correctly. If we appended "earlycon keep_bootcon" to the kernel
> command like, we could get kernel log like below.
> 
>     SError Interrupt on CPU0, code 0xbf000002 -- SError
>     CPU: 0 PID: 1 Comm: swapper/0 Not tainted 5.8.0-rc3-salvator-x-00505-g6c843129e6faaf01 #785
>     Hardware name: Renesas Salvator-X 2nd version board based on r8a77951 (DT)
>     pstate: 60400085 (nZCv daIf +PAN -UAO BTYPE=--)
>     pc : rcar_gen3_phy_usb2_irq+0x14/0x54
>     lr : free_irq+0xf4/0x27c
> 
> This means free_irq() calls the interrupt handler while PM runtime
> is not getting if DEBUG_SHIRQ is enabled and rcar_gen3_phy_usb2_probe()
> failed. To fix the issue, move the irq registration place to
> rcar_gen3_phy_usb2_init() which is ready to handle the interrupts.
> 
> Note that after the commit 549b6b55b005 ("phy: renesas: rcar-gen3-usb2:
> enable/disable independent irqs") which is merged into v5.2, since this
> driver creates multiple phy instances, needs to check whether one of
> phy instances is initialized. However, if we backport this patch to v5.1
> or less, we don't need to check it because such kernel have single
> phy instance.
> 
> Reported-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
> Reported-by: Geert Uytterhoeven <geert+renesas@glider.be>
> Fixes: 9f391c574efc ("phy: rcar-gen3-usb2: add runtime ID/VBUS pin detection")
> Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>

Yeah, makes my boards boot with CONFIG_DEBUG_SHIRQ!

Reviewed-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Tested-by: Wolfram Sang <wsa+renesas@sang-engineering.com>


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

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

* Re: [PATCH v3 2/2] phy: renesas: rcar-gen3-usb2: exit if request_irq() failed
  2020-07-17 11:44 ` [PATCH v3 2/2] phy: renesas: rcar-gen3-usb2: exit if request_irq() failed Yoshihiro Shimoda
@ 2020-07-22  8:28   ` Wolfram Sang
  0 siblings, 0 replies; 6+ messages in thread
From: Wolfram Sang @ 2020-07-22  8:28 UTC (permalink / raw)
  To: Yoshihiro Shimoda
  Cc: kishon, vkoul, geert+renesas, linux-renesas-soc, linux-kernel

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

On Fri, Jul 17, 2020 at 08:44:57PM +0900, Yoshihiro Shimoda wrote:
> To avoid unexpected behaviors, it's better to exit if request_irq()
> failed.
> 
> Suggested-by: Vinod Koul <vkoul@kernel.org>
> Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>

Makes sense to me.

Reviewed-by: Wolfram Sang <wsa+renesas@sang-engineering.com>


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

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

end of thread, other threads:[~2020-07-22  8:28 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-17 11:44 [PATCH v3 0/2] phy: renesas: rcar-gen3-usb2: fix an issue and minor update Yoshihiro Shimoda
2020-07-17 11:44 ` [PATCH v3 1/2] phy: renesas: rcar-gen3-usb2: move irq registration to init Yoshihiro Shimoda
2020-07-22  8:27   ` Wolfram Sang
2020-07-17 11:44 ` [PATCH v3 2/2] phy: renesas: rcar-gen3-usb2: exit if request_irq() failed Yoshihiro Shimoda
2020-07-22  8:28   ` Wolfram Sang
2020-07-20  6:33 ` [PATCH v3 0/2] phy: renesas: rcar-gen3-usb2: fix an issue and minor update Vinod Koul

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