blob: bd5fa89af07c32814ea55f28c0075dad7747cdad [file] [log] [blame]
Mauro Carvalho Chehabd72d5062008-01-11 10:28:50 -03001/*
2 *
Dmitri Belimove28f49b2010-02-22 06:32:15 -03003 * Support for audio capture for tm5600/6000/6010
Mauro Carvalho Chehab7ca30c52008-01-11 13:19:09 -03004 * (c) 2007-2008 Mauro Carvalho Chehab <mchehab@redhat.com>
Mauro Carvalho Chehabd72d5062008-01-11 10:28:50 -03005 *
Mauro Carvalho Chehab7ca30c52008-01-11 13:19:09 -03006 * Based on cx88-alsa.c
Mauro Carvalho Chehabd72d5062008-01-11 10:28:50 -03007 *
8 * This program is free software; you can redistribute it and/or modify
Mauro Carvalho Chehab7ca30c52008-01-11 13:19:09 -03009 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
Mauro Carvalho Chehabd72d5062008-01-11 10:28:50 -030011 */
12
13#include <linux/module.h>
14#include <linux/init.h>
15#include <linux/device.h>
16#include <linux/interrupt.h>
Mauro Carvalho Chehab6ad6e882008-01-11 13:51:45 -030017#include <linux/usb.h>
Tejun Heo4ef09882010-03-30 02:52:33 +090018#include <linux/slab.h>
Mauro Carvalho Chehab54b78602010-06-03 16:24:19 -030019#include <linux/vmalloc.h>
Mauro Carvalho Chehabd72d5062008-01-11 10:28:50 -030020
Curtis McEnroed684aee2011-06-02 20:33:34 -040021#include <linux/delay.h>
Mauro Carvalho Chehabd72d5062008-01-11 10:28:50 -030022#include <sound/core.h>
23#include <sound/pcm.h>
24#include <sound/pcm_params.h>
25#include <sound/control.h>
26#include <sound/initval.h>
Mauro Carvalho Chehabd72d5062008-01-11 10:28:50 -030027
Mauro Carvalho Chehabd72d5062008-01-11 10:28:50 -030028
Mauro Carvalho Chehab7ca30c52008-01-11 13:19:09 -030029#include "tm6000.h"
30#include "tm6000-regs.h"
Mauro Carvalho Chehabd72d5062008-01-11 10:28:50 -030031
Mauro Carvalho Chehab7ca30c52008-01-11 13:19:09 -030032#undef dprintk
33
34#define dprintk(level, fmt, arg...) do { \
35 if (debug >= level) \
36 printk(KERN_INFO "%s/1: " fmt, chip->core->name , ## arg); \
37 } while (0)
Mauro Carvalho Chehabd72d5062008-01-11 10:28:50 -030038
39/****************************************************************************
Mauro Carvalho Chehabd72d5062008-01-11 10:28:50 -030040 Module global static vars
41 ****************************************************************************/
42
43static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
Mauro Carvalho Chehab0e57ff82010-06-03 13:45:41 -030044
Mauro Carvalho Chehabd72d5062008-01-11 10:28:50 -030045static int enable[SNDRV_CARDS] = {1, [1 ... (SNDRV_CARDS - 1)] = 1};
46
47module_param_array(enable, bool, NULL, 0444);
Mauro Carvalho Chehab7ca30c52008-01-11 13:19:09 -030048MODULE_PARM_DESC(enable, "Enable tm6000x soundcard. default enabled.");
Mauro Carvalho Chehabd72d5062008-01-11 10:28:50 -030049
50module_param_array(index, int, NULL, 0444);
Mauro Carvalho Chehab7ca30c52008-01-11 13:19:09 -030051MODULE_PARM_DESC(index, "Index value for tm6000x capture interface(s).");
Mauro Carvalho Chehabd72d5062008-01-11 10:28:50 -030052
53
54/****************************************************************************
55 Module macros
56 ****************************************************************************/
57
Dmitri Belimove28f49b2010-02-22 06:32:15 -030058MODULE_DESCRIPTION("ALSA driver module for tm5600/tm6000/tm6010 based TV cards");
Mauro Carvalho Chehabd72d5062008-01-11 10:28:50 -030059MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
60MODULE_LICENSE("GPL");
Mauro Carvalho Chehab7ca30c52008-01-11 13:19:09 -030061MODULE_SUPPORTED_DEVICE("{{Trident,tm5600},"
Dmitri Belimove28f49b2010-02-22 06:32:15 -030062 "{{Trident,tm6000},"
63 "{{Trident,tm6010}");
Mauro Carvalho Chehabd72d5062008-01-11 10:28:50 -030064static unsigned int debug;
Mauro Carvalho Chehab7ca30c52008-01-11 13:19:09 -030065module_param(debug, int, 0644);
66MODULE_PARM_DESC(debug, "enable debug messages");
Mauro Carvalho Chehabd72d5062008-01-11 10:28:50 -030067
68/****************************************************************************
69 Module specific funtions
70 ****************************************************************************/
71
72/*
73 * BOARD Specific: Sets audio DMA
74 */
75
Mauro Carvalho Chehab7ca30c52008-01-11 13:19:09 -030076static int _tm6000_start_audio_dma(struct snd_tm6000_card *chip)
Mauro Carvalho Chehabd72d5062008-01-11 10:28:50 -030077{
Mauro Carvalho Chehab7ca30c52008-01-11 13:19:09 -030078 struct tm6000_core *core = chip->core;
Mauro Carvalho Chehabd72d5062008-01-11 10:28:50 -030079
Mauro Carvalho Chehab3f23a812010-06-05 15:10:36 -030080 dprintk(1, "Starting audio DMA\n");
81
Mauro Carvalho Chehab7ca30c52008-01-11 13:19:09 -030082 /* Enables audio */
Dmitri Belimov8aff8ba2011-02-17 22:11:05 -030083 tm6000_set_reg_mask(core, TM6010_REQ07_RCC_ACTIVE_VIDEO_IF, 0x40, 0x40);
Mauro Carvalho Chehabd72d5062008-01-11 10:28:50 -030084
Mauro Carvalho Chehaba59bff32010-06-07 11:57:01 -030085 tm6000_set_audio_bitrate(core, 48000);
86
Mauro Carvalho Chehabd72d5062008-01-11 10:28:50 -030087 return 0;
88}
89
90/*
91 * BOARD Specific: Resets audio DMA
92 */
Mauro Carvalho Chehab7ca30c52008-01-11 13:19:09 -030093static int _tm6000_stop_audio_dma(struct snd_tm6000_card *chip)
Mauro Carvalho Chehabd72d5062008-01-11 10:28:50 -030094{
Mauro Carvalho Chehab7ca30c52008-01-11 13:19:09 -030095 struct tm6000_core *core = chip->core;
Dmitri Belimov8aff8ba2011-02-17 22:11:05 -030096
Mauro Carvalho Chehabd72d5062008-01-11 10:28:50 -030097 dprintk(1, "Stopping audio DMA\n");
98
Dmitri Belimov8aff8ba2011-02-17 22:11:05 -030099 /* Disables audio */
100 tm6000_set_reg_mask(core, TM6010_REQ07_RCC_ACTIVE_VIDEO_IF, 0x00, 0x40);
Mauro Carvalho Chehabd72d5062008-01-11 10:28:50 -0300101
Mauro Carvalho Chehabd72d5062008-01-11 10:28:50 -0300102 return 0;
103}
104
Mauro Carvalho Chehab54b78602010-06-03 16:24:19 -0300105static void dsp_buffer_free(struct snd_pcm_substream *substream)
Mauro Carvalho Chehabd72d5062008-01-11 10:28:50 -0300106{
Mauro Carvalho Chehab54b78602010-06-03 16:24:19 -0300107 struct snd_tm6000_card *chip = snd_pcm_substream_chip(substream);
Mauro Carvalho Chehabd72d5062008-01-11 10:28:50 -0300108
Mauro Carvalho Chehab7ca30c52008-01-11 13:19:09 -0300109 dprintk(2, "Freeing buffer\n");
Mauro Carvalho Chehabd72d5062008-01-11 10:28:50 -0300110
Mauro Carvalho Chehab54b78602010-06-03 16:24:19 -0300111 vfree(substream->runtime->dma_area);
112 substream->runtime->dma_area = NULL;
113 substream->runtime->dma_bytes = 0;
Mauro Carvalho Chehabd72d5062008-01-11 10:28:50 -0300114}
115
Mauro Carvalho Chehab54b78602010-06-03 16:24:19 -0300116static int dsp_buffer_alloc(struct snd_pcm_substream *substream, int size)
117{
118 struct snd_tm6000_card *chip = snd_pcm_substream_chip(substream);
119
120 dprintk(2, "Allocating buffer\n");
121
122 if (substream->runtime->dma_area) {
123 if (substream->runtime->dma_bytes > size)
124 return 0;
Adam M. Dutko37f96192011-06-23 11:57:45 -0300125
Mauro Carvalho Chehab54b78602010-06-03 16:24:19 -0300126 dsp_buffer_free(substream);
127 }
128
129 substream->runtime->dma_area = vmalloc(size);
130 if (!substream->runtime->dma_area)
131 return -ENOMEM;
132
133 substream->runtime->dma_bytes = size;
134
135 return 0;
136}
137
138
Mauro Carvalho Chehabd72d5062008-01-11 10:28:50 -0300139/****************************************************************************
140 ALSA PCM Interface
141 ****************************************************************************/
142
143/*
144 * Digital hardware definition
145 */
146#define DEFAULT_FIFO_SIZE 4096
Mauro Carvalho Chehab7ca30c52008-01-11 13:19:09 -0300147
148static struct snd_pcm_hardware snd_tm6000_digital_hw = {
Mauro Carvalho Chehabd72d5062008-01-11 10:28:50 -0300149 .info = SNDRV_PCM_INFO_MMAP |
150 SNDRV_PCM_INFO_INTERLEAVED |
151 SNDRV_PCM_INFO_BLOCK_TRANSFER |
152 SNDRV_PCM_INFO_MMAP_VALID,
153 .formats = SNDRV_PCM_FMTBIT_S16_LE,
154
Adam M. Dutko37f96192011-06-23 11:57:45 -0300155 .rates = SNDRV_PCM_RATE_CONTINUOUS,
156 .rate_min = 48000,
157 .rate_max = 48000,
Mauro Carvalho Chehabd72d5062008-01-11 10:28:50 -0300158 .channels_min = 2,
159 .channels_max = 2,
Dmitri Belimov73f4d262010-09-20 17:07:15 -0300160 .period_bytes_min = 64,
161 .period_bytes_max = 12544,
Mauro Carvalho Chehabd72d5062008-01-11 10:28:50 -0300162 .periods_min = 1,
Dmitri Belimov73f4d262010-09-20 17:07:15 -0300163 .periods_max = 98,
Mauro Carvalho Chehabe8cbf032010-06-05 19:21:34 -0300164 .buffer_bytes_max = 62720 * 8,
Mauro Carvalho Chehabd72d5062008-01-11 10:28:50 -0300165};
166
167/*
168 * audio pcm capture open callback
169 */
Mauro Carvalho Chehab7ca30c52008-01-11 13:19:09 -0300170static int snd_tm6000_pcm_open(struct snd_pcm_substream *substream)
Mauro Carvalho Chehabd72d5062008-01-11 10:28:50 -0300171{
Mauro Carvalho Chehab7ca30c52008-01-11 13:19:09 -0300172 struct snd_tm6000_card *chip = snd_pcm_substream_chip(substream);
Mauro Carvalho Chehabd72d5062008-01-11 10:28:50 -0300173 struct snd_pcm_runtime *runtime = substream->runtime;
174 int err;
175
Mauro Carvalho Chehab7ca30c52008-01-11 13:19:09 -0300176 err = snd_pcm_hw_constraint_pow2(runtime, 0,
177 SNDRV_PCM_HW_PARAM_PERIODS);
Mauro Carvalho Chehabd72d5062008-01-11 10:28:50 -0300178 if (err < 0)
179 goto _error;
180
181 chip->substream = substream;
182
Mauro Carvalho Chehab7ca30c52008-01-11 13:19:09 -0300183 runtime->hw = snd_tm6000_digital_hw;
Mauro Carvalho Chehabd72d5062008-01-11 10:28:50 -0300184
185 return 0;
186_error:
Mauro Carvalho Chehab7ca30c52008-01-11 13:19:09 -0300187 dprintk(1, "Error opening PCM!\n");
Mauro Carvalho Chehabd72d5062008-01-11 10:28:50 -0300188 return err;
189}
190
191/*
192 * audio close callback
193 */
Mauro Carvalho Chehab7ca30c52008-01-11 13:19:09 -0300194static int snd_tm6000_close(struct snd_pcm_substream *substream)
Mauro Carvalho Chehabd72d5062008-01-11 10:28:50 -0300195{
Mauro Carvalho Chehab06f08e32010-10-09 21:15:33 -0300196 struct snd_tm6000_card *chip = snd_pcm_substream_chip(substream);
197 struct tm6000_core *core = chip->core;
198
199 if (atomic_read(&core->stream_started) > 0) {
200 atomic_set(&core->stream_started, 0);
201 schedule_work(&core->wq_trigger);
202 }
203
Mauro Carvalho Chehabd72d5062008-01-11 10:28:50 -0300204 return 0;
205}
206
Mauro Carvalho Chehabb17b8692010-06-03 17:16:28 -0300207static int tm6000_fillbuf(struct tm6000_core *core, char *buf, int size)
208{
Mauro Carvalho Chehabe8cbf032010-06-05 19:21:34 -0300209 struct snd_tm6000_card *chip = core->adev;
210 struct snd_pcm_substream *substream = chip->substream;
211 struct snd_pcm_runtime *runtime;
212 int period_elapsed = 0;
213 unsigned int stride, buf_pos;
Dmitri Belimov73f4d262010-09-20 17:07:15 -0300214 int length;
Mauro Carvalho Chehabb17b8692010-06-03 17:16:28 -0300215
Mauro Carvalho Chehab06f08e32010-10-09 21:15:33 -0300216 if (atomic_read(&core->stream_started) == 0)
217 return 0;
218
Dmitri Belimov73f4d262010-09-20 17:07:15 -0300219 if (!size || !substream) {
220 dprintk(1, "substream was NULL\n");
Mauro Carvalho Chehabe8cbf032010-06-05 19:21:34 -0300221 return -EINVAL;
Dmitri Belimov73f4d262010-09-20 17:07:15 -0300222 }
Mauro Carvalho Chehabb17b8692010-06-03 17:16:28 -0300223
Mauro Carvalho Chehabe8cbf032010-06-05 19:21:34 -0300224 runtime = substream->runtime;
Dmitri Belimov73f4d262010-09-20 17:07:15 -0300225 if (!runtime || !runtime->dma_area) {
226 dprintk(1, "runtime was NULL\n");
Mauro Carvalho Chehabe8cbf032010-06-05 19:21:34 -0300227 return -EINVAL;
Dmitri Belimov73f4d262010-09-20 17:07:15 -0300228 }
Mauro Carvalho Chehabe8cbf032010-06-05 19:21:34 -0300229
230 buf_pos = chip->buf_pos;
231 stride = runtime->frame_bits >> 3;
232
Dmitri Belimov73f4d262010-09-20 17:07:15 -0300233 if (stride == 0) {
234 dprintk(1, "stride is zero\n");
235 return -EINVAL;
236 }
237
238 length = size / stride;
239 if (length == 0) {
240 dprintk(1, "%s: length was zero\n", __func__);
241 return -EINVAL;
242 }
243
Mauro Carvalho Chehabe8cbf032010-06-05 19:21:34 -0300244 dprintk(1, "Copying %d bytes at %p[%d] - buf size=%d x %d\n", size,
245 runtime->dma_area, buf_pos,
246 (unsigned int)runtime->buffer_size, stride);
247
Dmitri Belimov73f4d262010-09-20 17:07:15 -0300248 if (buf_pos + length >= runtime->buffer_size) {
249 unsigned int cnt = runtime->buffer_size - buf_pos;
250 memcpy(runtime->dma_area + buf_pos * stride, buf, cnt * stride);
251 memcpy(runtime->dma_area, buf + cnt * stride,
252 length * stride - cnt * stride);
Mauro Carvalho Chehabe8cbf032010-06-05 19:21:34 -0300253 } else
Dmitri Belimov73f4d262010-09-20 17:07:15 -0300254 memcpy(runtime->dma_area + buf_pos * stride, buf,
255 length * stride);
Mauro Carvalho Chehabe8cbf032010-06-05 19:21:34 -0300256
Curtis McEnroed684aee2011-06-02 20:33:34 -0400257 snd_pcm_stream_lock(substream);
Mauro Carvalho Chehabe8cbf032010-06-05 19:21:34 -0300258
Dmitri Belimov73f4d262010-09-20 17:07:15 -0300259 chip->buf_pos += length;
260 if (chip->buf_pos >= runtime->buffer_size)
261 chip->buf_pos -= runtime->buffer_size;
262
263 chip->period_pos += length;
Mauro Carvalho Chehabe8cbf032010-06-05 19:21:34 -0300264 if (chip->period_pos >= runtime->period_size) {
265 chip->period_pos -= runtime->period_size;
266 period_elapsed = 1;
267 }
268
Curtis McEnroed684aee2011-06-02 20:33:34 -0400269 snd_pcm_stream_unlock(substream);
Dmitri Belimov73f4d262010-09-20 17:07:15 -0300270
Mauro Carvalho Chehabe8cbf032010-06-05 19:21:34 -0300271 if (period_elapsed)
272 snd_pcm_period_elapsed(substream);
Mauro Carvalho Chehabb17b8692010-06-03 17:16:28 -0300273
274 return 0;
275}
276
Mauro Carvalho Chehabd72d5062008-01-11 10:28:50 -0300277/*
278 * hw_params callback
279 */
Mauro Carvalho Chehab7ca30c52008-01-11 13:19:09 -0300280static int snd_tm6000_hw_params(struct snd_pcm_substream *substream,
281 struct snd_pcm_hw_params *hw_params)
Mauro Carvalho Chehabd72d5062008-01-11 10:28:50 -0300282{
Mauro Carvalho Chehab54b78602010-06-03 16:24:19 -0300283 int size, rc;
Mauro Carvalho Chehabd72d5062008-01-11 10:28:50 -0300284
Mauro Carvalho Chehab54b78602010-06-03 16:24:19 -0300285 size = params_period_bytes(hw_params) * params_periods(hw_params);
Mauro Carvalho Chehabd72d5062008-01-11 10:28:50 -0300286
Mauro Carvalho Chehab54b78602010-06-03 16:24:19 -0300287 rc = dsp_buffer_alloc(substream, size);
288 if (rc < 0)
289 return rc;
Mauro Carvalho Chehabd72d5062008-01-11 10:28:50 -0300290
Mauro Carvalho Chehabd72d5062008-01-11 10:28:50 -0300291 return 0;
Mauro Carvalho Chehabd72d5062008-01-11 10:28:50 -0300292}
293
294/*
295 * hw free callback
296 */
Mauro Carvalho Chehab7ca30c52008-01-11 13:19:09 -0300297static int snd_tm6000_hw_free(struct snd_pcm_substream *substream)
Mauro Carvalho Chehabd72d5062008-01-11 10:28:50 -0300298{
Mauro Carvalho Chehab3f23a812010-06-05 15:10:36 -0300299 struct snd_tm6000_card *chip = snd_pcm_substream_chip(substream);
Mauro Carvalho Chehab06f08e32010-10-09 21:15:33 -0300300 struct tm6000_core *core = chip->core;
Mauro Carvalho Chehab3f23a812010-06-05 15:10:36 -0300301
Mauro Carvalho Chehab06f08e32010-10-09 21:15:33 -0300302 if (atomic_read(&core->stream_started) > 0) {
303 atomic_set(&core->stream_started, 0);
304 schedule_work(&core->wq_trigger);
305 }
Mauro Carvalho Chehabd72d5062008-01-11 10:28:50 -0300306
307 return 0;
308}
309
310/*
311 * prepare callback
312 */
Mauro Carvalho Chehab7ca30c52008-01-11 13:19:09 -0300313static int snd_tm6000_prepare(struct snd_pcm_substream *substream)
Mauro Carvalho Chehabd72d5062008-01-11 10:28:50 -0300314{
Mauro Carvalho Chehab3f23a812010-06-05 15:10:36 -0300315 struct snd_tm6000_card *chip = snd_pcm_substream_chip(substream);
316
317 chip->buf_pos = 0;
318 chip->period_pos = 0;
319
Mauro Carvalho Chehabd72d5062008-01-11 10:28:50 -0300320 return 0;
321}
322
Mauro Carvalho Chehab7ca30c52008-01-11 13:19:09 -0300323
Mauro Carvalho Chehabd72d5062008-01-11 10:28:50 -0300324/*
325 * trigger callback
326 */
Mauro Carvalho Chehab06f08e32010-10-09 21:15:33 -0300327static void audio_trigger(struct work_struct *work)
328{
329 struct tm6000_core *core = container_of(work, struct tm6000_core,
330 wq_trigger);
331 struct snd_tm6000_card *chip = core->adev;
332
333 if (atomic_read(&core->stream_started)) {
334 dprintk(1, "starting capture");
335 _tm6000_start_audio_dma(chip);
336 } else {
337 dprintk(1, "stopping capture");
338 _tm6000_stop_audio_dma(chip);
339 }
340}
341
Mauro Carvalho Chehab7ca30c52008-01-11 13:19:09 -0300342static int snd_tm6000_card_trigger(struct snd_pcm_substream *substream, int cmd)
Mauro Carvalho Chehabd72d5062008-01-11 10:28:50 -0300343{
Mauro Carvalho Chehab7ca30c52008-01-11 13:19:09 -0300344 struct snd_tm6000_card *chip = snd_pcm_substream_chip(substream);
Mauro Carvalho Chehab06f08e32010-10-09 21:15:33 -0300345 struct tm6000_core *core = chip->core;
346 int err = 0;
Mauro Carvalho Chehabd72d5062008-01-11 10:28:50 -0300347
348 switch (cmd) {
349 case SNDRV_PCM_TRIGGER_START:
Mauro Carvalho Chehab06f08e32010-10-09 21:15:33 -0300350 atomic_set(&core->stream_started, 1);
Mauro Carvalho Chehabd72d5062008-01-11 10:28:50 -0300351 break;
352 case SNDRV_PCM_TRIGGER_STOP:
Mauro Carvalho Chehab06f08e32010-10-09 21:15:33 -0300353 atomic_set(&core->stream_started, 0);
Mauro Carvalho Chehabd72d5062008-01-11 10:28:50 -0300354 break;
355 default:
Mauro Carvalho Chehab7ca30c52008-01-11 13:19:09 -0300356 err = -EINVAL;
Mauro Carvalho Chehabd72d5062008-01-11 10:28:50 -0300357 break;
358 }
Mauro Carvalho Chehab06f08e32010-10-09 21:15:33 -0300359 schedule_work(&core->wq_trigger);
Mauro Carvalho Chehabd72d5062008-01-11 10:28:50 -0300360
361 return err;
362}
Mauro Carvalho Chehabd72d5062008-01-11 10:28:50 -0300363/*
364 * pointer callback
365 */
Mauro Carvalho Chehab7ca30c52008-01-11 13:19:09 -0300366static snd_pcm_uframes_t snd_tm6000_pointer(struct snd_pcm_substream *substream)
Mauro Carvalho Chehabd72d5062008-01-11 10:28:50 -0300367{
Mauro Carvalho Chehab7ca30c52008-01-11 13:19:09 -0300368 struct snd_tm6000_card *chip = snd_pcm_substream_chip(substream);
Mauro Carvalho Chehabd72d5062008-01-11 10:28:50 -0300369
Mauro Carvalho Chehab3f23a812010-06-05 15:10:36 -0300370 return chip->buf_pos;
Mauro Carvalho Chehabd72d5062008-01-11 10:28:50 -0300371}
372
373/*
Mauro Carvalho Chehabd72d5062008-01-11 10:28:50 -0300374 * operators
375 */
Mauro Carvalho Chehab7ca30c52008-01-11 13:19:09 -0300376static struct snd_pcm_ops snd_tm6000_pcm_ops = {
377 .open = snd_tm6000_pcm_open,
378 .close = snd_tm6000_close,
Mauro Carvalho Chehabd72d5062008-01-11 10:28:50 -0300379 .ioctl = snd_pcm_lib_ioctl,
Mauro Carvalho Chehab7ca30c52008-01-11 13:19:09 -0300380 .hw_params = snd_tm6000_hw_params,
381 .hw_free = snd_tm6000_hw_free,
382 .prepare = snd_tm6000_prepare,
383 .trigger = snd_tm6000_card_trigger,
384 .pointer = snd_tm6000_pointer,
Mauro Carvalho Chehabd72d5062008-01-11 10:28:50 -0300385};
386
387/*
388 * create a PCM device
389 */
Mauro Carvalho Chehabd72d5062008-01-11 10:28:50 -0300390
Mauro Carvalho Chehab7ca30c52008-01-11 13:19:09 -0300391/* FIXME: Control interface - How to control volume/mute? */
Mauro Carvalho Chehabd72d5062008-01-11 10:28:50 -0300392
393/****************************************************************************
394 Basic Flow for Sound Devices
395 ****************************************************************************/
396
Mauro Carvalho Chehabd72d5062008-01-11 10:28:50 -0300397/*
398 * Alsa Constructor - Component probe
399 */
Stefan Ringeld77057f2010-05-30 09:19:02 -0300400int tm6000_audio_init(struct tm6000_core *dev)
Mauro Carvalho Chehabd72d5062008-01-11 10:28:50 -0300401{
Stefan Ringeld77057f2010-05-30 09:19:02 -0300402 struct snd_card *card;
403 struct snd_tm6000_card *chip;
404 int rc;
405 static int devnr;
406 char component[14];
407 struct snd_pcm *pcm;
Mauro Carvalho Chehab6ad6e882008-01-11 13:51:45 -0300408
Stefan Ringeld77057f2010-05-30 09:19:02 -0300409 if (!dev)
410 return 0;
411
412 if (devnr >= SNDRV_CARDS)
Mauro Carvalho Chehab6ad6e882008-01-11 13:51:45 -0300413 return -ENODEV;
414
Stefan Ringeld77057f2010-05-30 09:19:02 -0300415 if (!enable[devnr])
Mauro Carvalho Chehab6ad6e882008-01-11 13:51:45 -0300416 return -ENOENT;
417
Mauro Carvalho Chehab0e57ff82010-06-03 13:45:41 -0300418 rc = snd_card_create(index[devnr], "tm6000", THIS_MODULE, 0, &card);
Mauro Carvalho Chehab427f7fa2009-09-14 16:37:13 -0300419 if (rc < 0) {
Stefan Ringeld77057f2010-05-30 09:19:02 -0300420 snd_printk(KERN_ERR "cannot create card instance %d\n", devnr);
Mauro Carvalho Chehab427f7fa2009-09-14 16:37:13 -0300421 return rc;
Mauro Carvalho Chehab6ad6e882008-01-11 13:51:45 -0300422 }
Mauro Carvalho Chehab3f23a812010-06-05 15:10:36 -0300423 strcpy(card->driver, "tm6000-alsa");
424 strcpy(card->shortname, "TM5600/60x0");
425 sprintf(card->longname, "TM5600/60x0 Audio at bus %d device %d",
426 dev->udev->bus->busnum, dev->udev->devnum);
427
428 sprintf(component, "USB%04x:%04x",
429 le16_to_cpu(dev->udev->descriptor.idVendor),
430 le16_to_cpu(dev->udev->descriptor.idProduct));
431 snd_component_add(card, component);
432 snd_card_set_dev(card, &dev->udev->dev);
Mauro Carvalho Chehab6ad6e882008-01-11 13:51:45 -0300433
Stefan Ringeld77057f2010-05-30 09:19:02 -0300434 chip = kzalloc(sizeof(struct snd_tm6000_card), GFP_KERNEL);
Mauro Carvalho Chehab6ad6e882008-01-11 13:51:45 -0300435 if (!chip) {
436 rc = -ENOMEM;
437 goto error;
438 }
439
Mauro Carvalho Chehab3f23a812010-06-05 15:10:36 -0300440 chip->core = dev;
441 chip->card = card;
442 dev->adev = chip;
Stefan Ringeld77057f2010-05-30 09:19:02 -0300443 spin_lock_init(&chip->reg_lock);
Mauro Carvalho Chehab3f23a812010-06-05 15:10:36 -0300444
Stefan Ringeld77057f2010-05-30 09:19:02 -0300445 rc = snd_pcm_new(card, "TM6000 Audio", 0, 0, 1, &pcm);
Mauro Carvalho Chehab6ad6e882008-01-11 13:51:45 -0300446 if (rc < 0)
Kulikov Vasiliycd6541c2010-08-11 12:01:19 +0400447 goto error_chip;
Mauro Carvalho Chehab6ad6e882008-01-11 13:51:45 -0300448
Stefan Ringeld77057f2010-05-30 09:19:02 -0300449 pcm->info_flags = 0;
Mauro Carvalho Chehab3f23a812010-06-05 15:10:36 -0300450 pcm->private_data = chip;
Stefan Ringeld77057f2010-05-30 09:19:02 -0300451 strcpy(pcm->name, "Trident TM5600/60x0");
Stefan Ringeld77057f2010-05-30 09:19:02 -0300452
Mauro Carvalho Chehab3f23a812010-06-05 15:10:36 -0300453 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_tm6000_pcm_ops);
Stefan Ringeld77057f2010-05-30 09:19:02 -0300454
Mauro Carvalho Chehab06f08e32010-10-09 21:15:33 -0300455 INIT_WORK(&dev->wq_trigger, audio_trigger);
Mauro Carvalho Chehab6ad6e882008-01-11 13:51:45 -0300456 rc = snd_card_register(card);
457 if (rc < 0)
Kulikov Vasiliycd6541c2010-08-11 12:01:19 +0400458 goto error_chip;
Mauro Carvalho Chehab6ad6e882008-01-11 13:51:45 -0300459
Curtis McEnroed684aee2011-06-02 20:33:34 -0400460 dprintk(1, "Registered audio driver for %s\n", card->longname);
Mauro Carvalho Chehabd72d5062008-01-11 10:28:50 -0300461
462 return 0;
Mauro Carvalho Chehab6ad6e882008-01-11 13:51:45 -0300463
Kulikov Vasiliycd6541c2010-08-11 12:01:19 +0400464error_chip:
465 kfree(chip);
466 dev->adev = NULL;
Mauro Carvalho Chehab6ad6e882008-01-11 13:51:45 -0300467error:
468 snd_card_free(card);
469 return rc;
Mauro Carvalho Chehabd72d5062008-01-11 10:28:50 -0300470}
471
Stefan Ringel0439db752010-05-10 13:22:51 -0300472static int tm6000_audio_fini(struct tm6000_core *dev)
473{
Stefan Ringeld77057f2010-05-30 09:19:02 -0300474 struct snd_tm6000_card *chip = dev->adev;
475
476 if (!dev)
477 return 0;
478
479 if (!chip)
480 return 0;
481
482 if (!chip->card)
483 return 0;
484
485 snd_card_free(chip->card);
486 chip->card = NULL;
487 kfree(chip);
488 dev->adev = NULL;
489
Stefan Ringel0439db752010-05-10 13:22:51 -0300490 return 0;
491}
492
493struct tm6000_ops audio_ops = {
Mauro Carvalho Chehab39e12562010-06-03 16:31:20 -0300494 .type = TM6000_AUDIO,
Stefan Ringel0439db752010-05-10 13:22:51 -0300495 .name = "TM6000 Audio Extension",
496 .init = tm6000_audio_init,
497 .fini = tm6000_audio_fini,
Mauro Carvalho Chehabb17b8692010-06-03 17:16:28 -0300498 .fillbuf = tm6000_fillbuf,
Stefan Ringel0439db752010-05-10 13:22:51 -0300499};
500
501static int __init tm6000_alsa_register(void)
502{
503 return tm6000_register_extension(&audio_ops);
504}
505
506static void __exit tm6000_alsa_unregister(void)
507{
508 tm6000_unregister_extension(&audio_ops);
509}
510
511module_init(tm6000_alsa_register);
512module_exit(tm6000_alsa_unregister);