[PATCH net v1 1/2] ARM: dts: imx: let's name the ptp interrupt for the fec ethernet driver

Subsystems: the rest

STALE3234d

6 messages, 3 authors, 2017-10-09 · open the first message on its own page

[PATCH net v1 1/2] ARM: dts: imx: let's name the ptp interrupt for the fec ethernet driver

From: Troy Kisky <hidden>
Date: 2017-10-03 00:04:50

imx7s/imx7d has the ptp interrupt newly added as well.
This will allow the ptp interrupt to have its own interrupt routine.

Signed-off-by: Troy Kisky <redacted>
---
 arch/arm/boot/dts/imx6qdl.dtsi | 1 +
 arch/arm/boot/dts/imx6sx.dtsi  | 2 ++
 arch/arm/boot/dts/imx6ul.dtsi  | 2 ++
 arch/arm/boot/dts/imx7d.dtsi   | 4 +++-
 arch/arm/boot/dts/imx7s.dtsi   | 4 +++-
 5 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/arch/arm/boot/dts/imx6qdl.dtsi b/arch/arm/boot/dts/imx6qdl.dtsi
index 8884b4a3cafb..d848d2bfe8e2 100644
--- a/arch/arm/boot/dts/imx6qdl.dtsi
+++ b/arch/arm/boot/dts/imx6qdl.dtsi
@@ -1017,6 +1017,7 @@
 			fec: ethernet@02188000 {
 				compatible = "fsl,imx6q-fec";
 				reg = <0x02188000 0x4000>;
+				interrupt-names = "","ptp";
 				interrupts-extended =
 					<&intc 0 118 IRQ_TYPE_LEVEL_HIGH>,
 					<&intc 0 119 IRQ_TYPE_LEVEL_HIGH>;
diff --git a/arch/arm/boot/dts/imx6sx.dtsi b/arch/arm/boot/dts/imx6sx.dtsi
index 6c7eb54be9e2..d64ae33c0b41 100644
--- a/arch/arm/boot/dts/imx6sx.dtsi
+++ b/arch/arm/boot/dts/imx6sx.dtsi
@@ -861,6 +861,7 @@
 			fec1: ethernet@02188000 {
 				compatible = "fsl,imx6sx-fec", "fsl,imx6q-fec";
 				reg = <0x02188000 0x4000>;
+				interrupt-names = "","ptp";
 				interrupts = <GIC_SPI 118 IRQ_TYPE_LEVEL_HIGH>,
 					     <GIC_SPI 119 IRQ_TYPE_LEVEL_HIGH>;
 				clocks = <&clks IMX6SX_CLK_ENET>,
@@ -970,6 +971,7 @@
 			fec2: ethernet@021b4000 {
 				compatible = "fsl,imx6sx-fec", "fsl,imx6q-fec";
 				reg = <0x021b4000 0x4000>;
+				interrupt-names = "","ptp";
 				interrupts = <GIC_SPI 102 IRQ_TYPE_LEVEL_HIGH>,
 					     <GIC_SPI 103 IRQ_TYPE_LEVEL_HIGH>;
 				clocks = <&clks IMX6SX_CLK_ENET>,
diff --git a/arch/arm/boot/dts/imx6ul.dtsi b/arch/arm/boot/dts/imx6ul.dtsi
index f11a241a340d..fe093f8531b0 100644
--- a/arch/arm/boot/dts/imx6ul.dtsi
+++ b/arch/arm/boot/dts/imx6ul.dtsi
@@ -476,6 +476,7 @@
 			fec2: ethernet@020b4000 {
 				compatible = "fsl,imx6ul-fec", "fsl,imx6q-fec";
 				reg = <0x020b4000 0x4000>;
+				interrupt-names = "","ptp";
 				interrupts = <GIC_SPI 120 IRQ_TYPE_LEVEL_HIGH>,
 					     <GIC_SPI 121 IRQ_TYPE_LEVEL_HIGH>;
 				clocks = <&clks IMX6UL_CLK_ENET>,
@@ -775,6 +776,7 @@
 			fec1: ethernet@02188000 {
 				compatible = "fsl,imx6ul-fec", "fsl,imx6q-fec";
 				reg = <0x02188000 0x4000>;
+				interrupt-names = "","ptp";
 				interrupts = <GIC_SPI 118 IRQ_TYPE_LEVEL_HIGH>,
 					     <GIC_SPI 119 IRQ_TYPE_LEVEL_HIGH>;
 				clocks = <&clks IMX6UL_CLK_ENET>,
diff --git a/arch/arm/boot/dts/imx7d.dtsi b/arch/arm/boot/dts/imx7d.dtsi
index f46814a7ea44..e8fc76483236 100644
--- a/arch/arm/boot/dts/imx7d.dtsi
+++ b/arch/arm/boot/dts/imx7d.dtsi
@@ -114,9 +114,11 @@
 	fec2: ethernet@30bf0000 {
 		compatible = "fsl,imx7d-fec", "fsl,imx6sx-fec";
 		reg = <0x30bf0000 0x10000>;
+		interrupt-names = "","","","ptp";
 		interrupts = <GIC_SPI 100 IRQ_TYPE_LEVEL_HIGH>,
 			<GIC_SPI 101 IRQ_TYPE_LEVEL_HIGH>,
-			<GIC_SPI 102 IRQ_TYPE_LEVEL_HIGH>;
+			<GIC_SPI 102 IRQ_TYPE_LEVEL_HIGH>,
+			<GIC_SPI 103 IRQ_TYPE_LEVEL_HIGH>;
 		clocks = <&clks IMX7D_ENET_AXI_ROOT_CLK>,
 			<&clks IMX7D_ENET_AXI_ROOT_CLK>,
 			<&clks IMX7D_ENET2_TIME_ROOT_CLK>,
diff --git a/arch/arm/boot/dts/imx7s.dtsi b/arch/arm/boot/dts/imx7s.dtsi
index 82ad26e766eb..fc1376079494 100644
--- a/arch/arm/boot/dts/imx7s.dtsi
+++ b/arch/arm/boot/dts/imx7s.dtsi
@@ -1007,9 +1007,11 @@
 			fec1: ethernet@30be0000 {
 				compatible = "fsl,imx7d-fec", "fsl,imx6sx-fec";
 				reg = <0x30be0000 0x10000>;
+				interrupt-names = "","","","ptp";
 				interrupts = <GIC_SPI 118 IRQ_TYPE_LEVEL_HIGH>,
 					<GIC_SPI 119 IRQ_TYPE_LEVEL_HIGH>,
-					<GIC_SPI 120 IRQ_TYPE_LEVEL_HIGH>;
+					<GIC_SPI 120 IRQ_TYPE_LEVEL_HIGH>,
+					<GIC_SPI 121 IRQ_TYPE_LEVEL_HIGH>;
 				clocks = <&clks IMX7D_ENET_AXI_ROOT_CLK>,
 					<&clks IMX7D_ENET_AXI_ROOT_CLK>,
 					<&clks IMX7D_ENET1_TIME_ROOT_CLK>,
-- 
2.11.0

[PATCH net v1 2/2] net: fec: Let fec_ptp have its own interrupt routine

From: Troy Kisky <hidden>
Date: 2017-10-03 00:04:50

This is better for code locality and should slightly
speed up normal interrupts.

This also allows PPS clock output to start working for
i.mx7. This is because i.mx7 was already using the limit
of 3 interrupts, and needed another.

Signed-off-by: Troy Kisky <redacted>

---
If this patch is taken before the corresponding dtb file patch
than time stamping will be momentarily broken.
---
 drivers/net/ethernet/freescale/fec.h      |  1 -
 drivers/net/ethernet/freescale/fec_main.c | 15 +++---
 drivers/net/ethernet/freescale/fec_ptp.c  | 77 ++++++++++++++++++-------------
 3 files changed, 52 insertions(+), 41 deletions(-)
diff --git a/drivers/net/ethernet/freescale/fec.h b/drivers/net/ethernet/freescale/fec.h
index ede1876a9a19..782509041102 100644
--- a/drivers/net/ethernet/freescale/fec.h
+++ b/drivers/net/ethernet/freescale/fec.h
@@ -587,7 +587,6 @@ void fec_ptp_stop(struct platform_device *pdev);
 void fec_ptp_start_cyclecounter(struct net_device *ndev);
 int fec_ptp_set(struct net_device *ndev, struct ifreq *ifr);
 int fec_ptp_get(struct net_device *ndev, struct ifreq *ifr);
-uint fec_ptp_check_pps_event(struct fec_enet_private *fep);
 
 /****************************************************************************/
 #endif /* FEC_H */
diff --git a/drivers/net/ethernet/freescale/fec_main.c b/drivers/net/ethernet/freescale/fec_main.c
index 3dc2d771a222..80fe04165ba0 100644
--- a/drivers/net/ethernet/freescale/fec_main.c
+++ b/drivers/net/ethernet/freescale/fec_main.c
@@ -1602,10 +1602,6 @@ fec_enet_interrupt(int irq, void *dev_id)
 		ret = IRQ_HANDLED;
 		complete(&fep->mdio_done);
 	}
-
-	if (fep->ptp_clock)
-		if (fec_ptp_check_pps_event(fep))
-			ret = IRQ_HANDLED;
 	return ret;
 }
 
@@ -3325,6 +3321,7 @@ fec_probe(struct platform_device *pdev)
 	struct device_node *np = pdev->dev.of_node, *phy_node;
 	int num_tx_qs;
 	int num_rx_qs;
+	int ptp_irq, j;
 
 	fec_enet_get_queue_num(pdev, &num_tx_qs, &num_rx_qs);
 
@@ -3472,20 +3469,24 @@ fec_probe(struct platform_device *pdev)
 	if (ret)
 		goto failed_init;
 
-	for (i = 0; i < FEC_IRQ_NUM; i++) {
-		irq = platform_get_irq(pdev, i);
+	ptp_irq = platform_get_irq_byname(pdev, "ptp");
+	i = j = 0;
+	while (i < FEC_IRQ_NUM) {
+		irq = platform_get_irq(pdev, j++);
 		if (irq < 0) {
 			if (i)
 				break;
 			ret = irq;
 			goto failed_irq;
 		}
+		if (irq == ptp_irq)
+			continue;
 		ret = devm_request_irq(&pdev->dev, irq, fec_enet_interrupt,
 				       0, pdev->name, ndev);
 		if (ret)
 			goto failed_irq;
 
-		fep->irq[i] = irq;
+		fep->irq[i++] = irq;
 	}
 
 	init_completion(&fep->mdio_done);
diff --git a/drivers/net/ethernet/freescale/fec_ptp.c b/drivers/net/ethernet/freescale/fec_ptp.c
index 6ebad3fac81d..20e01a3ca453 100644
--- a/drivers/net/ethernet/freescale/fec_ptp.c
+++ b/drivers/net/ethernet/freescale/fec_ptp.c
@@ -549,6 +549,38 @@ static void fec_time_keep(struct work_struct *work)
 	schedule_delayed_work(&fep->time_keep, HZ);
 }
 
+/*
+ * This function checks the pps event and reloads the timer compare counter.
+ */
+static irqreturn_t fec_ptp_interrupt(int irq, void *dev_id)
+{
+	struct net_device *ndev = dev_id;
+	struct fec_enet_private *fep = netdev_priv(ndev);
+	u32 val;
+	u8 channel = fep->pps_channel;
+	struct ptp_clock_event event;
+
+	val = readl(fep->hwp + FEC_TCSR(channel));
+	if (val & FEC_T_TF_MASK) {
+		/* Write the next next compare(not the next according the spec)
+		 * value to the register
+		 */
+		writel(fep->next_counter, fep->hwp + FEC_TCCR(channel));
+		do {
+			writel(val, fep->hwp + FEC_TCSR(channel));
+		} while (readl(fep->hwp + FEC_TCSR(channel)) & FEC_T_TF_MASK);
+
+		/* Update the counter; */
+		fep->next_counter = (fep->next_counter + fep->reload_period) & fep->cc.mask;
+
+		event.type = PTP_CLOCK_PPS;
+		ptp_clock_event(fep->ptp_clock, &event);
+		return IRQ_HANDLED;
+	}
+
+	return IRQ_NONE;
+}
+
 /**
  * fec_ptp_init
  * @ndev: The FEC network adapter
@@ -562,6 +594,8 @@ void fec_ptp_init(struct platform_device *pdev)
 {
 	struct net_device *ndev = platform_get_drvdata(pdev);
 	struct fec_enet_private *fep = netdev_priv(ndev);
+	int irq;
+	int ret;
 
 	fep->ptp_caps.owner = THIS_MODULE;
 	snprintf(fep->ptp_caps.name, 16, "fec ptp");
@@ -587,6 +621,16 @@ void fec_ptp_init(struct platform_device *pdev)
 
 	INIT_DELAYED_WORK(&fep->time_keep, fec_time_keep);
 
+	irq = platform_get_irq_byname(pdev, "ptp");
+	if (irq < 0)
+		return;
+	ret = devm_request_irq(&pdev->dev, irq, fec_ptp_interrupt,
+			       0, pdev->name, ndev);
+	if (ret < 0) {
+		dev_warn(&pdev->dev, "request for ptp irq failed(%d)\n", ret);
+		return;
+	}
+
 	fep->ptp_clock = ptp_clock_register(&fep->ptp_caps, &pdev->dev);
 	if (IS_ERR(fep->ptp_clock)) {
 		fep->ptp_clock = NULL;
@@ -605,36 +649,3 @@ void fec_ptp_stop(struct platform_device *pdev)
 	if (fep->ptp_clock)
 		ptp_clock_unregister(fep->ptp_clock);
 }
-
-/**
- * fec_ptp_check_pps_event
- * @fep: the fec_enet_private structure handle
- *
- * This function check the pps event and reload the timer compare counter.
- */
-uint fec_ptp_check_pps_event(struct fec_enet_private *fep)
-{
-	u32 val;
-	u8 channel = fep->pps_channel;
-	struct ptp_clock_event event;
-
-	val = readl(fep->hwp + FEC_TCSR(channel));
-	if (val & FEC_T_TF_MASK) {
-		/* Write the next next compare(not the next according the spec)
-		 * value to the register
-		 */
-		writel(fep->next_counter, fep->hwp + FEC_TCCR(channel));
-		do {
-			writel(val, fep->hwp + FEC_TCSR(channel));
-		} while (readl(fep->hwp + FEC_TCSR(channel)) & FEC_T_TF_MASK);
-
-		/* Update the counter; */
-		fep->next_counter = (fep->next_counter + fep->reload_period) & fep->cc.mask;
-
-		event.type = PTP_CLOCK_PPS;
-		ptp_clock_event(fep->ptp_clock, &event);
-		return 1;
-	}
-
-	return 0;
-}
-- 
2.11.0

Re: [PATCH net v1 1/2] ARM: dts: imx: let's name the ptp interrupt for the fec ethernet driver

From: Andrew Lunn <andrew@lunn.ch>
Date: 2017-10-03 00:51:53

On Mon, Oct 02, 2017 at 05:04:41PM -0700, Troy Kisky wrote:
quoted hunk
imx7s/imx7d has the ptp interrupt newly added as well.
This will allow the ptp interrupt to have its own interrupt routine.

Signed-off-by: Troy Kisky <redacted>
---
 arch/arm/boot/dts/imx6qdl.dtsi | 1 +
 arch/arm/boot/dts/imx6sx.dtsi  | 2 ++
 arch/arm/boot/dts/imx6ul.dtsi  | 2 ++
 arch/arm/boot/dts/imx7d.dtsi   | 4 +++-
 arch/arm/boot/dts/imx7s.dtsi   | 4 +++-
 5 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/arch/arm/boot/dts/imx6qdl.dtsi b/arch/arm/boot/dts/imx6qdl.dtsi
index 8884b4a3cafb..d848d2bfe8e2 100644
--- a/arch/arm/boot/dts/imx6qdl.dtsi
+++ b/arch/arm/boot/dts/imx6qdl.dtsi
@@ -1017,6 +1017,7 @@
 			fec: ethernet@02188000 {
 				compatible = "fsl,imx6q-fec";
 				reg = <0x02188000 0x4000>;
+				interrupt-names = "","ptp";
Hi Troy

The "" looks a bit odd. Can you use a name here?

    Andrew

Re: [PATCH net v1 1/2] ARM: dts: imx: let's name the ptp interrupt for the fec ethernet driver

From: Troy Kisky <hidden>
Date: 2017-10-03 20:41:30

On 10/2/2017 5:51 PM, Andrew Lunn wrote:
On Mon, Oct 02, 2017 at 05:04:41PM -0700, Troy Kisky wrote:
quoted
imx7s/imx7d has the ptp interrupt newly added as well.
This will allow the ptp interrupt to have its own interrupt routine.

Signed-off-by: Troy Kisky <redacted>
---
 arch/arm/boot/dts/imx6qdl.dtsi | 1 +
 arch/arm/boot/dts/imx6sx.dtsi  | 2 ++
 arch/arm/boot/dts/imx6ul.dtsi  | 2 ++
 arch/arm/boot/dts/imx7d.dtsi   | 4 +++-
 arch/arm/boot/dts/imx7s.dtsi   | 4 +++-
 5 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/arch/arm/boot/dts/imx6qdl.dtsi b/arch/arm/boot/dts/imx6qdl.dtsi
index 8884b4a3cafb..d848d2bfe8e2 100644
--- a/arch/arm/boot/dts/imx6qdl.dtsi
+++ b/arch/arm/boot/dts/imx6qdl.dtsi
@@ -1017,6 +1017,7 @@
 			fec: ethernet@02188000 {
 				compatible = "fsl,imx6q-fec";
 				reg = <0x02188000 0x4000>;
+				interrupt-names = "","ptp";
Hi Troy

The "" looks a bit odd. Can you use a name here?

    Andrew
Sure. Can I use "q0","q1","q2",  and look them up by name in fec_main
as well ?

Should I worrying about compatiblity with old dtbs ?
I could look up by number if name fails. Maybe with a
deprecated warning ?


Thanks
Troy

Re: [PATCH net v1 1/2] ARM: dts: imx: let's name the ptp interrupt for the fec ethernet driver

From: Andrew Lunn <andrew@lunn.ch>
Date: 2017-10-03 20:54:03

On Tue, Oct 03, 2017 at 01:41:34PM -0700, Troy Kisky wrote:
On 10/2/2017 5:51 PM, Andrew Lunn wrote:
quoted
On Mon, Oct 02, 2017 at 05:04:41PM -0700, Troy Kisky wrote:
quoted
imx7s/imx7d has the ptp interrupt newly added as well.
This will allow the ptp interrupt to have its own interrupt routine.

Signed-off-by: Troy Kisky <redacted>
---
 arch/arm/boot/dts/imx6qdl.dtsi | 1 +
 arch/arm/boot/dts/imx6sx.dtsi  | 2 ++
 arch/arm/boot/dts/imx6ul.dtsi  | 2 ++
 arch/arm/boot/dts/imx7d.dtsi   | 4 +++-
 arch/arm/boot/dts/imx7s.dtsi   | 4 +++-
 5 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/arch/arm/boot/dts/imx6qdl.dtsi b/arch/arm/boot/dts/imx6qdl.dtsi
index 8884b4a3cafb..d848d2bfe8e2 100644
--- a/arch/arm/boot/dts/imx6qdl.dtsi
+++ b/arch/arm/boot/dts/imx6qdl.dtsi
@@ -1017,6 +1017,7 @@
 			fec: ethernet@02188000 {
 				compatible = "fsl,imx6q-fec";
 				reg = <0x02188000 0x4000>;
+				interrupt-names = "","ptp";
Hi Troy

The "" looks a bit odd. Can you use a name here?

    Andrew
Sure. Can I use "q0","q1","q2",  and look them up by name in fec_main
as well ?
Hi Troy

Is there no better name? How does the datasheet name them?
Should I worrying about compatiblity with old dtbs ?
Yes. You cannot break old dtb blobs. So i would suggest keep looking
up the old interrupts by number. But this new interrupt you can use
the name.

    Andrew

RE: [PATCH net v1 2/2] net: fec: Let fec_ptp have its own interrupt routine

From: Andy Duan <hidden>
Date: 2017-10-09 02:55:40

From: Troy Kisky <redacted> Sent: Tuesday, October 03, 2017 8:05 AM
To: shawn.guo@linaro.org; Andy Duan <redacted>;
netdev@vger.kernel.org; davem@davemloft.net
Cc: Fabio Estevam <redacted>; lznuaa@gmail.com; Troy Kisky
[off-list ref]
Subject: [PATCH net v1 2/2] net: fec: Let fec_ptp have its own interrupt
routine

This is better for code locality and should slightly speed up normal interrupts.

This also allows PPS clock output to start working for i.mx7. This is because
i.mx7 was already using the limit of 3 interrupts, and needed another.

Signed-off-by: Troy Kisky <redacted>

---
If this patch is taken before the corresponding dtb file patch than time
stamping will be momentarily broken.
---
The two patches for PPS seems 
quoted hunk
drivers/net/ethernet/freescale/fec.h      |  1 -
drivers/net/ethernet/freescale/fec_main.c | 15 +++---
drivers/net/ethernet/freescale/fec_ptp.c  | 77 ++++++++++++++++++--------
-----
3 files changed, 52 insertions(+), 41 deletions(-)
diff --git a/drivers/net/ethernet/freescale/fec.h
b/drivers/net/ethernet/freescale/fec.h
index ede1876a9a19..782509041102 100644
--- a/drivers/net/ethernet/freescale/fec.h
+++ b/drivers/net/ethernet/freescale/fec.h
@@ -587,7 +587,6 @@ void fec_ptp_stop(struct platform_device *pdev);
void fec_ptp_start_cyclecounter(struct net_device *ndev);  int
fec_ptp_set(struct net_device *ndev, struct ifreq *ifr);  int
fec_ptp_get(struct net_device *ndev, struct ifreq *ifr); -uint
fec_ptp_check_pps_event(struct fec_enet_private *fep);


/**********************************************************
******************/
#endif /* FEC_H */
diff --git a/drivers/net/ethernet/freescale/fec_main.c
b/drivers/net/ethernet/freescale/fec_main.c
index 3dc2d771a222..80fe04165ba0 100644
--- a/drivers/net/ethernet/freescale/fec_main.c
+++ b/drivers/net/ethernet/freescale/fec_main.c
@@ -1602,10 +1602,6 @@ fec_enet_interrupt(int irq, void *dev_id)
		ret = IRQ_HANDLED;
		complete(&fep->mdio_done);
	}
-
-	if (fep->ptp_clock)
-		if (fec_ptp_check_pps_event(fep))
-			ret = IRQ_HANDLED;
	return ret;
}
@@ -3325,6 +3321,7 @@ fec_probe(struct platform_device *pdev)
	struct device_node *np = pdev->dev.of_node, *phy_node;
	int num_tx_qs;
	int num_rx_qs;
+	int ptp_irq, j;

	fec_enet_get_queue_num(pdev, &num_tx_qs, &num_rx_qs);
@@ -3472,20 +3469,24 @@ fec_probe(struct platform_device *pdev)
	if (ret)
		goto failed_init;

-	for (i = 0; i < FEC_IRQ_NUM; i++) {
-		irq = platform_get_irq(pdev, i);
+	ptp_irq = platform_get_irq_byname(pdev, "ptp");
Here, interrupt-names property is required properties, it should update binding doc.
Also need to handle the return value checking.
+	i = j = 0;
+	while (i < FEC_IRQ_NUM) {
+		irq = platform_get_irq(pdev, j++);
		if (irq < 0) {
			if (i)
				break;
			ret = irq;
			goto failed_irq;
		}
+		if (irq == ptp_irq)
+			continue;
		ret = devm_request_irq(&pdev->dev, irq, fec_enet_interrupt,
				       0, pdev->name, ndev);
		if (ret)
			goto failed_irq;

-		fep->irq[i] = irq;
+		fep->irq[i++] = irq;
I think it is not necessary to split pps interrupt handler.
To support pps interrupt handler,  just change the maximum interrupt number FEC_IRQ_NUM to 4 that minimize the code change.
quoted hunk
	}

	init_completion(&fep->mdio_done);
diff --git a/drivers/net/ethernet/freescale/fec_ptp.c
b/drivers/net/ethernet/freescale/fec_ptp.c
index 6ebad3fac81d..20e01a3ca453 100644
--- a/drivers/net/ethernet/freescale/fec_ptp.c
+++ b/drivers/net/ethernet/freescale/fec_ptp.c
@@ -549,6 +549,38 @@ static void fec_time_keep(struct work_struct *work)
	schedule_delayed_work(&fep->time_keep, HZ);  }

+/*
+ * This function checks the pps event and reloads the timer compare counter.
+ */
+static irqreturn_t fec_ptp_interrupt(int irq, void *dev_id) {
+	struct net_device *ndev = dev_id;
+	struct fec_enet_private *fep = netdev_priv(ndev);
+	u32 val;
+	u8 channel = fep->pps_channel;
+	struct ptp_clock_event event;
+
+	val = readl(fep->hwp + FEC_TCSR(channel));
+	if (val & FEC_T_TF_MASK) {
+		/* Write the next next compare(not the next according the
spec)
+		 * value to the register
+		 */
+		writel(fep->next_counter, fep->hwp + FEC_TCCR(channel));
+		do {
+			writel(val, fep->hwp + FEC_TCSR(channel));
+		} while (readl(fep->hwp + FEC_TCSR(channel)) &
FEC_T_TF_MASK);
+
+		/* Update the counter; */
+		fep->next_counter = (fep->next_counter + fep-
quoted
reload_period) &
+fep->cc.mask;
+
+		event.type = PTP_CLOCK_PPS;
+		ptp_clock_event(fep->ptp_clock, &event);
+		return IRQ_HANDLED;
+	}
+
+	return IRQ_NONE;
+}
+
/**
 * fec_ptp_init
 * @ndev: The FEC network adapter
@@ -562,6 +594,8 @@ void fec_ptp_init(struct platform_device *pdev)  {
	struct net_device *ndev = platform_get_drvdata(pdev);
	struct fec_enet_private *fep = netdev_priv(ndev);
+	int irq;
+	int ret;

	fep->ptp_caps.owner = THIS_MODULE;
	snprintf(fep->ptp_caps.name, 16, "fec ptp"); @@ -587,6 +621,16 @@
void fec_ptp_init(struct platform_device *pdev)

	INIT_DELAYED_WORK(&fep->time_keep, fec_time_keep);

+	irq = platform_get_irq_byname(pdev, "ptp");
+	if (irq < 0)
+		return;
If dts don't set interrupt name, here break ptp function. Suppose PPS don't break ptp.
+	ret = devm_request_irq(&pdev->dev, irq, fec_ptp_interrupt,
+			       0, pdev->name, ndev);
+	if (ret < 0) {
+		dev_warn(&pdev->dev, "request for ptp irq failed(%d)\n",
ret);
+		return;
Ditto...
quoted hunk
+	}
+
	fep->ptp_clock = ptp_clock_register(&fep->ptp_caps, &pdev->dev);
	if (IS_ERR(fep->ptp_clock)) {
		fep->ptp_clock = NULL;
@@ -605,36 +649,3 @@ void fec_ptp_stop(struct platform_device *pdev)
	if (fep->ptp_clock)
		ptp_clock_unregister(fep->ptp_clock);
}
-
-/**
- * fec_ptp_check_pps_event
- * @fep: the fec_enet_private structure handle
- *
- * This function check the pps event and reload the timer compare counter.
- */
-uint fec_ptp_check_pps_event(struct fec_enet_private *fep) -{
-	u32 val;
-	u8 channel = fep->pps_channel;
-	struct ptp_clock_event event;
-
-	val = readl(fep->hwp + FEC_TCSR(channel));
-	if (val & FEC_T_TF_MASK) {
-		/* Write the next next compare(not the next according the
spec)
-		 * value to the register
-		 */
-		writel(fep->next_counter, fep->hwp + FEC_TCCR(channel));
-		do {
-			writel(val, fep->hwp + FEC_TCSR(channel));
-		} while (readl(fep->hwp + FEC_TCSR(channel)) &
FEC_T_TF_MASK);
-
-		/* Update the counter; */
-		fep->next_counter = (fep->next_counter + fep-
quoted
reload_period) & fep->cc.mask;
-
-		event.type = PTP_CLOCK_PPS;
-		ptp_clock_event(fep->ptp_clock, &event);
-		return 1;
-	}
-
-	return 0;
-}
--
2.11.0
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help