Skip to content

Commit 9c6b5c6

Browse files
claudiubezneaopsiff
authored andcommitted
phy: renesas: rcar-gen3-usb2: Fix role detection on unbind/bind
commit 54c4c58 upstream. It has been observed on the Renesas RZ/G3S SoC that unbinding and binding the PHY driver leads to role autodetection failures. This issue occurs when PHY 3 is the first initialized PHY. PHY 3 does not have an interrupt associated with the USB2_INT_ENABLE register (as rcar_gen3_int_enable[3] = 0). As a result, rcar_gen3_init_otg() is called to initialize OTG without enabling PHY interrupts. To resolve this, add rcar_gen3_is_any_otg_rphy_initialized() and call it in role_store(), role_show(), and rcar_gen3_init_otg(). At the same time, rcar_gen3_init_otg() is only called when initialization for a PHY with interrupt bits is in progress. As a result, the struct rcar_gen3_phy::otg_initialized is no longer needed. Fixes: 549b6b5 ("phy: renesas: rcar-gen3-usb2: enable/disable independent irqs") Cc: stable@vger.kernel.org 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-2-claudiu.beznea.uj@bp.renesas.com Signed-off-by: Vinod Koul <vkoul@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> (cherry picked from commit 99fc6f1c371e8e70196b2cf0c7e0710ba16e23f9)
1 parent 0dcc52c commit 9c6b5c6

1 file changed

Lines changed: 14 additions & 19 deletions

File tree

drivers/phy/renesas/phy-rcar-gen3-usb2.c

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ struct rcar_gen3_phy {
101101
struct rcar_gen3_chan *ch;
102102
u32 int_enable_bits;
103103
bool initialized;
104-
bool otg_initialized;
105104
bool powered;
106105
};
107106

@@ -309,16 +308,15 @@ static bool rcar_gen3_is_any_rphy_initialized(struct rcar_gen3_chan *ch)
309308
return false;
310309
}
311310

312-
static bool rcar_gen3_needs_init_otg(struct rcar_gen3_chan *ch)
311+
static bool rcar_gen3_is_any_otg_rphy_initialized(struct rcar_gen3_chan *ch)
313312
{
314-
int i;
315-
316-
for (i = 0; i < NUM_OF_PHYS; i++) {
317-
if (ch->rphys[i].otg_initialized)
318-
return false;
313+
for (enum rcar_gen3_phy_index i = PHY_INDEX_BOTH_HC; i <= PHY_INDEX_EHCI;
314+
i++) {
315+
if (ch->rphys[i].initialized)
316+
return true;
319317
}
320318

321-
return true;
319+
return false;
322320
}
323321

324322
static bool rcar_gen3_are_all_rphys_power_off(struct rcar_gen3_chan *ch)
@@ -340,7 +338,7 @@ static ssize_t role_store(struct device *dev, struct device_attribute *attr,
340338
bool is_b_device;
341339
enum phy_mode cur_mode, new_mode;
342340

343-
if (!ch->is_otg_channel || !rcar_gen3_is_any_rphy_initialized(ch))
341+
if (!ch->is_otg_channel || !rcar_gen3_is_any_otg_rphy_initialized(ch))
344342
return -EIO;
345343

346344
if (sysfs_streq(buf, "host"))
@@ -378,7 +376,7 @@ static ssize_t role_show(struct device *dev, struct device_attribute *attr,
378376
{
379377
struct rcar_gen3_chan *ch = dev_get_drvdata(dev);
380378

381-
if (!ch->is_otg_channel || !rcar_gen3_is_any_rphy_initialized(ch))
379+
if (!ch->is_otg_channel || !rcar_gen3_is_any_otg_rphy_initialized(ch))
382380
return -EIO;
383381

384382
return sprintf(buf, "%s\n", rcar_gen3_is_host(ch) ? "host" :
@@ -391,6 +389,9 @@ static void rcar_gen3_init_otg(struct rcar_gen3_chan *ch)
391389
void __iomem *usb2_base = ch->base;
392390
u32 val;
393391

392+
if (!ch->is_otg_channel || rcar_gen3_is_any_otg_rphy_initialized(ch))
393+
return;
394+
394395
/* Should not use functions of read-modify-write a register */
395396
val = readl(usb2_base + USB2_LINECTRL1);
396397
val = (val & ~USB2_LINECTRL1_DP_RPD) | USB2_LINECTRL1_DPRPD_EN |
@@ -454,12 +455,9 @@ static int rcar_gen3_phy_usb2_init(struct phy *p)
454455
writel(USB2_SPD_RSM_TIMSET_INIT, usb2_base + USB2_SPD_RSM_TIMSET);
455456
writel(USB2_OC_TIMSET_INIT, usb2_base + USB2_OC_TIMSET);
456457

457-
/* Initialize otg part */
458-
if (channel->is_otg_channel) {
459-
if (rcar_gen3_needs_init_otg(channel))
460-
rcar_gen3_init_otg(channel);
461-
rphy->otg_initialized = true;
462-
}
458+
/* Initialize otg part (only if we initialize a PHY with IRQs). */
459+
if (rphy->int_enable_bits)
460+
rcar_gen3_init_otg(channel);
463461

464462
rphy->initialized = true;
465463

@@ -475,9 +473,6 @@ static int rcar_gen3_phy_usb2_exit(struct phy *p)
475473

476474
rphy->initialized = false;
477475

478-
if (channel->is_otg_channel)
479-
rphy->otg_initialized = false;
480-
481476
val = readl(usb2_base + USB2_INT_ENABLE);
482477
val &= ~rphy->int_enable_bits;
483478
if (!rcar_gen3_is_any_rphy_initialized(channel))

0 commit comments

Comments
 (0)