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 * - Playback support seems to be pretty stable - no issues here.
32 * - Capture support "works" now, too. Overruns don't happen any longer so often.
33 * But there might still be some ...
36 #include <linux/init.h>
37 #include <linux/moduleparam.h>
39 #include <linux/platform_device.h>
41 #include <linux/ioport.h>
43 #include <linux/interrupt.h>
46 #include <linux/param.h>
47 /* jiffies, time_*() */
48 #include <linux/jiffies.h>
49 /* schedule_timeout*() */
50 #include <linux/sched.h>
52 #include <linux/spinlock.h>
53 /* struct mutex, mutex_init(), mutex_*lock() */
54 #include <linux/mutex.h>
56 /* snd_printk(), snd_printd() */
57 #include <sound/core.h>
58 #include <sound/pcm.h>
59 #include <sound/pcm_params.h>
60 #include <sound/initval.h>
61 #include <sound/ac97_codec.h>
63 #include "pcm-indirect2.h"
66 #define SND_ML403_AC97CR_DRIVER "ml403-ac97cr"
68 MODULE_AUTHOR("Joachim Foerster <JOFT@gmx.de>");
69 MODULE_DESCRIPTION("Xilinx ML403 AC97 Controller Reference");
70 MODULE_LICENSE("GPL");
71 MODULE_SUPPORTED_DEVICE("{{Xilinx,ML403 AC97 Controller Reference}}");
73 static int index
[SNDRV_CARDS
] = SNDRV_DEFAULT_IDX
;
74 static char *id
[SNDRV_CARDS
] = SNDRV_DEFAULT_STR
;
75 static int enable
[SNDRV_CARDS
] = SNDRV_DEFAULT_ENABLE
;
77 module_param_array(index
, int, NULL
, 0444);
78 MODULE_PARM_DESC(index
, "Index value for ML403 AC97 Controller Reference.");
79 module_param_array(id
, charp
, NULL
, 0444);
80 MODULE_PARM_DESC(id
, "ID string for ML403 AC97 Controller Reference.");
81 module_param_array(enable
, bool, NULL
, 0444);
82 MODULE_PARM_DESC(enable
, "Enable this ML403 AC97 Controller Reference.");
84 /* Special feature options */
85 /*#define CODEC_WRITE_CHECK_RAF*/ /* don't return after a write to a codec
86 * register, while RAF bit is not set
88 /* Debug options for code which may be removed completely in a final version */
89 #ifdef CONFIG_SND_DEBUG
90 /*#define CODEC_STAT*/ /* turn on some minimal "statistics"
91 * about codec register usage
93 #define SND_PCM_INDIRECT2_STAT /* turn on some "statistics" about the
94 * process of copying bytes from the
95 * intermediate buffer to the hardware
96 * fifo and the other way round
100 /* Definition of a "level/facility dependent" printk(); may be removed
101 * completely in a final version
104 #ifdef CONFIG_SND_DEBUG
105 /* "facilities" for PDEBUG */
106 #define UNKNOWN (1<<0)
107 #define CODEC_SUCCESS (1<<1)
108 #define CODEC_FAKE (1<<2)
109 #define INIT_INFO (1<<3)
110 #define INIT_FAILURE (1<<4)
111 #define WORK_INFO (1<<5)
112 #define WORK_FAILURE (1<<6)
114 #define PDEBUG_FACILITIES (UNKNOWN | INIT_FAILURE | WORK_FAILURE)
116 #define PDEBUG(fac, fmt, args...) do { \
117 if (fac & PDEBUG_FACILITIES) \
118 snd_printd(KERN_DEBUG SND_ML403_AC97CR_DRIVER ": " \
122 #define PDEBUG(fac, fmt, args...) /* nothing */
127 /* Defines for "waits"/timeouts (portions of HZ=250 on arch/ppc by default) */
128 #define CODEC_TIMEOUT_ON_INIT 5 /* timeout for checking for codec
129 * readiness (after insmod)
131 #ifndef CODEC_WRITE_CHECK_RAF
132 #define CODEC_WAIT_AFTER_WRITE 100 /* general, static wait after a write
133 * access to a codec register, may be
134 * 0 to completely remove wait
137 #define CODEC_TIMEOUT_AFTER_WRITE 5 /* timeout after a write access to a
138 * codec register, if RAF bit is used
141 #define CODEC_TIMEOUT_AFTER_READ 5 /* timeout after a read access to a
142 * codec register (checking RAF bit)
145 /* Infrastructure for codec register shadowing */
146 #define LM4550_REG_OK (1<<0) /* register exists */
147 #define LM4550_REG_DONEREAD (1<<1) /* read register once, value should be
148 * the same currently in the register
150 #define LM4550_REG_NOSAVE (1<<2) /* values written to this register will
151 * not be saved in the register
153 #define LM4550_REG_NOSHADOW (1<<3) /* don't do register shadowing, use plain
156 #define LM4550_REG_READONLY (1<<4) /* register is read only */
157 #define LM4550_REG_FAKEPROBE (1<<5) /* fake write _and_ read actions during
160 #define LM4550_REG_FAKEREAD (1<<6) /* fake read access, always return
163 #define LM4550_REG_ALLFAKE (LM4550_REG_FAKEREAD | LM4550_REG_FAKEPROBE)
172 struct lm4550_reg lm4550_regfile
[64] = {
173 [AC97_RESET
/ 2] = {.flag
= LM4550_REG_OK \
174 | LM4550_REG_NOSAVE \
175 | LM4550_REG_FAKEREAD
,
177 [AC97_MASTER
/ 2] = {.flag
= LM4550_REG_OK
178 | LM4550_REG_FAKEPROBE
,
181 [AC97_HEADPHONE
/ 2] = {.flag
= LM4550_REG_OK \
182 | LM4550_REG_FAKEPROBE
,
185 [AC97_MASTER_MONO
/ 2] = {.flag
= LM4550_REG_OK \
186 | LM4550_REG_FAKEPROBE
,
189 [AC97_PC_BEEP
/ 2] = {.flag
= LM4550_REG_OK \
190 | LM4550_REG_FAKEPROBE
,
193 [AC97_PHONE
/ 2] = {.flag
= LM4550_REG_OK \
194 | LM4550_REG_FAKEPROBE
,
197 [AC97_MIC
/ 2] = {.flag
= LM4550_REG_OK \
198 | LM4550_REG_FAKEPROBE
,
201 [AC97_LINE
/ 2] = {.flag
= LM4550_REG_OK \
202 | LM4550_REG_FAKEPROBE
,
205 [AC97_CD
/ 2] = {.flag
= LM4550_REG_OK \
206 | LM4550_REG_FAKEPROBE
,
209 [AC97_VIDEO
/ 2] = {.flag
= LM4550_REG_OK \
210 | LM4550_REG_FAKEPROBE
,
213 [AC97_AUX
/ 2] = {.flag
= LM4550_REG_OK \
214 | LM4550_REG_FAKEPROBE
,
217 [AC97_PCM
/ 2] = {.flag
= LM4550_REG_OK \
218 | LM4550_REG_FAKEPROBE
,
221 [AC97_REC_SEL
/ 2] = {.flag
= LM4550_REG_OK \
222 | LM4550_REG_FAKEPROBE
,
225 [AC97_REC_GAIN
/ 2] = {.flag
= LM4550_REG_OK \
226 | LM4550_REG_FAKEPROBE
,
229 [AC97_GENERAL_PURPOSE
/ 2] = {.flag
= LM4550_REG_OK \
230 | LM4550_REG_FAKEPROBE
,
233 [AC97_3D_CONTROL
/ 2] = {.flag
= LM4550_REG_OK \
234 | LM4550_REG_FAKEREAD \
235 | LM4550_REG_READONLY
,
237 [AC97_POWERDOWN
/ 2] = {.flag
= LM4550_REG_OK \
238 | LM4550_REG_NOSHADOW \
241 /* may not write ones to
242 * REF/ANL/DAC/ADC bits
245 [AC97_EXTENDED_ID
/ 2] = {.flag
= LM4550_REG_OK \
246 | LM4550_REG_FAKEREAD \
247 | LM4550_REG_READONLY
,
248 .def
= 0x0201}, /* primary codec */
249 [AC97_EXTENDED_STATUS
/ 2] = {.flag
= LM4550_REG_OK \
250 | LM4550_REG_NOSHADOW \
253 [AC97_PCM_FRONT_DAC_RATE
/ 2] = {.flag
= LM4550_REG_OK \
254 | LM4550_REG_FAKEPROBE
,
257 [AC97_PCM_LR_ADC_RATE
/ 2] = {.flag
= LM4550_REG_OK \
258 | LM4550_REG_FAKEPROBE
,
261 [AC97_VENDOR_ID1
/ 2] = {.flag
= LM4550_REG_OK \
262 | LM4550_REG_READONLY \
263 | LM4550_REG_FAKEREAD
,
265 [AC97_VENDOR_ID2
/ 2] = {.flag
= LM4550_REG_OK \
266 | LM4550_REG_READONLY \
267 | LM4550_REG_FAKEREAD
,
271 #define LM4550_RF_OK(reg) (lm4550_regfile[reg / 2].flag & LM4550_REG_OK)
273 static void lm4550_regfile_init(void)
276 for (i
= 0; i
< 64; i
++)
277 if (lm4550_regfile
[i
].flag
& LM4550_REG_FAKEPROBE
)
278 lm4550_regfile
[i
].value
= lm4550_regfile
[i
].def
;
281 static void lm4550_regfile_write_values_after_init(struct snd_ac97
*ac97
)
284 for (i
= 0; i
< 64; i
++)
285 if ((lm4550_regfile
[i
].flag
& LM4550_REG_FAKEPROBE
) &&
286 (lm4550_regfile
[i
].value
!= lm4550_regfile
[i
].def
)) {
287 PDEBUG(CODEC_FAKE
, "lm4550_regfile_write_values_after_"
288 "init(): reg=0x%x value=0x%x / %d is different "
289 "from def=0x%x / %d\n",
290 i
, lm4550_regfile
[i
].value
,
291 lm4550_regfile
[i
].value
, lm4550_regfile
[i
].def
,
292 lm4550_regfile
[i
].def
);
293 snd_ac97_write(ac97
, i
* 2, lm4550_regfile
[i
].value
);
294 lm4550_regfile
[i
].flag
|= LM4550_REG_DONEREAD
;
299 /* direct registers */
300 #define CR_REG(ml403_ac97cr, x) ((ml403_ac97cr)->port + CR_REG_##x)
302 #define CR_REG_PLAYFIFO 0x00
303 #define CR_PLAYDATA(a) ((a) & 0xFFFF)
305 #define CR_REG_RECFIFO 0x04
306 #define CR_RECDATA(a) ((a) & 0xFFFF)
308 #define CR_REG_STATUS 0x08
309 #define CR_RECOVER (1<<7)
310 #define CR_PLAYUNDER (1<<6)
311 #define CR_CODECREADY (1<<5)
312 #define CR_RAF (1<<4)
313 #define CR_RECEMPTY (1<<3)
314 #define CR_RECFULL (1<<2)
315 #define CR_PLAYHALF (1<<1)
316 #define CR_PLAYFULL (1<<0)
318 #define CR_REG_RESETFIFO 0x0C
319 #define CR_RECRESET (1<<1)
320 #define CR_PLAYRESET (1<<0)
322 #define CR_REG_CODEC_ADDR 0x10
324 * #define CR_CODEC_ADDR(a) ((a) << 1)
325 * #define CR_CODEC_READ (1<<0)
326 * #define CR_CODEC_WRITE (0<<0)
328 /* RefDesign example says: */
329 #define CR_CODEC_ADDR(a) ((a) << 0)
330 #define CR_CODEC_READ (1<<7)
331 #define CR_CODEC_WRITE (0<<7)
333 #define CR_REG_CODEC_DATAREAD 0x14
334 #define CR_CODEC_DATAREAD(v) ((v) & 0xFFFF)
336 #define CR_REG_CODEC_DATAWRITE 0x18
337 #define CR_CODEC_DATAWRITE(v) ((v) & 0xFFFF)
339 #define CR_FIFO_SIZE 32
341 struct snd_ml403_ac97cr
{
342 /* lock for access to (controller) registers */
344 /* mutex for the whole sequence of accesses to (controller) registers
345 * which affect codec registers
347 struct mutex cdc_mutex
;
349 int irq
; /* for playback */
350 int enable_irq
; /* for playback */
353 int enable_capture_irq
;
355 struct resource
*res_port
;
358 struct snd_ac97
*ac97
;
365 struct platform_device
*pfdev
;
366 struct snd_card
*card
;
368 struct snd_pcm_substream
*playback_substream
;
369 struct snd_pcm_substream
*capture_substream
;
371 struct snd_pcm_indirect2 ind_rec
; /* for playback */
372 struct snd_pcm_indirect2 capture_ind2_rec
;
375 static struct snd_pcm_hardware snd_ml403_ac97cr_playback
= {
376 .info
= (SNDRV_PCM_INFO_MMAP
|
377 SNDRV_PCM_INFO_INTERLEAVED
|
378 SNDRV_PCM_INFO_MMAP_VALID
),
379 .formats
= SNDRV_PCM_FMTBIT_S16_BE
,
380 .rates
= (SNDRV_PCM_RATE_CONTINUOUS
|
381 SNDRV_PCM_RATE_8000_48000
),
386 .buffer_bytes_max
= (128*1024),
387 .period_bytes_min
= CR_FIFO_SIZE
/2,
388 .period_bytes_max
= (64*1024),
390 .periods_max
= (128*1024)/(CR_FIFO_SIZE
/2),
394 static struct snd_pcm_hardware snd_ml403_ac97cr_capture
= {
395 .info
= (SNDRV_PCM_INFO_MMAP
|
396 SNDRV_PCM_INFO_INTERLEAVED
|
397 SNDRV_PCM_INFO_MMAP_VALID
),
398 .formats
= SNDRV_PCM_FMTBIT_S16_BE
,
399 .rates
= (SNDRV_PCM_RATE_CONTINUOUS
|
400 SNDRV_PCM_RATE_8000_48000
),
405 .buffer_bytes_max
= (128*1024),
406 .period_bytes_min
= CR_FIFO_SIZE
/2,
407 .period_bytes_max
= (64*1024),
409 .periods_max
= (128*1024)/(CR_FIFO_SIZE
/2),
414 snd_ml403_ac97cr_playback_ind2_zero(struct snd_pcm_substream
*substream
,
415 struct snd_pcm_indirect2
*rec
)
417 struct snd_ml403_ac97cr
*ml403_ac97cr
;
418 int copied_words
= 0;
421 ml403_ac97cr
= snd_pcm_substream_chip(substream
);
423 spin_lock(&ml403_ac97cr
->reg_lock
);
424 while ((full
= (in_be32(CR_REG(ml403_ac97cr
, STATUS
)) &
425 CR_PLAYFULL
)) != CR_PLAYFULL
) {
426 out_be32(CR_REG(ml403_ac97cr
, PLAYFIFO
), 0);
430 spin_unlock(&ml403_ac97cr
->reg_lock
);
432 return (size_t) (copied_words
* 2);
436 snd_ml403_ac97cr_playback_ind2_copy(struct snd_pcm_substream
*substream
,
437 struct snd_pcm_indirect2
*rec
,
440 struct snd_ml403_ac97cr
*ml403_ac97cr
;
442 int copied_words
= 0;
445 ml403_ac97cr
= snd_pcm_substream_chip(substream
);
446 src
= (u16
*)(substream
->runtime
->dma_area
+ rec
->sw_data
);
448 spin_lock(&ml403_ac97cr
->reg_lock
);
449 while (((full
= (in_be32(CR_REG(ml403_ac97cr
, STATUS
)) &
450 CR_PLAYFULL
)) != CR_PLAYFULL
) && (bytes
> 1)) {
451 out_be32(CR_REG(ml403_ac97cr
, PLAYFIFO
),
452 CR_PLAYDATA(src
[copied_words
]));
456 if (full
!= CR_PLAYFULL
)
460 spin_unlock(&ml403_ac97cr
->reg_lock
);
462 return (size_t) (copied_words
* 2);
466 snd_ml403_ac97cr_capture_ind2_null(struct snd_pcm_substream
*substream
,
467 struct snd_pcm_indirect2
*rec
)
469 struct snd_ml403_ac97cr
*ml403_ac97cr
;
470 int copied_words
= 0;
473 ml403_ac97cr
= snd_pcm_substream_chip(substream
);
475 spin_lock(&ml403_ac97cr
->reg_lock
);
476 while ((empty
= (in_be32(CR_REG(ml403_ac97cr
, STATUS
)) &
477 CR_RECEMPTY
)) != CR_RECEMPTY
) {
480 trash
= CR_RECDATA(in_be32(CR_REG(ml403_ac97cr
, RECFIFO
)));
481 /* Hmmmm, really necessary? Don't want call to in_be32()
482 * to be optimised away!
488 spin_unlock(&ml403_ac97cr
->reg_lock
);
490 return (size_t) (copied_words
* 2);
494 snd_ml403_ac97cr_capture_ind2_copy(struct snd_pcm_substream
*substream
,
495 struct snd_pcm_indirect2
*rec
, size_t bytes
)
497 struct snd_ml403_ac97cr
*ml403_ac97cr
;
499 int copied_words
= 0;
502 ml403_ac97cr
= snd_pcm_substream_chip(substream
);
503 dst
= (u16
*)(substream
->runtime
->dma_area
+ rec
->sw_data
);
505 spin_lock(&ml403_ac97cr
->reg_lock
);
506 while (((empty
= (in_be32(CR_REG(ml403_ac97cr
, STATUS
)) &
507 CR_RECEMPTY
)) != CR_RECEMPTY
) && (bytes
> 1)) {
508 dst
[copied_words
] = CR_RECDATA(in_be32(CR_REG(ml403_ac97cr
,
513 if (empty
!= CR_RECEMPTY
)
517 spin_unlock(&ml403_ac97cr
->reg_lock
);
519 return (size_t) (copied_words
* 2);
522 static snd_pcm_uframes_t
523 snd_ml403_ac97cr_pcm_pointer(struct snd_pcm_substream
*substream
)
525 struct snd_ml403_ac97cr
*ml403_ac97cr
;
526 struct snd_pcm_indirect2
*ind2_rec
= NULL
;
528 ml403_ac97cr
= snd_pcm_substream_chip(substream
);
530 if (substream
== ml403_ac97cr
->playback_substream
)
531 ind2_rec
= &ml403_ac97cr
->ind_rec
;
532 if (substream
== ml403_ac97cr
->capture_substream
)
533 ind2_rec
= &ml403_ac97cr
->capture_ind2_rec
;
535 if (ind2_rec
!= NULL
)
536 return snd_pcm_indirect2_pointer(substream
, ind2_rec
);
537 return (snd_pcm_uframes_t
) 0;
541 snd_ml403_ac97cr_pcm_playback_trigger(struct snd_pcm_substream
*substream
,
544 struct snd_ml403_ac97cr
*ml403_ac97cr
;
547 ml403_ac97cr
= snd_pcm_substream_chip(substream
);
550 case SNDRV_PCM_TRIGGER_START
:
551 PDEBUG(WORK_INFO
, "trigger(playback): START\n");
552 ml403_ac97cr
->ind_rec
.hw_ready
= 1;
554 /* clear play FIFO */
555 out_be32(CR_REG(ml403_ac97cr
, RESETFIFO
), CR_PLAYRESET
);
557 /* enable play irq */
558 ml403_ac97cr
->enable_irq
= 1;
559 enable_irq(ml403_ac97cr
->irq
);
561 case SNDRV_PCM_TRIGGER_STOP
:
562 PDEBUG(WORK_INFO
, "trigger(playback): STOP\n");
563 ml403_ac97cr
->ind_rec
.hw_ready
= 0;
564 #ifdef SND_PCM_INDIRECT2_STAT
565 snd_pcm_indirect2_stat(substream
, &ml403_ac97cr
->ind_rec
);
567 /* disable play irq */
568 disable_irq_nosync(ml403_ac97cr
->irq
);
569 ml403_ac97cr
->enable_irq
= 0;
575 PDEBUG(WORK_INFO
, "trigger(playback): (done)\n");
580 snd_ml403_ac97cr_pcm_capture_trigger(struct snd_pcm_substream
*substream
,
583 struct snd_ml403_ac97cr
*ml403_ac97cr
;
586 ml403_ac97cr
= snd_pcm_substream_chip(substream
);
589 case SNDRV_PCM_TRIGGER_START
:
590 PDEBUG(WORK_INFO
, "trigger(capture): START\n");
591 ml403_ac97cr
->capture_ind2_rec
.hw_ready
= 0;
593 /* clear record FIFO */
594 out_be32(CR_REG(ml403_ac97cr
, RESETFIFO
), CR_RECRESET
);
596 /* enable record irq */
597 ml403_ac97cr
->enable_capture_irq
= 1;
598 enable_irq(ml403_ac97cr
->capture_irq
);
600 case SNDRV_PCM_TRIGGER_STOP
:
601 PDEBUG(WORK_INFO
, "trigger(capture): STOP\n");
602 ml403_ac97cr
->capture_ind2_rec
.hw_ready
= 0;
603 #ifdef SND_PCM_INDIRECT2_STAT
604 snd_pcm_indirect2_stat(substream
,
605 &ml403_ac97cr
->capture_ind2_rec
);
607 /* disable capture irq */
608 disable_irq_nosync(ml403_ac97cr
->capture_irq
);
609 ml403_ac97cr
->enable_capture_irq
= 0;
615 PDEBUG(WORK_INFO
, "trigger(capture): (done)\n");
620 snd_ml403_ac97cr_pcm_playback_prepare(struct snd_pcm_substream
*substream
)
622 struct snd_ml403_ac97cr
*ml403_ac97cr
;
623 struct snd_pcm_runtime
*runtime
;
625 ml403_ac97cr
= snd_pcm_substream_chip(substream
);
626 runtime
= substream
->runtime
;
629 "prepare(): period_bytes=%d, minperiod_bytes=%d\n",
630 snd_pcm_lib_period_bytes(substream
), CR_FIFO_SIZE
/ 2);
632 /* set sampling rate */
633 snd_ac97_set_rate(ml403_ac97cr
->ac97
, AC97_PCM_FRONT_DAC_RATE
,
635 PDEBUG(WORK_INFO
, "prepare(): rate=%d\n", runtime
->rate
);
637 /* init struct for intermediate buffer */
638 memset(&ml403_ac97cr
->ind_rec
, 0,
639 sizeof(struct snd_pcm_indirect2
));
640 ml403_ac97cr
->ind_rec
.hw_buffer_size
= CR_FIFO_SIZE
;
641 ml403_ac97cr
->ind_rec
.sw_buffer_size
=
642 snd_pcm_lib_buffer_bytes(substream
);
643 ml403_ac97cr
->ind_rec
.min_periods
= -1;
644 ml403_ac97cr
->ind_rec
.min_multiple
=
645 snd_pcm_lib_period_bytes(substream
) / (CR_FIFO_SIZE
/ 2);
646 PDEBUG(WORK_INFO
, "prepare(): hw_buffer_size=%d, "
647 "sw_buffer_size=%d, min_multiple=%d\n",
648 CR_FIFO_SIZE
, ml403_ac97cr
->ind_rec
.sw_buffer_size
,
649 ml403_ac97cr
->ind_rec
.min_multiple
);
654 snd_ml403_ac97cr_pcm_capture_prepare(struct snd_pcm_substream
*substream
)
656 struct snd_ml403_ac97cr
*ml403_ac97cr
;
657 struct snd_pcm_runtime
*runtime
;
659 ml403_ac97cr
= snd_pcm_substream_chip(substream
);
660 runtime
= substream
->runtime
;
663 "prepare(capture): period_bytes=%d, minperiod_bytes=%d\n",
664 snd_pcm_lib_period_bytes(substream
), CR_FIFO_SIZE
/ 2);
666 /* set sampling rate */
667 snd_ac97_set_rate(ml403_ac97cr
->ac97
, AC97_PCM_LR_ADC_RATE
,
669 PDEBUG(WORK_INFO
, "prepare(capture): rate=%d\n", runtime
->rate
);
671 /* init struct for intermediate buffer */
672 memset(&ml403_ac97cr
->capture_ind2_rec
, 0,
673 sizeof(struct snd_pcm_indirect2
));
674 ml403_ac97cr
->capture_ind2_rec
.hw_buffer_size
= CR_FIFO_SIZE
;
675 ml403_ac97cr
->capture_ind2_rec
.sw_buffer_size
=
676 snd_pcm_lib_buffer_bytes(substream
);
677 ml403_ac97cr
->capture_ind2_rec
.min_multiple
=
678 snd_pcm_lib_period_bytes(substream
) / (CR_FIFO_SIZE
/ 2);
679 PDEBUG(WORK_INFO
, "prepare(capture): hw_buffer_size=%d, "
680 "sw_buffer_size=%d, min_multiple=%d\n", CR_FIFO_SIZE
,
681 ml403_ac97cr
->capture_ind2_rec
.sw_buffer_size
,
682 ml403_ac97cr
->capture_ind2_rec
.min_multiple
);
686 static int snd_ml403_ac97cr_hw_free(struct snd_pcm_substream
*substream
)
688 PDEBUG(WORK_INFO
, "hw_free()\n");
689 return snd_pcm_lib_free_pages(substream
);
693 snd_ml403_ac97cr_hw_params(struct snd_pcm_substream
*substream
,
694 struct snd_pcm_hw_params
*hw_params
)
696 PDEBUG(WORK_INFO
, "hw_params(): desired buffer bytes=%d, desired "
698 params_buffer_bytes(hw_params
), params_period_bytes(hw_params
));
699 return snd_pcm_lib_malloc_pages(substream
,
700 params_buffer_bytes(hw_params
));
703 static int snd_ml403_ac97cr_playback_open(struct snd_pcm_substream
*substream
)
705 struct snd_ml403_ac97cr
*ml403_ac97cr
;
706 struct snd_pcm_runtime
*runtime
;
708 ml403_ac97cr
= snd_pcm_substream_chip(substream
);
709 runtime
= substream
->runtime
;
711 PDEBUG(WORK_INFO
, "open(playback)\n");
712 ml403_ac97cr
->playback_substream
= substream
;
713 runtime
->hw
= snd_ml403_ac97cr_playback
;
715 snd_pcm_hw_constraint_step(runtime
, 0,
716 SNDRV_PCM_HW_PARAM_PERIOD_BYTES
,
721 static int snd_ml403_ac97cr_capture_open(struct snd_pcm_substream
*substream
)
723 struct snd_ml403_ac97cr
*ml403_ac97cr
;
724 struct snd_pcm_runtime
*runtime
;
726 ml403_ac97cr
= snd_pcm_substream_chip(substream
);
727 runtime
= substream
->runtime
;
729 PDEBUG(WORK_INFO
, "open(capture)\n");
730 ml403_ac97cr
->capture_substream
= substream
;
731 runtime
->hw
= snd_ml403_ac97cr_capture
;
733 snd_pcm_hw_constraint_step(runtime
, 0,
734 SNDRV_PCM_HW_PARAM_PERIOD_BYTES
,
739 static int snd_ml403_ac97cr_playback_close(struct snd_pcm_substream
*substream
)
741 struct snd_ml403_ac97cr
*ml403_ac97cr
;
743 ml403_ac97cr
= snd_pcm_substream_chip(substream
);
745 PDEBUG(WORK_INFO
, "close(playback)\n");
746 ml403_ac97cr
->playback_substream
= NULL
;
750 static int snd_ml403_ac97cr_capture_close(struct snd_pcm_substream
*substream
)
752 struct snd_ml403_ac97cr
*ml403_ac97cr
;
754 ml403_ac97cr
= snd_pcm_substream_chip(substream
);
756 PDEBUG(WORK_INFO
, "close(capture)\n");
757 ml403_ac97cr
->capture_substream
= NULL
;
761 static struct snd_pcm_ops snd_ml403_ac97cr_playback_ops
= {
762 .open
= snd_ml403_ac97cr_playback_open
,
763 .close
= snd_ml403_ac97cr_playback_close
,
764 .ioctl
= snd_pcm_lib_ioctl
,
765 .hw_params
= snd_ml403_ac97cr_hw_params
,
766 .hw_free
= snd_ml403_ac97cr_hw_free
,
767 .prepare
= snd_ml403_ac97cr_pcm_playback_prepare
,
768 .trigger
= snd_ml403_ac97cr_pcm_playback_trigger
,
769 .pointer
= snd_ml403_ac97cr_pcm_pointer
,
772 static struct snd_pcm_ops snd_ml403_ac97cr_capture_ops
= {
773 .open
= snd_ml403_ac97cr_capture_open
,
774 .close
= snd_ml403_ac97cr_capture_close
,
775 .ioctl
= snd_pcm_lib_ioctl
,
776 .hw_params
= snd_ml403_ac97cr_hw_params
,
777 .hw_free
= snd_ml403_ac97cr_hw_free
,
778 .prepare
= snd_ml403_ac97cr_pcm_capture_prepare
,
779 .trigger
= snd_ml403_ac97cr_pcm_capture_trigger
,
780 .pointer
= snd_ml403_ac97cr_pcm_pointer
,
783 static irqreturn_t
snd_ml403_ac97cr_irq(int irq
, void *dev_id
)
785 struct snd_ml403_ac97cr
*ml403_ac97cr
;
786 struct platform_device
*pfdev
;
789 ml403_ac97cr
= (struct snd_ml403_ac97cr
*)dev_id
;
790 if (ml403_ac97cr
== NULL
)
793 pfdev
= ml403_ac97cr
->pfdev
;
795 /* playback interrupt */
796 cmp_irq
= platform_get_irq(pfdev
, 0);
797 if (irq
== cmp_irq
) {
798 if (ml403_ac97cr
->enable_irq
)
799 snd_pcm_indirect2_playback_interrupt(
800 ml403_ac97cr
->playback_substream
,
801 &ml403_ac97cr
->ind_rec
,
802 snd_ml403_ac97cr_playback_ind2_copy
,
803 snd_ml403_ac97cr_playback_ind2_zero
);
807 /* record interrupt */
808 cmp_irq
= platform_get_irq(pfdev
, 1);
809 if (irq
== cmp_irq
) {
810 if (ml403_ac97cr
->enable_capture_irq
)
811 snd_pcm_indirect2_capture_interrupt(
812 ml403_ac97cr
->capture_substream
,
813 &ml403_ac97cr
->capture_ind2_rec
,
814 snd_ml403_ac97cr_capture_ind2_copy
,
815 snd_ml403_ac97cr_capture_ind2_null
);
824 PDEBUG(INIT_INFO
, "irq(): irq %d is meant to be disabled! So, now try "
825 "to disable it _really_!\n", irq
);
826 disable_irq_nosync(irq
);
830 static unsigned short
831 snd_ml403_ac97cr_codec_read(struct snd_ac97
*ac97
, unsigned short reg
)
833 struct snd_ml403_ac97cr
*ml403_ac97cr
= ac97
->private_data
;
838 unsigned long end_time
;
841 if (!LM4550_RF_OK(reg
)) {
842 snd_printk(KERN_WARNING SND_ML403_AC97CR_DRIVER
": "
843 "access to unknown/unused codec register 0x%x "
847 /* check if we can fake/answer this access from our shadow register */
848 if ((lm4550_regfile
[reg
/ 2].flag
&
849 (LM4550_REG_DONEREAD
| LM4550_REG_ALLFAKE
)) &&
850 !(lm4550_regfile
[reg
/ 2].flag
& LM4550_REG_NOSHADOW
)) {
851 if (lm4550_regfile
[reg
/ 2].flag
& LM4550_REG_FAKEREAD
) {
852 PDEBUG(CODEC_FAKE
, "codec_read(): faking read from "
853 "reg=0x%x, val=0x%x / %d\n",
854 reg
, lm4550_regfile
[reg
/ 2].def
,
855 lm4550_regfile
[reg
/ 2].def
);
856 return lm4550_regfile
[reg
/ 2].def
;
857 } else if ((lm4550_regfile
[reg
/ 2].flag
&
858 LM4550_REG_FAKEPROBE
) &&
859 ml403_ac97cr
->ac97_fake
) {
860 PDEBUG(CODEC_FAKE
, "codec_read(): faking read from "
861 "reg=0x%x, val=0x%x / %d (probe)\n",
862 reg
, lm4550_regfile
[reg
/ 2].value
,
863 lm4550_regfile
[reg
/ 2].value
);
864 return lm4550_regfile
[reg
/ 2].value
;
867 PDEBUG(CODEC_FAKE
, "codec_read(): read access "
868 "answered by shadow register 0x%x (value=0x%x "
869 "/ %d) (cw=%d cr=%d)\n",
870 reg
, lm4550_regfile
[reg
/ 2].value
,
871 lm4550_regfile
[reg
/ 2].value
,
872 ml403_ac97cr
->ac97_write
,
873 ml403_ac97cr
->ac97_read
);
875 PDEBUG(CODEC_FAKE
, "codec_read(): read access "
876 "answered by shadow register 0x%x (value=0x%x "
878 reg
, lm4550_regfile
[reg
/ 2].value
,
879 lm4550_regfile
[reg
/ 2].value
);
881 return lm4550_regfile
[reg
/ 2].value
;
884 /* if we are here, we _have_ to access the codec really, no faking */
885 if (mutex_lock_interruptible(&ml403_ac97cr
->cdc_mutex
) != 0)
888 ml403_ac97cr
->ac97_read
++;
890 spin_lock(&ml403_ac97cr
->reg_lock
);
891 out_be32(CR_REG(ml403_ac97cr
, CODEC_ADDR
),
892 CR_CODEC_ADDR(reg
) | CR_CODEC_READ
);
893 spin_unlock(&ml403_ac97cr
->reg_lock
);
894 end_time
= jiffies
+ (HZ
/ CODEC_TIMEOUT_AFTER_READ
);
896 spin_lock(&ml403_ac97cr
->reg_lock
);
899 stat
= in_be32(CR_REG(ml403_ac97cr
, STATUS
));
900 if ((stat
& CR_RAF
) == CR_RAF
) {
901 value
= CR_CODEC_DATAREAD(
902 in_be32(CR_REG(ml403_ac97cr
, CODEC_DATAREAD
)));
903 PDEBUG(CODEC_SUCCESS
, "codec_read(): (done) reg=0x%x, "
904 "value=0x%x / %d (STATUS=0x%x)\n",
905 reg
, value
, value
, stat
);
907 if ((in_be32(CR_REG(ml403_ac97cr
, STATUS
)) &
909 value
= CR_CODEC_DATAREAD(
910 in_be32(CR_REG(ml403_ac97cr
, CODEC_DATAREAD
)));
911 PDEBUG(CODEC_SUCCESS
, "codec_read(): (done) "
912 "reg=0x%x, value=0x%x / %d\n",
915 lm4550_regfile
[reg
/ 2].value
= value
;
916 lm4550_regfile
[reg
/ 2].flag
|= LM4550_REG_DONEREAD
;
917 spin_unlock(&ml403_ac97cr
->reg_lock
);
918 mutex_unlock(&ml403_ac97cr
->cdc_mutex
);
921 spin_unlock(&ml403_ac97cr
->reg_lock
);
922 schedule_timeout_uninterruptible(1);
923 } while (time_after(end_time
, jiffies
));
924 /* read the DATAREAD register anyway, see comment below */
925 spin_lock(&ml403_ac97cr
->reg_lock
);
927 CR_CODEC_DATAREAD(in_be32(CR_REG(ml403_ac97cr
, CODEC_DATAREAD
)));
928 spin_unlock(&ml403_ac97cr
->reg_lock
);
930 snd_printk(KERN_WARNING SND_ML403_AC97CR_DRIVER
": "
931 "timeout while codec read! "
932 "(reg=0x%x, last STATUS=0x%x, DATAREAD=0x%x / %d, %d) "
934 reg
, stat
, value
, value
, rafaccess
,
935 ml403_ac97cr
->ac97_write
, ml403_ac97cr
->ac97_read
);
937 snd_printk(KERN_WARNING SND_ML403_AC97CR_DRIVER
": "
938 "timeout while codec read! "
939 "(reg=0x%x, DATAREAD=0x%x / %d)\n",
942 /* BUG: This is PURE speculation! But after _most_ read timeouts the
943 * value in the register is ok!
945 lm4550_regfile
[reg
/ 2].value
= value
;
946 lm4550_regfile
[reg
/ 2].flag
|= LM4550_REG_DONEREAD
;
947 mutex_unlock(&ml403_ac97cr
->cdc_mutex
);
952 snd_ml403_ac97cr_codec_write(struct snd_ac97
*ac97
, unsigned short reg
,
955 struct snd_ml403_ac97cr
*ml403_ac97cr
= ac97
->private_data
;
961 #ifdef CODEC_WRITE_CHECK_RAF
962 unsigned long end_time
;
965 if (!LM4550_RF_OK(reg
)) {
966 snd_printk(KERN_WARNING SND_ML403_AC97CR_DRIVER
": "
967 "access to unknown/unused codec register 0x%x "
971 if (lm4550_regfile
[reg
/ 2].flag
& LM4550_REG_READONLY
) {
972 snd_printk(KERN_WARNING SND_ML403_AC97CR_DRIVER
": "
973 "write access to read only codec register 0x%x "
977 if ((val
& lm4550_regfile
[reg
/ 2].wmask
) != val
) {
978 snd_printk(KERN_WARNING SND_ML403_AC97CR_DRIVER
": "
979 "write access to codec register 0x%x "
980 "with bad value 0x%x / %d!\n",
982 val
= val
& lm4550_regfile
[reg
/ 2].wmask
;
984 if (((lm4550_regfile
[reg
/ 2].flag
& LM4550_REG_FAKEPROBE
) &&
985 ml403_ac97cr
->ac97_fake
) &&
986 !(lm4550_regfile
[reg
/ 2].flag
& LM4550_REG_NOSHADOW
)) {
987 PDEBUG(CODEC_FAKE
, "codec_write(): faking write to reg=0x%x, "
988 "val=0x%x / %d\n", reg
, val
, val
);
989 lm4550_regfile
[reg
/ 2].value
= (val
&
990 lm4550_regfile
[reg
/ 2].wmask
);
993 if (mutex_lock_interruptible(&ml403_ac97cr
->cdc_mutex
) != 0)
996 ml403_ac97cr
->ac97_write
++;
998 spin_lock(&ml403_ac97cr
->reg_lock
);
999 out_be32(CR_REG(ml403_ac97cr
, CODEC_DATAWRITE
),
1000 CR_CODEC_DATAWRITE(val
));
1001 out_be32(CR_REG(ml403_ac97cr
, CODEC_ADDR
),
1002 CR_CODEC_ADDR(reg
) | CR_CODEC_WRITE
);
1003 spin_unlock(&ml403_ac97cr
->reg_lock
);
1004 #ifdef CODEC_WRITE_CHECK_RAF
1005 /* check CR_CODEC_RAF bit to see if write access to register is done;
1006 * loop until bit is set or timeout happens
1008 end_time
= jiffies
+ HZ
/ CODEC_TIMEOUT_AFTER_WRITE
;
1010 spin_lock(&ml403_ac97cr
->reg_lock
);
1013 stat
= in_be32(CR_REG(ml403_ac97cr
, STATUS
))
1014 if ((stat
& CR_RAF
) == CR_RAF
) {
1016 if ((in_be32(CR_REG(ml403_ac97cr
, STATUS
)) &
1017 CR_RAF
) == CR_RAF
) {
1019 PDEBUG(CODEC_SUCCESS
, "codec_write(): (done) "
1020 "reg=0x%x, value=%d / 0x%x\n",
1022 if (!(lm4550_regfile
[reg
/ 2].flag
&
1023 LM4550_REG_NOSHADOW
) &&
1024 !(lm4550_regfile
[reg
/ 2].flag
&
1026 lm4550_regfile
[reg
/ 2].value
= val
;
1027 lm4550_regfile
[reg
/ 2].flag
|= LM4550_REG_DONEREAD
;
1028 spin_unlock(&ml403_ac97cr
->reg_lock
);
1029 mutex_unlock(&ml403_ac97cr
->cdc_mutex
);
1032 spin_unlock(&ml403_ac97cr
->reg_lock
);
1033 schedule_timeout_uninterruptible(1);
1034 } while (time_after(end_time
, jiffies
));
1036 snd_printk(KERN_WARNING SND_ML403_AC97CR_DRIVER
": "
1037 "timeout while codec write "
1038 "(reg=0x%x, val=0x%x / %d, last STATUS=0x%x, %d) "
1040 reg
, val
, val
, stat
, rafaccess
, ml403_ac97cr
->ac97_write
,
1041 ml403_ac97cr
->ac97_read
);
1043 snd_printk(KERN_WARNING SND_ML403_AC97CR_DRIVER
": "
1044 "timeout while codec write (reg=0x%x, val=0x%x / %d)\n",
1047 #else /* CODEC_WRITE_CHECK_RAF */
1048 #if CODEC_WAIT_AFTER_WRITE > 0
1049 /* officially, in AC97 spec there is no possibility for a AC97
1050 * controller to determine, if write access is done or not - so: How
1051 * is Xilinx able to provide a RAF bit for write access?
1052 * => very strange, thus just don't check RAF bit (compare with
1053 * Xilinx's example app in EDK 8.1i) and wait
1055 schedule_timeout_uninterruptible(HZ
/ CODEC_WAIT_AFTER_WRITE
);
1057 PDEBUG(CODEC_SUCCESS
, "codec_write(): (done) "
1058 "reg=0x%x, value=%d / 0x%x (no RAF check)\n",
1061 mutex_unlock(&ml403_ac97cr
->cdc_mutex
);
1065 static int __devinit
1066 snd_ml403_ac97cr_chip_init(struct snd_ml403_ac97cr
*ml403_ac97cr
)
1068 unsigned long end_time
;
1069 PDEBUG(INIT_INFO
, "chip_init():\n");
1070 end_time
= jiffies
+ HZ
/ CODEC_TIMEOUT_ON_INIT
;
1072 if (in_be32(CR_REG(ml403_ac97cr
, STATUS
)) & CR_CODECREADY
) {
1073 /* clear both hardware FIFOs */
1074 out_be32(CR_REG(ml403_ac97cr
, RESETFIFO
),
1075 CR_RECRESET
| CR_PLAYRESET
);
1076 PDEBUG(INIT_INFO
, "chip_init(): (done)\n");
1079 schedule_timeout_uninterruptible(1);
1080 } while (time_after(end_time
, jiffies
));
1081 snd_printk(KERN_ERR SND_ML403_AC97CR_DRIVER
": "
1082 "timeout while waiting for codec, "
1087 static int snd_ml403_ac97cr_free(struct snd_ml403_ac97cr
*ml403_ac97cr
)
1089 PDEBUG(INIT_INFO
, "free():\n");
1091 if (ml403_ac97cr
->irq
>= 0)
1092 free_irq(ml403_ac97cr
->irq
, ml403_ac97cr
);
1093 if (ml403_ac97cr
->capture_irq
>= 0)
1094 free_irq(ml403_ac97cr
->capture_irq
, ml403_ac97cr
);
1095 /* give back "port" */
1096 if (ml403_ac97cr
->port
!= NULL
)
1097 iounmap(ml403_ac97cr
->port
);
1098 kfree(ml403_ac97cr
);
1099 PDEBUG(INIT_INFO
, "free(): (done)\n");
1103 static int snd_ml403_ac97cr_dev_free(struct snd_device
*snddev
)
1105 struct snd_ml403_ac97cr
*ml403_ac97cr
= snddev
->device_data
;
1106 PDEBUG(INIT_INFO
, "dev_free():\n");
1107 return snd_ml403_ac97cr_free(ml403_ac97cr
);
1110 static int __devinit
1111 snd_ml403_ac97cr_create(struct snd_card
*card
, struct platform_device
*pfdev
,
1112 struct snd_ml403_ac97cr
**rml403_ac97cr
)
1114 struct snd_ml403_ac97cr
*ml403_ac97cr
;
1116 static struct snd_device_ops ops
= {
1117 .dev_free
= snd_ml403_ac97cr_dev_free
,
1119 struct resource
*resource
;
1122 *rml403_ac97cr
= NULL
;
1123 ml403_ac97cr
= kzalloc(sizeof(*ml403_ac97cr
), GFP_KERNEL
);
1124 if (ml403_ac97cr
== NULL
)
1126 spin_lock_init(&ml403_ac97cr
->reg_lock
);
1127 mutex_init(&ml403_ac97cr
->cdc_mutex
);
1128 ml403_ac97cr
->card
= card
;
1129 ml403_ac97cr
->pfdev
= pfdev
;
1130 ml403_ac97cr
->irq
= -1;
1131 ml403_ac97cr
->enable_irq
= 0;
1132 ml403_ac97cr
->capture_irq
= -1;
1133 ml403_ac97cr
->enable_capture_irq
= 0;
1134 ml403_ac97cr
->port
= NULL
;
1135 ml403_ac97cr
->res_port
= NULL
;
1137 PDEBUG(INIT_INFO
, "Trying to reserve resources now ...\n");
1138 resource
= platform_get_resource(pfdev
, IORESOURCE_MEM
, 0);
1140 ml403_ac97cr
->port
= ioremap_nocache(resource
->start
,
1142 (resource
->start
) + 1);
1143 if (ml403_ac97cr
->port
== NULL
) {
1144 snd_printk(KERN_ERR SND_ML403_AC97CR_DRIVER
": "
1145 "unable to remap memory region (%x to %x)\n",
1146 resource
->start
, resource
->end
);
1147 snd_ml403_ac97cr_free(ml403_ac97cr
);
1150 snd_printk(KERN_INFO SND_ML403_AC97CR_DRIVER
": "
1151 "remap controller memory region to "
1152 "0x%x done\n", (unsigned int)ml403_ac97cr
->port
);
1154 irq
= platform_get_irq(pfdev
, 0);
1155 if (request_irq(irq
, snd_ml403_ac97cr_irq
, IRQF_DISABLED
,
1156 dev_name(&pfdev
->dev
), (void *)ml403_ac97cr
)) {
1157 snd_printk(KERN_ERR SND_ML403_AC97CR_DRIVER
": "
1158 "unable to grab IRQ %d\n",
1160 snd_ml403_ac97cr_free(ml403_ac97cr
);
1163 ml403_ac97cr
->irq
= irq
;
1164 snd_printk(KERN_INFO SND_ML403_AC97CR_DRIVER
": "
1165 "request (playback) irq %d done\n",
1167 irq
= platform_get_irq(pfdev
, 1);
1168 if (request_irq(irq
, snd_ml403_ac97cr_irq
, IRQF_DISABLED
,
1169 dev_name(&pfdev
->dev
), (void *)ml403_ac97cr
)) {
1170 snd_printk(KERN_ERR SND_ML403_AC97CR_DRIVER
": "
1171 "unable to grab IRQ %d\n",
1173 snd_ml403_ac97cr_free(ml403_ac97cr
);
1176 ml403_ac97cr
->capture_irq
= irq
;
1177 snd_printk(KERN_INFO SND_ML403_AC97CR_DRIVER
": "
1178 "request (capture) irq %d done\n",
1179 ml403_ac97cr
->capture_irq
);
1181 err
= snd_ml403_ac97cr_chip_init(ml403_ac97cr
);
1183 snd_ml403_ac97cr_free(ml403_ac97cr
);
1187 err
= snd_device_new(card
, SNDRV_DEV_LOWLEVEL
, ml403_ac97cr
, &ops
);
1189 PDEBUG(INIT_FAILURE
, "probe(): snd_device_new() failed!\n");
1190 snd_ml403_ac97cr_free(ml403_ac97cr
);
1194 *rml403_ac97cr
= ml403_ac97cr
;
1198 static void snd_ml403_ac97cr_mixer_free(struct snd_ac97
*ac97
)
1200 struct snd_ml403_ac97cr
*ml403_ac97cr
= ac97
->private_data
;
1201 PDEBUG(INIT_INFO
, "mixer_free():\n");
1202 ml403_ac97cr
->ac97
= NULL
;
1203 PDEBUG(INIT_INFO
, "mixer_free(): (done)\n");
1206 static int __devinit
1207 snd_ml403_ac97cr_mixer(struct snd_ml403_ac97cr
*ml403_ac97cr
)
1209 struct snd_ac97_bus
*bus
;
1210 struct snd_ac97_template ac97
;
1212 static struct snd_ac97_bus_ops ops
= {
1213 .write
= snd_ml403_ac97cr_codec_write
,
1214 .read
= snd_ml403_ac97cr_codec_read
,
1216 PDEBUG(INIT_INFO
, "mixer():\n");
1217 err
= snd_ac97_bus(ml403_ac97cr
->card
, 0, &ops
, NULL
, &bus
);
1221 memset(&ac97
, 0, sizeof(ac97
));
1222 ml403_ac97cr
->ac97_fake
= 1;
1223 lm4550_regfile_init();
1225 ml403_ac97cr
->ac97_read
= 0;
1226 ml403_ac97cr
->ac97_write
= 0;
1228 ac97
.private_data
= ml403_ac97cr
;
1229 ac97
.private_free
= snd_ml403_ac97cr_mixer_free
;
1230 ac97
.scaps
= AC97_SCAP_AUDIO
| AC97_SCAP_SKIP_MODEM
|
1232 err
= snd_ac97_mixer(bus
, &ac97
, &ml403_ac97cr
->ac97
);
1233 ml403_ac97cr
->ac97_fake
= 0;
1234 lm4550_regfile_write_values_after_init(ml403_ac97cr
->ac97
);
1235 PDEBUG(INIT_INFO
, "mixer(): (done) snd_ac97_mixer()=%d\n", err
);
1239 static int __devinit
1240 snd_ml403_ac97cr_pcm(struct snd_ml403_ac97cr
*ml403_ac97cr
, int device
,
1241 struct snd_pcm
**rpcm
)
1243 struct snd_pcm
*pcm
;
1248 err
= snd_pcm_new(ml403_ac97cr
->card
, "ML403AC97CR/1", device
, 1, 1,
1252 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_PLAYBACK
,
1253 &snd_ml403_ac97cr_playback_ops
);
1254 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_CAPTURE
,
1255 &snd_ml403_ac97cr_capture_ops
);
1256 pcm
->private_data
= ml403_ac97cr
;
1257 pcm
->info_flags
= 0;
1258 strcpy(pcm
->name
, "ML403AC97CR DAC/ADC");
1259 ml403_ac97cr
->pcm
= pcm
;
1261 snd_pcm_lib_preallocate_pages_for_all(pcm
, SNDRV_DMA_TYPE_CONTINUOUS
,
1262 snd_dma_continuous_data(GFP_KERNEL
),
1270 static int __devinit
snd_ml403_ac97cr_probe(struct platform_device
*pfdev
)
1272 struct snd_card
*card
;
1273 struct snd_ml403_ac97cr
*ml403_ac97cr
= NULL
;
1275 int dev
= pfdev
->id
;
1277 if (dev
>= SNDRV_CARDS
)
1282 card
= snd_card_new(index
[dev
], id
[dev
], THIS_MODULE
, 0);
1285 err
= snd_ml403_ac97cr_create(card
, pfdev
, &ml403_ac97cr
);
1287 PDEBUG(INIT_FAILURE
, "probe(): create failed!\n");
1288 snd_card_free(card
);
1291 PDEBUG(INIT_INFO
, "probe(): create done\n");
1292 card
->private_data
= ml403_ac97cr
;
1293 err
= snd_ml403_ac97cr_mixer(ml403_ac97cr
);
1295 snd_card_free(card
);
1298 PDEBUG(INIT_INFO
, "probe(): mixer done\n");
1299 err
= snd_ml403_ac97cr_pcm(ml403_ac97cr
, 0, NULL
);
1301 snd_card_free(card
);
1304 PDEBUG(INIT_INFO
, "probe(): PCM done\n");
1305 strcpy(card
->driver
, SND_ML403_AC97CR_DRIVER
);
1306 strcpy(card
->shortname
, "ML403 AC97 Controller Reference");
1307 sprintf(card
->longname
, "%s %s at 0x%lx, irq %i & %i, device %i",
1308 card
->shortname
, card
->driver
,
1309 (unsigned long)ml403_ac97cr
->port
, ml403_ac97cr
->irq
,
1310 ml403_ac97cr
->capture_irq
, dev
+ 1);
1312 snd_card_set_dev(card
, &pfdev
->dev
);
1314 err
= snd_card_register(card
);
1316 snd_card_free(card
);
1319 platform_set_drvdata(pfdev
, card
);
1320 PDEBUG(INIT_INFO
, "probe(): (done)\n");
1324 static int snd_ml403_ac97cr_remove(struct platform_device
*pfdev
)
1326 snd_card_free(platform_get_drvdata(pfdev
));
1327 platform_set_drvdata(pfdev
, NULL
);
1331 /* work with hotplug and coldplug */
1332 MODULE_ALIAS("platform:" SND_ML403_AC97CR_DRIVER
);
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
,
1339 .owner
= THIS_MODULE
,
1343 static int __init
alsa_card_ml403_ac97cr_init(void)
1345 return platform_driver_register(&snd_ml403_ac97cr_driver
);
1348 static void __exit
alsa_card_ml403_ac97cr_exit(void)
1350 platform_driver_unregister(&snd_ml403_ac97cr_driver
);
1353 module_init(alsa_card_ml403_ac97cr_init
)
1354 module_exit(alsa_card_ml403_ac97cr_exit
)