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>
34 static void snd_emu10k1_proc_spdif_status(emu10k1_t * emu,
35 snd_info_buffer_t * buffer,
40 static char *clkaccy[4] = { "1000ppm", "50ppm", "variable", "unknown" };
41 static int samplerate[16] = { 44100, 1, 48000, 32000, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
42 static char *channel[16] = { "unspec", "left", "right", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15" };
43 static char *emphasis[8] = { "none", "50/15 usec 2 channel", "2", "3", "4", "5", "6", "7" };
44 unsigned int status, rate = 0;
46 status = snd_emu10k1_ptr_read(emu, status_reg, 0);
48 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]);
64 rate = snd_emu10k1_ptr_read(emu, rate_reg, 0);
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);
71 snd_iprintf(buffer, "No signal detected.\n");
76 static void snd_emu10k1_proc_read(snd_info_entry_t *entry,
77 snd_info_buffer_t * buffer)
79 /* FIXME - output names are in emufx.c too */
80 static char *creative_outs[32] = {
82 /* 01 */ "AC97 Right",
83 /* 02 */ "Optical IEC958 Left",
84 /* 03 */ "Optical IEC958 Right",
87 /* 06 */ "Headphone Left",
88 /* 07 */ "Headphone Right",
89 /* 08 */ "Surround Left",
90 /* 09 */ "Surround Right",
91 /* 10 */ "PCM Capture Left",
92 /* 11 */ "PCM Capture Right",
93 /* 12 */ "MIC Capture",
94 /* 13 */ "AC97 Surround Left",
95 /* 14 */ "AC97 Surround Right",
98 /* 17 */ "Analog Center",
99 /* 18 */ "Analog LFE",
115 static char *audigy_outs[64] = {
116 /* 00 */ "Digital Front Left",
117 /* 01 */ "Digital Front Right",
118 /* 02 */ "Digital Center",
119 /* 03 */ "Digital LEF",
120 /* 04 */ "Headphone Left",
121 /* 05 */ "Headphone Right",
122 /* 06 */ "Digital Rear Left",
123 /* 07 */ "Digital Rear Right",
124 /* 08 */ "Front Left",
125 /* 09 */ "Front Right",
130 /* 14 */ "Rear Left",
131 /* 15 */ "Rear Right",
132 /* 16 */ "AC97 Front Left",
133 /* 17 */ "AC97 Front Right",
134 /* 18 */ "ADC Caputre Left",
135 /* 19 */ "ADC Capture Right",
158 /* 42 */ "FXBUS2_10",
159 /* 43 */ "FXBUS2_11",
160 /* 44 */ "FXBUS2_12",
161 /* 45 */ "FXBUS2_13",
162 /* 46 */ "FXBUS2_14",
163 /* 47 */ "FXBUS2_15",
164 /* 48 */ "FXBUS2_16",
165 /* 49 */ "FXBUS2_17",
166 /* 50 */ "FXBUS2_18",
167 /* 51 */ "FXBUS2_19",
168 /* 52 */ "FXBUS2_20",
169 /* 53 */ "FXBUS2_21",
170 /* 54 */ "FXBUS2_22",
171 /* 55 */ "FXBUS2_23",
172 /* 56 */ "FXBUS2_24",
173 /* 57 */ "FXBUS2_25",
174 /* 58 */ "FXBUS2_26",
175 /* 59 */ "FXBUS2_27",
176 /* 60 */ "FXBUS2_28",
177 /* 61 */ "FXBUS2_29",
178 /* 62 */ "FXBUS2_30",
182 emu10k1_t *emu = entry->private_data;
183 unsigned int val, val1;
184 int nefx = emu->audigy ? 64 : 32;
185 char **outputs = emu->audigy ? audigy_outs : creative_outs;
188 snd_iprintf(buffer, "EMU10K1\n\n");
189 snd_iprintf(buffer, "Card : %s\n",
190 emu->audigy ? "Audigy" : (emu->card_capabilities->ecard ? "EMU APS" : "Creative"));
191 snd_iprintf(buffer, "Internal TRAM (words) : 0x%x\n", emu->fx8010.itram_size);
192 snd_iprintf(buffer, "External TRAM (words) : 0x%x\n", (int)emu->fx8010.etram_pages.bytes / 2);
193 snd_iprintf(buffer, "\n");
194 snd_iprintf(buffer, "Effect Send Routing :\n");
195 for (idx = 0; idx < NUM_G; idx++) {
197 snd_emu10k1_ptr_read(emu, A_FXRT1, idx) :
198 snd_emu10k1_ptr_read(emu, FXRT, idx);
200 snd_emu10k1_ptr_read(emu, A_FXRT2, idx) :
203 snd_iprintf(buffer, "Ch%i: A=%i, B=%i, C=%i, D=%i, ",
209 snd_iprintf(buffer, "E=%i, F=%i, G=%i, H=%i\n",
213 (val1 >> 24) & 0x3f);
215 snd_iprintf(buffer, "Ch%i: A=%i, B=%i, C=%i, D=%i\n",
223 snd_iprintf(buffer, "\nCaptured FX Outputs :\n");
224 for (idx = 0; idx < nefx; idx++) {
225 if (emu->efx_voices_mask[idx/32] & (1 << (idx%32)))
226 snd_iprintf(buffer, " Output %02i [%s]\n", idx, outputs[idx]);
228 snd_iprintf(buffer, "\nAll FX Outputs :\n");
229 for (idx = 0; idx < (emu->audigy ? 64 : 32); idx++)
230 snd_iprintf(buffer, " Output %02i [%s]\n", idx, outputs[idx]);
233 static void snd_emu10k1_proc_spdif_read(snd_info_entry_t *entry,
234 snd_info_buffer_t * buffer)
236 emu10k1_t *emu = entry->private_data;
237 snd_emu10k1_proc_spdif_status(emu, buffer, "CD-ROM S/PDIF In", CDCS, CDSRCS);
238 snd_emu10k1_proc_spdif_status(emu, buffer, "Optical or Coax S/PDIF In", GPSCS, GPSRCS);
240 val = snd_emu10k1_ptr_read(emu, ZVSRCS, 0);
241 snd_iprintf(buffer, "\nZoomed Video\n");
242 snd_iprintf(buffer, "Rate Locked : %s\n", val & SRCS_RATELOCKED ? "on" : "off");
243 snd_iprintf(buffer, "Estimated Sample Rate : 0x%x\n", val & SRCS_ESTSAMPLERATE);
247 static void snd_emu10k1_proc_acode_read(snd_info_entry_t *entry,
248 snd_info_buffer_t * buffer)
251 emu10k1_t *emu = entry->private_data;
253 snd_iprintf(buffer, "FX8010 Instruction List '%s'\n", emu->fx8010.name);
254 snd_iprintf(buffer, " Code dump :\n");
255 for (pc = 0; pc < (emu->audigy ? 1024 : 512); pc++) {
258 low = snd_emu10k1_efx_read(emu, pc * 2);
259 high = snd_emu10k1_efx_read(emu, pc * 2 + 1);
261 snd_iprintf(buffer, " OP(0x%02x, 0x%03x, 0x%03x, 0x%03x, 0x%03x) /* 0x%04x: 0x%08x%08x */\n",
263 (high >> 12) & 0x7ff,
270 snd_iprintf(buffer, " OP(0x%02x, 0x%03x, 0x%03x, 0x%03x, 0x%03x) /* 0x%04x: 0x%08x%08x */\n",
272 (high >> 10) & 0x3ff,
281 #define TOTAL_SIZE_GPR (0x100*4)
282 #define A_TOTAL_SIZE_GPR (0x200*4)
283 #define TOTAL_SIZE_TANKMEM_DATA (0xa0*4)
284 #define TOTAL_SIZE_TANKMEM_ADDR (0xa0*4)
285 #define A_TOTAL_SIZE_TANKMEM_DATA (0x100*4)
286 #define A_TOTAL_SIZE_TANKMEM_ADDR (0x100*4)
287 #define TOTAL_SIZE_CODE (0x200*8)
288 #define A_TOTAL_SIZE_CODE (0x400*8)
290 static long snd_emu10k1_fx8010_read(snd_info_entry_t *entry, void *file_private_data,
291 struct file *file, char __user *buf,
292 unsigned long count, unsigned long pos)
295 emu10k1_t *emu = entry->private_data;
299 if (!strcmp(entry->name, "fx8010_tram_addr")) {
300 offset = TANKMEMADDRREGBASE;
302 } else if (!strcmp(entry->name, "fx8010_tram_data")) {
303 offset = TANKMEMDATAREGBASE;
304 } else if (!strcmp(entry->name, "fx8010_code")) {
305 offset = emu->audigy ? A_MICROCODEBASE : MICROCODEBASE;
307 offset = emu->audigy ? A_FXGPREGBASE : FXGPREGBASE;
310 if (pos + size > entry->size)
311 size = (long)entry->size - pos;
316 if ((tmp = kmalloc(size + 8, GFP_KERNEL)) == NULL)
318 for (idx = 0; idx < ((pos & 3) + size + 3) >> 2; idx++)
319 if (tram_addr && emu->audigy) {
320 tmp[idx] = snd_emu10k1_ptr_read(emu, offset + idx + (pos >> 2), 0) >> 11;
321 tmp[idx] |= snd_emu10k1_ptr_read(emu, 0x100 + idx + (pos >> 2), 0) << 20;
323 tmp[idx] = snd_emu10k1_ptr_read(emu, offset + idx + (pos >> 2), 0);
324 if (copy_to_user(buf, ((char *)tmp) + (pos & 3), size))
335 static void snd_emu10k1_proc_voices_read(snd_info_entry_t *entry,
336 snd_info_buffer_t * buffer)
338 emu10k1_t *emu = entry->private_data;
339 emu10k1_voice_t *voice;
342 snd_iprintf(buffer, "ch\tuse\tpcm\tefx\tsynth\tmidi\n");
343 for (idx = 0; idx < NUM_G; idx++) {
344 voice = &emu->voices[idx];
345 snd_iprintf(buffer, "%i\t%i\t%i\t%i\t%i\t%i\n",
355 #ifdef CONFIG_SND_DEBUG
356 static void snd_emu_proc_io_reg_read(snd_info_entry_t *entry,
357 snd_info_buffer_t * buffer)
359 emu10k1_t *emu = entry->private_data;
363 snd_iprintf(buffer, "IO Registers:\n\n");
364 for(i = 0; i < 0x40; i+=4) {
365 spin_lock_irqsave(&emu->emu_lock, flags);
366 value = inl(emu->port + i);
367 spin_unlock_irqrestore(&emu->emu_lock, flags);
368 snd_iprintf(buffer, "%02X: %08lX\n", i, value);
372 static void snd_emu_proc_io_reg_write(snd_info_entry_t *entry,
373 snd_info_buffer_t * buffer)
375 emu10k1_t *emu = entry->private_data;
379 while (!snd_info_get_line(buffer, line, sizeof(line))) {
380 if (sscanf(line, "%x %x", ®, &val) != 2)
382 if ((reg < 0x40) && (reg >=0) && (val <= 0xffffffff) ) {
383 spin_lock_irqsave(&emu->emu_lock, flags);
384 outl(val, emu->port + (reg & 0xfffffffc));
385 spin_unlock_irqrestore(&emu->emu_lock, flags);
390 static unsigned int snd_ptr_read(emu10k1_t * emu,
396 unsigned int regptr, val;
398 regptr = (reg << 16) | chn;
400 spin_lock_irqsave(&emu->emu_lock, flags);
401 outl(regptr, emu->port + iobase + PTR);
402 val = inl(emu->port + iobase + DATA);
403 spin_unlock_irqrestore(&emu->emu_lock, flags);
407 static void snd_ptr_write(emu10k1_t *emu,
416 regptr = (reg << 16) | chn;
418 spin_lock_irqsave(&emu->emu_lock, flags);
419 outl(regptr, emu->port + iobase + PTR);
420 outl(data, emu->port + iobase + DATA);
421 spin_unlock_irqrestore(&emu->emu_lock, flags);
425 static void snd_emu_proc_ptr_reg_read(snd_info_entry_t *entry,
426 snd_info_buffer_t * buffer, int iobase, int offset, int length, int voices)
428 emu10k1_t *emu = entry->private_data;
431 if (offset+length > 0x80) {
432 snd_iprintf(buffer, "Input values out of range\n");
435 snd_iprintf(buffer, "Registers 0x%x\n", iobase);
436 for(i = offset; i < offset+length; i++) {
437 snd_iprintf(buffer, "%02X: ",i);
438 for (j = 0; j < voices; j++) {
440 value = snd_ptr_read(emu, 0, i, j);
442 value = snd_ptr_read(emu, 0x20, i, j);
443 snd_iprintf(buffer, "%08lX ", value);
445 snd_iprintf(buffer, "\n");
449 static void snd_emu_proc_ptr_reg_write(snd_info_entry_t *entry,
450 snd_info_buffer_t * buffer, int iobase)
452 emu10k1_t *emu = entry->private_data;
454 unsigned int reg, channel_id , val;
455 while (!snd_info_get_line(buffer, line, sizeof(line))) {
456 if (sscanf(line, "%x %x %x", ®, &channel_id, &val) != 3)
458 if ((reg < 0x80) && (reg >=0) && (val <= 0xffffffff) && (channel_id >=0) && (channel_id <= 3) )
459 snd_ptr_write(emu, iobase, reg, channel_id, val);
463 static void snd_emu_proc_ptr_reg_write00(snd_info_entry_t *entry,
464 snd_info_buffer_t * buffer)
466 snd_emu_proc_ptr_reg_write(entry, buffer, 0);
469 static void snd_emu_proc_ptr_reg_write20(snd_info_entry_t *entry,
470 snd_info_buffer_t * buffer)
472 snd_emu_proc_ptr_reg_write(entry, buffer, 0x20);
476 static void snd_emu_proc_ptr_reg_read00a(snd_info_entry_t *entry,
477 snd_info_buffer_t * buffer)
479 snd_emu_proc_ptr_reg_read(entry, buffer, 0, 0, 0x40, 64);
482 static void snd_emu_proc_ptr_reg_read00b(snd_info_entry_t *entry,
483 snd_info_buffer_t * buffer)
485 snd_emu_proc_ptr_reg_read(entry, buffer, 0, 0x40, 0x40, 64);
488 static void snd_emu_proc_ptr_reg_read20a(snd_info_entry_t *entry,
489 snd_info_buffer_t * buffer)
491 snd_emu_proc_ptr_reg_read(entry, buffer, 0x20, 0, 0x40, 4);
494 static void snd_emu_proc_ptr_reg_read20b(snd_info_entry_t *entry,
495 snd_info_buffer_t * buffer)
497 snd_emu_proc_ptr_reg_read(entry, buffer, 0x20, 0x40, 0x40, 4);
501 static struct snd_info_entry_ops snd_emu10k1_proc_ops_fx8010 = {
502 .read = snd_emu10k1_fx8010_read,
505 int __devinit snd_emu10k1_proc_init(emu10k1_t * emu)
507 snd_info_entry_t *entry;
508 #ifdef CONFIG_SND_DEBUG
509 if (! snd_card_proc_new(emu->card, "io_regs", &entry)) {
510 snd_info_set_text_ops(entry, emu, 1024, snd_emu_proc_io_reg_read);
511 entry->c.text.write_size = 64;
512 entry->c.text.write = snd_emu_proc_io_reg_write;
514 if (! snd_card_proc_new(emu->card, "ptr_regs00a", &entry)) {
515 snd_info_set_text_ops(entry, emu, 65536, snd_emu_proc_ptr_reg_read00a);
516 entry->c.text.write_size = 64;
517 entry->c.text.write = snd_emu_proc_ptr_reg_write00;
519 if (! snd_card_proc_new(emu->card, "ptr_regs00b", &entry)) {
520 snd_info_set_text_ops(entry, emu, 65536, snd_emu_proc_ptr_reg_read00b);
521 entry->c.text.write_size = 64;
522 entry->c.text.write = snd_emu_proc_ptr_reg_write00;
524 if (! snd_card_proc_new(emu->card, "ptr_regs20a", &entry)) {
525 snd_info_set_text_ops(entry, emu, 65536, snd_emu_proc_ptr_reg_read20a);
526 entry->c.text.write_size = 64;
527 entry->c.text.write = snd_emu_proc_ptr_reg_write20;
529 if (! snd_card_proc_new(emu->card, "ptr_regs20b", &entry)) {
530 snd_info_set_text_ops(entry, emu, 65536, snd_emu_proc_ptr_reg_read20b);
531 entry->c.text.write_size = 64;
532 entry->c.text.write = snd_emu_proc_ptr_reg_write20;
536 if (! snd_card_proc_new(emu->card, "emu10k1", &entry))
537 snd_info_set_text_ops(entry, emu, 2048, snd_emu10k1_proc_read);
539 if (emu->card_capabilities->emu10k2_chip) {
540 if (! snd_card_proc_new(emu->card, "spdif-in", &entry))
541 snd_info_set_text_ops(entry, emu, 2048, snd_emu10k1_proc_spdif_read);
544 if (! snd_card_proc_new(emu->card, "voices", &entry))
545 snd_info_set_text_ops(entry, emu, 2048, snd_emu10k1_proc_voices_read);
547 if (! snd_card_proc_new(emu->card, "fx8010_gpr", &entry)) {
548 entry->content = SNDRV_INFO_CONTENT_DATA;
549 entry->private_data = emu;
550 entry->mode = S_IFREG | S_IRUGO /*| S_IWUSR*/;
551 entry->size = emu->audigy ? A_TOTAL_SIZE_GPR : TOTAL_SIZE_GPR;
552 entry->c.ops = &snd_emu10k1_proc_ops_fx8010;
554 if (! snd_card_proc_new(emu->card, "fx8010_tram_data", &entry)) {
555 entry->content = SNDRV_INFO_CONTENT_DATA;
556 entry->private_data = emu;
557 entry->mode = S_IFREG | S_IRUGO /*| S_IWUSR*/;
558 entry->size = emu->audigy ? A_TOTAL_SIZE_TANKMEM_DATA : TOTAL_SIZE_TANKMEM_DATA ;
559 entry->c.ops = &snd_emu10k1_proc_ops_fx8010;
561 if (! snd_card_proc_new(emu->card, "fx8010_tram_addr", &entry)) {
562 entry->content = SNDRV_INFO_CONTENT_DATA;
563 entry->private_data = emu;
564 entry->mode = S_IFREG | S_IRUGO /*| S_IWUSR*/;
565 entry->size = emu->audigy ? A_TOTAL_SIZE_TANKMEM_ADDR : TOTAL_SIZE_TANKMEM_ADDR ;
566 entry->c.ops = &snd_emu10k1_proc_ops_fx8010;
568 if (! snd_card_proc_new(emu->card, "fx8010_code", &entry)) {
569 entry->content = SNDRV_INFO_CONTENT_DATA;
570 entry->private_data = emu;
571 entry->mode = S_IFREG | S_IRUGO /*| S_IWUSR*/;
572 entry->size = emu->audigy ? A_TOTAL_SIZE_CODE : TOTAL_SIZE_CODE;
573 entry->c.ops = &snd_emu10k1_proc_ops_fx8010;
575 if (! snd_card_proc_new(emu->card, "fx8010_acode", &entry)) {
576 entry->content = SNDRV_INFO_CONTENT_TEXT;
577 entry->private_data = emu;
578 entry->mode = S_IFREG | S_IRUGO /*| S_IWUSR*/;
579 entry->c.text.read_size = 128*1024;
580 entry->c.text.read = snd_emu10k1_proc_acode_read;