mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-12-05 01:54:09 +08:00
90ce665c6a
There is a recurring pattern throughout some of the PHY code converting a devad and regnum to our packed clause 45 representation. Rather than having this scattered around the code, let's put a common translation function in mdio.h, and provide some register accessors. Convert the phylib core, phylink, bcm87xx and cortina to use these. Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk> Reviewed-by: Andrew Lunn <andrew@lunn.ch> Reviewed-by: Florian Fainelli <f.fainelli@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
100 lines
2.1 KiB
C
100 lines
2.1 KiB
C
// SPDX-License-Identifier: GPL-2.0+
|
|
/*
|
|
* Copyright 2017 NXP
|
|
*
|
|
* CORTINA is a registered trademark of Cortina Systems, Inc.
|
|
*
|
|
*/
|
|
#include <linux/module.h>
|
|
#include <linux/phy.h>
|
|
|
|
#define PHY_ID_CS4340 0x13e51002
|
|
|
|
#define VILLA_GLOBAL_CHIP_ID_LSB 0x0
|
|
#define VILLA_GLOBAL_CHIP_ID_MSB 0x1
|
|
|
|
#define VILLA_GLOBAL_GPIO_1_INTS 0x017
|
|
|
|
static int cortina_read_reg(struct phy_device *phydev, u16 regnum)
|
|
{
|
|
return mdiobus_c45_read(phydev->mdio.bus, phydev->mdio.addr, 0, regnum);
|
|
}
|
|
|
|
static int cortina_read_status(struct phy_device *phydev)
|
|
{
|
|
int gpio_int_status, ret = 0;
|
|
|
|
gpio_int_status = cortina_read_reg(phydev, VILLA_GLOBAL_GPIO_1_INTS);
|
|
if (gpio_int_status < 0) {
|
|
ret = gpio_int_status;
|
|
goto err;
|
|
}
|
|
|
|
if (gpio_int_status & 0x8) {
|
|
/* up when edc_convergedS set */
|
|
phydev->speed = SPEED_10000;
|
|
phydev->duplex = DUPLEX_FULL;
|
|
phydev->link = 1;
|
|
} else {
|
|
phydev->link = 0;
|
|
}
|
|
|
|
err:
|
|
return ret;
|
|
}
|
|
|
|
static int cortina_probe(struct phy_device *phydev)
|
|
{
|
|
u32 phy_id = 0;
|
|
int id_lsb = 0, id_msb = 0;
|
|
|
|
/* Read device id from phy registers. */
|
|
id_lsb = cortina_read_reg(phydev, VILLA_GLOBAL_CHIP_ID_LSB);
|
|
if (id_lsb < 0)
|
|
return -ENXIO;
|
|
|
|
phy_id = id_lsb << 16;
|
|
|
|
id_msb = cortina_read_reg(phydev, VILLA_GLOBAL_CHIP_ID_MSB);
|
|
if (id_msb < 0)
|
|
return -ENXIO;
|
|
|
|
phy_id |= id_msb;
|
|
|
|
/* Make sure the device tree binding matched the driver with the
|
|
* right device.
|
|
*/
|
|
if (phy_id != phydev->drv->phy_id) {
|
|
phydev_err(phydev, "Error matching phy with %s driver\n",
|
|
phydev->drv->name);
|
|
return -ENODEV;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static struct phy_driver cortina_driver[] = {
|
|
{
|
|
.phy_id = PHY_ID_CS4340,
|
|
.phy_id_mask = 0xffffffff,
|
|
.name = "Cortina CS4340",
|
|
.features = PHY_10GBIT_FEATURES,
|
|
.config_aneg = gen10g_config_aneg,
|
|
.read_status = cortina_read_status,
|
|
.probe = cortina_probe,
|
|
},
|
|
};
|
|
|
|
module_phy_driver(cortina_driver);
|
|
|
|
static struct mdio_device_id __maybe_unused cortina_tbl[] = {
|
|
{ PHY_ID_CS4340, 0xffffffff},
|
|
{},
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(mdio, cortina_tbl);
|
|
|
|
MODULE_DESCRIPTION("Cortina EDC CDR 10G Ethernet PHY driver");
|
|
MODULE_AUTHOR("NXP");
|
|
MODULE_LICENSE("GPL");
|