* [PATCH 1/2] net: phy: micrel: add LED control on KSZ9131
2020-12-09 14:04 [PATCH 0/2] Add LED mode behavior/select properties and handle Ivan Mikhaylov
@ 2020-12-09 14:05 ` Ivan Mikhaylov
2020-12-09 14:05 ` [PATCH 2/2] dt-bindings: net: phy: micrel: add LED mode behavior and select properties Ivan Mikhaylov
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Ivan Mikhaylov @ 2020-12-09 14:05 UTC (permalink / raw)
To: David S . Miller, Jakub Kicinski, Rob Herring, Andrew Lunn,
Florian Fainelli, Heiner Kallweit, Russell King
Cc: Ivan Mikhaylov, netdev, devicetree, linux-kernel
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 <i.mikhaylov@yadro.com>
---
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
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/2] dt-bindings: net: phy: micrel: add LED mode behavior and select properties
2020-12-09 14:04 [PATCH 0/2] Add LED mode behavior/select properties and handle Ivan Mikhaylov
2020-12-09 14:05 ` [PATCH 1/2] net: phy: micrel: add LED control on KSZ9131 Ivan Mikhaylov
@ 2020-12-09 14:05 ` Ivan Mikhaylov
2020-12-09 23:05 ` [PATCH 0/2] Add LED mode behavior/select properties and handle Andrew Lunn
2020-12-16 22:41 ` Pavel Machek
3 siblings, 0 replies; 5+ messages in thread
From: Ivan Mikhaylov @ 2020-12-09 14:05 UTC (permalink / raw)
To: David S . Miller, Jakub Kicinski, Rob Herring, Andrew Lunn,
Florian Fainelli, Heiner Kallweit, Russell King
Cc: Ivan Mikhaylov, netdev, devicetree, linux-kernel
Add LED mode behavior and LED mode select properties which can be used
in KSZ9131 PHY.
Signed-off-by: Ivan Mikhaylov <i.mikhaylov@yadro.com>
---
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
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 0/2] Add LED mode behavior/select properties and handle
2020-12-09 14:04 [PATCH 0/2] Add LED mode behavior/select properties and handle Ivan Mikhaylov
` (2 preceding siblings ...)
2020-12-09 23:05 ` [PATCH 0/2] Add LED mode behavior/select properties and handle Andrew Lunn
@ 2020-12-16 22:41 ` Pavel Machek
3 siblings, 0 replies; 5+ messages in thread
From: Pavel Machek @ 2020-12-16 22:41 UTC (permalink / raw)
To: Ivan Mikhaylov, marek.behun, linux-leds
Cc: David S . Miller, Jakub Kicinski, Rob Herring, Andrew Lunn,
Florian Fainelli, Heiner Kallweit, Russell King, netdev,
devicetree, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 998 bytes --]
Hi!
> 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?
Lets... not do this?
We have a LED subsystem which should probably control the LEDs... so
user can specify behaviours at run-time, instead of them being
hard-coded in the device tree.
Plus, LED subsystem will use same interface for networks LEDs as for
... other LEDs.
Best regards,
Pavel
--
http://www.livejournal.com/~pavelmachek
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 181 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread