2006-06-17 22:52:55 +00:00
|
|
|
/*
|
|
|
|
* Driver for Vitesse PHYs
|
|
|
|
*
|
|
|
|
* Author: Kriston Carson
|
|
|
|
*
|
|
|
|
* Copyright (c) 2005 Freescale Semiconductor, Inc.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation; either version 2 of the License, or (at your
|
|
|
|
* option) any later version.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/mii.h>
|
|
|
|
#include <linux/ethtool.h>
|
|
|
|
#include <linux/phy.h>
|
|
|
|
|
|
|
|
/* Vitesse Extended Control Register 1 */
|
|
|
|
#define MII_VSC8244_EXT_CON1 0x17
|
|
|
|
#define MII_VSC8244_EXTCON1_INIT 0x0000
|
2007-07-11 16:42:35 +00:00
|
|
|
#define MII_VSC8244_EXTCON1_TX_SKEW_MASK 0x0c00
|
|
|
|
#define MII_VSC8244_EXTCON1_RX_SKEW_MASK 0x0300
|
|
|
|
#define MII_VSC8244_EXTCON1_TX_SKEW 0x0800
|
|
|
|
#define MII_VSC8244_EXTCON1_RX_SKEW 0x0200
|
2006-06-17 22:52:55 +00:00
|
|
|
|
|
|
|
/* Vitesse Interrupt Mask Register */
|
|
|
|
#define MII_VSC8244_IMASK 0x19
|
|
|
|
#define MII_VSC8244_IMASK_IEN 0x8000
|
|
|
|
#define MII_VSC8244_IMASK_SPEED 0x4000
|
|
|
|
#define MII_VSC8244_IMASK_LINK 0x2000
|
|
|
|
#define MII_VSC8244_IMASK_DUPLEX 0x1000
|
|
|
|
#define MII_VSC8244_IMASK_MASK 0xf000
|
|
|
|
|
|
|
|
/* Vitesse Interrupt Status Register */
|
|
|
|
#define MII_VSC8244_ISTAT 0x1a
|
|
|
|
#define MII_VSC8244_ISTAT_STATUS 0x8000
|
|
|
|
#define MII_VSC8244_ISTAT_SPEED 0x4000
|
|
|
|
#define MII_VSC8244_ISTAT_LINK 0x2000
|
|
|
|
#define MII_VSC8244_ISTAT_DUPLEX 0x1000
|
|
|
|
|
|
|
|
/* Vitesse Auxiliary Control/Status Register */
|
|
|
|
#define MII_VSC8244_AUX_CONSTAT 0x1c
|
2007-07-11 16:42:35 +00:00
|
|
|
#define MII_VSC8244_AUXCONSTAT_INIT 0x0000
|
2006-06-17 22:52:55 +00:00
|
|
|
#define MII_VSC8244_AUXCONSTAT_DUPLEX 0x0020
|
|
|
|
#define MII_VSC8244_AUXCONSTAT_SPEED 0x0018
|
|
|
|
#define MII_VSC8244_AUXCONSTAT_GBIT 0x0010
|
|
|
|
#define MII_VSC8244_AUXCONSTAT_100 0x0008
|
|
|
|
|
|
|
|
MODULE_DESCRIPTION("Vitesse PHY driver");
|
|
|
|
MODULE_AUTHOR("Kriston Carson");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|
|
|
|
static int vsc824x_config_init(struct phy_device *phydev)
|
|
|
|
{
|
2007-07-11 16:42:35 +00:00
|
|
|
int extcon;
|
2006-06-17 22:52:55 +00:00
|
|
|
int err;
|
|
|
|
|
|
|
|
err = phy_write(phydev, MII_VSC8244_AUX_CONSTAT,
|
|
|
|
MII_VSC8244_AUXCONSTAT_INIT);
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
2007-07-11 16:42:35 +00:00
|
|
|
extcon = phy_read(phydev, MII_VSC8244_EXT_CON1);
|
|
|
|
|
|
|
|
if (extcon < 0)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
extcon &= ~(MII_VSC8244_EXTCON1_TX_SKEW_MASK |
|
|
|
|
MII_VSC8244_EXTCON1_RX_SKEW_MASK);
|
|
|
|
|
|
|
|
if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID)
|
|
|
|
extcon |= (MII_VSC8244_EXTCON1_TX_SKEW |
|
|
|
|
MII_VSC8244_EXTCON1_RX_SKEW);
|
|
|
|
|
|
|
|
err = phy_write(phydev, MII_VSC8244_EXT_CON1, extcon);
|
|
|
|
|
2006-06-17 22:52:55 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int vsc824x_ack_interrupt(struct phy_device *phydev)
|
|
|
|
{
|
2007-07-10 21:42:04 +00:00
|
|
|
int err = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Don't bother to ACK the interrupts if interrupts
|
|
|
|
* are disabled. The 824x cannot clear the interrupts
|
|
|
|
* if they are disabled.
|
|
|
|
*/
|
|
|
|
if (phydev->interrupts == PHY_INTERRUPT_ENABLED)
|
|
|
|
err = phy_read(phydev, MII_VSC8244_ISTAT);
|
2006-06-17 22:52:55 +00:00
|
|
|
|
|
|
|
return (err < 0) ? err : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int vsc824x_config_intr(struct phy_device *phydev)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
|
|
|
if (phydev->interrupts == PHY_INTERRUPT_ENABLED)
|
|
|
|
err = phy_write(phydev, MII_VSC8244_IMASK,
|
|
|
|
MII_VSC8244_IMASK_MASK);
|
2007-07-10 21:42:04 +00:00
|
|
|
else {
|
|
|
|
/*
|
|
|
|
* The Vitesse PHY cannot clear the interrupt
|
|
|
|
* once it has disabled them, so we clear them first
|
|
|
|
*/
|
|
|
|
err = phy_read(phydev, MII_VSC8244_ISTAT);
|
|
|
|
|
2007-07-18 06:06:28 +00:00
|
|
|
if (err < 0)
|
2007-07-10 21:42:04 +00:00
|
|
|
return err;
|
|
|
|
|
2006-06-17 22:52:55 +00:00
|
|
|
err = phy_write(phydev, MII_VSC8244_IMASK, 0);
|
2007-07-10 21:42:04 +00:00
|
|
|
}
|
|
|
|
|
2006-06-17 22:52:55 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Vitesse 824x */
|
|
|
|
static struct phy_driver vsc8244_driver = {
|
2007-06-28 18:26:06 +00:00
|
|
|
.phy_id = 0x000fc6c0,
|
2006-06-17 22:52:55 +00:00
|
|
|
.name = "Vitesse VSC8244",
|
|
|
|
.phy_id_mask = 0x000fffc0,
|
|
|
|
.features = PHY_GBIT_FEATURES,
|
|
|
|
.flags = PHY_HAS_INTERRUPT,
|
|
|
|
.config_init = &vsc824x_config_init,
|
|
|
|
.config_aneg = &genphy_config_aneg,
|
|
|
|
.read_status = &genphy_read_status,
|
|
|
|
.ack_interrupt = &vsc824x_ack_interrupt,
|
|
|
|
.config_intr = &vsc824x_config_intr,
|
|
|
|
.driver = { .owner = THIS_MODULE,},
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init vsc8244_init(void)
|
|
|
|
{
|
|
|
|
return phy_driver_register(&vsc8244_driver);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit vsc8244_exit(void)
|
|
|
|
{
|
|
|
|
phy_driver_unregister(&vsc8244_driver);
|
|
|
|
}
|
|
|
|
|
|
|
|
module_init(vsc8244_init);
|
|
|
|
module_exit(vsc8244_exit);
|