@@ -2042,6 +2042,34 @@ static int fec_enet_clk_enable(struct net_device *ndev, bool enable)
20422042 return ret ;
20432043}
20442044
2045+ static int fec_enet_parse_rgmii_delay (struct fec_enet_private * fep ,
2046+ struct device_node * np )
2047+ {
2048+ u32 rgmii_tx_delay , rgmii_rx_delay ;
2049+
2050+ /* For rgmii tx internal delay, valid values are 0ps and 2000ps */
2051+ if (!of_property_read_u32 (np , "tx-internal-delay-ps" , & rgmii_tx_delay )) {
2052+ if (rgmii_tx_delay != 0 && rgmii_tx_delay != 2000 ) {
2053+ dev_err (& fep -> pdev -> dev , "The only allowed RGMII TX delay values are: 0ps, 2000ps" );
2054+ return - EINVAL ;
2055+ } else if (rgmii_tx_delay == 2000 ) {
2056+ fep -> rgmii_txc_dly = true;
2057+ }
2058+ }
2059+
2060+ /* For rgmii rx internal delay, valid values are 0ps and 2000ps */
2061+ if (!of_property_read_u32 (np , "rx-internal-delay-ps" , & rgmii_rx_delay )) {
2062+ if (rgmii_rx_delay != 0 && rgmii_rx_delay != 2000 ) {
2063+ dev_err (& fep -> pdev -> dev , "The only allowed RGMII RX delay values are: 0ps, 2000ps" );
2064+ return - EINVAL ;
2065+ } else if (rgmii_rx_delay == 2000 ) {
2066+ fep -> rgmii_rxc_dly = true;
2067+ }
2068+ }
2069+
2070+ return 0 ;
2071+ }
2072+
20452073static int fec_enet_mii_probe (struct net_device * ndev )
20462074{
20472075 struct fec_enet_private * fep = netdev_priv (ndev );
@@ -3719,7 +3747,6 @@ fec_probe(struct platform_device *pdev)
37193747 char irq_name [8 ];
37203748 int irq_cnt ;
37213749 struct fec_devinfo * dev_info ;
3722- u32 rgmii_delay ;
37233750
37243751 fec_enet_get_queue_num (pdev , & num_tx_qs , & num_rx_qs );
37253752
@@ -3777,12 +3804,6 @@ fec_probe(struct platform_device *pdev)
37773804 if (ret )
37783805 goto failed_stop_mode ;
37793806
3780- /* For rgmii internal delay, valid values are 0ps and 2000ps */
3781- if (of_property_read_u32 (np , "tx-internal-delay-ps" , & rgmii_delay ))
3782- fep -> rgmii_txc_dly = true;
3783- if (of_property_read_u32 (np , "rx-internal-delay-ps" , & rgmii_delay ))
3784- fep -> rgmii_rxc_dly = true;
3785-
37863807 phy_node = of_parse_phandle (np , "phy-handle" , 0 );
37873808 if (!phy_node && of_phy_is_fixed_link (np )) {
37883809 ret = of_phy_register_fixed_link (np );
@@ -3806,6 +3827,10 @@ fec_probe(struct platform_device *pdev)
38063827 fep -> phy_interface = interface ;
38073828 }
38083829
3830+ ret = fec_enet_parse_rgmii_delay (fep , np );
3831+ if (ret )
3832+ goto failed_rgmii_delay ;
3833+
38093834 fep -> clk_ipg = devm_clk_get (& pdev -> dev , "ipg" );
38103835 if (IS_ERR (fep -> clk_ipg )) {
38113836 ret = PTR_ERR (fep -> clk_ipg );
@@ -3835,9 +3860,11 @@ fec_probe(struct platform_device *pdev)
38353860 fep -> clk_ref_rate = clk_get_rate (fep -> clk_ref );
38363861
38373862 /* clk_2x_txclk is optional, depends on board */
3838- fep -> clk_2x_txclk = devm_clk_get (& pdev -> dev , "enet_2x_txclk" );
3839- if (IS_ERR (fep -> clk_2x_txclk ))
3840- fep -> clk_2x_txclk = NULL ;
3863+ if (fep -> rgmii_txc_dly || fep -> rgmii_rxc_dly ) {
3864+ fep -> clk_2x_txclk = devm_clk_get (& pdev -> dev , "enet_2x_txclk" );
3865+ if (IS_ERR (fep -> clk_2x_txclk ))
3866+ fep -> clk_2x_txclk = NULL ;
3867+ }
38413868
38423869 fep -> bufdesc_ex = fep -> quirks & FEC_QUIRK_HAS_BUFDESC_EX ;
38433870 fep -> clk_ptp = devm_clk_get (& pdev -> dev , "ptp" );
@@ -3955,6 +3982,7 @@ fec_probe(struct platform_device *pdev)
39553982failed_clk_ipg :
39563983 fec_enet_clk_enable (ndev , false);
39573984failed_clk :
3985+ failed_rgmii_delay :
39583986 if (of_phy_is_fixed_link (np ))
39593987 of_phy_deregister_fixed_link (np );
39603988 of_node_put (phy_node );
0 commit comments