1 // SPDX-License-Identifier: GPL-2.0-only
3 * Samsung SoC USB 1.1/2.0 PHY driver - Exynos 4x12 support
5 * Copyright (C) 2013 Samsung Electronics Co., Ltd.
6 * Author: Kamil Debski <k.debski@samsung.com>
9 #include <linux/delay.h>
11 #include <linux/phy/phy.h>
12 #include <linux/regmap.h>
13 #include "phy-samsung-usb2.h"
15 /* Exynos USB PHY registers */
17 /* PHY power control */
18 #define EXYNOS_4x12_UPHYPWR 0x0
20 #define EXYNOS_4x12_UPHYPWR_PHY0_SUSPEND BIT(0)
21 #define EXYNOS_4x12_UPHYPWR_PHY0_PWR BIT(3)
22 #define EXYNOS_4x12_UPHYPWR_PHY0_OTG_PWR BIT(4)
23 #define EXYNOS_4x12_UPHYPWR_PHY0_SLEEP BIT(5)
24 #define EXYNOS_4x12_UPHYPWR_PHY0 ( \
25 EXYNOS_4x12_UPHYPWR_PHY0_SUSPEND | \
26 EXYNOS_4x12_UPHYPWR_PHY0_PWR | \
27 EXYNOS_4x12_UPHYPWR_PHY0_OTG_PWR | \
28 EXYNOS_4x12_UPHYPWR_PHY0_SLEEP)
30 #define EXYNOS_4x12_UPHYPWR_PHY1_SUSPEND BIT(6)
31 #define EXYNOS_4x12_UPHYPWR_PHY1_PWR BIT(7)
32 #define EXYNOS_4x12_UPHYPWR_PHY1_SLEEP BIT(8)
33 #define EXYNOS_4x12_UPHYPWR_PHY1 ( \
34 EXYNOS_4x12_UPHYPWR_PHY1_SUSPEND | \
35 EXYNOS_4x12_UPHYPWR_PHY1_PWR | \
36 EXYNOS_4x12_UPHYPWR_PHY1_SLEEP)
38 #define EXYNOS_4x12_UPHYPWR_HSIC0_SUSPEND BIT(9)
39 #define EXYNOS_4x12_UPHYPWR_HSIC0_PWR BIT(10)
40 #define EXYNOS_4x12_UPHYPWR_HSIC0_SLEEP BIT(11)
41 #define EXYNOS_4x12_UPHYPWR_HSIC0 ( \
42 EXYNOS_4x12_UPHYPWR_HSIC0_SUSPEND | \
43 EXYNOS_4x12_UPHYPWR_HSIC0_PWR | \
44 EXYNOS_4x12_UPHYPWR_HSIC0_SLEEP)
46 #define EXYNOS_4x12_UPHYPWR_HSIC1_SUSPEND BIT(12)
47 #define EXYNOS_4x12_UPHYPWR_HSIC1_PWR BIT(13)
48 #define EXYNOS_4x12_UPHYPWR_HSIC1_SLEEP BIT(14)
49 #define EXYNOS_4x12_UPHYPWR_HSIC1 ( \
50 EXYNOS_4x12_UPHYPWR_HSIC1_SUSPEND | \
51 EXYNOS_4x12_UPHYPWR_HSIC1_PWR | \
52 EXYNOS_4x12_UPHYPWR_HSIC1_SLEEP)
54 /* PHY clock control */
55 #define EXYNOS_4x12_UPHYCLK 0x4
57 #define EXYNOS_4x12_UPHYCLK_PHYFSEL_MASK (0x7 << 0)
58 #define EXYNOS_4x12_UPHYCLK_PHYFSEL_OFFSET 0
59 #define EXYNOS_4x12_UPHYCLK_PHYFSEL_9MHZ6 (0x0 << 0)
60 #define EXYNOS_4x12_UPHYCLK_PHYFSEL_10MHZ (0x1 << 0)
61 #define EXYNOS_4x12_UPHYCLK_PHYFSEL_12MHZ (0x2 << 0)
62 #define EXYNOS_4x12_UPHYCLK_PHYFSEL_19MHZ2 (0x3 << 0)
63 #define EXYNOS_4x12_UPHYCLK_PHYFSEL_20MHZ (0x4 << 0)
64 #define EXYNOS_4x12_UPHYCLK_PHYFSEL_24MHZ (0x5 << 0)
65 #define EXYNOS_4x12_UPHYCLK_PHYFSEL_50MHZ (0x7 << 0)
67 #define EXYNOS_3250_UPHYCLK_REFCLKSEL (0x2 << 8)
69 #define EXYNOS_4x12_UPHYCLK_PHY0_ID_PULLUP BIT(3)
70 #define EXYNOS_4x12_UPHYCLK_PHY0_COMMON_ON BIT(4)
71 #define EXYNOS_4x12_UPHYCLK_PHY1_COMMON_ON BIT(7)
73 #define EXYNOS_4x12_UPHYCLK_HSIC_REFCLK_MASK (0x7f << 10)
74 #define EXYNOS_4x12_UPHYCLK_HSIC_REFCLK_OFFSET 10
75 #define EXYNOS_4x12_UPHYCLK_HSIC_REFCLK_12MHZ (0x24 << 10)
76 #define EXYNOS_4x12_UPHYCLK_HSIC_REFCLK_15MHZ (0x1c << 10)
77 #define EXYNOS_4x12_UPHYCLK_HSIC_REFCLK_16MHZ (0x1a << 10)
78 #define EXYNOS_4x12_UPHYCLK_HSIC_REFCLK_19MHZ2 (0x15 << 10)
79 #define EXYNOS_4x12_UPHYCLK_HSIC_REFCLK_20MHZ (0x14 << 10)
81 /* PHY reset control */
82 #define EXYNOS_4x12_UPHYRST 0x8
84 #define EXYNOS_4x12_URSTCON_PHY0 BIT(0)
85 #define EXYNOS_4x12_URSTCON_OTG_HLINK BIT(1)
86 #define EXYNOS_4x12_URSTCON_OTG_PHYLINK BIT(2)
87 #define EXYNOS_4x12_URSTCON_HOST_PHY BIT(3)
88 /* The following bit defines are presented in the
89 * order taken from the Exynos4412 reference manual.
91 * During experiments with the hardware and debugging
92 * it was determined that the hardware behaves contrary
95 * The following bit values were chaned accordingly to the
96 * results of real hardware experiments.
98 #define EXYNOS_4x12_URSTCON_PHY1 BIT(4)
99 #define EXYNOS_4x12_URSTCON_HSIC0 BIT(6)
100 #define EXYNOS_4x12_URSTCON_HSIC1 BIT(5)
101 #define EXYNOS_4x12_URSTCON_HOST_LINK_ALL BIT(7)
102 #define EXYNOS_4x12_URSTCON_HOST_LINK_P0 BIT(10)
103 #define EXYNOS_4x12_URSTCON_HOST_LINK_P1 BIT(9)
104 #define EXYNOS_4x12_URSTCON_HOST_LINK_P2 BIT(8)
106 /* Isolation, configured in the power management unit */
107 #define EXYNOS_4x12_USB_ISOL_OFFSET 0x704
108 #define EXYNOS_4x12_USB_ISOL_OTG BIT(0)
109 #define EXYNOS_4x12_USB_ISOL_HSIC0_OFFSET 0x708
110 #define EXYNOS_4x12_USB_ISOL_HSIC0 BIT(0)
111 #define EXYNOS_4x12_USB_ISOL_HSIC1_OFFSET 0x70c
112 #define EXYNOS_4x12_USB_ISOL_HSIC1 BIT(0)
114 /* Mode switching SUB Device <-> Host */
115 #define EXYNOS_4x12_MODE_SWITCH_OFFSET 0x21c
116 #define EXYNOS_4x12_MODE_SWITCH_MASK 1
117 #define EXYNOS_4x12_MODE_SWITCH_DEVICE 0
118 #define EXYNOS_4x12_MODE_SWITCH_HOST 1
120 enum exynos4x12_phy_id
{
129 * exynos4x12_rate_to_clk() converts the supplied clock rate to the value that
130 * can be written to the phy register.
132 static int exynos4x12_rate_to_clk(unsigned long rate
, u32
*reg
)
134 /* EXYNOS_4x12_UPHYCLK_PHYFSEL_MASK */
138 *reg
= EXYNOS_4x12_UPHYCLK_PHYFSEL_9MHZ6
;
141 *reg
= EXYNOS_4x12_UPHYCLK_PHYFSEL_10MHZ
;
144 *reg
= EXYNOS_4x12_UPHYCLK_PHYFSEL_12MHZ
;
147 *reg
= EXYNOS_4x12_UPHYCLK_PHYFSEL_19MHZ2
;
150 *reg
= EXYNOS_4x12_UPHYCLK_PHYFSEL_20MHZ
;
153 *reg
= EXYNOS_4x12_UPHYCLK_PHYFSEL_24MHZ
;
156 *reg
= EXYNOS_4x12_UPHYCLK_PHYFSEL_50MHZ
;
165 static void exynos4x12_isol(struct samsung_usb2_phy_instance
*inst
, bool on
)
167 struct samsung_usb2_phy_driver
*drv
= inst
->drv
;
171 switch (inst
->cfg
->id
) {
172 case EXYNOS4x12_DEVICE
:
173 case EXYNOS4x12_HOST
:
174 offset
= EXYNOS_4x12_USB_ISOL_OFFSET
;
175 mask
= EXYNOS_4x12_USB_ISOL_OTG
;
177 case EXYNOS4x12_HSIC0
:
178 offset
= EXYNOS_4x12_USB_ISOL_HSIC0_OFFSET
;
179 mask
= EXYNOS_4x12_USB_ISOL_HSIC0
;
181 case EXYNOS4x12_HSIC1
:
182 offset
= EXYNOS_4x12_USB_ISOL_HSIC1_OFFSET
;
183 mask
= EXYNOS_4x12_USB_ISOL_HSIC1
;
189 regmap_update_bits(drv
->reg_pmu
, offset
, mask
, on
? 0 : mask
);
192 static void exynos4x12_setup_clk(struct samsung_usb2_phy_instance
*inst
)
194 struct samsung_usb2_phy_driver
*drv
= inst
->drv
;
197 clk
= readl(drv
->reg_phy
+ EXYNOS_4x12_UPHYCLK
);
198 clk
&= ~EXYNOS_4x12_UPHYCLK_PHYFSEL_MASK
;
200 if (drv
->cfg
->has_refclk_sel
)
201 clk
= EXYNOS_3250_UPHYCLK_REFCLKSEL
;
203 clk
|= drv
->ref_reg_val
<< EXYNOS_4x12_UPHYCLK_PHYFSEL_OFFSET
;
204 clk
|= EXYNOS_4x12_UPHYCLK_PHY1_COMMON_ON
;
205 writel(clk
, drv
->reg_phy
+ EXYNOS_4x12_UPHYCLK
);
208 static void exynos4x12_phy_pwr(struct samsung_usb2_phy_instance
*inst
, bool on
)
210 struct samsung_usb2_phy_driver
*drv
= inst
->drv
;
216 switch (inst
->cfg
->id
) {
217 case EXYNOS4x12_DEVICE
:
218 phypwr
= EXYNOS_4x12_UPHYPWR_PHY0
;
219 rstbits
= EXYNOS_4x12_URSTCON_PHY0
;
221 case EXYNOS4x12_HOST
:
222 phypwr
= EXYNOS_4x12_UPHYPWR_PHY1
;
223 rstbits
= EXYNOS_4x12_URSTCON_HOST_PHY
|
224 EXYNOS_4x12_URSTCON_PHY1
|
225 EXYNOS_4x12_URSTCON_HOST_LINK_P0
;
227 case EXYNOS4x12_HSIC0
:
228 phypwr
= EXYNOS_4x12_UPHYPWR_HSIC0
;
229 rstbits
= EXYNOS_4x12_URSTCON_HSIC0
|
230 EXYNOS_4x12_URSTCON_HOST_LINK_P1
;
232 case EXYNOS4x12_HSIC1
:
233 phypwr
= EXYNOS_4x12_UPHYPWR_HSIC1
;
234 rstbits
= EXYNOS_4x12_URSTCON_HSIC1
|
235 EXYNOS_4x12_URSTCON_HOST_LINK_P1
;
240 pwr
= readl(drv
->reg_phy
+ EXYNOS_4x12_UPHYPWR
);
242 writel(pwr
, drv
->reg_phy
+ EXYNOS_4x12_UPHYPWR
);
244 rst
= readl(drv
->reg_phy
+ EXYNOS_4x12_UPHYRST
);
246 writel(rst
, drv
->reg_phy
+ EXYNOS_4x12_UPHYRST
);
249 writel(rst
, drv
->reg_phy
+ EXYNOS_4x12_UPHYRST
);
250 /* The following delay is necessary for the reset sequence to be
254 pwr
= readl(drv
->reg_phy
+ EXYNOS_4x12_UPHYPWR
);
256 writel(pwr
, drv
->reg_phy
+ EXYNOS_4x12_UPHYPWR
);
260 static void exynos4x12_power_on_int(struct samsung_usb2_phy_instance
*inst
)
262 if (inst
->int_cnt
++ > 0)
265 exynos4x12_setup_clk(inst
);
266 exynos4x12_isol(inst
, 0);
267 exynos4x12_phy_pwr(inst
, 1);
270 static int exynos4x12_power_on(struct samsung_usb2_phy_instance
*inst
)
272 struct samsung_usb2_phy_driver
*drv
= inst
->drv
;
274 if (inst
->ext_cnt
++ > 0)
277 if (inst
->cfg
->id
== EXYNOS4x12_HOST
) {
278 regmap_update_bits(drv
->reg_sys
, EXYNOS_4x12_MODE_SWITCH_OFFSET
,
279 EXYNOS_4x12_MODE_SWITCH_MASK
,
280 EXYNOS_4x12_MODE_SWITCH_HOST
);
281 exynos4x12_power_on_int(&drv
->instances
[EXYNOS4x12_DEVICE
]);
284 if (inst
->cfg
->id
== EXYNOS4x12_DEVICE
&& drv
->cfg
->has_mode_switch
)
285 regmap_update_bits(drv
->reg_sys
, EXYNOS_4x12_MODE_SWITCH_OFFSET
,
286 EXYNOS_4x12_MODE_SWITCH_MASK
,
287 EXYNOS_4x12_MODE_SWITCH_DEVICE
);
289 if (inst
->cfg
->id
== EXYNOS4x12_HSIC0
||
290 inst
->cfg
->id
== EXYNOS4x12_HSIC1
) {
291 exynos4x12_power_on_int(&drv
->instances
[EXYNOS4x12_DEVICE
]);
292 exynos4x12_power_on_int(&drv
->instances
[EXYNOS4x12_HOST
]);
295 exynos4x12_power_on_int(inst
);
300 static void exynos4x12_power_off_int(struct samsung_usb2_phy_instance
*inst
)
302 if (inst
->int_cnt
-- > 1)
305 exynos4x12_isol(inst
, 1);
306 exynos4x12_phy_pwr(inst
, 0);
309 static int exynos4x12_power_off(struct samsung_usb2_phy_instance
*inst
)
311 struct samsung_usb2_phy_driver
*drv
= inst
->drv
;
313 if (inst
->ext_cnt
-- > 1)
316 if (inst
->cfg
->id
== EXYNOS4x12_DEVICE
&& drv
->cfg
->has_mode_switch
)
317 regmap_update_bits(drv
->reg_sys
, EXYNOS_4x12_MODE_SWITCH_OFFSET
,
318 EXYNOS_4x12_MODE_SWITCH_MASK
,
319 EXYNOS_4x12_MODE_SWITCH_HOST
);
321 if (inst
->cfg
->id
== EXYNOS4x12_HOST
)
322 exynos4x12_power_off_int(&drv
->instances
[EXYNOS4x12_DEVICE
]);
324 if (inst
->cfg
->id
== EXYNOS4x12_HSIC0
||
325 inst
->cfg
->id
== EXYNOS4x12_HSIC1
) {
326 exynos4x12_power_off_int(&drv
->instances
[EXYNOS4x12_DEVICE
]);
327 exynos4x12_power_off_int(&drv
->instances
[EXYNOS4x12_HOST
]);
330 exynos4x12_power_off_int(inst
);
336 static const struct samsung_usb2_common_phy exynos4x12_phys
[] = {
339 .id
= EXYNOS4x12_DEVICE
,
340 .power_on
= exynos4x12_power_on
,
341 .power_off
= exynos4x12_power_off
,
345 .id
= EXYNOS4x12_HOST
,
346 .power_on
= exynos4x12_power_on
,
347 .power_off
= exynos4x12_power_off
,
351 .id
= EXYNOS4x12_HSIC0
,
352 .power_on
= exynos4x12_power_on
,
353 .power_off
= exynos4x12_power_off
,
357 .id
= EXYNOS4x12_HSIC1
,
358 .power_on
= exynos4x12_power_on
,
359 .power_off
= exynos4x12_power_off
,
363 const struct samsung_usb2_phy_config exynos3250_usb2_phy_config
= {
366 .phys
= exynos4x12_phys
,
367 .rate_to_clk
= exynos4x12_rate_to_clk
,
370 const struct samsung_usb2_phy_config exynos4x12_usb2_phy_config
= {
371 .has_mode_switch
= 1,
372 .num_phys
= EXYNOS4x12_NUM_PHYS
,
373 .phys
= exynos4x12_phys
,
374 .rate_to_clk
= exynos4x12_rate_to_clk
,