2019-01-22 02:05:50 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2008-11-29 08:42:41 +08:00
|
|
|
/*
|
|
|
|
* drivers/net/phy/ste10Xp.c
|
|
|
|
*
|
|
|
|
* Driver for STMicroelectronics STe10Xp PHYs
|
|
|
|
*
|
|
|
|
* Author: Giuseppe Cavallaro <peppe.cavallaro@st.com>
|
|
|
|
*
|
|
|
|
* Copyright (c) 2008 STMicroelectronics Limited
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/moduleparam.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/netdevice.h>
|
|
|
|
#include <linux/ethtool.h>
|
|
|
|
#include <linux/mii.h>
|
|
|
|
#include <linux/phy.h>
|
|
|
|
|
2021-06-16 18:01:22 +08:00
|
|
|
#define MII_XCIIS 0x11 /* Configuration Info IRQ & Status Reg */
|
|
|
|
#define MII_XIE 0x12 /* Interrupt Enable Register */
|
2008-11-29 08:42:41 +08:00
|
|
|
#define MII_XIE_DEFAULT_MASK 0x0070 /* ANE complete, Remote Fault, Link Down */
|
|
|
|
|
|
|
|
#define STE101P_PHY_ID 0x00061c50
|
2021-06-16 18:01:22 +08:00
|
|
|
#define STE100P_PHY_ID 0x1c040011
|
2008-11-29 08:42:41 +08:00
|
|
|
|
|
|
|
static int ste10Xp_config_init(struct phy_device *phydev)
|
|
|
|
{
|
|
|
|
int value, err;
|
|
|
|
|
|
|
|
/* Software Reset PHY */
|
|
|
|
value = phy_read(phydev, MII_BMCR);
|
|
|
|
if (value < 0)
|
|
|
|
return value;
|
|
|
|
|
|
|
|
value |= BMCR_RESET;
|
|
|
|
err = phy_write(phydev, MII_BMCR, value);
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
do {
|
|
|
|
value = phy_read(phydev, MII_BMCR);
|
|
|
|
} while (value & BMCR_RESET);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-11-14 00:52:24 +08:00
|
|
|
static int ste10Xp_ack_interrupt(struct phy_device *phydev)
|
|
|
|
{
|
|
|
|
int err = phy_read(phydev, MII_XCIIS);
|
|
|
|
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-11-29 08:42:41 +08:00
|
|
|
static int ste10Xp_config_intr(struct phy_device *phydev)
|
|
|
|
{
|
2020-11-14 00:52:24 +08:00
|
|
|
int err;
|
2008-11-29 08:42:41 +08:00
|
|
|
|
|
|
|
if (phydev->interrupts == PHY_INTERRUPT_ENABLED) {
|
2020-11-14 00:52:24 +08:00
|
|
|
/* clear any pending interrupts */
|
|
|
|
err = ste10Xp_ack_interrupt(phydev);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
2008-11-29 08:42:41 +08:00
|
|
|
/* Enable all STe101P interrupts (PR12) */
|
|
|
|
err = phy_write(phydev, MII_XIE, MII_XIE_DEFAULT_MASK);
|
2020-11-14 00:52:24 +08:00
|
|
|
} else {
|
2008-11-29 08:42:41 +08:00
|
|
|
err = phy_write(phydev, MII_XIE, 0);
|
2020-11-14 00:52:24 +08:00
|
|
|
if (err)
|
|
|
|
return err;
|
2008-11-29 08:42:41 +08:00
|
|
|
|
2020-11-14 00:52:24 +08:00
|
|
|
err = ste10Xp_ack_interrupt(phydev);
|
|
|
|
}
|
2008-11-29 08:42:41 +08:00
|
|
|
|
2020-11-14 00:52:24 +08:00
|
|
|
return err;
|
2008-11-29 08:42:41 +08:00
|
|
|
}
|
|
|
|
|
2020-11-14 00:52:23 +08:00
|
|
|
static irqreturn_t ste10Xp_handle_interrupt(struct phy_device *phydev)
|
|
|
|
{
|
|
|
|
int irq_status;
|
|
|
|
|
|
|
|
irq_status = phy_read(phydev, MII_XCIIS);
|
|
|
|
if (irq_status < 0) {
|
|
|
|
phy_error(phydev);
|
|
|
|
return IRQ_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(irq_status & MII_XIE_DEFAULT_MASK))
|
|
|
|
return IRQ_NONE;
|
|
|
|
|
|
|
|
phy_trigger_machine(phydev);
|
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
2012-07-04 13:44:34 +08:00
|
|
|
static struct phy_driver ste10xp_pdriver[] = {
|
|
|
|
{
|
2008-11-29 08:42:41 +08:00
|
|
|
.phy_id = STE101P_PHY_ID,
|
|
|
|
.phy_id_mask = 0xfffffff0,
|
|
|
|
.name = "STe101p",
|
2019-04-13 02:47:03 +08:00
|
|
|
/* PHY_BASIC_FEATURES */
|
2008-11-29 08:42:41 +08:00
|
|
|
.config_init = ste10Xp_config_init,
|
|
|
|
.config_intr = ste10Xp_config_intr,
|
2020-11-14 00:52:23 +08:00
|
|
|
.handle_interrupt = ste10Xp_handle_interrupt,
|
2008-11-29 08:42:41 +08:00
|
|
|
.suspend = genphy_suspend,
|
|
|
|
.resume = genphy_resume,
|
2012-07-04 13:44:34 +08:00
|
|
|
}, {
|
2008-11-29 08:42:41 +08:00
|
|
|
.phy_id = STE100P_PHY_ID,
|
|
|
|
.phy_id_mask = 0xffffffff,
|
|
|
|
.name = "STe100p",
|
2019-04-13 02:47:03 +08:00
|
|
|
/* PHY_BASIC_FEATURES */
|
2008-11-29 08:42:41 +08:00
|
|
|
.config_init = ste10Xp_config_init,
|
|
|
|
.config_intr = ste10Xp_config_intr,
|
2020-11-14 00:52:23 +08:00
|
|
|
.handle_interrupt = ste10Xp_handle_interrupt,
|
2008-11-29 08:42:41 +08:00
|
|
|
.suspend = genphy_suspend,
|
|
|
|
.resume = genphy_resume,
|
2012-07-04 13:44:34 +08:00
|
|
|
} };
|
2008-11-29 08:42:41 +08:00
|
|
|
|
2014-11-12 02:45:59 +08:00
|
|
|
module_phy_driver(ste10xp_pdriver);
|
2008-11-29 08:42:41 +08:00
|
|
|
|
2010-10-04 07:43:32 +08:00
|
|
|
static struct mdio_device_id __maybe_unused ste10Xp_tbl[] = {
|
2010-04-02 09:05:56 +08:00
|
|
|
{ STE101P_PHY_ID, 0xfffffff0 },
|
|
|
|
{ STE100P_PHY_ID, 0xffffffff },
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
MODULE_DEVICE_TABLE(mdio, ste10Xp_tbl);
|
|
|
|
|
2008-11-29 08:42:41 +08:00
|
|
|
MODULE_DESCRIPTION("STMicroelectronics STe10Xp PHY driver");
|
|
|
|
MODULE_AUTHOR("Giuseppe Cavallaro <peppe.cavallaro@st.com>");
|
|
|
|
MODULE_LICENSE("GPL");
|