cpts.c (391fd6caf5cfc74a15a79c1237de0a2d84dfd398) | cpts.c (c8395d4e1d4ffbc9d8aa61f534c82e8deed72cfd) |
---|---|
1/* 2 * TI Common Platform Time Sync 3 * 4 * Copyright (C) 2012 Richard Cochran <richardcochran@gmail.com> 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; either version 2 of the License, or --- 17 unchanged lines hidden (view full) --- 26#include <linux/time.h> 27#include <linux/uaccess.h> 28#include <linux/workqueue.h> 29#include <linux/if_ether.h> 30#include <linux/if_vlan.h> 31 32#include "cpts.h" 33 | 1/* 2 * TI Common Platform Time Sync 3 * 4 * Copyright (C) 2012 Richard Cochran <richardcochran@gmail.com> 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; either version 2 of the License, or --- 17 unchanged lines hidden (view full) --- 26#include <linux/time.h> 27#include <linux/uaccess.h> 28#include <linux/workqueue.h> 29#include <linux/if_ether.h> 30#include <linux/if_vlan.h> 31 32#include "cpts.h" 33 |
34#ifdef CONFIG_TI_CPTS 35 | |
36#define cpts_read32(c, r) readl_relaxed(&c->reg->r) 37#define cpts_write32(c, v, r) writel_relaxed(v, &c->reg->r) 38 39static int event_expired(struct cpts_event *event) 40{ 41 return time_after(jiffies, event->tmo); 42} 43 --- 285 unchanged lines hidden (view full) --- 329 return; 330 ns = cpts_find_ts(cpts, skb, CPTS_EV_RX); 331 if (!ns) 332 return; 333 ssh = skb_hwtstamps(skb); 334 memset(ssh, 0, sizeof(*ssh)); 335 ssh->hwtstamp = ns_to_ktime(ns); 336} | 34#define cpts_read32(c, r) readl_relaxed(&c->reg->r) 35#define cpts_write32(c, v, r) writel_relaxed(v, &c->reg->r) 36 37static int event_expired(struct cpts_event *event) 38{ 39 return time_after(jiffies, event->tmo); 40} 41 --- 285 unchanged lines hidden (view full) --- 327 return; 328 ns = cpts_find_ts(cpts, skb, CPTS_EV_RX); 329 if (!ns) 330 return; 331 ssh = skb_hwtstamps(skb); 332 memset(ssh, 0, sizeof(*ssh)); 333 ssh->hwtstamp = ns_to_ktime(ns); 334} |
335EXPORT_SYMBOL_GPL(cpts_rx_timestamp); |
|
337 338void cpts_tx_timestamp(struct cpts *cpts, struct sk_buff *skb) 339{ 340 u64 ns; 341 struct skb_shared_hwtstamps ssh; 342 343 if (!(skb_shinfo(skb)->tx_flags & SKBTX_IN_PROGRESS)) 344 return; 345 ns = cpts_find_ts(cpts, skb, CPTS_EV_TX); 346 if (!ns) 347 return; 348 memset(&ssh, 0, sizeof(ssh)); 349 ssh.hwtstamp = ns_to_ktime(ns); 350 skb_tstamp_tx(skb, &ssh); 351} | 336 337void cpts_tx_timestamp(struct cpts *cpts, struct sk_buff *skb) 338{ 339 u64 ns; 340 struct skb_shared_hwtstamps ssh; 341 342 if (!(skb_shinfo(skb)->tx_flags & SKBTX_IN_PROGRESS)) 343 return; 344 ns = cpts_find_ts(cpts, skb, CPTS_EV_TX); 345 if (!ns) 346 return; 347 memset(&ssh, 0, sizeof(ssh)); 348 ssh.hwtstamp = ns_to_ktime(ns); 349 skb_tstamp_tx(skb, &ssh); 350} |
351EXPORT_SYMBOL_GPL(cpts_tx_timestamp); |
|
352 | 352 |
353#endif /*CONFIG_TI_CPTS*/ 354 | |
355int cpts_register(struct device *dev, struct cpts *cpts, 356 u32 mult, u32 shift) 357{ | 353int cpts_register(struct device *dev, struct cpts *cpts, 354 u32 mult, u32 shift) 355{ |
358#ifdef CONFIG_TI_CPTS | |
359 int err, i; 360 unsigned long flags; 361 362 cpts->info = cpts_info; 363 cpts->clock = ptp_clock_register(&cpts->info, dev); 364 if (IS_ERR(cpts->clock)) { 365 err = PTR_ERR(cpts->clock); 366 cpts->clock = NULL; --- 19 unchanged lines hidden (view full) --- 386 spin_lock_irqsave(&cpts->lock, flags); 387 timecounter_init(&cpts->tc, &cpts->cc, ktime_to_ns(ktime_get_real())); 388 spin_unlock_irqrestore(&cpts->lock, flags); 389 390 INIT_DELAYED_WORK(&cpts->overflow_work, cpts_overflow_check); 391 schedule_delayed_work(&cpts->overflow_work, CPTS_OVERFLOW_PERIOD); 392 393 cpts->phc_index = ptp_clock_index(cpts->clock); | 356 int err, i; 357 unsigned long flags; 358 359 cpts->info = cpts_info; 360 cpts->clock = ptp_clock_register(&cpts->info, dev); 361 if (IS_ERR(cpts->clock)) { 362 err = PTR_ERR(cpts->clock); 363 cpts->clock = NULL; --- 19 unchanged lines hidden (view full) --- 383 spin_lock_irqsave(&cpts->lock, flags); 384 timecounter_init(&cpts->tc, &cpts->cc, ktime_to_ns(ktime_get_real())); 385 spin_unlock_irqrestore(&cpts->lock, flags); 386 387 INIT_DELAYED_WORK(&cpts->overflow_work, cpts_overflow_check); 388 schedule_delayed_work(&cpts->overflow_work, CPTS_OVERFLOW_PERIOD); 389 390 cpts->phc_index = ptp_clock_index(cpts->clock); |
394#endif | |
395 return 0; 396} | 391 return 0; 392} |
393EXPORT_SYMBOL_GPL(cpts_register); |
|
397 398void cpts_unregister(struct cpts *cpts) 399{ | 394 395void cpts_unregister(struct cpts *cpts) 396{ |
400#ifdef CONFIG_TI_CPTS | |
401 if (cpts->clock) { 402 ptp_clock_unregister(cpts->clock); 403 cancel_delayed_work_sync(&cpts->overflow_work); 404 } 405 if (cpts->refclk) 406 cpts_clk_release(cpts); | 397 if (cpts->clock) { 398 ptp_clock_unregister(cpts->clock); 399 cancel_delayed_work_sync(&cpts->overflow_work); 400 } 401 if (cpts->refclk) 402 cpts_clk_release(cpts); |
407#endif | |
408} | 403} |
404EXPORT_SYMBOL_GPL(cpts_unregister); 405 406MODULE_LICENSE("GPL v2"); 407MODULE_DESCRIPTION("TI CPTS driver"); 408MODULE_AUTHOR("Richard Cochran <richardcochran@gmail.com>"); |
|