/** * Open ALSA PCM and control device files * Initial the PCM or control device */ static int gaudio_open_snd_dev(struct gaudio *card) { struct snd_pcm_file *pcm_file; struct gaudio_snd_dev *snd; if (!card) return -ENODEV; /* Open control device */ snd = &card->control; snd->filp = filp_open(fn_cntl, O_RDWR, 0); if (IS_ERR(snd->filp)) { int ret = PTR_ERR(snd->filp); ERROR(card, "unable to open sound control device file: %s\n", fn_cntl); snd->filp = NULL; return ret; } snd->card = card; /* Open PCM playback device and setup substream */ snd = &card->playback; snd->filp = filp_open(fn_play, O_WRONLY, 0); if (IS_ERR(snd->filp)) { int ret = PTR_ERR(snd->filp); ERROR(card, "No such PCM playback device: %s\n", fn_play); snd->filp = NULL; return ret; } pcm_file = snd->filp->private_data; snd->substream = pcm_file->substream; snd->card = card; playback_default_hw_params(snd); /* Open PCM capture device and setup substream */ snd = &card->capture; snd->filp = filp_open(fn_cap, O_RDONLY, 0); if (IS_ERR(snd->filp)) { ERROR(card, "No such PCM capture device: %s\n", fn_cap); snd->substream = NULL; snd->card = NULL; snd->filp = NULL; } else { pcm_file = snd->filp->private_data; snd->substream = pcm_file->substream; snd->card = card; } return 0; }
static int gaudio_open_snd_dev(struct gaudio *card) { struct snd_pcm_file *pcm_file; struct gaudio_snd_dev *snd; int res = 0; if (!card) { pr_err("%s: Card is NULL", __func__); return -ENODEV; } snd = &card->control; snd->filp = filp_open(fn_cntl, O_RDWR, 0); if (IS_ERR(snd->filp)) { int ret = PTR_ERR(snd->filp); pr_err("unable to open sound control device file: %s\n", fn_cntl); snd->filp = NULL; return ret; } snd->card = card; snd = &card->playback; snd->filp = filp_open(fn_play, O_WRONLY, 0); if (IS_ERR(snd->filp)) { pr_err("No such PCM playback device: %s\n", fn_play); snd->filp = NULL; return -EINVAL; } pr_debug("Initialized PCM playback device: %s\n", fn_play); pcm_file = snd->filp->private_data; snd->substream = pcm_file->substream; snd->card = card; res = playback_default_hw_params(snd); if (res) { pr_err("Setting playback HW params failed: err %d", res); return res; } snd = &card->capture; snd->filp = filp_open(fn_cap, O_RDONLY, 0); if (IS_ERR(snd->filp)) { pr_err("No such PCM capture device: %s\n", fn_cap); snd->substream = NULL; snd->card = NULL; snd->filp = NULL; return -EINVAL; } pcm_file = snd->filp->private_data; snd->substream = pcm_file->substream; snd->card = card; res = capture_default_hw_params(snd); if (res) pr_err("Setting capture HW params failed: err %d", res); return res; }