blob: 52c7189b904af6e3ef6998158ca5f3ed1ac0f549 [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
Andy Fleming60ca78b2011-04-07 21:56:05 -050024/* Davicom DM9161E */
25static int dm9161_config(struct phy_device *phydev)
26{
27 phy_write(phydev, MDIO_DEVAD_NONE, MII_BMCR, BMCR_ISOLATE);
28 /* Do not bypass the scrambler/descrambler */
29 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_DM9161_SCR,
30 MIIM_DM9161_SCR_INIT);
31 /* Clear 10BTCSR to default */
32 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_DM9161_10BTCSR,
33 MIIM_DM9161_10BTCSR_INIT);
34
35 genphy_config_aneg(phydev);
36
37 return 0;
38}
39
40static int dm9161_parse_status(struct phy_device *phydev)
41{
42 int mii_reg;
43
44 mii_reg = phy_read(phydev, MDIO_DEVAD_NONE, MIIM_DM9161_SCSR);
45
46 if (mii_reg & (MIIM_DM9161_SCSR_100F | MIIM_DM9161_SCSR_100H))
47 phydev->speed = SPEED_100;
48 else
49 phydev->speed = SPEED_10;
50
51 if (mii_reg & (MIIM_DM9161_SCSR_100F | MIIM_DM9161_SCSR_10F))
52 phydev->duplex = DUPLEX_FULL;
53 else
54 phydev->duplex = DUPLEX_HALF;
55
56 return 0;
57}
58
59static int dm9161_startup(struct phy_device *phydev)
60{
Michal Simek5ff89662016-05-18 12:46:12 +020061 int ret;
62
63 ret = genphy_update_link(phydev);
64 if (ret)
65 return ret;
Andy Fleming60ca78b2011-04-07 21:56:05 -050066
Michal Simek5ff89662016-05-18 12:46:12 +020067 return dm9161_parse_status(phydev);
Andy Fleming60ca78b2011-04-07 21:56:05 -050068}
69
Marek Vasutb389d1c2023-03-19 18:02:50 +010070U_BOOT_PHY_DRIVER(dm9161) = {
Andy Fleming60ca78b2011-04-07 21:56:05 -050071 .name = "Davicom DM9161E",
72 .uid = 0x181b880,
73 .mask = 0xffffff0,
74 .features = PHY_BASIC_FEATURES,
75 .config = &dm9161_config,
76 .startup = &dm9161_startup,
77 .shutdown = &genphy_shutdown,
78};