1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* Microchip Sparx5 Switch SerDes driver
4 * Copyright (c) 2020 Microchip Technology Inc. and its subsidiaries.
6 * The Sparx5 Chip Register Model can be browsed at this location:
7 * https://github.com/microchip-ung/sparx-5_reginfo
8 * and the datasheet is available here:
9 * https://ww1.microchip.com/downloads/en/DeviceDoc/SparX-5_Family_L2L3_Enterprise_10G_Ethernet_Switches_Datasheet_00003822B.pdf
11 #include <linux/printk.h>
12 #include <linux/module.h>
13 #include <linux/device.h>
14 #include <linux/netdevice.h>
15 #include <linux/platform_device.h>
18 #include <linux/clk.h>
19 #include <linux/phy.h>
20 #include <linux/phy/phy.h>
22 #include "sparx5_serdes.h"
24 #define SPX5_CMU_MAX 14
26 #define SPX5_SERDES_10G_START 13
27 #define SPX5_SERDES_25G_START 25
29 enum sparx5_10g28cmu_mode {
30 SPX5_SD10G28_CMU_MAIN = 0,
31 SPX5_SD10G28_CMU_AUX1 = 1,
32 SPX5_SD10G28_CMU_AUX2 = 3,
33 SPX5_SD10G28_CMU_NONE = 4,
36 enum sparx5_sd25g28_mode_preset_type {
37 SPX5_SD25G28_MODE_PRESET_25000,
38 SPX5_SD25G28_MODE_PRESET_10000,
39 SPX5_SD25G28_MODE_PRESET_5000,
40 SPX5_SD25G28_MODE_PRESET_SD_2G5,
41 SPX5_SD25G28_MODE_PRESET_1000BASEX,
44 enum sparx5_sd10g28_mode_preset_type {
45 SPX5_SD10G28_MODE_PRESET_10000,
46 SPX5_SD10G28_MODE_PRESET_SFI_5000_6G,
47 SPX5_SD10G28_MODE_PRESET_SFI_5000_10G,
48 SPX5_SD10G28_MODE_PRESET_QSGMII,
49 SPX5_SD10G28_MODE_PRESET_SD_2G5,
50 SPX5_SD10G28_MODE_PRESET_1000BASEX,
53 struct sparx5_serdes_io_resource {
54 enum sparx5_serdes_target id;
58 struct sparx5_sd25g28_mode_preset {
68 u8 com_tx_reserve_msb;
69 u8 com_tx_reserve_lsb;
70 u8 cfg_itx_ipcml_base;
85 struct sparx5_sd25g28_media_preset {
86 u8 cfg_eq_c_force_3_0;
87 u8 cfg_vga_ctrl_byp_4_0;
88 u8 cfg_eq_r_force_3_0;
98 struct sparx5_sd25g28_args {
99 u8 if_width; /* UDL if-width: 10/16/20/32/64 */
100 bool skip_cmu_cfg:1; /* Enable/disable CMU cfg */
101 enum sparx5_10g28cmu_mode cmu_sel; /* Device/Mode serdes uses */
102 bool no_pwrcycle:1; /* Omit initial power-cycle */
103 bool txinvert:1; /* Enable inversion of output data */
104 bool rxinvert:1; /* Enable inversion of input data */
105 u16 txswing; /* Set output level */
106 u8 rate; /* Rate of network interface */
108 u8 duty_cycle; /* Set output level to half/full */
109 bool mute:1; /* Mute Output Buffer */
114 struct sparx5_sd25g28_params {
117 u8 cfg_common_reserve_7_0;
119 u8 r_d_width_ctrl_from_hwt;
120 u8 r_d_width_ctrl_2_0;
121 u8 r_txfifo_ck_div_pmad_2_0;
122 u8 r_rxfifo_ck_div_pmad_2_0;
124 u8 cfg_vco_div_mode_1_0;
125 u8 cfg_pre_divsel_1_0;
127 u8 cfg_vco_start_code_3_0;
128 u8 cfg_pma_tx_ck_bitwidth_2_0;
129 u8 cfg_tx_prediv_1_0;
130 u8 cfg_rxdiv_sel_2_0;
131 u8 cfg_tx_subrate_2_0;
132 u8 cfg_rx_subrate_2_0;
133 u8 r_multi_lane_mode;
138 u8 cfg_dfetap_en_5_1;
155 u8 cfg_itx_ipdriver_base_2_0;
163 u8 l1_pcs_en_fast_iscan;
167 u8 cfg_pll_reserve_3_0;
168 u8 l0_cfg_tx_reserve_15_8;
169 u8 l0_cfg_tx_reserve_7_0;
170 u8 cfg_tx_reserve_15_8;
171 u8 cfg_tx_reserve_7_0;
174 u8 cfg_phase_man_4_0;
176 u8 cfg_txcal_shift_code_5_0;
177 u8 cfg_txcal_valid_sel_3_0;
187 u8 cfg_itx_ipcml_base_1_0;
188 u8 cfg_rx_reserve_7_0;
189 u8 cfg_rx_reserve_15_8;
192 u8 cfg_rx_sp_ctle_1_0;
193 u8 cfg_isel_ctle_1_0;
194 u8 cfg_vga_ctrl_byp_4_0;
198 u8 cfg_eqr_force_3_0;
199 u8 cfg_eqc_force_3_0;
201 u8 cfg_init_pos_iscan_6_0;
202 u8 cfg_init_pos_ipi_6_0;
214 struct sparx5_sd10g28_media_preset {
225 u8 cfg_eq_c_force_3_0;
229 struct sparx5_sd10g28_mode_preset {
230 u8 bwidth; /* interface width: 10/16/20/32/64 */
231 enum sparx5_10g28cmu_mode cmu_sel; /* Device/Mode serdes uses */
232 u8 rate; /* Rate of network interface */
236 u8 duty_cycle; /* Set output level to half/full */
239 struct sparx5_sd10g28_args {
240 bool skip_cmu_cfg:1; /* Enable/disable CMU cfg */
241 bool no_pwrcycle:1; /* Omit initial power-cycle */
242 bool txinvert:1; /* Enable inversion of output data */
243 bool rxinvert:1; /* Enable inversion of input data */
244 bool txmargin:1; /* Set output level to half/full */
245 u16 txswing; /* Set output level */
246 bool mute:1; /* Mute Output Buffer */
251 struct sparx5_sd10g28_params {
255 u8 cfg_lane_reserve_7_0;
256 u8 cfg_ssc_rtl_clk_sel;
257 u8 cfg_lane_reserve_15_8;
260 u8 r_d_width_ctrl_2_0;
261 u8 cfg_pma_tx_ck_bitwidth_2_0;
262 u8 cfg_rxdiv_sel_2_0;
263 u8 r_pcs2pma_phymode_4_0;
268 u8 cfg_dfetap_en_5_1;
283 u8 r_multi_lane_mode;
294 u8 cfg_eq_c_force_3_0;
298 u8 cfg_itx_ippreemp_base_1_0;
299 u8 cfg_itx_ipdriver_base_2_0;
300 u8 cfg_ibias_tune_reserve_5_0;
302 u8 cfg_dis_2nd_order;
304 u8 cfg_pi_floop_steps_1_0;
305 u8 cfg_pi_ext_dac_23_16;
306 u8 cfg_pi_ext_dac_15_8;
307 u8 cfg_iscan_ext_dac_7_0;
308 u8 cfg_cdr_kf_gen1_2_0;
309 u8 cfg_cdr_kf_gen2_2_0;
310 u8 cfg_cdr_kf_gen3_2_0;
311 u8 cfg_cdr_kf_gen4_2_0;
313 u8 cfg_pi_bw_gen1_3_0;
317 u8 cfg_pi_ext_dac_7_0;
322 u8 cfg_predrv_slewrate_1_0;
323 u8 cfg_itx_ipcml_base_1_0;
324 u8 cfg_ip_pre_base_1_0;
328 u8 r_en_auto_cdr_rstn;
331 u8 cfg_resetb_oscal_afe[2];
332 u8 cfg_center_spreading;
333 u8 cfg_m_cnt_maxval_4_0;
334 u8 cfg_ncnt_maxval_7_0;
335 u8 cfg_ncnt_maxval_10_8;
346 static struct sparx5_sd25g28_media_preset media_presets_25g[] = {
347 { /* ETH_MEDIA_DEFAULT */
351 .cfg_tap_adv_3_0 = 0,
353 .cfg_tap_dly_4_0 = 0,
354 .cfg_eq_c_force_3_0 = 0xf,
355 .cfg_vga_ctrl_byp_4_0 = 4,
356 .cfg_eq_r_force_3_0 = 12,
357 .cfg_alos_thr_2_0 = 7,
363 .cfg_tap_adv_3_0 = 0,
365 .cfg_tap_dly_4_0 = 0x10,
366 .cfg_eq_c_force_3_0 = 0xf,
367 .cfg_vga_ctrl_byp_4_0 = 8,
368 .cfg_eq_r_force_3_0 = 4,
369 .cfg_alos_thr_2_0 = 0,
371 { /* ETH_MEDIA_DAC */
375 .cfg_tap_adv_3_0 = 0,
377 .cfg_tap_dly_4_0 = 0,
378 .cfg_eq_c_force_3_0 = 0xf,
379 .cfg_vga_ctrl_byp_4_0 = 8,
380 .cfg_eq_r_force_3_0 = 0xc,
381 .cfg_alos_thr_2_0 = 0,
385 static struct sparx5_sd25g28_mode_preset mode_presets_25g[] = {
386 { /* SPX5_SD25G28_MODE_PRESET_25000 */
396 .com_tx_reserve_msb = (0x26 << 1),
397 .com_tx_reserve_lsb = 0xf0,
398 .cfg_itx_ipcml_base = 0,
399 .tx_reserve_msb = 0xcc,
400 .tx_reserve_lsb = 0xfe,
412 { /* SPX5_SD25G28_MODE_PRESET_10000 */
422 .com_tx_reserve_msb = (0x20 << 1),
423 .com_tx_reserve_lsb = 0x40,
424 .cfg_itx_ipcml_base = 0,
425 .tx_reserve_msb = 0x4c,
426 .tx_reserve_lsb = 0x44,
438 { /* SPX5_SD25G28_MODE_PRESET_5000 */
448 .com_tx_reserve_msb = (0x20 << 1),
449 .com_tx_reserve_lsb = 0,
450 .cfg_itx_ipcml_base = 0,
451 .tx_reserve_msb = 0xe,
452 .tx_reserve_lsb = 0x80,
461 { /* SPX5_SD25G28_MODE_PRESET_SD_2G5 */
471 .com_tx_reserve_msb = (0x26 << 1),
472 .com_tx_reserve_lsb = (0xf << 4),
473 .cfg_itx_ipcml_base = 2,
474 .tx_reserve_msb = 0x8,
475 .tx_reserve_lsb = 0x8a,
484 { /* SPX5_SD25G28_MODE_PRESET_1000BASEX */
494 .com_tx_reserve_msb = (0x26 << 1),
495 .com_tx_reserve_lsb = 0xf0,
496 .cfg_itx_ipcml_base = 0,
497 .tx_reserve_msb = 0x8,
498 .tx_reserve_lsb = 0xce,
509 static struct sparx5_sd10g28_media_preset media_presets_10g[] = {
510 { /* ETH_MEDIA_DEFAULT */
514 .cfg_tap_adv_3_0 = 0,
516 .cfg_tap_dly_4_0 = 0,
517 .cfg_vga_ctrl_3_0 = 5,
519 .cfg_eq_res_3_0 = 0xa,
521 .cfg_eq_c_force_3_0 = 0x8,
522 .cfg_alos_thr_3_0 = 0x3,
528 .cfg_tap_adv_3_0 = 0,
530 .cfg_tap_dly_4_0 = 0xc,
531 .cfg_vga_ctrl_3_0 = 0xa,
532 .cfg_vga_cp_2_0 = 0x4,
533 .cfg_eq_res_3_0 = 0xa,
535 .cfg_eq_c_force_3_0 = 0xF,
536 .cfg_alos_thr_3_0 = 0x3,
538 { /* ETH_MEDIA_DAC */
542 .cfg_tap_adv_3_0 = 12,
544 .cfg_tap_dly_4_0 = 8,
545 .cfg_vga_ctrl_3_0 = 0xa,
547 .cfg_eq_res_3_0 = 0xa,
549 .cfg_eq_c_force_3_0 = 0xf,
550 .cfg_alos_thr_3_0 = 0x0,
554 static struct sparx5_sd10g28_mode_preset mode_presets_10g[] = {
555 { /* SPX5_SD10G28_MODE_PRESET_10000 */
557 .cmu_sel = SPX5_SD10G28_CMU_MAIN,
564 { /* SPX5_SD10G28_MODE_PRESET_SFI_5000_6G */
566 .cmu_sel = SPX5_SD10G28_CMU_MAIN,
573 { /* SPX5_SD10G28_MODE_PRESET_SFI_5000_10G */
575 .cmu_sel = SPX5_SD10G28_CMU_MAIN,
582 { /* SPX5_SD10G28_MODE_PRESET_QSGMII */
584 .cmu_sel = SPX5_SD10G28_CMU_AUX1,
591 { /* SPX5_SD10G28_MODE_PRESET_SD_2G5 */
593 .cmu_sel = SPX5_SD10G28_CMU_AUX2,
600 { /* SPX5_SD10G28_MODE_PRESET_1000BASEX */
602 .cmu_sel = SPX5_SD10G28_CMU_AUX1,
611 /* map from SD25G28 interface width to configuration value */
612 static u8 sd25g28_get_iw_setting(struct device *dev, const u8 interface_width)
614 switch (interface_width) {
621 dev_err(dev, "%s: Illegal value %d for interface width\n",
622 __func__, interface_width);
627 /* map from SD10G28 interface width to configuration value */
628 static u8 sd10g28_get_iw_setting(struct device *dev, const u8 interface_width)
630 switch (interface_width) {
638 dev_err(dev, "%s: Illegal value %d for interface width\n", __func__,
644 static int sparx5_sd10g25_get_mode_preset(struct sparx5_serdes_macro *macro,
645 struct sparx5_sd25g28_mode_preset *mode)
647 switch (macro->serdesmode) {
648 case SPX5_SD_MODE_SFI:
649 if (macro->speed == SPEED_25000)
650 *mode = mode_presets_25g[SPX5_SD25G28_MODE_PRESET_25000];
651 else if (macro->speed == SPEED_10000)
652 *mode = mode_presets_25g[SPX5_SD25G28_MODE_PRESET_10000];
653 else if (macro->speed == SPEED_5000)
654 *mode = mode_presets_25g[SPX5_SD25G28_MODE_PRESET_5000];
656 case SPX5_SD_MODE_2G5:
657 *mode = mode_presets_25g[SPX5_SD25G28_MODE_PRESET_SD_2G5];
659 case SPX5_SD_MODE_1000BASEX:
660 *mode = mode_presets_25g[SPX5_SD25G28_MODE_PRESET_1000BASEX];
662 case SPX5_SD_MODE_100FX:
666 *mode = mode_presets_25g[SPX5_SD25G28_MODE_PRESET_25000];
672 static int sparx5_sd10g28_get_mode_preset(struct sparx5_serdes_macro *macro,
673 struct sparx5_sd10g28_mode_preset *mode,
674 struct sparx5_sd10g28_args *args)
676 switch (macro->serdesmode) {
677 case SPX5_SD_MODE_SFI:
678 if (macro->speed == SPEED_10000) {
679 *mode = mode_presets_10g[SPX5_SD10G28_MODE_PRESET_10000];
680 } else if (macro->speed == SPEED_5000) {
682 *mode = mode_presets_10g[SPX5_SD10G28_MODE_PRESET_SFI_5000_6G];
684 *mode = mode_presets_10g[SPX5_SD10G28_MODE_PRESET_SFI_5000_10G];
686 dev_err(macro->priv->dev, "%s: Illegal speed: %02u, sidx: %02u, mode (%u)",
687 __func__, macro->speed, macro->sidx,
692 case SPX5_SD_MODE_QSGMII:
693 *mode = mode_presets_10g[SPX5_SD10G28_MODE_PRESET_QSGMII];
695 case SPX5_SD_MODE_2G5:
696 *mode = mode_presets_10g[SPX5_SD10G28_MODE_PRESET_SD_2G5];
698 case SPX5_SD_MODE_100FX:
699 case SPX5_SD_MODE_1000BASEX:
700 *mode = mode_presets_10g[SPX5_SD10G28_MODE_PRESET_1000BASEX];
703 *mode = mode_presets_10g[SPX5_SD10G28_MODE_PRESET_10000];
709 static void sparx5_sd25g28_get_params(struct sparx5_serdes_macro *macro,
710 struct sparx5_sd25g28_media_preset *media,
711 struct sparx5_sd25g28_mode_preset *mode,
712 struct sparx5_sd25g28_args *args,
713 struct sparx5_sd25g28_params *params)
715 u8 iw = sd25g28_get_iw_setting(macro->priv->dev, mode->bitwidth);
716 struct sparx5_sd25g28_params init = {
717 .r_d_width_ctrl_2_0 = iw,
718 .r_txfifo_ck_div_pmad_2_0 = mode->fifo_ck_div,
719 .r_rxfifo_ck_div_pmad_2_0 = mode->fifo_ck_div,
720 .cfg_vco_div_mode_1_0 = mode->vco_div_mode,
721 .cfg_pre_divsel_1_0 = mode->pre_divsel,
722 .cfg_sel_div_3_0 = mode->sel_div,
723 .cfg_vco_start_code_3_0 = 0,
724 .cfg_pma_tx_ck_bitwidth_2_0 = mode->ck_bitwidth,
725 .cfg_tx_prediv_1_0 = mode->tx_pre_div,
726 .cfg_rxdiv_sel_2_0 = mode->ck_bitwidth,
727 .cfg_tx_subrate_2_0 = mode->subrate,
728 .cfg_rx_subrate_2_0 = mode->subrate,
729 .r_multi_lane_mode = 0,
731 .cfg_dfeck_en = mode->dfe_enable,
732 .cfg_dfe_pd = mode->dfe_enable == 1 ? 0 : 1,
734 .cfg_dfetap_en_5_1 = mode->dfe_tap,
736 .cfg_dmux_clk_pd = 1,
737 .cfg_erramp_pd = mode->dfe_enable == 1 ? 0 : 1,
738 .cfg_pi_DFE_en = mode->dfe_enable,
751 .cfg_itx_ipdriver_base_2_0 = mode->txmargin,
752 .cfg_tap_dly_4_0 = media->cfg_tap_dly_4_0,
753 .cfg_tap_main = media->cfg_tap_main,
754 .cfg_en_main = media->cfg_en_main,
755 .cfg_tap_adv_3_0 = media->cfg_tap_adv_3_0,
756 .cfg_en_adv = media->cfg_en_adv,
757 .cfg_en_dly = media->cfg_en_dly,
759 .l1_pcs_en_fast_iscan = 0,
762 .cfg_pll_reserve_3_0 = args->com_pll_reserve,
763 .l0_cfg_txcal_en = mode->com_txcal_en,
764 .l0_cfg_tx_reserve_15_8 = mode->com_tx_reserve_msb,
765 .l0_cfg_tx_reserve_7_0 = mode->com_tx_reserve_lsb,
766 .cfg_tx_reserve_15_8 = mode->tx_reserve_msb,
767 .cfg_tx_reserve_7_0 = mode->tx_reserve_lsb,
768 .cfg_bw_1_0 = mode->bw,
769 .cfg_txcal_man_en = 1,
770 .cfg_phase_man_4_0 = 0,
771 .cfg_quad_man_1_0 = 0,
772 .cfg_txcal_shift_code_5_0 = 2,
773 .cfg_txcal_valid_sel_3_0 = 4,
777 .cfg_pi_bw_3_0 = mode->cfg_pi_bw_3_0,
778 .cfg_pi_steps_1_0 = 0,
779 .cfg_dis_2ndorder = 1,
780 .cfg_ctle_rstn = mode->cfg_ctle_rstn,
781 .r_dfe_rstn = mode->r_dfe_rstn,
782 .cfg_alos_thr_2_0 = media->cfg_alos_thr_2_0,
783 .cfg_itx_ipcml_base_1_0 = mode->cfg_itx_ipcml_base,
784 .cfg_rx_reserve_7_0 = 0xbf,
785 .cfg_rx_reserve_15_8 = 0x61,
786 .cfg_rxterm_2_0 = mode->rxterm,
788 .cfg_rx_sp_ctle_1_0 = 0,
789 .cfg_isel_ctle_1_0 = 0,
790 .cfg_vga_ctrl_byp_4_0 = media->cfg_vga_ctrl_byp_4_0,
792 .cfg_agc_adpt_byp = 1,
794 .cfg_eqr_force_3_0 = media->cfg_eq_r_force_3_0,
795 .cfg_eqc_force_3_0 = media->cfg_eq_c_force_3_0,
796 .cfg_sum_setcm_en = 1,
798 .cfg_init_pos_iscan_6_0 = 6,
799 .cfg_init_pos_ipi_6_0 = 9,
800 .cfg_dfedig_m_2_0 = 6,
801 .cfg_en_dfedig = mode->dfe_enable,
802 .r_d_width_ctrl_from_hwt = 0,
804 .reg_rst = args->reg_rst,
806 .cfg_common_reserve_7_0 = 1,
807 .cfg_pll_lol_set = 1,
808 .cfg_tx2rx_lp_en = 0,
810 .cfg_rx2tx_lp_en = 0,
812 .r_tx_pol_inv = args->txinvert,
813 .r_rx_pol_inv = args->rxinvert,
819 static void sparx5_sd10g28_get_params(struct sparx5_serdes_macro *macro,
820 struct sparx5_sd10g28_media_preset *media,
821 struct sparx5_sd10g28_mode_preset *mode,
822 struct sparx5_sd10g28_args *args,
823 struct sparx5_sd10g28_params *params)
825 u8 iw = sd10g28_get_iw_setting(macro->priv->dev, mode->bwidth);
826 struct sparx5_sd10g28_params init = {
827 .skip_cmu_cfg = args->skip_cmu_cfg,
828 .is_6g = args->is_6g,
829 .cmu_sel = mode->cmu_sel,
830 .cfg_lane_reserve_7_0 = (mode->cmu_sel % 2) << 6,
831 .cfg_ssc_rtl_clk_sel = (mode->cmu_sel / 2),
832 .cfg_lane_reserve_15_8 = mode->duty_cycle,
833 .cfg_txrate_1_0 = mode->rate,
834 .cfg_rxrate_1_0 = mode->rate,
835 .fx_100 = macro->serdesmode == SPX5_SD_MODE_100FX,
836 .r_d_width_ctrl_2_0 = iw,
837 .cfg_pma_tx_ck_bitwidth_2_0 = iw,
838 .cfg_rxdiv_sel_2_0 = iw,
839 .r_pcs2pma_phymode_4_0 = 0,
840 .cfg_lane_id_2_0 = 0,
842 .cfg_dfeck_en = mode->dfe_enable,
843 .cfg_dfe_pd = (mode->dfe_enable == 1) ? 0 : 1,
844 .cfg_dfetap_en_5_1 = mode->dfe_tap,
845 .cfg_erramp_pd = (mode->dfe_enable == 1) ? 0 : 1,
846 .cfg_pi_DFE_en = mode->dfe_enable,
850 .cfg_pd_rx_cktree = 0,
856 .cfg_pd_sq = mode->dfe_enable,
859 .r_multi_lane_mode = 0,
860 .cfg_en_adv = media->cfg_en_adv,
862 .cfg_en_dly = media->cfg_en_dly,
863 .cfg_tap_adv_3_0 = media->cfg_tap_adv_3_0,
864 .cfg_tap_main = media->cfg_tap_main,
865 .cfg_tap_dly_4_0 = media->cfg_tap_dly_4_0,
866 .cfg_vga_ctrl_3_0 = media->cfg_vga_ctrl_3_0,
867 .cfg_vga_cp_2_0 = media->cfg_vga_cp_2_0,
868 .cfg_eq_res_3_0 = media->cfg_eq_res_3_0,
869 .cfg_eq_r_byp = media->cfg_eq_r_byp,
870 .cfg_eq_c_force_3_0 = media->cfg_eq_c_force_3_0,
871 .cfg_en_dfedig = mode->dfe_enable,
872 .cfg_sum_setcm_en = 1,
874 .cfg_itx_ippreemp_base_1_0 = 0,
875 .cfg_itx_ipdriver_base_2_0 = (args->txswing >> 6),
876 .cfg_ibias_tune_reserve_5_0 = (args->txswing & 63),
877 .cfg_txswing_half = (args->txmargin),
878 .cfg_dis_2nd_order = 0x1,
879 .cfg_rx_ssc_lh = 0x0,
880 .cfg_pi_floop_steps_1_0 = 0x0,
881 .cfg_pi_ext_dac_23_16 = (1 << 5),
882 .cfg_pi_ext_dac_15_8 = (0 << 6),
883 .cfg_iscan_ext_dac_7_0 = (1 << 7) + 9,
884 .cfg_cdr_kf_gen1_2_0 = 1,
885 .cfg_cdr_kf_gen2_2_0 = 1,
886 .cfg_cdr_kf_gen3_2_0 = 1,
887 .cfg_cdr_kf_gen4_2_0 = 1,
888 .r_cdr_m_gen1_7_0 = 4,
889 .cfg_pi_bw_gen1_3_0 = mode->pi_bw_gen1,
890 .cfg_pi_bw_gen2 = mode->pi_bw_gen1,
891 .cfg_pi_bw_gen3 = mode->pi_bw_gen1,
892 .cfg_pi_bw_gen4 = mode->pi_bw_gen1,
893 .cfg_pi_ext_dac_7_0 = 3,
896 .cfg_rstn_dfedig = mode->dfe_enable,
897 .cfg_alos_thr_3_0 = media->cfg_alos_thr_3_0,
898 .cfg_predrv_slewrate_1_0 = 3,
899 .cfg_itx_ipcml_base_1_0 = 0,
900 .cfg_ip_pre_base_1_0 = 0,
901 .r_cdr_m_gen2_7_0 = 2,
902 .r_cdr_m_gen3_7_0 = 2,
903 .r_cdr_m_gen4_7_0 = 2,
904 .r_en_auto_cdr_rstn = 0,
906 .cfg_pd_osdac_afe = 0,
907 .cfg_resetb_oscal_afe[0] = 0,
908 .cfg_resetb_oscal_afe[1] = 1,
909 .cfg_center_spreading = 0,
910 .cfg_m_cnt_maxval_4_0 = 15,
911 .cfg_ncnt_maxval_7_0 = 32,
912 .cfg_ncnt_maxval_10_8 = 6,
914 .cfg_tx2rx_lp_en = 0,
916 .cfg_rx2tx_lp_en = 0,
918 .r_tx_pol_inv = args->txinvert,
919 .r_rx_pol_inv = args->rxinvert,
925 static void sparx5_sd25g28_reset(void __iomem *regs[],
926 struct sparx5_sd25g28_params *params,
929 if (params->reg_rst == 1) {
930 sdx5_rmw_addr(SD_LANE_25G_SD_LANE_CFG_EXT_CFG_RST_SET(1),
931 SD_LANE_25G_SD_LANE_CFG_EXT_CFG_RST,
932 sdx5_addr(regs, SD_LANE_25G_SD_LANE_CFG(sd_index)));
934 usleep_range(1000, 2000);
936 sdx5_rmw_addr(SD_LANE_25G_SD_LANE_CFG_EXT_CFG_RST_SET(0),
937 SD_LANE_25G_SD_LANE_CFG_EXT_CFG_RST,
938 sdx5_addr(regs, SD_LANE_25G_SD_LANE_CFG(sd_index)));
942 static int sparx5_sd25g28_apply_params(struct sparx5_serdes_macro *macro,
943 struct sparx5_sd25g28_params *params)
945 struct sparx5_serdes_private *priv = macro->priv;
946 void __iomem **regs = priv->regs;
947 struct device *dev = priv->dev;
948 u32 sd_index = macro->stpidx;
951 sdx5_rmw(SD_LANE_25G_SD_LANE_CFG_MACRO_RST_SET(1),
952 SD_LANE_25G_SD_LANE_CFG_MACRO_RST,
954 SD_LANE_25G_SD_LANE_CFG(sd_index));
956 sdx5_rmw(SD25G_LANE_CMU_FF_REGISTER_TABLE_INDEX_SET(0xFF),
957 SD25G_LANE_CMU_FF_REGISTER_TABLE_INDEX,
959 SD25G_LANE_CMU_FF(sd_index));
961 sdx5_rmw(SD25G_LANE_CMU_1A_R_DWIDTHCTRL_FROM_HWT_SET
962 (params->r_d_width_ctrl_from_hwt) |
963 SD25G_LANE_CMU_1A_R_REG_MANUAL_SET(params->r_reg_manual),
964 SD25G_LANE_CMU_1A_R_DWIDTHCTRL_FROM_HWT |
965 SD25G_LANE_CMU_1A_R_REG_MANUAL,
967 SD25G_LANE_CMU_1A(sd_index));
969 sdx5_rmw(SD25G_LANE_CMU_31_CFG_COMMON_RESERVE_7_0_SET
970 (params->cfg_common_reserve_7_0),
971 SD25G_LANE_CMU_31_CFG_COMMON_RESERVE_7_0,
973 SD25G_LANE_CMU_31(sd_index));
975 sdx5_rmw(SD25G_LANE_CMU_09_CFG_EN_DUMMY_SET(params->cfg_en_dummy),
976 SD25G_LANE_CMU_09_CFG_EN_DUMMY,
978 SD25G_LANE_CMU_09(sd_index));
980 sdx5_rmw(SD25G_LANE_CMU_13_CFG_PLL_RESERVE_3_0_SET
981 (params->cfg_pll_reserve_3_0),
982 SD25G_LANE_CMU_13_CFG_PLL_RESERVE_3_0,
984 SD25G_LANE_CMU_13(sd_index));
986 sdx5_rmw(SD25G_LANE_CMU_40_L0_CFG_TXCAL_EN_SET(params->l0_cfg_txcal_en),
987 SD25G_LANE_CMU_40_L0_CFG_TXCAL_EN,
989 SD25G_LANE_CMU_40(sd_index));
991 sdx5_rmw(SD25G_LANE_CMU_46_L0_CFG_TX_RESERVE_15_8_SET
992 (params->l0_cfg_tx_reserve_15_8),
993 SD25G_LANE_CMU_46_L0_CFG_TX_RESERVE_15_8,
995 SD25G_LANE_CMU_46(sd_index));
997 sdx5_rmw(SD25G_LANE_CMU_45_L0_CFG_TX_RESERVE_7_0_SET
998 (params->l0_cfg_tx_reserve_7_0),
999 SD25G_LANE_CMU_45_L0_CFG_TX_RESERVE_7_0,
1001 SD25G_LANE_CMU_45(sd_index));
1003 sdx5_rmw(SD25G_LANE_CMU_0B_CFG_VCO_CAL_RESETN_SET(0),
1004 SD25G_LANE_CMU_0B_CFG_VCO_CAL_RESETN,
1006 SD25G_LANE_CMU_0B(sd_index));
1008 sdx5_rmw(SD25G_LANE_CMU_0B_CFG_VCO_CAL_RESETN_SET(1),
1009 SD25G_LANE_CMU_0B_CFG_VCO_CAL_RESETN,
1011 SD25G_LANE_CMU_0B(sd_index));
1013 sdx5_rmw(SD25G_LANE_CMU_19_R_CK_RESETB_SET(0),
1014 SD25G_LANE_CMU_19_R_CK_RESETB,
1016 SD25G_LANE_CMU_19(sd_index));
1018 sdx5_rmw(SD25G_LANE_CMU_19_R_CK_RESETB_SET(1),
1019 SD25G_LANE_CMU_19_R_CK_RESETB,
1021 SD25G_LANE_CMU_19(sd_index));
1023 sdx5_rmw(SD25G_LANE_CMU_18_R_PLL_RSTN_SET(0),
1024 SD25G_LANE_CMU_18_R_PLL_RSTN,
1026 SD25G_LANE_CMU_18(sd_index));
1028 sdx5_rmw(SD25G_LANE_CMU_18_R_PLL_RSTN_SET(1),
1029 SD25G_LANE_CMU_18_R_PLL_RSTN,
1031 SD25G_LANE_CMU_18(sd_index));
1033 sdx5_rmw(SD25G_LANE_CMU_1A_R_DWIDTHCTRL_2_0_SET(params->r_d_width_ctrl_2_0),
1034 SD25G_LANE_CMU_1A_R_DWIDTHCTRL_2_0,
1036 SD25G_LANE_CMU_1A(sd_index));
1038 sdx5_rmw(SD25G_LANE_CMU_30_R_TXFIFO_CK_DIV_PMAD_2_0_SET
1039 (params->r_txfifo_ck_div_pmad_2_0) |
1040 SD25G_LANE_CMU_30_R_RXFIFO_CK_DIV_PMAD_2_0_SET
1041 (params->r_rxfifo_ck_div_pmad_2_0),
1042 SD25G_LANE_CMU_30_R_TXFIFO_CK_DIV_PMAD_2_0 |
1043 SD25G_LANE_CMU_30_R_RXFIFO_CK_DIV_PMAD_2_0,
1045 SD25G_LANE_CMU_30(sd_index));
1047 sdx5_rmw(SD25G_LANE_CMU_0C_CFG_PLL_LOL_SET_SET(params->cfg_pll_lol_set) |
1048 SD25G_LANE_CMU_0C_CFG_VCO_DIV_MODE_1_0_SET
1049 (params->cfg_vco_div_mode_1_0),
1050 SD25G_LANE_CMU_0C_CFG_PLL_LOL_SET |
1051 SD25G_LANE_CMU_0C_CFG_VCO_DIV_MODE_1_0,
1053 SD25G_LANE_CMU_0C(sd_index));
1055 sdx5_rmw(SD25G_LANE_CMU_0D_CFG_PRE_DIVSEL_1_0_SET
1056 (params->cfg_pre_divsel_1_0),
1057 SD25G_LANE_CMU_0D_CFG_PRE_DIVSEL_1_0,
1059 SD25G_LANE_CMU_0D(sd_index));
1061 sdx5_rmw(SD25G_LANE_CMU_0E_CFG_SEL_DIV_3_0_SET(params->cfg_sel_div_3_0),
1062 SD25G_LANE_CMU_0E_CFG_SEL_DIV_3_0,
1064 SD25G_LANE_CMU_0E(sd_index));
1066 sdx5_rmw(SD25G_LANE_CMU_FF_REGISTER_TABLE_INDEX_SET(0x00),
1067 SD25G_LANE_CMU_FF_REGISTER_TABLE_INDEX,
1069 SD25G_LANE_CMU_FF(sd_index));
1071 sdx5_rmw(SD25G_LANE_LANE_0C_LN_CFG_PMA_TX_CK_BITWIDTH_2_0_SET
1072 (params->cfg_pma_tx_ck_bitwidth_2_0),
1073 SD25G_LANE_LANE_0C_LN_CFG_PMA_TX_CK_BITWIDTH_2_0,
1075 SD25G_LANE_LANE_0C(sd_index));
1077 sdx5_rmw(SD25G_LANE_LANE_01_LN_CFG_TX_PREDIV_1_0_SET
1078 (params->cfg_tx_prediv_1_0),
1079 SD25G_LANE_LANE_01_LN_CFG_TX_PREDIV_1_0,
1081 SD25G_LANE_LANE_01(sd_index));
1083 sdx5_rmw(SD25G_LANE_LANE_18_LN_CFG_RXDIV_SEL_2_0_SET
1084 (params->cfg_rxdiv_sel_2_0),
1085 SD25G_LANE_LANE_18_LN_CFG_RXDIV_SEL_2_0,
1087 SD25G_LANE_LANE_18(sd_index));
1089 sdx5_rmw(SD25G_LANE_LANE_2C_LN_CFG_TX_SUBRATE_2_0_SET
1090 (params->cfg_tx_subrate_2_0),
1091 SD25G_LANE_LANE_2C_LN_CFG_TX_SUBRATE_2_0,
1093 SD25G_LANE_LANE_2C(sd_index));
1095 sdx5_rmw(SD25G_LANE_LANE_28_LN_CFG_RX_SUBRATE_2_0_SET
1096 (params->cfg_rx_subrate_2_0),
1097 SD25G_LANE_LANE_28_LN_CFG_RX_SUBRATE_2_0,
1099 SD25G_LANE_LANE_28(sd_index));
1101 sdx5_rmw(SD25G_LANE_LANE_18_LN_CFG_CDRCK_EN_SET(params->cfg_cdrck_en),
1102 SD25G_LANE_LANE_18_LN_CFG_CDRCK_EN,
1104 SD25G_LANE_LANE_18(sd_index));
1106 sdx5_rmw(SD25G_LANE_LANE_0F_LN_CFG_DFETAP_EN_5_1_SET
1107 (params->cfg_dfetap_en_5_1),
1108 SD25G_LANE_LANE_0F_LN_CFG_DFETAP_EN_5_1,
1110 SD25G_LANE_LANE_0F(sd_index));
1112 sdx5_rmw(SD25G_LANE_LANE_18_LN_CFG_ERRAMP_PD_SET(params->cfg_erramp_pd),
1113 SD25G_LANE_LANE_18_LN_CFG_ERRAMP_PD,
1115 SD25G_LANE_LANE_18(sd_index));
1117 sdx5_rmw(SD25G_LANE_LANE_1D_LN_CFG_PI_DFE_EN_SET(params->cfg_pi_dfe_en),
1118 SD25G_LANE_LANE_1D_LN_CFG_PI_DFE_EN,
1120 SD25G_LANE_LANE_1D(sd_index));
1122 sdx5_rmw(SD25G_LANE_LANE_19_LN_CFG_ECDR_PD_SET(params->cfg_ecdr_pd),
1123 SD25G_LANE_LANE_19_LN_CFG_ECDR_PD,
1125 SD25G_LANE_LANE_19(sd_index));
1127 sdx5_rmw(SD25G_LANE_LANE_01_LN_CFG_ITX_IPDRIVER_BASE_2_0_SET
1128 (params->cfg_itx_ipdriver_base_2_0),
1129 SD25G_LANE_LANE_01_LN_CFG_ITX_IPDRIVER_BASE_2_0,
1131 SD25G_LANE_LANE_01(sd_index));
1133 sdx5_rmw(SD25G_LANE_LANE_03_LN_CFG_TAP_DLY_4_0_SET(params->cfg_tap_dly_4_0),
1134 SD25G_LANE_LANE_03_LN_CFG_TAP_DLY_4_0,
1136 SD25G_LANE_LANE_03(sd_index));
1138 sdx5_rmw(SD25G_LANE_LANE_06_LN_CFG_TAP_ADV_3_0_SET(params->cfg_tap_adv_3_0),
1139 SD25G_LANE_LANE_06_LN_CFG_TAP_ADV_3_0,
1141 SD25G_LANE_LANE_06(sd_index));
1143 sdx5_rmw(SD25G_LANE_LANE_07_LN_CFG_EN_ADV_SET(params->cfg_en_adv) |
1144 SD25G_LANE_LANE_07_LN_CFG_EN_DLY_SET(params->cfg_en_dly),
1145 SD25G_LANE_LANE_07_LN_CFG_EN_ADV |
1146 SD25G_LANE_LANE_07_LN_CFG_EN_DLY,
1148 SD25G_LANE_LANE_07(sd_index));
1150 sdx5_rmw(SD25G_LANE_LANE_43_LN_CFG_TX_RESERVE_15_8_SET
1151 (params->cfg_tx_reserve_15_8),
1152 SD25G_LANE_LANE_43_LN_CFG_TX_RESERVE_15_8,
1154 SD25G_LANE_LANE_43(sd_index));
1156 sdx5_rmw(SD25G_LANE_LANE_42_LN_CFG_TX_RESERVE_7_0_SET
1157 (params->cfg_tx_reserve_7_0),
1158 SD25G_LANE_LANE_42_LN_CFG_TX_RESERVE_7_0,
1160 SD25G_LANE_LANE_42(sd_index));
1162 sdx5_rmw(SD25G_LANE_LANE_05_LN_CFG_BW_1_0_SET(params->cfg_bw_1_0),
1163 SD25G_LANE_LANE_05_LN_CFG_BW_1_0,
1165 SD25G_LANE_LANE_05(sd_index));
1167 sdx5_rmw(SD25G_LANE_LANE_0B_LN_CFG_TXCAL_MAN_EN_SET
1168 (params->cfg_txcal_man_en),
1169 SD25G_LANE_LANE_0B_LN_CFG_TXCAL_MAN_EN,
1171 SD25G_LANE_LANE_0B(sd_index));
1173 sdx5_rmw(SD25G_LANE_LANE_0A_LN_CFG_TXCAL_SHIFT_CODE_5_0_SET
1174 (params->cfg_txcal_shift_code_5_0),
1175 SD25G_LANE_LANE_0A_LN_CFG_TXCAL_SHIFT_CODE_5_0,
1177 SD25G_LANE_LANE_0A(sd_index));
1179 sdx5_rmw(SD25G_LANE_LANE_09_LN_CFG_TXCAL_VALID_SEL_3_0_SET
1180 (params->cfg_txcal_valid_sel_3_0),
1181 SD25G_LANE_LANE_09_LN_CFG_TXCAL_VALID_SEL_3_0,
1183 SD25G_LANE_LANE_09(sd_index));
1185 sdx5_rmw(SD25G_LANE_LANE_1A_LN_CFG_CDR_KF_2_0_SET(params->cfg_cdr_kf_2_0),
1186 SD25G_LANE_LANE_1A_LN_CFG_CDR_KF_2_0,
1188 SD25G_LANE_LANE_1A(sd_index));
1190 sdx5_rmw(SD25G_LANE_LANE_1B_LN_CFG_CDR_M_7_0_SET(params->cfg_cdr_m_7_0),
1191 SD25G_LANE_LANE_1B_LN_CFG_CDR_M_7_0,
1193 SD25G_LANE_LANE_1B(sd_index));
1195 sdx5_rmw(SD25G_LANE_LANE_2B_LN_CFG_PI_BW_3_0_SET(params->cfg_pi_bw_3_0),
1196 SD25G_LANE_LANE_2B_LN_CFG_PI_BW_3_0,
1198 SD25G_LANE_LANE_2B(sd_index));
1200 sdx5_rmw(SD25G_LANE_LANE_2C_LN_CFG_DIS_2NDORDER_SET
1201 (params->cfg_dis_2ndorder),
1202 SD25G_LANE_LANE_2C_LN_CFG_DIS_2NDORDER,
1204 SD25G_LANE_LANE_2C(sd_index));
1206 sdx5_rmw(SD25G_LANE_LANE_2E_LN_CFG_CTLE_RSTN_SET(params->cfg_ctle_rstn),
1207 SD25G_LANE_LANE_2E_LN_CFG_CTLE_RSTN,
1209 SD25G_LANE_LANE_2E(sd_index));
1211 sdx5_rmw(SD25G_LANE_LANE_00_LN_CFG_ITX_IPCML_BASE_1_0_SET
1212 (params->cfg_itx_ipcml_base_1_0),
1213 SD25G_LANE_LANE_00_LN_CFG_ITX_IPCML_BASE_1_0,
1215 SD25G_LANE_LANE_00(sd_index));
1217 sdx5_rmw(SD25G_LANE_LANE_44_LN_CFG_RX_RESERVE_7_0_SET
1218 (params->cfg_rx_reserve_7_0),
1219 SD25G_LANE_LANE_44_LN_CFG_RX_RESERVE_7_0,
1221 SD25G_LANE_LANE_44(sd_index));
1223 sdx5_rmw(SD25G_LANE_LANE_45_LN_CFG_RX_RESERVE_15_8_SET
1224 (params->cfg_rx_reserve_15_8),
1225 SD25G_LANE_LANE_45_LN_CFG_RX_RESERVE_15_8,
1227 SD25G_LANE_LANE_45(sd_index));
1229 sdx5_rmw(SD25G_LANE_LANE_0D_LN_CFG_DFECK_EN_SET(params->cfg_dfeck_en) |
1230 SD25G_LANE_LANE_0D_LN_CFG_RXTERM_2_0_SET(params->cfg_rxterm_2_0),
1231 SD25G_LANE_LANE_0D_LN_CFG_DFECK_EN |
1232 SD25G_LANE_LANE_0D_LN_CFG_RXTERM_2_0,
1234 SD25G_LANE_LANE_0D(sd_index));
1236 sdx5_rmw(SD25G_LANE_LANE_21_LN_CFG_VGA_CTRL_BYP_4_0_SET
1237 (params->cfg_vga_ctrl_byp_4_0),
1238 SD25G_LANE_LANE_21_LN_CFG_VGA_CTRL_BYP_4_0,
1240 SD25G_LANE_LANE_21(sd_index));
1242 sdx5_rmw(SD25G_LANE_LANE_22_LN_CFG_EQR_FORCE_3_0_SET
1243 (params->cfg_eqr_force_3_0),
1244 SD25G_LANE_LANE_22_LN_CFG_EQR_FORCE_3_0,
1246 SD25G_LANE_LANE_22(sd_index));
1248 sdx5_rmw(SD25G_LANE_LANE_1C_LN_CFG_EQC_FORCE_3_0_SET
1249 (params->cfg_eqc_force_3_0) |
1250 SD25G_LANE_LANE_1C_LN_CFG_DFE_PD_SET(params->cfg_dfe_pd),
1251 SD25G_LANE_LANE_1C_LN_CFG_EQC_FORCE_3_0 |
1252 SD25G_LANE_LANE_1C_LN_CFG_DFE_PD,
1254 SD25G_LANE_LANE_1C(sd_index));
1256 sdx5_rmw(SD25G_LANE_LANE_1E_LN_CFG_SUM_SETCM_EN_SET
1257 (params->cfg_sum_setcm_en),
1258 SD25G_LANE_LANE_1E_LN_CFG_SUM_SETCM_EN,
1260 SD25G_LANE_LANE_1E(sd_index));
1262 sdx5_rmw(SD25G_LANE_LANE_25_LN_CFG_INIT_POS_ISCAN_6_0_SET
1263 (params->cfg_init_pos_iscan_6_0),
1264 SD25G_LANE_LANE_25_LN_CFG_INIT_POS_ISCAN_6_0,
1266 SD25G_LANE_LANE_25(sd_index));
1268 sdx5_rmw(SD25G_LANE_LANE_26_LN_CFG_INIT_POS_IPI_6_0_SET
1269 (params->cfg_init_pos_ipi_6_0),
1270 SD25G_LANE_LANE_26_LN_CFG_INIT_POS_IPI_6_0,
1272 SD25G_LANE_LANE_26(sd_index));
1274 sdx5_rmw(SD25G_LANE_LANE_18_LN_CFG_ERRAMP_PD_SET(params->cfg_erramp_pd),
1275 SD25G_LANE_LANE_18_LN_CFG_ERRAMP_PD,
1277 SD25G_LANE_LANE_18(sd_index));
1279 sdx5_rmw(SD25G_LANE_LANE_0E_LN_CFG_DFEDIG_M_2_0_SET
1280 (params->cfg_dfedig_m_2_0),
1281 SD25G_LANE_LANE_0E_LN_CFG_DFEDIG_M_2_0,
1283 SD25G_LANE_LANE_0E(sd_index));
1285 sdx5_rmw(SD25G_LANE_LANE_0E_LN_CFG_EN_DFEDIG_SET(params->cfg_en_dfedig),
1286 SD25G_LANE_LANE_0E_LN_CFG_EN_DFEDIG,
1288 SD25G_LANE_LANE_0E(sd_index));
1290 sdx5_rmw(SD25G_LANE_LANE_40_LN_R_TX_POL_INV_SET(params->r_tx_pol_inv) |
1291 SD25G_LANE_LANE_40_LN_R_RX_POL_INV_SET(params->r_rx_pol_inv),
1292 SD25G_LANE_LANE_40_LN_R_TX_POL_INV |
1293 SD25G_LANE_LANE_40_LN_R_RX_POL_INV,
1295 SD25G_LANE_LANE_40(sd_index));
1297 sdx5_rmw(SD25G_LANE_LANE_04_LN_CFG_RX2TX_LP_EN_SET(params->cfg_rx2tx_lp_en) |
1298 SD25G_LANE_LANE_04_LN_CFG_TX2RX_LP_EN_SET(params->cfg_tx2rx_lp_en),
1299 SD25G_LANE_LANE_04_LN_CFG_RX2TX_LP_EN |
1300 SD25G_LANE_LANE_04_LN_CFG_TX2RX_LP_EN,
1302 SD25G_LANE_LANE_04(sd_index));
1304 sdx5_rmw(SD25G_LANE_LANE_1E_LN_CFG_RXLB_EN_SET(params->cfg_rxlb_en),
1305 SD25G_LANE_LANE_1E_LN_CFG_RXLB_EN,
1307 SD25G_LANE_LANE_1E(sd_index));
1309 sdx5_rmw(SD25G_LANE_LANE_19_LN_CFG_TXLB_EN_SET(params->cfg_txlb_en),
1310 SD25G_LANE_LANE_19_LN_CFG_TXLB_EN,
1312 SD25G_LANE_LANE_19(sd_index));
1314 sdx5_rmw(SD25G_LANE_LANE_2E_LN_CFG_RSTN_DFEDIG_SET(0),
1315 SD25G_LANE_LANE_2E_LN_CFG_RSTN_DFEDIG,
1317 SD25G_LANE_LANE_2E(sd_index));
1319 sdx5_rmw(SD25G_LANE_LANE_2E_LN_CFG_RSTN_DFEDIG_SET(1),
1320 SD25G_LANE_LANE_2E_LN_CFG_RSTN_DFEDIG,
1322 SD25G_LANE_LANE_2E(sd_index));
1324 sdx5_rmw(SD_LANE_25G_SD_LANE_CFG_MACRO_RST_SET(0),
1325 SD_LANE_25G_SD_LANE_CFG_MACRO_RST,
1327 SD_LANE_25G_SD_LANE_CFG(sd_index));
1329 sdx5_rmw(SD25G_LANE_LANE_1C_LN_CFG_CDR_RSTN_SET(0),
1330 SD25G_LANE_LANE_1C_LN_CFG_CDR_RSTN,
1332 SD25G_LANE_LANE_1C(sd_index));
1334 usleep_range(1000, 2000);
1336 sdx5_rmw(SD25G_LANE_LANE_1C_LN_CFG_CDR_RSTN_SET(1),
1337 SD25G_LANE_LANE_1C_LN_CFG_CDR_RSTN,
1339 SD25G_LANE_LANE_1C(sd_index));
1341 usleep_range(10000, 20000);
1343 sdx5_rmw(SD25G_LANE_CMU_FF_REGISTER_TABLE_INDEX_SET(0xff),
1344 SD25G_LANE_CMU_FF_REGISTER_TABLE_INDEX,
1346 SD25G_LANE_CMU_FF(sd_index));
1348 value = readl(sdx5_addr(regs, SD25G_LANE_CMU_C0(sd_index)));
1349 value = SD25G_LANE_CMU_C0_PLL_LOL_UDL_GET(value);
1352 dev_err(dev, "25G PLL Loss of Lock: 0x%x\n", value);
1356 value = readl(sdx5_addr(regs, SD_LANE_25G_SD_LANE_STAT(sd_index)));
1357 value = SD_LANE_25G_SD_LANE_STAT_PMA_RST_DONE_GET(value);
1360 dev_err(dev, "25G PMA Reset failed: 0x%x\n", value);
1363 sdx5_rmw(SD25G_LANE_CMU_2A_R_DBG_LOL_STATUS_SET(0x1),
1364 SD25G_LANE_CMU_2A_R_DBG_LOL_STATUS,
1366 SD25G_LANE_CMU_2A(sd_index));
1368 sdx5_rmw(SD_LANE_25G_SD_SER_RST_SER_RST_SET(0x0),
1369 SD_LANE_25G_SD_SER_RST_SER_RST,
1371 SD_LANE_25G_SD_SER_RST(sd_index));
1373 sdx5_rmw(SD_LANE_25G_SD_DES_RST_DES_RST_SET(0x0),
1374 SD_LANE_25G_SD_DES_RST_DES_RST,
1376 SD_LANE_25G_SD_DES_RST(sd_index));
1378 sdx5_rmw(SD25G_LANE_CMU_FF_REGISTER_TABLE_INDEX_SET(0),
1379 SD25G_LANE_CMU_FF_REGISTER_TABLE_INDEX,
1381 SD25G_LANE_CMU_FF(sd_index));
1383 sdx5_rmw(SD25G_LANE_LANE_2D_LN_CFG_ALOS_THR_2_0_SET
1384 (params->cfg_alos_thr_2_0),
1385 SD25G_LANE_LANE_2D_LN_CFG_ALOS_THR_2_0,
1387 SD25G_LANE_LANE_2D(sd_index));
1389 sdx5_rmw(SD25G_LANE_LANE_2E_LN_CFG_DIS_SQ_SET(0),
1390 SD25G_LANE_LANE_2E_LN_CFG_DIS_SQ,
1392 SD25G_LANE_LANE_2E(sd_index));
1394 sdx5_rmw(SD25G_LANE_LANE_2E_LN_CFG_PD_SQ_SET(0),
1395 SD25G_LANE_LANE_2E_LN_CFG_PD_SQ,
1397 SD25G_LANE_LANE_2E(sd_index));
1402 static void sparx5_sd10g28_reset(void __iomem *regs[], u32 lane_index)
1404 /* Note: SerDes SD10G_LANE_1 is configured in 10G_LAN mode */
1405 sdx5_rmw_addr(SD_LANE_SD_LANE_CFG_EXT_CFG_RST_SET(1),
1406 SD_LANE_SD_LANE_CFG_EXT_CFG_RST,
1407 sdx5_addr(regs, SD_LANE_SD_LANE_CFG(lane_index)));
1409 usleep_range(1000, 2000);
1411 sdx5_rmw_addr(SD_LANE_SD_LANE_CFG_EXT_CFG_RST_SET(0),
1412 SD_LANE_SD_LANE_CFG_EXT_CFG_RST,
1413 sdx5_addr(regs, SD_LANE_SD_LANE_CFG(lane_index)));
1416 static int sparx5_sd10g28_apply_params(struct sparx5_serdes_macro *macro,
1417 struct sparx5_sd10g28_params *params)
1419 struct sparx5_serdes_private *priv = macro->priv;
1420 void __iomem **regs = priv->regs;
1421 struct device *dev = priv->dev;
1422 u32 lane_index = macro->sidx;
1423 u32 sd_index = macro->stpidx;
1424 void __iomem *sd_inst;
1428 sd_inst = sdx5_inst_get(priv, TARGET_SD6G_LANE, sd_index);
1430 sd_inst = sdx5_inst_get(priv, TARGET_SD10G_LANE, sd_index);
1432 sdx5_rmw(SD_LANE_SD_LANE_CFG_MACRO_RST_SET(1),
1433 SD_LANE_SD_LANE_CFG_MACRO_RST,
1435 SD_LANE_SD_LANE_CFG(lane_index));
1437 sdx5_inst_rmw(SD10G_LANE_LANE_93_R_DWIDTHCTRL_FROM_HWT_SET(0x0) |
1438 SD10G_LANE_LANE_93_R_REG_MANUAL_SET(0x1) |
1439 SD10G_LANE_LANE_93_R_AUXCKSEL_FROM_HWT_SET(0x1) |
1440 SD10G_LANE_LANE_93_R_LANE_ID_FROM_HWT_SET(0x1) |
1441 SD10G_LANE_LANE_93_R_EN_RATECHG_CTRL_SET(0x0),
1442 SD10G_LANE_LANE_93_R_DWIDTHCTRL_FROM_HWT |
1443 SD10G_LANE_LANE_93_R_REG_MANUAL |
1444 SD10G_LANE_LANE_93_R_AUXCKSEL_FROM_HWT |
1445 SD10G_LANE_LANE_93_R_LANE_ID_FROM_HWT |
1446 SD10G_LANE_LANE_93_R_EN_RATECHG_CTRL,
1448 SD10G_LANE_LANE_93(sd_index));
1450 sdx5_inst_rmw(SD10G_LANE_LANE_94_R_ISCAN_REG_SET(0x1) |
1451 SD10G_LANE_LANE_94_R_TXEQ_REG_SET(0x1) |
1452 SD10G_LANE_LANE_94_R_MISC_REG_SET(0x1) |
1453 SD10G_LANE_LANE_94_R_SWING_REG_SET(0x1),
1454 SD10G_LANE_LANE_94_R_ISCAN_REG |
1455 SD10G_LANE_LANE_94_R_TXEQ_REG |
1456 SD10G_LANE_LANE_94_R_MISC_REG |
1457 SD10G_LANE_LANE_94_R_SWING_REG,
1459 SD10G_LANE_LANE_94(sd_index));
1461 sdx5_inst_rmw(SD10G_LANE_LANE_9E_R_RXEQ_REG_SET(0x1),
1462 SD10G_LANE_LANE_9E_R_RXEQ_REG,
1464 SD10G_LANE_LANE_9E(sd_index));
1466 sdx5_inst_rmw(SD10G_LANE_LANE_A1_R_SSC_FROM_HWT_SET(0x0) |
1467 SD10G_LANE_LANE_A1_R_CDR_FROM_HWT_SET(0x0) |
1468 SD10G_LANE_LANE_A1_R_PCLK_GATING_FROM_HWT_SET(0x1),
1469 SD10G_LANE_LANE_A1_R_SSC_FROM_HWT |
1470 SD10G_LANE_LANE_A1_R_CDR_FROM_HWT |
1471 SD10G_LANE_LANE_A1_R_PCLK_GATING_FROM_HWT,
1473 SD10G_LANE_LANE_A1(sd_index));
1475 sdx5_rmw(SD_LANE_SD_LANE_CFG_RX_REF_SEL_SET(params->cmu_sel) |
1476 SD_LANE_SD_LANE_CFG_TX_REF_SEL_SET(params->cmu_sel),
1477 SD_LANE_SD_LANE_CFG_RX_REF_SEL |
1478 SD_LANE_SD_LANE_CFG_TX_REF_SEL,
1480 SD_LANE_SD_LANE_CFG(lane_index));
1482 sdx5_inst_rmw(SD10G_LANE_LANE_40_CFG_LANE_RESERVE_7_0_SET
1483 (params->cfg_lane_reserve_7_0),
1484 SD10G_LANE_LANE_40_CFG_LANE_RESERVE_7_0,
1486 SD10G_LANE_LANE_40(sd_index));
1488 sdx5_inst_rmw(SD10G_LANE_LANE_50_CFG_SSC_RTL_CLK_SEL_SET
1489 (params->cfg_ssc_rtl_clk_sel),
1490 SD10G_LANE_LANE_50_CFG_SSC_RTL_CLK_SEL,
1492 SD10G_LANE_LANE_50(sd_index));
1494 sdx5_inst_rmw(SD10G_LANE_LANE_35_CFG_TXRATE_1_0_SET
1495 (params->cfg_txrate_1_0) |
1496 SD10G_LANE_LANE_35_CFG_RXRATE_1_0_SET
1497 (params->cfg_rxrate_1_0),
1498 SD10G_LANE_LANE_35_CFG_TXRATE_1_0 |
1499 SD10G_LANE_LANE_35_CFG_RXRATE_1_0,
1501 SD10G_LANE_LANE_35(sd_index));
1503 sdx5_inst_rmw(SD10G_LANE_LANE_94_R_DWIDTHCTRL_2_0_SET
1504 (params->r_d_width_ctrl_2_0),
1505 SD10G_LANE_LANE_94_R_DWIDTHCTRL_2_0,
1507 SD10G_LANE_LANE_94(sd_index));
1509 sdx5_inst_rmw(SD10G_LANE_LANE_01_CFG_PMA_TX_CK_BITWIDTH_2_0_SET
1510 (params->cfg_pma_tx_ck_bitwidth_2_0),
1511 SD10G_LANE_LANE_01_CFG_PMA_TX_CK_BITWIDTH_2_0,
1513 SD10G_LANE_LANE_01(sd_index));
1515 sdx5_inst_rmw(SD10G_LANE_LANE_30_CFG_RXDIV_SEL_2_0_SET
1516 (params->cfg_rxdiv_sel_2_0),
1517 SD10G_LANE_LANE_30_CFG_RXDIV_SEL_2_0,
1519 SD10G_LANE_LANE_30(sd_index));
1521 sdx5_inst_rmw(SD10G_LANE_LANE_A2_R_PCS2PMA_PHYMODE_4_0_SET
1522 (params->r_pcs2pma_phymode_4_0),
1523 SD10G_LANE_LANE_A2_R_PCS2PMA_PHYMODE_4_0,
1525 SD10G_LANE_LANE_A2(sd_index));
1527 sdx5_inst_rmw(SD10G_LANE_LANE_13_CFG_CDRCK_EN_SET(params->cfg_cdrck_en),
1528 SD10G_LANE_LANE_13_CFG_CDRCK_EN,
1530 SD10G_LANE_LANE_13(sd_index));
1532 sdx5_inst_rmw(SD10G_LANE_LANE_23_CFG_DFECK_EN_SET
1533 (params->cfg_dfeck_en) |
1534 SD10G_LANE_LANE_23_CFG_DFE_PD_SET(params->cfg_dfe_pd) |
1535 SD10G_LANE_LANE_23_CFG_ERRAMP_PD_SET
1536 (params->cfg_erramp_pd),
1537 SD10G_LANE_LANE_23_CFG_DFECK_EN |
1538 SD10G_LANE_LANE_23_CFG_DFE_PD |
1539 SD10G_LANE_LANE_23_CFG_ERRAMP_PD,
1541 SD10G_LANE_LANE_23(sd_index));
1543 sdx5_inst_rmw(SD10G_LANE_LANE_22_CFG_DFETAP_EN_5_1_SET
1544 (params->cfg_dfetap_en_5_1),
1545 SD10G_LANE_LANE_22_CFG_DFETAP_EN_5_1,
1547 SD10G_LANE_LANE_22(sd_index));
1549 sdx5_inst_rmw(SD10G_LANE_LANE_1A_CFG_PI_DFE_EN_SET
1550 (params->cfg_pi_DFE_en),
1551 SD10G_LANE_LANE_1A_CFG_PI_DFE_EN,
1553 SD10G_LANE_LANE_1A(sd_index));
1555 sdx5_inst_rmw(SD10G_LANE_LANE_02_CFG_EN_ADV_SET(params->cfg_en_adv) |
1556 SD10G_LANE_LANE_02_CFG_EN_MAIN_SET(params->cfg_en_main) |
1557 SD10G_LANE_LANE_02_CFG_EN_DLY_SET(params->cfg_en_dly) |
1558 SD10G_LANE_LANE_02_CFG_TAP_ADV_3_0_SET
1559 (params->cfg_tap_adv_3_0),
1560 SD10G_LANE_LANE_02_CFG_EN_ADV |
1561 SD10G_LANE_LANE_02_CFG_EN_MAIN |
1562 SD10G_LANE_LANE_02_CFG_EN_DLY |
1563 SD10G_LANE_LANE_02_CFG_TAP_ADV_3_0,
1565 SD10G_LANE_LANE_02(sd_index));
1567 sdx5_inst_rmw(SD10G_LANE_LANE_03_CFG_TAP_MAIN_SET(params->cfg_tap_main),
1568 SD10G_LANE_LANE_03_CFG_TAP_MAIN,
1570 SD10G_LANE_LANE_03(sd_index));
1572 sdx5_inst_rmw(SD10G_LANE_LANE_04_CFG_TAP_DLY_4_0_SET
1573 (params->cfg_tap_dly_4_0),
1574 SD10G_LANE_LANE_04_CFG_TAP_DLY_4_0,
1576 SD10G_LANE_LANE_04(sd_index));
1578 sdx5_inst_rmw(SD10G_LANE_LANE_2F_CFG_VGA_CTRL_3_0_SET
1579 (params->cfg_vga_ctrl_3_0),
1580 SD10G_LANE_LANE_2F_CFG_VGA_CTRL_3_0,
1582 SD10G_LANE_LANE_2F(sd_index));
1584 sdx5_inst_rmw(SD10G_LANE_LANE_2F_CFG_VGA_CP_2_0_SET
1585 (params->cfg_vga_cp_2_0),
1586 SD10G_LANE_LANE_2F_CFG_VGA_CP_2_0,
1588 SD10G_LANE_LANE_2F(sd_index));
1590 sdx5_inst_rmw(SD10G_LANE_LANE_0B_CFG_EQ_RES_3_0_SET
1591 (params->cfg_eq_res_3_0),
1592 SD10G_LANE_LANE_0B_CFG_EQ_RES_3_0,
1594 SD10G_LANE_LANE_0B(sd_index));
1596 sdx5_inst_rmw(SD10G_LANE_LANE_0D_CFG_EQR_BYP_SET(params->cfg_eq_r_byp),
1597 SD10G_LANE_LANE_0D_CFG_EQR_BYP,
1599 SD10G_LANE_LANE_0D(sd_index));
1601 sdx5_inst_rmw(SD10G_LANE_LANE_0E_CFG_EQC_FORCE_3_0_SET
1602 (params->cfg_eq_c_force_3_0) |
1603 SD10G_LANE_LANE_0E_CFG_SUM_SETCM_EN_SET
1604 (params->cfg_sum_setcm_en),
1605 SD10G_LANE_LANE_0E_CFG_EQC_FORCE_3_0 |
1606 SD10G_LANE_LANE_0E_CFG_SUM_SETCM_EN,
1608 SD10G_LANE_LANE_0E(sd_index));
1610 sdx5_inst_rmw(SD10G_LANE_LANE_23_CFG_EN_DFEDIG_SET
1611 (params->cfg_en_dfedig),
1612 SD10G_LANE_LANE_23_CFG_EN_DFEDIG,
1614 SD10G_LANE_LANE_23(sd_index));
1616 sdx5_inst_rmw(SD10G_LANE_LANE_06_CFG_EN_PREEMPH_SET
1617 (params->cfg_en_preemph),
1618 SD10G_LANE_LANE_06_CFG_EN_PREEMPH,
1620 SD10G_LANE_LANE_06(sd_index));
1622 sdx5_inst_rmw(SD10G_LANE_LANE_33_CFG_ITX_IPPREEMP_BASE_1_0_SET
1623 (params->cfg_itx_ippreemp_base_1_0) |
1624 SD10G_LANE_LANE_33_CFG_ITX_IPDRIVER_BASE_2_0_SET
1625 (params->cfg_itx_ipdriver_base_2_0),
1626 SD10G_LANE_LANE_33_CFG_ITX_IPPREEMP_BASE_1_0 |
1627 SD10G_LANE_LANE_33_CFG_ITX_IPDRIVER_BASE_2_0,
1629 SD10G_LANE_LANE_33(sd_index));
1631 sdx5_inst_rmw(SD10G_LANE_LANE_52_CFG_IBIAS_TUNE_RESERVE_5_0_SET
1632 (params->cfg_ibias_tune_reserve_5_0),
1633 SD10G_LANE_LANE_52_CFG_IBIAS_TUNE_RESERVE_5_0,
1635 SD10G_LANE_LANE_52(sd_index));
1637 sdx5_inst_rmw(SD10G_LANE_LANE_37_CFG_TXSWING_HALF_SET
1638 (params->cfg_txswing_half),
1639 SD10G_LANE_LANE_37_CFG_TXSWING_HALF,
1641 SD10G_LANE_LANE_37(sd_index));
1643 sdx5_inst_rmw(SD10G_LANE_LANE_3C_CFG_DIS_2NDORDER_SET
1644 (params->cfg_dis_2nd_order),
1645 SD10G_LANE_LANE_3C_CFG_DIS_2NDORDER,
1647 SD10G_LANE_LANE_3C(sd_index));
1649 sdx5_inst_rmw(SD10G_LANE_LANE_39_CFG_RX_SSC_LH_SET
1650 (params->cfg_rx_ssc_lh),
1651 SD10G_LANE_LANE_39_CFG_RX_SSC_LH,
1653 SD10G_LANE_LANE_39(sd_index));
1655 sdx5_inst_rmw(SD10G_LANE_LANE_1A_CFG_PI_FLOOP_STEPS_1_0_SET
1656 (params->cfg_pi_floop_steps_1_0),
1657 SD10G_LANE_LANE_1A_CFG_PI_FLOOP_STEPS_1_0,
1659 SD10G_LANE_LANE_1A(sd_index));
1661 sdx5_inst_rmw(SD10G_LANE_LANE_16_CFG_PI_EXT_DAC_23_16_SET
1662 (params->cfg_pi_ext_dac_23_16),
1663 SD10G_LANE_LANE_16_CFG_PI_EXT_DAC_23_16,
1665 SD10G_LANE_LANE_16(sd_index));
1667 sdx5_inst_rmw(SD10G_LANE_LANE_15_CFG_PI_EXT_DAC_15_8_SET
1668 (params->cfg_pi_ext_dac_15_8),
1669 SD10G_LANE_LANE_15_CFG_PI_EXT_DAC_15_8,
1671 SD10G_LANE_LANE_15(sd_index));
1673 sdx5_inst_rmw(SD10G_LANE_LANE_26_CFG_ISCAN_EXT_DAC_7_0_SET
1674 (params->cfg_iscan_ext_dac_7_0),
1675 SD10G_LANE_LANE_26_CFG_ISCAN_EXT_DAC_7_0,
1677 SD10G_LANE_LANE_26(sd_index));
1679 sdx5_inst_rmw(SD10G_LANE_LANE_42_CFG_CDR_KF_GEN1_2_0_SET
1680 (params->cfg_cdr_kf_gen1_2_0),
1681 SD10G_LANE_LANE_42_CFG_CDR_KF_GEN1_2_0,
1683 SD10G_LANE_LANE_42(sd_index));
1685 sdx5_inst_rmw(SD10G_LANE_LANE_0F_R_CDR_M_GEN1_7_0_SET
1686 (params->r_cdr_m_gen1_7_0),
1687 SD10G_LANE_LANE_0F_R_CDR_M_GEN1_7_0,
1689 SD10G_LANE_LANE_0F(sd_index));
1691 sdx5_inst_rmw(SD10G_LANE_LANE_24_CFG_PI_BW_GEN1_3_0_SET
1692 (params->cfg_pi_bw_gen1_3_0),
1693 SD10G_LANE_LANE_24_CFG_PI_BW_GEN1_3_0,
1695 SD10G_LANE_LANE_24(sd_index));
1697 sdx5_inst_rmw(SD10G_LANE_LANE_14_CFG_PI_EXT_DAC_7_0_SET
1698 (params->cfg_pi_ext_dac_7_0),
1699 SD10G_LANE_LANE_14_CFG_PI_EXT_DAC_7_0,
1701 SD10G_LANE_LANE_14(sd_index));
1703 sdx5_inst_rmw(SD10G_LANE_LANE_1A_CFG_PI_STEPS_SET(params->cfg_pi_steps),
1704 SD10G_LANE_LANE_1A_CFG_PI_STEPS,
1706 SD10G_LANE_LANE_1A(sd_index));
1708 sdx5_inst_rmw(SD10G_LANE_LANE_3A_CFG_MP_MAX_3_0_SET
1709 (params->cfg_mp_max_3_0),
1710 SD10G_LANE_LANE_3A_CFG_MP_MAX_3_0,
1712 SD10G_LANE_LANE_3A(sd_index));
1714 sdx5_inst_rmw(SD10G_LANE_LANE_31_CFG_RSTN_DFEDIG_SET
1715 (params->cfg_rstn_dfedig),
1716 SD10G_LANE_LANE_31_CFG_RSTN_DFEDIG,
1718 SD10G_LANE_LANE_31(sd_index));
1720 sdx5_inst_rmw(SD10G_LANE_LANE_48_CFG_ALOS_THR_3_0_SET
1721 (params->cfg_alos_thr_3_0),
1722 SD10G_LANE_LANE_48_CFG_ALOS_THR_3_0,
1724 SD10G_LANE_LANE_48(sd_index));
1726 sdx5_inst_rmw(SD10G_LANE_LANE_36_CFG_PREDRV_SLEWRATE_1_0_SET
1727 (params->cfg_predrv_slewrate_1_0),
1728 SD10G_LANE_LANE_36_CFG_PREDRV_SLEWRATE_1_0,
1730 SD10G_LANE_LANE_36(sd_index));
1732 sdx5_inst_rmw(SD10G_LANE_LANE_32_CFG_ITX_IPCML_BASE_1_0_SET
1733 (params->cfg_itx_ipcml_base_1_0),
1734 SD10G_LANE_LANE_32_CFG_ITX_IPCML_BASE_1_0,
1736 SD10G_LANE_LANE_32(sd_index));
1738 sdx5_inst_rmw(SD10G_LANE_LANE_37_CFG_IP_PRE_BASE_1_0_SET
1739 (params->cfg_ip_pre_base_1_0),
1740 SD10G_LANE_LANE_37_CFG_IP_PRE_BASE_1_0,
1742 SD10G_LANE_LANE_37(sd_index));
1744 sdx5_inst_rmw(SD10G_LANE_LANE_41_CFG_LANE_RESERVE_15_8_SET
1745 (params->cfg_lane_reserve_15_8),
1746 SD10G_LANE_LANE_41_CFG_LANE_RESERVE_15_8,
1748 SD10G_LANE_LANE_41(sd_index));
1750 sdx5_inst_rmw(SD10G_LANE_LANE_9E_R_EN_AUTO_CDR_RSTN_SET
1751 (params->r_en_auto_cdr_rstn),
1752 SD10G_LANE_LANE_9E_R_EN_AUTO_CDR_RSTN,
1754 SD10G_LANE_LANE_9E(sd_index));
1756 sdx5_inst_rmw(SD10G_LANE_LANE_0C_CFG_OSCAL_AFE_SET
1757 (params->cfg_oscal_afe) |
1758 SD10G_LANE_LANE_0C_CFG_PD_OSDAC_AFE_SET
1759 (params->cfg_pd_osdac_afe),
1760 SD10G_LANE_LANE_0C_CFG_OSCAL_AFE |
1761 SD10G_LANE_LANE_0C_CFG_PD_OSDAC_AFE,
1763 SD10G_LANE_LANE_0C(sd_index));
1765 sdx5_inst_rmw(SD10G_LANE_LANE_0B_CFG_RESETB_OSCAL_AFE_SET
1766 (params->cfg_resetb_oscal_afe[0]),
1767 SD10G_LANE_LANE_0B_CFG_RESETB_OSCAL_AFE,
1769 SD10G_LANE_LANE_0B(sd_index));
1771 sdx5_inst_rmw(SD10G_LANE_LANE_0B_CFG_RESETB_OSCAL_AFE_SET
1772 (params->cfg_resetb_oscal_afe[1]),
1773 SD10G_LANE_LANE_0B_CFG_RESETB_OSCAL_AFE,
1775 SD10G_LANE_LANE_0B(sd_index));
1777 sdx5_inst_rmw(SD10G_LANE_LANE_83_R_TX_POL_INV_SET
1778 (params->r_tx_pol_inv) |
1779 SD10G_LANE_LANE_83_R_RX_POL_INV_SET
1780 (params->r_rx_pol_inv),
1781 SD10G_LANE_LANE_83_R_TX_POL_INV |
1782 SD10G_LANE_LANE_83_R_RX_POL_INV,
1784 SD10G_LANE_LANE_83(sd_index));
1786 sdx5_inst_rmw(SD10G_LANE_LANE_06_CFG_RX2TX_LP_EN_SET
1787 (params->cfg_rx2tx_lp_en) |
1788 SD10G_LANE_LANE_06_CFG_TX2RX_LP_EN_SET
1789 (params->cfg_tx2rx_lp_en),
1790 SD10G_LANE_LANE_06_CFG_RX2TX_LP_EN |
1791 SD10G_LANE_LANE_06_CFG_TX2RX_LP_EN,
1793 SD10G_LANE_LANE_06(sd_index));
1795 sdx5_inst_rmw(SD10G_LANE_LANE_0E_CFG_RXLB_EN_SET(params->cfg_rxlb_en) |
1796 SD10G_LANE_LANE_0E_CFG_TXLB_EN_SET(params->cfg_txlb_en),
1797 SD10G_LANE_LANE_0E_CFG_RXLB_EN |
1798 SD10G_LANE_LANE_0E_CFG_TXLB_EN,
1800 SD10G_LANE_LANE_0E(sd_index));
1802 sdx5_rmw(SD_LANE_SD_LANE_CFG_MACRO_RST_SET(0),
1803 SD_LANE_SD_LANE_CFG_MACRO_RST,
1805 SD_LANE_SD_LANE_CFG(lane_index));
1807 sdx5_inst_rmw(SD10G_LANE_LANE_50_CFG_SSC_RESETB_SET(1),
1808 SD10G_LANE_LANE_50_CFG_SSC_RESETB,
1810 SD10G_LANE_LANE_50(sd_index));
1812 sdx5_rmw(SD10G_LANE_LANE_50_CFG_SSC_RESETB_SET(1),
1813 SD10G_LANE_LANE_50_CFG_SSC_RESETB,
1815 SD10G_LANE_LANE_50(sd_index));
1817 sdx5_rmw(SD_LANE_MISC_SD_125_RST_DIS_SET(params->fx_100),
1818 SD_LANE_MISC_SD_125_RST_DIS,
1820 SD_LANE_MISC(lane_index));
1822 sdx5_rmw(SD_LANE_MISC_RX_ENA_SET(params->fx_100),
1823 SD_LANE_MISC_RX_ENA,
1825 SD_LANE_MISC(lane_index));
1827 sdx5_rmw(SD_LANE_MISC_MUX_ENA_SET(params->fx_100),
1828 SD_LANE_MISC_MUX_ENA,
1830 SD_LANE_MISC(lane_index));
1832 usleep_range(3000, 6000);
1834 value = readl(sdx5_addr(regs, SD_LANE_SD_LANE_STAT(lane_index)));
1835 value = SD_LANE_SD_LANE_STAT_PMA_RST_DONE_GET(value);
1837 dev_err(dev, "10G PMA Reset failed: 0x%x\n", value);
1841 sdx5_rmw(SD_LANE_SD_SER_RST_SER_RST_SET(0x0),
1842 SD_LANE_SD_SER_RST_SER_RST,
1844 SD_LANE_SD_SER_RST(lane_index));
1846 sdx5_rmw(SD_LANE_SD_DES_RST_DES_RST_SET(0x0),
1847 SD_LANE_SD_DES_RST_DES_RST,
1849 SD_LANE_SD_DES_RST(lane_index));
1854 static int sparx5_sd25g28_config(struct sparx5_serdes_macro *macro, bool reset)
1856 struct sparx5_sd25g28_media_preset media = media_presets_25g[macro->media];
1857 struct sparx5_sd25g28_mode_preset mode;
1858 struct sparx5_sd25g28_args args = {
1862 .com_pll_reserve = 0xf,
1865 struct sparx5_sd25g28_params params;
1868 err = sparx5_sd10g25_get_mode_preset(macro, &mode);
1871 sparx5_sd25g28_get_params(macro, &media, &mode, &args, ¶ms);
1872 sparx5_sd25g28_reset(macro->priv->regs, ¶ms, macro->stpidx);
1873 return sparx5_sd25g28_apply_params(macro, ¶ms);
1876 static int sparx5_sd10g28_config(struct sparx5_serdes_macro *macro, bool reset)
1878 struct sparx5_sd10g28_media_preset media = media_presets_10g[macro->media];
1879 struct sparx5_sd10g28_mode_preset mode;
1880 struct sparx5_sd10g28_params params;
1881 struct sparx5_sd10g28_args args = {
1882 .is_6g = (macro->serdestype == SPX5_SDT_6G),
1890 err = sparx5_sd10g28_get_mode_preset(macro, &mode, &args);
1893 sparx5_sd10g28_get_params(macro, &media, &mode, &args, ¶ms);
1894 sparx5_sd10g28_reset(macro->priv->regs, macro->sidx);
1895 return sparx5_sd10g28_apply_params(macro, ¶ms);
1898 /* Power down serdes TX driver */
1899 static int sparx5_serdes_power_save(struct sparx5_serdes_macro *macro, u32 pwdn)
1901 struct sparx5_serdes_private *priv = macro->priv;
1902 void __iomem *sd_inst;
1904 if (macro->serdestype == SPX5_SDT_6G)
1905 sd_inst = sdx5_inst_get(priv, TARGET_SD6G_LANE, macro->stpidx);
1906 else if (macro->serdestype == SPX5_SDT_10G)
1907 sd_inst = sdx5_inst_get(priv, TARGET_SD10G_LANE, macro->stpidx);
1909 sd_inst = sdx5_inst_get(priv, TARGET_SD25G_LANE, macro->stpidx);
1911 if (macro->serdestype == SPX5_SDT_25G) {
1912 sdx5_inst_rmw(SD25G_LANE_LANE_04_LN_CFG_PD_DRIVER_SET(pwdn),
1913 SD25G_LANE_LANE_04_LN_CFG_PD_DRIVER,
1915 SD25G_LANE_LANE_04(0));
1918 sdx5_inst_rmw(SD10G_LANE_LANE_06_CFG_PD_DRIVER_SET(pwdn),
1919 SD10G_LANE_LANE_06_CFG_PD_DRIVER,
1921 SD10G_LANE_LANE_06(0));
1926 static int sparx5_serdes_clock_config(struct sparx5_serdes_macro *macro)
1928 struct sparx5_serdes_private *priv = macro->priv;
1930 if (macro->serdesmode == SPX5_SD_MODE_100FX) {
1931 u32 freq = priv->coreclock == 250000000 ? 2 :
1932 priv->coreclock == 500000000 ? 1 : 0;
1934 sdx5_rmw(SD_LANE_MISC_CORE_CLK_FREQ_SET(freq),
1935 SD_LANE_MISC_CORE_CLK_FREQ,
1937 SD_LANE_MISC(macro->sidx));
1942 static int sparx5_cmu_apply_cfg(struct sparx5_serdes_private *priv,
1944 void __iomem *cmu_tgt,
1945 void __iomem *cmu_cfg_tgt,
1948 void __iomem **regs = priv->regs;
1949 struct device *dev = priv->dev;
1952 cmu_tgt = sdx5_inst_get(priv, TARGET_SD_CMU, cmu_idx);
1953 cmu_cfg_tgt = sdx5_inst_get(priv, TARGET_SD_CMU_CFG, cmu_idx);
1955 if (cmu_idx == 1 || cmu_idx == 4 || cmu_idx == 7 ||
1956 cmu_idx == 10 || cmu_idx == 13) {
1960 sdx5_inst_rmw(SD_CMU_CFG_SD_CMU_CFG_EXT_CFG_RST_SET(1),
1961 SD_CMU_CFG_SD_CMU_CFG_EXT_CFG_RST,
1963 SD_CMU_CFG_SD_CMU_CFG(cmu_idx));
1965 sdx5_inst_rmw(SD_CMU_CFG_SD_CMU_CFG_EXT_CFG_RST_SET(0),
1966 SD_CMU_CFG_SD_CMU_CFG_EXT_CFG_RST,
1968 SD_CMU_CFG_SD_CMU_CFG(cmu_idx));
1970 sdx5_inst_rmw(SD_CMU_CFG_SD_CMU_CFG_CMU_RST_SET(1),
1971 SD_CMU_CFG_SD_CMU_CFG_CMU_RST,
1973 SD_CMU_CFG_SD_CMU_CFG(cmu_idx));
1975 sdx5_inst_rmw(SD_CMU_CMU_45_R_DWIDTHCTRL_FROM_HWT_SET(0x1) |
1976 SD_CMU_CMU_45_R_REFCK_SSC_EN_FROM_HWT_SET(0x1) |
1977 SD_CMU_CMU_45_R_LINK_BUF_EN_FROM_HWT_SET(0x1) |
1978 SD_CMU_CMU_45_R_BIAS_EN_FROM_HWT_SET(0x1) |
1979 SD_CMU_CMU_45_R_EN_RATECHG_CTRL_SET(0x0),
1980 SD_CMU_CMU_45_R_DWIDTHCTRL_FROM_HWT |
1981 SD_CMU_CMU_45_R_REFCK_SSC_EN_FROM_HWT |
1982 SD_CMU_CMU_45_R_LINK_BUF_EN_FROM_HWT |
1983 SD_CMU_CMU_45_R_BIAS_EN_FROM_HWT |
1984 SD_CMU_CMU_45_R_EN_RATECHG_CTRL,
1986 SD_CMU_CMU_45(cmu_idx));
1988 sdx5_inst_rmw(SD_CMU_CMU_47_R_PCS2PMA_PHYMODE_4_0_SET(0),
1989 SD_CMU_CMU_47_R_PCS2PMA_PHYMODE_4_0,
1991 SD_CMU_CMU_47(cmu_idx));
1993 sdx5_inst_rmw(SD_CMU_CMU_1B_CFG_RESERVE_7_0_SET(0),
1994 SD_CMU_CMU_1B_CFG_RESERVE_7_0,
1996 SD_CMU_CMU_1B(cmu_idx));
1998 sdx5_inst_rmw(SD_CMU_CMU_0D_CFG_JC_BYP_SET(0x1),
1999 SD_CMU_CMU_0D_CFG_JC_BYP,
2001 SD_CMU_CMU_0D(cmu_idx));
2003 sdx5_inst_rmw(SD_CMU_CMU_1F_CFG_VTUNE_SEL_SET(1),
2004 SD_CMU_CMU_1F_CFG_VTUNE_SEL,
2006 SD_CMU_CMU_1F(cmu_idx));
2008 sdx5_inst_rmw(SD_CMU_CMU_00_CFG_PLL_TP_SEL_1_0_SET(3),
2009 SD_CMU_CMU_00_CFG_PLL_TP_SEL_1_0,
2011 SD_CMU_CMU_00(cmu_idx));
2013 sdx5_inst_rmw(SD_CMU_CMU_05_CFG_BIAS_TP_SEL_1_0_SET(3),
2014 SD_CMU_CMU_05_CFG_BIAS_TP_SEL_1_0,
2016 SD_CMU_CMU_05(cmu_idx));
2018 sdx5_inst_rmw(SD_CMU_CMU_30_R_PLL_DLOL_EN_SET(1),
2019 SD_CMU_CMU_30_R_PLL_DLOL_EN,
2021 SD_CMU_CMU_30(cmu_idx));
2023 sdx5_inst_rmw(SD_CMU_CMU_09_CFG_SW_10G_SET(spd10g),
2024 SD_CMU_CMU_09_CFG_SW_10G,
2026 SD_CMU_CMU_09(cmu_idx));
2028 sdx5_inst_rmw(SD_CMU_CFG_SD_CMU_CFG_CMU_RST_SET(0),
2029 SD_CMU_CFG_SD_CMU_CFG_CMU_RST,
2031 SD_CMU_CFG_SD_CMU_CFG(cmu_idx));
2035 sdx5_inst_rmw(SD_CMU_CMU_44_R_PLL_RSTN_SET(0),
2036 SD_CMU_CMU_44_R_PLL_RSTN,
2038 SD_CMU_CMU_44(cmu_idx));
2040 sdx5_inst_rmw(SD_CMU_CMU_44_R_PLL_RSTN_SET(1),
2041 SD_CMU_CMU_44_R_PLL_RSTN,
2043 SD_CMU_CMU_44(cmu_idx));
2047 value = readl(sdx5_addr(regs, SD_CMU_CMU_E0(cmu_idx)));
2048 value = SD_CMU_CMU_E0_PLL_LOL_UDL_GET(value);
2051 dev_err(dev, "CMU PLL Loss of Lock: 0x%x\n", value);
2054 sdx5_inst_rmw(SD_CMU_CMU_0D_CFG_PMA_TX_CK_PD_SET(0),
2055 SD_CMU_CMU_0D_CFG_PMA_TX_CK_PD,
2057 SD_CMU_CMU_0D(cmu_idx));
2061 static int sparx5_cmu_cfg(struct sparx5_serdes_private *priv, u32 cmu_idx)
2063 void __iomem *cmu_tgt, *cmu_cfg_tgt;
2066 if (cmu_idx == 1 || cmu_idx == 4 || cmu_idx == 7 ||
2067 cmu_idx == 10 || cmu_idx == 13) {
2071 cmu_tgt = sdx5_inst_get(priv, TARGET_SD_CMU, cmu_idx);
2072 cmu_cfg_tgt = sdx5_inst_get(priv, TARGET_SD_CMU_CFG, cmu_idx);
2074 return sparx5_cmu_apply_cfg(priv, cmu_idx, cmu_tgt, cmu_cfg_tgt, spd10g);
2077 static int sparx5_serdes_cmu_enable(struct sparx5_serdes_private *priv)
2081 if (!priv->cmu_enabled) {
2082 for (idx = 0; idx < SPX5_CMU_MAX; idx++) {
2083 err = sparx5_cmu_cfg(priv, idx);
2085 dev_err(priv->dev, "CMU %u, error: %d\n", idx, err);
2089 priv->cmu_enabled = true;
2095 static int sparx5_serdes_get_serdesmode(phy_interface_t portmode, int speed)
2098 case PHY_INTERFACE_MODE_1000BASEX:
2099 case PHY_INTERFACE_MODE_2500BASEX:
2100 if (speed == SPEED_2500)
2101 return SPX5_SD_MODE_2G5;
2102 if (speed == SPEED_100)
2103 return SPX5_SD_MODE_100FX;
2104 return SPX5_SD_MODE_1000BASEX;
2105 case PHY_INTERFACE_MODE_SGMII:
2106 /* The same Serdes mode is used for both SGMII and 1000BaseX */
2107 return SPX5_SD_MODE_1000BASEX;
2108 case PHY_INTERFACE_MODE_QSGMII:
2109 return SPX5_SD_MODE_QSGMII;
2110 case PHY_INTERFACE_MODE_10GBASER:
2111 return SPX5_SD_MODE_SFI;
2117 static int sparx5_serdes_config(struct sparx5_serdes_macro *macro)
2119 struct device *dev = macro->priv->dev;
2123 err = sparx5_serdes_cmu_enable(macro->priv);
2127 serdesmode = sparx5_serdes_get_serdesmode(macro->portmode, macro->speed);
2128 if (serdesmode < 0) {
2129 dev_err(dev, "SerDes %u, interface not supported: %s\n",
2131 phy_modes(macro->portmode));
2134 macro->serdesmode = serdesmode;
2136 sparx5_serdes_clock_config(macro);
2138 if (macro->serdestype == SPX5_SDT_25G)
2139 err = sparx5_sd25g28_config(macro, false);
2141 err = sparx5_sd10g28_config(macro, false);
2143 dev_err(dev, "SerDes %u, config error: %d\n",
2149 static int sparx5_serdes_power_on(struct phy *phy)
2151 struct sparx5_serdes_macro *macro = phy_get_drvdata(phy);
2153 return sparx5_serdes_power_save(macro, false);
2156 static int sparx5_serdes_power_off(struct phy *phy)
2158 struct sparx5_serdes_macro *macro = phy_get_drvdata(phy);
2160 return sparx5_serdes_power_save(macro, true);
2163 static int sparx5_serdes_set_mode(struct phy *phy, enum phy_mode mode, int submode)
2165 struct sparx5_serdes_macro *macro;
2167 if (mode != PHY_MODE_ETHERNET)
2171 case PHY_INTERFACE_MODE_1000BASEX:
2172 case PHY_INTERFACE_MODE_2500BASEX:
2173 case PHY_INTERFACE_MODE_SGMII:
2174 case PHY_INTERFACE_MODE_QSGMII:
2175 case PHY_INTERFACE_MODE_10GBASER:
2176 macro = phy_get_drvdata(phy);
2177 macro->portmode = submode;
2178 sparx5_serdes_config(macro);
2185 static int sparx5_serdes_set_media(struct phy *phy, enum phy_media media)
2187 struct sparx5_serdes_macro *macro = phy_get_drvdata(phy);
2189 if (media != macro->media) {
2190 macro->media = media;
2191 if (macro->serdesmode != SPX5_SD_MODE_NONE)
2192 sparx5_serdes_config(macro);
2197 static int sparx5_serdes_set_speed(struct phy *phy, int speed)
2199 struct sparx5_serdes_macro *macro = phy_get_drvdata(phy);
2201 if (macro->sidx < SPX5_SERDES_10G_START && speed > SPEED_5000)
2203 if (macro->sidx < SPX5_SERDES_25G_START && speed > SPEED_10000)
2205 if (speed != macro->speed) {
2206 macro->speed = speed;
2207 if (macro->serdesmode != SPX5_SD_MODE_NONE)
2208 sparx5_serdes_config(macro);
2213 static int sparx5_serdes_reset(struct phy *phy)
2215 struct sparx5_serdes_macro *macro = phy_get_drvdata(phy);
2218 err = sparx5_serdes_cmu_enable(macro->priv);
2221 if (macro->serdestype == SPX5_SDT_25G)
2222 err = sparx5_sd25g28_config(macro, true);
2224 err = sparx5_sd10g28_config(macro, true);
2226 dev_err(&phy->dev, "SerDes %u, reset error: %d\n",
2232 static int sparx5_serdes_validate(struct phy *phy, enum phy_mode mode,
2234 union phy_configure_opts *opts)
2236 struct sparx5_serdes_macro *macro = phy_get_drvdata(phy);
2238 if (mode != PHY_MODE_ETHERNET)
2241 if (macro->speed == 0)
2244 if (macro->sidx < SPX5_SERDES_10G_START && macro->speed > SPEED_5000)
2246 if (macro->sidx < SPX5_SERDES_25G_START && macro->speed > SPEED_10000)
2250 case PHY_INTERFACE_MODE_1000BASEX:
2251 if (macro->speed != SPEED_100 && /* This is for 100BASE-FX */
2252 macro->speed != SPEED_1000)
2255 case PHY_INTERFACE_MODE_SGMII:
2256 case PHY_INTERFACE_MODE_2500BASEX:
2257 case PHY_INTERFACE_MODE_QSGMII:
2258 if (macro->speed >= SPEED_5000)
2261 case PHY_INTERFACE_MODE_10GBASER:
2262 if (macro->speed < SPEED_5000)
2271 static const struct phy_ops sparx5_serdes_ops = {
2272 .power_on = sparx5_serdes_power_on,
2273 .power_off = sparx5_serdes_power_off,
2274 .set_mode = sparx5_serdes_set_mode,
2275 .set_media = sparx5_serdes_set_media,
2276 .set_speed = sparx5_serdes_set_speed,
2277 .reset = sparx5_serdes_reset,
2278 .validate = sparx5_serdes_validate,
2279 .owner = THIS_MODULE,
2282 static int sparx5_phy_create(struct sparx5_serdes_private *priv,
2283 int idx, struct phy **phy)
2285 struct sparx5_serdes_macro *macro;
2287 *phy = devm_phy_create(priv->dev, NULL, &sparx5_serdes_ops);
2289 return PTR_ERR(*phy);
2291 macro = devm_kzalloc(priv->dev, sizeof(*macro), GFP_KERNEL);
2297 macro->speed = SPEED_UNKNOWN;
2298 if (idx < SPX5_SERDES_10G_START) {
2299 macro->serdestype = SPX5_SDT_6G;
2300 macro->stpidx = macro->sidx;
2301 } else if (idx < SPX5_SERDES_25G_START) {
2302 macro->serdestype = SPX5_SDT_10G;
2303 macro->stpidx = macro->sidx - SPX5_SERDES_10G_START;
2305 macro->serdestype = SPX5_SDT_25G;
2306 macro->stpidx = macro->sidx - SPX5_SERDES_25G_START;
2309 phy_set_drvdata(*phy, macro);
2314 static struct sparx5_serdes_io_resource sparx5_serdes_iomap[] = {
2315 { TARGET_SD_CMU, 0x0 }, /* 0x610808000: sd_cmu_0 */
2316 { TARGET_SD_CMU + 1, 0x8000 }, /* 0x610810000: sd_cmu_1 */
2317 { TARGET_SD_CMU + 2, 0x10000 }, /* 0x610818000: sd_cmu_2 */
2318 { TARGET_SD_CMU + 3, 0x18000 }, /* 0x610820000: sd_cmu_3 */
2319 { TARGET_SD_CMU + 4, 0x20000 }, /* 0x610828000: sd_cmu_4 */
2320 { TARGET_SD_CMU + 5, 0x28000 }, /* 0x610830000: sd_cmu_5 */
2321 { TARGET_SD_CMU + 6, 0x30000 }, /* 0x610838000: sd_cmu_6 */
2322 { TARGET_SD_CMU + 7, 0x38000 }, /* 0x610840000: sd_cmu_7 */
2323 { TARGET_SD_CMU + 8, 0x40000 }, /* 0x610848000: sd_cmu_8 */
2324 { TARGET_SD_CMU_CFG, 0x48000 }, /* 0x610850000: sd_cmu_cfg_0 */
2325 { TARGET_SD_CMU_CFG + 1, 0x50000 }, /* 0x610858000: sd_cmu_cfg_1 */
2326 { TARGET_SD_CMU_CFG + 2, 0x58000 }, /* 0x610860000: sd_cmu_cfg_2 */
2327 { TARGET_SD_CMU_CFG + 3, 0x60000 }, /* 0x610868000: sd_cmu_cfg_3 */
2328 { TARGET_SD_CMU_CFG + 4, 0x68000 }, /* 0x610870000: sd_cmu_cfg_4 */
2329 { TARGET_SD_CMU_CFG + 5, 0x70000 }, /* 0x610878000: sd_cmu_cfg_5 */
2330 { TARGET_SD_CMU_CFG + 6, 0x78000 }, /* 0x610880000: sd_cmu_cfg_6 */
2331 { TARGET_SD_CMU_CFG + 7, 0x80000 }, /* 0x610888000: sd_cmu_cfg_7 */
2332 { TARGET_SD_CMU_CFG + 8, 0x88000 }, /* 0x610890000: sd_cmu_cfg_8 */
2333 { TARGET_SD6G_LANE, 0x90000 }, /* 0x610898000: sd6g_lane_0 */
2334 { TARGET_SD6G_LANE + 1, 0x98000 }, /* 0x6108a0000: sd6g_lane_1 */
2335 { TARGET_SD6G_LANE + 2, 0xa0000 }, /* 0x6108a8000: sd6g_lane_2 */
2336 { TARGET_SD6G_LANE + 3, 0xa8000 }, /* 0x6108b0000: sd6g_lane_3 */
2337 { TARGET_SD6G_LANE + 4, 0xb0000 }, /* 0x6108b8000: sd6g_lane_4 */
2338 { TARGET_SD6G_LANE + 5, 0xb8000 }, /* 0x6108c0000: sd6g_lane_5 */
2339 { TARGET_SD6G_LANE + 6, 0xc0000 }, /* 0x6108c8000: sd6g_lane_6 */
2340 { TARGET_SD6G_LANE + 7, 0xc8000 }, /* 0x6108d0000: sd6g_lane_7 */
2341 { TARGET_SD6G_LANE + 8, 0xd0000 }, /* 0x6108d8000: sd6g_lane_8 */
2342 { TARGET_SD6G_LANE + 9, 0xd8000 }, /* 0x6108e0000: sd6g_lane_9 */
2343 { TARGET_SD6G_LANE + 10, 0xe0000 }, /* 0x6108e8000: sd6g_lane_10 */
2344 { TARGET_SD6G_LANE + 11, 0xe8000 }, /* 0x6108f0000: sd6g_lane_11 */
2345 { TARGET_SD6G_LANE + 12, 0xf0000 }, /* 0x6108f8000: sd6g_lane_12 */
2346 { TARGET_SD10G_LANE, 0xf8000 }, /* 0x610900000: sd10g_lane_0 */
2347 { TARGET_SD10G_LANE + 1, 0x100000 }, /* 0x610908000: sd10g_lane_1 */
2348 { TARGET_SD10G_LANE + 2, 0x108000 }, /* 0x610910000: sd10g_lane_2 */
2349 { TARGET_SD10G_LANE + 3, 0x110000 }, /* 0x610918000: sd10g_lane_3 */
2350 { TARGET_SD_LANE, 0x1a0000 }, /* 0x6109a8000: sd_lane_0 */
2351 { TARGET_SD_LANE + 1, 0x1a8000 }, /* 0x6109b0000: sd_lane_1 */
2352 { TARGET_SD_LANE + 2, 0x1b0000 }, /* 0x6109b8000: sd_lane_2 */
2353 { TARGET_SD_LANE + 3, 0x1b8000 }, /* 0x6109c0000: sd_lane_3 */
2354 { TARGET_SD_LANE + 4, 0x1c0000 }, /* 0x6109c8000: sd_lane_4 */
2355 { TARGET_SD_LANE + 5, 0x1c8000 }, /* 0x6109d0000: sd_lane_5 */
2356 { TARGET_SD_LANE + 6, 0x1d0000 }, /* 0x6109d8000: sd_lane_6 */
2357 { TARGET_SD_LANE + 7, 0x1d8000 }, /* 0x6109e0000: sd_lane_7 */
2358 { TARGET_SD_LANE + 8, 0x1e0000 }, /* 0x6109e8000: sd_lane_8 */
2359 { TARGET_SD_LANE + 9, 0x1e8000 }, /* 0x6109f0000: sd_lane_9 */
2360 { TARGET_SD_LANE + 10, 0x1f0000 }, /* 0x6109f8000: sd_lane_10 */
2361 { TARGET_SD_LANE + 11, 0x1f8000 }, /* 0x610a00000: sd_lane_11 */
2362 { TARGET_SD_LANE + 12, 0x200000 }, /* 0x610a08000: sd_lane_12 */
2363 { TARGET_SD_LANE + 13, 0x208000 }, /* 0x610a10000: sd_lane_13 */
2364 { TARGET_SD_LANE + 14, 0x210000 }, /* 0x610a18000: sd_lane_14 */
2365 { TARGET_SD_LANE + 15, 0x218000 }, /* 0x610a20000: sd_lane_15 */
2366 { TARGET_SD_LANE + 16, 0x220000 }, /* 0x610a28000: sd_lane_16 */
2367 { TARGET_SD_CMU + 9, 0x400000 }, /* 0x610c08000: sd_cmu_9 */
2368 { TARGET_SD_CMU + 10, 0x408000 }, /* 0x610c10000: sd_cmu_10 */
2369 { TARGET_SD_CMU + 11, 0x410000 }, /* 0x610c18000: sd_cmu_11 */
2370 { TARGET_SD_CMU + 12, 0x418000 }, /* 0x610c20000: sd_cmu_12 */
2371 { TARGET_SD_CMU + 13, 0x420000 }, /* 0x610c28000: sd_cmu_13 */
2372 { TARGET_SD_CMU_CFG + 9, 0x428000 }, /* 0x610c30000: sd_cmu_cfg_9 */
2373 { TARGET_SD_CMU_CFG + 10, 0x430000 }, /* 0x610c38000: sd_cmu_cfg_10 */
2374 { TARGET_SD_CMU_CFG + 11, 0x438000 }, /* 0x610c40000: sd_cmu_cfg_11 */
2375 { TARGET_SD_CMU_CFG + 12, 0x440000 }, /* 0x610c48000: sd_cmu_cfg_12 */
2376 { TARGET_SD_CMU_CFG + 13, 0x448000 }, /* 0x610c50000: sd_cmu_cfg_13 */
2377 { TARGET_SD10G_LANE + 4, 0x450000 }, /* 0x610c58000: sd10g_lane_4 */
2378 { TARGET_SD10G_LANE + 5, 0x458000 }, /* 0x610c60000: sd10g_lane_5 */
2379 { TARGET_SD10G_LANE + 6, 0x460000 }, /* 0x610c68000: sd10g_lane_6 */
2380 { TARGET_SD10G_LANE + 7, 0x468000 }, /* 0x610c70000: sd10g_lane_7 */
2381 { TARGET_SD10G_LANE + 8, 0x470000 }, /* 0x610c78000: sd10g_lane_8 */
2382 { TARGET_SD10G_LANE + 9, 0x478000 }, /* 0x610c80000: sd10g_lane_9 */
2383 { TARGET_SD10G_LANE + 10, 0x480000 }, /* 0x610c88000: sd10g_lane_10 */
2384 { TARGET_SD10G_LANE + 11, 0x488000 }, /* 0x610c90000: sd10g_lane_11 */
2385 { TARGET_SD25G_LANE, 0x490000 }, /* 0x610c98000: sd25g_lane_0 */
2386 { TARGET_SD25G_LANE + 1, 0x498000 }, /* 0x610ca0000: sd25g_lane_1 */
2387 { TARGET_SD25G_LANE + 2, 0x4a0000 }, /* 0x610ca8000: sd25g_lane_2 */
2388 { TARGET_SD25G_LANE + 3, 0x4a8000 }, /* 0x610cb0000: sd25g_lane_3 */
2389 { TARGET_SD25G_LANE + 4, 0x4b0000 }, /* 0x610cb8000: sd25g_lane_4 */
2390 { TARGET_SD25G_LANE + 5, 0x4b8000 }, /* 0x610cc0000: sd25g_lane_5 */
2391 { TARGET_SD25G_LANE + 6, 0x4c0000 }, /* 0x610cc8000: sd25g_lane_6 */
2392 { TARGET_SD25G_LANE + 7, 0x4c8000 }, /* 0x610cd0000: sd25g_lane_7 */
2393 { TARGET_SD_LANE + 17, 0x550000 }, /* 0x610d58000: sd_lane_17 */
2394 { TARGET_SD_LANE + 18, 0x558000 }, /* 0x610d60000: sd_lane_18 */
2395 { TARGET_SD_LANE + 19, 0x560000 }, /* 0x610d68000: sd_lane_19 */
2396 { TARGET_SD_LANE + 20, 0x568000 }, /* 0x610d70000: sd_lane_20 */
2397 { TARGET_SD_LANE + 21, 0x570000 }, /* 0x610d78000: sd_lane_21 */
2398 { TARGET_SD_LANE + 22, 0x578000 }, /* 0x610d80000: sd_lane_22 */
2399 { TARGET_SD_LANE + 23, 0x580000 }, /* 0x610d88000: sd_lane_23 */
2400 { TARGET_SD_LANE + 24, 0x588000 }, /* 0x610d90000: sd_lane_24 */
2401 { TARGET_SD_LANE_25G, 0x590000 }, /* 0x610d98000: sd_lane_25g_25 */
2402 { TARGET_SD_LANE_25G + 1, 0x598000 }, /* 0x610da0000: sd_lane_25g_26 */
2403 { TARGET_SD_LANE_25G + 2, 0x5a0000 }, /* 0x610da8000: sd_lane_25g_27 */
2404 { TARGET_SD_LANE_25G + 3, 0x5a8000 }, /* 0x610db0000: sd_lane_25g_28 */
2405 { TARGET_SD_LANE_25G + 4, 0x5b0000 }, /* 0x610db8000: sd_lane_25g_29 */
2406 { TARGET_SD_LANE_25G + 5, 0x5b8000 }, /* 0x610dc0000: sd_lane_25g_30 */
2407 { TARGET_SD_LANE_25G + 6, 0x5c0000 }, /* 0x610dc8000: sd_lane_25g_31 */
2408 { TARGET_SD_LANE_25G + 7, 0x5c8000 }, /* 0x610dd0000: sd_lane_25g_32 */
2411 /* Client lookup function, uses serdes index */
2412 static struct phy *sparx5_serdes_xlate(struct device *dev,
2413 struct of_phandle_args *args)
2415 struct sparx5_serdes_private *priv = dev_get_drvdata(dev);
2419 if (args->args_count != 1)
2420 return ERR_PTR(-EINVAL);
2422 sidx = args->args[0];
2424 /* Check validity: ERR_PTR(-ENODEV) if not valid */
2425 for (idx = 0; idx < SPX5_SERDES_MAX; idx++) {
2426 struct sparx5_serdes_macro *macro =
2427 phy_get_drvdata(priv->phys[idx]);
2429 if (sidx != macro->sidx)
2432 return priv->phys[idx];
2434 return ERR_PTR(-ENODEV);
2437 static int sparx5_serdes_probe(struct platform_device *pdev)
2439 struct device_node *np = pdev->dev.of_node;
2440 struct sparx5_serdes_private *priv;
2441 struct phy_provider *provider;
2442 struct resource *iores;
2443 void __iomem *iomem;
2444 unsigned long clock;
2449 if (!np && !pdev->dev.platform_data)
2452 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
2456 platform_set_drvdata(pdev, priv);
2457 priv->dev = &pdev->dev;
2460 clk = devm_clk_get(priv->dev, NULL);
2462 dev_err(priv->dev, "Failed to get coreclock\n");
2463 return PTR_ERR(clk);
2465 clock = clk_get_rate(clk);
2467 dev_err(priv->dev, "Invalid coreclock %lu\n", clock);
2470 priv->coreclock = clock;
2472 iores = platform_get_resource(pdev, IORESOURCE_MEM, 0);
2474 dev_err(priv->dev, "Invalid resource\n");
2477 iomem = devm_ioremap(priv->dev, iores->start, resource_size(iores));
2479 dev_err(priv->dev, "Unable to get serdes registers: %s\n",
2483 for (idx = 0; idx < ARRAY_SIZE(sparx5_serdes_iomap); idx++) {
2484 struct sparx5_serdes_io_resource *iomap = &sparx5_serdes_iomap[idx];
2486 priv->regs[iomap->id] = iomem + iomap->offset;
2488 for (idx = 0; idx < SPX5_SERDES_MAX; idx++) {
2489 err = sparx5_phy_create(priv, idx, &priv->phys[idx]);
2494 provider = devm_of_phy_provider_register(priv->dev, sparx5_serdes_xlate);
2496 return PTR_ERR_OR_ZERO(provider);
2499 static const struct of_device_id sparx5_serdes_match[] = {
2500 { .compatible = "microchip,sparx5-serdes" },
2503 MODULE_DEVICE_TABLE(of, sparx5_serdes_match);
2505 static struct platform_driver sparx5_serdes_driver = {
2506 .probe = sparx5_serdes_probe,
2508 .name = "sparx5-serdes",
2509 .of_match_table = sparx5_serdes_match,
2513 module_platform_driver(sparx5_serdes_driver);
2515 MODULE_DESCRIPTION("Microchip Sparx5 switch serdes driver");
2517 MODULE_LICENSE("GPL v2");