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(struct snd_emu10k1 * emu,
36 struct snd_info_buffer *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(struct snd_info_entry *entry,
79 struct snd_info_buffer *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 struct snd_emu10k1 *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(struct snd_info_entry *entry,
236 struct snd_info_buffer *buffer)
238 struct snd_emu10k1 *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(struct snd_info_entry *entry,
250 struct snd_info_buffer *buffer)
252 static int samplerate[8] = { 44100, 48000, 96000, 192000, 4, 5, 6, 7 };
253 struct snd_emu10k1 *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(struct snd_info_entry *entry,
265 struct snd_info_buffer *buffer)
268 struct snd_emu10k1 *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(struct snd_info_entry *entry,
308 void *file_private_data,
309 struct file *file, char __user *buf,
310 unsigned long count, unsigned long pos)
313 struct snd_emu10k1 *emu = entry->private_data;
317 if (!strcmp(entry->name, "fx8010_tram_addr")) {
318 offset = TANKMEMADDRREGBASE;
320 } else if (!strcmp(entry->name, "fx8010_tram_data")) {
321 offset = TANKMEMDATAREGBASE;
322 } else if (!strcmp(entry->name, "fx8010_code")) {
323 offset = emu->audigy ? A_MICROCODEBASE : MICROCODEBASE;
325 offset = emu->audigy ? A_FXGPREGBASE : FXGPREGBASE;
328 if (pos + size > entry->size)
329 size = (long)entry->size - pos;
334 if ((tmp = kmalloc(size + 8, GFP_KERNEL)) == NULL)
336 for (idx = 0; idx < ((pos & 3) + size + 3) >> 2; idx++)
337 if (tram_addr && emu->audigy) {
338 tmp[idx] = snd_emu10k1_ptr_read(emu, offset + idx + (pos >> 2), 0) >> 11;
339 tmp[idx] |= snd_emu10k1_ptr_read(emu, 0x100 + idx + (pos >> 2), 0) << 20;
341 tmp[idx] = snd_emu10k1_ptr_read(emu, offset + idx + (pos >> 2), 0);
342 if (copy_to_user(buf, ((char *)tmp) + (pos & 3), size))
353 static void snd_emu10k1_proc_voices_read(struct snd_info_entry *entry,
354 struct snd_info_buffer *buffer)
356 struct snd_emu10k1 *emu = entry->private_data;
357 struct snd_emu10k1_voice *voice;
360 snd_iprintf(buffer, "ch\tuse\tpcm\tefx\tsynth\tmidi\n");
361 for (idx = 0; idx < NUM_G; idx++) {
362 voice = &emu->voices[idx];
363 snd_iprintf(buffer, "%i\t%i\t%i\t%i\t%i\t%i\n",
373 #ifdef CONFIG_SND_DEBUG
374 static void snd_emu_proc_io_reg_read(struct snd_info_entry *entry,
375 struct snd_info_buffer *buffer)
377 struct snd_emu10k1 *emu = entry->private_data;
381 snd_iprintf(buffer, "IO Registers:\n\n");
382 for(i = 0; i < 0x40; i+=4) {
383 spin_lock_irqsave(&emu->emu_lock, flags);
384 value = inl(emu->port + i);
385 spin_unlock_irqrestore(&emu->emu_lock, flags);
386 snd_iprintf(buffer, "%02X: %08lX\n", i, value);
390 static void snd_emu_proc_io_reg_write(struct snd_info_entry *entry,
391 struct snd_info_buffer *buffer)
393 struct snd_emu10k1 *emu = entry->private_data;
397 while (!snd_info_get_line(buffer, line, sizeof(line))) {
398 if (sscanf(line, "%x %x", ®, &val) != 2)
400 if ((reg < 0x40) && (reg >=0) && (val <= 0xffffffff) ) {
401 spin_lock_irqsave(&emu->emu_lock, flags);
402 outl(val, emu->port + (reg & 0xfffffffc));
403 spin_unlock_irqrestore(&emu->emu_lock, flags);
408 static unsigned int snd_ptr_read(struct snd_emu10k1 * emu,
414 unsigned int regptr, val;
416 regptr = (reg << 16) | chn;
418 spin_lock_irqsave(&emu->emu_lock, flags);
419 outl(regptr, emu->port + iobase + PTR);
420 val = inl(emu->port + iobase + DATA);
421 spin_unlock_irqrestore(&emu->emu_lock, flags);
425 static void snd_ptr_write(struct snd_emu10k1 *emu,
434 regptr = (reg << 16) | chn;
436 spin_lock_irqsave(&emu->emu_lock, flags);
437 outl(regptr, emu->port + iobase + PTR);
438 outl(data, emu->port + iobase + DATA);
439 spin_unlock_irqrestore(&emu->emu_lock, flags);
443 static void snd_emu_proc_ptr_reg_read(struct snd_info_entry *entry,
444 struct snd_info_buffer *buffer, int iobase, int offset, int length, int voices)
446 struct snd_emu10k1 *emu = entry->private_data;
449 if (offset+length > 0xa0) {
450 snd_iprintf(buffer, "Input values out of range\n");
453 snd_iprintf(buffer, "Registers 0x%x\n", iobase);
454 for(i = offset; i < offset+length; i++) {
455 snd_iprintf(buffer, "%02X: ",i);
456 for (j = 0; j < voices; j++) {
458 value = snd_ptr_read(emu, 0, i, j);
460 value = snd_ptr_read(emu, 0x20, i, j);
461 snd_iprintf(buffer, "%08lX ", value);
463 snd_iprintf(buffer, "\n");
467 static void snd_emu_proc_ptr_reg_write(struct snd_info_entry *entry,
468 struct snd_info_buffer *buffer, int iobase)
470 struct snd_emu10k1 *emu = entry->private_data;
472 unsigned int reg, channel_id , val;
473 while (!snd_info_get_line(buffer, line, sizeof(line))) {
474 if (sscanf(line, "%x %x %x", ®, &channel_id, &val) != 3)
476 if ((reg < 0xa0) && (reg >=0) && (val <= 0xffffffff) && (channel_id >=0) && (channel_id <= 3) )
477 snd_ptr_write(emu, iobase, reg, channel_id, val);
481 static void snd_emu_proc_ptr_reg_write00(struct snd_info_entry *entry,
482 struct snd_info_buffer *buffer)
484 snd_emu_proc_ptr_reg_write(entry, buffer, 0);
487 static void snd_emu_proc_ptr_reg_write20(struct snd_info_entry *entry,
488 struct snd_info_buffer *buffer)
490 snd_emu_proc_ptr_reg_write(entry, buffer, 0x20);
494 static void snd_emu_proc_ptr_reg_read00a(struct snd_info_entry *entry,
495 struct snd_info_buffer *buffer)
497 snd_emu_proc_ptr_reg_read(entry, buffer, 0, 0, 0x40, 64);
500 static void snd_emu_proc_ptr_reg_read00b(struct snd_info_entry *entry,
501 struct snd_info_buffer *buffer)
503 snd_emu_proc_ptr_reg_read(entry, buffer, 0, 0x40, 0x40, 64);
506 static void snd_emu_proc_ptr_reg_read20a(struct snd_info_entry *entry,
507 struct snd_info_buffer *buffer)
509 snd_emu_proc_ptr_reg_read(entry, buffer, 0x20, 0, 0x40, 4);
512 static void snd_emu_proc_ptr_reg_read20b(struct snd_info_entry *entry,
513 struct snd_info_buffer *buffer)
515 snd_emu_proc_ptr_reg_read(entry, buffer, 0x20, 0x40, 0x40, 4);
518 static void snd_emu_proc_ptr_reg_read20c(struct snd_info_entry *entry,
519 struct snd_info_buffer * buffer)
521 snd_emu_proc_ptr_reg_read(entry, buffer, 0x20, 0x80, 0x20, 4);
525 static struct snd_info_entry_ops snd_emu10k1_proc_ops_fx8010 = {
526 .read = snd_emu10k1_fx8010_read,
529 int __devinit snd_emu10k1_proc_init(struct snd_emu10k1 * emu)
531 struct snd_info_entry *entry;
532 #ifdef CONFIG_SND_DEBUG
533 if (! snd_card_proc_new(emu->card, "io_regs", &entry)) {
534 snd_info_set_text_ops(entry, emu, 1024, snd_emu_proc_io_reg_read);
535 entry->c.text.write_size = 64;
536 entry->c.text.write = snd_emu_proc_io_reg_write;
537 entry->mode |= S_IWUSR;
539 if (! snd_card_proc_new(emu->card, "ptr_regs00a", &entry)) {
540 snd_info_set_text_ops(entry, emu, 65536, snd_emu_proc_ptr_reg_read00a);
541 entry->c.text.write_size = 64;
542 entry->c.text.write = snd_emu_proc_ptr_reg_write00;
543 entry->mode |= S_IWUSR;
545 if (! snd_card_proc_new(emu->card, "ptr_regs00b", &entry)) {
546 snd_info_set_text_ops(entry, emu, 65536, snd_emu_proc_ptr_reg_read00b);
547 entry->c.text.write_size = 64;
548 entry->c.text.write = snd_emu_proc_ptr_reg_write00;
549 entry->mode |= S_IWUSR;
551 if (! snd_card_proc_new(emu->card, "ptr_regs20a", &entry)) {
552 snd_info_set_text_ops(entry, emu, 65536, snd_emu_proc_ptr_reg_read20a);
553 entry->c.text.write_size = 64;
554 entry->c.text.write = snd_emu_proc_ptr_reg_write20;
555 entry->mode |= S_IWUSR;
557 if (! snd_card_proc_new(emu->card, "ptr_regs20b", &entry)) {
558 snd_info_set_text_ops(entry, emu, 65536, snd_emu_proc_ptr_reg_read20b);
559 entry->c.text.write_size = 64;
560 entry->c.text.write = snd_emu_proc_ptr_reg_write20;
561 entry->mode |= S_IWUSR;
563 if (! snd_card_proc_new(emu->card, "ptr_regs20c", &entry)) {
564 snd_info_set_text_ops(entry, emu, 65536, snd_emu_proc_ptr_reg_read20c);
565 entry->c.text.write_size = 64;
566 entry->c.text.write = snd_emu_proc_ptr_reg_write20;
567 entry->mode |= S_IWUSR;
571 if (! snd_card_proc_new(emu->card, "emu10k1", &entry))
572 snd_info_set_text_ops(entry, emu, 2048, snd_emu10k1_proc_read);
574 if (emu->card_capabilities->emu10k2_chip) {
575 if (! snd_card_proc_new(emu->card, "spdif-in", &entry))
576 snd_info_set_text_ops(entry, emu, 2048, snd_emu10k1_proc_spdif_read);
578 if (emu->card_capabilities->ca0151_chip) {
579 if (! snd_card_proc_new(emu->card, "capture-rates", &entry))
580 snd_info_set_text_ops(entry, emu, 2048, snd_emu10k1_proc_rates_read);
583 if (! snd_card_proc_new(emu->card, "voices", &entry))
584 snd_info_set_text_ops(entry, emu, 2048, snd_emu10k1_proc_voices_read);
586 if (! snd_card_proc_new(emu->card, "fx8010_gpr", &entry)) {
587 entry->content = SNDRV_INFO_CONTENT_DATA;
588 entry->private_data = emu;
589 entry->mode = S_IFREG | S_IRUGO /*| S_IWUSR*/;
590 entry->size = emu->audigy ? A_TOTAL_SIZE_GPR : TOTAL_SIZE_GPR;
591 entry->c.ops = &snd_emu10k1_proc_ops_fx8010;
593 if (! snd_card_proc_new(emu->card, "fx8010_tram_data", &entry)) {
594 entry->content = SNDRV_INFO_CONTENT_DATA;
595 entry->private_data = emu;
596 entry->mode = S_IFREG | S_IRUGO /*| S_IWUSR*/;
597 entry->size = emu->audigy ? A_TOTAL_SIZE_TANKMEM_DATA : TOTAL_SIZE_TANKMEM_DATA ;
598 entry->c.ops = &snd_emu10k1_proc_ops_fx8010;
600 if (! snd_card_proc_new(emu->card, "fx8010_tram_addr", &entry)) {
601 entry->content = SNDRV_INFO_CONTENT_DATA;
602 entry->private_data = emu;
603 entry->mode = S_IFREG | S_IRUGO /*| S_IWUSR*/;
604 entry->size = emu->audigy ? A_TOTAL_SIZE_TANKMEM_ADDR : TOTAL_SIZE_TANKMEM_ADDR ;
605 entry->c.ops = &snd_emu10k1_proc_ops_fx8010;
607 if (! snd_card_proc_new(emu->card, "fx8010_code", &entry)) {
608 entry->content = SNDRV_INFO_CONTENT_DATA;
609 entry->private_data = emu;
610 entry->mode = S_IFREG | S_IRUGO /*| S_IWUSR*/;
611 entry->size = emu->audigy ? A_TOTAL_SIZE_CODE : TOTAL_SIZE_CODE;
612 entry->c.ops = &snd_emu10k1_proc_ops_fx8010;
614 if (! snd_card_proc_new(emu->card, "fx8010_acode", &entry)) {
615 entry->content = SNDRV_INFO_CONTENT_TEXT;
616 entry->private_data = emu;
617 entry->mode = S_IFREG | S_IRUGO /*| S_IWUSR*/;
618 entry->c.text.read_size = 128*1024;
619 entry->c.text.read = snd_emu10k1_proc_acode_read;