int snd_cx18_pcm_create(struct snd_cx18_card *cxsc) { struct snd_pcm *sp; struct snd_card *sc = cxsc->sc; struct v4l2_device *v4l2_dev = cxsc->v4l2_dev; struct cx18 *cx = to_cx18(v4l2_dev); int ret; ret = snd_pcm_new(sc, "CX23418 PCM", 0, /* PCM device 0, the only one for this card */ 0, /* 0 playback substreams */ 1, /* 1 capture substream */ &sp); if (ret) { CX18_ALSA_ERR("%s: snd_cx18_pcm_create() failed with err %d\n", __func__, ret); goto err_exit; } spin_lock_init(&cxsc->slock); snd_pcm_set_ops(sp, SNDRV_PCM_STREAM_CAPTURE, &snd_cx18_pcm_capture_ops); sp->info_flags = 0; sp->private_data = cxsc; strlcpy(sp->name, cx->card_name, sizeof(sp->name)); return 0; err_exit: return ret; }
int cx18_alsa_load(struct cx18 *cx) { struct v4l2_device *v4l2_dev = &cx->v4l2_dev; struct cx18_stream *s; if (v4l2_dev == NULL) { printk(KERN_ERR "cx18-alsa: %s: struct v4l2_device * is NULL\n", __func__); return 0; } cx = to_cx18(v4l2_dev); if (cx == NULL) { printk(KERN_ERR "cx18-alsa cx is NULL\n"); return 0; } s = &cx->streams[CX18_ENC_STREAM_TYPE_PCM]; if (s->video_dev == NULL) { CX18_DEBUG_ALSA_INFO("%s: PCM stream for card is disabled - " "skipping\n", __func__); return 0; } if (cx->alsa != NULL) { CX18_ALSA_ERR("%s: struct snd_cx18_card * already exists\n", __func__); return 0; } if (snd_cx18_init(v4l2_dev)) { CX18_ALSA_ERR("%s: failed to create struct snd_cx18_card\n", __func__); } else { CX18_DEBUG_ALSA_INFO("%s: created cx18 ALSA interface instance " "\n", __func__); } return 0; }
static int snd_cx18_init(struct v4l2_device *v4l2_dev) { struct cx18 *cx = to_cx18(v4l2_dev); struct snd_card *sc = NULL; struct snd_cx18_card *cxsc; int ret; /* Numbrs steps from "Writing an ALSA Driver" by Takashi Iwai */ /* (1) Check and increment the device index */ /* This is a no-op for us. We'll use the cx->instance */ /* (2) Create a card instance */ ret = snd_card_create(SNDRV_DEFAULT_IDX1, /* use first available id */ SNDRV_DEFAULT_STR1, /* xid from end of shortname*/ THIS_MODULE, 0, &sc); if (ret) { CX18_ALSA_ERR("%s: snd_card_create() failed with err %d\n", __func__, ret); goto err_exit; } /* (3) Create a main component */ ret = snd_cx18_card_create(v4l2_dev, sc, &cxsc); if (ret) { CX18_ALSA_ERR("%s: snd_cx18_card_create() failed with err %d\n", __func__, ret); goto err_exit_free; } /* (4) Set the driver ID and name strings */ snd_cx18_card_set_names(cxsc); ret = snd_cx18_pcm_create(cxsc); if (ret) { CX18_ALSA_ERR("%s: snd_cx18_pcm_create() failed with err %d\n", __func__, ret); goto err_exit_free; } /* FIXME - proc files */ /* (7) Set the driver data and return 0 */ /* We do this out of normal order for PCI drivers to avoid races */ cx->alsa = cxsc; /* (6) Register the card instance */ ret = snd_card_register(sc); if (ret) { cx->alsa = NULL; CX18_ALSA_ERR("%s: snd_card_register() failed with err %d\n", __func__, ret); goto err_exit_free; } return 0; err_exit_free: if (sc != NULL) snd_card_free(sc); kfree(cxsc); err_exit: return ret; }
static int snd_cx18_init(struct v4l2_device *v4l2_dev) { struct cx18 *cx = to_cx18(v4l2_dev); struct snd_card *sc = NULL; struct snd_cx18_card *cxsc; int ret; /* */ /* */ /* */ /* */ ret = snd_card_create(SNDRV_DEFAULT_IDX1, /* */ SNDRV_DEFAULT_STR1, /* */ THIS_MODULE, 0, &sc); if (ret) { CX18_ALSA_ERR("%s: snd_card_create() failed with err %d\n", __func__, ret); goto err_exit; } /* */ ret = snd_cx18_card_create(v4l2_dev, sc, &cxsc); if (ret) { CX18_ALSA_ERR("%s: snd_cx18_card_create() failed with err %d\n", __func__, ret); goto err_exit_free; } /* */ snd_cx18_card_set_names(cxsc); ret = snd_cx18_pcm_create(cxsc); if (ret) { CX18_ALSA_ERR("%s: snd_cx18_pcm_create() failed with err %d\n", __func__, ret); goto err_exit_free; } /* */ /* */ /* */ cx->alsa = cxsc; /* */ ret = snd_card_register(sc); if (ret) { cx->alsa = NULL; CX18_ALSA_ERR("%s: snd_card_register() failed with err %d\n", __func__, ret); goto err_exit_free; } return 0; err_exit_free: if (sc != NULL) snd_card_free(sc); kfree(cxsc); err_exit: return ret; }