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 120 struct work_struct work; 121 121 struct mutex lock; /* protects rphys[...].powered */ 122 122 enum usb_dr_mode dr_mode; 123 - int irq; 124 123 u32 obint_enable_bits; 125 124 bool extcon_host; 126 125 bool is_otg_channel; ··· 427 428 { 428 429 struct rcar_gen3_chan *ch = _ch; 429 430 void __iomem *usb2_base = ch->base; 430 - u32 status = readl(usb2_base + USB2_OBINTSTA); 431 + struct device *dev = ch->dev; 431 432 irqreturn_t ret = IRQ_NONE; 433 + u32 status; 432 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); 433 441 if (status & ch->obint_enable_bits) { 434 - dev_vdbg(ch->dev, "%s: %08x\n", __func__, status); 442 + dev_vdbg(dev, "%s: %08x\n", __func__, status); 435 443 writel(ch->obint_enable_bits, usb2_base + USB2_OBINTSTA); 436 444 rcar_gen3_device_recognition(ch); 437 445 ret = IRQ_HANDLED; 438 446 } 439 447 448 + rpm_put: 449 + pm_runtime_put_noidle(dev); 440 450 return ret; 441 451 } 442 452 ··· 455 447 struct rcar_gen3_chan *channel = rphy->ch; 456 448 void __iomem *usb2_base = channel->base; 457 449 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 450 470 451 /* Initialize USB2 part */ 471 452 val = readl(usb2_base + USB2_INT_ENABLE); ··· 486 489 if (!rcar_gen3_is_any_rphy_initialized(channel)) 487 490 val &= ~USB2_INT_ENABLE_UCOM_INTEN; 488 491 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 492 493 493 return 0; 494 494 } ··· 692 698 struct device *dev = &pdev->dev; 693 699 struct rcar_gen3_chan *channel; 694 700 struct phy_provider *provider; 695 - int ret = 0, i; 701 + int ret = 0, i, irq; 696 702 697 703 if (!dev->of_node) { 698 704 dev_err(dev, "This driver needs device tree\n"); ··· 708 714 return PTR_ERR(channel->base); 709 715 710 716 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 717 channel->dr_mode = rcar_gen3_get_dr_mode(dev->of_node); 714 718 if (channel->dr_mode != USB_DR_MODE_UNKNOWN) { 715 719 channel->is_otg_channel = true; ··· 774 782 goto error; 775 783 } 776 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 + } 777 799 } 778 800 779 801 provider = devm_of_phy_provider_register(dev, rcar_gen3_phy_usb2_xlate);