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 */ 1031da177e4SLinus Torvalds int user_ctl_count; /* count of all 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? */ 120fabb26dcSTakashi Iwai int sync_irq; /* assigned irq, used for PCM sync */ 121c44027c8STakashi Iwai wait_queue_head_t remove_sleep; 1221da177e4SLinus Torvalds 123d4cfb30fSTakashi Iwai size_t total_pcm_alloc_bytes; /* total amount of allocated buffers */ 124d4cfb30fSTakashi Iwai struct mutex memory_mutex; /* protection for the above */ 125d4cfb30fSTakashi Iwai 1261da177e4SLinus Torvalds #ifdef CONFIG_PM 1271da177e4SLinus Torvalds unsigned int power_state; /* power state */ 1281da177e4SLinus Torvalds wait_queue_head_t power_sleep; 1291da177e4SLinus Torvalds #endif 1301da177e4SLinus Torvalds 1316d2412b8STakashi Iwai #if IS_ENABLED(CONFIG_SND_MIXER_OSS) 132512bbd6aSTakashi Iwai struct snd_mixer_oss *mixer_oss; 1331da177e4SLinus Torvalds int mixer_oss_change_count; 1341da177e4SLinus Torvalds #endif 1351da177e4SLinus Torvalds }; 1361da177e4SLinus Torvalds 1378bfb181cSTakashi Iwai #define dev_to_snd_card(p) container_of(p, struct snd_card, card_dev) 1388bfb181cSTakashi Iwai 1391da177e4SLinus Torvalds #ifdef CONFIG_PM 140512bbd6aSTakashi Iwai static inline unsigned int snd_power_get_state(struct snd_card *card) 1411da177e4SLinus Torvalds { 1421da177e4SLinus Torvalds return card->power_state; 1431da177e4SLinus Torvalds } 1441da177e4SLinus Torvalds 145512bbd6aSTakashi Iwai static inline void snd_power_change_state(struct snd_card *card, unsigned int state) 1461da177e4SLinus Torvalds { 1471da177e4SLinus Torvalds card->power_state = state; 1481da177e4SLinus Torvalds wake_up(&card->power_sleep); 1491da177e4SLinus Torvalds } 150d5750f67SHenrik Kretzschmar 151d5750f67SHenrik Kretzschmar /* init.c */ 152cbac4b0cSTakashi Iwai int snd_power_wait(struct snd_card *card, unsigned int power_state); 153d5750f67SHenrik Kretzschmar 1541da177e4SLinus Torvalds #else /* ! CONFIG_PM */ 1551da177e4SLinus Torvalds 1566fdb94bdSLinus Torvalds static inline int snd_power_wait(struct snd_card *card, unsigned int state) { return 0; } 157363129eaSMike Frysinger #define snd_power_get_state(card) ({ (void)(card); SNDRV_CTL_POWER_D0; }) 1581da177e4SLinus Torvalds #define snd_power_change_state(card, state) do { (void)(card); } while (0) 1591da177e4SLinus Torvalds 1601da177e4SLinus Torvalds #endif /* CONFIG_PM */ 1611da177e4SLinus Torvalds 162512bbd6aSTakashi Iwai struct snd_minor { 1632af677fcSClemens Ladisch int type; /* SNDRV_DEVICE_TYPE_XXX */ 1646983b724SClemens Ladisch int card; /* card number */ 1651da177e4SLinus Torvalds int device; /* device number */ 16699ac48f5SArjan van de Ven const struct file_operations *f_ops; /* file operations */ 167f87135f5SClemens Ladisch void *private_data; /* private data for f_ops->open */ 168d80f19faSGreg Kroah-Hartman struct device *dev; /* device for sysfs */ 169a0830dbdSTakashi Iwai struct snd_card *card_ptr; /* assigned card instance */ 1701da177e4SLinus Torvalds }; 1711da177e4SLinus Torvalds 1727d2aae1eSTakashi Iwai /* return a device pointer linked to each sound device as a parent */ 1737d2aae1eSTakashi Iwai static inline struct device *snd_card_get_device_link(struct snd_card *card) 1747d2aae1eSTakashi Iwai { 1758bfb181cSTakashi Iwai return card ? &card->card_dev : NULL; 1767d2aae1eSTakashi Iwai } 1777d2aae1eSTakashi Iwai 1781da177e4SLinus Torvalds /* sound.c */ 1791da177e4SLinus Torvalds 180f1902860SClemens Ladisch extern int snd_major; 1811da177e4SLinus Torvalds extern int snd_ecards_limit; 182d80f19faSGreg Kroah-Hartman extern struct class *sound_class; 1831da177e4SLinus Torvalds 1841da177e4SLinus Torvalds void snd_request_card(int card); 1851da177e4SLinus Torvalds 1864b440be6STakashi Iwai void snd_device_initialize(struct device *dev, struct snd_card *card); 1874b440be6STakashi Iwai 18840a4b263STakashi Iwai int snd_register_device(int type, struct snd_card *card, int dev, 18912b131c4SJohannes Berg const struct file_operations *f_ops, 19040a4b263STakashi Iwai void *private_data, struct device *device); 19140a4b263STakashi Iwai int snd_unregister_device(struct device *dev); 192f87135f5SClemens Ladisch void *snd_lookup_minor_data(unsigned int minor, int type); 1931da177e4SLinus Torvalds 1941da177e4SLinus Torvalds #ifdef CONFIG_SND_OSSEMUL 1952af677fcSClemens Ladisch int snd_register_oss_device(int type, struct snd_card *card, int dev, 19680d7d771STakashi Iwai const struct file_operations *f_ops, void *private_data); 197512bbd6aSTakashi Iwai int snd_unregister_oss_device(int type, struct snd_card *card, int dev); 198f87135f5SClemens Ladisch void *snd_lookup_oss_minor_data(unsigned int minor, int type); 1991da177e4SLinus Torvalds #endif 2001da177e4SLinus Torvalds 2011da177e4SLinus Torvalds int snd_minor_info_init(void); 2021da177e4SLinus Torvalds 2031da177e4SLinus Torvalds /* sound_oss.c */ 2041da177e4SLinus Torvalds 2051da177e4SLinus Torvalds #ifdef CONFIG_SND_OSSEMUL 2061da177e4SLinus Torvalds int snd_minor_info_oss_init(void); 2071da177e4SLinus Torvalds #else 208ad5fada5SPavel Machek static inline int snd_minor_info_oss_init(void) { return 0; } 2091da177e4SLinus Torvalds #endif 2101da177e4SLinus Torvalds 2111da177e4SLinus Torvalds /* memory.c */ 2121da177e4SLinus Torvalds 2131da177e4SLinus Torvalds int copy_to_user_fromio(void __user *dst, const volatile void __iomem *src, size_t count); 2141da177e4SLinus Torvalds int copy_from_user_toio(volatile void __iomem *dst, const void __user *src, size_t count); 2151da177e4SLinus Torvalds 2161da177e4SLinus Torvalds /* init.c */ 2171da177e4SLinus Torvalds 218746df948STakashi Iwai int snd_card_locked(int card); 2196d2412b8STakashi Iwai #if IS_ENABLED(CONFIG_SND_MIXER_OSS) 2201da177e4SLinus Torvalds #define SND_MIXER_OSS_NOTIFY_REGISTER 0 2211da177e4SLinus Torvalds #define SND_MIXER_OSS_NOTIFY_DISCONNECT 1 2221da177e4SLinus Torvalds #define SND_MIXER_OSS_NOTIFY_FREE 2 223512bbd6aSTakashi Iwai extern int (*snd_mixer_oss_notify_callback)(struct snd_card *card, int cmd); 2241da177e4SLinus Torvalds #endif 2251da177e4SLinus Torvalds 226393aa9c1STakashi Iwai int snd_card_new(struct device *parent, int idx, const char *xid, 22753fb1e63STakashi Iwai struct module *module, int extra_size, 22853fb1e63STakashi Iwai struct snd_card **card_ret); 22953fb1e63STakashi Iwai 230512bbd6aSTakashi Iwai int snd_card_disconnect(struct snd_card *card); 231c44027c8STakashi Iwai void snd_card_disconnect_sync(struct snd_card *card); 232512bbd6aSTakashi Iwai int snd_card_free(struct snd_card *card); 233c461482cSTakashi Iwai int snd_card_free_when_closed(struct snd_card *card); 23410a8ebbbSJaroslav Kysela void snd_card_set_id(struct snd_card *card, const char *id); 235512bbd6aSTakashi Iwai int snd_card_register(struct snd_card *card); 2361da177e4SLinus Torvalds int snd_card_info_init(void); 2376bbc7fedSTakashi Iwai int snd_card_add_dev_attr(struct snd_card *card, 2386bbc7fedSTakashi Iwai const struct attribute_group *group); 239512bbd6aSTakashi Iwai int snd_component_add(struct snd_card *card, const char *component); 240512bbd6aSTakashi Iwai int snd_card_file_add(struct snd_card *card, struct file *file); 241512bbd6aSTakashi Iwai int snd_card_file_remove(struct snd_card *card, struct file *file); 242f4fa9689STakashi Iwai 243f4fa9689STakashi Iwai struct snd_card *snd_card_ref(int card); 244f4fa9689STakashi Iwai 245f4fa9689STakashi Iwai /** 246f4fa9689STakashi Iwai * snd_card_unref - Unreference the card object 247f4fa9689STakashi Iwai * @card: the card object to unreference 248f4fa9689STakashi Iwai * 249f4fa9689STakashi Iwai * Call this function for the card object that was obtained via snd_card_ref() 250f4fa9689STakashi Iwai * or snd_lookup_minor_data(). 251f4fa9689STakashi Iwai */ 252f4fa9689STakashi Iwai static inline void snd_card_unref(struct snd_card *card) 253f4fa9689STakashi Iwai { 254f4fa9689STakashi Iwai put_device(&card->card_dev); 255f4fa9689STakashi Iwai } 2561da177e4SLinus Torvalds 2577d2aae1eSTakashi Iwai #define snd_card_set_dev(card, devptr) ((card)->dev = (devptr)) 2581da177e4SLinus Torvalds 2591da177e4SLinus Torvalds /* device.c */ 2601da177e4SLinus Torvalds 2619ce50543STakashi Iwai int snd_device_new(struct snd_card *card, enum snd_device_type type, 2628b575824STakashi Iwai void *device_data, const struct snd_device_ops *ops); 263512bbd6aSTakashi Iwai int snd_device_register(struct snd_card *card, void *device_data); 264512bbd6aSTakashi Iwai int snd_device_register_all(struct snd_card *card); 265e086e303STakashi Iwai void snd_device_disconnect(struct snd_card *card, void *device_data); 266e086e303STakashi Iwai void snd_device_disconnect_all(struct snd_card *card); 26772620d60STakashi Iwai void snd_device_free(struct snd_card *card, void *device_data); 26872620d60STakashi Iwai void snd_device_free_all(struct snd_card *card); 269c208a533STakashi Iwai int snd_device_get_state(struct snd_card *card, void *device_data); 2701da177e4SLinus Torvalds 2711da177e4SLinus Torvalds /* isadma.c */ 2721da177e4SLinus Torvalds 273276bd31cSAl Viro #ifdef CONFIG_ISA_DMA_API 2741da177e4SLinus Torvalds #define DMA_MODE_NO_ENABLE 0x0100 2751da177e4SLinus Torvalds 2761da177e4SLinus Torvalds void snd_dma_program(unsigned long dma, unsigned long addr, unsigned int size, unsigned short mode); 2771da177e4SLinus Torvalds void snd_dma_disable(unsigned long dma); 2781da177e4SLinus Torvalds unsigned int snd_dma_pointer(unsigned long dma, unsigned int size); 279276bd31cSAl Viro #endif 2801da177e4SLinus Torvalds 2811da177e4SLinus Torvalds /* misc.c */ 282b709e574STakashi Iwai struct resource; 283b1d5776dSTakashi Iwai void release_and_free_resource(struct resource *res); 2841da177e4SLinus Torvalds 2851da177e4SLinus Torvalds /* --- */ 2861da177e4SLinus Torvalds 287fae3d88aSFengguang Wu /* sound printk debug levels */ 288fae3d88aSFengguang Wu enum { 289fae3d88aSFengguang Wu SND_PR_ALWAYS, 290fae3d88aSFengguang Wu SND_PR_DEBUG, 291fae3d88aSFengguang Wu SND_PR_VERBOSE, 292fae3d88aSFengguang Wu }; 293fae3d88aSFengguang Wu 29436ce99c1STakashi Iwai #if defined(CONFIG_SND_DEBUG) || defined(CONFIG_SND_VERBOSE_PRINTK) 295b9075fa9SJoe Perches __printf(4, 5) 29636ce99c1STakashi Iwai void __snd_printk(unsigned int level, const char *file, int line, 297b9075fa9SJoe Perches const char *format, ...); 29836ce99c1STakashi Iwai #else 29943e575faSTakashi Iwai #define __snd_printk(level, file, line, format, ...) \ 30043e575faSTakashi Iwai printk(format, ##__VA_ARGS__) 30136ce99c1STakashi Iwai #endif 30236ce99c1STakashi Iwai 3031da177e4SLinus Torvalds /** 3041da177e4SLinus Torvalds * snd_printk - printk wrapper 3051da177e4SLinus Torvalds * @fmt: format string 3061da177e4SLinus Torvalds * 307f66fcedcSTakashi Iwai * Works like printk() but prints the file and the line of the caller 3081da177e4SLinus Torvalds * when configured with CONFIG_SND_VERBOSE_PRINTK. 3091da177e4SLinus Torvalds */ 31043e575faSTakashi Iwai #define snd_printk(fmt, ...) \ 31143e575faSTakashi Iwai __snd_printk(0, __FILE__, __LINE__, fmt, ##__VA_ARGS__) 3121da177e4SLinus Torvalds 3131da177e4SLinus Torvalds #ifdef CONFIG_SND_DEBUG 3141da177e4SLinus Torvalds /** 3151da177e4SLinus Torvalds * snd_printd - debug printk 3160863afb3SMartin Waitz * @fmt: format string 3171da177e4SLinus Torvalds * 318edab938eSPavel Machek * Works like snd_printk() for debugging purposes. 3191da177e4SLinus Torvalds * Ignored when CONFIG_SND_DEBUG is not set. 3201da177e4SLinus Torvalds */ 32143e575faSTakashi Iwai #define snd_printd(fmt, ...) \ 32243e575faSTakashi Iwai __snd_printk(1, __FILE__, __LINE__, fmt, ##__VA_ARGS__) 32343e575faSTakashi Iwai #define _snd_printd(level, fmt, ...) \ 32443e575faSTakashi Iwai __snd_printk(level, __FILE__, __LINE__, fmt, ##__VA_ARGS__) 3257c22f1aaSTakashi Iwai 326f66fcedcSTakashi Iwai /** 327f66fcedcSTakashi Iwai * snd_BUG - give a BUG warning message and stack trace 328f66fcedcSTakashi Iwai * 329f66fcedcSTakashi Iwai * Calls WARN() if CONFIG_SND_DEBUG is set. 330f66fcedcSTakashi Iwai * Ignored when CONFIG_SND_DEBUG is not set. 331f66fcedcSTakashi Iwai */ 332bdbecf50STakashi Iwai #define snd_BUG() WARN(1, "BUG?\n") 333f66fcedcSTakashi Iwai 334f66fcedcSTakashi Iwai /** 335*f7b6603cSMauro Carvalho Chehab * snd_printd_ratelimit - Suppress high rates of output when 336*f7b6603cSMauro Carvalho Chehab * CONFIG_SND_DEBUG is enabled. 337bcbb1553STim Gardner */ 338bcbb1553STim Gardner #define snd_printd_ratelimit() printk_ratelimit() 339bcbb1553STim Gardner 340bcbb1553STim Gardner /** 341f66fcedcSTakashi Iwai * snd_BUG_ON - debugging check macro 342f66fcedcSTakashi Iwai * @cond: condition to evaluate 343f66fcedcSTakashi Iwai * 344d5702162SChristine Spang * Has the same behavior as WARN_ON when CONFIG_SND_DEBUG is set, 345d5702162SChristine Spang * otherwise just evaluates the conditional and returns the value. 346f66fcedcSTakashi Iwai */ 347d5702162SChristine Spang #define snd_BUG_ON(cond) WARN_ON((cond)) 3481da177e4SLinus Torvalds 3491da177e4SLinus Torvalds #else /* !CONFIG_SND_DEBUG */ 3501da177e4SLinus Torvalds 35186b27237STakashi Iwai __printf(1, 2) 35286b27237STakashi Iwai static inline void snd_printd(const char *format, ...) {} 35386b27237STakashi Iwai __printf(2, 3) 35486b27237STakashi Iwai static inline void _snd_printd(int level, const char *format, ...) {} 35586b27237STakashi Iwai 356fcef7836SAndrew Morton #define snd_BUG() do { } while (0) 357d5702162SChristine Spang 358d5702162SChristine Spang #define snd_BUG_ON(condition) ({ \ 359d5702162SChristine Spang int __ret_warn_on = !!(condition); \ 360d5702162SChristine Spang unlikely(__ret_warn_on); \ 361d5702162SChristine Spang }) 3621da177e4SLinus Torvalds 363bcbb1553STim Gardner static inline bool snd_printd_ratelimit(void) { return false; } 364bcbb1553STim Gardner 3651da177e4SLinus Torvalds #endif /* CONFIG_SND_DEBUG */ 3661da177e4SLinus Torvalds 36762cf872aSTakashi Iwai #ifdef CONFIG_SND_DEBUG_VERBOSE 3681da177e4SLinus Torvalds /** 3691da177e4SLinus Torvalds * snd_printdd - debug printk 3701da177e4SLinus Torvalds * @format: format string 3711da177e4SLinus Torvalds * 372edab938eSPavel Machek * Works like snd_printk() for debugging purposes. 37362cf872aSTakashi Iwai * Ignored when CONFIG_SND_DEBUG_VERBOSE is not set. 3741da177e4SLinus Torvalds */ 37543e575faSTakashi Iwai #define snd_printdd(format, ...) \ 37643e575faSTakashi Iwai __snd_printk(2, __FILE__, __LINE__, format, ##__VA_ARGS__) 3771da177e4SLinus Torvalds #else 37886b27237STakashi Iwai __printf(1, 2) 37986b27237STakashi Iwai static inline void snd_printdd(const char *format, ...) {} 3801da177e4SLinus Torvalds #endif 3811da177e4SLinus Torvalds 3821da177e4SLinus Torvalds 3831da177e4SLinus Torvalds #define SNDRV_OSS_VERSION ((3<<16)|(8<<8)|(1<<4)|(0)) /* 3.8.1a */ 3841da177e4SLinus Torvalds 3851da177e4SLinus Torvalds /* for easier backward-porting */ 3866d2412b8STakashi Iwai #if IS_ENABLED(CONFIG_GAMEPORT) 3871da177e4SLinus Torvalds #define gameport_set_dev_parent(gp,xdev) ((gp)->dev.parent = (xdev)) 3881da177e4SLinus Torvalds #define gameport_set_port_data(gp,r) ((gp)->port_data = (r)) 3891da177e4SLinus Torvalds #define gameport_get_port_data(gp) (gp)->port_data 3901da177e4SLinus Torvalds #endif 3911da177e4SLinus Torvalds 392d9ea472cSTakashi Iwai /* PCI quirk list helper */ 393d9ea472cSTakashi Iwai struct snd_pci_quirk { 394d9ea472cSTakashi Iwai unsigned short subvendor; /* PCI subvendor ID */ 395d9ea472cSTakashi Iwai unsigned short subdevice; /* PCI subdevice ID */ 3968bd4bb7aSTakashi Iwai unsigned short subdevice_mask; /* bitmask to match */ 397d9ea472cSTakashi Iwai int value; /* value */ 39862cf872aSTakashi Iwai #ifdef CONFIG_SND_DEBUG_VERBOSE 399d9ea472cSTakashi Iwai const char *name; /* name of the device (optional) */ 400d9ea472cSTakashi Iwai #endif 401d9ea472cSTakashi Iwai }; 402d9ea472cSTakashi Iwai 4038bd4bb7aSTakashi Iwai #define _SND_PCI_QUIRK_ID_MASK(vend, mask, dev) \ 4048bd4bb7aSTakashi Iwai .subvendor = (vend), .subdevice = (dev), .subdevice_mask = (mask) 405d9ea472cSTakashi Iwai #define _SND_PCI_QUIRK_ID(vend, dev) \ 4068bd4bb7aSTakashi Iwai _SND_PCI_QUIRK_ID_MASK(vend, 0xffff, dev) 407d9ea472cSTakashi Iwai #define SND_PCI_QUIRK_ID(vend,dev) {_SND_PCI_QUIRK_ID(vend, dev)} 40862cf872aSTakashi Iwai #ifdef CONFIG_SND_DEBUG_VERBOSE 409d9ea472cSTakashi Iwai #define SND_PCI_QUIRK(vend,dev,xname,val) \ 410d9ea472cSTakashi Iwai {_SND_PCI_QUIRK_ID(vend, dev), .value = (val), .name = (xname)} 4118bd4bb7aSTakashi Iwai #define SND_PCI_QUIRK_VENDOR(vend, xname, val) \ 4128bd4bb7aSTakashi Iwai {_SND_PCI_QUIRK_ID_MASK(vend, 0, 0), .value = (val), .name = (xname)} 4138bd4bb7aSTakashi Iwai #define SND_PCI_QUIRK_MASK(vend, mask, dev, xname, val) \ 4148bd4bb7aSTakashi Iwai {_SND_PCI_QUIRK_ID_MASK(vend, mask, dev), \ 4158bd4bb7aSTakashi Iwai .value = (val), .name = (xname)} 41686b27237STakashi Iwai #define snd_pci_quirk_name(q) ((q)->name) 417d9ea472cSTakashi Iwai #else 418d9ea472cSTakashi Iwai #define SND_PCI_QUIRK(vend,dev,xname,val) \ 419d9ea472cSTakashi Iwai {_SND_PCI_QUIRK_ID(vend, dev), .value = (val)} 4208bd4bb7aSTakashi Iwai #define SND_PCI_QUIRK_MASK(vend, mask, dev, xname, val) \ 4218bd4bb7aSTakashi Iwai {_SND_PCI_QUIRK_ID_MASK(vend, mask, dev), .value = (val)} 4228bd4bb7aSTakashi Iwai #define SND_PCI_QUIRK_VENDOR(vend, xname, val) \ 4238bd4bb7aSTakashi Iwai {_SND_PCI_QUIRK_ID_MASK(vend, 0, 0), .value = (val)} 42486b27237STakashi Iwai #define snd_pci_quirk_name(q) "" 425d9ea472cSTakashi Iwai #endif 426d9ea472cSTakashi Iwai 427f0a220deSDylan Reid #ifdef CONFIG_PCI 428d9ea472cSTakashi Iwai const struct snd_pci_quirk * 429d9ea472cSTakashi Iwai snd_pci_quirk_lookup(struct pci_dev *pci, const struct snd_pci_quirk *list); 430d9ea472cSTakashi Iwai 431d1458279STakashi Iwai const struct snd_pci_quirk * 432d1458279STakashi Iwai snd_pci_quirk_lookup_id(u16 vendor, u16 device, 433d1458279STakashi Iwai const struct snd_pci_quirk *list); 434f0a220deSDylan Reid #else 435f0a220deSDylan Reid static inline const struct snd_pci_quirk * 436f0a220deSDylan Reid snd_pci_quirk_lookup(struct pci_dev *pci, const struct snd_pci_quirk *list) 437f0a220deSDylan Reid { 438f0a220deSDylan Reid return NULL; 439f0a220deSDylan Reid } 440f0a220deSDylan Reid 441f0a220deSDylan Reid static inline const struct snd_pci_quirk * 442f0a220deSDylan Reid snd_pci_quirk_lookup_id(u16 vendor, u16 device, 443f0a220deSDylan Reid const struct snd_pci_quirk *list) 444f0a220deSDylan Reid { 445f0a220deSDylan Reid return NULL; 446f0a220deSDylan Reid } 4478422fa11SAxel Lin #endif 448d9ea472cSTakashi Iwai 4491da177e4SLinus Torvalds #endif /* __SOUND_CORE_H */ 450