emuproc.c 21 KB

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