示例#1
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;
}