timestamp.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. #include <linux/module.h>
  2. #include <mach/am_regs.h>
  3. static s32 system_time_inc_adj = 0;
  4. static u32 system_time = 0;
  5. static u32 system_time_up = 0;
  6. static u32 audio_pts_up = 0;
  7. #ifdef MODIFY_TIMESTAMP_INC_WITH_PLL
  8. #define PLL_FACTOR 10000
  9. static u32 timestamp_inc_factor=PLL_FACTOR;
  10. void set_timestamp_inc_factor(u32 factor)
  11. {
  12. timestamp_inc_factor = factor;
  13. }
  14. #endif
  15. u32 timestamp_vpts_get(void)
  16. {
  17. return READ_MPEG_REG(VIDEO_PTS);
  18. }
  19. EXPORT_SYMBOL(timestamp_vpts_get);
  20. void timestamp_vpts_set(u32 pts)
  21. {
  22. WRITE_MPEG_REG(VIDEO_PTS, pts);
  23. }
  24. EXPORT_SYMBOL(timestamp_vpts_set);
  25. void timestamp_vpts_inc(s32 val)
  26. {
  27. WRITE_MPEG_REG(VIDEO_PTS, READ_MPEG_REG(VIDEO_PTS) + val);
  28. }
  29. EXPORT_SYMBOL(timestamp_vpts_inc);
  30. u32 timestamp_apts_get(void)
  31. {
  32. return READ_MPEG_REG(AUDIO_PTS);
  33. }
  34. EXPORT_SYMBOL(timestamp_apts_get);
  35. void timestamp_apts_set(u32 pts)
  36. {
  37. WRITE_MPEG_REG(AUDIO_PTS, pts);
  38. }
  39. EXPORT_SYMBOL(timestamp_apts_set);
  40. void timestamp_apts_inc(s32 inc)
  41. {
  42. if(audio_pts_up){
  43. #ifdef MODIFY_TIMESTAMP_INC_WITH_PLL
  44. inc = inc*timestamp_inc_factor/PLL_FACTOR;
  45. #endif
  46. WRITE_MPEG_REG(AUDIO_PTS, READ_MPEG_REG(AUDIO_PTS) + inc);
  47. }
  48. }
  49. EXPORT_SYMBOL(timestamp_apts_inc);
  50. void timestamp_apts_enable(u32 enable)
  51. {
  52. audio_pts_up = enable;
  53. }
  54. EXPORT_SYMBOL(timestamp_apts_enable);
  55. u32 timestamp_pcrscr_get(void)
  56. {
  57. return system_time;
  58. }
  59. EXPORT_SYMBOL(timestamp_pcrscr_get);
  60. void timestamp_pcrscr_set(u32 pts)
  61. {
  62. system_time = pts;
  63. }
  64. EXPORT_SYMBOL(timestamp_pcrscr_set);
  65. void timestamp_pcrscr_inc(s32 inc)
  66. {
  67. if (system_time_up) {
  68. #ifdef MODIFY_TIMESTAMP_INC_WITH_PLL
  69. inc = inc*timestamp_inc_factor/PLL_FACTOR;
  70. #endif
  71. system_time += inc + system_time_inc_adj;
  72. }
  73. }
  74. EXPORT_SYMBOL(timestamp_pcrscr_inc);
  75. void timestamp_pcrscr_set_adj(s32 inc)
  76. {
  77. system_time_inc_adj = inc;
  78. }
  79. EXPORT_SYMBOL(timestamp_pcrscr_set_adj);
  80. void timestamp_pcrscr_enable(u32 enable)
  81. {
  82. system_time_up = enable;
  83. }
  84. EXPORT_SYMBOL(timestamp_pcrscr_enable);
  85. u32 timestamp_pcrscr_enable_state(void)
  86. {
  87. return system_time_up;
  88. }
  89. EXPORT_SYMBOL(timestamp_pcrscr_enable_state);
  90. MODULE_DESCRIPTION("AMLOGIC time sync management driver");
  91. MODULE_LICENSE("GPL");
  92. MODULE_AUTHOR("Tim Yao <timyao@amlogic.com>");