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>
36 static void snd_emu10k1_proc_spdif_status(struct snd_emu10k1 * emu,
37 struct snd_info_buffer *buffer,
42 static char *clkaccy[4] = { "1000ppm", "50ppm", "variable", "unknown" };
43 static int samplerate[16] = { 44100, 1, 48000, 32000, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
44 static char *channel[16] = { "unspec", "left", "right", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15" };
45 static char *emphasis[8] = { "none", "50/15 usec 2 channel", "2", "3", "4", "5", "6", "7" };
46 unsigned int status, rate = 0;
48 status = snd_emu10k1_ptr_read(emu, status_reg, 0);
50 snd_iprintf(buffer, "\n%s\n", title);
52 if (status != 0xffffffff) {
53 snd_iprintf(buffer, "Professional Mode : %s\n", (status & SPCS_PROFESSIONAL) ? "yes" : "no");
54 snd_iprintf(buffer, "Not Audio Data : %s\n", (status & SPCS_NOTAUDIODATA) ? "yes" : "no");
55 snd_iprintf(buffer, "Copyright : %s\n", (status & SPCS_COPYRIGHT) ? "yes" : "no");
56 snd_iprintf(buffer, "Emphasis : %s\n", emphasis[(status & SPCS_EMPHASISMASK) >> 3]);
57 snd_iprintf(buffer, "Mode : %i\n", (status & SPCS_MODEMASK) >> 6);
58 snd_iprintf(buffer, "Category Code : 0x%x\n", (status & SPCS_CATEGORYCODEMASK) >> 8);
59 snd_iprintf(buffer, "Generation Status : %s\n", status & SPCS_GENERATIONSTATUS ? "original" : "copy");
60 snd_iprintf(buffer, "Source Mask : %i\n", (status & SPCS_SOURCENUMMASK) >> 16);
61 snd_iprintf(buffer, "Channel Number : %s\n", channel[(status & SPCS_CHANNELNUMMASK) >> 20]);
62 snd_iprintf(buffer, "Sample Rate : %iHz\n", samplerate[(status & SPCS_SAMPLERATEMASK) >> 24]);
63 snd_iprintf(buffer, "Clock Accuracy : %s\n", clkaccy[(status & SPCS_CLKACCYMASK) >> 28]);
66 rate = snd_emu10k1_ptr_read(emu, rate_reg, 0);
67 snd_iprintf(buffer, "S/PDIF Valid : %s\n", rate & SRCS_SPDIFVALID ? "on" : "off");
68 snd_iprintf(buffer, "S/PDIF Locked : %s\n", rate & SRCS_SPDIFLOCKED ? "on" : "off");
69 snd_iprintf(buffer, "Rate Locked : %s\n", rate & SRCS_RATELOCKED ? "on" : "off");
70 /* From ((Rate * 48000 ) / 262144); */
71 snd_iprintf(buffer, "Estimated Sample Rate : %d\n", ((rate & 0xFFFFF ) * 375) >> 11);
74 snd_iprintf(buffer, "No signal detected.\n");
79 static void snd_emu10k1_proc_read(struct snd_info_entry *entry,
80 struct snd_info_buffer *buffer)
82 /* FIXME - output names are in emufx.c too */
83 static char *creative_outs[32] = {
85 /* 01 */ "AC97 Right",
86 /* 02 */ "Optical IEC958 Left",
87 /* 03 */ "Optical IEC958 Right",
90 /* 06 */ "Headphone Left",
91 /* 07 */ "Headphone Right",
92 /* 08 */ "Surround Left",
93 /* 09 */ "Surround Right",
94 /* 10 */ "PCM Capture Left",
95 /* 11 */ "PCM Capture Right",
96 /* 12 */ "MIC Capture",
97 /* 13 */ "AC97 Surround Left",
98 /* 14 */ "AC97 Surround Right",
101 /* 17 */ "Analog Center",
102 /* 18 */ "Analog LFE",
118 static char *audigy_outs[64] = {
119 /* 00 */ "Digital Front Left",
120 /* 01 */ "Digital Front Right",
121 /* 02 */ "Digital Center",
122 /* 03 */ "Digital LEF",
123 /* 04 */ "Headphone Left",
124 /* 05 */ "Headphone Right",
125 /* 06 */ "Digital Rear Left",
126 /* 07 */ "Digital Rear Right",
127 /* 08 */ "Front Left",
128 /* 09 */ "Front Right",
133 /* 14 */ "Rear Left",
134 /* 15 */ "Rear Right",
135 /* 16 */ "AC97 Front Left",
136 /* 17 */ "AC97 Front Right",
137 /* 18 */ "ADC Caputre Left",
138 /* 19 */ "ADC Capture Right",
161 /* 42 */ "FXBUS2_10",
162 /* 43 */ "FXBUS2_11",
163 /* 44 */ "FXBUS2_12",
164 /* 45 */ "FXBUS2_13",
165 /* 46 */ "FXBUS2_14",
166 /* 47 */ "FXBUS2_15",
167 /* 48 */ "FXBUS2_16",
168 /* 49 */ "FXBUS2_17",
169 /* 50 */ "FXBUS2_18",
170 /* 51 */ "FXBUS2_19",
171 /* 52 */ "FXBUS2_20",
172 /* 53 */ "FXBUS2_21",
173 /* 54 */ "FXBUS2_22",
174 /* 55 */ "FXBUS2_23",
175 /* 56 */ "FXBUS2_24",
176 /* 57 */ "FXBUS2_25",
177 /* 58 */ "FXBUS2_26",
178 /* 59 */ "FXBUS2_27",
179 /* 60 */ "FXBUS2_28",
180 /* 61 */ "FXBUS2_29",
181 /* 62 */ "FXBUS2_30",
185 struct snd_emu10k1 *emu = entry->private_data;
186 unsigned int val, val1;
187 int nefx = emu->audigy ? 64 : 32;
188 char **outputs = emu->audigy ? audigy_outs : creative_outs;
191 snd_iprintf(buffer, "EMU10K1\n\n");
192 snd_iprintf(buffer, "Card : %s\n",
193 emu->audigy ? "Audigy" : (emu->card_capabilities->ecard ? "EMU APS" : "Creative"));
194 snd_iprintf(buffer, "Internal TRAM (words) : 0x%x\n", emu->fx8010.itram_size);
195 snd_iprintf(buffer, "External TRAM (words) : 0x%x\n", (int)emu->fx8010.etram_pages.bytes / 2);
196 snd_iprintf(buffer, "\n");
197 snd_iprintf(buffer, "Effect Send Routing :\n");
198 for (idx = 0; idx < NUM_G; idx++) {
200 snd_emu10k1_ptr_read(emu, A_FXRT1, idx) :
201 snd_emu10k1_ptr_read(emu, FXRT, idx);
203 snd_emu10k1_ptr_read(emu, A_FXRT2, idx) :
206 snd_iprintf(buffer, "Ch%i: A=%i, B=%i, C=%i, D=%i, ",
212 snd_iprintf(buffer, "E=%i, F=%i, G=%i, H=%i\n",
216 (val1 >> 24) & 0x3f);
218 snd_iprintf(buffer, "Ch%i: A=%i, B=%i, C=%i, D=%i\n",
226 snd_iprintf(buffer, "\nCaptured FX Outputs :\n");
227 for (idx = 0; idx < nefx; idx++) {
228 if (emu->efx_voices_mask[idx/32] & (1 << (idx%32)))
229 snd_iprintf(buffer, " Output %02i [%s]\n", idx, outputs[idx]);
231 snd_iprintf(buffer, "\nAll FX Outputs :\n");
232 for (idx = 0; idx < (emu->audigy ? 64 : 32); idx++)
233 snd_iprintf(buffer, " Output %02i [%s]\n", idx, outputs[idx]);
236 static void snd_emu10k1_proc_spdif_read(struct snd_info_entry *entry,
237 struct snd_info_buffer *buffer)
239 struct snd_emu10k1 *emu = entry->private_data;
240 snd_emu10k1_proc_spdif_status(emu, buffer, "CD-ROM S/PDIF In", CDCS, CDSRCS);
241 snd_emu10k1_proc_spdif_status(emu, buffer, "Optical or Coax S/PDIF In", GPSCS, GPSRCS);
243 val = snd_emu10k1_ptr_read(emu, ZVSRCS, 0);
244 snd_iprintf(buffer, "\nZoomed Video\n");
245 snd_iprintf(buffer, "Rate Locked : %s\n", val & SRCS_RATELOCKED ? "on" : "off");
246 snd_iprintf(buffer, "Estimated Sample Rate : 0x%x\n", val & SRCS_ESTSAMPLERATE);
250 static void snd_emu10k1_proc_rates_read(struct snd_info_entry *entry,
251 struct snd_info_buffer *buffer)
253 static int samplerate[8] = { 44100, 48000, 96000, 192000, 4, 5, 6, 7 };
254 struct snd_emu10k1 *emu = entry->private_data;
255 unsigned int val, tmp, n;
256 val = snd_emu10k1_ptr20_read(emu, CAPTURE_RATE_STATUS, 0);
257 tmp = (val >> 16) & 0x8;
259 tmp = val >> (16 + (n*4));
260 if (tmp & 0x8) snd_iprintf(buffer, "Channel %d: Rate=%d\n", n, samplerate[tmp & 0x7]);
261 else snd_iprintf(buffer, "Channel %d: No input\n", n);
265 static void snd_emu10k1_proc_acode_read(struct snd_info_entry *entry,
266 struct snd_info_buffer *buffer)
269 struct snd_emu10k1 *emu = entry->private_data;
271 snd_iprintf(buffer, "FX8010 Instruction List '%s'\n", emu->fx8010.name);
272 snd_iprintf(buffer, " Code dump :\n");
273 for (pc = 0; pc < (emu->audigy ? 1024 : 512); pc++) {
276 low = snd_emu10k1_efx_read(emu, pc * 2);
277 high = snd_emu10k1_efx_read(emu, pc * 2 + 1);
279 snd_iprintf(buffer, " OP(0x%02x, 0x%03x, 0x%03x, 0x%03x, 0x%03x) /* 0x%04x: 0x%08x%08x */\n",
281 (high >> 12) & 0x7ff,
288 snd_iprintf(buffer, " OP(0x%02x, 0x%03x, 0x%03x, 0x%03x, 0x%03x) /* 0x%04x: 0x%08x%08x */\n",
290 (high >> 10) & 0x3ff,
299 #define TOTAL_SIZE_GPR (0x100*4)
300 #define A_TOTAL_SIZE_GPR (0x200*4)
301 #define TOTAL_SIZE_TANKMEM_DATA (0xa0*4)
302 #define TOTAL_SIZE_TANKMEM_ADDR (0xa0*4)
303 #define A_TOTAL_SIZE_TANKMEM_DATA (0x100*4)
304 #define A_TOTAL_SIZE_TANKMEM_ADDR (0x100*4)
305 #define TOTAL_SIZE_CODE (0x200*8)
306 #define A_TOTAL_SIZE_CODE (0x400*8)
308 static long snd_emu10k1_fx8010_read(struct snd_info_entry *entry,
309 void *file_private_data,
310 struct file *file, char __user *buf,
311 unsigned long count, unsigned long pos)
314 struct snd_emu10k1 *emu = entry->private_data;
318 if (!strcmp(entry->name, "fx8010_tram_addr")) {
319 offset = TANKMEMADDRREGBASE;
321 } else if (!strcmp(entry->name, "fx8010_tram_data")) {
322 offset = TANKMEMDATAREGBASE;
323 } else if (!strcmp(entry->name, "fx8010_code")) {
324 offset = emu->audigy ? A_MICROCODEBASE : MICROCODEBASE;
326 offset = emu->audigy ? A_FXGPREGBASE : FXGPREGBASE;
329 if (pos + size > entry->size)
330 size = (long)entry->size - pos;
335 if ((tmp = kmalloc(size + 8, GFP_KERNEL)) == NULL)
337 for (idx = 0; idx < ((pos & 3) + size + 3) >> 2; idx++)
338 if (tram_addr && emu->audigy) {
339 tmp[idx] = snd_emu10k1_ptr_read(emu, offset + idx + (pos >> 2), 0) >> 11;
340 tmp[idx] |= snd_emu10k1_ptr_read(emu, 0x100 + idx + (pos >> 2), 0) << 20;
342 tmp[idx] = snd_emu10k1_ptr_read(emu, offset + idx + (pos >> 2), 0);
343 if (copy_to_user(buf, ((char *)tmp) + (pos & 3), size))
354 static void snd_emu10k1_proc_voices_read(struct snd_info_entry *entry,
355 struct snd_info_buffer *buffer)
357 struct snd_emu10k1 *emu = entry->private_data;
358 struct snd_emu10k1_voice *voice;
361 snd_iprintf(buffer, "ch\tuse\tpcm\tefx\tsynth\tmidi\n");
362 for (idx = 0; idx < NUM_G; idx++) {
363 voice = &emu->voices[idx];
364 snd_iprintf(buffer, "%i\t%i\t%i\t%i\t%i\t%i\n",
374 #ifdef CONFIG_SND_DEBUG
375 static void snd_emu_proc_io_reg_read(struct snd_info_entry *entry,
376 struct snd_info_buffer *buffer)
378 struct snd_emu10k1 *emu = entry->private_data;
382 snd_iprintf(buffer, "IO Registers:\n\n");
383 for(i = 0; i < 0x40; i+=4) {
384 spin_lock_irqsave(&emu->emu_lock, flags);
385 value = inl(emu->port + i);
386 spin_unlock_irqrestore(&emu->emu_lock, flags);
387 snd_iprintf(buffer, "%02X: %08lX\n", i, value);
391 static void snd_emu_proc_io_reg_write(struct snd_info_entry *entry,
392 struct snd_info_buffer *buffer)
394 struct snd_emu10k1 *emu = entry->private_data;
398 while (!snd_info_get_line(buffer, line, sizeof(line))) {
399 if (sscanf(line, "%x %x", ®, &val) != 2)
401 if ((reg < 0x40) && (reg >=0) && (val <= 0xffffffff) ) {
402 spin_lock_irqsave(&emu->emu_lock, flags);
403 outl(val, emu->port + (reg & 0xfffffffc));
404 spin_unlock_irqrestore(&emu->emu_lock, flags);
409 static unsigned int snd_ptr_read(struct snd_emu10k1 * emu,
415 unsigned int regptr, val;
417 regptr = (reg << 16) | chn;
419 spin_lock_irqsave(&emu->emu_lock, flags);
420 outl(regptr, emu->port + iobase + PTR);
421 val = inl(emu->port + iobase + DATA);
422 spin_unlock_irqrestore(&emu->emu_lock, flags);
426 static void snd_ptr_write(struct snd_emu10k1 *emu,
435 regptr = (reg << 16) | chn;
437 spin_lock_irqsave(&emu->emu_lock, flags);
438 outl(regptr, emu->port + iobase + PTR);
439 outl(data, emu->port + iobase + DATA);
440 spin_unlock_irqrestore(&emu->emu_lock, flags);
444 static void snd_emu_proc_ptr_reg_read(struct snd_info_entry *entry,
445 struct snd_info_buffer *buffer, int iobase, int offset, int length, int voices)
447 struct snd_emu10k1 *emu = entry->private_data;
450 if (offset+length > 0xa0) {
451 snd_iprintf(buffer, "Input values out of range\n");
454 snd_iprintf(buffer, "Registers 0x%x\n", iobase);
455 for(i = offset; i < offset+length; i++) {
456 snd_iprintf(buffer, "%02X: ",i);
457 for (j = 0; j < voices; j++) {
459 value = snd_ptr_read(emu, 0, i, j);
461 value = snd_ptr_read(emu, 0x20, i, j);
462 snd_iprintf(buffer, "%08lX ", value);
464 snd_iprintf(buffer, "\n");
468 static void snd_emu_proc_ptr_reg_write(struct snd_info_entry *entry,
469 struct snd_info_buffer *buffer, int iobase)
471 struct snd_emu10k1 *emu = entry->private_data;
473 unsigned int reg, channel_id , val;
474 while (!snd_info_get_line(buffer, line, sizeof(line))) {
475 if (sscanf(line, "%x %x %x", ®, &channel_id, &val) != 3)
477 if ((reg < 0xa0) && (reg >=0) && (val <= 0xffffffff) && (channel_id >=0) && (channel_id <= 3) )
478 snd_ptr_write(emu, iobase, reg, channel_id, val);
482 static void snd_emu_proc_ptr_reg_write00(struct snd_info_entry *entry,
483 struct snd_info_buffer *buffer)
485 snd_emu_proc_ptr_reg_write(entry, buffer, 0);
488 static void snd_emu_proc_ptr_reg_write20(struct snd_info_entry *entry,
489 struct snd_info_buffer *buffer)
491 snd_emu_proc_ptr_reg_write(entry, buffer, 0x20);
495 static void snd_emu_proc_ptr_reg_read00a(struct snd_info_entry *entry,
496 struct snd_info_buffer *buffer)
498 snd_emu_proc_ptr_reg_read(entry, buffer, 0, 0, 0x40, 64);
501 static void snd_emu_proc_ptr_reg_read00b(struct snd_info_entry *entry,
502 struct snd_info_buffer *buffer)
504 snd_emu_proc_ptr_reg_read(entry, buffer, 0, 0x40, 0x40, 64);
507 static void snd_emu_proc_ptr_reg_read20a(struct snd_info_entry *entry,
508 struct snd_info_buffer *buffer)
510 snd_emu_proc_ptr_reg_read(entry, buffer, 0x20, 0, 0x40, 4);
513 static void snd_emu_proc_ptr_reg_read20b(struct snd_info_entry *entry,
514 struct snd_info_buffer *buffer)
516 snd_emu_proc_ptr_reg_read(entry, buffer, 0x20, 0x40, 0x40, 4);
519 static void snd_emu_proc_ptr_reg_read20c(struct snd_info_entry *entry,
520 struct snd_info_buffer * buffer)
522 snd_emu_proc_ptr_reg_read(entry, buffer, 0x20, 0x80, 0x20, 4);
526 static struct snd_info_entry_ops snd_emu10k1_proc_ops_fx8010 = {
527 .read = snd_emu10k1_fx8010_read,
530 int __devinit snd_emu10k1_proc_init(struct snd_emu10k1 * emu)
532 struct snd_info_entry *entry;
533 #ifdef CONFIG_SND_DEBUG
534 if (! snd_card_proc_new(emu->card, "io_regs", &entry)) {
535 snd_info_set_text_ops(entry, emu, snd_emu_proc_io_reg_read);
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, snd_emu_proc_ptr_reg_read00a);
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_regs00b", &entry)) {
545 snd_info_set_text_ops(entry, emu, snd_emu_proc_ptr_reg_read00b);
546 entry->c.text.write = snd_emu_proc_ptr_reg_write00;
547 entry->mode |= S_IWUSR;
549 if (! snd_card_proc_new(emu->card, "ptr_regs20a", &entry)) {
550 snd_info_set_text_ops(entry, emu, snd_emu_proc_ptr_reg_read20a);
551 entry->c.text.write = snd_emu_proc_ptr_reg_write20;
552 entry->mode |= S_IWUSR;
554 if (! snd_card_proc_new(emu->card, "ptr_regs20b", &entry)) {
555 snd_info_set_text_ops(entry, emu, snd_emu_proc_ptr_reg_read20b);
556 entry->c.text.write = snd_emu_proc_ptr_reg_write20;
557 entry->mode |= S_IWUSR;
559 if (! snd_card_proc_new(emu->card, "ptr_regs20c", &entry)) {
560 snd_info_set_text_ops(entry, emu, snd_emu_proc_ptr_reg_read20c);
561 entry->c.text.write = snd_emu_proc_ptr_reg_write20;
562 entry->mode |= S_IWUSR;
566 if (! snd_card_proc_new(emu->card, "emu10k1", &entry))
567 snd_info_set_text_ops(entry, emu, snd_emu10k1_proc_read);
569 if (emu->card_capabilities->emu10k2_chip) {
570 if (! snd_card_proc_new(emu->card, "spdif-in", &entry))
571 snd_info_set_text_ops(entry, emu, snd_emu10k1_proc_spdif_read);
573 if (emu->card_capabilities->ca0151_chip) {
574 if (! snd_card_proc_new(emu->card, "capture-rates", &entry))
575 snd_info_set_text_ops(entry, emu, snd_emu10k1_proc_rates_read);
578 if (! snd_card_proc_new(emu->card, "voices", &entry))
579 snd_info_set_text_ops(entry, emu, snd_emu10k1_proc_voices_read);
581 if (! snd_card_proc_new(emu->card, "fx8010_gpr", &entry)) {
582 entry->content = SNDRV_INFO_CONTENT_DATA;
583 entry->private_data = emu;
584 entry->mode = S_IFREG | S_IRUGO /*| S_IWUSR*/;
585 entry->size = emu->audigy ? A_TOTAL_SIZE_GPR : TOTAL_SIZE_GPR;
586 entry->c.ops = &snd_emu10k1_proc_ops_fx8010;
588 if (! snd_card_proc_new(emu->card, "fx8010_tram_data", &entry)) {
589 entry->content = SNDRV_INFO_CONTENT_DATA;
590 entry->private_data = emu;
591 entry->mode = S_IFREG | S_IRUGO /*| S_IWUSR*/;
592 entry->size = emu->audigy ? A_TOTAL_SIZE_TANKMEM_DATA : TOTAL_SIZE_TANKMEM_DATA ;
593 entry->c.ops = &snd_emu10k1_proc_ops_fx8010;
595 if (! snd_card_proc_new(emu->card, "fx8010_tram_addr", &entry)) {
596 entry->content = SNDRV_INFO_CONTENT_DATA;
597 entry->private_data = emu;
598 entry->mode = S_IFREG | S_IRUGO /*| S_IWUSR*/;
599 entry->size = emu->audigy ? A_TOTAL_SIZE_TANKMEM_ADDR : TOTAL_SIZE_TANKMEM_ADDR ;
600 entry->c.ops = &snd_emu10k1_proc_ops_fx8010;
602 if (! snd_card_proc_new(emu->card, "fx8010_code", &entry)) {
603 entry->content = SNDRV_INFO_CONTENT_DATA;
604 entry->private_data = emu;
605 entry->mode = S_IFREG | S_IRUGO /*| S_IWUSR*/;
606 entry->size = emu->audigy ? A_TOTAL_SIZE_CODE : TOTAL_SIZE_CODE;
607 entry->c.ops = &snd_emu10k1_proc_ops_fx8010;
609 if (! snd_card_proc_new(emu->card, "fx8010_acode", &entry)) {
610 entry->content = SNDRV_INFO_CONTENT_TEXT;
611 entry->private_data = emu;
612 entry->mode = S_IFREG | S_IRUGO /*| S_IWUSR*/;
613 entry->c.text.read = snd_emu10k1_proc_acode_read;
617 #endif /* CONFIG_PROC_FS */