Thomas Gleixner | 1a59d1b8 | 2019-05-27 08:55:05 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | #ifndef __SOUND_TIMER_H |
| 3 | #define __SOUND_TIMER_H |
| 4 | |
| 5 | /* |
| 6 | * Timer abstract layer |
Jaroslav Kysela | c1017a4 | 2007-10-15 09:50:19 +0200 | [diff] [blame] | 7 | * Copyright (c) by Jaroslav Kysela <perex@perex.cz>, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | * Abramo Bagnara <abramo@alsa-project.org> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #include <sound/asound.h> |
| 12 | #include <linux/interrupt.h> |
| 13 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 /* auto trigger is supported */ |
| 21 | #define SNDRV_TIMER_HW_STOP 0x00000002 /* call stop before start */ |
| 22 | #define SNDRV_TIMER_HW_SLAVE 0x00000004 /* only slave timer (variable resolution) */ |
| 23 | #define SNDRV_TIMER_HW_FIRST 0x00000008 /* first tick can be incomplete */ |
Takashi Iwai | bf08359 | 2020-09-03 12:41:22 +0200 | [diff] [blame] | 24 | #define SNDRV_TIMER_HW_WORK 0x00000010 /* timer is called from work */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 /* auto restart */ |
Takashi Iwai | bf08359 | 2020-09-03 12:41:22 +0200 | [diff] [blame] | 30 | #define SNDRV_TIMER_IFLG_FAST 0x00000010 /* fast callback (do not use work) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #define SNDRV_TIMER_IFLG_CALLBACK 0x00000020 /* timer callback is active */ |
| 32 | #define SNDRV_TIMER_IFLG_EXCLUSIVE 0x00000040 /* exclusive owner - no more instances */ |
| 33 | #define SNDRV_TIMER_IFLG_EARLY_EVENT 0x00000080 /* write early event to the poll queue */ |
| 34 | |
| 35 | #define SNDRV_TIMER_FLG_CHANGE 0x00000001 |
| 36 | #define SNDRV_TIMER_FLG_RESCHED 0x00000002 /* need reschedule */ |
| 37 | |
Takashi Iwai | 53d2f74 | 2005-11-17 13:56:05 +0100 | [diff] [blame] | 38 | struct snd_timer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | |
Takashi Iwai | 53d2f74 | 2005-11-17 13:56:05 +0100 | [diff] [blame] | 40 | struct snd_timer_hardware { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | /* -- must be filled with low-level driver */ |
| 42 | unsigned int flags; /* various flags */ |
| 43 | unsigned long resolution; /* average timer resolution for one tick in nsec */ |
| 44 | unsigned long resolution_min; /* minimal resolution */ |
| 45 | unsigned long resolution_max; /* maximal resolution */ |
| 46 | unsigned long ticks; /* max timer ticks per interrupt */ |
| 47 | /* -- low-level functions -- */ |
Takashi Iwai | 53d2f74 | 2005-11-17 13:56:05 +0100 | [diff] [blame] | 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); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | }; |
| 56 | |
Takashi Iwai | 53d2f74 | 2005-11-17 13:56:05 +0100 | [diff] [blame] | 57 | struct snd_timer { |
| 58 | int tmr_class; |
| 59 | struct snd_card *card; |
Clemens Ladisch | de24214 | 2005-10-12 17:12:31 +0200 | [diff] [blame] | 60 | struct module *module; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | int tmr_device; |
| 62 | int tmr_subdevice; |
| 63 | char id[64]; |
| 64 | char name[80]; |
| 65 | unsigned int flags; |
| 66 | int running; /* running instances */ |
| 67 | unsigned long sticks; /* schedule ticks */ |
| 68 | void *private_data; |
Takashi Iwai | 53d2f74 | 2005-11-17 13:56:05 +0100 | [diff] [blame] | 69 | void (*private_free) (struct snd_timer *timer); |
| 70 | struct snd_timer_hardware hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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; /* slow ack list head */ |
Takashi Iwai | bf08359 | 2020-09-03 12:41:22 +0200 | [diff] [blame] | 77 | struct work_struct task_work; |
Takashi Iwai | 9b7d869 | 2017-11-05 10:07:43 +0100 | [diff] [blame] | 78 | int max_instances; /* upper limit of timer instances */ |
| 79 | int num_instances; /* current number of timer instances */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | }; |
| 81 | |
Takashi Iwai | 53d2f74 | 2005-11-17 13:56:05 +0100 | [diff] [blame] | 82 | struct snd_timer_instance { |
| 83 | struct snd_timer *timer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | char *owner; |
| 85 | unsigned int flags; |
| 86 | void *private_data; |
Takashi Iwai | 53d2f74 | 2005-11-17 13:56:05 +0100 | [diff] [blame] | 87 | void (*private_free) (struct snd_timer_instance *ti); |
| 88 | void (*callback) (struct snd_timer_instance *timeri, |
| 89 | unsigned long ticks, unsigned long resolution); |
| 90 | void (*ccallback) (struct snd_timer_instance * timeri, |
| 91 | int event, |
Baolin Wang | fcae40c | 2018-04-24 20:06:08 +0800 | [diff] [blame] | 92 | struct timespec64 * tstamp, |
Takashi Iwai | 53d2f74 | 2005-11-17 13:56:05 +0100 | [diff] [blame] | 93 | unsigned long resolution); |
Takashi Iwai | 40ed944 | 2016-01-21 17:43:08 +0100 | [diff] [blame] | 94 | void (*disconnect)(struct snd_timer_instance *timeri); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | void *callback_data; |
| 96 | unsigned long ticks; /* auto-load ticks when expired */ |
| 97 | unsigned long cticks; /* current ticks */ |
| 98 | unsigned long pticks; /* accumulated ticks for callback */ |
Takashi Iwai | bf08359 | 2020-09-03 12:41:22 +0200 | [diff] [blame] | 99 | unsigned long resolution; /* current resolution for work */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | unsigned long lost; /* lost ticks */ |
Takashi Iwai | 53d2f74 | 2005-11-17 13:56:05 +0100 | [diff] [blame] | 101 | int slave_class; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | unsigned int slave_id; |
| 103 | struct list_head open_list; |
| 104 | struct list_head active_list; |
| 105 | struct list_head ack_list; |
| 106 | struct list_head slave_list_head; |
| 107 | struct list_head slave_active_head; |
Takashi Iwai | 53d2f74 | 2005-11-17 13:56:05 +0100 | [diff] [blame] | 108 | struct snd_timer_instance *master; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | }; |
| 110 | |
| 111 | /* |
| 112 | * Registering |
| 113 | */ |
| 114 | |
Takashi Iwai | 53d2f74 | 2005-11-17 13:56:05 +0100 | [diff] [blame] | 115 | int snd_timer_new(struct snd_card *card, char *id, struct snd_timer_id *tid, struct snd_timer **rtimer); |
Baolin Wang | fcae40c | 2018-04-24 20:06:08 +0800 | [diff] [blame] | 116 | void snd_timer_notify(struct snd_timer *timer, int event, struct timespec64 *tstamp); |
Takashi Iwai | 53d2f74 | 2005-11-17 13:56:05 +0100 | [diff] [blame] | 117 | int snd_timer_global_new(char *id, int device, struct snd_timer **rtimer); |
| 118 | int snd_timer_global_free(struct snd_timer *timer); |
| 119 | int snd_timer_global_register(struct snd_timer *timer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | |
Takashi Iwai | 6a34367 | 2019-11-07 20:20:08 +0100 | [diff] [blame] | 121 | struct snd_timer_instance *snd_timer_instance_new(const char *owner); |
| 122 | void snd_timer_instance_free(struct snd_timer_instance *timeri); |
| 123 | int snd_timer_open(struct snd_timer_instance *timeri, struct snd_timer_id *tid, unsigned int slave_id); |
Takashi Iwai | 33bbb8a | 2019-11-07 20:20:07 +0100 | [diff] [blame] | 124 | void snd_timer_close(struct snd_timer_instance *timeri); |
Takashi Iwai | 53d2f74 | 2005-11-17 13:56:05 +0100 | [diff] [blame] | 125 | unsigned long snd_timer_resolution(struct snd_timer_instance *timeri); |
| 126 | int snd_timer_start(struct snd_timer_instance *timeri, unsigned int ticks); |
| 127 | int snd_timer_stop(struct snd_timer_instance *timeri); |
| 128 | int snd_timer_continue(struct snd_timer_instance *timeri); |
| 129 | int snd_timer_pause(struct snd_timer_instance *timeri); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | |
Takashi Iwai | 53d2f74 | 2005-11-17 13:56:05 +0100 | [diff] [blame] | 131 | void snd_timer_interrupt(struct snd_timer *timer, unsigned long ticks_left); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | #endif /* __SOUND_TIMER_H */ |