summaryrefslogtreecommitdiff
path: root/drivers/net/phy/mscc/mscc_serdes.c
blob: b3e854f53d67552e754f8cd9b378ed6e257962a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
// SPDX-License-Identifier: (GPL-2.0 OR MIT)
/*
 * Driver for Microsemi VSC85xx PHYs
 *
 * Author: Bjarni Jonasson <bjarni.jonassoni@microchip.com>
 * License: Dual MIT/GPL
 * Copyright (c) 2021 Microsemi Corporation
 */

#include <linux/phy.h>
#include "mscc_serdes.h"
#include "mscc.h"

static int pll5g_detune(struct phy_device *phydev)
{
	u32 rd_dat;
	int ret;

	rd_dat = vsc85xx_csr_read(phydev, MACRO_CTRL, PHY_S6G_PLL5G_CFG2);
	rd_dat &= ~PHY_S6G_PLL5G_CFG2_GAIN_MASK;
	rd_dat |= PHY_S6G_PLL5G_CFG2_ENA_GAIN;
	ret = vsc85xx_csr_write(phydev, MACRO_CTRL,
				PHY_S6G_PLL5G_CFG2, rd_dat);
	if (ret)
		dev_err(&phydev->mdio.dev, "%s: write error\n", __func__);
	return ret;
}

static int pll5g_tune(struct phy_device *phydev)
{
	u32 rd_dat;
	int ret;

	rd_dat = vsc85xx_csr_read(phydev, MACRO_CTRL, PHY_S6G_PLL5G_CFG2);
	rd_dat &= ~PHY_S6G_PLL5G_CFG2_ENA_GAIN;
	ret = vsc85xx_csr_write(phydev, MACRO_CTRL,
				PHY_S6G_PLL5G_CFG2, rd_dat);
	if (ret)
		dev_err(&phydev->mdio.dev, "%s: write error\n", __func__);
	return ret;
}

static int vsc85xx_sd6g_pll_cfg_wr(struct phy_device *phydev,
				   const u32 pll_ena_offs,
				   const u32 pll_fsm_ctrl_data,
				   const u32 pll_fsm_ena)
{
	int ret;

	ret = vsc85xx_csr_write(phydev, MACRO_CTRL,
				PHY_S6G_PLL_CFG,
				(pll_fsm_ena << PHY_S6G_PLL_ENA_OFFS_POS) |
				(pll_fsm_ctrl_data << PHY_S6G_PLL_FSM_CTRL_DATA_POS) |
				(pll_ena_offs << PHY_S6G_PLL_FSM_ENA_POS));
	if (ret)
		dev_err(&phydev->mdio.dev, "%s: write error\n", __func__);
	return ret;
}

static int vsc85xx_sd6g_common_cfg_wr(struct phy_device *phydev,
				      const u32 sys_rst,
				      const u32 ena_lane,
				      const u32 ena_loop,
				      const u32 qrate,
				      const u32 if_mode,
				      const u32 pwd_tx)
{
	/* ena_loop = 8 for eloop */
	/*          = 4 for floop */
	/*          = 2 for iloop */
	/*          = 1 for ploop */
	/* qrate    = 1 for SGMII, 0 for QSGMII */
	/* if_mode  = 1 for SGMII, 3 for QSGMII */

	int ret;

	ret = vsc85xx_csr_write(phydev, MACRO_CTRL,
				PHY_S6G_COMMON_CFG,
				(sys_rst << PHY_S6G_SYS_RST_POS) |
				(ena_lane << PHY_S6G_ENA_LANE_POS) |
				(ena_loop << PHY_S6G_ENA_LOOP_POS) |
				(qrate << PHY_S6G_QRATE_POS) |
				(if_mode << PHY_S6G_IF_MODE_POS));
	if (ret)
		dev_err(&phydev->mdio.dev, "%s: write error\n", __func__);
	return ret;
}

static int vsc85xx_sd6g_des_cfg_wr(struct phy_device *phydev,
				   const u32 des_phy_ctrl,
				   const u32 des_mbtr_ctrl,
				   const u32 des_bw_hyst,
				   const u32 des_bw_ana,
				   const u32 des_cpmd_sel)
{
	u32 reg_val;
	int ret;

	/* configurable terms */
	reg_val = (des_phy_ctrl << PHY_S6G_DES_PHY_CTRL_POS) |
		  (des_mbtr_ctrl << PHY_S6G_DES_MBTR_CTRL_POS) |
		  (des_cpmd_sel << PHY_S6G_DES_CPMD_SEL_POS) |
		  (des_bw_hyst << PHY_S6G_DES_BW_HYST_POS) |
		  (des_bw_ana << PHY_S6G_DES_BW_ANA_POS);
	ret = vsc85xx_csr_write(phydev, MACRO_CTRL,
				PHY_S6G_DES_CFG,
				reg_val);
	if (ret)
		dev_err(&phydev->mdio.dev, "%s: write error\n", __func__);
	return ret;
}

static int vsc85xx_sd6g_ib_cfg0_wr(struct phy_device *phydev,
				   const u32 ib_rtrm_adj,
				   const u32 ib_sig_det_clk_sel,
				   const u32 ib_reg_pat_sel_offset,
				   const u32 ib_cal_ena)
{
	u32 base_val;
	u32 reg_val;
	int ret;

	/* constant terms */
	base_val = 0x60a85837;
	/* configurable terms */
	reg_val = base_val | (ib_rtrm_adj << 25) |
		  (ib_sig_det_clk_sel << 16) |
		  (ib_reg_pat_sel_offset << 8) |
		  (ib_cal_ena << 3);
	ret = vsc85xx_csr_write(phydev, MACRO_CTRL,
				PHY_S6G_IB_CFG0,
				reg_val);
	if (ret)
		dev_err(&phydev->mdio.dev, "%s: write error\n", __func__);
	return ret;
}

static int vsc85xx_sd6g_ib_cfg1_wr(struct phy_device *phydev,
				   const u32 ib_tjtag,
				   const u32 ib_tsdet,
				   const u32 ib_scaly,
				   const u32 ib_frc_offset,
				   const u32 ib_filt_offset)
{
	u32 ib_filt_val;
	u32 reg_val = 0;
	int ret;

	/* constant terms */
	ib_filt_val = 0xe0;
	/* configurable terms */
	reg_val  = (ib_tjtag << 17) + (ib_tsdet << 12) + (ib_scaly << 8) +
		   ib_filt_val + (ib_filt_offset << 4) + (ib_frc_offset << 0);
	ret = vsc85xx_csr_write(phydev, MACRO_CTRL,
				PHY_S6G_IB_CFG1,
				reg_val);
	if (ret)
		dev_err(&phydev->mdio.dev, "%s: write error\n", __func__);
	return ret;
}

static int vsc85xx_sd6g_ib_cfg2_wr(struct phy_device *phydev,
				   const u32 ib_tinfv,
				   const u32 ib_tcalv,
				   const u32 ib_ureg)
{
	u32 ib_cfg2_val;
	u32 base_val;
	int ret;

	/* constant terms */
	base_val = 0x0f878010;
	/* configurable terms */
	ib_cfg2_val = base_val | ((ib_tinfv) << 28) | ((ib_tcalv) << 5) |
		      (ib_ureg << 0);
	ret = vsc85xx_csr_write(phydev, MACRO_CTRL,
				PHY_S6G_IB_CFG2,
				ib_cfg2_val);
	if (ret)
		dev_err(&phydev->mdio.dev, "%s: write error\n", __func__);
	return ret;
}

static int vsc85xx_sd6g_ib_cfg3_wr(struct phy_device *phydev,
				   const u32 ib_ini_hp,
				   const u32 ib_ini_mid,
				   const u32 ib_ini_lp,
				   const u32 ib_ini_offset)
{
	u32 reg_val;
	int ret;

	reg_val  = (ib_ini_hp << 24) + (ib_ini_mid << 16) +
		   (ib_ini_lp << 8) + (ib_ini_offset << 0);
	ret = vsc85xx_csr_write(phydev, MACRO_CTRL,
				PHY_S6G_IB_CFG3,
				reg_val);
	if (ret)
		dev_err(&phydev->mdio.dev, "%s: write error\n", __func__);
	return ret;
}

static int vsc85xx_sd6g_ib_cfg4_wr(struct phy_device *phydev,
				   const u32 ib_max_hp,
				   const u32 ib_max_mid,
				   const u32 ib_max_lp,
				   const u32 ib_max_offset)
{
	u32 reg_val;
	int ret;

	reg_val  = (ib_max_hp << 24) + (ib_max_mid << 16) +
		   (ib_max_lp << 8) + (ib_max_offset << 0);
	ret = vsc85xx_csr_write(phydev, MACRO_CTRL,
				PHY_S6G_IB_CFG4,
				reg_val);
	if (ret)
		dev_err(&phydev->mdio.dev, "%s: write error\n", __func__);
	return ret;
}

static int vsc85xx_sd6g_misc_cfg_wr(struct phy_device *phydev,
				    const u32 lane_rst)
{
	int ret;

	ret = vsc85xx_csr_write(phydev, MACRO_CTRL,
				PHY_S6G_MISC_CFG,
				lane_rst);
	if (ret)
		dev_err(&phydev->mdio.dev, "%s: write error\n", __func__);
	return ret;
}

static int vsc85xx_sd6g_gp_cfg_wr(struct phy_device *phydev, const u32 gp_cfg_val)
{
	int ret;

	ret = vsc85xx_csr_write(phydev, MACRO_CTRL,
				PHY_S6G_GP_CFG,
				gp_cfg_val);
	if (ret)
		dev_err(&phydev->mdio.dev, "%s: write error\n", __func__);
	return ret;
}

static int vsc85xx_sd6g_dft_cfg2_wr(struct phy_device *phydev,
				    const u32 rx_ji_ampl,
				    const u32 rx_step_freq,
				    const u32 rx_ji_ena,
				    const u32 rx_waveform_sel,
				    const u32 rx_freqoff_dir,
				    const u32 rx_freqoff_ena)
{
	u32 reg_val;
	int ret;

	/* configurable terms */
	reg_val = (rx_ji_ampl << 8) | (rx_step_freq << 4) |
		  (rx_ji_ena << 3) | (rx_waveform_sel << 2) |
		  (rx_freqoff_dir << 1) | rx_freqoff_ena;
	ret = vsc85xx_csr_write(phydev, MACRO_CTRL,
				PHY_S6G_IB_DFT_CFG2,
				reg_val);
	if (ret)
		dev_err(&phydev->mdio.dev, "%s: write error\n", __func__);
	return ret;
}

static int vsc85xx_sd6g_dft_cfg0_wr(struct phy_device *phydev,
				    const u32 prbs_sel,
				    const u32 test_mode,
				    const u32 rx_dft_ena)
{
	u32 reg_val;
	int ret;

	/* configurable terms */
	reg_val = (prbs_sel << 20) | (test_mode << 16) | (rx_dft_ena << 2);
	ret = vsc85xx_csr_write(phydev, MACRO_CTRL,
				PHY_S6G_DFT_CFG0,
				reg_val);
	if (ret)
		dev_err(&phydev->mdio.dev, "%s: write error\n", __func__);
	return ret;
}

/* Access LCPLL Cfg_0 */
static int vsc85xx_pll5g_cfg0_wr(struct phy_device *phydev,
				 const u32 selbgv820)
{
	u32 base_val;
	u32 reg_val;
	int ret;

	/* constant terms */
	base_val = 0x7036f145;
	/* configurable terms */
	reg_val = base_val | (selbgv820 << 23);
	ret = vsc85xx_csr_write(phydev, MACRO_CTRL,
				PHY_S6G_PLL5G_CFG0, reg_val);
	if (ret)
		dev_err(&phydev->mdio.dev, "%s: write error\n", __func__);
	return ret;
}

int vsc85xx_sd6g_config_v2(struct phy_device *phydev)
{
	u32 ib_sig_det_clk_sel_cal = 0;
	u32 ib_sig_det_clk_sel_mm  = 7;
	u32 pll_fsm_ctrl_data = 60;
	unsigned long deadline;
	u32 des_bw_ana_val = 3;
	u32 ib_tsdet_cal = 16;
	u32 ib_tsdet_mm  = 5;
	u32 ib_rtrm_adj;
	u32 if_mode = 1;
	u32 gp_iter = 5;
	u32 val32 = 0;
	u32 qrate = 1;
	u32 iter;
	int val = 0;
	int ret;

	phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS, MSCC_PHY_PAGE_STANDARD);

	/* Detune/Unlock LCPLL */
	ret = pll5g_detune(phydev);
	if (ret)
		return ret;

	/* 0. Reset RCPLL */
	ret = vsc85xx_sd6g_pll_cfg_wr(phydev, 3, pll_fsm_ctrl_data, 0);
	if (ret)
		return ret;
	ret = vsc85xx_sd6g_common_cfg_wr(phydev, 0, 0, 0, qrate, if_mode, 0);
	if (ret)
		return ret;
	ret = phy_commit_mcb_s6g(phydev, PHY_MCB_S6G_CFG, 0);
	if (ret)
		return ret;
	ret = vsc85xx_sd6g_des_cfg_wr(phydev, 6, 2, 5, des_bw_ana_val, 0);
	if (ret)
		return ret;

	/* 1. Configure sd6g for SGMII prior to sd6g_IB_CAL */
	ib_rtrm_adj = 13;
	ret = vsc85xx_sd6g_ib_cfg0_wr(phydev, ib_rtrm_adj, ib_sig_det_clk_sel_mm, 0, 0);
	if (ret)
		return ret;
	ret = vsc85xx_sd6g_ib_cfg1_wr(phydev, 8, ib_tsdet_mm, 15, 0, 1);
	if (ret)
		return ret;
	ret = vsc85xx_sd6g_ib_cfg2_wr(phydev, 3, 13, 5);
	if (ret)
		return ret;
	ret = vsc85xx_sd6g_ib_cfg3_wr(phydev,  0, 31, 1, 31);
	if (ret)
		return ret;
	ret = vsc85xx_sd6g_ib_cfg4_wr(phydev, 63, 63, 2, 63);
	if (ret)
		return ret;
	ret = vsc85xx_sd6g_common_cfg_wr(phydev, 1, 1, 0, qrate, if_mode, 0);
	if (ret)
		return ret;
	ret = vsc85xx_sd6g_misc_cfg_wr(phydev, 1);
	if (ret)
		return ret;
	ret = phy_commit_mcb_s6g(phydev, PHY_MCB_S6G_CFG, 0);
	if (ret)
		return ret;

	/* 2. Start rcpll_fsm */
	ret = vsc85xx_sd6g_pll_cfg_wr(phydev, 3, pll_fsm_ctrl_data, 1);
	if (ret)
		return ret;
	ret = phy_commit_mcb_s6g(phydev, PHY_MCB_S6G_CFG, 0);
	if (ret)
		return ret;

	deadline = jiffies + msecs_to_jiffies(PROC_CMD_NCOMPLETED_TIMEOUT_MS);
	do {
		usleep_range(500, 1000);
		ret = phy_update_mcb_s6g(phydev, PHY_MCB_S6G_CFG, 0);
		if (ret)
			return ret;
		val32 = vsc85xx_csr_read(phydev, MACRO_CTRL,
					 PHY_S6G_PLL_STATUS);
		/* wait for bit 12 to clear */
	} while (time_before(jiffies, deadline) && (val32 & BIT(12)));

	if (val32 & BIT(12))
		return -ETIMEDOUT;

	/* 4. Release digital reset and disable transmitter */
	ret = vsc85xx_sd6g_misc_cfg_wr(phydev, 0);
	if (ret)
		return ret;
	ret = vsc85xx_sd6g_common_cfg_wr(phydev, 1, 1, 0, qrate, if_mode, 1);
	if (ret)
		return ret;
	ret = phy_commit_mcb_s6g(phydev, PHY_MCB_S6G_CFG, 0);
	if (ret)
		return ret;

	/* 5. Apply a frequency offset on RX-side (using internal FoJi logic) */
	ret = vsc85xx_sd6g_gp_cfg_wr(phydev, 768);
	if (ret)
		return ret;
	ret = vsc85xx_sd6g_dft_cfg2_wr(phydev, 0, 2, 0, 0, 0, 1);
	if (ret)
		return ret;
	ret = vsc85xx_sd6g_dft_cfg0_wr(phydev, 0, 0, 1);
	if (ret)
		return ret;
	ret = vsc85xx_sd6g_des_cfg_wr(phydev, 6, 2, 5, des_bw_ana_val, 2);
	if (ret)
		return ret;
	ret = phy_commit_mcb_s6g(phydev, PHY_MCB_S6G_CFG, 0);
	if (ret)
		return ret;

	/* 6. Prepare required settings for IBCAL */
	ret = vsc85xx_sd6g_ib_cfg1_wr(phydev, 8, ib_tsdet_cal, 15, 1, 0);
	if (ret)
		return ret;
	ret = vsc85xx_sd6g_ib_cfg0_wr(phydev, ib_rtrm_adj, ib_sig_det_clk_sel_cal, 0, 0);
	if (ret)
		return ret;
	ret = phy_commit_mcb_s6g(phydev, PHY_MCB_S6G_CFG, 0);
	if (ret)
		return ret;

	/* 7. Start IB_CAL */
	ret = vsc85xx_sd6g_ib_cfg0_wr(phydev, ib_rtrm_adj,
				      ib_sig_det_clk_sel_cal, 0, 1);
	if (ret)
		return ret;
	ret = phy_commit_mcb_s6g(phydev, PHY_MCB_S6G_CFG, 0);
	if (ret)
		return ret;
	/* 11 cycles (for ViperA) or 5 cycles (for ViperB & Elise) w/ SW clock */
	for (iter = 0; iter < gp_iter; iter++) {
		/* set gp(0) */
		ret = vsc85xx_sd6g_gp_cfg_wr(phydev, 769);
		if (ret)
			return ret;
		ret = phy_commit_mcb_s6g(phydev, PHY_MCB_S6G_CFG, 0);
		if (ret)
			return ret;
		/* clear gp(0) */
		ret = vsc85xx_sd6g_gp_cfg_wr(phydev, 768);
		if (ret)
			return ret;
		ret = phy_commit_mcb_s6g(phydev, PHY_MCB_S6G_CFG, 0);
		if (ret)
			return ret;
	}

	ret = vsc85xx_sd6g_ib_cfg1_wr(phydev, 8, ib_tsdet_cal, 15, 1, 1);
	if (ret)
		return ret;
	ret = phy_commit_mcb_s6g(phydev, PHY_MCB_S6G_CFG, 0);
	if (ret)
		return ret;
	ret = vsc85xx_sd6g_ib_cfg1_wr(phydev, 8, ib_tsdet_cal, 15, 0, 1);
	if (ret)
		return ret;
	ret = phy_commit_mcb_s6g(phydev, PHY_MCB_S6G_CFG, 0);
	if (ret)
		return ret;

	/* 8. Wait for IB cal to complete */
	deadline = jiffies + msecs_to_jiffies(PROC_CMD_NCOMPLETED_TIMEOUT_MS);
	do {
		usleep_range(500, 1000);
		ret = phy_update_mcb_s6g(phydev, PHY_MCB_S6G_CFG, 0);
		if (ret)
			return ret;
		val32 = vsc85xx_csr_read(phydev, MACRO_CTRL,
					 PHY_S6G_IB_STATUS0);
		/* wait for bit 8 to set */
	} while (time_before(jiffies, deadline) && (~val32 & BIT(8)));

	if (~val32 & BIT(8))
		return -ETIMEDOUT;

	/* 9. Restore cfg values for mission mode */
	ret = vsc85xx_sd6g_ib_cfg0_wr(phydev, ib_rtrm_adj, ib_sig_det_clk_sel_mm, 0, 1);
	if (ret)
		return ret;
	ret = vsc85xx_sd6g_ib_cfg1_wr(phydev, 8, ib_tsdet_mm, 15, 0, 1);
	if (ret)
		return ret;
	ret = phy_commit_mcb_s6g(phydev, PHY_MCB_S6G_CFG, 0);
	if (ret)
		return ret;

	/* 10. Re-enable transmitter */
	ret = vsc85xx_sd6g_common_cfg_wr(phydev, 1, 1, 0, qrate, if_mode, 0);
	if (ret)
		return ret;
	ret = phy_commit_mcb_s6g(phydev, PHY_MCB_S6G_CFG, 0);
	if (ret)
		return ret;

	/* 11. Disable frequency offset generation (using internal FoJi logic) */
	ret = vsc85xx_sd6g_dft_cfg2_wr(phydev, 0, 0, 0, 0, 0, 0);
	if (ret)
		return ret;
	ret = vsc85xx_sd6g_dft_cfg0_wr(phydev, 0, 0, 0);
	if (ret)
		return ret;
	ret = vsc85xx_sd6g_des_cfg_wr(phydev, 6, 2, 5, des_bw_ana_val, 0);
	if (ret)
		return ret;
	ret = phy_commit_mcb_s6g(phydev, PHY_MCB_S6G_CFG, 0);
	if (ret)
		return ret;

	/* Tune/Re-lock LCPLL */
	ret = pll5g_tune(phydev);
	if (ret)
		return ret;

	/* 12. Configure for Final Configuration and Settings */
	/* a. Reset RCPLL */
	ret = vsc85xx_sd6g_pll_cfg_wr(phydev, 3, pll_fsm_ctrl_data, 0);
	if (ret)
		return ret;
	ret = vsc85xx_sd6g_common_cfg_wr(phydev, 0, 1, 0, qrate, if_mode, 0);
	if (ret)
		return ret;
	ret = phy_commit_mcb_s6g(phydev, PHY_MCB_S6G_CFG, 0);
	if (ret)
		return ret;

	/* b. Configure sd6g for desired operating mode */
	phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS, MSCC_PHY_PAGE_EXTENDED_GPIO);
	ret = phy_base_read(phydev, MSCC_PHY_MAC_CFG_FASTLINK);
	if ((ret & MAC_CFG_MASK) == MAC_CFG_QSGMII) {
		/* QSGMII */
		pll_fsm_ctrl_data = 120;
		qrate   = 0;
		if_mode = 3;
		des_bw_ana_val = 5;
		val = PROC_CMD_MCB_ACCESS_MAC_CONF | PROC_CMD_RST_CONF_PORT |
			PROC_CMD_READ_MOD_WRITE_PORT | PROC_CMD_QSGMII_MAC;

		ret = vsc8584_cmd(phydev, val);
		if (ret) {
			dev_err(&phydev->mdio.dev, "%s: QSGMII error: %d\n",
				__func__, ret);
			return ret;
		}

		phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS, MSCC_PHY_PAGE_STANDARD);
	} else if ((ret & MAC_CFG_MASK) == MAC_CFG_SGMII) {
		/* SGMII */
		pll_fsm_ctrl_data = 60;
		qrate   = 1;
		if_mode = 1;
		des_bw_ana_val = 3;

		val = PROC_CMD_MCB_ACCESS_MAC_CONF | PROC_CMD_RST_CONF_PORT |
			PROC_CMD_READ_MOD_WRITE_PORT | PROC_CMD_SGMII_MAC;

		ret = vsc8584_cmd(phydev, val);
		if (ret) {
			dev_err(&phydev->mdio.dev, "%s: SGMII error: %d\n",
				__func__, ret);
			return ret;
		}

		phy_base_write(phydev, MSCC_EXT_PAGE_ACCESS, MSCC_PHY_PAGE_STANDARD);
	} else {
		dev_err(&phydev->mdio.dev, "%s: invalid mac_if: %x\n",
			__func__, ret);
	}

	ret = phy_update_mcb_s6g(phydev, PHY_S6G_LCPLL_CFG, 0);
	if (ret)
		return ret;
	ret = phy_update_mcb_s6g(phydev, PHY_MCB_S6G_CFG, 0);
	if (ret)
		return ret;
	ret = vsc85xx_pll5g_cfg0_wr(phydev, 4);
	if (ret)
		return ret;
	ret = phy_commit_mcb_s6g(phydev, PHY_S6G_LCPLL_CFG, 0);
	if (ret)
		return ret;
	ret = vsc85xx_sd6g_des_cfg_wr(phydev, 6, 2, 5, des_bw_ana_val, 0);
	if (ret)
		return ret;
	ret = vsc85xx_sd6g_ib_cfg0_wr(phydev, ib_rtrm_adj, ib_sig_det_clk_sel_mm, 0, 1);
	if (ret)
		return ret;
	ret = vsc85xx_sd6g_ib_cfg1_wr(phydev, 8, ib_tsdet_mm, 15, 0, 1);
	if (ret)
		return ret;
	ret = vsc85xx_sd6g_common_cfg_wr(phydev, 1, 1, 0, qrate, if_mode, 0);
	if (ret)
		return ret;
	ret = vsc85xx_sd6g_ib_cfg2_wr(phydev, 3, 13, 5);
	if (ret)
		return ret;
	ret = vsc85xx_sd6g_ib_cfg3_wr(phydev,  0, 31, 1, 31);
	if (ret)
		return ret;
	ret = vsc85xx_sd6g_ib_cfg4_wr(phydev, 63, 63, 2, 63);
	if (ret)
		return ret;
	ret = vsc85xx_sd6g_misc_cfg_wr(phydev, 1);
	if (ret)
		return ret;
	ret = phy_commit_mcb_s6g(phydev, PHY_MCB_S6G_CFG, 0);
	if (ret)
		return ret;

	/* 13. Start rcpll_fsm */
	ret = vsc85xx_sd6g_pll_cfg_wr(phydev, 3, pll_fsm_ctrl_data, 1);
	if (ret)
		return ret;
	ret = phy_commit_mcb_s6g(phydev, PHY_MCB_S6G_CFG, 0);
	if (ret)
		return ret;

	/* 14. Wait for PLL cal to complete */
	deadline = jiffies + msecs_to_jiffies(PROC_CMD_NCOMPLETED_TIMEOUT_MS);
	do {
		usleep_range(500, 1000);
		ret = phy_update_mcb_s6g(phydev, PHY_MCB_S6G_CFG, 0);
		if (ret)
			return ret;
		val32 = vsc85xx_csr_read(phydev, MACRO_CTRL,
					 PHY_S6G_PLL_STATUS);
		/* wait for bit 12 to clear */
	} while (time_before(jiffies, deadline) && (val32 & BIT(12)));

	if (val32 & BIT(12))
		return -ETIMEDOUT;

	/* release lane reset */
	ret = vsc85xx_sd6g_misc_cfg_wr(phydev, 0);
	if (ret)
		return ret;

	return phy_commit_mcb_s6g(phydev, PHY_MCB_S6G_CFG, 0);
}