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 static char *outputs[32] = {
77 /* 02 */ "PCM Surround Left",
78 /* 03 */ "PCM Surround Right",
80 /* 05 */ "MIDI Right",
81 /* 06 */ "PCM Center",
87 /* 12 */ "MIDI Reverb",
88 /* 13 */ "MIDI Chorus",
93 /* 18 */ "ADC Left / CDROM S/PDIF Left",
94 /* 19 */ "ADC Right / CDROM S/PDIF Right",
95 /* 20 */ "MIC / Zoom Video Left",
96 /* 21 */ "Zoom Video Right",
97 /* 22 */ "S/PDIF Left",
98 /* 23 */ "S/PDIF Right",
108 emu10k1_t *emu = snd_magic_cast(emu10k1_t, entry->private_data, return);
110 int nefx = emu->audigy ? 64 : 32;
113 snd_iprintf(buffer, "EMU10K1\n\n");
115 snd_emu10k1_ptr_read(emu, A_FXRT1, 0) :
116 snd_emu10k1_ptr_read(emu, FXRT, 0);
117 snd_iprintf(buffer, "Card : %s\n",
118 emu->audigy ? "Audigy" : (emu->APS ? "EMU APS" : "Creative"));
119 snd_iprintf(buffer, "Internal TRAM (words) : 0x%x\n", emu->fx8010.itram_size);
120 snd_iprintf(buffer, "External TRAM (words) : 0x%x\n", emu->fx8010.etram_pages.bytes);
121 snd_iprintf(buffer, "\n");
123 snd_iprintf(buffer, "Effect Send Routing : A=%i, B=%i, C=%i, D=%i\n",
129 snd_iprintf(buffer, "Effect Send Routing : A=%i, B=%i, C=%i, D=%i\n",
135 snd_iprintf(buffer, "\nCaptured FX Outputs :\n");
136 for (idx = 0; idx < nefx; idx++) {
137 if (emu->efx_voices_mask[idx/32] & (1 << (idx%32)))
138 snd_iprintf(buffer, " Output %02i [%s]\n", idx, outputs[idx%32]);
140 snd_iprintf(buffer, "\nAll FX Outputs :\n");
141 for (idx = 0; idx < 32; idx++)
142 snd_iprintf(buffer, " Output %02i [%s]\n", idx, outputs[idx]);
143 snd_emu10k1_proc_spdif_status(emu, buffer, "S/PDIF Output 0", SPCS0, -1);
144 snd_emu10k1_proc_spdif_status(emu, buffer, "S/PDIF Output 1", SPCS1, -1);
145 snd_emu10k1_proc_spdif_status(emu, buffer, "S/PDIF Output 2/3", SPCS2, -1);
146 snd_emu10k1_proc_spdif_status(emu, buffer, "CD-ROM S/PDIF", CDCS, CDSRCS);
147 snd_emu10k1_proc_spdif_status(emu, buffer, "General purpose S/PDIF", GPSCS, GPSRCS);
148 val = snd_emu10k1_ptr_read(emu, ZVSRCS, 0);
149 snd_iprintf(buffer, "\nZoomed Video\n");
150 snd_iprintf(buffer, "Rate Locked : %s\n", val & SRCS_RATELOCKED ? "on" : "off");
151 snd_iprintf(buffer, "Estimated Sample Rate : 0x%x\n", val & SRCS_ESTSAMPLERATE);
154 static void snd_emu10k1_proc_acode_read(snd_info_entry_t *entry,
155 snd_info_buffer_t * buffer)
158 emu10k1_t *emu = snd_magic_cast(emu10k1_t, entry->private_data, return);
160 snd_iprintf(buffer, "FX8010 Instruction List '%s'\n", emu->fx8010.name);
161 snd_iprintf(buffer, " Code dump :\n");
162 for (pc = 0; pc < 512; pc++) {
165 low = snd_emu10k1_efx_read(emu, pc * 2);
166 high = snd_emu10k1_efx_read(emu, pc * 2 + 1);
168 snd_iprintf(buffer, " OP(0x%02x, 0x%03x, 0x%03x, 0x%03x, 0x%03x) /* 0x%04x: 0x%08x%08x */\n",
170 (high >> 12) & 0x7ff,
177 snd_iprintf(buffer, " OP(0x%02x, 0x%03x, 0x%03x, 0x%03x, 0x%03x) /* 0x%04x: 0x%08x%08x */\n",
179 (high >> 10) & 0x3ff,
188 #define TOTAL_SIZE_GPR (0x100*4)
189 #define TOTAL_SIZE_TANKMEM_DATA (0xa0*4)
190 #define TOTAL_SIZE_TANKMEM_ADDR (0xa0*4)
191 #define TOTAL_SIZE_CODE (0x200*8)
193 static long snd_emu10k1_fx8010_read(snd_info_entry_t *entry, void *file_private_data,
194 struct file *file, char __user *buf,
195 unsigned long count, unsigned long pos)
198 emu10k1_t *emu = snd_magic_cast(emu10k1_t, entry->private_data, return -ENXIO);
201 if (!strcmp(entry->name, "fx8010_tram_addr")) {
202 if (emu->audigy) return -EINVAL;
203 offset = TANKMEMADDRREGBASE;
204 } else if (!strcmp(entry->name, "fx8010_tram_data")) {
205 if (emu->audigy) return -EINVAL;
206 offset = TANKMEMDATAREGBASE;
207 } else if (!strcmp(entry->name, "fx8010_code")) {
208 offset = emu->audigy ? A_MICROCODEBASE : MICROCODEBASE;
210 offset = emu->audigy ? A_FXGPREGBASE : FXGPREGBASE;
213 if (pos + size > entry->size)
214 size = (long)entry->size - pos;
219 if ((tmp = kmalloc(size + 8, GFP_KERNEL)) == NULL)
221 for (idx = 0; idx < ((pos & 3) + size + 3) >> 2; idx++)
222 tmp[idx] = snd_emu10k1_ptr_read(emu, offset + idx + (pos >> 2), 0);
223 if (copy_to_user(buf, ((char *)tmp) + (pos & 3), size))
234 static struct snd_info_entry_ops snd_emu10k1_proc_ops_fx8010 = {
235 .read = snd_emu10k1_fx8010_read,
238 int __devinit snd_emu10k1_proc_init(emu10k1_t * emu)
240 snd_info_entry_t *entry;
242 if (! snd_card_proc_new(emu->card, "emu10k1", &entry))
243 snd_info_set_text_ops(entry, emu, 1024, snd_emu10k1_proc_read);
245 if (! snd_card_proc_new(emu->card, "fx8010_gpr", &entry)) {
246 entry->content = SNDRV_INFO_CONTENT_DATA;
247 entry->private_data = emu;
248 entry->mode = S_IFREG | S_IRUGO /*| S_IWUSR*/;
249 entry->size = TOTAL_SIZE_GPR;
250 entry->c.ops = &snd_emu10k1_proc_ops_fx8010;
252 if (!emu->audigy && ! snd_card_proc_new(emu->card, "fx8010_tram_data", &entry)) {
253 entry->content = SNDRV_INFO_CONTENT_DATA;
254 entry->private_data = emu;
255 entry->mode = S_IFREG | S_IRUGO /*| S_IWUSR*/;
256 entry->size = TOTAL_SIZE_TANKMEM_DATA;
257 entry->c.ops = &snd_emu10k1_proc_ops_fx8010;
259 if (!emu->audigy && ! snd_card_proc_new(emu->card, "fx8010_tram_addr", &entry)) {
260 entry->content = SNDRV_INFO_CONTENT_DATA;
261 entry->private_data = emu;
262 entry->mode = S_IFREG | S_IRUGO /*| S_IWUSR*/;
263 entry->size = TOTAL_SIZE_TANKMEM_ADDR;
264 entry->c.ops = &snd_emu10k1_proc_ops_fx8010;
266 if (! snd_card_proc_new(emu->card, "fx8010_code", &entry)) {
267 entry->content = SNDRV_INFO_CONTENT_DATA;
268 entry->private_data = emu;
269 entry->mode = S_IFREG | S_IRUGO /*| S_IWUSR*/;
270 entry->size = TOTAL_SIZE_CODE;
271 entry->c.ops = &snd_emu10k1_proc_ops_fx8010;
273 if (! snd_card_proc_new(emu->card, "fx8010_acode", &entry)) {
274 entry->content = SNDRV_INFO_CONTENT_TEXT;
275 entry->private_data = emu;
276 entry->mode = S_IFREG | S_IRUGO /*| S_IWUSR*/;
277 entry->c.text.read_size = 64*1024;
278 entry->c.text.read = snd_emu10k1_proc_acode_read;