xref: /openbmc/linux/include/sound/core.h (revision 8bfb181c17d20956f156e84638912e00e1aaca86)
11da177e4SLinus Torvalds #ifndef __SOUND_CORE_H
21da177e4SLinus Torvalds #define __SOUND_CORE_H
31da177e4SLinus Torvalds 
41da177e4SLinus Torvalds /*
51da177e4SLinus Torvalds  *  Main header file for the ALSA driver
6c1017a4cSJaroslav Kysela  *  Copyright (c) 1994-2001 by Jaroslav Kysela <perex@perex.cz>
71da177e4SLinus Torvalds  *
81da177e4SLinus Torvalds  *
91da177e4SLinus Torvalds  *   This program is free software; you can redistribute it and/or modify
101da177e4SLinus Torvalds  *   it under the terms of the GNU General Public License as published by
111da177e4SLinus Torvalds  *   the Free Software Foundation; either version 2 of the License, or
121da177e4SLinus Torvalds  *   (at your option) any later version.
131da177e4SLinus Torvalds  *
141da177e4SLinus Torvalds  *   This program is distributed in the hope that it will be useful,
151da177e4SLinus Torvalds  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
161da177e4SLinus Torvalds  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
171da177e4SLinus Torvalds  *   GNU General Public License for more details.
181da177e4SLinus Torvalds  *
191da177e4SLinus Torvalds  *   You should have received a copy of the GNU General Public License
201da177e4SLinus Torvalds  *   along with this program; if not, write to the Free Software
211da177e4SLinus Torvalds  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
221da177e4SLinus Torvalds  *
231da177e4SLinus Torvalds  */
241da177e4SLinus Torvalds 
25*8bfb181cSTakashi Iwai #include <linux/device.h>
261da177e4SLinus Torvalds #include <linux/sched.h>		/* wake_up() */
271a60d4c5SIngo Molnar #include <linux/mutex.h>		/* struct mutex */
281da177e4SLinus Torvalds #include <linux/rwsem.h>		/* struct rw_semaphore */
291da177e4SLinus Torvalds #include <linux/pm.h>			/* pm_message_t */
305ef03460STakashi Iwai #include <linux/stringify.h>
31bcbb1553STim Gardner #include <linux/printk.h>
321da177e4SLinus Torvalds 
339004acc7STakashi Iwai /* number of supported soundcards */
349004acc7STakashi Iwai #ifdef CONFIG_SND_DYNAMIC_MINORS
357bb2491bSTakashi Iwai #define SNDRV_CARDS CONFIG_SND_MAX_CARDS
369004acc7STakashi Iwai #else
379004acc7STakashi Iwai #define SNDRV_CARDS 8		/* don't change - minor numbers */
389004acc7STakashi Iwai #endif
399004acc7STakashi Iwai 
409004acc7STakashi Iwai #define CONFIG_SND_MAJOR	116	/* standard configuration */
419004acc7STakashi Iwai 
421da177e4SLinus Torvalds /* forward declarations */
431da177e4SLinus Torvalds struct pci_dev;
44de477254SPaul Gortmaker struct module;
451da177e4SLinus Torvalds 
461da177e4SLinus Torvalds /* device allocation stuff */
471da177e4SLinus Torvalds 
481da177e4SLinus Torvalds #define SNDRV_DEV_TYPE_RANGE_SIZE		0x1000
491da177e4SLinus Torvalds 
50512bbd6aSTakashi Iwai typedef int __bitwise snd_device_type_t;
51512bbd6aSTakashi Iwai #define	SNDRV_DEV_TOPLEVEL	((__force snd_device_type_t) 0)
52512bbd6aSTakashi Iwai #define	SNDRV_DEV_CONTROL	((__force snd_device_type_t) 1)
53512bbd6aSTakashi Iwai #define	SNDRV_DEV_LOWLEVEL_PRE	((__force snd_device_type_t) 2)
54512bbd6aSTakashi Iwai #define	SNDRV_DEV_LOWLEVEL_NORMAL ((__force snd_device_type_t) 0x1000)
55512bbd6aSTakashi Iwai #define	SNDRV_DEV_PCM		((__force snd_device_type_t) 0x1001)
56512bbd6aSTakashi Iwai #define	SNDRV_DEV_RAWMIDI	((__force snd_device_type_t) 0x1002)
57512bbd6aSTakashi Iwai #define	SNDRV_DEV_TIMER		((__force snd_device_type_t) 0x1003)
58512bbd6aSTakashi Iwai #define	SNDRV_DEV_SEQUENCER	((__force snd_device_type_t) 0x1004)
59512bbd6aSTakashi Iwai #define	SNDRV_DEV_HWDEP		((__force snd_device_type_t) 0x1005)
60512bbd6aSTakashi Iwai #define	SNDRV_DEV_INFO		((__force snd_device_type_t) 0x1006)
61512bbd6aSTakashi Iwai #define	SNDRV_DEV_BUS		((__force snd_device_type_t) 0x1007)
62512bbd6aSTakashi Iwai #define	SNDRV_DEV_CODEC		((__force snd_device_type_t) 0x1008)
63e76d8ceaSMark Brown #define	SNDRV_DEV_JACK          ((__force snd_device_type_t) 0x1009)
643eafc959SOmair Mohammed Abdullah #define	SNDRV_DEV_COMPRESS	((__force snd_device_type_t) 0x100A)
65512bbd6aSTakashi Iwai #define	SNDRV_DEV_LOWLEVEL	((__force snd_device_type_t) 0x2000)
661da177e4SLinus Torvalds 
67512bbd6aSTakashi Iwai typedef int __bitwise snd_device_state_t;
68512bbd6aSTakashi Iwai #define	SNDRV_DEV_BUILD		((__force snd_device_state_t) 0)
69512bbd6aSTakashi Iwai #define	SNDRV_DEV_REGISTERED	((__force snd_device_state_t) 1)
70512bbd6aSTakashi Iwai #define	SNDRV_DEV_DISCONNECTED	((__force snd_device_state_t) 2)
711da177e4SLinus Torvalds 
72512bbd6aSTakashi Iwai typedef int __bitwise snd_device_cmd_t;
73512bbd6aSTakashi Iwai #define	SNDRV_DEV_CMD_PRE	((__force snd_device_cmd_t) 0)
74512bbd6aSTakashi Iwai #define	SNDRV_DEV_CMD_NORMAL	((__force snd_device_cmd_t) 1)
75512bbd6aSTakashi Iwai #define	SNDRV_DEV_CMD_POST	((__force snd_device_cmd_t) 2)
761da177e4SLinus Torvalds 
77512bbd6aSTakashi Iwai struct snd_device;
781da177e4SLinus Torvalds 
79512bbd6aSTakashi Iwai struct snd_device_ops {
80512bbd6aSTakashi Iwai 	int (*dev_free)(struct snd_device *dev);
81512bbd6aSTakashi Iwai 	int (*dev_register)(struct snd_device *dev);
82512bbd6aSTakashi Iwai 	int (*dev_disconnect)(struct snd_device *dev);
83512bbd6aSTakashi Iwai };
841da177e4SLinus Torvalds 
85512bbd6aSTakashi Iwai struct snd_device {
861da177e4SLinus Torvalds 	struct list_head list;		/* list of registered devices */
87512bbd6aSTakashi Iwai 	struct snd_card *card;		/* card which holds this device */
881da177e4SLinus Torvalds 	snd_device_state_t state;	/* state of the device */
891da177e4SLinus Torvalds 	snd_device_type_t type;		/* device type */
901da177e4SLinus Torvalds 	void *device_data;		/* device structure */
91512bbd6aSTakashi Iwai 	struct snd_device_ops *ops;	/* operations */
921da177e4SLinus Torvalds };
931da177e4SLinus Torvalds 
94512bbd6aSTakashi Iwai #define snd_device(n) list_entry(n, struct snd_device, list)
951da177e4SLinus Torvalds 
961da177e4SLinus Torvalds /* main structure for soundcard */
971da177e4SLinus Torvalds 
98512bbd6aSTakashi Iwai struct snd_card {
99d5750f67SHenrik Kretzschmar 	int number;			/* number of soundcard (index to
100d5750f67SHenrik Kretzschmar 								snd_cards) */
1011da177e4SLinus Torvalds 
1021da177e4SLinus Torvalds 	char id[16];			/* id string of this card */
1031da177e4SLinus Torvalds 	char driver[16];		/* driver name */
1041da177e4SLinus Torvalds 	char shortname[32];		/* short name of this soundcard */
1051da177e4SLinus Torvalds 	char longname[80];		/* name of this soundcard */
1061da177e4SLinus Torvalds 	char mixername[80];		/* mixer name */
107ff33f230STakashi Iwai 	char components[128];		/* card components delimited with
108d5750f67SHenrik Kretzschmar 								space */
1091da177e4SLinus Torvalds 	struct module *module;		/* top-level module */
1101da177e4SLinus Torvalds 
1111da177e4SLinus Torvalds 	void *private_data;		/* private data for soundcard */
112512bbd6aSTakashi Iwai 	void (*private_free) (struct snd_card *card); /* callback for freeing of
113d5750f67SHenrik Kretzschmar 								private data */
1141da177e4SLinus Torvalds 	struct list_head devices;	/* devices */
1151da177e4SLinus Torvalds 
1161da177e4SLinus Torvalds 	unsigned int last_numid;	/* last used numeric ID */
1171da177e4SLinus Torvalds 	struct rw_semaphore controls_rwsem;	/* controls list lock */
1181da177e4SLinus Torvalds 	rwlock_t ctl_files_rwlock;	/* ctl_files list lock */
1191da177e4SLinus Torvalds 	int controls_count;		/* count of all controls */
1201da177e4SLinus Torvalds 	int user_ctl_count;		/* count of all user controls */
1211da177e4SLinus Torvalds 	struct list_head controls;	/* all controls for this card */
1221da177e4SLinus Torvalds 	struct list_head ctl_files;	/* active control files */
1231da177e4SLinus Torvalds 
124512bbd6aSTakashi Iwai 	struct snd_info_entry *proc_root;	/* root for soundcard specific files */
125512bbd6aSTakashi Iwai 	struct snd_info_entry *proc_id;	/* the card id */
1261da177e4SLinus Torvalds 	struct proc_dir_entry *proc_root_link;	/* number link to real id */
1271da177e4SLinus Torvalds 
128118dd6bfSTakashi Iwai 	struct list_head files_list;	/* all files associated to this card */
129d5750f67SHenrik Kretzschmar 	struct snd_shutdown_f_ops *s_f_ops; /* file operations in the shutdown
130d5750f67SHenrik Kretzschmar 								state */
1311da177e4SLinus Torvalds 	spinlock_t files_lock;		/* lock the files for this card */
1321da177e4SLinus Torvalds 	int shutdown;			/* this card is going down */
133c461482cSTakashi Iwai 	int free_on_last_close;		/* free in context of file_release */
1341da177e4SLinus Torvalds 	wait_queue_head_t shutdown_sleep;
135a0830dbdSTakashi Iwai 	atomic_t refcount;		/* refcount for disconnection */
1367d2aae1eSTakashi Iwai 	struct device *dev;		/* device assigned to this card */
137*8bfb181cSTakashi Iwai 	struct device card_dev;		/* cardX object for sysfs */
138*8bfb181cSTakashi Iwai 	bool registered;		/* card_dev is registered? */
1391da177e4SLinus Torvalds 
1401da177e4SLinus Torvalds #ifdef CONFIG_PM
1411da177e4SLinus Torvalds 	unsigned int power_state;	/* power state */
1421a60d4c5SIngo Molnar 	struct mutex power_lock;	/* power lock */
1431da177e4SLinus Torvalds 	wait_queue_head_t power_sleep;
1441da177e4SLinus Torvalds #endif
1451da177e4SLinus Torvalds 
1461da177e4SLinus Torvalds #if defined(CONFIG_SND_MIXER_OSS) || defined(CONFIG_SND_MIXER_OSS_MODULE)
147512bbd6aSTakashi Iwai 	struct snd_mixer_oss *mixer_oss;
1481da177e4SLinus Torvalds 	int mixer_oss_change_count;
1491da177e4SLinus Torvalds #endif
1501da177e4SLinus Torvalds };
1511da177e4SLinus Torvalds 
152*8bfb181cSTakashi Iwai #define dev_to_snd_card(p)	container_of(p, struct snd_card, card_dev)
153*8bfb181cSTakashi Iwai 
1541da177e4SLinus Torvalds #ifdef CONFIG_PM
155512bbd6aSTakashi Iwai static inline void snd_power_lock(struct snd_card *card)
1561da177e4SLinus Torvalds {
1571a60d4c5SIngo Molnar 	mutex_lock(&card->power_lock);
1581da177e4SLinus Torvalds }
1591da177e4SLinus Torvalds 
160512bbd6aSTakashi Iwai static inline void snd_power_unlock(struct snd_card *card)
1611da177e4SLinus Torvalds {
1621a60d4c5SIngo Molnar 	mutex_unlock(&card->power_lock);
1631da177e4SLinus Torvalds }
1641da177e4SLinus Torvalds 
165512bbd6aSTakashi Iwai static inline unsigned int snd_power_get_state(struct snd_card *card)
1661da177e4SLinus Torvalds {
1671da177e4SLinus Torvalds 	return card->power_state;
1681da177e4SLinus Torvalds }
1691da177e4SLinus Torvalds 
170512bbd6aSTakashi Iwai static inline void snd_power_change_state(struct snd_card *card, unsigned int state)
1711da177e4SLinus Torvalds {
1721da177e4SLinus Torvalds 	card->power_state = state;
1731da177e4SLinus Torvalds 	wake_up(&card->power_sleep);
1741da177e4SLinus Torvalds }
175d5750f67SHenrik Kretzschmar 
176d5750f67SHenrik Kretzschmar /* init.c */
177cbac4b0cSTakashi Iwai int snd_power_wait(struct snd_card *card, unsigned int power_state);
178d5750f67SHenrik Kretzschmar 
1791da177e4SLinus Torvalds #else /* ! CONFIG_PM */
1801da177e4SLinus Torvalds 
1811da177e4SLinus Torvalds #define snd_power_lock(card)		do { (void)(card); } while (0)
1821da177e4SLinus Torvalds #define snd_power_unlock(card)		do { (void)(card); } while (0)
1836fdb94bdSLinus Torvalds static inline int snd_power_wait(struct snd_card *card, unsigned int state) { return 0; }
184363129eaSMike Frysinger #define snd_power_get_state(card)	({ (void)(card); SNDRV_CTL_POWER_D0; })
1851da177e4SLinus Torvalds #define snd_power_change_state(card, state)	do { (void)(card); } while (0)
1861da177e4SLinus Torvalds 
1871da177e4SLinus Torvalds #endif /* CONFIG_PM */
1881da177e4SLinus Torvalds 
189512bbd6aSTakashi Iwai struct snd_minor {
1902af677fcSClemens Ladisch 	int type;			/* SNDRV_DEVICE_TYPE_XXX */
1916983b724SClemens Ladisch 	int card;			/* card number */
1921da177e4SLinus Torvalds 	int device;			/* device number */
19399ac48f5SArjan van de Ven 	const struct file_operations *f_ops;	/* file operations */
194f87135f5SClemens Ladisch 	void *private_data;		/* private data for f_ops->open */
195d80f19faSGreg Kroah-Hartman 	struct device *dev;		/* device for sysfs */
196a0830dbdSTakashi Iwai 	struct snd_card *card_ptr;	/* assigned card instance */
1971da177e4SLinus Torvalds };
1981da177e4SLinus Torvalds 
1997d2aae1eSTakashi Iwai /* return a device pointer linked to each sound device as a parent */
2007d2aae1eSTakashi Iwai static inline struct device *snd_card_get_device_link(struct snd_card *card)
2017d2aae1eSTakashi Iwai {
202*8bfb181cSTakashi Iwai 	return card ? &card->card_dev : NULL;
2037d2aae1eSTakashi Iwai }
2047d2aae1eSTakashi Iwai 
2051da177e4SLinus Torvalds /* sound.c */
2061da177e4SLinus Torvalds 
207f1902860SClemens Ladisch extern int snd_major;
2081da177e4SLinus Torvalds extern int snd_ecards_limit;
209d80f19faSGreg Kroah-Hartman extern struct class *sound_class;
2101da177e4SLinus Torvalds 
2111da177e4SLinus Torvalds void snd_request_card(int card);
2121da177e4SLinus Torvalds 
21312b131c4SJohannes Berg int snd_register_device_for_dev(int type, struct snd_card *card,
21412b131c4SJohannes Berg 				int dev,
21512b131c4SJohannes Berg 				const struct file_operations *f_ops,
21612b131c4SJohannes Berg 				void *private_data,
21712b131c4SJohannes Berg 				const char *name,
21812b131c4SJohannes Berg 				struct device *device);
21912b131c4SJohannes Berg 
22012b131c4SJohannes Berg /**
22112b131c4SJohannes Berg  * snd_register_device - Register the ALSA device file for the card
22212b131c4SJohannes Berg  * @type: the device type, SNDRV_DEVICE_TYPE_XXX
22312b131c4SJohannes Berg  * @card: the card instance
22412b131c4SJohannes Berg  * @dev: the device index
22512b131c4SJohannes Berg  * @f_ops: the file operations
22612b131c4SJohannes Berg  * @private_data: user pointer for f_ops->open()
22712b131c4SJohannes Berg  * @name: the device file name
22812b131c4SJohannes Berg  *
22912b131c4SJohannes Berg  * Registers an ALSA device file for the given card.
23012b131c4SJohannes Berg  * The operators have to be set in reg parameter.
23112b131c4SJohannes Berg  *
23212b131c4SJohannes Berg  * This function uses the card's device pointer to link to the
23312b131c4SJohannes Berg  * correct &struct device.
23412b131c4SJohannes Berg  *
235eb7c06e8SYacine Belkadi  * Return: Zero if successful, or a negative error code on failure.
23612b131c4SJohannes Berg  */
23712b131c4SJohannes Berg static inline int snd_register_device(int type, struct snd_card *card, int dev,
23812b131c4SJohannes Berg 				      const struct file_operations *f_ops,
23912b131c4SJohannes Berg 				      void *private_data,
24012b131c4SJohannes Berg 				      const char *name)
24112b131c4SJohannes Berg {
24212b131c4SJohannes Berg 	return snd_register_device_for_dev(type, card, dev, f_ops,
24312b131c4SJohannes Berg 					   private_data, name,
244c2902c8aSTakashi Iwai 					   snd_card_get_device_link(card));
24512b131c4SJohannes Berg }
24612b131c4SJohannes Berg 
247512bbd6aSTakashi Iwai int snd_unregister_device(int type, struct snd_card *card, int dev);
248f87135f5SClemens Ladisch void *snd_lookup_minor_data(unsigned int minor, int type);
2499d19f48cSTakashi Iwai int snd_add_device_sysfs_file(int type, struct snd_card *card, int dev,
250d80f19faSGreg Kroah-Hartman 			      struct device_attribute *attr);
2511da177e4SLinus Torvalds 
2521da177e4SLinus Torvalds #ifdef CONFIG_SND_OSSEMUL
2532af677fcSClemens Ladisch int snd_register_oss_device(int type, struct snd_card *card, int dev,
25480d7d771STakashi Iwai 			    const struct file_operations *f_ops, void *private_data);
255512bbd6aSTakashi Iwai int snd_unregister_oss_device(int type, struct snd_card *card, int dev);
256f87135f5SClemens Ladisch void *snd_lookup_oss_minor_data(unsigned int minor, int type);
2571da177e4SLinus Torvalds #endif
2581da177e4SLinus Torvalds 
2591da177e4SLinus Torvalds int snd_minor_info_init(void);
2601da177e4SLinus Torvalds int snd_minor_info_done(void);
2611da177e4SLinus Torvalds 
2621da177e4SLinus Torvalds /* sound_oss.c */
2631da177e4SLinus Torvalds 
2641da177e4SLinus Torvalds #ifdef CONFIG_SND_OSSEMUL
2651da177e4SLinus Torvalds int snd_minor_info_oss_init(void);
2661da177e4SLinus Torvalds int snd_minor_info_oss_done(void);
2671da177e4SLinus Torvalds #else
268ad5fada5SPavel Machek static inline int snd_minor_info_oss_init(void) { return 0; }
269ad5fada5SPavel Machek static inline int snd_minor_info_oss_done(void) { return 0; }
2701da177e4SLinus Torvalds #endif
2711da177e4SLinus Torvalds 
2721da177e4SLinus Torvalds /* memory.c */
2731da177e4SLinus Torvalds 
2741da177e4SLinus Torvalds int copy_to_user_fromio(void __user *dst, const volatile void __iomem *src, size_t count);
2751da177e4SLinus Torvalds int copy_from_user_toio(volatile void __iomem *dst, const void __user *src, size_t count);
2761da177e4SLinus Torvalds 
2771da177e4SLinus Torvalds /* init.c */
2781da177e4SLinus Torvalds 
279512bbd6aSTakashi Iwai extern struct snd_card *snd_cards[SNDRV_CARDS];
280746df948STakashi Iwai int snd_card_locked(int card);
2811da177e4SLinus Torvalds #if defined(CONFIG_SND_MIXER_OSS) || defined(CONFIG_SND_MIXER_OSS_MODULE)
2821da177e4SLinus Torvalds #define SND_MIXER_OSS_NOTIFY_REGISTER	0
2831da177e4SLinus Torvalds #define SND_MIXER_OSS_NOTIFY_DISCONNECT	1
2841da177e4SLinus Torvalds #define SND_MIXER_OSS_NOTIFY_FREE	2
285512bbd6aSTakashi Iwai extern int (*snd_mixer_oss_notify_callback)(struct snd_card *card, int cmd);
2861da177e4SLinus Torvalds #endif
2871da177e4SLinus Torvalds 
288393aa9c1STakashi Iwai int snd_card_new(struct device *parent, int idx, const char *xid,
28953fb1e63STakashi Iwai 		 struct module *module, int extra_size,
29053fb1e63STakashi Iwai 		 struct snd_card **card_ret);
29153fb1e63STakashi Iwai 
292393aa9c1STakashi Iwai static inline int __deprecated
293393aa9c1STakashi Iwai snd_card_create(int idx, const char *id, struct module *module, int extra_size,
294393aa9c1STakashi Iwai 		struct snd_card **ret)
295393aa9c1STakashi Iwai {
296393aa9c1STakashi Iwai 	return snd_card_new(NULL, idx, id, module, extra_size, ret);
297393aa9c1STakashi Iwai }
298393aa9c1STakashi Iwai 
299512bbd6aSTakashi Iwai int snd_card_disconnect(struct snd_card *card);
300512bbd6aSTakashi Iwai int snd_card_free(struct snd_card *card);
301c461482cSTakashi Iwai int snd_card_free_when_closed(struct snd_card *card);
30210a8ebbbSJaroslav Kysela void snd_card_set_id(struct snd_card *card, const char *id);
303512bbd6aSTakashi Iwai int snd_card_register(struct snd_card *card);
3041da177e4SLinus Torvalds int snd_card_info_init(void);
3051da177e4SLinus Torvalds int snd_card_info_done(void);
306512bbd6aSTakashi Iwai int snd_component_add(struct snd_card *card, const char *component);
307512bbd6aSTakashi Iwai int snd_card_file_add(struct snd_card *card, struct file *file);
308512bbd6aSTakashi Iwai int snd_card_file_remove(struct snd_card *card, struct file *file);
309a0830dbdSTakashi Iwai void snd_card_unref(struct snd_card *card);
3101da177e4SLinus Torvalds 
3117d2aae1eSTakashi Iwai #define snd_card_set_dev(card, devptr) ((card)->dev = (devptr))
3121da177e4SLinus Torvalds 
3131da177e4SLinus Torvalds /* device.c */
3141da177e4SLinus Torvalds 
315512bbd6aSTakashi Iwai int snd_device_new(struct snd_card *card, snd_device_type_t type,
316512bbd6aSTakashi Iwai 		   void *device_data, struct snd_device_ops *ops);
317512bbd6aSTakashi Iwai int snd_device_register(struct snd_card *card, void *device_data);
318512bbd6aSTakashi Iwai int snd_device_register_all(struct snd_card *card);
319512bbd6aSTakashi Iwai int snd_device_disconnect(struct snd_card *card, void *device_data);
320512bbd6aSTakashi Iwai int snd_device_disconnect_all(struct snd_card *card);
321512bbd6aSTakashi Iwai int snd_device_free(struct snd_card *card, void *device_data);
322512bbd6aSTakashi Iwai int snd_device_free_all(struct snd_card *card, snd_device_cmd_t cmd);
3231da177e4SLinus Torvalds 
3241da177e4SLinus Torvalds /* isadma.c */
3251da177e4SLinus Torvalds 
326276bd31cSAl Viro #ifdef CONFIG_ISA_DMA_API
3271da177e4SLinus Torvalds #define DMA_MODE_NO_ENABLE	0x0100
3281da177e4SLinus Torvalds 
3291da177e4SLinus Torvalds void snd_dma_program(unsigned long dma, unsigned long addr, unsigned int size, unsigned short mode);
3301da177e4SLinus Torvalds void snd_dma_disable(unsigned long dma);
3311da177e4SLinus Torvalds unsigned int snd_dma_pointer(unsigned long dma, unsigned int size);
332276bd31cSAl Viro #endif
3331da177e4SLinus Torvalds 
3341da177e4SLinus Torvalds /* misc.c */
335b709e574STakashi Iwai struct resource;
336b1d5776dSTakashi Iwai void release_and_free_resource(struct resource *res);
3371da177e4SLinus Torvalds 
3381da177e4SLinus Torvalds /* --- */
3391da177e4SLinus Torvalds 
340fae3d88aSFengguang Wu /* sound printk debug levels */
341fae3d88aSFengguang Wu enum {
342fae3d88aSFengguang Wu 	SND_PR_ALWAYS,
343fae3d88aSFengguang Wu 	SND_PR_DEBUG,
344fae3d88aSFengguang Wu 	SND_PR_VERBOSE,
345fae3d88aSFengguang Wu };
346fae3d88aSFengguang Wu 
34736ce99c1STakashi Iwai #if defined(CONFIG_SND_DEBUG) || defined(CONFIG_SND_VERBOSE_PRINTK)
348b9075fa9SJoe Perches __printf(4, 5)
34936ce99c1STakashi Iwai void __snd_printk(unsigned int level, const char *file, int line,
350b9075fa9SJoe Perches 		  const char *format, ...);
35136ce99c1STakashi Iwai #else
35236ce99c1STakashi Iwai #define __snd_printk(level, file, line, format, args...) \
353cf0baf16STakashi Iwai 	printk(format, ##args)
35436ce99c1STakashi Iwai #endif
35536ce99c1STakashi Iwai 
3561da177e4SLinus Torvalds /**
3571da177e4SLinus Torvalds  * snd_printk - printk wrapper
3581da177e4SLinus Torvalds  * @fmt: format string
3591da177e4SLinus Torvalds  *
360f66fcedcSTakashi Iwai  * Works like printk() but prints the file and the line of the caller
3611da177e4SLinus Torvalds  * when configured with CONFIG_SND_VERBOSE_PRINTK.
3621da177e4SLinus Torvalds  */
3631da177e4SLinus Torvalds #define snd_printk(fmt, args...) \
36436ce99c1STakashi Iwai 	__snd_printk(0, __FILE__, __LINE__, fmt, ##args)
3651da177e4SLinus Torvalds 
3661da177e4SLinus Torvalds #ifdef CONFIG_SND_DEBUG
3671da177e4SLinus Torvalds /**
3681da177e4SLinus Torvalds  * snd_printd - debug printk
3690863afb3SMartin Waitz  * @fmt: format string
3701da177e4SLinus Torvalds  *
371edab938eSPavel Machek  * Works like snd_printk() for debugging purposes.
3721da177e4SLinus Torvalds  * Ignored when CONFIG_SND_DEBUG is not set.
3731da177e4SLinus Torvalds  */
3741da177e4SLinus Torvalds #define snd_printd(fmt, args...) \
37536ce99c1STakashi Iwai 	__snd_printk(1, __FILE__, __LINE__, fmt, ##args)
376fae3d88aSFengguang Wu #define _snd_printd(level, fmt, args...) \
377fae3d88aSFengguang Wu 	__snd_printk(level, __FILE__, __LINE__, fmt, ##args)
3787c22f1aaSTakashi Iwai 
379f66fcedcSTakashi Iwai /**
380f66fcedcSTakashi Iwai  * snd_BUG - give a BUG warning message and stack trace
381f66fcedcSTakashi Iwai  *
382f66fcedcSTakashi Iwai  * Calls WARN() if CONFIG_SND_DEBUG is set.
383f66fcedcSTakashi Iwai  * Ignored when CONFIG_SND_DEBUG is not set.
384f66fcedcSTakashi Iwai  */
385bdbecf50STakashi Iwai #define snd_BUG()		WARN(1, "BUG?\n")
386f66fcedcSTakashi Iwai 
387f66fcedcSTakashi Iwai /**
388bcbb1553STim Gardner  * Suppress high rates of output when CONFIG_SND_DEBUG is enabled.
389bcbb1553STim Gardner  */
390bcbb1553STim Gardner #define snd_printd_ratelimit() printk_ratelimit()
391bcbb1553STim Gardner 
392bcbb1553STim Gardner /**
393f66fcedcSTakashi Iwai  * snd_BUG_ON - debugging check macro
394f66fcedcSTakashi Iwai  * @cond: condition to evaluate
395f66fcedcSTakashi Iwai  *
396d5702162SChristine Spang  * Has the same behavior as WARN_ON when CONFIG_SND_DEBUG is set,
397d5702162SChristine Spang  * otherwise just evaluates the conditional and returns the value.
398f66fcedcSTakashi Iwai  */
399d5702162SChristine Spang #define snd_BUG_ON(cond)	WARN_ON((cond))
4001da177e4SLinus Torvalds 
4011da177e4SLinus Torvalds #else /* !CONFIG_SND_DEBUG */
4021da177e4SLinus Torvalds 
40386b27237STakashi Iwai __printf(1, 2)
40486b27237STakashi Iwai static inline void snd_printd(const char *format, ...) {}
40586b27237STakashi Iwai __printf(2, 3)
40686b27237STakashi Iwai static inline void _snd_printd(int level, const char *format, ...) {}
40786b27237STakashi Iwai 
408fcef7836SAndrew Morton #define snd_BUG()			do { } while (0)
409d5702162SChristine Spang 
410d5702162SChristine Spang #define snd_BUG_ON(condition) ({ \
411d5702162SChristine Spang 	int __ret_warn_on = !!(condition); \
412d5702162SChristine Spang 	unlikely(__ret_warn_on); \
413d5702162SChristine Spang })
4141da177e4SLinus Torvalds 
415bcbb1553STim Gardner static inline bool snd_printd_ratelimit(void) { return false; }
416bcbb1553STim Gardner 
4171da177e4SLinus Torvalds #endif /* CONFIG_SND_DEBUG */
4181da177e4SLinus Torvalds 
41962cf872aSTakashi Iwai #ifdef CONFIG_SND_DEBUG_VERBOSE
4201da177e4SLinus Torvalds /**
4211da177e4SLinus Torvalds  * snd_printdd - debug printk
4221da177e4SLinus Torvalds  * @format: format string
4231da177e4SLinus Torvalds  *
424edab938eSPavel Machek  * Works like snd_printk() for debugging purposes.
42562cf872aSTakashi Iwai  * Ignored when CONFIG_SND_DEBUG_VERBOSE is not set.
4261da177e4SLinus Torvalds  */
42736ce99c1STakashi Iwai #define snd_printdd(format, args...) \
42836ce99c1STakashi Iwai 	__snd_printk(2, __FILE__, __LINE__, format, ##args)
4291da177e4SLinus Torvalds #else
43086b27237STakashi Iwai __printf(1, 2)
43186b27237STakashi Iwai static inline void snd_printdd(const char *format, ...) {}
4321da177e4SLinus Torvalds #endif
4331da177e4SLinus Torvalds 
4341da177e4SLinus Torvalds 
4351da177e4SLinus Torvalds #define SNDRV_OSS_VERSION         ((3<<16)|(8<<8)|(1<<4)|(0))	/* 3.8.1a */
4361da177e4SLinus Torvalds 
4371da177e4SLinus Torvalds /* for easier backward-porting */
4381da177e4SLinus Torvalds #if defined(CONFIG_GAMEPORT) || defined(CONFIG_GAMEPORT_MODULE)
4391da177e4SLinus Torvalds #define gameport_set_dev_parent(gp,xdev) ((gp)->dev.parent = (xdev))
4401da177e4SLinus Torvalds #define gameport_set_port_data(gp,r) ((gp)->port_data = (r))
4411da177e4SLinus Torvalds #define gameport_get_port_data(gp) (gp)->port_data
4421da177e4SLinus Torvalds #endif
4431da177e4SLinus Torvalds 
4448422fa11SAxel Lin #ifdef CONFIG_PCI
445d9ea472cSTakashi Iwai /* PCI quirk list helper */
446d9ea472cSTakashi Iwai struct snd_pci_quirk {
447d9ea472cSTakashi Iwai 	unsigned short subvendor;	/* PCI subvendor ID */
448d9ea472cSTakashi Iwai 	unsigned short subdevice;	/* PCI subdevice ID */
4498bd4bb7aSTakashi Iwai 	unsigned short subdevice_mask;	/* bitmask to match */
450d9ea472cSTakashi Iwai 	int value;			/* value */
45162cf872aSTakashi Iwai #ifdef CONFIG_SND_DEBUG_VERBOSE
452d9ea472cSTakashi Iwai 	const char *name;		/* name of the device (optional) */
453d9ea472cSTakashi Iwai #endif
454d9ea472cSTakashi Iwai };
455d9ea472cSTakashi Iwai 
4568bd4bb7aSTakashi Iwai #define _SND_PCI_QUIRK_ID_MASK(vend, mask, dev)	\
4578bd4bb7aSTakashi Iwai 	.subvendor = (vend), .subdevice = (dev), .subdevice_mask = (mask)
458d9ea472cSTakashi Iwai #define _SND_PCI_QUIRK_ID(vend, dev) \
4598bd4bb7aSTakashi Iwai 	_SND_PCI_QUIRK_ID_MASK(vend, 0xffff, dev)
460d9ea472cSTakashi Iwai #define SND_PCI_QUIRK_ID(vend,dev) {_SND_PCI_QUIRK_ID(vend, dev)}
46162cf872aSTakashi Iwai #ifdef CONFIG_SND_DEBUG_VERBOSE
462d9ea472cSTakashi Iwai #define SND_PCI_QUIRK(vend,dev,xname,val) \
463d9ea472cSTakashi Iwai 	{_SND_PCI_QUIRK_ID(vend, dev), .value = (val), .name = (xname)}
4648bd4bb7aSTakashi Iwai #define SND_PCI_QUIRK_VENDOR(vend, xname, val)			\
4658bd4bb7aSTakashi Iwai 	{_SND_PCI_QUIRK_ID_MASK(vend, 0, 0), .value = (val), .name = (xname)}
4668bd4bb7aSTakashi Iwai #define SND_PCI_QUIRK_MASK(vend, mask, dev, xname, val)			\
4678bd4bb7aSTakashi Iwai 	{_SND_PCI_QUIRK_ID_MASK(vend, mask, dev),			\
4688bd4bb7aSTakashi Iwai 			.value = (val), .name = (xname)}
46986b27237STakashi Iwai #define snd_pci_quirk_name(q)	((q)->name)
470d9ea472cSTakashi Iwai #else
471d9ea472cSTakashi Iwai #define SND_PCI_QUIRK(vend,dev,xname,val) \
472d9ea472cSTakashi Iwai 	{_SND_PCI_QUIRK_ID(vend, dev), .value = (val)}
4738bd4bb7aSTakashi Iwai #define SND_PCI_QUIRK_MASK(vend, mask, dev, xname, val)			\
4748bd4bb7aSTakashi Iwai 	{_SND_PCI_QUIRK_ID_MASK(vend, mask, dev), .value = (val)}
4758bd4bb7aSTakashi Iwai #define SND_PCI_QUIRK_VENDOR(vend, xname, val)			\
4768bd4bb7aSTakashi Iwai 	{_SND_PCI_QUIRK_ID_MASK(vend, 0, 0), .value = (val)}
47786b27237STakashi Iwai #define snd_pci_quirk_name(q)	""
478d9ea472cSTakashi Iwai #endif
479d9ea472cSTakashi Iwai 
480d9ea472cSTakashi Iwai const struct snd_pci_quirk *
481d9ea472cSTakashi Iwai snd_pci_quirk_lookup(struct pci_dev *pci, const struct snd_pci_quirk *list);
482d9ea472cSTakashi Iwai 
483d1458279STakashi Iwai const struct snd_pci_quirk *
484d1458279STakashi Iwai snd_pci_quirk_lookup_id(u16 vendor, u16 device,
485d1458279STakashi Iwai 			const struct snd_pci_quirk *list);
4868422fa11SAxel Lin #endif
487d9ea472cSTakashi Iwai 
4881da177e4SLinus Torvalds #endif /* __SOUND_CORE_H */
489