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 | */ |
| 8 | #include <phy.h> |
| 9 | |
Heiko Schocher | 96d0b9e | 2013-06-04 10:58:09 +0200 | [diff] [blame] | 10 | /* 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 | |
| 17 | static 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 Vasut | 390e3fc | 2023-03-19 18:02:58 +0100 | [diff] [blame] | 35 | U_BOOT_PHY_DRIVER(dp83630) = { |
Heiko Schocher | 96d0b9e | 2013-06-04 10:58:09 +0200 | [diff] [blame] | 36 | .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 Fleming | 9082eea | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 45 | /* 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 Fleming | 9082eea | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 52 | /* NatSemi DP83865 */ |
Vincent BENOIT | 5ea667e | 2015-11-02 18:50:23 +0100 | [diff] [blame] | 53 | static int dp838xx_config(struct phy_device *phydev) |
Andy Fleming | 9082eea | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 54 | { |
| 55 | phy_write(phydev, MDIO_DEVAD_NONE, MII_BMCR, BMCR_RESET); |
| 56 | genphy_config_aneg(phydev); |
| 57 | |
| 58 | return 0; |
| 59 | } |
| 60 | |
| 61 | static 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 | |
| 91 | static int dp83865_startup(struct phy_device *phydev) |
| 92 | { |
Michal Simek | b733c27 | 2016-05-18 12:46:12 +0200 | [diff] [blame] | 93 | int ret; |
Andy Fleming | 9082eea | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 94 | |
Michal Simek | b733c27 | 2016-05-18 12:46:12 +0200 | [diff] [blame] | 95 | ret = genphy_update_link(phydev); |
| 96 | if (ret) |
| 97 | return ret; |
| 98 | |
| 99 | return dp83865_parse_status(phydev); |
Andy Fleming | 9082eea | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 100 | } |
| 101 | |
Marek Vasut | 390e3fc | 2023-03-19 18:02:58 +0100 | [diff] [blame] | 102 | U_BOOT_PHY_DRIVER(dp83865) = { |
Andy Fleming | 9082eea | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 103 | .name = "NatSemi DP83865", |
| 104 | .uid = 0x20005c70, |
| 105 | .mask = 0xfffffff0, |
| 106 | .features = PHY_GBIT_FEATURES, |
Vincent BENOIT | 5ea667e | 2015-11-02 18:50:23 +0100 | [diff] [blame] | 107 | .config = &dp838xx_config, |
Andy Fleming | 9082eea | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 108 | .startup = &dp83865_startup, |
| 109 | .shutdown = &genphy_shutdown, |
| 110 | }; |
| 111 | |
Vincent BENOIT | 5ea667e | 2015-11-02 18:50:23 +0100 | [diff] [blame] | 112 | /* NatSemi DP83848 */ |
| 113 | static 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 | |
| 134 | static int dp83848_startup(struct phy_device *phydev) |
| 135 | { |
Michal Simek | b733c27 | 2016-05-18 12:46:12 +0200 | [diff] [blame] | 136 | int ret; |
Vincent BENOIT | 5ea667e | 2015-11-02 18:50:23 +0100 | [diff] [blame] | 137 | |
Michal Simek | b733c27 | 2016-05-18 12:46:12 +0200 | [diff] [blame] | 138 | ret = genphy_update_link(phydev); |
| 139 | if (ret) |
| 140 | return ret; |
| 141 | |
| 142 | return dp83848_parse_status(phydev); |
Vincent BENOIT | 5ea667e | 2015-11-02 18:50:23 +0100 | [diff] [blame] | 143 | } |
| 144 | |
Marek Vasut | 390e3fc | 2023-03-19 18:02:58 +0100 | [diff] [blame] | 145 | U_BOOT_PHY_DRIVER(dp83848) = { |
Vincent BENOIT | 5ea667e | 2015-11-02 18:50:23 +0100 | [diff] [blame] | 146 | .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 | }; |