From 92b7952da8279189aad352efbf9f2e7001de9524 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Thu, 29 Jan 2015 15:53:51 +0100 Subject: ALSA: Allow to pass the device object to snd_register_device*() This is a preliminary patch for the further work on embedding struct device into each sound device instance. It changes snd_register_device*() helpers to receive the device object directly for skipping creating a device there. Reviewed-by: Jaroslav Kysela Signed-off-by: Takashi Iwai --- include/sound/core.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'include/sound') diff --git a/include/sound/core.h b/include/sound/core.h index 1df3f2fe5350..39d14234961d 100644 --- a/include/sound/core.h +++ b/include/sound/core.h @@ -186,6 +186,7 @@ struct snd_minor { int type; /* SNDRV_DEVICE_TYPE_XXX */ int card; /* card number */ int device; /* device number */ + bool created; const struct file_operations *f_ops; /* file operations */ void *private_data; /* private data for f_ops->open */ struct device *dev; /* device for sysfs */ @@ -206,12 +207,10 @@ extern struct class *sound_class; void snd_request_card(int card); -int snd_register_device_for_dev(int type, struct snd_card *card, - int dev, +int snd_register_device_for_dev(int type, struct snd_card *card, int dev, const struct file_operations *f_ops, - void *private_data, - const char *name, - struct device *device); + void *private_data, struct device *device, + struct device *parent, const char *name); /** * snd_register_device - Register the ALSA device file for the card @@ -236,8 +235,9 @@ static inline int snd_register_device(int type, struct snd_card *card, int dev, const char *name) { return snd_register_device_for_dev(type, card, dev, f_ops, - private_data, name, - snd_card_get_device_link(card)); + private_data, NULL, + snd_card_get_device_link(card), + name); } int snd_unregister_device(int type, struct snd_card *card, int dev); -- cgit v1.2.3 From 23c18d4bfd73ee24070849faf98b3ab01263a3c4 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Wed, 19 Feb 2014 14:30:29 +0100 Subject: ALSA: control: Provide a helper to look for the preferred subdevice Instead of open-coding the search over the control file loop, provide a helper function for the preferred subdevice assigned to the current process. Reviewed-by: Jaroslav Kysela Signed-off-by: Takashi Iwai --- include/sound/control.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'include/sound') diff --git a/include/sound/control.h b/include/sound/control.h index 042613938a1d..75f3054023f7 100644 --- a/include/sound/control.h +++ b/include/sound/control.h @@ -93,12 +93,17 @@ struct snd_kctl_event { struct pid; +enum { + SND_CTL_SUBDEV_PCM, + SND_CTL_SUBDEV_RAWMIDI, + SND_CTL_SUBDEV_ITEMS, +}; + struct snd_ctl_file { struct list_head list; /* list of all control files */ struct snd_card *card; struct pid *pid; - int prefer_pcm_subdevice; - int prefer_rawmidi_subdevice; + int preferred_subdevice[SND_CTL_SUBDEV_ITEMS]; wait_queue_head_t change_sleep; spinlock_t read_lock; struct fasync_struct *fasync; @@ -138,6 +143,8 @@ int snd_ctl_unregister_ioctl_compat(snd_kctl_ioctl_func_t fcn); #define snd_ctl_unregister_ioctl_compat(fcn) #endif +int snd_ctl_get_preferred_subdevice(struct snd_card *card, int type); + static inline unsigned int snd_ctl_get_ioffnum(struct snd_kcontrol *kctl, struct snd_ctl_elem_id *id) { return id->numid - kctl->id.numid; -- cgit v1.2.3 From 4b440be667c6187717c99e4d427119fa415ced29 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Thu, 29 Jan 2015 21:32:47 +0100 Subject: ALSA: Add a helper to initialize device Introduce a new helper function snd_device_initialize() to initialize the device object for sound devices. Reviewed-by: Jaroslav Kysela Signed-off-by: Takashi Iwai --- include/sound/core.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'include/sound') diff --git a/include/sound/core.h b/include/sound/core.h index 39d14234961d..de7a878217d7 100644 --- a/include/sound/core.h +++ b/include/sound/core.h @@ -207,6 +207,8 @@ extern struct class *sound_class; void snd_request_card(int card); +void snd_device_initialize(struct device *dev, struct snd_card *card); + int snd_register_device_for_dev(int type, struct snd_card *card, int dev, const struct file_operations *f_ops, void *private_data, struct device *device, -- cgit v1.2.3 From 0fcd9f4b3c60382205e5819c456aa9ea17b6f20f Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Thu, 29 Jan 2015 16:41:27 +0100 Subject: ALSA: control: Embed struct device This patch embeds a struct device for the control device into the card object and avoid the device creation at registration time. Reviewed-by: Jaroslav Kysela Signed-off-by: Takashi Iwai --- include/sound/core.h | 1 + 1 file changed, 1 insertion(+) (limited to 'include/sound') diff --git a/include/sound/core.h b/include/sound/core.h index de7a878217d7..4b7e04e85e16 100644 --- a/include/sound/core.h +++ b/include/sound/core.h @@ -109,6 +109,7 @@ struct snd_card { private data */ struct list_head devices; /* devices */ + struct device ctl_dev; /* control device */ unsigned int last_numid; /* last used numeric ID */ struct rw_semaphore controls_rwsem; /* controls list lock */ rwlock_t ctl_files_rwlock; /* ctl_files list lock */ -- cgit v1.2.3 From 7b46160000197209f7ebca8b92bdbb75795c473f Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Thu, 29 Jan 2015 17:13:32 +0100 Subject: ALSA: hwdep: Embed struct device Like the previous patch, this one embeds the device object into hwdep object. For a proper object lifecycle, it's freed in the release callback. This also allows us to create sysfs entries via passing to the groups field of the device without explicit function calls. Since each driver can see the device and touch its groups field directly, we don't need to delegate in hwdep core any longer. So, remove the groups field from snd_hwdep, and let the user (in this case only hda_hwdep.c) modify the device groups. Reviewed-by: Jaroslav Kysela Signed-off-by: Takashi Iwai --- include/sound/hwdep.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'include/sound') diff --git a/include/sound/hwdep.h b/include/sound/hwdep.h index ae04a3ec9c77..ab9fcb2f97f0 100644 --- a/include/sound/hwdep.h +++ b/include/sound/hwdep.h @@ -68,8 +68,7 @@ struct snd_hwdep { wait_queue_head_t open_wait; void *private_data; void (*private_free) (struct snd_hwdep *hwdep); - struct device *dev; - const struct attribute_group **groups; + struct device dev; struct mutex open_mutex; int used; /* reference counter */ -- cgit v1.2.3 From ef46c7af93f98d07cd0ed891f93a26d135785526 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Thu, 29 Jan 2015 17:32:26 +0100 Subject: ALSA: pcm: Embed struct device Like previous patches, at this time we embed the struct device into PCM object. However, this needs a bit more caution: struct snd_pcm doesn't own one device but two, for both playback and capture! Thus not struct snd_pcm but struct snd_pcm_str object contains the device. Along with this change, pcm->dev field is dropped for avoiding confusion. It was meant to point to a non-standard parent. But, since now we can touch each struct device directly, we can manipulate the parent field easily there, too. Reviewed-by: Jaroslav Kysela Signed-off-by: Takashi Iwai --- include/sound/pcm.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/sound') diff --git a/include/sound/pcm.h b/include/sound/pcm.h index b429b73e875e..735bd0cc7347 100644 --- a/include/sound/pcm.h +++ b/include/sound/pcm.h @@ -449,6 +449,7 @@ struct snd_pcm_str { #endif #endif struct snd_kcontrol *chmap_kctl; /* channel-mapping controls */ + struct device dev; }; struct snd_pcm { @@ -465,7 +466,6 @@ struct snd_pcm { wait_queue_head_t open_wait; void *private_data; void (*private_free) (struct snd_pcm *pcm); - struct device *dev; /* actual hw device this belongs to */ bool internal; /* pcm is for internal use only */ bool nonatomic; /* whole PCM operations are in non-atomic context */ #if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE) -- cgit v1.2.3 From aee5012fbb77dad6179c44d83d531ad62dd8098a Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Thu, 29 Jan 2015 17:55:52 +0100 Subject: ALSA: rawmidi: Embed struct device Like previous patches, this changes the device management for rawmidi, embedding the struct device into struct snd_rawmidi. The required change is more or less same as hwdep device. The currently unused dev field is reused as the new embedded struct field now. Reviewed-by: Jaroslav Kysela Signed-off-by: Takashi Iwai --- include/sound/rawmidi.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'include/sound') diff --git a/include/sound/rawmidi.h b/include/sound/rawmidi.h index 311dafe6cc4b..f6cbef78db62 100644 --- a/include/sound/rawmidi.h +++ b/include/sound/rawmidi.h @@ -28,6 +28,7 @@ #include #include #include +#include #if defined(CONFIG_SND_SEQUENCER) || defined(CONFIG_SND_SEQUENCER_MODULE) #include @@ -139,7 +140,8 @@ struct snd_rawmidi { struct mutex open_mutex; wait_queue_head_t open_wait; - struct snd_info_entry *dev; + struct device dev; + struct snd_info_entry *proc_entry; #if defined(CONFIG_SND_SEQUENCER) || defined(CONFIG_SND_SEQUENCER_MODULE) -- cgit v1.2.3 From 04c5d5a430fca046cffac099a3f41e74816939da Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Fri, 30 Jan 2015 08:16:35 +0100 Subject: ALSA: compress: Embed struct device Like previous patches, this one embeds the struct device into struct snd_compr. As the dev field wasn't used beforehand, it's reused as the new device struct. Reviewed-by: Jaroslav Kysela Signed-off-by: Takashi Iwai --- include/sound/compress_driver.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include/sound') diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h index 396e8f73670a..1d0593b52573 100644 --- a/include/sound/compress_driver.h +++ b/include/sound/compress_driver.h @@ -134,7 +134,7 @@ struct snd_compr_ops { /** * struct snd_compr: Compressed device * @name: DSP device name - * @dev: Device pointer + * @dev: associated device instance * @ops: pointer to DSP callbacks * @private_data: pointer to DSP pvt data * @card: sound card pointer @@ -144,7 +144,7 @@ struct snd_compr_ops { */ struct snd_compr { const char *name; - struct device *dev; + struct device dev; struct snd_compr_ops *ops; void *private_data; struct snd_card *card; -- cgit v1.2.3 From 40a4b263854346fe7c7d1c3964c106296f690816 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Fri, 30 Jan 2015 08:34:58 +0100 Subject: ALSA: Simplify snd_device_register() variants Now that all callers have been replaced with snd_device_register_for_dev(), let's drop the obsolete device registration code and concentrate only on the code handling struct device directly. That said, - remove the old snd_device_register(), - rename snd_device_register_for_dev() with snd_device_register(), - drop superfluous arguments from snd_device_register(), - change snd_unregister_device() to pass the device pointer directly Reviewed-by: Jaroslav Kysela Signed-off-by: Takashi Iwai --- include/sound/core.h | 39 ++++----------------------------------- 1 file changed, 4 insertions(+), 35 deletions(-) (limited to 'include/sound') diff --git a/include/sound/core.h b/include/sound/core.h index 4b7e04e85e16..67ac309bb218 100644 --- a/include/sound/core.h +++ b/include/sound/core.h @@ -187,7 +187,6 @@ struct snd_minor { int type; /* SNDRV_DEVICE_TYPE_XXX */ int card; /* card number */ int device; /* device number */ - bool created; const struct file_operations *f_ops; /* file operations */ void *private_data; /* private data for f_ops->open */ struct device *dev; /* device for sysfs */ @@ -210,40 +209,10 @@ void snd_request_card(int card); void snd_device_initialize(struct device *dev, struct snd_card *card); -int snd_register_device_for_dev(int type, struct snd_card *card, int dev, - const struct file_operations *f_ops, - void *private_data, struct device *device, - struct device *parent, const char *name); - -/** - * snd_register_device - Register the ALSA device file for the card - * @type: the device type, SNDRV_DEVICE_TYPE_XXX - * @card: the card instance - * @dev: the device index - * @f_ops: the file operations - * @private_data: user pointer for f_ops->open() - * @name: the device file name - * - * Registers an ALSA device file for the given card. - * The operators have to be set in reg parameter. - * - * This function uses the card's device pointer to link to the - * correct &struct device. - * - * 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, - void *private_data, - const char *name) -{ - return snd_register_device_for_dev(type, card, dev, f_ops, - private_data, NULL, - snd_card_get_device_link(card), - name); -} - -int snd_unregister_device(int type, struct snd_card *card, int dev); +int snd_register_device(int type, struct snd_card *card, int dev, + const struct file_operations *f_ops, + void *private_data, struct device *device); +int snd_unregister_device(struct device *dev); void *snd_lookup_minor_data(unsigned int minor, int type); struct device *snd_get_device(int type, struct snd_card *card, int dev); -- cgit v1.2.3 From 830953c0724b42be30a74febcde6c89c706ed286 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Fri, 30 Jan 2015 08:39:40 +0100 Subject: ALSA: Drop snd_get_device() helper Since the device is no longer hidden but embedded into each component, we no longer need snd_get_device(). Let's drop it and relevant codes. Reviewed-by: Jaroslav Kysela Signed-off-by: Takashi Iwai --- include/sound/core.h | 1 - 1 file changed, 1 deletion(-) (limited to 'include/sound') diff --git a/include/sound/core.h b/include/sound/core.h index 67ac309bb218..58882bfacdd7 100644 --- a/include/sound/core.h +++ b/include/sound/core.h @@ -214,7 +214,6 @@ int snd_register_device(int type, struct snd_card *card, int dev, void *private_data, struct device *device); int snd_unregister_device(struct device *dev); void *snd_lookup_minor_data(unsigned int minor, int type); -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, -- cgit v1.2.3