| 1 |
|
| 2 | #ifndef __SOUND_TIMER_H
|
| 3 | #define __SOUND_TIMER_H
|
| 4 |
|
| 5 | |
| 6 | * Timer abstract layer
|
| 7 | * Copyright (c) by Jaroslav Kysela <[email protected]>,
|
| 8 | * Abramo Bagnara <[email protected]>
|
| 9 |
|
| 10 |
|
| 11 | #include <sound/asound.h>
|
| 12 | #include <linux/interrupt.h>
|
| 13 |
|
| 14 | #define snd_timer_chip(timer) ((timer)->private_data)
|
| 15 |
|
| 16 | #define SNDRV_TIMER_DEVICES 16
|
| 17 |
|
| 18 | #define SNDRV_TIMER_DEV_FLG_PCM 0x10000000
|
| 19 |
|
| 20 | #define SNDRV_TIMER_HW_AUTO 0x00000001
|
| 21 | #define SNDRV_TIMER_HW_STOP 0x00000002
|
| 22 | #define SNDRV_TIMER_HW_SLAVE 0x00000004
|
| 23 | #define SNDRV_TIMER_HW_FIRST 0x00000008
|
| 24 | #define SNDRV_TIMER_HW_WORK 0x00000010
|
| 25 |
|
| 26 | #define SNDRV_TIMER_IFLG_SLAVE 0x00000001
|
| 27 | #define SNDRV_TIMER_IFLG_RUNNING 0x00000002
|
| 28 | #define SNDRV_TIMER_IFLG_START 0x00000004
|
| 29 | #define SNDRV_TIMER_IFLG_AUTO 0x00000008
|
| 30 | #define SNDRV_TIMER_IFLG_FAST 0x00000010
|
| 31 | #define SNDRV_TIMER_IFLG_CALLBACK 0x00000020
|
| 32 | #define SNDRV_TIMER_IFLG_EXCLUSIVE 0x00000040
|
| 33 | #define SNDRV_TIMER_IFLG_EARLY_EVENT 0x00000080
|
| 34 |
|
| 35 | #define SNDRV_TIMER_FLG_CHANGE 0x00000001
|
| 36 | #define SNDRV_TIMER_FLG_RESCHED 0x00000002
|
| 37 |
|
| 38 | struct snd_timer;
|
| 39 |
|
| 40 | struct snd_timer_hardware {
|
| 41 |
|
| 42 | unsigned int flags;
|
| 43 | unsigned long resolution;
|
| 44 | unsigned long resolution_min;
|
| 45 | unsigned long resolution_max;
|
| 46 | unsigned long ticks;
|
| 47 |
|
| 48 | int (*open) (struct snd_timer * timer);
|
| 49 | int (*close) (struct snd_timer * timer);
|
| 50 | unsigned long (*c_resolution) (struct snd_timer * timer);
|
| 51 | int (*start) (struct snd_timer * timer);
|
| 52 | int (*stop) (struct snd_timer * timer);
|
| 53 | int (*set_period) (struct snd_timer * timer, unsigned long period_num, unsigned long period_den);
|
| 54 | int (*precise_resolution) (struct snd_timer * timer, unsigned long *num, unsigned long *den);
|
| 55 | };
|
| 56 |
|
| 57 | struct snd_timer {
|
| 58 | int tmr_class;
|
| 59 | struct snd_card *card;
|
| 60 | struct module *module;
|
| 61 | int tmr_device;
|
| 62 | int tmr_subdevice;
|
| 63 | char id[64];
|
| 64 | char name[80];
|
| 65 | unsigned int flags;
|
| 66 | int running;
|
| 67 | unsigned long sticks;
|
| 68 | void *private_data;
|
| 69 | void (*private_free) (struct snd_timer *timer);
|
| 70 | struct snd_timer_hardware hw;
|
| 71 | spinlock_t lock;
|
| 72 | struct list_head device_list;
|
| 73 | struct list_head open_list_head;
|
| 74 | struct list_head active_list_head;
|
| 75 | struct list_head ack_list_head;
|
| 76 | struct list_head sack_list_head;
|
| 77 | struct work_struct task_work;
|
| 78 | struct kref kref;
|
| 79 | int max_instances;
|
| 80 | int num_instances;
|
| 81 | };
|
| 82 |
|
| 83 | struct snd_timer_instance {
|
| 84 | struct snd_timer *timer;
|
| 85 | char *owner;
|
| 86 | unsigned int flags;
|
| 87 | void *private_data;
|
| 88 | void (*private_free) (struct snd_timer_instance *ti);
|
| 89 | void (*callback) (struct snd_timer_instance *timeri,
|
| 90 | unsigned long ticks, unsigned long resolution);
|
| 91 | void (*ccallback) (struct snd_timer_instance * timeri,
|
| 92 | int event,
|
| 93 | struct timespec64 * tstamp,
|
| 94 | unsigned long resolution);
|
| 95 | void (*disconnect)(struct snd_timer_instance *timeri);
|
| 96 | void *callback_data;
|
| 97 | unsigned long ticks;
|
| 98 | unsigned long cticks;
|
| 99 | unsigned long pticks;
|
| 100 | unsigned long resolution;
|
| 101 | unsigned long lost;
|
| 102 | int slave_class;
|
| 103 | unsigned int slave_id;
|
| 104 | struct list_head open_list;
|
| 105 | struct list_head active_list;
|
| 106 | struct list_head master_list;
|
| 107 | struct list_head ack_list;
|
| 108 | struct list_head slave_list_head;
|
| 109 | struct list_head slave_active_head;
|
| 110 | struct snd_timer_instance *master;
|
| 111 | };
|
| 112 |
|
| 113 | |
| 114 | * Registering
|
| 115 |
|
| 116 |
|
| 117 | int snd_timer_new(struct snd_card *card, char *id, struct snd_timer_id *tid, struct snd_timer **rtimer);
|
| 118 | void snd_timer_notify(struct snd_timer *timer, int event, struct timespec64 *tstamp);
|
| 119 | int snd_timer_global_new(char *id, int device, struct snd_timer **rtimer);
|
| 120 | int snd_timer_global_free(struct snd_timer *timer);
|
| 121 | int snd_timer_global_register(struct snd_timer *timer);
|
| 122 |
|
| 123 | struct snd_timer_instance *snd_timer_instance_new(const char *owner);
|
| 124 | void snd_timer_instance_free(struct snd_timer_instance *timeri);
|
| 125 | int snd_timer_open(struct snd_timer_instance *timeri, struct snd_timer_id *tid, unsigned int slave_id);
|
| 126 | void snd_timer_close(struct snd_timer_instance *timeri);
|
| 127 | unsigned long snd_timer_resolution(struct snd_timer_instance *timeri);
|
| 128 | int snd_timer_start(struct snd_timer_instance *timeri, unsigned int ticks);
|
| 129 | int snd_timer_stop(struct snd_timer_instance *timeri);
|
| 130 | int snd_timer_continue(struct snd_timer_instance *timeri);
|
| 131 | int snd_timer_pause(struct snd_timer_instance *timeri);
|
| 132 |
|
| 133 | void snd_timer_interrupt(struct snd_timer *timer, unsigned long ticks_left);
|
| 134 |
|
| 135 | struct snd_timer *snd_timeri_timer_get(struct snd_timer_instance *timeri);
|
| 136 | void snd_timeri_timer_put(struct snd_timer *timer);
|
| 137 |
|
| 138 | DEFINE_FREE(snd_timeri_timer, struct snd_timer *, if (_T) snd_timeri_timer_put(_T))
|
| 139 |
|
| 140 | #endif
|