1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /***************************************************************************
4 * Aureal Vortex Hardware EQ control/access.
6 * Sun Jun 8 18:19:19 2003
7 * 2003 Manuel Jander (mjander@users.sourceforge.net)
9 * 02 July 2003: First time something works :)
10 * November 2003: A3D Bypass code completed but untested.
14 * - Test peak visualization support.
16 ****************************************************************************/
22 The Aureal Hardware EQ is found on AU8810 and AU8830 chips only.
23 it has 4 inputs (2 for general mix, 2 for A3D) and 2 outputs (supposed
24 to be routed to the codec).
28 #include "au88x0_eq.h"
29 #include "au88x0_eqdata.c"
31 #define VORTEX_EQ_BASE 0x2b000
32 #define VORTEX_EQ_DEST (VORTEX_EQ_BASE + 0x410)
33 #define VORTEX_EQ_SOURCE (VORTEX_EQ_BASE + 0x430)
34 #define VORTEX_EQ_CTRL (VORTEX_EQ_BASE + 0x440)
36 #define VORTEX_BAND_COEFF_SIZE 0x30
39 static void vortex_EqHw_SetTimeConsts(vortex_t * vortex, u16 gain, u16 level)
41 hwwrite(vortex->mmio, 0x2b3c4, gain);
42 hwwrite(vortex->mmio, 0x2b3c8, level);
45 static inline u16 sign_invert(u16 a)
47 /* -(-32768) -> -32768 so we do -(-32768) -> 32767 to make the result positive */
54 static void vortex_EqHw_SetLeftCoefs(vortex_t *vortex, const u16 coefs[])
56 eqhw_t *eqhw = &(vortex->eq.this04);
57 int i = 0, n /*esp2c */;
59 for (n = 0; n < eqhw->this04; n++) {
60 hwwrite(vortex->mmio, 0x2b000 + n * 0x30, coefs[i + 0]);
61 hwwrite(vortex->mmio, 0x2b004 + n * 0x30, coefs[i + 1]);
63 if (eqhw->this08 == 0) {
64 hwwrite(vortex->mmio, 0x2b008 + n * 0x30, coefs[i + 2]);
65 hwwrite(vortex->mmio, 0x2b00c + n * 0x30, coefs[i + 3]);
66 hwwrite(vortex->mmio, 0x2b010 + n * 0x30, coefs[i + 4]);
68 hwwrite(vortex->mmio, 0x2b008 + n * 0x30, sign_invert(coefs[2 + i]));
69 hwwrite(vortex->mmio, 0x2b00c + n * 0x30, sign_invert(coefs[3 + i]));
70 hwwrite(vortex->mmio, 0x2b010 + n * 0x30, sign_invert(coefs[4 + i]));
76 static void vortex_EqHw_SetRightCoefs(vortex_t *vortex, const u16 coefs[])
78 eqhw_t *eqhw = &(vortex->eq.this04);
79 int i = 0, n /*esp2c */;
81 for (n = 0; n < eqhw->this04; n++) {
82 hwwrite(vortex->mmio, 0x2b1e0 + n * 0x30, coefs[0 + i]);
83 hwwrite(vortex->mmio, 0x2b1e4 + n * 0x30, coefs[1 + i]);
85 if (eqhw->this08 == 0) {
86 hwwrite(vortex->mmio, 0x2b1e8 + n * 0x30, coefs[2 + i]);
87 hwwrite(vortex->mmio, 0x2b1ec + n * 0x30, coefs[3 + i]);
88 hwwrite(vortex->mmio, 0x2b1f0 + n * 0x30, coefs[4 + i]);
90 hwwrite(vortex->mmio, 0x2b1e8 + n * 0x30, sign_invert(coefs[2 + i]));
91 hwwrite(vortex->mmio, 0x2b1ec + n * 0x30, sign_invert(coefs[3 + i]));
92 hwwrite(vortex->mmio, 0x2b1f0 + n * 0x30, sign_invert(coefs[4 + i]));
99 static void vortex_EqHw_SetLeftStates(vortex_t *vortex, const u16 a[], const u16 b[])
101 eqhw_t *eqhw = &(vortex->eq.this04);
104 hwwrite(vortex->mmio, 0x2b3fc, a[0]);
105 hwwrite(vortex->mmio, 0x2b400, a[1]);
107 for (ebx = 0; ebx < eqhw->this04; ebx++) {
108 hwwrite(vortex->mmio, 0x2b014 + (i * 0xc), b[i]);
109 hwwrite(vortex->mmio, 0x2b018 + (i * 0xc), b[1 + i]);
110 hwwrite(vortex->mmio, 0x2b01c + (i * 0xc), b[2 + i]);
111 hwwrite(vortex->mmio, 0x2b020 + (i * 0xc), b[3 + i]);
116 static void vortex_EqHw_SetRightStates(vortex_t *vortex, const u16 a[], const u16 b[])
118 eqhw_t *eqhw = &(vortex->eq.this04);
121 hwwrite(vortex->mmio, 0x2b404, a[0]);
122 hwwrite(vortex->mmio, 0x2b408, a[1]);
124 for (ebx = 0; ebx < eqhw->this04; ebx++) {
125 hwwrite(vortex->mmio, 0x2b1f4 + (i * 0xc), b[i]);
126 hwwrite(vortex->mmio, 0x2b1f8 + (i * 0xc), b[1 + i]);
127 hwwrite(vortex->mmio, 0x2b1fc + (i * 0xc), b[2 + i]);
128 hwwrite(vortex->mmio, 0x2b200 + (i * 0xc), b[3 + i]);
134 static void vortex_EqHw_GetTimeConsts(vortex_t * vortex, u16 * a, u16 * b)
136 *a = hwread(vortex->mmio, 0x2b3c4);
137 *b = hwread(vortex->mmio, 0x2b3c8);
140 static void vortex_EqHw_GetLeftCoefs(vortex_t * vortex, u16 a[])
145 static void vortex_EqHw_GetRightCoefs(vortex_t * vortex, u16 a[])
150 static void vortex_EqHw_GetLeftStates(vortex_t * vortex, u16 * a, u16 b[])
155 static void vortex_EqHw_GetRightStates(vortex_t * vortex, u16 * a, u16 b[])
162 static void vortex_EqHw_SetBypassGain(vortex_t * vortex, u16 a, u16 b)
164 eqhw_t *eqhw = &(vortex->eq.this04);
165 if (eqhw->this08 == 0) {
166 hwwrite(vortex->mmio, 0x2b3d4, a);
167 hwwrite(vortex->mmio, 0x2b3ec, b);
169 hwwrite(vortex->mmio, 0x2b3d4, sign_invert(a));
170 hwwrite(vortex->mmio, 0x2b3ec, sign_invert(b));
174 static void vortex_EqHw_SetA3DBypassGain(vortex_t * vortex, u16 a, u16 b)
177 hwwrite(vortex->mmio, 0x2b3e0, a);
178 hwwrite(vortex->mmio, 0x2b3f8, b);
182 static void vortex_EqHw_SetCurrBypassGain(vortex_t * vortex, u16 a, u16 b)
185 hwwrite(vortex->mmio, 0x2b3d0, a);
186 hwwrite(vortex->mmio, 0x2b3e8, b);
189 static void vortex_EqHw_SetCurrA3DBypassGain(vortex_t * vortex, u16 a, u16 b)
192 hwwrite(vortex->mmio, 0x2b3dc, a);
193 hwwrite(vortex->mmio, 0x2b3f4, b);
198 vortex_EqHw_SetLeftGainsSingleTarget(vortex_t * vortex, u16 index, u16 b)
200 hwwrite(vortex->mmio, 0x2b02c + (index * 0x30), b);
204 vortex_EqHw_SetRightGainsSingleTarget(vortex_t * vortex, u16 index, u16 b)
206 hwwrite(vortex->mmio, 0x2b20c + (index * 0x30), b);
209 static void vortex_EqHw_SetLeftGainsTarget(vortex_t *vortex, const u16 a[])
211 eqhw_t *eqhw = &(vortex->eq.this04);
214 for (ebx = 0; ebx < eqhw->this04; ebx++) {
215 hwwrite(vortex->mmio, 0x2b02c + ebx * 0x30, a[ebx]);
219 static void vortex_EqHw_SetRightGainsTarget(vortex_t *vortex, const u16 a[])
221 eqhw_t *eqhw = &(vortex->eq.this04);
224 for (ebx = 0; ebx < eqhw->this04; ebx++) {
225 hwwrite(vortex->mmio, 0x2b20c + ebx * 0x30, a[ebx]);
229 static void vortex_EqHw_SetLeftGainsCurrent(vortex_t *vortex, const u16 a[])
231 eqhw_t *eqhw = &(vortex->eq.this04);
234 for (ebx = 0; ebx < eqhw->this04; ebx++) {
235 hwwrite(vortex->mmio, 0x2b028 + ebx * 0x30, a[ebx]);
239 static void vortex_EqHw_SetRightGainsCurrent(vortex_t *vortex, const u16 a[])
241 eqhw_t *eqhw = &(vortex->eq.this04);
244 for (ebx = 0; ebx < eqhw->this04; ebx++) {
245 hwwrite(vortex->mmio, 0x2b208 + ebx * 0x30, a[ebx]);
250 static void vortex_EqHw_GetLeftGainsTarget(vortex_t * vortex, u16 a[])
252 eqhw_t *eqhw = &(vortex->eq.this04);
255 if (eqhw->this04 < 0)
259 a[ebx] = hwread(vortex->mmio, 0x2b02c + ebx * 0x30);
262 while (ebx < eqhw->this04);
265 static void vortex_EqHw_GetRightGainsTarget(vortex_t * vortex, u16 a[])
267 eqhw_t *eqhw = &(vortex->eq.this04);
270 if (eqhw->this04 < 0)
274 a[ebx] = hwread(vortex->mmio, 0x2b20c + ebx * 0x30);
277 while (ebx < eqhw->this04);
280 static void vortex_EqHw_GetLeftGainsCurrent(vortex_t * vortex, u16 a[])
282 eqhw_t *eqhw = &(vortex->eq.this04);
285 if (eqhw->this04 < 0)
289 a[ebx] = hwread(vortex->mmio, 0x2b028 + ebx * 0x30);
292 while (ebx < eqhw->this04);
295 static void vortex_EqHw_GetRightGainsCurrent(vortex_t * vortex, u16 a[])
297 eqhw_t *eqhw = &(vortex->eq.this04);
300 if (eqhw->this04 < 0)
304 a[ebx] = hwread(vortex->mmio, 0x2b208 + ebx * 0x30);
307 while (ebx < eqhw->this04);
311 /* EQ band levels settings */
312 static void vortex_EqHw_SetLevels(vortex_t *vortex, const u16 peaks[])
314 eqhw_t *eqhw = &(vortex->eq.this04);
318 for (i = 0; i < eqhw->this04; i++) {
319 hwwrite(vortex->mmio, 0x2b024 + i * VORTEX_BAND_COEFF_SIZE, peaks[i]);
322 hwwrite(vortex->mmio, 0x2b3cc, peaks[eqhw->this04]);
323 hwwrite(vortex->mmio, 0x2b3d8, peaks[eqhw->this04 + 1]);
325 /* set right peaks */
326 for (i = 0; i < eqhw->this04; i++) {
327 hwwrite(vortex->mmio, 0x2b204 + i * VORTEX_BAND_COEFF_SIZE,
328 peaks[i + (eqhw->this04 + 2)]);
331 hwwrite(vortex->mmio, 0x2b3e4, peaks[2 + (eqhw->this04 * 2)]);
332 hwwrite(vortex->mmio, 0x2b3f0, peaks[3 + (eqhw->this04 * 2)]);
336 static void vortex_EqHw_GetLevels(vortex_t * vortex, u16 a[])
338 eqhw_t *eqhw = &(vortex->eq.this04);
341 if (eqhw->this04 < 0)
346 a[ebx] = hwread(vortex->mmio, 0x2b024 + ebx * 0x30);
349 while (ebx < eqhw->this04);
351 a[eqhw->this04] = hwread(vortex->mmio, 0x2b3cc);
352 a[eqhw->this04 + 1] = hwread(vortex->mmio, 0x2b3d8);
356 a[ebx + (eqhw->this04 + 2)] =
357 hwread(vortex->mmio, 0x2b204 + ebx * 0x30);
360 while (ebx < eqhw->this04);
362 a[2 + (eqhw->this04 * 2)] = hwread(vortex->mmio, 0x2b3e4);
363 a[3 + (eqhw->this04 * 2)] = hwread(vortex->mmio, 0x2b3f0);
368 static void vortex_EqHw_SetControlReg(vortex_t * vortex, u32 reg)
370 hwwrite(vortex->mmio, 0x2b440, reg);
373 static void vortex_EqHw_SetSampleRate(vortex_t * vortex, u32 sr)
375 hwwrite(vortex->mmio, 0x2b440, ((sr & 0x1f) << 3) | 0xb800);
379 static void vortex_EqHw_GetControlReg(vortex_t * vortex, u32 *reg)
381 *reg = hwread(vortex->mmio, 0x2b440);
384 static void vortex_EqHw_GetSampleRate(vortex_t * vortex, u32 *sr)
386 *sr = (hwread(vortex->mmio, 0x2b440) >> 3) & 0x1f;
390 static void vortex_EqHw_Enable(vortex_t * vortex)
392 hwwrite(vortex->mmio, VORTEX_EQ_CTRL, 0xf001);
395 static void vortex_EqHw_Disable(vortex_t * vortex)
397 hwwrite(vortex->mmio, VORTEX_EQ_CTRL, 0xf000);
400 /* Reset (zero) buffers */
401 static void vortex_EqHw_ZeroIO(vortex_t * vortex)
404 for (i = 0; i < 0x8; i++)
405 hwwrite(vortex->mmio, VORTEX_EQ_DEST + (i << 2), 0x0);
406 for (i = 0; i < 0x4; i++)
407 hwwrite(vortex->mmio, VORTEX_EQ_SOURCE + (i << 2), 0x0);
410 static void vortex_EqHw_ZeroA3DIO(vortex_t * vortex)
413 for (i = 0; i < 0x4; i++)
414 hwwrite(vortex->mmio, VORTEX_EQ_DEST + (i << 2), 0x0);
417 static void vortex_EqHw_ZeroState(vortex_t * vortex)
420 vortex_EqHw_SetControlReg(vortex, 0);
421 vortex_EqHw_ZeroIO(vortex);
422 hwwrite(vortex->mmio, 0x2b3c0, 0);
424 vortex_EqHw_SetTimeConsts(vortex, 0, 0);
426 vortex_EqHw_SetLeftCoefs(vortex, asEqCoefsZeros);
427 vortex_EqHw_SetRightCoefs(vortex, asEqCoefsZeros);
429 vortex_EqHw_SetLeftGainsCurrent(vortex, eq_gains_zero);
430 vortex_EqHw_SetRightGainsCurrent(vortex, eq_gains_zero);
431 vortex_EqHw_SetLeftGainsTarget(vortex, eq_gains_zero);
432 vortex_EqHw_SetRightGainsTarget(vortex, eq_gains_zero);
434 vortex_EqHw_SetBypassGain(vortex, 0, 0);
435 //vortex_EqHw_SetCurrBypassGain(vortex, 0, 0);
436 vortex_EqHw_SetA3DBypassGain(vortex, 0, 0);
437 //vortex_EqHw_SetCurrA3DBypassGain(vortex, 0, 0);
438 vortex_EqHw_SetLeftStates(vortex, eq_states_zero, asEqOutStateZeros);
439 vortex_EqHw_SetRightStates(vortex, eq_states_zero, asEqOutStateZeros);
440 vortex_EqHw_SetLevels(vortex, (u16 *) eq_levels);
443 /* Program coeficients as pass through */
444 static void vortex_EqHw_ProgramPipe(vortex_t * vortex)
446 vortex_EqHw_SetTimeConsts(vortex, 0, 0);
448 vortex_EqHw_SetLeftCoefs(vortex, asEqCoefsPipes);
449 vortex_EqHw_SetRightCoefs(vortex, asEqCoefsPipes);
451 vortex_EqHw_SetLeftGainsCurrent(vortex, eq_gains_current);
452 vortex_EqHw_SetRightGainsCurrent(vortex, eq_gains_current);
453 vortex_EqHw_SetLeftGainsTarget(vortex, eq_gains_current);
454 vortex_EqHw_SetRightGainsTarget(vortex, eq_gains_current);
457 /* Program EQ block as 10 band Equalizer */
459 vortex_EqHw_Program10Band(vortex_t * vortex, auxxEqCoeffSet_t * coefset)
462 vortex_EqHw_SetTimeConsts(vortex, 0xc, 0x7fe0);
464 vortex_EqHw_SetLeftCoefs(vortex, coefset->LeftCoefs);
465 vortex_EqHw_SetRightCoefs(vortex, coefset->RightCoefs);
467 vortex_EqHw_SetLeftGainsCurrent(vortex, coefset->LeftGains);
469 vortex_EqHw_SetRightGainsTarget(vortex, coefset->RightGains);
470 vortex_EqHw_SetLeftGainsTarget(vortex, coefset->LeftGains);
472 vortex_EqHw_SetRightGainsCurrent(vortex, coefset->RightGains);
475 /* Read all EQ peaks. (think VU meter) */
476 static void vortex_EqHw_GetTenBandLevels(vortex_t * vortex, u16 peaks[])
478 eqhw_t *eqhw = &(vortex->eq.this04);
481 if (eqhw->this04 <= 0)
484 for (i = 0; i < eqhw->this04; i++)
485 peaks[i] = hwread(vortex->mmio, 0x2B024 + i * 0x30);
486 for (i = 0; i < eqhw->this04; i++)
487 peaks[i + eqhw->this04] =
488 hwread(vortex->mmio, 0x2B204 + i * 0x30);
493 static int vortex_Eqlzr_GetLeftGain(vortex_t * vortex, u16 index, u16 * gain)
495 eqlzr_t *eq = &(vortex->eq);
498 *gain = eq->this130[index];
504 static void vortex_Eqlzr_SetLeftGain(vortex_t * vortex, u16 index, u16 gain)
506 eqlzr_t *eq = &(vortex->eq);
511 eq->this130[index] = gain;
515 vortex_EqHw_SetLeftGainsSingleTarget(vortex, index, gain);
518 static int vortex_Eqlzr_GetRightGain(vortex_t * vortex, u16 index, u16 * gain)
520 eqlzr_t *eq = &(vortex->eq);
523 *gain = eq->this130[index + eq->this10];
529 static void vortex_Eqlzr_SetRightGain(vortex_t * vortex, u16 index, u16 gain)
531 eqlzr_t *eq = &(vortex->eq);
536 eq->this130[index + eq->this10] = gain;
540 vortex_EqHw_SetRightGainsSingleTarget(vortex, index, gain);
545 vortex_Eqlzr_GetAllBands(vortex_t * vortex, u16 * gains, s32 *cnt)
547 eqlzr_t *eq = &(vortex->eq);
554 if (vortex_Eqlzr_GetLeftGain(vortex, si, &gains[si]))
556 if (vortex_Eqlzr_GetRightGain
557 (vortex, si, &gains[si + eq->this10]))
561 while (eq->this10 > si) ;
566 static int vortex_Eqlzr_SetAllBandsFromActiveCoeffSet(vortex_t * vortex)
568 eqlzr_t *eq = &(vortex->eq);
570 vortex_EqHw_SetLeftGainsTarget(vortex, eq->this130);
571 vortex_EqHw_SetRightGainsTarget(vortex, &(eq->this130[eq->this10]));
577 vortex_Eqlzr_SetAllBands(vortex_t *vortex, const u16 gains[], s32 count)
579 eqlzr_t *eq = &(vortex->eq);
582 if (((eq->this10) * 2 != count) || (eq->this28 == 0))
585 for (i = 0; i < count; i++) {
586 eq->this130[i] = gains[i];
591 return vortex_Eqlzr_SetAllBandsFromActiveCoeffSet(vortex);
595 vortex_Eqlzr_SetA3dBypassGain(vortex_t * vortex, u32 a, u32 b)
597 eqlzr_t *eq = &(vortex->eq);
606 ebx = (eax * eq->this58) >> 0x10;
607 eax = (eax * eq->this5c) >> 0x10;
608 vortex_EqHw_SetA3DBypassGain(vortex, ebx, eax);
611 static void vortex_Eqlzr_ProgramA3dBypassGain(vortex_t * vortex)
613 eqlzr_t *eq = &(vortex->eq);
620 ebx = (eax * eq->this58) >> 0x10;
621 eax = (eax * eq->this5c) >> 0x10;
622 vortex_EqHw_SetA3DBypassGain(vortex, ebx, eax);
625 static void vortex_Eqlzr_ShutDownA3d(vortex_t * vortex)
628 vortex_EqHw_ZeroA3DIO(vortex);
631 static void vortex_Eqlzr_SetBypass(vortex_t * vortex, u32 bp)
633 eqlzr_t *eq = &(vortex->eq);
635 if ((eq->this28) && (bp == 0)) {
637 vortex_Eqlzr_SetAllBandsFromActiveCoeffSet(vortex);
638 vortex_EqHw_SetBypassGain(vortex, eq->this08, eq->this08);
641 vortex_EqHw_SetLeftGainsTarget(vortex, eq->this14_array);
642 vortex_EqHw_SetRightGainsTarget(vortex, eq->this14_array);
643 vortex_EqHw_SetBypassGain(vortex, eq->this0c, eq->this0c);
645 vortex_Eqlzr_ProgramA3dBypassGain(vortex);
648 static void vortex_Eqlzr_ReadAndSetActiveCoefSet(vortex_t * vortex)
650 eqlzr_t *eq = &(vortex->eq);
652 /* Set EQ BiQuad filter coeficients */
653 memcpy(&(eq->coefset), &asEqCoefsNormal, sizeof(auxxEqCoeffSet_t));
654 /* Set EQ Band gain levels and dump into hardware registers. */
655 vortex_Eqlzr_SetAllBands(vortex, eq_gains_normal, eq->this10 * 2);
658 static int vortex_Eqlzr_GetAllPeaks(vortex_t * vortex, u16 * peaks, int *count)
660 eqlzr_t *eq = &(vortex->eq);
664 *count = eq->this10 * 2;
665 vortex_EqHw_GetTenBandLevels(vortex, peaks);
670 static auxxEqCoeffSet_t *vortex_Eqlzr_GetActiveCoefSet(vortex_t * vortex)
672 eqlzr_t *eq = &(vortex->eq);
674 return (&(eq->coefset));
677 static void vortex_Eqlzr_init(vortex_t * vortex)
679 eqlzr_t *eq = &(vortex->eq);
681 /* Object constructor */
683 eq->this08 = 0; /* Bypass gain with EQ in use. */
685 eq->this0c = 0x5999; /* Bypass gain with EQ disabled. */
688 eq->this10 = 0xa; /* 10 eq frequency bands. */
689 eq->this04.this04 = eq->this10;
690 eq->this28 = 0x1; /* if 1 => Allow read access to this130 (gains) */
691 eq->this54 = 0x0; /* if 1 => Dont Allow access to hardware (gains) */
696 memset(eq->this14_array, 0, sizeof(eq->this14_array));
699 vortex_EqHw_ZeroState(vortex);
700 vortex_EqHw_SetSampleRate(vortex, 0x11);
701 vortex_Eqlzr_ReadAndSetActiveCoefSet(vortex);
703 vortex_EqHw_Program10Band(vortex, &(eq->coefset));
704 vortex_Eqlzr_SetBypass(vortex, eq->this54);
705 vortex_Eqlzr_SetA3dBypassGain(vortex, 0, 0);
706 vortex_EqHw_Enable(vortex);
709 static void vortex_Eqlzr_shutdown(vortex_t * vortex)
711 vortex_Eqlzr_ShutDownA3d(vortex);
712 vortex_EqHw_ProgramPipe(vortex);
713 vortex_EqHw_Disable(vortex);
718 /* Control interface */
719 #define snd_vortex_eqtoggle_info snd_ctl_boolean_mono_info
722 snd_vortex_eqtoggle_get(struct snd_kcontrol *kcontrol,
723 struct snd_ctl_elem_value *ucontrol)
725 vortex_t *vortex = snd_kcontrol_chip(kcontrol);
726 eqlzr_t *eq = &(vortex->eq);
727 //int i = kcontrol->private_value;
729 ucontrol->value.integer.value[0] = eq->this54 ? 0 : 1;
735 snd_vortex_eqtoggle_put(struct snd_kcontrol *kcontrol,
736 struct snd_ctl_elem_value *ucontrol)
738 vortex_t *vortex = snd_kcontrol_chip(kcontrol);
739 eqlzr_t *eq = &(vortex->eq);
740 //int i = kcontrol->private_value;
742 eq->this54 = ucontrol->value.integer.value[0] ? 0 : 1;
743 vortex_Eqlzr_SetBypass(vortex, eq->this54);
745 return 1; /* Allways changes */
748 static const struct snd_kcontrol_new vortex_eqtoggle_kcontrol = {
749 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
752 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
754 .info = snd_vortex_eqtoggle_info,
755 .get = snd_vortex_eqtoggle_get,
756 .put = snd_vortex_eqtoggle_put
760 snd_vortex_eq_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
762 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
764 uinfo->value.integer.min = 0x0000;
765 uinfo->value.integer.max = 0x7fff;
770 snd_vortex_eq_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
772 vortex_t *vortex = snd_kcontrol_chip(kcontrol);
773 int i = kcontrol->private_value;
774 u16 gainL = 0, gainR = 0;
776 vortex_Eqlzr_GetLeftGain(vortex, i, &gainL);
777 vortex_Eqlzr_GetRightGain(vortex, i, &gainR);
778 ucontrol->value.integer.value[0] = gainL;
779 ucontrol->value.integer.value[1] = gainR;
784 snd_vortex_eq_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
786 vortex_t *vortex = snd_kcontrol_chip(kcontrol);
787 int changed = 0, i = kcontrol->private_value;
788 u16 gainL = 0, gainR = 0;
790 vortex_Eqlzr_GetLeftGain(vortex, i, &gainL);
791 vortex_Eqlzr_GetRightGain(vortex, i, &gainR);
793 if (gainL != ucontrol->value.integer.value[0]) {
794 vortex_Eqlzr_SetLeftGain(vortex, i,
795 ucontrol->value.integer.value[0]);
798 if (gainR != ucontrol->value.integer.value[1]) {
799 vortex_Eqlzr_SetRightGain(vortex, i,
800 ucontrol->value.integer.value[1]);
806 static const struct snd_kcontrol_new vortex_eq_kcontrol = {
807 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
810 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
812 .info = snd_vortex_eq_info,
813 .get = snd_vortex_eq_get,
814 .put = snd_vortex_eq_put
818 snd_vortex_peaks_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
820 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
822 uinfo->value.integer.min = 0x0000;
823 uinfo->value.integer.max = 0x7fff;
828 snd_vortex_peaks_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
830 vortex_t *vortex = snd_kcontrol_chip(kcontrol);
834 vortex_Eqlzr_GetAllPeaks(vortex, peaks, &count);
836 dev_err(vortex->card->dev,
837 "peak count error 20 != %d\n", count);
840 for (i = 0; i < 20; i++)
841 ucontrol->value.integer.value[i] = peaks[i];
846 static const struct snd_kcontrol_new vortex_levels_kcontrol = {
847 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
849 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
850 .info = snd_vortex_peaks_info,
851 .get = snd_vortex_peaks_get,
854 /* EQ band gain labels. */
855 static const char * const EqBandLabels[10] = {
868 /* ALSA driver entry points. Init and exit. */
869 static int vortex_eq_init(vortex_t *vortex)
871 struct snd_kcontrol *kcontrol;
874 vortex_Eqlzr_init(vortex);
876 kcontrol = snd_ctl_new1(&vortex_eqtoggle_kcontrol, vortex);
879 kcontrol->private_value = 0;
880 err = snd_ctl_add(vortex->card, kcontrol);
884 /* EQ gain controls */
885 for (i = 0; i < 10; i++) {
886 kcontrol = snd_ctl_new1(&vortex_eq_kcontrol, vortex);
889 snprintf(kcontrol->id.name, sizeof(kcontrol->id.name),
890 "%s Playback Volume", EqBandLabels[i]);
891 kcontrol->private_value = i;
892 err = snd_ctl_add(vortex->card, kcontrol);
895 //vortex->eqctrl[i] = kcontrol;
898 kcontrol = snd_ctl_new1(&vortex_levels_kcontrol, vortex);
901 err = snd_ctl_add(vortex->card, kcontrol);
908 static int vortex_eq_free(vortex_t * vortex)
911 //FIXME: segfault because vortex->eqctrl[i] == 4
913 for (i=0; i<10; i++) {
914 if (vortex->eqctrl[i])
915 snd_ctl_remove(vortex->card, vortex->eqctrl[i]);
918 vortex_Eqlzr_shutdown(vortex);