]> err.no Git - linux-2.6/blobdiff - sound/core/pcm.c
[ALSA] alsa core: add struct device pointer to struct snd_pcm
[linux-2.6] / sound / core / pcm.c
index bf8f412988b8ead58fe147d102c006fda12b78fb..4701f07ee0ae9fc55b1bde3784b4c7187a4365c3 100644 (file)
@@ -629,6 +629,9 @@ int snd_pcm_new_stream(struct snd_pcm *pcm, int stream, int substream_count)
                substream->number = idx;
                substream->stream = stream;
                sprintf(substream->name, "subdevice #%i", idx);
+               snprintf(substream->latency_id, sizeof(substream->latency_id),
+                        "ALSA-PCM%d-%d%c%d", pcm->card->number, pcm->device,
+                        (stream ? 'c' : 'p'), idx);
                substream->buffer_bytes_max = UINT_MAX;
                if (prev == NULL)
                        pstr->substream = substream;
@@ -637,6 +640,10 @@ int snd_pcm_new_stream(struct snd_pcm *pcm, int stream, int substream_count)
                err = snd_pcm_substream_proc_init(substream);
                if (err < 0) {
                        snd_printk(KERN_ERR "Error in snd_pcm_stream_proc_init\n");
+                       if (prev == NULL)
+                               pstr->substream = NULL;
+                       else
+                               prev->next = NULL;
                        kfree(substream);
                        return err;
                }
@@ -907,7 +914,8 @@ void snd_pcm_detach_substream(struct snd_pcm_substream *substream)
        substream->pstr->substream_opened--;
 }
 
-static ssize_t show_pcm_class(struct class_device *class_device, char *buf)
+static ssize_t show_pcm_class(struct device *dev,
+                             struct device_attribute *attr, char *buf)
 {
        struct snd_pcm *pcm;
        const char *str;
@@ -918,7 +926,7 @@ static ssize_t show_pcm_class(struct class_device *class_device, char *buf)
                [SNDRV_PCM_CLASS_DIGITIZER] = "digitizer",
        };
 
-       if (! (pcm = class_get_devdata(class_device)) ||
+       if (! (pcm = dev_get_drvdata(dev)) ||
            pcm->dev_class > SNDRV_PCM_CLASS_LAST)
                str = "none";
        else
@@ -926,7 +934,7 @@ static ssize_t show_pcm_class(struct class_device *class_device, char *buf)
         return snprintf(buf, PAGE_SIZE, "%s\n", str);
 }
 
-static struct class_device_attribute pcm_attrs =
+static struct device_attribute pcm_attrs =
        __ATTR(pcm_class, S_IRUGO, show_pcm_class, NULL);
 
 static int snd_pcm_dev_register(struct snd_device *device)
@@ -936,6 +944,7 @@ static int snd_pcm_dev_register(struct snd_device *device)
        struct list_head *list;
        char str[16];
        struct snd_pcm *pcm = device->device_data;
+       struct device *dev;
 
        snd_assert(pcm != NULL && device != NULL, return -ENXIO);
        mutex_lock(&register_mutex);
@@ -958,11 +967,18 @@ static int snd_pcm_dev_register(struct snd_device *device)
                        devtype = SNDRV_DEVICE_TYPE_PCM_CAPTURE;
                        break;
                }
-               if ((err = snd_register_device(devtype, pcm->card,
-                                              pcm->device,
-                                              &snd_pcm_f_ops[cidx],
-                                              pcm, str)) < 0)
-               {
+               /* device pointer to use, pcm->dev takes precedence if
+                * it is assigned, otherwise fall back to card's device
+                * if possible */
+               dev = pcm->dev;
+               if (!dev)
+                       dev = pcm->card ? pcm->card->dev : NULL;
+               /* register pcm */
+               err = snd_register_device_for_dev(devtype, pcm->card,
+                                                 pcm->device,
+                                                 &snd_pcm_f_ops[cidx],
+                                                 pcm, str, dev);
+               if (err < 0) {
                        list_del(&pcm->list);
                        mutex_unlock(&register_mutex);
                        return err;