blob: 7dcb5aada1c416bad656c1d57a6a6ecac149c3fa [file] [log] [blame]
Shaohui Xief61687c2015-07-17 11:19:46 +08001/*
2 * Driver for Teranetics PHY
3 *
4 * Author: Shaohui Xie <Shaohui.Xie@freescale.com>
5 *
6 * Copyright 2015 Freescale Semiconductor, Inc.
7 *
8 * This file is licensed under the terms of the GNU General Public License
9 * version 2. This program is licensed "as is" without any warranty of any
10 * kind, whether express or implied.
11 */
12
13#include <linux/kernel.h>
14#include <linux/module.h>
15#include <linux/mii.h>
16#include <linux/ethtool.h>
17#include <linux/mdio.h>
18#include <linux/phy.h>
19
20MODULE_DESCRIPTION("Teranetics PHY driver");
21MODULE_AUTHOR("Shaohui Xie <Shaohui.Xie@freescale.com>");
22MODULE_LICENSE("GPL v2");
23
24#define PHY_ID_TN2020 0x00a19410
25#define MDIO_PHYXS_LNSTAT_SYNC0 0x0001
26#define MDIO_PHYXS_LNSTAT_SYNC1 0x0002
27#define MDIO_PHYXS_LNSTAT_SYNC2 0x0004
28#define MDIO_PHYXS_LNSTAT_SYNC3 0x0008
29#define MDIO_PHYXS_LNSTAT_ALIGN 0x1000
30
31#define MDIO_PHYXS_LANE_READY (MDIO_PHYXS_LNSTAT_SYNC0 | \
32 MDIO_PHYXS_LNSTAT_SYNC1 | \
33 MDIO_PHYXS_LNSTAT_SYNC2 | \
34 MDIO_PHYXS_LNSTAT_SYNC3 | \
35 MDIO_PHYXS_LNSTAT_ALIGN)
36
37static int teranetics_config_init(struct phy_device *phydev)
38{
39 phydev->supported = SUPPORTED_10000baseT_Full;
40 phydev->advertising = SUPPORTED_10000baseT_Full;
41
42 return 0;
43}
44
45static int teranetics_soft_reset(struct phy_device *phydev)
46{
47 return 0;
48}
49
50static int teranetics_aneg_done(struct phy_device *phydev)
51{
52 int reg;
53
54 reg = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_STAT1);
55 return (reg < 0) ? reg : (reg & BMSR_ANEGCOMPLETE);
56}
57
58static int teranetics_config_aneg(struct phy_device *phydev)
59{
60 return 0;
61}
62
63static int teranetics_read_status(struct phy_device *phydev)
64{
65 int reg;
66
67 phydev->link = 1;
68
69 phydev->speed = SPEED_10000;
70 phydev->duplex = DUPLEX_FULL;
71
72 if (!phy_read_mmd(phydev, MDIO_MMD_VEND1, 93)) {
73 reg = phy_read_mmd(phydev, MDIO_MMD_PHYXS, MDIO_PHYXS_LNSTAT);
74 if (reg < 0 ||
75 !((reg & MDIO_PHYXS_LANE_READY) == MDIO_PHYXS_LANE_READY)) {
76 phydev->link = 0;
77 return 0;
78 }
79
80 reg = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_STAT1);
81 if (reg < 0 || !(reg & MDIO_STAT1_LSTATUS))
82 phydev->link = 0;
83 }
84
85 return 0;
86}
87
88static int teranetics_match_phy_device(struct phy_device *phydev)
89{
90 return phydev->c45_ids.device_ids[3] == PHY_ID_TN2020;
91}
92
93static struct phy_driver teranetics_driver[] = {
94{
95 .phy_id = PHY_ID_TN2020,
96 .phy_id_mask = 0xffffffff,
97 .name = "Teranetics TN2020",
98 .soft_reset = teranetics_soft_reset,
99 .aneg_done = teranetics_aneg_done,
100 .config_init = teranetics_config_init,
101 .config_aneg = teranetics_config_aneg,
102 .read_status = teranetics_read_status,
103 .match_phy_device = teranetics_match_phy_device,
104 .driver = { .owner = THIS_MODULE,},
105},
106};
107
108static int __init teranetics_init(void)
109{
110 return phy_drivers_register(teranetics_driver,
111 ARRAY_SIZE(teranetics_driver));
112}
113
114static void __exit teranetics_exit(void)
115{
116 return phy_drivers_unregister(teranetics_driver,
117 ARRAY_SIZE(teranetics_driver));
118}
119
120module_init(teranetics_init);
121module_exit(teranetics_exit);
122
123static struct mdio_device_id __maybe_unused teranetics_tbl[] = {
124 { PHY_ID_TN2020, 0xffffffff },
125 { }
126};
127
128MODULE_DEVICE_TABLE(mdio, teranetics_tbl);