1
2
3
4
5
6
7
8
9#include <config.h>
10#include <common.h>
11#include <linux/bitops.h>
12#include <dm.h>
13#include <phy.h>
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31int meson_gxl_startup(struct phy_device *phydev)
32{
33 unsigned int retries = 10;
34 int ret, wol, lpa, exp;
35
36restart_aneg:
37 ret = genphy_update_link(phydev);
38 if (ret)
39 return ret;
40
41 if (phydev->autoneg == AUTONEG_ENABLE) {
42
43 ret = phy_write(phydev, MDIO_DEVAD_NONE, 0x14, 0x0000);
44 if (ret)
45 return ret;
46 ret = phy_write(phydev, MDIO_DEVAD_NONE, 0x14, 0x0400);
47 if (ret)
48 return ret;
49 ret = phy_write(phydev, MDIO_DEVAD_NONE, 0x14, 0x0000);
50 if (ret)
51 return ret;
52 ret = phy_write(phydev, MDIO_DEVAD_NONE, 0x14, 0x0400);
53 if (ret)
54 return ret;
55
56
57 ret = phy_write(phydev, MDIO_DEVAD_NONE, 0x14, 0x8D80);
58 if (ret)
59 return ret;
60
61
62 wol = phy_read(phydev, MDIO_DEVAD_NONE, 0x15);
63 if (wol < 0)
64 return wol;
65
66 lpa = phy_read(phydev, MDIO_DEVAD_NONE, MII_LPA);
67 if (lpa < 0)
68 return lpa;
69
70 exp = phy_read(phydev, MDIO_DEVAD_NONE, MII_EXPANSION);
71 if (exp < 0)
72 return exp;
73
74 if (!(wol & BIT(12)) ||
75 ((exp & EXPANSION_NWAY) && !(lpa & LPA_LPACK))) {
76
77
78 if (!retries) {
79 printf("%s LPA corruption max attempts\n",
80 phydev->dev->name);
81 return -ETIMEDOUT;
82 }
83
84 printf("%s LPA corruption - aneg restart\n",
85 phydev->dev->name);
86
87 ret = genphy_restart_aneg(phydev);
88 if (ret)
89 return ret;
90
91 --retries;
92
93 goto restart_aneg;
94 }
95 }
96
97 return genphy_parse_link(phydev);
98}
99
100static int meson_gxl_phy_config(struct phy_device *phydev)
101{
102
103 phy_write(phydev, MDIO_DEVAD_NONE, 0x14, 0x0000);
104 phy_write(phydev, MDIO_DEVAD_NONE, 0x14, 0x0400);
105 phy_write(phydev, MDIO_DEVAD_NONE, 0x14, 0x0000);
106 phy_write(phydev, MDIO_DEVAD_NONE, 0x14, 0x0400);
107
108
109 phy_write(phydev, MDIO_DEVAD_NONE, 0x17, 0x8E0D);
110 phy_write(phydev, MDIO_DEVAD_NONE, 0x14, 0x4417);
111
112
113 phy_write(phydev, MDIO_DEVAD_NONE, 0x17, 0x0005);
114 phy_write(phydev, MDIO_DEVAD_NONE, 0x14, 0x5C1B);
115
116
117 phy_write(phydev, MDIO_DEVAD_NONE, 0x17, 0x029A);
118 phy_write(phydev, MDIO_DEVAD_NONE, 0x14, 0x5C1D);
119
120
121 phy_write(phydev, MDIO_DEVAD_NONE, 0x17, 0xAAAA);
122 phy_write(phydev, MDIO_DEVAD_NONE, 0x14, 0x5C1C);
123
124 return genphy_config(phydev);
125}
126
127static struct phy_driver meson_gxl_phy_driver = {
128 .name = "Meson GXL Internal PHY",
129 .uid = 0x01814400,
130 .mask = 0xfffffff0,
131 .features = PHY_BASIC_FEATURES,
132 .config = &meson_gxl_phy_config,
133 .startup = &meson_gxl_startup,
134 .shutdown = &genphy_shutdown,
135};
136
137int phy_meson_gxl_init(void)
138{
139 phy_register(&meson_gxl_phy_driver);
140
141 return 0;
142}
143