1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * LXT PHY drivers
4 *
5 * Copyright 2010-2011 Freescale Semiconductor, Inc.
6 * author Andy Fleming
7 */
8 #include <phy.h>
9
10 /* LXT971 Status 2 registers */
11 #define MIIM_LXT971_SR2 0x11 /* Status Register 2 */
12 #define MIIM_LXT971_SR2_SPEED_MASK 0x4200
13 #define MIIM_LXT971_SR2_10HDX 0x0000 /* 10 Mbit half duplex selected */
14 #define MIIM_LXT971_SR2_10FDX 0x0200 /* 10 Mbit full duplex selected */
15 #define MIIM_LXT971_SR2_100HDX 0x4000 /* 100 Mbit half duplex selected */
16 #define MIIM_LXT971_SR2_100FDX 0x4200 /* 100 Mbit full duplex selected */
17
18
19 /* LXT971 */
lxt971_parse_status(struct phy_device * phydev)20 static int lxt971_parse_status(struct phy_device *phydev)
21 {
22 int mii_reg;
23 int speed;
24
25 mii_reg = phy_read(phydev, MDIO_DEVAD_NONE, MIIM_LXT971_SR2);
26 speed = mii_reg & MIIM_LXT971_SR2_SPEED_MASK;
27
28 switch (speed) {
29 case MIIM_LXT971_SR2_10HDX:
30 phydev->speed = SPEED_10;
31 phydev->duplex = DUPLEX_HALF;
32 break;
33 case MIIM_LXT971_SR2_10FDX:
34 phydev->speed = SPEED_10;
35 phydev->duplex = DUPLEX_FULL;
36 break;
37 case MIIM_LXT971_SR2_100HDX:
38 phydev->speed = SPEED_100;
39 phydev->duplex = DUPLEX_HALF;
40 break;
41 default:
42 phydev->speed = SPEED_100;
43 phydev->duplex = DUPLEX_FULL;
44 }
45
46 return 0;
47 }
48
lxt971_startup(struct phy_device * phydev)49 static int lxt971_startup(struct phy_device *phydev)
50 {
51 int ret;
52
53 ret = genphy_update_link(phydev);
54 if (ret)
55 return ret;
56
57 return lxt971_parse_status(phydev);
58 }
59
60 static struct phy_driver LXT971_driver = {
61 .name = "LXT971",
62 .uid = 0x1378e0,
63 .mask = 0xfffff0,
64 .features = PHY_BASIC_FEATURES,
65 .config = &genphy_config_aneg,
66 .startup = &lxt971_startup,
67 .shutdown = &genphy_shutdown,
68 };
69
phy_lxt_init(void)70 int phy_lxt_init(void)
71 {
72 phy_register(&LXT971_driver);
73
74 return 0;
75 }
76