Lines Matching +full:clock +full:- +full:mult

1 // SPDX-License-Identifier: GPL-2.0
4 // Marc Kleine-Budde <kernel@pengutronix.de>
24 ns = timecounter_cyc2time(&priv->tc, timestamp); in rkcanfd_skb_set_timestamp()
26 hwtstamps->hwtstamp = ns_to_ktime(ns); in rkcanfd_skb_set_timestamp()
35 timecounter_read(&priv->tc); in rkcanfd_timestamp_work()
37 schedule_delayed_work(&priv->timestamp, priv->work_delay_jiffies); in rkcanfd_timestamp_work()
42 const struct can_bittiming *dbt = &priv->can.data_bittiming; in rkcanfd_timestamp_init()
43 const struct can_bittiming *bt = &priv->can.bittiming; in rkcanfd_timestamp_init()
44 struct cyclecounter *cc = &priv->cc; in rkcanfd_timestamp_init()
49 /* At the standard clock rate of 300Mhz on the rk3658, the 32 in rkcanfd_timestamp_init()
56 bitrate = max(bt->bitrate, dbt->bitrate); in rkcanfd_timestamp_init()
57 div = min(DIV_ROUND_UP(priv->can.clock.freq, bitrate * 2), in rkcanfd_timestamp_init()
61 div - 1) | in rkcanfd_timestamp_init()
65 cc->read = rkcanfd_timestamp_read; in rkcanfd_timestamp_init()
66 cc->mask = CYCLECOUNTER_MASK(32); in rkcanfd_timestamp_init()
68 rate = priv->can.clock.freq / div; in rkcanfd_timestamp_init()
69 clocks_calc_mult_shift(&cc->mult, &cc->shift, rate, NSEC_PER_SEC, in rkcanfd_timestamp_init()
72 max_cycles = div_u64(ULLONG_MAX, cc->mult); in rkcanfd_timestamp_init()
73 max_cycles = min(max_cycles, cc->mask); in rkcanfd_timestamp_init()
74 work_delay_ns = clocksource_cyc2ns(max_cycles, cc->mult, cc->shift); in rkcanfd_timestamp_init()
75 priv->work_delay_jiffies = div_u64(work_delay_ns, 3u * NSEC_PER_SEC / HZ); in rkcanfd_timestamp_init()
76 INIT_DELAYED_WORK(&priv->timestamp, rkcanfd_timestamp_work); in rkcanfd_timestamp_init()
78 …netdev_dbg(priv->ndev, "clock=%lu.%02luMHz bitrate=%lu.%02luMBit/s div=%u rate=%lu.%02luMHz mult=%… in rkcanfd_timestamp_init()
79 priv->can.clock.freq / MEGA, in rkcanfd_timestamp_init()
80 priv->can.clock.freq % MEGA / KILO / 10, in rkcanfd_timestamp_init()
86 cc->mult, cc->shift, in rkcanfd_timestamp_init()
87 priv->work_delay_jiffies / HZ); in rkcanfd_timestamp_init()
92 timecounter_init(&priv->tc, &priv->cc, ktime_get_real_ns()); in rkcanfd_timestamp_start()
94 schedule_delayed_work(&priv->timestamp, priv->work_delay_jiffies); in rkcanfd_timestamp_start()
99 cancel_delayed_work(&priv->timestamp); in rkcanfd_timestamp_stop()
104 cancel_delayed_work_sync(&priv->timestamp); in rkcanfd_timestamp_stop_sync()