From 16879cd25a4089cde2f3393fb09567df53402679 Mon Sep 17 00:00:00 2001
From: Joe Hershberger <joe.hershberger@ni.com>
Date: Fri, 30 Mar 2018 11:52:16 -0500
Subject: [PATCH] net: phy: Don't limit phy addresses by default

Some boards expect to find more than one phy while other boards are old
and need to be limited to a specific phy address. Only limit the phy
address for boards that opt in.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>
Acked-by: Neil Armstrong <narmstrong@baylibre.com>
Reviewed-by: Philipp Tomsich <philipp.tomsich@theobroma-systems.com>
---
 configs/am335x_baltos_defconfig            | 1 +
 configs/am335x_shc_defconfig               | 1 +
 configs/am335x_shc_ict_defconfig           | 1 +
 configs/am335x_shc_netboot_defconfig       | 1 +
 configs/am335x_shc_prompt_defconfig        | 1 +
 configs/am335x_shc_sdboot_defconfig        | 1 +
 configs/am335x_shc_sdboot_prompt_defconfig | 1 +
 configs/devkit3250_defconfig               | 1 +
 configs/ds414_defconfig                    | 1 +
 configs/khadas-vim_defconfig               | 1 +
 configs/libretech-cc_defconfig             | 1 +
 configs/p212_defconfig                     | 1 +
 configs/pepper_defconfig                   | 1 +
 configs/work_92105_defconfig               | 1 +
 configs/x600_defconfig                     | 1 +
 drivers/net/phy/Kconfig                    | 8 ++++++++
 16 files changed, 23 insertions(+)

diff --git a/configs/am335x_baltos_defconfig b/configs/am335x_baltos_defconfig
index 2ceb761eed..d72228b9f2 100644
--- a/configs/am335x_baltos_defconfig
+++ b/configs/am335x_baltos_defconfig
@@ -44,6 +44,7 @@ CONFIG_SYS_OMAP24_I2C_SPEED=1000
 CONFIG_MMC_OMAP_HS=y
 CONFIG_NAND=y
 CONFIG_DRIVER_TI_CPSW=y
+CONFIG_PHY_ADDR_ENABLE=y
 CONFIG_SYS_NS16550=y
 CONFIG_OMAP3_SPI=y
 CONFIG_USB=y
diff --git a/configs/am335x_shc_defconfig b/configs/am335x_shc_defconfig
index 3be3063e50..42196dd75e 100644
--- a/configs/am335x_shc_defconfig
+++ b/configs/am335x_shc_defconfig
@@ -38,6 +38,7 @@ CONFIG_ENV_IS_IN_MMC=y
 CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG=y
 CONFIG_MMC_OMAP_HS=y
 CONFIG_DRIVER_TI_CPSW=y
+CONFIG_PHY_ADDR_ENABLE=y
 CONFIG_SYS_NS16550=y
 CONFIG_OMAP3_SPI=y
 CONFIG_FAT_WRITE=y
diff --git a/configs/am335x_shc_ict_defconfig b/configs/am335x_shc_ict_defconfig
index 1fe5bf8912..a32248e4f4 100644
--- a/configs/am335x_shc_ict_defconfig
+++ b/configs/am335x_shc_ict_defconfig
@@ -39,6 +39,7 @@ CONFIG_ENV_IS_IN_MMC=y
 CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG=y
 CONFIG_MMC_OMAP_HS=y
 CONFIG_DRIVER_TI_CPSW=y
+CONFIG_PHY_ADDR_ENABLE=y
 CONFIG_SYS_NS16550=y
 CONFIG_OMAP3_SPI=y
 CONFIG_FAT_WRITE=y
diff --git a/configs/am335x_shc_netboot_defconfig b/configs/am335x_shc_netboot_defconfig
index bd61102f67..3474f51f3c 100644
--- a/configs/am335x_shc_netboot_defconfig
+++ b/configs/am335x_shc_netboot_defconfig
@@ -40,6 +40,7 @@ CONFIG_ENV_IS_IN_MMC=y
 CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG=y
 CONFIG_MMC_OMAP_HS=y
 CONFIG_DRIVER_TI_CPSW=y
+CONFIG_PHY_ADDR_ENABLE=y
 CONFIG_SYS_NS16550=y
 CONFIG_OMAP3_SPI=y
 CONFIG_FAT_WRITE=y
diff --git a/configs/am335x_shc_prompt_defconfig b/configs/am335x_shc_prompt_defconfig
index 9658fb9a3d..de852cb248 100644
--- a/configs/am335x_shc_prompt_defconfig
+++ b/configs/am335x_shc_prompt_defconfig
@@ -37,6 +37,7 @@ CONFIG_ENV_IS_IN_MMC=y
 CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG=y
 CONFIG_MMC_OMAP_HS=y
 CONFIG_DRIVER_TI_CPSW=y
+CONFIG_PHY_ADDR_ENABLE=y
 CONFIG_SYS_NS16550=y
 CONFIG_OMAP3_SPI=y
 CONFIG_FAT_WRITE=y
diff --git a/configs/am335x_shc_sdboot_defconfig b/configs/am335x_shc_sdboot_defconfig
index f8f88d3996..346efad919 100644
--- a/configs/am335x_shc_sdboot_defconfig
+++ b/configs/am335x_shc_sdboot_defconfig
@@ -39,6 +39,7 @@ CONFIG_ENV_IS_IN_MMC=y
 CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG=y
 CONFIG_MMC_OMAP_HS=y
 CONFIG_DRIVER_TI_CPSW=y
+CONFIG_PHY_ADDR_ENABLE=y
 CONFIG_SYS_NS16550=y
 CONFIG_OMAP3_SPI=y
 CONFIG_FAT_WRITE=y
diff --git a/configs/am335x_shc_sdboot_prompt_defconfig b/configs/am335x_shc_sdboot_prompt_defconfig
index f8f88d3996..346efad919 100644
--- a/configs/am335x_shc_sdboot_prompt_defconfig
+++ b/configs/am335x_shc_sdboot_prompt_defconfig
@@ -39,6 +39,7 @@ CONFIG_ENV_IS_IN_MMC=y
 CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG=y
 CONFIG_MMC_OMAP_HS=y
 CONFIG_DRIVER_TI_CPSW=y
+CONFIG_PHY_ADDR_ENABLE=y
 CONFIG_SYS_NS16550=y
 CONFIG_OMAP3_SPI=y
 CONFIG_FAT_WRITE=y
diff --git a/configs/devkit3250_defconfig b/configs/devkit3250_defconfig
index fa35748b94..a88cf1cb25 100644
--- a/configs/devkit3250_defconfig
+++ b/configs/devkit3250_defconfig
@@ -36,6 +36,7 @@ CONFIG_MTD_NOR_FLASH=y
 CONFIG_NAND=y
 CONFIG_SPL_NAND_SIMPLE=y
 CONFIG_PHYLIB=y
+CONFIG_PHY_ADDR_ENABLE=y
 CONFIG_PHY_ADDR=31
 CONFIG_DM_SERIAL=y
 CONFIG_SYS_NS16550=y
diff --git a/configs/ds414_defconfig b/configs/ds414_defconfig
index d605ebfce8..907185953a 100644
--- a/configs/ds414_defconfig
+++ b/configs/ds414_defconfig
@@ -41,6 +41,7 @@ CONFIG_SPL_OF_TRANSLATE=y
 CONFIG_SPI_FLASH=y
 CONFIG_SPI_FLASH_BAR=y
 CONFIG_SPI_FLASH_STMICRO=y
+CONFIG_PHY_ADDR_ENABLE=y
 CONFIG_PHY_GIGE=y
 CONFIG_MVNETA=y
 CONFIG_PCI=y
diff --git a/configs/khadas-vim_defconfig b/configs/khadas-vim_defconfig
index f4674efb68..0bfb5942aa 100644
--- a/configs/khadas-vim_defconfig
+++ b/configs/khadas-vim_defconfig
@@ -20,6 +20,7 @@ CONFIG_NET_RANDOM_ETHADDR=y
 CONFIG_DM_GPIO=y
 CONFIG_DM_MMC=y
 CONFIG_MMC_MESON_GX=y
+CONFIG_PHY_ADDR_ENABLE=y
 CONFIG_PHY_ADDR=8
 CONFIG_PHY_MESON_GXL=y
 CONFIG_DM_ETH=y
diff --git a/configs/libretech-cc_defconfig b/configs/libretech-cc_defconfig
index 18ddb45d95..931496c8de 100644
--- a/configs/libretech-cc_defconfig
+++ b/configs/libretech-cc_defconfig
@@ -20,6 +20,7 @@ CONFIG_NET_RANDOM_ETHADDR=y
 CONFIG_DM_GPIO=y
 CONFIG_DM_MMC=y
 CONFIG_MMC_MESON_GX=y
+CONFIG_PHY_ADDR_ENABLE=y
 CONFIG_PHY_ADDR=8
 CONFIG_PHY_MESON_GXL=y
 CONFIG_DM_ETH=y
diff --git a/configs/p212_defconfig b/configs/p212_defconfig
index b6923f3a67..44221fc8d6 100644
--- a/configs/p212_defconfig
+++ b/configs/p212_defconfig
@@ -20,6 +20,7 @@ CONFIG_NET_RANDOM_ETHADDR=y
 CONFIG_DM_GPIO=y
 CONFIG_DM_MMC=y
 CONFIG_MMC_MESON_GX=y
+CONFIG_PHY_ADDR_ENABLE=y
 CONFIG_PHY_ADDR=8
 CONFIG_PHY_MESON_GXL=y
 CONFIG_DM_ETH=y
diff --git a/configs/pepper_defconfig b/configs/pepper_defconfig
index 91e9937b9c..f3d048d233 100644
--- a/configs/pepper_defconfig
+++ b/configs/pepper_defconfig
@@ -33,6 +33,7 @@ CONFIG_MMC_OMAP_HS=y
 CONFIG_PHY_MICREL=y
 CONFIG_PHY_MICREL_KSZ90X1=y
 CONFIG_DRIVER_TI_CPSW=y
+CONFIG_PHY_ADDR_ENABLE=y
 CONFIG_NETDEVICES=y
 CONFIG_SYS_NS16550=y
 CONFIG_OMAP3_SPI=y
diff --git a/configs/work_92105_defconfig b/configs/work_92105_defconfig
index 150fb077dc..677672d0b6 100644
--- a/configs/work_92105_defconfig
+++ b/configs/work_92105_defconfig
@@ -36,6 +36,7 @@ CONFIG_SPL_DM=y
 CONFIG_DM_GPIO=y
 # CONFIG_MMC is not set
 CONFIG_PHYLIB=y
+CONFIG_PHY_ADDR_ENABLE=y
 CONFIG_DM_SERIAL=y
 CONFIG_SYS_NS16550=y
 CONFIG_LPC32XX_SSP=y
diff --git a/configs/x600_defconfig b/configs/x600_defconfig
index 1da4d8d5e6..77f2b037e7 100644
--- a/configs/x600_defconfig
+++ b/configs/x600_defconfig
@@ -44,6 +44,7 @@ CONFIG_FPGA_SPARTAN3=y
 CONFIG_SYS_I2C_DW=y
 # CONFIG_MMC is not set
 CONFIG_MTD_NOR_FLASH=y
+CONFIG_PHY_ADDR_ENABLE=y
 CONFIG_PHY_MICREL=y
 CONFIG_PHY_MICREL_KSZ90X1=y
 CONFIG_NETDEVICES=y
diff --git a/drivers/net/phy/Kconfig b/drivers/net/phy/Kconfig
index 179e0418bc..f5821dfed9 100644
--- a/drivers/net/phy/Kconfig
+++ b/drivers/net/phy/Kconfig
@@ -13,12 +13,20 @@ menuconfig PHYLIB
 
 if PHYLIB
 
+config PHY_ADDR_ENABLE
+	bool "Limit phy address"
+	default y if ARCH_SUNXI
+	help
+	  Select this if you want to control which phy address is used
+
+if PHY_ADDR_ENABLE
 config PHY_ADDR
 	int "PHY address"
 	default 1 if ARCH_SUNXI
 	default 0
 	help
 	  The address of PHY on MII bus. Usually in range of 0 to 31.
+endif
 
 config B53_SWITCH
 	bool "Broadcom BCM53xx (RoboSwitch) Ethernet switch PHY support."
-- 
2.39.5