Skip to contentSkip to conversation

net: phy: tja11xx: Add IRQ support to the driver

PATCH Superseded Marek Vasut 3 participants 5 messages May 28, 2019

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: phy: tja11xx: Add IRQ support to the driver

Add support for handling the TJA11xx PHY IRQ signal.

Cc Andrew Lunn <[email protected]>
Cc Florian Fainelli <[email protected]>
Cc Guenter Roeck <[email protected]>
Cc Heiner Kallweit <[email protected]>
Cc Jean Delvare <[email protected]>
---
 drivers/net/phy/nxp-tja11xx.c | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)
drivers/net/phy/nxp-tja11xx.c +32 -0
index b705d0bd798b..0be9fe9a9604 100644
@@ -40,6 +40,8 @@
 #define MII_INTSRC_TEMP_ERR		BIT(1)
 #define MII_INTSRC_UV_ERR		BIT(3)
 
+#define MII_INTEN			22
+
 #define MII_COMMSTAT			23
 #define MII_COMMSTAT_LINK_UP		BIT(15)
 
@@ -239,6 +241,30 @@ static int tja11xx_read_status(struct phy_device *phydev)
 	return 0;
 }
 
+static int tja11xx_config_intr(struct phy_device *phydev)
+{
+	int ret;
+
+	if (phydev->interrupts == PHY_INTERRUPT_ENABLED)
+		ret = phy_write(phydev, MII_INTEN, 0xcfef);
+	else
+		ret = phy_write(phydev, MII_INTEN, 0);
+
+	if (ret < 0)
+		return ret;
+
+	ret = phy_read(phydev, MII_INTSRC);
+
+	return ret < 0 ? ret : 0;
+}
+
+static int tja11xx_ack_interrupt(struct phy_device *phydev)
+{
+	int ret = phy_read(phydev, MII_INTSRC);
+
+	return ret < 0 ? ret : 0;
+}
+
 static int tja11xx_get_sset_count(struct phy_device *phydev)
 {
 	return ARRAY_SIZE(tja11xx_hw_stats);
@@ -366,6 +392,9 @@ static struct phy_driver tja11xx_driver[] = {
 		.suspend	= genphy_suspend,
 		.resume		= genphy_resume,
 		.set_loopback   = genphy_loopback,
+		/* IRQ related */
+		.config_intr	= tja11xx_config_intr,
+		.ack_interrupt	= tja11xx_ack_interrupt,
 		/* Statistics */
 		.get_sset_count = tja11xx_get_sset_count,
 		.get_strings	= tja11xx_get_strings,
@@ -381,6 +410,9 @@ static struct phy_driver tja11xx_driver[] = {
 		.suspend	= genphy_suspend,
 		.resume		= genphy_resume,
 		.set_loopback   = genphy_loopback,
+		/* IRQ related */
+		.config_intr	= tja11xx_config_intr,
+		.ack_interrupt	= tja11xx_ack_interrupt,
 		/* Statistics */
 		.get_sset_count = tja11xx_get_sset_count,
 		.get_strings	= tja11xx_get_strings,
Signature · 1 line
2.20.1
#1 lore raw
Quoted 27 lines · Marek Vasut

Add support for handling the TJA11xx PHY IRQ signal.

Cc Andrew Lunn <[email protected]>
Cc Florian Fainelli <[email protected]>
Cc Guenter Roeck <[email protected]>
Cc Heiner Kallweit <[email protected]>
Cc Jean Delvare <[email protected]>
---
 drivers/net/phy/nxp-tja11xx.c | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)
drivers/net/phy/nxp-tja11xx.c +2 -0
index b705d0bd798b..0be9fe9a9604 100644
@@ -40,6 +40,8 @@
 #define MII_INTSRC_TEMP_ERR		BIT(1)
 #define MII_INTSRC_UV_ERR		BIT(3)
 
+#define MII_INTEN			22
+
 #define MII_COMMSTAT			23
 #define MII_COMMSTAT_LINK_UP		BIT(15)
 

drivers/net/phy/nxp-tja11xx.c static int tja11xx_read_status(struct phy_device *phydev) · line 249

Quoted 9 lines
drivers/net/phy/nxp-tja11xx.c +6 -0
@@ -239,6 +241,30 @@ static int tja11xx_read_status(struct phy_device *phydev)
 	return 0;
 }
 
+static int tja11xx_config_intr(struct phy_device *phydev)
+{
+	int ret;
+
+	if (phydev->interrupts == PHY_INTERRUPT_ENABLED)
+		ret = phy_write(phydev, MII_INTEN, 0xcfef);

It would be nice to define the shifts and masks being used here. Other than that, this looks good.

Signature · 1 line
Florian
#2 lore raw
Quoted 31 lines · Florian Fainelli
Quoted 30 lines · Marek Vasut

Add support for handling the TJA11xx PHY IRQ signal.

Cc Andrew Lunn <[email protected]>
Cc Florian Fainelli <[email protected]>
Cc Guenter Roeck <[email protected]>
Cc Heiner Kallweit <[email protected]>
Cc Jean Delvare <[email protected]>
---
 drivers/net/phy/nxp-tja11xx.c | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)
drivers/net/phy/nxp-tja11xx.c +2 -0
index b705d0bd798b..0be9fe9a9604 100644
@@ -40,6 +40,8 @@
 #define MII_INTSRC_TEMP_ERR		BIT(1)
 #define MII_INTSRC_UV_ERR		BIT(3)
 
+#define MII_INTEN			22
+
 #define MII_COMMSTAT			23
 #define MII_COMMSTAT_LINK_UP		BIT(15)
 
@@ -239,6 +241,30 @@ static int tja11xx_read_status(struct phy_device *phydev)
 	return 0;
 }
 
Quoted 9 lines

drivers/net/phy/nxp-tja11xx.c static int tja11xx_read_status(struct phy_device *phydev) · line 249

Quoted 6 lines
drivers/net/phy/nxp-tja11xx.c +6 -0
+static int tja11xx_config_intr(struct phy_device *phydev)
+{
+	int ret;
+
+	if (phydev->interrupts == PHY_INTERRUPT_ENABLED)
+		ret = phy_write(phydev, MII_INTEN, 0xcfef);

It would be nice to define the shifts and masks being used here. Other than that, this looks good.

OK

Signature · 2 lines
Best regards,
Marek Vasut
maintainer
#3 lore raw
In reply to Marek Vasut
Quoted 27 lines · Marek Vasut

Add support for handling the TJA11xx PHY IRQ signal.

Cc Andrew Lunn <[email protected]>
Cc Florian Fainelli <[email protected]>
Cc Guenter Roeck <[email protected]>
Cc Heiner Kallweit <[email protected]>
Cc Jean Delvare <[email protected]>
---
 drivers/net/phy/nxp-tja11xx.c | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)
drivers/net/phy/nxp-tja11xx.c +2 -0
index b705d0bd798b..0be9fe9a9604 100644
@@ -40,6 +40,8 @@
 #define MII_INTSRC_TEMP_ERR		BIT(1)
 #define MII_INTSRC_UV_ERR		BIT(3)
 
+#define MII_INTEN			22
+
 #define MII_COMMSTAT			23
 #define MII_COMMSTAT_LINK_UP		BIT(15)
 

drivers/net/phy/nxp-tja11xx.c static int tja11xx_read_status(struct phy_device *phydev) · line 249

Quoted 9 lines
drivers/net/phy/nxp-tja11xx.c +6 -0
@@ -239,6 +241,30 @@ static int tja11xx_read_status(struct phy_device *phydev)
 	return 0;
 }
 
+static int tja11xx_config_intr(struct phy_device *phydev)
+{
+	int ret;
+
+	if (phydev->interrupts == PHY_INTERRUPT_ENABLED)
+		ret = phy_write(phydev, MII_INTEN, 0xcfef);

As Florian commented already, such magic numbers are not nice. Better add a constant for each bit representing an interrupt source. Please note that phylib is interested in the link change event only. Therefore typically only one bit is set.

drivers/net/phy/nxp-tja11xx.c static int tja11xx_read_status(struct phy_device *phydev) · line 257

Quoted 8 lines
drivers/net/phy/nxp-tja11xx.c +8 -0
+	else
+		ret = phy_write(phydev, MII_INTEN, 0);
+
+	if (ret < 0)
+		return ret;
+
+	ret = phy_read(phydev, MII_INTSRC);
+

This IRQ ACK can be removed. It's done by phylib, see phy_enable_interrupts().

Quoted 34 lines
drivers/net/phy/nxp-tja11xx.c +16 -0
+	return ret < 0 ? ret : 0;
+}
+
+static int tja11xx_ack_interrupt(struct phy_device *phydev)
+{
+	int ret = phy_read(phydev, MII_INTSRC);
+
+	return ret < 0 ? ret : 0;
+}
+
 static int tja11xx_get_sset_count(struct phy_device *phydev)
 {
 	return ARRAY_SIZE(tja11xx_hw_stats);
@@ -366,6 +392,9 @@ static struct phy_driver tja11xx_driver[] = {
 		.suspend	= genphy_suspend,
 		.resume		= genphy_resume,
 		.set_loopback   = genphy_loopback,
+		/* IRQ related */
+		.config_intr	= tja11xx_config_intr,
+		.ack_interrupt	= tja11xx_ack_interrupt,
 		/* Statistics */
 		.get_sset_count = tja11xx_get_sset_count,
 		.get_strings	= tja11xx_get_strings,
@@ -381,6 +410,9 @@ static struct phy_driver tja11xx_driver[] = {
 		.suspend	= genphy_suspend,
 		.resume		= genphy_resume,
 		.set_loopback   = genphy_loopback,
+		/* IRQ related */
+		.config_intr	= tja11xx_config_intr,
+		.ack_interrupt	= tja11xx_ack_interrupt,
 		/* Statistics */
 		.get_sset_count = tja11xx_get_sset_count,
 		.get_strings	= tja11xx_get_strings,
#4 lore raw
Quoted 31 lines · Heiner Kallweit
Quoted 30 lines · Marek Vasut

Add support for handling the TJA11xx PHY IRQ signal.

Cc Andrew Lunn <[email protected]>
Cc Florian Fainelli <[email protected]>
Cc Guenter Roeck <[email protected]>
Cc Heiner Kallweit <[email protected]>
Cc Jean Delvare <[email protected]>
---
 drivers/net/phy/nxp-tja11xx.c | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)
drivers/net/phy/nxp-tja11xx.c +2 -0
index b705d0bd798b..0be9fe9a9604 100644
@@ -40,6 +40,8 @@
 #define MII_INTSRC_TEMP_ERR		BIT(1)
 #define MII_INTSRC_UV_ERR		BIT(3)
 
+#define MII_INTEN			22
+
 #define MII_COMMSTAT			23
 #define MII_COMMSTAT_LINK_UP		BIT(15)
 
@@ -239,6 +241,30 @@ static int tja11xx_read_status(struct phy_device *phydev)
 	return 0;
 }
 
Quoted 11 lines

drivers/net/phy/nxp-tja11xx.c static int tja11xx_read_status(struct phy_device *phydev) · line 249

Quoted 6 lines
drivers/net/phy/nxp-tja11xx.c +6 -0
+static int tja11xx_config_intr(struct phy_device *phydev)
+{
+	int ret;
+
+	if (phydev->interrupts == PHY_INTERRUPT_ENABLED)
+		ret = phy_write(phydev, MII_INTEN, 0xcfef);

As Florian commented already, such magic numbers are not nice. Better add a constant for each bit representing an interrupt source. Please note that phylib is interested in the link change event only. Therefore typically only one bit is set.

With this PHY, it seems all of those bits have impact on the link.

Quoted 11 lines

drivers/net/phy/nxp-tja11xx.c static int tja11xx_read_status(struct phy_device *phydev) · line 257

Quoted 8 lines
drivers/net/phy/nxp-tja11xx.c +8 -0
+	else
+		ret = phy_write(phydev, MII_INTEN, 0);
+
+	if (ret < 0)
+		return ret;
+
+	ret = phy_read(phydev, MII_INTSRC);
+

This IRQ ACK can be removed. It's done by phylib, see phy_enable_interrupts().

OK

Signature · 2 lines
Best regards,
Marek Vasut