2 * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
4 * Routines for control of EMU10K1 chips / proc interface routines
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #include <sound/driver.h>
29 #include <linux/slab.h>
30 #include <linux/init.h>
31 #include <sound/core.h>
32 #include <sound/emu10k1.h>
35 static void snd_emu10k1_proc_spdif_status(emu10k1_t * emu,
36 snd_info_buffer_t * buffer,
41 static char *clkaccy[4] = { "1000ppm", "50ppm", "variable", "unknown" };
42 static int samplerate[16] = { 44100, 1, 48000, 32000, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
43 static char *channel[16] = { "unspec", "left", "right", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15" };
44 static char *emphasis[8] = { "none", "50/15 usec 2 channel", "2", "3", "4", "5", "6", "7" };
45 unsigned int status, rate = 0;
47 status = snd_emu10k1_ptr_read(emu, status_reg, 0);
49 snd_iprintf(buffer, "\n%s\n", title);
51 if (status != 0xffffffff) {
52 snd_iprintf(buffer, "Professional Mode : %s\n", (status & SPCS_PROFESSIONAL) ? "yes" : "no");
53 snd_iprintf(buffer, "Not Audio Data : %s\n", (status & SPCS_NOTAUDIODATA) ? "yes" : "no");
54 snd_iprintf(buffer, "Copyright : %s\n", (status & SPCS_COPYRIGHT) ? "yes" : "no");
55 snd_iprintf(buffer, "Emphasis : %s\n", emphasis[(status & SPCS_EMPHASISMASK) >> 3]);
56 snd_iprintf(buffer, "Mode : %i\n", (status & SPCS_MODEMASK) >> 6);
57 snd_iprintf(buffer, "Category Code : 0x%x\n", (status & SPCS_CATEGORYCODEMASK) >> 8);
58 snd_iprintf(buffer, "Generation Status : %s\n", status & SPCS_GENERATIONSTATUS ? "original" : "copy");
59 snd_iprintf(buffer, "Source Mask : %i\n", (status & SPCS_SOURCENUMMASK) >> 16);
60 snd_iprintf(buffer, "Channel Number : %s\n", channel[(status & SPCS_CHANNELNUMMASK) >> 20]);
61 snd_iprintf(buffer, "Sample Rate : %iHz\n", samplerate[(status & SPCS_SAMPLERATEMASK) >> 24]);
62 snd_iprintf(buffer, "Clock Accuracy : %s\n", clkaccy[(status & SPCS_CLKACCYMASK) >> 28]);
65 rate = snd_emu10k1_ptr_read(emu, rate_reg, 0);
66 snd_iprintf(buffer, "S/PDIF Valid : %s\n", rate & SRCS_SPDIFVALID ? "on" : "off");
67 snd_iprintf(buffer, "S/PDIF Locked : %s\n", rate & SRCS_SPDIFLOCKED ? "on" : "off");
68 snd_iprintf(buffer, "Rate Locked : %s\n", rate & SRCS_RATELOCKED ? "on" : "off");
69 /* From ((Rate * 48000 ) / 262144); */
70 snd_iprintf(buffer, "Estimated Sample Rate : %d\n", ((rate & 0xFFFFF ) * 375) >> 11);
73 snd_iprintf(buffer, "No signal detected.\n");
78 static void snd_emu10k1_proc_read(snd_info_entry_t *entry,
79 snd_info_buffer_t * buffer)
81 /* FIXME - output names are in emufx.c too */
82 static char *creative_outs[32] = {
84 /* 01 */ "AC97 Right",
85 /* 02 */ "Optical IEC958 Left",
86 /* 03 */ "Optical IEC958 Right",
89 /* 06 */ "Headphone Left",
90 /* 07 */ "Headphone Right",
91 /* 08 */ "Surround Left",
92 /* 09 */ "Surround Right",
93 /* 10 */ "PCM Capture Left",
94 /* 11 */ "PCM Capture Right",
95 /* 12 */ "MIC Capture",
96 /* 13 */ "AC97 Surround Left",
97 /* 14 */ "AC97 Surround Right",
100 /* 17 */ "Analog Center",
101 /* 18 */ "Analog LFE",
117 static char *audigy_outs[64] = {
118 /* 00 */ "Digital Front Left",
119 /* 01 */ "Digital Front Right",
120 /* 02 */ "Digital Center",
121 /* 03 */ "Digital LEF",
122 /* 04 */ "Headphone Left",
123 /* 05 */ "Headphone Right",
124 /* 06 */ "Digital Rear Left",
125 /* 07 */ "Digital Rear Right",
126 /* 08 */ "Front Left",
127 /* 09 */ "Front Right",
132 /* 14 */ "Rear Left",
133 /* 15 */ "Rear Right",
134 /* 16 */ "AC97 Front Left",
135 /* 17 */ "AC97 Front Right",
136 /* 18 */ "ADC Caputre Left",
137 /* 19 */ "ADC Capture Right",
160 /* 42 */ "FXBUS2_10",
161 /* 43 */ "FXBUS2_11",
162 /* 44 */ "FXBUS2_12",
163 /* 45 */ "FXBUS2_13",
164 /* 46 */ "FXBUS2_14",
165 /* 47 */ "FXBUS2_15",
166 /* 48 */ "FXBUS2_16",
167 /* 49 */ "FXBUS2_17",
168 /* 50 */ "FXBUS2_18",
169 /* 51 */ "FXBUS2_19",
170 /* 52 */ "FXBUS2_20",
171 /* 53 */ "FXBUS2_21",
172 /* 54 */ "FXBUS2_22",
173 /* 55 */ "FXBUS2_23",
174 /* 56 */ "FXBUS2_24",
175 /* 57 */ "FXBUS2_25",
176 /* 58 */ "FXBUS2_26",
177 /* 59 */ "FXBUS2_27",
178 /* 60 */ "FXBUS2_28",
179 /* 61 */ "FXBUS2_29",
180 /* 62 */ "FXBUS2_30",
184 emu10k1_t *emu = entry->private_data;
185 unsigned int val, val1;
186 int nefx = emu->audigy ? 64 : 32;
187 char **outputs = emu->audigy ? audigy_outs : creative_outs;
190 snd_iprintf(buffer, "EMU10K1\n\n");
191 snd_iprintf(buffer, "Card : %s\n",
192 emu->audigy ? "Audigy" : (emu->card_capabilities->ecard ? "EMU APS" : "Creative"));
193 snd_iprintf(buffer, "Internal TRAM (words) : 0x%x\n", emu->fx8010.itram_size);
194 snd_iprintf(buffer, "External TRAM (words) : 0x%x\n", (int)emu->fx8010.etram_pages.bytes / 2);
195 snd_iprintf(buffer, "\n");
196 snd_iprintf(buffer, "Effect Send Routing :\n");
197 for (idx = 0; idx < NUM_G; idx++) {
199 snd_emu10k1_ptr_read(emu, A_FXRT1, idx) :
200 snd_emu10k1_ptr_read(emu, FXRT, idx);
202 snd_emu10k1_ptr_read(emu, A_FXRT2, idx) :
205 snd_iprintf(buffer, "Ch%i: A=%i, B=%i, C=%i, D=%i, ",
211 snd_iprintf(buffer, "E=%i, F=%i, G=%i, H=%i\n",
215 (val1 >> 24) & 0x3f);
217 snd_iprintf(buffer, "Ch%i: A=%i, B=%i, C=%i, D=%i\n",
225 snd_iprintf(buffer, "\nCaptured FX Outputs :\n");
226 for (idx = 0; idx < nefx; idx++) {
227 if (emu->efx_voices_mask[idx/32] & (1 << (idx%32)))
228 snd_iprintf(buffer, " Output %02i [%s]\n", idx, outputs[idx]);
230 snd_iprintf(buffer, "\nAll FX Outputs :\n");
231 for (idx = 0; idx < (emu->audigy ? 64 : 32); idx++)
232 snd_iprintf(buffer, " Output %02i [%s]\n", idx, outputs[idx]);
235 static void snd_emu10k1_proc_spdif_read(snd_info_entry_t *entry,
236 snd_info_buffer_t * buffer)
238 emu10k1_t *emu = entry->private_data;
239 snd_emu10k1_proc_spdif_status(emu, buffer, "CD-ROM S/PDIF In", CDCS, CDSRCS);
240 snd_emu10k1_proc_spdif_status(emu, buffer, "Optical or Coax S/PDIF In", GPSCS, GPSRCS);
242 val = snd_emu10k1_ptr_read(emu, ZVSRCS, 0);
243 snd_iprintf(buffer, "\nZoomed Video\n");
244 snd_iprintf(buffer, "Rate Locked : %s\n", val & SRCS_RATELOCKED ? "on" : "off");
245 snd_iprintf(buffer, "Estimated Sample Rate : 0x%x\n", val & SRCS_ESTSAMPLERATE);
249 static void snd_emu10k1_proc_rates_read(snd_info_entry_t *entry,
250 snd_info_buffer_t * buffer)
252 static int samplerate[8] = { 44100, 48000, 96000, 192000, 4, 5, 6, 7 };
253 emu10k1_t *emu = entry->private_data;
254 unsigned int val, tmp, n;
255 val = snd_emu10k1_ptr20_read(emu, CAPTURE_RATE_STATUS, 0);
256 tmp = (val >> 16) & 0x8;
258 tmp = val >> (16 + (n*4));
259 if (tmp & 0x8) snd_iprintf(buffer, "Channel %d: Rate=%d\n", n, samplerate[tmp & 0x7]);
260 else snd_iprintf(buffer, "Channel %d: No input\n", n);
264 static void snd_emu10k1_proc_acode_read(snd_info_entry_t *entry,
265 snd_info_buffer_t * buffer)
268 emu10k1_t *emu = entry->private_data;
270 snd_iprintf(buffer, "FX8010 Instruction List '%s'\n", emu->fx8010.name);
271 snd_iprintf(buffer, " Code dump :\n");
272 for (pc = 0; pc < (emu->audigy ? 1024 : 512); pc++) {
275 low = snd_emu10k1_efx_read(emu, pc * 2);
276 high = snd_emu10k1_efx_read(emu, pc * 2 + 1);
278 snd_iprintf(buffer, " OP(0x%02x, 0x%03x, 0x%03x, 0x%03x, 0x%03x) /* 0x%04x: 0x%08x%08x */\n",
280 (high >> 12) & 0x7ff,
287 snd_iprintf(buffer, " OP(0x%02x, 0x%03x, 0x%03x, 0x%03x, 0x%03x) /* 0x%04x: 0x%08x%08x */\n",
289 (high >> 10) & 0x3ff,
298 #define TOTAL_SIZE_GPR (0x100*4)
299 #define A_TOTAL_SIZE_GPR (0x200*4)
300 #define TOTAL_SIZE_TANKMEM_DATA (0xa0*4)
301 #define TOTAL_SIZE_TANKMEM_ADDR (0xa0*4)
302 #define A_TOTAL_SIZE_TANKMEM_DATA (0x100*4)
303 #define A_TOTAL_SIZE_TANKMEM_ADDR (0x100*4)
304 #define TOTAL_SIZE_CODE (0x200*8)
305 #define A_TOTAL_SIZE_CODE (0x400*8)
307 static long snd_emu10k1_fx8010_read(snd_info_entry_t *entry, void *file_private_data,
308 struct file *file, char __user *buf,
309 unsigned long count, unsigned long pos)
312 emu10k1_t *emu = entry->private_data;
316 if (!strcmp(entry->name, "fx8010_tram_addr")) {
317 offset = TANKMEMADDRREGBASE;
319 } else if (!strcmp(entry->name, "fx8010_tram_data")) {
320 offset = TANKMEMDATAREGBASE;
321 } else if (!strcmp(entry->name, "fx8010_code")) {
322 offset = emu->audigy ? A_MICROCODEBASE : MICROCODEBASE;
324 offset = emu->audigy ? A_FXGPREGBASE : FXGPREGBASE;
327 if (pos + size > entry->size)
328 size = (long)entry->size - pos;
333 if ((tmp = kmalloc(size + 8, GFP_KERNEL)) == NULL)
335 for (idx = 0; idx < ((pos & 3) + size + 3) >> 2; idx++)
336 if (tram_addr && emu->audigy) {
337 tmp[idx] = snd_emu10k1_ptr_read(emu, offset + idx + (pos >> 2), 0) >> 11;
338 tmp[idx] |= snd_emu10k1_ptr_read(emu, 0x100 + idx + (pos >> 2), 0) << 20;
340 tmp[idx] = snd_emu10k1_ptr_read(emu, offset + idx + (pos >> 2), 0);
341 if (copy_to_user(buf, ((char *)tmp) + (pos & 3), size))
352 static void snd_emu10k1_proc_voices_read(snd_info_entry_t *entry,
353 snd_info_buffer_t * buffer)
355 emu10k1_t *emu = entry->private_data;
356 emu10k1_voice_t *voice;
359 snd_iprintf(buffer, "ch\tuse\tpcm\tefx\tsynth\tmidi\n");
360 for (idx = 0; idx < NUM_G; idx++) {
361 voice = &emu->voices[idx];
362 snd_iprintf(buffer, "%i\t%i\t%i\t%i\t%i\t%i\n",
372 #ifdef CONFIG_SND_DEBUG
373 static void snd_emu_proc_io_reg_read(snd_info_entry_t *entry,
374 snd_info_buffer_t * buffer)
376 emu10k1_t *emu = entry->private_data;
380 snd_iprintf(buffer, "IO Registers:\n\n");
381 for(i = 0; i < 0x40; i+=4) {
382 spin_lock_irqsave(&emu->emu_lock, flags);
383 value = inl(emu->port + i);
384 spin_unlock_irqrestore(&emu->emu_lock, flags);
385 snd_iprintf(buffer, "%02X: %08lX\n", i, value);
389 static void snd_emu_proc_io_reg_write(snd_info_entry_t *entry,
390 snd_info_buffer_t * buffer)
392 emu10k1_t *emu = entry->private_data;
396 while (!snd_info_get_line(buffer, line, sizeof(line))) {
397 if (sscanf(line, "%x %x", ®, &val) != 2)
399 if ((reg < 0x40) && (reg >=0) && (val <= 0xffffffff) ) {
400 spin_lock_irqsave(&emu->emu_lock, flags);
401 outl(val, emu->port + (reg & 0xfffffffc));
402 spin_unlock_irqrestore(&emu->emu_lock, flags);
407 static unsigned int snd_ptr_read(emu10k1_t * emu,
413 unsigned int regptr, val;
415 regptr = (reg << 16) | chn;
417 spin_lock_irqsave(&emu->emu_lock, flags);
418 outl(regptr, emu->port + iobase + PTR);
419 val = inl(emu->port + iobase + DATA);
420 spin_unlock_irqrestore(&emu->emu_lock, flags);
424 static void snd_ptr_write(emu10k1_t *emu,
433 regptr = (reg << 16) | chn;
435 spin_lock_irqsave(&emu->emu_lock, flags);
436 outl(regptr, emu->port + iobase + PTR);
437 outl(data, emu->port + iobase + DATA);
438 spin_unlock_irqrestore(&emu->emu_lock, flags);
442 static void snd_emu_proc_ptr_reg_read(snd_info_entry_t *entry,
443 snd_info_buffer_t * buffer, int iobase, int offset, int length, int voices)
445 emu10k1_t *emu = entry->private_data;
448 if (offset+length > 0x80) {
449 snd_iprintf(buffer, "Input values out of range\n");
452 snd_iprintf(buffer, "Registers 0x%x\n", iobase);
453 for(i = offset; i < offset+length; i++) {
454 snd_iprintf(buffer, "%02X: ",i);
455 for (j = 0; j < voices; j++) {
457 value = snd_ptr_read(emu, 0, i, j);
459 value = snd_ptr_read(emu, 0x20, i, j);
460 snd_iprintf(buffer, "%08lX ", value);
462 snd_iprintf(buffer, "\n");
466 static void snd_emu_proc_ptr_reg_write(snd_info_entry_t *entry,
467 snd_info_buffer_t * buffer, int iobase)
469 emu10k1_t *emu = entry->private_data;
471 unsigned int reg, channel_id , val;
472 while (!snd_info_get_line(buffer, line, sizeof(line))) {
473 if (sscanf(line, "%x %x %x", ®, &channel_id, &val) != 3)
475 if ((reg < 0x80) && (reg >=0) && (val <= 0xffffffff) && (channel_id >=0) && (channel_id <= 3) )
476 snd_ptr_write(emu, iobase, reg, channel_id, val);
480 static void snd_emu_proc_ptr_reg_write00(snd_info_entry_t *entry,
481 snd_info_buffer_t * buffer)
483 snd_emu_proc_ptr_reg_write(entry, buffer, 0);
486 static void snd_emu_proc_ptr_reg_write20(snd_info_entry_t *entry,
487 snd_info_buffer_t * buffer)
489 snd_emu_proc_ptr_reg_write(entry, buffer, 0x20);
493 static void snd_emu_proc_ptr_reg_read00a(snd_info_entry_t *entry,
494 snd_info_buffer_t * buffer)
496 snd_emu_proc_ptr_reg_read(entry, buffer, 0, 0, 0x40, 64);
499 static void snd_emu_proc_ptr_reg_read00b(snd_info_entry_t *entry,
500 snd_info_buffer_t * buffer)
502 snd_emu_proc_ptr_reg_read(entry, buffer, 0, 0x40, 0x40, 64);
505 static void snd_emu_proc_ptr_reg_read20a(snd_info_entry_t *entry,
506 snd_info_buffer_t * buffer)
508 snd_emu_proc_ptr_reg_read(entry, buffer, 0x20, 0, 0x40, 4);
511 static void snd_emu_proc_ptr_reg_read20b(snd_info_entry_t *entry,
512 snd_info_buffer_t * buffer)
514 snd_emu_proc_ptr_reg_read(entry, buffer, 0x20, 0x40, 0x40, 4);
518 static struct snd_info_entry_ops snd_emu10k1_proc_ops_fx8010 = {
519 .read = snd_emu10k1_fx8010_read,
522 int __devinit snd_emu10k1_proc_init(emu10k1_t * emu)
524 snd_info_entry_t *entry;
525 #ifdef CONFIG_SND_DEBUG
526 if (! snd_card_proc_new(emu->card, "io_regs", &entry)) {
527 snd_info_set_text_ops(entry, emu, 1024, snd_emu_proc_io_reg_read);
528 entry->c.text.write_size = 64;
529 entry->c.text.write = snd_emu_proc_io_reg_write;
530 entry->mode |= S_IWUSR;
532 if (! snd_card_proc_new(emu->card, "ptr_regs00a", &entry)) {
533 snd_info_set_text_ops(entry, emu, 65536, snd_emu_proc_ptr_reg_read00a);
534 entry->c.text.write_size = 64;
535 entry->c.text.write = snd_emu_proc_ptr_reg_write00;
536 entry->mode |= S_IWUSR;
538 if (! snd_card_proc_new(emu->card, "ptr_regs00b", &entry)) {
539 snd_info_set_text_ops(entry, emu, 65536, snd_emu_proc_ptr_reg_read00b);
540 entry->c.text.write_size = 64;
541 entry->c.text.write = snd_emu_proc_ptr_reg_write00;
542 entry->mode |= S_IWUSR;
544 if (! snd_card_proc_new(emu->card, "ptr_regs20a", &entry)) {
545 snd_info_set_text_ops(entry, emu, 65536, snd_emu_proc_ptr_reg_read20a);
546 entry->c.text.write_size = 64;
547 entry->c.text.write = snd_emu_proc_ptr_reg_write20;
548 entry->mode |= S_IWUSR;
550 if (! snd_card_proc_new(emu->card, "ptr_regs20b", &entry)) {
551 snd_info_set_text_ops(entry, emu, 65536, snd_emu_proc_ptr_reg_read20b);
552 entry->c.text.write_size = 64;
553 entry->c.text.write = snd_emu_proc_ptr_reg_write20;
554 entry->mode |= S_IWUSR;
558 if (! snd_card_proc_new(emu->card, "emu10k1", &entry))
559 snd_info_set_text_ops(entry, emu, 2048, snd_emu10k1_proc_read);
561 if (emu->card_capabilities->emu10k2_chip) {
562 if (! snd_card_proc_new(emu->card, "spdif-in", &entry))
563 snd_info_set_text_ops(entry, emu, 2048, snd_emu10k1_proc_spdif_read);
565 if (emu->card_capabilities->ca0151_chip) {
566 if (! snd_card_proc_new(emu->card, "capture-rates", &entry))
567 snd_info_set_text_ops(entry, emu, 2048, snd_emu10k1_proc_rates_read);
570 if (! snd_card_proc_new(emu->card, "voices", &entry))
571 snd_info_set_text_ops(entry, emu, 2048, snd_emu10k1_proc_voices_read);
573 if (! snd_card_proc_new(emu->card, "fx8010_gpr", &entry)) {
574 entry->content = SNDRV_INFO_CONTENT_DATA;
575 entry->private_data = emu;
576 entry->mode = S_IFREG | S_IRUGO /*| S_IWUSR*/;
577 entry->size = emu->audigy ? A_TOTAL_SIZE_GPR : TOTAL_SIZE_GPR;
578 entry->c.ops = &snd_emu10k1_proc_ops_fx8010;
580 if (! snd_card_proc_new(emu->card, "fx8010_tram_data", &entry)) {
581 entry->content = SNDRV_INFO_CONTENT_DATA;
582 entry->private_data = emu;
583 entry->mode = S_IFREG | S_IRUGO /*| S_IWUSR*/;
584 entry->size = emu->audigy ? A_TOTAL_SIZE_TANKMEM_DATA : TOTAL_SIZE_TANKMEM_DATA ;
585 entry->c.ops = &snd_emu10k1_proc_ops_fx8010;
587 if (! snd_card_proc_new(emu->card, "fx8010_tram_addr", &entry)) {
588 entry->content = SNDRV_INFO_CONTENT_DATA;
589 entry->private_data = emu;
590 entry->mode = S_IFREG | S_IRUGO /*| S_IWUSR*/;
591 entry->size = emu->audigy ? A_TOTAL_SIZE_TANKMEM_ADDR : TOTAL_SIZE_TANKMEM_ADDR ;
592 entry->c.ops = &snd_emu10k1_proc_ops_fx8010;
594 if (! snd_card_proc_new(emu->card, "fx8010_code", &entry)) {
595 entry->content = SNDRV_INFO_CONTENT_DATA;
596 entry->private_data = emu;
597 entry->mode = S_IFREG | S_IRUGO /*| S_IWUSR*/;
598 entry->size = emu->audigy ? A_TOTAL_SIZE_CODE : TOTAL_SIZE_CODE;
599 entry->c.ops = &snd_emu10k1_proc_ops_fx8010;
601 if (! snd_card_proc_new(emu->card, "fx8010_acode", &entry)) {
602 entry->content = SNDRV_INFO_CONTENT_TEXT;
603 entry->private_data = emu;
604 entry->mode = S_IFREG | S_IRUGO /*| S_IWUSR*/;
605 entry->c.text.read_size = 128*1024;
606 entry->c.text.read = snd_emu10k1_proc_acode_read;