xref: /linux/include/sound/timer.h (revision c1017a4cdb68ae5368fbc9ee42c77f1f5dca8916)
11da177e4SLinus Torvalds #ifndef __SOUND_TIMER_H
21da177e4SLinus Torvalds #define __SOUND_TIMER_H
31da177e4SLinus Torvalds 
41da177e4SLinus Torvalds /*
51da177e4SLinus Torvalds  *  Timer abstract layer
6*c1017a4cSJaroslav Kysela  *  Copyright (c) by Jaroslav Kysela <perex@perex.cz>,
71da177e4SLinus Torvalds  *		     Abramo Bagnara <abramo@alsa-project.org>
81da177e4SLinus Torvalds  *
91da177e4SLinus Torvalds  *
101da177e4SLinus Torvalds  *   This program is free software; you can redistribute it and/or modify
111da177e4SLinus Torvalds  *   it under the terms of the GNU General Public License as published by
121da177e4SLinus Torvalds  *   the Free Software Foundation; either version 2 of the License, or
131da177e4SLinus Torvalds  *   (at your option) any later version.
141da177e4SLinus Torvalds  *
151da177e4SLinus Torvalds  *   This program is distributed in the hope that it will be useful,
161da177e4SLinus Torvalds  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
171da177e4SLinus Torvalds  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
181da177e4SLinus Torvalds  *   GNU General Public License for more details.
191da177e4SLinus Torvalds  *
201da177e4SLinus Torvalds  *   You should have received a copy of the GNU General Public License
211da177e4SLinus Torvalds  *   along with this program; if not, write to the Free Software
221da177e4SLinus Torvalds  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
231da177e4SLinus Torvalds  *
241da177e4SLinus Torvalds  */
251da177e4SLinus Torvalds 
261da177e4SLinus Torvalds #include <sound/asound.h>
271da177e4SLinus Torvalds #include <linux/interrupt.h>
281da177e4SLinus Torvalds 
291da177e4SLinus Torvalds #define snd_timer_chip(timer) ((timer)->private_data)
301da177e4SLinus Torvalds 
311da177e4SLinus Torvalds #define SNDRV_TIMER_DEVICES	16
321da177e4SLinus Torvalds 
331da177e4SLinus Torvalds #define SNDRV_TIMER_DEV_FLG_PCM	0x10000000
341da177e4SLinus Torvalds 
351da177e4SLinus Torvalds #define SNDRV_TIMER_HW_AUTO	0x00000001	/* auto trigger is supported */
361da177e4SLinus Torvalds #define SNDRV_TIMER_HW_STOP	0x00000002	/* call stop before start */
371da177e4SLinus Torvalds #define SNDRV_TIMER_HW_SLAVE	0x00000004	/* only slave timer (variable resolution) */
381da177e4SLinus Torvalds #define SNDRV_TIMER_HW_FIRST	0x00000008	/* first tick can be incomplete */
391da177e4SLinus Torvalds #define SNDRV_TIMER_HW_TASKLET	0x00000010	/* timer is called from tasklet */
401da177e4SLinus Torvalds 
411da177e4SLinus Torvalds #define SNDRV_TIMER_IFLG_SLAVE	  0x00000001
421da177e4SLinus Torvalds #define SNDRV_TIMER_IFLG_RUNNING  0x00000002
431da177e4SLinus Torvalds #define SNDRV_TIMER_IFLG_START	  0x00000004
441da177e4SLinus Torvalds #define SNDRV_TIMER_IFLG_AUTO	  0x00000008	/* auto restart */
451da177e4SLinus Torvalds #define SNDRV_TIMER_IFLG_FAST	  0x00000010	/* fast callback (do not use tasklet) */
461da177e4SLinus Torvalds #define SNDRV_TIMER_IFLG_CALLBACK 0x00000020	/* timer callback is active */
471da177e4SLinus Torvalds #define SNDRV_TIMER_IFLG_EXCLUSIVE 0x00000040	/* exclusive owner - no more instances */
481da177e4SLinus Torvalds #define SNDRV_TIMER_IFLG_EARLY_EVENT 0x00000080	/* write early event to the poll queue */
491da177e4SLinus Torvalds 
501da177e4SLinus Torvalds #define SNDRV_TIMER_FLG_CHANGE	0x00000001
511da177e4SLinus Torvalds #define SNDRV_TIMER_FLG_RESCHED	0x00000002	/* need reschedule */
521da177e4SLinus Torvalds 
5353d2f744STakashi Iwai struct snd_timer;
541da177e4SLinus Torvalds 
5553d2f744STakashi Iwai struct snd_timer_hardware {
561da177e4SLinus Torvalds 	/* -- must be filled with low-level driver */
571da177e4SLinus Torvalds 	unsigned int flags;		/* various flags */
581da177e4SLinus Torvalds 	unsigned long resolution;	/* average timer resolution for one tick in nsec */
591da177e4SLinus Torvalds 	unsigned long resolution_min;	/* minimal resolution */
601da177e4SLinus Torvalds 	unsigned long resolution_max;	/* maximal resolution */
611da177e4SLinus Torvalds 	unsigned long ticks;		/* max timer ticks per interrupt */
621da177e4SLinus Torvalds 	/* -- low-level functions -- */
6353d2f744STakashi Iwai 	int (*open) (struct snd_timer * timer);
6453d2f744STakashi Iwai 	int (*close) (struct snd_timer * timer);
6553d2f744STakashi Iwai 	unsigned long (*c_resolution) (struct snd_timer * timer);
6653d2f744STakashi Iwai 	int (*start) (struct snd_timer * timer);
6753d2f744STakashi Iwai 	int (*stop) (struct snd_timer * timer);
6853d2f744STakashi Iwai 	int (*set_period) (struct snd_timer * timer, unsigned long period_num, unsigned long period_den);
6953d2f744STakashi Iwai 	int (*precise_resolution) (struct snd_timer * timer, unsigned long *num, unsigned long *den);
701da177e4SLinus Torvalds };
711da177e4SLinus Torvalds 
7253d2f744STakashi Iwai struct snd_timer {
7353d2f744STakashi Iwai 	int tmr_class;
7453d2f744STakashi Iwai 	struct snd_card *card;
75de24214dSClemens Ladisch 	struct module *module;
761da177e4SLinus Torvalds 	int tmr_device;
771da177e4SLinus Torvalds 	int tmr_subdevice;
781da177e4SLinus Torvalds 	char id[64];
791da177e4SLinus Torvalds 	char name[80];
801da177e4SLinus Torvalds 	unsigned int flags;
811da177e4SLinus Torvalds 	int running;			/* running instances */
821da177e4SLinus Torvalds 	unsigned long sticks;		/* schedule ticks */
831da177e4SLinus Torvalds 	void *private_data;
8453d2f744STakashi Iwai 	void (*private_free) (struct snd_timer *timer);
8553d2f744STakashi Iwai 	struct snd_timer_hardware hw;
861da177e4SLinus Torvalds 	spinlock_t lock;
871da177e4SLinus Torvalds 	struct list_head device_list;
881da177e4SLinus Torvalds 	struct list_head open_list_head;
891da177e4SLinus Torvalds 	struct list_head active_list_head;
901da177e4SLinus Torvalds 	struct list_head ack_list_head;
911da177e4SLinus Torvalds 	struct list_head sack_list_head; /* slow ack list head */
921da177e4SLinus Torvalds 	struct tasklet_struct task_queue;
931da177e4SLinus Torvalds };
941da177e4SLinus Torvalds 
9553d2f744STakashi Iwai struct snd_timer_instance {
9653d2f744STakashi Iwai 	struct snd_timer *timer;
971da177e4SLinus Torvalds 	char *owner;
981da177e4SLinus Torvalds 	unsigned int flags;
991da177e4SLinus Torvalds 	void *private_data;
10053d2f744STakashi Iwai 	void (*private_free) (struct snd_timer_instance *ti);
10153d2f744STakashi Iwai 	void (*callback) (struct snd_timer_instance *timeri,
10253d2f744STakashi Iwai 			  unsigned long ticks, unsigned long resolution);
10353d2f744STakashi Iwai 	void (*ccallback) (struct snd_timer_instance * timeri,
10453d2f744STakashi Iwai 			   int event,
10553d2f744STakashi Iwai 			   struct timespec * tstamp,
10653d2f744STakashi Iwai 			   unsigned long resolution);
1071da177e4SLinus Torvalds 	void *callback_data;
1081da177e4SLinus Torvalds 	unsigned long ticks;		/* auto-load ticks when expired */
1091da177e4SLinus Torvalds 	unsigned long cticks;		/* current ticks */
1101da177e4SLinus Torvalds 	unsigned long pticks;		/* accumulated ticks for callback */
1111da177e4SLinus Torvalds 	unsigned long resolution;	/* current resolution for tasklet */
1121da177e4SLinus Torvalds 	unsigned long lost;		/* lost ticks */
11353d2f744STakashi Iwai 	int slave_class;
1141da177e4SLinus Torvalds 	unsigned int slave_id;
1151da177e4SLinus Torvalds 	struct list_head open_list;
1161da177e4SLinus Torvalds 	struct list_head active_list;
1171da177e4SLinus Torvalds 	struct list_head ack_list;
1181da177e4SLinus Torvalds 	struct list_head slave_list_head;
1191da177e4SLinus Torvalds 	struct list_head slave_active_head;
12053d2f744STakashi Iwai 	struct snd_timer_instance *master;
1211da177e4SLinus Torvalds };
1221da177e4SLinus Torvalds 
1231da177e4SLinus Torvalds /*
1241da177e4SLinus Torvalds  *  Registering
1251da177e4SLinus Torvalds  */
1261da177e4SLinus Torvalds 
12753d2f744STakashi Iwai int snd_timer_new(struct snd_card *card, char *id, struct snd_timer_id *tid, struct snd_timer **rtimer);
12853d2f744STakashi Iwai void snd_timer_notify(struct snd_timer *timer, int event, struct timespec *tstamp);
12953d2f744STakashi Iwai int snd_timer_global_new(char *id, int device, struct snd_timer **rtimer);
13053d2f744STakashi Iwai int snd_timer_global_free(struct snd_timer *timer);
13153d2f744STakashi Iwai int snd_timer_global_register(struct snd_timer *timer);
1321da177e4SLinus Torvalds 
13353d2f744STakashi Iwai int snd_timer_open(struct snd_timer_instance **ti, char *owner, struct snd_timer_id *tid, unsigned int slave_id);
13453d2f744STakashi Iwai int snd_timer_close(struct snd_timer_instance *timeri);
13553d2f744STakashi Iwai unsigned long snd_timer_resolution(struct snd_timer_instance *timeri);
13653d2f744STakashi Iwai int snd_timer_start(struct snd_timer_instance *timeri, unsigned int ticks);
13753d2f744STakashi Iwai int snd_timer_stop(struct snd_timer_instance *timeri);
13853d2f744STakashi Iwai int snd_timer_continue(struct snd_timer_instance *timeri);
13953d2f744STakashi Iwai int snd_timer_pause(struct snd_timer_instance *timeri);
1401da177e4SLinus Torvalds 
14153d2f744STakashi Iwai void snd_timer_interrupt(struct snd_timer *timer, unsigned long ticks_left);
1421da177e4SLinus Torvalds 
1431da177e4SLinus Torvalds #endif /* __SOUND_TIMER_H */
144