diff options
Diffstat (limited to 'include/sound/core.h')
| -rw-r--r-- | include/sound/core.h | 169 | 
1 files changed, 99 insertions, 70 deletions
diff --git a/include/sound/core.h b/include/sound/core.h index 1fa2407c966..1df3f2fe535 100644 --- a/include/sound/core.h +++ b/include/sound/core.h @@ -22,17 +22,17 @@   *   */ -#include <linux/module.h> +#include <linux/device.h>  #include <linux/sched.h>		/* wake_up() */  #include <linux/mutex.h>		/* struct mutex */  #include <linux/rwsem.h>		/* struct rw_semaphore */  #include <linux/pm.h>			/* pm_message_t */ -#include <linux/device.h>  #include <linux/stringify.h> +#include <linux/printk.h>  /* number of supported soundcards */  #ifdef CONFIG_SND_DYNAMIC_MINORS -#define SNDRV_CARDS 32 +#define SNDRV_CARDS CONFIG_SND_MAX_CARDS  #else  #define SNDRV_CARDS 8		/* don't change - minor numbers */  #endif @@ -40,39 +40,35 @@  #define CONFIG_SND_MAJOR	116	/* standard configuration */  /* forward declarations */ -#ifdef CONFIG_PCI  struct pci_dev; -#endif +struct module; +struct completion;  /* device allocation stuff */ -#define SNDRV_DEV_TYPE_RANGE_SIZE		0x1000 - -typedef int __bitwise snd_device_type_t; -#define	SNDRV_DEV_TOPLEVEL	((__force snd_device_type_t) 0) -#define	SNDRV_DEV_CONTROL	((__force snd_device_type_t) 1) -#define	SNDRV_DEV_LOWLEVEL_PRE	((__force snd_device_type_t) 2) -#define	SNDRV_DEV_LOWLEVEL_NORMAL ((__force snd_device_type_t) 0x1000) -#define	SNDRV_DEV_PCM		((__force snd_device_type_t) 0x1001) -#define	SNDRV_DEV_RAWMIDI	((__force snd_device_type_t) 0x1002) -#define	SNDRV_DEV_TIMER		((__force snd_device_type_t) 0x1003) -#define	SNDRV_DEV_SEQUENCER	((__force snd_device_type_t) 0x1004) -#define	SNDRV_DEV_HWDEP		((__force snd_device_type_t) 0x1005) -#define	SNDRV_DEV_INFO		((__force snd_device_type_t) 0x1006) -#define	SNDRV_DEV_BUS		((__force snd_device_type_t) 0x1007) -#define	SNDRV_DEV_CODEC		((__force snd_device_type_t) 0x1008) -#define	SNDRV_DEV_JACK          ((__force snd_device_type_t) 0x1009) -#define	SNDRV_DEV_LOWLEVEL	((__force snd_device_type_t) 0x2000) - -typedef int __bitwise snd_device_state_t; -#define	SNDRV_DEV_BUILD		((__force snd_device_state_t) 0) -#define	SNDRV_DEV_REGISTERED	((__force snd_device_state_t) 1) -#define	SNDRV_DEV_DISCONNECTED	((__force snd_device_state_t) 2) - -typedef int __bitwise snd_device_cmd_t; -#define	SNDRV_DEV_CMD_PRE	((__force snd_device_cmd_t) 0) -#define	SNDRV_DEV_CMD_NORMAL	((__force snd_device_cmd_t) 1)	 -#define	SNDRV_DEV_CMD_POST	((__force snd_device_cmd_t) 2) +/* type of the object used in snd_device_*() + * this also defines the calling order + */ +enum snd_device_type { +	SNDRV_DEV_LOWLEVEL, +	SNDRV_DEV_CONTROL, +	SNDRV_DEV_INFO, +	SNDRV_DEV_BUS, +	SNDRV_DEV_CODEC, +	SNDRV_DEV_PCM, +	SNDRV_DEV_COMPRESS, +	SNDRV_DEV_RAWMIDI, +	SNDRV_DEV_TIMER, +	SNDRV_DEV_SEQUENCER, +	SNDRV_DEV_HWDEP, +	SNDRV_DEV_JACK, +}; + +enum snd_device_state { +	SNDRV_DEV_BUILD, +	SNDRV_DEV_REGISTERED, +	SNDRV_DEV_DISCONNECTED, +};  struct snd_device; @@ -85,8 +81,8 @@ struct snd_device_ops {  struct snd_device {  	struct list_head list;		/* list of registered devices */  	struct snd_card *card;		/* card which holds this device */ -	snd_device_state_t state;	/* state of the device */ -	snd_device_type_t type;		/* device type */ +	enum snd_device_state state;	/* state of the device */ +	enum snd_device_type type;	/* device type */  	void *device_data;		/* device structure */  	struct snd_device_ops *ops;	/* operations */  }; @@ -120,6 +116,8 @@ struct snd_card {  	int user_ctl_count;		/* count of all user controls */  	struct list_head controls;	/* all controls for this card */  	struct list_head ctl_files;	/* active control files */ +	struct mutex user_ctl_lock;	/* protects user controls against +					   concurrent access */  	struct snd_info_entry *proc_root;	/* root for soundcard specific files */  	struct snd_info_entry *proc_id;	/* the card id */ @@ -130,10 +128,10 @@ struct snd_card {  								state */  	spinlock_t files_lock;		/* lock the files for this card */  	int shutdown;			/* this card is going down */ -	int free_on_last_close;		/* free in context of file_release */ -	wait_queue_head_t shutdown_sleep; +	struct completion *release_completion;  	struct device *dev;		/* device assigned to this card */ -	struct device *card_dev;	/* cardX object for sysfs */ +	struct device card_dev;		/* cardX object for sysfs */ +	bool registered;		/* card_dev is registered? */  #ifdef CONFIG_PM  	unsigned int power_state;	/* power state */ @@ -147,6 +145,8 @@ struct snd_card {  #endif  }; +#define dev_to_snd_card(p)	container_of(p, struct snd_card, card_dev) +  #ifdef CONFIG_PM  static inline void snd_power_lock(struct snd_card *card)  { @@ -189,12 +189,13 @@ struct snd_minor {  	const struct file_operations *f_ops;	/* file operations */  	void *private_data;		/* private data for f_ops->open */  	struct device *dev;		/* device for sysfs */ +	struct snd_card *card_ptr;	/* assigned card instance */  };  /* return a device pointer linked to each sound device as a parent */  static inline struct device *snd_card_get_device_link(struct snd_card *card)  { -	return card ? card->card_dev : NULL; +	return card ? &card->card_dev : NULL;  }  /* sound.c */ @@ -227,7 +228,7 @@ int snd_register_device_for_dev(int type, struct snd_card *card,   * This function uses the card's device pointer to link to the   * correct &struct device.   * - * Returns zero if successful, or a negative error code on failure. + * Return: Zero if successful, or a negative error code on failure.   */  static inline int snd_register_device(int type, struct snd_card *card, int dev,  				      const struct file_operations *f_ops, @@ -241,13 +242,11 @@ static inline int snd_register_device(int type, struct snd_card *card, int dev,  int snd_unregister_device(int type, struct snd_card *card, int dev);  void *snd_lookup_minor_data(unsigned int minor, int type); -int snd_add_device_sysfs_file(int type, struct snd_card *card, int dev, -			      struct device_attribute *attr); +struct device *snd_get_device(int type, struct snd_card *card, int dev);  #ifdef CONFIG_SND_OSSEMUL  int snd_register_oss_device(int type, struct snd_card *card, int dev, -			    const struct file_operations *f_ops, void *private_data, -			    const char *name); +			    const struct file_operations *f_ops, void *private_data);  int snd_unregister_oss_device(int type, struct snd_card *card, int dev);  void *snd_lookup_oss_minor_data(unsigned int minor, int type);  #endif @@ -281,9 +280,9 @@ int snd_card_locked(int card);  extern int (*snd_mixer_oss_notify_callback)(struct snd_card *card, int cmd);  #endif -int snd_card_create(int idx, const char *id, -		    struct module *module, int extra_size, -		    struct snd_card **card_ret); +int snd_card_new(struct device *parent, int idx, const char *xid, +		 struct module *module, int extra_size, +		 struct snd_card **card_ret);  int snd_card_disconnect(struct snd_card *card);  int snd_card_free(struct snd_card *card); @@ -295,19 +294,19 @@ int snd_card_info_done(void);  int snd_component_add(struct snd_card *card, const char *component);  int snd_card_file_add(struct snd_card *card, struct file *file);  int snd_card_file_remove(struct snd_card *card, struct file *file); +#define snd_card_unref(card)	put_device(&(card)->card_dev)  #define snd_card_set_dev(card, devptr) ((card)->dev = (devptr))  /* device.c */ -int snd_device_new(struct snd_card *card, snd_device_type_t type, +int snd_device_new(struct snd_card *card, enum snd_device_type type,  		   void *device_data, struct snd_device_ops *ops);  int snd_device_register(struct snd_card *card, void *device_data);  int snd_device_register_all(struct snd_card *card); -int snd_device_disconnect(struct snd_card *card, void *device_data);  int snd_device_disconnect_all(struct snd_card *card); -int snd_device_free(struct snd_card *card, void *device_data); -int snd_device_free_all(struct snd_card *card, snd_device_cmd_t cmd); +void snd_device_free(struct snd_card *card, void *device_data); +void snd_device_free_all(struct snd_card *card);  /* isadma.c */ @@ -325,10 +324,17 @@ void release_and_free_resource(struct resource *res);  /* --- */ +/* sound printk debug levels */ +enum { +	SND_PR_ALWAYS, +	SND_PR_DEBUG, +	SND_PR_VERBOSE, +}; +  #if defined(CONFIG_SND_DEBUG) || defined(CONFIG_SND_VERBOSE_PRINTK) +__printf(4, 5)  void __snd_printk(unsigned int level, const char *file, int line, -		  const char *format, ...) -     __attribute__ ((format (printf, 4, 5))); +		  const char *format, ...);  #else  #define __snd_printk(level, file, line, format, args...) \  	printk(format, ##args) @@ -354,6 +360,8 @@ void __snd_printk(unsigned int level, const char *file, int line,   */  #define snd_printd(fmt, args...) \  	__snd_printk(1, __FILE__, __LINE__, fmt, ##args) +#define _snd_printd(level, fmt, args...) \ +	__snd_printk(level, __FILE__, __LINE__, fmt, ##args)  /**   * snd_BUG - give a BUG warning message and stack trace @@ -364,31 +372,34 @@ void __snd_printk(unsigned int level, const char *file, int line,  #define snd_BUG()		WARN(1, "BUG?\n")  /** + * Suppress high rates of output when CONFIG_SND_DEBUG is enabled. + */ +#define snd_printd_ratelimit() printk_ratelimit() + +/**   * snd_BUG_ON - debugging check macro   * @cond: condition to evaluate   * - * When CONFIG_SND_DEBUG is set, this macro evaluates the given condition, - * and call WARN() and returns the value if it's non-zero. - *  - * When CONFIG_SND_DEBUG is not set, this just returns zero, and the given - * condition is ignored. - * - * NOTE: the argument won't be evaluated at all when CONFIG_SND_DEBUG=n. - * Thus, don't put any statement that influences on the code behavior, - * such as pre/post increment, to the argument of this macro. - * If you want to evaluate and give a warning, use standard WARN_ON(). + * Has the same behavior as WARN_ON when CONFIG_SND_DEBUG is set, + * otherwise just evaluates the conditional and returns the value.   */ -#define snd_BUG_ON(cond)	WARN((cond), "BUG? (%s)\n", __stringify(cond)) +#define snd_BUG_ON(cond)	WARN_ON((cond))  #else /* !CONFIG_SND_DEBUG */ -#define snd_printd(fmt, args...)	do { } while (0) +__printf(1, 2) +static inline void snd_printd(const char *format, ...) {} +__printf(2, 3) +static inline void _snd_printd(int level, const char *format, ...) {} +  #define snd_BUG()			do { } while (0) -static inline int __snd_bug_on(int cond) -{ -	return 0; -} -#define snd_BUG_ON(cond)	__snd_bug_on(0 && (cond))  /* always false */ + +#define snd_BUG_ON(condition) ({ \ +	int __ret_warn_on = !!(condition); \ +	unlikely(__ret_warn_on); \ +}) + +static inline bool snd_printd_ratelimit(void) { return false; }  #endif /* CONFIG_SND_DEBUG */ @@ -403,7 +414,8 @@ static inline int __snd_bug_on(int cond)  #define snd_printdd(format, args...) \  	__snd_printk(2, __FILE__, __LINE__, format, ##args)  #else -#define snd_printdd(format, args...)	do { } while (0) +__printf(1, 2) +static inline void snd_printdd(const char *format, ...) {}  #endif @@ -440,6 +452,7 @@ struct snd_pci_quirk {  #define SND_PCI_QUIRK_MASK(vend, mask, dev, xname, val)			\  	{_SND_PCI_QUIRK_ID_MASK(vend, mask, dev),			\  			.value = (val), .name = (xname)} +#define snd_pci_quirk_name(q)	((q)->name)  #else  #define SND_PCI_QUIRK(vend,dev,xname,val) \  	{_SND_PCI_QUIRK_ID(vend, dev), .value = (val)} @@ -447,13 +460,29 @@ struct snd_pci_quirk {  	{_SND_PCI_QUIRK_ID_MASK(vend, mask, dev), .value = (val)}  #define SND_PCI_QUIRK_VENDOR(vend, xname, val)			\  	{_SND_PCI_QUIRK_ID_MASK(vend, 0, 0), .value = (val)} +#define snd_pci_quirk_name(q)	""  #endif +#ifdef CONFIG_PCI  const struct snd_pci_quirk *  snd_pci_quirk_lookup(struct pci_dev *pci, const struct snd_pci_quirk *list);  const struct snd_pci_quirk *  snd_pci_quirk_lookup_id(u16 vendor, u16 device,  			const struct snd_pci_quirk *list); +#else +static inline const struct snd_pci_quirk * +snd_pci_quirk_lookup(struct pci_dev *pci, const struct snd_pci_quirk *list) +{ +	return NULL; +} + +static inline const struct snd_pci_quirk * +snd_pci_quirk_lookup_id(u16 vendor, u16 device, +			const struct snd_pci_quirk *list) +{ +	return NULL; +} +#endif  #endif /* __SOUND_CORE_H */  | 
