1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-or-later */
2*4882a593Smuzhiyun #ifndef __SOUND_CORE_H
3*4882a593Smuzhiyun #define __SOUND_CORE_H
4*4882a593Smuzhiyun
5*4882a593Smuzhiyun /*
6*4882a593Smuzhiyun * Main header file for the ALSA driver
7*4882a593Smuzhiyun * Copyright (c) 1994-2001 by Jaroslav Kysela <perex@perex.cz>
8*4882a593Smuzhiyun */
9*4882a593Smuzhiyun
10*4882a593Smuzhiyun #include <linux/device.h>
11*4882a593Smuzhiyun #include <linux/sched.h> /* wake_up() */
12*4882a593Smuzhiyun #include <linux/mutex.h> /* struct mutex */
13*4882a593Smuzhiyun #include <linux/rwsem.h> /* struct rw_semaphore */
14*4882a593Smuzhiyun #include <linux/pm.h> /* pm_message_t */
15*4882a593Smuzhiyun #include <linux/stringify.h>
16*4882a593Smuzhiyun #include <linux/printk.h>
17*4882a593Smuzhiyun #include <linux/android_kabi.h>
18*4882a593Smuzhiyun
19*4882a593Smuzhiyun /* number of supported soundcards */
20*4882a593Smuzhiyun #ifdef CONFIG_SND_DYNAMIC_MINORS
21*4882a593Smuzhiyun #define SNDRV_CARDS CONFIG_SND_MAX_CARDS
22*4882a593Smuzhiyun #else
23*4882a593Smuzhiyun #define SNDRV_CARDS 8 /* don't change - minor numbers */
24*4882a593Smuzhiyun #endif
25*4882a593Smuzhiyun
26*4882a593Smuzhiyun #define CONFIG_SND_MAJOR 116 /* standard configuration */
27*4882a593Smuzhiyun
28*4882a593Smuzhiyun /* forward declarations */
29*4882a593Smuzhiyun struct pci_dev;
30*4882a593Smuzhiyun struct module;
31*4882a593Smuzhiyun struct completion;
32*4882a593Smuzhiyun
33*4882a593Smuzhiyun /* device allocation stuff */
34*4882a593Smuzhiyun
35*4882a593Smuzhiyun /* type of the object used in snd_device_*()
36*4882a593Smuzhiyun * this also defines the calling order
37*4882a593Smuzhiyun */
38*4882a593Smuzhiyun enum snd_device_type {
39*4882a593Smuzhiyun SNDRV_DEV_LOWLEVEL,
40*4882a593Smuzhiyun SNDRV_DEV_INFO,
41*4882a593Smuzhiyun SNDRV_DEV_BUS,
42*4882a593Smuzhiyun SNDRV_DEV_CODEC,
43*4882a593Smuzhiyun SNDRV_DEV_PCM,
44*4882a593Smuzhiyun SNDRV_DEV_COMPRESS,
45*4882a593Smuzhiyun SNDRV_DEV_RAWMIDI,
46*4882a593Smuzhiyun SNDRV_DEV_TIMER,
47*4882a593Smuzhiyun SNDRV_DEV_SEQUENCER,
48*4882a593Smuzhiyun SNDRV_DEV_HWDEP,
49*4882a593Smuzhiyun SNDRV_DEV_JACK,
50*4882a593Smuzhiyun SNDRV_DEV_CONTROL, /* NOTE: this must be the last one */
51*4882a593Smuzhiyun };
52*4882a593Smuzhiyun
53*4882a593Smuzhiyun enum snd_device_state {
54*4882a593Smuzhiyun SNDRV_DEV_BUILD,
55*4882a593Smuzhiyun SNDRV_DEV_REGISTERED,
56*4882a593Smuzhiyun SNDRV_DEV_DISCONNECTED,
57*4882a593Smuzhiyun };
58*4882a593Smuzhiyun
59*4882a593Smuzhiyun struct snd_device;
60*4882a593Smuzhiyun
61*4882a593Smuzhiyun struct snd_device_ops {
62*4882a593Smuzhiyun int (*dev_free)(struct snd_device *dev);
63*4882a593Smuzhiyun int (*dev_register)(struct snd_device *dev);
64*4882a593Smuzhiyun int (*dev_disconnect)(struct snd_device *dev);
65*4882a593Smuzhiyun
66*4882a593Smuzhiyun ANDROID_KABI_RESERVE(1);
67*4882a593Smuzhiyun };
68*4882a593Smuzhiyun
69*4882a593Smuzhiyun struct snd_device {
70*4882a593Smuzhiyun struct list_head list; /* list of registered devices */
71*4882a593Smuzhiyun struct snd_card *card; /* card which holds this device */
72*4882a593Smuzhiyun enum snd_device_state state; /* state of the device */
73*4882a593Smuzhiyun enum snd_device_type type; /* device type */
74*4882a593Smuzhiyun void *device_data; /* device structure */
75*4882a593Smuzhiyun const struct snd_device_ops *ops; /* operations */
76*4882a593Smuzhiyun
77*4882a593Smuzhiyun ANDROID_KABI_RESERVE(1);
78*4882a593Smuzhiyun };
79*4882a593Smuzhiyun
80*4882a593Smuzhiyun #define snd_device(n) list_entry(n, struct snd_device, list)
81*4882a593Smuzhiyun
82*4882a593Smuzhiyun /* main structure for soundcard */
83*4882a593Smuzhiyun
84*4882a593Smuzhiyun struct snd_card {
85*4882a593Smuzhiyun int number; /* number of soundcard (index to
86*4882a593Smuzhiyun snd_cards) */
87*4882a593Smuzhiyun
88*4882a593Smuzhiyun char id[16]; /* id string of this card */
89*4882a593Smuzhiyun char driver[16]; /* driver name */
90*4882a593Smuzhiyun char shortname[32]; /* short name of this soundcard */
91*4882a593Smuzhiyun char longname[80]; /* name of this soundcard */
92*4882a593Smuzhiyun char irq_descr[32]; /* Interrupt description */
93*4882a593Smuzhiyun char mixername[80]; /* mixer name */
94*4882a593Smuzhiyun char components[128]; /* card components delimited with
95*4882a593Smuzhiyun space */
96*4882a593Smuzhiyun struct module *module; /* top-level module */
97*4882a593Smuzhiyun
98*4882a593Smuzhiyun void *private_data; /* private data for soundcard */
99*4882a593Smuzhiyun void (*private_free) (struct snd_card *card); /* callback for freeing of
100*4882a593Smuzhiyun private data */
101*4882a593Smuzhiyun struct list_head devices; /* devices */
102*4882a593Smuzhiyun
103*4882a593Smuzhiyun struct device ctl_dev; /* control device */
104*4882a593Smuzhiyun unsigned int last_numid; /* last used numeric ID */
105*4882a593Smuzhiyun struct rw_semaphore controls_rwsem; /* controls list lock */
106*4882a593Smuzhiyun rwlock_t ctl_files_rwlock; /* ctl_files list lock */
107*4882a593Smuzhiyun int controls_count; /* count of all controls */
108*4882a593Smuzhiyun int user_ctl_count; /* count of all user controls */
109*4882a593Smuzhiyun struct list_head controls; /* all controls for this card */
110*4882a593Smuzhiyun struct list_head ctl_files; /* active control files */
111*4882a593Smuzhiyun
112*4882a593Smuzhiyun struct snd_info_entry *proc_root; /* root for soundcard specific files */
113*4882a593Smuzhiyun struct proc_dir_entry *proc_root_link; /* number link to real id */
114*4882a593Smuzhiyun
115*4882a593Smuzhiyun struct list_head files_list; /* all files associated to this card */
116*4882a593Smuzhiyun struct snd_shutdown_f_ops *s_f_ops; /* file operations in the shutdown
117*4882a593Smuzhiyun state */
118*4882a593Smuzhiyun spinlock_t files_lock; /* lock the files for this card */
119*4882a593Smuzhiyun int shutdown; /* this card is going down */
120*4882a593Smuzhiyun struct completion *release_completion;
121*4882a593Smuzhiyun struct device *dev; /* device assigned to this card */
122*4882a593Smuzhiyun struct device card_dev; /* cardX object for sysfs */
123*4882a593Smuzhiyun const struct attribute_group *dev_groups[4]; /* assigned sysfs attr */
124*4882a593Smuzhiyun bool registered; /* card_dev is registered? */
125*4882a593Smuzhiyun int sync_irq; /* assigned irq, used for PCM sync */
126*4882a593Smuzhiyun wait_queue_head_t remove_sleep;
127*4882a593Smuzhiyun
128*4882a593Smuzhiyun size_t total_pcm_alloc_bytes; /* total amount of allocated buffers */
129*4882a593Smuzhiyun struct mutex memory_mutex; /* protection for the above */
130*4882a593Smuzhiyun
131*4882a593Smuzhiyun #ifdef CONFIG_PM
132*4882a593Smuzhiyun unsigned int power_state; /* power state */
133*4882a593Smuzhiyun wait_queue_head_t power_sleep;
134*4882a593Smuzhiyun #endif
135*4882a593Smuzhiyun
136*4882a593Smuzhiyun #if IS_ENABLED(CONFIG_SND_MIXER_OSS)
137*4882a593Smuzhiyun struct snd_mixer_oss *mixer_oss;
138*4882a593Smuzhiyun int mixer_oss_change_count;
139*4882a593Smuzhiyun #endif
140*4882a593Smuzhiyun
141*4882a593Smuzhiyun ANDROID_KABI_RESERVE(1);
142*4882a593Smuzhiyun ANDROID_KABI_RESERVE(2);
143*4882a593Smuzhiyun };
144*4882a593Smuzhiyun
145*4882a593Smuzhiyun #define dev_to_snd_card(p) container_of(p, struct snd_card, card_dev)
146*4882a593Smuzhiyun
147*4882a593Smuzhiyun #ifdef CONFIG_PM
snd_power_get_state(struct snd_card * card)148*4882a593Smuzhiyun static inline unsigned int snd_power_get_state(struct snd_card *card)
149*4882a593Smuzhiyun {
150*4882a593Smuzhiyun return card->power_state;
151*4882a593Smuzhiyun }
152*4882a593Smuzhiyun
snd_power_change_state(struct snd_card * card,unsigned int state)153*4882a593Smuzhiyun static inline void snd_power_change_state(struct snd_card *card, unsigned int state)
154*4882a593Smuzhiyun {
155*4882a593Smuzhiyun card->power_state = state;
156*4882a593Smuzhiyun wake_up(&card->power_sleep);
157*4882a593Smuzhiyun }
158*4882a593Smuzhiyun
159*4882a593Smuzhiyun /* init.c */
160*4882a593Smuzhiyun int snd_power_wait(struct snd_card *card, unsigned int power_state);
161*4882a593Smuzhiyun
162*4882a593Smuzhiyun #else /* ! CONFIG_PM */
163*4882a593Smuzhiyun
snd_power_wait(struct snd_card * card,unsigned int state)164*4882a593Smuzhiyun static inline int snd_power_wait(struct snd_card *card, unsigned int state) { return 0; }
165*4882a593Smuzhiyun #define snd_power_get_state(card) ({ (void)(card); SNDRV_CTL_POWER_D0; })
166*4882a593Smuzhiyun #define snd_power_change_state(card, state) do { (void)(card); } while (0)
167*4882a593Smuzhiyun
168*4882a593Smuzhiyun #endif /* CONFIG_PM */
169*4882a593Smuzhiyun
170*4882a593Smuzhiyun struct snd_minor {
171*4882a593Smuzhiyun int type; /* SNDRV_DEVICE_TYPE_XXX */
172*4882a593Smuzhiyun int card; /* card number */
173*4882a593Smuzhiyun int device; /* device number */
174*4882a593Smuzhiyun const struct file_operations *f_ops; /* file operations */
175*4882a593Smuzhiyun void *private_data; /* private data for f_ops->open */
176*4882a593Smuzhiyun struct device *dev; /* device for sysfs */
177*4882a593Smuzhiyun struct snd_card *card_ptr; /* assigned card instance */
178*4882a593Smuzhiyun
179*4882a593Smuzhiyun ANDROID_KABI_RESERVE(1);
180*4882a593Smuzhiyun };
181*4882a593Smuzhiyun
182*4882a593Smuzhiyun /* return a device pointer linked to each sound device as a parent */
snd_card_get_device_link(struct snd_card * card)183*4882a593Smuzhiyun static inline struct device *snd_card_get_device_link(struct snd_card *card)
184*4882a593Smuzhiyun {
185*4882a593Smuzhiyun return card ? &card->card_dev : NULL;
186*4882a593Smuzhiyun }
187*4882a593Smuzhiyun
188*4882a593Smuzhiyun /* sound.c */
189*4882a593Smuzhiyun
190*4882a593Smuzhiyun extern int snd_major;
191*4882a593Smuzhiyun extern int snd_ecards_limit;
192*4882a593Smuzhiyun extern struct class *sound_class;
193*4882a593Smuzhiyun
194*4882a593Smuzhiyun void snd_request_card(int card);
195*4882a593Smuzhiyun
196*4882a593Smuzhiyun void snd_device_initialize(struct device *dev, struct snd_card *card);
197*4882a593Smuzhiyun
198*4882a593Smuzhiyun int snd_register_device(int type, struct snd_card *card, int dev,
199*4882a593Smuzhiyun const struct file_operations *f_ops,
200*4882a593Smuzhiyun void *private_data, struct device *device);
201*4882a593Smuzhiyun int snd_unregister_device(struct device *dev);
202*4882a593Smuzhiyun void *snd_lookup_minor_data(unsigned int minor, int type);
203*4882a593Smuzhiyun
204*4882a593Smuzhiyun #ifdef CONFIG_SND_OSSEMUL
205*4882a593Smuzhiyun int snd_register_oss_device(int type, struct snd_card *card, int dev,
206*4882a593Smuzhiyun const struct file_operations *f_ops, void *private_data);
207*4882a593Smuzhiyun int snd_unregister_oss_device(int type, struct snd_card *card, int dev);
208*4882a593Smuzhiyun void *snd_lookup_oss_minor_data(unsigned int minor, int type);
209*4882a593Smuzhiyun #endif
210*4882a593Smuzhiyun
211*4882a593Smuzhiyun int snd_minor_info_init(void);
212*4882a593Smuzhiyun
213*4882a593Smuzhiyun /* sound_oss.c */
214*4882a593Smuzhiyun
215*4882a593Smuzhiyun #ifdef CONFIG_SND_OSSEMUL
216*4882a593Smuzhiyun int snd_minor_info_oss_init(void);
217*4882a593Smuzhiyun #else
snd_minor_info_oss_init(void)218*4882a593Smuzhiyun static inline int snd_minor_info_oss_init(void) { return 0; }
219*4882a593Smuzhiyun #endif
220*4882a593Smuzhiyun
221*4882a593Smuzhiyun /* memory.c */
222*4882a593Smuzhiyun
223*4882a593Smuzhiyun int copy_to_user_fromio(void __user *dst, const volatile void __iomem *src, size_t count);
224*4882a593Smuzhiyun int copy_from_user_toio(volatile void __iomem *dst, const void __user *src, size_t count);
225*4882a593Smuzhiyun
226*4882a593Smuzhiyun /* init.c */
227*4882a593Smuzhiyun
228*4882a593Smuzhiyun int snd_card_locked(int card);
229*4882a593Smuzhiyun #if IS_ENABLED(CONFIG_SND_MIXER_OSS)
230*4882a593Smuzhiyun #define SND_MIXER_OSS_NOTIFY_REGISTER 0
231*4882a593Smuzhiyun #define SND_MIXER_OSS_NOTIFY_DISCONNECT 1
232*4882a593Smuzhiyun #define SND_MIXER_OSS_NOTIFY_FREE 2
233*4882a593Smuzhiyun extern int (*snd_mixer_oss_notify_callback)(struct snd_card *card, int cmd);
234*4882a593Smuzhiyun #endif
235*4882a593Smuzhiyun
236*4882a593Smuzhiyun int snd_card_new(struct device *parent, int idx, const char *xid,
237*4882a593Smuzhiyun struct module *module, int extra_size,
238*4882a593Smuzhiyun struct snd_card **card_ret);
239*4882a593Smuzhiyun
240*4882a593Smuzhiyun int snd_card_disconnect(struct snd_card *card);
241*4882a593Smuzhiyun void snd_card_disconnect_sync(struct snd_card *card);
242*4882a593Smuzhiyun int snd_card_free(struct snd_card *card);
243*4882a593Smuzhiyun int snd_card_free_when_closed(struct snd_card *card);
244*4882a593Smuzhiyun void snd_card_set_id(struct snd_card *card, const char *id);
245*4882a593Smuzhiyun int snd_card_register(struct snd_card *card);
246*4882a593Smuzhiyun int snd_card_info_init(void);
247*4882a593Smuzhiyun int snd_card_add_dev_attr(struct snd_card *card,
248*4882a593Smuzhiyun const struct attribute_group *group);
249*4882a593Smuzhiyun int snd_component_add(struct snd_card *card, const char *component);
250*4882a593Smuzhiyun int snd_card_file_add(struct snd_card *card, struct file *file);
251*4882a593Smuzhiyun int snd_card_file_remove(struct snd_card *card, struct file *file);
252*4882a593Smuzhiyun
253*4882a593Smuzhiyun struct snd_card *snd_card_ref(int card);
254*4882a593Smuzhiyun
255*4882a593Smuzhiyun /**
256*4882a593Smuzhiyun * snd_card_unref - Unreference the card object
257*4882a593Smuzhiyun * @card: the card object to unreference
258*4882a593Smuzhiyun *
259*4882a593Smuzhiyun * Call this function for the card object that was obtained via snd_card_ref()
260*4882a593Smuzhiyun * or snd_lookup_minor_data().
261*4882a593Smuzhiyun */
snd_card_unref(struct snd_card * card)262*4882a593Smuzhiyun static inline void snd_card_unref(struct snd_card *card)
263*4882a593Smuzhiyun {
264*4882a593Smuzhiyun put_device(&card->card_dev);
265*4882a593Smuzhiyun }
266*4882a593Smuzhiyun
267*4882a593Smuzhiyun #define snd_card_set_dev(card, devptr) ((card)->dev = (devptr))
268*4882a593Smuzhiyun
269*4882a593Smuzhiyun /* device.c */
270*4882a593Smuzhiyun
271*4882a593Smuzhiyun int snd_device_new(struct snd_card *card, enum snd_device_type type,
272*4882a593Smuzhiyun void *device_data, const struct snd_device_ops *ops);
273*4882a593Smuzhiyun int snd_device_register(struct snd_card *card, void *device_data);
274*4882a593Smuzhiyun int snd_device_register_all(struct snd_card *card);
275*4882a593Smuzhiyun void snd_device_disconnect(struct snd_card *card, void *device_data);
276*4882a593Smuzhiyun void snd_device_disconnect_all(struct snd_card *card);
277*4882a593Smuzhiyun void snd_device_free(struct snd_card *card, void *device_data);
278*4882a593Smuzhiyun void snd_device_free_all(struct snd_card *card);
279*4882a593Smuzhiyun int snd_device_get_state(struct snd_card *card, void *device_data);
280*4882a593Smuzhiyun
281*4882a593Smuzhiyun /* isadma.c */
282*4882a593Smuzhiyun
283*4882a593Smuzhiyun #ifdef CONFIG_ISA_DMA_API
284*4882a593Smuzhiyun #define DMA_MODE_NO_ENABLE 0x0100
285*4882a593Smuzhiyun
286*4882a593Smuzhiyun void snd_dma_program(unsigned long dma, unsigned long addr, unsigned int size, unsigned short mode);
287*4882a593Smuzhiyun void snd_dma_disable(unsigned long dma);
288*4882a593Smuzhiyun unsigned int snd_dma_pointer(unsigned long dma, unsigned int size);
289*4882a593Smuzhiyun #endif
290*4882a593Smuzhiyun
291*4882a593Smuzhiyun /* misc.c */
292*4882a593Smuzhiyun struct resource;
293*4882a593Smuzhiyun void release_and_free_resource(struct resource *res);
294*4882a593Smuzhiyun
295*4882a593Smuzhiyun /* --- */
296*4882a593Smuzhiyun
297*4882a593Smuzhiyun /* sound printk debug levels */
298*4882a593Smuzhiyun enum {
299*4882a593Smuzhiyun SND_PR_ALWAYS,
300*4882a593Smuzhiyun SND_PR_DEBUG,
301*4882a593Smuzhiyun SND_PR_VERBOSE,
302*4882a593Smuzhiyun };
303*4882a593Smuzhiyun
304*4882a593Smuzhiyun #if defined(CONFIG_SND_DEBUG) || defined(CONFIG_SND_VERBOSE_PRINTK)
305*4882a593Smuzhiyun __printf(4, 5)
306*4882a593Smuzhiyun void __snd_printk(unsigned int level, const char *file, int line,
307*4882a593Smuzhiyun const char *format, ...);
308*4882a593Smuzhiyun #else
309*4882a593Smuzhiyun #define __snd_printk(level, file, line, format, ...) \
310*4882a593Smuzhiyun printk(format, ##__VA_ARGS__)
311*4882a593Smuzhiyun #endif
312*4882a593Smuzhiyun
313*4882a593Smuzhiyun /**
314*4882a593Smuzhiyun * snd_printk - printk wrapper
315*4882a593Smuzhiyun * @fmt: format string
316*4882a593Smuzhiyun *
317*4882a593Smuzhiyun * Works like printk() but prints the file and the line of the caller
318*4882a593Smuzhiyun * when configured with CONFIG_SND_VERBOSE_PRINTK.
319*4882a593Smuzhiyun */
320*4882a593Smuzhiyun #define snd_printk(fmt, ...) \
321*4882a593Smuzhiyun __snd_printk(0, __FILE__, __LINE__, fmt, ##__VA_ARGS__)
322*4882a593Smuzhiyun
323*4882a593Smuzhiyun #ifdef CONFIG_SND_DEBUG
324*4882a593Smuzhiyun /**
325*4882a593Smuzhiyun * snd_printd - debug printk
326*4882a593Smuzhiyun * @fmt: format string
327*4882a593Smuzhiyun *
328*4882a593Smuzhiyun * Works like snd_printk() for debugging purposes.
329*4882a593Smuzhiyun * Ignored when CONFIG_SND_DEBUG is not set.
330*4882a593Smuzhiyun */
331*4882a593Smuzhiyun #define snd_printd(fmt, ...) \
332*4882a593Smuzhiyun __snd_printk(1, __FILE__, __LINE__, fmt, ##__VA_ARGS__)
333*4882a593Smuzhiyun #define _snd_printd(level, fmt, ...) \
334*4882a593Smuzhiyun __snd_printk(level, __FILE__, __LINE__, fmt, ##__VA_ARGS__)
335*4882a593Smuzhiyun
336*4882a593Smuzhiyun /**
337*4882a593Smuzhiyun * snd_BUG - give a BUG warning message and stack trace
338*4882a593Smuzhiyun *
339*4882a593Smuzhiyun * Calls WARN() if CONFIG_SND_DEBUG is set.
340*4882a593Smuzhiyun * Ignored when CONFIG_SND_DEBUG is not set.
341*4882a593Smuzhiyun */
342*4882a593Smuzhiyun #define snd_BUG() WARN(1, "BUG?\n")
343*4882a593Smuzhiyun
344*4882a593Smuzhiyun /**
345*4882a593Smuzhiyun * snd_printd_ratelimit - Suppress high rates of output when
346*4882a593Smuzhiyun * CONFIG_SND_DEBUG is enabled.
347*4882a593Smuzhiyun */
348*4882a593Smuzhiyun #define snd_printd_ratelimit() printk_ratelimit()
349*4882a593Smuzhiyun
350*4882a593Smuzhiyun /**
351*4882a593Smuzhiyun * snd_BUG_ON - debugging check macro
352*4882a593Smuzhiyun * @cond: condition to evaluate
353*4882a593Smuzhiyun *
354*4882a593Smuzhiyun * Has the same behavior as WARN_ON when CONFIG_SND_DEBUG is set,
355*4882a593Smuzhiyun * otherwise just evaluates the conditional and returns the value.
356*4882a593Smuzhiyun */
357*4882a593Smuzhiyun #define snd_BUG_ON(cond) WARN_ON((cond))
358*4882a593Smuzhiyun
359*4882a593Smuzhiyun #else /* !CONFIG_SND_DEBUG */
360*4882a593Smuzhiyun
361*4882a593Smuzhiyun __printf(1, 2)
snd_printd(const char * format,...)362*4882a593Smuzhiyun static inline void snd_printd(const char *format, ...) {}
363*4882a593Smuzhiyun __printf(2, 3)
_snd_printd(int level,const char * format,...)364*4882a593Smuzhiyun static inline void _snd_printd(int level, const char *format, ...) {}
365*4882a593Smuzhiyun
366*4882a593Smuzhiyun #define snd_BUG() do { } while (0)
367*4882a593Smuzhiyun
368*4882a593Smuzhiyun #define snd_BUG_ON(condition) ({ \
369*4882a593Smuzhiyun int __ret_warn_on = !!(condition); \
370*4882a593Smuzhiyun unlikely(__ret_warn_on); \
371*4882a593Smuzhiyun })
372*4882a593Smuzhiyun
snd_printd_ratelimit(void)373*4882a593Smuzhiyun static inline bool snd_printd_ratelimit(void) { return false; }
374*4882a593Smuzhiyun
375*4882a593Smuzhiyun #endif /* CONFIG_SND_DEBUG */
376*4882a593Smuzhiyun
377*4882a593Smuzhiyun #ifdef CONFIG_SND_DEBUG_VERBOSE
378*4882a593Smuzhiyun /**
379*4882a593Smuzhiyun * snd_printdd - debug printk
380*4882a593Smuzhiyun * @format: format string
381*4882a593Smuzhiyun *
382*4882a593Smuzhiyun * Works like snd_printk() for debugging purposes.
383*4882a593Smuzhiyun * Ignored when CONFIG_SND_DEBUG_VERBOSE is not set.
384*4882a593Smuzhiyun */
385*4882a593Smuzhiyun #define snd_printdd(format, ...) \
386*4882a593Smuzhiyun __snd_printk(2, __FILE__, __LINE__, format, ##__VA_ARGS__)
387*4882a593Smuzhiyun #else
388*4882a593Smuzhiyun __printf(1, 2)
snd_printdd(const char * format,...)389*4882a593Smuzhiyun static inline void snd_printdd(const char *format, ...) {}
390*4882a593Smuzhiyun #endif
391*4882a593Smuzhiyun
392*4882a593Smuzhiyun
393*4882a593Smuzhiyun #define SNDRV_OSS_VERSION ((3<<16)|(8<<8)|(1<<4)|(0)) /* 3.8.1a */
394*4882a593Smuzhiyun
395*4882a593Smuzhiyun /* for easier backward-porting */
396*4882a593Smuzhiyun #if IS_ENABLED(CONFIG_GAMEPORT)
397*4882a593Smuzhiyun #define gameport_set_dev_parent(gp,xdev) ((gp)->dev.parent = (xdev))
398*4882a593Smuzhiyun #define gameport_set_port_data(gp,r) ((gp)->port_data = (r))
399*4882a593Smuzhiyun #define gameport_get_port_data(gp) (gp)->port_data
400*4882a593Smuzhiyun #endif
401*4882a593Smuzhiyun
402*4882a593Smuzhiyun /* PCI quirk list helper */
403*4882a593Smuzhiyun struct snd_pci_quirk {
404*4882a593Smuzhiyun unsigned short subvendor; /* PCI subvendor ID */
405*4882a593Smuzhiyun unsigned short subdevice; /* PCI subdevice ID */
406*4882a593Smuzhiyun unsigned short subdevice_mask; /* bitmask to match */
407*4882a593Smuzhiyun int value; /* value */
408*4882a593Smuzhiyun #ifdef CONFIG_SND_DEBUG_VERBOSE
409*4882a593Smuzhiyun const char *name; /* name of the device (optional) */
410*4882a593Smuzhiyun #endif
411*4882a593Smuzhiyun };
412*4882a593Smuzhiyun
413*4882a593Smuzhiyun #define _SND_PCI_QUIRK_ID_MASK(vend, mask, dev) \
414*4882a593Smuzhiyun .subvendor = (vend), .subdevice = (dev), .subdevice_mask = (mask)
415*4882a593Smuzhiyun #define _SND_PCI_QUIRK_ID(vend, dev) \
416*4882a593Smuzhiyun _SND_PCI_QUIRK_ID_MASK(vend, 0xffff, dev)
417*4882a593Smuzhiyun #define SND_PCI_QUIRK_ID(vend,dev) {_SND_PCI_QUIRK_ID(vend, dev)}
418*4882a593Smuzhiyun #ifdef CONFIG_SND_DEBUG_VERBOSE
419*4882a593Smuzhiyun #define SND_PCI_QUIRK(vend,dev,xname,val) \
420*4882a593Smuzhiyun {_SND_PCI_QUIRK_ID(vend, dev), .value = (val), .name = (xname)}
421*4882a593Smuzhiyun #define SND_PCI_QUIRK_VENDOR(vend, xname, val) \
422*4882a593Smuzhiyun {_SND_PCI_QUIRK_ID_MASK(vend, 0, 0), .value = (val), .name = (xname)}
423*4882a593Smuzhiyun #define SND_PCI_QUIRK_MASK(vend, mask, dev, xname, val) \
424*4882a593Smuzhiyun {_SND_PCI_QUIRK_ID_MASK(vend, mask, dev), \
425*4882a593Smuzhiyun .value = (val), .name = (xname)}
426*4882a593Smuzhiyun #define snd_pci_quirk_name(q) ((q)->name)
427*4882a593Smuzhiyun #else
428*4882a593Smuzhiyun #define SND_PCI_QUIRK(vend,dev,xname,val) \
429*4882a593Smuzhiyun {_SND_PCI_QUIRK_ID(vend, dev), .value = (val)}
430*4882a593Smuzhiyun #define SND_PCI_QUIRK_MASK(vend, mask, dev, xname, val) \
431*4882a593Smuzhiyun {_SND_PCI_QUIRK_ID_MASK(vend, mask, dev), .value = (val)}
432*4882a593Smuzhiyun #define SND_PCI_QUIRK_VENDOR(vend, xname, val) \
433*4882a593Smuzhiyun {_SND_PCI_QUIRK_ID_MASK(vend, 0, 0), .value = (val)}
434*4882a593Smuzhiyun #define snd_pci_quirk_name(q) ""
435*4882a593Smuzhiyun #endif
436*4882a593Smuzhiyun
437*4882a593Smuzhiyun #ifdef CONFIG_PCI
438*4882a593Smuzhiyun const struct snd_pci_quirk *
439*4882a593Smuzhiyun snd_pci_quirk_lookup(struct pci_dev *pci, const struct snd_pci_quirk *list);
440*4882a593Smuzhiyun
441*4882a593Smuzhiyun const struct snd_pci_quirk *
442*4882a593Smuzhiyun snd_pci_quirk_lookup_id(u16 vendor, u16 device,
443*4882a593Smuzhiyun const struct snd_pci_quirk *list);
444*4882a593Smuzhiyun #else
445*4882a593Smuzhiyun static inline const struct snd_pci_quirk *
snd_pci_quirk_lookup(struct pci_dev * pci,const struct snd_pci_quirk * list)446*4882a593Smuzhiyun snd_pci_quirk_lookup(struct pci_dev *pci, const struct snd_pci_quirk *list)
447*4882a593Smuzhiyun {
448*4882a593Smuzhiyun return NULL;
449*4882a593Smuzhiyun }
450*4882a593Smuzhiyun
451*4882a593Smuzhiyun static inline const struct snd_pci_quirk *
snd_pci_quirk_lookup_id(u16 vendor,u16 device,const struct snd_pci_quirk * list)452*4882a593Smuzhiyun snd_pci_quirk_lookup_id(u16 vendor, u16 device,
453*4882a593Smuzhiyun const struct snd_pci_quirk *list)
454*4882a593Smuzhiyun {
455*4882a593Smuzhiyun return NULL;
456*4882a593Smuzhiyun }
457*4882a593Smuzhiyun #endif
458*4882a593Smuzhiyun
459*4882a593Smuzhiyun /* async signal helpers */
460*4882a593Smuzhiyun struct snd_fasync;
461*4882a593Smuzhiyun
462*4882a593Smuzhiyun int snd_fasync_helper(int fd, struct file *file, int on,
463*4882a593Smuzhiyun struct snd_fasync **fasyncp);
464*4882a593Smuzhiyun void snd_kill_fasync(struct snd_fasync *fasync, int signal, int poll);
465*4882a593Smuzhiyun void snd_fasync_free(struct snd_fasync *fasync);
466*4882a593Smuzhiyun
467*4882a593Smuzhiyun #endif /* __SOUND_CORE_H */
468