Commit f3f6631b authored by David S. Miller's avatar David S. Miller

Merge branch 'lan8814-led'

Divya Koppera says:

====================
net: LED feature for LAN8814 PHY

Enable LED mode configuration for LAN8814 PHY

v2 -> v3:
- Fixed compilation issues

v1 -> v2:
- Updated dt-bindings for micrel,led-mode in LAN8814 PHY
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 504148fe a516b7f7
...@@ -16,6 +16,7 @@ Optional properties: ...@@ -16,6 +16,7 @@ Optional properties:
KSZ8051: register 0x1f, bits 5..4 KSZ8051: register 0x1f, bits 5..4
KSZ8081: register 0x1f, bits 5..4 KSZ8081: register 0x1f, bits 5..4
KSZ8091: register 0x1f, bits 5..4 KSZ8091: register 0x1f, bits 5..4
LAN8814: register EP5.0, bit 6
See the respective PHY datasheet for the mode values. See the respective PHY datasheet for the mode values.
......
...@@ -209,6 +209,9 @@ ...@@ -209,6 +209,9 @@
#define PTP_TSU_INT_STS_PTP_RX_TS_OVRFL_INT_ BIT(1) #define PTP_TSU_INT_STS_PTP_RX_TS_OVRFL_INT_ BIT(1)
#define PTP_TSU_INT_STS_PTP_RX_TS_EN_ BIT(0) #define PTP_TSU_INT_STS_PTP_RX_TS_EN_ BIT(0)
#define LAN8814_LED_CTRL_1 0x0
#define LAN8814_LED_CTRL_1_KSZ9031_LED_MODE_ BIT(6)
/* PHY Control 1 */ /* PHY Control 1 */
#define MII_KSZPHY_CTRL_1 0x1e #define MII_KSZPHY_CTRL_1 0x1e
#define KSZ8081_CTRL1_MDIX_STAT BIT(4) #define KSZ8081_CTRL1_MDIX_STAT BIT(4)
...@@ -308,6 +311,10 @@ struct kszphy_priv { ...@@ -308,6 +311,10 @@ struct kszphy_priv {
u64 stats[ARRAY_SIZE(kszphy_hw_stats)]; u64 stats[ARRAY_SIZE(kszphy_hw_stats)];
}; };
static const struct kszphy_type lan8814_type = {
.led_mode_reg = ~LAN8814_LED_CTRL_1,
};
static const struct kszphy_type ksz8021_type = { static const struct kszphy_type ksz8021_type = {
.led_mode_reg = MII_KSZPHY_CTRL_2, .led_mode_reg = MII_KSZPHY_CTRL_2,
.has_broadcast_disable = true, .has_broadcast_disable = true,
...@@ -1688,6 +1695,30 @@ static int kszphy_suspend(struct phy_device *phydev) ...@@ -1688,6 +1695,30 @@ static int kszphy_suspend(struct phy_device *phydev)
return genphy_suspend(phydev); return genphy_suspend(phydev);
} }
static void kszphy_parse_led_mode(struct phy_device *phydev)
{
const struct kszphy_type *type = phydev->drv->driver_data;
const struct device_node *np = phydev->mdio.dev.of_node;
struct kszphy_priv *priv = phydev->priv;
int ret;
if (type && type->led_mode_reg) {
ret = of_property_read_u32(np, "micrel,led-mode",
&priv->led_mode);
if (ret)
priv->led_mode = -1;
if (priv->led_mode > 3) {
phydev_err(phydev, "invalid led mode: 0x%02x\n",
priv->led_mode);
priv->led_mode = -1;
}
} else {
priv->led_mode = -1;
}
}
static int kszphy_resume(struct phy_device *phydev) static int kszphy_resume(struct phy_device *phydev)
{ {
int ret; int ret;
...@@ -1720,7 +1751,6 @@ static int kszphy_probe(struct phy_device *phydev) ...@@ -1720,7 +1751,6 @@ static int kszphy_probe(struct phy_device *phydev)
const struct device_node *np = phydev->mdio.dev.of_node; const struct device_node *np = phydev->mdio.dev.of_node;
struct kszphy_priv *priv; struct kszphy_priv *priv;
struct clk *clk; struct clk *clk;
int ret;
priv = devm_kzalloc(&phydev->mdio.dev, sizeof(*priv), GFP_KERNEL); priv = devm_kzalloc(&phydev->mdio.dev, sizeof(*priv), GFP_KERNEL);
if (!priv) if (!priv)
...@@ -1730,20 +1760,7 @@ static int kszphy_probe(struct phy_device *phydev) ...@@ -1730,20 +1760,7 @@ static int kszphy_probe(struct phy_device *phydev)
priv->type = type; priv->type = type;
if (type && type->led_mode_reg) { kszphy_parse_led_mode(phydev);
ret = of_property_read_u32(np, "micrel,led-mode",
&priv->led_mode);
if (ret)
priv->led_mode = -1;
if (priv->led_mode > 3) {
phydev_err(phydev, "invalid led mode: 0x%02x\n",
priv->led_mode);
priv->led_mode = -1;
}
} else {
priv->led_mode = -1;
}
clk = devm_clk_get(&phydev->mdio.dev, "rmii-ref"); clk = devm_clk_get(&phydev->mdio.dev, "rmii-ref");
/* NOTE: clk may be NULL if building without CONFIG_HAVE_CLK */ /* NOTE: clk may be NULL if building without CONFIG_HAVE_CLK */
...@@ -2815,8 +2832,23 @@ static int lan8814_ptp_probe_once(struct phy_device *phydev) ...@@ -2815,8 +2832,23 @@ static int lan8814_ptp_probe_once(struct phy_device *phydev)
return 0; return 0;
} }
static void lan8814_setup_led(struct phy_device *phydev, int val)
{
int temp;
temp = lanphy_read_page_reg(phydev, 5, LAN8814_LED_CTRL_1);
if (val)
temp |= LAN8814_LED_CTRL_1_KSZ9031_LED_MODE_;
else
temp &= ~LAN8814_LED_CTRL_1_KSZ9031_LED_MODE_;
lanphy_write_page_reg(phydev, 5, LAN8814_LED_CTRL_1, temp);
}
static int lan8814_config_init(struct phy_device *phydev) static int lan8814_config_init(struct phy_device *phydev)
{ {
struct kszphy_priv *lan8814 = phydev->priv;
int val; int val;
/* Reset the PHY */ /* Reset the PHY */
...@@ -2835,6 +2867,9 @@ static int lan8814_config_init(struct phy_device *phydev) ...@@ -2835,6 +2867,9 @@ static int lan8814_config_init(struct phy_device *phydev)
val |= LAN8814_ALIGN_TX_A_B_SWAP; val |= LAN8814_ALIGN_TX_A_B_SWAP;
lanphy_write_page_reg(phydev, 2, LAN8814_ALIGN_SWAP, val); lanphy_write_page_reg(phydev, 2, LAN8814_ALIGN_SWAP, val);
if (lan8814->led_mode >= 0)
lan8814_setup_led(phydev, lan8814->led_mode);
return 0; return 0;
} }
...@@ -2855,6 +2890,7 @@ static int lan8814_release_coma_mode(struct phy_device *phydev) ...@@ -2855,6 +2890,7 @@ static int lan8814_release_coma_mode(struct phy_device *phydev)
static int lan8814_probe(struct phy_device *phydev) static int lan8814_probe(struct phy_device *phydev)
{ {
const struct kszphy_type *type = phydev->drv->driver_data;
struct kszphy_priv *priv; struct kszphy_priv *priv;
u16 addr; u16 addr;
int err; int err;
...@@ -2863,10 +2899,12 @@ static int lan8814_probe(struct phy_device *phydev) ...@@ -2863,10 +2899,12 @@ static int lan8814_probe(struct phy_device *phydev)
if (!priv) if (!priv)
return -ENOMEM; return -ENOMEM;
priv->led_mode = -1;
phydev->priv = priv; phydev->priv = priv;
priv->type = type;
kszphy_parse_led_mode(phydev);
/* Strap-in value for PHY address, below register read gives starting /* Strap-in value for PHY address, below register read gives starting
* phy address value * phy address value
*/ */
...@@ -3068,6 +3106,7 @@ static struct phy_driver ksphy_driver[] = { ...@@ -3068,6 +3106,7 @@ static struct phy_driver ksphy_driver[] = {
.phy_id_mask = MICREL_PHY_ID_MASK, .phy_id_mask = MICREL_PHY_ID_MASK,
.name = "Microchip INDY Gigabit Quad PHY", .name = "Microchip INDY Gigabit Quad PHY",
.config_init = lan8814_config_init, .config_init = lan8814_config_init,
.driver_data = &lan8814_type,
.probe = lan8814_probe, .probe = lan8814_probe,
.soft_reset = genphy_soft_reset, .soft_reset = genphy_soft_reset,
.read_status = ksz9031_read_status, .read_status = ksz9031_read_status,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment