netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next 1/1] ptp: gianfar: Use high resolution frequency method.
@ 2016-11-23 20:11 Ulrik De Bie
  2016-11-23 20:23 ` Richard Cochran
  2016-11-27 20:27 ` David Miller
  0 siblings, 2 replies; 3+ messages in thread
From: Ulrik De Bie @ 2016-11-23 20:11 UTC (permalink / raw)
  To: netdev; +Cc: David Miller, Richard Cochran, ulrik.debie-os

This patch depends on commit d8d263541913 ("ptp: Introduce a high
resolution frequency adjustment method.")

The gianfar devices offer a frequency resolution of about 0.46 ppb
(depends on actual value of tmr_add, for the calculation assumed
0x80000000). This patch lets users of the device benefit from the increased
frequency resolution when tuning the clock. Thanks to the rounding the
maximum error between the requested frequency and the applied frequency
will then be about 0.23 ppb.

Tested on a v3.3.8 kernel on a real gianfar device. Verified compilation
on net-next (currently at v4.9-rc5).

Signed-off-by: Ulrik De Bie <ulrik.debie-os@e2big.org>
---
 drivers/net/ethernet/freescale/gianfar_ptp.c | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/drivers/net/ethernet/freescale/gianfar_ptp.c b/drivers/net/ethernet/freescale/gianfar_ptp.c
index 3e8d1ff..721be13 100644
--- a/drivers/net/ethernet/freescale/gianfar_ptp.c
+++ b/drivers/net/ethernet/freescale/gianfar_ptp.c
@@ -280,21 +280,26 @@ static irqreturn_t isr(int irq, void *priv)
  * PTP clock operations
  */
 
-static int ptp_gianfar_adjfreq(struct ptp_clock_info *ptp, s32 ppb)
+static int ptp_gianfar_adjfine(struct ptp_clock_info *ptp, long scaled_ppm)
 {
-	u64 adj;
-	u32 diff, tmr_add;
+	u64 adj, diff;
+	u32 tmr_add;
 	int neg_adj = 0;
 	struct etsects *etsects = container_of(ptp, struct etsects, caps);
 
-	if (ppb < 0) {
+	if (scaled_ppm < 0) {
 		neg_adj = 1;
-		ppb = -ppb;
+		scaled_ppm = -scaled_ppm;
 	}
 	tmr_add = etsects->tmr_add;
 	adj = tmr_add;
-	adj *= ppb;
-	diff = div_u64(adj, 1000000000ULL);
+
+	/* calculate diff as adj*(scaled_ppm/65536)/1000000
+	 * and round() to the nearest integer
+	 */
+	adj *= scaled_ppm;
+	diff = div_u64(adj, 8000000);
+	diff = (diff >> 13) + ((diff >> 12) & 1);
 
 	tmr_add = neg_adj ? tmr_add - diff : tmr_add + diff;
 
@@ -415,7 +420,7 @@ static struct ptp_clock_info ptp_gianfar_caps = {
 	.n_per_out	= 0,
 	.n_pins		= 0,
 	.pps		= 1,
-	.adjfreq	= ptp_gianfar_adjfreq,
+	.adjfine	= ptp_gianfar_adjfine,
 	.adjtime	= ptp_gianfar_adjtime,
 	.gettime64	= ptp_gianfar_gettime,
 	.settime64	= ptp_gianfar_settime,
-- 
2.10.2

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

* Re: [PATCH net-next 1/1] ptp: gianfar: Use high resolution frequency method.
  2016-11-23 20:11 [PATCH net-next 1/1] ptp: gianfar: Use high resolution frequency method Ulrik De Bie
@ 2016-11-23 20:23 ` Richard Cochran
  2016-11-27 20:27 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: Richard Cochran @ 2016-11-23 20:23 UTC (permalink / raw)
  To: Ulrik De Bie; +Cc: netdev, David Miller

On Wed, Nov 23, 2016 at 09:11:04PM +0100, Ulrik De Bie wrote:
> This patch depends on commit d8d263541913 ("ptp: Introduce a high
> resolution frequency adjustment method.")
> 
> The gianfar devices offer a frequency resolution of about 0.46 ppb
> (depends on actual value of tmr_add, for the calculation assumed
> 0x80000000). This patch lets users of the device benefit from the increased
> frequency resolution when tuning the clock. Thanks to the rounding the
> maximum error between the requested frequency and the applied frequency
> will then be about 0.23 ppb.
> 
> Tested on a v3.3.8 kernel on a real gianfar device. Verified compilation
> on net-next (currently at v4.9-rc5).
> 
> Signed-off-by: Ulrik De Bie <ulrik.debie-os@e2big.org>

Acked-by: Richard Cochran <richardcochran@gmail.com>

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

* Re: [PATCH net-next 1/1] ptp: gianfar: Use high resolution frequency method.
  2016-11-23 20:11 [PATCH net-next 1/1] ptp: gianfar: Use high resolution frequency method Ulrik De Bie
  2016-11-23 20:23 ` Richard Cochran
@ 2016-11-27 20:27 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2016-11-27 20:27 UTC (permalink / raw)
  To: ulrik.debie-os; +Cc: netdev, richardcochran

From: Ulrik De Bie <ulrik.debie-os@e2big.org>
Date: Wed, 23 Nov 2016 21:11:04 +0100

> This patch depends on commit d8d263541913 ("ptp: Introduce a high
> resolution frequency adjustment method.")
> 
> The gianfar devices offer a frequency resolution of about 0.46 ppb
> (depends on actual value of tmr_add, for the calculation assumed
> 0x80000000). This patch lets users of the device benefit from the increased
> frequency resolution when tuning the clock. Thanks to the rounding the
> maximum error between the requested frequency and the applied frequency
> will then be about 0.23 ppb.
> 
> Tested on a v3.3.8 kernel on a real gianfar device. Verified compilation
> on net-next (currently at v4.9-rc5).
> 
> Signed-off-by: Ulrik De Bie <ulrik.debie-os@e2big.org>

Applied.

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

end of thread, other threads:[~2016-11-27 20:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-11-23 20:11 [PATCH net-next 1/1] ptp: gianfar: Use high resolution frequency method Ulrik De Bie
2016-11-23 20:23 ` Richard Cochran
2016-11-27 20:27 ` David Miller

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