Skip to content

Commit 3983b4e

Browse files
ivoszbgvinodkoul
authored andcommitted
phy: phy-snps-eusb2: split phy init code
The current phy init consists of hardware power-up, as well as QCOM-specific eUSB2 init code. Split it into two parts, to make room for such non-QCOM init code. Signed-off-by: Ivaylo Ivanov <[email protected]> Reviewed-by: Dmitry Baryshkov <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Vinod Koul <[email protected]>
1 parent 93dbe9b commit 3983b4e

File tree

1 file changed

+61
-33
lines changed

1 file changed

+61
-33
lines changed

drivers/phy/phy-snps-eusb2.c

Lines changed: 61 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ static const char * const eusb2_hsphy_vreg_names[] = {
121121

122122
#define EUSB2_NUM_VREGS ARRAY_SIZE(eusb2_hsphy_vreg_names)
123123

124+
struct snps_eusb2_phy_drvdata {
125+
int (*phy_init)(struct phy *p);
126+
};
127+
124128
struct snps_eusb2_hsphy {
125129
struct phy *phy;
126130
void __iomem *base;
@@ -133,6 +137,8 @@ struct snps_eusb2_hsphy {
133137
enum phy_mode mode;
134138

135139
struct phy *repeater;
140+
141+
const struct snps_eusb2_phy_drvdata *data;
136142
};
137143

138144
static int snps_eusb2_hsphy_set_mode(struct phy *p, enum phy_mode mode, int submode)
@@ -230,41 +236,11 @@ static int qcom_eusb2_ref_clk_init(struct snps_eusb2_hsphy *phy)
230236
return 0;
231237
}
232238

233-
static int snps_eusb2_hsphy_init(struct phy *p)
239+
static int qcom_snps_eusb2_hsphy_init(struct phy *p)
234240
{
235241
struct snps_eusb2_hsphy *phy = phy_get_drvdata(p);
236242
int ret;
237243

238-
ret = regulator_bulk_enable(ARRAY_SIZE(phy->vregs), phy->vregs);
239-
if (ret)
240-
return ret;
241-
242-
ret = phy_init(phy->repeater);
243-
if (ret) {
244-
dev_err(&p->dev, "repeater init failed. %d\n", ret);
245-
goto disable_vreg;
246-
}
247-
248-
ret = clk_prepare_enable(phy->ref_clk);
249-
if (ret) {
250-
dev_err(&p->dev, "failed to enable ref clock, %d\n", ret);
251-
goto disable_vreg;
252-
}
253-
254-
ret = reset_control_assert(phy->phy_reset);
255-
if (ret) {
256-
dev_err(&p->dev, "failed to assert phy_reset, %d\n", ret);
257-
goto disable_ref_clk;
258-
}
259-
260-
usleep_range(100, 150);
261-
262-
ret = reset_control_deassert(phy->phy_reset);
263-
if (ret) {
264-
dev_err(&p->dev, "failed to de-assert phy_reset, %d\n", ret);
265-
goto disable_ref_clk;
266-
}
267-
268244
snps_eusb2_hsphy_write_mask(phy->base, QCOM_USB_PHY_CFG0,
269245
CMN_CTRL_OVERRIDE_EN, CMN_CTRL_OVERRIDE_EN);
270246

@@ -334,6 +310,52 @@ static int snps_eusb2_hsphy_init(struct phy *p)
334310
USB2_SUSPEND_N_SEL, 0);
335311

336312
return 0;
313+
}
314+
315+
static const struct snps_eusb2_phy_drvdata sm8550_snps_eusb2_phy = {
316+
.phy_init = qcom_snps_eusb2_hsphy_init,
317+
};
318+
319+
static int snps_eusb2_hsphy_init(struct phy *p)
320+
{
321+
struct snps_eusb2_hsphy *phy = phy_get_drvdata(p);
322+
int ret;
323+
324+
ret = regulator_bulk_enable(ARRAY_SIZE(phy->vregs), phy->vregs);
325+
if (ret)
326+
return ret;
327+
328+
ret = phy_init(phy->repeater);
329+
if (ret) {
330+
dev_err(&p->dev, "repeater init failed. %d\n", ret);
331+
goto disable_vreg;
332+
}
333+
334+
ret = clk_prepare_enable(phy->ref_clk);
335+
if (ret) {
336+
dev_err(&p->dev, "failed to enable ref clock, %d\n", ret);
337+
goto disable_vreg;
338+
}
339+
340+
ret = reset_control_assert(phy->phy_reset);
341+
if (ret) {
342+
dev_err(&p->dev, "failed to assert phy_reset, %d\n", ret);
343+
goto disable_ref_clk;
344+
}
345+
346+
usleep_range(100, 150);
347+
348+
ret = reset_control_deassert(phy->phy_reset);
349+
if (ret) {
350+
dev_err(&p->dev, "failed to de-assert phy_reset, %d\n", ret);
351+
goto disable_ref_clk;
352+
}
353+
354+
ret = phy->data->phy_init(p);
355+
if (ret)
356+
goto disable_ref_clk;
357+
358+
return 0;
337359

338360
disable_ref_clk:
339361
clk_disable_unprepare(phy->ref_clk);
@@ -378,6 +400,10 @@ static int snps_eusb2_hsphy_probe(struct platform_device *pdev)
378400
if (!phy)
379401
return -ENOMEM;
380402

403+
phy->data = device_get_match_data(dev);
404+
if (!phy->data)
405+
return -EINVAL;
406+
381407
phy->base = devm_platform_ioremap_resource(pdev, 0);
382408
if (IS_ERR(phy->base))
383409
return PTR_ERR(phy->base);
@@ -424,8 +450,10 @@ static int snps_eusb2_hsphy_probe(struct platform_device *pdev)
424450
}
425451

426452
static const struct of_device_id snps_eusb2_hsphy_of_match_table[] = {
427-
{ .compatible = "qcom,sm8550-snps-eusb2-phy", },
428-
{ },
453+
{
454+
.compatible = "qcom,sm8550-snps-eusb2-phy",
455+
.data = &sm8550_snps_eusb2_phy,
456+
}, { },
429457
};
430458
MODULE_DEVICE_TABLE(of, snps_eusb2_hsphy_of_match_table);
431459

0 commit comments

Comments
 (0)