linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net: phy: smsc: Fix disabling energy detect mode
@ 2016-01-15  9:20 Teresa Remmet
  2016-01-15 19:55 ` David Miller
  2016-01-16 17:11 ` Andrew Lunn
  0 siblings, 2 replies; 3+ messages in thread
From: Teresa Remmet @ 2016-01-15  9:20 UTC (permalink / raw)
  To: netdev; +Cc: Florian Fainelli, linux-kernel, David S. Miller

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 variable to check the energy detect status.

Signed-off-by: Teresa Remmet <t.remmet@phytec.de>
---
 drivers/net/phy/smsc.c | 61 ++++++++++++++++++++++++++++++++++++++++++--------
 1 file changed, 52 insertions(+), 9 deletions(-)

diff --git a/drivers/net/phy/smsc.c b/drivers/net/phy/smsc.c
index e485f26..5adb7f3 100644
--- a/drivers/net/phy/smsc.c
+++ b/drivers/net/phy/smsc.c
@@ -43,19 +43,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;
+	bool *energy_enable = 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 (*energy_enable) {
 		/* Enable energy detect mode for this SMSC Transceivers */
 		rc = phy_write(phydev, MII_LAN83C185_CTRL_STATUS,
 			       rc | MII_LAN83C185_EDPWRDOWN);
@@ -110,10 +105,11 @@ static int lan911x_config_init(struct phy_device *phydev)
  */
 static int lan87xx_read_status(struct phy_device *phydev)
 {
+	bool *energy_enable = phydev->priv;
 	int err = genphy_read_status(phydev);
 	int i;
 
-	if (!phydev->link) {
+	if (!phydev->link && *energy_enable) {
 		/* Disable EDPD to wake up PHY */
 		int rc = phy_read(phydev, MII_LAN83C185_CTRL_STATUS);
 		if (rc < 0)
@@ -149,6 +145,35 @@ 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;
+	bool *energy_enable;
+	int __maybe_unused len;
+	struct device_node *of_node __maybe_unused = dev->of_node;
+
+	energy_enable = devm_kzalloc(dev, sizeof(*energy_enable), GFP_KERNEL);
+	if (!energy_enable)
+		return -ENOMEM;
+
+	*energy_enable = true;
+	if (of_find_property(of_node, "smsc,disable-energy-detect", &len))
+		*energy_enable = false;
+
+	phydev->priv = energy_enable;
+
+	return 0;
+}
+
+static void smsc_phy_remove(struct phy_device *phydev)
+{
+	struct device *dev = &phydev->mdio.dev;
+	bool *priv = phydev->priv;
+
+	if (priv)
+		devm_kfree(dev, priv);
+}
+
 static struct phy_driver smsc_phy_driver[] = {
 {
 	.phy_id		= 0x0007c0a0, /* OUI=0x00800f, Model#=0x0a */
@@ -159,6 +184,9 @@ static struct phy_driver smsc_phy_driver[] = {
 				| SUPPORTED_Asym_Pause),
 	.flags		= PHY_HAS_INTERRUPT | PHY_HAS_MAGICANEG,
 
+	.probe		= smsc_phy_probe,
+	.remove		= smsc_phy_remove,
+
 	/* basic functions */
 	.config_aneg	= genphy_config_aneg,
 	.read_status	= genphy_read_status,
@@ -180,6 +208,9 @@ static struct phy_driver smsc_phy_driver[] = {
 				| SUPPORTED_Asym_Pause),
 	.flags		= PHY_HAS_INTERRUPT | PHY_HAS_MAGICANEG,
 
+	.probe		= smsc_phy_probe,
+	.remove		= smsc_phy_remove,
+
 	/* basic functions */
 	.config_aneg	= genphy_config_aneg,
 	.read_status	= genphy_read_status,
@@ -201,6 +232,9 @@ static struct phy_driver smsc_phy_driver[] = {
 				| SUPPORTED_Asym_Pause),
 	.flags		= PHY_HAS_INTERRUPT | PHY_HAS_MAGICANEG,
 
+	.probe		= smsc_phy_probe,
+	.remove		= smsc_phy_remove,
+
 	/* basic functions */
 	.config_aneg	= genphy_config_aneg,
 	.read_status	= lan87xx_read_status,
@@ -222,6 +256,9 @@ static struct phy_driver smsc_phy_driver[] = {
 				| SUPPORTED_Asym_Pause),
 	.flags		= PHY_HAS_INTERRUPT | PHY_HAS_MAGICANEG,
 
+	.probe		= smsc_phy_probe,
+	.remove		= smsc_phy_remove,
+
 	/* basic functions */
 	.config_aneg	= genphy_config_aneg,
 	.read_status	= genphy_read_status,
@@ -242,6 +279,9 @@ static struct phy_driver smsc_phy_driver[] = {
 				| SUPPORTED_Asym_Pause),
 	.flags		= PHY_HAS_INTERRUPT | PHY_HAS_MAGICANEG,
 
+	.probe		= smsc_phy_probe,
+	.remove		= smsc_phy_remove,
+
 	/* basic functions */
 	.config_aneg	= genphy_config_aneg,
 	.read_status	= lan87xx_read_status,
@@ -263,6 +303,9 @@ static struct phy_driver smsc_phy_driver[] = {
 				| SUPPORTED_Asym_Pause),
 	.flags		= PHY_HAS_INTERRUPT | PHY_HAS_MAGICANEG,
 
+	.probe		= smsc_phy_probe,
+	.remove		= smsc_phy_remove,
+
 	/* basic functions */
 	.config_aneg	= genphy_config_aneg,
 	.read_status	= lan87xx_read_status,
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] net: phy: smsc: Fix disabling energy detect mode
  2016-01-15  9:20 [PATCH] net: phy: smsc: Fix disabling energy detect mode Teresa Remmet
@ 2016-01-15 19:55 ` David Miller
  2016-01-16 17:11 ` Andrew Lunn
  1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2016-01-15 19:55 UTC (permalink / raw)
  To: t.remmet; +Cc: netdev, f.fainelli, linux-kernel

From: Teresa Remmet <t.remmet@phytec.de>
Date: Fri, 15 Jan 2016 10:20:33 +0100

> @@ -110,10 +105,11 @@ static int lan911x_config_init(struct phy_device *phydev)
>   */
>  static int lan87xx_read_status(struct phy_device *phydev)
>  {
> +	bool *energy_enable = phydev->priv;
>  	int err = genphy_read_status(phydev);
>  	int i;

Please order local variable declarations from longest to shortest line.

> +static int smsc_phy_probe(struct phy_device *phydev)
> +{
> +	struct device *dev = &phydev->mdio.dev;
> +	bool *energy_enable;
> +	int __maybe_unused len;
> +	struct device_node *of_node __maybe_unused = dev->of_node;

Likewise.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] net: phy: smsc: Fix disabling energy detect mode
  2016-01-15  9:20 [PATCH] net: phy: smsc: Fix disabling energy detect mode Teresa Remmet
  2016-01-15 19:55 ` David Miller
@ 2016-01-16 17:11 ` Andrew Lunn
  1 sibling, 0 replies; 3+ messages in thread
From: Andrew Lunn @ 2016-01-16 17:11 UTC (permalink / raw)
  To: Teresa Remmet; +Cc: netdev, Florian Fainelli, linux-kernel, David S. Miller

> +static void smsc_phy_remove(struct phy_device *phydev)
> +{
> +	struct device *dev = &phydev->mdio.dev;
> +	bool *priv = phydev->priv;
> +
> +	if (priv)
> +		devm_kfree(dev, priv);
> +}

Not needed, since this is the devm_ API.

>From a stylistic point of view, it might be better to define a
structure with a single member. It is what people expect a priv to be.
It keeps the maintenance burden lower if you do things in the normal
way.

    Andrew

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-01-16 17:11 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-15  9:20 [PATCH] net: phy: smsc: Fix disabling energy detect mode Teresa Remmet
2016-01-15 19:55 ` David Miller
2016-01-16 17:11 ` Andrew Lunn

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).