au88x0_synth.c 11 KB

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