提交 c6f9575c 编写于 作者: J Johan Hovold 提交者: David S. Miller

net: phy: micrel: refactor interrupt config

Add generic interrupt-config callback and store interrupt-level bitmask
in type data for PHY types not using bit 9.
Signed-off-by: NJohan Hovold <johan@kernel.org>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
上级 c3a8e1ed
...@@ -55,8 +55,6 @@ ...@@ -55,8 +55,6 @@
#define MII_KSZPHY_CTRL MII_KSZPHY_CTRL_2 #define MII_KSZPHY_CTRL MII_KSZPHY_CTRL_2
/* bitmap of PHY register to set interrupt mode */ /* bitmap of PHY register to set interrupt mode */
#define KSZPHY_CTRL_INT_ACTIVE_HIGH BIT(9) #define KSZPHY_CTRL_INT_ACTIVE_HIGH BIT(9)
#define KSZ9021_CTRL_INT_ACTIVE_HIGH BIT(14)
#define KS8737_CTRL_INT_ACTIVE_HIGH BIT(14)
#define KSZPHY_RMII_REF_CLK_SEL BIT(7) #define KSZPHY_RMII_REF_CLK_SEL BIT(7)
/* Write/read to/from extended registers */ /* Write/read to/from extended registers */
...@@ -75,6 +73,7 @@ ...@@ -75,6 +73,7 @@
struct kszphy_type { struct kszphy_type {
u32 led_mode_reg; u32 led_mode_reg;
u16 interrupt_level_mask;
bool has_broadcast_disable; bool has_broadcast_disable;
bool has_rmii_ref_clk_sel; bool has_rmii_ref_clk_sel;
}; };
...@@ -105,6 +104,14 @@ static const struct kszphy_type ksz8081_type = { ...@@ -105,6 +104,14 @@ static const struct kszphy_type ksz8081_type = {
.has_rmii_ref_clk_sel = true, .has_rmii_ref_clk_sel = true,
}; };
static const struct kszphy_type ks8737_type = {
.interrupt_level_mask = BIT(14),
};
static const struct kszphy_type ksz9021_type = {
.interrupt_level_mask = BIT(14),
};
static int kszphy_extended_write(struct phy_device *phydev, static int kszphy_extended_write(struct phy_device *phydev,
u32 regnum, u16 val) u32 regnum, u16 val)
{ {
...@@ -129,54 +136,31 @@ static int kszphy_ack_interrupt(struct phy_device *phydev) ...@@ -129,54 +136,31 @@ static int kszphy_ack_interrupt(struct phy_device *phydev)
return (rc < 0) ? rc : 0; return (rc < 0) ? rc : 0;
} }
static int kszphy_set_interrupt(struct phy_device *phydev)
{
int temp;
temp = (PHY_INTERRUPT_ENABLED == phydev->interrupts) ?
KSZPHY_INTCS_ALL : 0;
return phy_write(phydev, MII_KSZPHY_INTCS, temp);
}
static int kszphy_config_intr(struct phy_device *phydev) static int kszphy_config_intr(struct phy_device *phydev)
{ {
int temp, rc; const struct kszphy_type *type = phydev->drv->driver_data;
int temp;
/* set the interrupt pin active low */ u16 mask;
temp = phy_read(phydev, MII_KSZPHY_CTRL);
if (temp < 0)
return temp;
temp &= ~KSZPHY_CTRL_INT_ACTIVE_HIGH;
phy_write(phydev, MII_KSZPHY_CTRL, temp);
rc = kszphy_set_interrupt(phydev);
return rc < 0 ? rc : 0;
}
static int ksz9021_config_intr(struct phy_device *phydev) if (type && type->interrupt_level_mask)
{ mask = type->interrupt_level_mask;
int temp, rc; else
mask = KSZPHY_CTRL_INT_ACTIVE_HIGH;
/* set the interrupt pin active low */ /* set the interrupt pin active low */
temp = phy_read(phydev, MII_KSZPHY_CTRL); temp = phy_read(phydev, MII_KSZPHY_CTRL);
if (temp < 0) if (temp < 0)
return temp; return temp;
temp &= ~KSZ9021_CTRL_INT_ACTIVE_HIGH; temp &= ~mask;
phy_write(phydev, MII_KSZPHY_CTRL, temp); phy_write(phydev, MII_KSZPHY_CTRL, temp);
rc = kszphy_set_interrupt(phydev);
return rc < 0 ? rc : 0;
}
static int ks8737_config_intr(struct phy_device *phydev) /* enable / disable interrupts */
{ if (phydev->interrupts == PHY_INTERRUPT_ENABLED)
int temp, rc; temp = KSZPHY_INTCS_ALL;
else
temp = 0;
/* set the interrupt pin active low */ return phy_write(phydev, MII_KSZPHY_INTCS, temp);
temp = phy_read(phydev, MII_KSZPHY_CTRL);
if (temp < 0)
return temp;
temp &= ~KS8737_CTRL_INT_ACTIVE_HIGH;
phy_write(phydev, MII_KSZPHY_CTRL, temp);
rc = kszphy_set_interrupt(phydev);
return rc < 0 ? rc : 0;
} }
static int kszphy_rmii_clk_sel(struct phy_device *phydev, bool val) static int kszphy_rmii_clk_sel(struct phy_device *phydev, bool val)
...@@ -581,11 +565,12 @@ static struct phy_driver ksphy_driver[] = { ...@@ -581,11 +565,12 @@ static struct phy_driver ksphy_driver[] = {
.name = "Micrel KS8737", .name = "Micrel KS8737",
.features = (PHY_BASIC_FEATURES | SUPPORTED_Pause), .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause),
.flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT, .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
.driver_data = &ks8737_type,
.config_init = kszphy_config_init, .config_init = kszphy_config_init,
.config_aneg = genphy_config_aneg, .config_aneg = genphy_config_aneg,
.read_status = genphy_read_status, .read_status = genphy_read_status,
.ack_interrupt = kszphy_ack_interrupt, .ack_interrupt = kszphy_ack_interrupt,
.config_intr = ks8737_config_intr, .config_intr = kszphy_config_intr,
.suspend = genphy_suspend, .suspend = genphy_suspend,
.resume = genphy_resume, .resume = genphy_resume,
.driver = { .owner = THIS_MODULE,}, .driver = { .owner = THIS_MODULE,},
...@@ -726,11 +711,12 @@ static struct phy_driver ksphy_driver[] = { ...@@ -726,11 +711,12 @@ static struct phy_driver ksphy_driver[] = {
.name = "Micrel KSZ9021 Gigabit PHY", .name = "Micrel KSZ9021 Gigabit PHY",
.features = (PHY_GBIT_FEATURES | SUPPORTED_Pause), .features = (PHY_GBIT_FEATURES | SUPPORTED_Pause),
.flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT, .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
.driver_data = &ksz9021_type,
.config_init = ksz9021_config_init, .config_init = ksz9021_config_init,
.config_aneg = genphy_config_aneg, .config_aneg = genphy_config_aneg,
.read_status = genphy_read_status, .read_status = genphy_read_status,
.ack_interrupt = kszphy_ack_interrupt, .ack_interrupt = kszphy_ack_interrupt,
.config_intr = ksz9021_config_intr, .config_intr = kszphy_config_intr,
.suspend = genphy_suspend, .suspend = genphy_suspend,
.resume = genphy_resume, .resume = genphy_resume,
.read_mmd_indirect = ksz9021_rd_mmd_phyreg, .read_mmd_indirect = ksz9021_rd_mmd_phyreg,
...@@ -742,11 +728,12 @@ static struct phy_driver ksphy_driver[] = { ...@@ -742,11 +728,12 @@ static struct phy_driver ksphy_driver[] = {
.name = "Micrel KSZ9031 Gigabit PHY", .name = "Micrel KSZ9031 Gigabit PHY",
.features = (PHY_GBIT_FEATURES | SUPPORTED_Pause), .features = (PHY_GBIT_FEATURES | SUPPORTED_Pause),
.flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT, .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
.driver_data = &ksz9021_type,
.config_init = ksz9031_config_init, .config_init = ksz9031_config_init,
.config_aneg = genphy_config_aneg, .config_aneg = genphy_config_aneg,
.read_status = genphy_read_status, .read_status = genphy_read_status,
.ack_interrupt = kszphy_ack_interrupt, .ack_interrupt = kszphy_ack_interrupt,
.config_intr = ksz9021_config_intr, .config_intr = kszphy_config_intr,
.suspend = genphy_suspend, .suspend = genphy_suspend,
.resume = genphy_resume, .resume = genphy_resume,
.driver = { .owner = THIS_MODULE, }, .driver = { .owner = THIS_MODULE, },
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册