]> git.sur5r.net Git - u-boot/blob - drivers/net/phy/generic_10g.c
powerpc/83xx/km: make local functions and structs static
[u-boot] / drivers / net / phy / generic_10g.c
1 /*
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
31 int gen10g_shutdown(struct phy_device *phydev)
32 {
33         return 0;
34 }
35
36 int gen10g_startup(struct phy_device *phydev)
37 {
38         int devad, reg;
39         u32 mmd_mask = phydev->mmds & MDIO_DEVS_LINK;
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         /*
48          * Go through all the link-reporting devices, and make sure
49          * they're all up and happy
50          */
51         for (devad = 0; mmd_mask; devad++, mmd_mask = mmd_mask >> 1) {
52                 if (!(mmd_mask & 1))
53                         continue;
54
55                 /* Read twice because link state is latched and a
56                  * read moves the current state into the register */
57                 phy_read(phydev, devad, MDIO_STAT1);
58                 reg = phy_read(phydev, devad, MDIO_STAT1);
59                 if (reg < 0 || !(reg & MDIO_STAT1_LSTATUS))
60                         phydev->link = 0;
61         }
62
63         return 0;
64 }
65
66 int gen10g_discover_mmds(struct phy_device *phydev)
67 {
68         int mmd, stat2, devs1, devs2;
69
70         /* Assume PHY must have at least one of PMA/PMD, WIS, PCS, PHY
71          * XS or DTE XS; give up if none is present. */
72         for (mmd = 1; mmd <= 5; mmd++) {
73                 /* Is this MMD present? */
74                 stat2 = phy_read(phydev, mmd, MDIO_STAT2);
75                 if (stat2 < 0 ||
76                         (stat2 & MDIO_STAT2_DEVPRST) != MDIO_STAT2_DEVPRST_VAL)
77                         continue;
78
79                 /* It should tell us about all the other MMDs */
80                 devs1 = phy_read(phydev, mmd, MDIO_DEVS1);
81                 devs2 = phy_read(phydev, mmd, MDIO_DEVS2);
82                 if (devs1 < 0 || devs2 < 0)
83                         continue;
84
85                 phydev->mmds = devs1 | (devs2 << 16);
86                 return 0;
87         }
88
89         return 0;
90 }
91
92 int gen10g_config(struct phy_device *phydev)
93 {
94         /* For now, assume 10000baseT. Fill in later */
95         phydev->supported = phydev->advertising = SUPPORTED_10000baseT_Full;
96
97         return gen10g_discover_mmds(phydev);
98 }
99
100 struct phy_driver gen10g_driver = {
101         .uid            = 0xffffffff,
102         .mask           = 0xffffffff,
103         .name           = "Generic 10G PHY",
104         .features       = 0,
105         .config         = gen10g_config,
106         .startup        = gen10g_startup,
107         .shutdown       = gen10g_shutdown,
108 };