1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
4 * Lee Revell <rlrevell@joe-job.com>
5 * James Courtier-Dutton <James@superbug.co.uk>
6 * Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
7 * Creative Labs, Inc.
8 *
9 * Routines for control of EMU10K1 chips / proc interface routines
10 */
11
12 #include <linux/slab.h>
13 #include <linux/init.h>
14 #include <sound/core.h>
15 #include <sound/emu10k1.h>
16 #include "p16v.h"
17
snd_emu10k1_proc_spdif_status(struct snd_emu10k1 * emu,struct snd_info_buffer * buffer,char * title,int status_reg,int rate_reg)18 static void snd_emu10k1_proc_spdif_status(struct snd_emu10k1 * emu,
19 struct snd_info_buffer *buffer,
20 char *title,
21 int status_reg,
22 int rate_reg)
23 {
24 static const char * const clkaccy[4] = { "1000ppm", "50ppm", "variable", "unknown" };
25 static const int samplerate[16] = { 44100, 1, 48000, 32000, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
26 static const char * const channel[16] = { "unspec", "left", "right", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15" };
27 static const char * const emphasis[8] = { "none", "50/15 usec 2 channel", "2", "3", "4", "5", "6", "7" };
28 unsigned int status, rate = 0;
29
30 status = snd_emu10k1_ptr_read(emu, status_reg, 0);
31
32 snd_iprintf(buffer, "\n%s\n", title);
33
34 if (status != 0xffffffff) {
35 snd_iprintf(buffer, "Professional Mode : %s\n", (status & SPCS_PROFESSIONAL) ? "yes" : "no");
36 snd_iprintf(buffer, "Not Audio Data : %s\n", (status & SPCS_NOTAUDIODATA) ? "yes" : "no");
37 snd_iprintf(buffer, "Copyright : %s\n", (status & SPCS_COPYRIGHT) ? "yes" : "no");
38 snd_iprintf(buffer, "Emphasis : %s\n", emphasis[(status & SPCS_EMPHASISMASK) >> 3]);
39 snd_iprintf(buffer, "Mode : %i\n", (status & SPCS_MODEMASK) >> 6);
40 snd_iprintf(buffer, "Category Code : 0x%x\n", (status & SPCS_CATEGORYCODEMASK) >> 8);
41 snd_iprintf(buffer, "Generation Status : %s\n", status & SPCS_GENERATIONSTATUS ? "original" : "copy");
42 snd_iprintf(buffer, "Source Mask : %i\n", (status & SPCS_SOURCENUMMASK) >> 16);
43 snd_iprintf(buffer, "Channel Number : %s\n", channel[(status & SPCS_CHANNELNUMMASK) >> 20]);
44 snd_iprintf(buffer, "Sample Rate : %iHz\n", samplerate[(status & SPCS_SAMPLERATEMASK) >> 24]);
45 snd_iprintf(buffer, "Clock Accuracy : %s\n", clkaccy[(status & SPCS_CLKACCYMASK) >> 28]);
46
47 if (rate_reg > 0) {
48 rate = snd_emu10k1_ptr_read(emu, rate_reg, 0);
49 snd_iprintf(buffer, "S/PDIF Valid : %s\n", rate & SRCS_SPDIFVALID ? "on" : "off");
50 snd_iprintf(buffer, "S/PDIF Locked : %s\n", rate & SRCS_SPDIFLOCKED ? "on" : "off");
51 snd_iprintf(buffer, "Rate Locked : %s\n", rate & SRCS_RATELOCKED ? "on" : "off");
52 /* From ((Rate * 48000 ) / 262144); */
53 snd_iprintf(buffer, "Estimated Sample Rate : %d\n", ((rate & 0xFFFFF ) * 375) >> 11);
54 }
55 } else {
56 snd_iprintf(buffer, "No signal detected.\n");
57 }
58
59 }
60
snd_emu10k1_proc_read(struct snd_info_entry * entry,struct snd_info_buffer * buffer)61 static void snd_emu10k1_proc_read(struct snd_info_entry *entry,
62 struct snd_info_buffer *buffer)
63 {
64 struct snd_emu10k1 *emu = entry->private_data;
65 const char * const *inputs = emu->audigy ?
66 snd_emu10k1_audigy_ins : snd_emu10k1_sblive_ins;
67 const char * const *outputs = emu->audigy ?
68 snd_emu10k1_audigy_outs : snd_emu10k1_sblive_outs;
69 unsigned short extin_mask = emu->audigy ? ~0 : emu->fx8010.extin_mask;
70 unsigned short extout_mask = emu->audigy ? ~0 : emu->fx8010.extout_mask;
71 unsigned int val, val1, ptrx, psst, dsl, snda;
72 int nefx = emu->audigy ? 32 : 16;
73 int idx;
74
75 snd_iprintf(buffer, "EMU10K1\n\n");
76 snd_iprintf(buffer, "Card : %s\n",
77 emu->card_capabilities->emu_model ? "E-MU D.A.S." :
78 emu->card_capabilities->ecard ? "E-MU A.P.S." :
79 emu->audigy ? "SB Audigy" : "SB Live!");
80 snd_iprintf(buffer, "Internal TRAM (words) : 0x%x\n", emu->fx8010.itram_size);
81 snd_iprintf(buffer, "External TRAM (words) : 0x%x\n", (int)emu->fx8010.etram_pages.bytes / 2);
82
83 snd_iprintf(buffer, "\nEffect Send Routing & Amounts:\n");
84 for (idx = 0; idx < NUM_G; idx++) {
85 ptrx = snd_emu10k1_ptr_read(emu, PTRX, idx);
86 psst = snd_emu10k1_ptr_read(emu, PSST, idx);
87 dsl = snd_emu10k1_ptr_read(emu, DSL, idx);
88 if (emu->audigy) {
89 val = snd_emu10k1_ptr_read(emu, A_FXRT1, idx);
90 val1 = snd_emu10k1_ptr_read(emu, A_FXRT2, idx);
91 snda = snd_emu10k1_ptr_read(emu, A_SENDAMOUNTS, idx);
92 snd_iprintf(buffer, "Ch%-2i: A=%2i:%02x, B=%2i:%02x, C=%2i:%02x, D=%2i:%02x, ",
93 idx,
94 val & 0x3f, REG_VAL_GET(PTRX_FXSENDAMOUNT_A, ptrx),
95 (val >> 8) & 0x3f, REG_VAL_GET(PTRX_FXSENDAMOUNT_B, ptrx),
96 (val >> 16) & 0x3f, REG_VAL_GET(PSST_FXSENDAMOUNT_C, psst),
97 (val >> 24) & 0x3f, REG_VAL_GET(DSL_FXSENDAMOUNT_D, dsl));
98 snd_iprintf(buffer, "E=%2i:%02x, F=%2i:%02x, G=%2i:%02x, H=%2i:%02x\n",
99 val1 & 0x3f, (snda >> 24) & 0xff,
100 (val1 >> 8) & 0x3f, (snda >> 16) & 0xff,
101 (val1 >> 16) & 0x3f, (snda >> 8) & 0xff,
102 (val1 >> 24) & 0x3f, snda & 0xff);
103 } else {
104 val = snd_emu10k1_ptr_read(emu, FXRT, idx);
105 snd_iprintf(buffer, "Ch%-2i: A=%2i:%02x, B=%2i:%02x, C=%2i:%02x, D=%2i:%02x\n",
106 idx,
107 (val >> 16) & 0x0f, REG_VAL_GET(PTRX_FXSENDAMOUNT_A, ptrx),
108 (val >> 20) & 0x0f, REG_VAL_GET(PTRX_FXSENDAMOUNT_B, ptrx),
109 (val >> 24) & 0x0f, REG_VAL_GET(PSST_FXSENDAMOUNT_C, psst),
110 (val >> 28) & 0x0f, REG_VAL_GET(DSL_FXSENDAMOUNT_D, dsl));
111 }
112 }
113 snd_iprintf(buffer, "\nEffect Send Targets:\n");
114 // Audigy actually has 64, but we don't use them all.
115 for (idx = 0; idx < 32; idx++) {
116 const char *c = snd_emu10k1_fxbus[idx];
117 if (c)
118 snd_iprintf(buffer, " Channel %02i [%s]\n", idx, c);
119 }
120 if (!emu->card_capabilities->emu_model) {
121 snd_iprintf(buffer, "\nOutput Channels:\n");
122 for (idx = 0; idx < 32; idx++)
123 if (outputs[idx] && (extout_mask & (1 << idx)))
124 snd_iprintf(buffer, " Channel %02i [%s]\n", idx, outputs[idx]);
125 snd_iprintf(buffer, "\nInput Channels:\n");
126 for (idx = 0; idx < 16; idx++)
127 if (inputs[idx] && (extin_mask & (1 << idx)))
128 snd_iprintf(buffer, " Channel %02i [%s]\n", idx, inputs[idx]);
129 snd_iprintf(buffer, "\nMultichannel Capture Sources:\n");
130 for (idx = 0; idx < nefx; idx++)
131 if (emu->efx_voices_mask[0] & (1 << idx))
132 snd_iprintf(buffer, " Channel %02i [Output: %s]\n",
133 idx, outputs[idx] ? outputs[idx] : "???");
134 if (emu->audigy) {
135 for (idx = 0; idx < 32; idx++)
136 if (emu->efx_voices_mask[1] & (1 << idx))
137 snd_iprintf(buffer, " Channel %02i [Input: %s]\n",
138 idx + 32, inputs[idx] ? inputs[idx] : "???");
139 } else {
140 for (idx = 0; idx < 16; idx++) {
141 if (emu->efx_voices_mask[0] & ((1 << 16) << idx)) {
142 if (emu->card_capabilities->sblive51) {
143 s8 c = snd_emu10k1_sblive51_fxbus2_map[idx];
144 if (c == -1)
145 snd_iprintf(buffer, " Channel %02i [Output: %s]\n",
146 idx + 16, outputs[idx + 16]);
147 else
148 snd_iprintf(buffer, " Channel %02i [Input: %s]\n",
149 idx + 16, inputs[c]);
150 } else {
151 snd_iprintf(buffer, " Channel %02i [Input: %s]\n",
152 idx + 16, inputs[idx] ? inputs[idx] : "???");
153 }
154 }
155 }
156 }
157 }
158 }
159
snd_emu10k1_proc_spdif_read(struct snd_info_entry * entry,struct snd_info_buffer * buffer)160 static void snd_emu10k1_proc_spdif_read(struct snd_info_entry *entry,
161 struct snd_info_buffer *buffer)
162 {
163 struct snd_emu10k1 *emu = entry->private_data;
164 u32 value;
165 u32 value2;
166
167 if (emu->card_capabilities->emu_model) {
168 // This represents the S/PDIF lock status on 0404b, which is
169 // kinda weird and unhelpful, because monitoring it via IRQ is
170 // impractical (one gets an IRQ flood as long as it is desynced).
171 snd_emu1010_fpga_read(emu, EMU_HANA_IRQ_STATUS, &value);
172 snd_iprintf(buffer, "Lock status 1: %#x\n", value & 0x10);
173
174 // Bit 0x1 in LO being 0 is supposedly for ADAT lock.
175 // The registers are always all zero on 0404b.
176 snd_emu1010_fpga_read(emu, EMU_HANA_LOCK_STS_LO, &value);
177 snd_emu1010_fpga_read(emu, EMU_HANA_LOCK_STS_HI, &value2);
178 snd_iprintf(buffer, "Lock status 2: %#x %#x\n", value, value2);
179
180 snd_iprintf(buffer, "S/PDIF rate: %dHz\n",
181 snd_emu1010_get_raw_rate(emu, EMU_HANA_WCLOCK_HANA_SPDIF_IN));
182 if (emu->card_capabilities->emu_model != EMU_MODEL_EMU0404) {
183 snd_iprintf(buffer, "ADAT rate: %dHz\n",
184 snd_emu1010_get_raw_rate(emu, EMU_HANA_WCLOCK_HANA_ADAT_IN));
185 snd_iprintf(buffer, "Dock rate: %dHz\n",
186 snd_emu1010_get_raw_rate(emu, EMU_HANA_WCLOCK_2ND_HANA));
187 }
188 if (emu->card_capabilities->emu_model == EMU_MODEL_EMU0404 ||
189 emu->card_capabilities->emu_model == EMU_MODEL_EMU1010)
190 snd_iprintf(buffer, "BNC rate: %dHz\n",
191 snd_emu1010_get_raw_rate(emu, EMU_HANA_WCLOCK_SYNC_BNC));
192
193 snd_emu1010_fpga_read(emu, EMU_HANA_SPDIF_MODE, &value);
194 if (value & EMU_HANA_SPDIF_MODE_RX_INVALID)
195 snd_iprintf(buffer, "\nS/PDIF input invalid\n");
196 else
197 snd_iprintf(buffer, "\nS/PDIF mode: %s%s\n",
198 value & EMU_HANA_SPDIF_MODE_RX_PRO ? "professional" : "consumer",
199 value & EMU_HANA_SPDIF_MODE_RX_NOCOPY ? ", no copy" : "");
200 } else {
201 snd_emu10k1_proc_spdif_status(emu, buffer, "CD-ROM S/PDIF In", CDCS, CDSRCS);
202 snd_emu10k1_proc_spdif_status(emu, buffer, "Optical or Coax S/PDIF In", GPSCS, GPSRCS);
203 }
204 #if 0
205 val = snd_emu10k1_ptr_read(emu, ZVSRCS, 0);
206 snd_iprintf(buffer, "\nZoomed Video\n");
207 snd_iprintf(buffer, "Rate Locked : %s\n", val & SRCS_RATELOCKED ? "on" : "off");
208 snd_iprintf(buffer, "Estimated Sample Rate : 0x%x\n", val & SRCS_ESTSAMPLERATE);
209 #endif
210 }
211
snd_emu10k1_proc_rates_read(struct snd_info_entry * entry,struct snd_info_buffer * buffer)212 static void snd_emu10k1_proc_rates_read(struct snd_info_entry *entry,
213 struct snd_info_buffer *buffer)
214 {
215 static const int samplerate[8] = { 44100, 48000, 96000, 192000, 4, 5, 6, 7 };
216 struct snd_emu10k1 *emu = entry->private_data;
217 unsigned int val, tmp, n;
218 val = snd_emu10k1_ptr20_read(emu, CAPTURE_RATE_STATUS, 0);
219 for (n = 0; n < 4; n++) {
220 tmp = val >> (16 + (n*4));
221 if (tmp & 0x8) snd_iprintf(buffer, "Channel %d: Rate=%d\n", n, samplerate[tmp & 0x7]);
222 else snd_iprintf(buffer, "Channel %d: No input\n", n);
223 }
224 }
225
226 struct emu10k1_reg_entry {
227 unsigned short base, size;
228 const char *name;
229 };
230
231 static const struct emu10k1_reg_entry sblive_reg_entries[] = {
232 { 0, 0x10, "FXBUS" },
233 { 0x10, 0x10, "EXTIN" },
234 { 0x20, 0x10, "EXTOUT" },
235 { 0x30, 0x10, "FXBUS2" },
236 { 0x40, 0x20, NULL }, // Constants
237 { 0x100, 0x100, "GPR" },
238 { 0x200, 0x80, "ITRAM_DATA" },
239 { 0x280, 0x20, "ETRAM_DATA" },
240 { 0x300, 0x80, "ITRAM_ADDR" },
241 { 0x380, 0x20, "ETRAM_ADDR" },
242 { 0x400, 0, NULL }
243 };
244
245 static const struct emu10k1_reg_entry audigy_reg_entries[] = {
246 { 0, 0x40, "FXBUS" },
247 { 0x40, 0x10, "EXTIN" },
248 { 0x50, 0x10, "P16VIN" },
249 { 0x60, 0x20, "EXTOUT" },
250 { 0x80, 0x20, "FXBUS2" },
251 { 0xa0, 0x10, "EMU32OUTH" },
252 { 0xb0, 0x10, "EMU32OUTL" },
253 { 0xc0, 0x20, NULL }, // Constants
254 // This can't be quite right - overlap.
255 //{ 0x100, 0xc0, "ITRAM_CTL" },
256 //{ 0x1c0, 0x40, "ETRAM_CTL" },
257 { 0x160, 0x20, "A3_EMU32IN" },
258 { 0x1e0, 0x20, "A3_EMU32OUT" },
259 { 0x200, 0xc0, "ITRAM_DATA" },
260 { 0x2c0, 0x40, "ETRAM_DATA" },
261 { 0x300, 0xc0, "ITRAM_ADDR" },
262 { 0x3c0, 0x40, "ETRAM_ADDR" },
263 { 0x400, 0x200, "GPR" },
264 { 0x600, 0, NULL }
265 };
266
267 static const char * const emu10k1_const_entries[] = {
268 "C_00000000",
269 "C_00000001",
270 "C_00000002",
271 "C_00000003",
272 "C_00000004",
273 "C_00000008",
274 "C_00000010",
275 "C_00000020",
276 "C_00000100",
277 "C_00010000",
278 "C_00000800",
279 "C_10000000",
280 "C_20000000",
281 "C_40000000",
282 "C_80000000",
283 "C_7fffffff",
284 "C_ffffffff",
285 "C_fffffffe",
286 "C_c0000000",
287 "C_4f1bbcdc",
288 "C_5a7ef9db",
289 "C_00100000",
290 "GPR_ACCU",
291 "GPR_COND",
292 "GPR_NOISE0",
293 "GPR_NOISE1",
294 "GPR_IRQ",
295 "GPR_DBAC",
296 "GPR_DBACE",
297 "???",
298 };
299
disasm_emu10k1_reg(char * buffer,const struct emu10k1_reg_entry * entries,unsigned reg,const char * pfx)300 static int disasm_emu10k1_reg(char *buffer,
301 const struct emu10k1_reg_entry *entries,
302 unsigned reg, const char *pfx)
303 {
304 for (int i = 0; ; i++) {
305 unsigned base = entries[i].base;
306 unsigned size = entries[i].size;
307 if (!size)
308 return sprintf(buffer, "%s0x%03x", pfx, reg);
309 if (reg >= base && reg < base + size) {
310 const char *name = entries[i].name;
311 reg -= base;
312 if (name)
313 return sprintf(buffer, "%s%s(%u)", pfx, name, reg);
314 return sprintf(buffer, "%s%s", pfx, emu10k1_const_entries[reg]);
315 }
316 }
317 }
318
disasm_sblive_reg(char * buffer,unsigned reg,const char * pfx)319 static int disasm_sblive_reg(char *buffer, unsigned reg, const char *pfx)
320 {
321 return disasm_emu10k1_reg(buffer, sblive_reg_entries, reg, pfx);
322 }
323
disasm_audigy_reg(char * buffer,unsigned reg,const char * pfx)324 static int disasm_audigy_reg(char *buffer, unsigned reg, const char *pfx)
325 {
326 return disasm_emu10k1_reg(buffer, audigy_reg_entries, reg, pfx);
327 }
328
snd_emu10k1_proc_acode_read(struct snd_info_entry * entry,struct snd_info_buffer * buffer)329 static void snd_emu10k1_proc_acode_read(struct snd_info_entry *entry,
330 struct snd_info_buffer *buffer)
331 {
332 u32 pc;
333 struct snd_emu10k1 *emu = entry->private_data;
334 static const char * const insns[16] = {
335 "MAC0", "MAC1", "MAC2", "MAC3", "MACINT0", "MACINT1", "ACC3", "MACMV",
336 "ANDXOR", "TSTNEG", "LIMITGE", "LIMITLT", "LOG", "EXP", "INTERP", "SKIP",
337 };
338 static const char spaces[] = " ";
339 const int nspaces = sizeof(spaces) - 1;
340
341 snd_iprintf(buffer, "FX8010 Instruction List '%s'\n", emu->fx8010.name);
342 snd_iprintf(buffer, " Code dump :\n");
343 for (pc = 0; pc < (emu->audigy ? 1024 : 512); pc++) {
344 u32 low, high;
345 int len;
346 char buf[100];
347 char *bufp = buf;
348
349 low = snd_emu10k1_efx_read(emu, pc * 2);
350 high = snd_emu10k1_efx_read(emu, pc * 2 + 1);
351 if (emu->audigy) {
352 bufp += sprintf(bufp, " %-7s ", insns[(high >> 24) & 0x0f]);
353 bufp += disasm_audigy_reg(bufp, (high >> 12) & 0x7ff, "");
354 bufp += disasm_audigy_reg(bufp, (high >> 0) & 0x7ff, ", ");
355 bufp += disasm_audigy_reg(bufp, (low >> 12) & 0x7ff, ", ");
356 bufp += disasm_audigy_reg(bufp, (low >> 0) & 0x7ff, ", ");
357 } else {
358 bufp += sprintf(bufp, " %-7s ", insns[(high >> 20) & 0x0f]);
359 bufp += disasm_sblive_reg(bufp, (high >> 10) & 0x3ff, "");
360 bufp += disasm_sblive_reg(bufp, (high >> 0) & 0x3ff, ", ");
361 bufp += disasm_sblive_reg(bufp, (low >> 10) & 0x3ff, ", ");
362 bufp += disasm_sblive_reg(bufp, (low >> 0) & 0x3ff, ", ");
363 }
364 len = (int)(ptrdiff_t)(bufp - buf);
365 snd_iprintf(buffer, "%s %s /* 0x%04x: 0x%08x%08x */\n",
366 buf, &spaces[nspaces - clamp(65 - len, 0, nspaces)],
367 pc, high, low);
368 }
369 }
370
371 #define TOTAL_SIZE_GPR (0x100*4)
372 #define A_TOTAL_SIZE_GPR (0x200*4)
373 #define TOTAL_SIZE_TANKMEM_DATA (0xa0*4)
374 #define TOTAL_SIZE_TANKMEM_ADDR (0xa0*4)
375 #define A_TOTAL_SIZE_TANKMEM_DATA (0x100*4)
376 #define A_TOTAL_SIZE_TANKMEM_ADDR (0x100*4)
377 #define TOTAL_SIZE_CODE (0x200*8)
378 #define A_TOTAL_SIZE_CODE (0x400*8)
379
snd_emu10k1_fx8010_read(struct snd_info_entry * entry,void * file_private_data,struct file * file,char __user * buf,size_t count,loff_t pos)380 static ssize_t snd_emu10k1_fx8010_read(struct snd_info_entry *entry,
381 void *file_private_data,
382 struct file *file, char __user *buf,
383 size_t count, loff_t pos)
384 {
385 struct snd_emu10k1 *emu = entry->private_data;
386 unsigned int offset;
387 int tram_addr = 0;
388 unsigned int *tmp;
389 long res;
390 unsigned int idx;
391
392 if (!strcmp(entry->name, "fx8010_tram_addr")) {
393 offset = TANKMEMADDRREGBASE;
394 tram_addr = 1;
395 } else if (!strcmp(entry->name, "fx8010_tram_data")) {
396 offset = TANKMEMDATAREGBASE;
397 } else if (!strcmp(entry->name, "fx8010_code")) {
398 offset = emu->audigy ? A_MICROCODEBASE : MICROCODEBASE;
399 } else {
400 offset = emu->audigy ? A_FXGPREGBASE : FXGPREGBASE;
401 }
402
403 tmp = kmalloc(count + 8, GFP_KERNEL);
404 if (!tmp)
405 return -ENOMEM;
406 for (idx = 0; idx < ((pos & 3) + count + 3) >> 2; idx++) {
407 unsigned int val;
408 val = snd_emu10k1_ptr_read(emu, offset + idx + (pos >> 2), 0);
409 if (tram_addr && emu->audigy) {
410 val >>= 11;
411 val |= snd_emu10k1_ptr_read(emu, 0x100 + idx + (pos >> 2), 0) << 20;
412 }
413 tmp[idx] = val;
414 }
415 if (copy_to_user(buf, ((char *)tmp) + (pos & 3), count))
416 res = -EFAULT;
417 else
418 res = count;
419 kfree(tmp);
420 return res;
421 }
422
snd_emu10k1_proc_voices_read(struct snd_info_entry * entry,struct snd_info_buffer * buffer)423 static void snd_emu10k1_proc_voices_read(struct snd_info_entry *entry,
424 struct snd_info_buffer *buffer)
425 {
426 struct snd_emu10k1 *emu = entry->private_data;
427 struct snd_emu10k1_voice *voice;
428 int idx;
429 static const char * const types[] = {
430 "Unused", "EFX", "EFX IRQ", "PCM", "PCM IRQ", "Synth"
431 };
432 static_assert(ARRAY_SIZE(types) == EMU10K1_NUM_TYPES);
433
434 snd_iprintf(buffer, "ch\tdirty\tlast\tuse\n");
435 for (idx = 0; idx < NUM_G; idx++) {
436 voice = &emu->voices[idx];
437 snd_iprintf(buffer, "%i\t%u\t%u\t%s\n",
438 idx,
439 voice->dirty,
440 voice->last,
441 types[voice->use]);
442 }
443 }
444
445 #ifdef CONFIG_SND_DEBUG
446
snd_emu_proc_emu1010_link_read(struct snd_emu10k1 * emu,struct snd_info_buffer * buffer,u32 dst)447 static void snd_emu_proc_emu1010_link_read(struct snd_emu10k1 *emu,
448 struct snd_info_buffer *buffer,
449 u32 dst)
450 {
451 u32 src = snd_emu1010_fpga_link_dst_src_read(emu, dst);
452 snd_iprintf(buffer, "%04x: %04x\n", dst, src);
453 }
454
snd_emu_proc_emu1010_reg_read(struct snd_info_entry * entry,struct snd_info_buffer * buffer)455 static void snd_emu_proc_emu1010_reg_read(struct snd_info_entry *entry,
456 struct snd_info_buffer *buffer)
457 {
458 struct snd_emu10k1 *emu = entry->private_data;
459 u32 value;
460 int i;
461 snd_iprintf(buffer, "EMU1010 Registers:\n\n");
462
463 for(i = 0; i < 0x40; i+=1) {
464 snd_emu1010_fpga_read(emu, i, &value);
465 snd_iprintf(buffer, "%02x: %02x\n", i, value);
466 }
467
468 snd_iprintf(buffer, "\nEMU1010 Routes:\n\n");
469
470 for (i = 0; i < 16; i++) // To Alice2/Tina[2] via EMU32
471 snd_emu_proc_emu1010_link_read(emu, buffer, i);
472 if (emu->card_capabilities->emu_model != EMU_MODEL_EMU0404)
473 for (i = 0; i < 32; i++) // To Dock via EDI
474 snd_emu_proc_emu1010_link_read(emu, buffer, 0x100 + i);
475 if (emu->card_capabilities->emu_model != EMU_MODEL_EMU1616)
476 for (i = 0; i < 8; i++) // To Hamoa/local
477 snd_emu_proc_emu1010_link_read(emu, buffer, 0x200 + i);
478 for (i = 0; i < 8; i++) // To Hamoa/Mana/local
479 snd_emu_proc_emu1010_link_read(emu, buffer, 0x300 + i);
480 if (emu->card_capabilities->emu_model == EMU_MODEL_EMU1616) {
481 for (i = 0; i < 16; i++) // To Tina2 via EMU32
482 snd_emu_proc_emu1010_link_read(emu, buffer, 0x400 + i);
483 } else if (emu->card_capabilities->emu_model != EMU_MODEL_EMU0404) {
484 for (i = 0; i < 8; i++) // To Hana ADAT
485 snd_emu_proc_emu1010_link_read(emu, buffer, 0x400 + i);
486 if (emu->card_capabilities->emu_model == EMU_MODEL_EMU1010B) {
487 for (i = 0; i < 16; i++) // To Tina via EMU32
488 snd_emu_proc_emu1010_link_read(emu, buffer, 0x500 + i);
489 } else {
490 // To Alice2 via I2S
491 snd_emu_proc_emu1010_link_read(emu, buffer, 0x500);
492 snd_emu_proc_emu1010_link_read(emu, buffer, 0x501);
493 snd_emu_proc_emu1010_link_read(emu, buffer, 0x600);
494 snd_emu_proc_emu1010_link_read(emu, buffer, 0x601);
495 snd_emu_proc_emu1010_link_read(emu, buffer, 0x700);
496 snd_emu_proc_emu1010_link_read(emu, buffer, 0x701);
497 }
498 }
499 }
500
snd_emu_proc_io_reg_read(struct snd_info_entry * entry,struct snd_info_buffer * buffer)501 static void snd_emu_proc_io_reg_read(struct snd_info_entry *entry,
502 struct snd_info_buffer *buffer)
503 {
504 struct snd_emu10k1 *emu = entry->private_data;
505 unsigned long value;
506 int i;
507 snd_iprintf(buffer, "IO Registers:\n\n");
508 for(i = 0; i < 0x40; i+=4) {
509 value = inl(emu->port + i);
510 snd_iprintf(buffer, "%02X: %08lX\n", i, value);
511 }
512 }
513
snd_emu_proc_io_reg_write(struct snd_info_entry * entry,struct snd_info_buffer * buffer)514 static void snd_emu_proc_io_reg_write(struct snd_info_entry *entry,
515 struct snd_info_buffer *buffer)
516 {
517 struct snd_emu10k1 *emu = entry->private_data;
518 char line[64];
519 u32 reg, val;
520 while (!snd_info_get_line(buffer, line, sizeof(line))) {
521 if (sscanf(line, "%x %x", ®, &val) != 2)
522 continue;
523 if (reg < 0x40 && val <= 0xffffffff) {
524 outl(val, emu->port + (reg & 0xfffffffc));
525 }
526 }
527 }
528
snd_ptr_read(struct snd_emu10k1 * emu,unsigned int iobase,unsigned int reg,unsigned int chn)529 static unsigned int snd_ptr_read(struct snd_emu10k1 * emu,
530 unsigned int iobase,
531 unsigned int reg,
532 unsigned int chn)
533 {
534 unsigned int regptr, val;
535
536 regptr = (reg << 16) | chn;
537
538 spin_lock_irq(&emu->emu_lock);
539 outl(regptr, emu->port + iobase + PTR);
540 val = inl(emu->port + iobase + DATA);
541 spin_unlock_irq(&emu->emu_lock);
542 return val;
543 }
544
snd_ptr_write(struct snd_emu10k1 * emu,unsigned int iobase,unsigned int reg,unsigned int chn,unsigned int data)545 static void snd_ptr_write(struct snd_emu10k1 *emu,
546 unsigned int iobase,
547 unsigned int reg,
548 unsigned int chn,
549 unsigned int data)
550 {
551 unsigned int regptr;
552
553 regptr = (reg << 16) | chn;
554
555 spin_lock_irq(&emu->emu_lock);
556 outl(regptr, emu->port + iobase + PTR);
557 outl(data, emu->port + iobase + DATA);
558 spin_unlock_irq(&emu->emu_lock);
559 }
560
561
snd_emu_proc_ptr_reg_read(struct snd_info_entry * entry,struct snd_info_buffer * buffer,int iobase,int offset,int length,int voices)562 static void snd_emu_proc_ptr_reg_read(struct snd_info_entry *entry,
563 struct snd_info_buffer *buffer, int iobase, int offset, int length, int voices)
564 {
565 struct snd_emu10k1 *emu = entry->private_data;
566 unsigned long value;
567 int i,j;
568 if (offset+length > 0xa0) {
569 snd_iprintf(buffer, "Input values out of range\n");
570 return;
571 }
572 snd_iprintf(buffer, "Registers 0x%x\n", iobase);
573 for(i = offset; i < offset+length; i++) {
574 snd_iprintf(buffer, "%02X: ",i);
575 for (j = 0; j < voices; j++) {
576 value = snd_ptr_read(emu, iobase, i, j);
577 snd_iprintf(buffer, "%08lX ", value);
578 }
579 snd_iprintf(buffer, "\n");
580 }
581 }
582
snd_emu_proc_ptr_reg_write(struct snd_info_entry * entry,struct snd_info_buffer * buffer,int iobase,int length,int voices)583 static void snd_emu_proc_ptr_reg_write(struct snd_info_entry *entry,
584 struct snd_info_buffer *buffer,
585 int iobase, int length, int voices)
586 {
587 struct snd_emu10k1 *emu = entry->private_data;
588 char line[64];
589 unsigned int reg, channel_id , val;
590 while (!snd_info_get_line(buffer, line, sizeof(line))) {
591 if (sscanf(line, "%x %x %x", ®, &channel_id, &val) != 3)
592 continue;
593 if (reg < length && channel_id < voices)
594 snd_ptr_write(emu, iobase, reg, channel_id, val);
595 }
596 }
597
snd_emu_proc_ptr_reg_write00(struct snd_info_entry * entry,struct snd_info_buffer * buffer)598 static void snd_emu_proc_ptr_reg_write00(struct snd_info_entry *entry,
599 struct snd_info_buffer *buffer)
600 {
601 snd_emu_proc_ptr_reg_write(entry, buffer, 0, 0x80, 64);
602 }
603
snd_emu_proc_ptr_reg_write20(struct snd_info_entry * entry,struct snd_info_buffer * buffer)604 static void snd_emu_proc_ptr_reg_write20(struct snd_info_entry *entry,
605 struct snd_info_buffer *buffer)
606 {
607 struct snd_emu10k1 *emu = entry->private_data;
608 snd_emu_proc_ptr_reg_write(entry, buffer, 0x20,
609 emu->card_capabilities->ca0108_chip ? 0xa0 : 0x80, 4);
610 }
611
612
snd_emu_proc_ptr_reg_read00a(struct snd_info_entry * entry,struct snd_info_buffer * buffer)613 static void snd_emu_proc_ptr_reg_read00a(struct snd_info_entry *entry,
614 struct snd_info_buffer *buffer)
615 {
616 snd_emu_proc_ptr_reg_read(entry, buffer, 0, 0, 0x40, 64);
617 }
618
snd_emu_proc_ptr_reg_read00b(struct snd_info_entry * entry,struct snd_info_buffer * buffer)619 static void snd_emu_proc_ptr_reg_read00b(struct snd_info_entry *entry,
620 struct snd_info_buffer *buffer)
621 {
622 snd_emu_proc_ptr_reg_read(entry, buffer, 0, 0x40, 0x40, 64);
623 }
624
snd_emu_proc_ptr_reg_read20a(struct snd_info_entry * entry,struct snd_info_buffer * buffer)625 static void snd_emu_proc_ptr_reg_read20a(struct snd_info_entry *entry,
626 struct snd_info_buffer *buffer)
627 {
628 snd_emu_proc_ptr_reg_read(entry, buffer, 0x20, 0, 0x40, 4);
629 }
630
snd_emu_proc_ptr_reg_read20b(struct snd_info_entry * entry,struct snd_info_buffer * buffer)631 static void snd_emu_proc_ptr_reg_read20b(struct snd_info_entry *entry,
632 struct snd_info_buffer *buffer)
633 {
634 snd_emu_proc_ptr_reg_read(entry, buffer, 0x20, 0x40, 0x40, 4);
635 }
636
snd_emu_proc_ptr_reg_read20c(struct snd_info_entry * entry,struct snd_info_buffer * buffer)637 static void snd_emu_proc_ptr_reg_read20c(struct snd_info_entry *entry,
638 struct snd_info_buffer * buffer)
639 {
640 snd_emu_proc_ptr_reg_read(entry, buffer, 0x20, 0x80, 0x20, 4);
641 }
642 #endif
643
644 static const struct snd_info_entry_ops snd_emu10k1_proc_ops_fx8010 = {
645 .read = snd_emu10k1_fx8010_read,
646 };
647
snd_emu10k1_proc_init(struct snd_emu10k1 * emu)648 int snd_emu10k1_proc_init(struct snd_emu10k1 *emu)
649 {
650 struct snd_info_entry *entry;
651 #ifdef CONFIG_SND_DEBUG
652 if (emu->card_capabilities->emu_model) {
653 snd_card_ro_proc_new(emu->card, "emu1010_regs",
654 emu, snd_emu_proc_emu1010_reg_read);
655 }
656 snd_card_rw_proc_new(emu->card, "io_regs", emu,
657 snd_emu_proc_io_reg_read,
658 snd_emu_proc_io_reg_write);
659 snd_card_rw_proc_new(emu->card, "ptr_regs00a", emu,
660 snd_emu_proc_ptr_reg_read00a,
661 snd_emu_proc_ptr_reg_write00);
662 snd_card_rw_proc_new(emu->card, "ptr_regs00b", emu,
663 snd_emu_proc_ptr_reg_read00b,
664 snd_emu_proc_ptr_reg_write00);
665 if (!emu->card_capabilities->emu_model &&
666 (emu->card_capabilities->ca0151_chip || emu->card_capabilities->ca0108_chip)) {
667 snd_card_rw_proc_new(emu->card, "ptr_regs20a", emu,
668 snd_emu_proc_ptr_reg_read20a,
669 snd_emu_proc_ptr_reg_write20);
670 snd_card_rw_proc_new(emu->card, "ptr_regs20b", emu,
671 snd_emu_proc_ptr_reg_read20b,
672 snd_emu_proc_ptr_reg_write20);
673 if (emu->card_capabilities->ca0108_chip)
674 snd_card_rw_proc_new(emu->card, "ptr_regs20c", emu,
675 snd_emu_proc_ptr_reg_read20c,
676 snd_emu_proc_ptr_reg_write20);
677 }
678 #endif
679
680 snd_card_ro_proc_new(emu->card, "emu10k1", emu, snd_emu10k1_proc_read);
681
682 if (emu->card_capabilities->emu10k2_chip)
683 snd_card_ro_proc_new(emu->card, "spdif-in", emu,
684 snd_emu10k1_proc_spdif_read);
685 if (emu->card_capabilities->ca0151_chip)
686 snd_card_ro_proc_new(emu->card, "capture-rates", emu,
687 snd_emu10k1_proc_rates_read);
688
689 snd_card_ro_proc_new(emu->card, "voices", emu,
690 snd_emu10k1_proc_voices_read);
691
692 if (! snd_card_proc_new(emu->card, "fx8010_gpr", &entry)) {
693 entry->content = SNDRV_INFO_CONTENT_DATA;
694 entry->private_data = emu;
695 entry->mode = S_IFREG | 0444 /*| S_IWUSR*/;
696 entry->size = emu->audigy ? A_TOTAL_SIZE_GPR : TOTAL_SIZE_GPR;
697 entry->c.ops = &snd_emu10k1_proc_ops_fx8010;
698 }
699 if (! snd_card_proc_new(emu->card, "fx8010_tram_data", &entry)) {
700 entry->content = SNDRV_INFO_CONTENT_DATA;
701 entry->private_data = emu;
702 entry->mode = S_IFREG | 0444 /*| S_IWUSR*/;
703 entry->size = emu->audigy ? A_TOTAL_SIZE_TANKMEM_DATA : TOTAL_SIZE_TANKMEM_DATA ;
704 entry->c.ops = &snd_emu10k1_proc_ops_fx8010;
705 }
706 if (! snd_card_proc_new(emu->card, "fx8010_tram_addr", &entry)) {
707 entry->content = SNDRV_INFO_CONTENT_DATA;
708 entry->private_data = emu;
709 entry->mode = S_IFREG | 0444 /*| S_IWUSR*/;
710 entry->size = emu->audigy ? A_TOTAL_SIZE_TANKMEM_ADDR : TOTAL_SIZE_TANKMEM_ADDR ;
711 entry->c.ops = &snd_emu10k1_proc_ops_fx8010;
712 }
713 if (! snd_card_proc_new(emu->card, "fx8010_code", &entry)) {
714 entry->content = SNDRV_INFO_CONTENT_DATA;
715 entry->private_data = emu;
716 entry->mode = S_IFREG | 0444 /*| S_IWUSR*/;
717 entry->size = emu->audigy ? A_TOTAL_SIZE_CODE : TOTAL_SIZE_CODE;
718 entry->c.ops = &snd_emu10k1_proc_ops_fx8010;
719 }
720 snd_card_ro_proc_new(emu->card, "fx8010_acode", emu,
721 snd_emu10k1_proc_acode_read);
722 return 0;
723 }
724