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 | * Davicom 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 | |
| 11 | #define MIIM_DM9161_SCR 0x10 |
| 12 | #define MIIM_DM9161_SCR_INIT 0x0610 |
| 13 | |
| 14 | /* DM9161 Specified Configuration and Status Register */ |
| 15 | #define MIIM_DM9161_SCSR 0x11 |
| 16 | #define MIIM_DM9161_SCSR_100F 0x8000 |
| 17 | #define MIIM_DM9161_SCSR_100H 0x4000 |
| 18 | #define MIIM_DM9161_SCSR_10F 0x2000 |
| 19 | #define MIIM_DM9161_SCSR_10H 0x1000 |
| 20 | |
| 21 | /* DM9161 10BT Configuration/Status */ |
| 22 | #define MIIM_DM9161_10BTCSR 0x12 |
| 23 | #define MIIM_DM9161_10BTCSR_INIT 0x7800 |
| 24 | |
| 25 | |
| 26 | /* Davicom DM9161E */ |
| 27 | static int dm9161_config(struct phy_device *phydev) |
| 28 | { |
| 29 | phy_write(phydev, MDIO_DEVAD_NONE, MII_BMCR, BMCR_ISOLATE); |
| 30 | /* Do not bypass the scrambler/descrambler */ |
| 31 | phy_write(phydev, MDIO_DEVAD_NONE, MIIM_DM9161_SCR, |
| 32 | MIIM_DM9161_SCR_INIT); |
| 33 | /* Clear 10BTCSR to default */ |
| 34 | phy_write(phydev, MDIO_DEVAD_NONE, MIIM_DM9161_10BTCSR, |
| 35 | MIIM_DM9161_10BTCSR_INIT); |
| 36 | |
| 37 | genphy_config_aneg(phydev); |
| 38 | |
| 39 | return 0; |
| 40 | } |
| 41 | |
| 42 | static int dm9161_parse_status(struct phy_device *phydev) |
| 43 | { |
| 44 | int mii_reg; |
| 45 | |
| 46 | mii_reg = phy_read(phydev, MDIO_DEVAD_NONE, MIIM_DM9161_SCSR); |
| 47 | |
| 48 | if (mii_reg & (MIIM_DM9161_SCSR_100F | MIIM_DM9161_SCSR_100H)) |
| 49 | phydev->speed = SPEED_100; |
| 50 | else |
| 51 | phydev->speed = SPEED_10; |
| 52 | |
| 53 | if (mii_reg & (MIIM_DM9161_SCSR_100F | MIIM_DM9161_SCSR_10F)) |
| 54 | phydev->duplex = DUPLEX_FULL; |
| 55 | else |
| 56 | phydev->duplex = DUPLEX_HALF; |
| 57 | |
| 58 | return 0; |
| 59 | } |
| 60 | |
| 61 | static int dm9161_startup(struct phy_device *phydev) |
| 62 | { |
Michal Simek | b733c27 | 2016-05-18 12:46:12 +0200 | [diff] [blame] | 63 | int ret; |
Andy Fleming | 9082eea | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 64 | |
Michal Simek | b733c27 | 2016-05-18 12:46:12 +0200 | [diff] [blame] | 65 | ret = genphy_update_link(phydev); |
| 66 | if (ret) |
| 67 | return ret; |
| 68 | |
| 69 | return dm9161_parse_status(phydev); |
Andy Fleming | 9082eea | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 70 | } |
| 71 | |
Marek Vasut | 7e9ce5a | 2023-03-19 18:02:50 +0100 | [diff] [blame] | 72 | U_BOOT_PHY_DRIVER(dm9161) = { |
Andy Fleming | 9082eea | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 73 | .name = "Davicom DM9161E", |
| 74 | .uid = 0x181b880, |
| 75 | .mask = 0xffffff0, |
| 76 | .features = PHY_BASIC_FEATURES, |
| 77 | .config = &dm9161_config, |
| 78 | .startup = &dm9161_startup, |
| 79 | .shutdown = &genphy_shutdown, |
| 80 | }; |