blob: e997ce1037f590af5aaa44954d830c34b83e0d8f [file] [log] [blame]
Kongyang Liu1fbf86c2024-04-20 15:00:27 +08001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (c) 2024, Kongyang Liu <seashell11234455@gmail.com>
4 */
5
6#include <linux/io.h>
7#include <linux/bitops.h>
8#include <linux/mii.h>
9
10#define REG_EPHY_TOP_WRAP (u32 *)0x03009800
11#define REG_EPHY_BASE (u32 *)0x03009000
12
13#define REG_EPHY_CTL REG_EPHY_TOP_WRAP
14#define REG_EPHY_APB_RW_SEL REG_EPHY_TOP_WRAP + 1
15
16/* Page 0 register */
17#define REG_PHY_ID1 REG_EPHY_BASE + MII_PHYSID1
18#define REG_PHY_ID2 REG_EPHY_BASE + MII_PHYSID2
19#define REG_PHY_PAGE_SEL REG_EPHY_BASE + 0x1f
20
21/* Page 5 register */
22#define REG_PD_EN_CTL REG_EPHY_BASE + 0x10
23
24/* REG_EPHY_CTL */
25#define REG_EPHY_SHUTDOWN BIT(0)
26#define REG_EPHY_ANA_RST_N BIT(1)
27#define REG_EPHY_DIG_RST_N BIT(2)
28#define REG_EPHY_MAIN_RST_N BIT(3)
29
30/* REG_PD_EN_CTL */
31#define REG_EN_ETH_TXRT BIT(0)
32#define REG_EN_ETH_CLK100M BIT(1)
33#define REG_EN_ETH_CLK125M BIT(2)
34#define REG_EN_ETH_PLL_LCKDET BIT(3)
35#define REG_EN_ETH_RXADC BIT(4)
36#define REG_EN_ETH_RXPGA BIT(5)
37#define REG_EN_ETH_RXRT BIT(6)
38#define REG_EN_ETH_TXCROSSOVER BIT(7)
39#define REG_PD_ETH_PLL BIT(8)
40#define REG_PD_ETH_TXDAC BIT(9)
41#define REG_PD_ETH_TXDACBST BIT(10)
42#define REG_PD_ETH_TXECHO BIT(11)
43#define REG_PD_ETH_TXDRV_NMOS BIT(12)
44#define REG_PD_ETH_TXLDO BIT(13)
45
46void cv1800b_ephy_init(void)
47{
48 u32 reg;
49 u32 phy_id = 1;
50
51 /* enable direct memory access for phy register */
52 writel(1, REG_EPHY_APB_RW_SEL);
53
54 reg = readl(REG_EPHY_CTL);
55 reg &= ~REG_EPHY_SHUTDOWN;
56 reg |= REG_EPHY_ANA_RST_N | REG_EPHY_DIG_RST_N | REG_EPHY_MAIN_RST_N;
57 writel(reg, REG_EPHY_CTL);
58
59 /* switch to page 5 */
60 writel(5 << 8, REG_PHY_PAGE_SEL);
61 reg = readl(REG_PD_EN_CTL);
62 reg &= ~(REG_PD_ETH_TXLDO | REG_PD_ETH_TXDRV_NMOS | REG_PD_ETH_TXDAC | REG_PD_ETH_PLL);
63 reg |= REG_EN_ETH_TXRT | REG_EN_ETH_CLK100M | REG_EN_ETH_CLK125M
64 | REG_EN_ETH_PLL_LCKDET | REG_EN_ETH_RXADC | REG_EN_ETH_RXPGA | REG_EN_ETH_RXRT;
65 writel(reg, REG_PD_EN_CTL);
66
67 /* switch to page 0 */
68 writel(0 << 8, REG_PHY_PAGE_SEL);
69 /*
70 * As the phy_id in the cv1800b PHY register is initialized to 0, it
71 * is necessary to manually initialize the phy_id to an arbitrary
72 * value so that it could corresponds to the generic PHY driver.
73 */
74 writel(phy_id >> 16, REG_PHY_ID1);
75 writel(phy_id & 0xffff, REG_PHY_ID2);
76
77 /* switch to MDIO control */
78 writel(0, REG_EPHY_APB_RW_SEL);
79}