pps-ktimer.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * pps-ktimer.c -- kernel timer test client
  4. *
  5. * Copyright (C) 2005-2006 Rodolfo Giometti <giometti@linux.it>
  6. */
  7. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  8. #include <linux/kernel.h>
  9. #include <linux/module.h>
  10. #include <linux/init.h>
  11. #include <linux/time.h>
  12. #include <linux/timer.h>
  13. #include <linux/pps_kernel.h>
  14. /*
  15. * Global variables
  16. */
  17. static struct pps_device *pps;
  18. static struct timer_list ktimer;
  19. /*
  20. * The kernel timer
  21. */
  22. static void pps_ktimer_event(struct timer_list *unused)
  23. {
  24. struct pps_event_time ts;
  25. /* First of all we get the time stamp... */
  26. pps_get_ts(&ts);
  27. pps_event(pps, &ts, PPS_CAPTUREASSERT, NULL);
  28. mod_timer(&ktimer, jiffies + HZ);
  29. }
  30. /*
  31. * The PPS info struct
  32. */
  33. static struct pps_source_info pps_ktimer_info = {
  34. .name = "ktimer",
  35. .path = "",
  36. .mode = PPS_CAPTUREASSERT | PPS_OFFSETASSERT |
  37. PPS_ECHOASSERT |
  38. PPS_CANWAIT | PPS_TSFMT_TSPEC,
  39. .owner = THIS_MODULE,
  40. };
  41. /*
  42. * Module staff
  43. */
  44. static void __exit pps_ktimer_exit(void)
  45. {
  46. dev_info(pps->dev, "ktimer PPS source unregistered\n");
  47. del_timer_sync(&ktimer);
  48. pps_unregister_source(pps);
  49. }
  50. static int __init pps_ktimer_init(void)
  51. {
  52. pps = pps_register_source(&pps_ktimer_info,
  53. PPS_CAPTUREASSERT | PPS_OFFSETASSERT);
  54. if (IS_ERR(pps)) {
  55. pr_err("cannot register PPS source\n");
  56. return PTR_ERR(pps);
  57. }
  58. timer_setup(&ktimer, pps_ktimer_event, 0);
  59. mod_timer(&ktimer, jiffies + HZ);
  60. dev_info(pps->dev, "ktimer PPS source registered\n");
  61. return 0;
  62. }
  63. module_init(pps_ktimer_init);
  64. module_exit(pps_ktimer_exit);
  65. MODULE_AUTHOR("Rodolfo Giometti <giometti@linux.it>");
  66. MODULE_DESCRIPTION("dummy PPS source by using a kernel timer (just for debug)");
  67. MODULE_LICENSE("GPL");