1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2015 Linaro, Ltd.
4 * Rob Herring <robh@kernel.org>
6 * Based on vendor driver:
7 * Copyright (C) 2013 Marvell Inc.
8 * Author: Chao Xie <xiechao.mail@gmail.com>
11 #include <linux/delay.h>
12 #include <linux/slab.h>
15 #include <linux/iopoll.h>
16 #include <linux/err.h>
17 #include <linux/clk.h>
18 #include <linux/module.h>
19 #include <linux/platform_device.h>
20 #include <linux/phy/phy.h>
22 #define PHY_28NM_HSIC_CTRL 0x08
23 #define PHY_28NM_HSIC_IMPCAL_CAL 0x18
24 #define PHY_28NM_HSIC_PLL_CTRL01 0x1c
25 #define PHY_28NM_HSIC_PLL_CTRL2 0x20
26 #define PHY_28NM_HSIC_INT 0x28
28 #define PHY_28NM_HSIC_PLL_SELLPFR_SHIFT 26
29 #define PHY_28NM_HSIC_PLL_FBDIV_SHIFT 0
30 #define PHY_28NM_HSIC_PLL_REFDIV_SHIFT 9
32 #define PHY_28NM_HSIC_S2H_PU_PLL BIT(10)
33 #define PHY_28NM_HSIC_H2S_PLL_LOCK BIT(15)
34 #define PHY_28NM_HSIC_S2H_HSIC_EN BIT(7)
35 #define S2H_DRV_SE0_4RESUME BIT(14)
36 #define PHY_28NM_HSIC_H2S_IMPCAL_DONE BIT(27)
38 #define PHY_28NM_HSIC_CONNECT_INT BIT(1)
39 #define PHY_28NM_HSIC_HS_READY_INT BIT(2)
43 struct platform_device
*pdev
;
48 static int wait_for_reg(void __iomem
*reg
, u32 mask
, u32 ms
)
52 return readl_poll_timeout(reg
, val
, ((val
& mask
) == mask
),
56 static int mv_hsic_phy_init(struct phy
*phy
)
58 struct mv_hsic_phy
*mv_phy
= phy_get_drvdata(phy
);
59 struct platform_device
*pdev
= mv_phy
->pdev
;
60 void __iomem
*base
= mv_phy
->base
;
63 clk_prepare_enable(mv_phy
->clk
);
65 /* Set reference clock */
66 writel(0x1 << PHY_28NM_HSIC_PLL_SELLPFR_SHIFT
|
67 0xf0 << PHY_28NM_HSIC_PLL_FBDIV_SHIFT
|
68 0xd << PHY_28NM_HSIC_PLL_REFDIV_SHIFT
,
69 base
+ PHY_28NM_HSIC_PLL_CTRL01
);
72 writel(readl(base
+ PHY_28NM_HSIC_PLL_CTRL2
) |
73 PHY_28NM_HSIC_S2H_PU_PLL
,
74 base
+ PHY_28NM_HSIC_PLL_CTRL2
);
76 /* Make sure PHY PLL is locked */
77 ret
= wait_for_reg(base
+ PHY_28NM_HSIC_PLL_CTRL2
,
78 PHY_28NM_HSIC_H2S_PLL_LOCK
, 100);
80 dev_err(&pdev
->dev
, "HSIC PHY PLL not locked after 100mS.");
81 clk_disable_unprepare(mv_phy
->clk
);
87 static int mv_hsic_phy_power_on(struct phy
*phy
)
89 struct mv_hsic_phy
*mv_phy
= phy_get_drvdata(phy
);
90 struct platform_device
*pdev
= mv_phy
->pdev
;
91 void __iomem
*base
= mv_phy
->base
;
95 reg
= readl(base
+ PHY_28NM_HSIC_CTRL
);
96 /* Avoid SE0 state when resume for some device will take it as reset */
97 reg
&= ~S2H_DRV_SE0_4RESUME
;
98 reg
|= PHY_28NM_HSIC_S2H_HSIC_EN
; /* Enable HSIC PHY */
99 writel(reg
, base
+ PHY_28NM_HSIC_CTRL
);
103 * ____________________________
105 * ____________________
106 * CAL_DONE ___________|
110 /* Make sure PHY Calibration is ready */
111 ret
= wait_for_reg(base
+ PHY_28NM_HSIC_IMPCAL_CAL
,
112 PHY_28NM_HSIC_H2S_IMPCAL_DONE
, 100);
114 dev_warn(&pdev
->dev
, "HSIC PHY READY not set after 100mS.");
118 /* Waiting for HSIC connect int*/
119 ret
= wait_for_reg(base
+ PHY_28NM_HSIC_INT
,
120 PHY_28NM_HSIC_CONNECT_INT
, 200);
122 dev_warn(&pdev
->dev
, "HSIC wait for connect interrupt timeout.");
127 static int mv_hsic_phy_power_off(struct phy
*phy
)
129 struct mv_hsic_phy
*mv_phy
= phy_get_drvdata(phy
);
130 void __iomem
*base
= mv_phy
->base
;
132 writel(readl(base
+ PHY_28NM_HSIC_CTRL
) & ~PHY_28NM_HSIC_S2H_HSIC_EN
,
133 base
+ PHY_28NM_HSIC_CTRL
);
138 static int mv_hsic_phy_exit(struct phy
*phy
)
140 struct mv_hsic_phy
*mv_phy
= phy_get_drvdata(phy
);
141 void __iomem
*base
= mv_phy
->base
;
144 writel(readl(base
+ PHY_28NM_HSIC_PLL_CTRL2
) &
145 ~PHY_28NM_HSIC_S2H_PU_PLL
,
146 base
+ PHY_28NM_HSIC_PLL_CTRL2
);
148 clk_disable_unprepare(mv_phy
->clk
);
153 static const struct phy_ops hsic_ops
= {
154 .init
= mv_hsic_phy_init
,
155 .power_on
= mv_hsic_phy_power_on
,
156 .power_off
= mv_hsic_phy_power_off
,
157 .exit
= mv_hsic_phy_exit
,
158 .owner
= THIS_MODULE
,
161 static int mv_hsic_phy_probe(struct platform_device
*pdev
)
163 struct phy_provider
*phy_provider
;
164 struct mv_hsic_phy
*mv_phy
;
166 mv_phy
= devm_kzalloc(&pdev
->dev
, sizeof(*mv_phy
), GFP_KERNEL
);
172 mv_phy
->clk
= devm_clk_get(&pdev
->dev
, NULL
);
173 if (IS_ERR(mv_phy
->clk
)) {
174 dev_err(&pdev
->dev
, "failed to get clock.\n");
175 return PTR_ERR(mv_phy
->clk
);
178 mv_phy
->base
= devm_platform_ioremap_resource(pdev
, 0);
179 if (IS_ERR(mv_phy
->base
))
180 return PTR_ERR(mv_phy
->base
);
182 mv_phy
->phy
= devm_phy_create(&pdev
->dev
, pdev
->dev
.of_node
, &hsic_ops
);
183 if (IS_ERR(mv_phy
->phy
))
184 return PTR_ERR(mv_phy
->phy
);
186 phy_set_drvdata(mv_phy
->phy
, mv_phy
);
188 phy_provider
= devm_of_phy_provider_register(&pdev
->dev
, of_phy_simple_xlate
);
189 return PTR_ERR_OR_ZERO(phy_provider
);
192 static const struct of_device_id mv_hsic_phy_dt_match
[] = {
193 { .compatible
= "marvell,pxa1928-hsic-phy", },
196 MODULE_DEVICE_TABLE(of
, mv_hsic_phy_dt_match
);
198 static struct platform_driver mv_hsic_phy_driver
= {
199 .probe
= mv_hsic_phy_probe
,
201 .name
= "mv-hsic-phy",
202 .of_match_table
= of_match_ptr(mv_hsic_phy_dt_match
),
205 module_platform_driver(mv_hsic_phy_driver
);
207 MODULE_AUTHOR("Rob Herring <robh@kernel.org>");
208 MODULE_DESCRIPTION("Marvell HSIC phy driver");
209 MODULE_LICENSE("GPL v2");