1 // SPDX-License-Identifier: GPL-2.0-only
3 * Samsung EXYNOS5 SoC series USB DRD PHY driver
5 * Phy provider for USB 3.0 DRD controller on Exynos5 SoC series
7 * Copyright (C) 2014 Samsung Electronics Co., Ltd.
8 * Author: Vivek Gautam <gautam.vivek@samsung.com>
11 #include <linux/clk.h>
12 #include <linux/delay.h>
14 #include <linux/kernel.h>
15 #include <linux/module.h>
17 #include <linux/of_address.h>
18 #include <linux/of_device.h>
19 #include <linux/phy/phy.h>
20 #include <linux/platform_device.h>
21 #include <linux/mutex.h>
22 #include <linux/mfd/syscon.h>
23 #include <linux/regmap.h>
24 #include <linux/regulator/consumer.h>
25 #include <linux/soc/samsung/exynos-regs-pmu.h>
27 /* Exynos USB PHY registers */
28 #define EXYNOS5_FSEL_9MHZ6 0x0
29 #define EXYNOS5_FSEL_10MHZ 0x1
30 #define EXYNOS5_FSEL_12MHZ 0x2
31 #define EXYNOS5_FSEL_19MHZ2 0x3
32 #define EXYNOS5_FSEL_20MHZ 0x4
33 #define EXYNOS5_FSEL_24MHZ 0x5
34 #define EXYNOS5_FSEL_50MHZ 0x7
36 /* EXYNOS5: USB 3.0 DRD PHY registers */
37 #define EXYNOS5_DRD_LINKSYSTEM 0x04
39 #define LINKSYSTEM_FLADJ_MASK (0x3f << 1)
40 #define LINKSYSTEM_FLADJ(_x) ((_x) << 1)
41 #define LINKSYSTEM_XHCI_VERSION_CONTROL BIT(27)
43 #define EXYNOS5_DRD_PHYUTMI 0x08
45 #define PHYUTMI_OTGDISABLE BIT(6)
46 #define PHYUTMI_FORCESUSPEND BIT(1)
47 #define PHYUTMI_FORCESLEEP BIT(0)
49 #define EXYNOS5_DRD_PHYPIPE 0x0c
51 #define EXYNOS5_DRD_PHYCLKRST 0x10
53 #define PHYCLKRST_EN_UTMISUSPEND BIT(31)
55 #define PHYCLKRST_SSC_REFCLKSEL_MASK (0xff << 23)
56 #define PHYCLKRST_SSC_REFCLKSEL(_x) ((_x) << 23)
58 #define PHYCLKRST_SSC_RANGE_MASK (0x03 << 21)
59 #define PHYCLKRST_SSC_RANGE(_x) ((_x) << 21)
61 #define PHYCLKRST_SSC_EN BIT(20)
62 #define PHYCLKRST_REF_SSP_EN BIT(19)
63 #define PHYCLKRST_REF_CLKDIV2 BIT(18)
65 #define PHYCLKRST_MPLL_MULTIPLIER_MASK (0x7f << 11)
66 #define PHYCLKRST_MPLL_MULTIPLIER_100MHZ_REF (0x19 << 11)
67 #define PHYCLKRST_MPLL_MULTIPLIER_50M_REF (0x32 << 11)
68 #define PHYCLKRST_MPLL_MULTIPLIER_24MHZ_REF (0x68 << 11)
69 #define PHYCLKRST_MPLL_MULTIPLIER_20MHZ_REF (0x7d << 11)
70 #define PHYCLKRST_MPLL_MULTIPLIER_19200KHZ_REF (0x02 << 11)
72 #define PHYCLKRST_FSEL_UTMI_MASK (0x7 << 5)
73 #define PHYCLKRST_FSEL_PIPE_MASK (0x7 << 8)
74 #define PHYCLKRST_FSEL(_x) ((_x) << 5)
75 #define PHYCLKRST_FSEL_PAD_100MHZ (0x27 << 5)
76 #define PHYCLKRST_FSEL_PAD_24MHZ (0x2a << 5)
77 #define PHYCLKRST_FSEL_PAD_20MHZ (0x31 << 5)
78 #define PHYCLKRST_FSEL_PAD_19_2MHZ (0x38 << 5)
80 #define PHYCLKRST_RETENABLEN BIT(4)
82 #define PHYCLKRST_REFCLKSEL_MASK (0x03 << 2)
83 #define PHYCLKRST_REFCLKSEL_PAD_REFCLK (0x2 << 2)
84 #define PHYCLKRST_REFCLKSEL_EXT_REFCLK (0x3 << 2)
86 #define PHYCLKRST_PORTRESET BIT(1)
87 #define PHYCLKRST_COMMONONN BIT(0)
89 #define EXYNOS5_DRD_PHYREG0 0x14
90 #define PHYREG0_SSC_REF_CLK_SEL BIT(21)
91 #define PHYREG0_SSC_RANGE BIT(20)
92 #define PHYREG0_CR_WRITE BIT(19)
93 #define PHYREG0_CR_READ BIT(18)
94 #define PHYREG0_CR_DATA_IN(_x) ((_x) << 2)
95 #define PHYREG0_CR_CAP_DATA BIT(1)
96 #define PHYREG0_CR_CAP_ADDR BIT(0)
98 #define EXYNOS5_DRD_PHYREG1 0x18
99 #define PHYREG1_CR_DATA_OUT(_x) ((_x) << 1)
100 #define PHYREG1_CR_ACK BIT(0)
102 #define EXYNOS5_DRD_PHYPARAM0 0x1c
104 #define PHYPARAM0_REF_USE_PAD BIT(31)
105 #define PHYPARAM0_REF_LOSLEVEL_MASK (0x1f << 26)
106 #define PHYPARAM0_REF_LOSLEVEL (0x9 << 26)
108 #define EXYNOS5_DRD_PHYPARAM1 0x20
110 #define PHYPARAM1_PCS_TXDEEMPH_MASK (0x1f << 0)
111 #define PHYPARAM1_PCS_TXDEEMPH (0x1c)
113 #define EXYNOS5_DRD_PHYTERM 0x24
115 #define EXYNOS5_DRD_PHYTEST 0x28
117 #define PHYTEST_POWERDOWN_SSP BIT(3)
118 #define PHYTEST_POWERDOWN_HSP BIT(2)
120 #define EXYNOS5_DRD_PHYADP 0x2c
122 #define EXYNOS5_DRD_PHYUTMICLKSEL 0x30
124 #define PHYUTMICLKSEL_UTMI_CLKSEL BIT(2)
126 #define EXYNOS5_DRD_PHYRESUME 0x34
127 #define EXYNOS5_DRD_LINKPORT 0x44
129 /* USB 3.0 DRD PHY SS Function Control Reg; accessed by CR_PORT */
130 #define EXYNOS5_DRD_PHYSS_LOSLEVEL_OVRD_IN (0x15)
131 #define LOSLEVEL_OVRD_IN_LOS_BIAS_5420 (0x5 << 13)
132 #define LOSLEVEL_OVRD_IN_LOS_BIAS_DEFAULT (0x0 << 13)
133 #define LOSLEVEL_OVRD_IN_EN (0x1 << 10)
134 #define LOSLEVEL_OVRD_IN_LOS_LEVEL_DEFAULT (0x9 << 0)
136 #define EXYNOS5_DRD_PHYSS_TX_VBOOSTLEVEL_OVRD_IN (0x12)
137 #define TX_VBOOSTLEVEL_OVRD_IN_VBOOST_5420 (0x5 << 13)
138 #define TX_VBOOSTLEVEL_OVRD_IN_VBOOST_DEFAULT (0x4 << 13)
140 #define EXYNOS5_DRD_PHYSS_LANE0_TX_DEBUG (0x1010)
141 #define LANE0_TX_DEBUG_RXDET_MEAS_TIME_19M2_20M (0x4 << 4)
142 #define LANE0_TX_DEBUG_RXDET_MEAS_TIME_24M (0x8 << 4)
143 #define LANE0_TX_DEBUG_RXDET_MEAS_TIME_25M_26M (0x8 << 4)
144 #define LANE0_TX_DEBUG_RXDET_MEAS_TIME_48M_50M_52M (0x20 << 4)
145 #define LANE0_TX_DEBUG_RXDET_MEAS_TIME_62M5 (0x20 << 4)
146 #define LANE0_TX_DEBUG_RXDET_MEAS_TIME_96M_100M (0x40 << 4)
149 #define MHZ (KHZ * KHZ)
151 enum exynos5_usbdrd_phy_id
{
153 EXYNOS5_DRDPHY_PIPE3
,
157 struct phy_usb_instance
;
158 struct exynos5_usbdrd_phy
;
160 struct exynos5_usbdrd_phy_config
{
162 void (*phy_isol
)(struct phy_usb_instance
*inst
, u32 on
);
163 void (*phy_init
)(struct exynos5_usbdrd_phy
*phy_drd
);
164 unsigned int (*set_refclk
)(struct phy_usb_instance
*inst
);
167 struct exynos5_usbdrd_phy_drvdata
{
168 const struct exynos5_usbdrd_phy_config
*phy_cfg
;
169 u32 pmu_offset_usbdrd0_phy
;
170 u32 pmu_offset_usbdrd1_phy
;
171 bool has_common_clk_gate
;
175 * struct exynos5_usbdrd_phy - driver data for USB 3.0 PHY
176 * @dev: pointer to device instance of this platform device
177 * @reg_phy: usb phy controller register memory base
178 * @clk: phy clock for register access
179 * @pipeclk: clock for pipe3 phy
180 * @utmiclk: clock for utmi+ phy
181 * @itpclk: clock for ITP generation
182 * @drv_data: pointer to SoC level driver data structure
183 * @phys[]: array for 'EXYNOS5_DRDPHYS_NUM' number of PHY
184 * instances each with its 'phy' and 'phy_cfg'.
185 * @extrefclk: frequency select settings when using 'separate
186 * reference clocks' for SS and HS operations
187 * @ref_clk: reference clock to PHY block from which PHY's
188 * operational clocks are derived
189 * vbus: VBUS regulator for phy
190 * vbus_boost: Boost regulator for VBUS present on few Exynos boards
192 struct exynos5_usbdrd_phy
{
194 void __iomem
*reg_phy
;
199 const struct exynos5_usbdrd_phy_drvdata
*drv_data
;
200 struct phy_usb_instance
{
203 struct regmap
*reg_pmu
;
205 const struct exynos5_usbdrd_phy_config
*phy_cfg
;
206 } phys
[EXYNOS5_DRDPHYS_NUM
];
209 struct regulator
*vbus
;
210 struct regulator
*vbus_boost
;
214 struct exynos5_usbdrd_phy
*to_usbdrd_phy(struct phy_usb_instance
*inst
)
216 return container_of((inst
), struct exynos5_usbdrd_phy
,
217 phys
[(inst
)->index
]);
221 * exynos5_rate_to_clk() converts the supplied clock rate to the value that
222 * can be written to the phy register.
224 static unsigned int exynos5_rate_to_clk(unsigned long rate
, u32
*reg
)
226 /* EXYNOS5_FSEL_MASK */
230 *reg
= EXYNOS5_FSEL_9MHZ6
;
233 *reg
= EXYNOS5_FSEL_10MHZ
;
236 *reg
= EXYNOS5_FSEL_12MHZ
;
239 *reg
= EXYNOS5_FSEL_19MHZ2
;
242 *reg
= EXYNOS5_FSEL_20MHZ
;
245 *reg
= EXYNOS5_FSEL_24MHZ
;
248 *reg
= EXYNOS5_FSEL_50MHZ
;
257 static void exynos5_usbdrd_phy_isol(struct phy_usb_instance
*inst
,
265 val
= on
? 0 : EXYNOS4_PHY_ENABLE
;
267 regmap_update_bits(inst
->reg_pmu
, inst
->pmu_offset
,
268 EXYNOS4_PHY_ENABLE
, val
);
272 * Sets the pipe3 phy's clk as EXTREFCLK (XXTI) which is internal clock
273 * from clock core. Further sets multiplier values and spread spectrum
274 * clock settings for SuperSpeed operations.
277 exynos5_usbdrd_pipe3_set_refclk(struct phy_usb_instance
*inst
)
280 struct exynos5_usbdrd_phy
*phy_drd
= to_usbdrd_phy(inst
);
282 /* restore any previous reference clock settings */
283 reg
= readl(phy_drd
->reg_phy
+ EXYNOS5_DRD_PHYCLKRST
);
285 /* Use EXTREFCLK as ref clock */
286 reg
&= ~PHYCLKRST_REFCLKSEL_MASK
;
287 reg
|= PHYCLKRST_REFCLKSEL_EXT_REFCLK
;
289 /* FSEL settings corresponding to reference clock */
290 reg
&= ~PHYCLKRST_FSEL_PIPE_MASK
|
291 PHYCLKRST_MPLL_MULTIPLIER_MASK
|
292 PHYCLKRST_SSC_REFCLKSEL_MASK
;
293 switch (phy_drd
->extrefclk
) {
294 case EXYNOS5_FSEL_50MHZ
:
295 reg
|= (PHYCLKRST_MPLL_MULTIPLIER_50M_REF
|
296 PHYCLKRST_SSC_REFCLKSEL(0x00));
298 case EXYNOS5_FSEL_24MHZ
:
299 reg
|= (PHYCLKRST_MPLL_MULTIPLIER_24MHZ_REF
|
300 PHYCLKRST_SSC_REFCLKSEL(0x88));
302 case EXYNOS5_FSEL_20MHZ
:
303 reg
|= (PHYCLKRST_MPLL_MULTIPLIER_20MHZ_REF
|
304 PHYCLKRST_SSC_REFCLKSEL(0x00));
306 case EXYNOS5_FSEL_19MHZ2
:
307 reg
|= (PHYCLKRST_MPLL_MULTIPLIER_19200KHZ_REF
|
308 PHYCLKRST_SSC_REFCLKSEL(0x88));
311 dev_dbg(phy_drd
->dev
, "unsupported ref clk\n");
319 * Sets the utmi phy's clk as EXTREFCLK (XXTI) which is internal clock
320 * from clock core. Further sets the FSEL values for HighSpeed operations.
323 exynos5_usbdrd_utmi_set_refclk(struct phy_usb_instance
*inst
)
326 struct exynos5_usbdrd_phy
*phy_drd
= to_usbdrd_phy(inst
);
328 /* restore any previous reference clock settings */
329 reg
= readl(phy_drd
->reg_phy
+ EXYNOS5_DRD_PHYCLKRST
);
331 reg
&= ~PHYCLKRST_REFCLKSEL_MASK
;
332 reg
|= PHYCLKRST_REFCLKSEL_EXT_REFCLK
;
334 reg
&= ~PHYCLKRST_FSEL_UTMI_MASK
|
335 PHYCLKRST_MPLL_MULTIPLIER_MASK
|
336 PHYCLKRST_SSC_REFCLKSEL_MASK
;
337 reg
|= PHYCLKRST_FSEL(phy_drd
->extrefclk
);
342 static void exynos5_usbdrd_pipe3_init(struct exynos5_usbdrd_phy
*phy_drd
)
346 reg
= readl(phy_drd
->reg_phy
+ EXYNOS5_DRD_PHYPARAM1
);
347 /* Set Tx De-Emphasis level */
348 reg
&= ~PHYPARAM1_PCS_TXDEEMPH_MASK
;
349 reg
|= PHYPARAM1_PCS_TXDEEMPH
;
350 writel(reg
, phy_drd
->reg_phy
+ EXYNOS5_DRD_PHYPARAM1
);
352 reg
= readl(phy_drd
->reg_phy
+ EXYNOS5_DRD_PHYTEST
);
353 reg
&= ~PHYTEST_POWERDOWN_SSP
;
354 writel(reg
, phy_drd
->reg_phy
+ EXYNOS5_DRD_PHYTEST
);
357 static void exynos5_usbdrd_utmi_init(struct exynos5_usbdrd_phy
*phy_drd
)
361 reg
= readl(phy_drd
->reg_phy
+ EXYNOS5_DRD_PHYPARAM0
);
362 /* Set Loss-of-Signal Detector sensitivity */
363 reg
&= ~PHYPARAM0_REF_LOSLEVEL_MASK
;
364 reg
|= PHYPARAM0_REF_LOSLEVEL
;
365 writel(reg
, phy_drd
->reg_phy
+ EXYNOS5_DRD_PHYPARAM0
);
367 reg
= readl(phy_drd
->reg_phy
+ EXYNOS5_DRD_PHYPARAM1
);
368 /* Set Tx De-Emphasis level */
369 reg
&= ~PHYPARAM1_PCS_TXDEEMPH_MASK
;
370 reg
|= PHYPARAM1_PCS_TXDEEMPH
;
371 writel(reg
, phy_drd
->reg_phy
+ EXYNOS5_DRD_PHYPARAM1
);
373 /* UTMI Power Control */
374 writel(PHYUTMI_OTGDISABLE
, phy_drd
->reg_phy
+ EXYNOS5_DRD_PHYUTMI
);
376 reg
= readl(phy_drd
->reg_phy
+ EXYNOS5_DRD_PHYTEST
);
377 reg
&= ~PHYTEST_POWERDOWN_HSP
;
378 writel(reg
, phy_drd
->reg_phy
+ EXYNOS5_DRD_PHYTEST
);
381 static int exynos5_usbdrd_phy_init(struct phy
*phy
)
385 struct phy_usb_instance
*inst
= phy_get_drvdata(phy
);
386 struct exynos5_usbdrd_phy
*phy_drd
= to_usbdrd_phy(inst
);
388 ret
= clk_prepare_enable(phy_drd
->clk
);
392 /* Reset USB 3.0 PHY */
393 writel(0x0, phy_drd
->reg_phy
+ EXYNOS5_DRD_PHYREG0
);
394 writel(0x0, phy_drd
->reg_phy
+ EXYNOS5_DRD_PHYRESUME
);
397 * Setting the Frame length Adj value[6:1] to default 0x20
398 * See xHCI 1.0 spec, 5.2.4
400 reg
= LINKSYSTEM_XHCI_VERSION_CONTROL
|
401 LINKSYSTEM_FLADJ(0x20);
402 writel(reg
, phy_drd
->reg_phy
+ EXYNOS5_DRD_LINKSYSTEM
);
404 reg
= readl(phy_drd
->reg_phy
+ EXYNOS5_DRD_PHYPARAM0
);
405 /* Select PHY CLK source */
406 reg
&= ~PHYPARAM0_REF_USE_PAD
;
407 writel(reg
, phy_drd
->reg_phy
+ EXYNOS5_DRD_PHYPARAM0
);
409 /* This bit must be set for both HS and SS operations */
410 reg
= readl(phy_drd
->reg_phy
+ EXYNOS5_DRD_PHYUTMICLKSEL
);
411 reg
|= PHYUTMICLKSEL_UTMI_CLKSEL
;
412 writel(reg
, phy_drd
->reg_phy
+ EXYNOS5_DRD_PHYUTMICLKSEL
);
414 /* UTMI or PIPE3 specific init */
415 inst
->phy_cfg
->phy_init(phy_drd
);
417 /* reference clock settings */
418 reg
= inst
->phy_cfg
->set_refclk(inst
);
420 /* Digital power supply in normal operating mode */
421 reg
|= PHYCLKRST_RETENABLEN
|
422 /* Enable ref clock for SS function */
423 PHYCLKRST_REF_SSP_EN
|
424 /* Enable spread spectrum */
426 /* Power down HS Bias and PLL blocks in suspend mode */
427 PHYCLKRST_COMMONONN
|
431 writel(reg
, phy_drd
->reg_phy
+ EXYNOS5_DRD_PHYCLKRST
);
435 reg
&= ~PHYCLKRST_PORTRESET
;
436 writel(reg
, phy_drd
->reg_phy
+ EXYNOS5_DRD_PHYCLKRST
);
438 clk_disable_unprepare(phy_drd
->clk
);
443 static int exynos5_usbdrd_phy_exit(struct phy
*phy
)
447 struct phy_usb_instance
*inst
= phy_get_drvdata(phy
);
448 struct exynos5_usbdrd_phy
*phy_drd
= to_usbdrd_phy(inst
);
450 ret
= clk_prepare_enable(phy_drd
->clk
);
454 reg
= PHYUTMI_OTGDISABLE
|
455 PHYUTMI_FORCESUSPEND
|
457 writel(reg
, phy_drd
->reg_phy
+ EXYNOS5_DRD_PHYUTMI
);
459 /* Resetting the PHYCLKRST enable bits to reduce leakage current */
460 reg
= readl(phy_drd
->reg_phy
+ EXYNOS5_DRD_PHYCLKRST
);
461 reg
&= ~(PHYCLKRST_REF_SSP_EN
|
463 PHYCLKRST_COMMONONN
);
464 writel(reg
, phy_drd
->reg_phy
+ EXYNOS5_DRD_PHYCLKRST
);
466 /* Control PHYTEST to remove leakage current */
467 reg
= readl(phy_drd
->reg_phy
+ EXYNOS5_DRD_PHYTEST
);
468 reg
|= PHYTEST_POWERDOWN_SSP
|
469 PHYTEST_POWERDOWN_HSP
;
470 writel(reg
, phy_drd
->reg_phy
+ EXYNOS5_DRD_PHYTEST
);
472 clk_disable_unprepare(phy_drd
->clk
);
477 static int exynos5_usbdrd_phy_power_on(struct phy
*phy
)
480 struct phy_usb_instance
*inst
= phy_get_drvdata(phy
);
481 struct exynos5_usbdrd_phy
*phy_drd
= to_usbdrd_phy(inst
);
483 dev_dbg(phy_drd
->dev
, "Request to power_on usbdrd_phy phy\n");
485 clk_prepare_enable(phy_drd
->ref_clk
);
486 if (!phy_drd
->drv_data
->has_common_clk_gate
) {
487 clk_prepare_enable(phy_drd
->pipeclk
);
488 clk_prepare_enable(phy_drd
->utmiclk
);
489 clk_prepare_enable(phy_drd
->itpclk
);
492 /* Enable VBUS supply */
493 if (phy_drd
->vbus_boost
) {
494 ret
= regulator_enable(phy_drd
->vbus_boost
);
496 dev_err(phy_drd
->dev
,
497 "Failed to enable VBUS boost supply\n");
503 ret
= regulator_enable(phy_drd
->vbus
);
505 dev_err(phy_drd
->dev
, "Failed to enable VBUS supply\n");
506 goto fail_vbus_boost
;
511 inst
->phy_cfg
->phy_isol(inst
, 0);
516 if (phy_drd
->vbus_boost
)
517 regulator_disable(phy_drd
->vbus_boost
);
520 clk_disable_unprepare(phy_drd
->ref_clk
);
521 if (!phy_drd
->drv_data
->has_common_clk_gate
) {
522 clk_disable_unprepare(phy_drd
->itpclk
);
523 clk_disable_unprepare(phy_drd
->utmiclk
);
524 clk_disable_unprepare(phy_drd
->pipeclk
);
530 static int exynos5_usbdrd_phy_power_off(struct phy
*phy
)
532 struct phy_usb_instance
*inst
= phy_get_drvdata(phy
);
533 struct exynos5_usbdrd_phy
*phy_drd
= to_usbdrd_phy(inst
);
535 dev_dbg(phy_drd
->dev
, "Request to power_off usbdrd_phy phy\n");
537 /* Power-off the PHY */
538 inst
->phy_cfg
->phy_isol(inst
, 1);
540 /* Disable VBUS supply */
542 regulator_disable(phy_drd
->vbus
);
543 if (phy_drd
->vbus_boost
)
544 regulator_disable(phy_drd
->vbus_boost
);
546 clk_disable_unprepare(phy_drd
->ref_clk
);
547 if (!phy_drd
->drv_data
->has_common_clk_gate
) {
548 clk_disable_unprepare(phy_drd
->itpclk
);
549 clk_disable_unprepare(phy_drd
->pipeclk
);
550 clk_disable_unprepare(phy_drd
->utmiclk
);
556 static int crport_handshake(struct exynos5_usbdrd_phy
*phy_drd
,
562 writel(val
| cmd
, phy_drd
->reg_phy
+ EXYNOS5_DRD_PHYREG0
);
565 result
= readl(phy_drd
->reg_phy
+ EXYNOS5_DRD_PHYREG1
);
566 if (result
& PHYREG1_CR_ACK
)
570 } while (usec
-- > 0);
573 dev_err(phy_drd
->dev
,
574 "CRPORT handshake timeout1 (0x%08x)\n", val
);
580 writel(val
, phy_drd
->reg_phy
+ EXYNOS5_DRD_PHYREG0
);
583 result
= readl(phy_drd
->reg_phy
+ EXYNOS5_DRD_PHYREG1
);
584 if (!(result
& PHYREG1_CR_ACK
))
588 } while (usec
-- > 0);
591 dev_err(phy_drd
->dev
,
592 "CRPORT handshake timeout2 (0x%08x)\n", val
);
599 static int crport_ctrl_write(struct exynos5_usbdrd_phy
*phy_drd
,
605 writel(PHYREG0_CR_DATA_IN(addr
),
606 phy_drd
->reg_phy
+ EXYNOS5_DRD_PHYREG0
);
607 ret
= crport_handshake(phy_drd
, PHYREG0_CR_DATA_IN(addr
),
608 PHYREG0_CR_CAP_ADDR
);
613 writel(PHYREG0_CR_DATA_IN(data
),
614 phy_drd
->reg_phy
+ EXYNOS5_DRD_PHYREG0
);
615 ret
= crport_handshake(phy_drd
, PHYREG0_CR_DATA_IN(data
),
616 PHYREG0_CR_CAP_DATA
);
620 ret
= crport_handshake(phy_drd
, PHYREG0_CR_DATA_IN(data
),
627 * Calibrate few PHY parameters using CR_PORT register to meet
628 * SuperSpeed requirements on Exynos5420 and Exynos5800 systems,
629 * which have 28nm USB 3.0 DRD PHY.
631 static int exynos5420_usbdrd_phy_calibrate(struct exynos5_usbdrd_phy
*phy_drd
)
637 * Change los_bias to (0x5) for 28nm PHY from a
638 * default value (0x0); los_level is set as default
639 * (0x9) as also reflected in los_level[30:26] bits
640 * of PHYPARAM0 register.
642 temp
= LOSLEVEL_OVRD_IN_LOS_BIAS_5420
|
643 LOSLEVEL_OVRD_IN_EN
|
644 LOSLEVEL_OVRD_IN_LOS_LEVEL_DEFAULT
;
645 ret
= crport_ctrl_write(phy_drd
,
646 EXYNOS5_DRD_PHYSS_LOSLEVEL_OVRD_IN
,
649 dev_err(phy_drd
->dev
,
650 "Failed setting Loss-of-Signal level for SuperSpeed\n");
655 * Set tx_vboost_lvl to (0x5) for 28nm PHY Tuning,
656 * to raise Tx signal level from its default value of (0x4)
658 temp
= TX_VBOOSTLEVEL_OVRD_IN_VBOOST_5420
;
659 ret
= crport_ctrl_write(phy_drd
,
660 EXYNOS5_DRD_PHYSS_TX_VBOOSTLEVEL_OVRD_IN
,
663 dev_err(phy_drd
->dev
,
664 "Failed setting Tx-Vboost-Level for SuperSpeed\n");
669 * Set proper time to wait for RxDetect measurement, for
670 * desired reference clock of PHY, by tuning the CR_PORT
671 * register LANE0.TX_DEBUG which is internal to PHY.
672 * This fixes issue with few USB 3.0 devices, which are
673 * not detected (not even generate interrupts on the bus
674 * on insertion) without this change.
675 * e.g. Samsung SUM-TSB16S 3.0 USB drive.
677 switch (phy_drd
->extrefclk
) {
678 case EXYNOS5_FSEL_50MHZ
:
679 temp
= LANE0_TX_DEBUG_RXDET_MEAS_TIME_48M_50M_52M
;
681 case EXYNOS5_FSEL_20MHZ
:
682 case EXYNOS5_FSEL_19MHZ2
:
683 temp
= LANE0_TX_DEBUG_RXDET_MEAS_TIME_19M2_20M
;
685 case EXYNOS5_FSEL_24MHZ
:
687 temp
= LANE0_TX_DEBUG_RXDET_MEAS_TIME_24M
;
691 ret
= crport_ctrl_write(phy_drd
,
692 EXYNOS5_DRD_PHYSS_LANE0_TX_DEBUG
,
695 dev_err(phy_drd
->dev
,
696 "Fail to set RxDet measurement time for SuperSpeed\n");
701 static struct phy
*exynos5_usbdrd_phy_xlate(struct device
*dev
,
702 struct of_phandle_args
*args
)
704 struct exynos5_usbdrd_phy
*phy_drd
= dev_get_drvdata(dev
);
706 if (WARN_ON(args
->args
[0] >= EXYNOS5_DRDPHYS_NUM
))
707 return ERR_PTR(-ENODEV
);
709 return phy_drd
->phys
[args
->args
[0]].phy
;
712 static int exynos5_usbdrd_phy_calibrate(struct phy
*phy
)
714 struct phy_usb_instance
*inst
= phy_get_drvdata(phy
);
715 struct exynos5_usbdrd_phy
*phy_drd
= to_usbdrd_phy(inst
);
717 if (inst
->phy_cfg
->id
== EXYNOS5_DRDPHY_UTMI
)
718 return exynos5420_usbdrd_phy_calibrate(phy_drd
);
722 static const struct phy_ops exynos5_usbdrd_phy_ops
= {
723 .init
= exynos5_usbdrd_phy_init
,
724 .exit
= exynos5_usbdrd_phy_exit
,
725 .power_on
= exynos5_usbdrd_phy_power_on
,
726 .power_off
= exynos5_usbdrd_phy_power_off
,
727 .calibrate
= exynos5_usbdrd_phy_calibrate
,
728 .owner
= THIS_MODULE
,
731 static int exynos5_usbdrd_phy_clk_handle(struct exynos5_usbdrd_phy
*phy_drd
)
733 unsigned long ref_rate
;
736 phy_drd
->clk
= devm_clk_get(phy_drd
->dev
, "phy");
737 if (IS_ERR(phy_drd
->clk
)) {
738 dev_err(phy_drd
->dev
, "Failed to get phy clock\n");
739 return PTR_ERR(phy_drd
->clk
);
742 phy_drd
->ref_clk
= devm_clk_get(phy_drd
->dev
, "ref");
743 if (IS_ERR(phy_drd
->ref_clk
)) {
744 dev_err(phy_drd
->dev
, "Failed to get phy reference clock\n");
745 return PTR_ERR(phy_drd
->ref_clk
);
747 ref_rate
= clk_get_rate(phy_drd
->ref_clk
);
749 ret
= exynos5_rate_to_clk(ref_rate
, &phy_drd
->extrefclk
);
751 dev_err(phy_drd
->dev
, "Clock rate (%ld) not supported\n",
756 if (!phy_drd
->drv_data
->has_common_clk_gate
) {
757 phy_drd
->pipeclk
= devm_clk_get(phy_drd
->dev
, "phy_pipe");
758 if (IS_ERR(phy_drd
->pipeclk
)) {
759 dev_info(phy_drd
->dev
,
760 "PIPE3 phy operational clock not specified\n");
761 phy_drd
->pipeclk
= NULL
;
764 phy_drd
->utmiclk
= devm_clk_get(phy_drd
->dev
, "phy_utmi");
765 if (IS_ERR(phy_drd
->utmiclk
)) {
766 dev_info(phy_drd
->dev
,
767 "UTMI phy operational clock not specified\n");
768 phy_drd
->utmiclk
= NULL
;
771 phy_drd
->itpclk
= devm_clk_get(phy_drd
->dev
, "itp");
772 if (IS_ERR(phy_drd
->itpclk
)) {
773 dev_info(phy_drd
->dev
,
774 "ITP clock from main OSC not specified\n");
775 phy_drd
->itpclk
= NULL
;
782 static const struct exynos5_usbdrd_phy_config phy_cfg_exynos5
[] = {
784 .id
= EXYNOS5_DRDPHY_UTMI
,
785 .phy_isol
= exynos5_usbdrd_phy_isol
,
786 .phy_init
= exynos5_usbdrd_utmi_init
,
787 .set_refclk
= exynos5_usbdrd_utmi_set_refclk
,
790 .id
= EXYNOS5_DRDPHY_PIPE3
,
791 .phy_isol
= exynos5_usbdrd_phy_isol
,
792 .phy_init
= exynos5_usbdrd_pipe3_init
,
793 .set_refclk
= exynos5_usbdrd_pipe3_set_refclk
,
797 static const struct exynos5_usbdrd_phy_drvdata exynos5420_usbdrd_phy
= {
798 .phy_cfg
= phy_cfg_exynos5
,
799 .pmu_offset_usbdrd0_phy
= EXYNOS5_USBDRD_PHY_CONTROL
,
800 .pmu_offset_usbdrd1_phy
= EXYNOS5420_USBDRD1_PHY_CONTROL
,
801 .has_common_clk_gate
= true,
804 static const struct exynos5_usbdrd_phy_drvdata exynos5250_usbdrd_phy
= {
805 .phy_cfg
= phy_cfg_exynos5
,
806 .pmu_offset_usbdrd0_phy
= EXYNOS5_USBDRD_PHY_CONTROL
,
807 .has_common_clk_gate
= true,
810 static const struct exynos5_usbdrd_phy_drvdata exynos5433_usbdrd_phy
= {
811 .phy_cfg
= phy_cfg_exynos5
,
812 .pmu_offset_usbdrd0_phy
= EXYNOS5_USBDRD_PHY_CONTROL
,
813 .pmu_offset_usbdrd1_phy
= EXYNOS5433_USBHOST30_PHY_CONTROL
,
814 .has_common_clk_gate
= false,
817 static const struct exynos5_usbdrd_phy_drvdata exynos7_usbdrd_phy
= {
818 .phy_cfg
= phy_cfg_exynos5
,
819 .pmu_offset_usbdrd0_phy
= EXYNOS5_USBDRD_PHY_CONTROL
,
820 .has_common_clk_gate
= false,
823 static const struct of_device_id exynos5_usbdrd_phy_of_match
[] = {
825 .compatible
= "samsung,exynos5250-usbdrd-phy",
826 .data
= &exynos5250_usbdrd_phy
828 .compatible
= "samsung,exynos5420-usbdrd-phy",
829 .data
= &exynos5420_usbdrd_phy
831 .compatible
= "samsung,exynos5433-usbdrd-phy",
832 .data
= &exynos5433_usbdrd_phy
834 .compatible
= "samsung,exynos7-usbdrd-phy",
835 .data
= &exynos7_usbdrd_phy
839 MODULE_DEVICE_TABLE(of
, exynos5_usbdrd_phy_of_match
);
841 static int exynos5_usbdrd_phy_probe(struct platform_device
*pdev
)
843 struct device
*dev
= &pdev
->dev
;
844 struct device_node
*node
= dev
->of_node
;
845 struct exynos5_usbdrd_phy
*phy_drd
;
846 struct phy_provider
*phy_provider
;
847 struct resource
*res
;
848 const struct exynos5_usbdrd_phy_drvdata
*drv_data
;
849 struct regmap
*reg_pmu
;
854 phy_drd
= devm_kzalloc(dev
, sizeof(*phy_drd
), GFP_KERNEL
);
858 dev_set_drvdata(dev
, phy_drd
);
861 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
862 phy_drd
->reg_phy
= devm_ioremap_resource(dev
, res
);
863 if (IS_ERR(phy_drd
->reg_phy
))
864 return PTR_ERR(phy_drd
->reg_phy
);
866 drv_data
= of_device_get_match_data(dev
);
870 phy_drd
->drv_data
= drv_data
;
872 ret
= exynos5_usbdrd_phy_clk_handle(phy_drd
);
874 dev_err(dev
, "Failed to initialize clocks\n");
878 reg_pmu
= syscon_regmap_lookup_by_phandle(dev
->of_node
,
879 "samsung,pmu-syscon");
880 if (IS_ERR(reg_pmu
)) {
881 dev_err(dev
, "Failed to lookup PMU regmap\n");
882 return PTR_ERR(reg_pmu
);
886 * Exynos5420 SoC has multiple channels for USB 3.0 PHY, with
887 * each having separate power control registers.
888 * 'channel' facilitates to set such registers.
890 channel
= of_alias_get_id(node
, "usbdrdphy");
892 dev_dbg(dev
, "Not a multi-controller usbdrd phy\n");
896 pmu_offset
= phy_drd
->drv_data
->pmu_offset_usbdrd1_phy
;
900 pmu_offset
= phy_drd
->drv_data
->pmu_offset_usbdrd0_phy
;
904 /* Get Vbus regulators */
905 phy_drd
->vbus
= devm_regulator_get(dev
, "vbus");
906 if (IS_ERR(phy_drd
->vbus
)) {
907 ret
= PTR_ERR(phy_drd
->vbus
);
908 if (ret
== -EPROBE_DEFER
)
911 dev_warn(dev
, "Failed to get VBUS supply regulator\n");
912 phy_drd
->vbus
= NULL
;
915 phy_drd
->vbus_boost
= devm_regulator_get(dev
, "vbus-boost");
916 if (IS_ERR(phy_drd
->vbus_boost
)) {
917 ret
= PTR_ERR(phy_drd
->vbus_boost
);
918 if (ret
== -EPROBE_DEFER
)
921 dev_warn(dev
, "Failed to get VBUS boost supply regulator\n");
922 phy_drd
->vbus_boost
= NULL
;
925 dev_vdbg(dev
, "Creating usbdrd_phy phy\n");
927 for (i
= 0; i
< EXYNOS5_DRDPHYS_NUM
; i
++) {
928 struct phy
*phy
= devm_phy_create(dev
, NULL
,
929 &exynos5_usbdrd_phy_ops
);
931 dev_err(dev
, "Failed to create usbdrd_phy phy\n");
935 phy_drd
->phys
[i
].phy
= phy
;
936 phy_drd
->phys
[i
].index
= i
;
937 phy_drd
->phys
[i
].reg_pmu
= reg_pmu
;
938 phy_drd
->phys
[i
].pmu_offset
= pmu_offset
;
939 phy_drd
->phys
[i
].phy_cfg
= &drv_data
->phy_cfg
[i
];
940 phy_set_drvdata(phy
, &phy_drd
->phys
[i
]);
943 phy_provider
= devm_of_phy_provider_register(dev
,
944 exynos5_usbdrd_phy_xlate
);
945 if (IS_ERR(phy_provider
)) {
946 dev_err(phy_drd
->dev
, "Failed to register phy provider\n");
947 return PTR_ERR(phy_provider
);
953 static struct platform_driver exynos5_usb3drd_phy
= {
954 .probe
= exynos5_usbdrd_phy_probe
,
956 .of_match_table
= exynos5_usbdrd_phy_of_match
,
957 .name
= "exynos5_usb3drd_phy",
958 .suppress_bind_attrs
= true,
962 module_platform_driver(exynos5_usb3drd_phy
);
963 MODULE_DESCRIPTION("Samsung EXYNOS5 SoCs USB 3.0 DRD controller PHY driver");
964 MODULE_AUTHOR("Vivek Gautam <gautam.vivek@samsung.com>");
965 MODULE_LICENSE("GPL v2");
966 MODULE_ALIAS("platform:exynos5_usb3drd_phy");