phy: renesas: rcar-gen3-usb2: Move IRQ request in probe

Commit 08b0ad375ca6 ("phy: renesas: rcar-gen3-usb2: move IRQ registration
to init") moved the IRQ request operation from probe to
struct phy_ops::phy_init API to avoid triggering interrupts (which lead to
register accesses) while the PHY clocks (enabled through runtime PM APIs)
are not active. If this happens, it results in a synchronous abort.

One way to reproduce this issue is by enabling CONFIG_DEBUG_SHIRQ, which
calls free_irq() on driver removal.

Move the IRQ request and free operations back to probe, and take the
runtime PM state into account in IRQ handler. This commit is preparatory
for the subsequent fixes in this series.

Reviewed-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Tested-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Reviewed-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
Signed-off-by: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
Link: https://lore.kernel.org/r/20250507125032.565017-3-claudiu.beznea.uj@bp.renesas.com
Signed-off-by: Vinod Koul <vkoul@kernel.org>

authored by Claudiu Beznea and committed by Vinod Koul de76809f 54c4c587

+26 -20
+26 -20
drivers/phy/renesas/phy-rcar-gen3-usb2.c
··· 120 struct work_struct work; 121 struct mutex lock; /* protects rphys[...].powered */ 122 enum usb_dr_mode dr_mode; 123 - int irq; 124 u32 obint_enable_bits; 125 bool extcon_host; 126 bool is_otg_channel; ··· 427 { 428 struct rcar_gen3_chan *ch = _ch; 429 void __iomem *usb2_base = ch->base; 430 - u32 status = readl(usb2_base + USB2_OBINTSTA); 431 irqreturn_t ret = IRQ_NONE; 432 433 if (status & ch->obint_enable_bits) { 434 - dev_vdbg(ch->dev, "%s: %08x\n", __func__, status); 435 writel(ch->obint_enable_bits, usb2_base + USB2_OBINTSTA); 436 rcar_gen3_device_recognition(ch); 437 ret = IRQ_HANDLED; 438 } 439 440 return ret; 441 } 442 ··· 455 struct rcar_gen3_chan *channel = rphy->ch; 456 void __iomem *usb2_base = channel->base; 457 u32 val; 458 - int ret; 459 - 460 - if (!rcar_gen3_is_any_rphy_initialized(channel) && channel->irq >= 0) { 461 - INIT_WORK(&channel->work, rcar_gen3_phy_usb2_work); 462 - ret = request_irq(channel->irq, rcar_gen3_phy_usb2_irq, 463 - IRQF_SHARED, dev_name(channel->dev), channel); 464 - if (ret < 0) { 465 - dev_err(channel->dev, "No irq handler (%d)\n", channel->irq); 466 - return ret; 467 - } 468 - } 469 470 /* Initialize USB2 part */ 471 val = readl(usb2_base + USB2_INT_ENABLE); ··· 486 if (!rcar_gen3_is_any_rphy_initialized(channel)) 487 val &= ~USB2_INT_ENABLE_UCOM_INTEN; 488 writel(val, usb2_base + USB2_INT_ENABLE); 489 - 490 - if (channel->irq >= 0 && !rcar_gen3_is_any_rphy_initialized(channel)) 491 - free_irq(channel->irq, channel); 492 493 return 0; 494 } ··· 692 struct device *dev = &pdev->dev; 693 struct rcar_gen3_chan *channel; 694 struct phy_provider *provider; 695 - int ret = 0, i; 696 697 if (!dev->of_node) { 698 dev_err(dev, "This driver needs device tree\n"); ··· 708 return PTR_ERR(channel->base); 709 710 channel->obint_enable_bits = USB2_OBINT_BITS; 711 - /* get irq number here and request_irq for OTG in phy_init */ 712 - channel->irq = platform_get_irq_optional(pdev, 0); 713 channel->dr_mode = rcar_gen3_get_dr_mode(dev->of_node); 714 if (channel->dr_mode != USB_DR_MODE_UNKNOWN) { 715 channel->is_otg_channel = true; ··· 774 goto error; 775 } 776 channel->vbus = NULL; 777 } 778 779 provider = devm_of_phy_provider_register(dev, rcar_gen3_phy_usb2_xlate);
··· 120 struct work_struct work; 121 struct mutex lock; /* protects rphys[...].powered */ 122 enum usb_dr_mode dr_mode; 123 u32 obint_enable_bits; 124 bool extcon_host; 125 bool is_otg_channel; ··· 428 { 429 struct rcar_gen3_chan *ch = _ch; 430 void __iomem *usb2_base = ch->base; 431 + struct device *dev = ch->dev; 432 irqreturn_t ret = IRQ_NONE; 433 + u32 status; 434 435 + pm_runtime_get_noresume(dev); 436 + 437 + if (pm_runtime_suspended(dev)) 438 + goto rpm_put; 439 + 440 + status = readl(usb2_base + USB2_OBINTSTA); 441 if (status & ch->obint_enable_bits) { 442 + dev_vdbg(dev, "%s: %08x\n", __func__, status); 443 writel(ch->obint_enable_bits, usb2_base + USB2_OBINTSTA); 444 rcar_gen3_device_recognition(ch); 445 ret = IRQ_HANDLED; 446 } 447 448 + rpm_put: 449 + pm_runtime_put_noidle(dev); 450 return ret; 451 } 452 ··· 447 struct rcar_gen3_chan *channel = rphy->ch; 448 void __iomem *usb2_base = channel->base; 449 u32 val; 450 451 /* Initialize USB2 part */ 452 val = readl(usb2_base + USB2_INT_ENABLE); ··· 489 if (!rcar_gen3_is_any_rphy_initialized(channel)) 490 val &= ~USB2_INT_ENABLE_UCOM_INTEN; 491 writel(val, usb2_base + USB2_INT_ENABLE); 492 493 return 0; 494 } ··· 698 struct device *dev = &pdev->dev; 699 struct rcar_gen3_chan *channel; 700 struct phy_provider *provider; 701 + int ret = 0, i, irq; 702 703 if (!dev->of_node) { 704 dev_err(dev, "This driver needs device tree\n"); ··· 714 return PTR_ERR(channel->base); 715 716 channel->obint_enable_bits = USB2_OBINT_BITS; 717 channel->dr_mode = rcar_gen3_get_dr_mode(dev->of_node); 718 if (channel->dr_mode != USB_DR_MODE_UNKNOWN) { 719 channel->is_otg_channel = true; ··· 782 goto error; 783 } 784 channel->vbus = NULL; 785 + } 786 + 787 + irq = platform_get_irq_optional(pdev, 0); 788 + if (irq < 0 && irq != -ENXIO) { 789 + ret = irq; 790 + goto error; 791 + } else if (irq > 0) { 792 + INIT_WORK(&channel->work, rcar_gen3_phy_usb2_work); 793 + ret = devm_request_irq(dev, irq, rcar_gen3_phy_usb2_irq, 794 + IRQF_SHARED, dev_name(dev), channel); 795 + if (ret < 0) { 796 + dev_err(dev, "Failed to request irq (%d)\n", irq); 797 + goto error; 798 + } 799 } 800 801 provider = devm_of_phy_provider_register(dev, rcar_gen3_phy_usb2_xlate);