* [PATCH] net: phy: micrel: Add led-mode support
@ 2021-05-31 15:00 Trent Piepho
2021-06-02 6:41 ` Sascha Hauer
0 siblings, 1 reply; 2+ messages in thread
From: Trent Piepho @ 2021-05-31 15:00 UTC (permalink / raw)
To: barebox; +Cc: 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.
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] net: phy: micrel: Add led-mode support
2021-05-31 15:00 [PATCH] net: phy: micrel: Add led-mode support Trent Piepho
@ 2021-06-02 6:41 ` Sascha Hauer
0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2021-06-02 6:41 UTC (permalink / raw)
To: Trent Piepho; +Cc: barebox
On Mon, May 31, 2021 at 08:00:45AM -0700, Trent Piepho wrote:
> 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(-)
Applied, thanks
Sascha
>
> 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
>
--
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
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-06-02 6:42 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-31 15:00 [PATCH] net: phy: micrel: Add led-mode support Trent Piepho
2021-06-02 6:41 ` Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox