blob: 0a6e4107ba5dfd0f005a2c2bc06bc5d9a1dc0a4a [file] [log] [blame]
Andy Fleming9082eea2011-04-07 21:56:05 -05001/*
2 * Davicom PHY drivers
3 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02004 * SPDX-License-Identifier: GPL-2.0+
Andy Fleming9082eea2011-04-07 21:56:05 -05005 *
6 * Copyright 2010-2011 Freescale Semiconductor, Inc.
7 * author Andy Fleming
Andy Fleming9082eea2011-04-07 21:56:05 -05008 */
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 */
27static 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
42static 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
61static int dm9161_startup(struct phy_device *phydev)
62{
Michal Simekb733c272016-05-18 12:46:12 +020063 int ret;
Andy Fleming9082eea2011-04-07 21:56:05 -050064
Michal Simekb733c272016-05-18 12:46:12 +020065 ret = genphy_update_link(phydev);
66 if (ret)
67 return ret;
68
69 return dm9161_parse_status(phydev);
Andy Fleming9082eea2011-04-07 21:56:05 -050070}
71
72static struct phy_driver DM9161_driver = {
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};
81
82int phy_davicom_init(void)
83{
84 phy_register(&DM9161_driver);
85
86 return 0;
87}