au88x0_synth.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  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. printk(KERN_DEBUG "vortex: 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. printk(KERN_DEBUG "vortex: WT GMODE: %x\n", hwread(vortex->mmio, WT_GMODE(wt)));
  88. hwwrite(vortex->mmio, WT_PARM(wt, 2), 0xffffffff);
  89. hwwrite(vortex->mmio, WT_PARM(wt, 3), 0xcff1c810);
  90. voice->parm0 = voice->parm1 = 0xcfb23e2f;
  91. hwwrite(vortex->mmio, WT_PARM(wt, 0), voice->parm0);
  92. hwwrite(vortex->mmio, WT_PARM(wt, 1), voice->parm1);
  93. printk(KERN_DEBUG "vortex: WT GMODE 2 : %x\n", hwread(vortex->mmio, WT_GMODE(wt)));
  94. return 0;
  95. }
  96. static void vortex_wt_connect(vortex_t * vortex, int en)
  97. {
  98. int i, ii, mix;
  99. #define NR_WTROUTES 6
  100. #ifdef CHIP_AU8830
  101. #define NR_WTBLOCKS 2
  102. #else
  103. #define NR_WTBLOCKS 1
  104. #endif
  105. for (i = 0; i < NR_WTBLOCKS; i++) {
  106. for (ii = 0; ii < NR_WTROUTES; ii++) {
  107. mix =
  108. vortex_adb_checkinout(vortex,
  109. vortex->fixed_res, en,
  110. VORTEX_RESOURCE_MIXIN);
  111. vortex->mixwt[(i * NR_WTROUTES) + ii] = mix;
  112. vortex_route(vortex, en, 0x11,
  113. ADB_WTOUT(i, ii + 0x20), ADB_MIXIN(mix));
  114. vortex_connection_mixin_mix(vortex, en, mix,
  115. vortex->mixplayb[ii % 2], 0);
  116. if (VORTEX_IS_QUAD(vortex))
  117. vortex_connection_mixin_mix(vortex, en,
  118. mix,
  119. vortex->mixplayb[2 +
  120. (ii % 2)], 0);
  121. }
  122. }
  123. for (i = 0; i < NR_WT; i++) {
  124. hwwrite(vortex->mmio, WT_RUN(i), 1);
  125. }
  126. }
  127. /* Read WT Register */
  128. #if 0
  129. static int vortex_wt_GetReg(vortex_t * vortex, char reg, int wt)
  130. {
  131. //int eax, esi;
  132. if (reg == 4) {
  133. return hwread(vortex->mmio, WT_PARM(wt, 3));
  134. }
  135. if (reg == 7) {
  136. return hwread(vortex->mmio, WT_GMODE(wt));
  137. }
  138. return 0;
  139. }
  140. /* WT hardware abstraction layer generic register interface. */
  141. static int
  142. vortex_wt_SetReg2(vortex_t * vortex, unsigned char reg, int wt,
  143. u16 val)
  144. {
  145. /*
  146. int eax, edx;
  147. if (wt >= NR_WT) // 0x40 -> NR_WT
  148. return 0;
  149. if ((reg - 0x20) > 0) {
  150. if ((reg - 0x21) != 0)
  151. return 0;
  152. eax = ((((b & 0xff) << 0xb) + (edx & 0xff)) << 4) + 0x208; // param 2
  153. } else {
  154. eax = ((((b & 0xff) << 0xb) + (edx & 0xff)) << 4) + 0x20a; // param 3
  155. }
  156. hwwrite(vortex->mmio, eax, c);
  157. */
  158. return 1;
  159. }
  160. /*public: static void __thiscall CWTHal::SetReg(unsigned char,int,unsigned long) */
  161. #endif
  162. static int
  163. vortex_wt_SetReg(vortex_t * vortex, unsigned char reg, int wt,
  164. u32 val)
  165. {
  166. int ecx;
  167. if ((reg == 5) || ((reg >= 7) && (reg <= 10)) || (reg == 0xc)) {
  168. if (wt >= (NR_WT / NR_WT_PB)) {
  169. printk
  170. ("vortex: WT SetReg: bank out of range. reg=0x%x, wt=%d\n",
  171. reg, wt);
  172. return 0;
  173. }
  174. } else {
  175. if (wt >= NR_WT) {
  176. printk(KERN_ERR "vortex: WT SetReg: voice out of range\n");
  177. return 0;
  178. }
  179. }
  180. if (reg > 0xc)
  181. return 0;
  182. switch (reg) {
  183. /* Voice specific parameters */
  184. case 0: /* running */
  185. /*
  186. printk(KERN_DEBUG "vortex: WT SetReg(0x%x) = 0x%08x\n",
  187. WT_RUN(wt), (int)val);
  188. */
  189. hwwrite(vortex->mmio, WT_RUN(wt), val);
  190. return 0xc;
  191. break;
  192. case 1: /* param 0 */
  193. /*
  194. printk(KERN_DEBUG "vortex: WT SetReg(0x%x) = 0x%08x\n",
  195. WT_PARM(wt,0), (int)val);
  196. */
  197. hwwrite(vortex->mmio, WT_PARM(wt, 0), val);
  198. return 0xc;
  199. break;
  200. case 2: /* param 1 */
  201. /*
  202. printk(KERN_DEBUG "vortex: WT SetReg(0x%x) = 0x%08x\n",
  203. WT_PARM(wt,1), (int)val);
  204. */
  205. hwwrite(vortex->mmio, WT_PARM(wt, 1), val);
  206. return 0xc;
  207. break;
  208. case 3: /* param 2 */
  209. /*
  210. printk(KERN_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. break;
  216. case 4: /* param 3 */
  217. /*
  218. printk(KERN_DEBUG "vortex: WT SetReg(0x%x) = 0x%08x\n",
  219. WT_PARM(wt,3), (int)val);
  220. */
  221. hwwrite(vortex->mmio, WT_PARM(wt, 3), val);
  222. return 0xc;
  223. break;
  224. case 6: /* mute */
  225. /*
  226. printk(KERN_DEBUG "vortex: WT SetReg(0x%x) = 0x%08x\n",
  227. WT_MUTE(wt), (int)val);
  228. */
  229. hwwrite(vortex->mmio, WT_MUTE(wt), val);
  230. return 0xc;
  231. break;
  232. case 0xb:
  233. { /* delay */
  234. /*
  235. printk(KERN_DEBUG "vortex: WT SetReg(0x%x) = 0x%08x\n",
  236. WT_DELAY(wt,0), (int)val);
  237. */
  238. hwwrite(vortex->mmio, WT_DELAY(wt, 3), val);
  239. hwwrite(vortex->mmio, WT_DELAY(wt, 2), val);
  240. hwwrite(vortex->mmio, WT_DELAY(wt, 1), val);
  241. hwwrite(vortex->mmio, WT_DELAY(wt, 0), val);
  242. return 0xc;
  243. }
  244. break;
  245. /* Global WT block parameters */
  246. case 5: /* sramp */
  247. ecx = WT_SRAMP(wt);
  248. break;
  249. case 8: /* aramp */
  250. ecx = WT_ARAMP(wt);
  251. break;
  252. case 9: /* mramp */
  253. ecx = WT_MRAMP(wt);
  254. break;
  255. case 0xa: /* ctrl */
  256. ecx = WT_CTRL(wt);
  257. break;
  258. case 0xc: /* ds_reg */
  259. ecx = WT_DSREG(wt);
  260. break;
  261. default:
  262. return 0;
  263. break;
  264. }
  265. /*
  266. printk(KERN_DEBUG "vortex: WT SetReg(0x%x) = 0x%08x\n", ecx, (int)val);
  267. */
  268. hwwrite(vortex->mmio, ecx, val);
  269. return 1;
  270. }
  271. static void vortex_wt_init(vortex_t * vortex)
  272. {
  273. u32 var4, var8, varc, var10 = 0, edi;
  274. var10 &= 0xFFFFFFE3;
  275. var10 |= 0x22;
  276. var10 &= 0xFFFFFEBF;
  277. var10 |= 0x80;
  278. var10 |= 0x200;
  279. var10 &= 0xfffffffe;
  280. var10 &= 0xfffffbff;
  281. var10 |= 0x1800;
  282. // var10 = 0x1AA2
  283. var4 = 0x10000000;
  284. varc = 0x00830000;
  285. var8 = 0x00830000;
  286. /* Init Bank registers. */
  287. for (edi = 0; edi < (NR_WT / NR_WT_PB); edi++) {
  288. vortex_wt_SetReg(vortex, 0xc, edi, 0); /* ds_reg */
  289. vortex_wt_SetReg(vortex, 0xa, edi, var10); /* ctrl */
  290. vortex_wt_SetReg(vortex, 0x9, edi, var4); /* mramp */
  291. vortex_wt_SetReg(vortex, 0x8, edi, varc); /* aramp */
  292. vortex_wt_SetReg(vortex, 0x5, edi, var8); /* sramp */
  293. }
  294. /* Init Voice registers. */
  295. for (edi = 0; edi < NR_WT; edi++) {
  296. vortex_wt_SetReg(vortex, 0x4, edi, 0); /* param 3 0x20c */
  297. vortex_wt_SetReg(vortex, 0x3, edi, 0); /* param 2 0x208 */
  298. vortex_wt_SetReg(vortex, 0x2, edi, 0); /* param 1 0x204 */
  299. vortex_wt_SetReg(vortex, 0x1, edi, 0); /* param 0 0x200 */
  300. vortex_wt_SetReg(vortex, 0xb, edi, 0); /* delay 0x400 - 0x40c */
  301. }
  302. var10 |= 1;
  303. for (edi = 0; edi < (NR_WT / NR_WT_PB); edi++)
  304. vortex_wt_SetReg(vortex, 0xa, edi, var10); /* ctrl */
  305. }
  306. /* Extract of CAdbTopology::SetVolume(struct _ASPVOLUME *) */
  307. #if 0
  308. static void vortex_wt_SetVolume(vortex_t * vortex, int wt, int vol[])
  309. {
  310. wt_voice_t *voice = &(vortex->wt_voice[wt]);
  311. int ecx = vol[1], eax = vol[0];
  312. /* This is pure guess */
  313. voice->parm0 &= 0xff00ffff;
  314. voice->parm0 |= (vol[0] & 0xff) << 0x10;
  315. voice->parm1 &= 0xff00ffff;
  316. voice->parm1 |= (vol[1] & 0xff) << 0x10;
  317. /* This is real */
  318. hwwrite(vortex, WT_PARM(wt, 0), voice->parm0);
  319. hwwrite(vortex, WT_PARM(wt, 1), voice->parm0);
  320. if (voice->this_1D0 & 4) {
  321. eax >>= 8;
  322. ecx = eax;
  323. if (ecx < 0x80)
  324. ecx = 0x7f;
  325. voice->parm3 &= 0xFFFFC07F;
  326. voice->parm3 |= (ecx & 0x7f) << 7;
  327. voice->parm3 &= 0xFFFFFF80;
  328. voice->parm3 |= (eax & 0x7f);
  329. } else {
  330. voice->parm3 &= 0xFFE03FFF;
  331. voice->parm3 |= (eax & 0xFE00) << 5;
  332. }
  333. hwwrite(vortex, WT_PARM(wt, 3), voice->parm3);
  334. }
  335. /* Extract of CAdbTopology::SetFrequency(unsigned long arg_0) */
  336. static void vortex_wt_SetFrequency(vortex_t * vortex, int wt, unsigned int sr)
  337. {
  338. wt_voice_t *voice = &(vortex->wt_voice[wt]);
  339. u32 eax, edx;
  340. //FIXME: 64 bit operation.
  341. eax = ((sr << 0xf) * 0x57619F1) & 0xffffffff;
  342. edx = (((sr << 0xf) * 0x57619F1)) >> 0x20;
  343. edx >>= 0xa;
  344. edx <<= 1;
  345. if (edx) {
  346. if (edx & 0x0FFF80000)
  347. eax = 0x7fff;
  348. else {
  349. edx <<= 0xd;
  350. eax = 7;
  351. while ((edx & 0x80000000) == 0) {
  352. edx <<= 1;
  353. eax--;
  354. if (eax == 0)
  355. break;
  356. }
  357. if (eax)
  358. edx <<= 1;
  359. eax <<= 0xc;
  360. edx >>= 0x14;
  361. eax |= edx;
  362. }
  363. } else
  364. eax = 0;
  365. voice->parm0 &= 0xffff0001;
  366. voice->parm0 |= (eax & 0x7fff) << 1;
  367. voice->parm1 = voice->parm0 | 1;
  368. // Wt: this_1D4
  369. //AuWt::WriteReg((ulong)(this_1DC<<4)+0x200, (ulong)this_1E4);
  370. //AuWt::WriteReg((ulong)(this_1DC<<4)+0x204, (ulong)this_1E8);
  371. hwwrite(vortex->mmio, WT_PARM(wt, 0), voice->parm0);
  372. hwwrite(vortex->mmio, WT_PARM(wt, 1), voice->parm1);
  373. }
  374. #endif
  375. /* End of File */