1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * phy-ti-pipe3 - PIPE3 PHY driver.
5 * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com
6 * Author: Kishon Vijay Abraham I <kishon@ti.com>
9 #include <linux/module.h>
10 #include <linux/platform_device.h>
11 #include <linux/property.h>
12 #include <linux/slab.h>
13 #include <linux/phy/phy.h>
15 #include <linux/clk.h>
16 #include <linux/err.h>
18 #include <linux/pm_runtime.h>
19 #include <linux/delay.h>
20 #include <linux/phy/omap_control_phy.h>
21 #include <linux/of_platform.h>
22 #include <linux/mfd/syscon.h>
23 #include <linux/regmap.h>
25 #define PLL_STATUS 0x00000004
26 #define PLL_GO 0x00000008
27 #define PLL_CONFIGURATION1 0x0000000C
28 #define PLL_CONFIGURATION2 0x00000010
29 #define PLL_CONFIGURATION3 0x00000014
30 #define PLL_CONFIGURATION4 0x00000020
32 #define PLL_REGM_MASK 0x001FFE00
33 #define PLL_REGM_SHIFT 0x9
34 #define PLL_REGM_F_MASK 0x0003FFFF
35 #define PLL_REGM_F_SHIFT 0x0
36 #define PLL_REGN_MASK 0x000001FE
37 #define PLL_REGN_SHIFT 0x1
38 #define PLL_SELFREQDCO_MASK 0x0000000E
39 #define PLL_SELFREQDCO_SHIFT 0x1
40 #define PLL_SD_MASK 0x0003FC00
41 #define PLL_SD_SHIFT 10
42 #define SET_PLL_GO 0x1
43 #define PLL_LDOPWDN BIT(15)
44 #define PLL_TICOPWDN BIT(16)
48 #define SATA_PLL_SOFT_RESET BIT(18)
50 #define PIPE3_PHY_PWRCTL_CLK_CMD_MASK GENMASK(21, 14)
51 #define PIPE3_PHY_PWRCTL_CLK_CMD_SHIFT 14
53 #define PIPE3_PHY_PWRCTL_CLK_FREQ_MASK GENMASK(31, 22)
54 #define PIPE3_PHY_PWRCTL_CLK_FREQ_SHIFT 22
56 #define PIPE3_PHY_RX_POWERON (0x1 << PIPE3_PHY_PWRCTL_CLK_CMD_SHIFT)
57 #define PIPE3_PHY_TX_POWERON (0x2 << PIPE3_PHY_PWRCTL_CLK_CMD_SHIFT)
59 #define PCIE_PCS_MASK 0xFF0000
60 #define PCIE_PCS_DELAY_COUNT_SHIFT 0x10
62 #define PIPE3_PHY_RX_ANA_PROGRAMMABILITY 0x0000000C
63 #define INTERFACE_MASK GENMASK(31, 27)
64 #define INTERFACE_SHIFT 27
65 #define INTERFACE_MODE_USBSS BIT(4)
66 #define INTERFACE_MODE_SATA_1P5 BIT(3)
67 #define INTERFACE_MODE_SATA_3P0 BIT(2)
68 #define INTERFACE_MODE_PCIE BIT(0)
70 #define LOSD_MASK GENMASK(17, 14)
72 #define MEM_PLLDIV GENMASK(6, 5)
74 #define PIPE3_PHY_RX_TRIM 0x0000001C
75 #define MEM_DLL_TRIM_SEL_MASK GENMASK(31, 30)
76 #define MEM_DLL_TRIM_SHIFT 30
78 #define PIPE3_PHY_RX_DLL 0x00000024
79 #define MEM_DLL_PHINT_RATE_MASK GENMASK(31, 30)
80 #define MEM_DLL_PHINT_RATE_SHIFT 30
82 #define PIPE3_PHY_RX_DIGITAL_MODES 0x00000028
83 #define MEM_HS_RATE_MASK GENMASK(28, 27)
84 #define MEM_HS_RATE_SHIFT 27
85 #define MEM_OVRD_HS_RATE BIT(26)
86 #define MEM_OVRD_HS_RATE_SHIFT 26
87 #define MEM_CDR_FASTLOCK BIT(23)
88 #define MEM_CDR_FASTLOCK_SHIFT 23
89 #define MEM_CDR_LBW_MASK GENMASK(22, 21)
90 #define MEM_CDR_LBW_SHIFT 21
91 #define MEM_CDR_STEPCNT_MASK GENMASK(20, 19)
92 #define MEM_CDR_STEPCNT_SHIFT 19
93 #define MEM_CDR_STL_MASK GENMASK(18, 16)
94 #define MEM_CDR_STL_SHIFT 16
95 #define MEM_CDR_THR_MASK GENMASK(15, 13)
96 #define MEM_CDR_THR_SHIFT 13
97 #define MEM_CDR_THR_MODE BIT(12)
98 #define MEM_CDR_THR_MODE_SHIFT 12
99 #define MEM_CDR_2NDO_SDM_MODE BIT(11)
100 #define MEM_CDR_2NDO_SDM_MODE_SHIFT 11
102 #define PIPE3_PHY_RX_EQUALIZER 0x00000038
103 #define MEM_EQLEV_MASK GENMASK(31, 16)
104 #define MEM_EQLEV_SHIFT 16
105 #define MEM_EQFTC_MASK GENMASK(15, 11)
106 #define MEM_EQFTC_SHIFT 11
107 #define MEM_EQCTL_MASK GENMASK(10, 7)
108 #define MEM_EQCTL_SHIFT 7
109 #define MEM_OVRD_EQLEV BIT(2)
110 #define MEM_OVRD_EQLEV_SHIFT 2
111 #define MEM_OVRD_EQFTC BIT(1)
112 #define MEM_OVRD_EQFTC_SHIFT 1
114 #define SATA_PHY_RX_IO_AND_A2D_OVERRIDES 0x44
115 #define MEM_CDR_LOS_SOURCE_MASK GENMASK(10, 9)
116 #define MEM_CDR_LOS_SOURCE_SHIFT 9
119 * This is an Empirical value that works, need to confirm the actual
120 * value required for the PIPE3PHY_PLL_CONFIGURATION2.PLL_IDLE status
121 * to be correctly reflected in the PIPE3PHY_PLL_STATUS register.
123 #define PLL_IDLE_TIME 100 /* in milliseconds */
124 #define PLL_LOCK_TIME 100 /* in milliseconds */
126 enum pipe3_mode
{ PIPE3_MODE_PCIE
= 1,
130 struct pipe3_dpll_params
{
138 struct pipe3_dpll_map
{
140 struct pipe3_dpll_params params
;
143 struct pipe3_settings
{
152 u8 dig_2ndo_sdm_mode
;
165 void __iomem
*pll_ctrl_base
;
166 void __iomem
*phy_rx
;
167 void __iomem
*phy_tx
;
169 struct device
*control_dev
;
174 struct pipe3_dpll_map
*dpll_map
;
175 struct regmap
*phy_power_syscon
; /* ctrl. reg. acces */
176 struct regmap
*pcs_syscon
; /* ctrl. reg. acces */
177 struct regmap
*dpll_reset_syscon
; /* ctrl. reg. acces */
178 unsigned int dpll_reset_reg
; /* reg. index within syscon */
179 unsigned int power_reg
; /* power reg. index within syscon */
180 unsigned int pcie_pcs_reg
; /* pcs reg. index in syscon */
181 bool sata_refclk_enabled
;
182 enum pipe3_mode mode
;
183 struct pipe3_settings settings
;
186 static struct pipe3_dpll_map dpll_map_usb
[] = {
187 {12000000, {1250, 5, 4, 20, 0} }, /* 12 MHz */
188 {16800000, {3125, 20, 4, 20, 0} }, /* 16.8 MHz */
189 {19200000, {1172, 8, 4, 20, 65537} }, /* 19.2 MHz */
190 {20000000, {1000, 7, 4, 10, 0} }, /* 20 MHz */
191 {26000000, {1250, 12, 4, 20, 0} }, /* 26 MHz */
192 {38400000, {3125, 47, 4, 20, 92843} }, /* 38.4 MHz */
193 { }, /* Terminator */
196 static struct pipe3_dpll_map dpll_map_sata
[] = {
197 {12000000, {625, 4, 4, 6, 0} }, /* 12 MHz */
198 {16800000, {625, 6, 4, 7, 0} }, /* 16.8 MHz */
199 {19200000, {625, 7, 4, 6, 0} }, /* 19.2 MHz */
200 {20000000, {750, 9, 4, 6, 0} }, /* 20 MHz */
201 {26000000, {750, 12, 4, 6, 0} }, /* 26 MHz */
202 {38400000, {625, 15, 4, 6, 0} }, /* 38.4 MHz */
203 { }, /* Terminator */
207 enum pipe3_mode mode
;
208 struct pipe3_dpll_map
*dpll_map
;
209 struct pipe3_settings settings
;
212 static struct pipe3_data data_usb
= {
213 .mode
= PIPE3_MODE_USBSS
,
214 .dpll_map
= dpll_map_usb
,
216 /* DRA75x TRM Table 26-17 Preferred USB3_PHY_RX SCP Register Settings */
217 .ana_interface
= INTERFACE_MODE_USBSS
,
225 .dig_2ndo_sdm_mode
= 0,
227 .dig_ovrd_hs_rate
= 1,
229 .dll_phint_rate
= 0x3,
238 static struct pipe3_data data_sata
= {
239 .mode
= PIPE3_MODE_SATA
,
240 .dpll_map
= dpll_map_sata
,
242 /* DRA75x TRM Table 26-9 Preferred SATA_PHY_RX SCP Register Settings */
243 .ana_interface
= INTERFACE_MODE_SATA_3P0
,
251 .dig_2ndo_sdm_mode
= 0,
252 .dig_hs_rate
= 0, /* Not in TRM preferred settings */
253 .dig_ovrd_hs_rate
= 0, /* Not in TRM preferred settings */
255 .dll_phint_rate
= 0x2, /* for 1.5 GHz DPLL clock */
264 static struct pipe3_data data_pcie
= {
265 .mode
= PIPE3_MODE_PCIE
,
267 /* DRA75x TRM Table 26-62 Preferred PCIe_PHY_RX SCP Register Settings */
268 .ana_interface
= INTERFACE_MODE_PCIE
,
276 .dig_2ndo_sdm_mode
= 0,
278 .dig_ovrd_hs_rate
= 0,
280 .dll_phint_rate
= 0x3,
289 static inline u32
ti_pipe3_readl(void __iomem
*addr
, unsigned offset
)
291 return __raw_readl(addr
+ offset
);
294 static inline void ti_pipe3_writel(void __iomem
*addr
, unsigned offset
,
297 __raw_writel(data
, addr
+ offset
);
300 static struct pipe3_dpll_params
*ti_pipe3_get_dpll_params(struct ti_pipe3
*phy
)
303 struct pipe3_dpll_map
*dpll_map
= phy
->dpll_map
;
305 rate
= clk_get_rate(phy
->sys_clk
);
307 for (; dpll_map
->rate
; dpll_map
++) {
308 if (rate
== dpll_map
->rate
)
309 return &dpll_map
->params
;
312 dev_err(phy
->dev
, "No DPLL configuration for %lu Hz SYS CLK\n", rate
);
317 static int ti_pipe3_enable_clocks(struct ti_pipe3
*phy
);
318 static void ti_pipe3_disable_clocks(struct ti_pipe3
*phy
);
320 static int ti_pipe3_power_off(struct phy
*x
)
323 struct ti_pipe3
*phy
= phy_get_drvdata(x
);
325 if (!phy
->phy_power_syscon
) {
326 omap_control_phy_power(phy
->control_dev
, 0);
330 ret
= regmap_update_bits(phy
->phy_power_syscon
, phy
->power_reg
,
331 PIPE3_PHY_PWRCTL_CLK_CMD_MASK
, 0);
335 static void ti_pipe3_calibrate(struct ti_pipe3
*phy
);
337 static int ti_pipe3_power_on(struct phy
*x
)
342 struct ti_pipe3
*phy
= phy_get_drvdata(x
);
343 bool rx_pending
= false;
345 if (!phy
->phy_power_syscon
) {
346 omap_control_phy_power(phy
->control_dev
, 1);
350 rate
= clk_get_rate(phy
->sys_clk
);
352 dev_err(phy
->dev
, "Invalid clock rate\n");
355 rate
= rate
/ 1000000;
356 mask
= OMAP_CTRL_PIPE3_PHY_PWRCTL_CLK_FREQ_MASK
;
357 val
= rate
<< OMAP_CTRL_PIPE3_PHY_PWRCTL_CLK_FREQ_SHIFT
;
358 regmap_update_bits(phy
->phy_power_syscon
, phy
->power_reg
,
361 * For PCIe, TX and RX must be powered on simultaneously.
362 * For USB and SATA, TX must be powered on before RX
364 mask
= OMAP_CTRL_PIPE3_PHY_PWRCTL_CLK_CMD_MASK
;
365 if (phy
->mode
== PIPE3_MODE_SATA
|| phy
->mode
== PIPE3_MODE_USBSS
) {
366 val
= PIPE3_PHY_TX_POWERON
;
369 val
= PIPE3_PHY_TX_POWERON
| PIPE3_PHY_RX_POWERON
;
372 regmap_update_bits(phy
->phy_power_syscon
, phy
->power_reg
,
376 val
= PIPE3_PHY_TX_POWERON
| PIPE3_PHY_RX_POWERON
;
377 regmap_update_bits(phy
->phy_power_syscon
, phy
->power_reg
,
381 if (phy
->mode
== PIPE3_MODE_PCIE
)
382 ti_pipe3_calibrate(phy
);
387 static int ti_pipe3_dpll_wait_lock(struct ti_pipe3
*phy
)
390 unsigned long timeout
;
392 timeout
= jiffies
+ msecs_to_jiffies(PLL_LOCK_TIME
);
395 val
= ti_pipe3_readl(phy
->pll_ctrl_base
, PLL_STATUS
);
398 } while (!time_after(jiffies
, timeout
));
400 dev_err(phy
->dev
, "DPLL failed to lock\n");
404 static int ti_pipe3_dpll_program(struct ti_pipe3
*phy
)
407 struct pipe3_dpll_params
*dpll_params
;
409 dpll_params
= ti_pipe3_get_dpll_params(phy
);
413 val
= ti_pipe3_readl(phy
->pll_ctrl_base
, PLL_CONFIGURATION1
);
414 val
&= ~PLL_REGN_MASK
;
415 val
|= dpll_params
->n
<< PLL_REGN_SHIFT
;
416 ti_pipe3_writel(phy
->pll_ctrl_base
, PLL_CONFIGURATION1
, val
);
418 val
= ti_pipe3_readl(phy
->pll_ctrl_base
, PLL_CONFIGURATION2
);
419 val
&= ~PLL_SELFREQDCO_MASK
;
420 val
|= dpll_params
->freq
<< PLL_SELFREQDCO_SHIFT
;
421 ti_pipe3_writel(phy
->pll_ctrl_base
, PLL_CONFIGURATION2
, val
);
423 val
= ti_pipe3_readl(phy
->pll_ctrl_base
, PLL_CONFIGURATION1
);
424 val
&= ~PLL_REGM_MASK
;
425 val
|= dpll_params
->m
<< PLL_REGM_SHIFT
;
426 ti_pipe3_writel(phy
->pll_ctrl_base
, PLL_CONFIGURATION1
, val
);
428 val
= ti_pipe3_readl(phy
->pll_ctrl_base
, PLL_CONFIGURATION4
);
429 val
&= ~PLL_REGM_F_MASK
;
430 val
|= dpll_params
->mf
<< PLL_REGM_F_SHIFT
;
431 ti_pipe3_writel(phy
->pll_ctrl_base
, PLL_CONFIGURATION4
, val
);
433 val
= ti_pipe3_readl(phy
->pll_ctrl_base
, PLL_CONFIGURATION3
);
435 val
|= dpll_params
->sd
<< PLL_SD_SHIFT
;
436 ti_pipe3_writel(phy
->pll_ctrl_base
, PLL_CONFIGURATION3
, val
);
438 ti_pipe3_writel(phy
->pll_ctrl_base
, PLL_GO
, SET_PLL_GO
);
440 return ti_pipe3_dpll_wait_lock(phy
);
443 static void ti_pipe3_calibrate(struct ti_pipe3
*phy
)
446 struct pipe3_settings
*s
= &phy
->settings
;
448 val
= ti_pipe3_readl(phy
->phy_rx
, PIPE3_PHY_RX_ANA_PROGRAMMABILITY
);
449 val
&= ~(INTERFACE_MASK
| LOSD_MASK
| MEM_PLLDIV
);
450 val
|= (s
->ana_interface
<< INTERFACE_SHIFT
| s
->ana_losd
<< LOSD_SHIFT
);
451 ti_pipe3_writel(phy
->phy_rx
, PIPE3_PHY_RX_ANA_PROGRAMMABILITY
, val
);
453 val
= ti_pipe3_readl(phy
->phy_rx
, PIPE3_PHY_RX_DIGITAL_MODES
);
454 val
&= ~(MEM_HS_RATE_MASK
| MEM_OVRD_HS_RATE
| MEM_CDR_FASTLOCK
|
455 MEM_CDR_LBW_MASK
| MEM_CDR_STEPCNT_MASK
| MEM_CDR_STL_MASK
|
456 MEM_CDR_THR_MASK
| MEM_CDR_THR_MODE
| MEM_CDR_2NDO_SDM_MODE
);
457 val
|= s
->dig_hs_rate
<< MEM_HS_RATE_SHIFT
|
458 s
->dig_ovrd_hs_rate
<< MEM_OVRD_HS_RATE_SHIFT
|
459 s
->dig_fastlock
<< MEM_CDR_FASTLOCK_SHIFT
|
460 s
->dig_lbw
<< MEM_CDR_LBW_SHIFT
|
461 s
->dig_stepcnt
<< MEM_CDR_STEPCNT_SHIFT
|
462 s
->dig_stl
<< MEM_CDR_STL_SHIFT
|
463 s
->dig_thr
<< MEM_CDR_THR_SHIFT
|
464 s
->dig_thr_mode
<< MEM_CDR_THR_MODE_SHIFT
|
465 s
->dig_2ndo_sdm_mode
<< MEM_CDR_2NDO_SDM_MODE_SHIFT
;
466 ti_pipe3_writel(phy
->phy_rx
, PIPE3_PHY_RX_DIGITAL_MODES
, val
);
468 val
= ti_pipe3_readl(phy
->phy_rx
, PIPE3_PHY_RX_TRIM
);
469 val
&= ~MEM_DLL_TRIM_SEL_MASK
;
470 val
|= s
->dll_trim_sel
<< MEM_DLL_TRIM_SHIFT
;
471 ti_pipe3_writel(phy
->phy_rx
, PIPE3_PHY_RX_TRIM
, val
);
473 val
= ti_pipe3_readl(phy
->phy_rx
, PIPE3_PHY_RX_DLL
);
474 val
&= ~MEM_DLL_PHINT_RATE_MASK
;
475 val
|= s
->dll_phint_rate
<< MEM_DLL_PHINT_RATE_SHIFT
;
476 ti_pipe3_writel(phy
->phy_rx
, PIPE3_PHY_RX_DLL
, val
);
478 val
= ti_pipe3_readl(phy
->phy_rx
, PIPE3_PHY_RX_EQUALIZER
);
479 val
&= ~(MEM_EQLEV_MASK
| MEM_EQFTC_MASK
| MEM_EQCTL_MASK
|
480 MEM_OVRD_EQLEV
| MEM_OVRD_EQFTC
);
481 val
|= s
->eq_lev
<< MEM_EQLEV_SHIFT
|
482 s
->eq_ftc
<< MEM_EQFTC_SHIFT
|
483 s
->eq_ctl
<< MEM_EQCTL_SHIFT
|
484 s
->eq_ovrd_lev
<< MEM_OVRD_EQLEV_SHIFT
|
485 s
->eq_ovrd_ftc
<< MEM_OVRD_EQFTC_SHIFT
;
486 ti_pipe3_writel(phy
->phy_rx
, PIPE3_PHY_RX_EQUALIZER
, val
);
488 if (phy
->mode
== PIPE3_MODE_SATA
) {
489 val
= ti_pipe3_readl(phy
->phy_rx
,
490 SATA_PHY_RX_IO_AND_A2D_OVERRIDES
);
491 val
&= ~MEM_CDR_LOS_SOURCE_MASK
;
492 ti_pipe3_writel(phy
->phy_rx
, SATA_PHY_RX_IO_AND_A2D_OVERRIDES
,
497 static int ti_pipe3_init(struct phy
*x
)
499 struct ti_pipe3
*phy
= phy_get_drvdata(x
);
503 ti_pipe3_enable_clocks(phy
);
505 * Set pcie_pcs register to 0x96 for proper functioning of phy
506 * as recommended in AM572x TRM SPRUHZ6, section 18.5.2.2, table
509 if (phy
->mode
== PIPE3_MODE_PCIE
) {
510 if (!phy
->pcs_syscon
) {
511 omap_control_pcie_pcs(phy
->control_dev
, 0x96);
515 val
= 0x96 << OMAP_CTRL_PCIE_PCS_DELAY_COUNT_SHIFT
;
516 ret
= regmap_update_bits(phy
->pcs_syscon
, phy
->pcie_pcs_reg
,
521 /* Bring it out of IDLE if it is IDLE */
522 val
= ti_pipe3_readl(phy
->pll_ctrl_base
, PLL_CONFIGURATION2
);
523 if (val
& PLL_IDLE
) {
525 ti_pipe3_writel(phy
->pll_ctrl_base
, PLL_CONFIGURATION2
, val
);
526 ret
= ti_pipe3_dpll_wait_lock(phy
);
529 /* SATA has issues if re-programmed when locked */
530 val
= ti_pipe3_readl(phy
->pll_ctrl_base
, PLL_STATUS
);
531 if ((val
& PLL_LOCK
) && phy
->mode
== PIPE3_MODE_SATA
)
534 /* Program the DPLL */
535 ret
= ti_pipe3_dpll_program(phy
);
537 ti_pipe3_disable_clocks(phy
);
541 ti_pipe3_calibrate(phy
);
546 static int ti_pipe3_exit(struct phy
*x
)
548 struct ti_pipe3
*phy
= phy_get_drvdata(x
);
550 unsigned long timeout
;
552 /* If dpll_reset_syscon is not present we wont power down SATA DPLL
555 if (phy
->mode
== PIPE3_MODE_SATA
&& !phy
->dpll_reset_syscon
)
558 /* PCIe doesn't have internal DPLL */
559 if (phy
->mode
!= PIPE3_MODE_PCIE
) {
560 /* Put DPLL in IDLE mode */
561 val
= ti_pipe3_readl(phy
->pll_ctrl_base
, PLL_CONFIGURATION2
);
563 ti_pipe3_writel(phy
->pll_ctrl_base
, PLL_CONFIGURATION2
, val
);
565 /* wait for LDO and Oscillator to power down */
566 timeout
= jiffies
+ msecs_to_jiffies(PLL_IDLE_TIME
);
569 val
= ti_pipe3_readl(phy
->pll_ctrl_base
, PLL_STATUS
);
570 if ((val
& PLL_TICOPWDN
) && (val
& PLL_LDOPWDN
))
572 } while (!time_after(jiffies
, timeout
));
574 if (!(val
& PLL_TICOPWDN
) || !(val
& PLL_LDOPWDN
)) {
575 dev_err(phy
->dev
, "Failed to power down: PLL_STATUS 0x%x\n",
581 /* i783: SATA needs control bit toggle after PLL unlock */
582 if (phy
->mode
== PIPE3_MODE_SATA
) {
583 regmap_update_bits(phy
->dpll_reset_syscon
, phy
->dpll_reset_reg
,
584 SATA_PLL_SOFT_RESET
, SATA_PLL_SOFT_RESET
);
585 regmap_update_bits(phy
->dpll_reset_syscon
, phy
->dpll_reset_reg
,
586 SATA_PLL_SOFT_RESET
, 0);
589 ti_pipe3_disable_clocks(phy
);
593 static const struct phy_ops ops
= {
594 .init
= ti_pipe3_init
,
595 .exit
= ti_pipe3_exit
,
596 .power_on
= ti_pipe3_power_on
,
597 .power_off
= ti_pipe3_power_off
,
598 .owner
= THIS_MODULE
,
601 static const struct of_device_id ti_pipe3_id_table
[];
603 static int ti_pipe3_get_clk(struct ti_pipe3
*phy
)
606 struct device
*dev
= phy
->dev
;
608 phy
->refclk
= devm_clk_get(dev
, "refclk");
609 if (IS_ERR(phy
->refclk
)) {
610 dev_err(dev
, "unable to get refclk\n");
611 /* older DTBs have missing refclk in SATA PHY
612 * so don't bail out in case of SATA PHY.
614 if (phy
->mode
!= PIPE3_MODE_SATA
)
615 return PTR_ERR(phy
->refclk
);
618 if (phy
->mode
!= PIPE3_MODE_SATA
) {
619 phy
->wkupclk
= devm_clk_get(dev
, "wkupclk");
620 if (IS_ERR(phy
->wkupclk
)) {
621 dev_err(dev
, "unable to get wkupclk\n");
622 return PTR_ERR(phy
->wkupclk
);
625 phy
->wkupclk
= ERR_PTR(-ENODEV
);
628 if (phy
->mode
!= PIPE3_MODE_PCIE
|| phy
->phy_power_syscon
) {
629 phy
->sys_clk
= devm_clk_get(dev
, "sysclk");
630 if (IS_ERR(phy
->sys_clk
)) {
631 dev_err(dev
, "unable to get sysclk\n");
636 if (phy
->mode
== PIPE3_MODE_PCIE
) {
637 clk
= devm_clk_get(dev
, "dpll_ref");
639 dev_err(dev
, "unable to get dpll ref clk\n");
642 clk_set_rate(clk
, 1500000000);
644 clk
= devm_clk_get(dev
, "dpll_ref_m2");
646 dev_err(dev
, "unable to get dpll ref m2 clk\n");
649 clk_set_rate(clk
, 100000000);
651 clk
= devm_clk_get(dev
, "phy-div");
653 dev_err(dev
, "unable to get phy-div clk\n");
656 clk_set_rate(clk
, 100000000);
658 phy
->div_clk
= devm_clk_get(dev
, "div-clk");
659 if (IS_ERR(phy
->div_clk
)) {
660 dev_err(dev
, "unable to get div-clk\n");
661 return PTR_ERR(phy
->div_clk
);
664 phy
->div_clk
= ERR_PTR(-ENODEV
);
670 static int ti_pipe3_get_sysctrl(struct ti_pipe3
*phy
)
672 struct device
*dev
= phy
->dev
;
673 struct device_node
*node
= dev
->of_node
;
674 struct device_node
*control_node
;
675 struct platform_device
*control_pdev
;
677 phy
->phy_power_syscon
= syscon_regmap_lookup_by_phandle(node
,
679 if (IS_ERR(phy
->phy_power_syscon
)) {
681 "can't get syscon-phy-power, using control device\n");
682 phy
->phy_power_syscon
= NULL
;
684 if (of_property_read_u32_index(node
,
685 "syscon-phy-power", 1,
687 dev_err(dev
, "couldn't get power reg. offset\n");
692 if (!phy
->phy_power_syscon
) {
693 control_node
= of_parse_phandle(node
, "ctrl-module", 0);
695 dev_err(dev
, "Failed to get control device phandle\n");
699 control_pdev
= of_find_device_by_node(control_node
);
700 of_node_put(control_node
);
702 dev_err(dev
, "Failed to get control device\n");
706 phy
->control_dev
= &control_pdev
->dev
;
709 if (phy
->mode
== PIPE3_MODE_PCIE
) {
710 phy
->pcs_syscon
= syscon_regmap_lookup_by_phandle(node
,
712 if (IS_ERR(phy
->pcs_syscon
)) {
714 "can't get syscon-pcs, using omap control\n");
715 phy
->pcs_syscon
= NULL
;
717 if (of_property_read_u32_index(node
,
719 &phy
->pcie_pcs_reg
)) {
721 "couldn't get pcie pcs reg. offset\n");
727 if (phy
->mode
== PIPE3_MODE_SATA
) {
728 phy
->dpll_reset_syscon
= syscon_regmap_lookup_by_phandle(node
,
730 if (IS_ERR(phy
->dpll_reset_syscon
)) {
732 "can't get syscon-pllreset, sata dpll won't idle\n");
733 phy
->dpll_reset_syscon
= NULL
;
735 if (of_property_read_u32_index(node
,
736 "syscon-pllreset", 1,
737 &phy
->dpll_reset_reg
)) {
739 "couldn't get pllreset reg. offset\n");
748 static int ti_pipe3_get_tx_rx_base(struct ti_pipe3
*phy
)
750 struct device
*dev
= phy
->dev
;
751 struct platform_device
*pdev
= to_platform_device(dev
);
753 phy
->phy_rx
= devm_platform_ioremap_resource_byname(pdev
, "phy_rx");
754 if (IS_ERR(phy
->phy_rx
))
755 return PTR_ERR(phy
->phy_rx
);
757 phy
->phy_tx
= devm_platform_ioremap_resource_byname(pdev
, "phy_tx");
759 return PTR_ERR_OR_ZERO(phy
->phy_tx
);
762 static int ti_pipe3_get_pll_base(struct ti_pipe3
*phy
)
764 struct device
*dev
= phy
->dev
;
765 struct platform_device
*pdev
= to_platform_device(dev
);
767 if (phy
->mode
== PIPE3_MODE_PCIE
)
771 devm_platform_ioremap_resource_byname(pdev
, "pll_ctrl");
772 return PTR_ERR_OR_ZERO(phy
->pll_ctrl_base
);
775 static int ti_pipe3_probe(struct platform_device
*pdev
)
777 struct ti_pipe3
*phy
;
778 struct phy
*generic_phy
;
779 struct phy_provider
*phy_provider
;
780 struct device
*dev
= &pdev
->dev
;
782 const struct pipe3_data
*data
;
784 phy
= devm_kzalloc(dev
, sizeof(*phy
), GFP_KERNEL
);
788 data
= device_get_match_data(dev
);
793 phy
->mode
= data
->mode
;
794 phy
->dpll_map
= data
->dpll_map
;
795 phy
->settings
= data
->settings
;
797 ret
= ti_pipe3_get_pll_base(phy
);
801 ret
= ti_pipe3_get_tx_rx_base(phy
);
805 ret
= ti_pipe3_get_sysctrl(phy
);
809 ret
= ti_pipe3_get_clk(phy
);
813 platform_set_drvdata(pdev
, phy
);
814 pm_runtime_enable(dev
);
817 * Prevent auto-disable of refclk for SATA PHY due to Errata i783
819 if (phy
->mode
== PIPE3_MODE_SATA
) {
820 if (!IS_ERR(phy
->refclk
)) {
821 clk_prepare_enable(phy
->refclk
);
822 phy
->sata_refclk_enabled
= true;
826 generic_phy
= devm_phy_create(dev
, NULL
, &ops
);
827 if (IS_ERR(generic_phy
))
828 return PTR_ERR(generic_phy
);
830 phy_set_drvdata(generic_phy
, phy
);
832 ti_pipe3_power_off(generic_phy
);
834 phy_provider
= devm_of_phy_provider_register(dev
, of_phy_simple_xlate
);
835 return PTR_ERR_OR_ZERO(phy_provider
);
838 static void ti_pipe3_remove(struct platform_device
*pdev
)
840 struct ti_pipe3
*phy
= platform_get_drvdata(pdev
);
842 if (phy
->mode
== PIPE3_MODE_SATA
) {
843 clk_disable_unprepare(phy
->refclk
);
844 phy
->sata_refclk_enabled
= false;
846 pm_runtime_disable(&pdev
->dev
);
849 static int ti_pipe3_enable_clocks(struct ti_pipe3
*phy
)
853 if (!IS_ERR(phy
->refclk
)) {
854 ret
= clk_prepare_enable(phy
->refclk
);
856 dev_err(phy
->dev
, "Failed to enable refclk %d\n", ret
);
861 if (!IS_ERR(phy
->wkupclk
)) {
862 ret
= clk_prepare_enable(phy
->wkupclk
);
864 dev_err(phy
->dev
, "Failed to enable wkupclk %d\n", ret
);
869 if (!IS_ERR(phy
->div_clk
)) {
870 ret
= clk_prepare_enable(phy
->div_clk
);
872 dev_err(phy
->dev
, "Failed to enable div_clk %d\n", ret
);
873 goto disable_wkupclk
;
880 if (!IS_ERR(phy
->wkupclk
))
881 clk_disable_unprepare(phy
->wkupclk
);
884 if (!IS_ERR(phy
->refclk
))
885 clk_disable_unprepare(phy
->refclk
);
890 static void ti_pipe3_disable_clocks(struct ti_pipe3
*phy
)
892 if (!IS_ERR(phy
->wkupclk
))
893 clk_disable_unprepare(phy
->wkupclk
);
894 if (!IS_ERR(phy
->refclk
))
895 clk_disable_unprepare(phy
->refclk
);
896 if (!IS_ERR(phy
->div_clk
))
897 clk_disable_unprepare(phy
->div_clk
);
900 static const struct of_device_id ti_pipe3_id_table
[] = {
902 .compatible
= "ti,phy-usb3",
906 .compatible
= "ti,omap-usb3",
910 .compatible
= "ti,phy-pipe3-sata",
914 .compatible
= "ti,phy-pipe3-pcie",
919 MODULE_DEVICE_TABLE(of
, ti_pipe3_id_table
);
921 static struct platform_driver ti_pipe3_driver
= {
922 .probe
= ti_pipe3_probe
,
923 .remove
= ti_pipe3_remove
,
926 .of_match_table
= ti_pipe3_id_table
,
930 module_platform_driver(ti_pipe3_driver
);
932 MODULE_ALIAS("platform:ti_pipe3");
933 MODULE_AUTHOR("Texas Instruments Inc.");
934 MODULE_DESCRIPTION("TI PIPE3 phy driver");
935 MODULE_LICENSE("GPL v2");