devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Lunn <andrew@lunn.ch>
To: Raju Lakkaraju <Raju.Lakkaraju@microsemi.com>
Cc: netdev@vger.kernel.org, devicetree@vger.kernel.org,
	f.fainelli@gmail.com, Allan.Nielsen@microsemi.com
Subject: Re: [PATCH net-next] net: phy: Add LED mode driver for Microsemi PHYs.
Date: Tue, 31 Jan 2017 14:30:09 +0100	[thread overview]
Message-ID: <20170131133009.GA6894@lunn.ch> (raw)
In-Reply-To: <1485841561-32056-2-git-send-email-Raju.Lakkaraju@microsemi.com>

On Tue, Jan 31, 2017 at 11:16:01AM +0530, Raju Lakkaraju wrote:
> From: Raju Lakkaraju <Raju.Lakkaraju@microsemi.com>
> 
> LED Mode:
> Microsemi PHY support 2 LEDs (LED[0] and LED[1]) to display different
> status information that can be selected by setting LED mode.
> 
> LED Mode parameter (vddmac, led-0-mode) and (vddmac, led-1-mode) get
> from Device Tree.

Hi Raju

How is vddmac an LED mode parameter?

> Signed-off-by: Raju Lakkaraju <Raju.Lakkaraju@microsemi.com>
> ---
>  .../devicetree/bindings/net/mscc-phy-vsc8531.txt   | 39 ++++++++++++
>  drivers/net/phy/mscc.c                             | 72 ++++++++++++++++++++++
>  2 files changed, 111 insertions(+)
> 
> diff --git a/Documentation/devicetree/bindings/net/mscc-phy-vsc8531.txt b/Documentation/devicetree/bindings/net/mscc-phy-vsc8531.txt
> index bdefefc6..1abf4b6 100644
> --- a/Documentation/devicetree/bindings/net/mscc-phy-vsc8531.txt
> +++ b/Documentation/devicetree/bindings/net/mscc-phy-vsc8531.txt
> @@ -27,6 +27,12 @@ Optional properties:
>  			  'vddmac'.
>  			  Default value is 0%.
>  			  Ref: Table:1 - Edge rate change (below).
> +- vsc8531,led-0-mode	: LED mode. Specify how the LED[0] should behave.
> +			  Allowed values is listed in the 'PHY LED Mode' -
> +			  Table 2 (below).  Default value is 1.
> +- vsc8531,led-1-mode	: LED mode. Specify how the LED[1] should behave.
> +			  Allowed values is listed in the 'PHY LED Mode' -
> +			  Table 2 (below).  Default value is 2.
>  
>  Table: 1 - Edge rate change
>  ----------------------------------------------------------------|
> @@ -54,10 +60,43 @@ Table: 1 - Edge rate change
>  | (slowest)							|
>  |---------------------------------------------------------------|
>  
> +Table: 2 - PHY LED Mode
> +|-----------------------------------------------|
> +| LINK_ACTIVITY			| 0		|
> +|-----------------------------------------------|
> +| LINK_1000_ACTIVITY		| 1		|
> +|-----------------------------------------------|
> +| LINK_100_ACTIVITY		| 2		|
> +|-----------------------------------------------|
> +| LINK_10_ACTIVITY		| 3		|
> +|-----------------------------------------------|
> +| LINK_100_1000_ACTIVITY	| 4		|
> +|-----------------------------------------------|
> +| LINK_10_1000_ACTIVITY		| 5		|
> +|-----------------------------------------------|
> +| LINK_10_100_ACTIVITY		| 6		|
> +|-----------------------------------------------|
> +| DUPLEX_COLLISION		| 8		|
> +|-----------------------------------------------|
> +| COLLISION			| 9		|
> +|-----------------------------------------------|
> +| ACTIVITY			| 10		|
> +|-----------------------------------------------|
> +| AUTONEG_FAULT			| 12		|
> +|-----------------------------------------------|
> +| SERIAL_MODE			| 13		|
> +|-----------------------------------------------|
> +| FORCE_LED_OFF			| 14		|
> +|-----------------------------------------------|
> +| FORCE_LED_ON			| 15		|
> +|-----------------------------------------------|
> +
>  Example:
>  
>          vsc8531_0: ethernet-phy@0 {
>                  compatible = "ethernet-phy-id0007.0570";
>                  vsc8531,vddmac		= <3300>;
>                  vsc8531,edge-slowdown	= <7>;
> +                vsc8531,led-0-mode	= <1>;
> +                vsc8531,led-1-mode	= <2>;

Numbers like this are pretty unreadable. I would suggest adding a header file in
include/dt-bindings/net/

> +static int vsc85xx_led_cntl_set(struct phy_device *phydev,
> +				u8 led_num,
> +				u8 mode)
> +{
> +	int rc;
> +	u16 reg_val;
> +
> +	mutex_lock(&phydev->lock);
> +	reg_val = phy_read(phydev, MSCC_PHY_LED_MODE_SEL);
> +	if (led_num) {
> +		reg_val &= ~LED_1_MODE_SEL_MASK;
> +		reg_val |= (((u16)mode << LED_1_MODE_SEL_POS) &
> +			    LED_1_MODE_SEL_MASK);
> +	} else {
> +		reg_val |= ((u16)mode & LED_0_MODE_SEL_MASK);
> +	}

The asymmetry here makes me think this is wrong.

> +	rc = phy_write(phydev, MSCC_PHY_LED_MODE_SEL, reg_val);
> +	mutex_unlock(&phydev->lock);
> +
> +	return rc;
> +}
> +
>  static int vsc85xx_mdix_get(struct phy_device *phydev, u8 *mdix)
>  {
>  	u16 reg_val;
> @@ -499,6 +547,13 @@ static int vsc85xx_config_init(struct phy_device *phydev)
>  	if (rc)
>  		return rc;
>  
> +	rc = vsc85xx_led_cntl_set(phydev, 1, vsc8531->led_1_mode);
> +	if (rc)
> +		return rc;
> +	rc = vsc85xx_led_cntl_set(phydev, 0, vsc8531->led_0_mode);
> +	if (rc)
> +		return rc;
> +
>  	rc = genphy_config_init(phydev);
>  
>  	return rc;
> @@ -555,8 +610,13 @@ static int vsc85xx_read_status(struct phy_device *phydev)
>  
>  static int vsc85xx_probe(struct phy_device *phydev)
>  {
> +	int rc;
>  	int rate_magic;
> +	u8 led_0_mode;
> +	u8 led_1_mode;
>  	struct vsc8531_private *vsc8531;
> +	struct device *dev = &phydev->mdio.dev;
> +	struct device_node *of_node = dev->of_node;

declarations are supposed to be reverse Christmas tree. i.e. longest
lines first.

>  
>  	rate_magic = vsc85xx_edge_rate_magic_get(phydev);
>  	if (rate_magic < 0)
> @@ -570,6 +630,18 @@ static int vsc85xx_probe(struct phy_device *phydev)
>  
>  	vsc8531->rate_magic = rate_magic;
>  
> +	/* LED[0] and LED[1] mode */
> +	rc = of_property_read_u8(of_node, "vsc8531,led-0-mode", &led_0_mode);
> +	if (rc != 0)

Please simplify this to just if (rc). Actually, it can be even
simpler.  of_property_read_u8 guarantees not to modify the return
value unless it has a value to return. So

	vsc8531->led_0_mode = LINK_1000_ACTIVITY;
	err = of_property_read_u8(of_node, "vsc8531,led-0-mode", &led_0_mode);
	if (err != EINVAL)
		return err;

	vsc8531->led_1_mode = LINK_100_ACTIVITY;
	err = of_property_read_u8(of_node, "vsc8531,led-1-mode", &led_1_mode);
	if (err != EINVAL)
		return err;

What about range checking? I could put 42 in the device tree for led
0, and it would set led 1 as well i think?

   Andrew

  reply	other threads:[~2017-01-31 13:30 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-31  5:46 [PATCH net-next] net: phy: Add LED mode driver for Microsemi PHYs Raju Lakkaraju
2017-01-31  5:46 ` Raju Lakkaraju
2017-01-31 13:30   ` Andrew Lunn [this message]
2017-02-01  9:32     ` Raju Lakkaraju

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=20170131133009.GA6894@lunn.ch \
    --to=andrew@lunn.ch \
    --cc=Allan.Nielsen@microsemi.com \
    --cc=Raju.Lakkaraju@microsemi.com \
    --cc=devicetree@vger.kernel.org \
    --cc=f.fainelli@gmail.com \
    --cc=netdev@vger.kernel.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;
as well as URLs for NNTP newsgroup(s).