Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1311986 > unrolled thread

[PATCH v2] net: phy: smsc: Fix disabling energy detect mode

Started byTeresa Remmet <t.remmet@phytec.de>
First post2016-01-19 09:00 +0100
Last post2016-01-19 20:40 +0100
Articles 3 — 3 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH v2] net: phy: smsc: Fix disabling energy detect mode Teresa Remmet <t.remmet@phytec.de> - 2016-01-19 09:00 +0100
    Re: [PATCH v2] net: phy: smsc: Fix disabling energy detect mode Andrew Lunn <andrew@lunn.ch> - 2016-01-19 16:30 +0100
      Re: [PATCH v2] net: phy: smsc: Fix disabling energy detect mode David Miller <davem@davemloft.net> - 2016-01-19 20:40 +0100

#1311986 — [PATCH v2] net: phy: smsc: Fix disabling energy detect mode

FromTeresa Remmet <t.remmet@phytec.de>
Date2016-01-19 09:00 +0100
Subject[PATCH v2] net: phy: smsc: Fix disabling energy detect mode
Message-ID<qSzmO-4JC-23@gated-at.bofh.it>
When the lan87xx_read_status function is getting called the
energy detect mode is enabled again even if it has been
disabled by device tree.

Added private struct to check the energy detect status.

Signed-off-by: Teresa Remmet <t.remmet@phytec.de>
---
Changes since v1:
- reordered variable definition
- moved private variable into a struct for better readability 
- deleted smsc_phy_remove fuction as it is not needed

 drivers/net/phy/smsc.c | 53 ++++++++++++++++++++++++++++++++++++++++----------
 1 file changed, 43 insertions(+), 10 deletions(-)

diff --git a/drivers/net/phy/smsc.c b/drivers/net/phy/smsc.c
index e485f26..79fcb48 100644
--- a/drivers/net/phy/smsc.c
+++ b/drivers/net/phy/smsc.c
@@ -24,6 +24,10 @@
 #include <linux/netdevice.h>
 #include <linux/smscphy.h>
 
+struct smsc_phy_priv {
+	bool energy_enable:1;
+};
+
 static int smsc_phy_config_intr(struct phy_device *phydev)
 {
 	int rc = phy_write (phydev, MII_LAN83C185_IM,
@@ -43,19 +47,14 @@ static int smsc_phy_ack_interrupt(struct phy_device *phydev)
 
 static int smsc_phy_config_init(struct phy_device *phydev)
 {
-	int __maybe_unused len;
-	struct device *dev __maybe_unused = &phydev->mdio.dev;
-	struct device_node *of_node __maybe_unused = dev->of_node;
+	struct smsc_phy_priv *priv = phydev->priv;
+
 	int rc = phy_read(phydev, MII_LAN83C185_CTRL_STATUS);
-	int enable_energy = 1;
 
 	if (rc < 0)
 		return rc;
 
-	if (of_find_property(of_node, "smsc,disable-energy-detect", &len))
-		enable_energy = 0;
-
-	if (enable_energy) {
+	if (priv->energy_enable) {
 		/* Enable energy detect mode for this SMSC Transceivers */
 		rc = phy_write(phydev, MII_LAN83C185_CTRL_STATUS,
 			       rc | MII_LAN83C185_EDPWRDOWN);
@@ -110,10 +109,13 @@ static int lan911x_config_init(struct phy_device *phydev)
  */
 static int lan87xx_read_status(struct phy_device *phydev)
 {
+	struct smsc_phy_priv *priv = phydev->priv;
+
 	int err = genphy_read_status(phydev);
-	int i;
 
-	if (!phydev->link) {
+	if (!phydev->link && priv->energy_enable) {
+		int i;
+
 		/* Disable EDPD to wake up PHY */
 		int rc = phy_read(phydev, MII_LAN83C185_CTRL_STATUS);
 		if (rc < 0)
@@ -149,6 +151,25 @@ static int lan87xx_read_status(struct phy_device *phydev)
 	return err;
 }
 
+static int smsc_phy_probe(struct phy_device *phydev)
+{
+	struct device *dev = &phydev->mdio.dev;
+	struct device_node *of_node __maybe_unused = dev->of_node;
+	struct smsc_phy_priv *priv;
+	int __maybe_unused len;
+
+	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
+	if (!priv)
+		return -ENOMEM;
+
+	if (of_find_property(of_node, "smsc,disable-energy-detect", &len))
+		priv->energy_enable = false;
+
+	phydev->priv = priv;
+
+	return 0;
+}
+
 static struct phy_driver smsc_phy_driver[] = {
 {
 	.phy_id		= 0x0007c0a0, /* OUI=0x00800f, Model#=0x0a */
@@ -159,6 +180,8 @@ static struct phy_driver smsc_phy_driver[] = {
 				| SUPPORTED_Asym_Pause),
 	.flags		= PHY_HAS_INTERRUPT | PHY_HAS_MAGICANEG,
 
+	.probe		= smsc_phy_probe,
+
 	/* basic functions */
 	.config_aneg	= genphy_config_aneg,
 	.read_status	= genphy_read_status,
@@ -180,6 +203,8 @@ static struct phy_driver smsc_phy_driver[] = {
 				| SUPPORTED_Asym_Pause),
 	.flags		= PHY_HAS_INTERRUPT | PHY_HAS_MAGICANEG,
 
+	.probe		= smsc_phy_probe,
+
 	/* basic functions */
 	.config_aneg	= genphy_config_aneg,
 	.read_status	= genphy_read_status,
@@ -201,6 +226,8 @@ static struct phy_driver smsc_phy_driver[] = {
 				| SUPPORTED_Asym_Pause),
 	.flags		= PHY_HAS_INTERRUPT | PHY_HAS_MAGICANEG,
 
+	.probe		= smsc_phy_probe,
+
 	/* basic functions */
 	.config_aneg	= genphy_config_aneg,
 	.read_status	= lan87xx_read_status,
@@ -222,6 +249,8 @@ static struct phy_driver smsc_phy_driver[] = {
 				| SUPPORTED_Asym_Pause),
 	.flags		= PHY_HAS_INTERRUPT | PHY_HAS_MAGICANEG,
 
+	.probe		= smsc_phy_probe,
+
 	/* basic functions */
 	.config_aneg	= genphy_config_aneg,
 	.read_status	= genphy_read_status,
@@ -242,6 +271,8 @@ static struct phy_driver smsc_phy_driver[] = {
 				| SUPPORTED_Asym_Pause),
 	.flags		= PHY_HAS_INTERRUPT | PHY_HAS_MAGICANEG,
 
+	.probe		= smsc_phy_probe,
+
 	/* basic functions */
 	.config_aneg	= genphy_config_aneg,
 	.read_status	= lan87xx_read_status,
@@ -263,6 +294,8 @@ static struct phy_driver smsc_phy_driver[] = {
 				| SUPPORTED_Asym_Pause),
 	.flags		= PHY_HAS_INTERRUPT | PHY_HAS_MAGICANEG,
 
+	.probe		= smsc_phy_probe,
+
 	/* basic functions */
 	.config_aneg	= genphy_config_aneg,
 	.read_status	= lan87xx_read_status,
-- 
1.9.1

[toc] | [next] | [standalone]


#1312324

FromAndrew Lunn <andrew@lunn.ch>
Date2016-01-19 16:30 +0100
Message-ID<qSGoh-1fW-1@gated-at.bofh.it>
In reply to#1311986
> +struct smsc_phy_priv {
> +	bool energy_enable:1;
> +};

Time to show my ignorance of bitfields. Since this is a bool, does the
:1 actually do anything?

> +static int smsc_phy_probe(struct phy_device *phydev)
> +{
> +	struct device *dev = &phydev->mdio.dev;
> +	struct device_node *of_node __maybe_unused = dev->of_node;
> +	struct smsc_phy_priv *priv;
> +	int __maybe_unused len;
> +
> +	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
> +	if (!priv)
> +		return -ENOMEM;
> +
> +	if (of_find_property(of_node, "smsc,disable-energy-detect", &len))
> +		priv->energy_enable = false;

Here you set it to false. Where does it get set to true?

Also, of_property_read_bool() would be a better call than of_find_property.

     Andrew

[toc] | [prev] | [next] | [standalone]


#1312467

FromDavid Miller <davem@davemloft.net>
Date2016-01-19 20:40 +0100
Message-ID<qSKif-3QG-29@gated-at.bofh.it>
In reply to#1312324
From: Andrew Lunn <andrew@lunn.ch>
Date: Tue, 19 Jan 2016 16:25:03 +0100

>> +struct smsc_phy_priv {
>> +	bool energy_enable:1;
>> +};
> 
> Time to show my ignorance of bitfields. Since this is a bool, does the
> :1 actually do anything?

Even if does something, saving space for a datastructure like this makes
no sense.  There are no adjacent bit fields to share the space with.

Just use plain 'bool'.

>> +static int smsc_phy_probe(struct phy_device *phydev)
>> +{
>> +	struct device *dev = &phydev->mdio.dev;
>> +	struct device_node *of_node __maybe_unused = dev->of_node;
>> +	struct smsc_phy_priv *priv;
>> +	int __maybe_unused len;
>> +
>> +	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
>> +	if (!priv)
>> +		return -ENOMEM;
>> +
>> +	if (of_find_property(of_node, "smsc,disable-energy-detect", &len))
>> +		priv->energy_enable = false;
> 
> Here you set it to false. Where does it get set to true?
> 
> Also, of_property_read_bool() would be a better call than of_find_property.

Yeah this looks broken to me too.

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web