2007-05-12 07:24:51 +08: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>
|
2016-12-25 03:46:01 +08:00
|
|
|
#include <linux/uaccess.h>
|
2007-05-12 07:24:51 +08:00
|
|
|
|
2012-02-22 05:26:28 +08:00
|
|
|
MODULE_DESCRIPTION("ICPlus IP175C/IP101A/IP101G/IC1001 PHY drivers");
|
2007-05-12 07:24:51 +08:00
|
|
|
MODULE_AUTHOR("Michael Barkowski");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|
2012-02-22 05:26:28 +08:00
|
|
|
/* IP101A/G - IP1001 */
|
|
|
|
#define IP10XX_SPEC_CTRL_STATUS 16 /* Spec. Control Register */
|
2018-11-19 05:23:56 +08:00
|
|
|
#define IP1001_RXPHASE_SEL BIT(0) /* Add delay on RX_CLK */
|
|
|
|
#define IP1001_TXPHASE_SEL BIT(1) /* Add delay on TX_CLK */
|
2012-02-22 05:26:28 +08:00
|
|
|
#define IP1001_SPEC_CTRL_STATUS_2 20 /* IP1001 Spec. Control Reg 2 */
|
|
|
|
#define IP1001_APS_ON 11 /* IP1001 APS Mode bit */
|
2018-11-19 05:23:56 +08:00
|
|
|
#define IP101A_G_APS_ON BIT(1) /* IP101A/G APS Mode bit */
|
2012-04-18 05:16:40 +08:00
|
|
|
#define IP101A_G_IRQ_CONF_STATUS 0x11 /* Conf Info IRQ & Status Reg */
|
2018-11-12 04:49:12 +08:00
|
|
|
#define IP101A_G_IRQ_PIN_USED BIT(15) /* INTR pin used */
|
2018-11-19 05:23:57 +08:00
|
|
|
#define IP101A_G_IRQ_ALL_MASK BIT(11) /* IRQ's inactive */
|
2011-09-07 04:14:50 +08:00
|
|
|
|
2007-05-12 07:24:51 +08:00
|
|
|
static int ip175c_config_init(struct phy_device *phydev)
|
|
|
|
{
|
|
|
|
int err, i;
|
2013-12-18 13:38:08 +08:00
|
|
|
static int full_reset_performed;
|
2007-05-12 07:24:51 +08:00
|
|
|
|
|
|
|
if (full_reset_performed == 0) {
|
|
|
|
|
|
|
|
/* master reset */
|
2016-01-07 03:11:16 +08:00
|
|
|
err = mdiobus_write(phydev->mdio.bus, 30, 0, 0x175c);
|
2007-05-12 07:24:51 +08:00
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
/* ensure no bus delays overlap reset period */
|
2016-01-07 03:11:16 +08:00
|
|
|
err = mdiobus_read(phydev->mdio.bus, 30, 0);
|
2007-05-12 07:24:51 +08:00
|
|
|
|
|
|
|
/* data sheet specifies reset period is 2 msec */
|
|
|
|
mdelay(2);
|
|
|
|
|
|
|
|
/* enable IP175C mode */
|
2016-01-07 03:11:16 +08:00
|
|
|
err = mdiobus_write(phydev->mdio.bus, 29, 31, 0x175c);
|
2007-05-12 07:24:51 +08:00
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
/* Set MII0 speed and duplex (in PHY mode) */
|
2016-01-07 03:11:16 +08:00
|
|
|
err = mdiobus_write(phydev->mdio.bus, 29, 22, 0x420);
|
2007-05-12 07:24:51 +08:00
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
/* reset switch ports */
|
|
|
|
for (i = 0; i < 5; i++) {
|
2016-01-07 03:11:16 +08:00
|
|
|
err = mdiobus_write(phydev->mdio.bus, i,
|
2011-09-30 20:17:48 +08:00
|
|
|
MII_BMCR, BMCR_RESET);
|
2007-05-12 07:24:51 +08:00
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < 5; i++)
|
2016-01-07 03:11:16 +08:00
|
|
|
err = mdiobus_read(phydev->mdio.bus, i, MII_BMCR);
|
2007-05-12 07:24:51 +08:00
|
|
|
|
|
|
|
mdelay(2);
|
|
|
|
|
|
|
|
full_reset_performed = 1;
|
|
|
|
}
|
|
|
|
|
2016-01-07 03:11:16 +08:00
|
|
|
if (phydev->mdio.addr != 4) {
|
2007-05-12 07:24:51 +08:00
|
|
|
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-07 04:14:50 +08:00
|
|
|
static int ip1xx_reset(struct phy_device *phydev)
|
2010-12-09 07:05:13 +08:00
|
|
|
{
|
2012-02-22 05:24:57 +08:00
|
|
|
int bmcr;
|
2010-12-09 07:05:13 +08:00
|
|
|
|
|
|
|
/* Software Reset PHY */
|
2011-09-07 04:14:50 +08:00
|
|
|
bmcr = phy_read(phydev, MII_BMCR);
|
2012-02-22 05:24:57 +08:00
|
|
|
if (bmcr < 0)
|
|
|
|
return bmcr;
|
2011-09-07 04:14:50 +08:00
|
|
|
bmcr |= BMCR_RESET;
|
2012-02-22 05:24:57 +08:00
|
|
|
bmcr = phy_write(phydev, MII_BMCR, bmcr);
|
|
|
|
if (bmcr < 0)
|
|
|
|
return bmcr;
|
2010-12-09 07:05:13 +08:00
|
|
|
|
|
|
|
do {
|
2011-09-07 04:14:50 +08:00
|
|
|
bmcr = phy_read(phydev, MII_BMCR);
|
2012-02-22 05:24:57 +08:00
|
|
|
if (bmcr < 0)
|
|
|
|
return bmcr;
|
2011-09-07 04:14:50 +08:00
|
|
|
} while (bmcr & BMCR_RESET);
|
|
|
|
|
2012-02-22 05:24:57 +08:00
|
|
|
return 0;
|
2011-09-07 04:14:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2012-02-22 05:24:57 +08:00
|
|
|
if (c < 0)
|
|
|
|
return c;
|
2011-09-07 04:14:50 +08:00
|
|
|
c |= IP1001_APS_ON;
|
2012-02-22 05:24:57 +08:00
|
|
|
c = phy_write(phydev, IP1001_SPEC_CTRL_STATUS_2, c);
|
2011-09-07 04:14:50 +08:00
|
|
|
if (c < 0)
|
|
|
|
return c;
|
2010-12-09 07:05:13 +08:00
|
|
|
|
2015-05-27 03:19:59 +08:00
|
|
|
if (phy_interface_is_rgmii(phydev)) {
|
2013-01-23 08:22:36 +08:00
|
|
|
|
2011-10-11 05:37:56 +08:00
|
|
|
c = phy_read(phydev, IP10XX_SPEC_CTRL_STATUS);
|
2012-02-22 05:24:57 +08:00
|
|
|
if (c < 0)
|
|
|
|
return c;
|
|
|
|
|
2013-01-23 08:22:36 +08:00
|
|
|
c &= ~(IP1001_RXPHASE_SEL | IP1001_TXPHASE_SEL);
|
|
|
|
|
|
|
|
if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID)
|
|
|
|
c |= (IP1001_RXPHASE_SEL | IP1001_TXPHASE_SEL);
|
|
|
|
else if (phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID)
|
|
|
|
c |= IP1001_RXPHASE_SEL;
|
|
|
|
else if (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID)
|
|
|
|
c |= IP1001_TXPHASE_SEL;
|
|
|
|
|
2011-10-11 05:37:56 +08:00
|
|
|
c = phy_write(phydev, IP10XX_SPEC_CTRL_STATUS, c);
|
2012-02-22 05:24:57 +08:00
|
|
|
if (c < 0)
|
|
|
|
return c;
|
2011-10-11 05:37:56 +08:00
|
|
|
}
|
2011-09-07 04:14:50 +08:00
|
|
|
|
2012-02-22 05:24:57 +08:00
|
|
|
return 0;
|
2011-09-07 04:14:50 +08:00
|
|
|
}
|
|
|
|
|
2007-05-12 07:24:51 +08:00
|
|
|
static int ip175c_read_status(struct phy_device *phydev)
|
|
|
|
{
|
2016-01-07 03:11:16 +08:00
|
|
|
if (phydev->mdio.addr == 4) /* WAN port */
|
2007-05-12 07:24:51 +08:00
|
|
|
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)
|
|
|
|
{
|
2016-01-07 03:11:16 +08:00
|
|
|
if (phydev->mdio.addr == 4) /* WAN port */
|
2007-05-12 07:24:51 +08:00
|
|
|
genphy_config_aneg(phydev);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-11-19 05:23:55 +08:00
|
|
|
static int ip101a_g_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, IP10XX_SPEC_CTRL_STATUS);
|
|
|
|
c |= IP101A_G_APS_ON;
|
|
|
|
|
|
|
|
return phy_write(phydev, IP10XX_SPEC_CTRL_STATUS, c);
|
|
|
|
}
|
|
|
|
|
2018-11-12 04:49:12 +08:00
|
|
|
static int ip101a_g_config_intr(struct phy_device *phydev)
|
|
|
|
{
|
|
|
|
u16 val;
|
|
|
|
|
|
|
|
if (phydev->interrupts == PHY_INTERRUPT_ENABLED)
|
|
|
|
/* INTR pin used: Speed/link/duplex will cause an interrupt */
|
|
|
|
val = IP101A_G_IRQ_PIN_USED;
|
|
|
|
else
|
2018-11-19 05:23:57 +08:00
|
|
|
val = IP101A_G_IRQ_ALL_MASK;
|
2018-11-12 04:49:12 +08:00
|
|
|
|
|
|
|
return phy_write(phydev, IP101A_G_IRQ_CONF_STATUS, val);
|
|
|
|
}
|
|
|
|
|
2012-04-18 05:16:40 +08:00
|
|
|
static int ip101a_g_ack_interrupt(struct phy_device *phydev)
|
|
|
|
{
|
|
|
|
int err = phy_read(phydev, IP101A_G_IRQ_CONF_STATUS);
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-07-04 13:44:34 +08:00
|
|
|
static struct phy_driver icplus_driver[] = {
|
|
|
|
{
|
2007-05-12 07:24:51 +08:00
|
|
|
.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-21 04:24:25 +08:00
|
|
|
.suspend = genphy_suspend,
|
|
|
|
.resume = genphy_resume,
|
2012-07-04 13:44:34 +08:00
|
|
|
}, {
|
2010-12-09 07:05:13 +08:00
|
|
|
.phy_id = 0x02430d90,
|
|
|
|
.name = "ICPlus IP1001",
|
|
|
|
.phy_id_mask = 0x0ffffff0,
|
net: phy: phy drivers should not set SUPPORTED_[Asym_]Pause
Instead of having individual PHY drivers set the SUPPORTED_Pause and
SUPPORTED_Asym_Pause flags, phylib itself should set those flags,
unless there is a hardware erratum or other special case. During
autonegotiation, the PHYs will determine whether to enable pause
frame support.
Pause frames are a feature that is supported by the MAC. It is the MAC
that generates the frames and that processes them. The PHY can only be
configured to allow them to pass through.
This commit also effectively reverts the recently applied c7a61319
("net: phy: dp83848: Support ethernet pause frames").
So the new process is:
1) Unless the PHY driver overrides it, phylib sets the SUPPORTED_Pause
and SUPPORTED_AsymPause bits in phydev->supported. This indicates that
the PHY supports pause frames.
2) The MAC driver checks phydev->supported before it calls phy_start().
If (SUPPORTED_Pause | SUPPORTED_AsymPause) is set, then the MAC driver
sets those bits in phydev->advertising, if it wants to enable pause
frame support.
3) When the link state changes, the MAC driver checks phydev->pause and
phydev->asym_pause, If the bits are set, then it enables the corresponding
features in the MAC. The algorithm is:
if (phydev->pause)
The MAC should be programmed to receive and honor
pause frames it receives, i.e. enable receive flow control.
if (phydev->pause != phydev->asym_pause)
The MAC should be programmed to transmit pause
frames when needed, i.e. enable transmit flow control.
Signed-off-by: Timur Tabi <timur@codeaurora.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
2016-12-08 03:20:51 +08:00
|
|
|
.features = PHY_GBIT_FEATURES,
|
2010-12-09 07:05:13 +08:00
|
|
|
.config_init = &ip1001_config_init,
|
|
|
|
.suspend = genphy_suspend,
|
|
|
|
.resume = genphy_resume,
|
2012-07-04 13:44:34 +08:00
|
|
|
}, {
|
2011-09-07 04:14:50 +08:00
|
|
|
.phy_id = 0x02430c54,
|
2012-02-22 05:26:28 +08:00
|
|
|
.name = "ICPlus IP101A/G",
|
2011-09-07 04:14:50 +08:00
|
|
|
.phy_id_mask = 0x0ffffff0,
|
net: phy: phy drivers should not set SUPPORTED_[Asym_]Pause
Instead of having individual PHY drivers set the SUPPORTED_Pause and
SUPPORTED_Asym_Pause flags, phylib itself should set those flags,
unless there is a hardware erratum or other special case. During
autonegotiation, the PHYs will determine whether to enable pause
frame support.
Pause frames are a feature that is supported by the MAC. It is the MAC
that generates the frames and that processes them. The PHY can only be
configured to allow them to pass through.
This commit also effectively reverts the recently applied c7a61319
("net: phy: dp83848: Support ethernet pause frames").
So the new process is:
1) Unless the PHY driver overrides it, phylib sets the SUPPORTED_Pause
and SUPPORTED_AsymPause bits in phydev->supported. This indicates that
the PHY supports pause frames.
2) The MAC driver checks phydev->supported before it calls phy_start().
If (SUPPORTED_Pause | SUPPORTED_AsymPause) is set, then the MAC driver
sets those bits in phydev->advertising, if it wants to enable pause
frame support.
3) When the link state changes, the MAC driver checks phydev->pause and
phydev->asym_pause, If the bits are set, then it enables the corresponding
features in the MAC. The algorithm is:
if (phydev->pause)
The MAC should be programmed to receive and honor
pause frames it receives, i.e. enable receive flow control.
if (phydev->pause != phydev->asym_pause)
The MAC should be programmed to transmit pause
frames when needed, i.e. enable transmit flow control.
Signed-off-by: Timur Tabi <timur@codeaurora.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
2016-12-08 03:20:51 +08:00
|
|
|
.features = PHY_BASIC_FEATURES,
|
2018-11-12 04:49:12 +08:00
|
|
|
.config_intr = ip101a_g_config_intr,
|
2012-04-18 05:16:40 +08:00
|
|
|
.ack_interrupt = ip101a_g_ack_interrupt,
|
2012-02-22 05:26:28 +08:00
|
|
|
.config_init = &ip101a_g_config_init,
|
2011-09-07 04:14:50 +08:00
|
|
|
.suspend = genphy_suspend,
|
|
|
|
.resume = genphy_resume,
|
2012-07-04 13:44:34 +08:00
|
|
|
} };
|
2011-09-07 04:14:50 +08:00
|
|
|
|
2014-11-12 02:45:59 +08:00
|
|
|
module_phy_driver(icplus_driver);
|
2010-04-02 09:05:56 +08:00
|
|
|
|
2010-10-04 07:43:32 +08:00
|
|
|
static struct mdio_device_id __maybe_unused icplus_tbl[] = {
|
2010-04-02 09:05:56 +08:00
|
|
|
{ 0x02430d80, 0x0ffffff0 },
|
2010-12-09 07:05:13 +08:00
|
|
|
{ 0x02430d90, 0x0ffffff0 },
|
2012-02-22 05:26:28 +08:00
|
|
|
{ 0x02430c54, 0x0ffffff0 },
|
2010-04-02 09:05:56 +08:00
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
MODULE_DEVICE_TABLE(mdio, icplus_tbl);
|