blob: 72d668129851edc905964ddbb6e6b681886150a7 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Andy Fleming60ca78b2011-04-07 21:56:05 -05002/*
3 * Davicom PHY drivers
4 *
Andy Fleming60ca78b2011-04-07 21:56:05 -05005 * Copyright 2010-2011 Freescale Semiconductor, Inc.
6 * author Andy Fleming
Andy Fleming60ca78b2011-04-07 21:56:05 -05007 */
8#include <phy.h>
9
10#define MIIM_DM9161_SCR 0x10
11#define MIIM_DM9161_SCR_INIT 0x0610
12
13/* DM9161 Specified Configuration and Status Register */
14#define MIIM_DM9161_SCSR 0x11
15#define MIIM_DM9161_SCSR_100F 0x8000
16#define MIIM_DM9161_SCSR_100H 0x4000
17#define MIIM_DM9161_SCSR_10F 0x2000
18#define MIIM_DM9161_SCSR_10H 0x1000
19
20/* DM9161 10BT Configuration/Status */
21#define MIIM_DM9161_10BTCSR 0x12
22#define MIIM_DM9161_10BTCSR_INIT 0x7800
23
24
25/* Davicom DM9161E */
26static int dm9161_config(struct phy_device *phydev)
27{
28 phy_write(phydev, MDIO_DEVAD_NONE, MII_BMCR, BMCR_ISOLATE);
29 /* Do not bypass the scrambler/descrambler */
30 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_DM9161_SCR,
31 MIIM_DM9161_SCR_INIT);
32 /* Clear 10BTCSR to default */
33 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_DM9161_10BTCSR,
34 MIIM_DM9161_10BTCSR_INIT);
35
36 genphy_config_aneg(phydev);
37
38 return 0;
39}
40
41static int dm9161_parse_status(struct phy_device *phydev)
42{
43 int mii_reg;
44
45 mii_reg = phy_read(phydev, MDIO_DEVAD_NONE, MIIM_DM9161_SCSR);
46
47 if (mii_reg & (MIIM_DM9161_SCSR_100F | MIIM_DM9161_SCSR_100H))
48 phydev->speed = SPEED_100;
49 else
50 phydev->speed = SPEED_10;
51
52 if (mii_reg & (MIIM_DM9161_SCSR_100F | MIIM_DM9161_SCSR_10F))
53 phydev->duplex = DUPLEX_FULL;
54 else
55 phydev->duplex = DUPLEX_HALF;
56
57 return 0;
58}
59
60static int dm9161_startup(struct phy_device *phydev)
61{
Michal Simek5ff89662016-05-18 12:46:12 +020062 int ret;
63
64 ret = genphy_update_link(phydev);
65 if (ret)
66 return ret;
Andy Fleming60ca78b2011-04-07 21:56:05 -050067
Michal Simek5ff89662016-05-18 12:46:12 +020068 return dm9161_parse_status(phydev);
Andy Fleming60ca78b2011-04-07 21:56:05 -050069}
70
Marek Vasutb389d1c2023-03-19 18:02:50 +010071U_BOOT_PHY_DRIVER(dm9161) = {
Andy Fleming60ca78b2011-04-07 21:56:05 -050072 .name = "Davicom DM9161E",
73 .uid = 0x181b880,
74 .mask = 0xffffff0,
75 .features = PHY_BASIC_FEATURES,
76 .config = &dm9161_config,
77 .startup = &dm9161_startup,
78 .shutdown = &genphy_shutdown,
79};