2016-08-05 20:24:21 +08:00
|
|
|
/*
|
|
|
|
* Driver for Microsemi VSC85xx PHYs
|
|
|
|
*
|
|
|
|
* Author: Nagaraju Lakkaraju
|
|
|
|
* License: Dual MIT/GPL
|
|
|
|
* Copyright (c) 2016 Microsemi Corporation
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/mdio.h>
|
|
|
|
#include <linux/mii.h>
|
|
|
|
#include <linux/phy.h>
|
|
|
|
|
|
|
|
enum rgmii_rx_clock_delay {
|
2016-09-08 16:39:31 +08:00
|
|
|
RGMII_RX_CLK_DELAY_0_2_NS = 0,
|
|
|
|
RGMII_RX_CLK_DELAY_0_8_NS = 1,
|
|
|
|
RGMII_RX_CLK_DELAY_1_1_NS = 2,
|
|
|
|
RGMII_RX_CLK_DELAY_1_7_NS = 3,
|
|
|
|
RGMII_RX_CLK_DELAY_2_0_NS = 4,
|
|
|
|
RGMII_RX_CLK_DELAY_2_3_NS = 5,
|
|
|
|
RGMII_RX_CLK_DELAY_2_6_NS = 6,
|
|
|
|
RGMII_RX_CLK_DELAY_3_4_NS = 7
|
2016-08-05 20:24:21 +08:00
|
|
|
};
|
|
|
|
|
2016-09-08 16:39:31 +08:00
|
|
|
#define MII_VSC85XX_INT_MASK 25
|
|
|
|
#define MII_VSC85XX_INT_MASK_MASK 0xa000
|
|
|
|
#define MII_VSC85XX_INT_STATUS 26
|
2016-08-05 20:24:21 +08:00
|
|
|
|
2016-09-08 16:39:31 +08:00
|
|
|
#define MSCC_EXT_PAGE_ACCESS 31
|
|
|
|
#define MSCC_PHY_PAGE_STANDARD 0x0000 /* Standard registers */
|
|
|
|
#define MSCC_PHY_PAGE_EXTENDED_2 0x0002 /* Extended reg - page 2 */
|
2016-08-05 20:24:21 +08:00
|
|
|
|
|
|
|
/* Extended Page 2 Registers */
|
2016-09-08 16:39:31 +08:00
|
|
|
#define MSCC_PHY_RGMII_CNTL 20
|
|
|
|
#define RGMII_RX_CLK_DELAY_MASK 0x0070
|
|
|
|
#define RGMII_RX_CLK_DELAY_POS 4
|
2016-08-05 20:24:21 +08:00
|
|
|
|
|
|
|
/* Microsemi PHY ID's */
|
2016-09-08 16:39:31 +08:00
|
|
|
#define PHY_ID_VSC8531 0x00070570
|
|
|
|
#define PHY_ID_VSC8541 0x00070770
|
2016-08-05 20:24:21 +08:00
|
|
|
|
|
|
|
static int vsc85xx_phy_page_set(struct phy_device *phydev, u8 page)
|
|
|
|
{
|
2016-09-08 16:39:31 +08:00
|
|
|
int rc;
|
2016-08-05 20:24:21 +08:00
|
|
|
|
2016-09-08 16:39:31 +08:00
|
|
|
rc = phy_write(phydev, MSCC_EXT_PAGE_ACCESS, page);
|
|
|
|
return rc;
|
2016-08-05 20:24:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int vsc85xx_default_config(struct phy_device *phydev)
|
|
|
|
{
|
2016-09-08 16:39:31 +08:00
|
|
|
int rc;
|
|
|
|
u16 reg_val;
|
2016-08-05 20:24:21 +08:00
|
|
|
|
2016-09-08 16:39:31 +08:00
|
|
|
mutex_lock(&phydev->lock);
|
|
|
|
rc = vsc85xx_phy_page_set(phydev, MSCC_PHY_PAGE_EXTENDED_2);
|
|
|
|
if (rc != 0)
|
|
|
|
goto out_unlock;
|
2016-08-05 20:24:21 +08:00
|
|
|
|
2016-09-08 16:39:31 +08:00
|
|
|
reg_val = phy_read(phydev, MSCC_PHY_RGMII_CNTL);
|
|
|
|
reg_val &= ~(RGMII_RX_CLK_DELAY_MASK);
|
|
|
|
reg_val |= (RGMII_RX_CLK_DELAY_1_1_NS << RGMII_RX_CLK_DELAY_POS);
|
|
|
|
phy_write(phydev, MSCC_PHY_RGMII_CNTL, reg_val);
|
|
|
|
rc = vsc85xx_phy_page_set(phydev, MSCC_PHY_PAGE_STANDARD);
|
2016-08-05 20:24:21 +08:00
|
|
|
|
|
|
|
out_unlock:
|
2016-09-08 16:39:31 +08:00
|
|
|
mutex_unlock(&phydev->lock);
|
2016-08-05 20:24:21 +08:00
|
|
|
|
2016-09-08 16:39:31 +08:00
|
|
|
return rc;
|
2016-08-05 20:24:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int vsc85xx_config_init(struct phy_device *phydev)
|
|
|
|
{
|
2016-09-08 16:39:31 +08:00
|
|
|
int rc;
|
2016-08-05 20:24:21 +08:00
|
|
|
|
2016-09-08 16:39:31 +08:00
|
|
|
rc = vsc85xx_default_config(phydev);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
rc = genphy_config_init(phydev);
|
2016-08-05 20:24:21 +08:00
|
|
|
|
2016-09-08 16:39:31 +08:00
|
|
|
return rc;
|
2016-08-05 20:24:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int vsc85xx_ack_interrupt(struct phy_device *phydev)
|
|
|
|
{
|
2016-09-08 16:39:31 +08:00
|
|
|
int rc = 0;
|
2016-08-05 20:24:21 +08:00
|
|
|
|
2016-09-08 16:39:31 +08:00
|
|
|
if (phydev->interrupts == PHY_INTERRUPT_ENABLED)
|
|
|
|
rc = phy_read(phydev, MII_VSC85XX_INT_STATUS);
|
2016-08-05 20:24:21 +08:00
|
|
|
|
2016-09-08 16:39:31 +08:00
|
|
|
return (rc < 0) ? rc : 0;
|
2016-08-05 20:24:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int vsc85xx_config_intr(struct phy_device *phydev)
|
|
|
|
{
|
2016-09-08 16:39:31 +08:00
|
|
|
int rc;
|
|
|
|
|
|
|
|
if (phydev->interrupts == PHY_INTERRUPT_ENABLED) {
|
|
|
|
rc = phy_write(phydev, MII_VSC85XX_INT_MASK,
|
|
|
|
MII_VSC85XX_INT_MASK_MASK);
|
|
|
|
} else {
|
|
|
|
rc = phy_write(phydev, MII_VSC85XX_INT_MASK, 0);
|
|
|
|
if (rc < 0)
|
|
|
|
return rc;
|
|
|
|
rc = phy_read(phydev, MII_VSC85XX_INT_STATUS);
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
2016-08-05 20:24:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Microsemi VSC85xx PHYs */
|
|
|
|
static struct phy_driver vsc85xx_driver[] = {
|
|
|
|
{
|
2016-09-08 16:39:31 +08:00
|
|
|
.phy_id = PHY_ID_VSC8531,
|
|
|
|
.name = "Microsemi VSC8531",
|
|
|
|
.phy_id_mask = 0xfffffff0,
|
|
|
|
.features = PHY_GBIT_FEATURES,
|
|
|
|
.flags = PHY_HAS_INTERRUPT,
|
|
|
|
.soft_reset = &genphy_soft_reset,
|
|
|
|
.config_init = &vsc85xx_config_init,
|
|
|
|
.config_aneg = &genphy_config_aneg,
|
|
|
|
.aneg_done = &genphy_aneg_done,
|
|
|
|
.read_status = &genphy_read_status,
|
|
|
|
.ack_interrupt = &vsc85xx_ack_interrupt,
|
|
|
|
.config_intr = &vsc85xx_config_intr,
|
|
|
|
.suspend = &genphy_suspend,
|
|
|
|
.resume = &genphy_resume,
|
2016-08-05 20:24:21 +08:00
|
|
|
},
|
|
|
|
{
|
2016-09-08 16:39:31 +08:00
|
|
|
.phy_id = PHY_ID_VSC8541,
|
|
|
|
.name = "Microsemi VSC8541 SyncE",
|
|
|
|
.phy_id_mask = 0xfffffff0,
|
|
|
|
.features = PHY_GBIT_FEATURES,
|
|
|
|
.flags = PHY_HAS_INTERRUPT,
|
|
|
|
.soft_reset = &genphy_soft_reset,
|
|
|
|
.config_init = &vsc85xx_config_init,
|
|
|
|
.config_aneg = &genphy_config_aneg,
|
|
|
|
.aneg_done = &genphy_aneg_done,
|
|
|
|
.read_status = &genphy_read_status,
|
|
|
|
.ack_interrupt = &vsc85xx_ack_interrupt,
|
|
|
|
.config_intr = &vsc85xx_config_intr,
|
|
|
|
.suspend = &genphy_suspend,
|
|
|
|
.resume = &genphy_resume,
|
2016-08-05 20:24:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
module_phy_driver(vsc85xx_driver);
|
|
|
|
|
|
|
|
static struct mdio_device_id __maybe_unused vsc85xx_tbl[] = {
|
2016-09-08 16:39:31 +08:00
|
|
|
{ PHY_ID_VSC8531, 0xfffffff0, },
|
|
|
|
{ PHY_ID_VSC8541, 0xfffffff0, },
|
|
|
|
{ }
|
2016-08-05 20:24:21 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
MODULE_DEVICE_TABLE(mdio, vsc85xx_tbl);
|
|
|
|
|
|
|
|
MODULE_DESCRIPTION("Microsemi VSC85xx PHY driver");
|
|
|
|
MODULE_AUTHOR("Nagaraju Lakkaraju");
|
|
|
|
MODULE_LICENSE("Dual MIT/GPL");
|