timer.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. #ifndef __SOUND_TIMER_H
  3. #define __SOUND_TIMER_H
  4. /*
  5. * Timer abstract layer
  6. * Copyright (c) by Jaroslav Kysela <[email protected]>,
  7. * Abramo Bagnara <[email protected]>
  8. */
  9. #include <sound/asound.h>
  10. #include <linux/interrupt.h>
  11. #include <linux/android_kabi.h>
  12. #define snd_timer_chip(timer) ((timer)->private_data)
  13. #define SNDRV_TIMER_DEVICES 16
  14. #define SNDRV_TIMER_DEV_FLG_PCM 0x10000000
  15. #define SNDRV_TIMER_HW_AUTO 0x00000001 /* auto trigger is supported */
  16. #define SNDRV_TIMER_HW_STOP 0x00000002 /* call stop before start */
  17. #define SNDRV_TIMER_HW_SLAVE 0x00000004 /* only slave timer (variable resolution) */
  18. #define SNDRV_TIMER_HW_FIRST 0x00000008 /* first tick can be incomplete */
  19. #define SNDRV_TIMER_HW_WORK 0x00000010 /* timer is called from work */
  20. #define SNDRV_TIMER_IFLG_SLAVE 0x00000001
  21. #define SNDRV_TIMER_IFLG_RUNNING 0x00000002
  22. #define SNDRV_TIMER_IFLG_START 0x00000004
  23. #define SNDRV_TIMER_IFLG_AUTO 0x00000008 /* auto restart */
  24. #define SNDRV_TIMER_IFLG_FAST 0x00000010 /* fast callback (do not use work) */
  25. #define SNDRV_TIMER_IFLG_CALLBACK 0x00000020 /* timer callback is active */
  26. #define SNDRV_TIMER_IFLG_EXCLUSIVE 0x00000040 /* exclusive owner - no more instances */
  27. #define SNDRV_TIMER_IFLG_EARLY_EVENT 0x00000080 /* write early event to the poll queue */
  28. #define SNDRV_TIMER_FLG_CHANGE 0x00000001
  29. #define SNDRV_TIMER_FLG_RESCHED 0x00000002 /* need reschedule */
  30. struct snd_timer;
  31. struct snd_timer_hardware {
  32. /* -- must be filled with low-level driver */
  33. unsigned int flags; /* various flags */
  34. unsigned long resolution; /* average timer resolution for one tick in nsec */
  35. unsigned long resolution_min; /* minimal resolution */
  36. unsigned long resolution_max; /* maximal resolution */
  37. unsigned long ticks; /* max timer ticks per interrupt */
  38. /* -- low-level functions -- */
  39. int (*open) (struct snd_timer * timer);
  40. int (*close) (struct snd_timer * timer);
  41. unsigned long (*c_resolution) (struct snd_timer * timer);
  42. int (*start) (struct snd_timer * timer);
  43. int (*stop) (struct snd_timer * timer);
  44. int (*set_period) (struct snd_timer * timer, unsigned long period_num, unsigned long period_den);
  45. int (*precise_resolution) (struct snd_timer * timer, unsigned long *num, unsigned long *den);
  46. ANDROID_KABI_RESERVE(1);
  47. };
  48. struct snd_timer {
  49. int tmr_class;
  50. struct snd_card *card;
  51. struct module *module;
  52. int tmr_device;
  53. int tmr_subdevice;
  54. char id[64];
  55. char name[80];
  56. unsigned int flags;
  57. int running; /* running instances */
  58. unsigned long sticks; /* schedule ticks */
  59. void *private_data;
  60. void (*private_free) (struct snd_timer *timer);
  61. struct snd_timer_hardware hw;
  62. spinlock_t lock;
  63. struct list_head device_list;
  64. struct list_head open_list_head;
  65. struct list_head active_list_head;
  66. struct list_head ack_list_head;
  67. struct list_head sack_list_head; /* slow ack list head */
  68. struct work_struct task_work;
  69. int max_instances; /* upper limit of timer instances */
  70. int num_instances; /* current number of timer instances */
  71. ANDROID_KABI_RESERVE(1);
  72. };
  73. struct snd_timer_instance {
  74. struct snd_timer *timer;
  75. char *owner;
  76. unsigned int flags;
  77. void *private_data;
  78. void (*private_free) (struct snd_timer_instance *ti);
  79. void (*callback) (struct snd_timer_instance *timeri,
  80. unsigned long ticks, unsigned long resolution);
  81. void (*ccallback) (struct snd_timer_instance * timeri,
  82. int event,
  83. struct timespec64 * tstamp,
  84. unsigned long resolution);
  85. void (*disconnect)(struct snd_timer_instance *timeri);
  86. void *callback_data;
  87. unsigned long ticks; /* auto-load ticks when expired */
  88. unsigned long cticks; /* current ticks */
  89. unsigned long pticks; /* accumulated ticks for callback */
  90. unsigned long resolution; /* current resolution for work */
  91. unsigned long lost; /* lost ticks */
  92. int slave_class;
  93. unsigned int slave_id;
  94. struct list_head open_list;
  95. struct list_head active_list;
  96. struct list_head ack_list;
  97. struct list_head slave_list_head;
  98. struct list_head slave_active_head;
  99. struct snd_timer_instance *master;
  100. ANDROID_KABI_RESERVE(1);
  101. };
  102. /*
  103. * Registering
  104. */
  105. int snd_timer_new(struct snd_card *card, char *id, struct snd_timer_id *tid, struct snd_timer **rtimer);
  106. void snd_timer_notify(struct snd_timer *timer, int event, struct timespec64 *tstamp);
  107. int snd_timer_global_new(char *id, int device, struct snd_timer **rtimer);
  108. int snd_timer_global_free(struct snd_timer *timer);
  109. int snd_timer_global_register(struct snd_timer *timer);
  110. struct snd_timer_instance *snd_timer_instance_new(const char *owner);
  111. void snd_timer_instance_free(struct snd_timer_instance *timeri);
  112. int snd_timer_open(struct snd_timer_instance *timeri, struct snd_timer_id *tid, unsigned int slave_id);
  113. void snd_timer_close(struct snd_timer_instance *timeri);
  114. unsigned long snd_timer_resolution(struct snd_timer_instance *timeri);
  115. int snd_timer_start(struct snd_timer_instance *timeri, unsigned int ticks);
  116. int snd_timer_stop(struct snd_timer_instance *timeri);
  117. int snd_timer_continue(struct snd_timer_instance *timeri);
  118. int snd_timer_pause(struct snd_timer_instance *timeri);
  119. void snd_timer_interrupt(struct snd_timer *timer, unsigned long ticks_left);
  120. #endif /* __SOUND_TIMER_H */