blob: 1a65e55402b29141800d9a1b6b25e510b73d2d12 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Andy Fleming9082eea2011-04-07 21:56:05 -05002/*
3 * National Semiconductor PHY drivers
4 *
Andy Fleming9082eea2011-04-07 21:56:05 -05005 * Copyright 2010-2011 Freescale Semiconductor, Inc.
6 * author Andy Fleming
Andy Fleming9082eea2011-04-07 21:56:05 -05007 */
8#include <phy.h>
9
Heiko Schocher96d0b9e2013-06-04 10:58:09 +020010/* NatSemi DP83630 */
11
12#define DP83630_PHY_PAGESEL_REG 0x13
13#define DP83630_PHY_PTP_COC_REG 0x14
14#define DP83630_PHY_PTP_CLKOUT_EN (1<<15)
15#define DP83630_PHY_RBR_REG 0x17
16
17static int dp83630_config(struct phy_device *phydev)
18{
19 int ptp_coc_reg;
20
21 phy_write(phydev, MDIO_DEVAD_NONE, MII_BMCR, BMCR_RESET);
22 phy_write(phydev, MDIO_DEVAD_NONE, DP83630_PHY_PAGESEL_REG, 0x6);
23 ptp_coc_reg = phy_read(phydev, MDIO_DEVAD_NONE,
24 DP83630_PHY_PTP_COC_REG);
25 ptp_coc_reg &= ~DP83630_PHY_PTP_CLKOUT_EN;
26 phy_write(phydev, MDIO_DEVAD_NONE, DP83630_PHY_PTP_COC_REG,
27 ptp_coc_reg);
28 phy_write(phydev, MDIO_DEVAD_NONE, DP83630_PHY_PAGESEL_REG, 0);
29
30 genphy_config_aneg(phydev);
31
32 return 0;
33}
34
Marek Vasut390e3fc2023-03-19 18:02:58 +010035U_BOOT_PHY_DRIVER(dp83630) = {
Heiko Schocher96d0b9e2013-06-04 10:58:09 +020036 .name = "NatSemi DP83630",
37 .uid = 0x20005ce1,
38 .mask = 0xfffffff0,
39 .features = PHY_BASIC_FEATURES,
40 .config = &dp83630_config,
41 .startup = &genphy_startup,
42 .shutdown = &genphy_shutdown,
43};
44
Andy Fleming9082eea2011-04-07 21:56:05 -050045/* DP83865 Link and Auto-Neg Status Register */
46#define MIIM_DP83865_LANR 0x11
47#define MIIM_DP83865_SPD_MASK 0x0018
48#define MIIM_DP83865_SPD_1000 0x0010
49#define MIIM_DP83865_SPD_100 0x0008
50#define MIIM_DP83865_DPX_FULL 0x0002
51
Andy Fleming9082eea2011-04-07 21:56:05 -050052/* NatSemi DP83865 */
Vincent BENOIT5ea667e2015-11-02 18:50:23 +010053static int dp838xx_config(struct phy_device *phydev)
Andy Fleming9082eea2011-04-07 21:56:05 -050054{
55 phy_write(phydev, MDIO_DEVAD_NONE, MII_BMCR, BMCR_RESET);
56 genphy_config_aneg(phydev);
57
58 return 0;
59}
60
61static int dp83865_parse_status(struct phy_device *phydev)
62{
63 int mii_reg;
64
65 mii_reg = phy_read(phydev, MDIO_DEVAD_NONE, MIIM_DP83865_LANR);
66
67 switch (mii_reg & MIIM_DP83865_SPD_MASK) {
68
69 case MIIM_DP83865_SPD_1000:
70 phydev->speed = SPEED_1000;
71 break;
72
73 case MIIM_DP83865_SPD_100:
74 phydev->speed = SPEED_100;
75 break;
76
77 default:
78 phydev->speed = SPEED_10;
79 break;
80
81 }
82
83 if (mii_reg & MIIM_DP83865_DPX_FULL)
84 phydev->duplex = DUPLEX_FULL;
85 else
86 phydev->duplex = DUPLEX_HALF;
87
88 return 0;
89}
90
91static int dp83865_startup(struct phy_device *phydev)
92{
Michal Simekb733c272016-05-18 12:46:12 +020093 int ret;
Andy Fleming9082eea2011-04-07 21:56:05 -050094
Michal Simekb733c272016-05-18 12:46:12 +020095 ret = genphy_update_link(phydev);
96 if (ret)
97 return ret;
98
99 return dp83865_parse_status(phydev);
Andy Fleming9082eea2011-04-07 21:56:05 -0500100}
101
Marek Vasut390e3fc2023-03-19 18:02:58 +0100102U_BOOT_PHY_DRIVER(dp83865) = {
Andy Fleming9082eea2011-04-07 21:56:05 -0500103 .name = "NatSemi DP83865",
104 .uid = 0x20005c70,
105 .mask = 0xfffffff0,
106 .features = PHY_GBIT_FEATURES,
Vincent BENOIT5ea667e2015-11-02 18:50:23 +0100107 .config = &dp838xx_config,
Andy Fleming9082eea2011-04-07 21:56:05 -0500108 .startup = &dp83865_startup,
109 .shutdown = &genphy_shutdown,
110};
111
Vincent BENOIT5ea667e2015-11-02 18:50:23 +0100112/* NatSemi DP83848 */
113static int dp83848_parse_status(struct phy_device *phydev)
114{
115 int mii_reg;
116
117 mii_reg = phy_read(phydev, MDIO_DEVAD_NONE, MII_BMSR);
118
119 if(mii_reg & (BMSR_100FULL | BMSR_100HALF)) {
120 phydev->speed = SPEED_100;
121 } else {
122 phydev->speed = SPEED_10;
123 }
124
125 if (mii_reg & (BMSR_10FULL | BMSR_100FULL)) {
126 phydev->duplex = DUPLEX_FULL;
127 } else {
128 phydev->duplex = DUPLEX_HALF;
129 }
130
131 return 0;
132}
133
134static int dp83848_startup(struct phy_device *phydev)
135{
Michal Simekb733c272016-05-18 12:46:12 +0200136 int ret;
Vincent BENOIT5ea667e2015-11-02 18:50:23 +0100137
Michal Simekb733c272016-05-18 12:46:12 +0200138 ret = genphy_update_link(phydev);
139 if (ret)
140 return ret;
141
142 return dp83848_parse_status(phydev);
Vincent BENOIT5ea667e2015-11-02 18:50:23 +0100143}
144
Marek Vasut390e3fc2023-03-19 18:02:58 +0100145U_BOOT_PHY_DRIVER(dp83848) = {
Vincent BENOIT5ea667e2015-11-02 18:50:23 +0100146 .name = "NatSemi DP83848",
147 .uid = 0x20005c90,
148 .mask = 0x2000ff90,
149 .features = PHY_BASIC_FEATURES,
150 .config = &dp838xx_config,
151 .startup = &dp83848_startup,
152 .shutdown = &genphy_shutdown,
153};