netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next] net: phy: micrel: Adding interrupt support for Link up/Link down in LAN8814 Quad phy
@ 2021-12-21  7:05 Divya Koppera
  2021-12-21  9:00 ` Andrew Lunn
  0 siblings, 1 reply; 2+ messages in thread
From: Divya Koppera @ 2021-12-21  7:05 UTC (permalink / raw)
  To: andrew, hkallweit1, linux, davem, kuba, netdev, linux-kernel
  Cc: UNGLinuxDriver

This patch add support for Link up or Link down
interrupt support in LAN8814 Quad phy.

Signed-off-by: Divya Koppera <Divya.Koppera@microchip.com>
---
 drivers/net/phy/micrel.c | 71 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 71 insertions(+)

diff --git a/drivers/net/phy/micrel.c b/drivers/net/phy/micrel.c
index 44a24b99c894..46931020ef84 100644
--- a/drivers/net/phy/micrel.c
+++ b/drivers/net/phy/micrel.c
@@ -66,6 +66,23 @@
 #define KSZ8081_LMD_SHORT_INDICATOR		BIT(12)
 #define KSZ8081_LMD_DELTA_TIME_MASK		GENMASK(8, 0)
 
+/* Lan8814 general Interrupt control/status reg in GPHY specific block. */
+#define LAN8814_INTC				0x18
+#define LAN8814_INTC_LINK_DOWN			BIT(2)
+#define LAN8814_INTC_LINK_UP			BIT(0)
+#define LAN8814_INTC_LINK			(LAN8814_INTC_LINK_UP |\
+						 LAN8814_INTC_LINK_DOWN)
+
+#define LAN8814_INTS				0x1B
+#define LAN8814_INTS_LINK_DOWN			BIT(2)
+#define LAN8814_INTS_LINK_UP			BIT(0)
+#define LAN8814_INTS_LINK			(LAN8814_INTS_LINK_UP |\
+						 LAN8814_INTS_LINK_DOWN)
+
+#define LAN8814_INTR_CTRL_REG			0x34
+#define LAN8814_INTR_CTRL_REG_POLARITY		BIT(1)
+#define LAN8814_INTR_CTRL_REG_INTR_ENABLE	BIT(0)
+
 /* PHY Control 1 */
 #define MII_KSZPHY_CTRL_1			0x1e
 #define KSZ8081_CTRL1_MDIX_STAT			BIT(4)
@@ -1620,6 +1637,58 @@ static int lan8804_config_init(struct phy_device *phydev)
 	return 0;
 }
 
+static irqreturn_t lan8814_handle_interrupt(struct phy_device *phydev)
+{
+	int irq_status;
+
+	irq_status = phy_read(phydev, LAN8814_INTS);
+	if (irq_status < 0)
+		return IRQ_NONE;
+
+	if (!(irq_status & LAN8814_INTS_LINK))
+		return IRQ_NONE;
+
+	phy_trigger_machine(phydev);
+
+	return IRQ_HANDLED;
+}
+
+static int lan8814_ack_interrupt(struct phy_device *phydev)
+{
+	/* bit[12..0] int status, which is a read and clear register. */
+	int rc;
+
+	rc = phy_read(phydev, LAN8814_INTS);
+
+	return (rc < 0) ? rc : 0;
+}
+
+static int lan8814_config_intr(struct phy_device *phydev)
+{
+	int err;
+
+	lanphy_write_page_reg(phydev, 4, LAN8814_INTR_CTRL_REG,
+			      LAN8814_INTR_CTRL_REG_POLARITY |
+			      LAN8814_INTR_CTRL_REG_INTR_ENABLE);
+
+	/* enable / disable interrupts */
+	if (phydev->interrupts == PHY_INTERRUPT_ENABLED) {
+		err = lan8814_ack_interrupt(phydev);
+		if (err)
+			return err;
+
+		err =  phy_write(phydev, LAN8814_INTC, LAN8814_INTC_LINK);
+	} else {
+		err =  phy_write(phydev, LAN8814_INTC, 0);
+		if (err)
+			return err;
+
+		err = lan8814_ack_interrupt(phydev);
+	}
+
+	return err;
+}
+
 static struct phy_driver ksphy_driver[] = {
 {
 	.phy_id		= PHY_ID_KS8737,
@@ -1802,6 +1871,8 @@ static struct phy_driver ksphy_driver[] = {
 	.get_stats	= kszphy_get_stats,
 	.suspend	= genphy_suspend,
 	.resume		= kszphy_resume,
+	.config_intr	= lan8814_config_intr,
+	.handle_interrupt = lan8814_handle_interrupt,
 }, {
 	.phy_id		= PHY_ID_LAN8804,
 	.phy_id_mask	= MICREL_PHY_ID_MASK,
-- 
2.17.1


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

* Re: [PATCH net-next] net: phy: micrel: Adding interrupt support for Link up/Link down in LAN8814 Quad phy
  2021-12-21  7:05 [PATCH net-next] net: phy: micrel: Adding interrupt support for Link up/Link down in LAN8814 Quad phy Divya Koppera
@ 2021-12-21  9:00 ` Andrew Lunn
  0 siblings, 0 replies; 2+ messages in thread
From: Andrew Lunn @ 2021-12-21  9:00 UTC (permalink / raw)
  To: Divya Koppera
  Cc: hkallweit1, linux, davem, kuba, netdev, linux-kernel,
	UNGLinuxDriver

On Tue, Dec 21, 2021 at 12:35:02PM +0530, Divya Koppera wrote:
> This patch add support for Link up or Link down
> interrupt support in LAN8814 Quad phy.
> 
> Signed-off-by: Divya Koppera <Divya.Koppera@microchip.com>
> ---
>  drivers/net/phy/micrel.c | 71 ++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 71 insertions(+)
> 
> diff --git a/drivers/net/phy/micrel.c b/drivers/net/phy/micrel.c
> index 44a24b99c894..46931020ef84 100644
> --- a/drivers/net/phy/micrel.c
> +++ b/drivers/net/phy/micrel.c
> @@ -66,6 +66,23 @@
>  #define KSZ8081_LMD_SHORT_INDICATOR		BIT(12)
>  #define KSZ8081_LMD_DELTA_TIME_MASK		GENMASK(8, 0)
>  
> +/* Lan8814 general Interrupt control/status reg in GPHY specific block. */
> +#define LAN8814_INTC				0x18
> +#define LAN8814_INTC_LINK_DOWN			BIT(2)
> +#define LAN8814_INTC_LINK_UP			BIT(0)
> +#define LAN8814_INTC_LINK			(LAN8814_INTC_LINK_UP |\
> +						 LAN8814_INTC_LINK_DOWN)
> +
> +#define LAN8814_INTS				0x1B
> +#define LAN8814_INTS_LINK_DOWN			BIT(2)
> +#define LAN8814_INTS_LINK_UP			BIT(0)
> +#define LAN8814_INTS_LINK			(LAN8814_INTS_LINK_UP |\

I've never seen an interrupt controller where the interrupt control
bits and the interrupt status bits are different. So just define the
two interesting bits as LAN8814_INT_LINK_DOWN and LAN8814_INT_LINK_UP
and share them across the two registers.

Otherwise this looks good.

    Andrew

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

end of thread, other threads:[~2021-12-21  9:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-12-21  7:05 [PATCH net-next] net: phy: micrel: Adding interrupt support for Link up/Link down in LAN8814 Quad phy Divya Koppera
2021-12-21  9:00 ` 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).