emuproc.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  1. /*
  2. * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
  3. * Creative Labs, Inc.
  4. * Routines for control of EMU10K1 chips / proc interface routines
  5. *
  6. * Copyright (c) by James Courtier-Dutton <James@superbug.co.uk>
  7. * Added EMU 1010 support.
  8. *
  9. * BUGS:
  10. * --
  11. *
  12. * TODO:
  13. * --
  14. *
  15. * This program is free software; you can redistribute it and/or modify
  16. * it under the terms of the GNU General Public License as published by
  17. * the Free Software Foundation; either version 2 of the License, or
  18. * (at your option) any later version.
  19. *
  20. * This program is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU General Public License
  26. * along with this program; if not, write to the Free Software
  27. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  28. *
  29. */
  30. #include <linux/slab.h>
  31. #include <linux/init.h>
  32. #include <sound/core.h>
  33. #include <sound/emu10k1.h>
  34. #include "p16v.h"
  35. #ifdef CONFIG_PROC_FS
  36. static void snd_emu10k1_proc_spdif_status(struct snd_emu10k1 * emu,
  37. struct snd_info_buffer *buffer,
  38. char *title,
  39. int status_reg,
  40. int rate_reg)
  41. {
  42. static char *clkaccy[4] = { "1000ppm", "50ppm", "variable", "unknown" };
  43. static int samplerate[16] = { 44100, 1, 48000, 32000, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
  44. static char *channel[16] = { "unspec", "left", "right", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15" };
  45. static char *emphasis[8] = { "none", "50/15 usec 2 channel", "2", "3", "4", "5", "6", "7" };
  46. unsigned int status, rate = 0;
  47. status = snd_emu10k1_ptr_read(emu, status_reg, 0);
  48. snd_iprintf(buffer, "\n%s\n", title);
  49. if (status != 0xffffffff) {
  50. snd_iprintf(buffer, "Professional Mode : %s\n", (status & SPCS_PROFESSIONAL) ? "yes" : "no");
  51. snd_iprintf(buffer, "Not Audio Data : %s\n", (status & SPCS_NOTAUDIODATA) ? "yes" : "no");
  52. snd_iprintf(buffer, "Copyright : %s\n", (status & SPCS_COPYRIGHT) ? "yes" : "no");
  53. snd_iprintf(buffer, "Emphasis : %s\n", emphasis[(status & SPCS_EMPHASISMASK) >> 3]);
  54. snd_iprintf(buffer, "Mode : %i\n", (status & SPCS_MODEMASK) >> 6);
  55. snd_iprintf(buffer, "Category Code : 0x%x\n", (status & SPCS_CATEGORYCODEMASK) >> 8);
  56. snd_iprintf(buffer, "Generation Status : %s\n", status & SPCS_GENERATIONSTATUS ? "original" : "copy");
  57. snd_iprintf(buffer, "Source Mask : %i\n", (status & SPCS_SOURCENUMMASK) >> 16);
  58. snd_iprintf(buffer, "Channel Number : %s\n", channel[(status & SPCS_CHANNELNUMMASK) >> 20]);
  59. snd_iprintf(buffer, "Sample Rate : %iHz\n", samplerate[(status & SPCS_SAMPLERATEMASK) >> 24]);
  60. snd_iprintf(buffer, "Clock Accuracy : %s\n", clkaccy[(status & SPCS_CLKACCYMASK) >> 28]);
  61. if (rate_reg > 0) {
  62. rate = snd_emu10k1_ptr_read(emu, rate_reg, 0);
  63. snd_iprintf(buffer, "S/PDIF Valid : %s\n", rate & SRCS_SPDIFVALID ? "on" : "off");
  64. snd_iprintf(buffer, "S/PDIF Locked : %s\n", rate & SRCS_SPDIFLOCKED ? "on" : "off");
  65. snd_iprintf(buffer, "Rate Locked : %s\n", rate & SRCS_RATELOCKED ? "on" : "off");
  66. /* From ((Rate * 48000 ) / 262144); */
  67. snd_iprintf(buffer, "Estimated Sample Rate : %d\n", ((rate & 0xFFFFF ) * 375) >> 11);
  68. }
  69. } else {
  70. snd_iprintf(buffer, "No signal detected.\n");
  71. }
  72. }
  73. static void snd_emu10k1_proc_read(struct snd_info_entry *entry,
  74. struct snd_info_buffer *buffer)
  75. {
  76. /* FIXME - output names are in emufx.c too */
  77. static char *creative_outs[32] = {
  78. /* 00 */ "AC97 Left",
  79. /* 01 */ "AC97 Right",
  80. /* 02 */ "Optical IEC958 Left",
  81. /* 03 */ "Optical IEC958 Right",
  82. /* 04 */ "Center",
  83. /* 05 */ "LFE",
  84. /* 06 */ "Headphone Left",
  85. /* 07 */ "Headphone Right",
  86. /* 08 */ "Surround Left",
  87. /* 09 */ "Surround Right",
  88. /* 10 */ "PCM Capture Left",
  89. /* 11 */ "PCM Capture Right",
  90. /* 12 */ "MIC Capture",
  91. /* 13 */ "AC97 Surround Left",
  92. /* 14 */ "AC97 Surround Right",
  93. /* 15 */ "???",
  94. /* 16 */ "???",
  95. /* 17 */ "Analog Center",
  96. /* 18 */ "Analog LFE",
  97. /* 19 */ "???",
  98. /* 20 */ "???",
  99. /* 21 */ "???",
  100. /* 22 */ "???",
  101. /* 23 */ "???",
  102. /* 24 */ "???",
  103. /* 25 */ "???",
  104. /* 26 */ "???",
  105. /* 27 */ "???",
  106. /* 28 */ "???",
  107. /* 29 */ "???",
  108. /* 30 */ "???",
  109. /* 31 */ "???"
  110. };
  111. static char *audigy_outs[64] = {
  112. /* 00 */ "Digital Front Left",
  113. /* 01 */ "Digital Front Right",
  114. /* 02 */ "Digital Center",
  115. /* 03 */ "Digital LEF",
  116. /* 04 */ "Headphone Left",
  117. /* 05 */ "Headphone Right",
  118. /* 06 */ "Digital Rear Left",
  119. /* 07 */ "Digital Rear Right",
  120. /* 08 */ "Front Left",
  121. /* 09 */ "Front Right",
  122. /* 10 */ "Center",
  123. /* 11 */ "LFE",
  124. /* 12 */ "???",
  125. /* 13 */ "???",
  126. /* 14 */ "Rear Left",
  127. /* 15 */ "Rear Right",
  128. /* 16 */ "AC97 Front Left",
  129. /* 17 */ "AC97 Front Right",
  130. /* 18 */ "ADC Caputre Left",
  131. /* 19 */ "ADC Capture Right",
  132. /* 20 */ "???",
  133. /* 21 */ "???",
  134. /* 22 */ "???",
  135. /* 23 */ "???",
  136. /* 24 */ "???",
  137. /* 25 */ "???",
  138. /* 26 */ "???",
  139. /* 27 */ "???",
  140. /* 28 */ "???",
  141. /* 29 */ "???",
  142. /* 30 */ "???",
  143. /* 31 */ "???",
  144. /* 32 */ "FXBUS2_0",
  145. /* 33 */ "FXBUS2_1",
  146. /* 34 */ "FXBUS2_2",
  147. /* 35 */ "FXBUS2_3",
  148. /* 36 */ "FXBUS2_4",
  149. /* 37 */ "FXBUS2_5",
  150. /* 38 */ "FXBUS2_6",
  151. /* 39 */ "FXBUS2_7",
  152. /* 40 */ "FXBUS2_8",
  153. /* 41 */ "FXBUS2_9",
  154. /* 42 */ "FXBUS2_10",
  155. /* 43 */ "FXBUS2_11",
  156. /* 44 */ "FXBUS2_12",
  157. /* 45 */ "FXBUS2_13",
  158. /* 46 */ "FXBUS2_14",
  159. /* 47 */ "FXBUS2_15",
  160. /* 48 */ "FXBUS2_16",
  161. /* 49 */ "FXBUS2_17",
  162. /* 50 */ "FXBUS2_18",
  163. /* 51 */ "FXBUS2_19",
  164. /* 52 */ "FXBUS2_20",
  165. /* 53 */ "FXBUS2_21",
  166. /* 54 */ "FXBUS2_22",
  167. /* 55 */ "FXBUS2_23",
  168. /* 56 */ "FXBUS2_24",
  169. /* 57 */ "FXBUS2_25",
  170. /* 58 */ "FXBUS2_26",
  171. /* 59 */ "FXBUS2_27",
  172. /* 60 */ "FXBUS2_28",
  173. /* 61 */ "FXBUS2_29",
  174. /* 62 */ "FXBUS2_30",
  175. /* 63 */ "FXBUS2_31"
  176. };
  177. struct snd_emu10k1 *emu = entry->private_data;
  178. unsigned int val, val1;
  179. int nefx = emu->audigy ? 64 : 32;
  180. char **outputs = emu->audigy ? audigy_outs : creative_outs;
  181. int idx;
  182. snd_iprintf(buffer, "EMU10K1\n\n");
  183. snd_iprintf(buffer, "Card : %s\n",
  184. emu->audigy ? "Audigy" : (emu->card_capabilities->ecard ? "EMU APS" : "Creative"));
  185. snd_iprintf(buffer, "Internal TRAM (words) : 0x%x\n", emu->fx8010.itram_size);
  186. snd_iprintf(buffer, "External TRAM (words) : 0x%x\n", (int)emu->fx8010.etram_pages.bytes / 2);
  187. snd_iprintf(buffer, "\n");
  188. snd_iprintf(buffer, "Effect Send Routing :\n");
  189. for (idx = 0; idx < NUM_G; idx++) {
  190. val = emu->audigy ?
  191. snd_emu10k1_ptr_read(emu, A_FXRT1, idx) :
  192. snd_emu10k1_ptr_read(emu, FXRT, idx);
  193. val1 = emu->audigy ?
  194. snd_emu10k1_ptr_read(emu, A_FXRT2, idx) :
  195. 0;
  196. if (emu->audigy) {
  197. snd_iprintf(buffer, "Ch%i: A=%i, B=%i, C=%i, D=%i, ",
  198. idx,
  199. val & 0x3f,
  200. (val >> 8) & 0x3f,
  201. (val >> 16) & 0x3f,
  202. (val >> 24) & 0x3f);
  203. snd_iprintf(buffer, "E=%i, F=%i, G=%i, H=%i\n",
  204. val1 & 0x3f,
  205. (val1 >> 8) & 0x3f,
  206. (val1 >> 16) & 0x3f,
  207. (val1 >> 24) & 0x3f);
  208. } else {
  209. snd_iprintf(buffer, "Ch%i: A=%i, B=%i, C=%i, D=%i\n",
  210. idx,
  211. (val >> 16) & 0x0f,
  212. (val >> 20) & 0x0f,
  213. (val >> 24) & 0x0f,
  214. (val >> 28) & 0x0f);
  215. }
  216. }
  217. snd_iprintf(buffer, "\nCaptured FX Outputs :\n");
  218. for (idx = 0; idx < nefx; idx++) {
  219. if (emu->efx_voices_mask[idx/32] & (1 << (idx%32)))
  220. snd_iprintf(buffer, " Output %02i [%s]\n", idx, outputs[idx]);
  221. }
  222. snd_iprintf(buffer, "\nAll FX Outputs :\n");
  223. for (idx = 0; idx < (emu->audigy ? 64 : 32); idx++)
  224. snd_iprintf(buffer, " Output %02i [%s]\n", idx, outputs[idx]);
  225. }
  226. static void snd_emu10k1_proc_spdif_read(struct snd_info_entry *entry,
  227. struct snd_info_buffer *buffer)
  228. {
  229. struct snd_emu10k1 *emu = entry->private_data;
  230. u32 value;
  231. u32 value2;
  232. unsigned long flags;
  233. u32 rate;
  234. if (emu->card_capabilities->emu_model) {
  235. spin_lock_irqsave(&emu->emu_lock, flags);
  236. snd_emu1010_fpga_read(emu, 0x38, &value);
  237. spin_unlock_irqrestore(&emu->emu_lock, flags);
  238. if ((value & 0x1) == 0) {
  239. spin_lock_irqsave(&emu->emu_lock, flags);
  240. snd_emu1010_fpga_read(emu, 0x2a, &value);
  241. snd_emu1010_fpga_read(emu, 0x2b, &value2);
  242. spin_unlock_irqrestore(&emu->emu_lock, flags);
  243. rate = 0x1770000 / (((value << 5) | value2)+1);
  244. snd_iprintf(buffer, "ADAT Locked : %u\n", rate);
  245. } else {
  246. snd_iprintf(buffer, "ADAT Unlocked\n");
  247. }
  248. spin_lock_irqsave(&emu->emu_lock, flags);
  249. snd_emu1010_fpga_read(emu, 0x20, &value);
  250. spin_unlock_irqrestore(&emu->emu_lock, flags);
  251. if ((value & 0x4) == 0) {
  252. spin_lock_irqsave(&emu->emu_lock, flags);
  253. snd_emu1010_fpga_read(emu, 0x28, &value);
  254. snd_emu1010_fpga_read(emu, 0x29, &value2);
  255. spin_unlock_irqrestore(&emu->emu_lock, flags);
  256. rate = 0x1770000 / (((value << 5) | value2)+1);
  257. snd_iprintf(buffer, "SPDIF Locked : %d\n", rate);
  258. } else {
  259. snd_iprintf(buffer, "SPDIF Unlocked\n");
  260. }
  261. } else {
  262. snd_emu10k1_proc_spdif_status(emu, buffer, "CD-ROM S/PDIF In", CDCS, CDSRCS);
  263. snd_emu10k1_proc_spdif_status(emu, buffer, "Optical or Coax S/PDIF In", GPSCS, GPSRCS);
  264. }
  265. #if 0
  266. val = snd_emu10k1_ptr_read(emu, ZVSRCS, 0);
  267. snd_iprintf(buffer, "\nZoomed Video\n");
  268. snd_iprintf(buffer, "Rate Locked : %s\n", val & SRCS_RATELOCKED ? "on" : "off");
  269. snd_iprintf(buffer, "Estimated Sample Rate : 0x%x\n", val & SRCS_ESTSAMPLERATE);
  270. #endif
  271. }
  272. static void snd_emu10k1_proc_rates_read(struct snd_info_entry *entry,
  273. struct snd_info_buffer *buffer)
  274. {
  275. static int samplerate[8] = { 44100, 48000, 96000, 192000, 4, 5, 6, 7 };
  276. struct snd_emu10k1 *emu = entry->private_data;
  277. unsigned int val, tmp, n;
  278. val = snd_emu10k1_ptr20_read(emu, CAPTURE_RATE_STATUS, 0);
  279. tmp = (val >> 16) & 0x8;
  280. for (n = 0; n < 4; n++) {
  281. tmp = val >> (16 + (n*4));
  282. if (tmp & 0x8) snd_iprintf(buffer, "Channel %d: Rate=%d\n", n, samplerate[tmp & 0x7]);
  283. else snd_iprintf(buffer, "Channel %d: No input\n", n);
  284. }
  285. }
  286. static void snd_emu10k1_proc_acode_read(struct snd_info_entry *entry,
  287. struct snd_info_buffer *buffer)
  288. {
  289. u32 pc;
  290. struct snd_emu10k1 *emu = entry->private_data;
  291. snd_iprintf(buffer, "FX8010 Instruction List '%s'\n", emu->fx8010.name);
  292. snd_iprintf(buffer, " Code dump :\n");
  293. for (pc = 0; pc < (emu->audigy ? 1024 : 512); pc++) {
  294. u32 low, high;
  295. low = snd_emu10k1_efx_read(emu, pc * 2);
  296. high = snd_emu10k1_efx_read(emu, pc * 2 + 1);
  297. if (emu->audigy)
  298. snd_iprintf(buffer, " OP(0x%02x, 0x%03x, 0x%03x, 0x%03x, 0x%03x) /* 0x%04x: 0x%08x%08x */\n",
  299. (high >> 24) & 0x0f,
  300. (high >> 12) & 0x7ff,
  301. (high >> 0) & 0x7ff,
  302. (low >> 12) & 0x7ff,
  303. (low >> 0) & 0x7ff,
  304. pc,
  305. high, low);
  306. else
  307. snd_iprintf(buffer, " OP(0x%02x, 0x%03x, 0x%03x, 0x%03x, 0x%03x) /* 0x%04x: 0x%08x%08x */\n",
  308. (high >> 20) & 0x0f,
  309. (high >> 10) & 0x3ff,
  310. (high >> 0) & 0x3ff,
  311. (low >> 10) & 0x3ff,
  312. (low >> 0) & 0x3ff,
  313. pc,
  314. high, low);
  315. }
  316. }
  317. #define TOTAL_SIZE_GPR (0x100*4)
  318. #define A_TOTAL_SIZE_GPR (0x200*4)
  319. #define TOTAL_SIZE_TANKMEM_DATA (0xa0*4)
  320. #define TOTAL_SIZE_TANKMEM_ADDR (0xa0*4)
  321. #define A_TOTAL_SIZE_TANKMEM_DATA (0x100*4)
  322. #define A_TOTAL_SIZE_TANKMEM_ADDR (0x100*4)
  323. #define TOTAL_SIZE_CODE (0x200*8)
  324. #define A_TOTAL_SIZE_CODE (0x400*8)
  325. static long snd_emu10k1_fx8010_read(struct snd_info_entry *entry,
  326. void *file_private_data,
  327. struct file *file, char __user *buf,
  328. unsigned long count, unsigned long pos)
  329. {
  330. long size;
  331. struct snd_emu10k1 *emu = entry->private_data;
  332. unsigned int offset;
  333. int tram_addr = 0;
  334. if (!strcmp(entry->name, "fx8010_tram_addr")) {
  335. offset = TANKMEMADDRREGBASE;
  336. tram_addr = 1;
  337. } else if (!strcmp(entry->name, "fx8010_tram_data")) {
  338. offset = TANKMEMDATAREGBASE;
  339. } else if (!strcmp(entry->name, "fx8010_code")) {
  340. offset = emu->audigy ? A_MICROCODEBASE : MICROCODEBASE;
  341. } else {
  342. offset = emu->audigy ? A_FXGPREGBASE : FXGPREGBASE;
  343. }
  344. size = count;
  345. if (pos + size > entry->size)
  346. size = (long)entry->size - pos;
  347. if (size > 0) {
  348. unsigned int *tmp;
  349. long res;
  350. unsigned int idx;
  351. if ((tmp = kmalloc(size + 8, GFP_KERNEL)) == NULL)
  352. return -ENOMEM;
  353. for (idx = 0; idx < ((pos & 3) + size + 3) >> 2; idx++)
  354. if (tram_addr && emu->audigy) {
  355. tmp[idx] = snd_emu10k1_ptr_read(emu, offset + idx + (pos >> 2), 0) >> 11;
  356. tmp[idx] |= snd_emu10k1_ptr_read(emu, 0x100 + idx + (pos >> 2), 0) << 20;
  357. } else
  358. tmp[idx] = snd_emu10k1_ptr_read(emu, offset + idx + (pos >> 2), 0);
  359. if (copy_to_user(buf, ((char *)tmp) + (pos & 3), size))
  360. res = -EFAULT;
  361. else {
  362. res = size;
  363. }
  364. kfree(tmp);
  365. return res;
  366. }
  367. return 0;
  368. }
  369. static void snd_emu10k1_proc_voices_read(struct snd_info_entry *entry,
  370. struct snd_info_buffer *buffer)
  371. {
  372. struct snd_emu10k1 *emu = entry->private_data;
  373. struct snd_emu10k1_voice *voice;
  374. int idx;
  375. snd_iprintf(buffer, "ch\tuse\tpcm\tefx\tsynth\tmidi\n");
  376. for (idx = 0; idx < NUM_G; idx++) {
  377. voice = &emu->voices[idx];
  378. snd_iprintf(buffer, "%i\t%i\t%i\t%i\t%i\t%i\n",
  379. idx,
  380. voice->use,
  381. voice->pcm,
  382. voice->efx,
  383. voice->synth,
  384. voice->midi);
  385. }
  386. }
  387. #ifdef CONFIG_SND_DEBUG
  388. static void snd_emu_proc_emu1010_reg_read(struct snd_info_entry *entry,
  389. struct snd_info_buffer *buffer)
  390. {
  391. struct snd_emu10k1 *emu = entry->private_data;
  392. u32 value;
  393. unsigned long flags;
  394. int i;
  395. snd_iprintf(buffer, "EMU1010 Registers:\n\n");
  396. for(i = 0; i < 0x40; i+=1) {
  397. spin_lock_irqsave(&emu->emu_lock, flags);
  398. snd_emu1010_fpga_read(emu, i, &value);
  399. spin_unlock_irqrestore(&emu->emu_lock, flags);
  400. snd_iprintf(buffer, "%02X: %08X, %02X\n", i, value, (value >> 8) & 0x7f);
  401. }
  402. }
  403. static void snd_emu_proc_io_reg_read(struct snd_info_entry *entry,
  404. struct snd_info_buffer *buffer)
  405. {
  406. struct snd_emu10k1 *emu = entry->private_data;
  407. unsigned long value;
  408. unsigned long flags;
  409. int i;
  410. snd_iprintf(buffer, "IO Registers:\n\n");
  411. for(i = 0; i < 0x40; i+=4) {
  412. spin_lock_irqsave(&emu->emu_lock, flags);
  413. value = inl(emu->port + i);
  414. spin_unlock_irqrestore(&emu->emu_lock, flags);
  415. snd_iprintf(buffer, "%02X: %08lX\n", i, value);
  416. }
  417. }
  418. static void snd_emu_proc_io_reg_write(struct snd_info_entry *entry,
  419. struct snd_info_buffer *buffer)
  420. {
  421. struct snd_emu10k1 *emu = entry->private_data;
  422. unsigned long flags;
  423. char line[64];
  424. u32 reg, val;
  425. while (!snd_info_get_line(buffer, line, sizeof(line))) {
  426. if (sscanf(line, "%x %x", &reg, &val) != 2)
  427. continue;
  428. if ((reg < 0x40) && (reg >= 0) && (val <= 0xffffffff) ) {
  429. spin_lock_irqsave(&emu->emu_lock, flags);
  430. outl(val, emu->port + (reg & 0xfffffffc));
  431. spin_unlock_irqrestore(&emu->emu_lock, flags);
  432. }
  433. }
  434. }
  435. static unsigned int snd_ptr_read(struct snd_emu10k1 * emu,
  436. unsigned int iobase,
  437. unsigned int reg,
  438. unsigned int chn)
  439. {
  440. unsigned long flags;
  441. unsigned int regptr, val;
  442. regptr = (reg << 16) | chn;
  443. spin_lock_irqsave(&emu->emu_lock, flags);
  444. outl(regptr, emu->port + iobase + PTR);
  445. val = inl(emu->port + iobase + DATA);
  446. spin_unlock_irqrestore(&emu->emu_lock, flags);
  447. return val;
  448. }
  449. static void snd_ptr_write(struct snd_emu10k1 *emu,
  450. unsigned int iobase,
  451. unsigned int reg,
  452. unsigned int chn,
  453. unsigned int data)
  454. {
  455. unsigned int regptr;
  456. unsigned long flags;
  457. regptr = (reg << 16) | chn;
  458. spin_lock_irqsave(&emu->emu_lock, flags);
  459. outl(regptr, emu->port + iobase + PTR);
  460. outl(data, emu->port + iobase + DATA);
  461. spin_unlock_irqrestore(&emu->emu_lock, flags);
  462. }
  463. static void snd_emu_proc_ptr_reg_read(struct snd_info_entry *entry,
  464. struct snd_info_buffer *buffer, int iobase, int offset, int length, int voices)
  465. {
  466. struct snd_emu10k1 *emu = entry->private_data;
  467. unsigned long value;
  468. int i,j;
  469. if (offset+length > 0xa0) {
  470. snd_iprintf(buffer, "Input values out of range\n");
  471. return;
  472. }
  473. snd_iprintf(buffer, "Registers 0x%x\n", iobase);
  474. for(i = offset; i < offset+length; i++) {
  475. snd_iprintf(buffer, "%02X: ",i);
  476. for (j = 0; j < voices; j++) {
  477. if(iobase == 0)
  478. value = snd_ptr_read(emu, 0, i, j);
  479. else
  480. value = snd_ptr_read(emu, 0x20, i, j);
  481. snd_iprintf(buffer, "%08lX ", value);
  482. }
  483. snd_iprintf(buffer, "\n");
  484. }
  485. }
  486. static void snd_emu_proc_ptr_reg_write(struct snd_info_entry *entry,
  487. struct snd_info_buffer *buffer, int iobase)
  488. {
  489. struct snd_emu10k1 *emu = entry->private_data;
  490. char line[64];
  491. unsigned int reg, channel_id , val;
  492. while (!snd_info_get_line(buffer, line, sizeof(line))) {
  493. if (sscanf(line, "%x %x %x", &reg, &channel_id, &val) != 3)
  494. continue;
  495. if ((reg < 0xa0) && (reg >= 0) && (val <= 0xffffffff) && (channel_id >= 0) && (channel_id <= 3) )
  496. snd_ptr_write(emu, iobase, reg, channel_id, val);
  497. }
  498. }
  499. static void snd_emu_proc_ptr_reg_write00(struct snd_info_entry *entry,
  500. struct snd_info_buffer *buffer)
  501. {
  502. snd_emu_proc_ptr_reg_write(entry, buffer, 0);
  503. }
  504. static void snd_emu_proc_ptr_reg_write20(struct snd_info_entry *entry,
  505. struct snd_info_buffer *buffer)
  506. {
  507. snd_emu_proc_ptr_reg_write(entry, buffer, 0x20);
  508. }
  509. static void snd_emu_proc_ptr_reg_read00a(struct snd_info_entry *entry,
  510. struct snd_info_buffer *buffer)
  511. {
  512. snd_emu_proc_ptr_reg_read(entry, buffer, 0, 0, 0x40, 64);
  513. }
  514. static void snd_emu_proc_ptr_reg_read00b(struct snd_info_entry *entry,
  515. struct snd_info_buffer *buffer)
  516. {
  517. snd_emu_proc_ptr_reg_read(entry, buffer, 0, 0x40, 0x40, 64);
  518. }
  519. static void snd_emu_proc_ptr_reg_read20a(struct snd_info_entry *entry,
  520. struct snd_info_buffer *buffer)
  521. {
  522. snd_emu_proc_ptr_reg_read(entry, buffer, 0x20, 0, 0x40, 4);
  523. }
  524. static void snd_emu_proc_ptr_reg_read20b(struct snd_info_entry *entry,
  525. struct snd_info_buffer *buffer)
  526. {
  527. snd_emu_proc_ptr_reg_read(entry, buffer, 0x20, 0x40, 0x40, 4);
  528. }
  529. static void snd_emu_proc_ptr_reg_read20c(struct snd_info_entry *entry,
  530. struct snd_info_buffer * buffer)
  531. {
  532. snd_emu_proc_ptr_reg_read(entry, buffer, 0x20, 0x80, 0x20, 4);
  533. }
  534. #endif
  535. static struct snd_info_entry_ops snd_emu10k1_proc_ops_fx8010 = {
  536. .read = snd_emu10k1_fx8010_read,
  537. };
  538. int __devinit snd_emu10k1_proc_init(struct snd_emu10k1 * emu)
  539. {
  540. struct snd_info_entry *entry;
  541. #ifdef CONFIG_SND_DEBUG
  542. if (emu->card_capabilities->emu_model) {
  543. if (! snd_card_proc_new(emu->card, "emu1010_regs", &entry))
  544. snd_info_set_text_ops(entry, emu, snd_emu_proc_emu1010_reg_read);
  545. }
  546. if (! snd_card_proc_new(emu->card, "io_regs", &entry)) {
  547. snd_info_set_text_ops(entry, emu, snd_emu_proc_io_reg_read);
  548. entry->c.text.write = snd_emu_proc_io_reg_write;
  549. entry->mode |= S_IWUSR;
  550. }
  551. if (! snd_card_proc_new(emu->card, "ptr_regs00a", &entry)) {
  552. snd_info_set_text_ops(entry, emu, snd_emu_proc_ptr_reg_read00a);
  553. entry->c.text.write = snd_emu_proc_ptr_reg_write00;
  554. entry->mode |= S_IWUSR;
  555. }
  556. if (! snd_card_proc_new(emu->card, "ptr_regs00b", &entry)) {
  557. snd_info_set_text_ops(entry, emu, snd_emu_proc_ptr_reg_read00b);
  558. entry->c.text.write = snd_emu_proc_ptr_reg_write00;
  559. entry->mode |= S_IWUSR;
  560. }
  561. if (! snd_card_proc_new(emu->card, "ptr_regs20a", &entry)) {
  562. snd_info_set_text_ops(entry, emu, snd_emu_proc_ptr_reg_read20a);
  563. entry->c.text.write = snd_emu_proc_ptr_reg_write20;
  564. entry->mode |= S_IWUSR;
  565. }
  566. if (! snd_card_proc_new(emu->card, "ptr_regs20b", &entry)) {
  567. snd_info_set_text_ops(entry, emu, snd_emu_proc_ptr_reg_read20b);
  568. entry->c.text.write = snd_emu_proc_ptr_reg_write20;
  569. entry->mode |= S_IWUSR;
  570. }
  571. if (! snd_card_proc_new(emu->card, "ptr_regs20c", &entry)) {
  572. snd_info_set_text_ops(entry, emu, snd_emu_proc_ptr_reg_read20c);
  573. entry->c.text.write = snd_emu_proc_ptr_reg_write20;
  574. entry->mode |= S_IWUSR;
  575. }
  576. #endif
  577. if (! snd_card_proc_new(emu->card, "emu10k1", &entry))
  578. snd_info_set_text_ops(entry, emu, snd_emu10k1_proc_read);
  579. if (emu->card_capabilities->emu10k2_chip) {
  580. if (! snd_card_proc_new(emu->card, "spdif-in", &entry))
  581. snd_info_set_text_ops(entry, emu, snd_emu10k1_proc_spdif_read);
  582. }
  583. if (emu->card_capabilities->ca0151_chip) {
  584. if (! snd_card_proc_new(emu->card, "capture-rates", &entry))
  585. snd_info_set_text_ops(entry, emu, snd_emu10k1_proc_rates_read);
  586. }
  587. if (! snd_card_proc_new(emu->card, "voices", &entry))
  588. snd_info_set_text_ops(entry, emu, snd_emu10k1_proc_voices_read);
  589. if (! snd_card_proc_new(emu->card, "fx8010_gpr", &entry)) {
  590. entry->content = SNDRV_INFO_CONTENT_DATA;
  591. entry->private_data = emu;
  592. entry->mode = S_IFREG | S_IRUGO /*| S_IWUSR*/;
  593. entry->size = emu->audigy ? A_TOTAL_SIZE_GPR : TOTAL_SIZE_GPR;
  594. entry->c.ops = &snd_emu10k1_proc_ops_fx8010;
  595. }
  596. if (! snd_card_proc_new(emu->card, "fx8010_tram_data", &entry)) {
  597. entry->content = SNDRV_INFO_CONTENT_DATA;
  598. entry->private_data = emu;
  599. entry->mode = S_IFREG | S_IRUGO /*| S_IWUSR*/;
  600. entry->size = emu->audigy ? A_TOTAL_SIZE_TANKMEM_DATA : TOTAL_SIZE_TANKMEM_DATA ;
  601. entry->c.ops = &snd_emu10k1_proc_ops_fx8010;
  602. }
  603. if (! snd_card_proc_new(emu->card, "fx8010_tram_addr", &entry)) {
  604. entry->content = SNDRV_INFO_CONTENT_DATA;
  605. entry->private_data = emu;
  606. entry->mode = S_IFREG | S_IRUGO /*| S_IWUSR*/;
  607. entry->size = emu->audigy ? A_TOTAL_SIZE_TANKMEM_ADDR : TOTAL_SIZE_TANKMEM_ADDR ;
  608. entry->c.ops = &snd_emu10k1_proc_ops_fx8010;
  609. }
  610. if (! snd_card_proc_new(emu->card, "fx8010_code", &entry)) {
  611. entry->content = SNDRV_INFO_CONTENT_DATA;
  612. entry->private_data = emu;
  613. entry->mode = S_IFREG | S_IRUGO /*| S_IWUSR*/;
  614. entry->size = emu->audigy ? A_TOTAL_SIZE_CODE : TOTAL_SIZE_CODE;
  615. entry->c.ops = &snd_emu10k1_proc_ops_fx8010;
  616. }
  617. if (! snd_card_proc_new(emu->card, "fx8010_acode", &entry)) {
  618. entry->content = SNDRV_INFO_CONTENT_TEXT;
  619. entry->private_data = emu;
  620. entry->mode = S_IFREG | S_IRUGO /*| S_IWUSR*/;
  621. entry->c.text.read = snd_emu10k1_proc_acode_read;
  622. }
  623. return 0;
  624. }
  625. #endif /* CONFIG_PROC_FS */