^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) // Support for audio capture for tm5600/6000/6010
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) // Copyright (c) 2007-2008 Mauro Carvalho Chehab <mchehab@kernel.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) // Based on cx88-alsa.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6)
^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/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/usb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <sound/core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <sound/pcm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <sound/pcm_params.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <sound/control.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <sound/initval.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include "tm6000.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include "tm6000-regs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #undef dprintk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #define dprintk(level, fmt, arg...) do { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) if (debug >= level) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) printk(KERN_INFO "%s/1: " fmt, chip->core->name , ## arg); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) /****************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) Module global static vars
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) ****************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) module_param_array(enable, bool, NULL, 0444);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) MODULE_PARM_DESC(enable, "Enable tm6000x soundcard. default enabled.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) module_param_array(index, int, NULL, 0444);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) MODULE_PARM_DESC(index, "Index value for tm6000x capture interface(s).");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) /****************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) Module macros
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) ****************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) MODULE_DESCRIPTION("ALSA driver module for tm5600/tm6000/tm6010 based TV cards");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) MODULE_AUTHOR("Mauro Carvalho Chehab");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) MODULE_LICENSE("GPL v2");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) MODULE_SUPPORTED_DEVICE("{{Trident,tm5600},{{Trident,tm6000},{{Trident,tm6010}");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) static unsigned int debug;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) module_param(debug, int, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) MODULE_PARM_DESC(debug, "enable debug messages");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) /****************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) Module specific functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) ****************************************************************************/
^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) * BOARD Specific: Sets audio DMA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) static int _tm6000_start_audio_dma(struct snd_tm6000_card *chip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) struct tm6000_core *core = chip->core;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) dprintk(1, "Starting audio DMA\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) /* Enables audio */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) tm6000_set_reg_mask(core, TM6010_REQ07_RCC_ACTIVE_IF, 0x40, 0x40);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) tm6000_set_audio_bitrate(core, 48000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) * BOARD Specific: Resets audio DMA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) static int _tm6000_stop_audio_dma(struct snd_tm6000_card *chip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) struct tm6000_core *core = chip->core;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) dprintk(1, "Stopping audio DMA\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) /* Disables audio */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) tm6000_set_reg_mask(core, TM6010_REQ07_RCC_ACTIVE_IF, 0x00, 0x40);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) /****************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) ALSA PCM Interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) ****************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) * Digital hardware definition
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) #define DEFAULT_FIFO_SIZE 4096
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) static const struct snd_pcm_hardware snd_tm6000_digital_hw = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) .info = SNDRV_PCM_INFO_BATCH |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) SNDRV_PCM_INFO_MMAP |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) SNDRV_PCM_INFO_INTERLEAVED |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) SNDRV_PCM_INFO_BLOCK_TRANSFER |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) SNDRV_PCM_INFO_MMAP_VALID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) .formats = SNDRV_PCM_FMTBIT_S16_LE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_KNOT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) .rate_min = 48000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) .rate_max = 48000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) .channels_min = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) .channels_max = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) .period_bytes_min = 64,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) .period_bytes_max = 12544,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) .periods_min = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) .periods_max = 98,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) .buffer_bytes_max = 62720 * 8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) * audio pcm capture open callback
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) static int snd_tm6000_pcm_open(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) struct snd_tm6000_card *chip = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) struct snd_pcm_runtime *runtime = substream->runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) err = snd_pcm_hw_constraint_pow2(runtime, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) SNDRV_PCM_HW_PARAM_PERIODS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) goto _error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) chip->substream = substream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) runtime->hw = snd_tm6000_digital_hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS);
^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) _error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) dprintk(1, "Error opening PCM!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) * audio close callback
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) static int snd_tm6000_close(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) struct snd_tm6000_card *chip = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) struct tm6000_core *core = chip->core;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) if (atomic_read(&core->stream_started) > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) atomic_set(&core->stream_started, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) schedule_work(&core->wq_trigger);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) return 0;
^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) static int tm6000_fillbuf(struct tm6000_core *core, char *buf, int size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) struct snd_tm6000_card *chip = core->adev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) struct snd_pcm_substream *substream = chip->substream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) struct snd_pcm_runtime *runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) int period_elapsed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) unsigned int stride, buf_pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) int length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) if (atomic_read(&core->stream_started) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) if (!size || !substream) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) dprintk(1, "substream was NULL\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) runtime = substream->runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) if (!runtime || !runtime->dma_area) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) dprintk(1, "runtime was NULL\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) buf_pos = chip->buf_pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) stride = runtime->frame_bits >> 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) if (stride == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) dprintk(1, "stride is zero\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) length = size / stride;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) if (length == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) dprintk(1, "%s: length was zero\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) dprintk(1, "Copying %d bytes at %p[%d] - buf size=%d x %d\n", size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) runtime->dma_area, buf_pos,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) (unsigned int)runtime->buffer_size, stride);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) if (buf_pos + length >= runtime->buffer_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) unsigned int cnt = runtime->buffer_size - buf_pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) memcpy(runtime->dma_area + buf_pos * stride, buf, cnt * stride);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) memcpy(runtime->dma_area, buf + cnt * stride,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) length * stride - cnt * stride);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) memcpy(runtime->dma_area + buf_pos * stride, buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) length * stride);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) snd_pcm_stream_lock(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) chip->buf_pos += length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) if (chip->buf_pos >= runtime->buffer_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) chip->buf_pos -= runtime->buffer_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) chip->period_pos += length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) if (chip->period_pos >= runtime->period_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) chip->period_pos -= runtime->period_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) period_elapsed = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) snd_pcm_stream_unlock(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) if (period_elapsed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) snd_pcm_period_elapsed(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) * prepare callback
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) static int snd_tm6000_prepare(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) struct snd_tm6000_card *chip = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) chip->buf_pos = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) chip->period_pos = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) * trigger callback
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) static void audio_trigger(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) struct tm6000_core *core = container_of(work, struct tm6000_core,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) wq_trigger);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) struct snd_tm6000_card *chip = core->adev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) if (atomic_read(&core->stream_started)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) dprintk(1, "starting capture");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) _tm6000_start_audio_dma(chip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) dprintk(1, "stopping capture");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) _tm6000_stop_audio_dma(chip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) static int snd_tm6000_card_trigger(struct snd_pcm_substream *substream, int cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) struct snd_tm6000_card *chip = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) struct tm6000_core *core = chip->core;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) case SNDRV_PCM_TRIGGER_RESUME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) case SNDRV_PCM_TRIGGER_START:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) atomic_set(&core->stream_started, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) case SNDRV_PCM_TRIGGER_SUSPEND:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) case SNDRV_PCM_TRIGGER_STOP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) atomic_set(&core->stream_started, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) schedule_work(&core->wq_trigger);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) * pointer callback
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) static snd_pcm_uframes_t snd_tm6000_pointer(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) struct snd_tm6000_card *chip = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) return chip->buf_pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) * operators
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) static const struct snd_pcm_ops snd_tm6000_pcm_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) .open = snd_tm6000_pcm_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) .close = snd_tm6000_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) .prepare = snd_tm6000_prepare,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) .trigger = snd_tm6000_card_trigger,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) .pointer = snd_tm6000_pointer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) * create a PCM device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) /* FIXME: Control interface - How to control volume/mute? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) /****************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) Basic Flow for Sound Devices
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) ****************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) * Alsa Constructor - Component probe
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) static int tm6000_audio_init(struct tm6000_core *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) struct snd_card *card;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) struct snd_tm6000_card *chip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) static int devnr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) char component[14];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) struct snd_pcm *pcm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) if (!dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) if (devnr >= SNDRV_CARDS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) if (!enable[devnr])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) rc = snd_card_new(&dev->udev->dev, index[devnr], "tm6000",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) THIS_MODULE, 0, &card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) if (rc < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) snd_printk(KERN_ERR "cannot create card instance %d\n", devnr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) strscpy(card->driver, "tm6000-alsa", sizeof(card->driver));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) strscpy(card->shortname, "TM5600/60x0", sizeof(card->shortname));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) sprintf(card->longname, "TM5600/60x0 Audio at bus %d device %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) dev->udev->bus->busnum, dev->udev->devnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) sprintf(component, "USB%04x:%04x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) le16_to_cpu(dev->udev->descriptor.idVendor),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) le16_to_cpu(dev->udev->descriptor.idProduct));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) snd_component_add(card, component);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) chip = kzalloc(sizeof(struct snd_tm6000_card), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) if (!chip) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) chip->core = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) chip->card = card;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) dev->adev = chip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) spin_lock_init(&chip->reg_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) rc = snd_pcm_new(card, "TM6000 Audio", 0, 0, 1, &pcm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) if (rc < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) goto error_chip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) pcm->info_flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) pcm->private_data = chip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) strscpy(pcm->name, "Trident TM5600/60x0", sizeof(pcm->name));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_tm6000_pcm_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_VMALLOC, NULL, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) INIT_WORK(&dev->wq_trigger, audio_trigger);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) rc = snd_card_register(card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) if (rc < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) goto error_chip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) dprintk(1, "Registered audio driver for %s\n", card->longname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) error_chip:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) kfree(chip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) dev->adev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) snd_card_free(card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) static int tm6000_audio_fini(struct tm6000_core *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) struct snd_tm6000_card *chip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) if (!dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) chip = dev->adev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) if (!chip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) if (!chip->card)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) snd_card_free(chip->card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) chip->card = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) kfree(chip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) dev->adev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) static struct tm6000_ops audio_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) .type = TM6000_AUDIO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) .name = "TM6000 Audio Extension",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) .init = tm6000_audio_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) .fini = tm6000_audio_fini,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) .fillbuf = tm6000_fillbuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) static int __init tm6000_alsa_register(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) return tm6000_register_extension(&audio_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) static void __exit tm6000_alsa_unregister(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) tm6000_unregister_extension(&audio_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) module_init(tm6000_alsa_register);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) module_exit(tm6000_alsa_unregister);