Mauro Carvalho Chehab | d72d506 | 2008-01-11 10:28:50 -0300 | [diff] [blame] | 1 | /* |
| 2 | * |
Dmitri Belimov | e28f49b | 2010-02-22 06:32:15 -0300 | [diff] [blame] | 3 | * Support for audio capture for tm5600/6000/6010 |
Mauro Carvalho Chehab | 7ca30c5 | 2008-01-11 13:19:09 -0300 | [diff] [blame] | 4 | * (c) 2007-2008 Mauro Carvalho Chehab <mchehab@redhat.com> |
Mauro Carvalho Chehab | d72d506 | 2008-01-11 10:28:50 -0300 | [diff] [blame] | 5 | * |
Mauro Carvalho Chehab | 7ca30c5 | 2008-01-11 13:19:09 -0300 | [diff] [blame] | 6 | * Based on cx88-alsa.c |
Mauro Carvalho Chehab | d72d506 | 2008-01-11 10:28:50 -0300 | [diff] [blame] | 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
Mauro Carvalho Chehab | 7ca30c5 | 2008-01-11 13:19:09 -0300 | [diff] [blame] | 9 | * it under the terms of the GNU General Public License version 2 as |
| 10 | * published by the Free Software Foundation. |
Mauro Carvalho Chehab | d72d506 | 2008-01-11 10:28:50 -0300 | [diff] [blame] | 11 | */ |
| 12 | |
| 13 | #include <linux/module.h> |
| 14 | #include <linux/init.h> |
| 15 | #include <linux/device.h> |
| 16 | #include <linux/interrupt.h> |
Mauro Carvalho Chehab | 6ad6e88 | 2008-01-11 13:51:45 -0300 | [diff] [blame] | 17 | #include <linux/usb.h> |
Mauro Carvalho Chehab | d72d506 | 2008-01-11 10:28:50 -0300 | [diff] [blame] | 18 | |
| 19 | #include <asm/delay.h> |
Mauro Carvalho Chehab | d72d506 | 2008-01-11 10:28:50 -0300 | [diff] [blame] | 20 | #include <sound/core.h> |
| 21 | #include <sound/pcm.h> |
| 22 | #include <sound/pcm_params.h> |
| 23 | #include <sound/control.h> |
| 24 | #include <sound/initval.h> |
Mauro Carvalho Chehab | d72d506 | 2008-01-11 10:28:50 -0300 | [diff] [blame] | 25 | |
Mauro Carvalho Chehab | d72d506 | 2008-01-11 10:28:50 -0300 | [diff] [blame] | 26 | |
Mauro Carvalho Chehab | 7ca30c5 | 2008-01-11 13:19:09 -0300 | [diff] [blame] | 27 | #include "tm6000.h" |
| 28 | #include "tm6000-regs.h" |
Mauro Carvalho Chehab | d72d506 | 2008-01-11 10:28:50 -0300 | [diff] [blame] | 29 | |
Mauro Carvalho Chehab | 7ca30c5 | 2008-01-11 13:19:09 -0300 | [diff] [blame] | 30 | #undef dprintk |
| 31 | |
| 32 | #define dprintk(level, fmt, arg...) do { \ |
| 33 | if (debug >= level) \ |
| 34 | printk(KERN_INFO "%s/1: " fmt, chip->core->name , ## arg); \ |
| 35 | } while (0) |
Mauro Carvalho Chehab | d72d506 | 2008-01-11 10:28:50 -0300 | [diff] [blame] | 36 | |
| 37 | /**************************************************************************** |
| 38 | Data type declarations - Can be moded to a header file later |
| 39 | ****************************************************************************/ |
| 40 | |
Mauro Carvalho Chehab | 7ca30c5 | 2008-01-11 13:19:09 -0300 | [diff] [blame] | 41 | struct snd_tm6000_card { |
Mauro Carvalho Chehab | d72d506 | 2008-01-11 10:28:50 -0300 | [diff] [blame] | 42 | struct snd_card *card; |
| 43 | |
| 44 | spinlock_t reg_lock; |
Mauro Carvalho Chehab | 7ca30c5 | 2008-01-11 13:19:09 -0300 | [diff] [blame] | 45 | |
Mauro Carvalho Chehab | d72d506 | 2008-01-11 10:28:50 -0300 | [diff] [blame] | 46 | atomic_t count; |
| 47 | |
Mauro Carvalho Chehab | d72d506 | 2008-01-11 10:28:50 -0300 | [diff] [blame] | 48 | unsigned int period_size; |
| 49 | unsigned int num_periods; |
| 50 | |
Mauro Carvalho Chehab | 7ca30c5 | 2008-01-11 13:19:09 -0300 | [diff] [blame] | 51 | struct tm6000_core *core; |
| 52 | struct tm6000_buffer *buf; |
Mauro Carvalho Chehab | d72d506 | 2008-01-11 10:28:50 -0300 | [diff] [blame] | 53 | |
Mauro Carvalho Chehab | 7ca30c5 | 2008-01-11 13:19:09 -0300 | [diff] [blame] | 54 | int bufsize; |
Mauro Carvalho Chehab | d72d506 | 2008-01-11 10:28:50 -0300 | [diff] [blame] | 55 | |
Mauro Carvalho Chehab | 7ca30c5 | 2008-01-11 13:19:09 -0300 | [diff] [blame] | 56 | struct snd_pcm_substream *substream; |
Mauro Carvalho Chehab | d72d506 | 2008-01-11 10:28:50 -0300 | [diff] [blame] | 57 | }; |
Mauro Carvalho Chehab | d72d506 | 2008-01-11 10:28:50 -0300 | [diff] [blame] | 58 | |
| 59 | |
| 60 | /**************************************************************************** |
| 61 | Module global static vars |
| 62 | ****************************************************************************/ |
| 63 | |
| 64 | static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ |
Mauro Carvalho Chehab | 6ad6e88 | 2008-01-11 13:51:45 -0300 | [diff] [blame] | 65 | static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ |
Mauro Carvalho Chehab | d72d506 | 2008-01-11 10:28:50 -0300 | [diff] [blame] | 66 | static int enable[SNDRV_CARDS] = {1, [1 ... (SNDRV_CARDS - 1)] = 1}; |
| 67 | |
| 68 | module_param_array(enable, bool, NULL, 0444); |
Mauro Carvalho Chehab | 7ca30c5 | 2008-01-11 13:19:09 -0300 | [diff] [blame] | 69 | MODULE_PARM_DESC(enable, "Enable tm6000x soundcard. default enabled."); |
Mauro Carvalho Chehab | d72d506 | 2008-01-11 10:28:50 -0300 | [diff] [blame] | 70 | |
| 71 | module_param_array(index, int, NULL, 0444); |
Mauro Carvalho Chehab | 7ca30c5 | 2008-01-11 13:19:09 -0300 | [diff] [blame] | 72 | MODULE_PARM_DESC(index, "Index value for tm6000x capture interface(s)."); |
Mauro Carvalho Chehab | d72d506 | 2008-01-11 10:28:50 -0300 | [diff] [blame] | 73 | |
| 74 | |
| 75 | /**************************************************************************** |
| 76 | Module macros |
| 77 | ****************************************************************************/ |
| 78 | |
Dmitri Belimov | e28f49b | 2010-02-22 06:32:15 -0300 | [diff] [blame] | 79 | MODULE_DESCRIPTION("ALSA driver module for tm5600/tm6000/tm6010 based TV cards"); |
Mauro Carvalho Chehab | d72d506 | 2008-01-11 10:28:50 -0300 | [diff] [blame] | 80 | MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>"); |
| 81 | MODULE_LICENSE("GPL"); |
Mauro Carvalho Chehab | 7ca30c5 | 2008-01-11 13:19:09 -0300 | [diff] [blame] | 82 | MODULE_SUPPORTED_DEVICE("{{Trident,tm5600}," |
Dmitri Belimov | e28f49b | 2010-02-22 06:32:15 -0300 | [diff] [blame] | 83 | "{{Trident,tm6000}," |
| 84 | "{{Trident,tm6010}"); |
Mauro Carvalho Chehab | d72d506 | 2008-01-11 10:28:50 -0300 | [diff] [blame] | 85 | static unsigned int debug; |
Mauro Carvalho Chehab | 7ca30c5 | 2008-01-11 13:19:09 -0300 | [diff] [blame] | 86 | module_param(debug, int, 0644); |
| 87 | MODULE_PARM_DESC(debug, "enable debug messages"); |
Mauro Carvalho Chehab | d72d506 | 2008-01-11 10:28:50 -0300 | [diff] [blame] | 88 | |
| 89 | /**************************************************************************** |
| 90 | Module specific funtions |
| 91 | ****************************************************************************/ |
| 92 | |
| 93 | /* |
| 94 | * BOARD Specific: Sets audio DMA |
| 95 | */ |
| 96 | |
Mauro Carvalho Chehab | 7ca30c5 | 2008-01-11 13:19:09 -0300 | [diff] [blame] | 97 | static int _tm6000_start_audio_dma(struct snd_tm6000_card *chip) |
Mauro Carvalho Chehab | d72d506 | 2008-01-11 10:28:50 -0300 | [diff] [blame] | 98 | { |
Mauro Carvalho Chehab | 7ca30c5 | 2008-01-11 13:19:09 -0300 | [diff] [blame] | 99 | struct tm6000_core *core = chip->core; |
| 100 | int val; |
Mauro Carvalho Chehab | d72d506 | 2008-01-11 10:28:50 -0300 | [diff] [blame] | 101 | |
Mauro Carvalho Chehab | 7ca30c5 | 2008-01-11 13:19:09 -0300 | [diff] [blame] | 102 | /* Enables audio */ |
Mauro Carvalho Chehab | 9afec49 | 2010-03-11 10:26:46 -0300 | [diff] [blame] | 103 | val = tm6000_get_reg(core, TM6010_REQ07_RCC_ACTIVE_VIDEO_IF, 0x0); |
Mauro Carvalho Chehab | 7ca30c5 | 2008-01-11 13:19:09 -0300 | [diff] [blame] | 104 | val |= 0x20; |
Mauro Carvalho Chehab | 9afec49 | 2010-03-11 10:26:46 -0300 | [diff] [blame] | 105 | tm6000_set_reg(core, TM6010_REQ07_RCC_ACTIVE_VIDEO_IF, val); |
Mauro Carvalho Chehab | d72d506 | 2008-01-11 10:28:50 -0300 | [diff] [blame] | 106 | |
Mauro Carvalho Chehab | 9afec49 | 2010-03-11 10:26:46 -0300 | [diff] [blame] | 107 | tm6000_set_reg(core, TM6010_REQ08_R01_A_INIT, 0x80); |
Mauro Carvalho Chehab | d72d506 | 2008-01-11 10:28:50 -0300 | [diff] [blame] | 108 | |
| 109 | return 0; |
| 110 | } |
| 111 | |
| 112 | /* |
| 113 | * BOARD Specific: Resets audio DMA |
| 114 | */ |
Mauro Carvalho Chehab | 7ca30c5 | 2008-01-11 13:19:09 -0300 | [diff] [blame] | 115 | static int _tm6000_stop_audio_dma(struct snd_tm6000_card *chip) |
Mauro Carvalho Chehab | d72d506 | 2008-01-11 10:28:50 -0300 | [diff] [blame] | 116 | { |
Mauro Carvalho Chehab | 7ca30c5 | 2008-01-11 13:19:09 -0300 | [diff] [blame] | 117 | struct tm6000_core *core = chip->core; |
| 118 | int val; |
Mauro Carvalho Chehab | d72d506 | 2008-01-11 10:28:50 -0300 | [diff] [blame] | 119 | dprintk(1, "Stopping audio DMA\n"); |
| 120 | |
Mauro Carvalho Chehab | 7ca30c5 | 2008-01-11 13:19:09 -0300 | [diff] [blame] | 121 | /* Enables audio */ |
Mauro Carvalho Chehab | 9afec49 | 2010-03-11 10:26:46 -0300 | [diff] [blame] | 122 | val = tm6000_get_reg(core, TM6010_REQ07_RCC_ACTIVE_VIDEO_IF, 0x0); |
Mauro Carvalho Chehab | 7ca30c5 | 2008-01-11 13:19:09 -0300 | [diff] [blame] | 123 | val &= ~0x20; |
Mauro Carvalho Chehab | 9afec49 | 2010-03-11 10:26:46 -0300 | [diff] [blame] | 124 | tm6000_set_reg(core, TM6010_REQ07_RCC_ACTIVE_VIDEO_IF, val); |
Mauro Carvalho Chehab | d72d506 | 2008-01-11 10:28:50 -0300 | [diff] [blame] | 125 | |
Mauro Carvalho Chehab | 9afec49 | 2010-03-11 10:26:46 -0300 | [diff] [blame] | 126 | tm6000_set_reg(core, TM6010_REQ08_R01_A_INIT, 0); |
Mauro Carvalho Chehab | d72d506 | 2008-01-11 10:28:50 -0300 | [diff] [blame] | 127 | |
| 128 | return 0; |
| 129 | } |
| 130 | |
Mauro Carvalho Chehab | 7ca30c5 | 2008-01-11 13:19:09 -0300 | [diff] [blame] | 131 | static int dsp_buffer_free(struct snd_tm6000_card *chip) |
Mauro Carvalho Chehab | d72d506 | 2008-01-11 10:28:50 -0300 | [diff] [blame] | 132 | { |
Mauro Carvalho Chehab | 7ca30c5 | 2008-01-11 13:19:09 -0300 | [diff] [blame] | 133 | BUG_ON(!chip->bufsize); |
Mauro Carvalho Chehab | d72d506 | 2008-01-11 10:28:50 -0300 | [diff] [blame] | 134 | |
Mauro Carvalho Chehab | 7ca30c5 | 2008-01-11 13:19:09 -0300 | [diff] [blame] | 135 | dprintk(2, "Freeing buffer\n"); |
Mauro Carvalho Chehab | d72d506 | 2008-01-11 10:28:50 -0300 | [diff] [blame] | 136 | |
Mauro Carvalho Chehab | 7ca30c5 | 2008-01-11 13:19:09 -0300 | [diff] [blame] | 137 | /* FIXME: Frees buffer */ |
Mauro Carvalho Chehab | d72d506 | 2008-01-11 10:28:50 -0300 | [diff] [blame] | 138 | |
Mauro Carvalho Chehab | 7ca30c5 | 2008-01-11 13:19:09 -0300 | [diff] [blame] | 139 | chip->bufsize = 0; |
Mauro Carvalho Chehab | d72d506 | 2008-01-11 10:28:50 -0300 | [diff] [blame] | 140 | |
Mauro Carvalho Chehab | 7ca30c5 | 2008-01-11 13:19:09 -0300 | [diff] [blame] | 141 | return 0; |
Mauro Carvalho Chehab | d72d506 | 2008-01-11 10:28:50 -0300 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | /**************************************************************************** |
| 145 | ALSA PCM Interface |
| 146 | ****************************************************************************/ |
| 147 | |
| 148 | /* |
| 149 | * Digital hardware definition |
| 150 | */ |
| 151 | #define DEFAULT_FIFO_SIZE 4096 |
Mauro Carvalho Chehab | 7ca30c5 | 2008-01-11 13:19:09 -0300 | [diff] [blame] | 152 | |
| 153 | static struct snd_pcm_hardware snd_tm6000_digital_hw = { |
Mauro Carvalho Chehab | d72d506 | 2008-01-11 10:28:50 -0300 | [diff] [blame] | 154 | .info = SNDRV_PCM_INFO_MMAP | |
| 155 | SNDRV_PCM_INFO_INTERLEAVED | |
| 156 | SNDRV_PCM_INFO_BLOCK_TRANSFER | |
| 157 | SNDRV_PCM_INFO_MMAP_VALID, |
| 158 | .formats = SNDRV_PCM_FMTBIT_S16_LE, |
| 159 | |
Mauro Carvalho Chehab | 7ca30c5 | 2008-01-11 13:19:09 -0300 | [diff] [blame] | 160 | .rates = SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000, |
| 161 | .rate_min = 44100, |
Mauro Carvalho Chehab | d72d506 | 2008-01-11 10:28:50 -0300 | [diff] [blame] | 162 | .rate_max = 48000, |
| 163 | .channels_min = 2, |
| 164 | .channels_max = 2, |
Mauro Carvalho Chehab | d72d506 | 2008-01-11 10:28:50 -0300 | [diff] [blame] | 165 | .period_bytes_min = DEFAULT_FIFO_SIZE/4, |
| 166 | .period_bytes_max = DEFAULT_FIFO_SIZE/4, |
| 167 | .periods_min = 1, |
| 168 | .periods_max = 1024, |
| 169 | .buffer_bytes_max = (1024*1024), |
| 170 | }; |
| 171 | |
| 172 | /* |
| 173 | * audio pcm capture open callback |
| 174 | */ |
Mauro Carvalho Chehab | 7ca30c5 | 2008-01-11 13:19:09 -0300 | [diff] [blame] | 175 | static int snd_tm6000_pcm_open(struct snd_pcm_substream *substream) |
Mauro Carvalho Chehab | d72d506 | 2008-01-11 10:28:50 -0300 | [diff] [blame] | 176 | { |
Mauro Carvalho Chehab | 7ca30c5 | 2008-01-11 13:19:09 -0300 | [diff] [blame] | 177 | struct snd_tm6000_card *chip = snd_pcm_substream_chip(substream); |
Mauro Carvalho Chehab | d72d506 | 2008-01-11 10:28:50 -0300 | [diff] [blame] | 178 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 179 | int err; |
| 180 | |
Mauro Carvalho Chehab | 7ca30c5 | 2008-01-11 13:19:09 -0300 | [diff] [blame] | 181 | err = snd_pcm_hw_constraint_pow2(runtime, 0, |
| 182 | SNDRV_PCM_HW_PARAM_PERIODS); |
Mauro Carvalho Chehab | d72d506 | 2008-01-11 10:28:50 -0300 | [diff] [blame] | 183 | if (err < 0) |
| 184 | goto _error; |
| 185 | |
| 186 | chip->substream = substream; |
| 187 | |
Mauro Carvalho Chehab | 7ca30c5 | 2008-01-11 13:19:09 -0300 | [diff] [blame] | 188 | runtime->hw = snd_tm6000_digital_hw; |
Mauro Carvalho Chehab | d72d506 | 2008-01-11 10:28:50 -0300 | [diff] [blame] | 189 | |
| 190 | return 0; |
| 191 | _error: |
Mauro Carvalho Chehab | 7ca30c5 | 2008-01-11 13:19:09 -0300 | [diff] [blame] | 192 | dprintk(1, "Error opening PCM!\n"); |
Mauro Carvalho Chehab | d72d506 | 2008-01-11 10:28:50 -0300 | [diff] [blame] | 193 | return err; |
| 194 | } |
| 195 | |
| 196 | /* |
| 197 | * audio close callback |
| 198 | */ |
Mauro Carvalho Chehab | 7ca30c5 | 2008-01-11 13:19:09 -0300 | [diff] [blame] | 199 | static int snd_tm6000_close(struct snd_pcm_substream *substream) |
Mauro Carvalho Chehab | d72d506 | 2008-01-11 10:28:50 -0300 | [diff] [blame] | 200 | { |
| 201 | return 0; |
| 202 | } |
| 203 | |
| 204 | /* |
| 205 | * hw_params callback |
| 206 | */ |
Mauro Carvalho Chehab | 7ca30c5 | 2008-01-11 13:19:09 -0300 | [diff] [blame] | 207 | static int snd_tm6000_hw_params(struct snd_pcm_substream *substream, |
| 208 | struct snd_pcm_hw_params *hw_params) |
Mauro Carvalho Chehab | d72d506 | 2008-01-11 10:28:50 -0300 | [diff] [blame] | 209 | { |
Mauro Carvalho Chehab | 7ca30c5 | 2008-01-11 13:19:09 -0300 | [diff] [blame] | 210 | struct snd_tm6000_card *chip = snd_pcm_substream_chip(substream); |
Mauro Carvalho Chehab | d72d506 | 2008-01-11 10:28:50 -0300 | [diff] [blame] | 211 | |
| 212 | if (substream->runtime->dma_area) { |
| 213 | dsp_buffer_free(chip); |
| 214 | substream->runtime->dma_area = NULL; |
| 215 | } |
| 216 | |
| 217 | chip->period_size = params_period_bytes(hw_params); |
| 218 | chip->num_periods = params_periods(hw_params); |
Mauro Carvalho Chehab | 7ca30c5 | 2008-01-11 13:19:09 -0300 | [diff] [blame] | 219 | chip->bufsize = chip->period_size * params_periods(hw_params); |
Mauro Carvalho Chehab | d72d506 | 2008-01-11 10:28:50 -0300 | [diff] [blame] | 220 | |
Mauro Carvalho Chehab | 7ca30c5 | 2008-01-11 13:19:09 -0300 | [diff] [blame] | 221 | BUG_ON(!chip->bufsize); |
Mauro Carvalho Chehab | d72d506 | 2008-01-11 10:28:50 -0300 | [diff] [blame] | 222 | |
Mauro Carvalho Chehab | 7ca30c5 | 2008-01-11 13:19:09 -0300 | [diff] [blame] | 223 | dprintk(1, "Setting buffer\n"); |
Mauro Carvalho Chehab | d72d506 | 2008-01-11 10:28:50 -0300 | [diff] [blame] | 224 | |
Mauro Carvalho Chehab | 7ca30c5 | 2008-01-11 13:19:09 -0300 | [diff] [blame] | 225 | /* FIXME: Allocate buffer for audio */ |
Mauro Carvalho Chehab | d72d506 | 2008-01-11 10:28:50 -0300 | [diff] [blame] | 226 | |
Mauro Carvalho Chehab | d72d506 | 2008-01-11 10:28:50 -0300 | [diff] [blame] | 227 | |
Mauro Carvalho Chehab | d72d506 | 2008-01-11 10:28:50 -0300 | [diff] [blame] | 228 | return 0; |
Mauro Carvalho Chehab | d72d506 | 2008-01-11 10:28:50 -0300 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | /* |
| 232 | * hw free callback |
| 233 | */ |
Mauro Carvalho Chehab | 7ca30c5 | 2008-01-11 13:19:09 -0300 | [diff] [blame] | 234 | static int snd_tm6000_hw_free(struct snd_pcm_substream *substream) |
Mauro Carvalho Chehab | d72d506 | 2008-01-11 10:28:50 -0300 | [diff] [blame] | 235 | { |
| 236 | |
Mauro Carvalho Chehab | 7ca30c5 | 2008-01-11 13:19:09 -0300 | [diff] [blame] | 237 | struct snd_tm6000_card *chip = snd_pcm_substream_chip(substream); |
Mauro Carvalho Chehab | d72d506 | 2008-01-11 10:28:50 -0300 | [diff] [blame] | 238 | |
| 239 | if (substream->runtime->dma_area) { |
| 240 | dsp_buffer_free(chip); |
| 241 | substream->runtime->dma_area = NULL; |
| 242 | } |
| 243 | |
| 244 | return 0; |
| 245 | } |
| 246 | |
| 247 | /* |
| 248 | * prepare callback |
| 249 | */ |
Mauro Carvalho Chehab | 7ca30c5 | 2008-01-11 13:19:09 -0300 | [diff] [blame] | 250 | static int snd_tm6000_prepare(struct snd_pcm_substream *substream) |
Mauro Carvalho Chehab | d72d506 | 2008-01-11 10:28:50 -0300 | [diff] [blame] | 251 | { |
| 252 | return 0; |
| 253 | } |
| 254 | |
Mauro Carvalho Chehab | 7ca30c5 | 2008-01-11 13:19:09 -0300 | [diff] [blame] | 255 | |
Mauro Carvalho Chehab | d72d506 | 2008-01-11 10:28:50 -0300 | [diff] [blame] | 256 | /* |
| 257 | * trigger callback |
| 258 | */ |
Mauro Carvalho Chehab | 7ca30c5 | 2008-01-11 13:19:09 -0300 | [diff] [blame] | 259 | static int snd_tm6000_card_trigger(struct snd_pcm_substream *substream, int cmd) |
Mauro Carvalho Chehab | d72d506 | 2008-01-11 10:28:50 -0300 | [diff] [blame] | 260 | { |
Mauro Carvalho Chehab | 7ca30c5 | 2008-01-11 13:19:09 -0300 | [diff] [blame] | 261 | struct snd_tm6000_card *chip = snd_pcm_substream_chip(substream); |
Mauro Carvalho Chehab | d72d506 | 2008-01-11 10:28:50 -0300 | [diff] [blame] | 262 | int err; |
| 263 | |
Mauro Carvalho Chehab | d72d506 | 2008-01-11 10:28:50 -0300 | [diff] [blame] | 264 | spin_lock(&chip->reg_lock); |
| 265 | |
| 266 | switch (cmd) { |
| 267 | case SNDRV_PCM_TRIGGER_START: |
Mauro Carvalho Chehab | 7ca30c5 | 2008-01-11 13:19:09 -0300 | [diff] [blame] | 268 | err = _tm6000_start_audio_dma(chip); |
Mauro Carvalho Chehab | d72d506 | 2008-01-11 10:28:50 -0300 | [diff] [blame] | 269 | break; |
| 270 | case SNDRV_PCM_TRIGGER_STOP: |
Mauro Carvalho Chehab | 7ca30c5 | 2008-01-11 13:19:09 -0300 | [diff] [blame] | 271 | err = _tm6000_stop_audio_dma(chip); |
Mauro Carvalho Chehab | d72d506 | 2008-01-11 10:28:50 -0300 | [diff] [blame] | 272 | break; |
| 273 | default: |
Mauro Carvalho Chehab | 7ca30c5 | 2008-01-11 13:19:09 -0300 | [diff] [blame] | 274 | err = -EINVAL; |
Mauro Carvalho Chehab | d72d506 | 2008-01-11 10:28:50 -0300 | [diff] [blame] | 275 | break; |
| 276 | } |
| 277 | |
| 278 | spin_unlock(&chip->reg_lock); |
| 279 | |
| 280 | return err; |
| 281 | } |
| 282 | |
| 283 | /* |
| 284 | * pointer callback |
| 285 | */ |
Mauro Carvalho Chehab | 7ca30c5 | 2008-01-11 13:19:09 -0300 | [diff] [blame] | 286 | static snd_pcm_uframes_t snd_tm6000_pointer(struct snd_pcm_substream *substream) |
Mauro Carvalho Chehab | d72d506 | 2008-01-11 10:28:50 -0300 | [diff] [blame] | 287 | { |
Mauro Carvalho Chehab | 7ca30c5 | 2008-01-11 13:19:09 -0300 | [diff] [blame] | 288 | struct snd_tm6000_card *chip = snd_pcm_substream_chip(substream); |
Mauro Carvalho Chehab | d72d506 | 2008-01-11 10:28:50 -0300 | [diff] [blame] | 289 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 290 | u16 count; |
| 291 | |
| 292 | count = atomic_read(&chip->count); |
| 293 | |
Mauro Carvalho Chehab | d72d506 | 2008-01-11 10:28:50 -0300 | [diff] [blame] | 294 | return runtime->period_size * (count & (runtime->periods-1)); |
| 295 | } |
| 296 | |
| 297 | /* |
Mauro Carvalho Chehab | d72d506 | 2008-01-11 10:28:50 -0300 | [diff] [blame] | 298 | * operators |
| 299 | */ |
Mauro Carvalho Chehab | 7ca30c5 | 2008-01-11 13:19:09 -0300 | [diff] [blame] | 300 | static struct snd_pcm_ops snd_tm6000_pcm_ops = { |
| 301 | .open = snd_tm6000_pcm_open, |
| 302 | .close = snd_tm6000_close, |
Mauro Carvalho Chehab | d72d506 | 2008-01-11 10:28:50 -0300 | [diff] [blame] | 303 | .ioctl = snd_pcm_lib_ioctl, |
Mauro Carvalho Chehab | 7ca30c5 | 2008-01-11 13:19:09 -0300 | [diff] [blame] | 304 | .hw_params = snd_tm6000_hw_params, |
| 305 | .hw_free = snd_tm6000_hw_free, |
| 306 | .prepare = snd_tm6000_prepare, |
| 307 | .trigger = snd_tm6000_card_trigger, |
| 308 | .pointer = snd_tm6000_pointer, |
Mauro Carvalho Chehab | d72d506 | 2008-01-11 10:28:50 -0300 | [diff] [blame] | 309 | }; |
| 310 | |
| 311 | /* |
| 312 | * create a PCM device |
| 313 | */ |
Mauro Carvalho Chehab | 7ca30c5 | 2008-01-11 13:19:09 -0300 | [diff] [blame] | 314 | static int __devinit snd_tm6000_pcm(struct snd_tm6000_card *chip, |
| 315 | int device, char *name) |
Mauro Carvalho Chehab | d72d506 | 2008-01-11 10:28:50 -0300 | [diff] [blame] | 316 | { |
| 317 | int err; |
| 318 | struct snd_pcm *pcm; |
| 319 | |
| 320 | err = snd_pcm_new(chip->card, name, device, 0, 1, &pcm); |
| 321 | if (err < 0) |
| 322 | return err; |
| 323 | pcm->private_data = chip; |
| 324 | strcpy(pcm->name, name); |
Mauro Carvalho Chehab | 7ca30c5 | 2008-01-11 13:19:09 -0300 | [diff] [blame] | 325 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_tm6000_pcm_ops); |
Mauro Carvalho Chehab | d72d506 | 2008-01-11 10:28:50 -0300 | [diff] [blame] | 326 | |
| 327 | return 0; |
| 328 | } |
| 329 | |
Mauro Carvalho Chehab | 7ca30c5 | 2008-01-11 13:19:09 -0300 | [diff] [blame] | 330 | /* FIXME: Control interface - How to control volume/mute? */ |
Mauro Carvalho Chehab | d72d506 | 2008-01-11 10:28:50 -0300 | [diff] [blame] | 331 | |
| 332 | /**************************************************************************** |
| 333 | Basic Flow for Sound Devices |
| 334 | ****************************************************************************/ |
| 335 | |
Mauro Carvalho Chehab | d72d506 | 2008-01-11 10:28:50 -0300 | [diff] [blame] | 336 | /* |
| 337 | * Alsa Constructor - Component probe |
| 338 | */ |
| 339 | |
Mauro Carvalho Chehab | 576d573 | 2008-01-11 13:55:45 -0300 | [diff] [blame] | 340 | int tm6000_audio_init(struct tm6000_core *dev, int idx) |
Mauro Carvalho Chehab | d72d506 | 2008-01-11 10:28:50 -0300 | [diff] [blame] | 341 | { |
Mauro Carvalho Chehab | 6ad6e88 | 2008-01-11 13:51:45 -0300 | [diff] [blame] | 342 | struct snd_card *card; |
| 343 | struct snd_tm6000_card *chip; |
| 344 | int rc, len; |
| 345 | char component[14]; |
| 346 | |
| 347 | if (idx >= SNDRV_CARDS) |
| 348 | return -ENODEV; |
| 349 | |
| 350 | if (!enable[idx]) |
| 351 | return -ENOENT; |
| 352 | |
Mauro Carvalho Chehab | 427f7fa | 2009-09-14 16:37:13 -0300 | [diff] [blame] | 353 | rc = snd_card_create(index[idx], id[idx], THIS_MODULE, 0, &card); |
| 354 | if (rc < 0) { |
Mauro Carvalho Chehab | 6ad6e88 | 2008-01-11 13:51:45 -0300 | [diff] [blame] | 355 | snd_printk(KERN_ERR "cannot create card instance %d\n", idx); |
Mauro Carvalho Chehab | 427f7fa | 2009-09-14 16:37:13 -0300 | [diff] [blame] | 356 | return rc; |
Mauro Carvalho Chehab | 6ad6e88 | 2008-01-11 13:51:45 -0300 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | chip = kzalloc(sizeof(*chip), GFP_KERNEL); |
| 360 | if (!chip) { |
| 361 | rc = -ENOMEM; |
| 362 | goto error; |
| 363 | } |
| 364 | |
| 365 | chip->core = dev; |
| 366 | chip->card = card; |
| 367 | |
| 368 | strcpy(card->driver, "tm6000-alsa"); |
| 369 | sprintf(component, "USB%04x:%04x", |
| 370 | le16_to_cpu(dev->udev->descriptor.idVendor), |
| 371 | le16_to_cpu(dev->udev->descriptor.idProduct)); |
| 372 | snd_component_add(card, component); |
| 373 | |
| 374 | if (dev->udev->descriptor.iManufacturer) |
| 375 | len = usb_string(dev->udev, |
| 376 | dev->udev->descriptor.iManufacturer, |
| 377 | card->longname, sizeof(card->longname)); |
| 378 | else |
| 379 | len = 0; |
| 380 | |
| 381 | if (len > 0) |
| 382 | strlcat(card->longname, " ", sizeof(card->longname)); |
| 383 | |
| 384 | strlcat(card->longname, card->shortname, sizeof(card->longname)); |
| 385 | |
| 386 | len = strlcat(card->longname, " at ", sizeof(card->longname)); |
| 387 | |
| 388 | if (len < sizeof(card->longname)) |
| 389 | usb_make_path(dev->udev, card->longname + len, |
| 390 | sizeof(card->longname) - len); |
| 391 | |
| 392 | strlcat(card->longname, |
| 393 | dev->udev->speed == USB_SPEED_LOW ? ", low speed" : |
| 394 | dev->udev->speed == USB_SPEED_FULL ? ", full speed" : |
| 395 | ", high speed", |
| 396 | sizeof(card->longname)); |
| 397 | |
| 398 | rc = snd_tm6000_pcm(chip, 0, "tm6000 Digital"); |
| 399 | if (rc < 0) |
| 400 | goto error; |
| 401 | |
| 402 | rc = snd_card_register(card); |
| 403 | if (rc < 0) |
| 404 | goto error; |
| 405 | |
Mauro Carvalho Chehab | d72d506 | 2008-01-11 10:28:50 -0300 | [diff] [blame] | 406 | |
| 407 | return 0; |
Mauro Carvalho Chehab | 6ad6e88 | 2008-01-11 13:51:45 -0300 | [diff] [blame] | 408 | |
| 409 | error: |
| 410 | snd_card_free(card); |
| 411 | return rc; |
Mauro Carvalho Chehab | d72d506 | 2008-01-11 10:28:50 -0300 | [diff] [blame] | 412 | } |
| 413 | |
Stefan Ringel | 0439db75 | 2010-05-10 13:22:51 -0300 | [diff] [blame^] | 414 | static int tm6000_audio_fini(struct tm6000_core *dev) |
| 415 | { |
| 416 | return 0; |
| 417 | } |
| 418 | |
| 419 | struct tm6000_ops audio_ops = { |
| 420 | .id = TM6000_AUDIO, |
| 421 | .name = "TM6000 Audio Extension", |
| 422 | .init = tm6000_audio_init, |
| 423 | .fini = tm6000_audio_fini, |
| 424 | }; |
| 425 | |
| 426 | static int __init tm6000_alsa_register(void) |
| 427 | { |
| 428 | return tm6000_register_extension(&audio_ops); |
| 429 | } |
| 430 | |
| 431 | static void __exit tm6000_alsa_unregister(void) |
| 432 | { |
| 433 | tm6000_unregister_extension(&audio_ops); |
| 434 | } |
| 435 | |
| 436 | module_init(tm6000_alsa_register); |
| 437 | module_exit(tm6000_alsa_unregister); |