In KSZ9131 PHY it is possible to control LEDs blink behavior via
LED mode behavior and select registers. Add DTS properties plus handles
of them inside micrel PHY driver.
I've some concerns about passing raw register values into LED mode
select and behavior. It can be passed via array like in microchip
driver(Documentation/devicetree/bindings/net/microchip,lan78xx.txt).
There is the problem in this particular driver - there is a lot of other PHYs
and led mode behavior/select states may intersect, that's the reason why
I did it this way. Is there any good ways to make it look more properly?
Ivan Mikhaylov (2):
net: phy: micrel: add LED control on KSZ9131
dt-bindings: net: phy: micrel: add LED mode behavior and select
properties
.../devicetree/bindings/net/micrel.txt | 7 ++
drivers/net/phy/micrel.c | 69 ++++++++++++++++++-
2 files changed, 75 insertions(+), 1 deletion(-)
--
2.21.1
Add LED mode behavior and LED mode select properties which can be used
in KSZ9131 PHY.
Signed-off-by: Ivan Mikhaylov <[email protected]>
---
Documentation/devicetree/bindings/net/micrel.txt | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/Documentation/devicetree/bindings/net/micrel.txt b/Documentation/devicetree/bindings/net/micrel.txt
index 8d157f0295a5..3022c979287a 100644
--- a/Documentation/devicetree/bindings/net/micrel.txt
+++ b/Documentation/devicetree/bindings/net/micrel.txt
@@ -16,9 +16,16 @@ Optional properties:
KSZ8051: register 0x1f, bits 5..4
KSZ8081: register 0x1f, bits 5..4
KSZ8091: register 0x1f, bits 5..4
+ KSZ9131: register 0x1a, bit 14
See the respective PHY datasheet for the mode values.
+ - micrel,led-mode-select
+ See the respective PHY datasheet for the mode select values.
+
+ - micrel,led-mode-behavior
+ See the respective PHY datasheet for the mode behavior values.
+
- micrel,rmii-reference-clock-select-25-mhz: RMII Reference Clock Select
bit selects 25 MHz mode
--
2.21.1
On Wed, Dec 09, 2020 at 05:04:59PM +0300, Ivan Mikhaylov wrote:
> In KSZ9131 PHY it is possible to control LEDs blink behavior via
> LED mode behavior and select registers. Add DTS properties plus handles
> of them inside micrel PHY driver.
>
> I've some concerns about passing raw register values into LED mode
> select and behavior.
There was been some work done allowing PHY LEDs to be controlled just
like other LEDs in Linux. That is how this should be done. Please go
look back in the netdev and LED mailing list archives, and join that
work.
Andrew
Add the possibility to read the LED configuration via DTS properties from
KSZ9131 PHY node. Add the new proprties and handle for them:
micrel,led-mode-behavior
micrel,led-mode-select
Signed-off-by: Ivan Mikhaylov <[email protected]>
---
drivers/net/phy/micrel.c | 69 +++++++++++++++++++++++++++++++++++++++-
1 file changed, 68 insertions(+), 1 deletion(-)
diff --git a/drivers/net/phy/micrel.c b/drivers/net/phy/micrel.c
index 3fe552675dd2..117f3a3b9dd6 100644
--- a/drivers/net/phy/micrel.c
+++ b/drivers/net/phy/micrel.c
@@ -71,6 +71,11 @@
#define MII_KSZPHY_RX_DATA_PAD_SKEW 0x105
#define MII_KSZPHY_TX_DATA_PAD_SKEW 0x106
+/* KSZ9131 LED registers */
+#define MII_KSZPHY_LED_MODE_SELECT 0x16
+#define MII_KSZPHY_LED_BEHAVIOR 0x17
+#define MII_KSZPHY_LED_MODE 0x1a
+
#define PS_TO_REG 200
struct kszphy_hw_stat {
@@ -86,6 +91,8 @@ static struct kszphy_hw_stat kszphy_hw_stats[] = {
struct kszphy_type {
u32 led_mode_reg;
+ u32 led_mode_behavior_reg;
+ u32 led_mode_select_reg;
u16 interrupt_level_mask;
bool has_broadcast_disable;
bool has_nand_tree_disable;
@@ -95,6 +102,8 @@ struct kszphy_type {
struct kszphy_priv {
const struct kszphy_type *type;
int led_mode;
+ int led_mode_behavior;
+ int led_mode_select;
bool rmii_ref_clk_sel;
bool rmii_ref_clk_sel_val;
u64 stats[ARRAY_SIZE(kszphy_hw_stats)];
@@ -131,6 +140,13 @@ static const struct kszphy_type ksz9021_type = {
.interrupt_level_mask = BIT(14),
};
+static const struct kszphy_type ksz9131_type = {
+ .led_mode_reg = MII_KSZPHY_LED_MODE,
+ .led_mode_behavior_reg = MII_KSZPHY_LED_BEHAVIOR,
+ .led_mode_select_reg = MII_KSZPHY_LED_MODE_SELECT,
+ .interrupt_level_mask = BIT(14),
+};
+
static int kszphy_extended_write(struct phy_device *phydev,
u32 regnum, u16 val)
{
@@ -204,6 +220,7 @@ static int kszphy_setup_led(struct phy_device *phydev, u32 reg, int val)
switch (reg) {
case MII_KSZPHY_CTRL_1:
+ case MII_KSZPHY_LED_MODE:
shift = 14;
break;
case MII_KSZPHY_CTRL_2:
@@ -286,6 +303,26 @@ static int kszphy_config_reset(struct phy_device *phydev)
if (priv->led_mode >= 0)
kszphy_setup_led(phydev, priv->type->led_mode_reg, priv->led_mode);
+ if (priv->led_mode_behavior >= 0) {
+ ret = phy_write(phydev, priv->type->led_mode_behavior_reg,
+ priv->led_mode_behavior);
+ if (ret) {
+ phydev_err(phydev,
+ "failed to set led mode behavior reg\n");
+ return ret;
+ }
+ }
+
+ if (priv->led_mode_select >= 0) {
+ ret = phy_write(phydev, priv->type->led_mode_select_reg,
+ priv->led_mode_select);
+ if (ret) {
+ phydev_err(phydev,
+ "failed to set led mode select reg\n");
+ return ret;
+ }
+ }
+
return 0;
}
@@ -1122,6 +1159,36 @@ static int kszphy_probe(struct phy_device *phydev)
priv->led_mode = -1;
}
+ if (type->led_mode_behavior_reg) {
+ ret = of_property_read_u32(np, "micrel,led-mode-behavior",
+ &priv->led_mode_behavior);
+ if (!ret) {
+ ret = phy_write(phydev, type->led_mode_behavior_reg,
+ priv->led_mode_behavior);
+ if (ret)
+ phydev_err(phydev,
+ "invalid led mode behavior: 0x%x\n",
+ priv->led_mode_behavior);
+ }
+ } else {
+ priv->led_mode_behavior = -1;
+ }
+
+ if (type->led_mode_select_reg) {
+ ret = of_property_read_u32(np, "micrel,led-mode-select",
+ &priv->led_mode_select);
+ if (!ret) {
+ ret = phy_write(phydev, type->led_mode_select_reg,
+ priv->led_mode_select);
+ if (ret)
+ phydev_err(phydev,
+ "invalid led mode select: 0x%x\n",
+ priv->led_mode_select);
+ }
+ } else {
+ priv->led_mode_select = -1;
+ }
+
clk = devm_clk_get(&phydev->mdio.dev, "rmii-ref");
/* NOTE: clk may be NULL if building without CONFIG_HAVE_CLK */
if (!IS_ERR_OR_NULL(clk)) {
@@ -1319,7 +1386,7 @@ static struct phy_driver ksphy_driver[] = {
.phy_id_mask = MICREL_PHY_ID_MASK,
.name = "Microchip KSZ9131 Gigabit PHY",
/* PHY_GBIT_FEATURES */
- .driver_data = &ksz9021_type,
+ .driver_data = &ksz9131_type,
.probe = kszphy_probe,
.config_init = ksz9131_config_init,
.read_status = genphy_read_status,
--
2.21.1