Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Andy Fleming | 9082eea | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 2 | /* |
| 3 | * National Semiconductor PHY drivers |
| 4 | * |
Andy Fleming | 9082eea | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 5 | * Copyright 2010-2011 Freescale Semiconductor, Inc. |
| 6 | * author Andy Fleming |
Andy Fleming | 9082eea | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 7 | */ |
Joe Hershberger | 05b60ac | 2018-07-25 12:59:22 -0500 | [diff] [blame] | 8 | #include <common.h> |
Andy Fleming | 9082eea | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 9 | #include <phy.h> |
| 10 | |
Heiko Schocher | 96d0b9e | 2013-06-04 10:58:09 +0200 | [diff] [blame] | 11 | /* NatSemi DP83630 */ |
| 12 | |
| 13 | #define DP83630_PHY_PAGESEL_REG 0x13 |
| 14 | #define DP83630_PHY_PTP_COC_REG 0x14 |
| 15 | #define DP83630_PHY_PTP_CLKOUT_EN (1<<15) |
| 16 | #define DP83630_PHY_RBR_REG 0x17 |
| 17 | |
| 18 | static int dp83630_config(struct phy_device *phydev) |
| 19 | { |
| 20 | int ptp_coc_reg; |
| 21 | |
| 22 | phy_write(phydev, MDIO_DEVAD_NONE, MII_BMCR, BMCR_RESET); |
| 23 | phy_write(phydev, MDIO_DEVAD_NONE, DP83630_PHY_PAGESEL_REG, 0x6); |
| 24 | ptp_coc_reg = phy_read(phydev, MDIO_DEVAD_NONE, |
| 25 | DP83630_PHY_PTP_COC_REG); |
| 26 | ptp_coc_reg &= ~DP83630_PHY_PTP_CLKOUT_EN; |
| 27 | phy_write(phydev, MDIO_DEVAD_NONE, DP83630_PHY_PTP_COC_REG, |
| 28 | ptp_coc_reg); |
| 29 | phy_write(phydev, MDIO_DEVAD_NONE, DP83630_PHY_PAGESEL_REG, 0); |
| 30 | |
| 31 | genphy_config_aneg(phydev); |
| 32 | |
| 33 | return 0; |
| 34 | } |
| 35 | |
Marek Vasut | 390e3fc | 2023-03-19 18:02:58 +0100 | [diff] [blame] | 36 | U_BOOT_PHY_DRIVER(dp83630) = { |
Heiko Schocher | 96d0b9e | 2013-06-04 10:58:09 +0200 | [diff] [blame] | 37 | .name = "NatSemi DP83630", |
| 38 | .uid = 0x20005ce1, |
| 39 | .mask = 0xfffffff0, |
| 40 | .features = PHY_BASIC_FEATURES, |
| 41 | .config = &dp83630_config, |
| 42 | .startup = &genphy_startup, |
| 43 | .shutdown = &genphy_shutdown, |
| 44 | }; |
| 45 | |
| 46 | |
Andy Fleming | 9082eea | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 47 | /* DP83865 Link and Auto-Neg Status Register */ |
| 48 | #define MIIM_DP83865_LANR 0x11 |
| 49 | #define MIIM_DP83865_SPD_MASK 0x0018 |
| 50 | #define MIIM_DP83865_SPD_1000 0x0010 |
| 51 | #define MIIM_DP83865_SPD_100 0x0008 |
| 52 | #define MIIM_DP83865_DPX_FULL 0x0002 |
| 53 | |
| 54 | |
| 55 | /* NatSemi DP83865 */ |
Vincent BENOIT | 5ea667e | 2015-11-02 18:50:23 +0100 | [diff] [blame] | 56 | static int dp838xx_config(struct phy_device *phydev) |
Andy Fleming | 9082eea | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 57 | { |
| 58 | phy_write(phydev, MDIO_DEVAD_NONE, MII_BMCR, BMCR_RESET); |
| 59 | genphy_config_aneg(phydev); |
| 60 | |
| 61 | return 0; |
| 62 | } |
| 63 | |
| 64 | static int dp83865_parse_status(struct phy_device *phydev) |
| 65 | { |
| 66 | int mii_reg; |
| 67 | |
| 68 | mii_reg = phy_read(phydev, MDIO_DEVAD_NONE, MIIM_DP83865_LANR); |
| 69 | |
| 70 | switch (mii_reg & MIIM_DP83865_SPD_MASK) { |
| 71 | |
| 72 | case MIIM_DP83865_SPD_1000: |
| 73 | phydev->speed = SPEED_1000; |
| 74 | break; |
| 75 | |
| 76 | case MIIM_DP83865_SPD_100: |
| 77 | phydev->speed = SPEED_100; |
| 78 | break; |
| 79 | |
| 80 | default: |
| 81 | phydev->speed = SPEED_10; |
| 82 | break; |
| 83 | |
| 84 | } |
| 85 | |
| 86 | if (mii_reg & MIIM_DP83865_DPX_FULL) |
| 87 | phydev->duplex = DUPLEX_FULL; |
| 88 | else |
| 89 | phydev->duplex = DUPLEX_HALF; |
| 90 | |
| 91 | return 0; |
| 92 | } |
| 93 | |
| 94 | static int dp83865_startup(struct phy_device *phydev) |
| 95 | { |
Michal Simek | b733c27 | 2016-05-18 12:46:12 +0200 | [diff] [blame] | 96 | int ret; |
Andy Fleming | 9082eea | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 97 | |
Michal Simek | b733c27 | 2016-05-18 12:46:12 +0200 | [diff] [blame] | 98 | ret = genphy_update_link(phydev); |
| 99 | if (ret) |
| 100 | return ret; |
| 101 | |
| 102 | return dp83865_parse_status(phydev); |
Andy Fleming | 9082eea | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | |
Marek Vasut | 390e3fc | 2023-03-19 18:02:58 +0100 | [diff] [blame] | 106 | U_BOOT_PHY_DRIVER(dp83865) = { |
Andy Fleming | 9082eea | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 107 | .name = "NatSemi DP83865", |
| 108 | .uid = 0x20005c70, |
| 109 | .mask = 0xfffffff0, |
| 110 | .features = PHY_GBIT_FEATURES, |
Vincent BENOIT | 5ea667e | 2015-11-02 18:50:23 +0100 | [diff] [blame] | 111 | .config = &dp838xx_config, |
Andy Fleming | 9082eea | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 112 | .startup = &dp83865_startup, |
| 113 | .shutdown = &genphy_shutdown, |
| 114 | }; |
| 115 | |
Vincent BENOIT | 5ea667e | 2015-11-02 18:50:23 +0100 | [diff] [blame] | 116 | /* NatSemi DP83848 */ |
| 117 | static int dp83848_parse_status(struct phy_device *phydev) |
| 118 | { |
| 119 | int mii_reg; |
| 120 | |
| 121 | mii_reg = phy_read(phydev, MDIO_DEVAD_NONE, MII_BMSR); |
| 122 | |
| 123 | if(mii_reg & (BMSR_100FULL | BMSR_100HALF)) { |
| 124 | phydev->speed = SPEED_100; |
| 125 | } else { |
| 126 | phydev->speed = SPEED_10; |
| 127 | } |
| 128 | |
| 129 | if (mii_reg & (BMSR_10FULL | BMSR_100FULL)) { |
| 130 | phydev->duplex = DUPLEX_FULL; |
| 131 | } else { |
| 132 | phydev->duplex = DUPLEX_HALF; |
| 133 | } |
| 134 | |
| 135 | return 0; |
| 136 | } |
| 137 | |
| 138 | static int dp83848_startup(struct phy_device *phydev) |
| 139 | { |
Michal Simek | b733c27 | 2016-05-18 12:46:12 +0200 | [diff] [blame] | 140 | int ret; |
Vincent BENOIT | 5ea667e | 2015-11-02 18:50:23 +0100 | [diff] [blame] | 141 | |
Michal Simek | b733c27 | 2016-05-18 12:46:12 +0200 | [diff] [blame] | 142 | ret = genphy_update_link(phydev); |
| 143 | if (ret) |
| 144 | return ret; |
| 145 | |
| 146 | return dp83848_parse_status(phydev); |
Vincent BENOIT | 5ea667e | 2015-11-02 18:50:23 +0100 | [diff] [blame] | 147 | } |
| 148 | |
Marek Vasut | 390e3fc | 2023-03-19 18:02:58 +0100 | [diff] [blame] | 149 | U_BOOT_PHY_DRIVER(dp83848) = { |
Vincent BENOIT | 5ea667e | 2015-11-02 18:50:23 +0100 | [diff] [blame] | 150 | .name = "NatSemi DP83848", |
| 151 | .uid = 0x20005c90, |
| 152 | .mask = 0x2000ff90, |
| 153 | .features = PHY_BASIC_FEATURES, |
| 154 | .config = &dp838xx_config, |
| 155 | .startup = &dp83848_startup, |
| 156 | .shutdown = &genphy_shutdown, |
| 157 | }; |