au88x0_eq.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /***************************************************************************
  3. * au88x0_eq.c
  4. * Aureal Vortex Hardware EQ control/access.
  5. *
  6. * Sun Jun 8 18:19:19 2003
  7. * 2003 Manuel Jander ([email protected])
  8. *
  9. * 02 July 2003: First time something works :)
  10. * November 2003: A3D Bypass code completed but untested.
  11. *
  12. * TODO:
  13. * - Debug (testing)
  14. * - Test peak visualization support.
  15. *
  16. ****************************************************************************/
  17. /*
  18. */
  19. /*
  20. The Aureal Hardware EQ is found on AU8810 and AU8830 chips only.
  21. it has 4 inputs (2 for general mix, 2 for A3D) and 2 outputs (supposed
  22. to be routed to the codec).
  23. */
  24. #include "au88x0.h"
  25. #include "au88x0_eq.h"
  26. #include "au88x0_eqdata.c"
  27. #define VORTEX_EQ_BASE 0x2b000
  28. #define VORTEX_EQ_DEST (VORTEX_EQ_BASE + 0x410)
  29. #define VORTEX_EQ_SOURCE (VORTEX_EQ_BASE + 0x430)
  30. #define VORTEX_EQ_CTRL (VORTEX_EQ_BASE + 0x440)
  31. #define VORTEX_BAND_COEFF_SIZE 0x30
  32. /* CEqHw.s */
  33. static void vortex_EqHw_SetTimeConsts(vortex_t * vortex, u16 gain, u16 level)
  34. {
  35. hwwrite(vortex->mmio, 0x2b3c4, gain);
  36. hwwrite(vortex->mmio, 0x2b3c8, level);
  37. }
  38. static inline u16 sign_invert(u16 a)
  39. {
  40. /* -(-32768) -> -32768 so we do -(-32768) -> 32767 to make the result positive */
  41. if (a == (u16)-32768)
  42. return 32767;
  43. else
  44. return -a;
  45. }
  46. static void vortex_EqHw_SetLeftCoefs(vortex_t *vortex, const u16 coefs[])
  47. {
  48. eqhw_t *eqhw = &(vortex->eq.this04);
  49. int i = 0, n /*esp2c */;
  50. for (n = 0; n < eqhw->this04; n++) {
  51. hwwrite(vortex->mmio, 0x2b000 + n * 0x30, coefs[i + 0]);
  52. hwwrite(vortex->mmio, 0x2b004 + n * 0x30, coefs[i + 1]);
  53. if (eqhw->this08 == 0) {
  54. hwwrite(vortex->mmio, 0x2b008 + n * 0x30, coefs[i + 2]);
  55. hwwrite(vortex->mmio, 0x2b00c + n * 0x30, coefs[i + 3]);
  56. hwwrite(vortex->mmio, 0x2b010 + n * 0x30, coefs[i + 4]);
  57. } else {
  58. hwwrite(vortex->mmio, 0x2b008 + n * 0x30, sign_invert(coefs[2 + i]));
  59. hwwrite(vortex->mmio, 0x2b00c + n * 0x30, sign_invert(coefs[3 + i]));
  60. hwwrite(vortex->mmio, 0x2b010 + n * 0x30, sign_invert(coefs[4 + i]));
  61. }
  62. i += 5;
  63. }
  64. }
  65. static void vortex_EqHw_SetRightCoefs(vortex_t *vortex, const u16 coefs[])
  66. {
  67. eqhw_t *eqhw = &(vortex->eq.this04);
  68. int i = 0, n /*esp2c */;
  69. for (n = 0; n < eqhw->this04; n++) {
  70. hwwrite(vortex->mmio, 0x2b1e0 + n * 0x30, coefs[0 + i]);
  71. hwwrite(vortex->mmio, 0x2b1e4 + n * 0x30, coefs[1 + i]);
  72. if (eqhw->this08 == 0) {
  73. hwwrite(vortex->mmio, 0x2b1e8 + n * 0x30, coefs[2 + i]);
  74. hwwrite(vortex->mmio, 0x2b1ec + n * 0x30, coefs[3 + i]);
  75. hwwrite(vortex->mmio, 0x2b1f0 + n * 0x30, coefs[4 + i]);
  76. } else {
  77. hwwrite(vortex->mmio, 0x2b1e8 + n * 0x30, sign_invert(coefs[2 + i]));
  78. hwwrite(vortex->mmio, 0x2b1ec + n * 0x30, sign_invert(coefs[3 + i]));
  79. hwwrite(vortex->mmio, 0x2b1f0 + n * 0x30, sign_invert(coefs[4 + i]));
  80. }
  81. i += 5;
  82. }
  83. }
  84. static void vortex_EqHw_SetLeftStates(vortex_t *vortex, const u16 a[], const u16 b[])
  85. {
  86. eqhw_t *eqhw = &(vortex->eq.this04);
  87. int i = 0, ebx;
  88. hwwrite(vortex->mmio, 0x2b3fc, a[0]);
  89. hwwrite(vortex->mmio, 0x2b400, a[1]);
  90. for (ebx = 0; ebx < eqhw->this04; ebx++) {
  91. hwwrite(vortex->mmio, 0x2b014 + (i * 0xc), b[i]);
  92. hwwrite(vortex->mmio, 0x2b018 + (i * 0xc), b[1 + i]);
  93. hwwrite(vortex->mmio, 0x2b01c + (i * 0xc), b[2 + i]);
  94. hwwrite(vortex->mmio, 0x2b020 + (i * 0xc), b[3 + i]);
  95. i += 4;
  96. }
  97. }
  98. static void vortex_EqHw_SetRightStates(vortex_t *vortex, const u16 a[], const u16 b[])
  99. {
  100. eqhw_t *eqhw = &(vortex->eq.this04);
  101. int i = 0, ebx;
  102. hwwrite(vortex->mmio, 0x2b404, a[0]);
  103. hwwrite(vortex->mmio, 0x2b408, a[1]);
  104. for (ebx = 0; ebx < eqhw->this04; ebx++) {
  105. hwwrite(vortex->mmio, 0x2b1f4 + (i * 0xc), b[i]);
  106. hwwrite(vortex->mmio, 0x2b1f8 + (i * 0xc), b[1 + i]);
  107. hwwrite(vortex->mmio, 0x2b1fc + (i * 0xc), b[2 + i]);
  108. hwwrite(vortex->mmio, 0x2b200 + (i * 0xc), b[3 + i]);
  109. i += 4;
  110. }
  111. }
  112. #if 0
  113. static void vortex_EqHw_GetTimeConsts(vortex_t * vortex, u16 * a, u16 * b)
  114. {
  115. *a = hwread(vortex->mmio, 0x2b3c4);
  116. *b = hwread(vortex->mmio, 0x2b3c8);
  117. }
  118. static void vortex_EqHw_GetLeftCoefs(vortex_t * vortex, u16 a[])
  119. {
  120. }
  121. static void vortex_EqHw_GetRightCoefs(vortex_t * vortex, u16 a[])
  122. {
  123. }
  124. static void vortex_EqHw_GetLeftStates(vortex_t * vortex, u16 * a, u16 b[])
  125. {
  126. }
  127. static void vortex_EqHw_GetRightStates(vortex_t * vortex, u16 * a, u16 b[])
  128. {
  129. }
  130. #endif
  131. /* Mix Gains */
  132. static void vortex_EqHw_SetBypassGain(vortex_t * vortex, u16 a, u16 b)
  133. {
  134. eqhw_t *eqhw = &(vortex->eq.this04);
  135. if (eqhw->this08 == 0) {
  136. hwwrite(vortex->mmio, 0x2b3d4, a);
  137. hwwrite(vortex->mmio, 0x2b3ec, b);
  138. } else {
  139. hwwrite(vortex->mmio, 0x2b3d4, sign_invert(a));
  140. hwwrite(vortex->mmio, 0x2b3ec, sign_invert(b));
  141. }
  142. }
  143. static void vortex_EqHw_SetA3DBypassGain(vortex_t * vortex, u16 a, u16 b)
  144. {
  145. hwwrite(vortex->mmio, 0x2b3e0, a);
  146. hwwrite(vortex->mmio, 0x2b3f8, b);
  147. }
  148. #if 0
  149. static void vortex_EqHw_SetCurrBypassGain(vortex_t * vortex, u16 a, u16 b)
  150. {
  151. hwwrite(vortex->mmio, 0x2b3d0, a);
  152. hwwrite(vortex->mmio, 0x2b3e8, b);
  153. }
  154. static void vortex_EqHw_SetCurrA3DBypassGain(vortex_t * vortex, u16 a, u16 b)
  155. {
  156. hwwrite(vortex->mmio, 0x2b3dc, a);
  157. hwwrite(vortex->mmio, 0x2b3f4, b);
  158. }
  159. #endif
  160. static void
  161. vortex_EqHw_SetLeftGainsSingleTarget(vortex_t * vortex, u16 index, u16 b)
  162. {
  163. hwwrite(vortex->mmio, 0x2b02c + (index * 0x30), b);
  164. }
  165. static void
  166. vortex_EqHw_SetRightGainsSingleTarget(vortex_t * vortex, u16 index, u16 b)
  167. {
  168. hwwrite(vortex->mmio, 0x2b20c + (index * 0x30), b);
  169. }
  170. static void vortex_EqHw_SetLeftGainsTarget(vortex_t *vortex, const u16 a[])
  171. {
  172. eqhw_t *eqhw = &(vortex->eq.this04);
  173. int ebx;
  174. for (ebx = 0; ebx < eqhw->this04; ebx++) {
  175. hwwrite(vortex->mmio, 0x2b02c + ebx * 0x30, a[ebx]);
  176. }
  177. }
  178. static void vortex_EqHw_SetRightGainsTarget(vortex_t *vortex, const u16 a[])
  179. {
  180. eqhw_t *eqhw = &(vortex->eq.this04);
  181. int ebx;
  182. for (ebx = 0; ebx < eqhw->this04; ebx++) {
  183. hwwrite(vortex->mmio, 0x2b20c + ebx * 0x30, a[ebx]);
  184. }
  185. }
  186. static void vortex_EqHw_SetLeftGainsCurrent(vortex_t *vortex, const u16 a[])
  187. {
  188. eqhw_t *eqhw = &(vortex->eq.this04);
  189. int ebx;
  190. for (ebx = 0; ebx < eqhw->this04; ebx++) {
  191. hwwrite(vortex->mmio, 0x2b028 + ebx * 0x30, a[ebx]);
  192. }
  193. }
  194. static void vortex_EqHw_SetRightGainsCurrent(vortex_t *vortex, const u16 a[])
  195. {
  196. eqhw_t *eqhw = &(vortex->eq.this04);
  197. int ebx;
  198. for (ebx = 0; ebx < eqhw->this04; ebx++) {
  199. hwwrite(vortex->mmio, 0x2b208 + ebx * 0x30, a[ebx]);
  200. }
  201. }
  202. #if 0
  203. static void vortex_EqHw_GetLeftGainsTarget(vortex_t * vortex, u16 a[])
  204. {
  205. eqhw_t *eqhw = &(vortex->eq.this04);
  206. int ebx = 0;
  207. if (eqhw->this04 < 0)
  208. return;
  209. do {
  210. a[ebx] = hwread(vortex->mmio, 0x2b02c + ebx * 0x30);
  211. ebx++;
  212. }
  213. while (ebx < eqhw->this04);
  214. }
  215. static void vortex_EqHw_GetRightGainsTarget(vortex_t * vortex, u16 a[])
  216. {
  217. eqhw_t *eqhw = &(vortex->eq.this04);
  218. int ebx = 0;
  219. if (eqhw->this04 < 0)
  220. return;
  221. do {
  222. a[ebx] = hwread(vortex->mmio, 0x2b20c + ebx * 0x30);
  223. ebx++;
  224. }
  225. while (ebx < eqhw->this04);
  226. }
  227. static void vortex_EqHw_GetLeftGainsCurrent(vortex_t * vortex, u16 a[])
  228. {
  229. eqhw_t *eqhw = &(vortex->eq.this04);
  230. int ebx = 0;
  231. if (eqhw->this04 < 0)
  232. return;
  233. do {
  234. a[ebx] = hwread(vortex->mmio, 0x2b028 + ebx * 0x30);
  235. ebx++;
  236. }
  237. while (ebx < eqhw->this04);
  238. }
  239. static void vortex_EqHw_GetRightGainsCurrent(vortex_t * vortex, u16 a[])
  240. {
  241. eqhw_t *eqhw = &(vortex->eq.this04);
  242. int ebx = 0;
  243. if (eqhw->this04 < 0)
  244. return;
  245. do {
  246. a[ebx] = hwread(vortex->mmio, 0x2b208 + ebx * 0x30);
  247. ebx++;
  248. }
  249. while (ebx < eqhw->this04);
  250. }
  251. #endif
  252. /* EQ band levels settings */
  253. static void vortex_EqHw_SetLevels(vortex_t *vortex, const u16 peaks[])
  254. {
  255. eqhw_t *eqhw = &(vortex->eq.this04);
  256. int i;
  257. /* set left peaks */
  258. for (i = 0; i < eqhw->this04; i++) {
  259. hwwrite(vortex->mmio, 0x2b024 + i * VORTEX_BAND_COEFF_SIZE, peaks[i]);
  260. }
  261. hwwrite(vortex->mmio, 0x2b3cc, peaks[eqhw->this04]);
  262. hwwrite(vortex->mmio, 0x2b3d8, peaks[eqhw->this04 + 1]);
  263. /* set right peaks */
  264. for (i = 0; i < eqhw->this04; i++) {
  265. hwwrite(vortex->mmio, 0x2b204 + i * VORTEX_BAND_COEFF_SIZE,
  266. peaks[i + (eqhw->this04 + 2)]);
  267. }
  268. hwwrite(vortex->mmio, 0x2b3e4, peaks[2 + (eqhw->this04 * 2)]);
  269. hwwrite(vortex->mmio, 0x2b3f0, peaks[3 + (eqhw->this04 * 2)]);
  270. }
  271. #if 0
  272. static void vortex_EqHw_GetLevels(vortex_t * vortex, u16 a[])
  273. {
  274. eqhw_t *eqhw = &(vortex->eq.this04);
  275. int ebx;
  276. if (eqhw->this04 < 0)
  277. return;
  278. ebx = 0;
  279. do {
  280. a[ebx] = hwread(vortex->mmio, 0x2b024 + ebx * 0x30);
  281. ebx++;
  282. }
  283. while (ebx < eqhw->this04);
  284. a[eqhw->this04] = hwread(vortex->mmio, 0x2b3cc);
  285. a[eqhw->this04 + 1] = hwread(vortex->mmio, 0x2b3d8);
  286. ebx = 0;
  287. do {
  288. a[ebx + (eqhw->this04 + 2)] =
  289. hwread(vortex->mmio, 0x2b204 + ebx * 0x30);
  290. ebx++;
  291. }
  292. while (ebx < eqhw->this04);
  293. a[2 + (eqhw->this04 * 2)] = hwread(vortex->mmio, 0x2b3e4);
  294. a[3 + (eqhw->this04 * 2)] = hwread(vortex->mmio, 0x2b3f0);
  295. }
  296. #endif
  297. /* Global Control */
  298. static void vortex_EqHw_SetControlReg(vortex_t * vortex, u32 reg)
  299. {
  300. hwwrite(vortex->mmio, 0x2b440, reg);
  301. }
  302. static void vortex_EqHw_SetSampleRate(vortex_t * vortex, u32 sr)
  303. {
  304. hwwrite(vortex->mmio, 0x2b440, ((sr & 0x1f) << 3) | 0xb800);
  305. }
  306. #if 0
  307. static void vortex_EqHw_GetControlReg(vortex_t * vortex, u32 *reg)
  308. {
  309. *reg = hwread(vortex->mmio, 0x2b440);
  310. }
  311. static void vortex_EqHw_GetSampleRate(vortex_t * vortex, u32 *sr)
  312. {
  313. *sr = (hwread(vortex->mmio, 0x2b440) >> 3) & 0x1f;
  314. }
  315. #endif
  316. static void vortex_EqHw_Enable(vortex_t * vortex)
  317. {
  318. hwwrite(vortex->mmio, VORTEX_EQ_CTRL, 0xf001);
  319. }
  320. static void vortex_EqHw_Disable(vortex_t * vortex)
  321. {
  322. hwwrite(vortex->mmio, VORTEX_EQ_CTRL, 0xf000);
  323. }
  324. /* Reset (zero) buffers */
  325. static void vortex_EqHw_ZeroIO(vortex_t * vortex)
  326. {
  327. int i;
  328. for (i = 0; i < 0x8; i++)
  329. hwwrite(vortex->mmio, VORTEX_EQ_DEST + (i << 2), 0x0);
  330. for (i = 0; i < 0x4; i++)
  331. hwwrite(vortex->mmio, VORTEX_EQ_SOURCE + (i << 2), 0x0);
  332. }
  333. static void vortex_EqHw_ZeroA3DIO(vortex_t * vortex)
  334. {
  335. int i;
  336. for (i = 0; i < 0x4; i++)
  337. hwwrite(vortex->mmio, VORTEX_EQ_DEST + (i << 2), 0x0);
  338. }
  339. static void vortex_EqHw_ZeroState(vortex_t * vortex)
  340. {
  341. vortex_EqHw_SetControlReg(vortex, 0);
  342. vortex_EqHw_ZeroIO(vortex);
  343. hwwrite(vortex->mmio, 0x2b3c0, 0);
  344. vortex_EqHw_SetTimeConsts(vortex, 0, 0);
  345. vortex_EqHw_SetLeftCoefs(vortex, asEqCoefsZeros);
  346. vortex_EqHw_SetRightCoefs(vortex, asEqCoefsZeros);
  347. vortex_EqHw_SetLeftGainsCurrent(vortex, eq_gains_zero);
  348. vortex_EqHw_SetRightGainsCurrent(vortex, eq_gains_zero);
  349. vortex_EqHw_SetLeftGainsTarget(vortex, eq_gains_zero);
  350. vortex_EqHw_SetRightGainsTarget(vortex, eq_gains_zero);
  351. vortex_EqHw_SetBypassGain(vortex, 0, 0);
  352. //vortex_EqHw_SetCurrBypassGain(vortex, 0, 0);
  353. vortex_EqHw_SetA3DBypassGain(vortex, 0, 0);
  354. //vortex_EqHw_SetCurrA3DBypassGain(vortex, 0, 0);
  355. vortex_EqHw_SetLeftStates(vortex, eq_states_zero, asEqOutStateZeros);
  356. vortex_EqHw_SetRightStates(vortex, eq_states_zero, asEqOutStateZeros);
  357. vortex_EqHw_SetLevels(vortex, (u16 *) eq_levels);
  358. }
  359. /* Program coeficients as pass through */
  360. static void vortex_EqHw_ProgramPipe(vortex_t * vortex)
  361. {
  362. vortex_EqHw_SetTimeConsts(vortex, 0, 0);
  363. vortex_EqHw_SetLeftCoefs(vortex, asEqCoefsPipes);
  364. vortex_EqHw_SetRightCoefs(vortex, asEqCoefsPipes);
  365. vortex_EqHw_SetLeftGainsCurrent(vortex, eq_gains_current);
  366. vortex_EqHw_SetRightGainsCurrent(vortex, eq_gains_current);
  367. vortex_EqHw_SetLeftGainsTarget(vortex, eq_gains_current);
  368. vortex_EqHw_SetRightGainsTarget(vortex, eq_gains_current);
  369. }
  370. /* Program EQ block as 10 band Equalizer */
  371. static void
  372. vortex_EqHw_Program10Band(vortex_t * vortex, auxxEqCoeffSet_t * coefset)
  373. {
  374. vortex_EqHw_SetTimeConsts(vortex, 0xc, 0x7fe0);
  375. vortex_EqHw_SetLeftCoefs(vortex, coefset->LeftCoefs);
  376. vortex_EqHw_SetRightCoefs(vortex, coefset->RightCoefs);
  377. vortex_EqHw_SetLeftGainsCurrent(vortex, coefset->LeftGains);
  378. vortex_EqHw_SetRightGainsTarget(vortex, coefset->RightGains);
  379. vortex_EqHw_SetLeftGainsTarget(vortex, coefset->LeftGains);
  380. vortex_EqHw_SetRightGainsCurrent(vortex, coefset->RightGains);
  381. }
  382. /* Read all EQ peaks. (think VU meter) */
  383. static void vortex_EqHw_GetTenBandLevels(vortex_t * vortex, u16 peaks[])
  384. {
  385. eqhw_t *eqhw = &(vortex->eq.this04);
  386. int i;
  387. if (eqhw->this04 <= 0)
  388. return;
  389. for (i = 0; i < eqhw->this04; i++)
  390. peaks[i] = hwread(vortex->mmio, 0x2B024 + i * 0x30);
  391. for (i = 0; i < eqhw->this04; i++)
  392. peaks[i + eqhw->this04] =
  393. hwread(vortex->mmio, 0x2B204 + i * 0x30);
  394. }
  395. /* CEqlzr.s */
  396. static int vortex_Eqlzr_GetLeftGain(vortex_t * vortex, u16 index, u16 * gain)
  397. {
  398. eqlzr_t *eq = &(vortex->eq);
  399. if (eq->this28) {
  400. *gain = eq->this130[index];
  401. return 0;
  402. }
  403. return 1;
  404. }
  405. static void vortex_Eqlzr_SetLeftGain(vortex_t * vortex, u16 index, u16 gain)
  406. {
  407. eqlzr_t *eq = &(vortex->eq);
  408. if (eq->this28 == 0)
  409. return;
  410. eq->this130[index] = gain;
  411. if (eq->this54)
  412. return;
  413. vortex_EqHw_SetLeftGainsSingleTarget(vortex, index, gain);
  414. }
  415. static int vortex_Eqlzr_GetRightGain(vortex_t * vortex, u16 index, u16 * gain)
  416. {
  417. eqlzr_t *eq = &(vortex->eq);
  418. if (eq->this28) {
  419. *gain = eq->this130[index + eq->this10];
  420. return 0;
  421. }
  422. return 1;
  423. }
  424. static void vortex_Eqlzr_SetRightGain(vortex_t * vortex, u16 index, u16 gain)
  425. {
  426. eqlzr_t *eq = &(vortex->eq);
  427. if (eq->this28 == 0)
  428. return;
  429. eq->this130[index + eq->this10] = gain;
  430. if (eq->this54)
  431. return;
  432. vortex_EqHw_SetRightGainsSingleTarget(vortex, index, gain);
  433. }
  434. #if 0
  435. static int
  436. vortex_Eqlzr_GetAllBands(vortex_t * vortex, u16 * gains, s32 *cnt)
  437. {
  438. eqlzr_t *eq = &(vortex->eq);
  439. int si = 0;
  440. if (eq->this10 == 0)
  441. return 1;
  442. {
  443. if (vortex_Eqlzr_GetLeftGain(vortex, si, &gains[si]))
  444. return 1;
  445. if (vortex_Eqlzr_GetRightGain
  446. (vortex, si, &gains[si + eq->this10]))
  447. return 1;
  448. si++;
  449. }
  450. while (eq->this10 > si) ;
  451. *cnt = si * 2;
  452. return 0;
  453. }
  454. #endif
  455. static int vortex_Eqlzr_SetAllBandsFromActiveCoeffSet(vortex_t * vortex)
  456. {
  457. eqlzr_t *eq = &(vortex->eq);
  458. vortex_EqHw_SetLeftGainsTarget(vortex, eq->this130);
  459. vortex_EqHw_SetRightGainsTarget(vortex, &(eq->this130[eq->this10]));
  460. return 0;
  461. }
  462. static int
  463. vortex_Eqlzr_SetAllBands(vortex_t *vortex, const u16 gains[], s32 count)
  464. {
  465. eqlzr_t *eq = &(vortex->eq);
  466. int i;
  467. if (((eq->this10) * 2 != count) || (eq->this28 == 0))
  468. return 1;
  469. for (i = 0; i < count; i++) {
  470. eq->this130[i] = gains[i];
  471. }
  472. if (eq->this54)
  473. return 0;
  474. return vortex_Eqlzr_SetAllBandsFromActiveCoeffSet(vortex);
  475. }
  476. static void
  477. vortex_Eqlzr_SetA3dBypassGain(vortex_t * vortex, u32 a, u32 b)
  478. {
  479. eqlzr_t *eq = &(vortex->eq);
  480. u32 eax, ebx;
  481. eq->this58 = a;
  482. eq->this5c = b;
  483. if (eq->this54)
  484. eax = eq->this0e;
  485. else
  486. eax = eq->this0a;
  487. ebx = (eax * eq->this58) >> 0x10;
  488. eax = (eax * eq->this5c) >> 0x10;
  489. vortex_EqHw_SetA3DBypassGain(vortex, ebx, eax);
  490. }
  491. static void vortex_Eqlzr_ProgramA3dBypassGain(vortex_t * vortex)
  492. {
  493. eqlzr_t *eq = &(vortex->eq);
  494. u32 eax, ebx;
  495. if (eq->this54)
  496. eax = eq->this0e;
  497. else
  498. eax = eq->this0a;
  499. ebx = (eax * eq->this58) >> 0x10;
  500. eax = (eax * eq->this5c) >> 0x10;
  501. vortex_EqHw_SetA3DBypassGain(vortex, ebx, eax);
  502. }
  503. static void vortex_Eqlzr_ShutDownA3d(vortex_t * vortex)
  504. {
  505. if (vortex != NULL)
  506. vortex_EqHw_ZeroA3DIO(vortex);
  507. }
  508. static void vortex_Eqlzr_SetBypass(vortex_t * vortex, u32 bp)
  509. {
  510. eqlzr_t *eq = &(vortex->eq);
  511. if ((eq->this28) && (bp == 0)) {
  512. /* EQ enabled */
  513. vortex_Eqlzr_SetAllBandsFromActiveCoeffSet(vortex);
  514. vortex_EqHw_SetBypassGain(vortex, eq->this08, eq->this08);
  515. } else {
  516. /* EQ disabled. */
  517. vortex_EqHw_SetLeftGainsTarget(vortex, eq->this14_array);
  518. vortex_EqHw_SetRightGainsTarget(vortex, eq->this14_array);
  519. vortex_EqHw_SetBypassGain(vortex, eq->this0c, eq->this0c);
  520. }
  521. vortex_Eqlzr_ProgramA3dBypassGain(vortex);
  522. }
  523. static void vortex_Eqlzr_ReadAndSetActiveCoefSet(vortex_t * vortex)
  524. {
  525. eqlzr_t *eq = &(vortex->eq);
  526. /* Set EQ BiQuad filter coeficients */
  527. memcpy(&(eq->coefset), &asEqCoefsNormal, sizeof(auxxEqCoeffSet_t));
  528. /* Set EQ Band gain levels and dump into hardware registers. */
  529. vortex_Eqlzr_SetAllBands(vortex, eq_gains_normal, eq->this10 * 2);
  530. }
  531. static int vortex_Eqlzr_GetAllPeaks(vortex_t * vortex, u16 * peaks, int *count)
  532. {
  533. eqlzr_t *eq = &(vortex->eq);
  534. if (eq->this10 == 0)
  535. return 1;
  536. *count = eq->this10 * 2;
  537. vortex_EqHw_GetTenBandLevels(vortex, peaks);
  538. return 0;
  539. }
  540. #if 0
  541. static auxxEqCoeffSet_t *vortex_Eqlzr_GetActiveCoefSet(vortex_t * vortex)
  542. {
  543. eqlzr_t *eq = &(vortex->eq);
  544. return (&(eq->coefset));
  545. }
  546. #endif
  547. static void vortex_Eqlzr_init(vortex_t * vortex)
  548. {
  549. eqlzr_t *eq = &(vortex->eq);
  550. /* Object constructor */
  551. //eq->this04 = 0;
  552. eq->this08 = 0; /* Bypass gain with EQ in use. */
  553. eq->this0a = 0x5999;
  554. eq->this0c = 0x5999; /* Bypass gain with EQ disabled. */
  555. eq->this0e = 0x5999;
  556. eq->this10 = 0xa; /* 10 eq frequency bands. */
  557. eq->this04.this04 = eq->this10;
  558. eq->this28 = 0x1; /* if 1 => Allow read access to this130 (gains) */
  559. eq->this54 = 0x0; /* if 1 => Dont Allow access to hardware (gains) */
  560. eq->this58 = 0xffff;
  561. eq->this5c = 0xffff;
  562. /* Set gains. */
  563. memset(eq->this14_array, 0, sizeof(eq->this14_array));
  564. /* Actual init. */
  565. vortex_EqHw_ZeroState(vortex);
  566. vortex_EqHw_SetSampleRate(vortex, 0x11);
  567. vortex_Eqlzr_ReadAndSetActiveCoefSet(vortex);
  568. vortex_EqHw_Program10Band(vortex, &(eq->coefset));
  569. vortex_Eqlzr_SetBypass(vortex, eq->this54);
  570. vortex_Eqlzr_SetA3dBypassGain(vortex, 0, 0);
  571. vortex_EqHw_Enable(vortex);
  572. }
  573. static void vortex_Eqlzr_shutdown(vortex_t * vortex)
  574. {
  575. vortex_Eqlzr_ShutDownA3d(vortex);
  576. vortex_EqHw_ProgramPipe(vortex);
  577. vortex_EqHw_Disable(vortex);
  578. }
  579. /* ALSA interface */
  580. /* Control interface */
  581. #define snd_vortex_eqtoggle_info snd_ctl_boolean_mono_info
  582. static int
  583. snd_vortex_eqtoggle_get(struct snd_kcontrol *kcontrol,
  584. struct snd_ctl_elem_value *ucontrol)
  585. {
  586. vortex_t *vortex = snd_kcontrol_chip(kcontrol);
  587. eqlzr_t *eq = &(vortex->eq);
  588. //int i = kcontrol->private_value;
  589. ucontrol->value.integer.value[0] = eq->this54 ? 0 : 1;
  590. return 0;
  591. }
  592. static int
  593. snd_vortex_eqtoggle_put(struct snd_kcontrol *kcontrol,
  594. struct snd_ctl_elem_value *ucontrol)
  595. {
  596. vortex_t *vortex = snd_kcontrol_chip(kcontrol);
  597. eqlzr_t *eq = &(vortex->eq);
  598. //int i = kcontrol->private_value;
  599. eq->this54 = ucontrol->value.integer.value[0] ? 0 : 1;
  600. vortex_Eqlzr_SetBypass(vortex, eq->this54);
  601. return 1; /* Allways changes */
  602. }
  603. static const struct snd_kcontrol_new vortex_eqtoggle_kcontrol = {
  604. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  605. .name = "EQ Enable",
  606. .index = 0,
  607. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  608. .private_value = 0,
  609. .info = snd_vortex_eqtoggle_info,
  610. .get = snd_vortex_eqtoggle_get,
  611. .put = snd_vortex_eqtoggle_put
  612. };
  613. static int
  614. snd_vortex_eq_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  615. {
  616. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  617. uinfo->count = 2;
  618. uinfo->value.integer.min = 0x0000;
  619. uinfo->value.integer.max = 0x7fff;
  620. return 0;
  621. }
  622. static int
  623. snd_vortex_eq_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  624. {
  625. vortex_t *vortex = snd_kcontrol_chip(kcontrol);
  626. int i = kcontrol->private_value;
  627. u16 gainL = 0, gainR = 0;
  628. vortex_Eqlzr_GetLeftGain(vortex, i, &gainL);
  629. vortex_Eqlzr_GetRightGain(vortex, i, &gainR);
  630. ucontrol->value.integer.value[0] = gainL;
  631. ucontrol->value.integer.value[1] = gainR;
  632. return 0;
  633. }
  634. static int
  635. snd_vortex_eq_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  636. {
  637. vortex_t *vortex = snd_kcontrol_chip(kcontrol);
  638. int changed = 0, i = kcontrol->private_value;
  639. u16 gainL = 0, gainR = 0;
  640. vortex_Eqlzr_GetLeftGain(vortex, i, &gainL);
  641. vortex_Eqlzr_GetRightGain(vortex, i, &gainR);
  642. if (gainL != ucontrol->value.integer.value[0]) {
  643. vortex_Eqlzr_SetLeftGain(vortex, i,
  644. ucontrol->value.integer.value[0]);
  645. changed = 1;
  646. }
  647. if (gainR != ucontrol->value.integer.value[1]) {
  648. vortex_Eqlzr_SetRightGain(vortex, i,
  649. ucontrol->value.integer.value[1]);
  650. changed = 1;
  651. }
  652. return changed;
  653. }
  654. static const struct snd_kcontrol_new vortex_eq_kcontrol = {
  655. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  656. .name = " .",
  657. .index = 0,
  658. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  659. .private_value = 0,
  660. .info = snd_vortex_eq_info,
  661. .get = snd_vortex_eq_get,
  662. .put = snd_vortex_eq_put
  663. };
  664. static int
  665. snd_vortex_peaks_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  666. {
  667. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  668. uinfo->count = 20;
  669. uinfo->value.integer.min = 0x0000;
  670. uinfo->value.integer.max = 0x7fff;
  671. return 0;
  672. }
  673. static int
  674. snd_vortex_peaks_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  675. {
  676. vortex_t *vortex = snd_kcontrol_chip(kcontrol);
  677. int i, count = 0;
  678. u16 peaks[20];
  679. vortex_Eqlzr_GetAllPeaks(vortex, peaks, &count);
  680. if (count != 20) {
  681. dev_err(vortex->card->dev,
  682. "peak count error 20 != %d\n", count);
  683. return -1;
  684. }
  685. for (i = 0; i < 20; i++)
  686. ucontrol->value.integer.value[i] = peaks[i];
  687. return 0;
  688. }
  689. static const struct snd_kcontrol_new vortex_levels_kcontrol = {
  690. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  691. .name = "EQ Peaks",
  692. .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
  693. .info = snd_vortex_peaks_info,
  694. .get = snd_vortex_peaks_get,
  695. };
  696. /* EQ band gain labels. */
  697. static const char * const EqBandLabels[10] = {
  698. "EQ0 31Hz\0",
  699. "EQ1 63Hz\0",
  700. "EQ2 125Hz\0",
  701. "EQ3 250Hz\0",
  702. "EQ4 500Hz\0",
  703. "EQ5 1KHz\0",
  704. "EQ6 2KHz\0",
  705. "EQ7 4KHz\0",
  706. "EQ8 8KHz\0",
  707. "EQ9 16KHz\0",
  708. };
  709. /* ALSA driver entry points. Init and exit. */
  710. static int vortex_eq_init(vortex_t *vortex)
  711. {
  712. struct snd_kcontrol *kcontrol;
  713. int err, i;
  714. vortex_Eqlzr_init(vortex);
  715. kcontrol = snd_ctl_new1(&vortex_eqtoggle_kcontrol, vortex);
  716. if (!kcontrol)
  717. return -ENOMEM;
  718. kcontrol->private_value = 0;
  719. err = snd_ctl_add(vortex->card, kcontrol);
  720. if (err < 0)
  721. return err;
  722. /* EQ gain controls */
  723. for (i = 0; i < 10; i++) {
  724. kcontrol = snd_ctl_new1(&vortex_eq_kcontrol, vortex);
  725. if (!kcontrol)
  726. return -ENOMEM;
  727. snprintf(kcontrol->id.name, sizeof(kcontrol->id.name),
  728. "%s Playback Volume", EqBandLabels[i]);
  729. kcontrol->private_value = i;
  730. err = snd_ctl_add(vortex->card, kcontrol);
  731. if (err < 0)
  732. return err;
  733. //vortex->eqctrl[i] = kcontrol;
  734. }
  735. /* EQ band levels */
  736. kcontrol = snd_ctl_new1(&vortex_levels_kcontrol, vortex);
  737. if (!kcontrol)
  738. return -ENOMEM;
  739. err = snd_ctl_add(vortex->card, kcontrol);
  740. if (err < 0)
  741. return err;
  742. return 0;
  743. }
  744. static int vortex_eq_free(vortex_t * vortex)
  745. {
  746. /*
  747. //FIXME: segfault because vortex->eqctrl[i] == 4
  748. int i;
  749. for (i=0; i<10; i++) {
  750. if (vortex->eqctrl[i])
  751. snd_ctl_remove(vortex->card, vortex->eqctrl[i]);
  752. }
  753. */
  754. vortex_Eqlzr_shutdown(vortex);
  755. return 0;
  756. }
  757. /* End */