1 // SPDX-License-Identifier: GPL-2.0-only
3 * Cadence Torrent SD0801 PHY driver.
5 * Copyright 2018 Cadence Design Systems, Inc.
9 #include <dt-bindings/phy/phy.h>
10 #include <linux/clk.h>
11 #include <linux/delay.h>
12 #include <linux/err.h>
14 #include <linux/iopoll.h>
15 #include <linux/kernel.h>
16 #include <linux/module.h>
18 #include <linux/of_address.h>
19 #include <linux/of_device.h>
20 #include <linux/phy/phy.h>
21 #include <linux/platform_device.h>
22 #include <linux/reset.h>
23 #include <linux/regmap.h>
25 #define REF_CLK_19_2MHz 19200000
26 #define REF_CLK_25MHz 25000000
28 #define DEFAULT_NUM_LANES 4
29 #define MAX_NUM_LANES 4
30 #define DEFAULT_MAX_BIT_RATE 8100 /* in Mbps */
32 #define POLL_TIMEOUT_US 5000
34 #define TORRENT_COMMON_CDB_OFFSET 0x0
36 #define TORRENT_TX_LANE_CDB_OFFSET(ln, block_offset, reg_offset) \
37 ((0x4000 << (block_offset)) + \
38 (((ln) << 9) << (reg_offset)))
40 #define TORRENT_RX_LANE_CDB_OFFSET(ln, block_offset, reg_offset) \
41 ((0x8000 << (block_offset)) + \
42 (((ln) << 9) << (reg_offset)))
44 #define TORRENT_PHY_PCS_COMMON_OFFSET(block_offset) \
45 (0xC000 << (block_offset))
47 #define TORRENT_PHY_PMA_COMMON_OFFSET(block_offset) \
48 (0xE000 << (block_offset))
50 #define TORRENT_DPTX_PHY_OFFSET 0x0
53 * register offsets from DPTX PHY register block base (i.e MHDP
54 * register base + 0x30a00)
56 #define PHY_AUX_CTRL 0x04
57 #define PHY_RESET 0x20
58 #define PMA_TX_ELEC_IDLE_MASK 0xF0U
59 #define PMA_TX_ELEC_IDLE_SHIFT 4
60 #define PHY_L00_RESET_N_MASK 0x01U
61 #define PHY_PMA_XCVR_PLLCLK_EN 0x24
62 #define PHY_PMA_XCVR_PLLCLK_EN_ACK 0x28
63 #define PHY_PMA_XCVR_POWER_STATE_REQ 0x2c
64 #define PHY_POWER_STATE_LN_0 0x0000
65 #define PHY_POWER_STATE_LN_1 0x0008
66 #define PHY_POWER_STATE_LN_2 0x0010
67 #define PHY_POWER_STATE_LN_3 0x0018
68 #define PMA_XCVR_POWER_STATE_REQ_LN_MASK 0x3FU
69 #define PHY_PMA_XCVR_POWER_STATE_ACK 0x30
70 #define PHY_PMA_CMN_READY 0x34
73 * register offsets from SD0801 PHY register block base (i.e MHDP
74 * register base + 0x500000)
76 #define CMN_SSM_BANDGAP_TMR 0x0021U
77 #define CMN_SSM_BIAS_TMR 0x0022U
78 #define CMN_PLLSM0_PLLPRE_TMR 0x002AU
79 #define CMN_PLLSM0_PLLLOCK_TMR 0x002CU
80 #define CMN_PLLSM1_PLLPRE_TMR 0x0032U
81 #define CMN_PLLSM1_PLLLOCK_TMR 0x0034U
82 #define CMN_BGCAL_INIT_TMR 0x0064U
83 #define CMN_BGCAL_ITER_TMR 0x0065U
84 #define CMN_IBCAL_INIT_TMR 0x0074U
85 #define CMN_PLL0_VCOCAL_TCTRL 0x0082U
86 #define CMN_PLL0_VCOCAL_INIT_TMR 0x0084U
87 #define CMN_PLL0_VCOCAL_ITER_TMR 0x0085U
88 #define CMN_PLL0_VCOCAL_REFTIM_START 0x0086U
89 #define CMN_PLL0_VCOCAL_PLLCNT_START 0x0088U
90 #define CMN_PLL0_INTDIV_M0 0x0090U
91 #define CMN_PLL0_FRACDIVL_M0 0x0091U
92 #define CMN_PLL0_FRACDIVH_M0 0x0092U
93 #define CMN_PLL0_HIGH_THR_M0 0x0093U
94 #define CMN_PLL0_DSM_DIAG_M0 0x0094U
95 #define CMN_PLL0_SS_CTRL1_M0 0x0098U
96 #define CMN_PLL0_SS_CTRL2_M0 0x0099U
97 #define CMN_PLL0_SS_CTRL3_M0 0x009AU
98 #define CMN_PLL0_SS_CTRL4_M0 0x009BU
99 #define CMN_PLL0_LOCK_REFCNT_START 0x009CU
100 #define CMN_PLL0_LOCK_PLLCNT_START 0x009EU
101 #define CMN_PLL0_LOCK_PLLCNT_THR 0x009FU
102 #define CMN_PLL1_VCOCAL_TCTRL 0x00C2U
103 #define CMN_PLL1_VCOCAL_INIT_TMR 0x00C4U
104 #define CMN_PLL1_VCOCAL_ITER_TMR 0x00C5U
105 #define CMN_PLL1_VCOCAL_REFTIM_START 0x00C6U
106 #define CMN_PLL1_VCOCAL_PLLCNT_START 0x00C8U
107 #define CMN_PLL1_INTDIV_M0 0x00D0U
108 #define CMN_PLL1_FRACDIVL_M0 0x00D1U
109 #define CMN_PLL1_FRACDIVH_M0 0x00D2U
110 #define CMN_PLL1_HIGH_THR_M0 0x00D3U
111 #define CMN_PLL1_DSM_DIAG_M0 0x00D4U
112 #define CMN_PLL1_SS_CTRL1_M0 0x00D8U
113 #define CMN_PLL1_SS_CTRL2_M0 0x00D9U
114 #define CMN_PLL1_SS_CTRL3_M0 0x00DAU
115 #define CMN_PLL1_SS_CTRL4_M0 0x00DBU
116 #define CMN_PLL1_LOCK_REFCNT_START 0x00DCU
117 #define CMN_PLL1_LOCK_PLLCNT_START 0x00DEU
118 #define CMN_PLL1_LOCK_PLLCNT_THR 0x00DFU
119 #define CMN_TXPUCAL_INIT_TMR 0x0104U
120 #define CMN_TXPUCAL_ITER_TMR 0x0105U
121 #define CMN_TXPDCAL_INIT_TMR 0x010CU
122 #define CMN_TXPDCAL_ITER_TMR 0x010DU
123 #define CMN_RXCAL_INIT_TMR 0x0114U
124 #define CMN_RXCAL_ITER_TMR 0x0115U
125 #define CMN_SD_CAL_INIT_TMR 0x0124U
126 #define CMN_SD_CAL_ITER_TMR 0x0125U
127 #define CMN_SD_CAL_REFTIM_START 0x0126U
128 #define CMN_SD_CAL_PLLCNT_START 0x0128U
129 #define CMN_PDIAG_PLL0_CTRL_M0 0x01A0U
130 #define CMN_PDIAG_PLL0_CLK_SEL_M0 0x01A1U
131 #define CMN_PDIAG_PLL0_CP_PADJ_M0 0x01A4U
132 #define CMN_PDIAG_PLL0_CP_IADJ_M0 0x01A5U
133 #define CMN_PDIAG_PLL0_FILT_PADJ_M0 0x01A6U
134 #define CMN_PDIAG_PLL0_CP_PADJ_M1 0x01B4U
135 #define CMN_PDIAG_PLL0_CP_IADJ_M1 0x01B5U
136 #define CMN_PDIAG_PLL1_CTRL_M0 0x01C0U
137 #define CMN_PDIAG_PLL1_CLK_SEL_M0 0x01C1U
138 #define CMN_PDIAG_PLL1_CP_PADJ_M0 0x01C4U
139 #define CMN_PDIAG_PLL1_CP_IADJ_M0 0x01C5U
140 #define CMN_PDIAG_PLL1_FILT_PADJ_M0 0x01C6U
142 /* PMA TX Lane registers */
143 #define TX_TXCC_CTRL 0x0040U
144 #define TX_TXCC_CPOST_MULT_00 0x004CU
145 #define TX_TXCC_MGNFS_MULT_000 0x0050U
146 #define DRV_DIAG_TX_DRV 0x00C6U
147 #define XCVR_DIAG_PLLDRC_CTRL 0x00E5U
148 #define XCVR_DIAG_HSCLK_SEL 0x00E6U
149 #define XCVR_DIAG_HSCLK_DIV 0x00E7U
150 #define XCVR_DIAG_BIDI_CTRL 0x00EAU
151 #define TX_PSC_A0 0x0100U
152 #define TX_PSC_A2 0x0102U
153 #define TX_PSC_A3 0x0103U
154 #define TX_RCVDET_ST_TMR 0x0123U
155 #define TX_DIAG_ACYA 0x01E7U
156 #define TX_DIAG_ACYA_HBDC_MASK 0x0001U
158 /* PMA RX Lane registers */
159 #define RX_PSC_A0 0x0000U
160 #define RX_PSC_A2 0x0002U
161 #define RX_PSC_A3 0x0003U
162 #define RX_PSC_CAL 0x0006U
163 #define RX_REE_GCSM1_CTRL 0x0108U
164 #define RX_REE_GCSM2_CTRL 0x0110U
165 #define RX_REE_PERGCSM_CTRL 0x0118U
167 /* PHY PCS common registers */
168 #define PHY_PLL_CFG 0x000EU
170 /* PHY PMA common registers */
171 #define PHY_PMA_CMN_CTRL2 0x0001U
172 #define PHY_PMA_PLL_RAW_CTRL 0x0003U
174 static const struct reg_field phy_pll_cfg
=
175 REG_FIELD(PHY_PLL_CFG
, 0, 1);
177 static const struct reg_field phy_pma_cmn_ctrl_2
=
178 REG_FIELD(PHY_PMA_CMN_CTRL2
, 0, 7);
180 static const struct reg_field phy_pma_pll_raw_ctrl
=
181 REG_FIELD(PHY_PMA_PLL_RAW_CTRL
, 0, 1);
183 static const struct reg_field phy_reset_ctrl
=
184 REG_FIELD(PHY_RESET
, 8, 8);
186 static const struct of_device_id cdns_torrent_phy_of_match
[];
188 struct cdns_torrent_inst
{
193 struct reset_control
*lnk_rst
;
196 struct cdns_torrent_phy
{
197 void __iomem
*base
; /* DPTX registers base */
198 void __iomem
*sd_base
; /* SD0801 registers base */
199 u32 max_bit_rate
; /* Maximum link bit rate to use (in Mbps) */
200 struct reset_control
*phy_rst
;
203 unsigned long ref_clk_rate
;
204 struct cdns_torrent_inst phys
[MAX_NUM_LANES
];
206 struct regmap
*regmap
;
207 struct regmap
*regmap_common_cdb
;
208 struct regmap
*regmap_phy_pcs_common_cdb
;
209 struct regmap
*regmap_phy_pma_common_cdb
;
210 struct regmap
*regmap_tx_lane_cdb
[MAX_NUM_LANES
];
211 struct regmap
*regmap_rx_lane_cdb
[MAX_NUM_LANES
];
212 struct regmap
*regmap_dptx_phy_reg
;
213 struct regmap_field
*phy_pll_cfg
;
214 struct regmap_field
*phy_pma_cmn_ctrl_2
;
215 struct regmap_field
*phy_pma_pll_raw_ctrl
;
216 struct regmap_field
*phy_reset_ctrl
;
219 enum phy_powerstate
{
221 /* Powerstate A1 is unused */
226 static int cdns_torrent_dp_init(struct phy
*phy
);
227 static int cdns_torrent_dp_exit(struct phy
*phy
);
228 static int cdns_torrent_dp_run(struct cdns_torrent_phy
*cdns_phy
,
231 int cdns_torrent_dp_wait_pma_cmn_ready(struct cdns_torrent_phy
*cdns_phy
);
232 static void cdns_torrent_dp_pma_cfg(struct cdns_torrent_phy
*cdns_phy
,
233 struct cdns_torrent_inst
*inst
);
235 void cdns_torrent_dp_pma_cmn_cfg_19_2mhz(struct cdns_torrent_phy
*cdns_phy
);
237 void cdns_torrent_dp_pma_cmn_vco_cfg_19_2mhz(struct cdns_torrent_phy
*cdns_phy
,
240 void cdns_torrent_dp_pma_cmn_cfg_25mhz(struct cdns_torrent_phy
*cdns_phy
);
242 void cdns_torrent_dp_pma_cmn_vco_cfg_25mhz(struct cdns_torrent_phy
*cdns_phy
,
244 static void cdns_torrent_dp_pma_lane_cfg(struct cdns_torrent_phy
*cdns_phy
,
246 static void cdns_torrent_dp_pma_cmn_rate(struct cdns_torrent_phy
*cdns_phy
,
247 u32 rate
, u32 num_lanes
);
248 static int cdns_torrent_dp_configure(struct phy
*phy
,
249 union phy_configure_opts
*opts
);
250 static int cdns_torrent_dp_set_power_state(struct cdns_torrent_phy
*cdns_phy
,
252 enum phy_powerstate powerstate
);
253 static int cdns_torrent_phy_on(struct phy
*phy
);
254 static int cdns_torrent_phy_off(struct phy
*phy
);
256 static const struct phy_ops cdns_torrent_phy_ops
= {
257 .init
= cdns_torrent_dp_init
,
258 .exit
= cdns_torrent_dp_exit
,
259 .configure
= cdns_torrent_dp_configure
,
260 .power_on
= cdns_torrent_phy_on
,
261 .power_off
= cdns_torrent_phy_off
,
262 .owner
= THIS_MODULE
,
265 struct cdns_torrent_data
{
266 u8 block_offset_shift
;
270 struct cdns_regmap_cdb_context
{
276 static int cdns_regmap_write(void *context
, unsigned int reg
, unsigned int val
)
278 struct cdns_regmap_cdb_context
*ctx
= context
;
279 u32 offset
= reg
<< ctx
->reg_offset_shift
;
281 writew(val
, ctx
->base
+ offset
);
286 static int cdns_regmap_read(void *context
, unsigned int reg
, unsigned int *val
)
288 struct cdns_regmap_cdb_context
*ctx
= context
;
289 u32 offset
= reg
<< ctx
->reg_offset_shift
;
291 *val
= readw(ctx
->base
+ offset
);
295 static int cdns_regmap_dptx_write(void *context
, unsigned int reg
,
298 struct cdns_regmap_cdb_context
*ctx
= context
;
301 writel(val
, ctx
->base
+ offset
);
306 static int cdns_regmap_dptx_read(void *context
, unsigned int reg
,
309 struct cdns_regmap_cdb_context
*ctx
= context
;
312 *val
= readl(ctx
->base
+ offset
);
316 #define TORRENT_TX_LANE_CDB_REGMAP_CONF(n) \
318 .name = "torrent_tx_lane" n "_cdb", \
321 .reg_write = cdns_regmap_write, \
322 .reg_read = cdns_regmap_read, \
325 #define TORRENT_RX_LANE_CDB_REGMAP_CONF(n) \
327 .name = "torrent_rx_lane" n "_cdb", \
330 .reg_write = cdns_regmap_write, \
331 .reg_read = cdns_regmap_read, \
334 static struct regmap_config cdns_torrent_tx_lane_cdb_config
[] = {
335 TORRENT_TX_LANE_CDB_REGMAP_CONF("0"),
336 TORRENT_TX_LANE_CDB_REGMAP_CONF("1"),
337 TORRENT_TX_LANE_CDB_REGMAP_CONF("2"),
338 TORRENT_TX_LANE_CDB_REGMAP_CONF("3"),
341 static struct regmap_config cdns_torrent_rx_lane_cdb_config
[] = {
342 TORRENT_RX_LANE_CDB_REGMAP_CONF("0"),
343 TORRENT_RX_LANE_CDB_REGMAP_CONF("1"),
344 TORRENT_RX_LANE_CDB_REGMAP_CONF("2"),
345 TORRENT_RX_LANE_CDB_REGMAP_CONF("3"),
348 static struct regmap_config cdns_torrent_common_cdb_config
= {
349 .name
= "torrent_common_cdb",
352 .reg_write
= cdns_regmap_write
,
353 .reg_read
= cdns_regmap_read
,
356 static struct regmap_config cdns_torrent_phy_pcs_cmn_cdb_config
= {
357 .name
= "torrent_phy_pcs_cmn_cdb",
360 .reg_write
= cdns_regmap_write
,
361 .reg_read
= cdns_regmap_read
,
364 static struct regmap_config cdns_torrent_phy_pma_cmn_cdb_config
= {
365 .name
= "torrent_phy_pma_cmn_cdb",
368 .reg_write
= cdns_regmap_write
,
369 .reg_read
= cdns_regmap_read
,
372 static struct regmap_config cdns_torrent_dptx_phy_config
= {
373 .name
= "torrent_dptx_phy",
376 .reg_write
= cdns_regmap_dptx_write
,
377 .reg_read
= cdns_regmap_dptx_read
,
380 /* PHY mmr access functions */
382 static void cdns_torrent_phy_write(struct regmap
*regmap
, u32 offset
, u32 val
)
384 regmap_write(regmap
, offset
, val
);
387 static u32
cdns_torrent_phy_read(struct regmap
*regmap
, u32 offset
)
391 regmap_read(regmap
, offset
, &val
);
395 /* DPTX mmr access functions */
397 static void cdns_torrent_dp_write(struct regmap
*regmap
, u32 offset
, u32 val
)
399 regmap_write(regmap
, offset
, val
);
402 static u32
cdns_torrent_dp_read(struct regmap
*regmap
, u32 offset
)
406 regmap_read(regmap
, offset
, &val
);
411 * Structure used to store values of PHY registers for voltage-related
412 * coefficients, for particular voltage swing and pre-emphasis level. Values
413 * are shared across all physical lanes.
415 struct coefficients
{
416 /* Value of DRV_DIAG_TX_DRV register to use */
418 /* Value of TX_TXCC_MGNFS_MULT_000 register to use */
420 /* Value of TX_TXCC_CPOST_MULT_00 register to use */
425 * Array consists of values of voltage-related registers for sd0801 PHY. A value
426 * of 0xFFFF is a placeholder for invalid combination, and will never be used.
428 static const struct coefficients vltg_coeff
[4][4] = {
429 /* voltage swing 0, pre-emphasis 0->3 */
430 { {.diag_tx_drv
= 0x0003, .mgnfs_mult
= 0x002A,
431 .cpost_mult
= 0x0000},
432 {.diag_tx_drv
= 0x0003, .mgnfs_mult
= 0x001F,
433 .cpost_mult
= 0x0014},
434 {.diag_tx_drv
= 0x0003, .mgnfs_mult
= 0x0012,
435 .cpost_mult
= 0x0020},
436 {.diag_tx_drv
= 0x0003, .mgnfs_mult
= 0x0000,
437 .cpost_mult
= 0x002A}
440 /* voltage swing 1, pre-emphasis 0->3 */
441 { {.diag_tx_drv
= 0x0003, .mgnfs_mult
= 0x001F,
442 .cpost_mult
= 0x0000},
443 {.diag_tx_drv
= 0x0003, .mgnfs_mult
= 0x0013,
444 .cpost_mult
= 0x0012},
445 {.diag_tx_drv
= 0x0003, .mgnfs_mult
= 0x0000,
446 .cpost_mult
= 0x001F},
447 {.diag_tx_drv
= 0xFFFF, .mgnfs_mult
= 0xFFFF,
448 .cpost_mult
= 0xFFFF}
451 /* voltage swing 2, pre-emphasis 0->3 */
452 { {.diag_tx_drv
= 0x0003, .mgnfs_mult
= 0x0013,
453 .cpost_mult
= 0x0000},
454 {.diag_tx_drv
= 0x0003, .mgnfs_mult
= 0x0000,
455 .cpost_mult
= 0x0013},
456 {.diag_tx_drv
= 0xFFFF, .mgnfs_mult
= 0xFFFF,
457 .cpost_mult
= 0xFFFF},
458 {.diag_tx_drv
= 0xFFFF, .mgnfs_mult
= 0xFFFF,
459 .cpost_mult
= 0xFFFF}
462 /* voltage swing 3, pre-emphasis 0->3 */
463 { {.diag_tx_drv
= 0x0003, .mgnfs_mult
= 0x0000,
464 .cpost_mult
= 0x0000},
465 {.diag_tx_drv
= 0xFFFF, .mgnfs_mult
= 0xFFFF,
466 .cpost_mult
= 0xFFFF},
467 {.diag_tx_drv
= 0xFFFF, .mgnfs_mult
= 0xFFFF,
468 .cpost_mult
= 0xFFFF},
469 {.diag_tx_drv
= 0xFFFF, .mgnfs_mult
= 0xFFFF,
470 .cpost_mult
= 0xFFFF}
475 * Enable or disable PLL for selected lanes.
477 static int cdns_torrent_dp_set_pll_en(struct cdns_torrent_phy
*cdns_phy
,
478 struct phy_configure_opts_dp
*dp
,
483 struct regmap
*regmap
= cdns_phy
->regmap_dptx_phy_reg
;
486 * Used to determine, which bits to check for or enable in
487 * PHY_PMA_XCVR_PLLCLK_EN register.
490 /* Used to enable or disable lanes. */
493 /* Select values of registers and mask, depending on enabled lane
499 pll_bits
= 0x00000001;
503 pll_bits
= 0x00000003;
507 pll_bits
= 0x0000000F;
514 pll_val
= 0x00000000;
516 cdns_torrent_dp_write(regmap
, PHY_PMA_XCVR_PLLCLK_EN
, pll_val
);
518 /* Wait for acknowledgment from PHY. */
519 ret
= regmap_read_poll_timeout(regmap
,
520 PHY_PMA_XCVR_PLLCLK_EN_ACK
,
522 (rd_val
& pll_bits
) == pll_val
,
529 * Perform register operations related to setting link rate, once powerstate is
530 * set and PLL disable request was processed.
532 static int cdns_torrent_dp_configure_rate(struct cdns_torrent_phy
*cdns_phy
,
533 struct phy_configure_opts_dp
*dp
)
538 /* Disable the cmn_pll0_en before re-programming the new data rate. */
539 regmap_field_write(cdns_phy
->phy_pma_pll_raw_ctrl
, 0x0);
542 * Wait for PLL ready de-assertion.
543 * For PLL0 - PHY_PMA_CMN_CTRL2[2] == 1
545 ret
= regmap_field_read_poll_timeout(cdns_phy
->phy_pma_cmn_ctrl_2
,
547 ((read_val
>> 2) & 0x01) != 0,
553 /* DP Rate Change - VCO Output settings. */
554 if (cdns_phy
->ref_clk_rate
== REF_CLK_19_2MHz
) {
555 /* PMA common configuration 19.2MHz */
556 cdns_torrent_dp_pma_cmn_vco_cfg_19_2mhz(cdns_phy
, dp
->link_rate
,
558 cdns_torrent_dp_pma_cmn_cfg_19_2mhz(cdns_phy
);
559 } else if (cdns_phy
->ref_clk_rate
== REF_CLK_25MHz
) {
560 /* PMA common configuration 25MHz */
561 cdns_torrent_dp_pma_cmn_vco_cfg_25mhz(cdns_phy
, dp
->link_rate
,
563 cdns_torrent_dp_pma_cmn_cfg_25mhz(cdns_phy
);
565 cdns_torrent_dp_pma_cmn_rate(cdns_phy
, dp
->link_rate
, dp
->lanes
);
567 /* Enable the cmn_pll0_en. */
568 regmap_field_write(cdns_phy
->phy_pma_pll_raw_ctrl
, 0x3);
571 * Wait for PLL ready assertion.
572 * For PLL0 - PHY_PMA_CMN_CTRL2[0] == 1
574 ret
= regmap_field_read_poll_timeout(cdns_phy
->phy_pma_cmn_ctrl_2
,
576 (read_val
& 0x01) != 0,
582 * Verify, that parameters to configure PHY with are correct.
584 static int cdns_torrent_dp_verify_config(struct cdns_torrent_inst
*inst
,
585 struct phy_configure_opts_dp
*dp
)
589 /* If changing link rate was required, verify it's supported. */
591 switch (dp
->link_rate
) {
607 /* Verify lane count. */
612 /* valid lane count. */
618 /* Check against actual number of PHY's lanes. */
619 if (dp
->lanes
> inst
->num_lanes
)
623 * If changing voltages is required, check swing and pre-emphasis
626 if (dp
->set_voltages
) {
627 /* Lane count verified previously. */
628 for (i
= 0; i
< dp
->lanes
; i
++) {
629 if (dp
->voltage
[i
] > 3 || dp
->pre
[i
] > 3)
632 /* Sum of voltage swing and pre-emphasis levels cannot
635 if (dp
->voltage
[i
] + dp
->pre
[i
] > 3)
643 /* Set power state A0 and PLL clock enable to 0 on enabled lanes. */
644 static void cdns_torrent_dp_set_a0_pll(struct cdns_torrent_phy
*cdns_phy
,
647 struct regmap
*regmap
= cdns_phy
->regmap_dptx_phy_reg
;
648 u32 pwr_state
= cdns_torrent_dp_read(regmap
,
649 PHY_PMA_XCVR_POWER_STATE_REQ
);
650 u32 pll_clk_en
= cdns_torrent_dp_read(regmap
,
651 PHY_PMA_XCVR_PLLCLK_EN
);
653 /* Lane 0 is always enabled. */
654 pwr_state
&= ~(PMA_XCVR_POWER_STATE_REQ_LN_MASK
<<
655 PHY_POWER_STATE_LN_0
);
656 pll_clk_en
&= ~0x01U
;
660 pwr_state
&= ~(PMA_XCVR_POWER_STATE_REQ_LN_MASK
<<
661 PHY_POWER_STATE_LN_1
);
662 pll_clk_en
&= ~(0x01U
<< 1);
667 pwr_state
&= ~(PMA_XCVR_POWER_STATE_REQ_LN_MASK
<<
668 PHY_POWER_STATE_LN_2
);
669 pwr_state
&= ~(PMA_XCVR_POWER_STATE_REQ_LN_MASK
<<
670 PHY_POWER_STATE_LN_3
);
671 pll_clk_en
&= ~(0x01U
<< 2);
672 pll_clk_en
&= ~(0x01U
<< 3);
675 cdns_torrent_dp_write(regmap
, PHY_PMA_XCVR_POWER_STATE_REQ
, pwr_state
);
676 cdns_torrent_dp_write(regmap
, PHY_PMA_XCVR_PLLCLK_EN
, pll_clk_en
);
679 /* Configure lane count as required. */
680 static int cdns_torrent_dp_set_lanes(struct cdns_torrent_phy
*cdns_phy
,
681 struct phy_configure_opts_dp
*dp
)
685 struct regmap
*regmap
= cdns_phy
->regmap_dptx_phy_reg
;
686 u8 lane_mask
= (1 << dp
->lanes
) - 1;
688 value
= cdns_torrent_dp_read(regmap
, PHY_RESET
);
689 /* clear pma_tx_elec_idle_ln_* bits. */
690 value
&= ~PMA_TX_ELEC_IDLE_MASK
;
691 /* Assert pma_tx_elec_idle_ln_* for disabled lanes. */
692 value
|= ((~lane_mask
) << PMA_TX_ELEC_IDLE_SHIFT
) &
693 PMA_TX_ELEC_IDLE_MASK
;
694 cdns_torrent_dp_write(regmap
, PHY_RESET
, value
);
696 /* reset the link by asserting phy_l00_reset_n low */
697 cdns_torrent_dp_write(regmap
, PHY_RESET
,
698 value
& (~PHY_L00_RESET_N_MASK
));
701 * Assert lane reset on unused lanes and lane 0 so they remain in reset
702 * and powered down when re-enabling the link
704 value
= (value
& 0x0000FFF0) | (0x0000000E & lane_mask
);
705 cdns_torrent_dp_write(regmap
, PHY_RESET
, value
);
707 cdns_torrent_dp_set_a0_pll(cdns_phy
, dp
->lanes
);
709 /* release phy_l0*_reset_n based on used laneCount */
710 value
= (value
& 0x0000FFF0) | (0x0000000F & lane_mask
);
711 cdns_torrent_dp_write(regmap
, PHY_RESET
, value
);
713 /* Wait, until PHY gets ready after releasing PHY reset signal. */
714 ret
= cdns_torrent_dp_wait_pma_cmn_ready(cdns_phy
);
720 /* release pma_xcvr_pllclk_en_ln_*, only for the master lane */
721 cdns_torrent_dp_write(regmap
, PHY_PMA_XCVR_PLLCLK_EN
, 0x0001);
723 ret
= cdns_torrent_dp_run(cdns_phy
, dp
->lanes
);
728 /* Configure link rate as required. */
729 static int cdns_torrent_dp_set_rate(struct cdns_torrent_phy
*cdns_phy
,
730 struct phy_configure_opts_dp
*dp
)
734 ret
= cdns_torrent_dp_set_power_state(cdns_phy
, dp
->lanes
,
738 ret
= cdns_torrent_dp_set_pll_en(cdns_phy
, dp
, false);
743 ret
= cdns_torrent_dp_configure_rate(cdns_phy
, dp
);
748 ret
= cdns_torrent_dp_set_pll_en(cdns_phy
, dp
, true);
751 ret
= cdns_torrent_dp_set_power_state(cdns_phy
, dp
->lanes
,
755 ret
= cdns_torrent_dp_set_power_state(cdns_phy
, dp
->lanes
,
764 /* Configure voltage swing and pre-emphasis for all enabled lanes. */
765 static void cdns_torrent_dp_set_voltages(struct cdns_torrent_phy
*cdns_phy
,
766 struct phy_configure_opts_dp
*dp
)
771 for (lane
= 0; lane
< dp
->lanes
; lane
++) {
772 val
= cdns_torrent_phy_read(cdns_phy
->regmap_tx_lane_cdb
[lane
],
775 * Write 1 to register bit TX_DIAG_ACYA[0] to freeze the
776 * current state of the analog TX driver.
778 val
|= TX_DIAG_ACYA_HBDC_MASK
;
779 cdns_torrent_phy_write(cdns_phy
->regmap_tx_lane_cdb
[lane
],
782 cdns_torrent_phy_write(cdns_phy
->regmap_tx_lane_cdb
[lane
],
783 TX_TXCC_CTRL
, 0x08A4);
784 val
= vltg_coeff
[dp
->voltage
[lane
]][dp
->pre
[lane
]].diag_tx_drv
;
785 cdns_torrent_phy_write(cdns_phy
->regmap_tx_lane_cdb
[lane
],
786 DRV_DIAG_TX_DRV
, val
);
787 val
= vltg_coeff
[dp
->voltage
[lane
]][dp
->pre
[lane
]].mgnfs_mult
;
788 cdns_torrent_phy_write(cdns_phy
->regmap_tx_lane_cdb
[lane
],
789 TX_TXCC_MGNFS_MULT_000
,
791 val
= vltg_coeff
[dp
->voltage
[lane
]][dp
->pre
[lane
]].cpost_mult
;
792 cdns_torrent_phy_write(cdns_phy
->regmap_tx_lane_cdb
[lane
],
793 TX_TXCC_CPOST_MULT_00
,
796 val
= cdns_torrent_phy_read(cdns_phy
->regmap_tx_lane_cdb
[lane
],
799 * Write 0 to register bit TX_DIAG_ACYA[0] to allow the state of
800 * analog TX driver to reflect the new programmed one.
802 val
&= ~TX_DIAG_ACYA_HBDC_MASK
;
803 cdns_torrent_phy_write(cdns_phy
->regmap_tx_lane_cdb
[lane
],
808 static int cdns_torrent_dp_configure(struct phy
*phy
,
809 union phy_configure_opts
*opts
)
811 struct cdns_torrent_inst
*inst
= phy_get_drvdata(phy
);
812 struct cdns_torrent_phy
*cdns_phy
= dev_get_drvdata(phy
->dev
.parent
);
815 ret
= cdns_torrent_dp_verify_config(inst
, &opts
->dp
);
817 dev_err(&phy
->dev
, "invalid params for phy configure\n");
821 if (opts
->dp
.set_lanes
) {
822 ret
= cdns_torrent_dp_set_lanes(cdns_phy
, &opts
->dp
);
824 dev_err(&phy
->dev
, "cdns_torrent_dp_set_lanes failed\n");
829 if (opts
->dp
.set_rate
) {
830 ret
= cdns_torrent_dp_set_rate(cdns_phy
, &opts
->dp
);
832 dev_err(&phy
->dev
, "cdns_torrent_dp_set_rate failed\n");
837 if (opts
->dp
.set_voltages
)
838 cdns_torrent_dp_set_voltages(cdns_phy
, &opts
->dp
);
843 static int cdns_torrent_dp_init(struct phy
*phy
)
845 unsigned char lane_bits
;
847 struct cdns_torrent_inst
*inst
= phy_get_drvdata(phy
);
848 struct cdns_torrent_phy
*cdns_phy
= dev_get_drvdata(phy
->dev
.parent
);
849 struct regmap
*regmap
= cdns_phy
->regmap_dptx_phy_reg
;
851 ret
= clk_prepare_enable(cdns_phy
->clk
);
853 dev_err(cdns_phy
->dev
, "Failed to prepare ref clock\n");
857 cdns_phy
->ref_clk_rate
= clk_get_rate(cdns_phy
->clk
);
858 if (!(cdns_phy
->ref_clk_rate
)) {
859 dev_err(cdns_phy
->dev
, "Failed to get ref clock rate\n");
860 clk_disable_unprepare(cdns_phy
->clk
);
864 switch (cdns_phy
->ref_clk_rate
) {
865 case REF_CLK_19_2MHz
:
867 /* Valid Ref Clock Rate */
870 dev_err(cdns_phy
->dev
, "Unsupported Ref Clock Rate\n");
874 cdns_torrent_dp_write(regmap
, PHY_AUX_CTRL
, 0x0003); /* enable AUX */
876 /* PHY PMA registers configuration function */
877 cdns_torrent_dp_pma_cfg(cdns_phy
, inst
);
880 * Set lines power state to A0
881 * Set lines pll clk enable to 0
883 cdns_torrent_dp_set_a0_pll(cdns_phy
, inst
->num_lanes
);
886 * release phy_l0*_reset_n and pma_tx_elec_idle_ln_* based on
889 lane_bits
= (1 << inst
->num_lanes
) - 1;
890 cdns_torrent_dp_write(regmap
, PHY_RESET
,
891 ((0xF & ~lane_bits
) << 4) | (0xF & lane_bits
));
893 /* release pma_xcvr_pllclk_en_ln_*, only for the master lane */
894 cdns_torrent_dp_write(regmap
, PHY_PMA_XCVR_PLLCLK_EN
, 0x0001);
896 /* PHY PMA registers configuration functions */
897 /* Initialize PHY with max supported link rate, without SSC. */
898 if (cdns_phy
->ref_clk_rate
== REF_CLK_19_2MHz
)
899 cdns_torrent_dp_pma_cmn_vco_cfg_19_2mhz(cdns_phy
,
900 cdns_phy
->max_bit_rate
,
902 else if (cdns_phy
->ref_clk_rate
== REF_CLK_25MHz
)
903 cdns_torrent_dp_pma_cmn_vco_cfg_25mhz(cdns_phy
,
904 cdns_phy
->max_bit_rate
,
906 cdns_torrent_dp_pma_cmn_rate(cdns_phy
, cdns_phy
->max_bit_rate
,
909 /* take out of reset */
910 regmap_field_write(cdns_phy
->phy_reset_ctrl
, 0x1);
912 cdns_torrent_phy_on(phy
);
914 ret
= cdns_torrent_dp_wait_pma_cmn_ready(cdns_phy
);
918 ret
= cdns_torrent_dp_run(cdns_phy
, inst
->num_lanes
);
923 static int cdns_torrent_dp_exit(struct phy
*phy
)
925 struct cdns_torrent_phy
*cdns_phy
= dev_get_drvdata(phy
->dev
.parent
);
927 clk_disable_unprepare(cdns_phy
->clk
);
932 int cdns_torrent_dp_wait_pma_cmn_ready(struct cdns_torrent_phy
*cdns_phy
)
936 struct regmap
*regmap
= cdns_phy
->regmap_dptx_phy_reg
;
938 ret
= regmap_read_poll_timeout(regmap
, PHY_PMA_CMN_READY
, reg
,
939 reg
& 1, 0, POLL_TIMEOUT_US
);
940 if (ret
== -ETIMEDOUT
) {
941 dev_err(cdns_phy
->dev
,
942 "timeout waiting for PMA common ready\n");
949 static void cdns_torrent_dp_pma_cfg(struct cdns_torrent_phy
*cdns_phy
,
950 struct cdns_torrent_inst
*inst
)
954 if (cdns_phy
->ref_clk_rate
== REF_CLK_19_2MHz
)
955 /* PMA common configuration 19.2MHz */
956 cdns_torrent_dp_pma_cmn_cfg_19_2mhz(cdns_phy
);
957 else if (cdns_phy
->ref_clk_rate
== REF_CLK_25MHz
)
958 /* PMA common configuration 25MHz */
959 cdns_torrent_dp_pma_cmn_cfg_25mhz(cdns_phy
);
961 /* PMA lane configuration to deal with multi-link operation */
962 for (i
= 0; i
< inst
->num_lanes
; i
++)
963 cdns_torrent_dp_pma_lane_cfg(cdns_phy
, i
);
967 void cdns_torrent_dp_pma_cmn_cfg_19_2mhz(struct cdns_torrent_phy
*cdns_phy
)
969 struct regmap
*regmap
= cdns_phy
->regmap_common_cdb
;
971 /* refclock registers - assumes 19.2 MHz refclock */
972 cdns_torrent_phy_write(regmap
, CMN_SSM_BIAS_TMR
, 0x0014);
973 cdns_torrent_phy_write(regmap
, CMN_PLLSM0_PLLPRE_TMR
, 0x0027);
974 cdns_torrent_phy_write(regmap
, CMN_PLLSM0_PLLLOCK_TMR
, 0x00A1);
975 cdns_torrent_phy_write(regmap
, CMN_PLLSM1_PLLPRE_TMR
, 0x0027);
976 cdns_torrent_phy_write(regmap
, CMN_PLLSM1_PLLLOCK_TMR
, 0x00A1);
977 cdns_torrent_phy_write(regmap
, CMN_BGCAL_INIT_TMR
, 0x0060);
978 cdns_torrent_phy_write(regmap
, CMN_BGCAL_ITER_TMR
, 0x0060);
979 cdns_torrent_phy_write(regmap
, CMN_IBCAL_INIT_TMR
, 0x0014);
980 cdns_torrent_phy_write(regmap
, CMN_TXPUCAL_INIT_TMR
, 0x0018);
981 cdns_torrent_phy_write(regmap
, CMN_TXPUCAL_ITER_TMR
, 0x0005);
982 cdns_torrent_phy_write(regmap
, CMN_TXPDCAL_INIT_TMR
, 0x0018);
983 cdns_torrent_phy_write(regmap
, CMN_TXPDCAL_ITER_TMR
, 0x0005);
984 cdns_torrent_phy_write(regmap
, CMN_RXCAL_INIT_TMR
, 0x0240);
985 cdns_torrent_phy_write(regmap
, CMN_RXCAL_ITER_TMR
, 0x0005);
986 cdns_torrent_phy_write(regmap
, CMN_SD_CAL_INIT_TMR
, 0x0002);
987 cdns_torrent_phy_write(regmap
, CMN_SD_CAL_ITER_TMR
, 0x0002);
988 cdns_torrent_phy_write(regmap
, CMN_SD_CAL_REFTIM_START
, 0x000B);
989 cdns_torrent_phy_write(regmap
, CMN_SD_CAL_PLLCNT_START
, 0x0137);
992 cdns_torrent_phy_write(regmap
, CMN_PDIAG_PLL0_CP_PADJ_M0
, 0x0509);
993 cdns_torrent_phy_write(regmap
, CMN_PDIAG_PLL0_CP_IADJ_M0
, 0x0F00);
994 cdns_torrent_phy_write(regmap
, CMN_PDIAG_PLL0_FILT_PADJ_M0
, 0x0F08);
995 cdns_torrent_phy_write(regmap
, CMN_PLL0_DSM_DIAG_M0
, 0x0004);
996 cdns_torrent_phy_write(regmap
, CMN_PDIAG_PLL1_CP_PADJ_M0
, 0x0509);
997 cdns_torrent_phy_write(regmap
, CMN_PDIAG_PLL1_CP_IADJ_M0
, 0x0F00);
998 cdns_torrent_phy_write(regmap
, CMN_PDIAG_PLL1_FILT_PADJ_M0
, 0x0F08);
999 cdns_torrent_phy_write(regmap
, CMN_PLL1_DSM_DIAG_M0
, 0x0004);
1000 cdns_torrent_phy_write(regmap
, CMN_PLL0_VCOCAL_INIT_TMR
, 0x00C0);
1001 cdns_torrent_phy_write(regmap
, CMN_PLL0_VCOCAL_ITER_TMR
, 0x0004);
1002 cdns_torrent_phy_write(regmap
, CMN_PLL1_VCOCAL_INIT_TMR
, 0x00C0);
1003 cdns_torrent_phy_write(regmap
, CMN_PLL1_VCOCAL_ITER_TMR
, 0x0004);
1004 cdns_torrent_phy_write(regmap
, CMN_PLL0_VCOCAL_REFTIM_START
, 0x0260);
1005 cdns_torrent_phy_write(regmap
, CMN_PLL0_VCOCAL_TCTRL
, 0x0003);
1006 cdns_torrent_phy_write(regmap
, CMN_PLL1_VCOCAL_REFTIM_START
, 0x0260);
1007 cdns_torrent_phy_write(regmap
, CMN_PLL1_VCOCAL_TCTRL
, 0x0003);
1011 * Set registers responsible for enabling and configuring SSC, with second and
1012 * third register values provided by parameters.
1015 void cdns_torrent_dp_enable_ssc_19_2mhz(struct cdns_torrent_phy
*cdns_phy
,
1016 u32 ctrl2_val
, u32 ctrl3_val
)
1018 struct regmap
*regmap
= cdns_phy
->regmap_common_cdb
;
1020 cdns_torrent_phy_write(regmap
, CMN_PLL0_SS_CTRL1_M0
, 0x0001);
1021 cdns_torrent_phy_write(regmap
, CMN_PLL0_SS_CTRL1_M0
, ctrl2_val
);
1022 cdns_torrent_phy_write(regmap
, CMN_PLL0_SS_CTRL1_M0
, ctrl3_val
);
1023 cdns_torrent_phy_write(regmap
, CMN_PLL0_SS_CTRL4_M0
, 0x0003);
1024 cdns_torrent_phy_write(regmap
, CMN_PLL1_SS_CTRL1_M0
, 0x0001);
1025 cdns_torrent_phy_write(regmap
, CMN_PLL1_SS_CTRL1_M0
, ctrl2_val
);
1026 cdns_torrent_phy_write(regmap
, CMN_PLL1_SS_CTRL1_M0
, ctrl3_val
);
1027 cdns_torrent_phy_write(regmap
, CMN_PLL1_SS_CTRL4_M0
, 0x0003);
1031 void cdns_torrent_dp_pma_cmn_vco_cfg_19_2mhz(struct cdns_torrent_phy
*cdns_phy
,
1034 struct regmap
*regmap
= cdns_phy
->regmap_common_cdb
;
1036 /* Assumes 19.2 MHz refclock */
1038 /* Setting VCO for 10.8GHz */
1041 cdns_torrent_phy_write(regmap
,
1042 CMN_PLL0_INTDIV_M0
, 0x0119);
1043 cdns_torrent_phy_write(regmap
,
1044 CMN_PLL0_FRACDIVL_M0
, 0x4000);
1045 cdns_torrent_phy_write(regmap
,
1046 CMN_PLL0_FRACDIVH_M0
, 0x0002);
1047 cdns_torrent_phy_write(regmap
,
1048 CMN_PLL0_HIGH_THR_M0
, 0x00BC);
1049 cdns_torrent_phy_write(regmap
,
1050 CMN_PDIAG_PLL0_CTRL_M0
, 0x0012);
1051 cdns_torrent_phy_write(regmap
,
1052 CMN_PLL1_INTDIV_M0
, 0x0119);
1053 cdns_torrent_phy_write(regmap
,
1054 CMN_PLL1_FRACDIVL_M0
, 0x4000);
1055 cdns_torrent_phy_write(regmap
,
1056 CMN_PLL1_FRACDIVH_M0
, 0x0002);
1057 cdns_torrent_phy_write(regmap
,
1058 CMN_PLL1_HIGH_THR_M0
, 0x00BC);
1059 cdns_torrent_phy_write(regmap
,
1060 CMN_PDIAG_PLL1_CTRL_M0
, 0x0012);
1062 cdns_torrent_dp_enable_ssc_19_2mhz(cdns_phy
, 0x033A,
1065 /* Setting VCO for 9.72GHz */
1069 cdns_torrent_phy_write(regmap
,
1070 CMN_PLL0_INTDIV_M0
, 0x01FA);
1071 cdns_torrent_phy_write(regmap
,
1072 CMN_PLL0_FRACDIVL_M0
, 0x4000);
1073 cdns_torrent_phy_write(regmap
,
1074 CMN_PLL0_FRACDIVH_M0
, 0x0002);
1075 cdns_torrent_phy_write(regmap
,
1076 CMN_PLL0_HIGH_THR_M0
, 0x0152);
1077 cdns_torrent_phy_write(regmap
,
1078 CMN_PDIAG_PLL0_CTRL_M0
, 0x0002);
1079 cdns_torrent_phy_write(regmap
,
1080 CMN_PLL1_INTDIV_M0
, 0x01FA);
1081 cdns_torrent_phy_write(regmap
,
1082 CMN_PLL1_FRACDIVL_M0
, 0x4000);
1083 cdns_torrent_phy_write(regmap
,
1084 CMN_PLL1_FRACDIVH_M0
, 0x0002);
1085 cdns_torrent_phy_write(regmap
,
1086 CMN_PLL1_HIGH_THR_M0
, 0x0152);
1087 cdns_torrent_phy_write(regmap
,
1088 CMN_PDIAG_PLL1_CTRL_M0
, 0x0002);
1090 cdns_torrent_dp_enable_ssc_19_2mhz(cdns_phy
, 0x05DD,
1093 /* Setting VCO for 8.64GHz */
1096 cdns_torrent_phy_write(regmap
,
1097 CMN_PLL0_INTDIV_M0
, 0x01C2);
1098 cdns_torrent_phy_write(regmap
,
1099 CMN_PLL0_FRACDIVL_M0
, 0x0000);
1100 cdns_torrent_phy_write(regmap
,
1101 CMN_PLL0_FRACDIVH_M0
, 0x0002);
1102 cdns_torrent_phy_write(regmap
,
1103 CMN_PLL0_HIGH_THR_M0
, 0x012C);
1104 cdns_torrent_phy_write(regmap
,
1105 CMN_PDIAG_PLL0_CTRL_M0
, 0x0002);
1106 cdns_torrent_phy_write(regmap
,
1107 CMN_PLL1_INTDIV_M0
, 0x01C2);
1108 cdns_torrent_phy_write(regmap
,
1109 CMN_PLL1_FRACDIVL_M0
, 0x0000);
1110 cdns_torrent_phy_write(regmap
,
1111 CMN_PLL1_FRACDIVH_M0
, 0x0002);
1112 cdns_torrent_phy_write(regmap
,
1113 CMN_PLL1_HIGH_THR_M0
, 0x012C);
1114 cdns_torrent_phy_write(regmap
,
1115 CMN_PDIAG_PLL1_CTRL_M0
, 0x0002);
1117 cdns_torrent_dp_enable_ssc_19_2mhz(cdns_phy
, 0x0536,
1120 /* Setting VCO for 8.1GHz */
1122 cdns_torrent_phy_write(regmap
,
1123 CMN_PLL0_INTDIV_M0
, 0x01A5);
1124 cdns_torrent_phy_write(regmap
,
1125 CMN_PLL0_FRACDIVL_M0
, 0xE000);
1126 cdns_torrent_phy_write(regmap
,
1127 CMN_PLL0_FRACDIVH_M0
, 0x0002);
1128 cdns_torrent_phy_write(regmap
,
1129 CMN_PLL0_HIGH_THR_M0
, 0x011A);
1130 cdns_torrent_phy_write(regmap
,
1131 CMN_PDIAG_PLL0_CTRL_M0
, 0x0002);
1132 cdns_torrent_phy_write(regmap
,
1133 CMN_PLL1_INTDIV_M0
, 0x01A5);
1134 cdns_torrent_phy_write(regmap
,
1135 CMN_PLL1_FRACDIVL_M0
, 0xE000);
1136 cdns_torrent_phy_write(regmap
,
1137 CMN_PLL1_FRACDIVH_M0
, 0x0002);
1138 cdns_torrent_phy_write(regmap
,
1139 CMN_PLL1_HIGH_THR_M0
, 0x011A);
1140 cdns_torrent_phy_write(regmap
,
1141 CMN_PDIAG_PLL1_CTRL_M0
, 0x0002);
1143 cdns_torrent_dp_enable_ssc_19_2mhz(cdns_phy
, 0x04D7,
1149 cdns_torrent_phy_write(regmap
,
1150 CMN_PLL0_VCOCAL_PLLCNT_START
, 0x025E);
1151 cdns_torrent_phy_write(regmap
,
1152 CMN_PLL0_LOCK_PLLCNT_THR
, 0x0005);
1153 cdns_torrent_phy_write(regmap
,
1154 CMN_PLL1_VCOCAL_PLLCNT_START
, 0x025E);
1155 cdns_torrent_phy_write(regmap
,
1156 CMN_PLL1_LOCK_PLLCNT_THR
, 0x0005);
1158 cdns_torrent_phy_write(regmap
,
1159 CMN_PLL0_VCOCAL_PLLCNT_START
, 0x0260);
1160 cdns_torrent_phy_write(regmap
,
1161 CMN_PLL1_VCOCAL_PLLCNT_START
, 0x0260);
1162 /* Set reset register values to disable SSC */
1163 cdns_torrent_phy_write(regmap
,
1164 CMN_PLL0_SS_CTRL1_M0
, 0x0002);
1165 cdns_torrent_phy_write(regmap
,
1166 CMN_PLL0_SS_CTRL2_M0
, 0x0000);
1167 cdns_torrent_phy_write(regmap
,
1168 CMN_PLL0_SS_CTRL3_M0
, 0x0000);
1169 cdns_torrent_phy_write(regmap
,
1170 CMN_PLL0_SS_CTRL4_M0
, 0x0000);
1171 cdns_torrent_phy_write(regmap
,
1172 CMN_PLL0_LOCK_PLLCNT_THR
, 0x0003);
1173 cdns_torrent_phy_write(regmap
,
1174 CMN_PLL1_SS_CTRL1_M0
, 0x0002);
1175 cdns_torrent_phy_write(regmap
,
1176 CMN_PLL1_SS_CTRL2_M0
, 0x0000);
1177 cdns_torrent_phy_write(regmap
,
1178 CMN_PLL1_SS_CTRL3_M0
, 0x0000);
1179 cdns_torrent_phy_write(regmap
,
1180 CMN_PLL1_SS_CTRL4_M0
, 0x0000);
1181 cdns_torrent_phy_write(regmap
,
1182 CMN_PLL1_LOCK_PLLCNT_THR
, 0x0003);
1185 cdns_torrent_phy_write(regmap
, CMN_PLL0_LOCK_REFCNT_START
, 0x0099);
1186 cdns_torrent_phy_write(regmap
, CMN_PLL0_LOCK_PLLCNT_START
, 0x0099);
1187 cdns_torrent_phy_write(regmap
, CMN_PLL1_LOCK_REFCNT_START
, 0x0099);
1188 cdns_torrent_phy_write(regmap
, CMN_PLL1_LOCK_PLLCNT_START
, 0x0099);
1192 void cdns_torrent_dp_pma_cmn_cfg_25mhz(struct cdns_torrent_phy
*cdns_phy
)
1194 struct regmap
*regmap
= cdns_phy
->regmap_common_cdb
;
1196 /* refclock registers - assumes 25 MHz refclock */
1197 cdns_torrent_phy_write(regmap
, CMN_SSM_BIAS_TMR
, 0x0019);
1198 cdns_torrent_phy_write(regmap
, CMN_PLLSM0_PLLPRE_TMR
, 0x0032);
1199 cdns_torrent_phy_write(regmap
, CMN_PLLSM0_PLLLOCK_TMR
, 0x00D1);
1200 cdns_torrent_phy_write(regmap
, CMN_PLLSM1_PLLPRE_TMR
, 0x0032);
1201 cdns_torrent_phy_write(regmap
, CMN_PLLSM1_PLLLOCK_TMR
, 0x00D1);
1202 cdns_torrent_phy_write(regmap
, CMN_BGCAL_INIT_TMR
, 0x007D);
1203 cdns_torrent_phy_write(regmap
, CMN_BGCAL_ITER_TMR
, 0x007D);
1204 cdns_torrent_phy_write(regmap
, CMN_IBCAL_INIT_TMR
, 0x0019);
1205 cdns_torrent_phy_write(regmap
, CMN_TXPUCAL_INIT_TMR
, 0x001E);
1206 cdns_torrent_phy_write(regmap
, CMN_TXPUCAL_ITER_TMR
, 0x0006);
1207 cdns_torrent_phy_write(regmap
, CMN_TXPDCAL_INIT_TMR
, 0x001E);
1208 cdns_torrent_phy_write(regmap
, CMN_TXPDCAL_ITER_TMR
, 0x0006);
1209 cdns_torrent_phy_write(regmap
, CMN_RXCAL_INIT_TMR
, 0x02EE);
1210 cdns_torrent_phy_write(regmap
, CMN_RXCAL_ITER_TMR
, 0x0006);
1211 cdns_torrent_phy_write(regmap
, CMN_SD_CAL_INIT_TMR
, 0x0002);
1212 cdns_torrent_phy_write(regmap
, CMN_SD_CAL_ITER_TMR
, 0x0002);
1213 cdns_torrent_phy_write(regmap
, CMN_SD_CAL_REFTIM_START
, 0x000E);
1214 cdns_torrent_phy_write(regmap
, CMN_SD_CAL_PLLCNT_START
, 0x012B);
1217 cdns_torrent_phy_write(regmap
, CMN_PDIAG_PLL0_CP_PADJ_M0
, 0x0509);
1218 cdns_torrent_phy_write(regmap
, CMN_PDIAG_PLL0_CP_IADJ_M0
, 0x0F00);
1219 cdns_torrent_phy_write(regmap
, CMN_PDIAG_PLL0_FILT_PADJ_M0
, 0x0F08);
1220 cdns_torrent_phy_write(regmap
, CMN_PLL0_DSM_DIAG_M0
, 0x0004);
1221 cdns_torrent_phy_write(regmap
, CMN_PDIAG_PLL1_CP_PADJ_M0
, 0x0509);
1222 cdns_torrent_phy_write(regmap
, CMN_PDIAG_PLL1_CP_IADJ_M0
, 0x0F00);
1223 cdns_torrent_phy_write(regmap
, CMN_PDIAG_PLL1_FILT_PADJ_M0
, 0x0F08);
1224 cdns_torrent_phy_write(regmap
, CMN_PLL1_DSM_DIAG_M0
, 0x0004);
1225 cdns_torrent_phy_write(regmap
, CMN_PLL0_VCOCAL_INIT_TMR
, 0x00FA);
1226 cdns_torrent_phy_write(regmap
, CMN_PLL0_VCOCAL_ITER_TMR
, 0x0004);
1227 cdns_torrent_phy_write(regmap
, CMN_PLL1_VCOCAL_INIT_TMR
, 0x00FA);
1228 cdns_torrent_phy_write(regmap
, CMN_PLL1_VCOCAL_ITER_TMR
, 0x0004);
1229 cdns_torrent_phy_write(regmap
, CMN_PLL0_VCOCAL_REFTIM_START
, 0x0317);
1230 cdns_torrent_phy_write(regmap
, CMN_PLL0_VCOCAL_TCTRL
, 0x0003);
1231 cdns_torrent_phy_write(regmap
, CMN_PLL1_VCOCAL_REFTIM_START
, 0x0317);
1232 cdns_torrent_phy_write(regmap
, CMN_PLL1_VCOCAL_TCTRL
, 0x0003);
1236 * Set registers responsible for enabling and configuring SSC, with second
1237 * register value provided by a parameter.
1239 static void cdns_torrent_dp_enable_ssc_25mhz(struct cdns_torrent_phy
*cdns_phy
,
1242 struct regmap
*regmap
= cdns_phy
->regmap_common_cdb
;
1244 cdns_torrent_phy_write(regmap
, CMN_PLL0_SS_CTRL1_M0
, 0x0001);
1245 cdns_torrent_phy_write(regmap
, CMN_PLL0_SS_CTRL1_M0
, ctrl2_val
);
1246 cdns_torrent_phy_write(regmap
, CMN_PLL0_SS_CTRL1_M0
, 0x007F);
1247 cdns_torrent_phy_write(regmap
, CMN_PLL0_SS_CTRL4_M0
, 0x0003);
1248 cdns_torrent_phy_write(regmap
, CMN_PLL1_SS_CTRL1_M0
, 0x0001);
1249 cdns_torrent_phy_write(regmap
, CMN_PLL1_SS_CTRL1_M0
, ctrl2_val
);
1250 cdns_torrent_phy_write(regmap
, CMN_PLL1_SS_CTRL1_M0
, 0x007F);
1251 cdns_torrent_phy_write(regmap
, CMN_PLL1_SS_CTRL4_M0
, 0x0003);
1255 void cdns_torrent_dp_pma_cmn_vco_cfg_25mhz(struct cdns_torrent_phy
*cdns_phy
,
1258 struct regmap
*regmap
= cdns_phy
->regmap_common_cdb
;
1260 /* Assumes 25 MHz refclock */
1262 /* Setting VCO for 10.8GHz */
1265 cdns_torrent_phy_write(regmap
, CMN_PLL0_INTDIV_M0
, 0x01B0);
1266 cdns_torrent_phy_write(regmap
, CMN_PLL0_FRACDIVL_M0
, 0x0000);
1267 cdns_torrent_phy_write(regmap
, CMN_PLL0_FRACDIVH_M0
, 0x0002);
1268 cdns_torrent_phy_write(regmap
, CMN_PLL0_HIGH_THR_M0
, 0x0120);
1269 cdns_torrent_phy_write(regmap
, CMN_PLL1_INTDIV_M0
, 0x01B0);
1270 cdns_torrent_phy_write(regmap
, CMN_PLL1_FRACDIVL_M0
, 0x0000);
1271 cdns_torrent_phy_write(regmap
, CMN_PLL1_FRACDIVH_M0
, 0x0002);
1272 cdns_torrent_phy_write(regmap
, CMN_PLL1_HIGH_THR_M0
, 0x0120);
1274 cdns_torrent_dp_enable_ssc_25mhz(cdns_phy
, 0x0423);
1276 /* Setting VCO for 9.72GHz */
1280 cdns_torrent_phy_write(regmap
, CMN_PLL0_INTDIV_M0
, 0x0184);
1281 cdns_torrent_phy_write(regmap
, CMN_PLL0_FRACDIVL_M0
, 0xCCCD);
1282 cdns_torrent_phy_write(regmap
, CMN_PLL0_FRACDIVH_M0
, 0x0002);
1283 cdns_torrent_phy_write(regmap
, CMN_PLL0_HIGH_THR_M0
, 0x0104);
1284 cdns_torrent_phy_write(regmap
, CMN_PLL1_INTDIV_M0
, 0x0184);
1285 cdns_torrent_phy_write(regmap
, CMN_PLL1_FRACDIVL_M0
, 0xCCCD);
1286 cdns_torrent_phy_write(regmap
, CMN_PLL1_FRACDIVH_M0
, 0x0002);
1287 cdns_torrent_phy_write(regmap
, CMN_PLL1_HIGH_THR_M0
, 0x0104);
1289 cdns_torrent_dp_enable_ssc_25mhz(cdns_phy
, 0x03B9);
1291 /* Setting VCO for 8.64GHz */
1294 cdns_torrent_phy_write(regmap
, CMN_PLL0_INTDIV_M0
, 0x0159);
1295 cdns_torrent_phy_write(regmap
, CMN_PLL0_FRACDIVL_M0
, 0x999A);
1296 cdns_torrent_phy_write(regmap
, CMN_PLL0_FRACDIVH_M0
, 0x0002);
1297 cdns_torrent_phy_write(regmap
, CMN_PLL0_HIGH_THR_M0
, 0x00E7);
1298 cdns_torrent_phy_write(regmap
, CMN_PLL1_INTDIV_M0
, 0x0159);
1299 cdns_torrent_phy_write(regmap
, CMN_PLL1_FRACDIVL_M0
, 0x999A);
1300 cdns_torrent_phy_write(regmap
, CMN_PLL1_FRACDIVH_M0
, 0x0002);
1301 cdns_torrent_phy_write(regmap
, CMN_PLL1_HIGH_THR_M0
, 0x00E7);
1303 cdns_torrent_dp_enable_ssc_25mhz(cdns_phy
, 0x034F);
1305 /* Setting VCO for 8.1GHz */
1307 cdns_torrent_phy_write(regmap
, CMN_PLL0_INTDIV_M0
, 0x0144);
1308 cdns_torrent_phy_write(regmap
, CMN_PLL0_FRACDIVL_M0
, 0x0000);
1309 cdns_torrent_phy_write(regmap
, CMN_PLL0_FRACDIVH_M0
, 0x0002);
1310 cdns_torrent_phy_write(regmap
, CMN_PLL0_HIGH_THR_M0
, 0x00D8);
1311 cdns_torrent_phy_write(regmap
, CMN_PLL1_INTDIV_M0
, 0x0144);
1312 cdns_torrent_phy_write(regmap
, CMN_PLL1_FRACDIVL_M0
, 0x0000);
1313 cdns_torrent_phy_write(regmap
, CMN_PLL1_FRACDIVH_M0
, 0x0002);
1314 cdns_torrent_phy_write(regmap
, CMN_PLL1_HIGH_THR_M0
, 0x00D8);
1316 cdns_torrent_dp_enable_ssc_25mhz(cdns_phy
, 0x031A);
1320 cdns_torrent_phy_write(regmap
, CMN_PDIAG_PLL0_CTRL_M0
, 0x0002);
1321 cdns_torrent_phy_write(regmap
, CMN_PDIAG_PLL1_CTRL_M0
, 0x0002);
1324 cdns_torrent_phy_write(regmap
,
1325 CMN_PLL0_VCOCAL_PLLCNT_START
, 0x0315);
1326 cdns_torrent_phy_write(regmap
,
1327 CMN_PLL0_LOCK_PLLCNT_THR
, 0x0005);
1328 cdns_torrent_phy_write(regmap
,
1329 CMN_PLL1_VCOCAL_PLLCNT_START
, 0x0315);
1330 cdns_torrent_phy_write(regmap
,
1331 CMN_PLL1_LOCK_PLLCNT_THR
, 0x0005);
1333 cdns_torrent_phy_write(regmap
,
1334 CMN_PLL0_VCOCAL_PLLCNT_START
, 0x0317);
1335 cdns_torrent_phy_write(regmap
,
1336 CMN_PLL1_VCOCAL_PLLCNT_START
, 0x0317);
1337 /* Set reset register values to disable SSC */
1338 cdns_torrent_phy_write(regmap
, CMN_PLL0_SS_CTRL1_M0
, 0x0002);
1339 cdns_torrent_phy_write(regmap
, CMN_PLL0_SS_CTRL2_M0
, 0x0000);
1340 cdns_torrent_phy_write(regmap
, CMN_PLL0_SS_CTRL3_M0
, 0x0000);
1341 cdns_torrent_phy_write(regmap
, CMN_PLL0_SS_CTRL4_M0
, 0x0000);
1342 cdns_torrent_phy_write(regmap
,
1343 CMN_PLL0_LOCK_PLLCNT_THR
, 0x0003);
1344 cdns_torrent_phy_write(regmap
, CMN_PLL1_SS_CTRL1_M0
, 0x0002);
1345 cdns_torrent_phy_write(regmap
, CMN_PLL1_SS_CTRL2_M0
, 0x0000);
1346 cdns_torrent_phy_write(regmap
, CMN_PLL1_SS_CTRL3_M0
, 0x0000);
1347 cdns_torrent_phy_write(regmap
, CMN_PLL1_SS_CTRL4_M0
, 0x0000);
1348 cdns_torrent_phy_write(regmap
,
1349 CMN_PLL1_LOCK_PLLCNT_THR
, 0x0003);
1352 cdns_torrent_phy_write(regmap
, CMN_PLL0_LOCK_REFCNT_START
, 0x00C7);
1353 cdns_torrent_phy_write(regmap
, CMN_PLL0_LOCK_PLLCNT_START
, 0x00C7);
1354 cdns_torrent_phy_write(regmap
, CMN_PLL1_LOCK_REFCNT_START
, 0x00C7);
1355 cdns_torrent_phy_write(regmap
, CMN_PLL1_LOCK_PLLCNT_START
, 0x00C7);
1358 static void cdns_torrent_dp_pma_cmn_rate(struct cdns_torrent_phy
*cdns_phy
,
1359 u32 rate
, u32 num_lanes
)
1361 unsigned int clk_sel_val
= 0;
1362 unsigned int hsclk_div_val
= 0;
1365 /* 16'h0000 for single DP link configuration */
1366 regmap_field_write(cdns_phy
->phy_pll_cfg
, 0x0);
1370 clk_sel_val
= 0x0f01;
1376 clk_sel_val
= 0x0701;
1380 clk_sel_val
= 0x0b00;
1385 clk_sel_val
= 0x0301;
1389 clk_sel_val
= 0x0200;
1394 cdns_torrent_phy_write(cdns_phy
->regmap_common_cdb
,
1395 CMN_PDIAG_PLL0_CLK_SEL_M0
, clk_sel_val
);
1396 cdns_torrent_phy_write(cdns_phy
->regmap_common_cdb
,
1397 CMN_PDIAG_PLL1_CLK_SEL_M0
, clk_sel_val
);
1399 /* PMA lane configuration to deal with multi-link operation */
1400 for (i
= 0; i
< num_lanes
; i
++)
1401 cdns_torrent_phy_write(cdns_phy
->regmap_tx_lane_cdb
[i
],
1402 XCVR_DIAG_HSCLK_DIV
, hsclk_div_val
);
1405 static void cdns_torrent_dp_pma_lane_cfg(struct cdns_torrent_phy
*cdns_phy
,
1408 /* Per lane, refclock-dependent receiver detection setting */
1409 if (cdns_phy
->ref_clk_rate
== REF_CLK_19_2MHz
)
1410 cdns_torrent_phy_write(cdns_phy
->regmap_tx_lane_cdb
[lane
],
1411 TX_RCVDET_ST_TMR
, 0x0780);
1412 else if (cdns_phy
->ref_clk_rate
== REF_CLK_25MHz
)
1413 cdns_torrent_phy_write(cdns_phy
->regmap_tx_lane_cdb
[lane
],
1414 TX_RCVDET_ST_TMR
, 0x09C4);
1416 /* Writing Tx/Rx Power State Controllers registers */
1417 cdns_torrent_phy_write(cdns_phy
->regmap_tx_lane_cdb
[lane
],
1419 cdns_torrent_phy_write(cdns_phy
->regmap_tx_lane_cdb
[lane
],
1421 cdns_torrent_phy_write(cdns_phy
->regmap_tx_lane_cdb
[lane
],
1423 cdns_torrent_phy_write(cdns_phy
->regmap_rx_lane_cdb
[lane
],
1425 cdns_torrent_phy_write(cdns_phy
->regmap_rx_lane_cdb
[lane
],
1427 cdns_torrent_phy_write(cdns_phy
->regmap_rx_lane_cdb
[lane
],
1430 cdns_torrent_phy_write(cdns_phy
->regmap_rx_lane_cdb
[lane
],
1431 RX_PSC_CAL
, 0x0000);
1433 cdns_torrent_phy_write(cdns_phy
->regmap_rx_lane_cdb
[lane
],
1434 RX_REE_GCSM1_CTRL
, 0x0000);
1435 cdns_torrent_phy_write(cdns_phy
->regmap_rx_lane_cdb
[lane
],
1436 RX_REE_GCSM2_CTRL
, 0x0000);
1437 cdns_torrent_phy_write(cdns_phy
->regmap_rx_lane_cdb
[lane
],
1438 RX_REE_PERGCSM_CTRL
, 0x0000);
1440 cdns_torrent_phy_write(cdns_phy
->regmap_tx_lane_cdb
[lane
],
1441 XCVR_DIAG_BIDI_CTRL
, 0x000F);
1442 cdns_torrent_phy_write(cdns_phy
->regmap_tx_lane_cdb
[lane
],
1443 XCVR_DIAG_PLLDRC_CTRL
, 0x0001);
1444 cdns_torrent_phy_write(cdns_phy
->regmap_tx_lane_cdb
[lane
],
1445 XCVR_DIAG_HSCLK_SEL
, 0x0000);
1448 static int cdns_torrent_dp_set_power_state(struct cdns_torrent_phy
*cdns_phy
,
1450 enum phy_powerstate powerstate
)
1452 /* Register value for power state for a single byte. */
1458 struct regmap
*regmap
= cdns_phy
->regmap_dptx_phy_reg
;
1460 switch (powerstate
) {
1461 case (POWERSTATE_A0
):
1464 case (POWERSTATE_A2
):
1473 /* Select values of registers and mask, depending on enabled
1476 switch (num_lanes
) {
1485 | (value_part
<< 8));
1488 /* lanes 0-3, all */
1492 | (value_part
<< 16)
1493 | (value_part
<< 24));
1498 /* Set power state A<n>. */
1499 cdns_torrent_dp_write(regmap
, PHY_PMA_XCVR_POWER_STATE_REQ
, value
);
1500 /* Wait, until PHY acknowledges power state completion. */
1501 ret
= regmap_read_poll_timeout(regmap
, PHY_PMA_XCVR_POWER_STATE_ACK
,
1502 read_val
, (read_val
& mask
) == value
, 0,
1504 cdns_torrent_dp_write(regmap
, PHY_PMA_XCVR_POWER_STATE_REQ
, 0x00000000);
1510 static int cdns_torrent_dp_run(struct cdns_torrent_phy
*cdns_phy
, u32 num_lanes
)
1512 unsigned int read_val
;
1514 struct regmap
*regmap
= cdns_phy
->regmap_dptx_phy_reg
;
1517 * waiting for ACK of pma_xcvr_pllclk_en_ln_*, only for the
1520 ret
= regmap_read_poll_timeout(regmap
, PHY_PMA_XCVR_PLLCLK_EN_ACK
,
1521 read_val
, read_val
& 1,
1522 0, POLL_TIMEOUT_US
);
1523 if (ret
== -ETIMEDOUT
) {
1524 dev_err(cdns_phy
->dev
,
1525 "timeout waiting for link PLL clock enable ack\n");
1531 ret
= cdns_torrent_dp_set_power_state(cdns_phy
, num_lanes
,
1536 ret
= cdns_torrent_dp_set_power_state(cdns_phy
, num_lanes
,
1542 static int cdns_torrent_phy_on(struct phy
*phy
)
1544 struct cdns_torrent_inst
*inst
= phy_get_drvdata(phy
);
1545 struct cdns_torrent_phy
*cdns_phy
= dev_get_drvdata(phy
->dev
.parent
);
1548 /* Take the PHY out of reset */
1549 ret
= reset_control_deassert(cdns_phy
->phy_rst
);
1553 /* Take the PHY lane group out of reset */
1554 return reset_control_deassert(inst
->lnk_rst
);
1557 static int cdns_torrent_phy_off(struct phy
*phy
)
1559 struct cdns_torrent_inst
*inst
= phy_get_drvdata(phy
);
1560 struct cdns_torrent_phy
*cdns_phy
= dev_get_drvdata(phy
->dev
.parent
);
1563 ret
= reset_control_assert(cdns_phy
->phy_rst
);
1567 return reset_control_assert(inst
->lnk_rst
);
1570 static struct regmap
*cdns_regmap_init(struct device
*dev
, void __iomem
*base
,
1572 u8 reg_offset_shift
,
1573 const struct regmap_config
*config
)
1575 struct cdns_regmap_cdb_context
*ctx
;
1577 ctx
= devm_kzalloc(dev
, sizeof(*ctx
), GFP_KERNEL
);
1579 return ERR_PTR(-ENOMEM
);
1582 ctx
->base
= base
+ block_offset
;
1583 ctx
->reg_offset_shift
= reg_offset_shift
;
1585 return devm_regmap_init(dev
, NULL
, ctx
, config
);
1588 static int cdns_regfield_init(struct cdns_torrent_phy
*cdns_phy
)
1590 struct device
*dev
= cdns_phy
->dev
;
1591 struct regmap_field
*field
;
1592 struct regmap
*regmap
;
1594 regmap
= cdns_phy
->regmap_phy_pcs_common_cdb
;
1595 field
= devm_regmap_field_alloc(dev
, regmap
, phy_pll_cfg
);
1596 if (IS_ERR(field
)) {
1597 dev_err(dev
, "PHY_PLL_CFG reg field init failed\n");
1598 return PTR_ERR(field
);
1600 cdns_phy
->phy_pll_cfg
= field
;
1602 regmap
= cdns_phy
->regmap_phy_pma_common_cdb
;
1603 field
= devm_regmap_field_alloc(dev
, regmap
, phy_pma_cmn_ctrl_2
);
1604 if (IS_ERR(field
)) {
1605 dev_err(dev
, "PHY_PMA_CMN_CTRL2 reg field init failed\n");
1606 return PTR_ERR(field
);
1608 cdns_phy
->phy_pma_cmn_ctrl_2
= field
;
1610 regmap
= cdns_phy
->regmap_phy_pma_common_cdb
;
1611 field
= devm_regmap_field_alloc(dev
, regmap
, phy_pma_pll_raw_ctrl
);
1612 if (IS_ERR(field
)) {
1613 dev_err(dev
, "PHY_PMA_PLL_RAW_CTRL reg field init failed\n");
1614 return PTR_ERR(field
);
1616 cdns_phy
->phy_pma_pll_raw_ctrl
= field
;
1618 regmap
= cdns_phy
->regmap_dptx_phy_reg
;
1619 field
= devm_regmap_field_alloc(dev
, regmap
, phy_reset_ctrl
);
1620 if (IS_ERR(field
)) {
1621 dev_err(dev
, "PHY_RESET reg field init failed\n");
1622 return PTR_ERR(field
);
1624 cdns_phy
->phy_reset_ctrl
= field
;
1629 static int cdns_regmap_init_torrent_dp(struct cdns_torrent_phy
*cdns_phy
,
1630 void __iomem
*sd_base
,
1632 u8 block_offset_shift
,
1633 u8 reg_offset_shift
)
1635 struct device
*dev
= cdns_phy
->dev
;
1636 struct regmap
*regmap
;
1640 for (i
= 0; i
< MAX_NUM_LANES
; i
++) {
1641 block_offset
= TORRENT_TX_LANE_CDB_OFFSET(i
, block_offset_shift
,
1643 regmap
= cdns_regmap_init(dev
, sd_base
, block_offset
,
1645 &cdns_torrent_tx_lane_cdb_config
[i
]);
1646 if (IS_ERR(regmap
)) {
1647 dev_err(dev
, "Failed to init tx lane CDB regmap\n");
1648 return PTR_ERR(regmap
);
1650 cdns_phy
->regmap_tx_lane_cdb
[i
] = regmap
;
1652 block_offset
= TORRENT_RX_LANE_CDB_OFFSET(i
, block_offset_shift
,
1654 regmap
= cdns_regmap_init(dev
, sd_base
, block_offset
,
1656 &cdns_torrent_rx_lane_cdb_config
[i
]);
1657 if (IS_ERR(regmap
)) {
1658 dev_err(dev
, "Failed to init rx lane CDB regmap\n");
1659 return PTR_ERR(regmap
);
1661 cdns_phy
->regmap_rx_lane_cdb
[i
] = regmap
;
1664 block_offset
= TORRENT_COMMON_CDB_OFFSET
;
1665 regmap
= cdns_regmap_init(dev
, sd_base
, block_offset
,
1667 &cdns_torrent_common_cdb_config
);
1668 if (IS_ERR(regmap
)) {
1669 dev_err(dev
, "Failed to init common CDB regmap\n");
1670 return PTR_ERR(regmap
);
1672 cdns_phy
->regmap_common_cdb
= regmap
;
1674 block_offset
= TORRENT_PHY_PCS_COMMON_OFFSET(block_offset_shift
);
1675 regmap
= cdns_regmap_init(dev
, sd_base
, block_offset
,
1677 &cdns_torrent_phy_pcs_cmn_cdb_config
);
1678 if (IS_ERR(regmap
)) {
1679 dev_err(dev
, "Failed to init PHY PCS common CDB regmap\n");
1680 return PTR_ERR(regmap
);
1682 cdns_phy
->regmap_phy_pcs_common_cdb
= regmap
;
1684 block_offset
= TORRENT_PHY_PMA_COMMON_OFFSET(block_offset_shift
);
1685 regmap
= cdns_regmap_init(dev
, sd_base
, block_offset
,
1687 &cdns_torrent_phy_pma_cmn_cdb_config
);
1688 if (IS_ERR(regmap
)) {
1689 dev_err(dev
, "Failed to init PHY PMA common CDB regmap\n");
1690 return PTR_ERR(regmap
);
1692 cdns_phy
->regmap_phy_pma_common_cdb
= regmap
;
1694 block_offset
= TORRENT_DPTX_PHY_OFFSET
;
1695 regmap
= cdns_regmap_init(dev
, base
, block_offset
,
1697 &cdns_torrent_dptx_phy_config
);
1698 if (IS_ERR(regmap
)) {
1699 dev_err(dev
, "Failed to init DPTX PHY regmap\n");
1700 return PTR_ERR(regmap
);
1702 cdns_phy
->regmap_dptx_phy_reg
= regmap
;
1707 static int cdns_torrent_phy_probe(struct platform_device
*pdev
)
1709 struct resource
*regs
;
1710 struct cdns_torrent_phy
*cdns_phy
;
1711 struct device
*dev
= &pdev
->dev
;
1712 struct phy_provider
*phy_provider
;
1713 const struct of_device_id
*match
;
1714 struct cdns_torrent_data
*data
;
1715 struct device_node
*child
;
1716 int ret
, subnodes
, node
= 0, i
;
1718 /* Get init data for this PHY */
1719 match
= of_match_device(cdns_torrent_phy_of_match
, dev
);
1723 data
= (struct cdns_torrent_data
*)match
->data
;
1725 cdns_phy
= devm_kzalloc(dev
, sizeof(*cdns_phy
), GFP_KERNEL
);
1729 dev_set_drvdata(dev
, cdns_phy
);
1730 cdns_phy
->dev
= dev
;
1732 cdns_phy
->phy_rst
= devm_reset_control_get_exclusive_by_index(dev
, 0);
1733 if (IS_ERR(cdns_phy
->phy_rst
)) {
1734 dev_err(dev
, "%s: failed to get reset\n",
1735 dev
->of_node
->full_name
);
1736 return PTR_ERR(cdns_phy
->phy_rst
);
1739 cdns_phy
->clk
= devm_clk_get(dev
, "refclk");
1740 if (IS_ERR(cdns_phy
->clk
)) {
1741 dev_err(dev
, "phy ref clock not found\n");
1742 return PTR_ERR(cdns_phy
->clk
);
1745 regs
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
1746 cdns_phy
->sd_base
= devm_ioremap_resource(&pdev
->dev
, regs
);
1747 if (IS_ERR(cdns_phy
->sd_base
))
1748 return PTR_ERR(cdns_phy
->sd_base
);
1750 subnodes
= of_get_available_child_count(dev
->of_node
);
1751 if (subnodes
== 0) {
1752 dev_err(dev
, "No available link subnodes found\n");
1754 } else if (subnodes
!= 1) {
1755 dev_err(dev
, "Driver supports only one link subnode.\n");
1759 for_each_available_child_of_node(dev
->of_node
, child
) {
1762 cdns_phy
->phys
[node
].lnk_rst
=
1763 of_reset_control_array_get_exclusive(child
);
1764 if (IS_ERR(cdns_phy
->phys
[node
].lnk_rst
)) {
1765 dev_err(dev
, "%s: failed to get reset\n",
1767 ret
= PTR_ERR(cdns_phy
->phys
[node
].lnk_rst
);
1771 if (of_property_read_u32(child
, "reg",
1772 &cdns_phy
->phys
[node
].mlane
)) {
1773 dev_err(dev
, "%s: No \"reg\"-property.\n",
1779 if (cdns_phy
->phys
[node
].mlane
!= 0) {
1781 "%s: Driver supports only lane-0 as master lane.\n",
1787 if (of_property_read_u32(child
, "cdns,phy-type",
1788 &cdns_phy
->phys
[node
].phy_type
)) {
1789 dev_err(dev
, "%s: No \"cdns,phy-type\"-property.\n",
1795 cdns_phy
->phys
[node
].num_lanes
= DEFAULT_NUM_LANES
;
1796 of_property_read_u32(child
, "cdns,num-lanes",
1797 &cdns_phy
->phys
[node
].num_lanes
);
1799 if (cdns_phy
->phys
[node
].phy_type
== PHY_TYPE_DP
) {
1800 switch (cdns_phy
->phys
[node
].num_lanes
) {
1804 /* valid number of lanes */
1807 dev_err(dev
, "unsupported number of lanes: %d\n",
1808 cdns_phy
->phys
[node
].num_lanes
);
1813 cdns_phy
->max_bit_rate
= DEFAULT_MAX_BIT_RATE
;
1814 of_property_read_u32(child
, "cdns,max-bit-rate",
1815 &cdns_phy
->max_bit_rate
);
1817 switch (cdns_phy
->max_bit_rate
) {
1826 /* valid bit rate */
1829 dev_err(dev
, "unsupported max bit rate: %dMbps\n",
1830 cdns_phy
->max_bit_rate
);
1835 /* DPTX registers */
1836 regs
= platform_get_resource(pdev
, IORESOURCE_MEM
, 1);
1837 cdns_phy
->base
= devm_ioremap_resource(&pdev
->dev
,
1839 if (IS_ERR(cdns_phy
->base
)) {
1840 ret
= PTR_ERR(cdns_phy
->base
);
1844 gphy
= devm_phy_create(dev
, child
,
1845 &cdns_torrent_phy_ops
);
1847 ret
= PTR_ERR(gphy
);
1851 dev_info(dev
, "%d lanes, max bit rate %d.%03d Gbps\n",
1852 cdns_phy
->phys
[node
].num_lanes
,
1853 cdns_phy
->max_bit_rate
/ 1000,
1854 cdns_phy
->max_bit_rate
% 1000);
1856 dev_err(dev
, "Driver supports only PHY_TYPE_DP\n");
1860 cdns_phy
->phys
[node
].phy
= gphy
;
1861 phy_set_drvdata(gphy
, &cdns_phy
->phys
[node
]);
1865 cdns_phy
->nsubnodes
= node
;
1867 ret
= cdns_regmap_init_torrent_dp(cdns_phy
, cdns_phy
->sd_base
,
1869 data
->block_offset_shift
,
1870 data
->reg_offset_shift
);
1874 ret
= cdns_regfield_init(cdns_phy
);
1878 phy_provider
= devm_of_phy_provider_register(dev
, of_phy_simple_xlate
);
1879 if (IS_ERR(phy_provider
)) {
1880 ret
= PTR_ERR(phy_provider
);
1889 for (i
= 0; i
< node
; i
++)
1890 reset_control_put(cdns_phy
->phys
[i
].lnk_rst
);
1895 static int cdns_torrent_phy_remove(struct platform_device
*pdev
)
1897 struct cdns_torrent_phy
*cdns_phy
= platform_get_drvdata(pdev
);
1900 reset_control_assert(cdns_phy
->phy_rst
);
1901 for (i
= 0; i
< cdns_phy
->nsubnodes
; i
++) {
1902 reset_control_assert(cdns_phy
->phys
[i
].lnk_rst
);
1903 reset_control_put(cdns_phy
->phys
[i
].lnk_rst
);
1909 static const struct cdns_torrent_data cdns_map_torrent
= {
1910 .block_offset_shift
= 0x2,
1911 .reg_offset_shift
= 0x2,
1914 static const struct cdns_torrent_data ti_j721e_map_torrent
= {
1915 .block_offset_shift
= 0x0,
1916 .reg_offset_shift
= 0x1,
1919 static const struct of_device_id cdns_torrent_phy_of_match
[] = {
1921 .compatible
= "cdns,torrent-phy",
1922 .data
= &cdns_map_torrent
,
1925 .compatible
= "ti,j721e-serdes-10g",
1926 .data
= &ti_j721e_map_torrent
,
1930 MODULE_DEVICE_TABLE(of
, cdns_torrent_phy_of_match
);
1932 static struct platform_driver cdns_torrent_phy_driver
= {
1933 .probe
= cdns_torrent_phy_probe
,
1934 .remove
= cdns_torrent_phy_remove
,
1936 .name
= "cdns-torrent-phy",
1937 .of_match_table
= cdns_torrent_phy_of_match
,
1940 module_platform_driver(cdns_torrent_phy_driver
);
1942 MODULE_AUTHOR("Cadence Design Systems, Inc.");
1943 MODULE_DESCRIPTION("Cadence Torrent PHY driver");
1944 MODULE_LICENSE("GPL v2");