au88x0_eq.c 23 KB

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