2007-05-11 23:24:51 +00:00
|
|
|
/*
|
|
|
|
* Driver for ICPlus PHYs
|
|
|
|
*
|
|
|
|
* Copyright (c) 2007 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/string.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/unistd.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/netdevice.h>
|
|
|
|
#include <linux/etherdevice.h>
|
|
|
|
#include <linux/skbuff.h>
|
|
|
|
#include <linux/spinlock.h>
|
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/mii.h>
|
|
|
|
#include <linux/ethtool.h>
|
|
|
|
#include <linux/phy.h>
|
|
|
|
|
|
|
|
#include <asm/io.h>
|
|
|
|
#include <asm/irq.h>
|
|
|
|
#include <asm/uaccess.h>
|
|
|
|
|
2011-09-06 20:14:50 +00:00
|
|
|
MODULE_DESCRIPTION("ICPlus IP175C/IP101A/IC1001 PHY drivers");
|
2007-05-11 23:24:51 +00:00
|
|
|
MODULE_AUTHOR("Michael Barkowski");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|
2011-09-06 20:14:50 +00:00
|
|
|
/* IP101A/IP1001 */
|
|
|
|
#define IP10XX_SPEC_CTRL_STATUS 16 /* Spec. Control Register */
|
|
|
|
#define IP1001_SPEC_CTRL_STATUS_2 20 /* IP1001 Spec. Control Reg 2 */
|
|
|
|
#define IP1001_PHASE_SEL_MASK 3 /* IP1001 RX/TXPHASE_SEL */
|
|
|
|
#define IP1001_APS_ON 11 /* IP1001 APS Mode bit */
|
|
|
|
#define IP101A_APS_ON 2 /* IP101A APS Mode bit */
|
|
|
|
|
2007-05-11 23:24:51 +00:00
|
|
|
static int ip175c_config_init(struct phy_device *phydev)
|
|
|
|
{
|
|
|
|
int err, i;
|
|
|
|
static int full_reset_performed = 0;
|
|
|
|
|
|
|
|
if (full_reset_performed == 0) {
|
|
|
|
|
|
|
|
/* master reset */
|
2011-09-30 12:17:48 +00:00
|
|
|
err = mdiobus_write(phydev->bus, 30, 0, 0x175c);
|
2007-05-11 23:24:51 +00:00
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
/* ensure no bus delays overlap reset period */
|
2011-09-30 12:17:48 +00:00
|
|
|
err = mdiobus_read(phydev->bus, 30, 0);
|
2007-05-11 23:24:51 +00:00
|
|
|
|
|
|
|
/* data sheet specifies reset period is 2 msec */
|
|
|
|
mdelay(2);
|
|
|
|
|
|
|
|
/* enable IP175C mode */
|
2011-09-30 12:17:48 +00:00
|
|
|
err = mdiobus_write(phydev->bus, 29, 31, 0x175c);
|
2007-05-11 23:24:51 +00:00
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
/* Set MII0 speed and duplex (in PHY mode) */
|
2011-09-30 12:17:48 +00:00
|
|
|
err = mdiobus_write(phydev->bus, 29, 22, 0x420);
|
2007-05-11 23:24:51 +00:00
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
/* reset switch ports */
|
|
|
|
for (i = 0; i < 5; i++) {
|
2011-09-30 12:17:48 +00:00
|
|
|
err = mdiobus_write(phydev->bus, i,
|
|
|
|
MII_BMCR, BMCR_RESET);
|
2007-05-11 23:24:51 +00:00
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < 5; i++)
|
2011-09-30 12:17:48 +00:00
|
|
|
err = mdiobus_read(phydev->bus, i, MII_BMCR);
|
2007-05-11 23:24:51 +00:00
|
|
|
|
|
|
|
mdelay(2);
|
|
|
|
|
|
|
|
full_reset_performed = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (phydev->addr != 4) {
|
|
|
|
phydev->state = PHY_RUNNING;
|
|
|
|
phydev->speed = SPEED_100;
|
|
|
|
phydev->duplex = DUPLEX_FULL;
|
|
|
|
phydev->link = 1;
|
|
|
|
netif_carrier_on(phydev->attached_dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-09-06 20:14:50 +00:00
|
|
|
static int ip1xx_reset(struct phy_device *phydev)
|
2010-12-08 23:05:13 +00:00
|
|
|
{
|
2011-09-06 20:14:50 +00:00
|
|
|
int err, bmcr;
|
2010-12-08 23:05:13 +00:00
|
|
|
|
|
|
|
/* Software Reset PHY */
|
2011-09-06 20:14:50 +00:00
|
|
|
bmcr = phy_read(phydev, MII_BMCR);
|
|
|
|
bmcr |= BMCR_RESET;
|
|
|
|
err = phy_write(phydev, MII_BMCR, bmcr);
|
2010-12-08 23:05:13 +00:00
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
do {
|
2011-09-06 20:14:50 +00:00
|
|
|
bmcr = phy_read(phydev, MII_BMCR);
|
|
|
|
} while (bmcr & BMCR_RESET);
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ip1001_config_init(struct phy_device *phydev)
|
|
|
|
{
|
|
|
|
int c;
|
|
|
|
|
|
|
|
c = ip1xx_reset(phydev);
|
|
|
|
if (c < 0)
|
|
|
|
return c;
|
|
|
|
|
|
|
|
/* Enable Auto Power Saving mode */
|
|
|
|
c = phy_read(phydev, IP1001_SPEC_CTRL_STATUS_2);
|
|
|
|
c |= IP1001_APS_ON;
|
|
|
|
if (c < 0)
|
|
|
|
return c;
|
2010-12-08 23:05:13 +00:00
|
|
|
|
2011-10-10 21:37:56 +00:00
|
|
|
if (phydev->interface == PHY_INTERFACE_MODE_RGMII) {
|
|
|
|
/* Additional delay (2ns) used to adjust RX clock phase
|
|
|
|
* at RGMII interface */
|
|
|
|
c = phy_read(phydev, IP10XX_SPEC_CTRL_STATUS);
|
|
|
|
c |= IP1001_PHASE_SEL_MASK;
|
|
|
|
c = phy_write(phydev, IP10XX_SPEC_CTRL_STATUS, c);
|
|
|
|
}
|
2011-09-06 20:14:50 +00:00
|
|
|
|
2011-10-10 21:37:56 +00:00
|
|
|
return c;
|
2011-09-06 20:14:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int ip101a_config_init(struct phy_device *phydev)
|
|
|
|
{
|
|
|
|
int c;
|
2010-12-08 23:05:13 +00:00
|
|
|
|
2011-09-06 20:14:50 +00:00
|
|
|
c = ip1xx_reset(phydev);
|
|
|
|
if (c < 0)
|
|
|
|
return c;
|
|
|
|
|
|
|
|
/* Enable Auto Power Saving mode */
|
|
|
|
c = phy_read(phydev, IP10XX_SPEC_CTRL_STATUS);
|
|
|
|
c |= IP101A_APS_ON;
|
|
|
|
return c;
|
2010-12-08 23:05:13 +00:00
|
|
|
}
|
|
|
|
|
2007-05-11 23:24:51 +00:00
|
|
|
static int ip175c_read_status(struct phy_device *phydev)
|
|
|
|
{
|
|
|
|
if (phydev->addr == 4) /* WAN port */
|
|
|
|
genphy_read_status(phydev);
|
|
|
|
else
|
|
|
|
/* Don't need to read status for switch ports */
|
|
|
|
phydev->irq = PHY_IGNORE_INTERRUPT;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ip175c_config_aneg(struct phy_device *phydev)
|
|
|
|
{
|
|
|
|
if (phydev->addr == 4) /* WAN port */
|
|
|
|
genphy_config_aneg(phydev);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct phy_driver ip175c_driver = {
|
|
|
|
.phy_id = 0x02430d80,
|
|
|
|
.name = "ICPlus IP175C",
|
|
|
|
.phy_id_mask = 0x0ffffff0,
|
|
|
|
.features = PHY_BASIC_FEATURES,
|
|
|
|
.config_init = &ip175c_config_init,
|
|
|
|
.config_aneg = &ip175c_config_aneg,
|
|
|
|
.read_status = &ip175c_read_status,
|
2010-07-20 20:24:25 +00:00
|
|
|
.suspend = genphy_suspend,
|
|
|
|
.resume = genphy_resume,
|
2007-05-11 23:24:51 +00:00
|
|
|
.driver = { .owner = THIS_MODULE,},
|
|
|
|
};
|
|
|
|
|
2010-12-08 23:05:13 +00:00
|
|
|
static struct phy_driver ip1001_driver = {
|
|
|
|
.phy_id = 0x02430d90,
|
|
|
|
.name = "ICPlus IP1001",
|
|
|
|
.phy_id_mask = 0x0ffffff0,
|
|
|
|
.features = PHY_GBIT_FEATURES | SUPPORTED_Pause |
|
|
|
|
SUPPORTED_Asym_Pause,
|
|
|
|
.config_init = &ip1001_config_init,
|
|
|
|
.config_aneg = &genphy_config_aneg,
|
|
|
|
.read_status = &genphy_read_status,
|
|
|
|
.suspend = genphy_suspend,
|
|
|
|
.resume = genphy_resume,
|
|
|
|
.driver = { .owner = THIS_MODULE,},
|
|
|
|
};
|
|
|
|
|
2011-09-06 20:14:50 +00:00
|
|
|
static struct phy_driver ip101a_driver = {
|
|
|
|
.phy_id = 0x02430c54,
|
|
|
|
.name = "ICPlus IP101A",
|
|
|
|
.phy_id_mask = 0x0ffffff0,
|
|
|
|
.features = PHY_BASIC_FEATURES | SUPPORTED_Pause |
|
|
|
|
SUPPORTED_Asym_Pause,
|
|
|
|
.config_init = &ip101a_config_init,
|
|
|
|
.config_aneg = &genphy_config_aneg,
|
|
|
|
.read_status = &genphy_read_status,
|
|
|
|
.suspend = genphy_suspend,
|
|
|
|
.resume = genphy_resume,
|
|
|
|
.driver = { .owner = THIS_MODULE,},
|
|
|
|
};
|
|
|
|
|
2010-12-08 23:05:13 +00:00
|
|
|
static int __init icplus_init(void)
|
2007-05-11 23:24:51 +00:00
|
|
|
{
|
2010-12-08 23:05:13 +00:00
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
ret = phy_driver_register(&ip1001_driver);
|
|
|
|
if (ret < 0)
|
|
|
|
return -ENODEV;
|
|
|
|
|
2011-09-06 20:14:50 +00:00
|
|
|
ret = phy_driver_register(&ip101a_driver);
|
|
|
|
if (ret < 0)
|
|
|
|
return -ENODEV;
|
|
|
|
|
2007-05-11 23:24:51 +00:00
|
|
|
return phy_driver_register(&ip175c_driver);
|
|
|
|
}
|
|
|
|
|
2010-12-08 23:05:13 +00:00
|
|
|
static void __exit icplus_exit(void)
|
2007-05-11 23:24:51 +00:00
|
|
|
{
|
2010-12-08 23:05:13 +00:00
|
|
|
phy_driver_unregister(&ip1001_driver);
|
2011-09-06 20:14:50 +00:00
|
|
|
phy_driver_unregister(&ip101a_driver);
|
2007-05-11 23:24:51 +00:00
|
|
|
phy_driver_unregister(&ip175c_driver);
|
|
|
|
}
|
|
|
|
|
2010-12-08 23:05:13 +00:00
|
|
|
module_init(icplus_init);
|
|
|
|
module_exit(icplus_exit);
|
2010-04-02 01:05:56 +00:00
|
|
|
|
2010-10-03 23:43:32 +00:00
|
|
|
static struct mdio_device_id __maybe_unused icplus_tbl[] = {
|
2010-04-02 01:05:56 +00:00
|
|
|
{ 0x02430d80, 0x0ffffff0 },
|
2010-12-08 23:05:13 +00:00
|
|
|
{ 0x02430d90, 0x0ffffff0 },
|
2010-04-02 01:05:56 +00:00
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
MODULE_DEVICE_TABLE(mdio, icplus_tbl);
|