1212#include <linux/mii.h>
1313#include <linux/phy.h>
1414#include <linux/of.h>
15- #include <dt-bindings/net/mscc-phy-vsc8531.h>
1615#include <linux/netdevice.h>
1716
1817enum rgmii_rx_clock_delay {
@@ -69,23 +68,29 @@ enum rgmii_rx_clock_delay {
6968#define PHY_ID_VSC8531 0x00070570
7069#define PHY_ID_VSC8541 0x00070770
7170
72- struct edge_rate_table {
73- u16 vddmac ;
74- int slowdown [ MSCC_SLOWDOWN_MAX ];
75- };
71+ #define MSCC_VDDMAC_1500 1500
72+ #define MSCC_VDDMAC_1800 1800
73+ #define MSCC_VDDMAC_2500 2500
74+ #define MSCC_VDDMAC_3300 3300
7675
77- struct edge_rate_table edge_table [MSCC_VDDMAC_MAX ] = {
78- {3300 , { 0 , -2 , -4 , -7 , -10 , -17 , -29 , -53 } },
79- {2500 , { 0 , -3 , -6 , -10 , -14 , -23 , -37 , -63 } },
80- {1800 , { 0 , -5 , -9 , -16 , -23 , -35 , -52 , -76 } },
81- {1500 , { 0 , -6 , -14 , -21 , -29 , -42 , -58 , -77 } },
76+ struct vsc8531_private {
77+ int rate_magic ;
8278};
8379
84- struct vsc8531_private {
85- u8 edge_slowdown ;
80+ #ifdef CONFIG_OF_MDIO
81+ struct vsc8531_edge_rate_table {
8682 u16 vddmac ;
83+ u8 slowdown [8 ];
8784};
8885
86+ static const struct vsc8531_edge_rate_table edge_table [] = {
87+ {MSCC_VDDMAC_3300 , { 0 , 2 , 4 , 7 , 10 , 17 , 29 , 53 } },
88+ {MSCC_VDDMAC_2500 , { 0 , 3 , 6 , 10 , 14 , 23 , 37 , 63 } },
89+ {MSCC_VDDMAC_1800 , { 0 , 5 , 9 , 16 , 23 , 35 , 52 , 76 } },
90+ {MSCC_VDDMAC_1500 , { 0 , 6 , 14 , 21 , 29 , 42 , 58 , 77 } },
91+ };
92+ #endif /* CONFIG_OF_MDIO */
93+
8994static int vsc85xx_phy_page_set (struct phy_device * phydev , u8 page )
9095{
9196 int rc ;
@@ -205,29 +210,43 @@ static void vsc85xx_wol_get(struct phy_device *phydev,
205210 mutex_unlock (& phydev -> lock );
206211}
207212
208- static u8 edge_rate_magic_get ( u16 vddmac ,
209- int slowdown )
213+ #ifdef CONFIG_OF_MDIO
214+ static int vsc85xx_edge_rate_magic_get ( struct phy_device * phydev )
210215{
211- int rc = (MSCC_SLOWDOWN_MAX - 1 );
212- u8 vdd ;
213216 u8 sd ;
217+ u16 vdd ;
218+ int rc , i , j ;
219+ struct device * dev = & phydev -> mdio .dev ;
220+ struct device_node * of_node = dev -> of_node ;
221+ u8 sd_array_size = ARRAY_SIZE (edge_table [0 ].slowdown );
214222
215- for (vdd = 0 ; vdd < MSCC_VDDMAC_MAX ; vdd ++ ) {
216- if (edge_table [vdd ].vddmac == vddmac ) {
217- for (sd = 0 ; sd < MSCC_SLOWDOWN_MAX ; sd ++ ) {
218- if (edge_table [vdd ].slowdown [sd ] <= slowdown ) {
219- rc = (MSCC_SLOWDOWN_MAX - sd - 1 );
220- break ;
221- }
222- }
223- }
224- }
223+ if (!of_node )
224+ return - ENODEV ;
225225
226- return rc ;
226+ rc = of_property_read_u16 (of_node , "vsc8531,vddmac" , & vdd );
227+ if (rc != 0 )
228+ vdd = MSCC_VDDMAC_3300 ;
229+
230+ rc = of_property_read_u8 (of_node , "vsc8531,edge-slowdown" , & sd );
231+ if (rc != 0 )
232+ sd = 0 ;
233+
234+ for (i = 0 ; i < ARRAY_SIZE (edge_table ); i ++ )
235+ if (edge_table [i ].vddmac == vdd )
236+ for (j = 0 ; j < sd_array_size ; j ++ )
237+ if (edge_table [i ].slowdown [j ] == sd )
238+ return (sd_array_size - j - 1 );
239+
240+ return - EINVAL ;
241+ }
242+ #else
243+ static int vsc85xx_edge_rate_magic_get (struct phy_device * phydev )
244+ {
245+ return 0 ;
227246}
247+ #endif /* CONFIG_OF_MDIO */
228248
229- static int vsc85xx_edge_rate_cntl_set (struct phy_device * phydev ,
230- u8 edge_rate )
249+ static int vsc85xx_edge_rate_cntl_set (struct phy_device * phydev , u8 edge_rate )
231250{
232251 int rc ;
233252 u16 reg_val ;
@@ -308,45 +327,10 @@ static int vsc85xx_default_config(struct phy_device *phydev)
308327 return rc ;
309328}
310329
311- #ifdef CONFIG_OF_MDIO
312- static int vsc8531_of_init (struct phy_device * phydev )
313- {
314- int rc ;
315- struct vsc8531_private * vsc8531 = phydev -> priv ;
316- struct device * dev = & phydev -> mdio .dev ;
317- struct device_node * of_node = dev -> of_node ;
318-
319- if (!of_node )
320- return - ENODEV ;
321-
322- rc = of_property_read_u16 (of_node , "vsc8531,vddmac" ,
323- & vsc8531 -> vddmac );
324- if (rc == - EINVAL )
325- vsc8531 -> vddmac = MSCC_VDDMAC_3300 ;
326- rc = of_property_read_u8 (of_node , "vsc8531,edge-slowdown" ,
327- & vsc8531 -> edge_slowdown );
328- if (rc == - EINVAL )
329- vsc8531 -> edge_slowdown = 0 ;
330-
331- rc = 0 ;
332- return rc ;
333- }
334- #else
335- static int vsc8531_of_init (struct phy_device * phydev )
336- {
337- return 0 ;
338- }
339- #endif /* CONFIG_OF_MDIO */
340-
341330static int vsc85xx_config_init (struct phy_device * phydev )
342331{
343332 int rc ;
344333 struct vsc8531_private * vsc8531 = phydev -> priv ;
345- u8 edge_rate ;
346-
347- rc = vsc8531_of_init (phydev );
348- if (rc )
349- return rc ;
350334
351335 rc = vsc85xx_default_config (phydev );
352336 if (rc )
@@ -356,9 +340,7 @@ static int vsc85xx_config_init(struct phy_device *phydev)
356340 if (rc )
357341 return rc ;
358342
359- edge_rate = edge_rate_magic_get (vsc8531 -> vddmac ,
360- - (int )vsc8531 -> edge_slowdown );
361- rc = vsc85xx_edge_rate_cntl_set (phydev , edge_rate );
343+ rc = vsc85xx_edge_rate_cntl_set (phydev , vsc8531 -> rate_magic );
362344 if (rc )
363345 return rc ;
364346
@@ -396,14 +378,21 @@ static int vsc85xx_config_intr(struct phy_device *phydev)
396378
397379static int vsc85xx_probe (struct phy_device * phydev )
398380{
381+ int rate_magic ;
399382 struct vsc8531_private * vsc8531 ;
400383
384+ rate_magic = vsc85xx_edge_rate_magic_get (phydev );
385+ if (rate_magic < 0 )
386+ return rate_magic ;
387+
401388 vsc8531 = devm_kzalloc (& phydev -> mdio .dev , sizeof (* vsc8531 ), GFP_KERNEL );
402389 if (!vsc8531 )
403390 return - ENOMEM ;
404391
405392 phydev -> priv = vsc8531 ;
406393
394+ vsc8531 -> rate_magic = rate_magic ;
395+
407396 return 0 ;
408397}
409398
@@ -424,9 +413,9 @@ static struct phy_driver vsc85xx_driver[] = {
424413 .config_intr = & vsc85xx_config_intr ,
425414 .suspend = & genphy_suspend ,
426415 .resume = & genphy_resume ,
427- .probe = & vsc85xx_probe ,
428- .set_wol = & vsc85xx_wol_set ,
429- .get_wol = & vsc85xx_wol_get ,
416+ .probe = & vsc85xx_probe ,
417+ .set_wol = & vsc85xx_wol_set ,
418+ .get_wol = & vsc85xx_wol_get ,
430419},
431420{
432421 .phy_id = PHY_ID_VSC8541 ,
@@ -443,9 +432,9 @@ static struct phy_driver vsc85xx_driver[] = {
443432 .config_intr = & vsc85xx_config_intr ,
444433 .suspend = & genphy_suspend ,
445434 .resume = & genphy_resume ,
446- .probe = & vsc85xx_probe ,
447- .set_wol = & vsc85xx_wol_set ,
448- .get_wol = & vsc85xx_wol_get ,
435+ .probe = & vsc85xx_probe ,
436+ .set_wol = & vsc85xx_wol_set ,
437+ .get_wol = & vsc85xx_wol_get ,
449438}
450439
451440};
0 commit comments