mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Trent Piepho <tpiepho@gmail.com>
To: barebox@lists.infradead.org
Cc: Trent Piepho <tpiepho@gmail.com>
Subject: [PATCH] net: phy: micrel: Add led-mode support
Date: Mon, 31 May 2021 08:00:45 -0700	[thread overview]
Message-ID: <20210531150045.1214037-1-tpiepho@gmail.com> (raw)

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.

Signed-off-by: Trent Piepho <tpiepho@gmail.com>
---
 drivers/net/phy/micrel.c | 34 +++++++++++++++++++++++++++++-----
 1 file changed, 29 insertions(+), 5 deletions(-)

diff --git a/drivers/net/phy/micrel.c b/drivers/net/phy/micrel.c
index 4e4637024..ea193c84a 100644
--- a/drivers/net/phy/micrel.c
+++ b/drivers/net/phy/micrel.c
@@ -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;
-- 
2.26.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


             reply	other threads:[~2021-05-31 15:02 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-31 15:00 Trent Piepho [this message]
2021-06-02  6:41 ` Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210531150045.1214037-1-tpiepho@gmail.com \
    --to=tpiepho@gmail.com \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox