[PATCH 14/27] net: cpts: Use timecounter_initialize interface
From: Sagar Arun Kamble
Date: Fri Dec 15 2017 - 02:41:03 EST
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 <sagar.a.kamble@xxxxxxxxx>
Cc: "David S. Miller" <davem@xxxxxxxxxxxxx>
Cc: Grygorii Strashko <grygorii.strashko@xxxxxx>
Cc: Richard Cochran <richardcochran@xxxxxxxxx>
Cc: Bhumika Goyal <bhumirks@xxxxxxxxx>
Cc: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
Cc: Ivan Khoronzhuk <ivan.khoronzhuk@xxxxxxxxxx>
Cc: netdev@xxxxxxxxxxxxxxx
Cc: linux-kernel@xxxxxxxxxxxxxxx
---
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