2 * Driver for Aquantia PHY
4 * Author: Shaohui Xie <Shaohui.Xie@freescale.com>
6 * Copyright 2015 Freescale Semiconductor, Inc.
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.
13 #include <linux/kernel.h>
14 #include <linux/module.h>
15 #include <linux/delay.h>
16 #include <linux/mii.h>
17 #include <linux/ethtool.h>
18 #include <linux/phy.h>
19 #include <linux/mdio.h>
21 #define PHY_ID_AQ1202 0x03a1b445
22 #define PHY_ID_AQ2104 0x03a1b460
23 #define PHY_ID_AQR105 0x03a1b4a2
24 #define PHY_ID_AQR106 0x03a1b4d0
25 #define PHY_ID_AQR107 0x03a1b4e0
26 #define PHY_ID_AQR405 0x03a1b4b0
28 #define PHY_AQUANTIA_FEATURES (SUPPORTED_10000baseT_Full | \
29 SUPPORTED_1000baseT_Full | \
30 SUPPORTED_100baseT_Full | \
33 static int aquantia_config_aneg(struct phy_device
*phydev
)
35 phydev
->supported
= PHY_AQUANTIA_FEATURES
;
36 phydev
->advertising
= phydev
->supported
;
41 static int aquantia_config_intr(struct phy_device
*phydev
)
45 if (phydev
->interrupts
== PHY_INTERRUPT_ENABLED
) {
46 err
= phy_write_mmd(phydev
, MDIO_MMD_AN
, 0xd401, 1);
50 err
= phy_write_mmd(phydev
, MDIO_MMD_VEND1
, 0xff00, 1);
54 err
= phy_write_mmd(phydev
, MDIO_MMD_VEND1
, 0xff01, 0x1001);
56 err
= phy_write_mmd(phydev
, MDIO_MMD_AN
, 0xd401, 0);
60 err
= phy_write_mmd(phydev
, MDIO_MMD_VEND1
, 0xff00, 0);
64 err
= phy_write_mmd(phydev
, MDIO_MMD_VEND1
, 0xff01, 0);
70 static int aquantia_ack_interrupt(struct phy_device
*phydev
)
74 reg
= phy_read_mmd(phydev
, MDIO_MMD_AN
, 0xcc01);
75 return (reg
< 0) ? reg
: 0;
78 static int aquantia_read_status(struct phy_device
*phydev
)
82 reg
= phy_read_mmd(phydev
, MDIO_MMD_AN
, MDIO_STAT1
);
83 reg
= phy_read_mmd(phydev
, MDIO_MMD_AN
, MDIO_STAT1
);
84 if (reg
& MDIO_STAT1_LSTATUS
)
89 reg
= phy_read_mmd(phydev
, MDIO_MMD_AN
, 0xc800);
91 reg
= phy_read_mmd(phydev
, MDIO_MMD_AN
, 0xc800);
95 phydev
->speed
= SPEED_2500
;
98 phydev
->speed
= SPEED_1000
;
101 phydev
->speed
= SPEED_100
;
105 phydev
->speed
= SPEED_10000
;
108 phydev
->duplex
= DUPLEX_FULL
;
113 static struct phy_driver aquantia_driver
[] = {
115 .phy_id
= PHY_ID_AQ1202
,
116 .phy_id_mask
= 0xfffffff0,
117 .name
= "Aquantia AQ1202",
118 .features
= PHY_AQUANTIA_FEATURES
,
119 .flags
= PHY_HAS_INTERRUPT
,
120 .aneg_done
= genphy_c45_aneg_done
,
121 .config_aneg
= aquantia_config_aneg
,
122 .config_intr
= aquantia_config_intr
,
123 .ack_interrupt
= aquantia_ack_interrupt
,
124 .read_status
= aquantia_read_status
,
127 .phy_id
= PHY_ID_AQ2104
,
128 .phy_id_mask
= 0xfffffff0,
129 .name
= "Aquantia AQ2104",
130 .features
= PHY_AQUANTIA_FEATURES
,
131 .flags
= PHY_HAS_INTERRUPT
,
132 .aneg_done
= genphy_c45_aneg_done
,
133 .config_aneg
= aquantia_config_aneg
,
134 .config_intr
= aquantia_config_intr
,
135 .ack_interrupt
= aquantia_ack_interrupt
,
136 .read_status
= aquantia_read_status
,
139 .phy_id
= PHY_ID_AQR105
,
140 .phy_id_mask
= 0xfffffff0,
141 .name
= "Aquantia AQR105",
142 .features
= PHY_AQUANTIA_FEATURES
,
143 .flags
= PHY_HAS_INTERRUPT
,
144 .aneg_done
= genphy_c45_aneg_done
,
145 .config_aneg
= aquantia_config_aneg
,
146 .config_intr
= aquantia_config_intr
,
147 .ack_interrupt
= aquantia_ack_interrupt
,
148 .read_status
= aquantia_read_status
,
151 .phy_id
= PHY_ID_AQR106
,
152 .phy_id_mask
= 0xfffffff0,
153 .name
= "Aquantia AQR106",
154 .features
= PHY_AQUANTIA_FEATURES
,
155 .flags
= PHY_HAS_INTERRUPT
,
156 .aneg_done
= genphy_c45_aneg_done
,
157 .config_aneg
= aquantia_config_aneg
,
158 .config_intr
= aquantia_config_intr
,
159 .ack_interrupt
= aquantia_ack_interrupt
,
160 .read_status
= aquantia_read_status
,
163 .phy_id
= PHY_ID_AQR107
,
164 .phy_id_mask
= 0xfffffff0,
165 .name
= "Aquantia AQR107",
166 .features
= PHY_AQUANTIA_FEATURES
,
167 .flags
= PHY_HAS_INTERRUPT
,
168 .aneg_done
= genphy_c45_aneg_done
,
169 .config_aneg
= aquantia_config_aneg
,
170 .config_intr
= aquantia_config_intr
,
171 .ack_interrupt
= aquantia_ack_interrupt
,
172 .read_status
= aquantia_read_status
,
175 .phy_id
= PHY_ID_AQR405
,
176 .phy_id_mask
= 0xfffffff0,
177 .name
= "Aquantia AQR405",
178 .features
= PHY_AQUANTIA_FEATURES
,
179 .flags
= PHY_HAS_INTERRUPT
,
180 .aneg_done
= genphy_c45_aneg_done
,
181 .config_aneg
= aquantia_config_aneg
,
182 .config_intr
= aquantia_config_intr
,
183 .ack_interrupt
= aquantia_ack_interrupt
,
184 .read_status
= aquantia_read_status
,
188 module_phy_driver(aquantia_driver
);
190 static struct mdio_device_id __maybe_unused aquantia_tbl
[] = {
191 { PHY_ID_AQ1202
, 0xfffffff0 },
192 { PHY_ID_AQ2104
, 0xfffffff0 },
193 { PHY_ID_AQR105
, 0xfffffff0 },
194 { PHY_ID_AQR106
, 0xfffffff0 },
195 { PHY_ID_AQR107
, 0xfffffff0 },
196 { PHY_ID_AQR405
, 0xfffffff0 },
200 MODULE_DEVICE_TABLE(mdio
, aquantia_tbl
);
202 MODULE_DESCRIPTION("Aquantia PHY driver");
203 MODULE_AUTHOR("Shaohui Xie <Shaohui.Xie@freescale.com>");
204 MODULE_LICENSE("GPL v2");