Skip to contentSkip to conversation

net: phy: micrel: Add led-mode support

PATCH Applied Trent Piepho 2 participants 2 messages May 31, 2021 – Jun 2, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: phy: micrel: Add led-mode support

Add code that will use the micrel,led-mode property to configure the led.

It seems nearly every Micrel PHY equipped board has a custom phy fixup to do this. Maybe some of them won't be needed anymore.

---
 drivers/net/phy/micrel.c | 34 +++++++++++++++++++++++++++++-----
 1 file changed, 29 insertions(+), 5 deletions(-)
drivers/net/phy/micrel.c +29 -5
index 4e4637024..ea193c84a 100644
@@ -28,13 +28,16 @@
 #define KSZPHY_OMSO_MII_OVERRIDE		BIT(0)
 
 /* general PHY control reg in vendor specific block. */
-#define	MII_KSZPHY_CTRL			0x1F
+#define	MII_KSZPHY_CTRL				0x1F
 /* bitmap of PHY register to set interrupt mode */
 #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 KSZ8051_RMII_50MHZ_CLK			BIT(7)
 
+/* PHY Control 1 */
+#define MII_KSZPHY_CTRL_1			0x1e
+
 /* Write/read to/from extended registers */
 #define MII_KSZPHY_EXTREG                       0x0b
 #define KSZPHY_EXTREG_WRITE                     0x8000
@@ -63,18 +66,35 @@ static int kszphy_extended_read(struct phy_device *phydev,
 	return phy_read(phydev, MII_KSZPHY_EXTREG_READ);
 }
 
+/* Handle LED mode, shift = position of first led mode bit, usually 4 or 14 */
+static int kszphy_led_mode(struct phy_device *phydev, int reg, int shift)
+{
+	const struct device_d *dev = &phydev->dev;
+	const struct device_node *of_node = dev->device_node ? : dev->parent->device_node;
+	u32 val;
+
+	if (!of_property_read_u32(of_node, "micrel,led-mode", &val)) {
+		if (val > 0x03) {
+			dev_err(dev, "led-mode 0x%02x out of range\n", val);
+			return -1;
+		}
+		return phy_modify(phydev, reg, 0x03 << shift, val << shift);
+	}
+	return 0;
+}
+
 static int kszphy_config_init(struct phy_device *phydev)
 {
+	kszphy_led_mode(phydev, MII_KSZPHY_CTRL_1, 14);
+
 	return 0;
 }
 
 static int ksz8021_config_init(struct phy_device *phydev)
 {
-	u16 val;
+	phy_set_bits(phydev, MII_KSZPHY_OMSO, KSZPHY_OMSO_B_CAST_OFF);
 
-	val = phy_read(phydev, MII_KSZPHY_OMSO);
-	val |= KSZPHY_OMSO_B_CAST_OFF;
-	phy_write(phydev, MII_KSZPHY_OMSO, val);
+	kszphy_led_mode(phydev, MII_KSZPHY_CTRL, 4);
 
 	return 0;
 }
@@ -89,6 +109,8 @@ static int ks8051_config_init(struct phy_device *phydev)
 		phy_write(phydev, MII_KSZPHY_CTRL, regval);
 	}
 
+	kszphy_led_mode(phydev, MII_KSZPHY_CTRL, 4);
+
 	return 0;
 }
 
@@ -143,6 +165,8 @@ static int ksz9021_config_init(struct phy_device *phydev)
 		ksz9021_load_values_from_of(phydev, of_node,
 				    MII_KSZPHY_TX_DATA_PAD_SKEW,
 				    tx_pad_skew_names);
+
+		kszphy_led_mode(phydev, 0x11, 6);
 	}
 
 	return 0;
Signature · 7 lines
2.26.2


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Applied
#1 lore raw
Quoted 10 lines · Trent Piepho

Add code that will use the micrel,led-mode property to configure the led.

It seems nearly every Micrel PHY equipped board has a custom phy fixup to do this. Maybe some of them won't be needed anymore.

---
 drivers/net/phy/micrel.c | 34 +++++++++++++++++++++++++++++-----
 1 file changed, 29 insertions(+), 5 deletions(-)

Applied, thanks

Sascha

Quoted 90 lines
drivers/net/phy/micrel.c +29 -5
index 4e4637024..ea193c84a 100644
@@ -28,13 +28,16 @@
 #define KSZPHY_OMSO_MII_OVERRIDE		BIT(0)
 
 /* general PHY control reg in vendor specific block. */
-#define	MII_KSZPHY_CTRL			0x1F
+#define	MII_KSZPHY_CTRL				0x1F
 /* bitmap of PHY register to set interrupt mode */
 #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 KSZ8051_RMII_50MHZ_CLK			BIT(7)
 
+/* PHY Control 1 */
+#define MII_KSZPHY_CTRL_1			0x1e
+
 /* Write/read to/from extended registers */
 #define MII_KSZPHY_EXTREG                       0x0b
 #define KSZPHY_EXTREG_WRITE                     0x8000
@@ -63,18 +66,35 @@ static int kszphy_extended_read(struct phy_device *phydev,
 	return phy_read(phydev, MII_KSZPHY_EXTREG_READ);
 }
 
+/* Handle LED mode, shift = position of first led mode bit, usually 4 or 14 */
+static int kszphy_led_mode(struct phy_device *phydev, int reg, int shift)
+{
+	const struct device_d *dev = &phydev->dev;
+	const struct device_node *of_node = dev->device_node ? : dev->parent->device_node;
+	u32 val;
+
+	if (!of_property_read_u32(of_node, "micrel,led-mode", &val)) {
+		if (val > 0x03) {
+			dev_err(dev, "led-mode 0x%02x out of range\n", val);
+			return -1;
+		}
+		return phy_modify(phydev, reg, 0x03 << shift, val << shift);
+	}
+	return 0;
+}
+
 static int kszphy_config_init(struct phy_device *phydev)
 {
+	kszphy_led_mode(phydev, MII_KSZPHY_CTRL_1, 14);
+
 	return 0;
 }
 
 static int ksz8021_config_init(struct phy_device *phydev)
 {
-	u16 val;
+	phy_set_bits(phydev, MII_KSZPHY_OMSO, KSZPHY_OMSO_B_CAST_OFF);
 
-	val = phy_read(phydev, MII_KSZPHY_OMSO);
-	val |= KSZPHY_OMSO_B_CAST_OFF;
-	phy_write(phydev, MII_KSZPHY_OMSO, val);
+	kszphy_led_mode(phydev, MII_KSZPHY_CTRL, 4);
 
 	return 0;
 }
@@ -89,6 +109,8 @@ static int ks8051_config_init(struct phy_device *phydev)
 		phy_write(phydev, MII_KSZPHY_CTRL, regval);
 	}
 
+	kszphy_led_mode(phydev, MII_KSZPHY_CTRL, 4);
+
 	return 0;
 }
 
@@ -143,6 +165,8 @@ static int ksz9021_config_init(struct phy_device *phydev)
 		ksz9021_load_values_from_of(phydev, of_node,
 				    MII_KSZPHY_TX_DATA_PAD_SKEW,
 				    tx_pad_skew_names);
+
+		kszphy_led_mode(phydev, 0x11, 6);
 	}
 
 	return 0;
Signature · 7 lines
2.26.2


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Signature · 9 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox