1 // SPDX-License-Identifier: GPL-2.0-or-later
6 * Someday its supposed to make use of the WT DMA engine
7 * for a Wavetable synthesizer.
11 #include "au88x0_wt.h"
13 static void vortex_fifo_setwtvalid(vortex_t * vortex, int fifo, int en);
14 static void vortex_connection_adb_mixin(vortex_t * vortex, int en,
15 unsigned char channel,
18 static void vortex_connection_mixin_mix(vortex_t * vortex, int en,
20 unsigned char mix, int a);
21 static void vortex_fifo_wtinitialize(vortex_t * vortex, int fifo, int j);
22 static int vortex_wt_SetReg(vortex_t * vortex, unsigned char reg, int wt,
27 /* Put 2 WT channels together for one stereo interlaced channel. */
28 static void vortex_wt_setstereo(vortex_t * vortex, u32 wt, u32 stereo)
32 //temp = hwread(vortex->mmio, 0x80 + ((wt >> 0x5)<< 0xf) + (((wt & 0x1f) >> 1) << 2));
33 temp = hwread(vortex->mmio, WT_STEREO(wt));
34 temp = (temp & 0xfe) | (stereo & 1);
35 //hwwrite(vortex->mmio, 0x80 + ((wt >> 0x5)<< 0xf) + (((wt & 0x1f) >> 1) << 2), temp);
36 hwwrite(vortex->mmio, WT_STEREO(wt), temp);
39 /* Join to mixdown route. */
40 static void vortex_wt_setdsout(vortex_t * vortex, u32 wt, int en)
44 /* There is one DSREG register for each bank (32 voices each). */
45 temp = hwread(vortex->mmio, WT_DSREG((wt >= 0x20) ? 1 : 0));
47 temp |= (1 << (wt & 0x1f));
49 temp &= ~(1 << (wt & 0x1f));
50 hwwrite(vortex->mmio, WT_DSREG((wt >= 0x20) ? 1 : 0), temp);
54 static int vortex_wt_allocroute(vortex_t * vortex, int wt, int nr_ch)
56 wt_voice_t *voice = &(vortex->wt_voice[wt]);
59 //FIXME: WT audio routing.
61 vortex_fifo_wtinitialize(vortex, wt, 1);
62 vortex_fifo_setwtvalid(vortex, wt, 1);
63 vortex_wt_setstereo(vortex, wt, nr_ch - 1);
65 vortex_fifo_setwtvalid(vortex, wt, 0);
67 /* Set mixdown mode. */
68 vortex_wt_setdsout(vortex, wt, 1);
69 /* Set other parameter registers. */
70 hwwrite(vortex->mmio, WT_SRAMP(0), 0x880000);
71 //hwwrite(vortex->mmio, WT_GMODE(0), 0xffffffff);
73 hwwrite(vortex->mmio, WT_SRAMP(1), 0x880000);
74 //hwwrite(vortex->mmio, WT_GMODE(1), 0xffffffff);
76 hwwrite(vortex->mmio, WT_PARM(wt, 0), 0);
77 hwwrite(vortex->mmio, WT_PARM(wt, 1), 0);
78 hwwrite(vortex->mmio, WT_PARM(wt, 2), 0);
80 temp = hwread(vortex->mmio, WT_PARM(wt, 3));
81 dev_dbg(vortex->card->dev, "WT PARM3: %x\n", temp);
82 //hwwrite(vortex->mmio, WT_PARM(wt, 3), temp);
84 hwwrite(vortex->mmio, WT_DELAY(wt, 0), 0);
85 hwwrite(vortex->mmio, WT_DELAY(wt, 1), 0);
86 hwwrite(vortex->mmio, WT_DELAY(wt, 2), 0);
87 hwwrite(vortex->mmio, WT_DELAY(wt, 3), 0);
89 dev_dbg(vortex->card->dev, "WT GMODE: %x\n",
90 hwread(vortex->mmio, WT_GMODE(wt)));
92 hwwrite(vortex->mmio, WT_PARM(wt, 2), 0xffffffff);
93 hwwrite(vortex->mmio, WT_PARM(wt, 3), 0xcff1c810);
95 voice->parm0 = voice->parm1 = 0xcfb23e2f;
96 hwwrite(vortex->mmio, WT_PARM(wt, 0), voice->parm0);
97 hwwrite(vortex->mmio, WT_PARM(wt, 1), voice->parm1);
98 dev_dbg(vortex->card->dev, "WT GMODE 2 : %x\n",
99 hwread(vortex->mmio, WT_GMODE(wt)));
104 static void vortex_wt_connect(vortex_t * vortex, int en)
108 #define NR_WTROUTES 6
110 #define NR_WTBLOCKS 2
112 #define NR_WTBLOCKS 1
115 for (i = 0; i < NR_WTBLOCKS; i++) {
116 for (ii = 0; ii < NR_WTROUTES; ii++) {
118 vortex_adb_checkinout(vortex,
119 vortex->fixed_res, en,
120 VORTEX_RESOURCE_MIXIN);
121 vortex->mixwt[(i * NR_WTROUTES) + ii] = mix;
123 vortex_route(vortex, en, 0x11,
124 ADB_WTOUT(i, ii + 0x20), ADB_MIXIN(mix));
126 vortex_connection_mixin_mix(vortex, en, mix,
127 vortex->mixplayb[ii % 2], 0);
128 if (VORTEX_IS_QUAD(vortex))
129 vortex_connection_mixin_mix(vortex, en,
135 for (i = 0; i < NR_WT; i++) {
136 hwwrite(vortex->mmio, WT_RUN(i), 1);
140 /* Read WT Register */
142 static int vortex_wt_GetReg(vortex_t * vortex, char reg, int wt)
147 return hwread(vortex->mmio, WT_PARM(wt, 3));
150 return hwread(vortex->mmio, WT_GMODE(wt));
156 /* WT hardware abstraction layer generic register interface. */
158 vortex_wt_SetReg2(vortex_t * vortex, unsigned char reg, int wt,
164 if (wt >= NR_WT) // 0x40 -> NR_WT
167 if ((reg - 0x20) > 0) {
168 if ((reg - 0x21) != 0)
170 eax = ((((b & 0xff) << 0xb) + (edx & 0xff)) << 4) + 0x208; // param 2
172 eax = ((((b & 0xff) << 0xb) + (edx & 0xff)) << 4) + 0x20a; // param 3
174 hwwrite(vortex->mmio, eax, c);
179 /*public: static void __thiscall CWTHal::SetReg(unsigned char,int,unsigned long) */
182 vortex_wt_SetReg(vortex_t * vortex, unsigned char reg, int wt,
187 if ((reg == 5) || ((reg >= 7) && (reg <= 10)) || (reg == 0xc)) {
188 if (wt >= (NR_WT / NR_WT_PB)) {
189 dev_warn(vortex->card->dev,
190 "WT SetReg: bank out of range. reg=0x%x, wt=%d\n",
196 dev_err(vortex->card->dev,
197 "WT SetReg: voice out of range\n");
205 /* Voice specific parameters */
206 case 0: /* running */
208 pr_debug( "vortex: WT SetReg(0x%x) = 0x%08x\n",
209 WT_RUN(wt), (int)val);
211 hwwrite(vortex->mmio, WT_RUN(wt), val);
213 case 1: /* param 0 */
215 pr_debug( "vortex: WT SetReg(0x%x) = 0x%08x\n",
216 WT_PARM(wt,0), (int)val);
218 hwwrite(vortex->mmio, WT_PARM(wt, 0), val);
220 case 2: /* param 1 */
222 pr_debug( "vortex: WT SetReg(0x%x) = 0x%08x\n",
223 WT_PARM(wt,1), (int)val);
225 hwwrite(vortex->mmio, WT_PARM(wt, 1), val);
227 case 3: /* param 2 */
229 pr_debug( "vortex: WT SetReg(0x%x) = 0x%08x\n",
230 WT_PARM(wt,2), (int)val);
232 hwwrite(vortex->mmio, WT_PARM(wt, 2), val);
234 case 4: /* param 3 */
236 pr_debug( "vortex: WT SetReg(0x%x) = 0x%08x\n",
237 WT_PARM(wt,3), (int)val);
239 hwwrite(vortex->mmio, WT_PARM(wt, 3), val);
243 pr_debug( "vortex: WT SetReg(0x%x) = 0x%08x\n",
244 WT_MUTE(wt), (int)val);
246 hwwrite(vortex->mmio, WT_MUTE(wt), val);
251 pr_debug( "vortex: WT SetReg(0x%x) = 0x%08x\n",
252 WT_DELAY(wt,0), (int)val);
254 hwwrite(vortex->mmio, WT_DELAY(wt, 3), val);
255 hwwrite(vortex->mmio, WT_DELAY(wt, 2), val);
256 hwwrite(vortex->mmio, WT_DELAY(wt, 1), val);
257 hwwrite(vortex->mmio, WT_DELAY(wt, 0), val);
259 /* Global WT block parameters */
272 case 0xc: /* ds_reg */
279 pr_debug( "vortex: WT SetReg(0x%x) = 0x%08x\n", ecx, (int)val);
281 hwwrite(vortex->mmio, ecx, val);
285 static void vortex_wt_init(vortex_t * vortex)
287 u32 var4, var8, varc, var10 = 0, edi;
302 /* Init Bank registers. */
303 for (edi = 0; edi < (NR_WT / NR_WT_PB); edi++) {
304 vortex_wt_SetReg(vortex, 0xc, edi, 0); /* ds_reg */
305 vortex_wt_SetReg(vortex, 0xa, edi, var10); /* ctrl */
306 vortex_wt_SetReg(vortex, 0x9, edi, var4); /* mramp */
307 vortex_wt_SetReg(vortex, 0x8, edi, varc); /* aramp */
308 vortex_wt_SetReg(vortex, 0x5, edi, var8); /* sramp */
310 /* Init Voice registers. */
311 for (edi = 0; edi < NR_WT; edi++) {
312 vortex_wt_SetReg(vortex, 0x4, edi, 0); /* param 3 0x20c */
313 vortex_wt_SetReg(vortex, 0x3, edi, 0); /* param 2 0x208 */
314 vortex_wt_SetReg(vortex, 0x2, edi, 0); /* param 1 0x204 */
315 vortex_wt_SetReg(vortex, 0x1, edi, 0); /* param 0 0x200 */
316 vortex_wt_SetReg(vortex, 0xb, edi, 0); /* delay 0x400 - 0x40c */
319 for (edi = 0; edi < (NR_WT / NR_WT_PB); edi++)
320 vortex_wt_SetReg(vortex, 0xa, edi, var10); /* ctrl */
323 /* Extract of CAdbTopology::SetVolume(struct _ASPVOLUME *) */
325 static void vortex_wt_SetVolume(vortex_t * vortex, int wt, int vol[])
327 wt_voice_t *voice = &(vortex->wt_voice[wt]);
328 int ecx = vol[1], eax = vol[0];
330 /* This is pure guess */
331 voice->parm0 &= 0xff00ffff;
332 voice->parm0 |= (vol[0] & 0xff) << 0x10;
333 voice->parm1 &= 0xff00ffff;
334 voice->parm1 |= (vol[1] & 0xff) << 0x10;
337 hwwrite(vortex, WT_PARM(wt, 0), voice->parm0);
338 hwwrite(vortex, WT_PARM(wt, 1), voice->parm0);
340 if (voice->this_1D0 & 4) {
345 voice->parm3 &= 0xFFFFC07F;
346 voice->parm3 |= (ecx & 0x7f) << 7;
347 voice->parm3 &= 0xFFFFFF80;
348 voice->parm3 |= (eax & 0x7f);
350 voice->parm3 &= 0xFFE03FFF;
351 voice->parm3 |= (eax & 0xFE00) << 5;
354 hwwrite(vortex, WT_PARM(wt, 3), voice->parm3);
357 /* Extract of CAdbTopology::SetFrequency(unsigned long arg_0) */
358 static void vortex_wt_SetFrequency(vortex_t * vortex, int wt, unsigned int sr)
360 wt_voice_t *voice = &(vortex->wt_voice[wt]);
363 //FIXME: 64 bit operation.
364 eax = ((sr << 0xf) * 0x57619F1) & 0xffffffff;
365 edx = (((sr << 0xf) * 0x57619F1)) >> 0x20;
370 if (edx & 0x0FFF80000)
375 while ((edx & 0x80000000) == 0) {
389 voice->parm0 &= 0xffff0001;
390 voice->parm0 |= (eax & 0x7fff) << 1;
391 voice->parm1 = voice->parm0 | 1;
393 //AuWt::WriteReg((ulong)(this_1DC<<4)+0x200, (ulong)this_1E4);
394 //AuWt::WriteReg((ulong)(this_1DC<<4)+0x204, (ulong)this_1E8);
395 hwwrite(vortex->mmio, WT_PARM(wt, 0), voice->parm0);
396 hwwrite(vortex->mmio, WT_PARM(wt, 1), voice->parm1);