Skip to content

Commit 21eeefe

Browse files
committed
Merge tag 'phy-fixes-6.15' of git://git.kernel.org/pub/scm/linux/kernel/git/phy/linux-phy
Pull phy fixes from Vinod Koul: "A bunch of renesas fixes and few smaller fixes in other drivers: - Rensas fixes for unbind ole detection, irq, locking etc - tegra fixes for error handling at init and UTMI power states and stray unlock fix - rockchip missing assignment and pll output fixes - startfive usb host detection fixes" * tag 'phy-fixes-6.15' of git://git.kernel.org/pub/scm/linux/kernel/git/phy/linux-phy: phy: Fix error handling in tegra_xusb_port_init phy: renesas: rcar-gen3-usb2: Set timing registers only once phy: renesas: rcar-gen3-usb2: Assert PLL reset on PHY power off phy: renesas: rcar-gen3-usb2: Lock around hardware registers and driver data phy: renesas: rcar-gen3-usb2: Move IRQ request in probe phy: renesas: rcar-gen3-usb2: Fix role detection on unbind/bind phy: tegra: xusb: remove a stray unlock phy: phy-rockchip-samsung-hdptx: Fix PHY PLL output 50.25MHz error phy: starfive: jh7110-usb: Fix USB 2.0 host occasional detection failure phy: rockchip-samsung-dcphy: Add missing assignment phy: can-transceiver: Re-instate "mux-states" property presence check phy: qcom-qmp-ufs: check for mode type for phy setting phy: tegra: xusb: Use a bitmask for UTMI pad power state tracking
2 parents 6aa6f8c + b2ea5f4 commit 21eeefe

File tree

8 files changed

+133
-92
lines changed

8 files changed

+133
-92
lines changed

drivers/phy/phy-can-transceiver.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,16 @@ static const struct of_device_id can_transceiver_phy_ids[] = {
9393
};
9494
MODULE_DEVICE_TABLE(of, can_transceiver_phy_ids);
9595

96+
/* Temporary wrapper until the multiplexer subsystem supports optional muxes */
97+
static inline struct mux_state *
98+
devm_mux_state_get_optional(struct device *dev, const char *mux_name)
99+
{
100+
if (!of_property_present(dev->of_node, "mux-states"))
101+
return NULL;
102+
103+
return devm_mux_state_get(dev, mux_name);
104+
}
105+
96106
static int can_transceiver_phy_probe(struct platform_device *pdev)
97107
{
98108
struct phy_provider *phy_provider;
@@ -114,13 +124,11 @@ static int can_transceiver_phy_probe(struct platform_device *pdev)
114124
match = of_match_node(can_transceiver_phy_ids, pdev->dev.of_node);
115125
drvdata = match->data;
116126

117-
mux_state = devm_mux_state_get(dev, NULL);
118-
if (IS_ERR(mux_state)) {
119-
if (PTR_ERR(mux_state) == -EPROBE_DEFER)
120-
return PTR_ERR(mux_state);
121-
} else {
122-
can_transceiver_phy->mux_state = mux_state;
123-
}
127+
mux_state = devm_mux_state_get_optional(dev, NULL);
128+
if (IS_ERR(mux_state))
129+
return PTR_ERR(mux_state);
130+
131+
can_transceiver_phy->mux_state = mux_state;
124132

125133
phy = devm_phy_create(dev, dev->of_node,
126134
&can_transceiver_phy_ops);

drivers/phy/qualcomm/phy-qcom-qmp-ufs.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1754,7 +1754,8 @@ static void qmp_ufs_init_registers(struct qmp_ufs *qmp, const struct qmp_phy_cfg
17541754
qmp_ufs_init_all(qmp, &cfg->tbls_hs_overlay[i]);
17551755
}
17561756

1757-
qmp_ufs_init_all(qmp, &cfg->tbls_hs_b);
1757+
if (qmp->mode == PHY_MODE_UFS_HS_B)
1758+
qmp_ufs_init_all(qmp, &cfg->tbls_hs_b);
17581759
}
17591760

17601761
static int qmp_ufs_com_init(struct qmp_ufs *qmp)

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

Lines changed: 75 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* Copyright (C) 2014 Cogent Embedded, Inc.
1010
*/
1111

12+
#include <linux/cleanup.h>
1213
#include <linux/extcon-provider.h>
1314
#include <linux/interrupt.h>
1415
#include <linux/io.h>
@@ -107,7 +108,6 @@ struct rcar_gen3_phy {
107108
struct rcar_gen3_chan *ch;
108109
u32 int_enable_bits;
109110
bool initialized;
110-
bool otg_initialized;
111111
bool powered;
112112
};
113113

@@ -119,9 +119,8 @@ struct rcar_gen3_chan {
119119
struct regulator *vbus;
120120
struct reset_control *rstc;
121121
struct work_struct work;
122-
struct mutex lock; /* protects rphys[...].powered */
122+
spinlock_t lock; /* protects access to hardware and driver data structure. */
123123
enum usb_dr_mode dr_mode;
124-
int irq;
125124
u32 obint_enable_bits;
126125
bool extcon_host;
127126
bool is_otg_channel;
@@ -320,16 +319,15 @@ static bool rcar_gen3_is_any_rphy_initialized(struct rcar_gen3_chan *ch)
320319
return false;
321320
}
322321

323-
static bool rcar_gen3_needs_init_otg(struct rcar_gen3_chan *ch)
322+
static bool rcar_gen3_is_any_otg_rphy_initialized(struct rcar_gen3_chan *ch)
324323
{
325-
int i;
326-
327-
for (i = 0; i < NUM_OF_PHYS; i++) {
328-
if (ch->rphys[i].otg_initialized)
329-
return false;
324+
for (enum rcar_gen3_phy_index i = PHY_INDEX_BOTH_HC; i <= PHY_INDEX_EHCI;
325+
i++) {
326+
if (ch->rphys[i].initialized)
327+
return true;
330328
}
331329

332-
return true;
330+
return false;
333331
}
334332

335333
static bool rcar_gen3_are_all_rphys_power_off(struct rcar_gen3_chan *ch)
@@ -351,7 +349,9 @@ static ssize_t role_store(struct device *dev, struct device_attribute *attr,
351349
bool is_b_device;
352350
enum phy_mode cur_mode, new_mode;
353351

354-
if (!ch->is_otg_channel || !rcar_gen3_is_any_rphy_initialized(ch))
352+
guard(spinlock_irqsave)(&ch->lock);
353+
354+
if (!ch->is_otg_channel || !rcar_gen3_is_any_otg_rphy_initialized(ch))
355355
return -EIO;
356356

357357
if (sysfs_streq(buf, "host"))
@@ -389,7 +389,7 @@ static ssize_t role_show(struct device *dev, struct device_attribute *attr,
389389
{
390390
struct rcar_gen3_chan *ch = dev_get_drvdata(dev);
391391

392-
if (!ch->is_otg_channel || !rcar_gen3_is_any_rphy_initialized(ch))
392+
if (!ch->is_otg_channel || !rcar_gen3_is_any_otg_rphy_initialized(ch))
393393
return -EIO;
394394

395395
return sprintf(buf, "%s\n", rcar_gen3_is_host(ch) ? "host" :
@@ -402,6 +402,9 @@ static void rcar_gen3_init_otg(struct rcar_gen3_chan *ch)
402402
void __iomem *usb2_base = ch->base;
403403
u32 val;
404404

405+
if (!ch->is_otg_channel || rcar_gen3_is_any_otg_rphy_initialized(ch))
406+
return;
407+
405408
/* Should not use functions of read-modify-write a register */
406409
val = readl(usb2_base + USB2_LINECTRL1);
407410
val = (val & ~USB2_LINECTRL1_DP_RPD) | USB2_LINECTRL1_DPRPD_EN |
@@ -415,7 +418,7 @@ static void rcar_gen3_init_otg(struct rcar_gen3_chan *ch)
415418
val = readl(usb2_base + USB2_ADPCTRL);
416419
writel(val | USB2_ADPCTRL_IDPULLUP, usb2_base + USB2_ADPCTRL);
417420
}
418-
msleep(20);
421+
mdelay(20);
419422

420423
writel(0xffffffff, usb2_base + USB2_OBINTSTA);
421424
writel(ch->obint_enable_bits, usb2_base + USB2_OBINTEN);
@@ -427,16 +430,27 @@ static irqreturn_t rcar_gen3_phy_usb2_irq(int irq, void *_ch)
427430
{
428431
struct rcar_gen3_chan *ch = _ch;
429432
void __iomem *usb2_base = ch->base;
430-
u32 status = readl(usb2_base + USB2_OBINTSTA);
433+
struct device *dev = ch->dev;
431434
irqreturn_t ret = IRQ_NONE;
435+
u32 status;
436+
437+
pm_runtime_get_noresume(dev);
438+
439+
if (pm_runtime_suspended(dev))
440+
goto rpm_put;
432441

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;
442+
scoped_guard(spinlock, &ch->lock) {
443+
status = readl(usb2_base + USB2_OBINTSTA);
444+
if (status & ch->obint_enable_bits) {
445+
dev_vdbg(dev, "%s: %08x\n", __func__, status);
446+
writel(ch->obint_enable_bits, usb2_base + USB2_OBINTSTA);
447+
rcar_gen3_device_recognition(ch);
448+
ret = IRQ_HANDLED;
449+
}
438450
}
439451

452+
rpm_put:
453+
pm_runtime_put_noidle(dev);
440454
return ret;
441455
}
442456

@@ -446,32 +460,23 @@ static int rcar_gen3_phy_usb2_init(struct phy *p)
446460
struct rcar_gen3_chan *channel = rphy->ch;
447461
void __iomem *usb2_base = channel->base;
448462
u32 val;
449-
int ret;
450463

451-
if (!rcar_gen3_is_any_rphy_initialized(channel) && channel->irq >= 0) {
452-
INIT_WORK(&channel->work, rcar_gen3_phy_usb2_work);
453-
ret = request_irq(channel->irq, rcar_gen3_phy_usb2_irq,
454-
IRQF_SHARED, dev_name(channel->dev), channel);
455-
if (ret < 0) {
456-
dev_err(channel->dev, "No irq handler (%d)\n", channel->irq);
457-
return ret;
458-
}
459-
}
464+
guard(spinlock_irqsave)(&channel->lock);
460465

461466
/* Initialize USB2 part */
462467
val = readl(usb2_base + USB2_INT_ENABLE);
463468
val |= USB2_INT_ENABLE_UCOM_INTEN | rphy->int_enable_bits;
464469
writel(val, usb2_base + USB2_INT_ENABLE);
465-
writel(USB2_SPD_RSM_TIMSET_INIT, usb2_base + USB2_SPD_RSM_TIMSET);
466-
writel(USB2_OC_TIMSET_INIT, usb2_base + USB2_OC_TIMSET);
467-
468-
/* Initialize otg part */
469-
if (channel->is_otg_channel) {
470-
if (rcar_gen3_needs_init_otg(channel))
471-
rcar_gen3_init_otg(channel);
472-
rphy->otg_initialized = true;
470+
471+
if (!rcar_gen3_is_any_rphy_initialized(channel)) {
472+
writel(USB2_SPD_RSM_TIMSET_INIT, usb2_base + USB2_SPD_RSM_TIMSET);
473+
writel(USB2_OC_TIMSET_INIT, usb2_base + USB2_OC_TIMSET);
473474
}
474475

476+
/* Initialize otg part (only if we initialize a PHY with IRQs). */
477+
if (rphy->int_enable_bits)
478+
rcar_gen3_init_otg(channel);
479+
475480
rphy->initialized = true;
476481

477482
return 0;
@@ -484,20 +489,16 @@ static int rcar_gen3_phy_usb2_exit(struct phy *p)
484489
void __iomem *usb2_base = channel->base;
485490
u32 val;
486491

487-
rphy->initialized = false;
492+
guard(spinlock_irqsave)(&channel->lock);
488493

489-
if (channel->is_otg_channel)
490-
rphy->otg_initialized = false;
494+
rphy->initialized = false;
491495

492496
val = readl(usb2_base + USB2_INT_ENABLE);
493497
val &= ~rphy->int_enable_bits;
494498
if (!rcar_gen3_is_any_rphy_initialized(channel))
495499
val &= ~USB2_INT_ENABLE_UCOM_INTEN;
496500
writel(val, usb2_base + USB2_INT_ENABLE);
497501

498-
if (channel->irq >= 0 && !rcar_gen3_is_any_rphy_initialized(channel))
499-
free_irq(channel->irq, channel);
500-
501502
return 0;
502503
}
503504

@@ -509,16 +510,17 @@ static int rcar_gen3_phy_usb2_power_on(struct phy *p)
509510
u32 val;
510511
int ret = 0;
511512

512-
mutex_lock(&channel->lock);
513-
if (!rcar_gen3_are_all_rphys_power_off(channel))
514-
goto out;
515-
516513
if (channel->vbus) {
517514
ret = regulator_enable(channel->vbus);
518515
if (ret)
519-
goto out;
516+
return ret;
520517
}
521518

519+
guard(spinlock_irqsave)(&channel->lock);
520+
521+
if (!rcar_gen3_are_all_rphys_power_off(channel))
522+
goto out;
523+
522524
val = readl(usb2_base + USB2_USBCTR);
523525
val |= USB2_USBCTR_PLL_RST;
524526
writel(val, usb2_base + USB2_USBCTR);
@@ -528,7 +530,6 @@ static int rcar_gen3_phy_usb2_power_on(struct phy *p)
528530
out:
529531
/* The powered flag should be set for any other phys anyway */
530532
rphy->powered = true;
531-
mutex_unlock(&channel->lock);
532533

533534
return 0;
534535
}
@@ -539,18 +540,20 @@ static int rcar_gen3_phy_usb2_power_off(struct phy *p)
539540
struct rcar_gen3_chan *channel = rphy->ch;
540541
int ret = 0;
541542

542-
mutex_lock(&channel->lock);
543-
rphy->powered = false;
543+
scoped_guard(spinlock_irqsave, &channel->lock) {
544+
rphy->powered = false;
544545

545-
if (!rcar_gen3_are_all_rphys_power_off(channel))
546-
goto out;
546+
if (rcar_gen3_are_all_rphys_power_off(channel)) {
547+
u32 val = readl(channel->base + USB2_USBCTR);
548+
549+
val |= USB2_USBCTR_PLL_RST;
550+
writel(val, channel->base + USB2_USBCTR);
551+
}
552+
}
547553

548554
if (channel->vbus)
549555
ret = regulator_disable(channel->vbus);
550556

551-
out:
552-
mutex_unlock(&channel->lock);
553-
554557
return ret;
555558
}
556559

@@ -703,7 +706,7 @@ static int rcar_gen3_phy_usb2_probe(struct platform_device *pdev)
703706
struct device *dev = &pdev->dev;
704707
struct rcar_gen3_chan *channel;
705708
struct phy_provider *provider;
706-
int ret = 0, i;
709+
int ret = 0, i, irq;
707710

708711
if (!dev->of_node) {
709712
dev_err(dev, "This driver needs device tree\n");
@@ -719,8 +722,6 @@ static int rcar_gen3_phy_usb2_probe(struct platform_device *pdev)
719722
return PTR_ERR(channel->base);
720723

721724
channel->obint_enable_bits = USB2_OBINT_BITS;
722-
/* get irq number here and request_irq for OTG in phy_init */
723-
channel->irq = platform_get_irq_optional(pdev, 0);
724725
channel->dr_mode = rcar_gen3_get_dr_mode(dev->of_node);
725726
if (channel->dr_mode != USB_DR_MODE_UNKNOWN) {
726727
channel->is_otg_channel = true;
@@ -763,7 +764,7 @@ static int rcar_gen3_phy_usb2_probe(struct platform_device *pdev)
763764
if (phy_data->no_adp_ctrl)
764765
channel->obint_enable_bits = USB2_OBINT_IDCHG_EN;
765766

766-
mutex_init(&channel->lock);
767+
spin_lock_init(&channel->lock);
767768
for (i = 0; i < NUM_OF_PHYS; i++) {
768769
channel->rphys[i].phy = devm_phy_create(dev, NULL,
769770
phy_data->phy_usb2_ops);
@@ -789,6 +790,20 @@ static int rcar_gen3_phy_usb2_probe(struct platform_device *pdev)
789790
channel->vbus = NULL;
790791
}
791792

793+
irq = platform_get_irq_optional(pdev, 0);
794+
if (irq < 0 && irq != -ENXIO) {
795+
ret = irq;
796+
goto error;
797+
} else if (irq > 0) {
798+
INIT_WORK(&channel->work, rcar_gen3_phy_usb2_work);
799+
ret = devm_request_irq(dev, irq, rcar_gen3_phy_usb2_irq,
800+
IRQF_SHARED, dev_name(dev), channel);
801+
if (ret < 0) {
802+
dev_err(dev, "Failed to request irq (%d)\n", irq);
803+
goto error;
804+
}
805+
}
806+
792807
provider = devm_of_phy_provider_register(dev, rcar_gen3_phy_usb2_xlate);
793808
if (IS_ERR(provider)) {
794809
dev_err(dev, "Failed to register PHY provider\n");

drivers/phy/rockchip/phy-rockchip-samsung-dcphy.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1653,7 +1653,7 @@ static __maybe_unused int samsung_mipi_dcphy_runtime_resume(struct device *dev)
16531653
return ret;
16541654
}
16551655

1656-
clk_prepare_enable(samsung->ref_clk);
1656+
ret = clk_prepare_enable(samsung->ref_clk);
16571657
if (ret) {
16581658
dev_err(samsung->dev, "Failed to enable reference clock, %d\n", ret);
16591659
clk_disable_unprepare(samsung->pclk);

drivers/phy/rockchip/phy-rockchip-samsung-hdptx.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,8 @@ static const struct ropll_config ropll_tmds_cfg[] = {
476476
1, 1, 0, 0x20, 0x0c, 1, 0x0e, 0, 0, },
477477
{ 650000, 162, 162, 1, 1, 11, 1, 1, 1, 1, 1, 1, 1, 54, 0, 16, 4, 1,
478478
1, 1, 0, 0x20, 0x0c, 1, 0x0e, 0, 0, },
479+
{ 502500, 84, 84, 1, 1, 7, 1, 1, 1, 1, 1, 1, 1, 11, 1, 4, 5,
480+
4, 11, 1, 0, 0x20, 0x0c, 1, 0x0e, 0, 0, },
479481
{ 337500, 0x70, 0x70, 1, 1, 0xf, 1, 1, 1, 1, 1, 1, 1, 0x2, 0, 0x01, 5,
480482
1, 1, 1, 0, 0x20, 0x0c, 1, 0x0e, 0, 0, },
481483
{ 400000, 100, 100, 1, 1, 11, 1, 1, 0, 1, 0, 1, 1, 0x9, 0, 0x05, 0,

drivers/phy/starfive/phy-jh7110-usb.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#include <linux/usb/of.h>
1919

2020
#define USB_125M_CLK_RATE 125000000
21+
#define USB_CLK_MODE_OFF 0x0
22+
#define USB_CLK_MODE_RX_NORMAL_PWR BIT(1)
2123
#define USB_LS_KEEPALIVE_OFF 0x4
2224
#define USB_LS_KEEPALIVE_ENABLE BIT(4)
2325

@@ -78,6 +80,7 @@ static int jh7110_usb2_phy_init(struct phy *_phy)
7880
{
7981
struct jh7110_usb2_phy *phy = phy_get_drvdata(_phy);
8082
int ret;
83+
unsigned int val;
8184

8285
ret = clk_set_rate(phy->usb_125m_clk, USB_125M_CLK_RATE);
8386
if (ret)
@@ -87,6 +90,10 @@ static int jh7110_usb2_phy_init(struct phy *_phy)
8790
if (ret)
8891
return ret;
8992

93+
val = readl(phy->regs + USB_CLK_MODE_OFF);
94+
val |= USB_CLK_MODE_RX_NORMAL_PWR;
95+
writel(val, phy->regs + USB_CLK_MODE_OFF);
96+
9097
return 0;
9198
}
9299

0 commit comments

Comments
 (0)