blob: 315c50867dfdda864996574f1897f0d6d9dc5782 [file] [log] [blame]
Andy Fleming5f184712011-04-08 02:10:27 -05001/*
2 * Generic PHY Management code
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of
7 * the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
17 * MA 02111-1307 USA
18 *
19 *
20 * Copyright 2011 Freescale Semiconductor, Inc.
21 * author Andy Fleming
22 *
23 * Based loosely off of Linux's PHY Lib
24 */
25
26#include <config.h>
27#include <common.h>
28#include <miiphy.h>
29#include <phy.h>
30
31int gen10g_shutdown(struct phy_device *phydev)
32{
33 return 0;
34}
35
36int gen10g_startup(struct phy_device *phydev)
37{
38 int devad, reg;
39 u32 mmd_mask = phydev->mmds;
40
41 phydev->link = 1;
42
43 /* For now just lie and say it's 10G all the time */
44 phydev->speed = SPEED_10000;
45 phydev->duplex = DUPLEX_FULL;
46
47 for (devad = 0; mmd_mask; devad++, mmd_mask = mmd_mask >> 1) {
48 if (!mmd_mask & 1)
49 continue;
50
51 /* Read twice because link state is latched and a
52 * read moves the current state into the register */
53 phy_read(phydev, devad, MDIO_STAT1);
54 reg = phy_read(phydev, devad, MDIO_STAT1);
55 if (reg < 0 || !(reg & MDIO_STAT1_LSTATUS))
56 phydev->link = 0;
57 }
58
59 return 0;
60}
61
62int gen10g_discover_mmds(struct phy_device *phydev)
63{
64 int mmd, stat2, devs1, devs2;
65
66 /* Assume PHY must have at least one of PMA/PMD, WIS, PCS, PHY
67 * XS or DTE XS; give up if none is present. */
68 for (mmd = 1; mmd <= 5; mmd++) {
69 /* Is this MMD present? */
70 stat2 = phy_read(phydev, mmd, MDIO_STAT2);
71 if (stat2 < 0 ||
72 (stat2 & MDIO_STAT2_DEVPRST) != MDIO_STAT2_DEVPRST_VAL)
73 continue;
74
75 /* It should tell us about all the other MMDs */
76 devs1 = phy_read(phydev, mmd, MDIO_DEVS1);
77 devs2 = phy_read(phydev, mmd, MDIO_DEVS2);
78 if (devs1 < 0 || devs2 < 0)
79 continue;
80
81 phydev->mmds = devs1 | (devs2 << 16);
82 return 0;
83 }
84
85 return 0;
86}
87
88int gen10g_config(struct phy_device *phydev)
89{
90 /* For now, assume 10000baseT. Fill in later */
91 phydev->supported = phydev->advertising = SUPPORTED_10000baseT_Full;
92
93 return gen10g_discover_mmds(phydev);
94}
95
96struct phy_driver gen10g_driver = {
97 .uid = 0xffffffff,
98 .mask = 0xffffffff,
99 .name = "Generic 10G PHY",
100 .features = 0,
101 .config = gen10g_config,
102 .startup = gen10g_startup,
103 .shutdown = gen10g_shutdown,
104};
105