xref: /linux/include/sound/timer.h (revision de24214d0c8e78134875752619f99b9e5824c196)
11da177e4SLinus Torvalds #ifndef __SOUND_TIMER_H
21da177e4SLinus Torvalds #define __SOUND_TIMER_H
31da177e4SLinus Torvalds 
41da177e4SLinus Torvalds /*
51da177e4SLinus Torvalds  *  Timer abstract layer
61da177e4SLinus Torvalds  *  Copyright (c) by Jaroslav Kysela <perex@suse.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 typedef enum sndrv_timer_class snd_timer_class_t;
301da177e4SLinus Torvalds typedef enum sndrv_timer_slave_class snd_timer_slave_class_t;
311da177e4SLinus Torvalds typedef enum sndrv_timer_global snd_timer_global_t;
321da177e4SLinus Torvalds typedef struct sndrv_timer_id snd_timer_id_t;
331da177e4SLinus Torvalds typedef struct sndrv_timer_ginfo snd_timer_ginfo_t;
341da177e4SLinus Torvalds typedef struct sndrv_timer_gparams snd_timer_gparams_t;
351da177e4SLinus Torvalds typedef struct sndrv_timer_gstatus snd_timer_gstatus_t;
361da177e4SLinus Torvalds typedef struct sndrv_timer_select snd_timer_select_t;
371da177e4SLinus Torvalds typedef struct sndrv_timer_info snd_timer_info_t;
381da177e4SLinus Torvalds typedef struct sndrv_timer_params snd_timer_params_t;
391da177e4SLinus Torvalds typedef struct sndrv_timer_status snd_timer_status_t;
401da177e4SLinus Torvalds typedef struct sndrv_timer_read snd_timer_read_t;
411da177e4SLinus Torvalds typedef struct sndrv_timer_tread snd_timer_tread_t;
421da177e4SLinus Torvalds 
431da177e4SLinus Torvalds #define snd_timer_chip(timer) ((timer)->private_data)
441da177e4SLinus Torvalds 
451da177e4SLinus Torvalds #define SNDRV_TIMER_DEVICES	16
461da177e4SLinus Torvalds 
471da177e4SLinus Torvalds #define SNDRV_TIMER_DEV_FLG_PCM	0x10000000
481da177e4SLinus Torvalds 
491da177e4SLinus Torvalds #define SNDRV_TIMER_HW_AUTO	0x00000001	/* auto trigger is supported */
501da177e4SLinus Torvalds #define SNDRV_TIMER_HW_STOP	0x00000002	/* call stop before start */
511da177e4SLinus Torvalds #define SNDRV_TIMER_HW_SLAVE	0x00000004	/* only slave timer (variable resolution) */
521da177e4SLinus Torvalds #define SNDRV_TIMER_HW_FIRST	0x00000008	/* first tick can be incomplete */
531da177e4SLinus Torvalds #define SNDRV_TIMER_HW_TASKLET	0x00000010	/* timer is called from tasklet */
541da177e4SLinus Torvalds 
551da177e4SLinus Torvalds #define SNDRV_TIMER_IFLG_SLAVE	  0x00000001
561da177e4SLinus Torvalds #define SNDRV_TIMER_IFLG_RUNNING  0x00000002
571da177e4SLinus Torvalds #define SNDRV_TIMER_IFLG_START	  0x00000004
581da177e4SLinus Torvalds #define SNDRV_TIMER_IFLG_AUTO	  0x00000008	/* auto restart */
591da177e4SLinus Torvalds #define SNDRV_TIMER_IFLG_FAST	  0x00000010	/* fast callback (do not use tasklet) */
601da177e4SLinus Torvalds #define SNDRV_TIMER_IFLG_CALLBACK 0x00000020	/* timer callback is active */
611da177e4SLinus Torvalds #define SNDRV_TIMER_IFLG_EXCLUSIVE 0x00000040	/* exclusive owner - no more instances */
621da177e4SLinus Torvalds #define SNDRV_TIMER_IFLG_EARLY_EVENT 0x00000080	/* write early event to the poll queue */
631da177e4SLinus Torvalds 
641da177e4SLinus Torvalds #define SNDRV_TIMER_FLG_CHANGE	0x00000001
651da177e4SLinus Torvalds #define SNDRV_TIMER_FLG_RESCHED	0x00000002	/* need reschedule */
661da177e4SLinus Torvalds 
671da177e4SLinus Torvalds typedef void (*snd_timer_callback_t) (snd_timer_instance_t * timeri, unsigned long ticks, unsigned long resolution);
681da177e4SLinus Torvalds typedef void (*snd_timer_ccallback_t) (snd_timer_instance_t * timeri, enum sndrv_timer_event event,
691da177e4SLinus Torvalds 				       struct timespec * tstamp, unsigned long resolution);
701da177e4SLinus Torvalds 
711da177e4SLinus Torvalds struct _snd_timer_hardware {
721da177e4SLinus Torvalds 	/* -- must be filled with low-level driver */
731da177e4SLinus Torvalds 	unsigned int flags;		/* various flags */
741da177e4SLinus Torvalds 	unsigned long resolution;	/* average timer resolution for one tick in nsec */
751da177e4SLinus Torvalds 	unsigned long resolution_min;	/* minimal resolution */
761da177e4SLinus Torvalds 	unsigned long resolution_max;	/* maximal resolution */
771da177e4SLinus Torvalds 	unsigned long ticks;		/* max timer ticks per interrupt */
781da177e4SLinus Torvalds 	/* -- low-level functions -- */
791da177e4SLinus Torvalds 	int (*open) (snd_timer_t * timer);
801da177e4SLinus Torvalds 	int (*close) (snd_timer_t * timer);
811da177e4SLinus Torvalds 	unsigned long (*c_resolution) (snd_timer_t * timer);
821da177e4SLinus Torvalds 	int (*start) (snd_timer_t * timer);
831da177e4SLinus Torvalds 	int (*stop) (snd_timer_t * timer);
841da177e4SLinus Torvalds 	int (*set_period) (snd_timer_t * timer, unsigned long period_num, unsigned long period_den);
851da177e4SLinus Torvalds 	int (*precise_resolution) (snd_timer_t * timer, unsigned long *num, unsigned long *den);
861da177e4SLinus Torvalds };
871da177e4SLinus Torvalds 
881da177e4SLinus Torvalds struct _snd_timer {
891da177e4SLinus Torvalds 	snd_timer_class_t tmr_class;
901da177e4SLinus Torvalds 	snd_card_t *card;
91*de24214dSClemens Ladisch 	struct module *module;
921da177e4SLinus Torvalds 	int tmr_device;
931da177e4SLinus Torvalds 	int tmr_subdevice;
941da177e4SLinus Torvalds 	char id[64];
951da177e4SLinus Torvalds 	char name[80];
961da177e4SLinus Torvalds 	unsigned int flags;
971da177e4SLinus Torvalds 	int running;			/* running instances */
981da177e4SLinus Torvalds 	unsigned long sticks;		/* schedule ticks */
991da177e4SLinus Torvalds 	void *private_data;
1001da177e4SLinus Torvalds 	void (*private_free) (snd_timer_t *timer);
1011da177e4SLinus Torvalds 	struct _snd_timer_hardware hw;
1021da177e4SLinus Torvalds 	spinlock_t lock;
1031da177e4SLinus Torvalds 	struct list_head device_list;
1041da177e4SLinus Torvalds 	struct list_head open_list_head;
1051da177e4SLinus Torvalds 	struct list_head active_list_head;
1061da177e4SLinus Torvalds 	struct list_head ack_list_head;
1071da177e4SLinus Torvalds 	struct list_head sack_list_head; /* slow ack list head */
1081da177e4SLinus Torvalds 	struct tasklet_struct task_queue;
1091da177e4SLinus Torvalds };
1101da177e4SLinus Torvalds 
1111da177e4SLinus Torvalds struct _snd_timer_instance {
1121da177e4SLinus Torvalds 	snd_timer_t * timer;
1131da177e4SLinus Torvalds 	char *owner;
1141da177e4SLinus Torvalds 	unsigned int flags;
1151da177e4SLinus Torvalds 	void *private_data;
1161da177e4SLinus Torvalds 	void (*private_free) (snd_timer_instance_t *ti);
1171da177e4SLinus Torvalds 	snd_timer_callback_t callback;
1181da177e4SLinus Torvalds 	snd_timer_ccallback_t ccallback;
1191da177e4SLinus Torvalds 	void *callback_data;
1201da177e4SLinus Torvalds 	unsigned long ticks;		/* auto-load ticks when expired */
1211da177e4SLinus Torvalds 	unsigned long cticks;		/* current ticks */
1221da177e4SLinus Torvalds 	unsigned long pticks;		/* accumulated ticks for callback */
1231da177e4SLinus Torvalds 	unsigned long resolution;	/* current resolution for tasklet */
1241da177e4SLinus Torvalds 	unsigned long lost;		/* lost ticks */
1251da177e4SLinus Torvalds 	snd_timer_slave_class_t slave_class;
1261da177e4SLinus Torvalds 	unsigned int slave_id;
1271da177e4SLinus Torvalds 	struct list_head open_list;
1281da177e4SLinus Torvalds 	struct list_head active_list;
1291da177e4SLinus Torvalds 	struct list_head ack_list;
1301da177e4SLinus Torvalds 	struct list_head slave_list_head;
1311da177e4SLinus Torvalds 	struct list_head slave_active_head;
1321da177e4SLinus Torvalds 	snd_timer_instance_t *master;
1331da177e4SLinus Torvalds };
1341da177e4SLinus Torvalds 
1351da177e4SLinus Torvalds /*
1361da177e4SLinus Torvalds  *  Registering
1371da177e4SLinus Torvalds  */
1381da177e4SLinus Torvalds 
1391da177e4SLinus Torvalds extern int snd_timer_new(snd_card_t *card, char *id, snd_timer_id_t *tid, snd_timer_t ** rtimer);
1401da177e4SLinus Torvalds extern void snd_timer_notify(snd_timer_t *timer, enum sndrv_timer_event event, struct timespec *tstamp);
1411da177e4SLinus Torvalds extern int snd_timer_global_new(char *id, int device, snd_timer_t **rtimer);
1421da177e4SLinus Torvalds extern int snd_timer_global_free(snd_timer_t *timer);
1431da177e4SLinus Torvalds extern int snd_timer_global_register(snd_timer_t *timer);
1441da177e4SLinus Torvalds extern int snd_timer_global_unregister(snd_timer_t *timer);
1451da177e4SLinus Torvalds 
1461da177e4SLinus Torvalds extern int snd_timer_open(snd_timer_instance_t ** ti, char *owner, snd_timer_id_t *tid, unsigned int slave_id);
1471da177e4SLinus Torvalds extern int snd_timer_close(snd_timer_instance_t * timeri);
1481da177e4SLinus Torvalds extern unsigned long snd_timer_resolution(snd_timer_instance_t * timeri);
1491da177e4SLinus Torvalds extern int snd_timer_start(snd_timer_instance_t * timeri, unsigned int ticks);
1501da177e4SLinus Torvalds extern int snd_timer_stop(snd_timer_instance_t * timeri);
1511da177e4SLinus Torvalds extern int snd_timer_continue(snd_timer_instance_t * timeri);
1521da177e4SLinus Torvalds extern int snd_timer_pause(snd_timer_instance_t * timeri);
1531da177e4SLinus Torvalds 
1541da177e4SLinus Torvalds extern void snd_timer_interrupt(snd_timer_t * timer, unsigned long ticks_left);
1551da177e4SLinus Torvalds 
1561da177e4SLinus Torvalds #endif /* __SOUND_TIMER_H */
157