1111#include <linux/interrupt.h>
1212#include <linux/io.h>
1313#include <linux/iopoll.h>
14+ #include <linux/mfd/syscon.h>
1415#include <linux/mii.h>
1516#include <linux/module.h>
1617#include <linux/netdevice.h>
1718#include <linux/of_net.h>
1819#include <linux/of_mdio.h>
1920#include <linux/of_platform.h>
2021#include <linux/phy.h>
22+ #include <linux/regmap.h>
2123#include <linux/reset.h>
2224#include <linux/types.h>
2325#include <linux/u64_stats_sync.h>
197199#define AVE_INTM_COUNT 20
198200#define AVE_FORCE_TXINTCNT 1
199201
202+ /* SG */
203+ #define SG_ETPINMODE 0x540
204+ #define SG_ETPINMODE_EXTPHY BIT(1) /* for LD11 */
205+ #define SG_ETPINMODE_RMII (ins ) BIT(ins)
206+
200207#define IS_DESC_64BIT (p ) ((p)->data->is_desc_64bit)
201208
202209#define AVE_MAX_CLKS 4
@@ -228,12 +235,6 @@ struct ave_desc_info {
228235 struct ave_desc * desc ; /* skb info related descriptor */
229236};
230237
231- struct ave_soc_data {
232- bool is_desc_64bit ;
233- const char * clock_names [AVE_MAX_CLKS ];
234- const char * reset_names [AVE_MAX_RSTS ];
235- };
236-
237238struct ave_stats {
238239 struct u64_stats_sync syncp ;
239240 u64 packets ;
@@ -257,6 +258,9 @@ struct ave_private {
257258 phy_interface_t phy_mode ;
258259 struct phy_device * phydev ;
259260 struct mii_bus * mdio ;
261+ struct regmap * regmap ;
262+ unsigned int pinmode_mask ;
263+ unsigned int pinmode_val ;
260264
261265 /* stats */
262266 struct ave_stats stats_rx ;
@@ -279,6 +283,14 @@ struct ave_private {
279283 const struct ave_soc_data * data ;
280284};
281285
286+ struct ave_soc_data {
287+ bool is_desc_64bit ;
288+ const char * clock_names [AVE_MAX_CLKS ];
289+ const char * reset_names [AVE_MAX_RSTS ];
290+ int (* get_pinmode )(struct ave_private * priv ,
291+ phy_interface_t phy_mode , u32 arg );
292+ };
293+
282294static u32 ave_desc_read (struct net_device * ndev , enum desc_id id , int entry ,
283295 int offset )
284296{
@@ -1179,6 +1191,11 @@ static int ave_init(struct net_device *ndev)
11791191 }
11801192 }
11811193
1194+ ret = regmap_update_bits (priv -> regmap , SG_ETPINMODE ,
1195+ priv -> pinmode_mask , priv -> pinmode_val );
1196+ if (ret )
1197+ return ret ;
1198+
11821199 ave_global_reset (ndev );
11831200
11841201 mdio_np = of_get_child_by_name (np , "mdio" );
@@ -1537,6 +1554,7 @@ static int ave_probe(struct platform_device *pdev)
15371554 const struct ave_soc_data * data ;
15381555 struct device * dev = & pdev -> dev ;
15391556 char buf [ETHTOOL_FWVERS_LEN ];
1557+ struct of_phandle_args args ;
15401558 phy_interface_t phy_mode ;
15411559 struct ave_private * priv ;
15421560 struct net_device * ndev ;
@@ -1559,12 +1577,6 @@ static int ave_probe(struct platform_device *pdev)
15591577 dev_err (dev , "phy-mode not found\n" );
15601578 return - EINVAL ;
15611579 }
1562- if ((!phy_interface_mode_is_rgmii (phy_mode )) &&
1563- phy_mode != PHY_INTERFACE_MODE_RMII &&
1564- phy_mode != PHY_INTERFACE_MODE_MII ) {
1565- dev_err (dev , "phy-mode is invalid\n" );
1566- return - EINVAL ;
1567- }
15681580
15691581 irq = platform_get_irq (pdev , 0 );
15701582 if (irq < 0 ) {
@@ -1656,6 +1668,26 @@ static int ave_probe(struct platform_device *pdev)
16561668 priv -> nrsts ++ ;
16571669 }
16581670
1671+ ret = of_parse_phandle_with_fixed_args (np ,
1672+ "socionext,syscon-phy-mode" ,
1673+ 1 , 0 , & args );
1674+ if (ret ) {
1675+ netdev_err (ndev , "can't get syscon-phy-mode property\n" );
1676+ goto out_free_netdev ;
1677+ }
1678+ priv -> regmap = syscon_node_to_regmap (args .np );
1679+ of_node_put (args .np );
1680+ if (IS_ERR (priv -> regmap )) {
1681+ netdev_err (ndev , "can't map syscon-phy-mode\n" );
1682+ ret = PTR_ERR (priv -> regmap );
1683+ goto out_free_netdev ;
1684+ }
1685+ ret = priv -> data -> get_pinmode (priv , phy_mode , args .args [0 ]);
1686+ if (ret ) {
1687+ netdev_err (ndev , "invalid phy-mode setting\n" );
1688+ goto out_free_netdev ;
1689+ }
1690+
16591691 priv -> mdio = devm_mdiobus_alloc (dev );
16601692 if (!priv -> mdio ) {
16611693 ret = - ENOMEM ;
@@ -1715,6 +1747,95 @@ static int ave_remove(struct platform_device *pdev)
17151747 return 0 ;
17161748}
17171749
1750+ static int ave_pro4_get_pinmode (struct ave_private * priv ,
1751+ phy_interface_t phy_mode , u32 arg )
1752+ {
1753+ if (arg > 0 )
1754+ return - EINVAL ;
1755+
1756+ priv -> pinmode_mask = SG_ETPINMODE_RMII (0 );
1757+
1758+ switch (phy_mode ) {
1759+ case PHY_INTERFACE_MODE_RMII :
1760+ priv -> pinmode_val = SG_ETPINMODE_RMII (0 );
1761+ break ;
1762+ case PHY_INTERFACE_MODE_MII :
1763+ case PHY_INTERFACE_MODE_RGMII :
1764+ priv -> pinmode_val = 0 ;
1765+ break ;
1766+ default :
1767+ return - EINVAL ;
1768+ }
1769+
1770+ return 0 ;
1771+ }
1772+
1773+ static int ave_ld11_get_pinmode (struct ave_private * priv ,
1774+ phy_interface_t phy_mode , u32 arg )
1775+ {
1776+ if (arg > 0 )
1777+ return - EINVAL ;
1778+
1779+ priv -> pinmode_mask = SG_ETPINMODE_EXTPHY | SG_ETPINMODE_RMII (0 );
1780+
1781+ switch (phy_mode ) {
1782+ case PHY_INTERFACE_MODE_INTERNAL :
1783+ priv -> pinmode_val = 0 ;
1784+ break ;
1785+ case PHY_INTERFACE_MODE_RMII :
1786+ priv -> pinmode_val = SG_ETPINMODE_EXTPHY | SG_ETPINMODE_RMII (0 );
1787+ break ;
1788+ default :
1789+ return - EINVAL ;
1790+ }
1791+
1792+ return 0 ;
1793+ }
1794+
1795+ static int ave_ld20_get_pinmode (struct ave_private * priv ,
1796+ phy_interface_t phy_mode , u32 arg )
1797+ {
1798+ if (arg > 0 )
1799+ return - EINVAL ;
1800+
1801+ priv -> pinmode_mask = SG_ETPINMODE_RMII (0 );
1802+
1803+ switch (phy_mode ) {
1804+ case PHY_INTERFACE_MODE_RMII :
1805+ priv -> pinmode_val = SG_ETPINMODE_RMII (0 );
1806+ break ;
1807+ case PHY_INTERFACE_MODE_RGMII :
1808+ priv -> pinmode_val = 0 ;
1809+ break ;
1810+ default :
1811+ return - EINVAL ;
1812+ }
1813+
1814+ return 0 ;
1815+ }
1816+
1817+ static int ave_pxs3_get_pinmode (struct ave_private * priv ,
1818+ phy_interface_t phy_mode , u32 arg )
1819+ {
1820+ if (arg > 1 )
1821+ return - EINVAL ;
1822+
1823+ priv -> pinmode_mask = SG_ETPINMODE_RMII (arg );
1824+
1825+ switch (phy_mode ) {
1826+ case PHY_INTERFACE_MODE_RMII :
1827+ priv -> pinmode_val = SG_ETPINMODE_RMII (arg );
1828+ break ;
1829+ case PHY_INTERFACE_MODE_RGMII :
1830+ priv -> pinmode_val = 0 ;
1831+ break ;
1832+ default :
1833+ return - EINVAL ;
1834+ }
1835+
1836+ return 0 ;
1837+ }
1838+
17181839static const struct ave_soc_data ave_pro4_data = {
17191840 .is_desc_64bit = false,
17201841 .clock_names = {
@@ -1723,6 +1844,7 @@ static const struct ave_soc_data ave_pro4_data = {
17231844 .reset_names = {
17241845 "gio" , "ether" ,
17251846 },
1847+ .get_pinmode = ave_pro4_get_pinmode ,
17261848};
17271849
17281850static const struct ave_soc_data ave_pxs2_data = {
@@ -1733,6 +1855,7 @@ static const struct ave_soc_data ave_pxs2_data = {
17331855 .reset_names = {
17341856 "ether" ,
17351857 },
1858+ .get_pinmode = ave_pro4_get_pinmode ,
17361859};
17371860
17381861static const struct ave_soc_data ave_ld11_data = {
@@ -1743,6 +1866,7 @@ static const struct ave_soc_data ave_ld11_data = {
17431866 .reset_names = {
17441867 "ether" ,
17451868 },
1869+ .get_pinmode = ave_ld11_get_pinmode ,
17461870};
17471871
17481872static const struct ave_soc_data ave_ld20_data = {
@@ -1753,6 +1877,7 @@ static const struct ave_soc_data ave_ld20_data = {
17531877 .reset_names = {
17541878 "ether" ,
17551879 },
1880+ .get_pinmode = ave_ld20_get_pinmode ,
17561881};
17571882
17581883static const struct ave_soc_data ave_pxs3_data = {
@@ -1763,6 +1888,7 @@ static const struct ave_soc_data ave_pxs3_data = {
17631888 .reset_names = {
17641889 "ether" ,
17651890 },
1891+ .get_pinmode = ave_pxs3_get_pinmode ,
17661892};
17671893
17681894static const struct of_device_id of_ave_match [] = {
0 commit comments