@@ -38,20 +38,16 @@ static int mtk_pcs_config(struct phylink_pcs *pcs, unsigned int mode,
3838 const unsigned long * advertising ,
3939 bool permit_pause_to_mac )
4040{
41+ bool mode_changed = false, changed , use_an ;
4142 struct mtk_pcs * mpcs = pcs_to_mtk_pcs (pcs );
4243 unsigned int rgc3 , sgm_mode , bmcr ;
4344 int advertise , link_timer ;
44- bool changed , use_an ;
4545
4646 advertise = phylink_mii_c22_pcs_encode_advertisement (interface ,
4747 advertising );
4848 if (advertise < 0 )
4949 return advertise ;
5050
51- link_timer = phylink_get_link_timer_ns (interface );
52- if (link_timer < 0 )
53- return link_timer ;
54-
5551 /* Clearing IF_MODE_BIT0 switches the PCS to BASE-X mode, and
5652 * we assume that fixes it's speed at bitrate = line rate (in
5753 * other words, 1000Mbps or 2500Mbps).
@@ -77,13 +73,16 @@ static int mtk_pcs_config(struct phylink_pcs *pcs, unsigned int mode,
7773 }
7874
7975 if (use_an ) {
80- /* FIXME: Do we need to set AN_RESTART here? */
81- bmcr = SGMII_AN_RESTART | SGMII_AN_ENABLE ;
76+ bmcr = SGMII_AN_ENABLE ;
8277 } else {
8378 bmcr = 0 ;
8479 }
8580
8681 if (mpcs -> interface != interface ) {
82+ link_timer = phylink_get_link_timer_ns (interface );
83+ if (link_timer < 0 )
84+ return link_timer ;
85+
8786 /* PHYA power down */
8887 regmap_update_bits (mpcs -> regmap , SGMSYS_QPHY_PWR_STATE_CTRL ,
8988 SGMII_PHYA_PWD , SGMII_PHYA_PWD );
@@ -101,24 +100,25 @@ static int mtk_pcs_config(struct phylink_pcs *pcs, unsigned int mode,
101100 regmap_update_bits (mpcs -> regmap , mpcs -> ana_rgc3 ,
102101 RG_PHY_SPEED_3_125G , rgc3 );
103102
103+ /* Setup the link timer */
104+ regmap_write (mpcs -> regmap , SGMSYS_PCS_LINK_TIMER , link_timer / 2 / 8 );
105+
104106 mpcs -> interface = interface ;
107+ mode_changed = true;
105108 }
106109
107110 /* Update the advertisement, noting whether it has changed */
108111 regmap_update_bits_check (mpcs -> regmap , SGMSYS_PCS_ADVERTISE ,
109112 SGMII_ADVERTISE , advertise , & changed );
110113
111- /* Setup the link timer and QPHY power up inside SGMIISYS */
112- regmap_write (mpcs -> regmap , SGMSYS_PCS_LINK_TIMER , link_timer / 2 / 8 );
113-
114114 /* Update the sgmsys mode register */
115115 regmap_update_bits (mpcs -> regmap , SGMSYS_SGMII_MODE ,
116116 SGMII_REMOTE_FAULT_DIS | SGMII_SPEED_DUPLEX_AN |
117117 SGMII_IF_MODE_SGMII , sgm_mode );
118118
119119 /* Update the BMCR */
120120 regmap_update_bits (mpcs -> regmap , SGMSYS_PCS_CONTROL_1 ,
121- SGMII_AN_RESTART | SGMII_AN_ENABLE , bmcr );
121+ SGMII_AN_ENABLE , bmcr );
122122
123123 /* Release PHYA power down state
124124 * Only removing bit SGMII_PHYA_PWD isn't enough.
@@ -132,7 +132,7 @@ static int mtk_pcs_config(struct phylink_pcs *pcs, unsigned int mode,
132132 usleep_range (50 , 100 );
133133 regmap_write (mpcs -> regmap , SGMSYS_QPHY_PWR_STATE_CTRL , 0 );
134134
135- return changed ;
135+ return changed || mode_changed ;
136136}
137137
138138static void mtk_pcs_restart_an (struct phylink_pcs * pcs )
0 commit comments