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