Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Copyright (C) 2005-2006 Micronas USA Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/moduleparam.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/time.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/i2c.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <sound/core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <sound/pcm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <sound/initval.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include "go7007-priv.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) module_param_array(index, int, NULL, 0444);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) module_param_array(id, charp, NULL, 0444);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) module_param_array(enable, bool, NULL, 0444);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) MODULE_PARM_DESC(index, "Index value for the go7007 audio driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) MODULE_PARM_DESC(id, "ID string for the go7007 audio driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) MODULE_PARM_DESC(enable, "Enable for the go7007 audio driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) struct go7007_snd {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	struct snd_card *card;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	struct snd_pcm *pcm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	struct snd_pcm_substream *substream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	spinlock_t lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	int w_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	int hw_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	int avail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	int capturing;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) static const struct snd_pcm_hardware go7007_snd_capture_hw = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	.info			= (SNDRV_PCM_INFO_MMAP |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 					SNDRV_PCM_INFO_INTERLEAVED |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 					SNDRV_PCM_INFO_BLOCK_TRANSFER |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 					SNDRV_PCM_INFO_MMAP_VALID),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	.formats		= SNDRV_PCM_FMTBIT_S16_LE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	.rates			= SNDRV_PCM_RATE_48000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	.rate_min		= 48000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	.rate_max		= 48000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	.channels_min		= 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	.channels_max		= 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	.buffer_bytes_max	= (128*1024),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	.period_bytes_min	= 4096,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	.period_bytes_max	= (128*1024),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	.periods_min		= 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	.periods_max		= 32,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) static void parse_audio_stream_data(struct go7007 *go, u8 *buf, int length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	struct go7007_snd *gosnd = go->snd_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	struct snd_pcm_runtime *runtime = gosnd->substream->runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	int frames = bytes_to_frames(runtime, length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	spin_lock_irqsave(&gosnd->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	gosnd->hw_ptr += frames;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	if (gosnd->hw_ptr >= runtime->buffer_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 		gosnd->hw_ptr -= runtime->buffer_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	gosnd->avail += frames;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	spin_unlock_irqrestore(&gosnd->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	if (gosnd->w_idx + length > runtime->dma_bytes) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		int cpy = runtime->dma_bytes - gosnd->w_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		memcpy(runtime->dma_area + gosnd->w_idx, buf, cpy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		length -= cpy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 		buf += cpy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 		gosnd->w_idx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	memcpy(runtime->dma_area + gosnd->w_idx, buf, length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	gosnd->w_idx += length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	spin_lock_irqsave(&gosnd->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	if (gosnd->avail < runtime->period_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		spin_unlock_irqrestore(&gosnd->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	gosnd->avail -= runtime->period_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	spin_unlock_irqrestore(&gosnd->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	if (gosnd->capturing)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		snd_pcm_period_elapsed(gosnd->substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) static int go7007_snd_hw_params(struct snd_pcm_substream *substream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 				struct snd_pcm_hw_params *hw_params)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	struct go7007 *go = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	go->audio_deliver = parse_audio_stream_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) static int go7007_snd_hw_free(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	struct go7007 *go = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	go->audio_deliver = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) static int go7007_snd_capture_open(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	struct go7007 *go = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	struct go7007_snd *gosnd = go->snd_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	int r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	spin_lock_irqsave(&gosnd->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	if (gosnd->substream == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		gosnd->substream = substream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 		substream->runtime->hw = go7007_snd_capture_hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		r = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		r = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	spin_unlock_irqrestore(&gosnd->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) static int go7007_snd_capture_close(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	struct go7007 *go = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	struct go7007_snd *gosnd = go->snd_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	gosnd->substream = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) static int go7007_snd_pcm_prepare(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) static int go7007_snd_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	struct go7007 *go = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	struct go7007_snd *gosnd = go->snd_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	case SNDRV_PCM_TRIGGER_START:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 		/* Just set a flag to indicate we should signal ALSA when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 		 * sound comes in */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 		gosnd->capturing = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	case SNDRV_PCM_TRIGGER_STOP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 		gosnd->hw_ptr = gosnd->w_idx = gosnd->avail = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 		gosnd->capturing = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) static snd_pcm_uframes_t go7007_snd_pcm_pointer(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	struct go7007 *go = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	struct go7007_snd *gosnd = go->snd_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	return gosnd->hw_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) static const struct snd_pcm_ops go7007_snd_capture_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	.open		= go7007_snd_capture_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	.close		= go7007_snd_capture_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	.hw_params	= go7007_snd_hw_params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	.hw_free	= go7007_snd_hw_free,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	.prepare	= go7007_snd_pcm_prepare,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	.trigger	= go7007_snd_pcm_trigger,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	.pointer	= go7007_snd_pcm_pointer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) static int go7007_snd_free(struct snd_device *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	struct go7007 *go = device->device_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	kfree(go->snd_context);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	go->snd_context = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) static struct snd_device_ops go7007_snd_device_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	.dev_free	= go7007_snd_free,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) int go7007_snd_init(struct go7007 *go)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	static int dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	struct go7007_snd *gosnd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	if (dev >= SNDRV_CARDS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	if (!enable[dev]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 		dev++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 		return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	gosnd = kmalloc(sizeof(struct go7007_snd), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	if (gosnd == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	spin_lock_init(&gosnd->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	gosnd->hw_ptr = gosnd->w_idx = gosnd->avail = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	gosnd->capturing = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	ret = snd_card_new(go->dev, index[dev], id[dev], THIS_MODULE, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 			   &gosnd->card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 		goto free_snd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	ret = snd_device_new(gosnd->card, SNDRV_DEV_LOWLEVEL, go,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 			&go7007_snd_device_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 		goto free_card;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	ret = snd_pcm_new(gosnd->card, "go7007", 0, 0, 1, &gosnd->pcm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 		goto free_card;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	strscpy(gosnd->card->driver, "go7007", sizeof(gosnd->card->driver));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	strscpy(gosnd->card->shortname, go->name, sizeof(gosnd->card->shortname));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	strscpy(gosnd->card->longname, gosnd->card->shortname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		sizeof(gosnd->card->longname));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	gosnd->pcm->private_data = go;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	snd_pcm_set_ops(gosnd->pcm, SNDRV_PCM_STREAM_CAPTURE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 			&go7007_snd_capture_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	snd_pcm_set_managed_buffer_all(gosnd->pcm, SNDRV_DMA_TYPE_VMALLOC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 				       NULL, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	ret = snd_card_register(gosnd->card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 		goto free_card;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	gosnd->substream = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	go->snd_context = gosnd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	v4l2_device_get(&go->v4l2_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	++dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) free_card:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	snd_card_free(gosnd->card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) free_snd:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	kfree(gosnd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) EXPORT_SYMBOL(go7007_snd_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) int go7007_snd_remove(struct go7007 *go)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	struct go7007_snd *gosnd = go->snd_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	snd_card_disconnect(gosnd->card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	snd_card_free_when_closed(gosnd->card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	v4l2_device_put(&go->v4l2_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) EXPORT_SYMBOL(go7007_snd_remove);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) MODULE_LICENSE("GPL v2");