Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755125AbdLOHk6 (ORCPT ); Fri, 15 Dec 2017 02:40:58 -0500 Received: from mga06.intel.com ([134.134.136.31]:56944 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754319AbdLOHfr (ORCPT ); Fri, 15 Dec 2017 02:35:47 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,403,1508828400"; d="scan'208";a="158949346" From: Sagar Arun Kamble To: linux-kernel@vger.kernel.org Cc: Sagar Arun Kamble , "David S. Miller" , Grygorii Strashko , Richard Cochran , Bhumika Goyal , Thomas Gleixner , Ivan Khoronzhuk , netdev@vger.kernel.org Subject: [PATCH 14/27] net: cpts: Use timecounter_initialize interface Date: Fri, 15 Dec 2017 13:08:29 +0530 Message-Id: <1513323522-15021-15-git-send-email-sagar.a.kamble@intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1513323522-15021-1-git-send-email-sagar.a.kamble@intel.com> References: <1513323522-15021-1-git-send-email-sagar.a.kamble@intel.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3778 Lines: 114 With new interface timecounter_initialize we can initialize timecounter fields and underlying cyclecounter together. Update cpts timecounter init with this new function. Signed-off-by: Sagar Arun Kamble Cc: "David S. Miller" Cc: Grygorii Strashko Cc: Richard Cochran Cc: Bhumika Goyal Cc: Thomas Gleixner Cc: Ivan Khoronzhuk Cc: netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org --- drivers/net/ethernet/ti/cpts.c | 29 +++++++++++++++++------------ drivers/net/ethernet/ti/cpts.h | 3 +++ 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/drivers/net/ethernet/ti/cpts.c b/drivers/net/ethernet/ti/cpts.c index b8fe843..e6afc94 100644 --- a/drivers/net/ethernet/ti/cpts.c +++ b/drivers/net/ethernet/ti/cpts.c @@ -447,7 +447,12 @@ int cpts_register(struct cpts *cpts) cpts_write32(cpts, CPTS_EN, control); cpts_write32(cpts, TS_PEND_EN, int_enable); - timecounter_init(&cpts->tc, ktime_to_ns(ktime_get_real())); + timecounter_initialize(&cpts->tc, + cpts_systim_read, + cpts->mask, + cpts->mult, + cpts->shift, + ktime_to_ns(ktime_get_real())); cpts->clock = ptp_clock_register(&cpts->info, cpts->dev); if (IS_ERR(cpts->clock)) { @@ -484,7 +489,8 @@ void cpts_unregister(struct cpts *cpts) } EXPORT_SYMBOL_GPL(cpts_unregister); -static void cpts_calc_mult_shift(struct cpts *cpts) +static void cpts_calc_mult_shift(struct cpts *cpts, u64 mask, + u32 *mult, u32 *shift) { struct cyclecounter *cc = &cpts->tc.cc; u64 frac, maxsec, ns; @@ -495,7 +501,7 @@ static void cpts_calc_mult_shift(struct cpts *cpts) /* Calc the maximum number of seconds which we can run before * wrapping around. */ - maxsec = cc->mask; + maxsec = mask; do_div(maxsec, freq); /* limit conversation rate to 10 sec as higher values will produce * too small mult factors and so reduce the conversion accuracy @@ -508,18 +514,18 @@ static void cpts_calc_mult_shift(struct cpts *cpts) dev_info(cpts->dev, "cpts: overflow check period %lu (jiffies)\n", cpts->ov_check_period); - if (cc->mult || cc->shift) + if (*mult || *shift) return; - clocks_calc_mult_shift(&cc->mult, &cc->shift, + clocks_calc_mult_shift(mult, shift, freq, NSEC_PER_SEC, maxsec); frac = 0; - ns = cyclecounter_cyc2ns(cc, freq, cc->mask, &frac); + ns = cyclecounter_cyc2ns(cc, freq, mask, &frac); dev_info(cpts->dev, "CPTS: ref_clk_freq:%u calc_mult:%u calc_shift:%u error:%lld nsec/sec\n", - freq, cc->mult, cc->shift, + freq, *mult, *shift, (ns - NSEC_PER_SEC)); } @@ -571,15 +577,14 @@ struct cpts *cpts_create(struct device *dev, void __iomem *regs, clk_prepare(cpts->refclk); - cpts->tc.cc.read = cpts_systim_read; - cpts->tc.cc.mask = CLOCKSOURCE_MASK(32); + cpts->mask = CLOCKSOURCE_MASK(32); cpts->info = cpts_info; - cpts_calc_mult_shift(cpts); - /* save tc.cc.mult original value as it can be modified + cpts_calc_mult_shift(cpts, cpts->mask, &cpts->mult, &cpts->shift); + /* save mult original value as it can be modified * by cpts_ptp_adjfreq(). */ - cpts->cc_mult = cpts->tc.cc.mult; + cpts->cc_mult = cpts->mult; return cpts; } diff --git a/drivers/net/ethernet/ti/cpts.h b/drivers/net/ethernet/ti/cpts.h index a7174eb..da50d34 100644 --- a/drivers/net/ethernet/ti/cpts.h +++ b/drivers/net/ethernet/ti/cpts.h @@ -118,6 +118,9 @@ struct cpts { spinlock_t lock; /* protects time registers */ u32 cc_mult; /* for the nominal frequency */ struct timecounter tc; + u64 mask; + u32 mult; + u32 shift; int phc_index; struct clk *refclk; struct list_head events; -- 1.9.1