[PATCH] [RFC] move ethernet PHY config into drivers/phy/Kconfig

From: Arnd Bergmann
Date: Wed Apr 27 2016 - 05:51:18 EST


Calling mdiobus_register_board_info from builtin code with CONFIG_PHYLIB=m
currently results in a link error:

arch/arm/plat-orion/common.o: In function `orion_ge00_switch_init':
common.c:(.init.text+0x6a4): undefined reference to `mdiobus_register_board_info'

As the long-term strategy is to separate mdio from phylib, and to get generic-phy
and (networking-only) phylib closer together, this performs a first step in that
direction: The Kconfig file for phylib gets logically pulled under the PHY
driver configuration and becomes independent from networking. This lets us
select the new CONFIG_MDIO_BOARDINFO from platforms that need it, and provide
the functions exactly when we need them.

In the same step, we can also split out the MDIO driver configuration from
phylib. This is based on an older experimental patch I had, but it still
requires some code changes in phylib itself to let users actually rely on
MDIO without all of PHYLIB.

Signed-off-by: Arnd Bergmann <arnd@xxxxxxxx>

diff --git a/arch/arm/mach-orion5x/Kconfig b/arch/arm/mach-orion5x/Kconfig
index 468b8cb7fd5f..e1126e1aa3d2 100644
--- a/arch/arm/mach-orion5x/Kconfig
+++ b/arch/arm/mach-orion5x/Kconfig
@@ -4,6 +4,7 @@ menuconfig ARCH_ORION5X
select CPU_FEROCEON
select GENERIC_CLOCKEVENTS
select GPIOLIB
+ select MDIO_BOARDINFO
select MVEBU_MBUS
select PCI
select PLAT_ORION_LEGACY
diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
index a993cbeb9e0c..9eb15b7518bd 100644
--- a/drivers/net/Kconfig
+++ b/drivers/net/Kconfig
@@ -378,8 +378,6 @@ config NET_SB1000

If you don't have this card, of course say N.

-source "drivers/net/phy/Kconfig"
-
source "drivers/net/plip/Kconfig"

source "drivers/net/ppp/Kconfig"
diff --git a/drivers/net/Makefile b/drivers/net/Makefile
index 7336cbd3ef5d..3ab87e9f9442 100644
--- a/drivers/net/Makefile
+++ b/drivers/net/Makefile
@@ -17,7 +17,7 @@ obj-$(CONFIG_MII) += mii.o
obj-$(CONFIG_MDIO) += mdio.o
obj-$(CONFIG_NET) += Space.o loopback.o
obj-$(CONFIG_NETCONSOLE) += netconsole.o
-obj-$(CONFIG_PHYLIB) += phy/
+obj-y+= phy/
obj-$(CONFIG_RIONET) += rionet.o
obj-$(CONFIG_NET_TEAM) += team/
obj-$(CONFIG_TUN) += tun.o
diff --git a/drivers/net/ethernet/Kconfig b/drivers/net/ethernet/Kconfig
index 8c08f9deef92..9c4652ae2750 100644
--- a/drivers/net/ethernet/Kconfig
+++ b/drivers/net/ethernet/Kconfig
@@ -11,9 +11,6 @@ menuconfig ETHERNET

if ETHERNET

-config MDIO
- tristate
-
config SUNGEM_PHY
tristate

diff --git a/drivers/net/phy/Kconfig b/drivers/net/phy/Kconfig
index 8dbd59baa34d..37f5552cc5b3 100644
--- a/drivers/net/phy/Kconfig
+++ b/drivers/net/phy/Kconfig
@@ -3,8 +3,9 @@
#

menuconfig PHYLIB
- tristate "PHY Device support and infrastructure"
+ tristate "Ethernet PHY Device support and infrastructure"
depends on NETDEVICES
+ select MDIO
help
Ethernet controllers are usually attached to PHY
devices. This option provides infrastructure for
@@ -248,6 +249,16 @@ config FIXED_PHY
PHYs that are not connected to the real MDIO bus.

Currently tested with mpc866ads and mpc8349e-mitx.
+endif # PHYLIB
+
+config MDIO
+ tristate
+ help
+ The MDIO bus is typically used ethernet PHYs, but can also be
+ used by other PHY drivers.
+
+menu "MDIO bus drivers"
+ depends on MDIO

config ICPLUS_PHY
tristate "ICPlus PHYs"
@@ -340,7 +351,10 @@ config XILINX_GMII2RGMII
the Reduced Gigabit Media Independent Interface(RGMII) between
Ethernet physical media devices and the Gigabit Ethernet controller.

-endif # PHYLIB
+endmenu # MDIO
+
+config MDIO_BOARDINFO
+ bool

config MICREL_KS8995MA
tristate "Micrel KS8995MA 5-ports 10/100 managed Ethernet switch"
diff --git a/drivers/net/phy/Makefile b/drivers/net/phy/Makefile
index 407b0b601ea8..e60e5d2fae53 100644
--- a/drivers/net/phy/Makefile
+++ b/drivers/net/phy/Makefile
@@ -1,11 +1,13 @@
# Makefile for Linux PHY drivers and MDIO bus drivers

-libphy-y := phy.o phy_device.o mdio_bus.o mdio_device.o \
- mdio-boardinfo.o
+libphy-y := phy.o phy_device.o mdio_bus.o mdio_device.o
libphy-$(CONFIG_SWPHY) += swphy.o
libphy-$(CONFIG_LED_TRIGGER_PHY) += phy_led_triggers.o

obj-$(CONFIG_PHYLIB) += libphy.o
+ifdef CONFIG_PHYLIB
+obj-$(CONFIG_MDIO_BOARDINFO) += mdio-boardinfo.o
+endif

obj-$(CONFIG_MDIO_BCM_IPROC) += mdio-bcm-iproc.o
obj-$(CONFIG_MDIO_BCM_UNIMAC) += mdio-bcm-unimac.o
diff --git a/drivers/net/phy/mdio-boardinfo.c b/drivers/net/phy/mdio-boardinfo.c
index 6b988f77da08..f7cf98093344 100644
--- a/drivers/net/phy/mdio-boardinfo.c
+++ b/drivers/net/phy/mdio-boardinfo.c
@@ -55,6 +55,7 @@ void mdiobus_setup_mdiodev_from_board_info(struct mii_bus *bus)
}
mutex_unlock(&mdio_board_lock);
}
+EXPORT_SYMBOL_GPL(mdiobus_setup_mdiodev_from_board_info);

/**
* mdio_register_board_info - register MDIO devices for a given board
diff --git a/drivers/net/phy/mdio-boardinfo.h b/drivers/net/phy/mdio-boardinfo.h
index 00f98163e90e..3a72bd978114 100644
--- a/drivers/net/phy/mdio-boardinfo.h
+++ b/drivers/net/phy/mdio-boardinfo.h
@@ -14,6 +14,12 @@ struct mdio_board_entry {
struct mdio_board_info board_info;
};

+#ifdef CONFIG_MDIO_BOARDINFO
void mdiobus_setup_mdiodev_from_board_info(struct mii_bus *bus);
+#else
+static inline void mdiobus_setup_mdiodev_from_board_info(struct mii_bus *bus)
+{
+}
+#endif

#endif /* __MDIO_BOARD_INFO_H */
diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
index 519241bc8817..87c581f11297 100644
--- a/drivers/phy/Kconfig
+++ b/drivers/phy/Kconfig
@@ -2,7 +2,9 @@
# PHY
#

-menu "PHY Subsystem"
+menu "PHY drivers"
+
+menu "Generic PHY subsystem"

config GENERIC_PHY
bool "PHY Core"
@@ -515,3 +517,7 @@ config PHY_NSP_USB3
Enable this to support the Broadcom Northstar plus USB3 PHY.
If unsure, say N.
endmenu
+
+source "drivers/net/phy/Kconfig"
+
+endmenu
diff --git a/include/linux/phy.h b/include/linux/phy.h
index d9bdf53e0514..2ec82a4c3b8f 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -893,7 +893,7 @@ struct mdio_board_info {
const void *platform_data;
};

-#if IS_ENABLED(CONFIG_PHYLIB)
+#if IS_ENABLED(CONFIG_PHYLIB) && IS_ENABLED(CONFIG_MDIO_BOARDINFO)
int mdiobus_register_board_info(const struct mdio_board_info *info,
unsigned int n);
#else