au88x0_synth.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  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. case 1: /* param 0 */
  192. /*
  193. printk(KERN_DEBUG "vortex: WT SetReg(0x%x) = 0x%08x\n",
  194. WT_PARM(wt,0), (int)val);
  195. */
  196. hwwrite(vortex->mmio, WT_PARM(wt, 0), val);
  197. return 0xc;
  198. case 2: /* param 1 */
  199. /*
  200. printk(KERN_DEBUG "vortex: WT SetReg(0x%x) = 0x%08x\n",
  201. WT_PARM(wt,1), (int)val);
  202. */
  203. hwwrite(vortex->mmio, WT_PARM(wt, 1), val);
  204. return 0xc;
  205. case 3: /* param 2 */
  206. /*
  207. printk(KERN_DEBUG "vortex: WT SetReg(0x%x) = 0x%08x\n",
  208. WT_PARM(wt,2), (int)val);
  209. */
  210. hwwrite(vortex->mmio, WT_PARM(wt, 2), val);
  211. return 0xc;
  212. case 4: /* param 3 */
  213. /*
  214. printk(KERN_DEBUG "vortex: WT SetReg(0x%x) = 0x%08x\n",
  215. WT_PARM(wt,3), (int)val);
  216. */
  217. hwwrite(vortex->mmio, WT_PARM(wt, 3), val);
  218. return 0xc;
  219. case 6: /* mute */
  220. /*
  221. printk(KERN_DEBUG "vortex: WT SetReg(0x%x) = 0x%08x\n",
  222. WT_MUTE(wt), (int)val);
  223. */
  224. hwwrite(vortex->mmio, WT_MUTE(wt), val);
  225. return 0xc;
  226. case 0xb:
  227. /* delay */
  228. /*
  229. printk(KERN_DEBUG "vortex: WT SetReg(0x%x) = 0x%08x\n",
  230. WT_DELAY(wt,0), (int)val);
  231. */
  232. hwwrite(vortex->mmio, WT_DELAY(wt, 3), val);
  233. hwwrite(vortex->mmio, WT_DELAY(wt, 2), val);
  234. hwwrite(vortex->mmio, WT_DELAY(wt, 1), val);
  235. hwwrite(vortex->mmio, WT_DELAY(wt, 0), val);
  236. return 0xc;
  237. /* Global WT block parameters */
  238. case 5: /* sramp */
  239. ecx = WT_SRAMP(wt);
  240. break;
  241. case 8: /* aramp */
  242. ecx = WT_ARAMP(wt);
  243. break;
  244. case 9: /* mramp */
  245. ecx = WT_MRAMP(wt);
  246. break;
  247. case 0xa: /* ctrl */
  248. ecx = WT_CTRL(wt);
  249. break;
  250. case 0xc: /* ds_reg */
  251. ecx = WT_DSREG(wt);
  252. break;
  253. default:
  254. return 0;
  255. }
  256. /*
  257. printk(KERN_DEBUG "vortex: WT SetReg(0x%x) = 0x%08x\n", ecx, (int)val);
  258. */
  259. hwwrite(vortex->mmio, ecx, val);
  260. return 1;
  261. }
  262. static void vortex_wt_init(vortex_t * vortex)
  263. {
  264. u32 var4, var8, varc, var10 = 0, edi;
  265. var10 &= 0xFFFFFFE3;
  266. var10 |= 0x22;
  267. var10 &= 0xFFFFFEBF;
  268. var10 |= 0x80;
  269. var10 |= 0x200;
  270. var10 &= 0xfffffffe;
  271. var10 &= 0xfffffbff;
  272. var10 |= 0x1800;
  273. // var10 = 0x1AA2
  274. var4 = 0x10000000;
  275. varc = 0x00830000;
  276. var8 = 0x00830000;
  277. /* Init Bank registers. */
  278. for (edi = 0; edi < (NR_WT / NR_WT_PB); edi++) {
  279. vortex_wt_SetReg(vortex, 0xc, edi, 0); /* ds_reg */
  280. vortex_wt_SetReg(vortex, 0xa, edi, var10); /* ctrl */
  281. vortex_wt_SetReg(vortex, 0x9, edi, var4); /* mramp */
  282. vortex_wt_SetReg(vortex, 0x8, edi, varc); /* aramp */
  283. vortex_wt_SetReg(vortex, 0x5, edi, var8); /* sramp */
  284. }
  285. /* Init Voice registers. */
  286. for (edi = 0; edi < NR_WT; edi++) {
  287. vortex_wt_SetReg(vortex, 0x4, edi, 0); /* param 3 0x20c */
  288. vortex_wt_SetReg(vortex, 0x3, edi, 0); /* param 2 0x208 */
  289. vortex_wt_SetReg(vortex, 0x2, edi, 0); /* param 1 0x204 */
  290. vortex_wt_SetReg(vortex, 0x1, edi, 0); /* param 0 0x200 */
  291. vortex_wt_SetReg(vortex, 0xb, edi, 0); /* delay 0x400 - 0x40c */
  292. }
  293. var10 |= 1;
  294. for (edi = 0; edi < (NR_WT / NR_WT_PB); edi++)
  295. vortex_wt_SetReg(vortex, 0xa, edi, var10); /* ctrl */
  296. }
  297. /* Extract of CAdbTopology::SetVolume(struct _ASPVOLUME *) */
  298. #if 0
  299. static void vortex_wt_SetVolume(vortex_t * vortex, int wt, int vol[])
  300. {
  301. wt_voice_t *voice = &(vortex->wt_voice[wt]);
  302. int ecx = vol[1], eax = vol[0];
  303. /* This is pure guess */
  304. voice->parm0 &= 0xff00ffff;
  305. voice->parm0 |= (vol[0] & 0xff) << 0x10;
  306. voice->parm1 &= 0xff00ffff;
  307. voice->parm1 |= (vol[1] & 0xff) << 0x10;
  308. /* This is real */
  309. hwwrite(vortex, WT_PARM(wt, 0), voice->parm0);
  310. hwwrite(vortex, WT_PARM(wt, 1), voice->parm0);
  311. if (voice->this_1D0 & 4) {
  312. eax >>= 8;
  313. ecx = eax;
  314. if (ecx < 0x80)
  315. ecx = 0x7f;
  316. voice->parm3 &= 0xFFFFC07F;
  317. voice->parm3 |= (ecx & 0x7f) << 7;
  318. voice->parm3 &= 0xFFFFFF80;
  319. voice->parm3 |= (eax & 0x7f);
  320. } else {
  321. voice->parm3 &= 0xFFE03FFF;
  322. voice->parm3 |= (eax & 0xFE00) << 5;
  323. }
  324. hwwrite(vortex, WT_PARM(wt, 3), voice->parm3);
  325. }
  326. /* Extract of CAdbTopology::SetFrequency(unsigned long arg_0) */
  327. static void vortex_wt_SetFrequency(vortex_t * vortex, int wt, unsigned int sr)
  328. {
  329. wt_voice_t *voice = &(vortex->wt_voice[wt]);
  330. u32 eax, edx;
  331. //FIXME: 64 bit operation.
  332. eax = ((sr << 0xf) * 0x57619F1) & 0xffffffff;
  333. edx = (((sr << 0xf) * 0x57619F1)) >> 0x20;
  334. edx >>= 0xa;
  335. edx <<= 1;
  336. if (edx) {
  337. if (edx & 0x0FFF80000)
  338. eax = 0x7fff;
  339. else {
  340. edx <<= 0xd;
  341. eax = 7;
  342. while ((edx & 0x80000000) == 0) {
  343. edx <<= 1;
  344. eax--;
  345. if (eax == 0)
  346. break;
  347. }
  348. if (eax)
  349. edx <<= 1;
  350. eax <<= 0xc;
  351. edx >>= 0x14;
  352. eax |= edx;
  353. }
  354. } else
  355. eax = 0;
  356. voice->parm0 &= 0xffff0001;
  357. voice->parm0 |= (eax & 0x7fff) << 1;
  358. voice->parm1 = voice->parm0 | 1;
  359. // Wt: this_1D4
  360. //AuWt::WriteReg((ulong)(this_1DC<<4)+0x200, (ulong)this_1E4);
  361. //AuWt::WriteReg((ulong)(this_1DC<<4)+0x204, (ulong)this_1E8);
  362. hwwrite(vortex->mmio, WT_PARM(wt, 0), voice->parm0);
  363. hwwrite(vortex->mmio, WT_PARM(wt, 1), voice->parm1);
  364. }
  365. #endif
  366. /* End of File */