blob: 8f356bf38be8a36cbe18aaf1feaa641f45cacb21 [file] [log] [blame]
Alan Douglas44d30d62018-11-12 16:42:16 +00001// SPDX-License-Identifier: GPL-2.0
2/*
3 * Cadence Sierra PHY Driver
4 *
5 * Copyright (c) 2018 Cadence Design Systems
6 * Author: Alan Douglas <adouglas@cadence.com>
7 *
8 */
9#include <linux/clk.h>
Kishon Vijay Abraham I28081b72021-03-19 18:11:27 +053010#include <linux/clk-provider.h>
Alan Douglas44d30d62018-11-12 16:42:16 +000011#include <linux/delay.h>
12#include <linux/err.h>
13#include <linux/io.h>
14#include <linux/module.h>
15#include <linux/phy/phy.h>
16#include <linux/platform_device.h>
17#include <linux/pm_runtime.h>
18#include <linux/regmap.h>
19#include <linux/reset.h>
20#include <linux/slab.h>
21#include <linux/of.h>
22#include <linux/of_platform.h>
23#include <dt-bindings/phy/phy.h>
Kishon Vijay Abraham I28081b72021-03-19 18:11:27 +053024#include <dt-bindings/phy/phy-cadence.h>
Alan Douglas44d30d62018-11-12 16:42:16 +000025
Swapnil Jakhade078e9e92021-12-23 07:01:24 +010026#define NUM_SSC_MODE 3
Swapnil Jakhade6b81f052021-12-23 07:01:34 +010027#define NUM_PHY_TYPE 4
Swapnil Jakhade078e9e92021-12-23 07:01:24 +010028
Alan Douglas44d30d62018-11-12 16:42:16 +000029/* PHY register offsets */
Anil Varughese871002d2019-12-16 15:27:05 +053030#define SIERRA_COMMON_CDB_OFFSET 0x0
31#define SIERRA_MACRO_ID_REG 0x0
Kishon Vijay Abraham I28081b72021-03-19 18:11:27 +053032#define SIERRA_CMN_PLLLC_GEN_PREG 0x42
Anil Varughese871002d2019-12-16 15:27:05 +053033#define SIERRA_CMN_PLLLC_MODE_PREG 0x48
34#define SIERRA_CMN_PLLLC_LF_COEFF_MODE1_PREG 0x49
35#define SIERRA_CMN_PLLLC_LF_COEFF_MODE0_PREG 0x4A
36#define SIERRA_CMN_PLLLC_LOCK_CNTSTART_PREG 0x4B
37#define SIERRA_CMN_PLLLC_BWCAL_MODE1_PREG 0x4F
38#define SIERRA_CMN_PLLLC_BWCAL_MODE0_PREG 0x50
Swapnil Jakhade7a5ad9b2021-12-23 07:01:32 +010039#define SIERRA_CMN_PLLLC_DSMCORR_PREG 0x51
40#define SIERRA_CMN_PLLLC_SS_PREG 0x52
41#define SIERRA_CMN_PLLLC_SS_AMP_STEP_SIZE_PREG 0x53
42#define SIERRA_CMN_PLLLC_SSTWOPT_PREG 0x54
Anil Varughese871002d2019-12-16 15:27:05 +053043#define SIERRA_CMN_PLLLC_SS_TIME_STEPSIZE_MODE_PREG 0x62
Swapnil Jakhade7a5ad9b2021-12-23 07:01:32 +010044#define SIERRA_CMN_PLLLC_LOCK_DELAY_CTRL_PREG 0x63
Kishon Vijay Abraham I28081b72021-03-19 18:11:27 +053045#define SIERRA_CMN_REFRCV_PREG 0x98
46#define SIERRA_CMN_REFRCV1_PREG 0xB8
47#define SIERRA_CMN_PLLLC1_GEN_PREG 0xC2
Kishon Vijay Abraham I380f5702019-12-16 15:27:01 +053048
49#define SIERRA_LANE_CDB_OFFSET(ln, block_offset, reg_offset) \
50 ((0x4000 << (block_offset)) + \
51 (((ln) << 9) << (reg_offset)))
Kishon Vijay Abraham Iaead5fd2019-12-16 15:27:04 +053052
Anil Varughese871002d2019-12-16 15:27:05 +053053#define SIERRA_DET_STANDEC_A_PREG 0x000
54#define SIERRA_DET_STANDEC_B_PREG 0x001
55#define SIERRA_DET_STANDEC_C_PREG 0x002
56#define SIERRA_DET_STANDEC_D_PREG 0x003
57#define SIERRA_DET_STANDEC_E_PREG 0x004
58#define SIERRA_PSM_LANECAL_DLY_A1_RESETS_PREG 0x008
59#define SIERRA_PSM_A0IN_TMR_PREG 0x009
Swapnil Jakhade7a5ad9b2021-12-23 07:01:32 +010060#define SIERRA_PSM_A3IN_TMR_PREG 0x00C
Anil Varughese871002d2019-12-16 15:27:05 +053061#define SIERRA_PSM_DIAG_PREG 0x015
62#define SIERRA_PSC_TX_A0_PREG 0x028
63#define SIERRA_PSC_TX_A1_PREG 0x029
64#define SIERRA_PSC_TX_A2_PREG 0x02A
65#define SIERRA_PSC_TX_A3_PREG 0x02B
66#define SIERRA_PSC_RX_A0_PREG 0x030
67#define SIERRA_PSC_RX_A1_PREG 0x031
68#define SIERRA_PSC_RX_A2_PREG 0x032
69#define SIERRA_PSC_RX_A3_PREG 0x033
70#define SIERRA_PLLCTRL_SUBRATE_PREG 0x03A
71#define SIERRA_PLLCTRL_GEN_D_PREG 0x03E
72#define SIERRA_PLLCTRL_CPGAIN_MODE_PREG 0x03F
Kishon Vijay Abraham Iadc4bd62019-12-16 15:27:07 +053073#define SIERRA_PLLCTRL_STATUS_PREG 0x044
Anil Varughese871002d2019-12-16 15:27:05 +053074#define SIERRA_CLKPATH_BIASTRIM_PREG 0x04B
75#define SIERRA_DFE_BIASTRIM_PREG 0x04C
76#define SIERRA_DRVCTRL_ATTEN_PREG 0x06A
Swapnil Jakhade7a5ad9b2021-12-23 07:01:32 +010077#define SIERRA_DRVCTRL_BOOST_PREG 0x06F
Anil Varughese871002d2019-12-16 15:27:05 +053078#define SIERRA_CLKPATHCTRL_TMR_PREG 0x081
79#define SIERRA_RX_CREQ_FLTR_A_MODE3_PREG 0x085
80#define SIERRA_RX_CREQ_FLTR_A_MODE2_PREG 0x086
81#define SIERRA_RX_CREQ_FLTR_A_MODE1_PREG 0x087
82#define SIERRA_RX_CREQ_FLTR_A_MODE0_PREG 0x088
Swapnil Jakhade7a5ad9b2021-12-23 07:01:32 +010083#define SIERRA_CREQ_DCBIASATTEN_OVR_PREG 0x08C
Anil Varughese871002d2019-12-16 15:27:05 +053084#define SIERRA_CREQ_CCLKDET_MODE01_PREG 0x08E
Swapnil Jakhade7a5ad9b2021-12-23 07:01:32 +010085#define SIERRA_RX_CTLE_CAL_PREG 0x08F
Anil Varughese871002d2019-12-16 15:27:05 +053086#define SIERRA_RX_CTLE_MAINTENANCE_PREG 0x091
87#define SIERRA_CREQ_FSMCLK_SEL_PREG 0x092
88#define SIERRA_CREQ_EQ_CTRL_PREG 0x093
89#define SIERRA_CREQ_SPARE_PREG 0x096
90#define SIERRA_CREQ_EQ_OPEN_EYE_THRESH_PREG 0x097
91#define SIERRA_CTLELUT_CTRL_PREG 0x098
92#define SIERRA_DFE_ECMP_RATESEL_PREG 0x0C0
93#define SIERRA_DFE_SMP_RATESEL_PREG 0x0C1
94#define SIERRA_DEQ_PHALIGN_CTRL 0x0C4
95#define SIERRA_DEQ_CONCUR_CTRL1_PREG 0x0C8
96#define SIERRA_DEQ_CONCUR_CTRL2_PREG 0x0C9
97#define SIERRA_DEQ_EPIPWR_CTRL2_PREG 0x0CD
98#define SIERRA_DEQ_FAST_MAINT_CYCLES_PREG 0x0CE
99#define SIERRA_DEQ_ERRCMP_CTRL_PREG 0x0D0
100#define SIERRA_DEQ_OFFSET_CTRL_PREG 0x0D8
101#define SIERRA_DEQ_GAIN_CTRL_PREG 0x0E0
102#define SIERRA_DEQ_VGATUNE_CTRL_PREG 0x0E1
103#define SIERRA_DEQ_GLUT0 0x0E8
104#define SIERRA_DEQ_GLUT1 0x0E9
105#define SIERRA_DEQ_GLUT2 0x0EA
106#define SIERRA_DEQ_GLUT3 0x0EB
107#define SIERRA_DEQ_GLUT4 0x0EC
108#define SIERRA_DEQ_GLUT5 0x0ED
109#define SIERRA_DEQ_GLUT6 0x0EE
110#define SIERRA_DEQ_GLUT7 0x0EF
111#define SIERRA_DEQ_GLUT8 0x0F0
112#define SIERRA_DEQ_GLUT9 0x0F1
113#define SIERRA_DEQ_GLUT10 0x0F2
114#define SIERRA_DEQ_GLUT11 0x0F3
115#define SIERRA_DEQ_GLUT12 0x0F4
116#define SIERRA_DEQ_GLUT13 0x0F5
117#define SIERRA_DEQ_GLUT14 0x0F6
118#define SIERRA_DEQ_GLUT15 0x0F7
119#define SIERRA_DEQ_GLUT16 0x0F8
120#define SIERRA_DEQ_ALUT0 0x108
121#define SIERRA_DEQ_ALUT1 0x109
122#define SIERRA_DEQ_ALUT2 0x10A
123#define SIERRA_DEQ_ALUT3 0x10B
124#define SIERRA_DEQ_ALUT4 0x10C
125#define SIERRA_DEQ_ALUT5 0x10D
126#define SIERRA_DEQ_ALUT6 0x10E
127#define SIERRA_DEQ_ALUT7 0x10F
128#define SIERRA_DEQ_ALUT8 0x110
129#define SIERRA_DEQ_ALUT9 0x111
130#define SIERRA_DEQ_ALUT10 0x112
131#define SIERRA_DEQ_ALUT11 0x113
132#define SIERRA_DEQ_ALUT12 0x114
133#define SIERRA_DEQ_ALUT13 0x115
134#define SIERRA_DEQ_DFETAP_CTRL_PREG 0x128
Swapnil Jakhade7a5ad9b2021-12-23 07:01:32 +0100135#define SIERRA_DEQ_DFETAP0 0x129
136#define SIERRA_DEQ_DFETAP1 0x12B
137#define SIERRA_DEQ_DFETAP2 0x12D
138#define SIERRA_DEQ_DFETAP3 0x12F
139#define SIERRA_DEQ_DFETAP4 0x131
Anil Varughese871002d2019-12-16 15:27:05 +0530140#define SIERRA_DFE_EN_1010_IGNORE_PREG 0x134
Swapnil Jakhade7a5ad9b2021-12-23 07:01:32 +0100141#define SIERRA_DEQ_PRECUR_PREG 0x138
142#define SIERRA_DEQ_POSTCUR_PREG 0x140
143#define SIERRA_DEQ_POSTCUR_DECR_PREG 0x142
Anil Varughese871002d2019-12-16 15:27:05 +0530144#define SIERRA_DEQ_TAU_CTRL1_SLOW_MAINT_PREG 0x150
145#define SIERRA_DEQ_TAU_CTRL2_PREG 0x151
Swapnil Jakhade7a5ad9b2021-12-23 07:01:32 +0100146#define SIERRA_DEQ_TAU_CTRL3_PREG 0x152
147#define SIERRA_DEQ_OPENEYE_CTRL_PREG 0x158
Anil Varughese871002d2019-12-16 15:27:05 +0530148#define SIERRA_DEQ_PICTRL_PREG 0x161
149#define SIERRA_CPICAL_TMRVAL_MODE1_PREG 0x170
150#define SIERRA_CPICAL_TMRVAL_MODE0_PREG 0x171
151#define SIERRA_CPICAL_PICNT_MODE1_PREG 0x174
152#define SIERRA_CPI_OUTBUF_RATESEL_PREG 0x17C
Swapnil Jakhade7a5ad9b2021-12-23 07:01:32 +0100153#define SIERRA_CPI_TRIM_PREG 0x17F
Anil Varughese871002d2019-12-16 15:27:05 +0530154#define SIERRA_CPICAL_RES_STARTCODE_MODE23_PREG 0x183
Swapnil Jakhade7a5ad9b2021-12-23 07:01:32 +0100155#define SIERRA_EPI_CTRL_PREG 0x187
Anil Varughese871002d2019-12-16 15:27:05 +0530156#define SIERRA_LFPSDET_SUPPORT_PREG 0x188
157#define SIERRA_LFPSFILT_NS_PREG 0x18A
158#define SIERRA_LFPSFILT_RD_PREG 0x18B
159#define SIERRA_LFPSFILT_MP_PREG 0x18C
160#define SIERRA_SIGDET_SUPPORT_PREG 0x190
161#define SIERRA_SDFILT_H2L_A_PREG 0x191
162#define SIERRA_SDFILT_L2H_PREG 0x193
163#define SIERRA_RXBUFFER_CTLECTRL_PREG 0x19E
164#define SIERRA_RXBUFFER_RCDFECTRL_PREG 0x19F
165#define SIERRA_RXBUFFER_DFECTRL_PREG 0x1A0
166#define SIERRA_DEQ_TAU_CTRL1_FAST_MAINT_PREG 0x14F
167#define SIERRA_DEQ_TAU_CTRL1_SLOW_MAINT_PREG 0x150
Kishon Vijay Abraham I380f5702019-12-16 15:27:01 +0530168
Swapnil Jakhade8c95e172021-12-23 07:01:28 +0100169/* PHY PCS common registers */
170#define SIERRA_PHY_PCS_COMMON_OFFSET(block_offset) \
171 (0xc000 << (block_offset))
Swapnil Jakhadefa105172021-12-23 07:01:29 +0100172#define SIERRA_PHY_PIPE_CMN_CTRL1 0x0
Anil Varughese871002d2019-12-16 15:27:05 +0530173#define SIERRA_PHY_PLL_CFG 0xe
Alan Douglas44d30d62018-11-12 16:42:16 +0000174
Swapnil Jakhade36ce4162021-12-23 07:01:31 +0100175/* PHY PCS lane registers */
176#define SIERRA_PHY_PCS_LANE_CDB_OFFSET(ln, block_offset, reg_offset) \
177 ((0xD000 << (block_offset)) + \
178 (((ln) << 8) << (reg_offset)))
179
180#define SIERRA_PHY_ISO_LINK_CTRL 0xB
181
Swapnil Jakhadef1cc6c32021-12-23 07:01:30 +0100182/* PHY PMA common registers */
183#define SIERRA_PHY_PMA_COMMON_OFFSET(block_offset) \
184 (0xE000 << (block_offset))
185#define SIERRA_PHY_PMA_CMN_CTRL 0x000
186
Swapnil Jakhade6b81f052021-12-23 07:01:34 +0100187/* PHY PMA lane registers */
188#define SIERRA_PHY_PMA_LANE_CDB_OFFSET(ln, block_offset, reg_offset) \
189 ((0xF000 << (block_offset)) + \
190 (((ln) << 8) << (reg_offset)))
191
192#define SIERRA_PHY_PMA_XCVR_CTRL 0x000
193
Anil Varughese871002d2019-12-16 15:27:05 +0530194#define SIERRA_MACRO_ID 0x00007364
Kishon Vijay Abraham Ia43f72a2019-12-16 15:27:08 +0530195#define SIERRA_MAX_LANES 16
Kishon Vijay Abraham Iadc4bd62019-12-16 15:27:07 +0530196#define PLL_LOCK_TIME 100000
Alan Douglas44d30d62018-11-12 16:42:16 +0000197
Kishon Vijay Abraham I28081b72021-03-19 18:11:27 +0530198#define CDNS_SIERRA_OUTPUT_CLOCKS 2
199#define CDNS_SIERRA_INPUT_CLOCKS 5
Kishon Vijay Abraham Ia0c30cd2021-03-19 18:11:24 +0530200enum cdns_sierra_clock_input {
201 PHY_CLK,
202 CMN_REFCLK_DIG_DIV,
203 CMN_REFCLK1_DIG_DIV,
Kishon Vijay Abraham I28081b72021-03-19 18:11:27 +0530204 PLL0_REFCLK,
205 PLL1_REFCLK,
Kishon Vijay Abraham Ia0c30cd2021-03-19 18:11:24 +0530206};
207
Kishon Vijay Abraham I28081b72021-03-19 18:11:27 +0530208#define SIERRA_NUM_CMN_PLLC 2
209#define SIERRA_NUM_CMN_PLLC_PARENTS 2
210
Kishon Vijay Abraham I380f5702019-12-16 15:27:01 +0530211static const struct reg_field macro_id_type =
212 REG_FIELD(SIERRA_MACRO_ID_REG, 0, 15);
213static const struct reg_field phy_pll_cfg_1 =
214 REG_FIELD(SIERRA_PHY_PLL_CFG, 1, 1);
Swapnil Jakhadef1cc6c32021-12-23 07:01:30 +0100215static const struct reg_field pma_cmn_ready =
216 REG_FIELD(SIERRA_PHY_PMA_CMN_CTRL, 0, 0);
Kishon Vijay Abraham Iadc4bd62019-12-16 15:27:07 +0530217static const struct reg_field pllctrl_lock =
218 REG_FIELD(SIERRA_PLLCTRL_STATUS_PREG, 0, 0);
Swapnil Jakhade36ce4162021-12-23 07:01:31 +0100219static const struct reg_field phy_iso_link_ctrl_1 =
220 REG_FIELD(SIERRA_PHY_ISO_LINK_CTRL, 1, 1);
Kishon Vijay Abraham I380f5702019-12-16 15:27:01 +0530221
Kishon Vijay Abraham I28081b72021-03-19 18:11:27 +0530222static const char * const clk_names[] = {
223 [CDNS_SIERRA_PLL_CMNLC] = "pll_cmnlc",
224 [CDNS_SIERRA_PLL_CMNLC1] = "pll_cmnlc1",
225};
226
227enum cdns_sierra_cmn_plllc {
228 CMN_PLLLC,
229 CMN_PLLLC1,
230};
231
232struct cdns_sierra_pll_mux_reg_fields {
233 struct reg_field pfdclk_sel_preg;
234 struct reg_field plllc1en_field;
235 struct reg_field termen_field;
236};
237
238static const struct cdns_sierra_pll_mux_reg_fields cmn_plllc_pfdclk1_sel_preg[] = {
239 [CMN_PLLLC] = {
240 .pfdclk_sel_preg = REG_FIELD(SIERRA_CMN_PLLLC_GEN_PREG, 1, 1),
241 .plllc1en_field = REG_FIELD(SIERRA_CMN_REFRCV1_PREG, 8, 8),
242 .termen_field = REG_FIELD(SIERRA_CMN_REFRCV1_PREG, 0, 0),
243 },
244 [CMN_PLLLC1] = {
245 .pfdclk_sel_preg = REG_FIELD(SIERRA_CMN_PLLLC1_GEN_PREG, 1, 1),
246 .plllc1en_field = REG_FIELD(SIERRA_CMN_REFRCV_PREG, 8, 8),
247 .termen_field = REG_FIELD(SIERRA_CMN_REFRCV_PREG, 0, 0),
248 },
249};
250
251struct cdns_sierra_pll_mux {
252 struct clk_hw hw;
253 struct regmap_field *pfdclk_sel_preg;
254 struct regmap_field *plllc1en_field;
255 struct regmap_field *termen_field;
256 struct clk_init_data clk_data;
257};
258
259#define to_cdns_sierra_pll_mux(_hw) \
260 container_of(_hw, struct cdns_sierra_pll_mux, hw)
261
262static const int pll_mux_parent_index[][SIERRA_NUM_CMN_PLLC_PARENTS] = {
263 [CMN_PLLLC] = { PLL0_REFCLK, PLL1_REFCLK },
264 [CMN_PLLLC1] = { PLL1_REFCLK, PLL0_REFCLK },
265};
266
Swapnil Jakhadeda08aab2021-12-23 07:01:33 +0100267static u32 cdns_sierra_pll_mux_table[][SIERRA_NUM_CMN_PLLC_PARENTS] = {
268 [CMN_PLLLC] = { 0, 1 },
269 [CMN_PLLLC1] = { 1, 0 },
270};
Kishon Vijay Abraham I28081b72021-03-19 18:11:27 +0530271
Swapnil Jakhade078e9e92021-12-23 07:01:24 +0100272enum cdns_sierra_phy_type {
273 TYPE_NONE,
274 TYPE_PCIE,
275 TYPE_USB
276};
277
278enum cdns_sierra_ssc_mode {
279 NO_SSC,
280 EXTERNAL_SSC,
281 INTERNAL_SSC
282};
283
Alan Douglas44d30d62018-11-12 16:42:16 +0000284struct cdns_sierra_inst {
285 struct phy *phy;
Swapnil Jakhade078e9e92021-12-23 07:01:24 +0100286 enum cdns_sierra_phy_type phy_type;
Alan Douglas44d30d62018-11-12 16:42:16 +0000287 u32 num_lanes;
288 u32 mlane;
289 struct reset_control *lnk_rst;
Swapnil Jakhade1e902b22021-12-23 07:01:27 +0100290 enum cdns_sierra_ssc_mode ssc_mode;
Alan Douglas44d30d62018-11-12 16:42:16 +0000291};
292
293struct cdns_reg_pairs {
294 u16 val;
295 u32 off;
296};
297
Swapnil Jakhade078e9e92021-12-23 07:01:24 +0100298struct cdns_sierra_vals {
299 const struct cdns_reg_pairs *reg_pairs;
300 u32 num_regs;
301};
302
Alan Douglas44d30d62018-11-12 16:42:16 +0000303struct cdns_sierra_data {
Swapnil Jakhade078e9e92021-12-23 07:01:24 +0100304 u32 id_value;
305 u8 block_offset_shift;
306 u8 reg_offset_shift;
Swapnil Jakhadefa105172021-12-23 07:01:29 +0100307 struct cdns_sierra_vals *pcs_cmn_vals[NUM_PHY_TYPE][NUM_PHY_TYPE]
308 [NUM_SSC_MODE];
Swapnil Jakhade6b81f052021-12-23 07:01:34 +0100309 struct cdns_sierra_vals *phy_pma_ln_vals[NUM_PHY_TYPE][NUM_PHY_TYPE]
310 [NUM_SSC_MODE];
Swapnil Jakhade078e9e92021-12-23 07:01:24 +0100311 struct cdns_sierra_vals *pma_cmn_vals[NUM_PHY_TYPE][NUM_PHY_TYPE]
312 [NUM_SSC_MODE];
313 struct cdns_sierra_vals *pma_ln_vals[NUM_PHY_TYPE][NUM_PHY_TYPE]
314 [NUM_SSC_MODE];
Alan Douglas44d30d62018-11-12 16:42:16 +0000315};
316
Kishon Vijay Abraham I380f5702019-12-16 15:27:01 +0530317struct cdns_regmap_cdb_context {
Alan Douglas44d30d62018-11-12 16:42:16 +0000318 struct device *dev;
319 void __iomem *base;
Kishon Vijay Abraham I380f5702019-12-16 15:27:01 +0530320 u8 reg_offset_shift;
321};
322
323struct cdns_sierra_phy {
324 struct device *dev;
325 struct regmap *regmap;
Swapnil Jakhadec3c11d52021-12-23 07:01:23 +0100326 const struct cdns_sierra_data *init_data;
Alan Douglas44d30d62018-11-12 16:42:16 +0000327 struct cdns_sierra_inst phys[SIERRA_MAX_LANES];
328 struct reset_control *phy_rst;
329 struct reset_control *apb_rst;
Kishon Vijay Abraham I380f5702019-12-16 15:27:01 +0530330 struct regmap *regmap_lane_cdb[SIERRA_MAX_LANES];
Swapnil Jakhade8c95e172021-12-23 07:01:28 +0100331 struct regmap *regmap_phy_pcs_common_cdb;
Swapnil Jakhade36ce4162021-12-23 07:01:31 +0100332 struct regmap *regmap_phy_pcs_lane_cdb[SIERRA_MAX_LANES];
Swapnil Jakhadef1cc6c32021-12-23 07:01:30 +0100333 struct regmap *regmap_phy_pma_common_cdb;
Swapnil Jakhade6b81f052021-12-23 07:01:34 +0100334 struct regmap *regmap_phy_pma_lane_cdb[SIERRA_MAX_LANES];
Kishon Vijay Abraham I380f5702019-12-16 15:27:01 +0530335 struct regmap *regmap_common_cdb;
336 struct regmap_field *macro_id_type;
337 struct regmap_field *phy_pll_cfg_1;
Swapnil Jakhadef1cc6c32021-12-23 07:01:30 +0100338 struct regmap_field *pma_cmn_ready;
Kishon Vijay Abraham Iadc4bd62019-12-16 15:27:07 +0530339 struct regmap_field *pllctrl_lock[SIERRA_MAX_LANES];
Swapnil Jakhade36ce4162021-12-23 07:01:31 +0100340 struct regmap_field *phy_iso_link_ctrl_1[SIERRA_MAX_LANES];
Kishon Vijay Abraham I28081b72021-03-19 18:11:27 +0530341 struct regmap_field *cmn_refrcv_refclk_plllc1en_preg[SIERRA_NUM_CMN_PLLC];
342 struct regmap_field *cmn_refrcv_refclk_termen_preg[SIERRA_NUM_CMN_PLLC];
343 struct regmap_field *cmn_plllc_pfdclk1_sel_preg[SIERRA_NUM_CMN_PLLC];
Kishon Vijay Abraham Ia0c30cd2021-03-19 18:11:24 +0530344 struct clk *input_clks[CDNS_SIERRA_INPUT_CLOCKS];
Alan Douglas44d30d62018-11-12 16:42:16 +0000345 int nsubnodes;
Kishon Vijay Abraham Ia43f72a2019-12-16 15:27:08 +0530346 u32 num_lanes;
Alan Douglas44d30d62018-11-12 16:42:16 +0000347 bool autoconf;
Kishon Vijay Abraham I28081b72021-03-19 18:11:27 +0530348 struct clk_onecell_data clk_data;
349 struct clk *output_clks[CDNS_SIERRA_OUTPUT_CLOCKS];
Alan Douglas44d30d62018-11-12 16:42:16 +0000350};
351
Kishon Vijay Abraham I380f5702019-12-16 15:27:01 +0530352static int cdns_regmap_write(void *context, unsigned int reg, unsigned int val)
353{
354 struct cdns_regmap_cdb_context *ctx = context;
355 u32 offset = reg << ctx->reg_offset_shift;
356
357 writew(val, ctx->base + offset);
358
359 return 0;
360}
361
362static int cdns_regmap_read(void *context, unsigned int reg, unsigned int *val)
363{
364 struct cdns_regmap_cdb_context *ctx = context;
365 u32 offset = reg << ctx->reg_offset_shift;
366
367 *val = readw(ctx->base + offset);
368 return 0;
369}
370
371#define SIERRA_LANE_CDB_REGMAP_CONF(n) \
372{ \
373 .name = "sierra_lane" n "_cdb", \
374 .reg_stride = 1, \
375 .fast_io = true, \
376 .reg_write = cdns_regmap_write, \
377 .reg_read = cdns_regmap_read, \
378}
379
Rikard Falkeborn3cfb0e82020-09-12 22:46:37 +0200380static const struct regmap_config cdns_sierra_lane_cdb_config[] = {
Kishon Vijay Abraham I380f5702019-12-16 15:27:01 +0530381 SIERRA_LANE_CDB_REGMAP_CONF("0"),
382 SIERRA_LANE_CDB_REGMAP_CONF("1"),
383 SIERRA_LANE_CDB_REGMAP_CONF("2"),
384 SIERRA_LANE_CDB_REGMAP_CONF("3"),
Kishon Vijay Abraham Ia43f72a2019-12-16 15:27:08 +0530385 SIERRA_LANE_CDB_REGMAP_CONF("4"),
386 SIERRA_LANE_CDB_REGMAP_CONF("5"),
387 SIERRA_LANE_CDB_REGMAP_CONF("6"),
388 SIERRA_LANE_CDB_REGMAP_CONF("7"),
389 SIERRA_LANE_CDB_REGMAP_CONF("8"),
390 SIERRA_LANE_CDB_REGMAP_CONF("9"),
391 SIERRA_LANE_CDB_REGMAP_CONF("10"),
392 SIERRA_LANE_CDB_REGMAP_CONF("11"),
393 SIERRA_LANE_CDB_REGMAP_CONF("12"),
394 SIERRA_LANE_CDB_REGMAP_CONF("13"),
395 SIERRA_LANE_CDB_REGMAP_CONF("14"),
396 SIERRA_LANE_CDB_REGMAP_CONF("15"),
Kishon Vijay Abraham I380f5702019-12-16 15:27:01 +0530397};
398
Rikard Falkeborn3cfb0e82020-09-12 22:46:37 +0200399static const struct regmap_config cdns_sierra_common_cdb_config = {
Kishon Vijay Abraham I380f5702019-12-16 15:27:01 +0530400 .name = "sierra_common_cdb",
401 .reg_stride = 1,
402 .fast_io = true,
403 .reg_write = cdns_regmap_write,
404 .reg_read = cdns_regmap_read,
405};
406
Swapnil Jakhade8c95e172021-12-23 07:01:28 +0100407static const struct regmap_config cdns_sierra_phy_pcs_cmn_cdb_config = {
408 .name = "sierra_phy_pcs_cmn_cdb",
Kishon Vijay Abraham I380f5702019-12-16 15:27:01 +0530409 .reg_stride = 1,
410 .fast_io = true,
411 .reg_write = cdns_regmap_write,
412 .reg_read = cdns_regmap_read,
413};
414
Swapnil Jakhade36ce4162021-12-23 07:01:31 +0100415#define SIERRA_PHY_PCS_LANE_CDB_REGMAP_CONF(n) \
416{ \
417 .name = "sierra_phy_pcs_lane" n "_cdb", \
418 .reg_stride = 1, \
419 .fast_io = true, \
420 .reg_write = cdns_regmap_write, \
421 .reg_read = cdns_regmap_read, \
422}
423
424static const struct regmap_config cdns_sierra_phy_pcs_lane_cdb_config[] = {
425 SIERRA_PHY_PCS_LANE_CDB_REGMAP_CONF("0"),
426 SIERRA_PHY_PCS_LANE_CDB_REGMAP_CONF("1"),
427 SIERRA_PHY_PCS_LANE_CDB_REGMAP_CONF("2"),
428 SIERRA_PHY_PCS_LANE_CDB_REGMAP_CONF("3"),
429 SIERRA_PHY_PCS_LANE_CDB_REGMAP_CONF("4"),
430 SIERRA_PHY_PCS_LANE_CDB_REGMAP_CONF("5"),
431 SIERRA_PHY_PCS_LANE_CDB_REGMAP_CONF("6"),
432 SIERRA_PHY_PCS_LANE_CDB_REGMAP_CONF("7"),
433 SIERRA_PHY_PCS_LANE_CDB_REGMAP_CONF("8"),
434 SIERRA_PHY_PCS_LANE_CDB_REGMAP_CONF("9"),
435 SIERRA_PHY_PCS_LANE_CDB_REGMAP_CONF("10"),
436 SIERRA_PHY_PCS_LANE_CDB_REGMAP_CONF("11"),
437 SIERRA_PHY_PCS_LANE_CDB_REGMAP_CONF("12"),
438 SIERRA_PHY_PCS_LANE_CDB_REGMAP_CONF("13"),
439 SIERRA_PHY_PCS_LANE_CDB_REGMAP_CONF("14"),
440 SIERRA_PHY_PCS_LANE_CDB_REGMAP_CONF("15"),
441};
442
Swapnil Jakhadef1cc6c32021-12-23 07:01:30 +0100443static const struct regmap_config cdns_sierra_phy_pma_cmn_cdb_config = {
444 .name = "sierra_phy_pma_cmn_cdb",
445 .reg_stride = 1,
446 .fast_io = true,
447 .reg_write = cdns_regmap_write,
448 .reg_read = cdns_regmap_read,
449};
450
Swapnil Jakhade6b81f052021-12-23 07:01:34 +0100451#define SIERRA_PHY_PMA_LANE_CDB_REGMAP_CONF(n) \
452{ \
453 .name = "sierra_phy_pma_lane" n "_cdb", \
454 .reg_stride = 1, \
455 .fast_io = true, \
456 .reg_write = cdns_regmap_write, \
457 .reg_read = cdns_regmap_read, \
458}
459
460static const struct regmap_config cdns_sierra_phy_pma_lane_cdb_config[] = {
461 SIERRA_PHY_PMA_LANE_CDB_REGMAP_CONF("0"),
462 SIERRA_PHY_PMA_LANE_CDB_REGMAP_CONF("1"),
463 SIERRA_PHY_PMA_LANE_CDB_REGMAP_CONF("2"),
464 SIERRA_PHY_PMA_LANE_CDB_REGMAP_CONF("3"),
465 SIERRA_PHY_PMA_LANE_CDB_REGMAP_CONF("4"),
466 SIERRA_PHY_PMA_LANE_CDB_REGMAP_CONF("5"),
467 SIERRA_PHY_PMA_LANE_CDB_REGMAP_CONF("6"),
468 SIERRA_PHY_PMA_LANE_CDB_REGMAP_CONF("7"),
469 SIERRA_PHY_PMA_LANE_CDB_REGMAP_CONF("8"),
470 SIERRA_PHY_PMA_LANE_CDB_REGMAP_CONF("9"),
471 SIERRA_PHY_PMA_LANE_CDB_REGMAP_CONF("10"),
472 SIERRA_PHY_PMA_LANE_CDB_REGMAP_CONF("11"),
473 SIERRA_PHY_PMA_LANE_CDB_REGMAP_CONF("12"),
474 SIERRA_PHY_PMA_LANE_CDB_REGMAP_CONF("13"),
475 SIERRA_PHY_PMA_LANE_CDB_REGMAP_CONF("14"),
476 SIERRA_PHY_PMA_LANE_CDB_REGMAP_CONF("15"),
477};
478
Kishon Vijay Abraham Icedcc2e2019-12-16 15:27:03 +0530479static int cdns_sierra_phy_init(struct phy *gphy)
Alan Douglas44d30d62018-11-12 16:42:16 +0000480{
481 struct cdns_sierra_inst *ins = phy_get_drvdata(gphy);
482 struct cdns_sierra_phy *phy = dev_get_drvdata(gphy->dev.parent);
Swapnil Jakhade078e9e92021-12-23 07:01:24 +0100483 const struct cdns_sierra_data *init_data = phy->init_data;
484 struct cdns_sierra_vals *pma_cmn_vals, *pma_ln_vals;
485 enum cdns_sierra_phy_type phy_type = ins->phy_type;
Swapnil Jakhade1e902b22021-12-23 07:01:27 +0100486 enum cdns_sierra_ssc_mode ssc = ins->ssc_mode;
Swapnil Jakhade6b81f052021-12-23 07:01:34 +0100487 struct cdns_sierra_vals *phy_pma_ln_vals;
Swapnil Jakhade078e9e92021-12-23 07:01:24 +0100488 const struct cdns_reg_pairs *reg_pairs;
Swapnil Jakhadefa105172021-12-23 07:01:29 +0100489 struct cdns_sierra_vals *pcs_cmn_vals;
Colin Ian King80f96fb2020-01-08 11:59:36 +0530490 struct regmap *regmap;
Swapnil Jakhade078e9e92021-12-23 07:01:24 +0100491 u32 num_regs;
Alan Douglas44d30d62018-11-12 16:42:16 +0000492 int i, j;
Alan Douglas44d30d62018-11-12 16:42:16 +0000493
Kishon Vijay Abraham Icedcc2e2019-12-16 15:27:03 +0530494 /* Initialise the PHY registers, unless auto configured */
Swapnil Jakhade6b81f052021-12-23 07:01:34 +0100495 if (phy->autoconf || phy->nsubnodes > 1)
Kishon Vijay Abraham Icedcc2e2019-12-16 15:27:03 +0530496 return 0;
497
Kishon Vijay Abraham Ia0c30cd2021-03-19 18:11:24 +0530498 clk_set_rate(phy->input_clks[CMN_REFCLK_DIG_DIV], 25000000);
499 clk_set_rate(phy->input_clks[CMN_REFCLK1_DIG_DIV], 25000000);
Swapnil Jakhade078e9e92021-12-23 07:01:24 +0100500
Swapnil Jakhadefa105172021-12-23 07:01:29 +0100501 /* PHY PCS common registers configurations */
502 pcs_cmn_vals = init_data->pcs_cmn_vals[phy_type][TYPE_NONE][ssc];
503 if (pcs_cmn_vals) {
504 reg_pairs = pcs_cmn_vals->reg_pairs;
505 num_regs = pcs_cmn_vals->num_regs;
506 regmap = phy->regmap_phy_pcs_common_cdb;
507 for (i = 0; i < num_regs; i++)
508 regmap_write(regmap, reg_pairs[i].off, reg_pairs[i].val);
509 }
510
Swapnil Jakhade6b81f052021-12-23 07:01:34 +0100511 /* PHY PMA lane registers configurations */
512 phy_pma_ln_vals = init_data->phy_pma_ln_vals[phy_type][TYPE_NONE][ssc];
513 if (phy_pma_ln_vals) {
514 reg_pairs = phy_pma_ln_vals->reg_pairs;
515 num_regs = phy_pma_ln_vals->num_regs;
516 for (i = 0; i < ins->num_lanes; i++) {
517 regmap = phy->regmap_phy_pma_lane_cdb[i + ins->mlane];
518 for (j = 0; j < num_regs; j++)
519 regmap_write(regmap, reg_pairs[j].off, reg_pairs[j].val);
520 }
521 }
522
Swapnil Jakhade078e9e92021-12-23 07:01:24 +0100523 /* PMA common registers configurations */
524 pma_cmn_vals = init_data->pma_cmn_vals[phy_type][TYPE_NONE][ssc];
525 if (pma_cmn_vals) {
526 reg_pairs = pma_cmn_vals->reg_pairs;
527 num_regs = pma_cmn_vals->num_regs;
528 regmap = phy->regmap_common_cdb;
529 for (i = 0; i < num_regs; i++)
530 regmap_write(regmap, reg_pairs[i].off, reg_pairs[i].val);
Alan Douglas44d30d62018-11-12 16:42:16 +0000531 }
Anil Varughese871002d2019-12-16 15:27:05 +0530532
Swapnil Jakhade078e9e92021-12-23 07:01:24 +0100533 /* PMA lane registers configurations */
534 pma_ln_vals = init_data->pma_ln_vals[phy_type][TYPE_NONE][ssc];
535 if (pma_ln_vals) {
536 reg_pairs = pma_ln_vals->reg_pairs;
537 num_regs = pma_ln_vals->num_regs;
538 for (i = 0; i < ins->num_lanes; i++) {
Kishon Vijay Abraham I380f5702019-12-16 15:27:01 +0530539 regmap = phy->regmap_lane_cdb[i + ins->mlane];
Swapnil Jakhade078e9e92021-12-23 07:01:24 +0100540 for (j = 0; j < num_regs; j++)
541 regmap_write(regmap, reg_pairs[j].off, reg_pairs[j].val);
Kishon Vijay Abraham I380f5702019-12-16 15:27:01 +0530542 }
543 }
Kishon Vijay Abraham Icedcc2e2019-12-16 15:27:03 +0530544
545 return 0;
Alan Douglas44d30d62018-11-12 16:42:16 +0000546}
547
548static int cdns_sierra_phy_on(struct phy *gphy)
549{
Kishon Vijay Abraham Iadc4bd62019-12-16 15:27:07 +0530550 struct cdns_sierra_phy *sp = dev_get_drvdata(gphy->dev.parent);
Alan Douglas44d30d62018-11-12 16:42:16 +0000551 struct cdns_sierra_inst *ins = phy_get_drvdata(gphy);
Kishon Vijay Abraham Iadc4bd62019-12-16 15:27:07 +0530552 struct device *dev = sp->dev;
553 u32 val;
554 int ret;
Alan Douglas44d30d62018-11-12 16:42:16 +0000555
Swapnil Jakhade6b81f052021-12-23 07:01:34 +0100556 if (sp->nsubnodes == 1) {
557 /* Take the PHY out of reset */
558 ret = reset_control_deassert(sp->phy_rst);
559 if (ret) {
560 dev_err(dev, "Failed to take the PHY out of reset\n");
561 return ret;
562 }
Kishon Vijay Abraham I5b4f5752021-03-19 18:11:16 +0530563 }
564
Alan Douglas44d30d62018-11-12 16:42:16 +0000565 /* Take the PHY lane group out of reset */
Kishon Vijay Abraham Iadc4bd62019-12-16 15:27:07 +0530566 ret = reset_control_deassert(ins->lnk_rst);
567 if (ret) {
568 dev_err(dev, "Failed to take the PHY lane out of reset\n");
569 return ret;
570 }
571
Swapnil Jakhade36ce4162021-12-23 07:01:31 +0100572 if (ins->phy_type == TYPE_PCIE || ins->phy_type == TYPE_USB) {
573 ret = regmap_field_read_poll_timeout(sp->phy_iso_link_ctrl_1[ins->mlane],
574 val, !val, 1000, PLL_LOCK_TIME);
575 if (ret) {
576 dev_err(dev, "Timeout waiting for PHY status ready\n");
577 return ret;
578 }
579 }
580
Swapnil Jakhadef1cc6c32021-12-23 07:01:30 +0100581 /*
582 * Wait for cmn_ready assertion
583 * PHY_PMA_CMN_CTRL[0] == 1
584 */
585 ret = regmap_field_read_poll_timeout(sp->pma_cmn_ready, val, val,
586 1000, PLL_LOCK_TIME);
587 if (ret) {
588 dev_err(dev, "Timeout waiting for CMN ready\n");
589 return ret;
590 }
591
Kishon Vijay Abraham Iadc4bd62019-12-16 15:27:07 +0530592 ret = regmap_field_read_poll_timeout(sp->pllctrl_lock[ins->mlane],
593 val, val, 1000, PLL_LOCK_TIME);
594 if (ret < 0)
595 dev_err(dev, "PLL lock of lane failed\n");
596
597 return ret;
Alan Douglas44d30d62018-11-12 16:42:16 +0000598}
599
600static int cdns_sierra_phy_off(struct phy *gphy)
601{
602 struct cdns_sierra_inst *ins = phy_get_drvdata(gphy);
603
604 return reset_control_assert(ins->lnk_rst);
605}
606
Roger Quadros7904e152020-01-06 15:06:20 +0200607static int cdns_sierra_phy_reset(struct phy *gphy)
608{
609 struct cdns_sierra_phy *sp = dev_get_drvdata(gphy->dev.parent);
610
611 reset_control_assert(sp->phy_rst);
612 reset_control_deassert(sp->phy_rst);
613 return 0;
614};
615
Alan Douglas44d30d62018-11-12 16:42:16 +0000616static const struct phy_ops ops = {
Kishon Vijay Abraham Icedcc2e2019-12-16 15:27:03 +0530617 .init = cdns_sierra_phy_init,
Alan Douglas44d30d62018-11-12 16:42:16 +0000618 .power_on = cdns_sierra_phy_on,
619 .power_off = cdns_sierra_phy_off,
Roger Quadros7904e152020-01-06 15:06:20 +0200620 .reset = cdns_sierra_phy_reset,
Alan Douglas44d30d62018-11-12 16:42:16 +0000621 .owner = THIS_MODULE,
622};
623
Kishon Vijay Abraham I28081b72021-03-19 18:11:27 +0530624static u8 cdns_sierra_pll_mux_get_parent(struct clk_hw *hw)
625{
626 struct cdns_sierra_pll_mux *mux = to_cdns_sierra_pll_mux(hw);
Swapnil Jakhadeda08aab2021-12-23 07:01:33 +0100627 struct regmap_field *plllc1en_field = mux->plllc1en_field;
628 struct regmap_field *termen_field = mux->termen_field;
Kishon Vijay Abraham I28081b72021-03-19 18:11:27 +0530629 struct regmap_field *field = mux->pfdclk_sel_preg;
630 unsigned int val;
Swapnil Jakhadeda08aab2021-12-23 07:01:33 +0100631 int index;
Kishon Vijay Abraham I28081b72021-03-19 18:11:27 +0530632
633 regmap_field_read(field, &val);
Swapnil Jakhadeda08aab2021-12-23 07:01:33 +0100634
635 if (strstr(clk_hw_get_name(hw), clk_names[CDNS_SIERRA_PLL_CMNLC1])) {
636 index = clk_mux_val_to_index(hw, cdns_sierra_pll_mux_table[CMN_PLLLC1], 0, val);
637 if (index == 1) {
638 regmap_field_write(plllc1en_field, 1);
639 regmap_field_write(termen_field, 1);
640 }
641 } else {
642 index = clk_mux_val_to_index(hw, cdns_sierra_pll_mux_table[CMN_PLLLC], 0, val);
643 }
644
645 return index;
Kishon Vijay Abraham I28081b72021-03-19 18:11:27 +0530646}
647
648static int cdns_sierra_pll_mux_set_parent(struct clk_hw *hw, u8 index)
649{
650 struct cdns_sierra_pll_mux *mux = to_cdns_sierra_pll_mux(hw);
651 struct regmap_field *plllc1en_field = mux->plllc1en_field;
652 struct regmap_field *termen_field = mux->termen_field;
653 struct regmap_field *field = mux->pfdclk_sel_preg;
654 int val, ret;
655
656 ret = regmap_field_write(plllc1en_field, 0);
657 ret |= regmap_field_write(termen_field, 0);
658 if (index == 1) {
659 ret |= regmap_field_write(plllc1en_field, 1);
660 ret |= regmap_field_write(termen_field, 1);
661 }
662
Swapnil Jakhadeda08aab2021-12-23 07:01:33 +0100663 if (strstr(clk_hw_get_name(hw), clk_names[CDNS_SIERRA_PLL_CMNLC1]))
664 val = cdns_sierra_pll_mux_table[CMN_PLLLC1][index];
665 else
666 val = cdns_sierra_pll_mux_table[CMN_PLLLC][index];
667
Kishon Vijay Abraham I28081b72021-03-19 18:11:27 +0530668 ret |= regmap_field_write(field, val);
669
670 return ret;
671}
672
673static const struct clk_ops cdns_sierra_pll_mux_ops = {
674 .set_parent = cdns_sierra_pll_mux_set_parent,
675 .get_parent = cdns_sierra_pll_mux_get_parent,
676};
677
678static int cdns_sierra_pll_mux_register(struct cdns_sierra_phy *sp,
679 struct regmap_field *pfdclk1_sel_field,
680 struct regmap_field *plllc1en_field,
681 struct regmap_field *termen_field,
682 int clk_index)
683{
684 struct cdns_sierra_pll_mux *mux;
685 struct device *dev = sp->dev;
686 struct clk_init_data *init;
687 const char **parent_names;
688 unsigned int num_parents;
689 char clk_name[100];
690 struct clk *clk;
691 int i;
692
693 mux = devm_kzalloc(dev, sizeof(*mux), GFP_KERNEL);
694 if (!mux)
695 return -ENOMEM;
696
697 num_parents = SIERRA_NUM_CMN_PLLC_PARENTS;
698 parent_names = devm_kzalloc(dev, (sizeof(char *) * num_parents), GFP_KERNEL);
699 if (!parent_names)
700 return -ENOMEM;
701
702 for (i = 0; i < num_parents; i++) {
703 clk = sp->input_clks[pll_mux_parent_index[clk_index][i]];
704 if (IS_ERR_OR_NULL(clk)) {
Swapnil Jakhadeda08aab2021-12-23 07:01:33 +0100705 dev_err(dev, "No parent clock for PLL mux clocks\n");
706 return IS_ERR(clk) ? PTR_ERR(clk) : -ENOENT;
Kishon Vijay Abraham I28081b72021-03-19 18:11:27 +0530707 }
708 parent_names[i] = __clk_get_name(clk);
709 }
710
711 snprintf(clk_name, sizeof(clk_name), "%s_%s", dev_name(dev), clk_names[clk_index]);
712
713 init = &mux->clk_data;
714
715 init->ops = &cdns_sierra_pll_mux_ops;
716 init->flags = CLK_SET_RATE_NO_REPARENT;
717 init->parent_names = parent_names;
718 init->num_parents = num_parents;
719 init->name = clk_name;
720
721 mux->pfdclk_sel_preg = pfdclk1_sel_field;
722 mux->plllc1en_field = plllc1en_field;
723 mux->termen_field = termen_field;
724 mux->hw.init = init;
725
726 clk = devm_clk_register(dev, &mux->hw);
727 if (IS_ERR(clk))
728 return PTR_ERR(clk);
729
730 sp->output_clks[clk_index] = clk;
731
732 return 0;
733}
734
735static int cdns_sierra_phy_register_pll_mux(struct cdns_sierra_phy *sp)
736{
737 struct regmap_field *pfdclk1_sel_field;
738 struct regmap_field *plllc1en_field;
739 struct regmap_field *termen_field;
740 struct device *dev = sp->dev;
741 int ret = 0, i, clk_index;
742
743 clk_index = CDNS_SIERRA_PLL_CMNLC;
744 for (i = 0; i < SIERRA_NUM_CMN_PLLC; i++, clk_index++) {
745 pfdclk1_sel_field = sp->cmn_plllc_pfdclk1_sel_preg[i];
746 plllc1en_field = sp->cmn_refrcv_refclk_plllc1en_preg[i];
747 termen_field = sp->cmn_refrcv_refclk_termen_preg[i];
748
749 ret = cdns_sierra_pll_mux_register(sp, pfdclk1_sel_field, plllc1en_field,
750 termen_field, clk_index);
751 if (ret) {
752 dev_err(dev, "Fail to register cmn plllc mux\n");
753 return ret;
754 }
755 }
756
757 return 0;
758}
759
760static void cdns_sierra_clk_unregister(struct cdns_sierra_phy *sp)
761{
762 struct device *dev = sp->dev;
763 struct device_node *node = dev->of_node;
764
765 of_clk_del_provider(node);
766}
767
768static int cdns_sierra_clk_register(struct cdns_sierra_phy *sp)
769{
770 struct device *dev = sp->dev;
771 struct device_node *node = dev->of_node;
772 int ret;
773
774 ret = cdns_sierra_phy_register_pll_mux(sp);
775 if (ret) {
776 dev_err(dev, "Failed to pll mux clocks\n");
777 return ret;
778 }
779
780 sp->clk_data.clks = sp->output_clks;
781 sp->clk_data.clk_num = CDNS_SIERRA_OUTPUT_CLOCKS;
782 ret = of_clk_add_provider(node, of_clk_src_onecell_get, &sp->clk_data);
783 if (ret)
784 dev_err(dev, "Failed to add clock provider: %s\n", node->name);
785
786 return ret;
787}
788
Alan Douglas44d30d62018-11-12 16:42:16 +0000789static int cdns_sierra_get_optional(struct cdns_sierra_inst *inst,
790 struct device_node *child)
791{
Swapnil Jakhade078e9e92021-12-23 07:01:24 +0100792 u32 phy_type;
793
Alan Douglas44d30d62018-11-12 16:42:16 +0000794 if (of_property_read_u32(child, "reg", &inst->mlane))
795 return -EINVAL;
796
797 if (of_property_read_u32(child, "cdns,num-lanes", &inst->num_lanes))
798 return -EINVAL;
799
Swapnil Jakhade078e9e92021-12-23 07:01:24 +0100800 if (of_property_read_u32(child, "cdns,phy-type", &phy_type))
Alan Douglas44d30d62018-11-12 16:42:16 +0000801 return -EINVAL;
802
Swapnil Jakhade078e9e92021-12-23 07:01:24 +0100803 switch (phy_type) {
804 case PHY_TYPE_PCIE:
805 inst->phy_type = TYPE_PCIE;
806 break;
807 case PHY_TYPE_USB3:
808 inst->phy_type = TYPE_USB;
809 break;
810 default:
811 return -EINVAL;
812 }
813
Swapnil Jakhade1e902b22021-12-23 07:01:27 +0100814 inst->ssc_mode = EXTERNAL_SSC;
815 of_property_read_u32(child, "cdns,ssc-mode", &inst->ssc_mode);
816
Alan Douglas44d30d62018-11-12 16:42:16 +0000817 return 0;
818}
819
Kishon Vijay Abraham I380f5702019-12-16 15:27:01 +0530820static struct regmap *cdns_regmap_init(struct device *dev, void __iomem *base,
821 u32 block_offset, u8 reg_offset_shift,
822 const struct regmap_config *config)
823{
824 struct cdns_regmap_cdb_context *ctx;
825
826 ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL);
827 if (!ctx)
828 return ERR_PTR(-ENOMEM);
829
830 ctx->dev = dev;
831 ctx->base = base + block_offset;
832 ctx->reg_offset_shift = reg_offset_shift;
833
834 return devm_regmap_init(dev, NULL, ctx, config);
835}
836
837static int cdns_regfield_init(struct cdns_sierra_phy *sp)
838{
839 struct device *dev = sp->dev;
840 struct regmap_field *field;
Kishon Vijay Abraham I28081b72021-03-19 18:11:27 +0530841 struct reg_field reg_field;
Kishon Vijay Abraham I380f5702019-12-16 15:27:01 +0530842 struct regmap *regmap;
Kishon Vijay Abraham Iadc4bd62019-12-16 15:27:07 +0530843 int i;
Kishon Vijay Abraham I380f5702019-12-16 15:27:01 +0530844
845 regmap = sp->regmap_common_cdb;
846 field = devm_regmap_field_alloc(dev, regmap, macro_id_type);
847 if (IS_ERR(field)) {
848 dev_err(dev, "MACRO_ID_TYPE reg field init failed\n");
849 return PTR_ERR(field);
850 }
851 sp->macro_id_type = field;
852
Kishon Vijay Abraham I28081b72021-03-19 18:11:27 +0530853 for (i = 0; i < SIERRA_NUM_CMN_PLLC; i++) {
854 reg_field = cmn_plllc_pfdclk1_sel_preg[i].pfdclk_sel_preg;
855 field = devm_regmap_field_alloc(dev, regmap, reg_field);
856 if (IS_ERR(field)) {
857 dev_err(dev, "PLLLC%d_PFDCLK1_SEL failed\n", i);
858 return PTR_ERR(field);
859 }
860 sp->cmn_plllc_pfdclk1_sel_preg[i] = field;
861
862 reg_field = cmn_plllc_pfdclk1_sel_preg[i].plllc1en_field;
863 field = devm_regmap_field_alloc(dev, regmap, reg_field);
864 if (IS_ERR(field)) {
865 dev_err(dev, "REFRCV%d_REFCLK_PLLLC1EN failed\n", i);
866 return PTR_ERR(field);
867 }
868 sp->cmn_refrcv_refclk_plllc1en_preg[i] = field;
869
870 reg_field = cmn_plllc_pfdclk1_sel_preg[i].termen_field;
871 field = devm_regmap_field_alloc(dev, regmap, reg_field);
872 if (IS_ERR(field)) {
873 dev_err(dev, "REFRCV%d_REFCLK_TERMEN failed\n", i);
874 return PTR_ERR(field);
875 }
876 sp->cmn_refrcv_refclk_termen_preg[i] = field;
877 }
878
Swapnil Jakhade8c95e172021-12-23 07:01:28 +0100879 regmap = sp->regmap_phy_pcs_common_cdb;
Kishon Vijay Abraham I380f5702019-12-16 15:27:01 +0530880 field = devm_regmap_field_alloc(dev, regmap, phy_pll_cfg_1);
881 if (IS_ERR(field)) {
882 dev_err(dev, "PHY_PLL_CFG_1 reg field init failed\n");
883 return PTR_ERR(field);
884 }
885 sp->phy_pll_cfg_1 = field;
886
Swapnil Jakhadef1cc6c32021-12-23 07:01:30 +0100887 regmap = sp->regmap_phy_pma_common_cdb;
888 field = devm_regmap_field_alloc(dev, regmap, pma_cmn_ready);
889 if (IS_ERR(field)) {
890 dev_err(dev, "PHY_PMA_CMN_CTRL reg field init failed\n");
891 return PTR_ERR(field);
892 }
893 sp->pma_cmn_ready = field;
894
Kishon Vijay Abraham Iadc4bd62019-12-16 15:27:07 +0530895 for (i = 0; i < SIERRA_MAX_LANES; i++) {
896 regmap = sp->regmap_lane_cdb[i];
897 field = devm_regmap_field_alloc(dev, regmap, pllctrl_lock);
898 if (IS_ERR(field)) {
899 dev_err(dev, "P%d_ENABLE reg field init failed\n", i);
900 return PTR_ERR(field);
901 }
Swapnil Jakhade36ce4162021-12-23 07:01:31 +0100902 sp->pllctrl_lock[i] = field;
903 }
904
905 for (i = 0; i < SIERRA_MAX_LANES; i++) {
906 regmap = sp->regmap_phy_pcs_lane_cdb[i];
907 field = devm_regmap_field_alloc(dev, regmap, phy_iso_link_ctrl_1);
908 if (IS_ERR(field)) {
909 dev_err(dev, "PHY_ISO_LINK_CTRL reg field init for lane %d failed\n", i);
910 return PTR_ERR(field);
911 }
912 sp->phy_iso_link_ctrl_1[i] = field;
Kishon Vijay Abraham Iadc4bd62019-12-16 15:27:07 +0530913 }
914
Kishon Vijay Abraham I380f5702019-12-16 15:27:01 +0530915 return 0;
916}
917
918static int cdns_regmap_init_blocks(struct cdns_sierra_phy *sp,
919 void __iomem *base, u8 block_offset_shift,
920 u8 reg_offset_shift)
921{
922 struct device *dev = sp->dev;
923 struct regmap *regmap;
924 u32 block_offset;
925 int i;
926
927 for (i = 0; i < SIERRA_MAX_LANES; i++) {
928 block_offset = SIERRA_LANE_CDB_OFFSET(i, block_offset_shift,
929 reg_offset_shift);
930 regmap = cdns_regmap_init(dev, base, block_offset,
931 reg_offset_shift,
932 &cdns_sierra_lane_cdb_config[i]);
933 if (IS_ERR(regmap)) {
934 dev_err(dev, "Failed to init lane CDB regmap\n");
935 return PTR_ERR(regmap);
936 }
937 sp->regmap_lane_cdb[i] = regmap;
938 }
939
940 regmap = cdns_regmap_init(dev, base, SIERRA_COMMON_CDB_OFFSET,
941 reg_offset_shift,
942 &cdns_sierra_common_cdb_config);
943 if (IS_ERR(regmap)) {
944 dev_err(dev, "Failed to init common CDB regmap\n");
945 return PTR_ERR(regmap);
946 }
947 sp->regmap_common_cdb = regmap;
948
Swapnil Jakhade8c95e172021-12-23 07:01:28 +0100949 block_offset = SIERRA_PHY_PCS_COMMON_OFFSET(block_offset_shift);
Kishon Vijay Abraham I380f5702019-12-16 15:27:01 +0530950 regmap = cdns_regmap_init(dev, base, block_offset, reg_offset_shift,
Swapnil Jakhade8c95e172021-12-23 07:01:28 +0100951 &cdns_sierra_phy_pcs_cmn_cdb_config);
Kishon Vijay Abraham I380f5702019-12-16 15:27:01 +0530952 if (IS_ERR(regmap)) {
Swapnil Jakhade8c95e172021-12-23 07:01:28 +0100953 dev_err(dev, "Failed to init PHY PCS common CDB regmap\n");
Kishon Vijay Abraham I380f5702019-12-16 15:27:01 +0530954 return PTR_ERR(regmap);
955 }
Swapnil Jakhade8c95e172021-12-23 07:01:28 +0100956 sp->regmap_phy_pcs_common_cdb = regmap;
Kishon Vijay Abraham I380f5702019-12-16 15:27:01 +0530957
Swapnil Jakhade36ce4162021-12-23 07:01:31 +0100958 for (i = 0; i < SIERRA_MAX_LANES; i++) {
959 block_offset = SIERRA_PHY_PCS_LANE_CDB_OFFSET(i, block_offset_shift,
960 reg_offset_shift);
961 regmap = cdns_regmap_init(dev, base, block_offset,
962 reg_offset_shift,
963 &cdns_sierra_phy_pcs_lane_cdb_config[i]);
964 if (IS_ERR(regmap)) {
965 dev_err(dev, "Failed to init PHY PCS lane CDB regmap\n");
966 return PTR_ERR(regmap);
967 }
968 sp->regmap_phy_pcs_lane_cdb[i] = regmap;
969 }
970
Swapnil Jakhadef1cc6c32021-12-23 07:01:30 +0100971 block_offset = SIERRA_PHY_PMA_COMMON_OFFSET(block_offset_shift);
972 regmap = cdns_regmap_init(dev, base, block_offset, reg_offset_shift,
973 &cdns_sierra_phy_pma_cmn_cdb_config);
974 if (IS_ERR(regmap)) {
975 dev_err(dev, "Failed to init PHY PMA common CDB regmap\n");
976 return PTR_ERR(regmap);
977 }
978 sp->regmap_phy_pma_common_cdb = regmap;
979
Swapnil Jakhade6b81f052021-12-23 07:01:34 +0100980 for (i = 0; i < SIERRA_MAX_LANES; i++) {
981 block_offset = SIERRA_PHY_PMA_LANE_CDB_OFFSET(i, block_offset_shift,
982 reg_offset_shift);
983 regmap = cdns_regmap_init(dev, base, block_offset,
984 reg_offset_shift,
985 &cdns_sierra_phy_pma_lane_cdb_config[i]);
986 if (IS_ERR(regmap)) {
987 dev_err(dev, "Failed to init PHY PMA lane CDB regmap\n");
988 return PTR_ERR(regmap);
989 }
990 sp->regmap_phy_pma_lane_cdb[i] = regmap;
991 }
992
Kishon Vijay Abraham I380f5702019-12-16 15:27:01 +0530993 return 0;
994}
995
Kishon Vijay Abraham I7e016cb2021-03-19 18:11:20 +0530996static int cdns_sierra_phy_get_clocks(struct cdns_sierra_phy *sp,
997 struct device *dev)
998{
999 struct clk *clk;
1000 int ret;
1001
1002 clk = devm_clk_get_optional(dev, "phy_clk");
1003 if (IS_ERR(clk)) {
1004 dev_err(dev, "failed to get clock phy_clk\n");
1005 return PTR_ERR(clk);
1006 }
Kishon Vijay Abraham Ia0c30cd2021-03-19 18:11:24 +05301007 sp->input_clks[PHY_CLK] = clk;
Kishon Vijay Abraham I7e016cb2021-03-19 18:11:20 +05301008
1009 clk = devm_clk_get_optional(dev, "cmn_refclk_dig_div");
1010 if (IS_ERR(clk)) {
1011 dev_err(dev, "cmn_refclk_dig_div clock not found\n");
1012 ret = PTR_ERR(clk);
1013 return ret;
1014 }
Kishon Vijay Abraham Ia0c30cd2021-03-19 18:11:24 +05301015 sp->input_clks[CMN_REFCLK_DIG_DIV] = clk;
Kishon Vijay Abraham I7e016cb2021-03-19 18:11:20 +05301016
1017 clk = devm_clk_get_optional(dev, "cmn_refclk1_dig_div");
1018 if (IS_ERR(clk)) {
1019 dev_err(dev, "cmn_refclk1_dig_div clock not found\n");
1020 ret = PTR_ERR(clk);
1021 return ret;
1022 }
Kishon Vijay Abraham Ia0c30cd2021-03-19 18:11:24 +05301023 sp->input_clks[CMN_REFCLK1_DIG_DIV] = clk;
Kishon Vijay Abraham I7e016cb2021-03-19 18:11:20 +05301024
Kishon Vijay Abraham I28081b72021-03-19 18:11:27 +05301025 clk = devm_clk_get_optional(dev, "pll0_refclk");
1026 if (IS_ERR(clk)) {
1027 dev_err(dev, "pll0_refclk clock not found\n");
1028 ret = PTR_ERR(clk);
1029 return ret;
1030 }
1031 sp->input_clks[PLL0_REFCLK] = clk;
1032
1033 clk = devm_clk_get_optional(dev, "pll1_refclk");
1034 if (IS_ERR(clk)) {
1035 dev_err(dev, "pll1_refclk clock not found\n");
1036 ret = PTR_ERR(clk);
1037 return ret;
1038 }
1039 sp->input_clks[PLL1_REFCLK] = clk;
1040
Kishon Vijay Abraham I7e016cb2021-03-19 18:11:20 +05301041 return 0;
1042}
1043
Kishon Vijay Abraham I1436ec32021-03-19 18:11:28 +05301044static int cdns_sierra_phy_enable_clocks(struct cdns_sierra_phy *sp)
1045{
1046 int ret;
1047
1048 ret = clk_prepare_enable(sp->input_clks[PHY_CLK]);
1049 if (ret)
1050 return ret;
1051
1052 ret = clk_prepare_enable(sp->output_clks[CDNS_SIERRA_PLL_CMNLC]);
1053 if (ret)
1054 goto err_pll_cmnlc;
1055
1056 ret = clk_prepare_enable(sp->output_clks[CDNS_SIERRA_PLL_CMNLC1]);
1057 if (ret)
1058 goto err_pll_cmnlc1;
1059
1060 return 0;
1061
1062err_pll_cmnlc1:
1063 clk_disable_unprepare(sp->output_clks[CDNS_SIERRA_PLL_CMNLC]);
1064
1065err_pll_cmnlc:
1066 clk_disable_unprepare(sp->input_clks[PHY_CLK]);
1067
1068 return ret;
1069}
1070
1071static void cdns_sierra_phy_disable_clocks(struct cdns_sierra_phy *sp)
1072{
1073 clk_disable_unprepare(sp->output_clks[CDNS_SIERRA_PLL_CMNLC1]);
1074 clk_disable_unprepare(sp->output_clks[CDNS_SIERRA_PLL_CMNLC]);
1075 clk_disable_unprepare(sp->input_clks[PHY_CLK]);
1076}
1077
Kishon Vijay Abraham I1d5f40e2021-03-19 18:11:21 +05301078static int cdns_sierra_phy_get_resets(struct cdns_sierra_phy *sp,
1079 struct device *dev)
1080{
1081 struct reset_control *rst;
1082
Kishon Vijay Abraham I15b0b822021-03-19 18:11:22 +05301083 rst = devm_reset_control_get_exclusive(dev, "sierra_reset");
Kishon Vijay Abraham I1d5f40e2021-03-19 18:11:21 +05301084 if (IS_ERR(rst)) {
1085 dev_err(dev, "failed to get reset\n");
1086 return PTR_ERR(rst);
1087 }
1088 sp->phy_rst = rst;
1089
Kishon Vijay Abraham I15b0b822021-03-19 18:11:22 +05301090 rst = devm_reset_control_get_optional_exclusive(dev, "sierra_apb");
Kishon Vijay Abraham I1d5f40e2021-03-19 18:11:21 +05301091 if (IS_ERR(rst)) {
1092 dev_err(dev, "failed to get apb reset\n");
1093 return PTR_ERR(rst);
1094 }
1095 sp->apb_rst = rst;
1096
1097 return 0;
1098}
1099
Swapnil Jakhade6b81f052021-12-23 07:01:34 +01001100static int cdns_sierra_phy_configure_multilink(struct cdns_sierra_phy *sp)
1101{
1102 const struct cdns_sierra_data *init_data = sp->init_data;
1103 struct cdns_sierra_vals *pma_cmn_vals, *pma_ln_vals;
1104 enum cdns_sierra_phy_type phy_t1, phy_t2;
1105 struct cdns_sierra_vals *phy_pma_ln_vals;
1106 const struct cdns_reg_pairs *reg_pairs;
1107 struct cdns_sierra_vals *pcs_cmn_vals;
1108 int i, j, node, mlane, num_lanes, ret;
1109 enum cdns_sierra_ssc_mode ssc;
1110 struct regmap *regmap;
1111 u32 num_regs;
1112
1113 /* Maximum 2 links (subnodes) are supported */
1114 if (sp->nsubnodes != 2)
1115 return -EINVAL;
1116
1117 clk_set_rate(sp->input_clks[CMN_REFCLK_DIG_DIV], 25000000);
1118 clk_set_rate(sp->input_clks[CMN_REFCLK1_DIG_DIV], 25000000);
1119
1120 /* PHY configured to use both PLL LC and LC1 */
1121 regmap_field_write(sp->phy_pll_cfg_1, 0x1);
1122
1123 phy_t1 = sp->phys[0].phy_type;
1124 phy_t2 = sp->phys[1].phy_type;
1125
1126 /*
1127 * PHY configuration for multi-link operation is done in two steps.
1128 * e.g. Consider a case for a 4 lane PHY with PCIe using 2 lanes and QSGMII other 2 lanes.
1129 * Sierra PHY has 2 PLLs, viz. PLLLC and PLLLC1. So in this case, PLLLC is used for PCIe
1130 * and PLLLC1 is used for QSGMII. PHY is configured in two steps as described below.
1131 *
1132 * [1] For first step, phy_t1 = TYPE_PCIE and phy_t2 = TYPE_QSGMII
1133 * So the register values are selected as [TYPE_PCIE][TYPE_QSGMII][ssc].
1134 * This will configure PHY registers associated for PCIe (i.e. first protocol)
1135 * involving PLLLC registers and registers for first 2 lanes of PHY.
1136 * [2] In second step, the variables phy_t1 and phy_t2 are swapped. So now,
1137 * phy_t1 = TYPE_QSGMII and phy_t2 = TYPE_PCIE. And the register values are selected as
1138 * [TYPE_QSGMII][TYPE_PCIE][ssc].
1139 * This will configure PHY registers associated for QSGMII (i.e. second protocol)
1140 * involving PLLLC1 registers and registers for other 2 lanes of PHY.
1141 *
1142 * This completes the PHY configuration for multilink operation. This approach enables
1143 * dividing the large number of PHY register configurations into protocol specific
1144 * smaller groups.
1145 */
1146 for (node = 0; node < sp->nsubnodes; node++) {
1147 if (node == 1) {
1148 /*
1149 * If first link with phy_t1 is configured, then configure the PHY for
1150 * second link with phy_t2. Get the array values as [phy_t2][phy_t1][ssc].
1151 */
1152 swap(phy_t1, phy_t2);
1153 }
1154
1155 mlane = sp->phys[node].mlane;
1156 ssc = sp->phys[node].ssc_mode;
1157 num_lanes = sp->phys[node].num_lanes;
1158
1159 /* PHY PCS common registers configurations */
1160 pcs_cmn_vals = init_data->pcs_cmn_vals[phy_t1][phy_t2][ssc];
1161 if (pcs_cmn_vals) {
1162 reg_pairs = pcs_cmn_vals->reg_pairs;
1163 num_regs = pcs_cmn_vals->num_regs;
1164 regmap = sp->regmap_phy_pcs_common_cdb;
1165 for (i = 0; i < num_regs; i++)
1166 regmap_write(regmap, reg_pairs[i].off, reg_pairs[i].val);
1167 }
1168
1169 /* PHY PMA lane registers configurations */
1170 phy_pma_ln_vals = init_data->phy_pma_ln_vals[phy_t1][phy_t2][ssc];
1171 if (phy_pma_ln_vals) {
1172 reg_pairs = phy_pma_ln_vals->reg_pairs;
1173 num_regs = phy_pma_ln_vals->num_regs;
1174 for (i = 0; i < num_lanes; i++) {
1175 regmap = sp->regmap_phy_pma_lane_cdb[i + mlane];
1176 for (j = 0; j < num_regs; j++)
1177 regmap_write(regmap, reg_pairs[j].off, reg_pairs[j].val);
1178 }
1179 }
1180
1181 /* PMA common registers configurations */
1182 pma_cmn_vals = init_data->pma_cmn_vals[phy_t1][phy_t2][ssc];
1183 if (pma_cmn_vals) {
1184 reg_pairs = pma_cmn_vals->reg_pairs;
1185 num_regs = pma_cmn_vals->num_regs;
1186 regmap = sp->regmap_common_cdb;
1187 for (i = 0; i < num_regs; i++)
1188 regmap_write(regmap, reg_pairs[i].off, reg_pairs[i].val);
1189 }
1190
1191 /* PMA lane registers configurations */
1192 pma_ln_vals = init_data->pma_ln_vals[phy_t1][phy_t2][ssc];
1193 if (pma_ln_vals) {
1194 reg_pairs = pma_ln_vals->reg_pairs;
1195 num_regs = pma_ln_vals->num_regs;
1196 for (i = 0; i < num_lanes; i++) {
1197 regmap = sp->regmap_lane_cdb[i + mlane];
1198 for (j = 0; j < num_regs; j++)
1199 regmap_write(regmap, reg_pairs[j].off, reg_pairs[j].val);
1200 }
1201 }
1202 }
1203
1204 /* Take the PHY out of reset */
1205 ret = reset_control_deassert(sp->phy_rst);
1206 if (ret)
1207 return ret;
1208
1209 return 0;
1210}
1211
Alan Douglas44d30d62018-11-12 16:42:16 +00001212static int cdns_sierra_phy_probe(struct platform_device *pdev)
1213{
1214 struct cdns_sierra_phy *sp;
1215 struct phy_provider *phy_provider;
1216 struct device *dev = &pdev->dev;
Swapnil Jakhadec3c11d52021-12-23 07:01:23 +01001217 const struct cdns_sierra_data *data;
Kishon Vijay Abraham I380f5702019-12-16 15:27:01 +05301218 unsigned int id_value;
Alan Douglas44d30d62018-11-12 16:42:16 +00001219 int i, ret, node = 0;
Kishon Vijay Abraham I380f5702019-12-16 15:27:01 +05301220 void __iomem *base;
Alan Douglas44d30d62018-11-12 16:42:16 +00001221 struct device_node *dn = dev->of_node, *child;
1222
1223 if (of_get_child_count(dn) == 0)
1224 return -ENODEV;
1225
Kishon Vijay Abraham I380f5702019-12-16 15:27:01 +05301226 /* Get init data for this PHY */
Swapnil Jakhadec3c11d52021-12-23 07:01:23 +01001227 data = of_device_get_match_data(dev);
1228 if (!data)
Kishon Vijay Abraham I380f5702019-12-16 15:27:01 +05301229 return -EINVAL;
1230
Alan Douglas44d30d62018-11-12 16:42:16 +00001231 sp = devm_kzalloc(dev, sizeof(*sp), GFP_KERNEL);
1232 if (!sp)
1233 return -ENOMEM;
1234 dev_set_drvdata(dev, sp);
1235 sp->dev = dev;
Kishon Vijay Abraham I380f5702019-12-16 15:27:01 +05301236 sp->init_data = data;
Alan Douglas44d30d62018-11-12 16:42:16 +00001237
Chunfeng Yunfa629092020-11-06 14:08:37 +08001238 base = devm_platform_ioremap_resource(pdev, 0);
Kishon Vijay Abraham I380f5702019-12-16 15:27:01 +05301239 if (IS_ERR(base)) {
Alan Douglas44d30d62018-11-12 16:42:16 +00001240 dev_err(dev, "missing \"reg\"\n");
Kishon Vijay Abraham I380f5702019-12-16 15:27:01 +05301241 return PTR_ERR(base);
Alan Douglas44d30d62018-11-12 16:42:16 +00001242 }
1243
Kishon Vijay Abraham I380f5702019-12-16 15:27:01 +05301244 ret = cdns_regmap_init_blocks(sp, base, data->block_offset_shift,
1245 data->reg_offset_shift);
1246 if (ret)
1247 return ret;
1248
1249 ret = cdns_regfield_init(sp);
1250 if (ret)
1251 return ret;
Alan Douglas44d30d62018-11-12 16:42:16 +00001252
1253 platform_set_drvdata(pdev, sp);
1254
Kishon Vijay Abraham I7e016cb2021-03-19 18:11:20 +05301255 ret = cdns_sierra_phy_get_clocks(sp, dev);
1256 if (ret)
1257 return ret;
Alan Douglas44d30d62018-11-12 16:42:16 +00001258
Kishon Vijay Abraham I28081b72021-03-19 18:11:27 +05301259 ret = cdns_sierra_clk_register(sp);
Kishon Vijay Abraham I1d5f40e2021-03-19 18:11:21 +05301260 if (ret)
1261 return ret;
Alan Douglas44d30d62018-11-12 16:42:16 +00001262
Kishon Vijay Abraham I28081b72021-03-19 18:11:27 +05301263 ret = cdns_sierra_phy_get_resets(sp, dev);
1264 if (ret)
1265 goto unregister_clk;
1266
Kishon Vijay Abraham I1436ec32021-03-19 18:11:28 +05301267 ret = cdns_sierra_phy_enable_clocks(sp);
Alan Douglas44d30d62018-11-12 16:42:16 +00001268 if (ret)
Kishon Vijay Abraham I28081b72021-03-19 18:11:27 +05301269 goto unregister_clk;
Alan Douglas44d30d62018-11-12 16:42:16 +00001270
1271 /* Enable APB */
1272 reset_control_deassert(sp->apb_rst);
1273
1274 /* Check that PHY is present */
Kishon Vijay Abraham I380f5702019-12-16 15:27:01 +05301275 regmap_field_read(sp->macro_id_type, &id_value);
1276 if (sp->init_data->id_value != id_value) {
Alan Douglas44d30d62018-11-12 16:42:16 +00001277 ret = -EINVAL;
1278 goto clk_disable;
1279 }
1280
1281 sp->autoconf = of_property_read_bool(dn, "cdns,autoconf");
1282
1283 for_each_available_child_of_node(dn, child) {
1284 struct phy *gphy;
1285
Kishon Vijay Abraham I03ada5a32021-03-19 18:11:18 +05301286 if (!(of_node_name_eq(child, "phy") ||
1287 of_node_name_eq(child, "link")))
1288 continue;
1289
Alan Douglas44d30d62018-11-12 16:42:16 +00001290 sp->phys[node].lnk_rst =
Kishon Vijay Abraham Ib8729362019-12-16 15:27:06 +05301291 of_reset_control_array_get_exclusive(child);
Alan Douglas44d30d62018-11-12 16:42:16 +00001292
1293 if (IS_ERR(sp->phys[node].lnk_rst)) {
1294 dev_err(dev, "failed to get reset %s\n",
1295 child->full_name);
1296 ret = PTR_ERR(sp->phys[node].lnk_rst);
1297 goto put_child2;
1298 }
1299
1300 if (!sp->autoconf) {
1301 ret = cdns_sierra_get_optional(&sp->phys[node], child);
1302 if (ret) {
1303 dev_err(dev, "missing property in node %s\n",
1304 child->name);
1305 goto put_child;
1306 }
1307 }
1308
Kishon Vijay Abraham Ia43f72a2019-12-16 15:27:08 +05301309 sp->num_lanes += sp->phys[node].num_lanes;
1310
Alan Douglas44d30d62018-11-12 16:42:16 +00001311 gphy = devm_phy_create(dev, child, &ops);
1312
1313 if (IS_ERR(gphy)) {
1314 ret = PTR_ERR(gphy);
1315 goto put_child;
1316 }
1317 sp->phys[node].phy = gphy;
1318 phy_set_drvdata(gphy, &sp->phys[node]);
1319
Alan Douglas44d30d62018-11-12 16:42:16 +00001320 node++;
1321 }
1322 sp->nsubnodes = node;
1323
Kishon Vijay Abraham Ia43f72a2019-12-16 15:27:08 +05301324 if (sp->num_lanes > SIERRA_MAX_LANES) {
Wang Wensheng6411e382021-05-17 01:57:49 +00001325 ret = -EINVAL;
Kishon Vijay Abraham Ia43f72a2019-12-16 15:27:08 +05301326 dev_err(dev, "Invalid lane configuration\n");
1327 goto put_child2;
1328 }
1329
Alan Douglas44d30d62018-11-12 16:42:16 +00001330 /* If more than one subnode, configure the PHY as multilink */
Swapnil Jakhade6b81f052021-12-23 07:01:34 +01001331 if (!sp->autoconf && sp->nsubnodes > 1) {
1332 ret = cdns_sierra_phy_configure_multilink(sp);
1333 if (ret)
1334 goto put_child2;
1335 }
Alan Douglas44d30d62018-11-12 16:42:16 +00001336
1337 pm_runtime_enable(dev);
1338 phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
Alan Douglas44d30d62018-11-12 16:42:16 +00001339 return PTR_ERR_OR_ZERO(phy_provider);
1340
1341put_child:
1342 node++;
1343put_child2:
1344 for (i = 0; i < node; i++)
1345 reset_control_put(sp->phys[i].lnk_rst);
1346 of_node_put(child);
1347clk_disable:
Kishon Vijay Abraham I1436ec32021-03-19 18:11:28 +05301348 cdns_sierra_phy_disable_clocks(sp);
Alan Douglas44d30d62018-11-12 16:42:16 +00001349 reset_control_assert(sp->apb_rst);
Kishon Vijay Abraham I28081b72021-03-19 18:11:27 +05301350unregister_clk:
1351 cdns_sierra_clk_unregister(sp);
Alan Douglas44d30d62018-11-12 16:42:16 +00001352 return ret;
1353}
1354
1355static int cdns_sierra_phy_remove(struct platform_device *pdev)
1356{
Kishon Vijay Abraham I748e3452019-12-16 15:27:10 +05301357 struct cdns_sierra_phy *phy = platform_get_drvdata(pdev);
Alan Douglas44d30d62018-11-12 16:42:16 +00001358 int i;
1359
1360 reset_control_assert(phy->phy_rst);
1361 reset_control_assert(phy->apb_rst);
1362 pm_runtime_disable(&pdev->dev);
1363
Kishon Vijay Abraham I1436ec32021-03-19 18:11:28 +05301364 cdns_sierra_phy_disable_clocks(phy);
Alan Douglas44d30d62018-11-12 16:42:16 +00001365 /*
1366 * The device level resets will be put automatically.
1367 * Need to put the subnode resets here though.
1368 */
1369 for (i = 0; i < phy->nsubnodes; i++) {
1370 reset_control_assert(phy->phys[i].lnk_rst);
1371 reset_control_put(phy->phys[i].lnk_rst);
1372 }
Kishon Vijay Abraham I29c2d022021-03-19 18:11:25 +05301373
Kishon Vijay Abraham I28081b72021-03-19 18:11:27 +05301374 cdns_sierra_clk_unregister(phy);
Kishon Vijay Abraham I29c2d022021-03-19 18:11:25 +05301375
Alan Douglas44d30d62018-11-12 16:42:16 +00001376 return 0;
1377}
1378
Swapnil Jakhadefa105172021-12-23 07:01:29 +01001379/* PCIE PHY PCS common configuration */
1380static struct cdns_reg_pairs pcie_phy_pcs_cmn_regs[] = {
1381 {0x0430, SIERRA_PHY_PIPE_CMN_CTRL1}
1382};
1383
1384static struct cdns_sierra_vals pcie_phy_pcs_cmn_vals = {
1385 .reg_pairs = pcie_phy_pcs_cmn_regs,
1386 .num_regs = ARRAY_SIZE(pcie_phy_pcs_cmn_regs),
1387};
1388
Swapnil Jakhade7a5ad9b2021-12-23 07:01:32 +01001389/* refclk100MHz_32b_PCIe_cmn_pll_no_ssc */
1390static const struct cdns_reg_pairs cdns_pcie_cmn_regs_no_ssc[] = {
1391 {0x2105, SIERRA_CMN_PLLLC_LF_COEFF_MODE1_PREG},
1392 {0x2105, SIERRA_CMN_PLLLC_LF_COEFF_MODE0_PREG},
1393 {0x8A06, SIERRA_CMN_PLLLC_BWCAL_MODE1_PREG},
1394 {0x8A06, SIERRA_CMN_PLLLC_BWCAL_MODE0_PREG}
1395};
1396
1397/* refclk100MHz_32b_PCIe_ln_no_ssc */
1398static const struct cdns_reg_pairs cdns_pcie_ln_regs_no_ssc[] = {
1399 {0xFC08, SIERRA_DET_STANDEC_A_PREG},
1400 {0x001D, SIERRA_PSM_A3IN_TMR_PREG},
1401 {0x1555, SIERRA_DFE_BIASTRIM_PREG},
1402 {0x9703, SIERRA_DRVCTRL_BOOST_PREG},
1403 {0x8055, SIERRA_RX_CREQ_FLTR_A_MODE3_PREG},
1404 {0x80BB, SIERRA_RX_CREQ_FLTR_A_MODE2_PREG},
1405 {0x8351, SIERRA_RX_CREQ_FLTR_A_MODE1_PREG},
1406 {0x8349, SIERRA_RX_CREQ_FLTR_A_MODE0_PREG},
1407 {0x0002, SIERRA_CREQ_DCBIASATTEN_OVR_PREG},
1408 {0x9800, SIERRA_RX_CTLE_CAL_PREG},
1409 {0x5624, SIERRA_DEQ_CONCUR_CTRL2_PREG},
1410 {0x000F, SIERRA_DEQ_EPIPWR_CTRL2_PREG},
1411 {0x00FF, SIERRA_DEQ_FAST_MAINT_CYCLES_PREG},
1412 {0x4C4C, SIERRA_DEQ_ERRCMP_CTRL_PREG},
1413 {0x02FA, SIERRA_DEQ_OFFSET_CTRL_PREG},
1414 {0x02FA, SIERRA_DEQ_GAIN_CTRL_PREG},
1415 {0x0041, SIERRA_DEQ_GLUT0},
1416 {0x0082, SIERRA_DEQ_GLUT1},
1417 {0x00C3, SIERRA_DEQ_GLUT2},
1418 {0x0145, SIERRA_DEQ_GLUT3},
1419 {0x0186, SIERRA_DEQ_GLUT4},
1420 {0x09E7, SIERRA_DEQ_ALUT0},
1421 {0x09A6, SIERRA_DEQ_ALUT1},
1422 {0x0965, SIERRA_DEQ_ALUT2},
1423 {0x08E3, SIERRA_DEQ_ALUT3},
1424 {0x00FA, SIERRA_DEQ_DFETAP0},
1425 {0x00FA, SIERRA_DEQ_DFETAP1},
1426 {0x00FA, SIERRA_DEQ_DFETAP2},
1427 {0x00FA, SIERRA_DEQ_DFETAP3},
1428 {0x00FA, SIERRA_DEQ_DFETAP4},
1429 {0x000F, SIERRA_DEQ_PRECUR_PREG},
1430 {0x0280, SIERRA_DEQ_POSTCUR_PREG},
1431 {0x8F00, SIERRA_DEQ_POSTCUR_DECR_PREG},
1432 {0x3C0F, SIERRA_DEQ_TAU_CTRL1_SLOW_MAINT_PREG},
1433 {0x1C0C, SIERRA_DEQ_TAU_CTRL2_PREG},
1434 {0x0100, SIERRA_DEQ_TAU_CTRL3_PREG},
1435 {0x5E82, SIERRA_DEQ_OPENEYE_CTRL_PREG},
1436 {0x002B, SIERRA_CPI_TRIM_PREG},
1437 {0x0003, SIERRA_EPI_CTRL_PREG},
1438 {0x803F, SIERRA_SDFILT_H2L_A_PREG},
1439 {0x0004, SIERRA_RXBUFFER_CTLECTRL_PREG},
1440 {0x2010, SIERRA_RXBUFFER_RCDFECTRL_PREG},
1441 {0x4432, SIERRA_RXBUFFER_DFECTRL_PREG}
1442};
1443
1444static struct cdns_sierra_vals pcie_100_no_ssc_cmn_vals = {
1445 .reg_pairs = cdns_pcie_cmn_regs_no_ssc,
1446 .num_regs = ARRAY_SIZE(cdns_pcie_cmn_regs_no_ssc),
1447};
1448
1449static struct cdns_sierra_vals pcie_100_no_ssc_ln_vals = {
1450 .reg_pairs = cdns_pcie_ln_regs_no_ssc,
1451 .num_regs = ARRAY_SIZE(cdns_pcie_ln_regs_no_ssc),
1452};
1453
1454/* refclk100MHz_32b_PCIe_cmn_pll_int_ssc */
1455static const struct cdns_reg_pairs cdns_pcie_cmn_regs_int_ssc[] = {
1456 {0x000E, SIERRA_CMN_PLLLC_MODE_PREG},
1457 {0x4006, SIERRA_CMN_PLLLC_LF_COEFF_MODE1_PREG},
1458 {0x4006, SIERRA_CMN_PLLLC_LF_COEFF_MODE0_PREG},
1459 {0x0000, SIERRA_CMN_PLLLC_BWCAL_MODE1_PREG},
1460 {0x0000, SIERRA_CMN_PLLLC_BWCAL_MODE0_PREG},
1461 {0x0581, SIERRA_CMN_PLLLC_DSMCORR_PREG},
1462 {0x7F80, SIERRA_CMN_PLLLC_SS_PREG},
1463 {0x0041, SIERRA_CMN_PLLLC_SS_AMP_STEP_SIZE_PREG},
1464 {0x0464, SIERRA_CMN_PLLLC_SSTWOPT_PREG},
1465 {0x0D0D, SIERRA_CMN_PLLLC_SS_TIME_STEPSIZE_MODE_PREG},
1466 {0x0060, SIERRA_CMN_PLLLC_LOCK_DELAY_CTRL_PREG}
1467};
1468
1469/* refclk100MHz_32b_PCIe_ln_int_ssc */
1470static const struct cdns_reg_pairs cdns_pcie_ln_regs_int_ssc[] = {
1471 {0xFC08, SIERRA_DET_STANDEC_A_PREG},
1472 {0x001D, SIERRA_PSM_A3IN_TMR_PREG},
1473 {0x1555, SIERRA_DFE_BIASTRIM_PREG},
1474 {0x9703, SIERRA_DRVCTRL_BOOST_PREG},
1475 {0x813E, SIERRA_CLKPATHCTRL_TMR_PREG},
1476 {0x8047, SIERRA_RX_CREQ_FLTR_A_MODE3_PREG},
1477 {0x808F, SIERRA_RX_CREQ_FLTR_A_MODE2_PREG},
1478 {0x808F, SIERRA_RX_CREQ_FLTR_A_MODE1_PREG},
1479 {0x808F, SIERRA_RX_CREQ_FLTR_A_MODE0_PREG},
1480 {0x0002, SIERRA_CREQ_DCBIASATTEN_OVR_PREG},
1481 {0x9800, SIERRA_RX_CTLE_CAL_PREG},
1482 {0x033C, SIERRA_RX_CTLE_MAINTENANCE_PREG},
1483 {0x44CC, SIERRA_CREQ_EQ_OPEN_EYE_THRESH_PREG},
1484 {0x5624, SIERRA_DEQ_CONCUR_CTRL2_PREG},
1485 {0x000F, SIERRA_DEQ_EPIPWR_CTRL2_PREG},
1486 {0x00FF, SIERRA_DEQ_FAST_MAINT_CYCLES_PREG},
1487 {0x4C4C, SIERRA_DEQ_ERRCMP_CTRL_PREG},
1488 {0x02FA, SIERRA_DEQ_OFFSET_CTRL_PREG},
1489 {0x02FA, SIERRA_DEQ_GAIN_CTRL_PREG},
1490 {0x0041, SIERRA_DEQ_GLUT0},
1491 {0x0082, SIERRA_DEQ_GLUT1},
1492 {0x00C3, SIERRA_DEQ_GLUT2},
1493 {0x0145, SIERRA_DEQ_GLUT3},
1494 {0x0186, SIERRA_DEQ_GLUT4},
1495 {0x09E7, SIERRA_DEQ_ALUT0},
1496 {0x09A6, SIERRA_DEQ_ALUT1},
1497 {0x0965, SIERRA_DEQ_ALUT2},
1498 {0x08E3, SIERRA_DEQ_ALUT3},
1499 {0x00FA, SIERRA_DEQ_DFETAP0},
1500 {0x00FA, SIERRA_DEQ_DFETAP1},
1501 {0x00FA, SIERRA_DEQ_DFETAP2},
1502 {0x00FA, SIERRA_DEQ_DFETAP3},
1503 {0x00FA, SIERRA_DEQ_DFETAP4},
1504 {0x000F, SIERRA_DEQ_PRECUR_PREG},
1505 {0x0280, SIERRA_DEQ_POSTCUR_PREG},
1506 {0x8F00, SIERRA_DEQ_POSTCUR_DECR_PREG},
1507 {0x3C0F, SIERRA_DEQ_TAU_CTRL1_SLOW_MAINT_PREG},
1508 {0x1C0C, SIERRA_DEQ_TAU_CTRL2_PREG},
1509 {0x0100, SIERRA_DEQ_TAU_CTRL3_PREG},
1510 {0x5E82, SIERRA_DEQ_OPENEYE_CTRL_PREG},
1511 {0x002B, SIERRA_CPI_TRIM_PREG},
1512 {0x0003, SIERRA_EPI_CTRL_PREG},
1513 {0x803F, SIERRA_SDFILT_H2L_A_PREG},
1514 {0x0004, SIERRA_RXBUFFER_CTLECTRL_PREG},
1515 {0x2010, SIERRA_RXBUFFER_RCDFECTRL_PREG},
1516 {0x4432, SIERRA_RXBUFFER_DFECTRL_PREG}
1517};
1518
1519static struct cdns_sierra_vals pcie_100_int_ssc_cmn_vals = {
1520 .reg_pairs = cdns_pcie_cmn_regs_int_ssc,
1521 .num_regs = ARRAY_SIZE(cdns_pcie_cmn_regs_int_ssc),
1522};
1523
1524static struct cdns_sierra_vals pcie_100_int_ssc_ln_vals = {
1525 .reg_pairs = cdns_pcie_ln_regs_int_ssc,
1526 .num_regs = ARRAY_SIZE(cdns_pcie_ln_regs_int_ssc),
1527};
1528
Anil Varughese871002d2019-12-16 15:27:05 +05301529/* refclk100MHz_32b_PCIe_cmn_pll_ext_ssc */
Rikard Falkeborn3cfb0e82020-09-12 22:46:37 +02001530static const struct cdns_reg_pairs cdns_pcie_cmn_regs_ext_ssc[] = {
Anil Varughese871002d2019-12-16 15:27:05 +05301531 {0x2106, SIERRA_CMN_PLLLC_LF_COEFF_MODE1_PREG},
1532 {0x2106, SIERRA_CMN_PLLLC_LF_COEFF_MODE0_PREG},
1533 {0x8A06, SIERRA_CMN_PLLLC_BWCAL_MODE1_PREG},
1534 {0x8A06, SIERRA_CMN_PLLLC_BWCAL_MODE0_PREG},
1535 {0x1B1B, SIERRA_CMN_PLLLC_SS_TIME_STEPSIZE_MODE_PREG}
1536};
1537
1538/* refclk100MHz_32b_PCIe_ln_ext_ssc */
Rikard Falkeborn3cfb0e82020-09-12 22:46:37 +02001539static const struct cdns_reg_pairs cdns_pcie_ln_regs_ext_ssc[] = {
Swapnil Jakhade7a5ad9b2021-12-23 07:01:32 +01001540 {0xFC08, SIERRA_DET_STANDEC_A_PREG},
1541 {0x001D, SIERRA_PSM_A3IN_TMR_PREG},
1542 {0x1555, SIERRA_DFE_BIASTRIM_PREG},
1543 {0x9703, SIERRA_DRVCTRL_BOOST_PREG},
Anil Varughese871002d2019-12-16 15:27:05 +05301544 {0x813E, SIERRA_CLKPATHCTRL_TMR_PREG},
1545 {0x8047, SIERRA_RX_CREQ_FLTR_A_MODE3_PREG},
1546 {0x808F, SIERRA_RX_CREQ_FLTR_A_MODE2_PREG},
1547 {0x808F, SIERRA_RX_CREQ_FLTR_A_MODE1_PREG},
1548 {0x808F, SIERRA_RX_CREQ_FLTR_A_MODE0_PREG},
Swapnil Jakhade7a5ad9b2021-12-23 07:01:32 +01001549 {0x0002, SIERRA_CREQ_DCBIASATTEN_OVR_PREG},
1550 {0x9800, SIERRA_RX_CTLE_CAL_PREG},
Anil Varughese871002d2019-12-16 15:27:05 +05301551 {0x033C, SIERRA_RX_CTLE_MAINTENANCE_PREG},
Swapnil Jakhade7a5ad9b2021-12-23 07:01:32 +01001552 {0x44CC, SIERRA_CREQ_EQ_OPEN_EYE_THRESH_PREG},
1553 {0x5624, SIERRA_DEQ_CONCUR_CTRL2_PREG},
1554 {0x000F, SIERRA_DEQ_EPIPWR_CTRL2_PREG},
1555 {0x00FF, SIERRA_DEQ_FAST_MAINT_CYCLES_PREG},
1556 {0x4C4C, SIERRA_DEQ_ERRCMP_CTRL_PREG},
1557 {0x02FA, SIERRA_DEQ_OFFSET_CTRL_PREG},
1558 {0x02FA, SIERRA_DEQ_GAIN_CTRL_PREG},
1559 {0x0041, SIERRA_DEQ_GLUT0},
1560 {0x0082, SIERRA_DEQ_GLUT1},
1561 {0x00C3, SIERRA_DEQ_GLUT2},
1562 {0x0145, SIERRA_DEQ_GLUT3},
1563 {0x0186, SIERRA_DEQ_GLUT4},
1564 {0x09E7, SIERRA_DEQ_ALUT0},
1565 {0x09A6, SIERRA_DEQ_ALUT1},
1566 {0x0965, SIERRA_DEQ_ALUT2},
1567 {0x08E3, SIERRA_DEQ_ALUT3},
1568 {0x00FA, SIERRA_DEQ_DFETAP0},
1569 {0x00FA, SIERRA_DEQ_DFETAP1},
1570 {0x00FA, SIERRA_DEQ_DFETAP2},
1571 {0x00FA, SIERRA_DEQ_DFETAP3},
1572 {0x00FA, SIERRA_DEQ_DFETAP4},
1573 {0x000F, SIERRA_DEQ_PRECUR_PREG},
1574 {0x0280, SIERRA_DEQ_POSTCUR_PREG},
1575 {0x8F00, SIERRA_DEQ_POSTCUR_DECR_PREG},
1576 {0x3C0F, SIERRA_DEQ_TAU_CTRL1_SLOW_MAINT_PREG},
1577 {0x1C0C, SIERRA_DEQ_TAU_CTRL2_PREG},
1578 {0x0100, SIERRA_DEQ_TAU_CTRL3_PREG},
1579 {0x5E82, SIERRA_DEQ_OPENEYE_CTRL_PREG},
1580 {0x002B, SIERRA_CPI_TRIM_PREG},
1581 {0x0003, SIERRA_EPI_CTRL_PREG},
1582 {0x803F, SIERRA_SDFILT_H2L_A_PREG},
1583 {0x0004, SIERRA_RXBUFFER_CTLECTRL_PREG},
1584 {0x2010, SIERRA_RXBUFFER_RCDFECTRL_PREG},
1585 {0x4432, SIERRA_RXBUFFER_DFECTRL_PREG}
Anil Varughese871002d2019-12-16 15:27:05 +05301586};
1587
Swapnil Jakhade078e9e92021-12-23 07:01:24 +01001588static struct cdns_sierra_vals pcie_100_ext_ssc_cmn_vals = {
1589 .reg_pairs = cdns_pcie_cmn_regs_ext_ssc,
1590 .num_regs = ARRAY_SIZE(cdns_pcie_cmn_regs_ext_ssc),
1591};
1592
1593static struct cdns_sierra_vals pcie_100_ext_ssc_ln_vals = {
1594 .reg_pairs = cdns_pcie_ln_regs_ext_ssc,
1595 .num_regs = ARRAY_SIZE(cdns_pcie_ln_regs_ext_ssc),
1596};
1597
Anil Varughese871002d2019-12-16 15:27:05 +05301598/* refclk100MHz_20b_USB_cmn_pll_ext_ssc */
Rikard Falkeborn3cfb0e82020-09-12 22:46:37 +02001599static const struct cdns_reg_pairs cdns_usb_cmn_regs_ext_ssc[] = {
Anil Varughese871002d2019-12-16 15:27:05 +05301600 {0x2085, SIERRA_CMN_PLLLC_LF_COEFF_MODE1_PREG},
1601 {0x2085, SIERRA_CMN_PLLLC_LF_COEFF_MODE0_PREG},
1602 {0x0000, SIERRA_CMN_PLLLC_BWCAL_MODE0_PREG},
1603 {0x0000, SIERRA_CMN_PLLLC_SS_TIME_STEPSIZE_MODE_PREG}
1604};
1605
1606/* refclk100MHz_20b_USB_ln_ext_ssc */
Rikard Falkeborn3cfb0e82020-09-12 22:46:37 +02001607static const struct cdns_reg_pairs cdns_usb_ln_regs_ext_ssc[] = {
Kishon Vijay Abraham Iaead5fd2019-12-16 15:27:04 +05301608 {0xFE0A, SIERRA_DET_STANDEC_A_PREG},
1609 {0x000F, SIERRA_DET_STANDEC_B_PREG},
Sanket Parmar2bcf14c2020-05-18 14:14:13 +02001610 {0x55A5, SIERRA_DET_STANDEC_C_PREG},
Anil Varughese871002d2019-12-16 15:27:05 +05301611 {0x69ad, SIERRA_DET_STANDEC_D_PREG},
Kishon Vijay Abraham Iaead5fd2019-12-16 15:27:04 +05301612 {0x0241, SIERRA_DET_STANDEC_E_PREG},
Sanket Parmar2bcf14c2020-05-18 14:14:13 +02001613 {0x0110, SIERRA_PSM_LANECAL_DLY_A1_RESETS_PREG},
Anil Varughese871002d2019-12-16 15:27:05 +05301614 {0x0014, SIERRA_PSM_A0IN_TMR_PREG},
Kishon Vijay Abraham Iaead5fd2019-12-16 15:27:04 +05301615 {0xCF00, SIERRA_PSM_DIAG_PREG},
1616 {0x001F, SIERRA_PSC_TX_A0_PREG},
1617 {0x0007, SIERRA_PSC_TX_A1_PREG},
1618 {0x0003, SIERRA_PSC_TX_A2_PREG},
1619 {0x0003, SIERRA_PSC_TX_A3_PREG},
1620 {0x0FFF, SIERRA_PSC_RX_A0_PREG},
Sanket Parmar2bcf14c2020-05-18 14:14:13 +02001621 {0x0003, SIERRA_PSC_RX_A1_PREG},
Kishon Vijay Abraham Iaead5fd2019-12-16 15:27:04 +05301622 {0x0003, SIERRA_PSC_RX_A2_PREG},
1623 {0x0001, SIERRA_PSC_RX_A3_PREG},
1624 {0x0001, SIERRA_PLLCTRL_SUBRATE_PREG},
1625 {0x0406, SIERRA_PLLCTRL_GEN_D_PREG},
Anil Varughese871002d2019-12-16 15:27:05 +05301626 {0x5233, SIERRA_PLLCTRL_CPGAIN_MODE_PREG},
1627 {0x00CA, SIERRA_CLKPATH_BIASTRIM_PREG},
1628 {0x2512, SIERRA_DFE_BIASTRIM_PREG},
Kishon Vijay Abraham Iaead5fd2019-12-16 15:27:04 +05301629 {0x0000, SIERRA_DRVCTRL_ATTEN_PREG},
Sanket Parmar2bcf14c2020-05-18 14:14:13 +02001630 {0x823E, SIERRA_CLKPATHCTRL_TMR_PREG},
1631 {0x078F, SIERRA_RX_CREQ_FLTR_A_MODE1_PREG},
1632 {0x078F, SIERRA_RX_CREQ_FLTR_A_MODE0_PREG},
Kishon Vijay Abraham Iaead5fd2019-12-16 15:27:04 +05301633 {0x7B3C, SIERRA_CREQ_CCLKDET_MODE01_PREG},
Sanket Parmar2bcf14c2020-05-18 14:14:13 +02001634 {0x023C, SIERRA_RX_CTLE_MAINTENANCE_PREG},
Kishon Vijay Abraham Iaead5fd2019-12-16 15:27:04 +05301635 {0x3232, SIERRA_CREQ_FSMCLK_SEL_PREG},
Anil Varughese871002d2019-12-16 15:27:05 +05301636 {0x0000, SIERRA_CREQ_EQ_CTRL_PREG},
Sanket Parmar2bcf14c2020-05-18 14:14:13 +02001637 {0x0000, SIERRA_CREQ_SPARE_PREG},
Anil Varughese871002d2019-12-16 15:27:05 +05301638 {0xCC44, SIERRA_CREQ_EQ_OPEN_EYE_THRESH_PREG},
Sanket Parmar2bcf14c2020-05-18 14:14:13 +02001639 {0x8452, SIERRA_CTLELUT_CTRL_PREG},
1640 {0x4121, SIERRA_DFE_ECMP_RATESEL_PREG},
1641 {0x4121, SIERRA_DFE_SMP_RATESEL_PREG},
1642 {0x0003, SIERRA_DEQ_PHALIGN_CTRL},
Anil Varughese871002d2019-12-16 15:27:05 +05301643 {0x3200, SIERRA_DEQ_CONCUR_CTRL1_PREG},
1644 {0x5064, SIERRA_DEQ_CONCUR_CTRL2_PREG},
1645 {0x0030, SIERRA_DEQ_EPIPWR_CTRL2_PREG},
1646 {0x0048, SIERRA_DEQ_FAST_MAINT_CYCLES_PREG},
1647 {0x5A5A, SIERRA_DEQ_ERRCMP_CTRL_PREG},
1648 {0x02F5, SIERRA_DEQ_OFFSET_CTRL_PREG},
1649 {0x02F5, SIERRA_DEQ_GAIN_CTRL_PREG},
Sanket Parmar2bcf14c2020-05-18 14:14:13 +02001650 {0x9999, SIERRA_DEQ_VGATUNE_CTRL_PREG},
Anil Varughese871002d2019-12-16 15:27:05 +05301651 {0x0014, SIERRA_DEQ_GLUT0},
1652 {0x0014, SIERRA_DEQ_GLUT1},
1653 {0x0014, SIERRA_DEQ_GLUT2},
1654 {0x0014, SIERRA_DEQ_GLUT3},
1655 {0x0014, SIERRA_DEQ_GLUT4},
1656 {0x0014, SIERRA_DEQ_GLUT5},
1657 {0x0014, SIERRA_DEQ_GLUT6},
1658 {0x0014, SIERRA_DEQ_GLUT7},
1659 {0x0014, SIERRA_DEQ_GLUT8},
1660 {0x0014, SIERRA_DEQ_GLUT9},
1661 {0x0014, SIERRA_DEQ_GLUT10},
1662 {0x0014, SIERRA_DEQ_GLUT11},
1663 {0x0014, SIERRA_DEQ_GLUT12},
1664 {0x0014, SIERRA_DEQ_GLUT13},
1665 {0x0014, SIERRA_DEQ_GLUT14},
1666 {0x0014, SIERRA_DEQ_GLUT15},
1667 {0x0014, SIERRA_DEQ_GLUT16},
1668 {0x0BAE, SIERRA_DEQ_ALUT0},
1669 {0x0AEB, SIERRA_DEQ_ALUT1},
1670 {0x0A28, SIERRA_DEQ_ALUT2},
1671 {0x0965, SIERRA_DEQ_ALUT3},
1672 {0x08A2, SIERRA_DEQ_ALUT4},
1673 {0x07DF, SIERRA_DEQ_ALUT5},
1674 {0x071C, SIERRA_DEQ_ALUT6},
1675 {0x0659, SIERRA_DEQ_ALUT7},
1676 {0x0596, SIERRA_DEQ_ALUT8},
1677 {0x0514, SIERRA_DEQ_ALUT9},
1678 {0x0492, SIERRA_DEQ_ALUT10},
1679 {0x0410, SIERRA_DEQ_ALUT11},
1680 {0x038E, SIERRA_DEQ_ALUT12},
1681 {0x030C, SIERRA_DEQ_ALUT13},
1682 {0x03F4, SIERRA_DEQ_DFETAP_CTRL_PREG},
1683 {0x0001, SIERRA_DFE_EN_1010_IGNORE_PREG},
1684 {0x3C01, SIERRA_DEQ_TAU_CTRL1_FAST_MAINT_PREG},
1685 {0x3C40, SIERRA_DEQ_TAU_CTRL1_SLOW_MAINT_PREG},
1686 {0x1C08, SIERRA_DEQ_TAU_CTRL2_PREG},
1687 {0x0033, SIERRA_DEQ_PICTRL_PREG},
1688 {0x0400, SIERRA_CPICAL_TMRVAL_MODE1_PREG},
1689 {0x0330, SIERRA_CPICAL_TMRVAL_MODE0_PREG},
1690 {0x01FF, SIERRA_CPICAL_PICNT_MODE1_PREG},
Kishon Vijay Abraham Iaead5fd2019-12-16 15:27:04 +05301691 {0x0009, SIERRA_CPI_OUTBUF_RATESEL_PREG},
Anil Varughese871002d2019-12-16 15:27:05 +05301692 {0x3232, SIERRA_CPICAL_RES_STARTCODE_MODE23_PREG},
1693 {0x0005, SIERRA_LFPSDET_SUPPORT_PREG},
Kishon Vijay Abraham Iaead5fd2019-12-16 15:27:04 +05301694 {0x000F, SIERRA_LFPSFILT_NS_PREG},
1695 {0x0009, SIERRA_LFPSFILT_RD_PREG},
1696 {0x0001, SIERRA_LFPSFILT_MP_PREG},
Sanket Parmar2bcf14c2020-05-18 14:14:13 +02001697 {0x6013, SIERRA_SIGDET_SUPPORT_PREG},
Kishon Vijay Abraham Iaead5fd2019-12-16 15:27:04 +05301698 {0x8013, SIERRA_SDFILT_H2L_A_PREG},
Anil Varughese871002d2019-12-16 15:27:05 +05301699 {0x8009, SIERRA_SDFILT_L2H_PREG},
1700 {0x0024, SIERRA_RXBUFFER_CTLECTRL_PREG},
1701 {0x0020, SIERRA_RXBUFFER_RCDFECTRL_PREG},
1702 {0x4243, SIERRA_RXBUFFER_DFECTRL_PREG}
Alan Douglas44d30d62018-11-12 16:42:16 +00001703};
1704
Swapnil Jakhade078e9e92021-12-23 07:01:24 +01001705static struct cdns_sierra_vals usb_100_ext_ssc_cmn_vals = {
1706 .reg_pairs = cdns_usb_cmn_regs_ext_ssc,
1707 .num_regs = ARRAY_SIZE(cdns_usb_cmn_regs_ext_ssc),
1708};
1709
1710static struct cdns_sierra_vals usb_100_ext_ssc_ln_vals = {
1711 .reg_pairs = cdns_usb_ln_regs_ext_ssc,
1712 .num_regs = ARRAY_SIZE(cdns_usb_ln_regs_ext_ssc),
1713};
1714
Alan Douglas44d30d62018-11-12 16:42:16 +00001715static const struct cdns_sierra_data cdns_map_sierra = {
Swapnil Jakhade078e9e92021-12-23 07:01:24 +01001716 .id_value = SIERRA_MACRO_ID,
1717 .block_offset_shift = 0x2,
1718 .reg_offset_shift = 0x2,
Swapnil Jakhadefa105172021-12-23 07:01:29 +01001719 .pcs_cmn_vals = {
1720 [TYPE_PCIE] = {
1721 [TYPE_NONE] = {
Swapnil Jakhade7a5ad9b2021-12-23 07:01:32 +01001722 [NO_SSC] = &pcie_phy_pcs_cmn_vals,
Swapnil Jakhadefa105172021-12-23 07:01:29 +01001723 [EXTERNAL_SSC] = &pcie_phy_pcs_cmn_vals,
Swapnil Jakhade7a5ad9b2021-12-23 07:01:32 +01001724 [INTERNAL_SSC] = &pcie_phy_pcs_cmn_vals,
Swapnil Jakhadefa105172021-12-23 07:01:29 +01001725 },
1726 },
1727 },
Swapnil Jakhade078e9e92021-12-23 07:01:24 +01001728 .pma_cmn_vals = {
1729 [TYPE_PCIE] = {
1730 [TYPE_NONE] = {
Swapnil Jakhade7a5ad9b2021-12-23 07:01:32 +01001731 [NO_SSC] = &pcie_100_no_ssc_cmn_vals,
Swapnil Jakhade078e9e92021-12-23 07:01:24 +01001732 [EXTERNAL_SSC] = &pcie_100_ext_ssc_cmn_vals,
Swapnil Jakhade7a5ad9b2021-12-23 07:01:32 +01001733 [INTERNAL_SSC] = &pcie_100_int_ssc_cmn_vals,
Swapnil Jakhade078e9e92021-12-23 07:01:24 +01001734 },
1735 },
1736 [TYPE_USB] = {
1737 [TYPE_NONE] = {
1738 [EXTERNAL_SSC] = &usb_100_ext_ssc_cmn_vals,
1739 },
1740 },
1741 },
1742 .pma_ln_vals = {
1743 [TYPE_PCIE] = {
1744 [TYPE_NONE] = {
Swapnil Jakhade7a5ad9b2021-12-23 07:01:32 +01001745 [NO_SSC] = &pcie_100_no_ssc_ln_vals,
Swapnil Jakhade078e9e92021-12-23 07:01:24 +01001746 [EXTERNAL_SSC] = &pcie_100_ext_ssc_ln_vals,
Swapnil Jakhade7a5ad9b2021-12-23 07:01:32 +01001747 [INTERNAL_SSC] = &pcie_100_int_ssc_ln_vals,
Swapnil Jakhade078e9e92021-12-23 07:01:24 +01001748 },
1749 },
1750 [TYPE_USB] = {
1751 [TYPE_NONE] = {
1752 [EXTERNAL_SSC] = &usb_100_ext_ssc_ln_vals,
1753 },
1754 },
1755 },
Alan Douglas44d30d62018-11-12 16:42:16 +00001756};
1757
Kishon Vijay Abraham I367da972019-12-16 15:27:02 +05301758static const struct cdns_sierra_data cdns_ti_map_sierra = {
Swapnil Jakhade078e9e92021-12-23 07:01:24 +01001759 .id_value = SIERRA_MACRO_ID,
1760 .block_offset_shift = 0x0,
1761 .reg_offset_shift = 0x1,
Swapnil Jakhadefa105172021-12-23 07:01:29 +01001762 .pcs_cmn_vals = {
1763 [TYPE_PCIE] = {
1764 [TYPE_NONE] = {
Swapnil Jakhade7a5ad9b2021-12-23 07:01:32 +01001765 [NO_SSC] = &pcie_phy_pcs_cmn_vals,
Swapnil Jakhadefa105172021-12-23 07:01:29 +01001766 [EXTERNAL_SSC] = &pcie_phy_pcs_cmn_vals,
Swapnil Jakhade7a5ad9b2021-12-23 07:01:32 +01001767 [INTERNAL_SSC] = &pcie_phy_pcs_cmn_vals,
Swapnil Jakhadefa105172021-12-23 07:01:29 +01001768 },
1769 },
1770 },
Swapnil Jakhade078e9e92021-12-23 07:01:24 +01001771 .pma_cmn_vals = {
1772 [TYPE_PCIE] = {
1773 [TYPE_NONE] = {
Swapnil Jakhade7a5ad9b2021-12-23 07:01:32 +01001774 [NO_SSC] = &pcie_100_no_ssc_cmn_vals,
Swapnil Jakhade078e9e92021-12-23 07:01:24 +01001775 [EXTERNAL_SSC] = &pcie_100_ext_ssc_cmn_vals,
Swapnil Jakhade7a5ad9b2021-12-23 07:01:32 +01001776 [INTERNAL_SSC] = &pcie_100_int_ssc_cmn_vals,
Swapnil Jakhade078e9e92021-12-23 07:01:24 +01001777 },
1778 },
1779 [TYPE_USB] = {
1780 [TYPE_NONE] = {
1781 [EXTERNAL_SSC] = &usb_100_ext_ssc_cmn_vals,
1782 },
1783 },
1784 },
1785 .pma_ln_vals = {
1786 [TYPE_PCIE] = {
1787 [TYPE_NONE] = {
Swapnil Jakhade7a5ad9b2021-12-23 07:01:32 +01001788 [NO_SSC] = &pcie_100_no_ssc_ln_vals,
Swapnil Jakhade078e9e92021-12-23 07:01:24 +01001789 [EXTERNAL_SSC] = &pcie_100_ext_ssc_ln_vals,
Swapnil Jakhade7a5ad9b2021-12-23 07:01:32 +01001790 [INTERNAL_SSC] = &pcie_100_int_ssc_ln_vals,
Swapnil Jakhade078e9e92021-12-23 07:01:24 +01001791 },
1792 },
1793 [TYPE_USB] = {
1794 [TYPE_NONE] = {
1795 [EXTERNAL_SSC] = &usb_100_ext_ssc_ln_vals,
1796 },
1797 },
1798 },
Kishon Vijay Abraham I367da972019-12-16 15:27:02 +05301799};
1800
Alan Douglas44d30d62018-11-12 16:42:16 +00001801static const struct of_device_id cdns_sierra_id_table[] = {
1802 {
1803 .compatible = "cdns,sierra-phy-t0",
1804 .data = &cdns_map_sierra,
1805 },
Kishon Vijay Abraham I367da972019-12-16 15:27:02 +05301806 {
1807 .compatible = "ti,sierra-phy-t0",
1808 .data = &cdns_ti_map_sierra,
1809 },
Alan Douglas44d30d62018-11-12 16:42:16 +00001810 {}
1811};
1812MODULE_DEVICE_TABLE(of, cdns_sierra_id_table);
1813
1814static struct platform_driver cdns_sierra_driver = {
1815 .probe = cdns_sierra_phy_probe,
1816 .remove = cdns_sierra_phy_remove,
1817 .driver = {
1818 .name = "cdns-sierra-phy",
1819 .of_match_table = cdns_sierra_id_table,
1820 },
1821};
1822module_platform_driver(cdns_sierra_driver);
1823
1824MODULE_ALIAS("platform:cdns_sierra");
1825MODULE_AUTHOR("Cadence Design Systems");
1826MODULE_DESCRIPTION("CDNS sierra phy driver");
1827MODULE_LICENSE("GPL v2");