au88x0_synth.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  1. /*
  2. * This program is free software; you can redistribute it and/or modify
  3. * it under the terms of the GNU General Public License as published by
  4. * the Free Software Foundation; either version 2 of the License, or
  5. * (at your option) any later version.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU Library General Public License for more details.
  11. *
  12. * You should have received a copy of the GNU General Public License
  13. * along with this program; if not, write to the Free Software
  14. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  15. */
  16. /*
  17. * Someday its supposed to make use of the WT DMA engine
  18. * for a Wavetable synthesizer.
  19. */
  20. #include "au88x0.h"
  21. #include "au88x0_wt.h"
  22. static void vortex_fifo_setwtvalid(vortex_t * vortex, int fifo, int en);
  23. static void vortex_connection_adb_mixin(vortex_t * vortex, int en,
  24. unsigned char channel,
  25. unsigned char source,
  26. unsigned char mixin);
  27. static void vortex_connection_mixin_mix(vortex_t * vortex, int en,
  28. unsigned char mixin,
  29. unsigned char mix, int a);
  30. static void vortex_fifo_wtinitialize(vortex_t * vortex, int fifo, int j);
  31. static int vortex_wt_SetReg(vortex_t * vortex, unsigned char reg, int wt,
  32. u32 val);
  33. /* WT */
  34. /* Put 2 WT channels together for one stereo interlaced channel. */
  35. static void vortex_wt_setstereo(vortex_t * vortex, u32 wt, u32 stereo)
  36. {
  37. int temp;
  38. //temp = hwread(vortex->mmio, 0x80 + ((wt >> 0x5)<< 0xf) + (((wt & 0x1f) >> 1) << 2));
  39. temp = hwread(vortex->mmio, WT_STEREO(wt));
  40. temp = (temp & 0xfe) | (stereo & 1);
  41. //hwwrite(vortex->mmio, 0x80 + ((wt >> 0x5)<< 0xf) + (((wt & 0x1f) >> 1) << 2), temp);
  42. hwwrite(vortex->mmio, WT_STEREO(wt), temp);
  43. }
  44. /* Join to mixdown route. */
  45. static void vortex_wt_setdsout(vortex_t * vortex, u32 wt, int en)
  46. {
  47. int temp;
  48. /* There is one DSREG register for each bank (32 voices each). */
  49. temp = hwread(vortex->mmio, WT_DSREG((wt >= 0x20) ? 1 : 0));
  50. if (en)
  51. temp |= (1 << (wt & 0x1f));
  52. else
  53. temp &= ~(1 << (wt & 0x1f));
  54. hwwrite(vortex->mmio, WT_DSREG((wt >= 0x20) ? 1 : 0), temp);
  55. }
  56. /* Setup WT route. */
  57. static int vortex_wt_allocroute(vortex_t * vortex, int wt, int nr_ch)
  58. {
  59. wt_voice_t *voice = &(vortex->wt_voice[wt]);
  60. int temp;
  61. //FIXME: WT audio routing.
  62. if (nr_ch) {
  63. vortex_fifo_wtinitialize(vortex, wt, 1);
  64. vortex_fifo_setwtvalid(vortex, wt, 1);
  65. vortex_wt_setstereo(vortex, wt, nr_ch - 1);
  66. } else
  67. vortex_fifo_setwtvalid(vortex, wt, 0);
  68. /* Set mixdown mode. */
  69. vortex_wt_setdsout(vortex, wt, 1);
  70. /* Set other parameter registers. */
  71. hwwrite(vortex->mmio, WT_SRAMP(0), 0x880000);
  72. //hwwrite(vortex->mmio, WT_GMODE(0), 0xffffffff);
  73. #ifdef CHIP_AU8830
  74. hwwrite(vortex->mmio, WT_SRAMP(1), 0x880000);
  75. //hwwrite(vortex->mmio, WT_GMODE(1), 0xffffffff);
  76. #endif
  77. hwwrite(vortex->mmio, WT_PARM(wt, 0), 0);
  78. hwwrite(vortex->mmio, WT_PARM(wt, 1), 0);
  79. 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);
  83. hwwrite(vortex->mmio, WT_DELAY(wt, 0), 0);
  84. hwwrite(vortex->mmio, WT_DELAY(wt, 1), 0);
  85. hwwrite(vortex->mmio, WT_DELAY(wt, 2), 0);
  86. hwwrite(vortex->mmio, WT_DELAY(wt, 3), 0);
  87. dev_dbg(vortex->card->dev, "WT GMODE: %x\n",
  88. hwread(vortex->mmio, WT_GMODE(wt)));
  89. hwwrite(vortex->mmio, WT_PARM(wt, 2), 0xffffffff);
  90. hwwrite(vortex->mmio, WT_PARM(wt, 3), 0xcff1c810);
  91. voice->parm0 = voice->parm1 = 0xcfb23e2f;
  92. hwwrite(vortex->mmio, WT_PARM(wt, 0), voice->parm0);
  93. hwwrite(vortex->mmio, WT_PARM(wt, 1), voice->parm1);
  94. dev_dbg(vortex->card->dev, "WT GMODE 2 : %x\n",
  95. hwread(vortex->mmio, WT_GMODE(wt)));
  96. return 0;
  97. }
  98. static void vortex_wt_connect(vortex_t * vortex, int en)
  99. {
  100. int i, ii, mix;
  101. #define NR_WTROUTES 6
  102. #ifdef CHIP_AU8830
  103. #define NR_WTBLOCKS 2
  104. #else
  105. #define NR_WTBLOCKS 1
  106. #endif
  107. for (i = 0; i < NR_WTBLOCKS; i++) {
  108. for (ii = 0; ii < NR_WTROUTES; ii++) {
  109. mix =
  110. vortex_adb_checkinout(vortex,
  111. vortex->fixed_res, en,
  112. VORTEX_RESOURCE_MIXIN);
  113. vortex->mixwt[(i * NR_WTROUTES) + ii] = mix;
  114. vortex_route(vortex, en, 0x11,
  115. ADB_WTOUT(i, ii + 0x20), ADB_MIXIN(mix));
  116. vortex_connection_mixin_mix(vortex, en, mix,
  117. vortex->mixplayb[ii % 2], 0);
  118. if (VORTEX_IS_QUAD(vortex))
  119. vortex_connection_mixin_mix(vortex, en,
  120. mix,
  121. vortex->mixplayb[2 +
  122. (ii % 2)], 0);
  123. }
  124. }
  125. for (i = 0; i < NR_WT; i++) {
  126. hwwrite(vortex->mmio, WT_RUN(i), 1);
  127. }
  128. }
  129. /* Read WT Register */
  130. #if 0
  131. static int vortex_wt_GetReg(vortex_t * vortex, char reg, int wt)
  132. {
  133. //int eax, esi;
  134. if (reg == 4) {
  135. return hwread(vortex->mmio, WT_PARM(wt, 3));
  136. }
  137. if (reg == 7) {
  138. return hwread(vortex->mmio, WT_GMODE(wt));
  139. }
  140. return 0;
  141. }
  142. /* WT hardware abstraction layer generic register interface. */
  143. static int
  144. vortex_wt_SetReg2(vortex_t * vortex, unsigned char reg, int wt,
  145. u16 val)
  146. {
  147. /*
  148. int eax, edx;
  149. if (wt >= NR_WT) // 0x40 -> NR_WT
  150. return 0;
  151. if ((reg - 0x20) > 0) {
  152. if ((reg - 0x21) != 0)
  153. return 0;
  154. eax = ((((b & 0xff) << 0xb) + (edx & 0xff)) << 4) + 0x208; // param 2
  155. } else {
  156. eax = ((((b & 0xff) << 0xb) + (edx & 0xff)) << 4) + 0x20a; // param 3
  157. }
  158. hwwrite(vortex->mmio, eax, c);
  159. */
  160. return 1;
  161. }
  162. /*public: static void __thiscall CWTHal::SetReg(unsigned char,int,unsigned long) */
  163. #endif
  164. static int
  165. vortex_wt_SetReg(vortex_t * vortex, unsigned char reg, int wt,
  166. u32 val)
  167. {
  168. int ecx;
  169. if ((reg == 5) || ((reg >= 7) && (reg <= 10)) || (reg == 0xc)) {
  170. if (wt >= (NR_WT / NR_WT_PB)) {
  171. dev_warn(vortex->card->dev,
  172. "WT SetReg: bank out of range. reg=0x%x, wt=%d\n",
  173. reg, wt);
  174. return 0;
  175. }
  176. } else {
  177. if (wt >= NR_WT) {
  178. dev_err(vortex->card->dev,
  179. "WT SetReg: voice out of range\n");
  180. return 0;
  181. }
  182. }
  183. if (reg > 0xc)
  184. return 0;
  185. switch (reg) {
  186. /* Voice specific parameters */
  187. case 0: /* running */
  188. /*
  189. pr_debug( "vortex: WT SetReg(0x%x) = 0x%08x\n",
  190. WT_RUN(wt), (int)val);
  191. */
  192. hwwrite(vortex->mmio, WT_RUN(wt), val);
  193. return 0xc;
  194. case 1: /* param 0 */
  195. /*
  196. pr_debug( "vortex: WT SetReg(0x%x) = 0x%08x\n",
  197. WT_PARM(wt,0), (int)val);
  198. */
  199. hwwrite(vortex->mmio, WT_PARM(wt, 0), val);
  200. return 0xc;
  201. case 2: /* param 1 */
  202. /*
  203. pr_debug( "vortex: WT SetReg(0x%x) = 0x%08x\n",
  204. WT_PARM(wt,1), (int)val);
  205. */
  206. hwwrite(vortex->mmio, WT_PARM(wt, 1), val);
  207. return 0xc;
  208. case 3: /* param 2 */
  209. /*
  210. pr_debug( "vortex: WT SetReg(0x%x) = 0x%08x\n",
  211. WT_PARM(wt,2), (int)val);
  212. */
  213. hwwrite(vortex->mmio, WT_PARM(wt, 2), val);
  214. return 0xc;
  215. case 4: /* param 3 */
  216. /*
  217. pr_debug( "vortex: WT SetReg(0x%x) = 0x%08x\n",
  218. WT_PARM(wt,3), (int)val);
  219. */
  220. hwwrite(vortex->mmio, WT_PARM(wt, 3), val);
  221. return 0xc;
  222. case 6: /* mute */
  223. /*
  224. pr_debug( "vortex: WT SetReg(0x%x) = 0x%08x\n",
  225. WT_MUTE(wt), (int)val);
  226. */
  227. hwwrite(vortex->mmio, WT_MUTE(wt), val);
  228. return 0xc;
  229. case 0xb:
  230. /* delay */
  231. /*
  232. pr_debug( "vortex: WT SetReg(0x%x) = 0x%08x\n",
  233. WT_DELAY(wt,0), (int)val);
  234. */
  235. hwwrite(vortex->mmio, WT_DELAY(wt, 3), val);
  236. hwwrite(vortex->mmio, WT_DELAY(wt, 2), val);
  237. hwwrite(vortex->mmio, WT_DELAY(wt, 1), val);
  238. hwwrite(vortex->mmio, WT_DELAY(wt, 0), val);
  239. return 0xc;
  240. /* Global WT block parameters */
  241. case 5: /* sramp */
  242. ecx = WT_SRAMP(wt);
  243. break;
  244. case 8: /* aramp */
  245. ecx = WT_ARAMP(wt);
  246. break;
  247. case 9: /* mramp */
  248. ecx = WT_MRAMP(wt);
  249. break;
  250. case 0xa: /* ctrl */
  251. ecx = WT_CTRL(wt);
  252. break;
  253. case 0xc: /* ds_reg */
  254. ecx = WT_DSREG(wt);
  255. break;
  256. default:
  257. return 0;
  258. }
  259. /*
  260. pr_debug( "vortex: WT SetReg(0x%x) = 0x%08x\n", ecx, (int)val);
  261. */
  262. hwwrite(vortex->mmio, ecx, val);
  263. return 1;
  264. }
  265. static void vortex_wt_init(vortex_t * vortex)
  266. {
  267. u32 var4, var8, varc, var10 = 0, edi;
  268. var10 &= 0xFFFFFFE3;
  269. var10 |= 0x22;
  270. var10 &= 0xFFFFFEBF;
  271. var10 |= 0x80;
  272. var10 |= 0x200;
  273. var10 &= 0xfffffffe;
  274. var10 &= 0xfffffbff;
  275. var10 |= 0x1800;
  276. // var10 = 0x1AA2
  277. var4 = 0x10000000;
  278. varc = 0x00830000;
  279. var8 = 0x00830000;
  280. /* Init Bank registers. */
  281. for (edi = 0; edi < (NR_WT / NR_WT_PB); edi++) {
  282. vortex_wt_SetReg(vortex, 0xc, edi, 0); /* ds_reg */
  283. vortex_wt_SetReg(vortex, 0xa, edi, var10); /* ctrl */
  284. vortex_wt_SetReg(vortex, 0x9, edi, var4); /* mramp */
  285. vortex_wt_SetReg(vortex, 0x8, edi, varc); /* aramp */
  286. vortex_wt_SetReg(vortex, 0x5, edi, var8); /* sramp */
  287. }
  288. /* Init Voice registers. */
  289. for (edi = 0; edi < NR_WT; edi++) {
  290. vortex_wt_SetReg(vortex, 0x4, edi, 0); /* param 3 0x20c */
  291. vortex_wt_SetReg(vortex, 0x3, edi, 0); /* param 2 0x208 */
  292. vortex_wt_SetReg(vortex, 0x2, edi, 0); /* param 1 0x204 */
  293. vortex_wt_SetReg(vortex, 0x1, edi, 0); /* param 0 0x200 */
  294. vortex_wt_SetReg(vortex, 0xb, edi, 0); /* delay 0x400 - 0x40c */
  295. }
  296. var10 |= 1;
  297. for (edi = 0; edi < (NR_WT / NR_WT_PB); edi++)
  298. vortex_wt_SetReg(vortex, 0xa, edi, var10); /* ctrl */
  299. }
  300. /* Extract of CAdbTopology::SetVolume(struct _ASPVOLUME *) */
  301. #if 0
  302. static void vortex_wt_SetVolume(vortex_t * vortex, int wt, int vol[])
  303. {
  304. wt_voice_t *voice = &(vortex->wt_voice[wt]);
  305. int ecx = vol[1], eax = vol[0];
  306. /* This is pure guess */
  307. voice->parm0 &= 0xff00ffff;
  308. voice->parm0 |= (vol[0] & 0xff) << 0x10;
  309. voice->parm1 &= 0xff00ffff;
  310. voice->parm1 |= (vol[1] & 0xff) << 0x10;
  311. /* This is real */
  312. hwwrite(vortex, WT_PARM(wt, 0), voice->parm0);
  313. hwwrite(vortex, WT_PARM(wt, 1), voice->parm0);
  314. if (voice->this_1D0 & 4) {
  315. eax >>= 8;
  316. ecx = eax;
  317. if (ecx < 0x80)
  318. ecx = 0x7f;
  319. voice->parm3 &= 0xFFFFC07F;
  320. voice->parm3 |= (ecx & 0x7f) << 7;
  321. voice->parm3 &= 0xFFFFFF80;
  322. voice->parm3 |= (eax & 0x7f);
  323. } else {
  324. voice->parm3 &= 0xFFE03FFF;
  325. voice->parm3 |= (eax & 0xFE00) << 5;
  326. }
  327. hwwrite(vortex, WT_PARM(wt, 3), voice->parm3);
  328. }
  329. /* Extract of CAdbTopology::SetFrequency(unsigned long arg_0) */
  330. static void vortex_wt_SetFrequency(vortex_t * vortex, int wt, unsigned int sr)
  331. {
  332. wt_voice_t *voice = &(vortex->wt_voice[wt]);
  333. u32 eax, edx;
  334. //FIXME: 64 bit operation.
  335. eax = ((sr << 0xf) * 0x57619F1) & 0xffffffff;
  336. edx = (((sr << 0xf) * 0x57619F1)) >> 0x20;
  337. edx >>= 0xa;
  338. edx <<= 1;
  339. if (edx) {
  340. if (edx & 0x0FFF80000)
  341. eax = 0x7fff;
  342. else {
  343. edx <<= 0xd;
  344. eax = 7;
  345. while ((edx & 0x80000000) == 0) {
  346. edx <<= 1;
  347. eax--;
  348. if (eax == 0)
  349. break;
  350. }
  351. if (eax)
  352. edx <<= 1;
  353. eax <<= 0xc;
  354. edx >>= 0x14;
  355. eax |= edx;
  356. }
  357. } else
  358. eax = 0;
  359. voice->parm0 &= 0xffff0001;
  360. voice->parm0 |= (eax & 0x7fff) << 1;
  361. voice->parm1 = voice->parm0 | 1;
  362. // Wt: this_1D4
  363. //AuWt::WriteReg((ulong)(this_1DC<<4)+0x200, (ulong)this_1E4);
  364. //AuWt::WriteReg((ulong)(this_1DC<<4)+0x204, (ulong)this_1E8);
  365. hwwrite(vortex->mmio, WT_PARM(wt, 0), voice->parm0);
  366. hwwrite(vortex->mmio, WT_PARM(wt, 1), voice->parm1);
  367. }
  368. #endif
  369. /* End of File */