1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
5 * Routines for control of EMU10K1 chips / proc interface routines
7 * Copyright (c) by James Courtier-Dutton <James@superbug.co.uk>
8 * Added EMU 1010 support.
17 #include <linux/slab.h>
18 #include <linux/init.h>
19 #include <sound/core.h>
20 #include <sound/emu10k1.h>
23 static void snd_emu10k1_proc_spdif_status(struct snd_emu10k1 * emu,
24 struct snd_info_buffer *buffer,
29 static const char * const clkaccy[4] = { "1000ppm", "50ppm", "variable", "unknown" };
30 static const int samplerate[16] = { 44100, 1, 48000, 32000, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
31 static const char * const channel[16] = { "unspec", "left", "right", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15" };
32 static const char * const emphasis[8] = { "none", "50/15 usec 2 channel", "2", "3", "4", "5", "6", "7" };
33 unsigned int status, rate = 0;
35 status = snd_emu10k1_ptr_read(emu, status_reg, 0);
37 snd_iprintf(buffer, "\n%s\n", title);
39 if (status != 0xffffffff) {
40 snd_iprintf(buffer, "Professional Mode : %s\n", (status & SPCS_PROFESSIONAL) ? "yes" : "no");
41 snd_iprintf(buffer, "Not Audio Data : %s\n", (status & SPCS_NOTAUDIODATA) ? "yes" : "no");
42 snd_iprintf(buffer, "Copyright : %s\n", (status & SPCS_COPYRIGHT) ? "yes" : "no");
43 snd_iprintf(buffer, "Emphasis : %s\n", emphasis[(status & SPCS_EMPHASISMASK) >> 3]);
44 snd_iprintf(buffer, "Mode : %i\n", (status & SPCS_MODEMASK) >> 6);
45 snd_iprintf(buffer, "Category Code : 0x%x\n", (status & SPCS_CATEGORYCODEMASK) >> 8);
46 snd_iprintf(buffer, "Generation Status : %s\n", status & SPCS_GENERATIONSTATUS ? "original" : "copy");
47 snd_iprintf(buffer, "Source Mask : %i\n", (status & SPCS_SOURCENUMMASK) >> 16);
48 snd_iprintf(buffer, "Channel Number : %s\n", channel[(status & SPCS_CHANNELNUMMASK) >> 20]);
49 snd_iprintf(buffer, "Sample Rate : %iHz\n", samplerate[(status & SPCS_SAMPLERATEMASK) >> 24]);
50 snd_iprintf(buffer, "Clock Accuracy : %s\n", clkaccy[(status & SPCS_CLKACCYMASK) >> 28]);
53 rate = snd_emu10k1_ptr_read(emu, rate_reg, 0);
54 snd_iprintf(buffer, "S/PDIF Valid : %s\n", rate & SRCS_SPDIFVALID ? "on" : "off");
55 snd_iprintf(buffer, "S/PDIF Locked : %s\n", rate & SRCS_SPDIFLOCKED ? "on" : "off");
56 snd_iprintf(buffer, "Rate Locked : %s\n", rate & SRCS_RATELOCKED ? "on" : "off");
57 /* From ((Rate * 48000 ) / 262144); */
58 snd_iprintf(buffer, "Estimated Sample Rate : %d\n", ((rate & 0xFFFFF ) * 375) >> 11);
61 snd_iprintf(buffer, "No signal detected.\n");
66 static void snd_emu10k1_proc_read(struct snd_info_entry *entry,
67 struct snd_info_buffer *buffer)
69 /* FIXME - output names are in emufx.c too */
70 static const char * const creative_outs[32] = {
72 /* 01 */ "AC97 Right",
73 /* 02 */ "Optical IEC958 Left",
74 /* 03 */ "Optical IEC958 Right",
77 /* 06 */ "Headphone Left",
78 /* 07 */ "Headphone Right",
79 /* 08 */ "Surround Left",
80 /* 09 */ "Surround Right",
81 /* 10 */ "PCM Capture Left",
82 /* 11 */ "PCM Capture Right",
83 /* 12 */ "MIC Capture",
84 /* 13 */ "AC97 Surround Left",
85 /* 14 */ "AC97 Surround Right",
88 /* 17 */ "Analog Center",
89 /* 18 */ "Analog LFE",
105 static const char * const audigy_outs[64] = {
106 /* 00 */ "Digital Front Left",
107 /* 01 */ "Digital Front Right",
108 /* 02 */ "Digital Center",
109 /* 03 */ "Digital LEF",
110 /* 04 */ "Headphone Left",
111 /* 05 */ "Headphone Right",
112 /* 06 */ "Digital Rear Left",
113 /* 07 */ "Digital Rear Right",
114 /* 08 */ "Front Left",
115 /* 09 */ "Front Right",
120 /* 14 */ "Rear Left",
121 /* 15 */ "Rear Right",
122 /* 16 */ "AC97 Front Left",
123 /* 17 */ "AC97 Front Right",
124 /* 18 */ "ADC Capture Left",
125 /* 19 */ "ADC Capture Right",
148 /* 42 */ "FXBUS2_10",
149 /* 43 */ "FXBUS2_11",
150 /* 44 */ "FXBUS2_12",
151 /* 45 */ "FXBUS2_13",
152 /* 46 */ "FXBUS2_14",
153 /* 47 */ "FXBUS2_15",
154 /* 48 */ "FXBUS2_16",
155 /* 49 */ "FXBUS2_17",
156 /* 50 */ "FXBUS2_18",
157 /* 51 */ "FXBUS2_19",
158 /* 52 */ "FXBUS2_20",
159 /* 53 */ "FXBUS2_21",
160 /* 54 */ "FXBUS2_22",
161 /* 55 */ "FXBUS2_23",
162 /* 56 */ "FXBUS2_24",
163 /* 57 */ "FXBUS2_25",
164 /* 58 */ "FXBUS2_26",
165 /* 59 */ "FXBUS2_27",
166 /* 60 */ "FXBUS2_28",
167 /* 61 */ "FXBUS2_29",
168 /* 62 */ "FXBUS2_30",
172 struct snd_emu10k1 *emu = entry->private_data;
173 unsigned int val, val1;
174 int nefx = emu->audigy ? 64 : 32;
175 const char * const *outputs = emu->audigy ? audigy_outs : creative_outs;
178 snd_iprintf(buffer, "EMU10K1\n\n");
179 snd_iprintf(buffer, "Card : %s\n",
180 emu->audigy ? "Audigy" : (emu->card_capabilities->ecard ? "EMU APS" : "Creative"));
181 snd_iprintf(buffer, "Internal TRAM (words) : 0x%x\n", emu->fx8010.itram_size);
182 snd_iprintf(buffer, "External TRAM (words) : 0x%x\n", (int)emu->fx8010.etram_pages.bytes / 2);
183 snd_iprintf(buffer, "\n");
184 snd_iprintf(buffer, "Effect Send Routing :\n");
185 for (idx = 0; idx < NUM_G; idx++) {
187 snd_emu10k1_ptr_read(emu, A_FXRT1, idx) :
188 snd_emu10k1_ptr_read(emu, FXRT, idx);
190 snd_emu10k1_ptr_read(emu, A_FXRT2, idx) :
193 snd_iprintf(buffer, "Ch%i: A=%i, B=%i, C=%i, D=%i, ",
199 snd_iprintf(buffer, "E=%i, F=%i, G=%i, H=%i\n",
203 (val1 >> 24) & 0x3f);
205 snd_iprintf(buffer, "Ch%i: A=%i, B=%i, C=%i, D=%i\n",
213 snd_iprintf(buffer, "\nCaptured FX Outputs :\n");
214 for (idx = 0; idx < nefx; idx++) {
215 if (emu->efx_voices_mask[idx/32] & (1 << (idx%32)))
216 snd_iprintf(buffer, " Output %02i [%s]\n", idx, outputs[idx]);
218 snd_iprintf(buffer, "\nAll FX Outputs :\n");
219 for (idx = 0; idx < (emu->audigy ? 64 : 32); idx++)
220 snd_iprintf(buffer, " Output %02i [%s]\n", idx, outputs[idx]);
223 static void snd_emu10k1_proc_spdif_read(struct snd_info_entry *entry,
224 struct snd_info_buffer *buffer)
226 struct snd_emu10k1 *emu = entry->private_data;
231 if (emu->card_capabilities->emu_model) {
232 snd_emu1010_fpga_read(emu, 0x38, &value);
233 if ((value & 0x1) == 0) {
234 snd_emu1010_fpga_read(emu, 0x2a, &value);
235 snd_emu1010_fpga_read(emu, 0x2b, &value2);
236 rate = 0x1770000 / (((value << 5) | value2)+1);
237 snd_iprintf(buffer, "ADAT Locked : %u\n", rate);
239 snd_iprintf(buffer, "ADAT Unlocked\n");
241 snd_emu1010_fpga_read(emu, 0x20, &value);
242 if ((value & 0x4) == 0) {
243 snd_emu1010_fpga_read(emu, 0x28, &value);
244 snd_emu1010_fpga_read(emu, 0x29, &value2);
245 rate = 0x1770000 / (((value << 5) | value2)+1);
246 snd_iprintf(buffer, "SPDIF Locked : %d\n", rate);
248 snd_iprintf(buffer, "SPDIF Unlocked\n");
251 snd_emu10k1_proc_spdif_status(emu, buffer, "CD-ROM S/PDIF In", CDCS, CDSRCS);
252 snd_emu10k1_proc_spdif_status(emu, buffer, "Optical or Coax S/PDIF In", GPSCS, GPSRCS);
255 val = snd_emu10k1_ptr_read(emu, ZVSRCS, 0);
256 snd_iprintf(buffer, "\nZoomed Video\n");
257 snd_iprintf(buffer, "Rate Locked : %s\n", val & SRCS_RATELOCKED ? "on" : "off");
258 snd_iprintf(buffer, "Estimated Sample Rate : 0x%x\n", val & SRCS_ESTSAMPLERATE);
262 static void snd_emu10k1_proc_rates_read(struct snd_info_entry *entry,
263 struct snd_info_buffer *buffer)
265 static const int samplerate[8] = { 44100, 48000, 96000, 192000, 4, 5, 6, 7 };
266 struct snd_emu10k1 *emu = entry->private_data;
267 unsigned int val, tmp, n;
268 val = snd_emu10k1_ptr20_read(emu, CAPTURE_RATE_STATUS, 0);
269 for (n = 0; n < 4; n++) {
270 tmp = val >> (16 + (n*4));
271 if (tmp & 0x8) snd_iprintf(buffer, "Channel %d: Rate=%d\n", n, samplerate[tmp & 0x7]);
272 else snd_iprintf(buffer, "Channel %d: No input\n", n);
276 static void snd_emu10k1_proc_acode_read(struct snd_info_entry *entry,
277 struct snd_info_buffer *buffer)
280 struct snd_emu10k1 *emu = entry->private_data;
282 snd_iprintf(buffer, "FX8010 Instruction List '%s'\n", emu->fx8010.name);
283 snd_iprintf(buffer, " Code dump :\n");
284 for (pc = 0; pc < (emu->audigy ? 1024 : 512); pc++) {
287 low = snd_emu10k1_efx_read(emu, pc * 2);
288 high = snd_emu10k1_efx_read(emu, pc * 2 + 1);
290 snd_iprintf(buffer, " OP(0x%02x, 0x%03x, 0x%03x, 0x%03x, 0x%03x) /* 0x%04x: 0x%08x%08x */\n",
292 (high >> 12) & 0x7ff,
299 snd_iprintf(buffer, " OP(0x%02x, 0x%03x, 0x%03x, 0x%03x, 0x%03x) /* 0x%04x: 0x%08x%08x */\n",
301 (high >> 10) & 0x3ff,
310 #define TOTAL_SIZE_GPR (0x100*4)
311 #define A_TOTAL_SIZE_GPR (0x200*4)
312 #define TOTAL_SIZE_TANKMEM_DATA (0xa0*4)
313 #define TOTAL_SIZE_TANKMEM_ADDR (0xa0*4)
314 #define A_TOTAL_SIZE_TANKMEM_DATA (0x100*4)
315 #define A_TOTAL_SIZE_TANKMEM_ADDR (0x100*4)
316 #define TOTAL_SIZE_CODE (0x200*8)
317 #define A_TOTAL_SIZE_CODE (0x400*8)
319 static ssize_t snd_emu10k1_fx8010_read(struct snd_info_entry *entry,
320 void *file_private_data,
321 struct file *file, char __user *buf,
322 size_t count, loff_t pos)
324 struct snd_emu10k1 *emu = entry->private_data;
331 if (!strcmp(entry->name, "fx8010_tram_addr")) {
332 offset = TANKMEMADDRREGBASE;
334 } else if (!strcmp(entry->name, "fx8010_tram_data")) {
335 offset = TANKMEMDATAREGBASE;
336 } else if (!strcmp(entry->name, "fx8010_code")) {
337 offset = emu->audigy ? A_MICROCODEBASE : MICROCODEBASE;
339 offset = emu->audigy ? A_FXGPREGBASE : FXGPREGBASE;
342 tmp = kmalloc(count + 8, GFP_KERNEL);
345 for (idx = 0; idx < ((pos & 3) + count + 3) >> 2; idx++) {
347 val = snd_emu10k1_ptr_read(emu, offset + idx + (pos >> 2), 0);
348 if (tram_addr && emu->audigy) {
350 val |= snd_emu10k1_ptr_read(emu, 0x100 + idx + (pos >> 2), 0) << 20;
354 if (copy_to_user(buf, ((char *)tmp) + (pos & 3), count))
362 static void snd_emu10k1_proc_voices_read(struct snd_info_entry *entry,
363 struct snd_info_buffer *buffer)
365 struct snd_emu10k1 *emu = entry->private_data;
366 struct snd_emu10k1_voice *voice;
369 snd_iprintf(buffer, "ch\tuse\tpcm\tefx\tsynth\tmidi\n");
370 for (idx = 0; idx < NUM_G; idx++) {
371 voice = &emu->voices[idx];
372 snd_iprintf(buffer, "%i\t%i\t%i\t%i\t%i\t%i\n",
382 #ifdef CONFIG_SND_DEBUG
383 static void snd_emu_proc_emu1010_reg_read(struct snd_info_entry *entry,
384 struct snd_info_buffer *buffer)
386 struct snd_emu10k1 *emu = entry->private_data;
389 snd_iprintf(buffer, "EMU1010 Registers:\n\n");
391 for(i = 0; i < 0x40; i+=1) {
392 snd_emu1010_fpga_read(emu, i, &value);
393 snd_iprintf(buffer, "%02X: %08X, %02X\n", i, value, (value >> 8) & 0x7f);
397 static void snd_emu_proc_io_reg_read(struct snd_info_entry *entry,
398 struct snd_info_buffer *buffer)
400 struct snd_emu10k1 *emu = entry->private_data;
404 snd_iprintf(buffer, "IO Registers:\n\n");
405 for(i = 0; i < 0x40; i+=4) {
406 spin_lock_irqsave(&emu->emu_lock, flags);
407 value = inl(emu->port + i);
408 spin_unlock_irqrestore(&emu->emu_lock, flags);
409 snd_iprintf(buffer, "%02X: %08lX\n", i, value);
413 static void snd_emu_proc_io_reg_write(struct snd_info_entry *entry,
414 struct snd_info_buffer *buffer)
416 struct snd_emu10k1 *emu = entry->private_data;
420 while (!snd_info_get_line(buffer, line, sizeof(line))) {
421 if (sscanf(line, "%x %x", ®, &val) != 2)
423 if (reg < 0x40 && val <= 0xffffffff) {
424 spin_lock_irqsave(&emu->emu_lock, flags);
425 outl(val, emu->port + (reg & 0xfffffffc));
426 spin_unlock_irqrestore(&emu->emu_lock, flags);
431 static unsigned int snd_ptr_read(struct snd_emu10k1 * emu,
437 unsigned int regptr, val;
439 regptr = (reg << 16) | chn;
441 spin_lock_irqsave(&emu->emu_lock, flags);
442 outl(regptr, emu->port + iobase + PTR);
443 val = inl(emu->port + iobase + DATA);
444 spin_unlock_irqrestore(&emu->emu_lock, flags);
448 static void snd_ptr_write(struct snd_emu10k1 *emu,
457 regptr = (reg << 16) | chn;
459 spin_lock_irqsave(&emu->emu_lock, flags);
460 outl(regptr, emu->port + iobase + PTR);
461 outl(data, emu->port + iobase + DATA);
462 spin_unlock_irqrestore(&emu->emu_lock, flags);
466 static void snd_emu_proc_ptr_reg_read(struct snd_info_entry *entry,
467 struct snd_info_buffer *buffer, int iobase, int offset, int length, int voices)
469 struct snd_emu10k1 *emu = entry->private_data;
472 if (offset+length > 0xa0) {
473 snd_iprintf(buffer, "Input values out of range\n");
476 snd_iprintf(buffer, "Registers 0x%x\n", iobase);
477 for(i = offset; i < offset+length; i++) {
478 snd_iprintf(buffer, "%02X: ",i);
479 for (j = 0; j < voices; j++) {
481 value = snd_ptr_read(emu, 0, i, j);
483 value = snd_ptr_read(emu, 0x20, i, j);
484 snd_iprintf(buffer, "%08lX ", value);
486 snd_iprintf(buffer, "\n");
490 static void snd_emu_proc_ptr_reg_write(struct snd_info_entry *entry,
491 struct snd_info_buffer *buffer, int iobase)
493 struct snd_emu10k1 *emu = entry->private_data;
495 unsigned int reg, channel_id , val;
496 while (!snd_info_get_line(buffer, line, sizeof(line))) {
497 if (sscanf(line, "%x %x %x", ®, &channel_id, &val) != 3)
499 if (reg < 0xa0 && val <= 0xffffffff && channel_id <= 3)
500 snd_ptr_write(emu, iobase, reg, channel_id, val);
504 static void snd_emu_proc_ptr_reg_write00(struct snd_info_entry *entry,
505 struct snd_info_buffer *buffer)
507 snd_emu_proc_ptr_reg_write(entry, buffer, 0);
510 static void snd_emu_proc_ptr_reg_write20(struct snd_info_entry *entry,
511 struct snd_info_buffer *buffer)
513 snd_emu_proc_ptr_reg_write(entry, buffer, 0x20);
517 static void snd_emu_proc_ptr_reg_read00a(struct snd_info_entry *entry,
518 struct snd_info_buffer *buffer)
520 snd_emu_proc_ptr_reg_read(entry, buffer, 0, 0, 0x40, 64);
523 static void snd_emu_proc_ptr_reg_read00b(struct snd_info_entry *entry,
524 struct snd_info_buffer *buffer)
526 snd_emu_proc_ptr_reg_read(entry, buffer, 0, 0x40, 0x40, 64);
529 static void snd_emu_proc_ptr_reg_read20a(struct snd_info_entry *entry,
530 struct snd_info_buffer *buffer)
532 snd_emu_proc_ptr_reg_read(entry, buffer, 0x20, 0, 0x40, 4);
535 static void snd_emu_proc_ptr_reg_read20b(struct snd_info_entry *entry,
536 struct snd_info_buffer *buffer)
538 snd_emu_proc_ptr_reg_read(entry, buffer, 0x20, 0x40, 0x40, 4);
541 static void snd_emu_proc_ptr_reg_read20c(struct snd_info_entry *entry,
542 struct snd_info_buffer * buffer)
544 snd_emu_proc_ptr_reg_read(entry, buffer, 0x20, 0x80, 0x20, 4);
548 static const struct snd_info_entry_ops snd_emu10k1_proc_ops_fx8010 = {
549 .read = snd_emu10k1_fx8010_read,
552 int snd_emu10k1_proc_init(struct snd_emu10k1 *emu)
554 struct snd_info_entry *entry;
555 #ifdef CONFIG_SND_DEBUG
556 if (emu->card_capabilities->emu_model) {
557 snd_card_ro_proc_new(emu->card, "emu1010_regs",
558 emu, snd_emu_proc_emu1010_reg_read);
560 snd_card_rw_proc_new(emu->card, "io_regs", emu,
561 snd_emu_proc_io_reg_read,
562 snd_emu_proc_io_reg_write);
563 snd_card_rw_proc_new(emu->card, "ptr_regs00a", emu,
564 snd_emu_proc_ptr_reg_read00a,
565 snd_emu_proc_ptr_reg_write00);
566 snd_card_rw_proc_new(emu->card, "ptr_regs00b", emu,
567 snd_emu_proc_ptr_reg_read00b,
568 snd_emu_proc_ptr_reg_write00);
569 snd_card_rw_proc_new(emu->card, "ptr_regs20a", emu,
570 snd_emu_proc_ptr_reg_read20a,
571 snd_emu_proc_ptr_reg_write20);
572 snd_card_rw_proc_new(emu->card, "ptr_regs20b", emu,
573 snd_emu_proc_ptr_reg_read20b,
574 snd_emu_proc_ptr_reg_write20);
575 snd_card_rw_proc_new(emu->card, "ptr_regs20c", emu,
576 snd_emu_proc_ptr_reg_read20c,
577 snd_emu_proc_ptr_reg_write20);
580 snd_card_ro_proc_new(emu->card, "emu10k1", emu, snd_emu10k1_proc_read);
582 if (emu->card_capabilities->emu10k2_chip)
583 snd_card_ro_proc_new(emu->card, "spdif-in", emu,
584 snd_emu10k1_proc_spdif_read);
585 if (emu->card_capabilities->ca0151_chip)
586 snd_card_ro_proc_new(emu->card, "capture-rates", emu,
587 snd_emu10k1_proc_rates_read);
589 snd_card_ro_proc_new(emu->card, "voices", emu,
590 snd_emu10k1_proc_voices_read);
592 if (! snd_card_proc_new(emu->card, "fx8010_gpr", &entry)) {
593 entry->content = SNDRV_INFO_CONTENT_DATA;
594 entry->private_data = emu;
595 entry->mode = S_IFREG | 0444 /*| S_IWUSR*/;
596 entry->size = emu->audigy ? A_TOTAL_SIZE_GPR : TOTAL_SIZE_GPR;
597 entry->c.ops = &snd_emu10k1_proc_ops_fx8010;
599 if (! snd_card_proc_new(emu->card, "fx8010_tram_data", &entry)) {
600 entry->content = SNDRV_INFO_CONTENT_DATA;
601 entry->private_data = emu;
602 entry->mode = S_IFREG | 0444 /*| S_IWUSR*/;
603 entry->size = emu->audigy ? A_TOTAL_SIZE_TANKMEM_DATA : TOTAL_SIZE_TANKMEM_DATA ;
604 entry->c.ops = &snd_emu10k1_proc_ops_fx8010;
606 if (! snd_card_proc_new(emu->card, "fx8010_tram_addr", &entry)) {
607 entry->content = SNDRV_INFO_CONTENT_DATA;
608 entry->private_data = emu;
609 entry->mode = S_IFREG | 0444 /*| S_IWUSR*/;
610 entry->size = emu->audigy ? A_TOTAL_SIZE_TANKMEM_ADDR : TOTAL_SIZE_TANKMEM_ADDR ;
611 entry->c.ops = &snd_emu10k1_proc_ops_fx8010;
613 if (! snd_card_proc_new(emu->card, "fx8010_code", &entry)) {
614 entry->content = SNDRV_INFO_CONTENT_DATA;
615 entry->private_data = emu;
616 entry->mode = S_IFREG | 0444 /*| S_IWUSR*/;
617 entry->size = emu->audigy ? A_TOTAL_SIZE_CODE : TOTAL_SIZE_CODE;
618 entry->c.ops = &snd_emu10k1_proc_ops_fx8010;
620 snd_card_ro_proc_new(emu->card, "fx8010_acode", emu,
621 snd_emu10k1_proc_acode_read);