Provide empty functions if OF_NET is not configured
Subsystems (7)
cover Provide empty functions if OF_NET is not configured
Provide empty functions for of_get_phy_mode() and of_get_mac_address() if OF_NET is not configured. Modify affected drivers to rely on the now available functions.
----------------------------------------------------------------
Guenter Roeck (5):
of_net.h: Provide dummy functions if OF_NET is not configured net/cadence/at91_ether: Simplify OF dependencies net/cadence/macb: Simplify OF dependencies net/freescale/fec: Simplify OF dependencies net/nxp/lpc_eth: Drop ifdef CONFIG_OF_NET
drivers/net/ethernet/cadence/at91_ether.c | 44 ++++------------------------- drivers/net/ethernet/cadence/macb.c | 43 ++++------------------------ drivers/net/ethernet/freescale/fec.c | 19 +------------ drivers/net/ethernet/nxp/lpc_eth.c | 2 -- include/linux/of_net.h | 10 +++++++ 5 files changed, 23 insertions(+), 95 deletions(-)
PATCH 1/5 of_net.h: Provide empty functions if OF_NET is not configured
of_get_mac_address() and of_get_phy_mode() are only provided if OF_NET is configured. While most callers check for the define, not all do, and those who do require #ifdef around the code. For those who don't, the missing check can result in errors such as
arch/powerpc/sysdev/tsi108_dev.c:107:3: error: implicit declaration of
function 'of_get_mac_address' [-Werror=implicit-function-declaration]arch/powerpc/sysdev/mv64x60_dev.c:253:2: error: implicit declaration of
function 'of_get_mac_address' [-Werror=implicit-function-declaration]
Provide empty functions if OF_NET is not configured. This is safe because all callers do check the return values.
--- include/linux/of_net.h | 10 ++++++++++ 1 file changed, 10 insertions(+)
include/linux/of_net.h +10 -0
@@ -11,6 +11,16 @@#include <linux/of.h> extern const int of_get_phy_mode (struct device_node *np);extern const void *of_get_mac_address (struct device_node *np); +#else +static inline const int of_get_phy_mode (struct device_node *np) +{ +return -ENODEV ; +} + +static inline const void *of_get_mac_address (struct device_node *np) +{ +return NULL ; +}#endif #endif /* __LINUX_OF_NET_H */
Signature · 1 line
1.7.9.7
PATCH 2/5 net/cadence/at91_ether: Simplify OF dependencies
In reply to Guenter RoeckWith of_get_mac_address() and of_get_phy_mode() now defined as dummy functions if OF_NET is not configured, it is no longer necessary to provide OF dependent functions as front-end. Also, the two functions depend on OF_NET, not on OF, so the conditional code was not correct anyway.
Drop the front-end functions and call of_get_mac_address() and of_get_phy_mode() directly instead.
--- drivers/net/ethernet/cadence/at91_ether.c | 44 ++++------------------------- 1 file changed, 6 insertions(+), 38 deletions(-)
drivers/net/ethernet/cadence/at91_ether.c +6 -38
@@ -303,42 +303,7 @@ static const struct of_device_id at91ether_dt_ids[] = { { .compatible = "cdns,emac" }, {/* sentinel */ } }; -MODULE_DEVICE_TABLE (of, at91ether_dt_ids); - -static int at91ether_get_phy_mode_dt (struct platform_device *pdev) -{ -struct device_node *np = pdev->dev.of_node; - -if (np) -return of_get_phy_mode (np); - -return -ENODEV ; -} - -static int at91ether_get_hwaddr_dt (struct macb *bp) -{ -struct device_node *np = bp->pdev->dev.of_node; - -if (np) { -const char *mac =of_get_mac_address (np); -if (mac) { -memcpy (bp->dev->dev_addr, mac,ETH_ALEN ); -return 0 ; - } - } - -return -ENODEV ; -} -#else -static int at91ether_get_phy_mode_dt (struct platform_device *pdev) -{ -return -ENODEV ; -} -static int at91ether_get_hwaddr_dt (struct macb *bp) -{ -return -ENODEV ; -}#endif /* Detect MAC & PHY and perform ethernet interface initialization */
@@ -352,6 +317,7 @@ static int __init at91ether_probe(struct platform_device *pdev)struct macb *lp;int res;u32 reg; +const char *mac; regs =platform_get_resource (pdev,IORESOURCE_MEM ,0 );if (!regs)
@@ -403,11 +369,13 @@ static int __init at91ether_probe(struct platform_device *pdev)platform_set_drvdata (pdev, dev);SET_NETDEV_DEV (dev, &pdev->dev); - res =at91ether_get_hwaddr_dt (lp); -if (res <0 ) + mac =of_get_mac_address (pdev->dev.of_node); +if (mac) +memcpy (lp->dev->dev_addr, mac,ETH_ALEN ); +else macb_get_hwaddr (lp); - res =at91ether_get_phy_mode_dt (pdev); + res =of_get_phy_mode (pdev->dev.of_node);if (res <0 ) {if (board_data && board_data->is_rmii) lp->phy_interface =PHY_INTERFACE_MODE_RMII ;
Signature · 1 line
1.7.9.7
PATCH 3/5 net/cadence/macb: Simplify OF dependencies
In reply to Guenter RoeckWith of_get_mac_address() and of_get_phy_mode() now defined as dummy functions if OF_NET is not configured, it is no longer necessary to provide OF dependent functions as front-end. Also, the two functions depend on OF_NET, not on OF, so the conditional code was not correct anyway.
Drop the front-end functions and call of_get_mac_address() and of_get_phy_mode() directly instead.
--- drivers/net/ethernet/cadence/macb.c | 43 +++++------------------------------ 1 file changed, 6 insertions(+), 37 deletions(-)
drivers/net/ethernet/cadence/macb.c +6 -37
@@ -1472,41 +1472,7 @@ static const struct of_device_id macb_dt_ids[] = { { .compatible = "cdns,gem" }, {/* sentinel */ } }; -MODULE_DEVICE_TABLE (of, macb_dt_ids); - -static int macb_get_phy_mode_dt (struct platform_device *pdev) -{ -struct device_node *np = pdev->dev.of_node; - -if (np) -return of_get_phy_mode (np); - -return -ENODEV ; -} - -static int macb_get_hwaddr_dt (struct macb *bp) -{ -struct device_node *np = bp->pdev->dev.of_node; -if (np) { -const char *mac =of_get_mac_address (np); -if (mac) { -memcpy (bp->dev->dev_addr, mac,ETH_ALEN ); -return 0 ; - } - } - -return -ENODEV ; -} -#else -static int macb_get_phy_mode_dt (struct platform_device *pdev) -{ -return -ENODEV ; -} -static int macb_get_hwaddr_dt (struct macb *bp) -{ -return -ENODEV ; -}#endif static int __init macb_probe (struct platform_device *pdev)
@@ -1519,6 +1485,7 @@ static int __init macb_probe(struct platform_device *pdev)u32 config;int err = -ENXIO ;struct pinctrl *pinctrl; +const char *mac; regs =platform_get_resource (pdev,IORESOURCE_MEM ,0 );if (!regs) {
@@ -1592,11 +1559,13 @@ static int __init macb_probe(struct platform_device *pdev) config |=macb_dbw (bp);macb_writel (bp,NCFGR , config); - err =macb_get_hwaddr_dt (bp); -if (err <0 ) + mac =of_get_mac_address (pdev->dev.of_node); +if (mac) +memcpy (bp->dev->dev_addr, mac,ETH_ALEN ); +else macb_get_hwaddr (bp); - err =macb_get_phy_mode_dt (pdev); + err =of_get_phy_mode (pdev->dev.of_node);if (err <0 ) { pdata = pdev->dev.platform_data;if (pdata && pdata->is_rmii)
Signature · 1 line
1.7.9.7
PATCH 4/5 net/freescale/fec: Simplify OF dependencies
In reply to Guenter RoeckSince of_get_mac_address() is now defined even if CONFIG_OF_NET is not configured, the ifdef around the code calling it is no longer necessary and can be removed.
Similar, since of_get_phy_mode() is now defined as dummy function if OF_NET is not configured, it is no longer necessary to provide an OF dependent function as front-end. Also, the function depends on OF_NET, not on OF, so the conditional code was not correct anyway. Drop the front-end function and call of_get_phy_mode() directly.
--- drivers/net/ethernet/freescale/fec.c | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-)
drivers/net/ethernet/freescale/fec.c +1 -18
@@ -868,7 +868,6 @@ static void fec_get_mac(struct net_device *ndev)*/ iap = macaddr; -#ifdef CONFIG_OF /* * 2) from device tree data */
@@ -880,7 +879,6 @@ static void fec_get_mac(struct net_device *ndev) iap = (unsigned char *) mac; } } -#endif /* * 3) from flash or fuse (via platform data)
@@ -1666,16 +1664,6 @@ static int fec_enet_init(struct net_device *ndev) }#ifdef CONFIG_OF -static int fec_get_phy_mode_dt (struct platform_device *pdev) -{ -struct device_node *np = pdev->dev.of_node; - -if (np) -return of_get_phy_mode (np); - -return -ENODEV ; -} -static void fec_reset_phy (struct platform_device *pdev) {int err, phy_reset;
@@ -1704,11 +1692,6 @@ static void fec_reset_phy(struct platform_device *pdev) gpio_set_value(phy_reset, 1); }#else /* CONFIG_OF */ -static int fec_get_phy_mode_dt (struct platform_device *pdev) -{ -return -ENODEV ; -} -static void fec_reset_phy (struct platform_device *pdev) {/*
@@ -1773,7 +1756,7 @@ fec_probe(struct platform_device *pdev)platform_set_drvdata (pdev, ndev); - ret =fec_get_phy_mode_dt (pdev); + ret =of_get_phy_mode (pdev->dev.of_node);if (ret <0 ) { pdata = pdev->dev.platform_data;if (pdata)
Signature · 1 line
1.7.9.7
PATCH 5/5 net/nxp/lpc_eth: Drop ifdef CONFIG_OF_NET
In reply to Guenter RoeckSince of_get_mac_address() is now declared even if CONFIG_OF_NET is not configured, the ifdef is no longer necessary and can be removed.
--- drivers/net/ethernet/nxp/lpc_eth.c | 2 -- 1 file changed, 2 deletions(-)
drivers/net/ethernet/nxp/lpc_eth.c +0 -2
@@ -1434,13 +1434,11 @@ static int lpc_eth_drv_probe(struct platform_device *pdev)/* Get MAC address from current HW setting (POR state is all zeros) */ __lpc_get_mac (pldat, ndev->dev_addr); -#ifdef CONFIG_OF_NET if (!is_valid_ether_addr (ndev->dev_addr)) {const char *macaddr =of_get_mac_address (pdev->dev.of_node);if (macaddr)memcpy (ndev->dev_addr, macaddr,ETH_ALEN ); } -#endif if (!is_valid_ether_addr (ndev->dev_addr))eth_hw_addr_random (ndev);
Signature · 1 line
1.7.9.7
David Miller
maintainerFrom: Guenter Roeck <[email protected]>
Date: Tue, 2 Apr 2013 12:35:06 -0700
Quoted 3 lines
Provide empty functions for
of_get_phy_mode()andof_get_mac_address()ifOF_NETis not configured. Modify affected drivers to rely on the now available functions.
All applied, but please post your patches against the appropriate tree.
In net-next, fec.c has been renamed to fec_main.c so I had to adjust your patch so that it would apply correctly.