blob: a077b98d8c451e5279fdc378feafa15d7b263f01 [file] [log] [blame]
Andy Fleming9082eea2011-04-07 21:56:05 -05001/*
2 * Vitesse PHY drivers
3 *
Shengzhou Liuc18fc2c2014-11-24 17:11:59 +08004 * Copyright 2010-2014 Freescale Semiconductor, Inc.
5 * Original Author: Andy Fleming
Priyanka Jainf91ba0e2012-08-17 08:28:56 +00006 * Add vsc8662 phy support - Priyanka Jain
Wolfgang Denk1a459662013-07-08 09:37:19 +02007 * SPDX-License-Identifier: GPL-2.0+
Andy Fleming9082eea2011-04-07 21:56:05 -05008 */
9#include <miiphy.h>
10
11/* Cicada Auxiliary Control/Status Register */
12#define MIIM_CIS82xx_AUX_CONSTAT 0x1c
13#define MIIM_CIS82xx_AUXCONSTAT_INIT 0x0004
14#define MIIM_CIS82xx_AUXCONSTAT_DUPLEX 0x0020
15#define MIIM_CIS82xx_AUXCONSTAT_SPEED 0x0018
16#define MIIM_CIS82xx_AUXCONSTAT_GBIT 0x0010
17#define MIIM_CIS82xx_AUXCONSTAT_100 0x0008
18
19/* Cicada Extended Control Register 1 */
20#define MIIM_CIS82xx_EXT_CON1 0x17
21#define MIIM_CIS8201_EXTCON1_INIT 0x0000
22
23/* Cicada 8204 Extended PHY Control Register 1 */
24#define MIIM_CIS8204_EPHY_CON 0x17
25#define MIIM_CIS8204_EPHYCON_INIT 0x0006
26#define MIIM_CIS8204_EPHYCON_RGMII 0x1100
27
28/* Cicada 8204 Serial LED Control Register */
29#define MIIM_CIS8204_SLED_CON 0x1b
30#define MIIM_CIS8204_SLEDCON_INIT 0x1115
31
32/* Vitesse VSC8601 Extended PHY Control Register 1 */
Alexbb135a02016-11-22 10:55:13 -080033#define MII_VSC8601_EPHY_CTL 0x17
34#define MII_VSC8601_EPHY_CTL_RGMII_SKEW (1 << 8)
Andy Fleming9082eea2011-04-07 21:56:05 -050035
36#define PHY_EXT_PAGE_ACCESS 0x1f
Shaohui Xie7794b1a2013-03-25 07:39:31 +000037#define PHY_EXT_PAGE_ACCESS_GENERAL 0x10
38#define PHY_EXT_PAGE_ACCESS_EXTENDED3 0x3
39
40/* Vitesse VSC8574 control register */
41#define MIIM_VSC8574_MAC_SERDES_CON 0x10
42#define MIIM_VSC8574_MAC_SERDES_ANEG 0x80
43#define MIIM_VSC8574_GENERAL18 0x12
44#define MIIM_VSC8574_GENERAL19 0x13
45
46/* Vitesse VSC8574 gerenal purpose register 18 */
47#define MIIM_VSC8574_18G_SGMII 0x80f0
48#define MIIM_VSC8574_18G_QSGMII 0x80e0
49#define MIIM_VSC8574_18G_CMDSTAT 0x8000
Andy Fleming9082eea2011-04-07 21:56:05 -050050
Arpit Goele97a78c2013-08-23 20:18:05 +053051/* Vitesse VSC8514 control register */
Shengzhou Liuc18fc2c2014-11-24 17:11:59 +080052#define MIIM_VSC8514_MAC_SERDES_CON 0x10
Arpit Goele97a78c2013-08-23 20:18:05 +053053#define MIIM_VSC8514_GENERAL18 0x12
54#define MIIM_VSC8514_GENERAL19 0x13
55#define MIIM_VSC8514_GENERAL23 0x17
56
57/* Vitesse VSC8514 gerenal purpose register 18 */
58#define MIIM_VSC8514_18G_QSGMII 0x80e0
59#define MIIM_VSC8514_18G_CMDSTAT 0x8000
60
Chunhe Lanffc86672014-04-16 16:40:52 +080061/* Vitesse VSC8664 Control/Status Register */
62#define MIIM_VSC8664_SERDES_AND_SIGDET 0x13
63#define MIIM_VSC8664_ADDITIONAL_DEV 0x16
64#define MIIM_VSC8664_EPHY_CON 0x17
65#define MIIM_VSC8664_LED_CON 0x1E
66
67#define PHY_EXT_PAGE_ACCESS_EXTENDED 0x0001
68
Andy Fleming9082eea2011-04-07 21:56:05 -050069/* CIS8201 */
70static int vitesse_config(struct phy_device *phydev)
71{
72 /* Override PHY config settings */
73 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_CIS82xx_AUX_CONSTAT,
74 MIIM_CIS82xx_AUXCONSTAT_INIT);
75 /* Set up the interface mode */
76 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_CIS82xx_EXT_CON1,
77 MIIM_CIS8201_EXTCON1_INIT);
78
79 genphy_config_aneg(phydev);
80
81 return 0;
82}
83
84static int vitesse_parse_status(struct phy_device *phydev)
85{
86 int speed;
87 int mii_reg;
88
89 mii_reg = phy_read(phydev, MDIO_DEVAD_NONE, MIIM_CIS82xx_AUX_CONSTAT);
90
91 if (mii_reg & MIIM_CIS82xx_AUXCONSTAT_DUPLEX)
92 phydev->duplex = DUPLEX_FULL;
93 else
94 phydev->duplex = DUPLEX_HALF;
95
96 speed = mii_reg & MIIM_CIS82xx_AUXCONSTAT_SPEED;
97 switch (speed) {
98 case MIIM_CIS82xx_AUXCONSTAT_GBIT:
99 phydev->speed = SPEED_1000;
100 break;
101 case MIIM_CIS82xx_AUXCONSTAT_100:
102 phydev->speed = SPEED_100;
103 break;
104 default:
105 phydev->speed = SPEED_10;
106 break;
107 }
108
109 return 0;
110}
111
112static int vitesse_startup(struct phy_device *phydev)
113{
Michal Simekb733c272016-05-18 12:46:12 +0200114 int ret;
Andy Fleming9082eea2011-04-07 21:56:05 -0500115
Michal Simekb733c272016-05-18 12:46:12 +0200116 ret = genphy_update_link(phydev);
117 if (ret)
118 return ret;
119 return vitesse_parse_status(phydev);
Andy Fleming9082eea2011-04-07 21:56:05 -0500120}
121
122static int cis8204_config(struct phy_device *phydev)
123{
124 /* Override PHY config settings */
125 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_CIS82xx_AUX_CONSTAT,
126 MIIM_CIS82xx_AUXCONSTAT_INIT);
127
128 genphy_config_aneg(phydev);
129
130 if ((phydev->interface == PHY_INTERFACE_MODE_RGMII) ||
Andy Fleming9082eea2011-04-07 21:56:05 -0500131 (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID) ||
132 (phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID))
133 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_CIS8204_EPHY_CON,
134 MIIM_CIS8204_EPHYCON_INIT |
135 MIIM_CIS8204_EPHYCON_RGMII);
136 else
137 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_CIS8204_EPHY_CON,
138 MIIM_CIS8204_EPHYCON_INIT);
139
140 return 0;
141}
142
143/* Vitesse VSC8601 */
Alexbb135a02016-11-22 10:55:13 -0800144/* This adds a skew for both TX and RX clocks, so the skew should only be
145 * applied to "rgmii-id" interfaces. It may not work as expected
146 * on "rgmii-txid", "rgmii-rxid" or "rgmii" interfaces. */
147static int vsc8601_add_skew(struct phy_device *phydev)
148{
149 int ret;
150
151 ret = phy_read(phydev, MDIO_DEVAD_NONE, MII_VSC8601_EPHY_CTL);
152 if (ret < 0)
153 return ret;
154
155 ret |= MII_VSC8601_EPHY_CTL_RGMII_SKEW;
156 return phy_write(phydev, MDIO_DEVAD_NONE, MII_VSC8601_EPHY_CTL, ret);
157}
158
Kim Phillips960d70c2012-10-29 13:34:34 +0000159static int vsc8601_config(struct phy_device *phydev)
Andy Fleming9082eea2011-04-07 21:56:05 -0500160{
Alexbb135a02016-11-22 10:55:13 -0800161 int ret = 0;
Andy Fleming9082eea2011-04-07 21:56:05 -0500162
Alexbb135a02016-11-22 10:55:13 -0800163 if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID)
164 ret = vsc8601_add_skew(phydev);
Andy Fleming9082eea2011-04-07 21:56:05 -0500165
Alexbb135a02016-11-22 10:55:13 -0800166 if (ret < 0)
167 return ret;
168
169 return genphy_config_aneg(phydev);
Andy Fleming9082eea2011-04-07 21:56:05 -0500170}
171
Shaohui Xie7794b1a2013-03-25 07:39:31 +0000172static int vsc8574_config(struct phy_device *phydev)
173{
174 u32 val;
Arpit Goele97a78c2013-08-23 20:18:05 +0530175 /* configure register 19G for MAC */
Shaohui Xie7794b1a2013-03-25 07:39:31 +0000176 phy_write(phydev, MDIO_DEVAD_NONE, PHY_EXT_PAGE_ACCESS,
177 PHY_EXT_PAGE_ACCESS_GENERAL);
178
179 val = phy_read(phydev, MDIO_DEVAD_NONE, MIIM_VSC8574_GENERAL19);
180 if (phydev->interface == PHY_INTERFACE_MODE_QSGMII) {
181 /* set bit 15:14 to '01' for QSGMII mode */
182 val = (val & 0x3fff) | (1 << 14);
183 phy_write(phydev, MDIO_DEVAD_NONE,
184 MIIM_VSC8574_GENERAL19, val);
185 /* Enable 4 ports MAC QSGMII */
186 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_VSC8574_GENERAL18,
187 MIIM_VSC8574_18G_QSGMII);
188 } else {
189 /* set bit 15:14 to '00' for SGMII mode */
190 val = val & 0x3fff;
191 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_VSC8574_GENERAL19, val);
192 /* Enable 4 ports MAC SGMII */
193 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_VSC8574_GENERAL18,
194 MIIM_VSC8574_18G_SGMII);
195 }
196 val = phy_read(phydev, MDIO_DEVAD_NONE, MIIM_VSC8574_GENERAL18);
197 /* When bit 15 is cleared the command has completed */
198 while (val & MIIM_VSC8574_18G_CMDSTAT)
199 val = phy_read(phydev, MDIO_DEVAD_NONE, MIIM_VSC8574_GENERAL18);
200
201 /* Enable Serdes Auto-negotiation */
202 phy_write(phydev, MDIO_DEVAD_NONE, PHY_EXT_PAGE_ACCESS,
203 PHY_EXT_PAGE_ACCESS_EXTENDED3);
204 val = phy_read(phydev, MDIO_DEVAD_NONE, MIIM_VSC8574_MAC_SERDES_CON);
205 val = val | MIIM_VSC8574_MAC_SERDES_ANEG;
206 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_VSC8574_MAC_SERDES_CON, val);
207
208 phy_write(phydev, MDIO_DEVAD_NONE, PHY_EXT_PAGE_ACCESS, 0);
209
210 genphy_config_aneg(phydev);
211
212 return 0;
213}
214
Arpit Goele97a78c2013-08-23 20:18:05 +0530215static int vsc8514_config(struct phy_device *phydev)
216{
217 u32 val;
218 int timeout = 1000000;
219
220 /* configure register to access 19G */
221 phy_write(phydev, MDIO_DEVAD_NONE, PHY_EXT_PAGE_ACCESS,
222 PHY_EXT_PAGE_ACCESS_GENERAL);
223
224 val = phy_read(phydev, MDIO_DEVAD_NONE, MIIM_VSC8514_GENERAL19);
225 if (phydev->interface == PHY_INTERFACE_MODE_QSGMII) {
226 /* set bit 15:14 to '01' for QSGMII mode */
227 val = (val & 0x3fff) | (1 << 14);
228 phy_write(phydev, MDIO_DEVAD_NONE,
229 MIIM_VSC8514_GENERAL19, val);
230 /* Enable 4 ports MAC QSGMII */
231 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_VSC8514_GENERAL18,
232 MIIM_VSC8514_18G_QSGMII);
233 } else {
234 /*TODO Add SGMII functionality once spec sheet
235 * for VSC8514 defines complete functionality
236 */
237 }
238
239 val = phy_read(phydev, MDIO_DEVAD_NONE, MIIM_VSC8514_GENERAL18);
240 /* When bit 15 is cleared the command has completed */
241 while ((val & MIIM_VSC8514_18G_CMDSTAT) && timeout--)
242 val = phy_read(phydev, MDIO_DEVAD_NONE, MIIM_VSC8514_GENERAL18);
243
244 if (0 == timeout) {
245 printf("PHY 8514 config failed\n");
246 return -1;
247 }
248
249 phy_write(phydev, MDIO_DEVAD_NONE, PHY_EXT_PAGE_ACCESS, 0);
250
251 /* configure register to access 23 */
252 val = phy_read(phydev, MDIO_DEVAD_NONE, MIIM_VSC8514_GENERAL23);
253 /* set bits 10:8 to '000' */
254 val = (val & 0xf8ff);
255 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_VSC8514_GENERAL23, val);
256
Shengzhou Liuc18fc2c2014-11-24 17:11:59 +0800257 /* Enable Serdes Auto-negotiation */
258 phy_write(phydev, MDIO_DEVAD_NONE, PHY_EXT_PAGE_ACCESS,
259 PHY_EXT_PAGE_ACCESS_EXTENDED3);
260 val = phy_read(phydev, MDIO_DEVAD_NONE, MIIM_VSC8514_MAC_SERDES_CON);
261 val = val | MIIM_VSC8574_MAC_SERDES_ANEG;
262 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_VSC8514_MAC_SERDES_CON, val);
263 phy_write(phydev, MDIO_DEVAD_NONE, PHY_EXT_PAGE_ACCESS, 0);
264
Arpit Goele97a78c2013-08-23 20:18:05 +0530265 genphy_config_aneg(phydev);
266
267 return 0;
268}
269
Chunhe Lanffc86672014-04-16 16:40:52 +0800270static int vsc8664_config(struct phy_device *phydev)
271{
272 u32 val;
273
274 /* Enable MAC interface auto-negotiation */
275 phy_write(phydev, MDIO_DEVAD_NONE, PHY_EXT_PAGE_ACCESS, 0);
276 val = phy_read(phydev, MDIO_DEVAD_NONE, MIIM_VSC8664_EPHY_CON);
277 val |= (1 << 13);
278 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_VSC8664_EPHY_CON, val);
279
280 phy_write(phydev, MDIO_DEVAD_NONE, PHY_EXT_PAGE_ACCESS,
281 PHY_EXT_PAGE_ACCESS_EXTENDED);
282 val = phy_read(phydev, MDIO_DEVAD_NONE, MIIM_VSC8664_SERDES_AND_SIGDET);
283 val |= (1 << 11);
284 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_VSC8664_SERDES_AND_SIGDET, val);
285 phy_write(phydev, MDIO_DEVAD_NONE, PHY_EXT_PAGE_ACCESS, 0);
286
287 /* Enable LED blink */
288 val = phy_read(phydev, MDIO_DEVAD_NONE, MIIM_VSC8664_LED_CON);
289 val &= ~(1 << 2);
290 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_VSC8664_LED_CON, val);
291
292 genphy_config_aneg(phydev);
293
294 return 0;
295}
296
Andy Fleming9082eea2011-04-07 21:56:05 -0500297static struct phy_driver VSC8211_driver = {
298 .name = "Vitesse VSC8211",
299 .uid = 0xfc4b0,
300 .mask = 0xffff0,
301 .features = PHY_GBIT_FEATURES,
302 .config = &vitesse_config,
303 .startup = &vitesse_startup,
304 .shutdown = &genphy_shutdown,
305};
306
307static struct phy_driver VSC8221_driver = {
308 .name = "Vitesse VSC8221",
309 .uid = 0xfc550,
310 .mask = 0xffff0,
311 .features = PHY_GBIT_FEATURES,
312 .config = &genphy_config_aneg,
313 .startup = &vitesse_startup,
314 .shutdown = &genphy_shutdown,
315};
316
317static struct phy_driver VSC8244_driver = {
318 .name = "Vitesse VSC8244",
319 .uid = 0xfc6c0,
320 .mask = 0xffff0,
321 .features = PHY_GBIT_FEATURES,
322 .config = &genphy_config_aneg,
323 .startup = &vitesse_startup,
324 .shutdown = &genphy_shutdown,
325};
326
327static struct phy_driver VSC8234_driver = {
328 .name = "Vitesse VSC8234",
329 .uid = 0xfc620,
330 .mask = 0xffff0,
331 .features = PHY_GBIT_FEATURES,
332 .config = &genphy_config_aneg,
333 .startup = &vitesse_startup,
334 .shutdown = &genphy_shutdown,
335};
336
Shaohui Xie7794b1a2013-03-25 07:39:31 +0000337static struct phy_driver VSC8574_driver = {
338 .name = "Vitesse VSC8574",
339 .uid = 0x704a0,
340 .mask = 0xffff0,
341 .features = PHY_GBIT_FEATURES,
342 .config = &vsc8574_config,
343 .startup = &vitesse_startup,
344 .shutdown = &genphy_shutdown,
345};
346
Arpit Goele97a78c2013-08-23 20:18:05 +0530347static struct phy_driver VSC8514_driver = {
348 .name = "Vitesse VSC8514",
Codrin Ciubotariu44afbbc2014-03-26 18:13:14 +0200349 .uid = 0x70670,
Arpit Goele97a78c2013-08-23 20:18:05 +0530350 .mask = 0xffff0,
351 .features = PHY_GBIT_FEATURES,
352 .config = &vsc8514_config,
353 .startup = &vitesse_startup,
354 .shutdown = &genphy_shutdown,
355};
356
Prabhakar Kushwaha4c2620d2015-08-07 18:01:39 +0530357static struct phy_driver VSC8584_driver = {
358 .name = "Vitesse VSC8584",
359 .uid = 0x707c0,
360 .mask = 0xffff0,
361 .features = PHY_GBIT_FEATURES,
362 .config = &vsc8574_config,
363 .startup = &vitesse_startup,
364 .shutdown = &genphy_shutdown,
365};
366
Andy Fleming9082eea2011-04-07 21:56:05 -0500367static struct phy_driver VSC8601_driver = {
368 .name = "Vitesse VSC8601",
369 .uid = 0x70420,
370 .mask = 0xffff0,
371 .features = PHY_GBIT_FEATURES,
372 .config = &vsc8601_config,
373 .startup = &vitesse_startup,
374 .shutdown = &genphy_shutdown,
375};
376
377static struct phy_driver VSC8641_driver = {
378 .name = "Vitesse VSC8641",
379 .uid = 0x70430,
380 .mask = 0xffff0,
381 .features = PHY_GBIT_FEATURES,
382 .config = &genphy_config_aneg,
383 .startup = &vitesse_startup,
384 .shutdown = &genphy_shutdown,
385};
386
Priyanka Jainf91ba0e2012-08-17 08:28:56 +0000387static struct phy_driver VSC8662_driver = {
388 .name = "Vitesse VSC8662",
389 .uid = 0x70660,
390 .mask = 0xffff0,
391 .features = PHY_GBIT_FEATURES,
392 .config = &genphy_config_aneg,
393 .startup = &vitesse_startup,
394 .shutdown = &genphy_shutdown,
395};
396
Chunhe Lanffc86672014-04-16 16:40:52 +0800397static struct phy_driver VSC8664_driver = {
398 .name = "Vitesse VSC8664",
399 .uid = 0x70660,
400 .mask = 0xffff0,
401 .features = PHY_GBIT_FEATURES,
402 .config = &vsc8664_config,
403 .startup = &vitesse_startup,
404 .shutdown = &genphy_shutdown,
405};
406
Andy Fleming9082eea2011-04-07 21:56:05 -0500407/* Vitesse bought Cicada, so we'll put these here */
408static struct phy_driver cis8201_driver = {
409 .name = "CIS8201",
410 .uid = 0xfc410,
411 .mask = 0xffff0,
412 .features = PHY_GBIT_FEATURES,
413 .config = &vitesse_config,
414 .startup = &vitesse_startup,
415 .shutdown = &genphy_shutdown,
416};
417
418static struct phy_driver cis8204_driver = {
419 .name = "Cicada Cis8204",
420 .uid = 0xfc440,
421 .mask = 0xffff0,
422 .features = PHY_GBIT_FEATURES,
423 .config = &cis8204_config,
424 .startup = &vitesse_startup,
425 .shutdown = &genphy_shutdown,
426};
427
428int phy_vitesse_init(void)
429{
430 phy_register(&VSC8641_driver);
431 phy_register(&VSC8601_driver);
432 phy_register(&VSC8234_driver);
433 phy_register(&VSC8244_driver);
434 phy_register(&VSC8211_driver);
435 phy_register(&VSC8221_driver);
Shaohui Xie7794b1a2013-03-25 07:39:31 +0000436 phy_register(&VSC8574_driver);
Prabhakar Kushwaha4c2620d2015-08-07 18:01:39 +0530437 phy_register(&VSC8584_driver);
Arpit Goele97a78c2013-08-23 20:18:05 +0530438 phy_register(&VSC8514_driver);
Priyanka Jainf91ba0e2012-08-17 08:28:56 +0000439 phy_register(&VSC8662_driver);
Chunhe Lanffc86672014-04-16 16:40:52 +0800440 phy_register(&VSC8664_driver);
Andy Fleming9082eea2011-04-07 21:56:05 -0500441 phy_register(&cis8201_driver);
442 phy_register(&cis8204_driver);
443
444 return 0;
445}