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 */
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);
pr_debug("reg %s for device %s, direction %d\n", str, compr->name,
compr->direction);
/* register compressed device */
- ret = snd_register_device_for_dev(SNDRV_DEVICE_TYPE_COMPRESS,
- compr->card, compr->device,
- &snd_compr_file_ops, compr,
- &compr->dev, NULL, NULL);
+ ret = snd_register_device(SNDRV_DEVICE_TYPE_COMPRESS,
+ compr->card, compr->device,
+ &snd_compr_file_ops, compr, &compr->dev);
if (ret < 0) {
pr_err("snd_register_device failed\n %d", ret);
return ret;
struct snd_compr *compr;
compr = device->device_data;
- snd_unregister_device(SNDRV_DEVICE_TYPE_COMPRESS, compr->card,
- compr->device);
+ snd_unregister_device(&compr->dev);
return 0;
}
{
struct snd_card *card = device->device_data;
- return snd_register_device_for_dev(SNDRV_DEVICE_TYPE_CONTROL, card,
- -1, &snd_ctl_f_ops, card,
- &card->ctl_dev, NULL, NULL);
+ return snd_register_device(SNDRV_DEVICE_TYPE_CONTROL, card, -1,
+ &snd_ctl_f_ops, card, &card->ctl_dev);
}
/*
}
read_unlock(&card->ctl_files_rwlock);
- return snd_unregister_device(SNDRV_DEVICE_TYPE_CONTROL, card, -1);
+ return snd_unregister_device(&card->ctl_dev);
}
/*
return -EBUSY;
}
list_add_tail(&hwdep->list, &snd_hwdep_devices);
- err = snd_register_device_for_dev(SNDRV_DEVICE_TYPE_HWDEP,
- hwdep->card, hwdep->device,
- &snd_hwdep_f_ops, hwdep,
- &hwdep->dev, NULL, NULL);
+ err = snd_register_device(SNDRV_DEVICE_TYPE_HWDEP,
+ hwdep->card, hwdep->device,
+ &snd_hwdep_f_ops, hwdep, &hwdep->dev);
if (err < 0) {
dev_err(&hwdep->dev, "unable to register\n");
list_del(&hwdep->list);
if (hwdep->ossreg)
snd_unregister_oss_device(hwdep->oss_type, hwdep->card, hwdep->device);
#endif
- snd_unregister_device(SNDRV_DEVICE_TYPE_HWDEP, hwdep->card, hwdep->device);
+ snd_unregister_device(&hwdep->dev);
list_del_init(&hwdep->list);
mutex_unlock(&hwdep->open_mutex);
mutex_unlock(®ister_mutex);
break;
}
/* register pcm */
- err = snd_register_device_for_dev(devtype, pcm->card,
- pcm->device,
- &snd_pcm_f_ops[cidx],
- pcm, &pcm->streams[cidx].dev,
- NULL, NULL);
+ err = snd_register_device(devtype, pcm->card, pcm->device,
+ &snd_pcm_f_ops[cidx], pcm,
+ &pcm->streams[cidx].dev);
if (err < 0) {
list_del(&pcm->list);
mutex_unlock(®ister_mutex);
struct snd_pcm *pcm = device->device_data;
struct snd_pcm_notify *notify;
struct snd_pcm_substream *substream;
- int cidx, devtype;
+ int cidx;
mutex_lock(®ister_mutex);
if (list_empty(&pcm->list))
notify->n_disconnect(pcm);
}
for (cidx = 0; cidx < 2; cidx++) {
- devtype = -1;
- switch (cidx) {
- case SNDRV_PCM_STREAM_PLAYBACK:
- devtype = SNDRV_DEVICE_TYPE_PCM_PLAYBACK;
- break;
- case SNDRV_PCM_STREAM_CAPTURE:
- devtype = SNDRV_DEVICE_TYPE_PCM_CAPTURE;
- break;
- }
- snd_unregister_device(devtype, pcm->card, pcm->device);
+ snd_unregister_device(&pcm->streams[cidx].dev);
if (pcm->streams[cidx].chmap_kctl) {
snd_ctl_remove(pcm->card, pcm->streams[cidx].chmap_kctl);
pcm->streams[cidx].chmap_kctl = NULL;
return -EBUSY;
}
list_add_tail(&rmidi->list, &snd_rawmidi_devices);
- err = snd_register_device_for_dev(SNDRV_DEVICE_TYPE_RAWMIDI,
- rmidi->card, rmidi->device,
- &snd_rawmidi_f_ops, rmidi,
- &rmidi->dev, NULL, NULL);
+ err = snd_register_device(SNDRV_DEVICE_TYPE_RAWMIDI,
+ rmidi->card, rmidi->device,
+ &snd_rawmidi_f_ops, rmidi, &rmidi->dev);
if (err < 0) {
rmidi_err(rmidi, "unable to register\n");
list_del(&rmidi->list);
}
if (rmidi->ops && rmidi->ops->dev_register &&
(err = rmidi->ops->dev_register(rmidi)) < 0) {
- snd_unregister_device(SNDRV_DEVICE_TYPE_RAWMIDI, rmidi->card, rmidi->device);
+ snd_unregister_device(&rmidi->dev);
list_del(&rmidi->list);
mutex_unlock(®ister_mutex);
return err;
rmidi->ossreg = 0;
}
#endif /* CONFIG_SND_OSSEMUL */
- snd_unregister_device(SNDRV_DEVICE_TYPE_RAWMIDI, rmidi->card, rmidi->device);
+ snd_unregister_device(&rmidi->dev);
mutex_unlock(&rmidi->open_mutex);
mutex_unlock(®ister_mutex);
return 0;
if (mutex_lock_interruptible(®ister_mutex))
return -ERESTARTSYS;
- err = snd_register_device_for_dev(SNDRV_DEVICE_TYPE_SEQUENCER, NULL, 0,
- &snd_seq_f_ops, NULL,
- &seq_dev, NULL, NULL);
+ err = snd_register_device(SNDRV_DEVICE_TYPE_SEQUENCER, NULL, 0,
+ &snd_seq_f_ops, NULL, &seq_dev);
if (err < 0) {
mutex_unlock(®ister_mutex);
put_device(&seq_dev);
*/
void __exit snd_sequencer_device_done(void)
{
- snd_unregister_device(SNDRV_DEVICE_TYPE_SEQUENCER, NULL, 0);
+ snd_unregister_device(&seq_dev);
put_device(&seq_dev);
}
#endif
/**
- * snd_register_device_for_dev - Register the ALSA device file for the card
+ * 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()
- * @device: the device to register, NULL to create a new one
- * @parent: the &struct device to link this new device to (only for device=NULL)
- * @name: the device file name (only for device=NULL)
+ * @device: the device to register
*
* Registers an ALSA device file for the given card.
* The operators have to be set in reg parameter.
*
* Return: Zero if successful, or a negative error code on failure.
*/
-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)
+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 minor;
int err = 0;
struct snd_minor *preg;
+ if (snd_BUG_ON(!device))
+ return -EINVAL;
+
preg = kmalloc(sizeof *preg, GFP_KERNEL);
if (preg == NULL)
return -ENOMEM;
goto error;
}
- if (device) {
- preg->created = false;
- preg->dev = device;
- device->devt = MKDEV(major, minor);
- err = device_add(device);
- } else {
- preg->created = true;
- preg->dev = device_create(sound_class, parent,
- MKDEV(major, minor), private_data,
- "%s", name);
- if (IS_ERR(preg->dev))
- err = PTR_ERR(preg->dev);
- }
+ preg->dev = device;
+ device->devt = MKDEV(major, minor);
+ err = device_add(device);
if (err < 0)
goto error;
kfree(preg);
return err;
}
-
-EXPORT_SYMBOL(snd_register_device_for_dev);
+EXPORT_SYMBOL(snd_register_device);
/* find the matching minor record
* return the index of snd_minor, or -1 if not found
/**
* snd_unregister_device - unregister the device on the given card
- * @type: the device type, SNDRV_DEVICE_TYPE_XXX
- * @card: the card instance
- * @dev: the device index
+ * @dev: the device instance
*
* Unregisters the device file already registered via
* snd_register_device().
*
* Return: Zero if successful, or a negative error code on failure.
*/
-int snd_unregister_device(int type, struct snd_card *card, int dev)
+int snd_unregister_device(struct device *dev)
{
int minor;
struct snd_minor *preg;
mutex_lock(&sound_mutex);
- minor = find_snd_minor(type, card, dev);
- if (minor < 0) {
- mutex_unlock(&sound_mutex);
- return -EINVAL;
+ for (minor = 0; minor < ARRAY_SIZE(snd_minors); ++minor) {
+ preg = snd_minors[minor];
+ if (preg && preg->dev == dev) {
+ snd_minors[minor] = NULL;
+ device_del(dev);
+ kfree(preg);
+ break;
+ }
}
-
- preg = snd_minors[minor];
- if (preg && !preg->created)
- device_del(preg->dev);
- else
- device_destroy(sound_class, MKDEV(major, minor));
-
- kfree(snd_minors[minor]);
- snd_minors[minor] = NULL;
mutex_unlock(&sound_mutex);
+ if (minor >= ARRAY_SIZE(snd_minors))
+ return -ENOENT;
return 0;
}
-
EXPORT_SYMBOL(snd_unregister_device);
/**
return err;
}
- err = snd_register_device_for_dev(SNDRV_DEVICE_TYPE_TIMER, NULL, 0,
- &snd_timer_f_ops, NULL,
- &timer_dev, NULL, NULL);
+ err = snd_register_device(SNDRV_DEVICE_TYPE_TIMER, NULL, 0,
+ &snd_timer_f_ops, NULL, &timer_dev);
if (err < 0) {
pr_err("ALSA: unable to register timer device (%i)\n", err);
snd_timer_free_all();
static void __exit alsa_timer_exit(void)
{
- snd_unregister_device(SNDRV_DEVICE_TYPE_TIMER, NULL, 0);
+ snd_unregister_device(&timer_dev);
snd_timer_free_all();
put_device(&timer_dev);
snd_timer_proc_done();