2 * ALSA driver for Xilinx ML403 AC97 Controller Reference
3 * IP: opb_ac97_controller_ref_v1_00_a (EDK 8.1i)
4 * IP: opb_ac97_controller_ref_v1_00_a (EDK 9.1i)
6 * Copyright (c) by 2007 Joachim Foerster <JOFT@gmx.de>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 /* Some notes / status of this driver:
26 * - Don't wonder about some strange implementations of things - especially the
27 * (heavy) shadowing of codec registers, with which I tried to reduce read
28 * accesses to a minimum, because after a variable amount of accesses, the AC97
29 * controller doesn't raise the register access finished bit anymore ...
31 * - Capture support works - basically, but after ~30s (with rates > ~20kHz)
32 * ALSA stops reading captured samples from the intermediate buffer and
33 * therefore a overrun happens - ATM I don't know what's wrong.
35 * - Playback support seems to be pretty stable - no issues here.
38 #include <sound/driver.h>
39 #include <linux/init.h>
40 #include <linux/moduleparam.h>
42 #include <linux/platform_device.h>
44 #include <linux/ioport.h>
46 #include <linux/interrupt.h>
49 #include <linux/param.h>
50 /* jiffies, time_*() */
51 #include <linux/jiffies.h>
52 /* schedule_timeout*() */
53 #include <linux/sched.h>
55 #include <linux/spinlock.h>
56 /* struct mutex, mutex_init(), mutex_*lock() */
57 #include <linux/mutex.h>
59 /* snd_printk(), snd_printd() */
60 #include <sound/core.h>
61 #include <sound/pcm.h>
62 #include <sound/pcm_params.h>
63 #include <sound/initval.h>
64 #include <sound/ac97_codec.h>
66 #include "pcm-indirect2.h"
69 #define SND_ML403_AC97CR_DRIVER "ml403-ac97cr"
71 MODULE_AUTHOR("Joachim Foerster <JOFT@gmx.de>");
72 MODULE_DESCRIPTION("Xilinx ML403 AC97 Controller Reference");
73 MODULE_LICENSE("GPL");
74 MODULE_SUPPORTED_DEVICE("{{Xilinx,ML403 AC97 Controller Reference}}");
76 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
77 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
78 static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE;
80 module_param_array(index, int, NULL, 0444);
81 MODULE_PARM_DESC(index, "Index value for ML403 AC97 Controller Reference.");
82 module_param_array(id, charp, NULL, 0444);
83 MODULE_PARM_DESC(id, "ID string for ML403 AC97 Controller Reference.");
84 module_param_array(enable, bool, NULL, 0444);
85 MODULE_PARM_DESC(enable, "Enable this ML403 AC97 Controller Reference.");
87 /* Special feature options */
88 /*#define CODEC_WRITE_CHECK_RAF*/ /* don't return after a write to a codec
89 * register, while RAF bit is not set
91 /* Debug options for code which may be removed completely in a final version */
92 #ifdef CONFIG_SND_DEBUG
93 /*#define CODEC_STAT*/ /* turn on some minimal "statistics"
94 * about codec register usage
96 #define SND_PCM_INDIRECT2_STAT /* turn on some "statistics" about the
97 * process of copying bytes from the
98 * intermediate buffer to the hardware
99 * fifo and the other way round
103 /* Definition of a "level/facility dependent" printk(); may be removed
104 * completely in a final version
107 #ifdef CONFIG_SND_DEBUG
108 /* "facilities" for PDEBUG */
109 #define UNKNOWN (1<<0)
110 #define CODEC_SUCCESS (1<<1)
111 #define CODEC_FAKE (1<<2)
112 #define INIT_INFO (1<<3)
113 #define INIT_FAILURE (1<<4)
114 #define WORK_INFO (1<<5)
115 #define WORK_FAILURE (1<<6)
117 #define PDEBUG_FACILITIES (UNKNOWN | INIT_FAILURE | WORK_FAILURE)
119 #define PDEBUG(fac, fmt, args...) do { \
120 if (fac & PDEBUG_FACILITIES) \
121 snd_printd(KERN_DEBUG SND_ML403_AC97CR_DRIVER ": " \
125 #define PDEBUG(fac, fmt, args...) /* nothing */
130 /* Defines for "waits"/timeouts (portions of HZ=250 on arch/ppc by default) */
131 #define CODEC_TIMEOUT_ON_INIT 5 /* timeout for checking for codec
132 * readiness (after insmod)
134 #ifndef CODEC_WRITE_CHECK_RAF
135 #define CODEC_WAIT_AFTER_WRITE 100 /* general, static wait after a write
136 * access to a codec register, may be
137 * 0 to completely remove wait
140 #define CODEC_TIMEOUT_AFTER_WRITE 5 /* timeout after a write access to a
141 * codec register, if RAF bit is used
144 #define CODEC_TIMEOUT_AFTER_READ 5 /* timeout after a read access to a
145 * codec register (checking RAF bit)
148 /* Infrastructure for codec register shadowing */
149 #define LM4550_REG_OK (1<<0) /* register exists */
150 #define LM4550_REG_DONEREAD (1<<1) /* read register once, value should be
151 * the same currently in the register
153 #define LM4550_REG_NOSAVE (1<<2) /* values written to this register will
154 * not be saved in the register
156 #define LM4550_REG_NOSHADOW (1<<3) /* don't do register shadowing, use plain
159 #define LM4550_REG_READONLY (1<<4) /* register is read only */
160 #define LM4550_REG_FAKEPROBE (1<<5) /* fake write _and_ read actions during
163 #define LM4550_REG_FAKEREAD (1<<6) /* fake read access, always return
166 #define LM4550_REG_ALLFAKE (LM4550_REG_FAKEREAD | LM4550_REG_FAKEPROBE)
175 struct lm4550_reg lm4550_regfile[64] = {
176 [AC97_RESET / 2] = {.flag = LM4550_REG_OK \
177 | LM4550_REG_NOSAVE \
178 | LM4550_REG_FAKEREAD,
180 [AC97_MASTER / 2] = {.flag = LM4550_REG_OK
181 | LM4550_REG_FAKEPROBE,
184 [AC97_HEADPHONE / 2] = {.flag = LM4550_REG_OK \
185 | LM4550_REG_FAKEPROBE,
188 [AC97_MASTER_MONO / 2] = {.flag = LM4550_REG_OK \
189 | LM4550_REG_FAKEPROBE,
192 [AC97_PC_BEEP / 2] = {.flag = LM4550_REG_OK \
193 | LM4550_REG_FAKEPROBE,
196 [AC97_PHONE / 2] = {.flag = LM4550_REG_OK \
197 | LM4550_REG_FAKEPROBE,
200 [AC97_MIC / 2] = {.flag = LM4550_REG_OK \
201 | LM4550_REG_FAKEPROBE,
204 [AC97_LINE / 2] = {.flag = LM4550_REG_OK \
205 | LM4550_REG_FAKEPROBE,
208 [AC97_CD / 2] = {.flag = LM4550_REG_OK \
209 | LM4550_REG_FAKEPROBE,
212 [AC97_VIDEO / 2] = {.flag = LM4550_REG_OK \
213 | LM4550_REG_FAKEPROBE,
216 [AC97_AUX / 2] = {.flag = LM4550_REG_OK \
217 | LM4550_REG_FAKEPROBE,
220 [AC97_PCM / 2] = {.flag = LM4550_REG_OK \
221 | LM4550_REG_FAKEPROBE,
224 [AC97_REC_SEL / 2] = {.flag = LM4550_REG_OK \
225 | LM4550_REG_FAKEPROBE,
228 [AC97_REC_GAIN / 2] = {.flag = LM4550_REG_OK \
229 | LM4550_REG_FAKEPROBE,
232 [AC97_GENERAL_PURPOSE / 2] = {.flag = LM4550_REG_OK \
233 | LM4550_REG_FAKEPROBE,
236 [AC97_3D_CONTROL / 2] = {.flag = LM4550_REG_OK \
237 | LM4550_REG_FAKEREAD \
238 | LM4550_REG_READONLY,
240 [AC97_POWERDOWN / 2] = {.flag = LM4550_REG_OK \
241 | LM4550_REG_NOSHADOW \
244 /* may not write ones to
245 * REF/ANL/DAC/ADC bits
248 [AC97_EXTENDED_ID / 2] = {.flag = LM4550_REG_OK \
249 | LM4550_REG_FAKEREAD \
250 | LM4550_REG_READONLY,
251 .def = 0x0201}, /* primary codec */
252 [AC97_EXTENDED_STATUS / 2] = {.flag = LM4550_REG_OK \
253 | LM4550_REG_NOSHADOW \
256 [AC97_PCM_FRONT_DAC_RATE / 2] = {.flag = LM4550_REG_OK \
257 | LM4550_REG_FAKEPROBE,
260 [AC97_PCM_LR_ADC_RATE / 2] = {.flag = LM4550_REG_OK \
261 | LM4550_REG_FAKEPROBE,
264 [AC97_VENDOR_ID1 / 2] = {.flag = LM4550_REG_OK \
265 | LM4550_REG_READONLY \
266 | LM4550_REG_FAKEREAD,
268 [AC97_VENDOR_ID2 / 2] = {.flag = LM4550_REG_OK \
269 | LM4550_REG_READONLY \
270 | LM4550_REG_FAKEREAD,
274 #define LM4550_RF_OK(reg) (lm4550_regfile[reg / 2].flag & LM4550_REG_OK)
276 static void lm4550_regfile_init(void)
279 for (i = 0; i < 64; i++)
280 if (lm4550_regfile[i].flag & LM4550_REG_FAKEPROBE)
281 lm4550_regfile[i].value = lm4550_regfile[i].def;
284 static void lm4550_regfile_write_values_after_init(struct snd_ac97 *ac97)
287 for (i = 0; i < 64; i++)
288 if ((lm4550_regfile[i].flag & LM4550_REG_FAKEPROBE) &&
289 (lm4550_regfile[i].value != lm4550_regfile[i].def)) {
290 PDEBUG(CODEC_FAKE, "lm4550_regfile_write_values_after_"
291 "init(): reg=0x%x value=0x%x / %d is different "
292 "from def=0x%x / %d\n",
293 i, lm4550_regfile[i].value,
294 lm4550_regfile[i].value, lm4550_regfile[i].def,
295 lm4550_regfile[i].def);
296 snd_ac97_write(ac97, i * 2, lm4550_regfile[i].value);
297 lm4550_regfile[i].flag |= LM4550_REG_DONEREAD;
302 /* direct registers */
303 #define CR_REG(ml403_ac97cr, x) ((ml403_ac97cr)->port + CR_REG_##x)
305 #define CR_REG_PLAYFIFO 0x00
306 #define CR_PLAYDATA(a) ((a) & 0xFFFF)
308 #define CR_REG_RECFIFO 0x04
309 #define CR_RECDATA(a) ((a) & 0xFFFF)
311 #define CR_REG_STATUS 0x08
312 #define CR_RECOVER (1<<7)
313 #define CR_PLAYUNDER (1<<6)
314 #define CR_CODECREADY (1<<5)
315 #define CR_RAF (1<<4)
316 #define CR_RECEMPTY (1<<3)
317 #define CR_RECFULL (1<<2)
318 #define CR_PLAYHALF (1<<1)
319 #define CR_PLAYFULL (1<<0)
321 #define CR_REG_RESETFIFO 0x0C
322 #define CR_RECRESET (1<<1)
323 #define CR_PLAYRESET (1<<0)
325 #define CR_REG_CODEC_ADDR 0x10
327 * #define CR_CODEC_ADDR(a) ((a) << 1)
328 * #define CR_CODEC_READ (1<<0)
329 * #define CR_CODEC_WRITE (0<<0)
331 /* RefDesign example says: */
332 #define CR_CODEC_ADDR(a) ((a) << 0)
333 #define CR_CODEC_READ (1<<7)
334 #define CR_CODEC_WRITE (0<<7)
336 #define CR_REG_CODEC_DATAREAD 0x14
337 #define CR_CODEC_DATAREAD(v) ((v) & 0xFFFF)
339 #define CR_REG_CODEC_DATAWRITE 0x18
340 #define CR_CODEC_DATAWRITE(v) ((v) & 0xFFFF)
342 #define CR_FIFO_SIZE 32
344 struct snd_ml403_ac97cr {
345 /* lock for access to (controller) registers */
347 /* mutex for the whole sequence of accesses to (controller) registers
348 * which affect codec registers
350 struct mutex cdc_mutex;
352 int irq; /* for playback */
353 int enable_irq; /* for playback */
356 int enable_capture_irq;
358 struct resource *res_port;
361 struct snd_ac97 *ac97;
368 struct platform_device *pfdev;
369 struct snd_card *card;
371 struct snd_pcm_substream *playback_substream;
372 struct snd_pcm_substream *capture_substream;
374 struct snd_pcm_indirect2 ind_rec; /* for playback */
375 struct snd_pcm_indirect2 capture_ind2_rec;
378 static struct snd_pcm_hardware snd_ml403_ac97cr_playback = {
379 .info = (SNDRV_PCM_INFO_MMAP |
380 SNDRV_PCM_INFO_INTERLEAVED |
381 SNDRV_PCM_INFO_MMAP_VALID),
382 .formats = SNDRV_PCM_FMTBIT_S16_BE,
383 .rates = (SNDRV_PCM_RATE_CONTINUOUS |
384 SNDRV_PCM_RATE_8000_48000),
389 .buffer_bytes_max = (128*1024),
390 .period_bytes_min = CR_FIFO_SIZE/2,
391 .period_bytes_max = (64*1024),
393 .periods_max = (128*1024)/(CR_FIFO_SIZE/2),
397 static struct snd_pcm_hardware snd_ml403_ac97cr_capture = {
398 .info = (SNDRV_PCM_INFO_MMAP |
399 SNDRV_PCM_INFO_INTERLEAVED |
400 SNDRV_PCM_INFO_MMAP_VALID),
401 .formats = SNDRV_PCM_FMTBIT_S16_BE,
402 .rates = (SNDRV_PCM_RATE_CONTINUOUS |
403 SNDRV_PCM_RATE_8000_48000),
408 .buffer_bytes_max = (128*1024),
409 .period_bytes_min = CR_FIFO_SIZE/2,
410 .period_bytes_max = (64*1024),
412 .periods_max = (128*1024)/(CR_FIFO_SIZE/2),
417 snd_ml403_ac97cr_playback_ind2_zero(struct snd_pcm_substream *substream,
418 struct snd_pcm_indirect2 *rec)
420 struct snd_ml403_ac97cr *ml403_ac97cr;
421 int copied_words = 0;
424 ml403_ac97cr = snd_pcm_substream_chip(substream);
426 spin_lock(&ml403_ac97cr->reg_lock);
427 while ((full = (in_be32(CR_REG(ml403_ac97cr, STATUS)) &
428 CR_PLAYFULL)) != CR_PLAYFULL) {
429 out_be32(CR_REG(ml403_ac97cr, PLAYFIFO), 0);
433 spin_unlock(&ml403_ac97cr->reg_lock);
435 return (size_t) (copied_words * 2);
439 snd_ml403_ac97cr_playback_ind2_copy(struct snd_pcm_substream *substream,
440 struct snd_pcm_indirect2 *rec,
443 struct snd_ml403_ac97cr *ml403_ac97cr;
445 int copied_words = 0;
448 ml403_ac97cr = snd_pcm_substream_chip(substream);
449 src = (u16 *)(substream->runtime->dma_area + rec->sw_data);
451 spin_lock(&ml403_ac97cr->reg_lock);
452 while (((full = (in_be32(CR_REG(ml403_ac97cr, STATUS)) &
453 CR_PLAYFULL)) != CR_PLAYFULL) && (bytes > 1)) {
454 out_be32(CR_REG(ml403_ac97cr, PLAYFIFO),
455 CR_PLAYDATA(src[copied_words]));
459 if (full != CR_PLAYFULL)
463 spin_unlock(&ml403_ac97cr->reg_lock);
465 return (size_t) (copied_words * 2);
469 snd_ml403_ac97cr_capture_ind2_null(struct snd_pcm_substream *substream,
470 struct snd_pcm_indirect2 *rec)
472 struct snd_ml403_ac97cr *ml403_ac97cr;
473 int copied_words = 0;
476 ml403_ac97cr = snd_pcm_substream_chip(substream);
478 spin_lock(&ml403_ac97cr->reg_lock);
479 while ((empty = (in_be32(CR_REG(ml403_ac97cr, STATUS)) &
480 CR_RECEMPTY)) != CR_RECEMPTY) {
483 trash = CR_RECDATA(in_be32(CR_REG(ml403_ac97cr, RECFIFO)));
484 /* Hmmmm, really necessary? Don't want call to in_be32()
485 * to be optimised away!
491 spin_unlock(&ml403_ac97cr->reg_lock);
493 return (size_t) (copied_words * 2);
497 snd_ml403_ac97cr_capture_ind2_copy(struct snd_pcm_substream *substream,
498 struct snd_pcm_indirect2 *rec, size_t bytes)
500 struct snd_ml403_ac97cr *ml403_ac97cr;
502 int copied_words = 0;
505 ml403_ac97cr = snd_pcm_substream_chip(substream);
506 dst = (u16 *)(substream->runtime->dma_area + rec->sw_data);
508 spin_lock(&ml403_ac97cr->reg_lock);
509 while (((empty = (in_be32(CR_REG(ml403_ac97cr, STATUS)) &
510 CR_RECEMPTY)) != CR_RECEMPTY) && (bytes > 1)) {
511 dst[copied_words] = CR_RECDATA(in_be32(CR_REG(ml403_ac97cr,
516 if (empty != CR_RECEMPTY)
520 spin_unlock(&ml403_ac97cr->reg_lock);
522 return (size_t) (copied_words * 2);
525 static snd_pcm_uframes_t
526 snd_ml403_ac97cr_pcm_pointer(struct snd_pcm_substream *substream)
528 struct snd_ml403_ac97cr *ml403_ac97cr;
529 struct snd_pcm_indirect2 *ind2_rec = NULL;
531 ml403_ac97cr = snd_pcm_substream_chip(substream);
533 if (substream == ml403_ac97cr->playback_substream)
534 ind2_rec = &ml403_ac97cr->ind_rec;
535 if (substream == ml403_ac97cr->capture_substream)
536 ind2_rec = &ml403_ac97cr->capture_ind2_rec;
538 if (ind2_rec != NULL)
539 return snd_pcm_indirect2_pointer(substream, ind2_rec);
540 return (snd_pcm_uframes_t) 0;
544 snd_ml403_ac97cr_pcm_playback_trigger(struct snd_pcm_substream *substream,
547 struct snd_ml403_ac97cr *ml403_ac97cr;
550 ml403_ac97cr = snd_pcm_substream_chip(substream);
553 case SNDRV_PCM_TRIGGER_START:
554 PDEBUG(WORK_INFO, "trigger(playback): START\n");
555 ml403_ac97cr->ind_rec.hw_ready = 1;
557 /* clear play FIFO */
558 out_be32(CR_REG(ml403_ac97cr, RESETFIFO), CR_PLAYRESET);
560 /* enable play irq */
561 ml403_ac97cr->enable_irq = 1;
562 enable_irq(ml403_ac97cr->irq);
564 case SNDRV_PCM_TRIGGER_STOP:
565 PDEBUG(WORK_INFO, "trigger(playback): STOP\n");
566 ml403_ac97cr->ind_rec.hw_ready = 0;
567 #ifdef SND_PCM_INDIRECT2_STAT
568 snd_pcm_indirect2_stat(substream, &ml403_ac97cr->ind_rec);
570 /* disable play irq */
571 disable_irq_nosync(ml403_ac97cr->irq);
572 ml403_ac97cr->enable_irq = 0;
578 PDEBUG(WORK_INFO, "trigger(playback): (done)\n");
583 snd_ml403_ac97cr_pcm_capture_trigger(struct snd_pcm_substream *substream,
586 struct snd_ml403_ac97cr *ml403_ac97cr;
589 ml403_ac97cr = snd_pcm_substream_chip(substream);
592 case SNDRV_PCM_TRIGGER_START:
593 PDEBUG(WORK_INFO, "trigger(capture): START\n");
594 ml403_ac97cr->capture_ind2_rec.hw_ready = 0;
596 /* clear record FIFO */
597 out_be32(CR_REG(ml403_ac97cr, RESETFIFO), CR_RECRESET);
599 /* enable record irq */
600 ml403_ac97cr->enable_capture_irq = 1;
601 enable_irq(ml403_ac97cr->capture_irq);
603 case SNDRV_PCM_TRIGGER_STOP:
604 PDEBUG(WORK_INFO, "trigger(capture): STOP\n");
605 ml403_ac97cr->capture_ind2_rec.hw_ready = 0;
606 #ifdef SND_PCM_INDIRECT2_STAT
607 snd_pcm_indirect2_stat(substream,
608 &ml403_ac97cr->capture_ind2_rec);
610 /* disable capture irq */
611 disable_irq_nosync(ml403_ac97cr->capture_irq);
612 ml403_ac97cr->enable_capture_irq = 0;
618 PDEBUG(WORK_INFO, "trigger(capture): (done)\n");
623 snd_ml403_ac97cr_pcm_playback_prepare(struct snd_pcm_substream *substream)
625 struct snd_ml403_ac97cr *ml403_ac97cr;
626 struct snd_pcm_runtime *runtime;
628 ml403_ac97cr = snd_pcm_substream_chip(substream);
629 runtime = substream->runtime;
632 "prepare(): period_bytes=%d, minperiod_bytes=%d\n",
633 snd_pcm_lib_period_bytes(substream), CR_FIFO_SIZE / 2);
635 /* set sampling rate */
636 snd_ac97_set_rate(ml403_ac97cr->ac97, AC97_PCM_FRONT_DAC_RATE,
638 PDEBUG(WORK_INFO, "prepare(): rate=%d\n", runtime->rate);
640 /* init struct for intermediate buffer */
641 memset(&ml403_ac97cr->ind_rec, 0,
642 sizeof(struct snd_pcm_indirect2));
643 ml403_ac97cr->ind_rec.hw_buffer_size = CR_FIFO_SIZE;
644 ml403_ac97cr->ind_rec.sw_buffer_size =
645 snd_pcm_lib_buffer_bytes(substream);
646 ml403_ac97cr->ind_rec.min_periods = -1;
647 ml403_ac97cr->ind_rec.min_multiple =
648 snd_pcm_lib_period_bytes(substream) / (CR_FIFO_SIZE / 2);
649 PDEBUG(WORK_INFO, "prepare(): hw_buffer_size=%d, "
650 "sw_buffer_size=%d, min_multiple=%d\n",
651 CR_FIFO_SIZE, ml403_ac97cr->ind_rec.sw_buffer_size,
652 ml403_ac97cr->ind_rec.min_multiple);
657 snd_ml403_ac97cr_pcm_capture_prepare(struct snd_pcm_substream *substream)
659 struct snd_ml403_ac97cr *ml403_ac97cr;
660 struct snd_pcm_runtime *runtime;
662 ml403_ac97cr = snd_pcm_substream_chip(substream);
663 runtime = substream->runtime;
666 "prepare(capture): period_bytes=%d, minperiod_bytes=%d\n",
667 snd_pcm_lib_period_bytes(substream), CR_FIFO_SIZE / 2);
669 /* set sampling rate */
670 snd_ac97_set_rate(ml403_ac97cr->ac97, AC97_PCM_LR_ADC_RATE,
672 PDEBUG(WORK_INFO, "prepare(capture): rate=%d\n", runtime->rate);
674 /* init struct for intermediate buffer */
675 memset(&ml403_ac97cr->capture_ind2_rec, 0,
676 sizeof(struct snd_pcm_indirect2));
677 ml403_ac97cr->capture_ind2_rec.hw_buffer_size = CR_FIFO_SIZE;
678 ml403_ac97cr->capture_ind2_rec.sw_buffer_size =
679 snd_pcm_lib_buffer_bytes(substream);
680 ml403_ac97cr->capture_ind2_rec.min_multiple =
681 snd_pcm_lib_period_bytes(substream) / (CR_FIFO_SIZE / 2);
682 PDEBUG(WORK_INFO, "prepare(capture): hw_buffer_size=%d, "
683 "sw_buffer_size=%d, min_multiple=%d\n", CR_FIFO_SIZE,
684 ml403_ac97cr->capture_ind2_rec.sw_buffer_size,
685 ml403_ac97cr->capture_ind2_rec.min_multiple);
689 static int snd_ml403_ac97cr_hw_free(struct snd_pcm_substream *substream)
691 PDEBUG(WORK_INFO, "hw_free()\n");
692 return snd_pcm_lib_free_pages(substream);
696 snd_ml403_ac97cr_hw_params(struct snd_pcm_substream *substream,
697 struct snd_pcm_hw_params *hw_params)
699 PDEBUG(WORK_INFO, "hw_params(): desired buffer bytes=%d, desired "
701 params_buffer_bytes(hw_params), params_period_bytes(hw_params));
702 return snd_pcm_lib_malloc_pages(substream,
703 params_buffer_bytes(hw_params));
706 static int snd_ml403_ac97cr_playback_open(struct snd_pcm_substream *substream)
708 struct snd_ml403_ac97cr *ml403_ac97cr;
709 struct snd_pcm_runtime *runtime;
711 ml403_ac97cr = snd_pcm_substream_chip(substream);
712 runtime = substream->runtime;
714 PDEBUG(WORK_INFO, "open(playback)\n");
715 ml403_ac97cr->playback_substream = substream;
716 runtime->hw = snd_ml403_ac97cr_playback;
718 snd_pcm_hw_constraint_step(runtime, 0,
719 SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
724 static int snd_ml403_ac97cr_capture_open(struct snd_pcm_substream *substream)
726 struct snd_ml403_ac97cr *ml403_ac97cr;
727 struct snd_pcm_runtime *runtime;
729 ml403_ac97cr = snd_pcm_substream_chip(substream);
730 runtime = substream->runtime;
732 PDEBUG(WORK_INFO, "open(capture)\n");
733 ml403_ac97cr->capture_substream = substream;
734 runtime->hw = snd_ml403_ac97cr_capture;
736 snd_pcm_hw_constraint_step(runtime, 0,
737 SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
742 static int snd_ml403_ac97cr_playback_close(struct snd_pcm_substream *substream)
744 struct snd_ml403_ac97cr *ml403_ac97cr;
746 ml403_ac97cr = snd_pcm_substream_chip(substream);
748 PDEBUG(WORK_INFO, "close(playback)\n");
749 ml403_ac97cr->playback_substream = NULL;
753 static int snd_ml403_ac97cr_capture_close(struct snd_pcm_substream *substream)
755 struct snd_ml403_ac97cr *ml403_ac97cr;
757 ml403_ac97cr = snd_pcm_substream_chip(substream);
759 PDEBUG(WORK_INFO, "close(capture)\n");
760 ml403_ac97cr->capture_substream = NULL;
764 static struct snd_pcm_ops snd_ml403_ac97cr_playback_ops = {
765 .open = snd_ml403_ac97cr_playback_open,
766 .close = snd_ml403_ac97cr_playback_close,
767 .ioctl = snd_pcm_lib_ioctl,
768 .hw_params = snd_ml403_ac97cr_hw_params,
769 .hw_free = snd_ml403_ac97cr_hw_free,
770 .prepare = snd_ml403_ac97cr_pcm_playback_prepare,
771 .trigger = snd_ml403_ac97cr_pcm_playback_trigger,
772 .pointer = snd_ml403_ac97cr_pcm_pointer,
775 static struct snd_pcm_ops snd_ml403_ac97cr_capture_ops = {
776 .open = snd_ml403_ac97cr_capture_open,
777 .close = snd_ml403_ac97cr_capture_close,
778 .ioctl = snd_pcm_lib_ioctl,
779 .hw_params = snd_ml403_ac97cr_hw_params,
780 .hw_free = snd_ml403_ac97cr_hw_free,
781 .prepare = snd_ml403_ac97cr_pcm_capture_prepare,
782 .trigger = snd_ml403_ac97cr_pcm_capture_trigger,
783 .pointer = snd_ml403_ac97cr_pcm_pointer,
786 static irqreturn_t snd_ml403_ac97cr_irq(int irq, void *dev_id)
788 struct snd_ml403_ac97cr *ml403_ac97cr;
789 struct platform_device *pfdev;
792 ml403_ac97cr = (struct snd_ml403_ac97cr *)dev_id;
793 if (ml403_ac97cr == NULL)
796 pfdev = ml403_ac97cr->pfdev;
798 /* playback interrupt */
799 cmp_irq = platform_get_irq(pfdev, 0);
800 if (irq == cmp_irq) {
801 if (ml403_ac97cr->enable_irq)
802 snd_pcm_indirect2_playback_interrupt(
803 ml403_ac97cr->playback_substream,
804 &ml403_ac97cr->ind_rec,
805 snd_ml403_ac97cr_playback_ind2_copy,
806 snd_ml403_ac97cr_playback_ind2_zero);
810 /* record interrupt */
811 cmp_irq = platform_get_irq(pfdev, 1);
812 if (irq == cmp_irq) {
813 if (ml403_ac97cr->enable_capture_irq)
814 snd_pcm_indirect2_capture_interrupt(
815 ml403_ac97cr->capture_substream,
816 &ml403_ac97cr->capture_ind2_rec,
817 snd_ml403_ac97cr_capture_ind2_copy,
818 snd_ml403_ac97cr_capture_ind2_null);
827 PDEBUG(INIT_INFO, "irq(): irq %d is meant to be disabled! So, now try "
828 "to disable it _really_!\n", irq);
829 disable_irq_nosync(irq);
833 static unsigned short
834 snd_ml403_ac97cr_codec_read(struct snd_ac97 *ac97, unsigned short reg)
836 struct snd_ml403_ac97cr *ml403_ac97cr = ac97->private_data;
841 unsigned long end_time;
844 if (!LM4550_RF_OK(reg)) {
845 snd_printk(KERN_WARNING SND_ML403_AC97CR_DRIVER ": "
846 "access to unknown/unused codec register 0x%x "
850 /* check if we can fake/answer this access from our shadow register */
851 if ((lm4550_regfile[reg / 2].flag &
852 (LM4550_REG_DONEREAD | LM4550_REG_ALLFAKE)) &&
853 !(lm4550_regfile[reg / 2].flag & LM4550_REG_NOSHADOW)) {
854 if (lm4550_regfile[reg / 2].flag & LM4550_REG_FAKEREAD) {
855 PDEBUG(CODEC_FAKE, "codec_read(): faking read from "
856 "reg=0x%x, val=0x%x / %d\n",
857 reg, lm4550_regfile[reg / 2].def,
858 lm4550_regfile[reg / 2].def);
859 return lm4550_regfile[reg / 2].def;
860 } else if ((lm4550_regfile[reg / 2].flag &
861 LM4550_REG_FAKEPROBE) &&
862 ml403_ac97cr->ac97_fake) {
863 PDEBUG(CODEC_FAKE, "codec_read(): faking read from "
864 "reg=0x%x, val=0x%x / %d (probe)\n",
865 reg, lm4550_regfile[reg / 2].value,
866 lm4550_regfile[reg / 2].value);
867 return lm4550_regfile[reg / 2].value;
870 PDEBUG(CODEC_FAKE, "codec_read(): read access "
871 "answered by shadow register 0x%x (value=0x%x "
872 "/ %d) (cw=%d cr=%d)\n",
873 reg, lm4550_regfile[reg / 2].value,
874 lm4550_regfile[reg / 2].value,
875 ml403_ac97cr->ac97_write,
876 ml403_ac97cr->ac97_read);
878 PDEBUG(CODEC_FAKE, "codec_read(): read access "
879 "answered by shadow register 0x%x (value=0x%x "
881 reg, lm4550_regfile[reg / 2].value,
882 lm4550_regfile[reg / 2].value);
884 return lm4550_regfile[reg / 2].value;
887 /* if we are here, we _have_ to access the codec really, no faking */
888 if (mutex_lock_interruptible(&ml403_ac97cr->cdc_mutex) != 0)
891 ml403_ac97cr->ac97_read++;
893 spin_lock(&ml403_ac97cr->reg_lock);
894 out_be32(CR_REG(ml403_ac97cr, CODEC_ADDR),
895 CR_CODEC_ADDR(reg) | CR_CODEC_READ);
896 spin_unlock(&ml403_ac97cr->reg_lock);
897 end_time = jiffies + (HZ / CODEC_TIMEOUT_AFTER_READ);
899 spin_lock(&ml403_ac97cr->reg_lock);
902 stat = in_be32(CR_REG(ml403_ac97cr, STATUS));
903 if ((stat & CR_RAF) == CR_RAF) {
904 value = CR_CODEC_DATAREAD(
905 in_be32(CR_REG(ml403_ac97cr, CODEC_DATAREAD)));
906 PDEBUG(CODEC_SUCCESS, "codec_read(): (done) reg=0x%x, "
907 "value=0x%x / %d (STATUS=0x%x)\n",
908 reg, value, value, stat);
910 if ((in_be32(CR_REG(ml403_ac97cr, STATUS)) &
912 value = CR_CODEC_DATAREAD(
913 in_be32(CR_REG(ml403_ac97cr, CODEC_DATAREAD)));
914 PDEBUG(CODEC_SUCCESS, "codec_read(): (done) "
915 "reg=0x%x, value=0x%x / %d\n",
918 lm4550_regfile[reg / 2].value = value;
919 lm4550_regfile[reg / 2].flag |= LM4550_REG_DONEREAD;
920 spin_unlock(&ml403_ac97cr->reg_lock);
921 mutex_unlock(&ml403_ac97cr->cdc_mutex);
924 spin_unlock(&ml403_ac97cr->reg_lock);
925 schedule_timeout_uninterruptible(1);
926 } while (time_after(end_time, jiffies));
927 /* read the DATAREAD register anyway, see comment below */
928 spin_lock(&ml403_ac97cr->reg_lock);
930 CR_CODEC_DATAREAD(in_be32(CR_REG(ml403_ac97cr, CODEC_DATAREAD)));
931 spin_unlock(&ml403_ac97cr->reg_lock);
933 snd_printk(KERN_WARNING SND_ML403_AC97CR_DRIVER ": "
934 "timeout while codec read! "
935 "(reg=0x%x, last STATUS=0x%x, DATAREAD=0x%x / %d, %d) "
937 reg, stat, value, value, rafaccess,
938 ml403_ac97cr->ac97_write, ml403_ac97cr->ac97_read);
940 snd_printk(KERN_WARNING SND_ML403_AC97CR_DRIVER ": "
941 "timeout while codec read! "
942 "(reg=0x%x, DATAREAD=0x%x / %d)\n",
945 /* BUG: This is PURE speculation! But after _most_ read timeouts the
946 * value in the register is ok!
948 lm4550_regfile[reg / 2].value = value;
949 lm4550_regfile[reg / 2].flag |= LM4550_REG_DONEREAD;
950 mutex_unlock(&ml403_ac97cr->cdc_mutex);
955 snd_ml403_ac97cr_codec_write(struct snd_ac97 *ac97, unsigned short reg,
958 struct snd_ml403_ac97cr *ml403_ac97cr = ac97->private_data;
964 #ifdef CODEC_WRITE_CHECK_RAF
965 unsigned long end_time;
968 if (!LM4550_RF_OK(reg)) {
969 snd_printk(KERN_WARNING SND_ML403_AC97CR_DRIVER ": "
970 "access to unknown/unused codec register 0x%x "
974 if (lm4550_regfile[reg / 2].flag & LM4550_REG_READONLY) {
975 snd_printk(KERN_WARNING SND_ML403_AC97CR_DRIVER ": "
976 "write access to read only codec register 0x%x "
980 if ((val & lm4550_regfile[reg / 2].wmask) != val) {
981 snd_printk(KERN_WARNING SND_ML403_AC97CR_DRIVER ": "
982 "write access to codec register 0x%x "
983 "with bad value 0x%x / %d!\n",
985 val = val & lm4550_regfile[reg / 2].wmask;
987 if (((lm4550_regfile[reg / 2].flag & LM4550_REG_FAKEPROBE) &&
988 ml403_ac97cr->ac97_fake) &&
989 !(lm4550_regfile[reg / 2].flag & LM4550_REG_NOSHADOW)) {
990 PDEBUG(CODEC_FAKE, "codec_write(): faking write to reg=0x%x, "
991 "val=0x%x / %d\n", reg, val, val);
992 lm4550_regfile[reg / 2].value = (val &
993 lm4550_regfile[reg / 2].wmask);
996 if (mutex_lock_interruptible(&ml403_ac97cr->cdc_mutex) != 0)
999 ml403_ac97cr->ac97_write++;
1001 spin_lock(&ml403_ac97cr->reg_lock);
1002 out_be32(CR_REG(ml403_ac97cr, CODEC_DATAWRITE),
1003 CR_CODEC_DATAWRITE(val));
1004 out_be32(CR_REG(ml403_ac97cr, CODEC_ADDR),
1005 CR_CODEC_ADDR(reg) | CR_CODEC_WRITE);
1006 spin_unlock(&ml403_ac97cr->reg_lock);
1007 #ifdef CODEC_WRITE_CHECK_RAF
1008 /* check CR_CODEC_RAF bit to see if write access to register is done;
1009 * loop until bit is set or timeout happens
1011 end_time = jiffies + HZ / CODEC_TIMEOUT_AFTER_WRITE;
1013 spin_lock(&ml403_ac97cr->reg_lock);
1016 stat = in_be32(CR_REG(ml403_ac97cr, STATUS))
1017 if ((stat & CR_RAF) == CR_RAF) {
1019 if ((in_be32(CR_REG(ml403_ac97cr, STATUS)) &
1020 CR_RAF) == CR_RAF) {
1022 PDEBUG(CODEC_SUCCESS, "codec_write(): (done) "
1023 "reg=0x%x, value=%d / 0x%x\n",
1025 if (!(lm4550_regfile[reg / 2].flag &
1026 LM4550_REG_NOSHADOW) &&
1027 !(lm4550_regfile[reg / 2].flag &
1029 lm4550_regfile[reg / 2].value = val;
1030 lm4550_regfile[reg / 2].flag |= LM4550_REG_DONEREAD;
1031 spin_unlock(&ml403_ac97cr->reg_lock);
1032 mutex_unlock(&ml403_ac97cr->cdc_mutex);
1035 spin_unlock(&ml403_ac97cr->reg_lock);
1036 schedule_timeout_uninterruptible(1);
1037 } while (time_after(end_time, jiffies));
1039 snd_printk(KERN_WARNING SND_ML403_AC97CR_DRIVER ": "
1040 "timeout while codec write "
1041 "(reg=0x%x, val=0x%x / %d, last STATUS=0x%x, %d) "
1043 reg, val, val, stat, rafaccess, ml403_ac97cr->ac97_write,
1044 ml403_ac97cr->ac97_read);
1046 snd_printk(KERN_WARNING SND_ML403_AC97CR_DRIVER ": "
1047 "timeout while codec write (reg=0x%x, val=0x%x / %d)\n",
1050 #else /* CODEC_WRITE_CHECK_RAF */
1051 #if CODEC_WAIT_AFTER_WRITE > 0
1052 /* officially, in AC97 spec there is no possibility for a AC97
1053 * controller to determine, if write access is done or not - so: How
1054 * is Xilinx able to provide a RAF bit for write access?
1055 * => very strange, thus just don't check RAF bit (compare with
1056 * Xilinx's example app in EDK 8.1i) and wait
1058 schedule_timeout_uninterruptible(HZ / CODEC_WAIT_AFTER_WRITE);
1060 PDEBUG(CODEC_SUCCESS, "codec_write(): (done) "
1061 "reg=0x%x, value=%d / 0x%x (no RAF check)\n",
1064 mutex_unlock(&ml403_ac97cr->cdc_mutex);
1068 static int __devinit
1069 snd_ml403_ac97cr_chip_init(struct snd_ml403_ac97cr *ml403_ac97cr)
1071 unsigned long end_time;
1072 PDEBUG(INIT_INFO, "chip_init():\n");
1073 end_time = jiffies + HZ / CODEC_TIMEOUT_ON_INIT;
1075 if (in_be32(CR_REG(ml403_ac97cr, STATUS)) & CR_CODECREADY) {
1076 /* clear both hardware FIFOs */
1077 out_be32(CR_REG(ml403_ac97cr, RESETFIFO),
1078 CR_RECRESET | CR_PLAYRESET);
1079 PDEBUG(INIT_INFO, "chip_init(): (done)\n");
1082 schedule_timeout_uninterruptible(1);
1083 } while (time_after(end_time, jiffies));
1084 snd_printk(KERN_ERR SND_ML403_AC97CR_DRIVER ": "
1085 "timeout while waiting for codec, "
1090 static int snd_ml403_ac97cr_free(struct snd_ml403_ac97cr *ml403_ac97cr)
1092 PDEBUG(INIT_INFO, "free():\n");
1094 if (ml403_ac97cr->irq >= 0)
1095 free_irq(ml403_ac97cr->irq, ml403_ac97cr);
1096 if (ml403_ac97cr->capture_irq >= 0)
1097 free_irq(ml403_ac97cr->capture_irq, ml403_ac97cr);
1098 /* give back "port" */
1099 if (ml403_ac97cr->port != NULL)
1100 iounmap(ml403_ac97cr->port);
1101 kfree(ml403_ac97cr);
1102 PDEBUG(INIT_INFO, "free(): (done)\n");
1106 static int snd_ml403_ac97cr_dev_free(struct snd_device *snddev)
1108 struct snd_ml403_ac97cr *ml403_ac97cr = snddev->device_data;
1109 PDEBUG(INIT_INFO, "dev_free():\n");
1110 return snd_ml403_ac97cr_free(ml403_ac97cr);
1113 static int __devinit
1114 snd_ml403_ac97cr_create(struct snd_card *card, struct platform_device *pfdev,
1115 struct snd_ml403_ac97cr **rml403_ac97cr)
1117 struct snd_ml403_ac97cr *ml403_ac97cr;
1119 static struct snd_device_ops ops = {
1120 .dev_free = snd_ml403_ac97cr_dev_free,
1122 struct resource *resource;
1125 *rml403_ac97cr = NULL;
1126 ml403_ac97cr = kzalloc(sizeof(*ml403_ac97cr), GFP_KERNEL);
1127 if (ml403_ac97cr == NULL)
1129 spin_lock_init(&ml403_ac97cr->reg_lock);
1130 mutex_init(&ml403_ac97cr->cdc_mutex);
1131 ml403_ac97cr->card = card;
1132 ml403_ac97cr->pfdev = pfdev;
1133 ml403_ac97cr->irq = -1;
1134 ml403_ac97cr->enable_irq = 0;
1135 ml403_ac97cr->capture_irq = -1;
1136 ml403_ac97cr->enable_capture_irq = 0;
1137 ml403_ac97cr->port = NULL;
1138 ml403_ac97cr->res_port = NULL;
1140 PDEBUG(INIT_INFO, "Trying to reserve resources now ...\n");
1141 resource = platform_get_resource(pfdev, IORESOURCE_MEM, 0);
1143 ml403_ac97cr->port = ioremap_nocache(resource->start,
1145 (resource->start) + 1);
1146 if (ml403_ac97cr->port == NULL) {
1147 snd_printk(KERN_ERR SND_ML403_AC97CR_DRIVER ": "
1148 "unable to remap memory region (%x to %x)\n",
1149 resource->start, resource->end);
1150 snd_ml403_ac97cr_free(ml403_ac97cr);
1153 snd_printk(KERN_INFO SND_ML403_AC97CR_DRIVER ": "
1154 "remap controller memory region to "
1155 "0x%x done\n", (unsigned int)ml403_ac97cr->port);
1157 irq = platform_get_irq(pfdev, 0);
1158 if (request_irq(irq, snd_ml403_ac97cr_irq, IRQF_DISABLED,
1159 pfdev->dev.bus_id, (void *)ml403_ac97cr)) {
1160 snd_printk(KERN_ERR SND_ML403_AC97CR_DRIVER ": "
1161 "unable to grab IRQ %d\n",
1163 snd_ml403_ac97cr_free(ml403_ac97cr);
1166 ml403_ac97cr->irq = irq;
1167 snd_printk(KERN_INFO SND_ML403_AC97CR_DRIVER ": "
1168 "request (playback) irq %d done\n",
1170 irq = platform_get_irq(pfdev, 1);
1171 if (request_irq(irq, snd_ml403_ac97cr_irq, IRQF_DISABLED,
1172 pfdev->dev.bus_id, (void *)ml403_ac97cr)) {
1173 snd_printk(KERN_ERR SND_ML403_AC97CR_DRIVER ": "
1174 "unable to grab IRQ %d\n",
1176 snd_ml403_ac97cr_free(ml403_ac97cr);
1179 ml403_ac97cr->capture_irq = irq;
1180 snd_printk(KERN_INFO SND_ML403_AC97CR_DRIVER ": "
1181 "request (capture) irq %d done\n",
1182 ml403_ac97cr->capture_irq);
1184 err = snd_ml403_ac97cr_chip_init(ml403_ac97cr);
1186 snd_ml403_ac97cr_free(ml403_ac97cr);
1190 err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, ml403_ac97cr, &ops);
1192 PDEBUG(INIT_FAILURE, "probe(): snd_device_new() failed!\n");
1193 snd_ml403_ac97cr_free(ml403_ac97cr);
1197 snd_card_set_dev(card, &pfdev->dev);
1199 *rml403_ac97cr = ml403_ac97cr;
1203 static void snd_ml403_ac97cr_mixer_free(struct snd_ac97 *ac97)
1205 struct snd_ml403_ac97cr *ml403_ac97cr = ac97->private_data;
1206 PDEBUG(INIT_INFO, "mixer_free():\n");
1207 ml403_ac97cr->ac97 = NULL;
1208 PDEBUG(INIT_INFO, "mixer_free(): (done)\n");
1211 static int __devinit
1212 snd_ml403_ac97cr_mixer(struct snd_ml403_ac97cr *ml403_ac97cr)
1214 struct snd_ac97_bus *bus;
1215 struct snd_ac97_template ac97;
1217 static struct snd_ac97_bus_ops ops = {
1218 .write = snd_ml403_ac97cr_codec_write,
1219 .read = snd_ml403_ac97cr_codec_read,
1221 PDEBUG(INIT_INFO, "mixer():\n");
1222 err = snd_ac97_bus(ml403_ac97cr->card, 0, &ops, NULL, &bus);
1226 memset(&ac97, 0, sizeof(ac97));
1227 ml403_ac97cr->ac97_fake = 1;
1228 lm4550_regfile_init();
1230 ml403_ac97cr->ac97_read = 0;
1231 ml403_ac97cr->ac97_write = 0;
1233 ac97.private_data = ml403_ac97cr;
1234 ac97.private_free = snd_ml403_ac97cr_mixer_free;
1235 ac97.scaps = AC97_SCAP_AUDIO | AC97_SCAP_SKIP_MODEM |
1237 err = snd_ac97_mixer(bus, &ac97, &ml403_ac97cr->ac97);
1238 ml403_ac97cr->ac97_fake = 0;
1239 lm4550_regfile_write_values_after_init(ml403_ac97cr->ac97);
1240 PDEBUG(INIT_INFO, "mixer(): (done) snd_ac97_mixer()=%d\n", err);
1244 static int __devinit
1245 snd_ml403_ac97cr_pcm(struct snd_ml403_ac97cr *ml403_ac97cr, int device,
1246 struct snd_pcm **rpcm)
1248 struct snd_pcm *pcm;
1253 err = snd_pcm_new(ml403_ac97cr->card, "ML403AC97CR/1", device, 1, 1,
1257 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
1258 &snd_ml403_ac97cr_playback_ops);
1259 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE,
1260 &snd_ml403_ac97cr_capture_ops);
1261 pcm->private_data = ml403_ac97cr;
1262 pcm->info_flags = 0;
1263 strcpy(pcm->name, "ML403AC97CR DAC/ADC");
1264 ml403_ac97cr->pcm = pcm;
1266 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_CONTINUOUS,
1267 snd_dma_continuous_data(GFP_KERNEL),
1275 static int __devinit snd_ml403_ac97cr_probe(struct platform_device *pfdev)
1277 struct snd_card *card;
1278 struct snd_ml403_ac97cr *ml403_ac97cr = NULL;
1280 int dev = pfdev->id;
1282 if (dev >= SNDRV_CARDS)
1287 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
1290 err = snd_ml403_ac97cr_create(card, pfdev, &ml403_ac97cr);
1292 PDEBUG(INIT_FAILURE, "probe(): create failed!\n");
1293 snd_card_free(card);
1296 PDEBUG(INIT_INFO, "probe(): create done\n");
1297 card->private_data = ml403_ac97cr;
1298 err = snd_ml403_ac97cr_mixer(ml403_ac97cr);
1300 snd_card_free(card);
1303 PDEBUG(INIT_INFO, "probe(): mixer done\n");
1304 err = snd_ml403_ac97cr_pcm(ml403_ac97cr, 0, NULL);
1306 snd_card_free(card);
1309 PDEBUG(INIT_INFO, "probe(): PCM done\n");
1310 strcpy(card->driver, SND_ML403_AC97CR_DRIVER);
1311 strcpy(card->shortname, "ML403 AC97 Controller Reference");
1312 sprintf(card->longname, "%s %s at 0x%lx, irq %i & %i, device %i",
1313 card->shortname, card->driver,
1314 (unsigned long)ml403_ac97cr->port, ml403_ac97cr->irq,
1315 ml403_ac97cr->capture_irq, dev + 1);
1317 err = snd_card_register(card);
1319 snd_card_free(card);
1322 platform_set_drvdata(pfdev, card);
1323 PDEBUG(INIT_INFO, "probe(): (done)\n");
1327 static int snd_ml403_ac97cr_remove(struct platform_device *pfdev)
1329 snd_card_free(platform_get_drvdata(pfdev));
1330 platform_set_drvdata(pfdev, NULL);
1334 static struct platform_driver snd_ml403_ac97cr_driver = {
1335 .probe = snd_ml403_ac97cr_probe,
1336 .remove = snd_ml403_ac97cr_remove,
1338 .name = SND_ML403_AC97CR_DRIVER,
1342 static int __init alsa_card_ml403_ac97cr_init(void)
1344 return platform_driver_register(&snd_ml403_ac97cr_driver);
1347 static void __exit alsa_card_ml403_ac97cr_exit(void)
1349 platform_driver_unregister(&snd_ml403_ac97cr_driver);
1352 module_init(alsa_card_ml403_ac97cr_init)
1353 module_exit(alsa_card_ml403_ac97cr_exit)