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