emuproc.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671
  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 ssize_t snd_emu10k1_fx8010_read(struct snd_info_entry *entry,
  326. void *file_private_data,
  327. struct file *file, char __user *buf,
  328. size_t count, loff_t pos)
  329. {
  330. struct snd_emu10k1 *emu = entry->private_data;
  331. unsigned int offset;
  332. int tram_addr = 0;
  333. unsigned int *tmp;
  334. long res;
  335. unsigned int idx;
  336. if (!strcmp(entry->name, "fx8010_tram_addr")) {
  337. offset = TANKMEMADDRREGBASE;
  338. tram_addr = 1;
  339. } else if (!strcmp(entry->name, "fx8010_tram_data")) {
  340. offset = TANKMEMDATAREGBASE;
  341. } else if (!strcmp(entry->name, "fx8010_code")) {
  342. offset = emu->audigy ? A_MICROCODEBASE : MICROCODEBASE;
  343. } else {
  344. offset = emu->audigy ? A_FXGPREGBASE : FXGPREGBASE;
  345. }
  346. tmp = kmalloc(count + 8, GFP_KERNEL);
  347. if (!tmp)
  348. return -ENOMEM;
  349. for (idx = 0; idx < ((pos & 3) + count + 3) >> 2; idx++) {
  350. unsigned int val;
  351. val = snd_emu10k1_ptr_read(emu, offset + idx + (pos >> 2), 0);
  352. if (tram_addr && emu->audigy) {
  353. val >>= 11;
  354. val |= snd_emu10k1_ptr_read(emu, 0x100 + idx + (pos >> 2), 0) << 20;
  355. }
  356. tmp[idx] = val;
  357. }
  358. if (copy_to_user(buf, ((char *)tmp) + (pos & 3), count))
  359. res = -EFAULT;
  360. else
  361. res = count;
  362. kfree(tmp);
  363. return res;
  364. }
  365. static void snd_emu10k1_proc_voices_read(struct snd_info_entry *entry,
  366. struct snd_info_buffer *buffer)
  367. {
  368. struct snd_emu10k1 *emu = entry->private_data;
  369. struct snd_emu10k1_voice *voice;
  370. int idx;
  371. snd_iprintf(buffer, "ch\tuse\tpcm\tefx\tsynth\tmidi\n");
  372. for (idx = 0; idx < NUM_G; idx++) {
  373. voice = &emu->voices[idx];
  374. snd_iprintf(buffer, "%i\t%i\t%i\t%i\t%i\t%i\n",
  375. idx,
  376. voice->use,
  377. voice->pcm,
  378. voice->efx,
  379. voice->synth,
  380. voice->midi);
  381. }
  382. }
  383. #ifdef CONFIG_SND_DEBUG
  384. static void snd_emu_proc_emu1010_reg_read(struct snd_info_entry *entry,
  385. struct snd_info_buffer *buffer)
  386. {
  387. struct snd_emu10k1 *emu = entry->private_data;
  388. u32 value;
  389. unsigned long flags;
  390. int i;
  391. snd_iprintf(buffer, "EMU1010 Registers:\n\n");
  392. for(i = 0; i < 0x40; i+=1) {
  393. spin_lock_irqsave(&emu->emu_lock, flags);
  394. snd_emu1010_fpga_read(emu, i, &value);
  395. spin_unlock_irqrestore(&emu->emu_lock, flags);
  396. snd_iprintf(buffer, "%02X: %08X, %02X\n", i, value, (value >> 8) & 0x7f);
  397. }
  398. }
  399. static void snd_emu_proc_io_reg_read(struct snd_info_entry *entry,
  400. struct snd_info_buffer *buffer)
  401. {
  402. struct snd_emu10k1 *emu = entry->private_data;
  403. unsigned long value;
  404. unsigned long flags;
  405. int i;
  406. snd_iprintf(buffer, "IO Registers:\n\n");
  407. for(i = 0; i < 0x40; i+=4) {
  408. spin_lock_irqsave(&emu->emu_lock, flags);
  409. value = inl(emu->port + i);
  410. spin_unlock_irqrestore(&emu->emu_lock, flags);
  411. snd_iprintf(buffer, "%02X: %08lX\n", i, value);
  412. }
  413. }
  414. static void snd_emu_proc_io_reg_write(struct snd_info_entry *entry,
  415. struct snd_info_buffer *buffer)
  416. {
  417. struct snd_emu10k1 *emu = entry->private_data;
  418. unsigned long flags;
  419. char line[64];
  420. u32 reg, val;
  421. while (!snd_info_get_line(buffer, line, sizeof(line))) {
  422. if (sscanf(line, "%x %x", &reg, &val) != 2)
  423. continue;
  424. if (reg < 0x40 && val <= 0xffffffff) {
  425. spin_lock_irqsave(&emu->emu_lock, flags);
  426. outl(val, emu->port + (reg & 0xfffffffc));
  427. spin_unlock_irqrestore(&emu->emu_lock, flags);
  428. }
  429. }
  430. }
  431. static unsigned int snd_ptr_read(struct snd_emu10k1 * emu,
  432. unsigned int iobase,
  433. unsigned int reg,
  434. unsigned int chn)
  435. {
  436. unsigned long flags;
  437. unsigned int regptr, val;
  438. regptr = (reg << 16) | chn;
  439. spin_lock_irqsave(&emu->emu_lock, flags);
  440. outl(regptr, emu->port + iobase + PTR);
  441. val = inl(emu->port + iobase + DATA);
  442. spin_unlock_irqrestore(&emu->emu_lock, flags);
  443. return val;
  444. }
  445. static void snd_ptr_write(struct snd_emu10k1 *emu,
  446. unsigned int iobase,
  447. unsigned int reg,
  448. unsigned int chn,
  449. unsigned int data)
  450. {
  451. unsigned int regptr;
  452. unsigned long flags;
  453. regptr = (reg << 16) | chn;
  454. spin_lock_irqsave(&emu->emu_lock, flags);
  455. outl(regptr, emu->port + iobase + PTR);
  456. outl(data, emu->port + iobase + DATA);
  457. spin_unlock_irqrestore(&emu->emu_lock, flags);
  458. }
  459. static void snd_emu_proc_ptr_reg_read(struct snd_info_entry *entry,
  460. struct snd_info_buffer *buffer, int iobase, int offset, int length, int voices)
  461. {
  462. struct snd_emu10k1 *emu = entry->private_data;
  463. unsigned long value;
  464. int i,j;
  465. if (offset+length > 0xa0) {
  466. snd_iprintf(buffer, "Input values out of range\n");
  467. return;
  468. }
  469. snd_iprintf(buffer, "Registers 0x%x\n", iobase);
  470. for(i = offset; i < offset+length; i++) {
  471. snd_iprintf(buffer, "%02X: ",i);
  472. for (j = 0; j < voices; j++) {
  473. if(iobase == 0)
  474. value = snd_ptr_read(emu, 0, i, j);
  475. else
  476. value = snd_ptr_read(emu, 0x20, i, j);
  477. snd_iprintf(buffer, "%08lX ", value);
  478. }
  479. snd_iprintf(buffer, "\n");
  480. }
  481. }
  482. static void snd_emu_proc_ptr_reg_write(struct snd_info_entry *entry,
  483. struct snd_info_buffer *buffer, int iobase)
  484. {
  485. struct snd_emu10k1 *emu = entry->private_data;
  486. char line[64];
  487. unsigned int reg, channel_id , val;
  488. while (!snd_info_get_line(buffer, line, sizeof(line))) {
  489. if (sscanf(line, "%x %x %x", &reg, &channel_id, &val) != 3)
  490. continue;
  491. if (reg < 0xa0 && val <= 0xffffffff && channel_id <= 3)
  492. snd_ptr_write(emu, iobase, reg, channel_id, val);
  493. }
  494. }
  495. static void snd_emu_proc_ptr_reg_write00(struct snd_info_entry *entry,
  496. struct snd_info_buffer *buffer)
  497. {
  498. snd_emu_proc_ptr_reg_write(entry, buffer, 0);
  499. }
  500. static void snd_emu_proc_ptr_reg_write20(struct snd_info_entry *entry,
  501. struct snd_info_buffer *buffer)
  502. {
  503. snd_emu_proc_ptr_reg_write(entry, buffer, 0x20);
  504. }
  505. static void snd_emu_proc_ptr_reg_read00a(struct snd_info_entry *entry,
  506. struct snd_info_buffer *buffer)
  507. {
  508. snd_emu_proc_ptr_reg_read(entry, buffer, 0, 0, 0x40, 64);
  509. }
  510. static void snd_emu_proc_ptr_reg_read00b(struct snd_info_entry *entry,
  511. struct snd_info_buffer *buffer)
  512. {
  513. snd_emu_proc_ptr_reg_read(entry, buffer, 0, 0x40, 0x40, 64);
  514. }
  515. static void snd_emu_proc_ptr_reg_read20a(struct snd_info_entry *entry,
  516. struct snd_info_buffer *buffer)
  517. {
  518. snd_emu_proc_ptr_reg_read(entry, buffer, 0x20, 0, 0x40, 4);
  519. }
  520. static void snd_emu_proc_ptr_reg_read20b(struct snd_info_entry *entry,
  521. struct snd_info_buffer *buffer)
  522. {
  523. snd_emu_proc_ptr_reg_read(entry, buffer, 0x20, 0x40, 0x40, 4);
  524. }
  525. static void snd_emu_proc_ptr_reg_read20c(struct snd_info_entry *entry,
  526. struct snd_info_buffer * buffer)
  527. {
  528. snd_emu_proc_ptr_reg_read(entry, buffer, 0x20, 0x80, 0x20, 4);
  529. }
  530. #endif
  531. static struct snd_info_entry_ops snd_emu10k1_proc_ops_fx8010 = {
  532. .read = snd_emu10k1_fx8010_read,
  533. };
  534. int __devinit snd_emu10k1_proc_init(struct snd_emu10k1 * emu)
  535. {
  536. struct snd_info_entry *entry;
  537. #ifdef CONFIG_SND_DEBUG
  538. if (emu->card_capabilities->emu_model) {
  539. if (! snd_card_proc_new(emu->card, "emu1010_regs", &entry))
  540. snd_info_set_text_ops(entry, emu, snd_emu_proc_emu1010_reg_read);
  541. }
  542. if (! snd_card_proc_new(emu->card, "io_regs", &entry)) {
  543. snd_info_set_text_ops(entry, emu, snd_emu_proc_io_reg_read);
  544. entry->c.text.write = snd_emu_proc_io_reg_write;
  545. entry->mode |= S_IWUSR;
  546. }
  547. if (! snd_card_proc_new(emu->card, "ptr_regs00a", &entry)) {
  548. snd_info_set_text_ops(entry, emu, snd_emu_proc_ptr_reg_read00a);
  549. entry->c.text.write = snd_emu_proc_ptr_reg_write00;
  550. entry->mode |= S_IWUSR;
  551. }
  552. if (! snd_card_proc_new(emu->card, "ptr_regs00b", &entry)) {
  553. snd_info_set_text_ops(entry, emu, snd_emu_proc_ptr_reg_read00b);
  554. entry->c.text.write = snd_emu_proc_ptr_reg_write00;
  555. entry->mode |= S_IWUSR;
  556. }
  557. if (! snd_card_proc_new(emu->card, "ptr_regs20a", &entry)) {
  558. snd_info_set_text_ops(entry, emu, snd_emu_proc_ptr_reg_read20a);
  559. entry->c.text.write = snd_emu_proc_ptr_reg_write20;
  560. entry->mode |= S_IWUSR;
  561. }
  562. if (! snd_card_proc_new(emu->card, "ptr_regs20b", &entry)) {
  563. snd_info_set_text_ops(entry, emu, snd_emu_proc_ptr_reg_read20b);
  564. entry->c.text.write = snd_emu_proc_ptr_reg_write20;
  565. entry->mode |= S_IWUSR;
  566. }
  567. if (! snd_card_proc_new(emu->card, "ptr_regs20c", &entry)) {
  568. snd_info_set_text_ops(entry, emu, snd_emu_proc_ptr_reg_read20c);
  569. entry->c.text.write = snd_emu_proc_ptr_reg_write20;
  570. entry->mode |= S_IWUSR;
  571. }
  572. #endif
  573. if (! snd_card_proc_new(emu->card, "emu10k1", &entry))
  574. snd_info_set_text_ops(entry, emu, snd_emu10k1_proc_read);
  575. if (emu->card_capabilities->emu10k2_chip) {
  576. if (! snd_card_proc_new(emu->card, "spdif-in", &entry))
  577. snd_info_set_text_ops(entry, emu, snd_emu10k1_proc_spdif_read);
  578. }
  579. if (emu->card_capabilities->ca0151_chip) {
  580. if (! snd_card_proc_new(emu->card, "capture-rates", &entry))
  581. snd_info_set_text_ops(entry, emu, snd_emu10k1_proc_rates_read);
  582. }
  583. if (! snd_card_proc_new(emu->card, "voices", &entry))
  584. snd_info_set_text_ops(entry, emu, snd_emu10k1_proc_voices_read);
  585. if (! snd_card_proc_new(emu->card, "fx8010_gpr", &entry)) {
  586. entry->content = SNDRV_INFO_CONTENT_DATA;
  587. entry->private_data = emu;
  588. entry->mode = S_IFREG | S_IRUGO /*| S_IWUSR*/;
  589. entry->size = emu->audigy ? A_TOTAL_SIZE_GPR : TOTAL_SIZE_GPR;
  590. entry->c.ops = &snd_emu10k1_proc_ops_fx8010;
  591. }
  592. if (! snd_card_proc_new(emu->card, "fx8010_tram_data", &entry)) {
  593. entry->content = SNDRV_INFO_CONTENT_DATA;
  594. entry->private_data = emu;
  595. entry->mode = S_IFREG | S_IRUGO /*| S_IWUSR*/;
  596. entry->size = emu->audigy ? A_TOTAL_SIZE_TANKMEM_DATA : TOTAL_SIZE_TANKMEM_DATA ;
  597. entry->c.ops = &snd_emu10k1_proc_ops_fx8010;
  598. }
  599. if (! snd_card_proc_new(emu->card, "fx8010_tram_addr", &entry)) {
  600. entry->content = SNDRV_INFO_CONTENT_DATA;
  601. entry->private_data = emu;
  602. entry->mode = S_IFREG | S_IRUGO /*| S_IWUSR*/;
  603. entry->size = emu->audigy ? A_TOTAL_SIZE_TANKMEM_ADDR : TOTAL_SIZE_TANKMEM_ADDR ;
  604. entry->c.ops = &snd_emu10k1_proc_ops_fx8010;
  605. }
  606. if (! snd_card_proc_new(emu->card, "fx8010_code", &entry)) {
  607. entry->content = SNDRV_INFO_CONTENT_DATA;
  608. entry->private_data = emu;
  609. entry->mode = S_IFREG | S_IRUGO /*| S_IWUSR*/;
  610. entry->size = emu->audigy ? A_TOTAL_SIZE_CODE : TOTAL_SIZE_CODE;
  611. entry->c.ops = &snd_emu10k1_proc_ops_fx8010;
  612. }
  613. if (! snd_card_proc_new(emu->card, "fx8010_acode", &entry)) {
  614. entry->content = SNDRV_INFO_CONTENT_TEXT;
  615. entry->private_data = emu;
  616. entry->mode = S_IFREG | S_IRUGO /*| S_IWUSR*/;
  617. entry->c.text.read = snd_emu10k1_proc_acode_read;
  618. }
  619. return 0;
  620. }
  621. #endif /* CONFIG_PROC_FS */