xref: /openbmc/linux/include/sound/core.h (revision fee2b871d8d6389c9b4bdf9346a99ccc1c98c9b8)
11a59d1b8SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */
21da177e4SLinus Torvalds #ifndef __SOUND_CORE_H
31da177e4SLinus Torvalds #define __SOUND_CORE_H
41da177e4SLinus Torvalds 
51da177e4SLinus Torvalds /*
61da177e4SLinus Torvalds  *  Main header file for the ALSA driver
7c1017a4cSJaroslav Kysela  *  Copyright (c) 1994-2001 by Jaroslav Kysela <perex@perex.cz>
81da177e4SLinus Torvalds  */
91da177e4SLinus Torvalds 
108bfb181cSTakashi Iwai #include <linux/device.h>
111da177e4SLinus Torvalds #include <linux/sched.h>		/* wake_up() */
121a60d4c5SIngo Molnar #include <linux/mutex.h>		/* struct mutex */
131da177e4SLinus Torvalds #include <linux/rwsem.h>		/* struct rw_semaphore */
141da177e4SLinus Torvalds #include <linux/pm.h>			/* pm_message_t */
155ef03460STakashi Iwai #include <linux/stringify.h>
16bcbb1553STim Gardner #include <linux/printk.h>
171da177e4SLinus Torvalds 
189004acc7STakashi Iwai /* number of supported soundcards */
199004acc7STakashi Iwai #ifdef CONFIG_SND_DYNAMIC_MINORS
207bb2491bSTakashi Iwai #define SNDRV_CARDS CONFIG_SND_MAX_CARDS
219004acc7STakashi Iwai #else
229004acc7STakashi Iwai #define SNDRV_CARDS 8		/* don't change - minor numbers */
239004acc7STakashi Iwai #endif
249004acc7STakashi Iwai 
259004acc7STakashi Iwai #define CONFIG_SND_MAJOR	116	/* standard configuration */
269004acc7STakashi Iwai 
271da177e4SLinus Torvalds /* forward declarations */
281da177e4SLinus Torvalds struct pci_dev;
29de477254SPaul Gortmaker struct module;
30f2464064STakashi Iwai struct completion;
311da177e4SLinus Torvalds 
321da177e4SLinus Torvalds /* device allocation stuff */
331da177e4SLinus Torvalds 
34289ca025STakashi Iwai /* type of the object used in snd_device_*()
35289ca025STakashi Iwai  * this also defines the calling order
36289ca025STakashi Iwai  */
379ce50543STakashi Iwai enum snd_device_type {
38289ca025STakashi Iwai 	SNDRV_DEV_LOWLEVEL,
39289ca025STakashi Iwai 	SNDRV_DEV_INFO,
40289ca025STakashi Iwai 	SNDRV_DEV_BUS,
41289ca025STakashi Iwai 	SNDRV_DEV_CODEC,
429ce50543STakashi Iwai 	SNDRV_DEV_PCM,
43289ca025STakashi Iwai 	SNDRV_DEV_COMPRESS,
449ce50543STakashi Iwai 	SNDRV_DEV_RAWMIDI,
459ce50543STakashi Iwai 	SNDRV_DEV_TIMER,
469ce50543STakashi Iwai 	SNDRV_DEV_SEQUENCER,
479ce50543STakashi Iwai 	SNDRV_DEV_HWDEP,
489ce50543STakashi Iwai 	SNDRV_DEV_JACK,
49dc82e524STakashi Iwai 	SNDRV_DEV_CONTROL,	/* NOTE: this must be the last one */
509ce50543STakashi Iwai };
511da177e4SLinus Torvalds 
529ce50543STakashi Iwai enum snd_device_state {
539ce50543STakashi Iwai 	SNDRV_DEV_BUILD,
549ce50543STakashi Iwai 	SNDRV_DEV_REGISTERED,
559ce50543STakashi Iwai 	SNDRV_DEV_DISCONNECTED,
569ce50543STakashi Iwai };
571da177e4SLinus Torvalds 
58512bbd6aSTakashi Iwai struct snd_device;
591da177e4SLinus Torvalds 
60512bbd6aSTakashi Iwai struct snd_device_ops {
61512bbd6aSTakashi Iwai 	int (*dev_free)(struct snd_device *dev);
62512bbd6aSTakashi Iwai 	int (*dev_register)(struct snd_device *dev);
63512bbd6aSTakashi Iwai 	int (*dev_disconnect)(struct snd_device *dev);
64512bbd6aSTakashi Iwai };
651da177e4SLinus Torvalds 
66512bbd6aSTakashi Iwai struct snd_device {
671da177e4SLinus Torvalds 	struct list_head list;		/* list of registered devices */
68512bbd6aSTakashi Iwai 	struct snd_card *card;		/* card which holds this device */
699ce50543STakashi Iwai 	enum snd_device_state state;	/* state of the device */
709ce50543STakashi Iwai 	enum snd_device_type type;	/* device type */
711da177e4SLinus Torvalds 	void *device_data;		/* device structure */
728b575824STakashi Iwai 	const struct snd_device_ops *ops;	/* operations */
731da177e4SLinus Torvalds };
741da177e4SLinus Torvalds 
75512bbd6aSTakashi Iwai #define snd_device(n) list_entry(n, struct snd_device, list)
761da177e4SLinus Torvalds 
771da177e4SLinus Torvalds /* main structure for soundcard */
781da177e4SLinus Torvalds 
79512bbd6aSTakashi Iwai struct snd_card {
80d5750f67SHenrik Kretzschmar 	int number;			/* number of soundcard (index to
81d5750f67SHenrik Kretzschmar 								snd_cards) */
821da177e4SLinus Torvalds 
831da177e4SLinus Torvalds 	char id[16];			/* id string of this card */
841da177e4SLinus Torvalds 	char driver[16];		/* driver name */
851da177e4SLinus Torvalds 	char shortname[32];		/* short name of this soundcard */
861da177e4SLinus Torvalds 	char longname[80];		/* name of this soundcard */
87de65360bSHeiner Kallweit 	char irq_descr[32];		/* Interrupt description */
881da177e4SLinus Torvalds 	char mixername[80];		/* mixer name */
89ff33f230STakashi Iwai 	char components[128];		/* card components delimited with
90d5750f67SHenrik Kretzschmar 								space */
911da177e4SLinus Torvalds 	struct module *module;		/* top-level module */
921da177e4SLinus Torvalds 
931da177e4SLinus Torvalds 	void *private_data;		/* private data for soundcard */
94512bbd6aSTakashi Iwai 	void (*private_free) (struct snd_card *card); /* callback for freeing of
95d5750f67SHenrik Kretzschmar 								private data */
961da177e4SLinus Torvalds 	struct list_head devices;	/* devices */
971da177e4SLinus Torvalds 
980fcd9f4bSTakashi Iwai 	struct device ctl_dev;		/* control device */
991da177e4SLinus Torvalds 	unsigned int last_numid;	/* last used numeric ID */
1001da177e4SLinus Torvalds 	struct rw_semaphore controls_rwsem;	/* controls list lock */
1011da177e4SLinus Torvalds 	rwlock_t ctl_files_rwlock;	/* ctl_files list lock */
1021da177e4SLinus Torvalds 	int controls_count;		/* count of all controls */
10366c6d1efSTakashi Sakamoto 	size_t user_ctl_alloc_size;	// current memory allocation by user controls.
1041da177e4SLinus Torvalds 	struct list_head controls;	/* all controls for this card */
1051da177e4SLinus Torvalds 	struct list_head ctl_files;	/* active control files */
1061da177e4SLinus Torvalds 
107512bbd6aSTakashi Iwai 	struct snd_info_entry *proc_root;	/* root for soundcard specific files */
1081da177e4SLinus Torvalds 	struct proc_dir_entry *proc_root_link;	/* number link to real id */
1091da177e4SLinus Torvalds 
110118dd6bfSTakashi Iwai 	struct list_head files_list;	/* all files associated to this card */
111d5750f67SHenrik Kretzschmar 	struct snd_shutdown_f_ops *s_f_ops; /* file operations in the shutdown
112d5750f67SHenrik Kretzschmar 								state */
1131da177e4SLinus Torvalds 	spinlock_t files_lock;		/* lock the files for this card */
1141da177e4SLinus Torvalds 	int shutdown;			/* this card is going down */
115f2464064STakashi Iwai 	struct completion *release_completion;
1167d2aae1eSTakashi Iwai 	struct device *dev;		/* device assigned to this card */
1178bfb181cSTakashi Iwai 	struct device card_dev;		/* cardX object for sysfs */
1186bbc7fedSTakashi Iwai 	const struct attribute_group *dev_groups[4]; /* assigned sysfs attr */
1198bfb181cSTakashi Iwai 	bool registered;		/* card_dev is registered? */
120e8ad415bSTakashi Iwai 	bool managed;			/* managed via devres */
121e8ad415bSTakashi Iwai 	bool releasing;			/* during card free process */
122fabb26dcSTakashi Iwai 	int sync_irq;			/* assigned irq, used for PCM sync */
123c44027c8STakashi Iwai 	wait_queue_head_t remove_sleep;
1241da177e4SLinus Torvalds 
125d4cfb30fSTakashi Iwai 	size_t total_pcm_alloc_bytes;	/* total amount of allocated buffers */
126d4cfb30fSTakashi Iwai 	struct mutex memory_mutex;	/* protection for the above */
1272d670ea2SHui Wang #ifdef CONFIG_SND_DEBUG
1282d670ea2SHui Wang 	struct dentry *debugfs_root;    /* debugfs root for card */
1292d670ea2SHui Wang #endif
130d4cfb30fSTakashi Iwai 
1311da177e4SLinus Torvalds #ifdef CONFIG_PM
1321da177e4SLinus Torvalds 	unsigned int power_state;	/* power state */
133e94fdbd7STakashi Iwai 	atomic_t power_ref;
1341da177e4SLinus Torvalds 	wait_queue_head_t power_sleep;
135e94fdbd7STakashi Iwai 	wait_queue_head_t power_ref_sleep;
1361da177e4SLinus Torvalds #endif
1371da177e4SLinus Torvalds 
1386d2412b8STakashi Iwai #if IS_ENABLED(CONFIG_SND_MIXER_OSS)
139512bbd6aSTakashi Iwai 	struct snd_mixer_oss *mixer_oss;
1401da177e4SLinus Torvalds 	int mixer_oss_change_count;
1411da177e4SLinus Torvalds #endif
1421da177e4SLinus Torvalds };
1431da177e4SLinus Torvalds 
1448bfb181cSTakashi Iwai #define dev_to_snd_card(p)	container_of(p, struct snd_card, card_dev)
1458bfb181cSTakashi Iwai 
1461da177e4SLinus Torvalds #ifdef CONFIG_PM
147512bbd6aSTakashi Iwai static inline unsigned int snd_power_get_state(struct snd_card *card)
1481da177e4SLinus Torvalds {
149533a7ed9STakashi Iwai 	return READ_ONCE(card->power_state);
1501da177e4SLinus Torvalds }
1511da177e4SLinus Torvalds 
152512bbd6aSTakashi Iwai static inline void snd_power_change_state(struct snd_card *card, unsigned int state)
1531da177e4SLinus Torvalds {
154533a7ed9STakashi Iwai 	WRITE_ONCE(card->power_state, state);
1551da177e4SLinus Torvalds 	wake_up(&card->power_sleep);
1561da177e4SLinus Torvalds }
157d5750f67SHenrik Kretzschmar 
158e94fdbd7STakashi Iwai /**
159e94fdbd7STakashi Iwai  * snd_power_ref - Take the reference count for power control
160e94fdbd7STakashi Iwai  * @card: sound card object
161e94fdbd7STakashi Iwai  *
162e94fdbd7STakashi Iwai  * The power_ref reference of the card is used for managing to block
163e94fdbd7STakashi Iwai  * the snd_power_sync_ref() operation.  This function increments the reference.
164e94fdbd7STakashi Iwai  * The counterpart snd_power_unref() has to be called appropriately later.
165e94fdbd7STakashi Iwai  */
166e94fdbd7STakashi Iwai static inline void snd_power_ref(struct snd_card *card)
167e94fdbd7STakashi Iwai {
168e94fdbd7STakashi Iwai 	atomic_inc(&card->power_ref);
169e94fdbd7STakashi Iwai }
170e94fdbd7STakashi Iwai 
171e94fdbd7STakashi Iwai /**
172e94fdbd7STakashi Iwai  * snd_power_unref - Release the reference count for power control
173e94fdbd7STakashi Iwai  * @card: sound card object
174e94fdbd7STakashi Iwai  */
175e94fdbd7STakashi Iwai static inline void snd_power_unref(struct snd_card *card)
176e94fdbd7STakashi Iwai {
177e94fdbd7STakashi Iwai 	if (atomic_dec_and_test(&card->power_ref))
178e94fdbd7STakashi Iwai 		wake_up(&card->power_ref_sleep);
179e94fdbd7STakashi Iwai }
180e94fdbd7STakashi Iwai 
181e94fdbd7STakashi Iwai /**
182e94fdbd7STakashi Iwai  * snd_power_sync_ref - wait until the card power_ref is freed
183e94fdbd7STakashi Iwai  * @card: sound card object
184e94fdbd7STakashi Iwai  *
185e94fdbd7STakashi Iwai  * This function is used to synchronize with the pending power_ref being
186e94fdbd7STakashi Iwai  * released.
187e94fdbd7STakashi Iwai  */
188e94fdbd7STakashi Iwai static inline void snd_power_sync_ref(struct snd_card *card)
189e94fdbd7STakashi Iwai {
190e94fdbd7STakashi Iwai 	wait_event(card->power_ref_sleep, !atomic_read(&card->power_ref));
191e94fdbd7STakashi Iwai }
192e94fdbd7STakashi Iwai 
193d5750f67SHenrik Kretzschmar /* init.c */
194b6cc78daSTakashi Iwai int snd_power_wait(struct snd_card *card);
195e94fdbd7STakashi Iwai int snd_power_ref_and_wait(struct snd_card *card);
196d5750f67SHenrik Kretzschmar 
1971da177e4SLinus Torvalds #else /* ! CONFIG_PM */
1981da177e4SLinus Torvalds 
199b6cc78daSTakashi Iwai static inline int snd_power_wait(struct snd_card *card) { return 0; }
200e94fdbd7STakashi Iwai static inline void snd_power_ref(struct snd_card *card) {}
201e94fdbd7STakashi Iwai static inline void snd_power_unref(struct snd_card *card) {}
202e94fdbd7STakashi Iwai static inline int snd_power_ref_and_wait(struct snd_card *card) { return 0; }
203e94fdbd7STakashi Iwai static inline void snd_power_sync_ref(struct snd_card *card) {}
204363129eaSMike Frysinger #define snd_power_get_state(card)	({ (void)(card); SNDRV_CTL_POWER_D0; })
2051da177e4SLinus Torvalds #define snd_power_change_state(card, state)	do { (void)(card); } while (0)
2061da177e4SLinus Torvalds 
2071da177e4SLinus Torvalds #endif /* CONFIG_PM */
2081da177e4SLinus Torvalds 
209512bbd6aSTakashi Iwai struct snd_minor {
2102af677fcSClemens Ladisch 	int type;			/* SNDRV_DEVICE_TYPE_XXX */
2116983b724SClemens Ladisch 	int card;			/* card number */
2121da177e4SLinus Torvalds 	int device;			/* device number */
21399ac48f5SArjan van de Ven 	const struct file_operations *f_ops;	/* file operations */
214f87135f5SClemens Ladisch 	void *private_data;		/* private data for f_ops->open */
215d80f19faSGreg Kroah-Hartman 	struct device *dev;		/* device for sysfs */
216a0830dbdSTakashi Iwai 	struct snd_card *card_ptr;	/* assigned card instance */
2171da177e4SLinus Torvalds };
2181da177e4SLinus Torvalds 
2197d2aae1eSTakashi Iwai /* return a device pointer linked to each sound device as a parent */
2207d2aae1eSTakashi Iwai static inline struct device *snd_card_get_device_link(struct snd_card *card)
2217d2aae1eSTakashi Iwai {
2228bfb181cSTakashi Iwai 	return card ? &card->card_dev : NULL;
2237d2aae1eSTakashi Iwai }
2247d2aae1eSTakashi Iwai 
2251da177e4SLinus Torvalds /* sound.c */
2261da177e4SLinus Torvalds 
227f1902860SClemens Ladisch extern int snd_major;
2281da177e4SLinus Torvalds extern int snd_ecards_limit;
229d80f19faSGreg Kroah-Hartman extern struct class *sound_class;
2302d670ea2SHui Wang #ifdef CONFIG_SND_DEBUG
2312d670ea2SHui Wang extern struct dentry *sound_debugfs_root;
2322d670ea2SHui Wang #endif
2331da177e4SLinus Torvalds 
2341da177e4SLinus Torvalds void snd_request_card(int card);
2351da177e4SLinus Torvalds 
2364b440be6STakashi Iwai void snd_device_initialize(struct device *dev, struct snd_card *card);
2374b440be6STakashi Iwai 
23840a4b263STakashi Iwai int snd_register_device(int type, struct snd_card *card, int dev,
23912b131c4SJohannes Berg 			const struct file_operations *f_ops,
24040a4b263STakashi Iwai 			void *private_data, struct device *device);
24140a4b263STakashi Iwai int snd_unregister_device(struct device *dev);
242f87135f5SClemens Ladisch void *snd_lookup_minor_data(unsigned int minor, int type);
2431da177e4SLinus Torvalds 
2441da177e4SLinus Torvalds #ifdef CONFIG_SND_OSSEMUL
2452af677fcSClemens Ladisch int snd_register_oss_device(int type, struct snd_card *card, int dev,
24680d7d771STakashi Iwai 			    const struct file_operations *f_ops, void *private_data);
247512bbd6aSTakashi Iwai int snd_unregister_oss_device(int type, struct snd_card *card, int dev);
248f87135f5SClemens Ladisch void *snd_lookup_oss_minor_data(unsigned int minor, int type);
2491da177e4SLinus Torvalds #endif
2501da177e4SLinus Torvalds 
2511da177e4SLinus Torvalds int snd_minor_info_init(void);
2521da177e4SLinus Torvalds 
2531da177e4SLinus Torvalds /* sound_oss.c */
2541da177e4SLinus Torvalds 
2551da177e4SLinus Torvalds #ifdef CONFIG_SND_OSSEMUL
2561da177e4SLinus Torvalds int snd_minor_info_oss_init(void);
2571da177e4SLinus Torvalds #else
258ad5fada5SPavel Machek static inline int snd_minor_info_oss_init(void) { return 0; }
2591da177e4SLinus Torvalds #endif
2601da177e4SLinus Torvalds 
2611da177e4SLinus Torvalds /* memory.c */
2621da177e4SLinus Torvalds 
2631da177e4SLinus Torvalds int copy_to_user_fromio(void __user *dst, const volatile void __iomem *src, size_t count);
2641da177e4SLinus Torvalds int copy_from_user_toio(volatile void __iomem *dst, const void __user *src, size_t count);
2651da177e4SLinus Torvalds 
2661da177e4SLinus Torvalds /* init.c */
2671da177e4SLinus Torvalds 
268746df948STakashi Iwai int snd_card_locked(int card);
2696d2412b8STakashi Iwai #if IS_ENABLED(CONFIG_SND_MIXER_OSS)
2701da177e4SLinus Torvalds #define SND_MIXER_OSS_NOTIFY_REGISTER	0
2711da177e4SLinus Torvalds #define SND_MIXER_OSS_NOTIFY_DISCONNECT	1
2721da177e4SLinus Torvalds #define SND_MIXER_OSS_NOTIFY_FREE	2
273512bbd6aSTakashi Iwai extern int (*snd_mixer_oss_notify_callback)(struct snd_card *card, int cmd);
2741da177e4SLinus Torvalds #endif
2751da177e4SLinus Torvalds 
276393aa9c1STakashi Iwai int snd_card_new(struct device *parent, int idx, const char *xid,
27753fb1e63STakashi Iwai 		 struct module *module, int extra_size,
27853fb1e63STakashi Iwai 		 struct snd_card **card_ret);
279e8ad415bSTakashi Iwai int snd_devm_card_new(struct device *parent, int idx, const char *xid,
280e8ad415bSTakashi Iwai 		      struct module *module, size_t extra_size,
281e8ad415bSTakashi Iwai 		      struct snd_card **card_ret);
28253fb1e63STakashi Iwai 
283512bbd6aSTakashi Iwai int snd_card_disconnect(struct snd_card *card);
284c44027c8STakashi Iwai void snd_card_disconnect_sync(struct snd_card *card);
285512bbd6aSTakashi Iwai int snd_card_free(struct snd_card *card);
286c461482cSTakashi Iwai int snd_card_free_when_closed(struct snd_card *card);
287*fee2b871STakashi Iwai int snd_card_free_on_error(struct device *dev, int ret);
28810a8ebbbSJaroslav Kysela void snd_card_set_id(struct snd_card *card, const char *id);
289512bbd6aSTakashi Iwai int snd_card_register(struct snd_card *card);
2901da177e4SLinus Torvalds int snd_card_info_init(void);
2916bbc7fedSTakashi Iwai int snd_card_add_dev_attr(struct snd_card *card,
2926bbc7fedSTakashi Iwai 			  const struct attribute_group *group);
293512bbd6aSTakashi Iwai int snd_component_add(struct snd_card *card, const char *component);
294512bbd6aSTakashi Iwai int snd_card_file_add(struct snd_card *card, struct file *file);
295512bbd6aSTakashi Iwai int snd_card_file_remove(struct snd_card *card, struct file *file);
296f4fa9689STakashi Iwai 
297f4fa9689STakashi Iwai struct snd_card *snd_card_ref(int card);
298f4fa9689STakashi Iwai 
299f4fa9689STakashi Iwai /**
300f4fa9689STakashi Iwai  * snd_card_unref - Unreference the card object
301f4fa9689STakashi Iwai  * @card: the card object to unreference
302f4fa9689STakashi Iwai  *
303f4fa9689STakashi Iwai  * Call this function for the card object that was obtained via snd_card_ref()
304f4fa9689STakashi Iwai  * or snd_lookup_minor_data().
305f4fa9689STakashi Iwai  */
306f4fa9689STakashi Iwai static inline void snd_card_unref(struct snd_card *card)
307f4fa9689STakashi Iwai {
308f4fa9689STakashi Iwai 	put_device(&card->card_dev);
309f4fa9689STakashi Iwai }
3101da177e4SLinus Torvalds 
3117d2aae1eSTakashi Iwai #define snd_card_set_dev(card, devptr) ((card)->dev = (devptr))
3121da177e4SLinus Torvalds 
3131da177e4SLinus Torvalds /* device.c */
3141da177e4SLinus Torvalds 
3159ce50543STakashi Iwai int snd_device_new(struct snd_card *card, enum snd_device_type type,
3168b575824STakashi Iwai 		   void *device_data, const 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);
319e086e303STakashi Iwai void snd_device_disconnect(struct snd_card *card, void *device_data);
320e086e303STakashi Iwai void snd_device_disconnect_all(struct snd_card *card);
32172620d60STakashi Iwai void snd_device_free(struct snd_card *card, void *device_data);
32272620d60STakashi Iwai void snd_device_free_all(struct snd_card *card);
323c208a533STakashi Iwai int snd_device_get_state(struct snd_card *card, void *device_data);
3241da177e4SLinus Torvalds 
3251da177e4SLinus Torvalds /* isadma.c */
3261da177e4SLinus Torvalds 
327276bd31cSAl Viro #ifdef CONFIG_ISA_DMA_API
3281da177e4SLinus Torvalds #define DMA_MODE_NO_ENABLE	0x0100
3291da177e4SLinus Torvalds 
3301da177e4SLinus Torvalds void snd_dma_program(unsigned long dma, unsigned long addr, unsigned int size, unsigned short mode);
3311da177e4SLinus Torvalds void snd_dma_disable(unsigned long dma);
3321da177e4SLinus Torvalds unsigned int snd_dma_pointer(unsigned long dma, unsigned int size);
333c2b94954STakashi Iwai int snd_devm_request_dma(struct device *dev, int dma, const char *name);
334276bd31cSAl Viro #endif
3351da177e4SLinus Torvalds 
3361da177e4SLinus Torvalds /* misc.c */
337b709e574STakashi Iwai struct resource;
338b1d5776dSTakashi Iwai void release_and_free_resource(struct resource *res);
3391da177e4SLinus Torvalds 
3401da177e4SLinus Torvalds /* --- */
3411da177e4SLinus Torvalds 
342fae3d88aSFengguang Wu /* sound printk debug levels */
343fae3d88aSFengguang Wu enum {
344fae3d88aSFengguang Wu 	SND_PR_ALWAYS,
345fae3d88aSFengguang Wu 	SND_PR_DEBUG,
346fae3d88aSFengguang Wu 	SND_PR_VERBOSE,
347fae3d88aSFengguang Wu };
348fae3d88aSFengguang Wu 
34936ce99c1STakashi Iwai #if defined(CONFIG_SND_DEBUG) || defined(CONFIG_SND_VERBOSE_PRINTK)
350b9075fa9SJoe Perches __printf(4, 5)
35136ce99c1STakashi Iwai void __snd_printk(unsigned int level, const char *file, int line,
352b9075fa9SJoe Perches 		  const char *format, ...);
35336ce99c1STakashi Iwai #else
35443e575faSTakashi Iwai #define __snd_printk(level, file, line, format, ...) \
35543e575faSTakashi Iwai 	printk(format, ##__VA_ARGS__)
35636ce99c1STakashi Iwai #endif
35736ce99c1STakashi Iwai 
3581da177e4SLinus Torvalds /**
3591da177e4SLinus Torvalds  * snd_printk - printk wrapper
3601da177e4SLinus Torvalds  * @fmt: format string
3611da177e4SLinus Torvalds  *
362f66fcedcSTakashi Iwai  * Works like printk() but prints the file and the line of the caller
3631da177e4SLinus Torvalds  * when configured with CONFIG_SND_VERBOSE_PRINTK.
3641da177e4SLinus Torvalds  */
36543e575faSTakashi Iwai #define snd_printk(fmt, ...) \
36643e575faSTakashi Iwai 	__snd_printk(0, __FILE__, __LINE__, fmt, ##__VA_ARGS__)
3671da177e4SLinus Torvalds 
3681da177e4SLinus Torvalds #ifdef CONFIG_SND_DEBUG
3691da177e4SLinus Torvalds /**
3701da177e4SLinus Torvalds  * snd_printd - debug printk
3710863afb3SMartin Waitz  * @fmt: format string
3721da177e4SLinus Torvalds  *
373edab938eSPavel Machek  * Works like snd_printk() for debugging purposes.
3741da177e4SLinus Torvalds  * Ignored when CONFIG_SND_DEBUG is not set.
3751da177e4SLinus Torvalds  */
37643e575faSTakashi Iwai #define snd_printd(fmt, ...) \
37743e575faSTakashi Iwai 	__snd_printk(1, __FILE__, __LINE__, fmt, ##__VA_ARGS__)
37843e575faSTakashi Iwai #define _snd_printd(level, fmt, ...) \
37943e575faSTakashi Iwai 	__snd_printk(level, __FILE__, __LINE__, fmt, ##__VA_ARGS__)
3807c22f1aaSTakashi Iwai 
381f66fcedcSTakashi Iwai /**
382f66fcedcSTakashi Iwai  * snd_BUG - give a BUG warning message and stack trace
383f66fcedcSTakashi Iwai  *
384f66fcedcSTakashi Iwai  * Calls WARN() if CONFIG_SND_DEBUG is set.
385f66fcedcSTakashi Iwai  * Ignored when CONFIG_SND_DEBUG is not set.
386f66fcedcSTakashi Iwai  */
387bdbecf50STakashi Iwai #define snd_BUG()		WARN(1, "BUG?\n")
388f66fcedcSTakashi Iwai 
389f66fcedcSTakashi Iwai /**
390f7b6603cSMauro Carvalho Chehab  * snd_printd_ratelimit - Suppress high rates of output when
391f7b6603cSMauro Carvalho Chehab  * 			  CONFIG_SND_DEBUG is enabled.
392bcbb1553STim Gardner  */
393bcbb1553STim Gardner #define snd_printd_ratelimit() printk_ratelimit()
394bcbb1553STim Gardner 
395bcbb1553STim Gardner /**
396f66fcedcSTakashi Iwai  * snd_BUG_ON - debugging check macro
397f66fcedcSTakashi Iwai  * @cond: condition to evaluate
398f66fcedcSTakashi Iwai  *
399d5702162SChristine Spang  * Has the same behavior as WARN_ON when CONFIG_SND_DEBUG is set,
400d5702162SChristine Spang  * otherwise just evaluates the conditional and returns the value.
401f66fcedcSTakashi Iwai  */
402d5702162SChristine Spang #define snd_BUG_ON(cond)	WARN_ON((cond))
4031da177e4SLinus Torvalds 
4041da177e4SLinus Torvalds #else /* !CONFIG_SND_DEBUG */
4051da177e4SLinus Torvalds 
40686b27237STakashi Iwai __printf(1, 2)
40786b27237STakashi Iwai static inline void snd_printd(const char *format, ...) {}
40886b27237STakashi Iwai __printf(2, 3)
40986b27237STakashi Iwai static inline void _snd_printd(int level, const char *format, ...) {}
41086b27237STakashi Iwai 
411fcef7836SAndrew Morton #define snd_BUG()			do { } while (0)
412d5702162SChristine Spang 
413d5702162SChristine Spang #define snd_BUG_ON(condition) ({ \
414d5702162SChristine Spang 	int __ret_warn_on = !!(condition); \
415d5702162SChristine Spang 	unlikely(__ret_warn_on); \
416d5702162SChristine Spang })
4171da177e4SLinus Torvalds 
418bcbb1553STim Gardner static inline bool snd_printd_ratelimit(void) { return false; }
419bcbb1553STim Gardner 
4201da177e4SLinus Torvalds #endif /* CONFIG_SND_DEBUG */
4211da177e4SLinus Torvalds 
42262cf872aSTakashi Iwai #ifdef CONFIG_SND_DEBUG_VERBOSE
4231da177e4SLinus Torvalds /**
4241da177e4SLinus Torvalds  * snd_printdd - debug printk
4251da177e4SLinus Torvalds  * @format: format string
4261da177e4SLinus Torvalds  *
427edab938eSPavel Machek  * Works like snd_printk() for debugging purposes.
42862cf872aSTakashi Iwai  * Ignored when CONFIG_SND_DEBUG_VERBOSE is not set.
4291da177e4SLinus Torvalds  */
43043e575faSTakashi Iwai #define snd_printdd(format, ...) \
43143e575faSTakashi Iwai 	__snd_printk(2, __FILE__, __LINE__, format, ##__VA_ARGS__)
4321da177e4SLinus Torvalds #else
43386b27237STakashi Iwai __printf(1, 2)
43486b27237STakashi Iwai static inline void snd_printdd(const char *format, ...) {}
4351da177e4SLinus Torvalds #endif
4361da177e4SLinus Torvalds 
4371da177e4SLinus Torvalds 
4381da177e4SLinus Torvalds #define SNDRV_OSS_VERSION         ((3<<16)|(8<<8)|(1<<4)|(0))	/* 3.8.1a */
4391da177e4SLinus Torvalds 
4401da177e4SLinus Torvalds /* for easier backward-porting */
4416d2412b8STakashi Iwai #if IS_ENABLED(CONFIG_GAMEPORT)
4421da177e4SLinus Torvalds #define gameport_set_dev_parent(gp,xdev) ((gp)->dev.parent = (xdev))
4431da177e4SLinus Torvalds #define gameport_set_port_data(gp,r) ((gp)->port_data = (r))
4441da177e4SLinus Torvalds #define gameport_get_port_data(gp) (gp)->port_data
4451da177e4SLinus Torvalds #endif
4461da177e4SLinus Torvalds 
447d9ea472cSTakashi Iwai /* PCI quirk list helper */
448d9ea472cSTakashi Iwai struct snd_pci_quirk {
449d9ea472cSTakashi Iwai 	unsigned short subvendor;	/* PCI subvendor ID */
450d9ea472cSTakashi Iwai 	unsigned short subdevice;	/* PCI subdevice ID */
4518bd4bb7aSTakashi Iwai 	unsigned short subdevice_mask;	/* bitmask to match */
452d9ea472cSTakashi Iwai 	int value;			/* value */
45362cf872aSTakashi Iwai #ifdef CONFIG_SND_DEBUG_VERBOSE
454d9ea472cSTakashi Iwai 	const char *name;		/* name of the device (optional) */
455d9ea472cSTakashi Iwai #endif
456d9ea472cSTakashi Iwai };
457d9ea472cSTakashi Iwai 
4588bd4bb7aSTakashi Iwai #define _SND_PCI_QUIRK_ID_MASK(vend, mask, dev)	\
4598bd4bb7aSTakashi Iwai 	.subvendor = (vend), .subdevice = (dev), .subdevice_mask = (mask)
460d9ea472cSTakashi Iwai #define _SND_PCI_QUIRK_ID(vend, dev) \
4618bd4bb7aSTakashi Iwai 	_SND_PCI_QUIRK_ID_MASK(vend, 0xffff, dev)
462d9ea472cSTakashi Iwai #define SND_PCI_QUIRK_ID(vend,dev) {_SND_PCI_QUIRK_ID(vend, dev)}
46362cf872aSTakashi Iwai #ifdef CONFIG_SND_DEBUG_VERBOSE
464d9ea472cSTakashi Iwai #define SND_PCI_QUIRK(vend,dev,xname,val) \
465d9ea472cSTakashi Iwai 	{_SND_PCI_QUIRK_ID(vend, dev), .value = (val), .name = (xname)}
4668bd4bb7aSTakashi Iwai #define SND_PCI_QUIRK_VENDOR(vend, xname, val)			\
4678bd4bb7aSTakashi Iwai 	{_SND_PCI_QUIRK_ID_MASK(vend, 0, 0), .value = (val), .name = (xname)}
4688bd4bb7aSTakashi Iwai #define SND_PCI_QUIRK_MASK(vend, mask, dev, xname, val)			\
4698bd4bb7aSTakashi Iwai 	{_SND_PCI_QUIRK_ID_MASK(vend, mask, dev),			\
4708bd4bb7aSTakashi Iwai 			.value = (val), .name = (xname)}
47186b27237STakashi Iwai #define snd_pci_quirk_name(q)	((q)->name)
472d9ea472cSTakashi Iwai #else
473d9ea472cSTakashi Iwai #define SND_PCI_QUIRK(vend,dev,xname,val) \
474d9ea472cSTakashi Iwai 	{_SND_PCI_QUIRK_ID(vend, dev), .value = (val)}
4758bd4bb7aSTakashi Iwai #define SND_PCI_QUIRK_MASK(vend, mask, dev, xname, val)			\
4768bd4bb7aSTakashi Iwai 	{_SND_PCI_QUIRK_ID_MASK(vend, mask, dev), .value = (val)}
4778bd4bb7aSTakashi Iwai #define SND_PCI_QUIRK_VENDOR(vend, xname, val)			\
4788bd4bb7aSTakashi Iwai 	{_SND_PCI_QUIRK_ID_MASK(vend, 0, 0), .value = (val)}
47986b27237STakashi Iwai #define snd_pci_quirk_name(q)	""
480d9ea472cSTakashi Iwai #endif
481d9ea472cSTakashi Iwai 
482f0a220deSDylan Reid #ifdef CONFIG_PCI
483d9ea472cSTakashi Iwai const struct snd_pci_quirk *
484d9ea472cSTakashi Iwai snd_pci_quirk_lookup(struct pci_dev *pci, const struct snd_pci_quirk *list);
485d9ea472cSTakashi Iwai 
486d1458279STakashi Iwai const struct snd_pci_quirk *
487d1458279STakashi Iwai snd_pci_quirk_lookup_id(u16 vendor, u16 device,
488d1458279STakashi Iwai 			const struct snd_pci_quirk *list);
489f0a220deSDylan Reid #else
490f0a220deSDylan Reid static inline const struct snd_pci_quirk *
491f0a220deSDylan Reid snd_pci_quirk_lookup(struct pci_dev *pci, const struct snd_pci_quirk *list)
492f0a220deSDylan Reid {
493f0a220deSDylan Reid 	return NULL;
494f0a220deSDylan Reid }
495f0a220deSDylan Reid 
496f0a220deSDylan Reid static inline const struct snd_pci_quirk *
497f0a220deSDylan Reid snd_pci_quirk_lookup_id(u16 vendor, u16 device,
498f0a220deSDylan Reid 			const struct snd_pci_quirk *list)
499f0a220deSDylan Reid {
500f0a220deSDylan Reid 	return NULL;
501f0a220deSDylan Reid }
5028422fa11SAxel Lin #endif
503d9ea472cSTakashi Iwai 
5041da177e4SLinus Torvalds #endif /* __SOUND_CORE_H */
505