2019-01-21 18:05:50 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2007-05-11 23:24:51 +00:00
|
|
|
/*
|
|
|
|
* Driver for ICPlus PHYs
|
|
|
|
*
|
|
|
|
* Copyright (c) 2007 Freescale Semiconductor, Inc.
|
|
|
|
*/
|
|
|
|
#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>
|
2018-11-18 21:23:59 +00:00
|
|
|
#include <linux/property.h>
|
2007-05-11 23:24:51 +00:00
|
|
|
|
|
|
|
#include <asm/io.h>
|
|
|
|
#include <asm/irq.h>
|
2016-12-24 19:46:01 +00:00
|
|
|
#include <linux/uaccess.h>
|
2007-05-11 23:24:51 +00:00
|
|
|
|
2012-02-21 21:26:28 +00:00
|
|
|
MODULE_DESCRIPTION("ICPlus IP175C/IP101A/IP101G/IC1001 PHY drivers");
|
2007-05-11 23:24:51 +00:00
|
|
|
MODULE_AUTHOR("Michael Barkowski");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|
2012-02-21 21:26:28 +00:00
|
|
|
/* IP101A/G - IP1001 */
|
|
|
|
#define IP10XX_SPEC_CTRL_STATUS 16 /* Spec. Control Register */
|
2018-11-18 21:23:56 +00: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-21 21:26:28 +00:00
|
|
|
#define IP1001_SPEC_CTRL_STATUS_2 20 /* IP1001 Spec. Control Reg 2 */
|
|
|
|
#define IP1001_APS_ON 11 /* IP1001 APS Mode bit */
|
2018-11-18 21:23:56 +00:00
|
|
|
#define IP101A_G_APS_ON BIT(1) /* IP101A/G APS Mode bit */
|
2021-02-11 07:47:50 +00:00
|
|
|
#define IP101A_G_AUTO_MDIX_DIS BIT(11)
|
2012-04-17 21:16:40 +00:00
|
|
|
#define IP101A_G_IRQ_CONF_STATUS 0x11 /* Conf Info IRQ & Status Reg */
|
2018-11-11 20:49:12 +00:00
|
|
|
#define IP101A_G_IRQ_PIN_USED BIT(15) /* INTR pin used */
|
2018-11-18 21:23:57 +00:00
|
|
|
#define IP101A_G_IRQ_ALL_MASK BIT(11) /* IRQ's inactive */
|
2018-11-18 21:23:58 +00:00
|
|
|
#define IP101A_G_IRQ_SPEED_CHANGE BIT(2)
|
|
|
|
#define IP101A_G_IRQ_DUPLEX_CHANGE BIT(1)
|
|
|
|
#define IP101A_G_IRQ_LINK_CHANGE BIT(0)
|
2021-02-11 07:47:50 +00:00
|
|
|
#define IP101A_G_PHY_STATUS 18
|
|
|
|
#define IP101A_G_MDIX BIT(9)
|
|
|
|
#define IP101A_G_PHY_SPEC_CTRL 30
|
|
|
|
#define IP101A_G_FORCE_MDIX BIT(3)
|
2011-09-06 20:14:50 +00:00
|
|
|
|
2021-02-11 07:47:46 +00:00
|
|
|
#define IP101G_PAGE_CONTROL 0x14
|
|
|
|
#define IP101G_PAGE_CONTROL_MASK GENMASK(4, 0)
|
2018-11-18 21:23:59 +00:00
|
|
|
#define IP101G_DIGITAL_IO_SPEC_CTRL 0x1d
|
|
|
|
#define IP101G_DIGITAL_IO_SPEC_CTRL_SEL_INTR32 BIT(2)
|
|
|
|
|
2021-02-11 07:47:48 +00:00
|
|
|
#define IP101G_DEFAULT_PAGE 16
|
|
|
|
|
2021-02-11 07:47:49 +00:00
|
|
|
#define IP101G_P1_CNT_CTRL 17
|
|
|
|
#define CNT_CTRL_RX_EN BIT(13)
|
|
|
|
#define IP101G_P8_CNT_CTRL 17
|
|
|
|
#define CNT_CTRL_RDCLR_EN BIT(15)
|
|
|
|
#define IP101G_CNT_REG 18
|
|
|
|
|
2021-02-11 07:47:42 +00:00
|
|
|
#define IP175C_PHY_ID 0x02430d80
|
|
|
|
#define IP1001_PHY_ID 0x02430d90
|
|
|
|
#define IP101A_PHY_ID 0x02430c54
|
|
|
|
|
2018-11-18 21:23:59 +00:00
|
|
|
/* The 32-pin IP101GR package can re-configure the mode of the RXER/INTR_32 pin
|
|
|
|
* (pin number 21). The hardware default is RXER (receive error) mode. But it
|
|
|
|
* can be configured to interrupt mode manually.
|
|
|
|
*/
|
|
|
|
enum ip101gr_sel_intr32 {
|
|
|
|
IP101GR_SEL_INTR32_KEEP,
|
|
|
|
IP101GR_SEL_INTR32_INTR,
|
|
|
|
IP101GR_SEL_INTR32_RXER,
|
|
|
|
};
|
|
|
|
|
2021-02-11 07:47:49 +00:00
|
|
|
struct ip101g_hw_stat {
|
|
|
|
const char *name;
|
|
|
|
int page;
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct ip101g_hw_stat ip101g_hw_stats[] = {
|
|
|
|
{ "phy_crc_errors", 1 },
|
|
|
|
{ "phy_symbol_errors", 11, },
|
|
|
|
};
|
|
|
|
|
2018-11-18 21:23:59 +00:00
|
|
|
struct ip101a_g_phy_priv {
|
|
|
|
enum ip101gr_sel_intr32 sel_intr32;
|
2021-02-11 07:47:49 +00:00
|
|
|
u64 stats[ARRAY_SIZE(ip101g_hw_stats)];
|
2018-11-18 21:23:59 +00:00
|
|
|
};
|
|
|
|
|
2007-05-11 23:24:51 +00:00
|
|
|
static int ip175c_config_init(struct phy_device *phydev)
|
|
|
|
{
|
|
|
|
int err, i;
|
2013-12-18 05:38:08 +00:00
|
|
|
static int full_reset_performed;
|
2007-05-11 23:24:51 +00:00
|
|
|
|
|
|
|
if (full_reset_performed == 0) {
|
|
|
|
|
|
|
|
/* master reset */
|
2016-01-06 19:11:16 +00:00
|
|
|
err = mdiobus_write(phydev->mdio.bus, 30, 0, 0x175c);
|
2007-05-11 23:24:51 +00:00
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
/* ensure no bus delays overlap reset period */
|
2016-01-06 19:11:16 +00:00
|
|
|
err = mdiobus_read(phydev->mdio.bus, 30, 0);
|
2007-05-11 23:24:51 +00:00
|
|
|
|
|
|
|
/* data sheet specifies reset period is 2 msec */
|
|
|
|
mdelay(2);
|
|
|
|
|
|
|
|
/* enable IP175C mode */
|
2016-01-06 19:11:16 +00:00
|
|
|
err = mdiobus_write(phydev->mdio.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) */
|
2016-01-06 19:11:16 +00:00
|
|
|
err = mdiobus_write(phydev->mdio.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++) {
|
2016-01-06 19:11:16 +00:00
|
|
|
err = mdiobus_write(phydev->mdio.bus, i,
|
2011-09-30 12:17:48 +00:00
|
|
|
MII_BMCR, BMCR_RESET);
|
2007-05-11 23:24:51 +00:00
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < 5; i++)
|
2016-01-06 19:11:16 +00:00
|
|
|
err = mdiobus_read(phydev->mdio.bus, i, MII_BMCR);
|
2007-05-11 23:24:51 +00:00
|
|
|
|
|
|
|
mdelay(2);
|
|
|
|
|
|
|
|
full_reset_performed = 1;
|
|
|
|
}
|
|
|
|
|
2016-01-06 19:11:16 +00:00
|
|
|
if (phydev->mdio.addr != 4) {
|
2007-05-11 23:24:51 +00: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-06 20:14:50 +00:00
|
|
|
static int ip1001_config_init(struct phy_device *phydev)
|
|
|
|
{
|
|
|
|
int c;
|
|
|
|
|
|
|
|
/* Enable Auto Power Saving mode */
|
|
|
|
c = phy_read(phydev, IP1001_SPEC_CTRL_STATUS_2);
|
2012-02-21 21:24:57 +00:00
|
|
|
if (c < 0)
|
|
|
|
return c;
|
2011-09-06 20:14:50 +00:00
|
|
|
c |= IP1001_APS_ON;
|
2012-02-21 21:24:57 +00:00
|
|
|
c = phy_write(phydev, IP1001_SPEC_CTRL_STATUS_2, c);
|
2011-09-06 20:14:50 +00:00
|
|
|
if (c < 0)
|
|
|
|
return c;
|
2010-12-08 23:05:13 +00:00
|
|
|
|
2015-05-26 19:19:59 +00:00
|
|
|
if (phy_interface_is_rgmii(phydev)) {
|
2013-01-23 00:22:36 +00:00
|
|
|
|
2011-10-10 21:37:56 +00:00
|
|
|
c = phy_read(phydev, IP10XX_SPEC_CTRL_STATUS);
|
2012-02-21 21:24:57 +00:00
|
|
|
if (c < 0)
|
|
|
|
return c;
|
|
|
|
|
2013-01-23 00:22:36 +00: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-10 21:37:56 +00:00
|
|
|
c = phy_write(phydev, IP10XX_SPEC_CTRL_STATUS, c);
|
2012-02-21 21:24:57 +00:00
|
|
|
if (c < 0)
|
|
|
|
return c;
|
2011-10-10 21:37:56 +00:00
|
|
|
}
|
2011-09-06 20:14:50 +00:00
|
|
|
|
2012-02-21 21:24:57 +00:00
|
|
|
return 0;
|
2011-09-06 20:14:50 +00:00
|
|
|
}
|
|
|
|
|
2007-05-11 23:24:51 +00:00
|
|
|
static int ip175c_read_status(struct phy_device *phydev)
|
|
|
|
{
|
2016-01-06 19:11:16 +00:00
|
|
|
if (phydev->mdio.addr == 4) /* WAN port */
|
2007-05-11 23:24:51 +00:00
|
|
|
genphy_read_status(phydev);
|
|
|
|
else
|
|
|
|
/* Don't need to read status for switch ports */
|
2021-02-14 14:16:23 +00:00
|
|
|
phydev->irq = PHY_MAC_INTERRUPT;
|
2007-05-11 23:24:51 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ip175c_config_aneg(struct phy_device *phydev)
|
|
|
|
{
|
2016-01-06 19:11:16 +00:00
|
|
|
if (phydev->mdio.addr == 4) /* WAN port */
|
2007-05-11 23:24:51 +00:00
|
|
|
genphy_config_aneg(phydev);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-11-18 21:23:59 +00:00
|
|
|
static int ip101a_g_probe(struct phy_device *phydev)
|
|
|
|
{
|
|
|
|
struct device *dev = &phydev->mdio.dev;
|
|
|
|
struct ip101a_g_phy_priv *priv;
|
|
|
|
|
|
|
|
priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
|
|
|
|
if (!priv)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
/* Both functions (RX error and interrupt status) are sharing the same
|
|
|
|
* pin on the 32-pin IP101GR, so this is an exclusive choice.
|
|
|
|
*/
|
|
|
|
if (device_property_read_bool(dev, "icplus,select-rx-error") &&
|
|
|
|
device_property_read_bool(dev, "icplus,select-interrupt")) {
|
|
|
|
dev_err(dev,
|
|
|
|
"RXER and INTR mode cannot be selected together\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (device_property_read_bool(dev, "icplus,select-rx-error"))
|
|
|
|
priv->sel_intr32 = IP101GR_SEL_INTR32_RXER;
|
|
|
|
else if (device_property_read_bool(dev, "icplus,select-interrupt"))
|
|
|
|
priv->sel_intr32 = IP101GR_SEL_INTR32_INTR;
|
|
|
|
else
|
|
|
|
priv->sel_intr32 = IP101GR_SEL_INTR32_KEEP;
|
|
|
|
|
|
|
|
phydev->priv = priv;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-02-11 07:47:47 +00:00
|
|
|
static int ip101a_g_config_intr_pin(struct phy_device *phydev)
|
2018-11-18 21:23:55 +00:00
|
|
|
{
|
2018-11-18 21:23:59 +00:00
|
|
|
struct ip101a_g_phy_priv *priv = phydev->priv;
|
2021-02-11 07:47:48 +00:00
|
|
|
int oldpage, err = 0;
|
|
|
|
|
|
|
|
oldpage = phy_select_page(phydev, IP101G_DEFAULT_PAGE);
|
|
|
|
if (oldpage < 0)
|
2021-02-19 10:10:44 +00:00
|
|
|
goto out;
|
2018-11-18 21:23:55 +00:00
|
|
|
|
2018-11-18 21:23:59 +00:00
|
|
|
/* configure the RXER/INTR_32 pin of the 32-pin IP101GR if needed: */
|
|
|
|
switch (priv->sel_intr32) {
|
|
|
|
case IP101GR_SEL_INTR32_RXER:
|
2021-02-11 07:47:48 +00:00
|
|
|
err = __phy_modify(phydev, IP101G_DIGITAL_IO_SPEC_CTRL,
|
|
|
|
IP101G_DIGITAL_IO_SPEC_CTRL_SEL_INTR32, 0);
|
2018-11-18 21:23:59 +00:00
|
|
|
if (err < 0)
|
2021-02-11 07:47:48 +00:00
|
|
|
goto out;
|
2018-11-18 21:23:59 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case IP101GR_SEL_INTR32_INTR:
|
2021-02-11 07:47:48 +00:00
|
|
|
err = __phy_modify(phydev, IP101G_DIGITAL_IO_SPEC_CTRL,
|
|
|
|
IP101G_DIGITAL_IO_SPEC_CTRL_SEL_INTR32,
|
|
|
|
IP101G_DIGITAL_IO_SPEC_CTRL_SEL_INTR32);
|
2018-11-18 21:23:59 +00:00
|
|
|
if (err < 0)
|
2021-02-11 07:47:48 +00:00
|
|
|
goto out;
|
2018-11-18 21:23:59 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
/* Don't touch IP101G_DIGITAL_IO_SPEC_CTRL because it's not
|
|
|
|
* documented on IP101A and it's not clear whether this would
|
|
|
|
* cause problems.
|
|
|
|
* For the 32-pin IP101GR we simply keep the SEL_INTR32
|
|
|
|
* configuration as set by the bootloader when not configured
|
|
|
|
* to one of the special functions.
|
|
|
|
*/
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-02-11 07:47:48 +00:00
|
|
|
out:
|
|
|
|
return phy_restore_page(phydev, oldpage, err);
|
2021-02-11 07:47:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int ip101a_config_init(struct phy_device *phydev)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2018-11-18 21:23:55 +00:00
|
|
|
/* Enable Auto Power Saving mode */
|
2021-02-11 07:47:47 +00:00
|
|
|
ret = phy_set_bits(phydev, IP10XX_SPEC_CTRL_STATUS, IP101A_G_APS_ON);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2018-11-18 21:23:55 +00:00
|
|
|
|
2021-02-11 07:47:47 +00:00
|
|
|
return ip101a_g_config_intr_pin(phydev);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ip101g_config_init(struct phy_device *phydev)
|
|
|
|
{
|
2021-02-11 07:47:49 +00:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Enable the PHY counters */
|
|
|
|
ret = phy_modify_paged(phydev, 1, IP101G_P1_CNT_CTRL,
|
|
|
|
CNT_CTRL_RX_EN, CNT_CTRL_RX_EN);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
/* Clear error counters on read */
|
|
|
|
ret = phy_modify_paged(phydev, 8, IP101G_P8_CNT_CTRL,
|
|
|
|
CNT_CTRL_RDCLR_EN, CNT_CTRL_RDCLR_EN);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2021-02-11 07:47:47 +00:00
|
|
|
return ip101a_g_config_intr_pin(phydev);
|
2018-11-18 21:23:55 +00:00
|
|
|
}
|
|
|
|
|
2021-02-11 07:47:50 +00:00
|
|
|
static int ip101a_g_read_status(struct phy_device *phydev)
|
|
|
|
{
|
|
|
|
int oldpage, ret, stat1, stat2;
|
|
|
|
|
|
|
|
ret = genphy_read_status(phydev);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
oldpage = phy_select_page(phydev, IP101G_DEFAULT_PAGE);
|
|
|
|
if (oldpage < 0)
|
2021-02-19 10:10:44 +00:00
|
|
|
goto out;
|
2021-02-11 07:47:50 +00:00
|
|
|
|
|
|
|
ret = __phy_read(phydev, IP10XX_SPEC_CTRL_STATUS);
|
|
|
|
if (ret < 0)
|
|
|
|
goto out;
|
|
|
|
stat1 = ret;
|
|
|
|
|
|
|
|
ret = __phy_read(phydev, IP101A_G_PHY_SPEC_CTRL);
|
|
|
|
if (ret < 0)
|
|
|
|
goto out;
|
|
|
|
stat2 = ret;
|
|
|
|
|
|
|
|
if (stat1 & IP101A_G_AUTO_MDIX_DIS) {
|
|
|
|
if (stat2 & IP101A_G_FORCE_MDIX)
|
|
|
|
phydev->mdix_ctrl = ETH_TP_MDI_X;
|
|
|
|
else
|
|
|
|
phydev->mdix_ctrl = ETH_TP_MDI;
|
|
|
|
} else {
|
|
|
|
phydev->mdix_ctrl = ETH_TP_MDI_AUTO;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stat2 & IP101A_G_MDIX)
|
|
|
|
phydev->mdix = ETH_TP_MDI_X;
|
|
|
|
else
|
|
|
|
phydev->mdix = ETH_TP_MDI;
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
out:
|
|
|
|
return phy_restore_page(phydev, oldpage, ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ip101a_g_config_mdix(struct phy_device *phydev)
|
|
|
|
{
|
|
|
|
u16 ctrl = 0, ctrl2 = 0;
|
2021-02-19 10:10:44 +00:00
|
|
|
int oldpage;
|
|
|
|
int ret = 0;
|
2021-02-11 07:47:50 +00:00
|
|
|
|
|
|
|
switch (phydev->mdix_ctrl) {
|
|
|
|
case ETH_TP_MDI:
|
|
|
|
ctrl = IP101A_G_AUTO_MDIX_DIS;
|
|
|
|
break;
|
|
|
|
case ETH_TP_MDI_X:
|
|
|
|
ctrl = IP101A_G_AUTO_MDIX_DIS;
|
|
|
|
ctrl2 = IP101A_G_FORCE_MDIX;
|
|
|
|
break;
|
|
|
|
case ETH_TP_MDI_AUTO:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
oldpage = phy_select_page(phydev, IP101G_DEFAULT_PAGE);
|
|
|
|
if (oldpage < 0)
|
2021-02-19 10:10:44 +00:00
|
|
|
goto out;
|
2021-02-11 07:47:50 +00:00
|
|
|
|
|
|
|
ret = __phy_modify(phydev, IP10XX_SPEC_CTRL_STATUS,
|
|
|
|
IP101A_G_AUTO_MDIX_DIS, ctrl);
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
ret = __phy_modify(phydev, IP101A_G_PHY_SPEC_CTRL,
|
|
|
|
IP101A_G_FORCE_MDIX, ctrl2);
|
|
|
|
|
|
|
|
out:
|
|
|
|
return phy_restore_page(phydev, oldpage, ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ip101a_g_config_aneg(struct phy_device *phydev)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = ip101a_g_config_mdix(phydev);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return genphy_config_aneg(phydev);
|
|
|
|
}
|
|
|
|
|
2020-11-23 15:38:06 +00:00
|
|
|
static int ip101a_g_ack_interrupt(struct phy_device *phydev)
|
|
|
|
{
|
2021-02-11 07:47:48 +00:00
|
|
|
int err;
|
2020-11-23 15:38:06 +00:00
|
|
|
|
2021-02-11 07:47:48 +00:00
|
|
|
err = phy_read_paged(phydev, IP101G_DEFAULT_PAGE,
|
|
|
|
IP101A_G_IRQ_CONF_STATUS);
|
2020-11-23 15:38:06 +00:00
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-11-11 20:49:12 +00:00
|
|
|
static int ip101a_g_config_intr(struct phy_device *phydev)
|
|
|
|
{
|
|
|
|
u16 val;
|
2020-11-23 15:38:06 +00:00
|
|
|
int err;
|
|
|
|
|
|
|
|
if (phydev->interrupts == PHY_INTERRUPT_ENABLED) {
|
|
|
|
err = ip101a_g_ack_interrupt(phydev);
|
|
|
|
if (err)
|
|
|
|
return err;
|
2018-11-11 20:49:12 +00:00
|
|
|
|
|
|
|
/* INTR pin used: Speed/link/duplex will cause an interrupt */
|
|
|
|
val = IP101A_G_IRQ_PIN_USED;
|
2021-02-11 07:47:48 +00:00
|
|
|
err = phy_write_paged(phydev, IP101G_DEFAULT_PAGE,
|
|
|
|
IP101A_G_IRQ_CONF_STATUS, val);
|
2020-11-23 15:38:06 +00:00
|
|
|
} else {
|
2018-11-18 21:23:57 +00:00
|
|
|
val = IP101A_G_IRQ_ALL_MASK;
|
2021-02-11 07:47:48 +00:00
|
|
|
err = phy_write_paged(phydev, IP101G_DEFAULT_PAGE,
|
|
|
|
IP101A_G_IRQ_CONF_STATUS, val);
|
2020-11-23 15:38:06 +00:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
err = ip101a_g_ack_interrupt(phydev);
|
|
|
|
}
|
2018-11-11 20:49:12 +00:00
|
|
|
|
2020-11-23 15:38:06 +00:00
|
|
|
return err;
|
2018-11-11 20:49:12 +00:00
|
|
|
}
|
|
|
|
|
2020-11-23 15:38:05 +00:00
|
|
|
static irqreturn_t ip101a_g_handle_interrupt(struct phy_device *phydev)
|
2018-11-18 21:23:58 +00:00
|
|
|
{
|
2020-11-23 15:38:05 +00:00
|
|
|
int irq_status;
|
2018-11-18 21:23:58 +00:00
|
|
|
|
2021-02-11 07:47:48 +00:00
|
|
|
irq_status = phy_read_paged(phydev, IP101G_DEFAULT_PAGE,
|
|
|
|
IP101A_G_IRQ_CONF_STATUS);
|
2020-11-23 15:38:05 +00:00
|
|
|
if (irq_status < 0) {
|
|
|
|
phy_error(phydev);
|
|
|
|
return IRQ_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(irq_status & (IP101A_G_IRQ_SPEED_CHANGE |
|
|
|
|
IP101A_G_IRQ_DUPLEX_CHANGE |
|
|
|
|
IP101A_G_IRQ_LINK_CHANGE)))
|
|
|
|
return IRQ_NONE;
|
|
|
|
|
|
|
|
phy_trigger_machine(phydev);
|
2018-11-18 21:23:58 +00:00
|
|
|
|
2020-11-23 15:38:05 +00:00
|
|
|
return IRQ_HANDLED;
|
2018-11-18 21:23:58 +00:00
|
|
|
}
|
|
|
|
|
2021-02-11 07:47:48 +00:00
|
|
|
/* The IP101A doesn't really have a page register. We just pretend to have one
|
|
|
|
* so we can use the paged versions of the callbacks of the IP101G.
|
|
|
|
*/
|
|
|
|
static int ip101a_read_page(struct phy_device *phydev)
|
|
|
|
{
|
|
|
|
return IP101G_DEFAULT_PAGE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ip101a_write_page(struct phy_device *phydev, int page)
|
|
|
|
{
|
|
|
|
WARN_ONCE(page != IP101G_DEFAULT_PAGE, "wrong page selected\n");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ip101g_read_page(struct phy_device *phydev)
|
|
|
|
{
|
|
|
|
return __phy_read(phydev, IP101G_PAGE_CONTROL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ip101g_write_page(struct phy_device *phydev, int page)
|
|
|
|
{
|
|
|
|
return __phy_write(phydev, IP101G_PAGE_CONTROL, page);
|
|
|
|
}
|
|
|
|
|
2021-02-11 07:47:46 +00:00
|
|
|
static int ip101a_g_has_page_register(struct phy_device *phydev)
|
|
|
|
{
|
|
|
|
int oldval, val, ret;
|
|
|
|
|
|
|
|
oldval = phy_read(phydev, IP101G_PAGE_CONTROL);
|
|
|
|
if (oldval < 0)
|
|
|
|
return oldval;
|
|
|
|
|
|
|
|
ret = phy_write(phydev, IP101G_PAGE_CONTROL, 0xffff);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
val = phy_read(phydev, IP101G_PAGE_CONTROL);
|
|
|
|
if (val < 0)
|
|
|
|
return val;
|
|
|
|
|
|
|
|
ret = phy_write(phydev, IP101G_PAGE_CONTROL, oldval);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return val == IP101G_PAGE_CONTROL_MASK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ip101a_g_match_phy_device(struct phy_device *phydev, bool ip101a)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (phydev->phy_id != IP101A_PHY_ID)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* The IP101A and the IP101G share the same PHY identifier.The IP101G
|
|
|
|
* seems to be a successor of the IP101A and implements more functions.
|
|
|
|
* Amongst other things there is a page select register, which is not
|
|
|
|
* available on the IP101A. Use this to distinguish these two.
|
|
|
|
*/
|
|
|
|
ret = ip101a_g_has_page_register(phydev);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return ip101a == !ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ip101a_match_phy_device(struct phy_device *phydev)
|
|
|
|
{
|
|
|
|
return ip101a_g_match_phy_device(phydev, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ip101g_match_phy_device(struct phy_device *phydev)
|
|
|
|
{
|
|
|
|
return ip101a_g_match_phy_device(phydev, false);
|
|
|
|
}
|
|
|
|
|
2021-02-11 07:47:49 +00:00
|
|
|
static int ip101g_get_sset_count(struct phy_device *phydev)
|
|
|
|
{
|
|
|
|
return ARRAY_SIZE(ip101g_hw_stats);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ip101g_get_strings(struct phy_device *phydev, u8 *data)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(ip101g_hw_stats); i++)
|
|
|
|
strscpy(data + i * ETH_GSTRING_LEN,
|
|
|
|
ip101g_hw_stats[i].name, ETH_GSTRING_LEN);
|
|
|
|
}
|
|
|
|
|
|
|
|
static u64 ip101g_get_stat(struct phy_device *phydev, int i)
|
|
|
|
{
|
|
|
|
struct ip101g_hw_stat stat = ip101g_hw_stats[i];
|
|
|
|
struct ip101a_g_phy_priv *priv = phydev->priv;
|
|
|
|
int val;
|
|
|
|
u64 ret;
|
|
|
|
|
|
|
|
val = phy_read_paged(phydev, stat.page, IP101G_CNT_REG);
|
|
|
|
if (val < 0) {
|
|
|
|
ret = U64_MAX;
|
|
|
|
} else {
|
|
|
|
priv->stats[i] += val;
|
|
|
|
ret = priv->stats[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ip101g_get_stats(struct phy_device *phydev,
|
|
|
|
struct ethtool_stats *stats, u64 *data)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(ip101g_hw_stats); i++)
|
|
|
|
data[i] = ip101g_get_stat(phydev, i);
|
|
|
|
}
|
|
|
|
|
2012-07-04 05:44:34 +00:00
|
|
|
static struct phy_driver icplus_driver[] = {
|
|
|
|
{
|
2021-02-11 07:47:42 +00:00
|
|
|
PHY_ID_MATCH_MODEL(IP175C_PHY_ID),
|
2007-05-11 23:24:51 +00:00
|
|
|
.name = "ICPlus IP175C",
|
2019-04-12 18:47:03 +00:00
|
|
|
/* PHY_BASIC_FEATURES */
|
2021-02-11 07:47:44 +00:00
|
|
|
.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,
|
2012-07-04 05:44:34 +00:00
|
|
|
}, {
|
2021-02-11 07:47:42 +00:00
|
|
|
PHY_ID_MATCH_MODEL(IP1001_PHY_ID),
|
2010-12-08 23:05:13 +00:00
|
|
|
.name = "ICPlus IP1001",
|
2019-04-12 18:47:03 +00:00
|
|
|
/* PHY_GBIT_FEATURES */
|
2021-02-11 07:47:44 +00:00
|
|
|
.config_init = ip1001_config_init,
|
2021-02-11 07:47:45 +00:00
|
|
|
.soft_reset = genphy_soft_reset,
|
2010-12-08 23:05:13 +00:00
|
|
|
.suspend = genphy_suspend,
|
|
|
|
.resume = genphy_resume,
|
2012-07-04 05:44:34 +00:00
|
|
|
}, {
|
2021-02-11 07:47:46 +00:00
|
|
|
.name = "ICPlus IP101A",
|
|
|
|
.match_phy_device = ip101a_match_phy_device,
|
|
|
|
.probe = ip101a_g_probe,
|
2021-02-11 07:47:48 +00:00
|
|
|
.read_page = ip101a_read_page,
|
|
|
|
.write_page = ip101a_write_page,
|
2021-02-11 07:47:46 +00:00
|
|
|
.config_intr = ip101a_g_config_intr,
|
|
|
|
.handle_interrupt = ip101a_g_handle_interrupt,
|
2021-02-11 07:47:47 +00:00
|
|
|
.config_init = ip101a_config_init,
|
2021-02-11 07:47:50 +00:00
|
|
|
.config_aneg = ip101a_g_config_aneg,
|
|
|
|
.read_status = ip101a_g_read_status,
|
2021-02-11 07:47:46 +00:00
|
|
|
.soft_reset = genphy_soft_reset,
|
|
|
|
.suspend = genphy_suspend,
|
|
|
|
.resume = genphy_resume,
|
|
|
|
}, {
|
|
|
|
.name = "ICPlus IP101G",
|
|
|
|
.match_phy_device = ip101g_match_phy_device,
|
2018-11-18 21:23:59 +00:00
|
|
|
.probe = ip101a_g_probe,
|
2021-02-11 07:47:48 +00:00
|
|
|
.read_page = ip101g_read_page,
|
|
|
|
.write_page = ip101g_write_page,
|
2018-11-11 20:49:12 +00:00
|
|
|
.config_intr = ip101a_g_config_intr,
|
2020-11-23 15:38:05 +00:00
|
|
|
.handle_interrupt = ip101a_g_handle_interrupt,
|
2021-02-11 07:47:47 +00:00
|
|
|
.config_init = ip101g_config_init,
|
2021-02-11 07:47:50 +00:00
|
|
|
.config_aneg = ip101a_g_config_aneg,
|
|
|
|
.read_status = ip101a_g_read_status,
|
2021-02-11 07:47:45 +00:00
|
|
|
.soft_reset = genphy_soft_reset,
|
2021-02-11 07:47:49 +00:00
|
|
|
.get_sset_count = ip101g_get_sset_count,
|
|
|
|
.get_strings = ip101g_get_strings,
|
|
|
|
.get_stats = ip101g_get_stats,
|
2011-09-06 20:14:50 +00:00
|
|
|
.suspend = genphy_suspend,
|
|
|
|
.resume = genphy_resume,
|
2012-07-04 05:44:34 +00:00
|
|
|
} };
|
2011-09-06 20:14:50 +00:00
|
|
|
|
2014-11-11 18:45:59 +00:00
|
|
|
module_phy_driver(icplus_driver);
|
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[] = {
|
2021-02-11 07:47:42 +00:00
|
|
|
{ PHY_ID_MATCH_MODEL(IP175C_PHY_ID) },
|
|
|
|
{ PHY_ID_MATCH_MODEL(IP1001_PHY_ID) },
|
2021-02-11 07:47:43 +00:00
|
|
|
{ PHY_ID_MATCH_EXACT(IP101A_PHY_ID) },
|
2010-04-02 01:05:56 +00:00
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
MODULE_DEVICE_TABLE(mdio, icplus_tbl);
|