1 // SPDX-License-Identifier: GPL-2.0-or-later
6 Vortex core low level functions.
8 Author: Manuel Jander (mjander@users.sourceforge.cl)
9 These functions are mainly the result of translations made
10 from the original disassembly of the au88x0 binary drivers,
11 written by Aureal before they went down.
12 Many thanks to the Jeff Muizelaar, Kester Maddock, and whoever
13 contributed to the OpenVortex project.
14 The author of this file, put the few available pieces together
15 and translated the rest of the riddle (Mix, Src and connection stuff).
16 Some things are still to be discovered, and their meanings are unclear.
18 Some of these functions aren't intended to be really used, rather
19 to help to understand how does the AU88X0 chips work. Keep them in, because
20 they could be used somewhere in the future.
22 This code hasn't been tested or proof read thoroughly. If you wanna help,
23 take a look at the AU88X0 assembly and check if this matches.
24 Functions tested ok so far are (they show the desired effect
26 vortex_routes(); (1 bug fixed).
27 vortex_adb_addroute();
28 vortex_adb_addroutes();
29 vortex_connect_codecplay();
30 vortex_src_flushbuffers();
31 vortex_adbdma_setmode(); note: still some unknown arguments!
32 vortex_adbdma_startfifo();
33 vortex_adbdma_stopfifo();
34 vortex_fifo_setadbctrl(); note: still some unknown arguments!
35 vortex_mix_setinputvolumebyte();
36 vortex_mix_enableinput();
37 vortex_mixer_addWTD(); (fixed)
38 vortex_connection_adbdma_src_src();
39 vortex_connection_adbdma_src();
40 vortex_src_change_convratio();
41 vortex_src_addWTD(); (fixed)
45 01-03-2003 First revision.
46 01-21-2003 Some bug fixes.
47 17-02-2003 many bugfixes after a big versioning mess.
48 18-02-2003 JAAAAAHHHUUUUUU!!!! The mixer works !! I'm just so happy !
49 (2 hours later...) I cant believe it! Im really lucky today.
50 Now the SRC is working too! Yeah! XMMS works !
51 20-02-2003 First steps into the ALSA world.
52 28-02-2003 As my birthday present, i discovered how the DMA buffer pages really
53 work :-). It was all wrong.
54 12-03-2003 ALSA driver starts working (2 channels).
55 16-03-2003 More srcblock_setupchannel discoveries.
56 12-04-2003 AU8830 playback support. Recording in the works.
57 17-04-2003 vortex_route() and vortex_routes() bug fixes. AU8830 recording
58 works now, but chipn' dale effect is still there.
59 16-05-2003 SrcSetupChannel cleanup. Moved the Src setup stuff entirely
61 06-06-2003 Buffer shifter bugfix. Mixer volume fix.
62 07-12-2003 A3D routing finally fixed. Believed to be OK.
63 25-03-2004 Many thanks to Claudia, for such valuable bug reports.
68 #include "au88x0_a3d.h"
69 #include <linux/delay.h>
71 /* MIXER (CAsp4Mix.s and CAsp4Mixer.s) */
73 // FIXME: get rid of this.
74 static int mchannels
[NR_MIXIN
];
75 static int rampchs
[NR_MIXIN
];
77 static void vortex_mixer_en_sr(vortex_t
* vortex
, int channel
)
79 hwwrite(vortex
->mmio
, VORTEX_MIXER_SR
,
80 hwread(vortex
->mmio
, VORTEX_MIXER_SR
) | (0x1 << channel
));
82 static void vortex_mixer_dis_sr(vortex_t
* vortex
, int channel
)
84 hwwrite(vortex
->mmio
, VORTEX_MIXER_SR
,
85 hwread(vortex
->mmio
, VORTEX_MIXER_SR
) & ~(0x1 << channel
));
90 vortex_mix_muteinputgain(vortex_t
* vortex
, unsigned char mix
,
91 unsigned char channel
)
93 hwwrite(vortex
->mmio
, VORTEX_MIX_INVOL_A
+ ((mix
<< 5) + channel
),
95 hwwrite(vortex
->mmio
, VORTEX_MIX_INVOL_B
+ ((mix
<< 5) + channel
),
99 static int vortex_mix_getvolume(vortex_t
* vortex
, unsigned char mix
)
102 a
= hwread(vortex
->mmio
, VORTEX_MIX_VOL_A
+ (mix
<< 2)) & 0xff;
108 vortex_mix_getinputvolume(vortex_t
* vortex
, unsigned char mix
,
109 int channel
, int *vol
)
112 if (!(mchannels
[mix
] & (1 << channel
)))
114 a
= hwread(vortex
->mmio
,
115 VORTEX_MIX_INVOL_A
+ (((mix
<< 5) + channel
) << 2));
117 if (rampchs[mix] == 0)
118 a = FP2LinearFrac(a);
120 a = FP2LinearFracWT(a);
126 static unsigned int vortex_mix_boost6db(unsigned char vol
)
128 return (vol
+ 8); /* WOW! what a complex function! */
131 static void vortex_mix_rampvolume(vortex_t
* vortex
, int mix
)
135 // This function is intended for ramping down only (see vortex_disableinput()).
136 for (ch
= 0; ch
< 0x20; ch
++) {
137 if (((1 << ch
) & rampchs
[mix
]) == 0)
139 a
= hwread(vortex
->mmio
,
140 VORTEX_MIX_INVOL_B
+ (((mix
<< 5) + ch
) << 2));
143 hwwrite(vortex
->mmio
,
145 (((mix
<< 5) + ch
) << 2), a
);
146 hwwrite(vortex
->mmio
,
148 (((mix
<< 5) + ch
) << 2), a
);
150 vortex_mix_killinput(vortex
, mix
, ch
);
155 vortex_mix_getenablebit(vortex_t
* vortex
, unsigned char mix
, int mixin
)
162 addr
= ((mix
<< 3) + (addr
>> 2)) << 2;
163 temp
= hwread(vortex
->mmio
, VORTEX_MIX_ENIN
+ addr
);
164 return ((temp
>> (mixin
& 3)) & 1);
168 vortex_mix_setvolumebyte(vortex_t
* vortex
, unsigned char mix
,
172 hwwrite(vortex
->mmio
, VORTEX_MIX_VOL_A
+ (mix
<< 2), vol
);
173 if (1) { /*if (this_10) */
174 temp
= hwread(vortex
->mmio
, VORTEX_MIX_VOL_B
+ (mix
<< 2));
175 if ((temp
!= 0x80) || (vol
== 0x80))
178 hwwrite(vortex
->mmio
, VORTEX_MIX_VOL_B
+ (mix
<< 2), vol
);
182 vortex_mix_setinputvolumebyte(vortex_t
* vortex
, unsigned char mix
,
183 int mixin
, unsigned char vol
)
187 hwwrite(vortex
->mmio
,
188 VORTEX_MIX_INVOL_A
+ (((mix
<< 5) + mixin
) << 2), vol
);
189 if (1) { /* this_10, initialized to 1. */
192 VORTEX_MIX_INVOL_B
+ (((mix
<< 5) + mixin
) << 2));
193 if ((temp
!= 0x80) || (vol
== 0x80))
196 hwwrite(vortex
->mmio
,
197 VORTEX_MIX_INVOL_B
+ (((mix
<< 5) + mixin
) << 2), vol
);
201 vortex_mix_setenablebit(vortex_t
* vortex
, unsigned char mix
, int mixin
, int en
)
209 addr
= ((mix
<< 3) + (addr
>> 2)) << 2;
210 temp
= hwread(vortex
->mmio
, VORTEX_MIX_ENIN
+ addr
);
212 temp
|= (1 << (mixin
& 3));
214 temp
&= ~(1 << (mixin
& 3));
215 /* Mute input. Astatic void crackling? */
216 hwwrite(vortex
->mmio
,
217 VORTEX_MIX_INVOL_B
+ (((mix
<< 5) + mixin
) << 2), 0x80);
218 /* Looks like clear buffer. */
219 hwwrite(vortex
->mmio
, VORTEX_MIX_SMP
+ (mixin
<< 2), 0x0);
220 hwwrite(vortex
->mmio
, VORTEX_MIX_SMP
+ 4 + (mixin
<< 2), 0x0);
221 /* Write enable bit. */
222 hwwrite(vortex
->mmio
, VORTEX_MIX_ENIN
+ addr
, temp
);
226 vortex_mix_killinput(vortex_t
* vortex
, unsigned char mix
, int mixin
)
228 rampchs
[mix
] &= ~(1 << mixin
);
229 vortex_mix_setinputvolumebyte(vortex
, mix
, mixin
, 0x80);
230 mchannels
[mix
] &= ~(1 << mixin
);
231 vortex_mix_setenablebit(vortex
, mix
, mixin
, 0);
235 vortex_mix_enableinput(vortex_t
* vortex
, unsigned char mix
, int mixin
)
237 vortex_mix_killinput(vortex
, mix
, mixin
);
238 if ((mchannels
[mix
] & (1 << mixin
)) == 0) {
239 vortex_mix_setinputvolumebyte(vortex
, mix
, mixin
, 0x80); /*0x80 : mute */
240 mchannels
[mix
] |= (1 << mixin
);
242 vortex_mix_setenablebit(vortex
, mix
, mixin
, 1);
246 vortex_mix_disableinput(vortex_t
* vortex
, unsigned char mix
, int channel
,
250 rampchs
[mix
] |= (1 << channel
);
251 // Register callback.
252 //vortex_mix_startrampvolume(vortex);
253 vortex_mix_killinput(vortex
, mix
, channel
);
255 vortex_mix_killinput(vortex
, mix
, channel
);
259 vortex_mixer_addWTD(vortex_t
* vortex
, unsigned char mix
, unsigned char ch
)
261 int temp
, lifeboat
= 0, prev
;
263 temp
= hwread(vortex
->mmio
, VORTEX_MIXER_SR
);
264 if ((temp
& (1 << ch
)) == 0) {
265 hwwrite(vortex
->mmio
, VORTEX_MIXER_CHNBASE
+ (ch
<< 2), mix
);
266 vortex_mixer_en_sr(vortex
, ch
);
269 prev
= VORTEX_MIXER_CHNBASE
+ (ch
<< 2);
270 temp
= hwread(vortex
->mmio
, prev
);
271 while (temp
& 0x10) {
272 prev
= VORTEX_MIXER_RTBASE
+ ((temp
& 0xf) << 2);
273 temp
= hwread(vortex
->mmio
, prev
);
274 //printk(KERN_INFO "vortex: mixAddWTD: while addr=%x, val=%x\n", prev, temp);
275 if ((++lifeboat
) > 0xf) {
276 dev_err(vortex
->card
->dev
,
277 "vortex_mixer_addWTD: lifeboat overflow\n");
281 hwwrite(vortex
->mmio
, VORTEX_MIXER_RTBASE
+ ((temp
& 0xf) << 2), mix
);
282 hwwrite(vortex
->mmio
, prev
, (temp
& 0xf) | 0x10);
287 vortex_mixer_delWTD(vortex_t
* vortex
, unsigned char mix
, unsigned char ch
)
289 int esp14
= -1, esp18
, eax
, ebx
, edx
, ebp
, esi
= 0;
290 //int esp1f=edi(while)=src, esp10=ch;
292 eax
= hwread(vortex
->mmio
, VORTEX_MIXER_SR
);
293 if (((1 << ch
) & eax
) == 0) {
294 dev_err(vortex
->card
->dev
, "mix ALARM %x\n", eax
);
297 ebp
= VORTEX_MIXER_CHNBASE
+ (ch
<< 2);
298 esp18
= hwread(vortex
->mmio
, ebp
);
302 ebx
= VORTEX_MIXER_RTBASE
+ (mix
<< 2);
303 edx
= hwread(vortex
->mmio
, ebx
);
305 hwwrite(vortex
->mmio
, ebp
, edx
);
306 hwwrite(vortex
->mmio
, ebx
, 0);
311 VORTEX_MIXER_RTBASE
+ (ebx
<< 2));
312 //printk(KERN_INFO "vortex: mixdelWTD: 1 addr=%x, val=%x, src=%x\n", ebx, edx, src);
313 while ((edx
& 0xf) != mix
) {
315 dev_err(vortex
->card
->dev
,
316 "mixdelWTD: error lifeboat overflow\n");
324 VORTEX_MIXER_RTBASE
+ ebp
);
325 //printk(KERN_INFO "vortex: mixdelWTD: while addr=%x, val=%x\n", ebp, edx);
330 if (edx
& 0x10) { /* Delete entry in between others */
331 ebx
= VORTEX_MIXER_RTBASE
+ ((edx
& 0xf) << 2);
332 edx
= hwread(vortex
->mmio
, ebx
);
334 hwwrite(vortex
->mmio
,
335 VORTEX_MIXER_RTBASE
+ ebp
, edx
);
336 hwwrite(vortex
->mmio
, ebx
, 0);
337 //printk(KERN_INFO "vortex mixdelWTD between addr= 0x%x, val= 0x%x\n", ebp, edx);
338 } else { /* Delete last entry */
341 hwwrite(vortex
->mmio
,
342 VORTEX_MIXER_CHNBASE
+
343 (ch
<< 2), esp18
& 0xef);
345 ebx
= (0xffffffe0 & edx
) | (0xf & ebx
);
346 hwwrite(vortex
->mmio
,
347 VORTEX_MIXER_RTBASE
+
349 //printk(KERN_INFO "vortex mixdelWTD last addr= 0x%x, val= 0x%x\n", esp14, ebx);
351 hwwrite(vortex
->mmio
,
352 VORTEX_MIXER_RTBASE
+ ebp
, 0);
357 //printk(KERN_INFO "removed last mix\n");
359 vortex_mixer_dis_sr(vortex
, ch
);
360 hwwrite(vortex
->mmio
, ebp
, 0);
365 static void vortex_mixer_init(vortex_t
* vortex
)
370 // FIXME: get rid of this crap.
371 memset(mchannels
, 0, NR_MIXOUT
* sizeof(int));
372 memset(rampchs
, 0, NR_MIXOUT
* sizeof(int));
374 addr
= VORTEX_MIX_SMP
+ 0x17c;
375 for (x
= 0x5f; x
>= 0; x
--) {
376 hwwrite(vortex
->mmio
, addr
, 0);
379 addr
= VORTEX_MIX_ENIN
+ 0x1fc;
380 for (x
= 0x7f; x
>= 0; x
--) {
381 hwwrite(vortex
->mmio
, addr
, 0);
384 addr
= VORTEX_MIX_SMP
+ 0x17c;
385 for (x
= 0x5f; x
>= 0; x
--) {
386 hwwrite(vortex
->mmio
, addr
, 0);
389 addr
= VORTEX_MIX_INVOL_A
+ 0x7fc;
390 for (x
= 0x1ff; x
>= 0; x
--) {
391 hwwrite(vortex
->mmio
, addr
, 0x80);
394 addr
= VORTEX_MIX_VOL_A
+ 0x3c;
395 for (x
= 0xf; x
>= 0; x
--) {
396 hwwrite(vortex
->mmio
, addr
, 0x80);
399 addr
= VORTEX_MIX_INVOL_B
+ 0x7fc;
400 for (x
= 0x1ff; x
>= 0; x
--) {
401 hwwrite(vortex
->mmio
, addr
, 0x80);
404 addr
= VORTEX_MIX_VOL_B
+ 0x3c;
405 for (x
= 0xf; x
>= 0; x
--) {
406 hwwrite(vortex
->mmio
, addr
, 0x80);
409 addr
= VORTEX_MIXER_RTBASE
+ (MIXER_RTBASE_SIZE
- 1) * 4;
410 for (x
= (MIXER_RTBASE_SIZE
- 1); x
>= 0; x
--) {
411 hwwrite(vortex
->mmio
, addr
, 0x0);
414 hwwrite(vortex
->mmio
, VORTEX_MIXER_SR
, 0);
416 /* Set clipping ceiling (this may be all wrong). */
418 for (x = 0; x < 0x80; x++) {
419 hwwrite(vortex->mmio, VORTEX_MIXER_CLIP + (x << 2), 0x3ffff);
423 call CAsp4Mix__Initialize_CAsp4HwIO____CAsp4Mixer____
424 Register ISR callback for volume smooth fade out.
425 Maybe this avoids clicks when press "stop" ?
429 /* SRC (CAsp4Src.s and CAsp4SrcBlock) */
431 static void vortex_src_en_sr(vortex_t
* vortex
, int channel
)
433 hwwrite(vortex
->mmio
, VORTEX_SRCBLOCK_SR
,
434 hwread(vortex
->mmio
, VORTEX_SRCBLOCK_SR
) | (0x1 << channel
));
437 static void vortex_src_dis_sr(vortex_t
* vortex
, int channel
)
439 hwwrite(vortex
->mmio
, VORTEX_SRCBLOCK_SR
,
440 hwread(vortex
->mmio
, VORTEX_SRCBLOCK_SR
) & ~(0x1 << channel
));
443 static void vortex_src_flushbuffers(vortex_t
* vortex
, unsigned char src
)
447 for (i
= 0x1f; i
>= 0; i
--)
448 hwwrite(vortex
->mmio
,
449 VORTEX_SRC_DATA0
+ (src
<< 7) + (i
<< 2), 0);
450 hwwrite(vortex
->mmio
, VORTEX_SRC_DATA
+ (src
<< 3), 0);
451 hwwrite(vortex
->mmio
, VORTEX_SRC_DATA
+ (src
<< 3) + 4, 0);
454 static void vortex_src_cleardrift(vortex_t
* vortex
, unsigned char src
)
456 hwwrite(vortex
->mmio
, VORTEX_SRC_DRIFT0
+ (src
<< 2), 0);
457 hwwrite(vortex
->mmio
, VORTEX_SRC_DRIFT1
+ (src
<< 2), 0);
458 hwwrite(vortex
->mmio
, VORTEX_SRC_DRIFT2
+ (src
<< 2), 1);
462 vortex_src_set_throttlesource(vortex_t
* vortex
, unsigned char src
, int en
)
466 temp
= hwread(vortex
->mmio
, VORTEX_SRC_SOURCE
);
471 hwwrite(vortex
->mmio
, VORTEX_SRC_SOURCE
, temp
);
475 vortex_src_persist_convratio(vortex_t
* vortex
, unsigned char src
, int ratio
)
477 int temp
, lifeboat
= 0;
480 hwwrite(vortex
->mmio
, VORTEX_SRC_CONVRATIO
+ (src
<< 2), ratio
);
481 temp
= hwread(vortex
->mmio
, VORTEX_SRC_CONVRATIO
+ (src
<< 2));
482 if ((++lifeboat
) > 0x9) {
483 dev_err(vortex
->card
->dev
, "Src cvr fail\n");
487 while (temp
!= ratio
);
492 static void vortex_src_slowlock(vortex_t
* vortex
, unsigned char src
)
496 hwwrite(vortex
->mmio
, VORTEX_SRC_DRIFT2
+ (src
<< 2), 1);
497 hwwrite(vortex
->mmio
, VORTEX_SRC_DRIFT0
+ (src
<< 2), 0);
498 temp
= hwread(vortex
->mmio
, VORTEX_SRC_U0
+ (src
<< 2));
500 hwwrite(vortex
->mmio
, VORTEX_SRC_U0
+ (src
<< 2),
505 vortex_src_change_convratio(vortex_t
* vortex
, unsigned char src
, int ratio
)
509 if ((ratio
& 0x10000) && (ratio
!= 0x10000)) {
511 a
= (0x11 - ((ratio
>> 0xe) & 0x3)) - 1;
513 a
= (0x11 - ((ratio
>> 0xe) & 0x3)) - 2;
516 temp
= hwread(vortex
->mmio
, VORTEX_SRC_U0
+ (src
<< 2));
517 if (((temp
>> 4) & 0xf) != a
)
518 hwwrite(vortex
->mmio
, VORTEX_SRC_U0
+ (src
<< 2),
519 (temp
& 0xf) | ((a
& 0xf) << 4));
521 vortex_src_persist_convratio(vortex
, src
, ratio
);
525 vortex_src_checkratio(vortex_t
* vortex
, unsigned char src
,
526 unsigned int desired_ratio
)
528 int hw_ratio
, lifeboat
= 0;
530 hw_ratio
= hwread(vortex
->mmio
, VORTEX_SRC_CONVRATIO
+ (src
<< 2));
532 while (hw_ratio
!= desired_ratio
) {
533 hwwrite(vortex
->mmio
, VORTEX_SRC_CONVRATIO
+ (src
<< 2), desired_ratio
);
535 if ((lifeboat
++) > 15) {
536 pr_err( "Vortex: could not set src-%d from %d to %d\n",
537 src
, hw_ratio
, desired_ratio
);
547 Objective: Set samplerate for given SRC module.
549 card: pointer to vortex_t strcut.
550 src: Integer index of the SRC module.
551 cr: Current sample rate conversion factor.
552 b: unknown 16 bit value.
553 sweep: Enable Samplerate fade from cr toward tr flag.
554 dirplay: 1: playback, 0: recording.
556 tr: Target samplerate conversion.
557 thsource: Throttle source flag (no idea what that means).
559 static void vortex_src_setupchannel(vortex_t
* card
, unsigned char src
,
560 unsigned int cr
, unsigned int b
, int sweep
, int d
,
561 int dirplay
, int sl
, unsigned int tr
, int thsource
)
563 // noplayback: d=2,4,7,0xa,0xb when using first 2 src's.
564 // c: enables pitch sweep.
565 // looks like g is c related. Maybe g is a sweep parameter ?
567 // dirplay: 0 = recording, 1 = playback
570 int esi
, ebp
= 0, esp10
;
572 vortex_src_flushbuffers(card
, src
);
575 if ((tr
& 0x10000) && (tr
!= 0x10000)) {
579 if ((((short)tr
) < 0) && (tr
!= 0x8000)) {
588 if ((cr
& 0x10000) && (cr
!= 0x10000)) {
590 esi
= 0x11 - ((cr
>> 0xe) & 7);
600 vortex_src_cleardrift(card
, src
);
601 vortex_src_set_throttlesource(card
, src
, thsource
);
603 if ((dirplay
== 0) && (sweep
== 0)) {
616 hwwrite(card
->mmio
, VORTEX_SRC_U0
+ (src
<< 2),
617 (sl
<< 0x9) | (sweep
<< 0x8) | ((esi
& 0xf) << 4) | d
);
618 /* 0xc0 esi=0xc c=f=0 d=0 */
619 vortex_src_persist_convratio(card
, src
, cr
);
620 hwwrite(card
->mmio
, VORTEX_SRC_U1
+ (src
<< 2), b
& 0xffff);
622 hwwrite(card
->mmio
, VORTEX_SRC_U2
+ (src
<< 2),
623 (tr
<< 0x11) | (dirplay
<< 0x10) | (ebp
<< 0x8) | esp10
);
624 /* 0x30f00 e=g=1 esp10=0 ebp=f */
625 //printk(KERN_INFO "vortex: SRC %d, d=0x%x, esi=0x%x, esp10=0x%x, ebp=0x%x\n", src, d, esi, esp10, ebp);
628 static void vortex_srcblock_init(vortex_t
* vortex
)
632 hwwrite(vortex
->mmio
, VORTEX_SRC_SOURCESIZE
, 0x1ff);
634 for (x=0; x<0x10; x++) {
635 vortex_src_init(&vortex_src[x], x);
640 addr
= VORTEX_SRC_RTBASE
+ 0x3c;
641 for (x
= 0xf; x
>= 0; x
--) {
642 hwwrite(vortex
->mmio
, addr
, 0);
647 addr
= VORTEX_SRC_CHNBASE
+ 0x54;
648 for (x
= 0x15; x
>= 0; x
--) {
649 hwwrite(vortex
->mmio
, addr
, 0);
655 vortex_src_addWTD(vortex_t
* vortex
, unsigned char src
, unsigned char ch
)
657 int temp
, lifeboat
= 0, prev
;
660 temp
= hwread(vortex
->mmio
, VORTEX_SRCBLOCK_SR
);
661 if ((temp
& (1 << ch
)) == 0) {
662 hwwrite(vortex
->mmio
, VORTEX_SRC_CHNBASE
+ (ch
<< 2), src
);
663 vortex_src_en_sr(vortex
, ch
);
666 prev
= VORTEX_SRC_CHNBASE
+ (ch
<< 2); /*ebp */
667 temp
= hwread(vortex
->mmio
, prev
);
668 //while (temp & NR_SRC) {
669 while (temp
& 0x10) {
670 prev
= VORTEX_SRC_RTBASE
+ ((temp
& 0xf) << 2); /*esp12 */
671 //prev = VORTEX_SRC_RTBASE + ((temp & (NR_SRC-1)) << 2); /*esp12*/
672 temp
= hwread(vortex
->mmio
, prev
);
673 //printk(KERN_INFO "vortex: srcAddWTD: while addr=%x, val=%x\n", prev, temp);
674 if ((++lifeboat
) > 0xf) {
675 dev_err(vortex
->card
->dev
,
676 "vortex_src_addWTD: lifeboat overflow\n");
680 hwwrite(vortex
->mmio
, VORTEX_SRC_RTBASE
+ ((temp
& 0xf) << 2), src
);
681 //hwwrite(vortex->mmio, prev, (temp & (NR_SRC-1)) | NR_SRC);
682 hwwrite(vortex
->mmio
, prev
, (temp
& 0xf) | 0x10);
687 vortex_src_delWTD(vortex_t
* vortex
, unsigned char src
, unsigned char ch
)
689 int esp14
= -1, esp18
, eax
, ebx
, edx
, ebp
, esi
= 0;
690 //int esp1f=edi(while)=src, esp10=ch;
692 eax
= hwread(vortex
->mmio
, VORTEX_SRCBLOCK_SR
);
693 if (((1 << ch
) & eax
) == 0) {
694 dev_err(vortex
->card
->dev
, "src alarm\n");
697 ebp
= VORTEX_SRC_CHNBASE
+ (ch
<< 2);
698 esp18
= hwread(vortex
->mmio
, ebp
);
702 ebx
= VORTEX_SRC_RTBASE
+ (src
<< 2);
703 edx
= hwread(vortex
->mmio
, ebx
);
705 hwwrite(vortex
->mmio
, ebp
, edx
);
706 hwwrite(vortex
->mmio
, ebx
, 0);
711 VORTEX_SRC_RTBASE
+ (ebx
<< 2));
712 //printk(KERN_INFO "vortex: srcdelWTD: 1 addr=%x, val=%x, src=%x\n", ebx, edx, src);
713 while ((edx
& 0xf) != src
) {
715 dev_warn(vortex
->card
->dev
,
716 "srcdelWTD: error, lifeboat overflow\n");
724 VORTEX_SRC_RTBASE
+ ebp
);
725 //printk(KERN_INFO "vortex: srcdelWTD: while addr=%x, val=%x\n", ebp, edx);
730 if (edx
& 0x10) { /* Delete entry in between others */
731 ebx
= VORTEX_SRC_RTBASE
+ ((edx
& 0xf) << 2);
732 edx
= hwread(vortex
->mmio
, ebx
);
734 hwwrite(vortex
->mmio
,
735 VORTEX_SRC_RTBASE
+ ebp
, edx
);
736 hwwrite(vortex
->mmio
, ebx
, 0);
737 //printk(KERN_INFO "vortex srcdelWTD between addr= 0x%x, val= 0x%x\n", ebp, edx);
738 } else { /* Delete last entry */
741 hwwrite(vortex
->mmio
,
743 (ch
<< 2), esp18
& 0xef);
745 ebx
= (0xffffffe0 & edx
) | (0xf & ebx
);
746 hwwrite(vortex
->mmio
,
749 //printk(KERN_INFO"vortex srcdelWTD last addr= 0x%x, val= 0x%x\n", esp14, ebx);
751 hwwrite(vortex
->mmio
,
752 VORTEX_SRC_RTBASE
+ ebp
, 0);
758 vortex_src_dis_sr(vortex
, ch
);
759 hwwrite(vortex
->mmio
, ebp
, 0);
767 vortex_fifo_clearadbdata(vortex_t
* vortex
, int fifo
, int x
)
769 for (x
--; x
>= 0; x
--)
770 hwwrite(vortex
->mmio
,
771 VORTEX_FIFO_ADBDATA
+
772 (((fifo
<< FIFO_SIZE_BITS
) + x
) << 2), 0);
776 static void vortex_fifo_adbinitialize(vortex_t
* vortex
, int fifo
, int j
)
778 vortex_fifo_clearadbdata(vortex
, fifo
, FIFO_SIZE
);
780 hwwrite(vortex
->mmio
, VORTEX_FIFO_ADBCTRL
+ (fifo
<< 2),
781 (FIFO_U1
| ((j
& FIFO_MASK
) << 0xb)));
783 hwwrite(vortex
->mmio
, VORTEX_FIFO_ADBCTRL
+ (fifo
<< 2),
784 (FIFO_U1
| ((j
& FIFO_MASK
) << 0xc)));
788 static void vortex_fifo_setadbvalid(vortex_t
* vortex
, int fifo
, int en
)
790 hwwrite(vortex
->mmio
, VORTEX_FIFO_ADBCTRL
+ (fifo
<< 2),
791 (hwread(vortex
->mmio
, VORTEX_FIFO_ADBCTRL
+ (fifo
<< 2)) &
792 0xffffffef) | ((1 & en
) << 4) | FIFO_U1
);
796 vortex_fifo_setadbctrl(vortex_t
* vortex
, int fifo
, int stereo
, int priority
,
797 int empty
, int valid
, int f
)
799 int temp
, lifeboat
= 0;
800 //int this_8[NR_ADB] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; /* position */
802 /* f seems priority related.
803 * CAsp4AdbDma::SetPriority is the only place that calls SetAdbCtrl with f set to 1
804 * every where else it is set to 0. It seems, however, that CAsp4AdbDma::SetPriority
805 * is never called, thus the f related bits remain a mystery for now.
808 temp
= hwread(vortex
->mmio
, VORTEX_FIFO_ADBCTRL
+ (fifo
<< 2));
809 if (lifeboat
++ > 0xbb8) {
810 dev_err(vortex
->card
->dev
,
811 "vortex_fifo_setadbctrl fail\n");
815 while (temp
& FIFO_RDONLY
);
817 // AU8830 semes to take some special care about fifo content (data).
818 // But i'm just to lazy to translate that :)
820 if ((temp
& FIFO_VALID
) == 0) {
822 vortex_fifo_clearadbdata(vortex
, fifo
, FIFO_SIZE
); // this_4
824 temp
= (this_4
& 0x1f) << 0xb;
826 temp
= (this_4
& 0x3f) << 0xc;
828 temp
= (temp
& 0xfffffffd) | ((stereo
& 1) << 1);
829 temp
= (temp
& 0xfffffff3) | ((priority
& 3) << 2);
830 temp
= (temp
& 0xffffffef) | ((valid
& 1) << 4);
832 temp
= (temp
& 0xffffffdf) | ((empty
& 1) << 5);
834 temp
= (temp
& 0xfffbffff) | ((f
& 1) << 0x12);
837 temp
= (temp
& 0xf7ffffff) | ((f
& 1) << 0x1b);
838 temp
= (temp
& 0xefffffff) | ((f
& 1) << 0x1c);
841 temp
= (temp
& 0xfeffffff) | ((f
& 1) << 0x18);
842 temp
= (temp
& 0xfdffffff) | ((f
& 1) << 0x19);
846 if (temp
& FIFO_VALID
) {
848 temp
= ((f
& 1) << 0x12) | (temp
& 0xfffbffef);
852 ((f
& 1) << 0x1b) | (temp
& 0xe7ffffef) | FIFO_BITS
;
856 ((f
& 1) << 0x18) | (temp
& 0xfcffffef) | FIFO_BITS
;
859 /*if (this_8[fifo]) */
860 vortex_fifo_clearadbdata(vortex
, fifo
, FIFO_SIZE
);
862 hwwrite(vortex
->mmio
, VORTEX_FIFO_ADBCTRL
+ (fifo
<< 2), temp
);
863 hwread(vortex
->mmio
, VORTEX_FIFO_ADBCTRL
+ (fifo
<< 2));
867 static void vortex_fifo_clearwtdata(vortex_t
* vortex
, int fifo
, int x
)
871 for (x
--; x
>= 0; x
--)
872 hwwrite(vortex
->mmio
,
874 (((fifo
<< FIFO_SIZE_BITS
) + x
) << 2), 0);
877 static void vortex_fifo_wtinitialize(vortex_t
* vortex
, int fifo
, int j
)
879 vortex_fifo_clearwtdata(vortex
, fifo
, FIFO_SIZE
);
881 hwwrite(vortex
->mmio
, VORTEX_FIFO_WTCTRL
+ (fifo
<< 2),
882 (FIFO_U1
| ((j
& FIFO_MASK
) << 0xb)));
884 hwwrite(vortex
->mmio
, VORTEX_FIFO_WTCTRL
+ (fifo
<< 2),
885 (FIFO_U1
| ((j
& FIFO_MASK
) << 0xc)));
889 static void vortex_fifo_setwtvalid(vortex_t
* vortex
, int fifo
, int en
)
891 hwwrite(vortex
->mmio
, VORTEX_FIFO_WTCTRL
+ (fifo
<< 2),
892 (hwread(vortex
->mmio
, VORTEX_FIFO_WTCTRL
+ (fifo
<< 2)) &
893 0xffffffef) | ((en
& 1) << 4) | FIFO_U1
);
897 vortex_fifo_setwtctrl(vortex_t
* vortex
, int fifo
, int ctrl
, int priority
,
898 int empty
, int valid
, int f
)
900 int temp
= 0, lifeboat
= 0;
904 temp
= hwread(vortex
->mmio
, VORTEX_FIFO_WTCTRL
+ (fifo
<< 2));
905 if (lifeboat
++ > 0xbb8) {
906 dev_err(vortex
->card
->dev
,
907 "vortex_fifo_setwtctrl fail\n");
911 while (temp
& FIFO_RDONLY
);
914 if ((temp
& FIFO_VALID
) == 0) {
915 vortex_fifo_clearwtdata(vortex
, fifo
, FIFO_SIZE
); // this_4
917 temp
= (this_4
& 0x1f) << 0xb;
919 temp
= (this_4
& 0x3f) << 0xc;
921 temp
= (temp
& 0xfffffffd) | ((ctrl
& 1) << 1);
922 temp
= (temp
& 0xfffffff3) | ((priority
& 3) << 2);
923 temp
= (temp
& 0xffffffef) | ((valid
& 1) << 4);
925 temp
= (temp
& 0xffffffdf) | ((empty
& 1) << 5);
927 temp
= (temp
& 0xfffbffff) | ((f
& 1) << 0x12);
930 temp
= (temp
& 0xf7ffffff) | ((f
& 1) << 0x1b);
931 temp
= (temp
& 0xefffffff) | ((f
& 1) << 0x1c);
934 temp
= (temp
& 0xfeffffff) | ((f
& 1) << 0x18);
935 temp
= (temp
& 0xfdffffff) | ((f
& 1) << 0x19);
939 if (temp
& FIFO_VALID
) {
941 temp
= ((f
& 1) << 0x12) | (temp
& 0xfffbffef);
945 ((f
& 1) << 0x1b) | (temp
& 0xe7ffffef) | FIFO_BITS
;
949 ((f
& 1) << 0x18) | (temp
& 0xfcffffef) | FIFO_BITS
;
952 /*if (this_8[fifo]) */
953 vortex_fifo_clearwtdata(vortex
, fifo
, FIFO_SIZE
);
955 hwwrite(vortex
->mmio
, VORTEX_FIFO_WTCTRL
+ (fifo
<< 2), temp
);
956 hwread(vortex
->mmio
, VORTEX_FIFO_WTCTRL
+ (fifo
<< 2));
960 temp = hwread(vortex->mmio, VORTEX_FIFO_WTCTRL + (fifo << 2));
961 if (lifeboat++ > 0xbb8) {
962 pr_err( "Vortex: vortex_fifo_setwtctrl fail (hanging)\n");
965 } while ((temp & FIFO_RDONLY)&&(temp & FIFO_VALID)&&(temp != 0xFFFFFFFF));
969 if (temp & FIFO_VALID) {
971 //temp |= 0x08000000;
972 //temp |= 0x10000000;
973 //temp |= 0x04000000;
974 //temp |= 0x00400000;
978 temp |= (valid & 1) << 4;
979 hwwrite(vortex->mmio, VORTEX_FIFO_WTCTRL + (fifo << 2), temp);
982 vortex_fifo_clearwtdata(vortex, fifo, FIFO_SIZE);
991 hwwrite(vortex->mmio, VORTEX_FIFO_WTCTRL + (fifo << 2), temp);
992 temp = hwread(vortex->mmio, VORTEX_FIFO_WTCTRL + (fifo << 2));
993 //((temp >> 6) & 0x3f)
996 if (((temp & 0x0fc0) ^ ((temp >> 6) & 0x0fc0)) & 0FFFFFFC0)
997 vortex_fifo_clearwtdata(vortex, fifo, FIFO_SIZE);
999 temp = (temp & 0xfffffffd) | ((ctrl & 1) << 1);
1000 temp = (temp & 0xfffdffff) | ((f & 1) << 0x11);
1001 temp = (temp & 0xfffffff3) | ((priority & 3) << 2);
1002 temp = (temp & 0xffffffef) | ((valid & 1) << 4);
1003 temp = (temp & 0xffffffdf) | ((empty & 1) << 5);
1004 hwwrite(vortex->mmio, VORTEX_FIFO_WTCTRL + (fifo << 2), temp);
1010 temp = (temp & 0xfffffffd) | ((ctrl & 1) << 1);
1011 temp = (temp & 0xfffdffff) | ((f & 1) << 0x11);
1012 temp = (temp & 0xfffffff3) | ((priority & 3) << 2);
1013 temp = (temp & 0xffffffef) | ((valid & 1) << 4);
1014 temp = (temp & 0xffffffdf) | ((empty & 1) << 5);
1016 temp = temp | FIFO_BITS | 40000;
1018 // 0x1c440010, 0x1c400000
1019 hwwrite(vortex->mmio, VORTEX_FIFO_WTCTRL + (fifo << 2), temp);
1024 static void vortex_fifo_init(vortex_t
* vortex
)
1029 /* ADB DMA channels fifos. */
1030 addr
= VORTEX_FIFO_ADBCTRL
+ ((NR_ADB
- 1) * 4);
1031 for (x
= NR_ADB
- 1; x
>= 0; x
--) {
1032 hwwrite(vortex
->mmio
, addr
, (FIFO_U0
| FIFO_U1
));
1033 if (hwread(vortex
->mmio
, addr
) != (FIFO_U0
| FIFO_U1
))
1034 dev_err(vortex
->card
->dev
, "bad adb fifo reset!\n");
1035 vortex_fifo_clearadbdata(vortex
, x
, FIFO_SIZE
);
1040 /* WT DMA channels fifos. */
1041 addr
= VORTEX_FIFO_WTCTRL
+ ((NR_WT
- 1) * 4);
1042 for (x
= NR_WT
- 1; x
>= 0; x
--) {
1043 hwwrite(vortex
->mmio
, addr
, FIFO_U0
);
1044 if (hwread(vortex
->mmio
, addr
) != FIFO_U0
)
1045 dev_err(vortex
->card
->dev
,
1046 "bad wt fifo reset (0x%08x, 0x%08x)!\n",
1047 addr
, hwread(vortex
->mmio
, addr
));
1048 vortex_fifo_clearwtdata(vortex
, x
, FIFO_SIZE
);
1054 hwwrite(vortex
->mmio
, 0xf8c0, 0xd03); //0x0843 0xd6b
1057 hwwrite(vortex
->mmio
, 0x17000, 0x61); /* wt a */
1058 hwwrite(vortex
->mmio
, 0x17004, 0x61); /* wt b */
1060 hwwrite(vortex
->mmio
, 0x17008, 0x61); /* adb */
1066 static void vortex_adbdma_init(vortex_t
* vortex
)
1070 static void vortex_adbdma_setfirstbuffer(vortex_t
* vortex
, int adbdma
)
1072 stream_t
*dma
= &vortex
->dma_adb
[adbdma
];
1074 hwwrite(vortex
->mmio
, VORTEX_ADBDMA_CTRL
+ (adbdma
<< 2),
1078 static void vortex_adbdma_setstartbuffer(vortex_t
* vortex
, int adbdma
, int sb
)
1080 stream_t
*dma
= &vortex
->dma_adb
[adbdma
];
1081 //hwwrite(vortex->mmio, VORTEX_ADBDMA_START + (adbdma << 2), sb << (((NR_ADB-1)-((adbdma&0xf)*2))));
1082 hwwrite(vortex
->mmio
, VORTEX_ADBDMA_START
+ (adbdma
<< 2),
1083 sb
<< ((0xf - (adbdma
& 0xf)) * 2));
1084 dma
->period_real
= dma
->period_virt
= sb
;
1088 vortex_adbdma_setbuffers(vortex_t
* vortex
, int adbdma
,
1089 int psize
, int count
)
1091 stream_t
*dma
= &vortex
->dma_adb
[adbdma
];
1093 dma
->period_bytes
= psize
;
1094 dma
->nr_periods
= count
;
1099 /* Four or more pages */
1102 dma
->cfg1
|= 0x88000000 | 0x44000000 | 0x30000000 | (psize
- 1);
1103 hwwrite(vortex
->mmio
,
1104 VORTEX_ADBDMA_BUFBASE
+ (adbdma
<< 4) + 0xc,
1105 snd_pcm_sgbuf_get_addr(dma
->substream
, psize
* 3));
1109 dma
->cfg0
|= 0x12000000;
1110 dma
->cfg1
|= 0x80000000 | 0x40000000 | ((psize
- 1) << 0xc);
1111 hwwrite(vortex
->mmio
,
1112 VORTEX_ADBDMA_BUFBASE
+ (adbdma
<< 4) + 0x8,
1113 snd_pcm_sgbuf_get_addr(dma
->substream
, psize
* 2));
1117 dma
->cfg0
|= 0x88000000 | 0x44000000 | 0x10000000 | (psize
- 1);
1118 hwwrite(vortex
->mmio
,
1119 VORTEX_ADBDMA_BUFBASE
+ (adbdma
<< 4) + 0x4,
1120 snd_pcm_sgbuf_get_addr(dma
->substream
, psize
));
1124 dma
->cfg0
|= 0x80000000 | 0x40000000 | ((psize
- 1) << 0xc);
1125 hwwrite(vortex
->mmio
,
1126 VORTEX_ADBDMA_BUFBASE
+ (adbdma
<< 4),
1127 snd_pcm_sgbuf_get_addr(dma
->substream
, 0));
1131 pr_debug( "vortex: cfg0 = 0x%x\nvortex: cfg1=0x%x\n",
1132 dma->cfg0, dma->cfg1);
1134 hwwrite(vortex
->mmio
, VORTEX_ADBDMA_BUFCFG0
+ (adbdma
<< 3), dma
->cfg0
);
1135 hwwrite(vortex
->mmio
, VORTEX_ADBDMA_BUFCFG1
+ (adbdma
<< 3), dma
->cfg1
);
1137 vortex_adbdma_setfirstbuffer(vortex
, adbdma
);
1138 vortex_adbdma_setstartbuffer(vortex
, adbdma
, 0);
1142 vortex_adbdma_setmode(vortex_t
* vortex
, int adbdma
, int ie
, int dir
,
1143 int fmt
, int stereo
, u32 offset
)
1145 stream_t
*dma
= &vortex
->dma_adb
[adbdma
];
1147 dma
->dma_unknown
= stereo
;
1149 ((offset
& OFFSET_MASK
) | (dma
->dma_ctrl
& ~OFFSET_MASK
));
1150 /* Enable PCMOUT interrupts. */
1152 (dma
->dma_ctrl
& ~IE_MASK
) | ((ie
<< IE_SHIFT
) & IE_MASK
);
1155 (dma
->dma_ctrl
& ~DIR_MASK
) | ((dir
<< DIR_SHIFT
) & DIR_MASK
);
1157 (dma
->dma_ctrl
& ~FMT_MASK
) | ((fmt
<< FMT_SHIFT
) & FMT_MASK
);
1159 hwwrite(vortex
->mmio
, VORTEX_ADBDMA_CTRL
+ (adbdma
<< 2),
1161 hwread(vortex
->mmio
, VORTEX_ADBDMA_CTRL
+ (adbdma
<< 2));
1164 static int vortex_adbdma_bufshift(vortex_t
* vortex
, int adbdma
)
1166 stream_t
*dma
= &vortex
->dma_adb
[adbdma
];
1167 int page
, p
, pp
, delta
, i
;
1170 (hwread(vortex
->mmio
, VORTEX_ADBDMA_STAT
+ (adbdma
<< 2)) &
1171 ADB_SUBBUF_MASK
) >> ADB_SUBBUF_SHIFT
;
1172 if (dma
->nr_periods
>= 4)
1173 delta
= (page
- dma
->period_real
) & 3;
1175 delta
= (page
- dma
->period_real
);
1177 delta
+= dma
->nr_periods
;
1182 /* refresh hw page table */
1183 if (dma
->nr_periods
> 4) {
1184 for (i
= 0; i
< delta
; i
++) {
1185 /* p: audio buffer page index */
1186 p
= dma
->period_virt
+ i
+ 4;
1187 if (p
>= dma
->nr_periods
)
1188 p
-= dma
->nr_periods
;
1189 /* pp: hardware DMA page index. */
1190 pp
= dma
->period_real
+ i
;
1193 //hwwrite(vortex->mmio, VORTEX_ADBDMA_BUFBASE+(((adbdma << 2)+pp) << 2), dma->table[p].addr);
1194 hwwrite(vortex
->mmio
,
1195 VORTEX_ADBDMA_BUFBASE
+ (((adbdma
<< 2) + pp
) << 2),
1196 snd_pcm_sgbuf_get_addr(dma
->substream
,
1197 dma
->period_bytes
* p
));
1198 /* Force write thru cache. */
1199 hwread(vortex
->mmio
, VORTEX_ADBDMA_BUFBASE
+
1200 (((adbdma
<< 2) + pp
) << 2));
1203 dma
->period_virt
+= delta
;
1204 dma
->period_real
= page
;
1205 if (dma
->period_virt
>= dma
->nr_periods
)
1206 dma
->period_virt
-= dma
->nr_periods
;
1208 dev_info(vortex
->card
->dev
,
1209 "%d virt=%d, real=%d, delta=%d\n",
1210 adbdma
, dma
->period_virt
, dma
->period_real
, delta
);
1216 static void vortex_adbdma_resetup(vortex_t
*vortex
, int adbdma
) {
1217 stream_t
*dma
= &vortex
->dma_adb
[adbdma
];
1220 /* refresh hw page table */
1221 for (i
=0 ; i
< 4 && i
< dma
->nr_periods
; i
++) {
1222 /* p: audio buffer page index */
1223 p
= dma
->period_virt
+ i
;
1224 if (p
>= dma
->nr_periods
)
1225 p
-= dma
->nr_periods
;
1226 /* pp: hardware DMA page index. */
1227 pp
= dma
->period_real
+ i
;
1228 if (dma
->nr_periods
< 4) {
1229 if (pp
>= dma
->nr_periods
)
1230 pp
-= dma
->nr_periods
;
1236 hwwrite(vortex
->mmio
,
1237 VORTEX_ADBDMA_BUFBASE
+ (((adbdma
<< 2) + pp
) << 2),
1238 snd_pcm_sgbuf_get_addr(dma
->substream
,
1239 dma
->period_bytes
* p
));
1240 /* Force write thru cache. */
1241 hwread(vortex
->mmio
, VORTEX_ADBDMA_BUFBASE
+ (((adbdma
<< 2)+pp
) << 2));
1245 static inline int vortex_adbdma_getlinearpos(vortex_t
* vortex
, int adbdma
)
1247 stream_t
*dma
= &vortex
->dma_adb
[adbdma
];
1248 int temp
, page
, delta
;
1250 temp
= hwread(vortex
->mmio
, VORTEX_ADBDMA_STAT
+ (adbdma
<< 2));
1251 page
= (temp
& ADB_SUBBUF_MASK
) >> ADB_SUBBUF_SHIFT
;
1252 if (dma
->nr_periods
>= 4)
1253 delta
= (page
- dma
->period_real
) & 3;
1255 delta
= (page
- dma
->period_real
);
1257 delta
+= dma
->nr_periods
;
1259 return (dma
->period_virt
+ delta
) * dma
->period_bytes
1260 + (temp
& (dma
->period_bytes
- 1));
1263 static void vortex_adbdma_startfifo(vortex_t
* vortex
, int adbdma
)
1265 int this_8
= 0 /*empty */ , this_4
= 0 /*priority */ ;
1266 stream_t
*dma
= &vortex
->dma_adb
[adbdma
];
1268 switch (dma
->fifo_status
) {
1270 vortex_fifo_setadbvalid(vortex
, adbdma
,
1271 dma
->fifo_enabled
? 1 : 0);
1275 hwwrite(vortex
->mmio
, VORTEX_ADBDMA_CTRL
+ (adbdma
<< 2),
1277 vortex_fifo_setadbctrl(vortex
, adbdma
, dma
->dma_unknown
,
1279 dma
->fifo_enabled
? 1 : 0, 0);
1282 vortex_fifo_setadbctrl(vortex
, adbdma
, dma
->dma_unknown
,
1284 dma
->fifo_enabled
? 1 : 0, 0);
1287 dma
->fifo_status
= FIFO_START
;
1290 static void vortex_adbdma_resumefifo(vortex_t
* vortex
, int adbdma
)
1292 stream_t
*dma
= &vortex
->dma_adb
[adbdma
];
1294 int this_8
= 1, this_4
= 0;
1295 switch (dma
->fifo_status
) {
1297 hwwrite(vortex
->mmio
, VORTEX_ADBDMA_CTRL
+ (adbdma
<< 2),
1299 vortex_fifo_setadbctrl(vortex
, adbdma
, dma
->dma_unknown
,
1301 dma
->fifo_enabled
? 1 : 0, 0);
1304 vortex_fifo_setadbctrl(vortex
, adbdma
, dma
->dma_unknown
,
1306 dma
->fifo_enabled
? 1 : 0, 0);
1309 dma
->fifo_status
= FIFO_START
;
1312 static void vortex_adbdma_pausefifo(vortex_t
* vortex
, int adbdma
)
1314 stream_t
*dma
= &vortex
->dma_adb
[adbdma
];
1316 int this_8
= 0, this_4
= 0;
1317 switch (dma
->fifo_status
) {
1319 vortex_fifo_setadbctrl(vortex
, adbdma
, dma
->dma_unknown
,
1320 this_4
, this_8
, 0, 0);
1323 hwwrite(vortex
->mmio
, VORTEX_ADBDMA_CTRL
+ (adbdma
<< 2),
1325 vortex_fifo_setadbctrl(vortex
, adbdma
, dma
->dma_unknown
,
1326 this_4
, this_8
, 0, 0);
1329 dma
->fifo_status
= FIFO_PAUSE
;
1332 static void vortex_adbdma_stopfifo(vortex_t
* vortex
, int adbdma
)
1334 stream_t
*dma
= &vortex
->dma_adb
[adbdma
];
1336 int this_4
= 0, this_8
= 0;
1337 if (dma
->fifo_status
== FIFO_START
)
1338 vortex_fifo_setadbctrl(vortex
, adbdma
, dma
->dma_unknown
,
1339 this_4
, this_8
, 0, 0);
1340 else if (dma
->fifo_status
== FIFO_STOP
)
1342 dma
->fifo_status
= FIFO_STOP
;
1343 dma
->fifo_enabled
= 0;
1349 static void vortex_wtdma_setfirstbuffer(vortex_t
* vortex
, int wtdma
)
1351 //int this_7c=dma_ctrl;
1352 stream_t
*dma
= &vortex
->dma_wt
[wtdma
];
1354 hwwrite(vortex
->mmio
, VORTEX_WTDMA_CTRL
+ (wtdma
<< 2), dma
->dma_ctrl
);
1357 static void vortex_wtdma_setstartbuffer(vortex_t
* vortex
, int wtdma
, int sb
)
1359 stream_t
*dma
= &vortex
->dma_wt
[wtdma
];
1360 //hwwrite(vortex->mmio, VORTEX_WTDMA_START + (wtdma << 2), sb << ((0x1f-(wtdma&0xf)*2)));
1361 hwwrite(vortex
->mmio
, VORTEX_WTDMA_START
+ (wtdma
<< 2),
1362 sb
<< ((0xf - (wtdma
& 0xf)) * 2));
1363 dma
->period_real
= dma
->period_virt
= sb
;
1367 vortex_wtdma_setbuffers(vortex_t
* vortex
, int wtdma
,
1368 int psize
, int count
)
1370 stream_t
*dma
= &vortex
->dma_wt
[wtdma
];
1372 dma
->period_bytes
= psize
;
1373 dma
->nr_periods
= count
;
1378 /* Four or more pages */
1381 dma
->cfg1
|= 0x88000000 | 0x44000000 | 0x30000000 | (psize
-1);
1382 hwwrite(vortex
->mmio
, VORTEX_WTDMA_BUFBASE
+ (wtdma
<< 4) + 0xc,
1383 snd_pcm_sgbuf_get_addr(dma
->substream
, psize
* 3));
1387 dma
->cfg0
|= 0x12000000;
1388 dma
->cfg1
|= 0x80000000 | 0x40000000 | ((psize
-1) << 0xc);
1389 hwwrite(vortex
->mmio
, VORTEX_WTDMA_BUFBASE
+ (wtdma
<< 4) + 0x8,
1390 snd_pcm_sgbuf_get_addr(dma
->substream
, psize
* 2));
1394 dma
->cfg0
|= 0x88000000 | 0x44000000 | 0x10000000 | (psize
-1);
1395 hwwrite(vortex
->mmio
, VORTEX_WTDMA_BUFBASE
+ (wtdma
<< 4) + 0x4,
1396 snd_pcm_sgbuf_get_addr(dma
->substream
, psize
));
1400 dma
->cfg0
|= 0x80000000 | 0x40000000 | ((psize
-1) << 0xc);
1401 hwwrite(vortex
->mmio
, VORTEX_WTDMA_BUFBASE
+ (wtdma
<< 4),
1402 snd_pcm_sgbuf_get_addr(dma
->substream
, 0));
1405 hwwrite(vortex
->mmio
, VORTEX_WTDMA_BUFCFG0
+ (wtdma
<< 3), dma
->cfg0
);
1406 hwwrite(vortex
->mmio
, VORTEX_WTDMA_BUFCFG1
+ (wtdma
<< 3), dma
->cfg1
);
1408 vortex_wtdma_setfirstbuffer(vortex
, wtdma
);
1409 vortex_wtdma_setstartbuffer(vortex
, wtdma
, 0);
1413 vortex_wtdma_setmode(vortex_t
* vortex
, int wtdma
, int ie
, int fmt
, int d
,
1414 /*int e, */ u32 offset
)
1416 stream_t
*dma
= &vortex
->dma_wt
[wtdma
];
1419 dma
->dma_unknown
= d
;
1422 ((offset
& OFFSET_MASK
) | (dma
->dma_ctrl
& ~OFFSET_MASK
));
1423 /* PCMOUT interrupt */
1425 (dma
->dma_ctrl
& ~IE_MASK
) | ((ie
<< IE_SHIFT
) & IE_MASK
);
1426 /* Always playback. */
1427 dma
->dma_ctrl
|= (1 << DIR_SHIFT
);
1430 (dma
->dma_ctrl
& FMT_MASK
) | ((fmt
<< FMT_SHIFT
) & FMT_MASK
);
1431 /* Write into hardware */
1432 hwwrite(vortex
->mmio
, VORTEX_WTDMA_CTRL
+ (wtdma
<< 2), dma
->dma_ctrl
);
1435 static int vortex_wtdma_bufshift(vortex_t
* vortex
, int wtdma
)
1437 stream_t
*dma
= &vortex
->dma_wt
[wtdma
];
1438 int page
, p
, pp
, delta
, i
;
1441 (hwread(vortex
->mmio
, VORTEX_WTDMA_STAT
+ (wtdma
<< 2))
1442 >> WT_SUBBUF_SHIFT
) & WT_SUBBUF_MASK
;
1443 if (dma
->nr_periods
>= 4)
1444 delta
= (page
- dma
->period_real
) & 3;
1446 delta
= (page
- dma
->period_real
);
1448 delta
+= dma
->nr_periods
;
1453 /* refresh hw page table */
1454 if (dma
->nr_periods
> 4) {
1455 for (i
= 0; i
< delta
; i
++) {
1456 /* p: audio buffer page index */
1457 p
= dma
->period_virt
+ i
+ 4;
1458 if (p
>= dma
->nr_periods
)
1459 p
-= dma
->nr_periods
;
1460 /* pp: hardware DMA page index. */
1461 pp
= dma
->period_real
+ i
;
1464 hwwrite(vortex
->mmio
,
1465 VORTEX_WTDMA_BUFBASE
+
1466 (((wtdma
<< 2) + pp
) << 2),
1467 snd_pcm_sgbuf_get_addr(dma
->substream
,
1468 dma
->period_bytes
* p
));
1469 /* Force write thru cache. */
1470 hwread(vortex
->mmio
, VORTEX_WTDMA_BUFBASE
+
1471 (((wtdma
<< 2) + pp
) << 2));
1474 dma
->period_virt
+= delta
;
1475 if (dma
->period_virt
>= dma
->nr_periods
)
1476 dma
->period_virt
-= dma
->nr_periods
;
1477 dma
->period_real
= page
;
1480 dev_warn(vortex
->card
->dev
, "wt virt = %d, delta = %d\n",
1481 dma
->period_virt
, delta
);
1488 vortex_wtdma_getposition(vortex_t
* vortex
, int wtdma
, int *subbuf
, int *pos
)
1491 temp
= hwread(vortex
->mmio
, VORTEX_WTDMA_STAT
+ (wtdma
<< 2));
1492 *subbuf
= (temp
>> WT_SUBBUF_SHIFT
) & WT_SUBBUF_MASK
;
1493 *pos
= temp
& POS_MASK
;
1496 static int vortex_wtdma_getcursubuffer(vortex_t
* vortex
, int wtdma
)
1498 return ((hwread(vortex
->mmio
, VORTEX_WTDMA_STAT
+ (wtdma
<< 2)) >>
1499 POS_SHIFT
) & POS_MASK
);
1502 static inline int vortex_wtdma_getlinearpos(vortex_t
* vortex
, int wtdma
)
1504 stream_t
*dma
= &vortex
->dma_wt
[wtdma
];
1507 temp
= hwread(vortex
->mmio
, VORTEX_WTDMA_STAT
+ (wtdma
<< 2));
1508 temp
= (dma
->period_virt
* dma
->period_bytes
) + (temp
& (dma
->period_bytes
- 1));
1512 static void vortex_wtdma_startfifo(vortex_t
* vortex
, int wtdma
)
1514 stream_t
*dma
= &vortex
->dma_wt
[wtdma
];
1515 int this_8
= 0, this_4
= 0;
1517 switch (dma
->fifo_status
) {
1519 vortex_fifo_setwtvalid(vortex
, wtdma
,
1520 dma
->fifo_enabled
? 1 : 0);
1524 hwwrite(vortex
->mmio
, VORTEX_WTDMA_CTRL
+ (wtdma
<< 2),
1526 vortex_fifo_setwtctrl(vortex
, wtdma
, dma
->dma_unknown
,
1528 dma
->fifo_enabled
? 1 : 0, 0);
1531 vortex_fifo_setwtctrl(vortex
, wtdma
, dma
->dma_unknown
,
1533 dma
->fifo_enabled
? 1 : 0, 0);
1536 dma
->fifo_status
= FIFO_START
;
1539 static void vortex_wtdma_resumefifo(vortex_t
* vortex
, int wtdma
)
1541 stream_t
*dma
= &vortex
->dma_wt
[wtdma
];
1543 int this_8
= 0, this_4
= 0;
1544 switch (dma
->fifo_status
) {
1546 hwwrite(vortex
->mmio
, VORTEX_WTDMA_CTRL
+ (wtdma
<< 2),
1548 vortex_fifo_setwtctrl(vortex
, wtdma
, dma
->dma_unknown
,
1550 dma
->fifo_enabled
? 1 : 0, 0);
1553 vortex_fifo_setwtctrl(vortex
, wtdma
, dma
->dma_unknown
,
1555 dma
->fifo_enabled
? 1 : 0, 0);
1558 dma
->fifo_status
= FIFO_START
;
1561 static void vortex_wtdma_pausefifo(vortex_t
* vortex
, int wtdma
)
1563 stream_t
*dma
= &vortex
->dma_wt
[wtdma
];
1565 int this_8
= 0, this_4
= 0;
1566 switch (dma
->fifo_status
) {
1568 vortex_fifo_setwtctrl(vortex
, wtdma
, dma
->dma_unknown
,
1569 this_4
, this_8
, 0, 0);
1572 hwwrite(vortex
->mmio
, VORTEX_WTDMA_CTRL
+ (wtdma
<< 2),
1574 vortex_fifo_setwtctrl(vortex
, wtdma
, dma
->dma_unknown
,
1575 this_4
, this_8
, 0, 0);
1578 dma
->fifo_status
= FIFO_PAUSE
;
1581 static void vortex_wtdma_stopfifo(vortex_t
* vortex
, int wtdma
)
1583 stream_t
*dma
= &vortex
->dma_wt
[wtdma
];
1585 int this_4
= 0, this_8
= 0;
1586 if (dma
->fifo_status
== FIFO_START
)
1587 vortex_fifo_setwtctrl(vortex
, wtdma
, dma
->dma_unknown
,
1588 this_4
, this_8
, 0, 0);
1589 else if (dma
->fifo_status
== FIFO_STOP
)
1591 dma
->fifo_status
= FIFO_STOP
;
1592 dma
->fifo_enabled
= 0;
1598 typedef int ADBRamLink
;
1599 static void vortex_adb_init(vortex_t
* vortex
)
1602 /* it looks like we are writing more than we need to...
1603 * if we write what we are supposed to it breaks things... */
1604 hwwrite(vortex
->mmio
, VORTEX_ADB_SR
, 0);
1605 for (i
= 0; i
< VORTEX_ADB_RTBASE_COUNT
; i
++)
1606 hwwrite(vortex
->mmio
, VORTEX_ADB_RTBASE
+ (i
<< 2),
1607 hwread(vortex
->mmio
,
1608 VORTEX_ADB_RTBASE
+ (i
<< 2)) | ROUTE_MASK
);
1609 for (i
= 0; i
< VORTEX_ADB_CHNBASE_COUNT
; i
++) {
1610 hwwrite(vortex
->mmio
, VORTEX_ADB_CHNBASE
+ (i
<< 2),
1611 hwread(vortex
->mmio
,
1612 VORTEX_ADB_CHNBASE
+ (i
<< 2)) | ROUTE_MASK
);
1616 static void vortex_adb_en_sr(vortex_t
* vortex
, int channel
)
1618 hwwrite(vortex
->mmio
, VORTEX_ADB_SR
,
1619 hwread(vortex
->mmio
, VORTEX_ADB_SR
) | (0x1 << channel
));
1622 static void vortex_adb_dis_sr(vortex_t
* vortex
, int channel
)
1624 hwwrite(vortex
->mmio
, VORTEX_ADB_SR
,
1625 hwread(vortex
->mmio
, VORTEX_ADB_SR
) & ~(0x1 << channel
));
1629 vortex_adb_addroutes(vortex_t
* vortex
, unsigned char channel
,
1630 ADBRamLink
* route
, int rnum
)
1632 int temp
, prev
, lifeboat
= 0;
1634 if ((rnum
<= 0) || (route
== NULL
))
1636 /* Write last routes. */
1638 hwwrite(vortex
->mmio
,
1639 VORTEX_ADB_RTBASE
+ ((route
[rnum
] & ADB_MASK
) << 2),
1642 hwwrite(vortex
->mmio
,
1644 ((route
[rnum
- 1] & ADB_MASK
) << 2), route
[rnum
]);
1647 /* Write first route. */
1649 hwread(vortex
->mmio
,
1650 VORTEX_ADB_CHNBASE
+ (channel
<< 2)) & ADB_MASK
;
1651 if (temp
== ADB_MASK
) {
1652 /* First entry on this channel. */
1653 hwwrite(vortex
->mmio
, VORTEX_ADB_CHNBASE
+ (channel
<< 2),
1655 vortex_adb_en_sr(vortex
, channel
);
1658 /* Not first entry on this channel. Need to link. */
1662 hwread(vortex
->mmio
,
1663 VORTEX_ADB_RTBASE
+ (temp
<< 2)) & ADB_MASK
;
1664 if ((lifeboat
++) > ADB_MASK
) {
1665 dev_err(vortex
->card
->dev
,
1666 "vortex_adb_addroutes: unending route! 0x%x\n",
1671 while (temp
!= ADB_MASK
);
1672 hwwrite(vortex
->mmio
, VORTEX_ADB_RTBASE
+ (prev
<< 2), route
[0]);
1676 vortex_adb_delroutes(vortex_t
* vortex
, unsigned char channel
,
1677 ADBRamLink route0
, ADBRamLink route1
)
1679 int temp
, lifeboat
= 0, prev
;
1683 hwread(vortex
->mmio
,
1684 VORTEX_ADB_CHNBASE
+ (channel
<< 2)) & ADB_MASK
;
1685 if (temp
== (route0
& ADB_MASK
)) {
1687 hwread(vortex
->mmio
,
1688 VORTEX_ADB_RTBASE
+ ((route1
& ADB_MASK
) << 2));
1689 if ((temp
& ADB_MASK
) == ADB_MASK
)
1690 vortex_adb_dis_sr(vortex
, channel
);
1691 hwwrite(vortex
->mmio
, VORTEX_ADB_CHNBASE
+ (channel
<< 2),
1698 hwread(vortex
->mmio
,
1699 VORTEX_ADB_RTBASE
+ (prev
<< 2)) & ADB_MASK
;
1700 if (((lifeboat
++) > ADB_MASK
) || (temp
== ADB_MASK
)) {
1701 dev_err(vortex
->card
->dev
,
1702 "vortex_adb_delroutes: route not found! 0x%x\n",
1707 while (temp
!= (route0
& ADB_MASK
));
1708 temp
= hwread(vortex
->mmio
, VORTEX_ADB_RTBASE
+ (temp
<< 2));
1709 if ((temp
& ADB_MASK
) == route1
)
1710 temp
= hwread(vortex
->mmio
, VORTEX_ADB_RTBASE
+ (temp
<< 2));
1711 /* Make bridge over deleted route. */
1712 hwwrite(vortex
->mmio
, VORTEX_ADB_RTBASE
+ (prev
<< 2), temp
);
1716 vortex_route(vortex_t
* vortex
, int en
, unsigned char channel
,
1717 unsigned char source
, unsigned char dest
)
1721 route
= ((source
& ADB_MASK
) << ADB_SHIFT
) | (dest
& ADB_MASK
);
1723 vortex_adb_addroutes(vortex
, channel
, &route
, 1);
1724 if ((source
< (OFFSET_SRCOUT
+ NR_SRC
))
1725 && (source
>= OFFSET_SRCOUT
))
1726 vortex_src_addWTD(vortex
, (source
- OFFSET_SRCOUT
),
1728 else if ((source
< (OFFSET_MIXOUT
+ NR_MIXOUT
))
1729 && (source
>= OFFSET_MIXOUT
))
1730 vortex_mixer_addWTD(vortex
,
1731 (source
- OFFSET_MIXOUT
), channel
);
1733 vortex_adb_delroutes(vortex
, channel
, route
, route
);
1734 if ((source
< (OFFSET_SRCOUT
+ NR_SRC
))
1735 && (source
>= OFFSET_SRCOUT
))
1736 vortex_src_delWTD(vortex
, (source
- OFFSET_SRCOUT
),
1738 else if ((source
< (OFFSET_MIXOUT
+ NR_MIXOUT
))
1739 && (source
>= OFFSET_MIXOUT
))
1740 vortex_mixer_delWTD(vortex
,
1741 (source
- OFFSET_MIXOUT
), channel
);
1747 vortex_routes(vortex_t
* vortex
, int en
, unsigned char channel
,
1748 unsigned char source
, unsigned char dest0
, unsigned char dest1
)
1750 ADBRamLink route
[2];
1752 route
[0] = ((source
& ADB_MASK
) << ADB_SHIFT
) | (dest0
& ADB_MASK
);
1753 route
[1] = ((source
& ADB_MASK
) << ADB_SHIFT
) | (dest1
& ADB_MASK
);
1756 vortex_adb_addroutes(vortex
, channel
, route
, 2);
1757 if ((source
< (OFFSET_SRCOUT
+ NR_SRC
))
1758 && (source
>= (OFFSET_SRCOUT
)))
1759 vortex_src_addWTD(vortex
, (source
- OFFSET_SRCOUT
),
1761 else if ((source
< (OFFSET_MIXOUT
+ NR_MIXOUT
))
1762 && (source
>= (OFFSET_MIXOUT
)))
1763 vortex_mixer_addWTD(vortex
,
1764 (source
- OFFSET_MIXOUT
), channel
);
1766 vortex_adb_delroutes(vortex
, channel
, route
[0], route
[1]);
1767 if ((source
< (OFFSET_SRCOUT
+ NR_SRC
))
1768 && (source
>= (OFFSET_SRCOUT
)))
1769 vortex_src_delWTD(vortex
, (source
- OFFSET_SRCOUT
),
1771 else if ((source
< (OFFSET_MIXOUT
+ NR_MIXOUT
))
1772 && (source
>= (OFFSET_MIXOUT
)))
1773 vortex_mixer_delWTD(vortex
,
1774 (source
- OFFSET_MIXOUT
), channel
);
1779 /* Route two sources to same target. Sources must be of same class !!! */
1781 vortex_routeLRT(vortex_t
* vortex
, int en
, unsigned char ch
,
1782 unsigned char source0
, unsigned char source1
,
1785 ADBRamLink route
[2];
1787 route
[0] = ((source0
& ADB_MASK
) << ADB_SHIFT
) | (dest
& ADB_MASK
);
1788 route
[1] = ((source1
& ADB_MASK
) << ADB_SHIFT
) | (dest
& ADB_MASK
);
1791 route
[1] = (route
[1] & ~ADB_MASK
) | (dest
+ 0x20); /* fifo A */
1794 vortex_adb_addroutes(vortex
, ch
, route
, 2);
1795 if ((source0
< (OFFSET_SRCOUT
+ NR_SRC
))
1796 && (source0
>= OFFSET_SRCOUT
)) {
1797 vortex_src_addWTD(vortex
,
1798 (source0
- OFFSET_SRCOUT
), ch
);
1799 vortex_src_addWTD(vortex
,
1800 (source1
- OFFSET_SRCOUT
), ch
);
1801 } else if ((source0
< (OFFSET_MIXOUT
+ NR_MIXOUT
))
1802 && (source0
>= OFFSET_MIXOUT
)) {
1803 vortex_mixer_addWTD(vortex
,
1804 (source0
- OFFSET_MIXOUT
), ch
);
1805 vortex_mixer_addWTD(vortex
,
1806 (source1
- OFFSET_MIXOUT
), ch
);
1809 vortex_adb_delroutes(vortex
, ch
, route
[0], route
[1]);
1810 if ((source0
< (OFFSET_SRCOUT
+ NR_SRC
))
1811 && (source0
>= OFFSET_SRCOUT
)) {
1812 vortex_src_delWTD(vortex
,
1813 (source0
- OFFSET_SRCOUT
), ch
);
1814 vortex_src_delWTD(vortex
,
1815 (source1
- OFFSET_SRCOUT
), ch
);
1816 } else if ((source0
< (OFFSET_MIXOUT
+ NR_MIXOUT
))
1817 && (source0
>= OFFSET_MIXOUT
)) {
1818 vortex_mixer_delWTD(vortex
,
1819 (source0
- OFFSET_MIXOUT
), ch
);
1820 vortex_mixer_delWTD(vortex
,
1821 (source1
- OFFSET_MIXOUT
), ch
);
1826 /* Connection stuff */
1828 // Connect adbdma to src('s).
1830 vortex_connection_adbdma_src(vortex_t
* vortex
, int en
, unsigned char ch
,
1831 unsigned char adbdma
, unsigned char src
)
1833 vortex_route(vortex
, en
, ch
, ADB_DMA(adbdma
), ADB_SRCIN(src
));
1836 // Connect SRC to mixin.
1838 vortex_connection_src_mixin(vortex_t
* vortex
, int en
,
1839 unsigned char channel
, unsigned char src
,
1840 unsigned char mixin
)
1842 vortex_route(vortex
, en
, channel
, ADB_SRCOUT(src
), ADB_MIXIN(mixin
));
1845 // Connect mixin with mix output.
1847 vortex_connection_mixin_mix(vortex_t
* vortex
, int en
, unsigned char mixin
,
1848 unsigned char mix
, int a
)
1851 vortex_mix_enableinput(vortex
, mix
, mixin
);
1852 vortex_mix_setinputvolumebyte(vortex
, mix
, mixin
, MIX_DEFIGAIN
); // added to original code.
1854 vortex_mix_disableinput(vortex
, mix
, mixin
, a
);
1857 // Connect absolut address to mixin.
1859 vortex_connection_adb_mixin(vortex_t
* vortex
, int en
,
1860 unsigned char channel
, unsigned char source
,
1861 unsigned char mixin
)
1863 vortex_route(vortex
, en
, channel
, source
, ADB_MIXIN(mixin
));
1867 vortex_connection_src_adbdma(vortex_t
* vortex
, int en
, unsigned char ch
,
1868 unsigned char src
, unsigned char adbdma
)
1870 vortex_route(vortex
, en
, ch
, ADB_SRCOUT(src
), ADB_DMA(adbdma
));
1874 vortex_connection_src_src_adbdma(vortex_t
* vortex
, int en
,
1875 unsigned char ch
, unsigned char src0
,
1876 unsigned char src1
, unsigned char adbdma
)
1879 vortex_routeLRT(vortex
, en
, ch
, ADB_SRCOUT(src0
), ADB_SRCOUT(src1
),
1883 // mix to absolut address.
1885 vortex_connection_mix_adb(vortex_t
* vortex
, int en
, unsigned char ch
,
1886 unsigned char mix
, unsigned char dest
)
1888 vortex_route(vortex
, en
, ch
, ADB_MIXOUT(mix
), dest
);
1889 vortex_mix_setvolumebyte(vortex
, mix
, MIX_DEFOGAIN
); // added to original code.
1894 vortex_connection_mix_src(vortex_t
* vortex
, int en
, unsigned char ch
,
1895 unsigned char mix
, unsigned char src
)
1897 vortex_route(vortex
, en
, ch
, ADB_MIXOUT(mix
), ADB_SRCIN(src
));
1898 vortex_mix_setvolumebyte(vortex
, mix
, MIX_DEFOGAIN
); // added to original code.
1903 vortex_connection_adbdma_src_src(vortex_t
* vortex
, int en
,
1904 unsigned char channel
,
1905 unsigned char adbdma
, unsigned char src0
,
1908 vortex_routes(vortex
, en
, channel
, ADB_DMA(adbdma
),
1909 ADB_SRCIN(src0
), ADB_SRCIN(src1
));
1912 // Connect two mix to AdbDma.
1914 vortex_connection_mix_mix_adbdma(vortex_t
* vortex
, int en
,
1915 unsigned char ch
, unsigned char mix0
,
1916 unsigned char mix1
, unsigned char adbdma
)
1919 ADBRamLink routes
[2];
1922 OFFSET_MIXOUT
) & ADB_MASK
) << ADB_SHIFT
) | (adbdma
& ADB_MASK
);
1924 (((mix1
+ OFFSET_MIXOUT
) & ADB_MASK
) << ADB_SHIFT
) | ((adbdma
+
1928 vortex_adb_addroutes(vortex
, ch
, routes
, 0x2);
1929 vortex_mixer_addWTD(vortex
, mix0
, ch
);
1930 vortex_mixer_addWTD(vortex
, mix1
, ch
);
1932 vortex_adb_delroutes(vortex
, ch
, routes
[0], routes
[1]);
1933 vortex_mixer_delWTD(vortex
, mix0
, ch
);
1934 vortex_mixer_delWTD(vortex
, mix1
, ch
);
1939 /* CODEC connect. */
1942 vortex_connect_codecplay(vortex_t
* vortex
, int en
, unsigned char mixers
[])
1945 vortex_connection_mix_adb(vortex
, en
, 0x11, mixers
[0], ADB_CODECOUT(0));
1946 vortex_connection_mix_adb(vortex
, en
, 0x11, mixers
[1], ADB_CODECOUT(1));
1949 // Connect front channels through EQ.
1950 vortex_connection_mix_adb(vortex
, en
, 0x11, mixers
[0], ADB_EQIN(0));
1951 vortex_connection_mix_adb(vortex
, en
, 0x11, mixers
[1], ADB_EQIN(1));
1952 /* Lower volume, since EQ has some gain. */
1953 vortex_mix_setvolumebyte(vortex
, mixers
[0], 0);
1954 vortex_mix_setvolumebyte(vortex
, mixers
[1], 0);
1955 vortex_route(vortex
, en
, 0x11, ADB_EQOUT(0), ADB_CODECOUT(0));
1956 vortex_route(vortex
, en
, 0x11, ADB_EQOUT(1), ADB_CODECOUT(1));
1958 /* Check if reg 0x28 has SDAC bit set. */
1959 if (VORTEX_IS_QUAD(vortex
)) {
1960 /* Rear channel. Note: ADB_CODECOUT(0+2) and (1+2) is for AC97 modem */
1961 vortex_connection_mix_adb(vortex
, en
, 0x11, mixers
[2],
1962 ADB_CODECOUT(0 + 4));
1963 vortex_connection_mix_adb(vortex
, en
, 0x11, mixers
[3],
1964 ADB_CODECOUT(1 + 4));
1965 /* pr_debug( "SDAC detected "); */
1968 // Use plain direct output to codec.
1969 vortex_connection_mix_adb(vortex
, en
, 0x11, mixers
[0], ADB_CODECOUT(0));
1970 vortex_connection_mix_adb(vortex
, en
, 0x11, mixers
[1], ADB_CODECOUT(1));
1976 vortex_connect_codecrec(vortex_t
* vortex
, int en
, unsigned char mixin0
,
1977 unsigned char mixin1
)
1982 ADB Source address: 0x48, 0x49
1983 Destination Asp4Topology_0x9c,0x98
1985 vortex_connection_adb_mixin(vortex
, en
, 0x11, ADB_CODECIN(0), mixin0
);
1986 vortex_connection_adb_mixin(vortex
, en
, 0x11, ADB_CODECIN(1), mixin1
);
1989 // Higher level ADB audio path (de)allocator.
1991 /* Resource manager */
1992 static const int resnum
[VORTEX_RESOURCE_LAST
] =
1993 { NR_ADB
, NR_SRC
, NR_MIXIN
, NR_MIXOUT
, NR_A3D
};
1995 Checkout/Checkin resource of given type.
1996 resmap: resource map to be used. If NULL means that we want to allocate
1997 a DMA resource (root of all other resources of a dma channel).
1998 out: Mean checkout if != 0. Else mean Checkin resource.
1999 restype: Indicates type of resource to be checked in or out.
2002 vortex_adb_checkinout(vortex_t
* vortex
, int resmap
[], int out
, int restype
)
2004 int i
, qty
= resnum
[restype
], resinuse
= 0;
2007 /* Gather used resources by all streams. */
2008 for (i
= 0; i
< NR_ADB
; i
++) {
2009 resinuse
|= vortex
->dma_adb
[i
].resources
[restype
];
2011 resinuse
|= vortex
->fixed_res
[restype
];
2012 /* Find and take free resource. */
2013 for (i
= 0; i
< qty
; i
++) {
2014 if ((resinuse
& (1 << i
)) == 0) {
2016 resmap
[restype
] |= (1 << i
);
2018 vortex
->dma_adb
[i
].resources
[restype
] |= (1 << i
);
2021 "vortex: ResManager: type %d out %d\n",
2030 /* Checkin first resource of type restype. */
2031 for (i
= 0; i
< qty
; i
++) {
2032 if (resmap
[restype
] & (1 << i
)) {
2033 resmap
[restype
] &= ~(1 << i
);
2036 "vortex: ResManager: type %d in %d\n",
2043 dev_err(vortex
->card
->dev
,
2044 "FATAL: ResManager: resource type %d exhausted.\n",
2049 /* Default Connections */
2051 static void vortex_connect_default(vortex_t
* vortex
, int en
)
2053 // Connect AC97 codec.
2054 vortex
->mixplayb
[0] = vortex_adb_checkinout(vortex
, vortex
->fixed_res
, en
,
2055 VORTEX_RESOURCE_MIXOUT
);
2056 vortex
->mixplayb
[1] = vortex_adb_checkinout(vortex
, vortex
->fixed_res
, en
,
2057 VORTEX_RESOURCE_MIXOUT
);
2058 if (VORTEX_IS_QUAD(vortex
)) {
2059 vortex
->mixplayb
[2] = vortex_adb_checkinout(vortex
, vortex
->fixed_res
, en
,
2060 VORTEX_RESOURCE_MIXOUT
);
2061 vortex
->mixplayb
[3] = vortex_adb_checkinout(vortex
, vortex
->fixed_res
, en
,
2062 VORTEX_RESOURCE_MIXOUT
);
2064 vortex_connect_codecplay(vortex
, en
, vortex
->mixplayb
);
2066 vortex
->mixcapt
[0] = vortex_adb_checkinout(vortex
, vortex
->fixed_res
, en
,
2067 VORTEX_RESOURCE_MIXIN
);
2068 vortex
->mixcapt
[1] = vortex_adb_checkinout(vortex
, vortex
->fixed_res
, en
,
2069 VORTEX_RESOURCE_MIXIN
);
2070 vortex_connect_codecrec(vortex
, en
, MIX_CAPT(0), MIX_CAPT(1));
2074 vortex
->mixspdif
[0] = vortex_adb_checkinout(vortex
, vortex
->fixed_res
, en
,
2075 VORTEX_RESOURCE_MIXOUT
);
2076 vortex
->mixspdif
[1] = vortex_adb_checkinout(vortex
, vortex
->fixed_res
, en
,
2077 VORTEX_RESOURCE_MIXOUT
);
2078 vortex_connection_mix_adb(vortex
, en
, 0x14, vortex
->mixspdif
[0],
2080 vortex_connection_mix_adb(vortex
, en
, 0x14, vortex
->mixspdif
[1],
2085 vortex_wt_connect(vortex
, en
);
2087 // A3D (crosstalk canceler and A3D slices). AU8810 disabled for now.
2089 vortex_Vort3D_connect(vortex
, en
);
2093 // Connect DSP interface for SQ3500 turbo (not here i think...)
2095 // Connect AC98 modem codec
2100 Allocate nr_ch pcm audio routes if dma < 0. If dma >= 0, existing routes
2102 dma: DMA engine routes to be deallocated when dma >= 0.
2103 nr_ch: Number of channels to be de/allocated.
2104 dir: direction of stream. Uses same values as substream->stream.
2105 type: Type of audio output/source (codec, spdif, i2s, dsp, etc)
2106 Return: Return allocated DMA or same DMA passed as "dma" when dma >= 0.
2109 vortex_adb_allocroute(vortex_t
*vortex
, int dma
, int nr_ch
, int dir
,
2110 int type
, int subdev
)
2118 vortex_adb_checkinout(vortex
,
2119 vortex
->dma_adb
[dma
].resources
, en
,
2120 VORTEX_RESOURCE_DMA
);
2124 vortex_adb_checkinout(vortex
, NULL
, en
,
2125 VORTEX_RESOURCE_DMA
)) < 0)
2129 stream
= &vortex
->dma_adb
[dma
];
2132 stream
->type
= type
;
2134 /* PLAYBACK ROUTES. */
2135 if (dir
== SNDRV_PCM_STREAM_PLAYBACK
) {
2136 int src
[4], mix
[4], ch_top
;
2140 /* Get SRC and MIXER hardware resources. */
2141 if (stream
->type
!= VORTEX_PCM_SPDIF
) {
2142 for (i
= 0; i
< nr_ch
; i
++) {
2143 if ((src
[i
] = vortex_adb_checkinout(vortex
,
2144 stream
->resources
, en
,
2145 VORTEX_RESOURCE_SRC
)) < 0) {
2146 memset(stream
->resources
, 0,
2147 sizeof(stream
->resources
));
2150 if (stream
->type
!= VORTEX_PCM_A3D
) {
2151 if ((mix
[i
] = vortex_adb_checkinout(vortex
,
2154 VORTEX_RESOURCE_MIXIN
)) < 0) {
2155 memset(stream
->resources
,
2157 sizeof(stream
->resources
));
2164 if (stream
->type
== VORTEX_PCM_A3D
) {
2166 vortex_adb_checkinout(vortex
,
2167 stream
->resources
, en
,
2168 VORTEX_RESOURCE_A3D
)) < 0) {
2169 memset(stream
->resources
, 0,
2170 sizeof(stream
->resources
));
2171 dev_err(vortex
->card
->dev
,
2172 "out of A3D sources. Sorry\n");
2175 /* (De)Initialize A3D hardware source. */
2176 vortex_Vort3D_InitializeSource(&vortex
->a3d
[a3d
], en
,
2179 /* Make SPDIF out exclusive to "spdif" device when in use. */
2180 if ((stream
->type
== VORTEX_PCM_SPDIF
) && (en
)) {
2181 vortex_route(vortex
, 0, 0x14,
2182 ADB_MIXOUT(vortex
->mixspdif
[0]),
2184 vortex_route(vortex
, 0, 0x14,
2185 ADB_MIXOUT(vortex
->mixspdif
[1]),
2189 /* Make playback routes. */
2190 for (i
= 0; i
< nr_ch
; i
++) {
2191 if (stream
->type
== VORTEX_PCM_ADB
) {
2192 vortex_connection_adbdma_src(vortex
, en
,
2196 vortex_connection_src_mixin(vortex
, en
,
2199 vortex_connection_mixin_mix(vortex
, en
,
2203 vortex_connection_mixin_mix(vortex
, en
,
2205 MIX_SPDIF(i
% 2), 0);
2206 vortex_mix_setinputvolumebyte(vortex
,
2213 if (stream
->type
== VORTEX_PCM_A3D
) {
2214 vortex_connection_adbdma_src(vortex
, en
,
2218 vortex_route(vortex
, en
, 0x11, ADB_SRCOUT(src
[i
]), ADB_A3DIN(a3d
));
2220 //vortex_route(vortex, en, 0x11, dma, ADB_XTALKIN(i?9:4));
2221 //vortex_route(vortex, en, 0x11, ADB_SRCOUT(src[i]), ADB_XTALKIN(i?4:9));
2223 if (stream
->type
== VORTEX_PCM_SPDIF
)
2224 vortex_route(vortex
, en
, 0x14,
2225 ADB_DMA(stream
->dma
),
2229 if (stream
->type
!= VORTEX_PCM_SPDIF
&& stream
->type
!= VORTEX_PCM_A3D
) {
2230 ch_top
= (VORTEX_IS_QUAD(vortex
) ? 4 : 2);
2231 for (i
= nr_ch
; i
< ch_top
; i
++) {
2232 vortex_connection_mixin_mix(vortex
, en
,
2236 vortex_connection_mixin_mix(vortex
, en
,
2240 vortex_mix_setinputvolumebyte(vortex
,
2246 if (stream
->type
== VORTEX_PCM_ADB
&& en
) {
2247 p
= &vortex
->pcm_vol
[subdev
];
2249 for (i
= 0; i
< nr_ch
; i
++)
2250 p
->mixin
[i
] = mix
[i
];
2251 for (i
= 0; i
< ch_top
; i
++)
2257 if (nr_ch
== 1 && stream
->type
== VORTEX_PCM_SPDIF
)
2258 vortex_route(vortex
, en
, 0x14,
2259 ADB_DMA(stream
->dma
),
2262 /* Reconnect SPDIF out when "spdif" device is down. */
2263 if ((stream
->type
== VORTEX_PCM_SPDIF
) && (!en
)) {
2264 vortex_route(vortex
, 1, 0x14,
2265 ADB_MIXOUT(vortex
->mixspdif
[0]),
2267 vortex_route(vortex
, 1, 0x14,
2268 ADB_MIXOUT(vortex
->mixspdif
[1]),
2272 /* CAPTURE ROUTES. */
2279 /* Get SRC and MIXER hardware resources. */
2280 for (i
= 0; i
< nr_ch
; i
++) {
2282 vortex_adb_checkinout(vortex
,
2283 stream
->resources
, en
,
2284 VORTEX_RESOURCE_MIXOUT
))
2286 memset(stream
->resources
, 0,
2287 sizeof(stream
->resources
));
2291 vortex_adb_checkinout(vortex
,
2292 stream
->resources
, en
,
2293 VORTEX_RESOURCE_SRC
)) < 0) {
2294 memset(stream
->resources
, 0,
2295 sizeof(stream
->resources
));
2300 /* Make capture routes. */
2301 vortex_connection_mixin_mix(vortex
, en
, MIX_CAPT(0), mix
[0], 0);
2302 vortex_connection_mix_src(vortex
, en
, 0x11, mix
[0], src
[0]);
2304 vortex_connection_mixin_mix(vortex
, en
,
2305 MIX_CAPT(1), mix
[0], 0);
2306 vortex_connection_src_adbdma(vortex
, en
,
2310 vortex_connection_mixin_mix(vortex
, en
,
2311 MIX_CAPT(1), mix
[1], 0);
2312 vortex_connection_mix_src(vortex
, en
, 0x11, mix
[1],
2314 vortex_connection_src_src_adbdma(vortex
, en
,
2319 vortex
->dma_adb
[dma
].nr_ch
= nr_ch
;
2322 /* AC97 Codec channel setup. FIXME: this has no effect on some cards !! */
2324 /* Copy stereo to rear channel (surround) */
2325 snd_ac97_write_cache(vortex
->codec
,
2326 AC97_SIGMATEL_DAC2INVERT
,
2327 snd_ac97_read(vortex
->codec
,
2328 AC97_SIGMATEL_DAC2INVERT
)
2331 /* Allow separate front and rear channels. */
2332 snd_ac97_write_cache(vortex
->codec
,
2333 AC97_SIGMATEL_DAC2INVERT
,
2334 snd_ac97_read(vortex
->codec
,
2335 AC97_SIGMATEL_DAC2INVERT
)
2344 Set the SampleRate of the SRC's attached to the given DMA engine.
2347 vortex_adb_setsrc(vortex_t
* vortex
, int adbdma
, unsigned int rate
, int dir
)
2349 stream_t
*stream
= &(vortex
->dma_adb
[adbdma
]);
2352 /* dir=1:play ; dir=0:rec */
2354 cvrt
= SRC_RATIO(rate
, 48000);
2356 cvrt
= SRC_RATIO(48000, rate
);
2359 for (i
= 0; i
< NR_SRC
; i
++) {
2360 if (stream
->resources
[VORTEX_RESOURCE_SRC
] & (1 << i
))
2361 vortex_src_setupchannel(vortex
, i
, cvrt
, 0, 0, i
, dir
, 1, cvrt
, dir
);
2365 // Timer and ISR functions.
2367 static void vortex_settimer(vortex_t
* vortex
, int period
)
2369 //set the timer period to <period> 48000ths of a second.
2370 hwwrite(vortex
->mmio
, VORTEX_IRQ_STAT
, period
);
2374 static void vortex_enable_timer_int(vortex_t
* card
)
2376 hwwrite(card
->mmio
, VORTEX_IRQ_CTRL
,
2377 hwread(card
->mmio
, VORTEX_IRQ_CTRL
) | IRQ_TIMER
| 0x60);
2380 static void vortex_disable_timer_int(vortex_t
* card
)
2382 hwwrite(card
->mmio
, VORTEX_IRQ_CTRL
,
2383 hwread(card
->mmio
, VORTEX_IRQ_CTRL
) & ~IRQ_TIMER
);
2387 static void vortex_enable_int(vortex_t
* card
)
2389 // CAsp4ISR__EnableVortexInt_void_
2390 hwwrite(card
->mmio
, VORTEX_CTRL
,
2391 hwread(card
->mmio
, VORTEX_CTRL
) | CTRL_IRQ_ENABLE
);
2392 hwwrite(card
->mmio
, VORTEX_IRQ_CTRL
,
2393 (hwread(card
->mmio
, VORTEX_IRQ_CTRL
) & 0xffffefc0) | 0x24);
2396 static void vortex_disable_int(vortex_t
* card
)
2398 hwwrite(card
->mmio
, VORTEX_CTRL
,
2399 hwread(card
->mmio
, VORTEX_CTRL
) & ~CTRL_IRQ_ENABLE
);
2402 static irqreturn_t
vortex_interrupt(int irq
, void *dev_id
)
2404 vortex_t
*vortex
= dev_id
;
2408 //check if the interrupt is ours.
2409 if (!(hwread(vortex
->mmio
, VORTEX_STAT
) & 0x1))
2412 // This is the Interrupt Enable flag we set before (consistency check).
2413 if (!(hwread(vortex
->mmio
, VORTEX_CTRL
) & CTRL_IRQ_ENABLE
))
2416 source
= hwread(vortex
->mmio
, VORTEX_IRQ_SOURCE
);
2418 hwwrite(vortex
->mmio
, VORTEX_IRQ_SOURCE
, source
);
2419 hwread(vortex
->mmio
, VORTEX_IRQ_SOURCE
);
2420 // Is at least one IRQ flag set?
2422 dev_err(vortex
->card
->dev
, "missing irq source\n");
2427 // Attend every interrupt source.
2428 if (unlikely(source
& IRQ_ERR_MASK
)) {
2429 if (source
& IRQ_FATAL
) {
2430 dev_err(vortex
->card
->dev
, "IRQ fatal error\n");
2432 if (source
& IRQ_PARITY
) {
2433 dev_err(vortex
->card
->dev
, "IRQ parity error\n");
2435 if (source
& IRQ_REG
) {
2436 dev_err(vortex
->card
->dev
, "IRQ reg error\n");
2438 if (source
& IRQ_FIFO
) {
2439 dev_err(vortex
->card
->dev
, "IRQ fifo error\n");
2441 if (source
& IRQ_DMA
) {
2442 dev_err(vortex
->card
->dev
, "IRQ dma error\n");
2446 if (source
& IRQ_PCMOUT
) {
2447 /* ALSA period acknowledge. */
2448 spin_lock(&vortex
->lock
);
2449 for (i
= 0; i
< NR_ADB
; i
++) {
2450 if (vortex
->dma_adb
[i
].fifo_status
== FIFO_START
) {
2451 if (!vortex_adbdma_bufshift(vortex
, i
))
2453 spin_unlock(&vortex
->lock
);
2454 snd_pcm_period_elapsed(vortex
->dma_adb
[i
].
2456 spin_lock(&vortex
->lock
);
2460 for (i
= 0; i
< NR_WT
; i
++) {
2461 if (vortex
->dma_wt
[i
].fifo_status
== FIFO_START
) {
2462 /* FIXME: we ignore the return value from
2463 * vortex_wtdma_bufshift() below as the delta
2464 * calculation seems not working for wavetable
2467 vortex_wtdma_bufshift(vortex
, i
);
2468 spin_unlock(&vortex
->lock
);
2469 snd_pcm_period_elapsed(vortex
->dma_wt
[i
].
2471 spin_lock(&vortex
->lock
);
2475 spin_unlock(&vortex
->lock
);
2478 //Acknowledge the Timer interrupt
2479 if (source
& IRQ_TIMER
) {
2480 hwread(vortex
->mmio
, VORTEX_IRQ_STAT
);
2483 if ((source
& IRQ_MIDI
) && vortex
->rmidi
) {
2484 snd_mpu401_uart_interrupt(vortex
->irq
,
2485 vortex
->rmidi
->private_data
);
2490 dev_err(vortex
->card
->dev
, "unknown irq source %x\n", source
);
2492 return IRQ_RETVAL(handled
);
2497 #define POLL_COUNT 1000
2498 static void vortex_codec_init(vortex_t
* vortex
)
2502 for (i
= 0; i
< 32; i
++) {
2503 /* the windows driver writes -i, so we write -i */
2504 hwwrite(vortex
->mmio
, (VORTEX_CODEC_CHN
+ (i
<< 2)), -i
);
2508 hwwrite(vortex
->mmio
, VORTEX_CODEC_CTRL
, 0x8068);
2510 hwwrite(vortex
->mmio
, VORTEX_CODEC_CTRL
, 0x00e8);
2513 hwwrite(vortex
->mmio
, VORTEX_CODEC_CTRL
, 0x00a8);
2515 hwwrite(vortex
->mmio
, VORTEX_CODEC_CTRL
, 0x80a8);
2517 hwwrite(vortex
->mmio
, VORTEX_CODEC_CTRL
, 0x80e8);
2519 hwwrite(vortex
->mmio
, VORTEX_CODEC_CTRL
, 0x80a8);
2521 hwwrite(vortex
->mmio
, VORTEX_CODEC_CTRL
, 0x00a8);
2523 hwwrite(vortex
->mmio
, VORTEX_CODEC_CTRL
, 0x00e8);
2525 for (i
= 0; i
< 32; i
++) {
2526 hwwrite(vortex
->mmio
, (VORTEX_CODEC_CHN
+ (i
<< 2)), -i
);
2529 hwwrite(vortex
->mmio
, VORTEX_CODEC_CTRL
, 0xe8);
2531 /* Enable codec channels 0 and 1. */
2532 hwwrite(vortex
->mmio
, VORTEX_CODEC_EN
,
2533 hwread(vortex
->mmio
, VORTEX_CODEC_EN
) | EN_CODEC
);
2537 vortex_codec_write(struct snd_ac97
* codec
, unsigned short addr
, unsigned short data
)
2540 vortex_t
*card
= (vortex_t
*) codec
->private_data
;
2541 unsigned int lifeboat
= 0;
2543 /* wait for transactions to clear */
2544 while (!(hwread(card
->mmio
, VORTEX_CODEC_CTRL
) & 0x100)) {
2546 if (lifeboat
++ > POLL_COUNT
) {
2547 dev_err(card
->card
->dev
, "ac97 codec stuck busy\n");
2551 /* write register */
2552 hwwrite(card
->mmio
, VORTEX_CODEC_IO
,
2553 ((addr
<< VORTEX_CODEC_ADDSHIFT
) & VORTEX_CODEC_ADDMASK
) |
2554 ((data
<< VORTEX_CODEC_DATSHIFT
) & VORTEX_CODEC_DATMASK
) |
2555 VORTEX_CODEC_WRITE
|
2556 (codec
->num
<< VORTEX_CODEC_ID_SHIFT
) );
2559 hwread(card
->mmio
, VORTEX_CODEC_IO
);
2562 static unsigned short vortex_codec_read(struct snd_ac97
* codec
, unsigned short addr
)
2565 vortex_t
*card
= (vortex_t
*) codec
->private_data
;
2566 u32 read_addr
, data
;
2567 unsigned lifeboat
= 0;
2569 /* wait for transactions to clear */
2570 while (!(hwread(card
->mmio
, VORTEX_CODEC_CTRL
) & 0x100)) {
2572 if (lifeboat
++ > POLL_COUNT
) {
2573 dev_err(card
->card
->dev
, "ac97 codec stuck busy\n");
2577 /* set up read address */
2578 read_addr
= ((addr
<< VORTEX_CODEC_ADDSHIFT
) & VORTEX_CODEC_ADDMASK
) |
2579 (codec
->num
<< VORTEX_CODEC_ID_SHIFT
) ;
2580 hwwrite(card
->mmio
, VORTEX_CODEC_IO
, read_addr
);
2582 /* wait for address */
2585 data
= hwread(card
->mmio
, VORTEX_CODEC_IO
);
2586 if (lifeboat
++ > POLL_COUNT
) {
2587 dev_err(card
->card
->dev
,
2588 "ac97 address never arrived\n");
2591 } while ((data
& VORTEX_CODEC_ADDMASK
) !=
2592 (addr
<< VORTEX_CODEC_ADDSHIFT
));
2595 return (u16
) (data
& VORTEX_CODEC_DATMASK
);
2600 static void vortex_spdif_init(vortex_t
* vortex
, int spdif_sr
, int spdif_mode
)
2602 int i
, this_38
= 0, this_04
= 0, this_08
= 0, this_0c
= 0;
2604 /* CAsp4Spdif::InitializeSpdifHardware(void) */
2605 hwwrite(vortex
->mmio
, VORTEX_SPDIF_FLAGS
,
2606 hwread(vortex
->mmio
, VORTEX_SPDIF_FLAGS
) & 0xfff3fffd);
2607 //for (i=0x291D4; i<0x29200; i+=4)
2608 for (i
= 0; i
< 11; i
++)
2609 hwwrite(vortex
->mmio
, VORTEX_SPDIF_CFG1
+ (i
<< 2), 0);
2610 //hwwrite(vortex->mmio, 0x29190, hwread(vortex->mmio, 0x29190) | 0xc0000);
2611 hwwrite(vortex
->mmio
, VORTEX_CODEC_EN
,
2612 hwread(vortex
->mmio
, VORTEX_CODEC_EN
) | EN_SPDIF
);
2614 /* CAsp4Spdif::ProgramSRCInHardware(enum SPDIF_SR,enum SPDIFMODE) */
2615 if (this_04
&& this_08
) {
2618 i
= (((0x5DC00000 / spdif_sr
) + 1) >> 1);
2627 /* this_04 and this_08 are the CASp4Src's (samplerate converters) */
2628 vortex_src_setupchannel(vortex
, this_04
, edi
, 0, 1,
2629 this_0c
, 1, 0, edi
, 1);
2630 vortex_src_setupchannel(vortex
, this_08
, edi
, 0, 1,
2631 this_0c
, 1, 0, edi
, 1);
2638 this_38
&= 0xFFFFFFFE;
2639 this_38
&= 0xFFFFFFFD;
2640 this_38
&= 0xF3FFFFFF;
2641 this_38
|= 0x03000000; /* set 32khz samplerate */
2642 this_38
&= 0xFFFFFF3F;
2643 spdif_sr
&= 0xFFFFFFFD;
2647 this_38
&= 0xFFFFFFFE;
2648 this_38
&= 0xFFFFFFFD;
2649 this_38
&= 0xF0FFFFFF;
2650 this_38
|= 0x03000000;
2651 this_38
&= 0xFFFFFF3F;
2652 spdif_sr
&= 0xFFFFFFFC;
2655 if (spdif_mode
== 1) {
2656 this_38
&= 0xFFFFFFFE;
2657 this_38
&= 0xFFFFFFFD;
2658 this_38
&= 0xF2FFFFFF;
2659 this_38
|= 0x02000000; /* set 48khz samplerate */
2660 this_38
&= 0xFFFFFF3F;
2662 /* J. Gordon Wolfe: I think this stuff is for AC3 */
2663 this_38
|= 0x00000003;
2664 this_38
&= 0xFFFFFFBF;
2668 spdif_sr
&= 0xFFFFFFFE;
2672 /* looks like the next 2 lines transfer a 16-bit value into 2 8-bit
2673 registers. seems to be for the standard IEC/SPDIF initialization
2675 hwwrite(vortex
->mmio
, VORTEX_SPDIF_CFG0
, this_38
& 0xffff);
2676 hwwrite(vortex
->mmio
, VORTEX_SPDIF_CFG1
, this_38
>> 0x10);
2677 hwwrite(vortex
->mmio
, VORTEX_SPDIF_SMPRATE
, spdif_sr
);
2680 /* Initialization */
2682 static int vortex_core_init(vortex_t
*vortex
)
2685 dev_info(vortex
->card
->dev
, "init started\n");
2686 /* Hardware Init. */
2687 hwwrite(vortex
->mmio
, VORTEX_CTRL
, 0xffffffff);
2689 hwwrite(vortex
->mmio
, VORTEX_CTRL
,
2690 hwread(vortex
->mmio
, VORTEX_CTRL
) & 0xffdfffff);
2692 /* Reset IRQ flags */
2693 hwwrite(vortex
->mmio
, VORTEX_IRQ_SOURCE
, 0xffffffff);
2694 hwread(vortex
->mmio
, VORTEX_IRQ_STAT
);
2696 vortex_codec_init(vortex
);
2699 hwwrite(vortex
->mmio
, VORTEX_CTRL
,
2700 hwread(vortex
->mmio
, VORTEX_CTRL
) | 0x1000000);
2703 /* Init audio engine. */
2704 vortex_adbdma_init(vortex
);
2705 hwwrite(vortex
->mmio
, VORTEX_ENGINE_CTRL
, 0x0); //, 0xc83c7e58, 0xc5f93e58
2706 vortex_adb_init(vortex
);
2707 /* Init processing blocks. */
2708 vortex_fifo_init(vortex
);
2709 vortex_mixer_init(vortex
);
2710 vortex_srcblock_init(vortex
);
2712 vortex_eq_init(vortex
);
2713 vortex_spdif_init(vortex
, 48000, 1);
2714 vortex_Vort3D_enable(vortex
);
2717 vortex_wt_init(vortex
);
2719 // Moved to au88x0.c
2720 //vortex_connect_default(vortex, 1);
2722 vortex_settimer(vortex
, 0x90);
2723 // Enable Interrupts.
2724 // vortex_enable_int() must be first !!
2725 // hwwrite(vortex->mmio, VORTEX_IRQ_CTRL, 0);
2726 // vortex_enable_int(vortex);
2727 //vortex_enable_timer_int(vortex);
2728 //vortex_disable_timer_int(vortex);
2730 dev_info(vortex
->card
->dev
, "init.... done.\n");
2731 spin_lock_init(&vortex
->lock
);
2736 static int vortex_core_shutdown(vortex_t
* vortex
)
2739 dev_info(vortex
->card
->dev
, "shutdown started\n");
2741 vortex_eq_free(vortex
);
2742 vortex_Vort3D_disable(vortex
);
2744 //vortex_disable_timer_int(vortex);
2745 vortex_disable_int(vortex
);
2746 vortex_connect_default(vortex
, 0);
2747 /* Reset all DMA fifos. */
2748 vortex_fifo_init(vortex
);
2749 /* Erase all audio routes. */
2750 vortex_adb_init(vortex
);
2752 /* Disable MPU401 */
2753 //hwwrite(vortex->mmio, VORTEX_IRQ_CTRL, hwread(vortex->mmio, VORTEX_IRQ_CTRL) & ~IRQ_MIDI);
2754 //hwwrite(vortex->mmio, VORTEX_CTRL, hwread(vortex->mmio, VORTEX_CTRL) & ~CTRL_MIDI_EN);
2756 hwwrite(vortex
->mmio
, VORTEX_IRQ_CTRL
, 0);
2757 hwwrite(vortex
->mmio
, VORTEX_CTRL
, 0);
2759 hwwrite(vortex
->mmio
, VORTEX_IRQ_SOURCE
, 0xffff);
2761 dev_info(vortex
->card
->dev
, "shutdown.... done.\n");
2767 static int vortex_alsafmt_aspfmt(snd_pcm_format_t alsafmt
, vortex_t
*v
)
2772 case SNDRV_PCM_FORMAT_U8
:
2775 case SNDRV_PCM_FORMAT_MU_LAW
:
2778 case SNDRV_PCM_FORMAT_A_LAW
:
2781 case SNDRV_PCM_FORMAT_SPECIAL
:
2782 fmt
= 0x4; /* guess. */
2784 case SNDRV_PCM_FORMAT_IEC958_SUBFRAME_LE
:
2785 fmt
= 0x5; /* guess. */
2787 case SNDRV_PCM_FORMAT_S16_LE
:
2790 case SNDRV_PCM_FORMAT_S16_BE
:
2791 fmt
= 0x9; /* check this... */
2795 dev_err(v
->card
->dev
,
2796 "format unsupported %d\n", alsafmt
);
2802 /* Some not yet useful translations. */
2805 ASPFMTLINEAR16
= 0, /* 0x8 */
2806 ASPFMTLINEAR8
, /* 0x1 */
2807 ASPFMTULAW
, /* 0x2 */
2808 ASPFMTALAW
, /* 0x3 */
2809 ASPFMTSPORT
, /* ? */
2810 ASPFMTSPDIF
, /* ? */
2814 vortex_translateformat(vortex_t
* vortex
, char bits
, char nch
, int encod
)
2818 if ((bits
!= 8) && (bits
!= 16))
2854 static void vortex_cdmacore_setformat(vortex_t
* vortex
, int bits
, int nch
)
2856 short int d
, this_148
;
2858 d
= ((bits
>> 3) * nch
);
2859 this_148
= 0xbb80 / d
;