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