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 rate
= snd_emu10k1_ptr_read(emu
, rate_reg
, 0);
50 snd_iprintf(buffer
, "\n%s\n", title
);
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 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 snd_iprintf(buffer
, "Estimated Sample Rate : 0x%x\n", rate
& SRCS_ESTSAMPLERATE
);
71 static void snd_emu10k1_proc_read(snd_info_entry_t
*entry
,
72 snd_info_buffer_t
* buffer
)
74 /* FIXME - output names are in emufx.c too */
75 static char *creative_outs
[32] = {
77 /* 01 */ "AC97 Right",
78 /* 02 */ "Optical IEC958 Left",
79 /* 03 */ "Optical IEC958 Right",
82 /* 06 */ "Headphone Left",
83 /* 07 */ "Headphone Right",
84 /* 08 */ "Surround Left",
85 /* 09 */ "Surround Right",
86 /* 10 */ "PCM Capture Left",
87 /* 11 */ "PCM Capture Right",
88 /* 12 */ "MIC Capture",
89 /* 13 */ "AC97 Surround Left",
90 /* 14 */ "AC97 Surround Right",
93 /* 17 */ "Analog Center",
94 /* 18 */ "Analog LFE",
110 static char *audigy_outs
[64] = {
111 /* 00 */ "Digital Front Left",
112 /* 01 */ "Digital Front Right",
113 /* 02 */ "Digital Center",
114 /* 03 */ "Digital LEF",
115 /* 04 */ "Headphone Left",
116 /* 05 */ "Headphone Right",
117 /* 06 */ "Digital Rear Left",
118 /* 07 */ "Digital Rear Right",
119 /* 08 */ "Front Left",
120 /* 09 */ "Front Right",
125 /* 14 */ "Rear Left",
126 /* 15 */ "Rear Right",
127 /* 16 */ "AC97 Front Left",
128 /* 17 */ "AC97 Front Right",
129 /* 18 */ "ADC Caputre Left",
130 /* 19 */ "ADC Capture Right",
153 /* 42 */ "FXBUS2_10",
154 /* 43 */ "FXBUS2_11",
155 /* 44 */ "FXBUS2_12",
156 /* 45 */ "FXBUS2_13",
157 /* 46 */ "FXBUS2_14",
158 /* 47 */ "FXBUS2_15",
159 /* 48 */ "FXBUS2_16",
160 /* 49 */ "FXBUS2_17",
161 /* 50 */ "FXBUS2_18",
162 /* 51 */ "FXBUS2_19",
163 /* 52 */ "FXBUS2_20",
164 /* 53 */ "FXBUS2_21",
165 /* 54 */ "FXBUS2_22",
166 /* 55 */ "FXBUS2_23",
167 /* 56 */ "FXBUS2_24",
168 /* 57 */ "FXBUS2_25",
169 /* 58 */ "FXBUS2_26",
170 /* 59 */ "FXBUS2_27",
171 /* 60 */ "FXBUS2_28",
172 /* 61 */ "FXBUS2_29",
173 /* 62 */ "FXBUS2_30",
177 emu10k1_t
*emu
= entry
->private_data
;
178 unsigned int val
, val1
;
179 int nefx
= emu
->audigy
? 64 : 32;
180 char **outputs
= emu
->audigy
? audigy_outs
: creative_outs
;
183 snd_iprintf(buffer
, "EMU10K1\n\n");
184 snd_iprintf(buffer
, "Card : %s\n",
185 emu
->audigy
? "Audigy" : (emu
->APS
? "EMU APS" : "Creative"));
186 snd_iprintf(buffer
, "Internal TRAM (words) : 0x%x\n", emu
->fx8010
.itram_size
);
187 snd_iprintf(buffer
, "External TRAM (words) : 0x%x\n", (int)emu
->fx8010
.etram_pages
.bytes
/ 2);
188 snd_iprintf(buffer
, "\n");
189 snd_iprintf(buffer
, "Effect Send Routing :\n");
190 for (idx
= 0; idx
< NUM_G
; idx
++) {
192 snd_emu10k1_ptr_read(emu
, A_FXRT1
, idx
) :
193 snd_emu10k1_ptr_read(emu
, FXRT
, idx
);
195 snd_emu10k1_ptr_read(emu
, A_FXRT2
, idx
) :
198 snd_iprintf(buffer
, "Ch%i: A=%i, B=%i, C=%i, D=%i, ",
204 snd_iprintf(buffer
, "E=%i, F=%i, G=%i, H=%i\n",
208 (val1
>> 24) & 0x3f);
210 snd_iprintf(buffer
, "Ch%i: A=%i, B=%i, C=%i, D=%i\n",
218 snd_iprintf(buffer
, "\nCaptured FX Outputs :\n");
219 for (idx
= 0; idx
< nefx
; idx
++) {
220 if (emu
->efx_voices_mask
[idx
/32] & (1 << (idx
%32)))
221 snd_iprintf(buffer
, " Output %02i [%s]\n", idx
, outputs
[idx
]);
223 snd_iprintf(buffer
, "\nAll FX Outputs :\n");
224 for (idx
= 0; idx
< (emu
->audigy
? 64 : 32); idx
++)
225 snd_iprintf(buffer
, " Output %02i [%s]\n", idx
, outputs
[idx
]);
226 snd_emu10k1_proc_spdif_status(emu
, buffer
, "S/PDIF Output 0", SPCS0
, -1);
227 snd_emu10k1_proc_spdif_status(emu
, buffer
, "S/PDIF Output 1", SPCS1
, -1);
228 snd_emu10k1_proc_spdif_status(emu
, buffer
, "S/PDIF Output 2/3", SPCS2
, -1);
229 snd_emu10k1_proc_spdif_status(emu
, buffer
, "CD-ROM S/PDIF", CDCS
, CDSRCS
);
230 snd_emu10k1_proc_spdif_status(emu
, buffer
, "General purpose S/PDIF", GPSCS
, GPSRCS
);
231 val
= snd_emu10k1_ptr_read(emu
, ZVSRCS
, 0);
232 snd_iprintf(buffer
, "\nZoomed Video\n");
233 snd_iprintf(buffer
, "Rate Locked : %s\n", val
& SRCS_RATELOCKED
? "on" : "off");
234 snd_iprintf(buffer
, "Estimated Sample Rate : 0x%x\n", val
& SRCS_ESTSAMPLERATE
);
237 static void snd_emu10k1_proc_acode_read(snd_info_entry_t
*entry
,
238 snd_info_buffer_t
* buffer
)
241 emu10k1_t
*emu
= entry
->private_data
;
243 snd_iprintf(buffer
, "FX8010 Instruction List '%s'\n", emu
->fx8010
.name
);
244 snd_iprintf(buffer
, " Code dump :\n");
245 for (pc
= 0; pc
< (emu
->audigy
? 1024 : 512); pc
++) {
248 low
= snd_emu10k1_efx_read(emu
, pc
* 2);
249 high
= snd_emu10k1_efx_read(emu
, pc
* 2 + 1);
251 snd_iprintf(buffer
, " OP(0x%02x, 0x%03x, 0x%03x, 0x%03x, 0x%03x) /* 0x%04x: 0x%08x%08x */\n",
253 (high
>> 12) & 0x7ff,
260 snd_iprintf(buffer
, " OP(0x%02x, 0x%03x, 0x%03x, 0x%03x, 0x%03x) /* 0x%04x: 0x%08x%08x */\n",
262 (high
>> 10) & 0x3ff,
271 #define TOTAL_SIZE_GPR (0x100*4)
272 #define A_TOTAL_SIZE_GPR (0x200*4)
273 #define TOTAL_SIZE_TANKMEM_DATA (0xa0*4)
274 #define TOTAL_SIZE_TANKMEM_ADDR (0xa0*4)
275 #define A_TOTAL_SIZE_TANKMEM_DATA (0x100*4)
276 #define A_TOTAL_SIZE_TANKMEM_ADDR (0x100*4)
277 #define TOTAL_SIZE_CODE (0x200*8)
278 #define A_TOTAL_SIZE_CODE (0x400*8)
280 static long snd_emu10k1_fx8010_read(snd_info_entry_t
*entry
, void *file_private_data
,
281 struct file
*file
, char __user
*buf
,
282 unsigned long count
, unsigned long pos
)
285 emu10k1_t
*emu
= entry
->private_data
;
289 if (!strcmp(entry
->name
, "fx8010_tram_addr")) {
290 offset
= TANKMEMADDRREGBASE
;
292 } else if (!strcmp(entry
->name
, "fx8010_tram_data")) {
293 offset
= TANKMEMDATAREGBASE
;
294 } else if (!strcmp(entry
->name
, "fx8010_code")) {
295 offset
= emu
->audigy
? A_MICROCODEBASE
: MICROCODEBASE
;
297 offset
= emu
->audigy
? A_FXGPREGBASE
: FXGPREGBASE
;
300 if (pos
+ size
> entry
->size
)
301 size
= (long)entry
->size
- pos
;
306 if ((tmp
= kmalloc(size
+ 8, GFP_KERNEL
)) == NULL
)
308 for (idx
= 0; idx
< ((pos
& 3) + size
+ 3) >> 2; idx
++)
309 if (tram_addr
&& emu
->audigy
) {
310 tmp
[idx
] = snd_emu10k1_ptr_read(emu
, offset
+ idx
+ (pos
>> 2), 0) >> 11;
311 tmp
[idx
] |= snd_emu10k1_ptr_read(emu
, 0x100 + idx
+ (pos
>> 2), 0) << 20;
313 tmp
[idx
] = snd_emu10k1_ptr_read(emu
, offset
+ idx
+ (pos
>> 2), 0);
314 if (copy_to_user(buf
, ((char *)tmp
) + (pos
& 3), size
))
325 static void snd_emu10k1_proc_voices_read(snd_info_entry_t
*entry
,
326 snd_info_buffer_t
* buffer
)
328 emu10k1_t
*emu
= entry
->private_data
;
329 emu10k1_voice_t
*voice
;
332 snd_iprintf(buffer
, "ch\tuse\tpcm\tefx\tsynth\tmidi\n");
333 for (idx
= 0; idx
< NUM_G
; idx
++) {
334 voice
= &emu
->voices
[idx
];
335 snd_iprintf(buffer
, "%i\t%i\t%i\t%i\t%i\t%i\n",
345 #ifdef CONFIG_SND_DEBUG
346 static void snd_emu_proc_io_reg_read(snd_info_entry_t
*entry
,
347 snd_info_buffer_t
* buffer
)
349 emu10k1_t
*emu
= entry
->private_data
;
353 snd_iprintf(buffer
, "IO Registers:\n\n");
354 for(i
= 0; i
< 0x40; i
+=4) {
355 spin_lock_irqsave(&emu
->emu_lock
, flags
);
356 value
= inl(emu
->port
+ i
);
357 spin_unlock_irqrestore(&emu
->emu_lock
, flags
);
358 snd_iprintf(buffer
, "%02X: %08lX\n", i
, value
);
362 static void snd_emu_proc_io_reg_write(snd_info_entry_t
*entry
,
363 snd_info_buffer_t
* buffer
)
365 emu10k1_t
*emu
= entry
->private_data
;
369 while (!snd_info_get_line(buffer
, line
, sizeof(line
))) {
370 if (sscanf(line
, "%x %x", ®
, &val
) != 2)
372 if ((reg
< 0x40) && (reg
>=0) && (val
<= 0xffffffff) ) {
373 spin_lock_irqsave(&emu
->emu_lock
, flags
);
374 outl(val
, emu
->port
+ (reg
& 0xfffffffc));
375 spin_unlock_irqrestore(&emu
->emu_lock
, flags
);
380 static unsigned int snd_ptr_read(emu10k1_t
* emu
,
386 unsigned int regptr
, val
;
388 regptr
= (reg
<< 16) | chn
;
390 spin_lock_irqsave(&emu
->emu_lock
, flags
);
391 outl(regptr
, emu
->port
+ iobase
+ PTR
);
392 val
= inl(emu
->port
+ iobase
+ DATA
);
393 spin_unlock_irqrestore(&emu
->emu_lock
, flags
);
397 static void snd_ptr_write(emu10k1_t
*emu
,
406 regptr
= (reg
<< 16) | chn
;
408 spin_lock_irqsave(&emu
->emu_lock
, flags
);
409 outl(regptr
, emu
->port
+ iobase
+ PTR
);
410 outl(data
, emu
->port
+ iobase
+ DATA
);
411 spin_unlock_irqrestore(&emu
->emu_lock
, flags
);
415 static void snd_emu_proc_ptr_reg_read(snd_info_entry_t
*entry
,
416 snd_info_buffer_t
* buffer
, int iobase
, int offset
, int length
, int voices
)
418 emu10k1_t
*emu
= entry
->private_data
;
421 if (offset
+length
> 0x80) {
422 snd_iprintf(buffer
, "Input values out of range\n");
425 snd_iprintf(buffer
, "Registers 0x%x\n", iobase
);
426 for(i
= offset
; i
< offset
+length
; i
++) {
427 snd_iprintf(buffer
, "%02X: ",i
);
428 for (j
= 0; j
< voices
; j
++) {
430 value
= snd_ptr_read(emu
, 0, i
, j
);
432 value
= snd_ptr_read(emu
, 0x20, i
, j
);
433 snd_iprintf(buffer
, "%08lX ", value
);
435 snd_iprintf(buffer
, "\n");
439 static void snd_emu_proc_ptr_reg_write(snd_info_entry_t
*entry
,
440 snd_info_buffer_t
* buffer
, int iobase
)
442 emu10k1_t
*emu
= entry
->private_data
;
444 unsigned int reg
, channel_id
, val
;
445 while (!snd_info_get_line(buffer
, line
, sizeof(line
))) {
446 if (sscanf(line
, "%x %x %x", ®
, &channel_id
, &val
) != 3)
448 if ((reg
< 0x80) && (reg
>=0) && (val
<= 0xffffffff) && (channel_id
>=0) && (channel_id
<= 3) )
449 snd_ptr_write(emu
, iobase
, reg
, channel_id
, val
);
453 static void snd_emu_proc_ptr_reg_write00(snd_info_entry_t
*entry
,
454 snd_info_buffer_t
* buffer
)
456 snd_emu_proc_ptr_reg_write(entry
, buffer
, 0);
459 static void snd_emu_proc_ptr_reg_write20(snd_info_entry_t
*entry
,
460 snd_info_buffer_t
* buffer
)
462 snd_emu_proc_ptr_reg_write(entry
, buffer
, 0x20);
466 static void snd_emu_proc_ptr_reg_read00a(snd_info_entry_t
*entry
,
467 snd_info_buffer_t
* buffer
)
469 snd_emu_proc_ptr_reg_read(entry
, buffer
, 0, 0, 0x40, 64);
472 static void snd_emu_proc_ptr_reg_read00b(snd_info_entry_t
*entry
,
473 snd_info_buffer_t
* buffer
)
475 snd_emu_proc_ptr_reg_read(entry
, buffer
, 0, 0x40, 0x40, 64);
478 static void snd_emu_proc_ptr_reg_read20a(snd_info_entry_t
*entry
,
479 snd_info_buffer_t
* buffer
)
481 snd_emu_proc_ptr_reg_read(entry
, buffer
, 0x20, 0, 0x40, 4);
484 static void snd_emu_proc_ptr_reg_read20b(snd_info_entry_t
*entry
,
485 snd_info_buffer_t
* buffer
)
487 snd_emu_proc_ptr_reg_read(entry
, buffer
, 0x20, 0x40, 0x40, 4);
491 static struct snd_info_entry_ops snd_emu10k1_proc_ops_fx8010
= {
492 .read
= snd_emu10k1_fx8010_read
,
495 int __devinit
snd_emu10k1_proc_init(emu10k1_t
* emu
)
497 snd_info_entry_t
*entry
;
498 #ifdef CONFIG_SND_DEBUG
499 if (! snd_card_proc_new(emu
->card
, "io_regs", &entry
)) {
500 snd_info_set_text_ops(entry
, emu
, 1024, snd_emu_proc_io_reg_read
);
501 entry
->c
.text
.write_size
= 64;
502 entry
->c
.text
.write
= snd_emu_proc_io_reg_write
;
504 if (! snd_card_proc_new(emu
->card
, "ptr_regs00a", &entry
)) {
505 snd_info_set_text_ops(entry
, emu
, 65536, snd_emu_proc_ptr_reg_read00a
);
506 entry
->c
.text
.write_size
= 64;
507 entry
->c
.text
.write
= snd_emu_proc_ptr_reg_write00
;
509 if (! snd_card_proc_new(emu
->card
, "ptr_regs00b", &entry
)) {
510 snd_info_set_text_ops(entry
, emu
, 65536, snd_emu_proc_ptr_reg_read00b
);
511 entry
->c
.text
.write_size
= 64;
512 entry
->c
.text
.write
= snd_emu_proc_ptr_reg_write00
;
514 if (! snd_card_proc_new(emu
->card
, "ptr_regs20a", &entry
)) {
515 snd_info_set_text_ops(entry
, emu
, 65536, snd_emu_proc_ptr_reg_read20a
);
516 entry
->c
.text
.write_size
= 64;
517 entry
->c
.text
.write
= snd_emu_proc_ptr_reg_write20
;
519 if (! snd_card_proc_new(emu
->card
, "ptr_regs20b", &entry
)) {
520 snd_info_set_text_ops(entry
, emu
, 65536, snd_emu_proc_ptr_reg_read20b
);
521 entry
->c
.text
.write_size
= 64;
522 entry
->c
.text
.write
= snd_emu_proc_ptr_reg_write20
;
526 if (! snd_card_proc_new(emu
->card
, "emu10k1", &entry
))
527 snd_info_set_text_ops(entry
, emu
, 2048, snd_emu10k1_proc_read
);
529 if (! snd_card_proc_new(emu
->card
, "voices", &entry
))
530 snd_info_set_text_ops(entry
, emu
, 2048, snd_emu10k1_proc_voices_read
);
532 if (! snd_card_proc_new(emu
->card
, "fx8010_gpr", &entry
)) {
533 entry
->content
= SNDRV_INFO_CONTENT_DATA
;
534 entry
->private_data
= emu
;
535 entry
->mode
= S_IFREG
| S_IRUGO
/*| S_IWUSR*/;
536 entry
->size
= emu
->audigy
? A_TOTAL_SIZE_GPR
: TOTAL_SIZE_GPR
;
537 entry
->c
.ops
= &snd_emu10k1_proc_ops_fx8010
;
539 if (! snd_card_proc_new(emu
->card
, "fx8010_tram_data", &entry
)) {
540 entry
->content
= SNDRV_INFO_CONTENT_DATA
;
541 entry
->private_data
= emu
;
542 entry
->mode
= S_IFREG
| S_IRUGO
/*| S_IWUSR*/;
543 entry
->size
= emu
->audigy
? A_TOTAL_SIZE_TANKMEM_DATA
: TOTAL_SIZE_TANKMEM_DATA
;
544 entry
->c
.ops
= &snd_emu10k1_proc_ops_fx8010
;
546 if (! snd_card_proc_new(emu
->card
, "fx8010_tram_addr", &entry
)) {
547 entry
->content
= SNDRV_INFO_CONTENT_DATA
;
548 entry
->private_data
= emu
;
549 entry
->mode
= S_IFREG
| S_IRUGO
/*| S_IWUSR*/;
550 entry
->size
= emu
->audigy
? A_TOTAL_SIZE_TANKMEM_ADDR
: TOTAL_SIZE_TANKMEM_ADDR
;
551 entry
->c
.ops
= &snd_emu10k1_proc_ops_fx8010
;
553 if (! snd_card_proc_new(emu
->card
, "fx8010_code", &entry
)) {
554 entry
->content
= SNDRV_INFO_CONTENT_DATA
;
555 entry
->private_data
= emu
;
556 entry
->mode
= S_IFREG
| S_IRUGO
/*| S_IWUSR*/;
557 entry
->size
= emu
->audigy
? A_TOTAL_SIZE_CODE
: TOTAL_SIZE_CODE
;
558 entry
->c
.ops
= &snd_emu10k1_proc_ops_fx8010
;
560 if (! snd_card_proc_new(emu
->card
, "fx8010_acode", &entry
)) {
561 entry
->content
= SNDRV_INFO_CONTENT_TEXT
;
562 entry
->private_data
= emu
;
563 entry
->mode
= S_IFREG
| S_IRUGO
/*| S_IWUSR*/;
564 entry
->c
.text
.read_size
= 128*1024;
565 entry
->c
.text
.read
= snd_emu10k1_proc_acode_read
;