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