From 9a49d04bbf0e642f1628088d3613ef2338225858 Mon Sep 17 00:00:00 2001 From: Dirk Chang Date: Mon, 18 Mar 2024 16:02:18 +0800 Subject: [PATCH] sunxi: port changes from 21.02 --- .../9909-net-phy-dp83848-leds-init.patch | 71 ++++++++++++++ ...CH_sun8i-r40-second-ethernet-support.patch | 12 +-- ...-ARM-dts-sun8i-kooiot-tlink-dly-t3v1.patch | 6 +- .../915-ARM-dts-sun8i-kooiot-tlink-k2x.patch | 9 +- ...-r40-second-ethernet-reset-when-open.patch | 96 +++++++++++++++++++ ...c-sun8i-fix-double-disable-regulator.patch | 19 ++++ ...r-remove-crash-when-mdio-init-failed.patch | 35 +++++++ 7 files changed, 234 insertions(+), 14 deletions(-) create mode 100644 target/linux/generic/hack-6.1/9909-net-phy-dp83848-leds-init.patch create mode 100644 target/linux/sunxi/patches-6.1/9900-sun8i-r40-second-ethernet-reset-when-open.patch create mode 100644 target/linux/sunxi/patches-6.1/9901-drivers-net-stmmac-sun8i-fix-double-disable-regulator.patch create mode 100644 target/linux/sunxi/patches-6.1/9902-net-stmmac-main-fix-dvr-remove-crash-when-mdio-init-failed.patch diff --git a/target/linux/generic/hack-6.1/9909-net-phy-dp83848-leds-init.patch b/target/linux/generic/hack-6.1/9909-net-phy-dp83848-leds-init.patch new file mode 100644 index 00000000000000..c25f273178c7d9 --- /dev/null +++ b/target/linux/generic/hack-6.1/9909-net-phy-dp83848-leds-init.patch @@ -0,0 +1,71 @@ +--- a/drivers/net/phy/dp83848.c ++++ b/drivers/net/phy/dp83848.c +@@ -16,6 +16,8 @@ + /* Registers */ + #define DP83848_MICR 0x11 /* MII Interrupt Control Register */ + #define DP83848_MISR 0x12 /* MII Interrupt Status Register */ ++#define DP83848_LEDCR 0x18 /* LED Direct Control Register */ ++#define DP83848_PHYCR 0x19 /* PHY Control Register */ + + /* MICR Register Fields */ + #define DP83848_MICR_INT_OE BIT(0) /* Interrupt Output Enable */ +@@ -31,6 +33,10 @@ + #define DP83848_MISR_ED_INT_EN BIT(6) /* Energy detect */ + #define DP83848_MISR_LQM_INT_EN BIT(7) /* Link Quality Monitor */ + ++/* PHYCR Register Fields */ ++#define DP83848_PHYCR_LED_CNFG BIT(5) /* LED Configuration */ ++#define DP83848_PHYCR_FORCE_MDIX BIT(14) /* Force MDIX */ ++ + #define DP83848_INT_EN_MASK \ + (DP83848_MISR_ANC_INT_EN | \ + DP83848_MISR_DUP_INT_EN | \ +@@ -109,6 +115,39 @@ + return IRQ_HANDLED; + } + ++static int ns_dp83848_config_init(struct phy_device *phydev) ++{ ++ int val; ++ ++ msleep(1); ++ ++ val = phy_read(phydev, MII_PHYSID1) << 16; ++ val |= phy_read(phydev, MII_PHYSID2); ++ phydev_info(phydev, "%s: phy_id: %x", __func__, val); ++ if (val != NS_DP83848C_PHY_ID) ++ return 0; ++ ++ val = phy_read(phydev, DP83848_PHYCR); ++ if (val & DP83848_PHYCR_LED_CNFG) { ++ phydev_info(phydev, "%s: fix led value: %x", __func__, val); ++ val &= ~DP83848_PHYCR_LED_CNFG; ++ // val |= DP83848_PHYCR_FORCE_MDIX; ++ msleep(10); ++ phy_write(phydev, DP83848_PHYCR, val); ++ msleep(10); ++ phy_write(phydev, DP83848_PHYCR, val); ++ msleep(10); ++ val = phy_read(phydev, DP83848_PHYCR); ++ phydev_info(phydev, "%s: fixed led value: %x", __func__, val); ++ // val = phy_read(phydev, DP83848_LEDCR); ++ // phydev_info(phydev, "%s: led direct control value: %x", __func__, val); ++ } else { ++ phydev_info(phydev, "%s: led value: %x", __func__, val); ++ } ++ ++ return 0; ++} ++ + static int dp83848_config_init(struct phy_device *phydev) + { + int val; +@@ -153,7 +192,7 @@ + DP83848_PHY_DRIVER(TI_DP83848C_PHY_ID, "TI DP83848C 10/100 Mbps PHY", + NULL), + DP83848_PHY_DRIVER(NS_DP83848C_PHY_ID, "NS DP83848C 10/100 Mbps PHY", +- NULL), ++ ns_dp83848_config_init), + DP83848_PHY_DRIVER(TI_DP83620_PHY_ID, "TI DP83620 10/100 Mbps PHY", + dp83848_config_init), + DP83848_PHY_DRIVER(TLK10X_PHY_ID, "TI TLK10X 10/100 Mbps PHY", diff --git a/target/linux/sunxi/patches-6.1/8000_PATCH_sun8i-r40-second-ethernet-support.patch b/target/linux/sunxi/patches-6.1/8000_PATCH_sun8i-r40-second-ethernet-support.patch index 0320ef84236777..8afce7745692ca 100644 --- a/target/linux/sunxi/patches-6.1/8000_PATCH_sun8i-r40-second-ethernet-support.patch +++ b/target/linux/sunxi/patches-6.1/8000_PATCH_sun8i-r40-second-ethernet-support.patch @@ -9,9 +9,9 @@ index 8d8560a67abf..27f99372d153 100644 - const: allwinner,sun4i-a10-emac + oneOf: + - const: allwinner,sun4i-a10-emac -+ - const: allwinner,sun4i-r40-emac ++ - const: allwinner,sun8i-r40-emac + - items: -+ - const: allwinner,sun4i-r40-emac ++ - const: allwinner,sun8i-r40-emac + - const: allwinner,sun4i-a10-emac reg: @@ -161,7 +161,7 @@ index 5ed80d9a6b9f..b26913610a38 100644 + .has_reset = false, +}; -+static const struct emac_quirks sun4i_r40_emac_quirks = { ++static const struct emac_quirks sun8i_r40_emac_quirks = { + .has_reset = true, +}; + @@ -171,8 +171,8 @@ index 5ed80d9a6b9f..b26913610a38 100644 + .data = &sun4i_a10_emac_quirks + }, + { -+ .compatible = "allwinner,sun4i-r40-emac", -+ .data = &sun4i_r40_emac_quirks ++ .compatible = "allwinner,sun8i-r40-emac", ++ .data = &sun8i_r40_emac_quirks + }, /* Deprecated */ - {.compatible = "allwinner,sun4i-emac",}, @@ -238,7 +238,7 @@ index d5ad3b9efd12..c31386e421b1 100644 }; + emac: ethernet@1c0b000 { -+ compatible = "allwinner,sun4i-r40-emac"; ++ compatible = "allwinner,sun8i-r40-emac"; + reg = <0x01c0b000 0x1000>; + interrupts = ; + clocks = <&ccu CLK_BUS_EMAC>; diff --git a/target/linux/sunxi/patches-6.1/891-ARM-dts-sun8i-kooiot-tlink-dly-t3v1.patch b/target/linux/sunxi/patches-6.1/891-ARM-dts-sun8i-kooiot-tlink-dly-t3v1.patch index edd014888f2182..55b62af18875cf 100644 --- a/target/linux/sunxi/patches-6.1/891-ARM-dts-sun8i-kooiot-tlink-dly-t3v1.patch +++ b/target/linux/sunxi/patches-6.1/891-ARM-dts-sun8i-kooiot-tlink-dly-t3v1.patch @@ -1,6 +1,6 @@ --- /dev/null +++ b/arch/arm/boot/dts/sun8i-t3-tlink-dly-t3v2.dtsi -@@ -0,0 +1,536 @@ +@@ -0,0 +1,534 @@ +/* + * Copyright (C) 2021 Dirk Chang + * @@ -122,15 +122,13 @@ + phy-handle = <&emac_phy>; + phy-supply = <®_dcdc1>; + phy-mode = "mii"; ++ reset-gpios = <&pio 7 27 GPIO_ACTIVE_LOW>; /* PH27 */ + status = "okay"; +}; + +&emac_mdio { + status = "okay"; + phy-supply = <®_dcdc1>; -+ reset-gpios = <&pio 7 27 GPIO_ACTIVE_LOW>; /* PH27 */ -+ reset-assert-us = <10000>; -+ reset-deassert-us = <1000000>; + allwinner,emac-fix-phy-id = <0x20005c90>; + + emac_phy: ethernet-phy@1 { diff --git a/target/linux/sunxi/patches-6.1/915-ARM-dts-sun8i-kooiot-tlink-k2x.patch b/target/linux/sunxi/patches-6.1/915-ARM-dts-sun8i-kooiot-tlink-k2x.patch index a938a0e565544a..40a2bd7930c915 100644 --- a/target/linux/sunxi/patches-6.1/915-ARM-dts-sun8i-kooiot-tlink-k2x.patch +++ b/target/linux/sunxi/patches-6.1/915-ARM-dts-sun8i-kooiot-tlink-k2x.patch @@ -10,7 +10,7 @@ sun8i-r40-tlink-nano-a40i.dtb \ --- /dev/null +++ b/arch/arm/boot/dts/sun8i-r40-tlink-k2x.dts -@@ -0,0 +1,623 @@ +@@ -0,0 +1,624 @@ +/* + * Copyright (C) 2022 Dirk Chang + * @@ -255,6 +255,7 @@ + phy-handle = <&emac_phy>; + phy-supply = <®_vdd_io_3v3>; + phy-mode = "mii"; ++ reset-gpios = <&pio 7 27 GPIO_ACTIVE_LOW>; /* PH27 */ + status = "okay"; +}; + @@ -270,9 +271,9 @@ + motorcomm,led0 = <0x331>; + motorcomm,led1 = <0x30>; + -+ reset-gpios = <&pio 7 27 GPIO_ACTIVE_LOW>; /* PH27 */ -+ reset-assert-us = <10000>; -+ reset-deassert-us = <1000000>; ++ // reset-gpios = <&pio 7 27 GPIO_ACTIVE_LOW>; /* PH27 */ ++ // reset-assert-us = <10000>; ++ // reset-deassert-us = <1000000>; + }; +}; + diff --git a/target/linux/sunxi/patches-6.1/9900-sun8i-r40-second-ethernet-reset-when-open.patch b/target/linux/sunxi/patches-6.1/9900-sun8i-r40-second-ethernet-reset-when-open.patch new file mode 100644 index 00000000000000..2c8511a1d55fdb --- /dev/null +++ b/target/linux/sunxi/patches-6.1/9900-sun8i-r40-second-ethernet-reset-when-open.patch @@ -0,0 +1,96 @@ +--- a/drivers/net/ethernet/allwinner/sun4i-emac.c ++++ b/drivers/net/ethernet/allwinner/sun4i-emac.c +@@ -21,6 +21,8 @@ + #include + #include + #include ++#include ++#include + #include + #include + #include +@@ -98,6 +100,7 @@ + struct reset_control *reset; + + phy_interface_t phy_interface; ++ int phyrst; + struct dma_chan *rx_chan; + phys_addr_t emac_rx_fifo; + }; +@@ -846,6 +849,16 @@ + if (request_irq(dev->irq, &emac_interrupt, 0, dev->name, dev)) + return -EAGAIN; + ++ if (gpio_is_valid(db->phyrst)) { ++ dev_err(db->dev, "%s sun4i-emac reset gpio %d \n", __func__, db->phyrst); ++ gpio_set_value(db->phyrst, 0); ++ // msleep(300); ++ udelay(200); ++ gpio_set_value(db->phyrst, 1); ++ udelay(200); ++ // msleep(40); ++ } ++ + /* Initialize EMAC board */ + emac_reset(db); + emac_init_device(dev); +@@ -980,6 +993,7 @@ + struct net_device *ndev; + int ret = 0; + const struct emac_quirks *quirks; ++ enum of_gpio_flags flags; + + int alias_id; + +@@ -1053,6 +1067,32 @@ + goto out_assert_reset; + } + ++ db->phyrst = of_get_named_gpio_flags(pdev->dev.of_node, "reset-gpios", 0, ++ &flags); ++ if (gpio_is_valid(db->phyrst)) { ++ ++ flags = (flags == OF_GPIO_ACTIVE_LOW ? GPIOF_OUT_INIT_LOW : GPIOF_OUT_INIT_HIGH); ++ ++ ret = devm_gpio_request_one(&pdev->dev, db->phyrst, flags, ++ "sun4i_emac_reset"); ++ if (ret) { ++ dev_err(&pdev->dev, "failed to request reset gpio %d: %d\n", ++ db->phyrst, ret);; ++ ++ goto out_assert_reset; ++ } ++ ++ dev_err(&pdev->dev, "%s sun4i-emac reset gpio %d flags %d\n", ++ __func__, db->phyrst, flags);; ++ // msleep(20); ++ gpio_set_value(db->phyrst, 0); ++ udelay(200); ++ // msleep(300); ++ gpio_set_value(db->phyrst, 1); ++ udelay(200); ++ // msleep(40); ++ } ++ + ret = sunxi_sram_claim(&pdev->dev); + if (ret) { + dev_err(&pdev->dev, "Error couldn't map SRAM to device\n"); +@@ -1122,6 +1162,9 @@ + out: + dev_err(db->dev, "not found (%d).\n", ret); + ++ if (gpio_is_valid(db->phyrst)) ++ gpio_free(db->phyrst); ++ + free_netdev(ndev); + + return ret; +@@ -1143,6 +1186,8 @@ + reset_control_assert(db->reset); + irq_dispose_mapping(ndev->irq); + iounmap(db->membase); ++ if (gpio_is_valid(db->phyrst)) ++ gpio_free(db->phyrst); + free_netdev(ndev); + + dev_dbg(&pdev->dev, "released and freed device\n"); diff --git a/target/linux/sunxi/patches-6.1/9901-drivers-net-stmmac-sun8i-fix-double-disable-regulator.patch b/target/linux/sunxi/patches-6.1/9901-drivers-net-stmmac-sun8i-fix-double-disable-regulator.patch new file mode 100644 index 00000000000000..03dcb4ccfbb411 --- /dev/null +++ b/target/linux/sunxi/patches-6.1/9901-drivers-net-stmmac-sun8i-fix-double-disable-regulator.patch @@ -0,0 +1,19 @@ +--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c ++++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c +@@ -1045,8 +1045,14 @@ + if (gmac->variant->soc_has_internal_phy) + sun8i_dwmac_unpower_internal_phy(gmac); + +- regulator_disable(gmac->regulator_phy); +- regulator_disable(gmac->regulator_phy_io); ++ if (gmac->regulator_phy) { ++ regulator_disable(gmac->regulator_phy); ++ gmac->regulator_phy = NULL; ++ } ++ if (gmac->regulator_phy_io) { ++ regulator_disable(gmac->regulator_phy_io); ++ gmac->regulator_phy_io = NULL; ++ } + } + + static void sun8i_dwmac_set_mac_loopback(void __iomem *ioaddr, bool enable) diff --git a/target/linux/sunxi/patches-6.1/9902-net-stmmac-main-fix-dvr-remove-crash-when-mdio-init-failed.patch b/target/linux/sunxi/patches-6.1/9902-net-stmmac-main-fix-dvr-remove-crash-when-mdio-init-failed.patch new file mode 100644 index 00000000000000..97d41d88a9ca55 --- /dev/null +++ b/target/linux/sunxi/patches-6.1/9902-net-stmmac-main-fix-dvr-remove-crash-when-mdio-init-failed.patch @@ -0,0 +1,35 @@ +--- a/drivers/net/ethernet/stmicro/stmmac/stmmac.h ++++ b/drivers/net/ethernet/stmicro/stmmac/stmmac.h +@@ -324,6 +324,9 @@ + /* XDP BPF Program */ + unsigned long *af_xdp_zc_qps; + struct bpf_prog *xdp_prog; ++ ++ /* For unregister_netdev crash */ ++ int netdev_inited; + }; + + enum stmmac_state { +--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c ++++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +@@ -7479,6 +7479,7 @@ + __func__, ret); + goto error_netdev_register; + } ++ priv->netdev_inited = 1; + + #ifdef CONFIG_DEBUG_FS + stmmac_init_fs(ndev); +@@ -7529,8 +7530,10 @@ + + stmmac_stop_all_dma(priv); + stmmac_mac_set(priv, priv->ioaddr, false); +- netif_carrier_off(ndev); +- unregister_netdev(ndev); ++ if (priv->netdev_inited) { ++ netif_carrier_off(ndev); ++ unregister_netdev(ndev); ++ } + + #ifdef CONFIG_DEBUG_FS + stmmac_exit_fs(ndev);