From 0976b6c4262a11a8d0dab9aeb64f5cdee266c44a Mon Sep 17 00:00:00 2001 From: Michael Pratt Date: Sat, 3 Apr 2021 14:42:51 -0400 Subject: [PATCH] ramips: mt7620: use DTS to set PHY base address for external PHYs Set the PHY base address to 12 for mt7530 and 8 for others, which is based on the default setting for some devices from printing the register with the following command after it is written to by uboot during the boot cycle. `md 0x10117014 1` PHY_BASE option only uses 5 bits of the register, bits 16 to 20, so use 8-bit integer type. Set the option using the DTS property mediatek,ephy-base and create the gsw node if missing. Also, added a kernel message to display the EPHY base address. Note: If anything is written to a PHY address that is greater than 1 hex char (greater than 0xf) then there is adverse effects with Atheros switches. Signed-off-by: Michael Pratt --- target/linux/ramips/dts/mt7620a_dlink_dwr-118-a1.dts | 1 + target/linux/ramips/dts/mt7620a_dlink_dwr-118-a2.dts | 2 +- target/linux/ramips/dts/mt7620a_dovado_tiny-ac.dts | 1 + .../linux/ramips/dts/mt7620a_edimax_br-6478ac-v2.dts | 4 ++++ target/linux/ramips/dts/mt7620a_edimax_ew-7478apc.dts | 4 ++++ target/linux/ramips/dts/mt7620a_edimax_ew-747x.dtsi | 4 ++++ target/linux/ramips/dts/mt7620a_engenius_esr600.dts | 4 ++++ target/linux/ramips/dts/mt7620a_fon_fon2601.dts | 1 + .../linux/ramips/dts/mt7620a_head-weblink_hdrm200.dts | 1 + target/linux/ramips/dts/mt7620a_iodata_wn-ac1167gr.dts | 4 ++++ target/linux/ramips/dts/mt7620a_iptime_a1004ns.dts | 4 ++++ target/linux/ramips/dts/mt7620a_lava_lr-25g001.dts | 4 ++++ target/linux/ramips/dts/mt7620a_lb-link_bl-w1200.dts | 4 ++++ target/linux/ramips/dts/mt7620a_lenovo_newifi-y1s.dts | 1 + target/linux/ramips/dts/mt7620a_linksys_e1700.dts | 4 ++++ target/linux/ramips/dts/mt7620a_netis_wf2770.dts | 4 ++++ target/linux/ramips/dts/mt7620a_ralink_mt7620a-evb.dts | 1 + .../ramips/dts/mt7620a_ralink_mt7620a-mt7530-evb.dts | 4 ++++ .../ramips/dts/mt7620a_ralink_mt7620a-v22sg-evb.dts | 1 + target/linux/ramips/dts/mt7620a_sercomm_na930.dts | 1 + target/linux/ramips/dts/mt7620a_tplink_re210-v1.dts | 1 + target/linux/ramips/dts/mt7620a_wavlink_wl-wn579x3.dts | 1 + .../linux/ramips/dts/mt7620a_zyxel_keenetic-viva.dts | 1 + .../files/drivers/net/ethernet/ralink/gsw_mt7620.c | 10 ++++------ 24 files changed, 60 insertions(+), 7 deletions(-) diff --git a/target/linux/ramips/dts/mt7620a_dlink_dwr-118-a1.dts b/target/linux/ramips/dts/mt7620a_dlink_dwr-118-a1.dts index 71b532fc345..b86ab1449b6 100644 --- a/target/linux/ramips/dts/mt7620a_dlink_dwr-118-a1.dts +++ b/target/linux/ramips/dts/mt7620a_dlink_dwr-118-a1.dts @@ -186,4 +186,5 @@ &gsw { mediatek,port4-gmac; + mediatek,ephy-base = /bits/ 8 <8>; }; diff --git a/target/linux/ramips/dts/mt7620a_dlink_dwr-118-a2.dts b/target/linux/ramips/dts/mt7620a_dlink_dwr-118-a2.dts index 9ea28706aa1..b0dd31cafcd 100644 --- a/target/linux/ramips/dts/mt7620a_dlink_dwr-118-a2.dts +++ b/target/linux/ramips/dts/mt7620a_dlink_dwr-118-a2.dts @@ -174,5 +174,5 @@ &gsw { mediatek,port4-gmac; - mediatek,ephy-base-address = /bits/ 16 < 2 >; + mediatek,ephy-base = /bits/ 8 <2>; }; diff --git a/target/linux/ramips/dts/mt7620a_dovado_tiny-ac.dts b/target/linux/ramips/dts/mt7620a_dovado_tiny-ac.dts index 068f75bd960..ba1a2becdab 100644 --- a/target/linux/ramips/dts/mt7620a_dovado_tiny-ac.dts +++ b/target/linux/ramips/dts/mt7620a_dovado_tiny-ac.dts @@ -136,6 +136,7 @@ &gsw { mediatek,port4-gmac; + mediatek,ephy-base = /bits/ 8 <8>; }; &pcie { diff --git a/target/linux/ramips/dts/mt7620a_edimax_br-6478ac-v2.dts b/target/linux/ramips/dts/mt7620a_edimax_br-6478ac-v2.dts index 2337c0f9d36..03a4c96f6ba 100644 --- a/target/linux/ramips/dts/mt7620a_edimax_br-6478ac-v2.dts +++ b/target/linux/ramips/dts/mt7620a_edimax_br-6478ac-v2.dts @@ -177,6 +177,10 @@ }; }; +&gsw { + mediatek,ephy-base = /bits/ 8 <12>; +}; + &wmac { ralink,mtd-eeprom = <&factory 0x0>; }; diff --git a/target/linux/ramips/dts/mt7620a_edimax_ew-7478apc.dts b/target/linux/ramips/dts/mt7620a_edimax_ew-7478apc.dts index 09763db388c..986b047e477 100644 --- a/target/linux/ramips/dts/mt7620a_edimax_ew-7478apc.dts +++ b/target/linux/ramips/dts/mt7620a_edimax_ew-7478apc.dts @@ -169,6 +169,10 @@ }; }; +&gsw { + mediatek,ephy-base = /bits/ 8 <12>; +}; + &wmac { ralink,mtd-eeprom = <&factory 0x0>; }; diff --git a/target/linux/ramips/dts/mt7620a_edimax_ew-747x.dtsi b/target/linux/ramips/dts/mt7620a_edimax_ew-747x.dtsi index 07b03f5c066..5cb8451547a 100644 --- a/target/linux/ramips/dts/mt7620a_edimax_ew-747x.dtsi +++ b/target/linux/ramips/dts/mt7620a_edimax_ew-747x.dtsi @@ -201,6 +201,10 @@ }; }; +&gsw { + mediatek,ephy-base = /bits/ 8 <8>; +}; + &wmac { ralink,mtd-eeprom = <&factory 0x0>; }; diff --git a/target/linux/ramips/dts/mt7620a_engenius_esr600.dts b/target/linux/ramips/dts/mt7620a_engenius_esr600.dts index 35d0b3dbeca..2f0f9b256e9 100644 --- a/target/linux/ramips/dts/mt7620a_engenius_esr600.dts +++ b/target/linux/ramips/dts/mt7620a_engenius_esr600.dts @@ -160,6 +160,10 @@ }; }; +&gsw { + mediatek,ephy-base = /bits/ 8 <8>; +}; + &state_default { gpio { groups = "i2c", "uartf", "nd_sd", "wled"; diff --git a/target/linux/ramips/dts/mt7620a_fon_fon2601.dts b/target/linux/ramips/dts/mt7620a_fon_fon2601.dts index b47d63be858..373205e7254 100644 --- a/target/linux/ramips/dts/mt7620a_fon_fon2601.dts +++ b/target/linux/ramips/dts/mt7620a_fon_fon2601.dts @@ -137,6 +137,7 @@ &gsw { mediatek,port4-gmac; + mediatek,ephy-base = /bits/ 8 <8>; }; &wmac { diff --git a/target/linux/ramips/dts/mt7620a_head-weblink_hdrm200.dts b/target/linux/ramips/dts/mt7620a_head-weblink_hdrm200.dts index 487f6aaf6eb..7d807bff4bb 100644 --- a/target/linux/ramips/dts/mt7620a_head-weblink_hdrm200.dts +++ b/target/linux/ramips/dts/mt7620a_head-weblink_hdrm200.dts @@ -151,6 +151,7 @@ &gsw { mediatek,port4-gmac; + mediatek,ephy-base = /bits/ 8 <8>; }; &wmac { diff --git a/target/linux/ramips/dts/mt7620a_iodata_wn-ac1167gr.dts b/target/linux/ramips/dts/mt7620a_iodata_wn-ac1167gr.dts index 7044a511bcc..d59b481a612 100644 --- a/target/linux/ramips/dts/mt7620a_iodata_wn-ac1167gr.dts +++ b/target/linux/ramips/dts/mt7620a_iodata_wn-ac1167gr.dts @@ -184,6 +184,10 @@ }; }; +&gsw { + mediatek,ephy-base = /bits/ 8 <12>; +}; + &state_default { gpio { groups = "i2c", "uartf"; diff --git a/target/linux/ramips/dts/mt7620a_iptime_a1004ns.dts b/target/linux/ramips/dts/mt7620a_iptime_a1004ns.dts index 20d05579163..6270af3b158 100644 --- a/target/linux/ramips/dts/mt7620a_iptime_a1004ns.dts +++ b/target/linux/ramips/dts/mt7620a_iptime_a1004ns.dts @@ -101,3 +101,7 @@ }; }; }; + +&gsw { + mediatek,ephy-base = /bits/ 8 <12>; +}; diff --git a/target/linux/ramips/dts/mt7620a_lava_lr-25g001.dts b/target/linux/ramips/dts/mt7620a_lava_lr-25g001.dts index 962ef3371d6..ee845c7b5ec 100644 --- a/target/linux/ramips/dts/mt7620a_lava_lr-25g001.dts +++ b/target/linux/ramips/dts/mt7620a_lava_lr-25g001.dts @@ -150,6 +150,10 @@ }; }; +&gsw { + mediatek,ephy-base = /bits/ 8 <8>; +}; + &pcie { status = "okay"; }; diff --git a/target/linux/ramips/dts/mt7620a_lb-link_bl-w1200.dts b/target/linux/ramips/dts/mt7620a_lb-link_bl-w1200.dts index bb1303d4fb4..9e0b8171633 100644 --- a/target/linux/ramips/dts/mt7620a_lb-link_bl-w1200.dts +++ b/target/linux/ramips/dts/mt7620a_lb-link_bl-w1200.dts @@ -135,6 +135,10 @@ }; }; +&gsw { + mediatek,ephy-base = /bits/ 8 <12>; +}; + &wmac { ralink,mtd-eeprom = <&factory 0x0>; }; diff --git a/target/linux/ramips/dts/mt7620a_lenovo_newifi-y1s.dts b/target/linux/ramips/dts/mt7620a_lenovo_newifi-y1s.dts index 0997d8a00ec..0544550bf9d 100644 --- a/target/linux/ramips/dts/mt7620a_lenovo_newifi-y1s.dts +++ b/target/linux/ramips/dts/mt7620a_lenovo_newifi-y1s.dts @@ -112,4 +112,5 @@ &gsw { mediatek,port4-gmac; + mediatek,ephy-base = /bits/ 8 <8>; }; diff --git a/target/linux/ramips/dts/mt7620a_linksys_e1700.dts b/target/linux/ramips/dts/mt7620a_linksys_e1700.dts index 2672d54f360..c38ea8082ca 100644 --- a/target/linux/ramips/dts/mt7620a_linksys_e1700.dts +++ b/target/linux/ramips/dts/mt7620a_linksys_e1700.dts @@ -144,6 +144,10 @@ }; }; +&gsw { + mediatek,ephy-base = /bits/ 8 <12>; +}; + &wmac { ralink,mtd-eeprom = <&factory 0x0>; }; diff --git a/target/linux/ramips/dts/mt7620a_netis_wf2770.dts b/target/linux/ramips/dts/mt7620a_netis_wf2770.dts index ab8c61b1d82..f8390488656 100644 --- a/target/linux/ramips/dts/mt7620a_netis_wf2770.dts +++ b/target/linux/ramips/dts/mt7620a_netis_wf2770.dts @@ -142,6 +142,10 @@ }; }; +&gsw { + mediatek,ephy-base = /bits/ 8 <12>; +}; + &pcie { status = "okay"; }; diff --git a/target/linux/ramips/dts/mt7620a_ralink_mt7620a-evb.dts b/target/linux/ramips/dts/mt7620a_ralink_mt7620a-evb.dts index 4c5baf1e508..ae359415074 100644 --- a/target/linux/ramips/dts/mt7620a_ralink_mt7620a-evb.dts +++ b/target/linux/ramips/dts/mt7620a_ralink_mt7620a-evb.dts @@ -106,6 +106,7 @@ &gsw { mediatek,port4-gmac; + mediatek,ephy-base = /bits/ 8 <8>; }; &sdhci { diff --git a/target/linux/ramips/dts/mt7620a_ralink_mt7620a-mt7530-evb.dts b/target/linux/ramips/dts/mt7620a_ralink_mt7620a-mt7530-evb.dts index b76ab2aa595..f7d8cae1602 100644 --- a/target/linux/ramips/dts/mt7620a_ralink_mt7620a-mt7530-evb.dts +++ b/target/linux/ramips/dts/mt7620a_ralink_mt7620a-mt7530-evb.dts @@ -99,6 +99,10 @@ }; }; +&gsw { + mediatek,ephy-base = /bits/ 8 <12>; +}; + &pcie { status = "okay"; }; diff --git a/target/linux/ramips/dts/mt7620a_ralink_mt7620a-v22sg-evb.dts b/target/linux/ramips/dts/mt7620a_ralink_mt7620a-v22sg-evb.dts index 6e8eff50bcf..0e963e1f02a 100644 --- a/target/linux/ramips/dts/mt7620a_ralink_mt7620a-v22sg-evb.dts +++ b/target/linux/ramips/dts/mt7620a_ralink_mt7620a-v22sg-evb.dts @@ -100,6 +100,7 @@ &gsw { mediatek,port4-gmac; + mediatek,ephy-base = /bits/ 8 <8>; }; &pcie { diff --git a/target/linux/ramips/dts/mt7620a_sercomm_na930.dts b/target/linux/ramips/dts/mt7620a_sercomm_na930.dts index 329ecc5ea8a..1ffc0a2bc81 100644 --- a/target/linux/ramips/dts/mt7620a_sercomm_na930.dts +++ b/target/linux/ramips/dts/mt7620a_sercomm_na930.dts @@ -167,6 +167,7 @@ &gsw { mediatek,port4-gmac; + mediatek,ephy-base = /bits/ 8 <8>; }; &ehci { diff --git a/target/linux/ramips/dts/mt7620a_tplink_re210-v1.dts b/target/linux/ramips/dts/mt7620a_tplink_re210-v1.dts index 247b5752ef1..57cd0ed539f 100644 --- a/target/linux/ramips/dts/mt7620a_tplink_re210-v1.dts +++ b/target/linux/ramips/dts/mt7620a_tplink_re210-v1.dts @@ -62,6 +62,7 @@ &gsw { mediatek,port4-gmac; + mediatek,ephy-base = /bits/ 8 <8>; }; ðernet { diff --git a/target/linux/ramips/dts/mt7620a_wavlink_wl-wn579x3.dts b/target/linux/ramips/dts/mt7620a_wavlink_wl-wn579x3.dts index 55ab939d157..bfec806c125 100644 --- a/target/linux/ramips/dts/mt7620a_wavlink_wl-wn579x3.dts +++ b/target/linux/ramips/dts/mt7620a_wavlink_wl-wn579x3.dts @@ -196,6 +196,7 @@ &gsw { mediatek,port4-gmac; + mediatek,ephy-base = /bits/ 8 <8>; }; &wmac { diff --git a/target/linux/ramips/dts/mt7620a_zyxel_keenetic-viva.dts b/target/linux/ramips/dts/mt7620a_zyxel_keenetic-viva.dts index 506b828ec83..1a5ff2d0dfc 100644 --- a/target/linux/ramips/dts/mt7620a_zyxel_keenetic-viva.dts +++ b/target/linux/ramips/dts/mt7620a_zyxel_keenetic-viva.dts @@ -158,6 +158,7 @@ &gsw { mediatek,port4-gmac; + mediatek,ephy-base = /bits/ 8 <8>; }; &wmac { diff --git a/target/linux/ramips/files/drivers/net/ethernet/ralink/gsw_mt7620.c b/target/linux/ramips/files/drivers/net/ethernet/ralink/gsw_mt7620.c index 4b030f457be..54b8b204ebf 100644 --- a/target/linux/ramips/files/drivers/net/ethernet/ralink/gsw_mt7620.c +++ b/target/linux/ramips/files/drivers/net/ethernet/ralink/gsw_mt7620.c @@ -98,9 +98,6 @@ static void mt7620_hw_init(struct mt7620_gsw *gsw, int mdio_mode) mtk_switch_w32(gsw, mtk_switch_r32(gsw, GSW_REG_MIB_CNT_EN) | (1 << 1), GSW_REG_MIB_CNT_EN); if (mdio_mode) { - if (!gsw->ephy_base) - gsw->ephy_base = 12; - /* set MT7530 central align */ val = mt7530_mdio_r32(gsw, 0x7830); val &= ~BIT(0); @@ -115,11 +112,12 @@ static void mt7620_hw_init(struct mt7620_gsw *gsw, int mdio_mode) } if (gsw->ephy_base) { - /* set phy base addr to ephy_base */ mtk_switch_w32(gsw, mtk_switch_r32(gsw, GSW_REG_GPC1) | (gsw->ephy_base << 16), GSW_REG_GPC1); fe_reset(BIT(24)); /* Resets the Ethernet PHY block. */ + + pr_info("gsw: ephy base address: %d\n", gsw->ephy_base); } /* global page 4 */ @@ -246,7 +244,7 @@ static int mt7620_gsw_probe(struct platform_device *pdev) struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0); struct mt7620_gsw *gsw; struct device_node *np = pdev->dev.of_node; - u16 val; + u8 val; gsw = devm_kzalloc(&pdev->dev, sizeof(struct mt7620_gsw), GFP_KERNEL); if (!gsw) @@ -260,7 +258,7 @@ static int mt7620_gsw_probe(struct platform_device *pdev) gsw->port4_ephy = !of_property_read_bool(np, "mediatek,port4-gmac"); - if (of_property_read_u16(np, "mediatek,ephy-base-address", &val) == 0) + if (of_property_read_u8(np, "mediatek,ephy-base", &val) == 0) gsw->ephy_base = val; else gsw->ephy_base = 0; -- 2.30.2