]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
board: milkv_duo: Add init code for Milk-V Duo ethernet
authorKongyang Liu <seashell11234455@gmail.com>
Sat, 20 Apr 2024 07:00:27 +0000 (15:00 +0800)
committerLeo Yu-Chi Liang <ycliang@andestech.com>
Wed, 1 May 2024 14:46:39 +0000 (22:46 +0800)
Initialize register in cv1800b ethernet phy to make it compatible with
generic phy driver

Signed-off-by: Kongyang Liu <seashell11234455@gmail.com>
Reviewed-by: Leo Yu-Chi Liang <ycliang@andestech.com>
board/sophgo/milkv_duo/Makefile
board/sophgo/milkv_duo/board.c
board/sophgo/milkv_duo/ethernet.c [new file with mode: 0644]
board/sophgo/milkv_duo/ethernet.h [new file with mode: 0644]
drivers/net/designware.c

index a087013f5c663d3d31f4d8e44759ffdbd685d07f..d0525eba853ed7110ba4a4d37b1715c7689f0650 100644 (file)
@@ -2,4 +2,5 @@
 #
 # Copyright (c) 2024, Kongyang Liu <seashell11234455@gmail.com>
 
-obj-y := board.o
+obj-y += board.o
+obj-$(CONFIG_NET) += ethernet.o
index e7e28fe2486df0146ff2e0df658d7d4d2936146d..9adbb08f5cece87751e56e6897583f2f3912a938 100644 (file)
@@ -3,11 +3,17 @@
  * Copyright (c) 2024, Kongyang Liu <seashell11234455@gmail.com>
  */
 
- #include <dm/lists.h>
+#include <dm/lists.h>
+
+#include "ethernet.h"
 
 int board_init(void)
 {
        if (IS_ENABLED(CONFIG_SYSRESET_CV1800B))
                device_bind_driver(gd->dm_root, "cv1800b_sysreset", "sysreset", NULL);
+
+       if (IS_ENABLED(CONFIG_NET))
+               cv1800b_ephy_init();
+
        return 0;
 }
diff --git a/board/sophgo/milkv_duo/ethernet.c b/board/sophgo/milkv_duo/ethernet.c
new file mode 100644 (file)
index 0000000..e997ce1
--- /dev/null
@@ -0,0 +1,79 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (c) 2024, Kongyang Liu <seashell11234455@gmail.com>
+ */
+
+#include <linux/io.h>
+#include <linux/bitops.h>
+#include <linux/mii.h>
+
+#define REG_EPHY_TOP_WRAP (u32 *)0x03009800
+#define REG_EPHY_BASE     (u32 *)0x03009000
+
+#define REG_EPHY_CTL         REG_EPHY_TOP_WRAP
+#define REG_EPHY_APB_RW_SEL  REG_EPHY_TOP_WRAP + 1
+
+/* Page 0 register */
+#define REG_PHY_ID1          REG_EPHY_BASE + MII_PHYSID1
+#define REG_PHY_ID2          REG_EPHY_BASE + MII_PHYSID2
+#define REG_PHY_PAGE_SEL     REG_EPHY_BASE + 0x1f
+
+/* Page 5 register */
+#define REG_PD_EN_CTL        REG_EPHY_BASE + 0x10
+
+/* REG_EPHY_CTL */
+#define REG_EPHY_SHUTDOWN    BIT(0)
+#define REG_EPHY_ANA_RST_N   BIT(1)
+#define REG_EPHY_DIG_RST_N   BIT(2)
+#define REG_EPHY_MAIN_RST_N  BIT(3)
+
+/* REG_PD_EN_CTL */
+#define REG_EN_ETH_TXRT          BIT(0)
+#define REG_EN_ETH_CLK100M       BIT(1)
+#define REG_EN_ETH_CLK125M       BIT(2)
+#define REG_EN_ETH_PLL_LCKDET    BIT(3)
+#define REG_EN_ETH_RXADC         BIT(4)
+#define REG_EN_ETH_RXPGA         BIT(5)
+#define REG_EN_ETH_RXRT          BIT(6)
+#define REG_EN_ETH_TXCROSSOVER   BIT(7)
+#define REG_PD_ETH_PLL           BIT(8)
+#define REG_PD_ETH_TXDAC         BIT(9)
+#define REG_PD_ETH_TXDACBST      BIT(10)
+#define REG_PD_ETH_TXECHO        BIT(11)
+#define REG_PD_ETH_TXDRV_NMOS    BIT(12)
+#define REG_PD_ETH_TXLDO         BIT(13)
+
+void cv1800b_ephy_init(void)
+{
+       u32 reg;
+       u32 phy_id = 1;
+
+       /* enable direct memory access for phy register */
+       writel(1, REG_EPHY_APB_RW_SEL);
+
+       reg = readl(REG_EPHY_CTL);
+       reg &= ~REG_EPHY_SHUTDOWN;
+       reg |= REG_EPHY_ANA_RST_N | REG_EPHY_DIG_RST_N | REG_EPHY_MAIN_RST_N;
+       writel(reg, REG_EPHY_CTL);
+
+       /* switch to page 5 */
+       writel(5 << 8, REG_PHY_PAGE_SEL);
+       reg = readl(REG_PD_EN_CTL);
+       reg &= ~(REG_PD_ETH_TXLDO | REG_PD_ETH_TXDRV_NMOS | REG_PD_ETH_TXDAC | REG_PD_ETH_PLL);
+       reg |= REG_EN_ETH_TXRT | REG_EN_ETH_CLK100M | REG_EN_ETH_CLK125M
+               | REG_EN_ETH_PLL_LCKDET | REG_EN_ETH_RXADC | REG_EN_ETH_RXPGA | REG_EN_ETH_RXRT;
+       writel(reg, REG_PD_EN_CTL);
+
+       /* switch to page 0 */
+       writel(0 << 8, REG_PHY_PAGE_SEL);
+       /*
+        * As the phy_id in the cv1800b PHY register is initialized to 0, it
+        * is necessary to manually initialize the phy_id to an arbitrary
+        * value so that it could corresponds to the generic PHY driver.
+        */
+       writel(phy_id >> 16, REG_PHY_ID1);
+       writel(phy_id & 0xffff, REG_PHY_ID2);
+
+       /* switch to MDIO control */
+       writel(0, REG_EPHY_APB_RW_SEL);
+}
diff --git a/board/sophgo/milkv_duo/ethernet.h b/board/sophgo/milkv_duo/ethernet.h
new file mode 100644 (file)
index 0000000..7b21f1b
--- /dev/null
@@ -0,0 +1,11 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright (c) 2024, Kongyang Liu <seashell11234455@gmail.com>
+ */
+
+#ifndef __CV1800B_ETHERNET_H
+#define __CV1800B_ETHERNET_H
+
+void cv1800b_ephy_init(void);
+
+#endif
index 4c1642b29a84477b292b45abb1a968b940ca99fd..682045cea2cfb058beeae01ea527e3e6d49b3518 100644 (file)
@@ -871,6 +871,7 @@ static const struct udevice_id designware_eth_ids[] = {
        { .compatible = "amlogic,meson6-dwmac" },
        { .compatible = "st,stm32-dwmac" },
        { .compatible = "snps,arc-dwmac-3.70a" },
+       { .compatible = "sophgo,cv1800b-dwmac" },
        { }
 };