blob: 54d316d4ec410e087eb68127d80d7550eed20363 [file] [log] [blame]
Alan Douglas39b82332021-07-21 21:28:36 +05301// SPDX-License-Identifier: GPL-2.0
2/*
3 * Cadence Sierra PHY Driver
4 *
5 * Based on the linux driver provided by Cadence
6 *
7 * Copyright (c) 2018 Cadence Design Systems
8 * Author: Alan Douglas <adouglas@cadence.com>
9 *
10 * Copyright (C) 2019 Texas Instruments Incorporated - http://www.ti.com/
11 * Jean-Jacques Hiblot <jjhiblot@ti.com>
12 *
13 */
14#include <common.h>
15#include <clk.h>
Aswath Govindrajudd759272022-01-28 13:41:36 +053016#include <linux/clk-provider.h>
Alan Douglas39b82332021-07-21 21:28:36 +053017#include <generic-phy.h>
18#include <reset.h>
19#include <dm/device.h>
20#include <dm/device-internal.h>
21#include <dm/device_compat.h>
22#include <dm/lists.h>
23#include <dm/read.h>
24#include <dm/uclass.h>
25#include <dm/devres.h>
26#include <linux/io.h>
27#include <dt-bindings/phy/phy.h>
Aswath Govindrajudd759272022-01-28 13:41:36 +053028#include <dt-bindings/phy/phy-cadence.h>
Alan Douglas39b82332021-07-21 21:28:36 +053029#include <regmap.h>
30
Swapnil Jakhade14ed6702022-01-28 13:41:40 +053031#define NUM_SSC_MODE 3
32#define NUM_PHY_TYPE 3
33
Alan Douglas39b82332021-07-21 21:28:36 +053034/* PHY register offsets */
35#define SIERRA_COMMON_CDB_OFFSET 0x0
36#define SIERRA_MACRO_ID_REG 0x0
Aswath Govindrajudd759272022-01-28 13:41:36 +053037#define SIERRA_CMN_PLLLC_GEN_PREG 0x42
Alan Douglas39b82332021-07-21 21:28:36 +053038#define SIERRA_CMN_PLLLC_MODE_PREG 0x48
39#define SIERRA_CMN_PLLLC_LF_COEFF_MODE1_PREG 0x49
40#define SIERRA_CMN_PLLLC_LF_COEFF_MODE0_PREG 0x4A
41#define SIERRA_CMN_PLLLC_LOCK_CNTSTART_PREG 0x4B
42#define SIERRA_CMN_PLLLC_BWCAL_MODE1_PREG 0x4F
43#define SIERRA_CMN_PLLLC_BWCAL_MODE0_PREG 0x50
Swapnil Jakhade960efc52022-01-28 13:41:47 +053044#define SIERRA_CMN_PLLLC_DSMCORR_PREG 0x51
45#define SIERRA_CMN_PLLLC_SS_PREG 0x52
46#define SIERRA_CMN_PLLLC_SS_AMP_STEP_SIZE_PREG 0x53
47#define SIERRA_CMN_PLLLC_SSTWOPT_PREG 0x54
Alan Douglas39b82332021-07-21 21:28:36 +053048#define SIERRA_CMN_PLLLC_SS_TIME_STEPSIZE_MODE_PREG 0x62
Aswath Govindrajudd759272022-01-28 13:41:36 +053049#define SIERRA_CMN_REFRCV_PREG 0x98
50#define SIERRA_CMN_REFRCV1_PREG 0xB8
51#define SIERRA_CMN_PLLLC1_GEN_PREG 0xC2
Swapnil Jakhade960efc52022-01-28 13:41:47 +053052#define SIERRA_CMN_PLLLC_LOCK_DELAY_CTRL_PREG 0x63
Alan Douglas39b82332021-07-21 21:28:36 +053053
54#define SIERRA_LANE_CDB_OFFSET(ln, offset) \
55 (0x4000 + ((ln) * (0x800 >> (2 - (offset)))))
56
57#define SIERRA_DET_STANDEC_A_PREG 0x000
58#define SIERRA_DET_STANDEC_B_PREG 0x001
59#define SIERRA_DET_STANDEC_C_PREG 0x002
60#define SIERRA_DET_STANDEC_D_PREG 0x003
61#define SIERRA_DET_STANDEC_E_PREG 0x004
62#define SIERRA_PSM_LANECAL_DLY_A1_RESETS_PREG 0x008
63#define SIERRA_PSM_A0IN_TMR_PREG 0x009
Swapnil Jakhade960efc52022-01-28 13:41:47 +053064#define SIERRA_PSM_A3IN_TMR_PREG 0x00C
Alan Douglas39b82332021-07-21 21:28:36 +053065#define SIERRA_PSM_DIAG_PREG 0x015
66#define SIERRA_PSC_TX_A0_PREG 0x028
67#define SIERRA_PSC_TX_A1_PREG 0x029
68#define SIERRA_PSC_TX_A2_PREG 0x02A
69#define SIERRA_PSC_TX_A3_PREG 0x02B
70#define SIERRA_PSC_RX_A0_PREG 0x030
71#define SIERRA_PSC_RX_A1_PREG 0x031
72#define SIERRA_PSC_RX_A2_PREG 0x032
73#define SIERRA_PSC_RX_A3_PREG 0x033
74#define SIERRA_PLLCTRL_SUBRATE_PREG 0x03A
75#define SIERRA_PLLCTRL_GEN_D_PREG 0x03E
76#define SIERRA_PLLCTRL_CPGAIN_MODE_PREG 0x03F
77#define SIERRA_PLLCTRL_STATUS_PREG 0x044
78#define SIERRA_CLKPATH_BIASTRIM_PREG 0x04B
79#define SIERRA_DFE_BIASTRIM_PREG 0x04C
80#define SIERRA_DRVCTRL_ATTEN_PREG 0x06A
Swapnil Jakhade960efc52022-01-28 13:41:47 +053081#define SIERRA_DRVCTRL_BOOST_PREG 0x06F
Alan Douglas39b82332021-07-21 21:28:36 +053082#define SIERRA_CLKPATHCTRL_TMR_PREG 0x081
83#define SIERRA_RX_CREQ_FLTR_A_MODE3_PREG 0x085
84#define SIERRA_RX_CREQ_FLTR_A_MODE2_PREG 0x086
85#define SIERRA_RX_CREQ_FLTR_A_MODE1_PREG 0x087
86#define SIERRA_RX_CREQ_FLTR_A_MODE0_PREG 0x088
Swapnil Jakhade960efc52022-01-28 13:41:47 +053087#define SIERRA_CREQ_DCBIASATTEN_OVR_PREG 0x08C
Alan Douglas39b82332021-07-21 21:28:36 +053088#define SIERRA_CREQ_CCLKDET_MODE01_PREG 0x08E
Swapnil Jakhade960efc52022-01-28 13:41:47 +053089#define SIERRA_RX_CTLE_CAL_PREG 0x08F
Alan Douglas39b82332021-07-21 21:28:36 +053090#define SIERRA_RX_CTLE_MAINTENANCE_PREG 0x091
91#define SIERRA_CREQ_FSMCLK_SEL_PREG 0x092
92#define SIERRA_CREQ_EQ_CTRL_PREG 0x093
93#define SIERRA_CREQ_SPARE_PREG 0x096
94#define SIERRA_CREQ_EQ_OPEN_EYE_THRESH_PREG 0x097
95#define SIERRA_CTLELUT_CTRL_PREG 0x098
96#define SIERRA_DFE_ECMP_RATESEL_PREG 0x0C0
97#define SIERRA_DFE_SMP_RATESEL_PREG 0x0C1
98#define SIERRA_DEQ_PHALIGN_CTRL 0x0C4
99#define SIERRA_DEQ_CONCUR_CTRL1_PREG 0x0C8
100#define SIERRA_DEQ_CONCUR_CTRL2_PREG 0x0C9
101#define SIERRA_DEQ_EPIPWR_CTRL2_PREG 0x0CD
102#define SIERRA_DEQ_FAST_MAINT_CYCLES_PREG 0x0CE
103#define SIERRA_DEQ_ERRCMP_CTRL_PREG 0x0D0
104#define SIERRA_DEQ_OFFSET_CTRL_PREG 0x0D8
105#define SIERRA_DEQ_GAIN_CTRL_PREG 0x0E0
106#define SIERRA_DEQ_VGATUNE_CTRL_PREG 0x0E1
107#define SIERRA_DEQ_GLUT0 0x0E8
108#define SIERRA_DEQ_GLUT1 0x0E9
109#define SIERRA_DEQ_GLUT2 0x0EA
110#define SIERRA_DEQ_GLUT3 0x0EB
111#define SIERRA_DEQ_GLUT4 0x0EC
112#define SIERRA_DEQ_GLUT5 0x0ED
113#define SIERRA_DEQ_GLUT6 0x0EE
114#define SIERRA_DEQ_GLUT7 0x0EF
115#define SIERRA_DEQ_GLUT8 0x0F0
116#define SIERRA_DEQ_GLUT9 0x0F1
117#define SIERRA_DEQ_GLUT10 0x0F2
118#define SIERRA_DEQ_GLUT11 0x0F3
119#define SIERRA_DEQ_GLUT12 0x0F4
120#define SIERRA_DEQ_GLUT13 0x0F5
121#define SIERRA_DEQ_GLUT14 0x0F6
122#define SIERRA_DEQ_GLUT15 0x0F7
123#define SIERRA_DEQ_GLUT16 0x0F8
124#define SIERRA_DEQ_ALUT0 0x108
125#define SIERRA_DEQ_ALUT1 0x109
126#define SIERRA_DEQ_ALUT2 0x10A
127#define SIERRA_DEQ_ALUT3 0x10B
128#define SIERRA_DEQ_ALUT4 0x10C
129#define SIERRA_DEQ_ALUT5 0x10D
130#define SIERRA_DEQ_ALUT6 0x10E
131#define SIERRA_DEQ_ALUT7 0x10F
132#define SIERRA_DEQ_ALUT8 0x110
133#define SIERRA_DEQ_ALUT9 0x111
134#define SIERRA_DEQ_ALUT10 0x112
135#define SIERRA_DEQ_ALUT11 0x113
136#define SIERRA_DEQ_ALUT12 0x114
137#define SIERRA_DEQ_ALUT13 0x115
138#define SIERRA_DEQ_DFETAP_CTRL_PREG 0x128
Swapnil Jakhade960efc52022-01-28 13:41:47 +0530139#define SIERRA_DEQ_DFETAP0 0x129
140#define SIERRA_DEQ_DFETAP1 0x12B
141#define SIERRA_DEQ_DFETAP2 0x12D
142#define SIERRA_DEQ_DFETAP3 0x12F
143#define SIERRA_DEQ_DFETAP4 0x131
Alan Douglas39b82332021-07-21 21:28:36 +0530144#define SIERRA_DFE_EN_1010_IGNORE_PREG 0x134
Swapnil Jakhade960efc52022-01-28 13:41:47 +0530145#define SIERRA_DEQ_PRECUR_PREG 0x138
146#define SIERRA_DEQ_POSTCUR_PREG 0x140
147#define SIERRA_DEQ_POSTCUR_DECR_PREG 0x142
Alan Douglas39b82332021-07-21 21:28:36 +0530148#define SIERRA_DEQ_TAU_CTRL1_SLOW_MAINT_PREG 0x150
149#define SIERRA_DEQ_TAU_CTRL2_PREG 0x151
Swapnil Jakhade960efc52022-01-28 13:41:47 +0530150#define SIERRA_DEQ_TAU_CTRL3_PREG 0x152
151#define SIERRA_DEQ_OPENEYE_CTRL_PREG 0x158
Alan Douglas39b82332021-07-21 21:28:36 +0530152#define SIERRA_DEQ_PICTRL_PREG 0x161
153#define SIERRA_CPICAL_TMRVAL_MODE1_PREG 0x170
154#define SIERRA_CPICAL_TMRVAL_MODE0_PREG 0x171
155#define SIERRA_CPICAL_PICNT_MODE1_PREG 0x174
156#define SIERRA_CPI_OUTBUF_RATESEL_PREG 0x17C
Swapnil Jakhade960efc52022-01-28 13:41:47 +0530157#define SIERRA_CPI_TRIM_PREG 0x17F
Alan Douglas39b82332021-07-21 21:28:36 +0530158#define SIERRA_CPICAL_RES_STARTCODE_MODE23_PREG 0x183
Swapnil Jakhade960efc52022-01-28 13:41:47 +0530159#define SIERRA_EPI_CTRL_PREG 0x187
Alan Douglas39b82332021-07-21 21:28:36 +0530160#define SIERRA_LFPSDET_SUPPORT_PREG 0x188
161#define SIERRA_LFPSFILT_NS_PREG 0x18A
162#define SIERRA_LFPSFILT_RD_PREG 0x18B
163#define SIERRA_LFPSFILT_MP_PREG 0x18C
164#define SIERRA_SIGDET_SUPPORT_PREG 0x190
165#define SIERRA_SDFILT_H2L_A_PREG 0x191
166#define SIERRA_SDFILT_L2H_PREG 0x193
167#define SIERRA_RXBUFFER_CTLECTRL_PREG 0x19E
168#define SIERRA_RXBUFFER_RCDFECTRL_PREG 0x19F
169#define SIERRA_RXBUFFER_DFECTRL_PREG 0x1A0
170#define SIERRA_DEQ_TAU_CTRL1_FAST_MAINT_PREG 0x14F
171#define SIERRA_DEQ_TAU_CTRL1_SLOW_MAINT_PREG 0x150
172
Swapnil Jakhade445c8cf2022-01-28 13:41:43 +0530173#define SIERRA_PHY_PCS_COMMON_OFFSET 0xc000
Swapnil Jakhade990ce532022-01-28 13:41:44 +0530174#define SIERRA_PHY_PIPE_CMN_CTRL1 0x0
Alan Douglas39b82332021-07-21 21:28:36 +0530175#define SIERRA_PHY_PLL_CFG 0xe
176
Swapnil Jakhade48f29872022-01-28 13:41:45 +0530177/* PHY PMA common registers */
178#define SIERRA_PHY_PMA_COMMON_OFFSET 0xe000
179#define SIERRA_PHY_PMA_CMN_CTRL 0x0
180
Swapnil Jakhadef0cb8092022-01-28 13:41:46 +0530181/* PHY PCS lane registers */
182#define SIERRA_PHY_PCS_LANE_CDB_OFFSET(ln, offset) \
183 (0xD000 + ((ln) * (0x800 >> (3 - (offset)))))
184#define SIERRA_PHY_ISO_LINK_CTRL 0xB
185
Alan Douglas39b82332021-07-21 21:28:36 +0530186#define SIERRA_MACRO_ID 0x00007364
187#define SIERRA_MAX_LANES 16
188#define PLL_LOCK_TIME 100
189
Aswath Govindrajudd759272022-01-28 13:41:36 +0530190#define CDNS_SIERRA_INPUT_CLOCKS 5
Kishon Vijay Abraham I82574372022-01-28 13:41:33 +0530191enum cdns_sierra_clock_input {
192 PHY_CLK,
193 CMN_REFCLK_DIG_DIV,
194 CMN_REFCLK1_DIG_DIV,
Aswath Govindrajudd759272022-01-28 13:41:36 +0530195 PLL0_REFCLK,
196 PLL1_REFCLK,
Kishon Vijay Abraham I82574372022-01-28 13:41:33 +0530197};
198
Aswath Govindrajudd759272022-01-28 13:41:36 +0530199#define SIERRA_NUM_CMN_PLLC 2
200#define SIERRA_NUM_CMN_PLLC_PARENTS 2
201
Alan Douglas39b82332021-07-21 21:28:36 +0530202static const struct reg_field macro_id_type =
203 REG_FIELD(SIERRA_MACRO_ID_REG, 0, 15);
204static const struct reg_field phy_pll_cfg_1 =
205 REG_FIELD(SIERRA_PHY_PLL_CFG, 1, 1);
Swapnil Jakhade48f29872022-01-28 13:41:45 +0530206static const struct reg_field pma_cmn_ready =
207 REG_FIELD(SIERRA_PHY_PMA_CMN_CTRL, 0, 0);
Alan Douglas39b82332021-07-21 21:28:36 +0530208static const struct reg_field pllctrl_lock =
209 REG_FIELD(SIERRA_PLLCTRL_STATUS_PREG, 0, 0);
Swapnil Jakhadef0cb8092022-01-28 13:41:46 +0530210static const struct reg_field phy_iso_link_ctrl_1 =
211 REG_FIELD(SIERRA_PHY_ISO_LINK_CTRL, 1, 1);
Alan Douglas39b82332021-07-21 21:28:36 +0530212
Aswath Govindrajudd759272022-01-28 13:41:36 +0530213static const char * const clk_names[] = {
214 [CDNS_SIERRA_PLL_CMNLC] = "pll_cmnlc",
215 [CDNS_SIERRA_PLL_CMNLC1] = "pll_cmnlc1",
216};
217
218enum cdns_sierra_cmn_plllc {
219 CMN_PLLLC,
220 CMN_PLLLC1,
221};
222
223struct cdns_sierra_pll_mux_reg_fields {
224 struct reg_field pfdclk_sel_preg;
225 struct reg_field plllc1en_field;
226 struct reg_field termen_field;
227};
228
229static const struct cdns_sierra_pll_mux_reg_fields cmn_plllc_pfdclk1_sel_preg[] = {
230 [CMN_PLLLC] = {
231 .pfdclk_sel_preg = REG_FIELD(SIERRA_CMN_PLLLC_GEN_PREG, 1, 1),
232 .plllc1en_field = REG_FIELD(SIERRA_CMN_REFRCV1_PREG, 8, 8),
233 .termen_field = REG_FIELD(SIERRA_CMN_REFRCV1_PREG, 0, 0),
234 },
235 [CMN_PLLLC1] = {
236 .pfdclk_sel_preg = REG_FIELD(SIERRA_CMN_PLLLC1_GEN_PREG, 1, 1),
237 .plllc1en_field = REG_FIELD(SIERRA_CMN_REFRCV_PREG, 8, 8),
238 .termen_field = REG_FIELD(SIERRA_CMN_REFRCV_PREG, 0, 0),
239 },
240};
241
242struct cdns_sierra_pll_mux {
243 struct cdns_sierra_phy *sp;
244 struct clk *clk;
245 struct clk *parent_clks[2];
246 struct regmap_field *pfdclk_sel_preg;
247 struct regmap_field *plllc1en_field;
248 struct regmap_field *termen_field;
249};
250
Alan Douglas39b82332021-07-21 21:28:36 +0530251#define reset_control_assert(rst) cdns_reset_assert(rst)
252#define reset_control_deassert(rst) cdns_reset_deassert(rst)
253#define reset_control reset_ctl
254
Swapnil Jakhade14ed6702022-01-28 13:41:40 +0530255enum cdns_sierra_phy_type {
256 TYPE_NONE,
257 TYPE_PCIE,
258 TYPE_USB
259};
260
261enum cdns_sierra_ssc_mode {
262 NO_SSC,
263 EXTERNAL_SSC,
264 INTERNAL_SSC
265};
266
Alan Douglas39b82332021-07-21 21:28:36 +0530267struct cdns_sierra_inst {
Swapnil Jakhade14ed6702022-01-28 13:41:40 +0530268 enum cdns_sierra_phy_type phy_type;
Alan Douglas39b82332021-07-21 21:28:36 +0530269 u32 num_lanes;
270 u32 mlane;
271 struct reset_ctl_bulk *lnk_rst;
Swapnil Jakhadeb6541d42022-01-28 13:41:42 +0530272 enum cdns_sierra_ssc_mode ssc_mode;
Alan Douglas39b82332021-07-21 21:28:36 +0530273};
274
275struct cdns_reg_pairs {
276 u16 val;
277 u32 off;
278};
279
Swapnil Jakhade14ed6702022-01-28 13:41:40 +0530280struct cdns_sierra_vals {
281 const struct cdns_reg_pairs *reg_pairs;
282 u32 num_regs;
283};
284
Alan Douglas39b82332021-07-21 21:28:36 +0530285struct cdns_sierra_data {
286 u32 id_value;
287 u8 block_offset_shift;
288 u8 reg_offset_shift;
Swapnil Jakhade990ce532022-01-28 13:41:44 +0530289 struct cdns_sierra_vals *pcs_cmn_vals[NUM_PHY_TYPE][NUM_PHY_TYPE]
290 [NUM_SSC_MODE];
Swapnil Jakhade14ed6702022-01-28 13:41:40 +0530291 struct cdns_sierra_vals *pma_cmn_vals[NUM_PHY_TYPE][NUM_PHY_TYPE]
292 [NUM_SSC_MODE];
293 struct cdns_sierra_vals *pma_ln_vals[NUM_PHY_TYPE][NUM_PHY_TYPE]
294 [NUM_SSC_MODE];
Alan Douglas39b82332021-07-21 21:28:36 +0530295};
296
Alan Douglas39b82332021-07-21 21:28:36 +0530297struct cdns_sierra_phy {
298 struct udevice *dev;
299 void *base;
300 size_t size;
301 struct regmap *regmap;
302 struct cdns_sierra_data *init_data;
Aswath Govindraju6f46c742022-01-28 13:41:35 +0530303 struct cdns_sierra_inst *phys[SIERRA_MAX_LANES];
Alan Douglas39b82332021-07-21 21:28:36 +0530304 struct reset_control *phy_rst;
305 struct regmap *regmap_lane_cdb[SIERRA_MAX_LANES];
Swapnil Jakhade445c8cf2022-01-28 13:41:43 +0530306 struct regmap *regmap_phy_pcs_common_cdb;
Swapnil Jakhadef0cb8092022-01-28 13:41:46 +0530307 struct regmap *regmap_phy_pcs_lane_cdb[SIERRA_MAX_LANES];
Swapnil Jakhade48f29872022-01-28 13:41:45 +0530308 struct regmap *regmap_phy_pma_common_cdb;
Alan Douglas39b82332021-07-21 21:28:36 +0530309 struct regmap *regmap_common_cdb;
310 struct regmap_field *macro_id_type;
311 struct regmap_field *phy_pll_cfg_1;
Swapnil Jakhade48f29872022-01-28 13:41:45 +0530312 struct regmap_field *pma_cmn_ready;
Alan Douglas39b82332021-07-21 21:28:36 +0530313 struct regmap_field *pllctrl_lock[SIERRA_MAX_LANES];
Aswath Govindrajudd759272022-01-28 13:41:36 +0530314 struct regmap_field *cmn_refrcv_refclk_plllc1en_preg[SIERRA_NUM_CMN_PLLC];
315 struct regmap_field *cmn_refrcv_refclk_termen_preg[SIERRA_NUM_CMN_PLLC];
316 struct regmap_field *cmn_plllc_pfdclk1_sel_preg[SIERRA_NUM_CMN_PLLC];
Kishon Vijay Abraham I82574372022-01-28 13:41:33 +0530317 struct clk *input_clks[CDNS_SIERRA_INPUT_CLOCKS];
Swapnil Jakhadef0cb8092022-01-28 13:41:46 +0530318 struct regmap_field *phy_iso_link_ctrl_1[SIERRA_MAX_LANES];
Alan Douglas39b82332021-07-21 21:28:36 +0530319 int nsubnodes;
320 u32 num_lanes;
321 bool autoconf;
322};
323
324static inline int cdns_reset_assert(struct reset_control *rst)
325{
326 if (rst)
327 return reset_assert(rst);
328 else
329 return 0;
330}
331
332static inline int cdns_reset_deassert(struct reset_control *rst)
333{
334 if (rst)
335 return reset_deassert(rst);
336 else
337 return 0;
338}
339
340static inline struct cdns_sierra_inst *phy_get_drvdata(struct phy *phy)
341{
342 struct cdns_sierra_phy *sp = dev_get_priv(phy->dev);
343 int index;
344
345 if (phy->id >= SIERRA_MAX_LANES)
346 return NULL;
347
348 for (index = 0; index < sp->nsubnodes; index++) {
Aswath Govindraju6f46c742022-01-28 13:41:35 +0530349 if (phy->id == sp->phys[index]->mlane)
350 return sp->phys[index];
Alan Douglas39b82332021-07-21 21:28:36 +0530351 }
352
353 return NULL;
354}
355
356static int cdns_sierra_phy_init(struct phy *gphy)
357{
358 struct cdns_sierra_inst *ins = phy_get_drvdata(gphy);
359 struct cdns_sierra_phy *phy = dev_get_priv(gphy->dev);
Swapnil Jakhade14ed6702022-01-28 13:41:40 +0530360 struct cdns_sierra_data *init_data = phy->init_data;
361 struct cdns_sierra_vals *pma_cmn_vals, *pma_ln_vals;
362 enum cdns_sierra_phy_type phy_type = ins->phy_type;
Swapnil Jakhadeb6541d42022-01-28 13:41:42 +0530363 enum cdns_sierra_ssc_mode ssc = ins->ssc_mode;
Swapnil Jakhade14ed6702022-01-28 13:41:40 +0530364 const struct cdns_reg_pairs *reg_pairs;
Swapnil Jakhade990ce532022-01-28 13:41:44 +0530365 struct cdns_sierra_vals *pcs_cmn_vals;
Alan Douglas39b82332021-07-21 21:28:36 +0530366 struct regmap *regmap = phy->regmap;
Swapnil Jakhade14ed6702022-01-28 13:41:40 +0530367 u32 num_regs;
Alan Douglas39b82332021-07-21 21:28:36 +0530368 int i, j;
Alan Douglas39b82332021-07-21 21:28:36 +0530369
370 /* Initialise the PHY registers, unless auto configured */
371 if (phy->autoconf)
372 return 0;
373
Kishon Vijay Abraham I82574372022-01-28 13:41:33 +0530374 clk_set_rate(phy->input_clks[CMN_REFCLK_DIG_DIV], 25000000);
375 clk_set_rate(phy->input_clks[CMN_REFCLK1_DIG_DIV], 25000000);
Alan Douglas39b82332021-07-21 21:28:36 +0530376
Swapnil Jakhade990ce532022-01-28 13:41:44 +0530377 /* PHY PCS common registers configurations */
378 pcs_cmn_vals = init_data->pcs_cmn_vals[phy_type][TYPE_NONE][ssc];
379 if (pcs_cmn_vals) {
380 reg_pairs = pcs_cmn_vals->reg_pairs;
381 num_regs = pcs_cmn_vals->num_regs;
382 regmap = phy->regmap_phy_pcs_common_cdb;
383 for (i = 0; i < num_regs; i++)
384 regmap_write(regmap, reg_pairs[i].off, reg_pairs[i].val);
385 }
386
Swapnil Jakhade14ed6702022-01-28 13:41:40 +0530387 /* PMA common registers configurations */
388 pma_cmn_vals = init_data->pma_cmn_vals[phy_type][TYPE_NONE][ssc];
389 if (pma_cmn_vals) {
390 reg_pairs = pma_cmn_vals->reg_pairs;
391 num_regs = pma_cmn_vals->num_regs;
392 regmap = phy->regmap_common_cdb;
393 for (i = 0; i < num_regs; i++)
394 regmap_write(regmap, reg_pairs[i].off, reg_pairs[i].val);
Alan Douglas39b82332021-07-21 21:28:36 +0530395 }
396
Swapnil Jakhade14ed6702022-01-28 13:41:40 +0530397 /* PMA TX lane registers configurations */
398 pma_ln_vals = init_data->pma_ln_vals[phy_type][TYPE_NONE][ssc];
399 if (pma_ln_vals) {
400 reg_pairs = pma_ln_vals->reg_pairs;
401 num_regs = pma_ln_vals->num_regs;
402 for (i = 0; i < ins->num_lanes; i++) {
Alan Douglas39b82332021-07-21 21:28:36 +0530403 regmap = phy->regmap_lane_cdb[i + ins->mlane];
Swapnil Jakhade14ed6702022-01-28 13:41:40 +0530404 for (j = 0; j < num_regs; j++)
405 regmap_write(regmap, reg_pairs[j].off, reg_pairs[j].val);
Alan Douglas39b82332021-07-21 21:28:36 +0530406 }
407 }
408
409 return 0;
410}
411
412static int cdns_sierra_phy_on(struct phy *gphy)
413{
414 struct cdns_sierra_inst *ins = phy_get_drvdata(gphy);
415 struct cdns_sierra_phy *sp = dev_get_priv(gphy->dev);
416 struct udevice *dev = gphy->dev;
417 u32 val;
418 int ret;
419
Kishon Vijay Abraham I67703ee2022-01-28 13:41:29 +0530420 ret = reset_control_deassert(sp->phy_rst);
421 if (ret) {
422 dev_err(dev, "Failed to take the PHY out of reset\n");
423 return ret;
424 }
425
Alan Douglas39b82332021-07-21 21:28:36 +0530426 /* Take the PHY lane group out of reset */
427 ret = reset_deassert_bulk(ins->lnk_rst);
428 if (ret) {
429 dev_err(dev, "Failed to take the PHY lane out of reset\n");
430 return ret;
431 }
432
Swapnil Jakhadef0cb8092022-01-28 13:41:46 +0530433 if (ins->phy_type == TYPE_PCIE || ins->phy_type == TYPE_USB) {
434 ret = regmap_field_read_poll_timeout(sp->phy_iso_link_ctrl_1[ins->mlane],
435 val, !val, 1000, PLL_LOCK_TIME);
436 if (ret) {
437 dev_err(dev, "Timeout waiting for PHY status ready\n");
438 return ret;
439 }
440 }
441
Swapnil Jakhade48f29872022-01-28 13:41:45 +0530442 /*
443 * Wait for cmn_ready assertion
444 * PHY_PMA_CMN_CTRL[0] == 1
445 */
446 ret = regmap_field_read_poll_timeout(sp->pma_cmn_ready, val, val,
447 1000, PLL_LOCK_TIME);
448 if (ret) {
449 dev_err(dev, "Timeout waiting for CMN ready\n");
450 return ret;
451 }
452
Alan Douglas39b82332021-07-21 21:28:36 +0530453 ret = regmap_field_read_poll_timeout(sp->pllctrl_lock[ins->mlane],
454 val, val, 1000, PLL_LOCK_TIME);
455 if (ret < 0)
456 dev_err(dev, "PLL lock of lane failed\n");
457
458 reset_control_assert(sp->phy_rst);
459 reset_control_deassert(sp->phy_rst);
460
461 return ret;
462}
463
464static int cdns_sierra_phy_off(struct phy *gphy)
465{
466 struct cdns_sierra_inst *ins = phy_get_drvdata(gphy);
467
468 return reset_assert_bulk(ins->lnk_rst);
469}
470
471static int cdns_sierra_phy_reset(struct phy *gphy)
472{
473 struct cdns_sierra_phy *sp = dev_get_priv(gphy->dev);
474
475 reset_control_assert(sp->phy_rst);
476 reset_control_deassert(sp->phy_rst);
477 return 0;
478};
479
480static const struct phy_ops ops = {
481 .init = cdns_sierra_phy_init,
482 .power_on = cdns_sierra_phy_on,
483 .power_off = cdns_sierra_phy_off,
484 .reset = cdns_sierra_phy_reset,
485};
486
Aswath Govindrajudd759272022-01-28 13:41:36 +0530487struct cdns_sierra_pll_mux_sel {
488 enum cdns_sierra_cmn_plllc mux_sel;
489 u32 table[2];
490 const char *node_name;
491 u32 num_parents;
492 u32 parents[2];
493};
494
495static struct cdns_sierra_pll_mux_sel pll_clk_mux_sel[] = {
496 {
497 .num_parents = 2,
498 .parents = { PLL0_REFCLK, PLL1_REFCLK },
499 .mux_sel = CMN_PLLLC,
500 .table = { 0, 1 },
501 .node_name = "pll_cmnlc",
502 },
503 {
504 .num_parents = 2,
505 .parents = { PLL1_REFCLK, PLL0_REFCLK },
506 .mux_sel = CMN_PLLLC1,
507 .table = { 1, 0 },
508 .node_name = "pll_cmnlc1",
509 },
510};
511
512static int cdns_sierra_pll_mux_set_parent(struct clk *clk, struct clk *parent)
513{
514 struct udevice *dev = clk->dev;
515 struct cdns_sierra_pll_mux *priv = dev_get_priv(dev);
516 struct cdns_sierra_pll_mux_sel *data = dev_get_plat(dev);
517 struct cdns_sierra_phy *sp = priv->sp;
518 int ret;
519 int i;
520
521 for (i = 0; i < ARRAY_SIZE(priv->parent_clks); i++) {
522 if (parent->dev == priv->parent_clks[i]->dev)
523 break;
524 }
525
526 if (i == ARRAY_SIZE(priv->parent_clks))
527 return -EINVAL;
528
529 ret = regmap_field_write(sp->cmn_refrcv_refclk_plllc1en_preg[data[clk->id].mux_sel], i);
530 ret |= regmap_field_write(sp->cmn_refrcv_refclk_termen_preg[data[clk->id].mux_sel], i);
531 ret |= regmap_field_write(sp->cmn_plllc_pfdclk1_sel_preg[data[clk->id].mux_sel],
532 data[clk->id].table[i]);
533
534 return ret;
535}
536
537static const struct clk_ops cdns_sierra_pll_mux_ops = {
538 .set_parent = cdns_sierra_pll_mux_set_parent,
539};
540
541int cdns_sierra_pll_mux_probe(struct udevice *dev)
542{
543 struct cdns_sierra_pll_mux *priv = dev_get_priv(dev);
544 struct cdns_sierra_phy *sp = dev_get_priv(dev->parent);
545 struct cdns_sierra_pll_mux_sel *data = dev_get_plat(dev);
546 struct clk *clk;
547 int i, j;
548
549 for (j = 0; j < SIERRA_NUM_CMN_PLLC; j++) {
550 for (i = 0; i < ARRAY_SIZE(priv->parent_clks); i++) {
551 clk = sp->input_clks[data[j].parents[i]];
552 if (IS_ERR_OR_NULL(clk)) {
553 dev_err(dev, "No parent clock for PLL mux clocks\n");
554 return IS_ERR(clk) ? PTR_ERR(clk) : -ENOENT;
555 }
556 priv->parent_clks[i] = clk;
557 }
558 }
559
560 priv->sp = dev_get_priv(dev->parent);
561
562 return 0;
563}
564
565U_BOOT_DRIVER(cdns_sierra_pll_mux_clk) = {
566 .name = "cdns_sierra_mux_clk",
567 .id = UCLASS_CLK,
568 .priv_auto = sizeof(struct cdns_sierra_pll_mux),
569 .ops = &cdns_sierra_pll_mux_ops,
570 .probe = cdns_sierra_pll_mux_probe,
571 .plat_auto = sizeof(struct cdns_sierra_pll_mux_sel) * SIERRA_NUM_CMN_PLLC,
572};
573
574static int cdns_sierra_pll_bind_of_clocks(struct cdns_sierra_phy *sp)
575{
576 struct udevice *dev = sp->dev;
577 struct driver *cdns_sierra_clk_drv;
578 struct cdns_sierra_pll_mux_sel *data = pll_clk_mux_sel;
579 int i, rc;
580
581 cdns_sierra_clk_drv = lists_driver_lookup_name("cdns_sierra_mux_clk");
582 if (!cdns_sierra_clk_drv) {
583 dev_err(dev, "Can not find driver 'cdns_sierra_mux_clk'\n");
584 return -ENOENT;
585 }
586
587 rc = device_bind(dev, cdns_sierra_clk_drv, "pll_mux_clk",
588 data, dev_ofnode(dev), NULL);
589 if (rc) {
590 dev_err(dev, "cannot bind driver for clock %s\n",
591 clk_names[i]);
592 }
593
594 return 0;
595}
596
Alan Douglas39b82332021-07-21 21:28:36 +0530597static int cdns_sierra_get_optional(struct cdns_sierra_inst *inst,
598 ofnode child)
599{
Swapnil Jakhade14ed6702022-01-28 13:41:40 +0530600 u32 phy_type;
601
Alan Douglas39b82332021-07-21 21:28:36 +0530602 if (ofnode_read_u32(child, "reg", &inst->mlane))
603 return -EINVAL;
604
605 if (ofnode_read_u32(child, "cdns,num-lanes", &inst->num_lanes))
606 return -EINVAL;
607
Swapnil Jakhade14ed6702022-01-28 13:41:40 +0530608 if (ofnode_read_u32(child, "cdns,phy-type", &phy_type))
Alan Douglas39b82332021-07-21 21:28:36 +0530609 return -EINVAL;
610
Swapnil Jakhade14ed6702022-01-28 13:41:40 +0530611 switch (phy_type) {
612 case PHY_TYPE_PCIE:
613 inst->phy_type = TYPE_PCIE;
614 break;
615 case PHY_TYPE_USB3:
616 inst->phy_type = TYPE_USB;
617 break;
618 default:
619 return -EINVAL;
620 }
621
Swapnil Jakhadeb6541d42022-01-28 13:41:42 +0530622 inst->ssc_mode = EXTERNAL_SSC;
623 ofnode_read_u32(child, "cdns,ssc-mode", &inst->ssc_mode);
624
Alan Douglas39b82332021-07-21 21:28:36 +0530625 return 0;
626}
627
628static struct regmap *cdns_regmap_init(struct udevice *dev, void __iomem *base,
629 u32 block_offset, u8 block_offset_shift,
630 u8 reg_offset_shift)
631{
632 struct cdns_sierra_phy *sp = dev_get_priv(dev);
633 struct regmap_config config;
634
635 config.r_start = (ulong)(base + (block_offset << block_offset_shift));
636 config.r_size = sp->size - (block_offset << block_offset_shift);
637 config.reg_offset_shift = reg_offset_shift;
638 config.width = REGMAP_SIZE_16;
639
640 return devm_regmap_init(dev, NULL, NULL, &config);
641}
642
643static int cdns_regfield_init(struct cdns_sierra_phy *sp)
644{
645 struct udevice *dev = sp->dev;
646 struct regmap_field *field;
Aswath Govindrajudd759272022-01-28 13:41:36 +0530647 struct reg_field reg_field;
Alan Douglas39b82332021-07-21 21:28:36 +0530648 struct regmap *regmap;
649 int i;
650
651 regmap = sp->regmap_common_cdb;
652 field = devm_regmap_field_alloc(dev, regmap, macro_id_type);
653 if (IS_ERR(field)) {
654 dev_err(dev, "MACRO_ID_TYPE reg field init failed\n");
655 return PTR_ERR(field);
656 }
657 sp->macro_id_type = field;
658
Aswath Govindrajudd759272022-01-28 13:41:36 +0530659 for (i = 0; i < SIERRA_NUM_CMN_PLLC; i++) {
660 reg_field = cmn_plllc_pfdclk1_sel_preg[i].pfdclk_sel_preg;
661 field = devm_regmap_field_alloc(dev, regmap, reg_field);
662 if (IS_ERR(field)) {
663 dev_err(dev, "PLLLC%d_PFDCLK1_SEL failed\n", i);
664 return PTR_ERR(field);
665 }
666 sp->cmn_plllc_pfdclk1_sel_preg[i] = field;
667
668 reg_field = cmn_plllc_pfdclk1_sel_preg[i].plllc1en_field;
669 field = devm_regmap_field_alloc(dev, regmap, reg_field);
670 if (IS_ERR(field)) {
671 dev_err(dev, "REFRCV%d_REFCLK_PLLLC1EN failed\n", i);
672 return PTR_ERR(field);
673 }
674 sp->cmn_refrcv_refclk_plllc1en_preg[i] = field;
675
676 reg_field = cmn_plllc_pfdclk1_sel_preg[i].termen_field;
677 field = devm_regmap_field_alloc(dev, regmap, reg_field);
678 if (IS_ERR(field)) {
679 dev_err(dev, "REFRCV%d_REFCLK_TERMEN failed\n", i);
680 return PTR_ERR(field);
681 }
682 sp->cmn_refrcv_refclk_termen_preg[i] = field;
683 }
684
Swapnil Jakhade445c8cf2022-01-28 13:41:43 +0530685 regmap = sp->regmap_phy_pcs_common_cdb;
Alan Douglas39b82332021-07-21 21:28:36 +0530686 field = devm_regmap_field_alloc(dev, regmap, phy_pll_cfg_1);
687 if (IS_ERR(field)) {
688 dev_err(dev, "PHY_PLL_CFG_1 reg field init failed\n");
689 return PTR_ERR(field);
690 }
691 sp->phy_pll_cfg_1 = field;
692
Swapnil Jakhade48f29872022-01-28 13:41:45 +0530693 regmap = sp->regmap_phy_pma_common_cdb;
694 field = devm_regmap_field_alloc(dev, regmap, pma_cmn_ready);
695 if (IS_ERR(field)) {
696 dev_err(dev, "PHY_PMA_CMN_CTRL reg field init failed\n");
697 return PTR_ERR(field);
698 }
699 sp->pma_cmn_ready = field;
700
Alan Douglas39b82332021-07-21 21:28:36 +0530701 for (i = 0; i < SIERRA_MAX_LANES; i++) {
702 regmap = sp->regmap_lane_cdb[i];
703 field = devm_regmap_field_alloc(dev, regmap, pllctrl_lock);
704 if (IS_ERR(field)) {
705 dev_err(dev, "P%d_ENABLE reg field init failed\n", i);
706 return PTR_ERR(field);
707 }
Swapnil Jakhadef0cb8092022-01-28 13:41:46 +0530708 sp->pllctrl_lock[i] = field;
709 }
710
711 for (i = 0; i < SIERRA_MAX_LANES; i++) {
712 regmap = sp->regmap_phy_pcs_lane_cdb[i];
713 field = devm_regmap_field_alloc(dev, regmap, phy_iso_link_ctrl_1);
714 if (IS_ERR(field)) {
715 dev_err(dev, "PHY_ISO_LINK_CTRL reg field init for lane %d failed\n", i);
716 return PTR_ERR(field);
717 }
718 sp->phy_iso_link_ctrl_1[i] = field;
Alan Douglas39b82332021-07-21 21:28:36 +0530719 }
720
721 return 0;
722}
723
724static int cdns_regmap_init_blocks(struct cdns_sierra_phy *sp,
725 void __iomem *base, u8 block_offset_shift,
726 u8 reg_offset_shift)
727{
728 struct udevice *dev = sp->dev;
729 struct regmap *regmap;
730 u32 block_offset;
731 int i;
732
733 for (i = 0; i < SIERRA_MAX_LANES; i++) {
734 block_offset = SIERRA_LANE_CDB_OFFSET(i, reg_offset_shift);
735 regmap = cdns_regmap_init(dev, base, block_offset,
736 block_offset_shift, reg_offset_shift);
737 if (IS_ERR(regmap)) {
738 dev_err(dev, "Failed to init lane CDB regmap\n");
739 return PTR_ERR(regmap);
740 }
741 sp->regmap_lane_cdb[i] = regmap;
742 }
743
744 regmap = cdns_regmap_init(dev, base, SIERRA_COMMON_CDB_OFFSET,
745 block_offset_shift, reg_offset_shift);
746 if (IS_ERR(regmap)) {
747 dev_err(dev, "Failed to init common CDB regmap\n");
748 return PTR_ERR(regmap);
749 }
750 sp->regmap_common_cdb = regmap;
751
Swapnil Jakhade445c8cf2022-01-28 13:41:43 +0530752 regmap = cdns_regmap_init(dev, base, SIERRA_PHY_PCS_COMMON_OFFSET,
Alan Douglas39b82332021-07-21 21:28:36 +0530753 block_offset_shift, reg_offset_shift);
754 if (IS_ERR(regmap)) {
Swapnil Jakhade445c8cf2022-01-28 13:41:43 +0530755 dev_err(dev, "Failed to init PHY PCS common CDB regmap\n");
Alan Douglas39b82332021-07-21 21:28:36 +0530756 return PTR_ERR(regmap);
757 }
Swapnil Jakhade445c8cf2022-01-28 13:41:43 +0530758 sp->regmap_phy_pcs_common_cdb = regmap;
Alan Douglas39b82332021-07-21 21:28:36 +0530759
Swapnil Jakhadef0cb8092022-01-28 13:41:46 +0530760 for (i = 0; i < SIERRA_MAX_LANES; i++) {
761 block_offset = SIERRA_PHY_PCS_LANE_CDB_OFFSET(i, reg_offset_shift);
762 regmap = cdns_regmap_init(dev, base, block_offset,
763 block_offset_shift, reg_offset_shift);
764 if (IS_ERR(regmap)) {
765 dev_err(dev, "Failed to init PHY PCS lane CDB regmap\n");
766 return PTR_ERR(regmap);
767 }
768 sp->regmap_phy_pcs_lane_cdb[i] = regmap;
769 }
770
Swapnil Jakhade48f29872022-01-28 13:41:45 +0530771 regmap = cdns_regmap_init(dev, base, SIERRA_PHY_PMA_COMMON_OFFSET,
772 block_offset_shift, reg_offset_shift);
773 if (IS_ERR(regmap)) {
774 dev_err(dev, "Failed to init PHY PMA common CDB regmap\n");
775 return PTR_ERR(regmap);
776 }
777 sp->regmap_phy_pma_common_cdb = regmap;
778
Alan Douglas39b82332021-07-21 21:28:36 +0530779 return 0;
780}
781
Kishon Vijay Abraham Ia9382b02022-01-28 13:41:31 +0530782static int cdns_sierra_phy_get_clocks(struct cdns_sierra_phy *sp,
783 struct udevice *dev)
784{
785 struct clk *clk;
786 int ret;
787
788 clk = devm_clk_get_optional(dev, "phy_clk");
789 if (IS_ERR(clk)) {
790 dev_err(dev, "failed to get clock phy_clk\n");
791 return PTR_ERR(clk);
792 }
Kishon Vijay Abraham I82574372022-01-28 13:41:33 +0530793 sp->input_clks[PHY_CLK] = clk;
Kishon Vijay Abraham Ia9382b02022-01-28 13:41:31 +0530794
795 clk = devm_clk_get_optional(dev, "cmn_refclk_dig_div");
796 if (IS_ERR(clk)) {
797 dev_err(dev, "cmn_refclk_dig_div clock not found\n");
798 ret = PTR_ERR(clk);
799 return ret;
800 }
Kishon Vijay Abraham I82574372022-01-28 13:41:33 +0530801 sp->input_clks[CMN_REFCLK_DIG_DIV] = clk;
Kishon Vijay Abraham Ia9382b02022-01-28 13:41:31 +0530802
803 clk = devm_clk_get_optional(dev, "cmn_refclk1_dig_div");
804 if (IS_ERR(clk)) {
805 dev_err(dev, "cmn_refclk1_dig_div clock not found\n");
806 ret = PTR_ERR(clk);
807 return ret;
808 }
Kishon Vijay Abraham I82574372022-01-28 13:41:33 +0530809 sp->input_clks[CMN_REFCLK1_DIG_DIV] = clk;
Kishon Vijay Abraham Ia9382b02022-01-28 13:41:31 +0530810
Aswath Govindrajudd759272022-01-28 13:41:36 +0530811 clk = devm_clk_get_optional(dev, "pll0_refclk");
812 if (IS_ERR(clk)) {
813 dev_err(dev, "pll0_refclk clock not found\n");
814 ret = PTR_ERR(clk);
815 return ret;
816 }
817 sp->input_clks[PLL0_REFCLK] = clk;
818
819 clk = devm_clk_get_optional(dev, "pll1_refclk");
820 if (IS_ERR(clk)) {
821 dev_err(dev, "pll1_refclk clock not found\n");
822 ret = PTR_ERR(clk);
823 return ret;
824 }
825 sp->input_clks[PLL1_REFCLK] = clk;
826
Kishon Vijay Abraham Ia9382b02022-01-28 13:41:31 +0530827 return 0;
828}
829
Kishon Vijay Abraham Ic1c1b342022-01-28 13:41:32 +0530830static int cdns_sierra_phy_get_resets(struct cdns_sierra_phy *sp,
831 struct udevice *dev)
832{
833 struct reset_control *rst;
834
835 rst = devm_reset_control_get(dev, "sierra_reset");
836 if (IS_ERR(rst)) {
837 dev_err(dev, "failed to get reset\n");
838 return PTR_ERR(rst);
839 }
840 sp->phy_rst = rst;
841
842 return 0;
843}
844
Aswath Govindraju6f46c742022-01-28 13:41:35 +0530845static int cdns_sierra_bind_link_nodes(struct cdns_sierra_phy *sp)
846{
847 struct udevice *dev = sp->dev;
848 struct driver *link_drv;
849 ofnode child;
850 int rc;
851
852 link_drv = lists_driver_lookup_name("sierra_phy_link");
853 if (!link_drv) {
854 dev_err(dev, "Cannot find driver 'sierra_phy_link'\n");
855 return -ENOENT;
856 }
857
858 ofnode_for_each_subnode(child, dev_ofnode(dev)) {
859 if (!(ofnode_name_eq(child, "phy") ||
860 ofnode_name_eq(child, "link")))
861 continue;
862
863 rc = device_bind(dev, link_drv, "link", NULL, child, NULL);
864 if (rc) {
865 dev_err(dev, "cannot bind driver for link\n");
866 return rc;
867 }
868 }
869
870 return 0;
871}
872
873static int cdns_sierra_link_probe(struct udevice *dev)
874{
875 struct cdns_sierra_inst *inst = dev_get_priv(dev);
876 struct cdns_sierra_phy *sp = dev_get_priv(dev->parent);
877 struct reset_ctl_bulk *rst;
878 int ret, node;
879
880 rst = devm_reset_bulk_get_by_node(dev, dev_ofnode(dev));
881 if (IS_ERR(rst)) {
882 ret = PTR_ERR(rst);
883 dev_err(dev, "failed to get reset\n");
884 return ret;
885 }
886 inst->lnk_rst = rst;
887
888 ret = cdns_sierra_get_optional(inst, dev_ofnode(dev));
889 if (ret) {
890 dev_err(dev, "missing property in node\n");
891 return ret;
892 }
893 node = sp->nsubnodes;
894 sp->phys[node] = inst;
895 sp->nsubnodes += 1;
896 sp->num_lanes += inst->num_lanes;
897
898 /* If more than one subnode, configure the PHY as multilink */
899 if (!sp->autoconf && sp->nsubnodes > 1)
900 regmap_field_write(sp->phy_pll_cfg_1, 0x1);
901
902 return 0;
903}
904
905U_BOOT_DRIVER(sierra_phy_link) = {
906 .name = "sierra_phy_link",
907 .id = UCLASS_PHY,
908 .probe = cdns_sierra_link_probe,
909 .priv_auto = sizeof(struct cdns_sierra_inst),
910};
911
Alan Douglas39b82332021-07-21 21:28:36 +0530912static int cdns_sierra_phy_probe(struct udevice *dev)
913{
914 struct cdns_sierra_phy *sp = dev_get_priv(dev);
915 struct cdns_sierra_data *data;
916 unsigned int id_value;
Aswath Govindrajudd759272022-01-28 13:41:36 +0530917 int ret;
Alan Douglas39b82332021-07-21 21:28:36 +0530918
919 sp->dev = dev;
920
921 sp->base = devfdt_remap_addr_index(dev, 0);
922 if (!sp->base) {
923 dev_err(dev, "unable to map regs\n");
924 return -ENOMEM;
925 }
926 devfdt_get_addr_size_index(dev, 0, (fdt_size_t *)&sp->size);
927
928 /* Get init data for this PHY */
929 data = (struct cdns_sierra_data *)dev_get_driver_data(dev);
930 sp->init_data = data;
931
932 ret = cdns_regmap_init_blocks(sp, sp->base, data->block_offset_shift,
933 data->reg_offset_shift);
934 if (ret)
935 return ret;
936
937 ret = cdns_regfield_init(sp);
938 if (ret)
939 return ret;
940
Kishon Vijay Abraham Ia9382b02022-01-28 13:41:31 +0530941 ret = cdns_sierra_phy_get_clocks(sp, dev);
942 if (ret)
943 return ret;
Alan Douglas39b82332021-07-21 21:28:36 +0530944
Aswath Govindrajudd759272022-01-28 13:41:36 +0530945 ret = cdns_sierra_pll_bind_of_clocks(sp);
946 if (ret)
947 return ret;
Alan Douglas39b82332021-07-21 21:28:36 +0530948
Kishon Vijay Abraham Ic1c1b342022-01-28 13:41:32 +0530949 ret = cdns_sierra_phy_get_resets(sp, dev);
950 if (ret)
951 return ret;
952
Kishon Vijay Abraham I82574372022-01-28 13:41:33 +0530953 ret = clk_prepare_enable(sp->input_clks[PHY_CLK]);
Alan Douglas39b82332021-07-21 21:28:36 +0530954 if (ret)
955 return ret;
956
957 /* Check that PHY is present */
958 regmap_field_read(sp->macro_id_type, &id_value);
959 if (sp->init_data->id_value != id_value) {
960 dev_err(dev, "PHY not found 0x%x vs 0x%x\n",
961 sp->init_data->id_value, id_value);
962 ret = -EINVAL;
963 goto clk_disable;
964 }
965
966 sp->autoconf = dev_read_bool(dev, "cdns,autoconf");
Aswath Govindraju6f46c742022-01-28 13:41:35 +0530967 /* Binding link nodes as children to serdes */
968 ret = cdns_sierra_bind_link_nodes(sp);
969 if (ret)
970 goto clk_disable;
Alan Douglas39b82332021-07-21 21:28:36 +0530971
Alan Douglas39b82332021-07-21 21:28:36 +0530972 dev_info(dev, "sierra probed\n");
973 return 0;
974
Alan Douglas39b82332021-07-21 21:28:36 +0530975clk_disable:
Kishon Vijay Abraham I82574372022-01-28 13:41:33 +0530976 clk_disable_unprepare(sp->input_clks[PHY_CLK]);
Alan Douglas39b82332021-07-21 21:28:36 +0530977 return ret;
978}
979
980static int cdns_sierra_phy_remove(struct udevice *dev)
981{
982 struct cdns_sierra_phy *phy = dev_get_priv(dev);
983 int i;
984
985 reset_control_assert(phy->phy_rst);
986
987 /*
988 * The device level resets will be put automatically.
989 * Need to put the subnode resets here though.
990 */
991 for (i = 0; i < phy->nsubnodes; i++)
Aswath Govindraju6f46c742022-01-28 13:41:35 +0530992 reset_assert_bulk(phy->phys[i]->lnk_rst);
Alan Douglas39b82332021-07-21 21:28:36 +0530993
Kishon Vijay Abraham Ie7a29862022-01-28 13:41:34 +0530994 clk_disable_unprepare(phy->input_clks[PHY_CLK]);
995
Alan Douglas39b82332021-07-21 21:28:36 +0530996 return 0;
997}
998
Swapnil Jakhade990ce532022-01-28 13:41:44 +0530999/* PCIE PHY PCS common configuration */
1000static struct cdns_reg_pairs pcie_phy_pcs_cmn_regs[] = {
1001 {0x0430, SIERRA_PHY_PIPE_CMN_CTRL1}
1002};
1003
1004static struct cdns_sierra_vals pcie_phy_pcs_cmn_vals = {
1005 .reg_pairs = pcie_phy_pcs_cmn_regs,
1006 .num_regs = ARRAY_SIZE(pcie_phy_pcs_cmn_regs),
1007};
1008
Swapnil Jakhade960efc52022-01-28 13:41:47 +05301009/* refclk100MHz_32b_PCIe_cmn_pll_no_ssc */
1010static const struct cdns_reg_pairs cdns_pcie_cmn_regs_no_ssc[] = {
1011 {0x2105, SIERRA_CMN_PLLLC_LF_COEFF_MODE1_PREG},
1012 {0x2105, SIERRA_CMN_PLLLC_LF_COEFF_MODE0_PREG},
1013 {0x8A06, SIERRA_CMN_PLLLC_BWCAL_MODE1_PREG},
1014 {0x8A06, SIERRA_CMN_PLLLC_BWCAL_MODE0_PREG}
1015};
1016
1017/* refclk100MHz_32b_PCIe_ln_no_ssc */
1018static const struct cdns_reg_pairs cdns_pcie_ln_regs_no_ssc[] = {
1019 {0xFC08, SIERRA_DET_STANDEC_A_PREG},
1020 {0x001D, SIERRA_PSM_A3IN_TMR_PREG},
1021 {0x1555, SIERRA_DFE_BIASTRIM_PREG},
1022 {0x9703, SIERRA_DRVCTRL_BOOST_PREG},
1023 {0x8055, SIERRA_RX_CREQ_FLTR_A_MODE3_PREG},
1024 {0x80BB, SIERRA_RX_CREQ_FLTR_A_MODE2_PREG},
1025 {0x8351, SIERRA_RX_CREQ_FLTR_A_MODE1_PREG},
1026 {0x8349, SIERRA_RX_CREQ_FLTR_A_MODE0_PREG},
1027 {0x0002, SIERRA_CREQ_DCBIASATTEN_OVR_PREG},
1028 {0x9800, SIERRA_RX_CTLE_CAL_PREG},
1029 {0x5624, SIERRA_DEQ_CONCUR_CTRL2_PREG},
1030 {0x000F, SIERRA_DEQ_EPIPWR_CTRL2_PREG},
1031 {0x00FF, SIERRA_DEQ_FAST_MAINT_CYCLES_PREG},
1032 {0x4C4C, SIERRA_DEQ_ERRCMP_CTRL_PREG},
1033 {0x02FA, SIERRA_DEQ_OFFSET_CTRL_PREG},
1034 {0x02FA, SIERRA_DEQ_GAIN_CTRL_PREG},
1035 {0x0041, SIERRA_DEQ_GLUT0},
1036 {0x0082, SIERRA_DEQ_GLUT1},
1037 {0x00C3, SIERRA_DEQ_GLUT2},
1038 {0x0145, SIERRA_DEQ_GLUT3},
1039 {0x0186, SIERRA_DEQ_GLUT4},
1040 {0x09E7, SIERRA_DEQ_ALUT0},
1041 {0x09A6, SIERRA_DEQ_ALUT1},
1042 {0x0965, SIERRA_DEQ_ALUT2},
1043 {0x08E3, SIERRA_DEQ_ALUT3},
1044 {0x00FA, SIERRA_DEQ_DFETAP0},
1045 {0x00FA, SIERRA_DEQ_DFETAP1},
1046 {0x00FA, SIERRA_DEQ_DFETAP2},
1047 {0x00FA, SIERRA_DEQ_DFETAP3},
1048 {0x00FA, SIERRA_DEQ_DFETAP4},
1049 {0x000F, SIERRA_DEQ_PRECUR_PREG},
1050 {0x0280, SIERRA_DEQ_POSTCUR_PREG},
1051 {0x8F00, SIERRA_DEQ_POSTCUR_DECR_PREG},
1052 {0x3C0F, SIERRA_DEQ_TAU_CTRL1_SLOW_MAINT_PREG},
1053 {0x1C0C, SIERRA_DEQ_TAU_CTRL2_PREG},
1054 {0x0100, SIERRA_DEQ_TAU_CTRL3_PREG},
1055 {0x5E82, SIERRA_DEQ_OPENEYE_CTRL_PREG},
1056 {0x002B, SIERRA_CPI_TRIM_PREG},
1057 {0x0003, SIERRA_EPI_CTRL_PREG},
1058 {0x803F, SIERRA_SDFILT_H2L_A_PREG},
1059 {0x0004, SIERRA_RXBUFFER_CTLECTRL_PREG},
1060 {0x2010, SIERRA_RXBUFFER_RCDFECTRL_PREG},
1061 {0x4432, SIERRA_RXBUFFER_DFECTRL_PREG}
1062};
1063
1064static struct cdns_sierra_vals pcie_100_no_ssc_cmn_vals = {
1065 .reg_pairs = cdns_pcie_cmn_regs_no_ssc,
1066 .num_regs = ARRAY_SIZE(cdns_pcie_cmn_regs_no_ssc),
1067};
1068
1069static struct cdns_sierra_vals pcie_100_no_ssc_ln_vals = {
1070 .reg_pairs = cdns_pcie_ln_regs_no_ssc,
1071 .num_regs = ARRAY_SIZE(cdns_pcie_ln_regs_no_ssc),
1072};
1073
1074/* refclk100MHz_32b_PCIe_cmn_pll_int_ssc */
1075static const struct cdns_reg_pairs cdns_pcie_cmn_regs_int_ssc[] = {
1076 {0x000E, SIERRA_CMN_PLLLC_MODE_PREG},
1077 {0x4006, SIERRA_CMN_PLLLC_LF_COEFF_MODE1_PREG},
1078 {0x4006, SIERRA_CMN_PLLLC_LF_COEFF_MODE0_PREG},
1079 {0x0000, SIERRA_CMN_PLLLC_BWCAL_MODE1_PREG},
1080 {0x0000, SIERRA_CMN_PLLLC_BWCAL_MODE0_PREG},
1081 {0x0581, SIERRA_CMN_PLLLC_DSMCORR_PREG},
1082 {0x7F80, SIERRA_CMN_PLLLC_SS_PREG},
1083 {0x0041, SIERRA_CMN_PLLLC_SS_AMP_STEP_SIZE_PREG},
1084 {0x0464, SIERRA_CMN_PLLLC_SSTWOPT_PREG},
1085 {0x0D0D, SIERRA_CMN_PLLLC_SS_TIME_STEPSIZE_MODE_PREG},
1086 {0x0060, SIERRA_CMN_PLLLC_LOCK_DELAY_CTRL_PREG}
1087};
1088
1089/* refclk100MHz_32b_PCIe_ln_int_ssc */
1090static const struct cdns_reg_pairs cdns_pcie_ln_regs_int_ssc[] = {
1091 {0xFC08, SIERRA_DET_STANDEC_A_PREG},
1092 {0x001D, SIERRA_PSM_A3IN_TMR_PREG},
1093 {0x1555, SIERRA_DFE_BIASTRIM_PREG},
1094 {0x9703, SIERRA_DRVCTRL_BOOST_PREG},
1095 {0x813E, SIERRA_CLKPATHCTRL_TMR_PREG},
1096 {0x8047, SIERRA_RX_CREQ_FLTR_A_MODE3_PREG},
1097 {0x808F, SIERRA_RX_CREQ_FLTR_A_MODE2_PREG},
1098 {0x808F, SIERRA_RX_CREQ_FLTR_A_MODE1_PREG},
1099 {0x808F, SIERRA_RX_CREQ_FLTR_A_MODE0_PREG},
1100 {0x0002, SIERRA_CREQ_DCBIASATTEN_OVR_PREG},
1101 {0x9800, SIERRA_RX_CTLE_CAL_PREG},
1102 {0x033C, SIERRA_RX_CTLE_MAINTENANCE_PREG},
1103 {0x44CC, SIERRA_CREQ_EQ_OPEN_EYE_THRESH_PREG},
1104 {0x5624, SIERRA_DEQ_CONCUR_CTRL2_PREG},
1105 {0x000F, SIERRA_DEQ_EPIPWR_CTRL2_PREG},
1106 {0x00FF, SIERRA_DEQ_FAST_MAINT_CYCLES_PREG},
1107 {0x4C4C, SIERRA_DEQ_ERRCMP_CTRL_PREG},
1108 {0x02FA, SIERRA_DEQ_OFFSET_CTRL_PREG},
1109 {0x02FA, SIERRA_DEQ_GAIN_CTRL_PREG},
1110 {0x0041, SIERRA_DEQ_GLUT0},
1111 {0x0082, SIERRA_DEQ_GLUT1},
1112 {0x00C3, SIERRA_DEQ_GLUT2},
1113 {0x0145, SIERRA_DEQ_GLUT3},
1114 {0x0186, SIERRA_DEQ_GLUT4},
1115 {0x09E7, SIERRA_DEQ_ALUT0},
1116 {0x09A6, SIERRA_DEQ_ALUT1},
1117 {0x0965, SIERRA_DEQ_ALUT2},
1118 {0x08E3, SIERRA_DEQ_ALUT3},
1119 {0x00FA, SIERRA_DEQ_DFETAP0},
1120 {0x00FA, SIERRA_DEQ_DFETAP1},
1121 {0x00FA, SIERRA_DEQ_DFETAP2},
1122 {0x00FA, SIERRA_DEQ_DFETAP3},
1123 {0x00FA, SIERRA_DEQ_DFETAP4},
1124 {0x000F, SIERRA_DEQ_PRECUR_PREG},
1125 {0x0280, SIERRA_DEQ_POSTCUR_PREG},
1126 {0x8F00, SIERRA_DEQ_POSTCUR_DECR_PREG},
1127 {0x3C0F, SIERRA_DEQ_TAU_CTRL1_SLOW_MAINT_PREG},
1128 {0x1C0C, SIERRA_DEQ_TAU_CTRL2_PREG},
1129 {0x0100, SIERRA_DEQ_TAU_CTRL3_PREG},
1130 {0x5E82, SIERRA_DEQ_OPENEYE_CTRL_PREG},
1131 {0x002B, SIERRA_CPI_TRIM_PREG},
1132 {0x0003, SIERRA_EPI_CTRL_PREG},
1133 {0x803F, SIERRA_SDFILT_H2L_A_PREG},
1134 {0x0004, SIERRA_RXBUFFER_CTLECTRL_PREG},
1135 {0x2010, SIERRA_RXBUFFER_RCDFECTRL_PREG},
1136 {0x4432, SIERRA_RXBUFFER_DFECTRL_PREG}
1137};
1138
1139static struct cdns_sierra_vals pcie_100_int_ssc_cmn_vals = {
1140 .reg_pairs = cdns_pcie_cmn_regs_int_ssc,
1141 .num_regs = ARRAY_SIZE(cdns_pcie_cmn_regs_int_ssc),
1142};
1143
1144static struct cdns_sierra_vals pcie_100_int_ssc_ln_vals = {
1145 .reg_pairs = cdns_pcie_ln_regs_int_ssc,
1146 .num_regs = ARRAY_SIZE(cdns_pcie_ln_regs_int_ssc),
1147};
1148
Alan Douglas39b82332021-07-21 21:28:36 +05301149/* refclk100MHz_32b_PCIe_cmn_pll_ext_ssc */
1150static struct cdns_reg_pairs cdns_pcie_cmn_regs_ext_ssc[] = {
1151 {0x2106, SIERRA_CMN_PLLLC_LF_COEFF_MODE1_PREG},
1152 {0x2106, SIERRA_CMN_PLLLC_LF_COEFF_MODE0_PREG},
1153 {0x8A06, SIERRA_CMN_PLLLC_BWCAL_MODE1_PREG},
1154 {0x8A06, SIERRA_CMN_PLLLC_BWCAL_MODE0_PREG},
1155 {0x1B1B, SIERRA_CMN_PLLLC_SS_TIME_STEPSIZE_MODE_PREG}
1156};
1157
1158/* refclk100MHz_32b_PCIe_ln_ext_ssc */
1159static struct cdns_reg_pairs cdns_pcie_ln_regs_ext_ssc[] = {
Swapnil Jakhade960efc52022-01-28 13:41:47 +05301160 {0xFC08, SIERRA_DET_STANDEC_A_PREG},
1161 {0x001D, SIERRA_PSM_A3IN_TMR_PREG},
1162 {0x1555, SIERRA_DFE_BIASTRIM_PREG},
1163 {0x9703, SIERRA_DRVCTRL_BOOST_PREG},
Alan Douglas39b82332021-07-21 21:28:36 +05301164 {0x813E, SIERRA_CLKPATHCTRL_TMR_PREG},
1165 {0x8047, SIERRA_RX_CREQ_FLTR_A_MODE3_PREG},
1166 {0x808F, SIERRA_RX_CREQ_FLTR_A_MODE2_PREG},
1167 {0x808F, SIERRA_RX_CREQ_FLTR_A_MODE1_PREG},
1168 {0x808F, SIERRA_RX_CREQ_FLTR_A_MODE0_PREG},
Swapnil Jakhade960efc52022-01-28 13:41:47 +05301169 {0x0002, SIERRA_CREQ_DCBIASATTEN_OVR_PREG},
1170 {0x9800, SIERRA_RX_CTLE_CAL_PREG},
Alan Douglas39b82332021-07-21 21:28:36 +05301171 {0x033C, SIERRA_RX_CTLE_MAINTENANCE_PREG},
Swapnil Jakhade960efc52022-01-28 13:41:47 +05301172 {0x44CC, SIERRA_CREQ_EQ_OPEN_EYE_THRESH_PREG},
1173 {0x5624, SIERRA_DEQ_CONCUR_CTRL2_PREG},
1174 {0x000F, SIERRA_DEQ_EPIPWR_CTRL2_PREG},
1175 {0x00FF, SIERRA_DEQ_FAST_MAINT_CYCLES_PREG},
1176 {0x4C4C, SIERRA_DEQ_ERRCMP_CTRL_PREG},
1177 {0x02FA, SIERRA_DEQ_OFFSET_CTRL_PREG},
1178 {0x02FA, SIERRA_DEQ_GAIN_CTRL_PREG},
1179 {0x0041, SIERRA_DEQ_GLUT0},
1180 {0x0082, SIERRA_DEQ_GLUT1},
1181 {0x00C3, SIERRA_DEQ_GLUT2},
1182 {0x0145, SIERRA_DEQ_GLUT3},
1183 {0x0186, SIERRA_DEQ_GLUT4},
1184 {0x09E7, SIERRA_DEQ_ALUT0},
1185 {0x09A6, SIERRA_DEQ_ALUT1},
1186 {0x0965, SIERRA_DEQ_ALUT2},
1187 {0x08E3, SIERRA_DEQ_ALUT3},
1188 {0x00FA, SIERRA_DEQ_DFETAP0},
1189 {0x00FA, SIERRA_DEQ_DFETAP1},
1190 {0x00FA, SIERRA_DEQ_DFETAP2},
1191 {0x00FA, SIERRA_DEQ_DFETAP3},
1192 {0x00FA, SIERRA_DEQ_DFETAP4},
1193 {0x000F, SIERRA_DEQ_PRECUR_PREG},
1194 {0x0280, SIERRA_DEQ_POSTCUR_PREG},
1195 {0x8F00, SIERRA_DEQ_POSTCUR_DECR_PREG},
1196 {0x3C0F, SIERRA_DEQ_TAU_CTRL1_SLOW_MAINT_PREG},
1197 {0x1C0C, SIERRA_DEQ_TAU_CTRL2_PREG},
1198 {0x0100, SIERRA_DEQ_TAU_CTRL3_PREG},
1199 {0x5E82, SIERRA_DEQ_OPENEYE_CTRL_PREG},
1200 {0x002B, SIERRA_CPI_TRIM_PREG},
1201 {0x0003, SIERRA_EPI_CTRL_PREG},
1202 {0x803F, SIERRA_SDFILT_H2L_A_PREG},
1203 {0x0004, SIERRA_RXBUFFER_CTLECTRL_PREG},
1204 {0x2010, SIERRA_RXBUFFER_RCDFECTRL_PREG},
1205 {0x4432, SIERRA_RXBUFFER_DFECTRL_PREG}
Alan Douglas39b82332021-07-21 21:28:36 +05301206};
1207
Swapnil Jakhade14ed6702022-01-28 13:41:40 +05301208static struct cdns_sierra_vals pcie_100_ext_ssc_cmn_vals = {
1209 .reg_pairs = cdns_pcie_cmn_regs_ext_ssc,
1210 .num_regs = ARRAY_SIZE(cdns_pcie_cmn_regs_ext_ssc),
1211};
1212
1213static struct cdns_sierra_vals pcie_100_ext_ssc_ln_vals = {
1214 .reg_pairs = cdns_pcie_ln_regs_ext_ssc,
1215 .num_regs = ARRAY_SIZE(cdns_pcie_ln_regs_ext_ssc),
1216};
1217
Alan Douglas39b82332021-07-21 21:28:36 +05301218/* refclk100MHz_20b_USB_cmn_pll_ext_ssc */
1219static struct cdns_reg_pairs cdns_usb_cmn_regs_ext_ssc[] = {
1220 {0x2085, SIERRA_CMN_PLLLC_LF_COEFF_MODE1_PREG},
1221 {0x2085, SIERRA_CMN_PLLLC_LF_COEFF_MODE0_PREG},
1222 {0x0000, SIERRA_CMN_PLLLC_BWCAL_MODE0_PREG},
1223 {0x0000, SIERRA_CMN_PLLLC_SS_TIME_STEPSIZE_MODE_PREG}
1224};
1225
1226/* refclk100MHz_20b_USB_ln_ext_ssc */
1227static struct cdns_reg_pairs cdns_usb_ln_regs_ext_ssc[] = {
1228 {0xFE0A, SIERRA_DET_STANDEC_A_PREG},
1229 {0x000F, SIERRA_DET_STANDEC_B_PREG},
Sanket Parmar86866692022-01-28 13:41:28 +05301230 {0x55A5, SIERRA_DET_STANDEC_C_PREG},
Alan Douglas39b82332021-07-21 21:28:36 +05301231 {0x69ad, SIERRA_DET_STANDEC_D_PREG},
1232 {0x0241, SIERRA_DET_STANDEC_E_PREG},
Sanket Parmar86866692022-01-28 13:41:28 +05301233 {0x0110, SIERRA_PSM_LANECAL_DLY_A1_RESETS_PREG},
Alan Douglas39b82332021-07-21 21:28:36 +05301234 {0x0014, SIERRA_PSM_A0IN_TMR_PREG},
1235 {0xCF00, SIERRA_PSM_DIAG_PREG},
1236 {0x001F, SIERRA_PSC_TX_A0_PREG},
1237 {0x0007, SIERRA_PSC_TX_A1_PREG},
1238 {0x0003, SIERRA_PSC_TX_A2_PREG},
1239 {0x0003, SIERRA_PSC_TX_A3_PREG},
1240 {0x0FFF, SIERRA_PSC_RX_A0_PREG},
Sanket Parmar86866692022-01-28 13:41:28 +05301241 {0x0003, SIERRA_PSC_RX_A1_PREG},
Alan Douglas39b82332021-07-21 21:28:36 +05301242 {0x0003, SIERRA_PSC_RX_A2_PREG},
1243 {0x0001, SIERRA_PSC_RX_A3_PREG},
1244 {0x0001, SIERRA_PLLCTRL_SUBRATE_PREG},
1245 {0x0406, SIERRA_PLLCTRL_GEN_D_PREG},
1246 {0x5233, SIERRA_PLLCTRL_CPGAIN_MODE_PREG},
1247 {0x00CA, SIERRA_CLKPATH_BIASTRIM_PREG},
1248 {0x2512, SIERRA_DFE_BIASTRIM_PREG},
1249 {0x0000, SIERRA_DRVCTRL_ATTEN_PREG},
Sanket Parmar86866692022-01-28 13:41:28 +05301250 {0x823E, SIERRA_CLKPATHCTRL_TMR_PREG},
1251 {0x078F, SIERRA_RX_CREQ_FLTR_A_MODE1_PREG},
1252 {0x078F, SIERRA_RX_CREQ_FLTR_A_MODE0_PREG},
Alan Douglas39b82332021-07-21 21:28:36 +05301253 {0x7B3C, SIERRA_CREQ_CCLKDET_MODE01_PREG},
Sanket Parmar86866692022-01-28 13:41:28 +05301254 {0x023C, SIERRA_RX_CTLE_MAINTENANCE_PREG},
Alan Douglas39b82332021-07-21 21:28:36 +05301255 {0x3232, SIERRA_CREQ_FSMCLK_SEL_PREG},
1256 {0x0000, SIERRA_CREQ_EQ_CTRL_PREG},
Sanket Parmar86866692022-01-28 13:41:28 +05301257 {0x0000, SIERRA_CREQ_SPARE_PREG},
Alan Douglas39b82332021-07-21 21:28:36 +05301258 {0xCC44, SIERRA_CREQ_EQ_OPEN_EYE_THRESH_PREG},
Sanket Parmar86866692022-01-28 13:41:28 +05301259 {0x8452, SIERRA_CTLELUT_CTRL_PREG},
1260 {0x4121, SIERRA_DFE_ECMP_RATESEL_PREG},
1261 {0x4121, SIERRA_DFE_SMP_RATESEL_PREG},
1262 {0x0003, SIERRA_DEQ_PHALIGN_CTRL},
Alan Douglas39b82332021-07-21 21:28:36 +05301263 {0x3200, SIERRA_DEQ_CONCUR_CTRL1_PREG},
1264 {0x5064, SIERRA_DEQ_CONCUR_CTRL2_PREG},
1265 {0x0030, SIERRA_DEQ_EPIPWR_CTRL2_PREG},
1266 {0x0048, SIERRA_DEQ_FAST_MAINT_CYCLES_PREG},
1267 {0x5A5A, SIERRA_DEQ_ERRCMP_CTRL_PREG},
1268 {0x02F5, SIERRA_DEQ_OFFSET_CTRL_PREG},
1269 {0x02F5, SIERRA_DEQ_GAIN_CTRL_PREG},
Sanket Parmar86866692022-01-28 13:41:28 +05301270 {0x9999, SIERRA_DEQ_VGATUNE_CTRL_PREG},
Alan Douglas39b82332021-07-21 21:28:36 +05301271 {0x0014, SIERRA_DEQ_GLUT0},
1272 {0x0014, SIERRA_DEQ_GLUT1},
1273 {0x0014, SIERRA_DEQ_GLUT2},
1274 {0x0014, SIERRA_DEQ_GLUT3},
1275 {0x0014, SIERRA_DEQ_GLUT4},
1276 {0x0014, SIERRA_DEQ_GLUT5},
1277 {0x0014, SIERRA_DEQ_GLUT6},
1278 {0x0014, SIERRA_DEQ_GLUT7},
1279 {0x0014, SIERRA_DEQ_GLUT8},
1280 {0x0014, SIERRA_DEQ_GLUT9},
1281 {0x0014, SIERRA_DEQ_GLUT10},
1282 {0x0014, SIERRA_DEQ_GLUT11},
1283 {0x0014, SIERRA_DEQ_GLUT12},
1284 {0x0014, SIERRA_DEQ_GLUT13},
1285 {0x0014, SIERRA_DEQ_GLUT14},
1286 {0x0014, SIERRA_DEQ_GLUT15},
1287 {0x0014, SIERRA_DEQ_GLUT16},
1288 {0x0BAE, SIERRA_DEQ_ALUT0},
1289 {0x0AEB, SIERRA_DEQ_ALUT1},
1290 {0x0A28, SIERRA_DEQ_ALUT2},
1291 {0x0965, SIERRA_DEQ_ALUT3},
1292 {0x08A2, SIERRA_DEQ_ALUT4},
1293 {0x07DF, SIERRA_DEQ_ALUT5},
1294 {0x071C, SIERRA_DEQ_ALUT6},
1295 {0x0659, SIERRA_DEQ_ALUT7},
1296 {0x0596, SIERRA_DEQ_ALUT8},
1297 {0x0514, SIERRA_DEQ_ALUT9},
1298 {0x0492, SIERRA_DEQ_ALUT10},
1299 {0x0410, SIERRA_DEQ_ALUT11},
1300 {0x038E, SIERRA_DEQ_ALUT12},
1301 {0x030C, SIERRA_DEQ_ALUT13},
1302 {0x03F4, SIERRA_DEQ_DFETAP_CTRL_PREG},
1303 {0x0001, SIERRA_DFE_EN_1010_IGNORE_PREG},
1304 {0x3C01, SIERRA_DEQ_TAU_CTRL1_FAST_MAINT_PREG},
1305 {0x3C40, SIERRA_DEQ_TAU_CTRL1_SLOW_MAINT_PREG},
1306 {0x1C08, SIERRA_DEQ_TAU_CTRL2_PREG},
1307 {0x0033, SIERRA_DEQ_PICTRL_PREG},
1308 {0x0400, SIERRA_CPICAL_TMRVAL_MODE1_PREG},
1309 {0x0330, SIERRA_CPICAL_TMRVAL_MODE0_PREG},
1310 {0x01FF, SIERRA_CPICAL_PICNT_MODE1_PREG},
1311 {0x0009, SIERRA_CPI_OUTBUF_RATESEL_PREG},
1312 {0x3232, SIERRA_CPICAL_RES_STARTCODE_MODE23_PREG},
1313 {0x0005, SIERRA_LFPSDET_SUPPORT_PREG},
1314 {0x000F, SIERRA_LFPSFILT_NS_PREG},
1315 {0x0009, SIERRA_LFPSFILT_RD_PREG},
1316 {0x0001, SIERRA_LFPSFILT_MP_PREG},
Sanket Parmar86866692022-01-28 13:41:28 +05301317 {0x6013, SIERRA_SIGDET_SUPPORT_PREG},
Alan Douglas39b82332021-07-21 21:28:36 +05301318 {0x8013, SIERRA_SDFILT_H2L_A_PREG},
1319 {0x8009, SIERRA_SDFILT_L2H_PREG},
1320 {0x0024, SIERRA_RXBUFFER_CTLECTRL_PREG},
1321 {0x0020, SIERRA_RXBUFFER_RCDFECTRL_PREG},
1322 {0x4243, SIERRA_RXBUFFER_DFECTRL_PREG}
1323};
1324
Swapnil Jakhade14ed6702022-01-28 13:41:40 +05301325static struct cdns_sierra_vals usb_100_ext_ssc_cmn_vals = {
1326 .reg_pairs = cdns_usb_cmn_regs_ext_ssc,
1327 .num_regs = ARRAY_SIZE(cdns_usb_cmn_regs_ext_ssc),
1328};
1329
1330static struct cdns_sierra_vals usb_100_ext_ssc_ln_vals = {
1331 .reg_pairs = cdns_usb_ln_regs_ext_ssc,
1332 .num_regs = ARRAY_SIZE(cdns_usb_ln_regs_ext_ssc),
1333};
1334
Alan Douglas39b82332021-07-21 21:28:36 +05301335static const struct cdns_sierra_data cdns_map_sierra = {
Swapnil Jakhade14ed6702022-01-28 13:41:40 +05301336 .id_value = SIERRA_MACRO_ID,
1337 .block_offset_shift = 0x2,
1338 .reg_offset_shift = 0x2,
Swapnil Jakhade990ce532022-01-28 13:41:44 +05301339 .pcs_cmn_vals = {
1340 [TYPE_PCIE] = {
1341 [TYPE_NONE] = {
Swapnil Jakhade960efc52022-01-28 13:41:47 +05301342 [NO_SSC] = &pcie_phy_pcs_cmn_vals,
Swapnil Jakhade990ce532022-01-28 13:41:44 +05301343 [EXTERNAL_SSC] = &pcie_phy_pcs_cmn_vals,
Swapnil Jakhade960efc52022-01-28 13:41:47 +05301344 [INTERNAL_SSC] = &pcie_phy_pcs_cmn_vals,
Swapnil Jakhade990ce532022-01-28 13:41:44 +05301345 },
1346 },
1347 },
Swapnil Jakhade14ed6702022-01-28 13:41:40 +05301348 .pma_cmn_vals = {
1349 [TYPE_PCIE] = {
1350 [TYPE_NONE] = {
Swapnil Jakhade960efc52022-01-28 13:41:47 +05301351 [NO_SSC] = &pcie_100_no_ssc_cmn_vals,
1352 [EXTERNAL_SSC] = &pcie_100_ext_ssc_cmn_vals,
1353 [INTERNAL_SSC] = &pcie_100_int_ssc_cmn_vals
Swapnil Jakhade14ed6702022-01-28 13:41:40 +05301354 },
Swapnil Jakhade960efc52022-01-28 13:41:47 +05301355 },
Swapnil Jakhade14ed6702022-01-28 13:41:40 +05301356 [TYPE_USB] = {
1357 [TYPE_NONE] = {
1358 [EXTERNAL_SSC] = &usb_100_ext_ssc_cmn_vals,
1359 },
1360 },
1361 },
1362 .pma_ln_vals = {
1363 [TYPE_PCIE] = {
1364 [TYPE_NONE] = {
Swapnil Jakhade960efc52022-01-28 13:41:47 +05301365 [NO_SSC] = &pcie_100_no_ssc_ln_vals,
Swapnil Jakhade14ed6702022-01-28 13:41:40 +05301366 [EXTERNAL_SSC] = &pcie_100_ext_ssc_ln_vals,
Swapnil Jakhade960efc52022-01-28 13:41:47 +05301367 [INTERNAL_SSC] = &pcie_100_int_ssc_ln_vals,
Swapnil Jakhade14ed6702022-01-28 13:41:40 +05301368 },
1369 },
1370 [TYPE_USB] = {
1371 [TYPE_NONE] = {
1372 [EXTERNAL_SSC] = &usb_100_ext_ssc_ln_vals,
1373 },
1374 },
1375 },
Alan Douglas39b82332021-07-21 21:28:36 +05301376};
1377
1378static const struct cdns_sierra_data cdns_ti_map_sierra = {
Swapnil Jakhade14ed6702022-01-28 13:41:40 +05301379 .id_value = SIERRA_MACRO_ID,
1380 .block_offset_shift = 0x0,
1381 .reg_offset_shift = 0x1,
Swapnil Jakhade990ce532022-01-28 13:41:44 +05301382 .pcs_cmn_vals = {
1383 [TYPE_PCIE] = {
1384 [TYPE_NONE] = {
Swapnil Jakhade960efc52022-01-28 13:41:47 +05301385 [NO_SSC] = &pcie_phy_pcs_cmn_vals,
Swapnil Jakhade990ce532022-01-28 13:41:44 +05301386 [EXTERNAL_SSC] = &pcie_phy_pcs_cmn_vals,
Swapnil Jakhade960efc52022-01-28 13:41:47 +05301387 [INTERNAL_SSC] = &pcie_phy_pcs_cmn_vals,
Swapnil Jakhade990ce532022-01-28 13:41:44 +05301388 },
1389 },
1390 },
Swapnil Jakhade14ed6702022-01-28 13:41:40 +05301391 .pma_cmn_vals = {
1392 [TYPE_PCIE] = {
1393 [TYPE_NONE] = {
Swapnil Jakhade960efc52022-01-28 13:41:47 +05301394 [NO_SSC] = &pcie_100_no_ssc_cmn_vals,
Swapnil Jakhade14ed6702022-01-28 13:41:40 +05301395 [EXTERNAL_SSC] = &pcie_100_ext_ssc_cmn_vals,
Swapnil Jakhade960efc52022-01-28 13:41:47 +05301396 [INTERNAL_SSC] = &pcie_100_int_ssc_cmn_vals,
Swapnil Jakhade14ed6702022-01-28 13:41:40 +05301397 },
1398 },
1399 [TYPE_USB] = {
1400 [TYPE_NONE] = {
1401 [EXTERNAL_SSC] = &usb_100_ext_ssc_cmn_vals,
1402 },
1403 },
1404 },
1405 .pma_ln_vals = {
1406 [TYPE_PCIE] = {
1407 [TYPE_NONE] = {
Swapnil Jakhade960efc52022-01-28 13:41:47 +05301408 [NO_SSC] = &pcie_100_no_ssc_ln_vals,
Swapnil Jakhade14ed6702022-01-28 13:41:40 +05301409 [EXTERNAL_SSC] = &pcie_100_ext_ssc_ln_vals,
Swapnil Jakhade960efc52022-01-28 13:41:47 +05301410 [INTERNAL_SSC] = &pcie_100_int_ssc_ln_vals,
Swapnil Jakhade14ed6702022-01-28 13:41:40 +05301411 },
1412 },
1413 [TYPE_USB] = {
1414 [TYPE_NONE] = {
1415 [EXTERNAL_SSC] = &usb_100_ext_ssc_ln_vals,
1416 },
1417 },
1418 },
Alan Douglas39b82332021-07-21 21:28:36 +05301419};
1420
1421static const struct udevice_id cdns_sierra_id_table[] = {
1422 {
1423 .compatible = "cdns,sierra-phy-t0",
1424 .data = (ulong)&cdns_map_sierra,
1425 },
1426 {
1427 .compatible = "ti,sierra-phy-t0",
1428 .data = (ulong)&cdns_ti_map_sierra,
1429 },
1430 {}
1431};
1432
1433U_BOOT_DRIVER(sierra_phy_provider) = {
1434 .name = "cdns,sierra",
1435 .id = UCLASS_PHY,
1436 .of_match = cdns_sierra_id_table,
1437 .probe = cdns_sierra_phy_probe,
1438 .remove = cdns_sierra_phy_remove,
1439 .ops = &ops,
1440 .priv_auto = sizeof(struct cdns_sierra_phy),
1441};