Skip to content

Commit

Permalink
sunxi: port changes from 21.02
Browse files Browse the repository at this point in the history
  • Loading branch information
srdgame committed Mar 18, 2024
1 parent 6b69fcf commit 9a49d04
Show file tree
Hide file tree
Showing 7 changed files with 234 additions and 14 deletions.
71 changes: 71 additions & 0 deletions target/linux/generic/hack-6.1/9909-net-phy-dp83848-leds-init.patch
Original file line number Diff line number Diff line change
@@ -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",
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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,
+};
+
Expand All @@ -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",},
Expand Down Expand Up @@ -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 = <GIC_SPI 55 IRQ_TYPE_LEVEL_HIGH>;
+ clocks = <&ccu CLK_BUS_EMAC>;
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
+ *
Expand Down Expand Up @@ -122,15 +122,13 @@
+ phy-handle = <&emac_phy>;
+ phy-supply = <&reg_dcdc1>;
+ phy-mode = "mii";
+ reset-gpios = <&pio 7 27 GPIO_ACTIVE_LOW>; /* PH27 */
+ status = "okay";
+};
+
+&emac_mdio {
+ status = "okay";
+ phy-supply = <&reg_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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>
+ *
Expand Down Expand Up @@ -255,6 +255,7 @@
+ phy-handle = <&emac_phy>;
+ phy-supply = <&reg_vdd_io_3v3>;
+ phy-mode = "mii";
+ reset-gpios = <&pio 7 27 GPIO_ACTIVE_LOW>; /* PH27 */
+ status = "okay";
+};
+
Expand All @@ -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>;
+ };
+};
+
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <linux/mii.h>
#include <linux/module.h>
#include <linux/netdevice.h>
+#include <linux/gpio.h>
+#include <linux/of_gpio.h>
#include <linux/of_address.h>
#include <linux/of_irq.h>
#include <linux/of_mdio.h>
@@ -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");
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -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);

0 comments on commit 9a49d04

Please sign in to comment.