2019-01-21 18:05:50 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2015-07-31 08:58:42 +00:00
|
|
|
/*
|
|
|
|
* Driver for Aquantia PHY
|
|
|
|
*
|
|
|
|
* Author: Shaohui Xie <Shaohui.Xie@freescale.com>
|
|
|
|
*
|
|
|
|
* Copyright 2015 Freescale Semiconductor, Inc.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/phy.h>
|
|
|
|
|
|
|
|
#define PHY_ID_AQ1202 0x03a1b445
|
|
|
|
#define PHY_ID_AQ2104 0x03a1b460
|
|
|
|
#define PHY_ID_AQR105 0x03a1b4a2
|
2016-10-20 08:30:31 +00:00
|
|
|
#define PHY_ID_AQR106 0x03a1b4d0
|
|
|
|
#define PHY_ID_AQR107 0x03a1b4e0
|
2015-07-31 08:58:42 +00:00
|
|
|
#define PHY_ID_AQR405 0x03a1b4b0
|
|
|
|
|
2019-02-03 20:16:18 +00:00
|
|
|
static int aqr_config_aneg(struct phy_device *phydev)
|
2015-07-31 08:58:42 +00:00
|
|
|
{
|
2018-11-10 22:43:33 +00:00
|
|
|
linkmode_copy(phydev->supported, phy_10gbit_features);
|
|
|
|
linkmode_copy(phydev->advertising, phydev->supported);
|
2015-07-31 08:58:42 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-02-03 20:16:18 +00:00
|
|
|
static int aqr_config_intr(struct phy_device *phydev)
|
2015-08-21 07:29:29 +00:00
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
|
|
|
if (phydev->interrupts == PHY_INTERRUPT_ENABLED) {
|
|
|
|
err = phy_write_mmd(phydev, MDIO_MMD_AN, 0xd401, 1);
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
err = phy_write_mmd(phydev, MDIO_MMD_VEND1, 0xff00, 1);
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
err = phy_write_mmd(phydev, MDIO_MMD_VEND1, 0xff01, 0x1001);
|
|
|
|
} else {
|
|
|
|
err = phy_write_mmd(phydev, MDIO_MMD_AN, 0xd401, 0);
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
err = phy_write_mmd(phydev, MDIO_MMD_VEND1, 0xff00, 0);
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
err = phy_write_mmd(phydev, MDIO_MMD_VEND1, 0xff01, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2019-02-03 20:16:18 +00:00
|
|
|
static int aqr_ack_interrupt(struct phy_device *phydev)
|
2015-08-21 07:29:29 +00:00
|
|
|
{
|
|
|
|
int reg;
|
|
|
|
|
|
|
|
reg = phy_read_mmd(phydev, MDIO_MMD_AN, 0xcc01);
|
|
|
|
return (reg < 0) ? reg : 0;
|
|
|
|
}
|
|
|
|
|
2019-02-03 20:16:18 +00:00
|
|
|
static int aqr_read_status(struct phy_device *phydev)
|
2015-07-31 08:58:42 +00:00
|
|
|
{
|
|
|
|
int reg;
|
|
|
|
|
|
|
|
reg = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_STAT1);
|
|
|
|
reg = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_STAT1);
|
|
|
|
if (reg & MDIO_STAT1_LSTATUS)
|
|
|
|
phydev->link = 1;
|
|
|
|
else
|
|
|
|
phydev->link = 0;
|
|
|
|
|
|
|
|
reg = phy_read_mmd(phydev, MDIO_MMD_AN, 0xc800);
|
|
|
|
mdelay(10);
|
|
|
|
reg = phy_read_mmd(phydev, MDIO_MMD_AN, 0xc800);
|
|
|
|
|
|
|
|
switch (reg) {
|
|
|
|
case 0x9:
|
|
|
|
phydev->speed = SPEED_2500;
|
|
|
|
break;
|
|
|
|
case 0x5:
|
|
|
|
phydev->speed = SPEED_1000;
|
|
|
|
break;
|
|
|
|
case 0x3:
|
|
|
|
phydev->speed = SPEED_100;
|
|
|
|
break;
|
|
|
|
case 0x7:
|
|
|
|
default:
|
|
|
|
phydev->speed = SPEED_10000;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
phydev->duplex = DUPLEX_FULL;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-02-03 20:16:18 +00:00
|
|
|
static struct phy_driver aqr_driver[] = {
|
2015-07-31 08:58:42 +00:00
|
|
|
{
|
2019-02-03 20:18:03 +00:00
|
|
|
PHY_ID_MATCH_MODEL(PHY_ID_AQ1202),
|
2015-07-31 08:58:42 +00:00
|
|
|
.name = "Aquantia AQ1202",
|
2018-09-29 21:04:16 +00:00
|
|
|
.features = PHY_10GBIT_FULL_FEATURES,
|
2018-03-02 00:08:55 +00:00
|
|
|
.aneg_done = genphy_c45_aneg_done,
|
2019-02-03 20:16:18 +00:00
|
|
|
.config_aneg = aqr_config_aneg,
|
|
|
|
.config_intr = aqr_config_intr,
|
|
|
|
.ack_interrupt = aqr_ack_interrupt,
|
|
|
|
.read_status = aqr_read_status,
|
2015-07-31 08:58:42 +00:00
|
|
|
},
|
|
|
|
{
|
2019-02-03 20:18:03 +00:00
|
|
|
PHY_ID_MATCH_MODEL(PHY_ID_AQ2104),
|
2015-07-31 08:58:42 +00:00
|
|
|
.name = "Aquantia AQ2104",
|
2018-09-29 21:04:16 +00:00
|
|
|
.features = PHY_10GBIT_FULL_FEATURES,
|
2018-03-02 00:08:55 +00:00
|
|
|
.aneg_done = genphy_c45_aneg_done,
|
2019-02-03 20:16:18 +00:00
|
|
|
.config_aneg = aqr_config_aneg,
|
|
|
|
.config_intr = aqr_config_intr,
|
|
|
|
.ack_interrupt = aqr_ack_interrupt,
|
|
|
|
.read_status = aqr_read_status,
|
2015-07-31 08:58:42 +00:00
|
|
|
},
|
|
|
|
{
|
2019-02-03 20:18:03 +00:00
|
|
|
PHY_ID_MATCH_MODEL(PHY_ID_AQR105),
|
2015-07-31 08:58:42 +00:00
|
|
|
.name = "Aquantia AQR105",
|
2018-09-29 21:04:16 +00:00
|
|
|
.features = PHY_10GBIT_FULL_FEATURES,
|
2018-03-02 00:08:55 +00:00
|
|
|
.aneg_done = genphy_c45_aneg_done,
|
2019-02-03 20:16:18 +00:00
|
|
|
.config_aneg = aqr_config_aneg,
|
|
|
|
.config_intr = aqr_config_intr,
|
|
|
|
.ack_interrupt = aqr_ack_interrupt,
|
|
|
|
.read_status = aqr_read_status,
|
2015-07-31 08:58:42 +00:00
|
|
|
},
|
2016-10-20 08:30:31 +00:00
|
|
|
{
|
2019-02-03 20:18:03 +00:00
|
|
|
PHY_ID_MATCH_MODEL(PHY_ID_AQR106),
|
2016-10-20 08:30:31 +00:00
|
|
|
.name = "Aquantia AQR106",
|
2018-09-29 21:04:16 +00:00
|
|
|
.features = PHY_10GBIT_FULL_FEATURES,
|
2018-03-02 00:08:55 +00:00
|
|
|
.aneg_done = genphy_c45_aneg_done,
|
2019-02-03 20:16:18 +00:00
|
|
|
.config_aneg = aqr_config_aneg,
|
|
|
|
.config_intr = aqr_config_intr,
|
|
|
|
.ack_interrupt = aqr_ack_interrupt,
|
|
|
|
.read_status = aqr_read_status,
|
2016-10-20 08:30:31 +00:00
|
|
|
},
|
|
|
|
{
|
2019-02-03 20:18:03 +00:00
|
|
|
PHY_ID_MATCH_MODEL(PHY_ID_AQR107),
|
2016-10-20 08:30:31 +00:00
|
|
|
.name = "Aquantia AQR107",
|
2018-09-29 21:04:16 +00:00
|
|
|
.features = PHY_10GBIT_FULL_FEATURES,
|
2018-03-02 00:08:55 +00:00
|
|
|
.aneg_done = genphy_c45_aneg_done,
|
2019-02-03 20:16:18 +00:00
|
|
|
.config_aneg = aqr_config_aneg,
|
|
|
|
.config_intr = aqr_config_intr,
|
|
|
|
.ack_interrupt = aqr_ack_interrupt,
|
|
|
|
.read_status = aqr_read_status,
|
2016-10-20 08:30:31 +00:00
|
|
|
},
|
2015-07-31 08:58:42 +00:00
|
|
|
{
|
2019-02-03 20:18:03 +00:00
|
|
|
PHY_ID_MATCH_MODEL(PHY_ID_AQR405),
|
2015-07-31 08:58:42 +00:00
|
|
|
.name = "Aquantia AQR405",
|
2018-09-29 21:04:16 +00:00
|
|
|
.features = PHY_10GBIT_FULL_FEATURES,
|
2018-03-02 00:08:55 +00:00
|
|
|
.aneg_done = genphy_c45_aneg_done,
|
2019-02-03 20:16:18 +00:00
|
|
|
.config_aneg = aqr_config_aneg,
|
|
|
|
.config_intr = aqr_config_intr,
|
|
|
|
.ack_interrupt = aqr_ack_interrupt,
|
|
|
|
.read_status = aqr_read_status,
|
2015-07-31 08:58:42 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2019-02-03 20:16:18 +00:00
|
|
|
module_phy_driver(aqr_driver);
|
2015-07-31 08:58:42 +00:00
|
|
|
|
2019-02-03 20:16:18 +00:00
|
|
|
static struct mdio_device_id __maybe_unused aqr_tbl[] = {
|
2019-02-03 20:18:03 +00:00
|
|
|
{ PHY_ID_MATCH_MODEL(PHY_ID_AQ1202) },
|
|
|
|
{ PHY_ID_MATCH_MODEL(PHY_ID_AQ2104) },
|
|
|
|
{ PHY_ID_MATCH_MODEL(PHY_ID_AQR105) },
|
|
|
|
{ PHY_ID_MATCH_MODEL(PHY_ID_AQR106) },
|
|
|
|
{ PHY_ID_MATCH_MODEL(PHY_ID_AQR107) },
|
|
|
|
{ PHY_ID_MATCH_MODEL(PHY_ID_AQR405) },
|
2015-07-31 08:58:42 +00:00
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
2019-02-03 20:16:18 +00:00
|
|
|
MODULE_DEVICE_TABLE(mdio, aqr_tbl);
|
2015-07-31 08:58:42 +00:00
|
|
|
|
|
|
|
MODULE_DESCRIPTION("Aquantia PHY driver");
|
|
|
|
MODULE_AUTHOR("Shaohui Xie <Shaohui.Xie@freescale.com>");
|
|
|
|
MODULE_LICENSE("GPL v2");
|