• Home
  • Raw
  • Download

Lines Matching refs:cpts

49 static int cpts_fifo_pop(struct cpts *cpts, u32 *high, u32 *low)  in cpts_fifo_pop()  argument
51 u32 r = cpts_read32(cpts, intstat_raw); in cpts_fifo_pop()
54 *high = cpts_read32(cpts, event_high); in cpts_fifo_pop()
55 *low = cpts_read32(cpts, event_low); in cpts_fifo_pop()
56 cpts_write32(cpts, EVENT_POP, event_pop); in cpts_fifo_pop()
65 static int cpts_fifo_read(struct cpts *cpts, int match) in cpts_fifo_read() argument
72 if (cpts_fifo_pop(cpts, &hi, &lo)) in cpts_fifo_read()
74 if (list_empty(&cpts->pool)) { in cpts_fifo_read()
78 event = list_first_entry(&cpts->pool, struct cpts_event, list); in cpts_fifo_read()
88 list_add_tail(&event->list, &cpts->events); in cpts_fifo_read()
109 struct cpts *cpts = container_of(cc, struct cpts, cc); in cpts_systim_read() local
111 cpts_write32(cpts, TS_PUSH, ts_push); in cpts_systim_read()
112 if (cpts_fifo_read(cpts, CPTS_EV_PUSH)) in cpts_systim_read()
115 list_for_each_safe(this, next, &cpts->events) { in cpts_systim_read()
119 list_add(&event->list, &cpts->pool); in cpts_systim_read()
136 struct cpts *cpts = container_of(ptp, struct cpts, info); in cpts_ptp_adjfreq() local
142 mult = cpts->cc_mult; in cpts_ptp_adjfreq()
147 spin_lock_irqsave(&cpts->lock, flags); in cpts_ptp_adjfreq()
149 timecounter_read(&cpts->tc); in cpts_ptp_adjfreq()
151 cpts->cc.mult = neg_adj ? mult - diff : mult + diff; in cpts_ptp_adjfreq()
153 spin_unlock_irqrestore(&cpts->lock, flags); in cpts_ptp_adjfreq()
161 struct cpts *cpts = container_of(ptp, struct cpts, info); in cpts_ptp_adjtime() local
163 spin_lock_irqsave(&cpts->lock, flags); in cpts_ptp_adjtime()
164 timecounter_adjtime(&cpts->tc, delta); in cpts_ptp_adjtime()
165 spin_unlock_irqrestore(&cpts->lock, flags); in cpts_ptp_adjtime()
174 struct cpts *cpts = container_of(ptp, struct cpts, info); in cpts_ptp_gettime() local
176 spin_lock_irqsave(&cpts->lock, flags); in cpts_ptp_gettime()
177 ns = timecounter_read(&cpts->tc); in cpts_ptp_gettime()
178 spin_unlock_irqrestore(&cpts->lock, flags); in cpts_ptp_gettime()
190 struct cpts *cpts = container_of(ptp, struct cpts, info); in cpts_ptp_settime() local
194 spin_lock_irqsave(&cpts->lock, flags); in cpts_ptp_settime()
195 timecounter_init(&cpts->tc, &cpts->cc, ns); in cpts_ptp_settime()
196 spin_unlock_irqrestore(&cpts->lock, flags); in cpts_ptp_settime()
224 struct cpts *cpts = container_of(work, struct cpts, overflow_work.work); in cpts_overflow_check() local
226 cpts_write32(cpts, CPTS_EN, control); in cpts_overflow_check()
227 cpts_write32(cpts, TS_PEND_EN, int_enable); in cpts_overflow_check()
228 cpts_ptp_gettime(&cpts->info, &ts); in cpts_overflow_check()
230 schedule_delayed_work(&cpts->overflow_work, CPTS_OVERFLOW_PERIOD); in cpts_overflow_check()
233 static void cpts_clk_init(struct device *dev, struct cpts *cpts) in cpts_clk_init() argument
235 cpts->refclk = devm_clk_get(dev, "cpts"); in cpts_clk_init()
236 if (IS_ERR(cpts->refclk)) { in cpts_clk_init()
238 cpts->refclk = NULL; in cpts_clk_init()
241 clk_prepare_enable(cpts->refclk); in cpts_clk_init()
244 static void cpts_clk_release(struct cpts *cpts) in cpts_clk_release() argument
246 clk_disable(cpts->refclk); in cpts_clk_release()
286 static u64 cpts_find_ts(struct cpts *cpts, struct sk_buff *skb, int ev_type) in cpts_find_ts() argument
299 spin_lock_irqsave(&cpts->lock, flags); in cpts_find_ts()
300 cpts_fifo_read(cpts, CPTS_EV_PUSH); in cpts_find_ts()
301 list_for_each_safe(this, next, &cpts->events) { in cpts_find_ts()
305 list_add(&event->list, &cpts->pool); in cpts_find_ts()
312 ns = timecounter_cyc2time(&cpts->tc, event->low); in cpts_find_ts()
314 list_add(&event->list, &cpts->pool); in cpts_find_ts()
318 spin_unlock_irqrestore(&cpts->lock, flags); in cpts_find_ts()
323 void cpts_rx_timestamp(struct cpts *cpts, struct sk_buff *skb) in cpts_rx_timestamp() argument
328 if (!cpts->rx_enable) in cpts_rx_timestamp()
330 ns = cpts_find_ts(cpts, skb, CPTS_EV_RX); in cpts_rx_timestamp()
338 void cpts_tx_timestamp(struct cpts *cpts, struct sk_buff *skb) in cpts_tx_timestamp() argument
345 ns = cpts_find_ts(cpts, skb, CPTS_EV_TX); in cpts_tx_timestamp()
355 int cpts_register(struct device *dev, struct cpts *cpts, in cpts_register() argument
362 cpts->info = cpts_info; in cpts_register()
363 cpts->clock = ptp_clock_register(&cpts->info, dev); in cpts_register()
364 if (IS_ERR(cpts->clock)) { in cpts_register()
365 err = PTR_ERR(cpts->clock); in cpts_register()
366 cpts->clock = NULL; in cpts_register()
369 spin_lock_init(&cpts->lock); in cpts_register()
371 cpts->cc.read = cpts_systim_read; in cpts_register()
372 cpts->cc.mask = CLOCKSOURCE_MASK(32); in cpts_register()
373 cpts->cc_mult = mult; in cpts_register()
374 cpts->cc.mult = mult; in cpts_register()
375 cpts->cc.shift = shift; in cpts_register()
377 INIT_LIST_HEAD(&cpts->events); in cpts_register()
378 INIT_LIST_HEAD(&cpts->pool); in cpts_register()
380 list_add(&cpts->pool_data[i].list, &cpts->pool); in cpts_register()
382 cpts_clk_init(dev, cpts); in cpts_register()
383 cpts_write32(cpts, CPTS_EN, control); in cpts_register()
384 cpts_write32(cpts, TS_PEND_EN, int_enable); in cpts_register()
386 spin_lock_irqsave(&cpts->lock, flags); in cpts_register()
387 timecounter_init(&cpts->tc, &cpts->cc, ktime_to_ns(ktime_get_real())); in cpts_register()
388 spin_unlock_irqrestore(&cpts->lock, flags); in cpts_register()
390 INIT_DELAYED_WORK(&cpts->overflow_work, cpts_overflow_check); in cpts_register()
391 schedule_delayed_work(&cpts->overflow_work, CPTS_OVERFLOW_PERIOD); in cpts_register()
393 cpts->phc_index = ptp_clock_index(cpts->clock); in cpts_register()
398 void cpts_unregister(struct cpts *cpts) in cpts_unregister() argument
401 if (cpts->clock) { in cpts_unregister()
402 ptp_clock_unregister(cpts->clock); in cpts_unregister()
403 cancel_delayed_work_sync(&cpts->overflow_work); in cpts_unregister()
405 if (cpts->refclk) in cpts_unregister()
406 cpts_clk_release(cpts); in cpts_unregister()