xref: /openbmc/linux/sound/pci/emu10k1/emuproc.c (revision 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2)
1*1da177e4SLinus Torvalds /*
2*1da177e4SLinus Torvalds  *  Copyright (c) by Jaroslav Kysela <perex@suse.cz>
3*1da177e4SLinus Torvalds  *                   Creative Labs, Inc.
4*1da177e4SLinus Torvalds  *  Routines for control of EMU10K1 chips / proc interface routines
5*1da177e4SLinus Torvalds  *
6*1da177e4SLinus Torvalds  *  BUGS:
7*1da177e4SLinus Torvalds  *    --
8*1da177e4SLinus Torvalds  *
9*1da177e4SLinus Torvalds  *  TODO:
10*1da177e4SLinus Torvalds  *    --
11*1da177e4SLinus Torvalds  *
12*1da177e4SLinus Torvalds  *   This program is free software; you can redistribute it and/or modify
13*1da177e4SLinus Torvalds  *   it under the terms of the GNU General Public License as published by
14*1da177e4SLinus Torvalds  *   the Free Software Foundation; either version 2 of the License, or
15*1da177e4SLinus Torvalds  *   (at your option) any later version.
16*1da177e4SLinus Torvalds  *
17*1da177e4SLinus Torvalds  *   This program is distributed in the hope that it will be useful,
18*1da177e4SLinus Torvalds  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
19*1da177e4SLinus Torvalds  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20*1da177e4SLinus Torvalds  *   GNU General Public License for more details.
21*1da177e4SLinus Torvalds  *
22*1da177e4SLinus Torvalds  *   You should have received a copy of the GNU General Public License
23*1da177e4SLinus Torvalds  *   along with this program; if not, write to the Free Software
24*1da177e4SLinus Torvalds  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
25*1da177e4SLinus Torvalds  *
26*1da177e4SLinus Torvalds  */
27*1da177e4SLinus Torvalds 
28*1da177e4SLinus Torvalds #include <sound/driver.h>
29*1da177e4SLinus Torvalds #include <linux/slab.h>
30*1da177e4SLinus Torvalds #include <linux/init.h>
31*1da177e4SLinus Torvalds #include <sound/core.h>
32*1da177e4SLinus Torvalds #include <sound/emu10k1.h>
33*1da177e4SLinus Torvalds 
34*1da177e4SLinus Torvalds static void snd_emu10k1_proc_spdif_status(emu10k1_t * emu,
35*1da177e4SLinus Torvalds 					  snd_info_buffer_t * buffer,
36*1da177e4SLinus Torvalds 					  char *title,
37*1da177e4SLinus Torvalds 					  int status_reg,
38*1da177e4SLinus Torvalds 					  int rate_reg)
39*1da177e4SLinus Torvalds {
40*1da177e4SLinus Torvalds 	static char *clkaccy[4] = { "1000ppm", "50ppm", "variable", "unknown" };
41*1da177e4SLinus Torvalds 	static int samplerate[16] = { 44100, 1, 48000, 32000, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
42*1da177e4SLinus Torvalds 	static char *channel[16] = { "unspec", "left", "right", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15" };
43*1da177e4SLinus Torvalds 	static char *emphasis[8] = { "none", "50/15 usec 2 channel", "2", "3", "4", "5", "6", "7" };
44*1da177e4SLinus Torvalds 	unsigned int status, rate = 0;
45*1da177e4SLinus Torvalds 
46*1da177e4SLinus Torvalds 	status = snd_emu10k1_ptr_read(emu, status_reg, 0);
47*1da177e4SLinus Torvalds 	if (rate_reg > 0)
48*1da177e4SLinus Torvalds 		rate = snd_emu10k1_ptr_read(emu, rate_reg, 0);
49*1da177e4SLinus Torvalds 
50*1da177e4SLinus Torvalds 	snd_iprintf(buffer, "\n%s\n", title);
51*1da177e4SLinus Torvalds 
52*1da177e4SLinus Torvalds 	snd_iprintf(buffer, "Professional Mode     : %s\n", (status & SPCS_PROFESSIONAL) ? "yes" : "no");
53*1da177e4SLinus Torvalds 	snd_iprintf(buffer, "Not Audio Data        : %s\n", (status & SPCS_NOTAUDIODATA) ? "yes" : "no");
54*1da177e4SLinus Torvalds 	snd_iprintf(buffer, "Copyright             : %s\n", (status & SPCS_COPYRIGHT) ? "yes" : "no");
55*1da177e4SLinus Torvalds 	snd_iprintf(buffer, "Emphasis              : %s\n", emphasis[(status & SPCS_EMPHASISMASK) >> 3]);
56*1da177e4SLinus Torvalds 	snd_iprintf(buffer, "Mode                  : %i\n", (status & SPCS_MODEMASK) >> 6);
57*1da177e4SLinus Torvalds 	snd_iprintf(buffer, "Category Code         : 0x%x\n", (status & SPCS_CATEGORYCODEMASK) >> 8);
58*1da177e4SLinus Torvalds 	snd_iprintf(buffer, "Generation Status     : %s\n", status & SPCS_GENERATIONSTATUS ? "original" : "copy");
59*1da177e4SLinus Torvalds 	snd_iprintf(buffer, "Source Mask           : %i\n", (status & SPCS_SOURCENUMMASK) >> 16);
60*1da177e4SLinus Torvalds 	snd_iprintf(buffer, "Channel Number        : %s\n", channel[(status & SPCS_CHANNELNUMMASK) >> 20]);
61*1da177e4SLinus Torvalds 	snd_iprintf(buffer, "Sample Rate           : %iHz\n", samplerate[(status & SPCS_SAMPLERATEMASK) >> 24]);
62*1da177e4SLinus Torvalds 	snd_iprintf(buffer, "Clock Accuracy        : %s\n", clkaccy[(status & SPCS_CLKACCYMASK) >> 28]);
63*1da177e4SLinus Torvalds 
64*1da177e4SLinus Torvalds 	if (rate_reg > 0) {
65*1da177e4SLinus Torvalds 		snd_iprintf(buffer, "S/PDIF Locked         : %s\n", rate & SRCS_SPDIFLOCKED ? "on" : "off");
66*1da177e4SLinus Torvalds 		snd_iprintf(buffer, "Rate Locked           : %s\n", rate & SRCS_RATELOCKED ? "on" : "off");
67*1da177e4SLinus Torvalds 		snd_iprintf(buffer, "Estimated Sample Rate : 0x%x\n", rate & SRCS_ESTSAMPLERATE);
68*1da177e4SLinus Torvalds 	}
69*1da177e4SLinus Torvalds }
70*1da177e4SLinus Torvalds 
71*1da177e4SLinus Torvalds static void snd_emu10k1_proc_read(snd_info_entry_t *entry,
72*1da177e4SLinus Torvalds 				  snd_info_buffer_t * buffer)
73*1da177e4SLinus Torvalds {
74*1da177e4SLinus Torvalds 	/* FIXME - output names are in emufx.c too */
75*1da177e4SLinus Torvalds 	static char *creative_outs[32] = {
76*1da177e4SLinus Torvalds 		/* 00 */ "AC97 Left",
77*1da177e4SLinus Torvalds 		/* 01 */ "AC97 Right",
78*1da177e4SLinus Torvalds 		/* 02 */ "Optical IEC958 Left",
79*1da177e4SLinus Torvalds 		/* 03 */ "Optical IEC958 Right",
80*1da177e4SLinus Torvalds 		/* 04 */ "Center",
81*1da177e4SLinus Torvalds 		/* 05 */ "LFE",
82*1da177e4SLinus Torvalds 		/* 06 */ "Headphone Left",
83*1da177e4SLinus Torvalds 		/* 07 */ "Headphone Right",
84*1da177e4SLinus Torvalds 		/* 08 */ "Surround Left",
85*1da177e4SLinus Torvalds 		/* 09 */ "Surround Right",
86*1da177e4SLinus Torvalds 		/* 10 */ "PCM Capture Left",
87*1da177e4SLinus Torvalds 		/* 11 */ "PCM Capture Right",
88*1da177e4SLinus Torvalds 		/* 12 */ "MIC Capture",
89*1da177e4SLinus Torvalds 		/* 13 */ "AC97 Surround Left",
90*1da177e4SLinus Torvalds 		/* 14 */ "AC97 Surround Right",
91*1da177e4SLinus Torvalds 		/* 15 */ "???",
92*1da177e4SLinus Torvalds 		/* 16 */ "???",
93*1da177e4SLinus Torvalds 		/* 17 */ "Analog Center",
94*1da177e4SLinus Torvalds 		/* 18 */ "Analog LFE",
95*1da177e4SLinus Torvalds 		/* 19 */ "???",
96*1da177e4SLinus Torvalds 		/* 20 */ "???",
97*1da177e4SLinus Torvalds 		/* 21 */ "???",
98*1da177e4SLinus Torvalds 		/* 22 */ "???",
99*1da177e4SLinus Torvalds 		/* 23 */ "???",
100*1da177e4SLinus Torvalds 		/* 24 */ "???",
101*1da177e4SLinus Torvalds 		/* 25 */ "???",
102*1da177e4SLinus Torvalds 		/* 26 */ "???",
103*1da177e4SLinus Torvalds 		/* 27 */ "???",
104*1da177e4SLinus Torvalds 		/* 28 */ "???",
105*1da177e4SLinus Torvalds 		/* 29 */ "???",
106*1da177e4SLinus Torvalds 		/* 30 */ "???",
107*1da177e4SLinus Torvalds 		/* 31 */ "???"
108*1da177e4SLinus Torvalds 	};
109*1da177e4SLinus Torvalds 
110*1da177e4SLinus Torvalds 	static char *audigy_outs[64] = {
111*1da177e4SLinus Torvalds 		/* 00 */ "Digital Front Left",
112*1da177e4SLinus Torvalds 		/* 01 */ "Digital Front Right",
113*1da177e4SLinus Torvalds 		/* 02 */ "Digital Center",
114*1da177e4SLinus Torvalds 		/* 03 */ "Digital LEF",
115*1da177e4SLinus Torvalds 		/* 04 */ "Headphone Left",
116*1da177e4SLinus Torvalds 		/* 05 */ "Headphone Right",
117*1da177e4SLinus Torvalds 		/* 06 */ "Digital Rear Left",
118*1da177e4SLinus Torvalds 		/* 07 */ "Digital Rear Right",
119*1da177e4SLinus Torvalds 		/* 08 */ "Front Left",
120*1da177e4SLinus Torvalds 		/* 09 */ "Front Right",
121*1da177e4SLinus Torvalds 		/* 10 */ "Center",
122*1da177e4SLinus Torvalds 		/* 11 */ "LFE",
123*1da177e4SLinus Torvalds 		/* 12 */ "???",
124*1da177e4SLinus Torvalds 		/* 13 */ "???",
125*1da177e4SLinus Torvalds 		/* 14 */ "Rear Left",
126*1da177e4SLinus Torvalds 		/* 15 */ "Rear Right",
127*1da177e4SLinus Torvalds 		/* 16 */ "AC97 Front Left",
128*1da177e4SLinus Torvalds 		/* 17 */ "AC97 Front Right",
129*1da177e4SLinus Torvalds 		/* 18 */ "ADC Caputre Left",
130*1da177e4SLinus Torvalds 		/* 19 */ "ADC Capture Right",
131*1da177e4SLinus Torvalds 		/* 20 */ "???",
132*1da177e4SLinus Torvalds 		/* 21 */ "???",
133*1da177e4SLinus Torvalds 		/* 22 */ "???",
134*1da177e4SLinus Torvalds 		/* 23 */ "???",
135*1da177e4SLinus Torvalds 		/* 24 */ "???",
136*1da177e4SLinus Torvalds 		/* 25 */ "???",
137*1da177e4SLinus Torvalds 		/* 26 */ "???",
138*1da177e4SLinus Torvalds 		/* 27 */ "???",
139*1da177e4SLinus Torvalds 		/* 28 */ "???",
140*1da177e4SLinus Torvalds 		/* 29 */ "???",
141*1da177e4SLinus Torvalds 		/* 30 */ "???",
142*1da177e4SLinus Torvalds 		/* 31 */ "???",
143*1da177e4SLinus Torvalds 		/* 32 */ "FXBUS2_0",
144*1da177e4SLinus Torvalds 		/* 33 */ "FXBUS2_1",
145*1da177e4SLinus Torvalds 		/* 34 */ "FXBUS2_2",
146*1da177e4SLinus Torvalds 		/* 35 */ "FXBUS2_3",
147*1da177e4SLinus Torvalds 		/* 36 */ "FXBUS2_4",
148*1da177e4SLinus Torvalds 		/* 37 */ "FXBUS2_5",
149*1da177e4SLinus Torvalds 		/* 38 */ "FXBUS2_6",
150*1da177e4SLinus Torvalds 		/* 39 */ "FXBUS2_7",
151*1da177e4SLinus Torvalds 		/* 40 */ "FXBUS2_8",
152*1da177e4SLinus Torvalds 		/* 41 */ "FXBUS2_9",
153*1da177e4SLinus Torvalds 		/* 42 */ "FXBUS2_10",
154*1da177e4SLinus Torvalds 		/* 43 */ "FXBUS2_11",
155*1da177e4SLinus Torvalds 		/* 44 */ "FXBUS2_12",
156*1da177e4SLinus Torvalds 		/* 45 */ "FXBUS2_13",
157*1da177e4SLinus Torvalds 		/* 46 */ "FXBUS2_14",
158*1da177e4SLinus Torvalds 		/* 47 */ "FXBUS2_15",
159*1da177e4SLinus Torvalds 		/* 48 */ "FXBUS2_16",
160*1da177e4SLinus Torvalds 		/* 49 */ "FXBUS2_17",
161*1da177e4SLinus Torvalds 		/* 50 */ "FXBUS2_18",
162*1da177e4SLinus Torvalds 		/* 51 */ "FXBUS2_19",
163*1da177e4SLinus Torvalds 		/* 52 */ "FXBUS2_20",
164*1da177e4SLinus Torvalds 		/* 53 */ "FXBUS2_21",
165*1da177e4SLinus Torvalds 		/* 54 */ "FXBUS2_22",
166*1da177e4SLinus Torvalds 		/* 55 */ "FXBUS2_23",
167*1da177e4SLinus Torvalds 		/* 56 */ "FXBUS2_24",
168*1da177e4SLinus Torvalds 		/* 57 */ "FXBUS2_25",
169*1da177e4SLinus Torvalds 		/* 58 */ "FXBUS2_26",
170*1da177e4SLinus Torvalds 		/* 59 */ "FXBUS2_27",
171*1da177e4SLinus Torvalds 		/* 60 */ "FXBUS2_28",
172*1da177e4SLinus Torvalds 		/* 61 */ "FXBUS2_29",
173*1da177e4SLinus Torvalds 		/* 62 */ "FXBUS2_30",
174*1da177e4SLinus Torvalds 		/* 63 */ "FXBUS2_31"
175*1da177e4SLinus Torvalds 	};
176*1da177e4SLinus Torvalds 
177*1da177e4SLinus Torvalds 	emu10k1_t *emu = entry->private_data;
178*1da177e4SLinus Torvalds 	unsigned int val, val1;
179*1da177e4SLinus Torvalds 	int nefx = emu->audigy ? 64 : 32;
180*1da177e4SLinus Torvalds 	char **outputs = emu->audigy ? audigy_outs : creative_outs;
181*1da177e4SLinus Torvalds 	int idx;
182*1da177e4SLinus Torvalds 
183*1da177e4SLinus Torvalds 	snd_iprintf(buffer, "EMU10K1\n\n");
184*1da177e4SLinus Torvalds 	snd_iprintf(buffer, "Card                  : %s\n",
185*1da177e4SLinus Torvalds 		    emu->audigy ? "Audigy" : (emu->APS ? "EMU APS" : "Creative"));
186*1da177e4SLinus Torvalds 	snd_iprintf(buffer, "Internal TRAM (words) : 0x%x\n", emu->fx8010.itram_size);
187*1da177e4SLinus Torvalds 	snd_iprintf(buffer, "External TRAM (words) : 0x%x\n", (int)emu->fx8010.etram_pages.bytes / 2);
188*1da177e4SLinus Torvalds 	snd_iprintf(buffer, "\n");
189*1da177e4SLinus Torvalds 	snd_iprintf(buffer, "Effect Send Routing   :\n");
190*1da177e4SLinus Torvalds 	for (idx = 0; idx < NUM_G; idx++) {
191*1da177e4SLinus Torvalds 		val = emu->audigy ?
192*1da177e4SLinus Torvalds 			snd_emu10k1_ptr_read(emu, A_FXRT1, idx) :
193*1da177e4SLinus Torvalds 			snd_emu10k1_ptr_read(emu, FXRT, idx);
194*1da177e4SLinus Torvalds 		val1 = emu->audigy ?
195*1da177e4SLinus Torvalds 			snd_emu10k1_ptr_read(emu, A_FXRT2, idx) :
196*1da177e4SLinus Torvalds 			0;
197*1da177e4SLinus Torvalds 		if (emu->audigy) {
198*1da177e4SLinus Torvalds 			snd_iprintf(buffer, "Ch%i: A=%i, B=%i, C=%i, D=%i, ",
199*1da177e4SLinus Torvalds 				idx,
200*1da177e4SLinus Torvalds 				val & 0x3f,
201*1da177e4SLinus Torvalds 				(val >> 8) & 0x3f,
202*1da177e4SLinus Torvalds 				(val >> 16) & 0x3f,
203*1da177e4SLinus Torvalds 				(val >> 24) & 0x3f);
204*1da177e4SLinus Torvalds 			snd_iprintf(buffer, "E=%i, F=%i, G=%i, H=%i\n",
205*1da177e4SLinus Torvalds 				val1 & 0x3f,
206*1da177e4SLinus Torvalds 				(val1 >> 8) & 0x3f,
207*1da177e4SLinus Torvalds 				(val1 >> 16) & 0x3f,
208*1da177e4SLinus Torvalds 				(val1 >> 24) & 0x3f);
209*1da177e4SLinus Torvalds 		} else {
210*1da177e4SLinus Torvalds 			snd_iprintf(buffer, "Ch%i: A=%i, B=%i, C=%i, D=%i\n",
211*1da177e4SLinus Torvalds 				idx,
212*1da177e4SLinus Torvalds 				(val >> 16) & 0x0f,
213*1da177e4SLinus Torvalds 				(val >> 20) & 0x0f,
214*1da177e4SLinus Torvalds 				(val >> 24) & 0x0f,
215*1da177e4SLinus Torvalds 				(val >> 28) & 0x0f);
216*1da177e4SLinus Torvalds 		}
217*1da177e4SLinus Torvalds 	}
218*1da177e4SLinus Torvalds 	snd_iprintf(buffer, "\nCaptured FX Outputs   :\n");
219*1da177e4SLinus Torvalds 	for (idx = 0; idx < nefx; idx++) {
220*1da177e4SLinus Torvalds 		if (emu->efx_voices_mask[idx/32] & (1 << (idx%32)))
221*1da177e4SLinus Torvalds 			snd_iprintf(buffer, "  Output %02i [%s]\n", idx, outputs[idx]);
222*1da177e4SLinus Torvalds 	}
223*1da177e4SLinus Torvalds 	snd_iprintf(buffer, "\nAll FX Outputs        :\n");
224*1da177e4SLinus Torvalds 	for (idx = 0; idx < (emu->audigy ? 64 : 32); idx++)
225*1da177e4SLinus Torvalds 		snd_iprintf(buffer, "  Output %02i [%s]\n", idx, outputs[idx]);
226*1da177e4SLinus Torvalds 	snd_emu10k1_proc_spdif_status(emu, buffer, "S/PDIF Output 0", SPCS0, -1);
227*1da177e4SLinus Torvalds 	snd_emu10k1_proc_spdif_status(emu, buffer, "S/PDIF Output 1", SPCS1, -1);
228*1da177e4SLinus Torvalds 	snd_emu10k1_proc_spdif_status(emu, buffer, "S/PDIF Output 2/3", SPCS2, -1);
229*1da177e4SLinus Torvalds 	snd_emu10k1_proc_spdif_status(emu, buffer, "CD-ROM S/PDIF", CDCS, CDSRCS);
230*1da177e4SLinus Torvalds 	snd_emu10k1_proc_spdif_status(emu, buffer, "General purpose S/PDIF", GPSCS, GPSRCS);
231*1da177e4SLinus Torvalds 	val = snd_emu10k1_ptr_read(emu, ZVSRCS, 0);
232*1da177e4SLinus Torvalds 	snd_iprintf(buffer, "\nZoomed Video\n");
233*1da177e4SLinus Torvalds 	snd_iprintf(buffer, "Rate Locked           : %s\n", val & SRCS_RATELOCKED ? "on" : "off");
234*1da177e4SLinus Torvalds 	snd_iprintf(buffer, "Estimated Sample Rate : 0x%x\n", val & SRCS_ESTSAMPLERATE);
235*1da177e4SLinus Torvalds }
236*1da177e4SLinus Torvalds 
237*1da177e4SLinus Torvalds static void snd_emu10k1_proc_acode_read(snd_info_entry_t *entry,
238*1da177e4SLinus Torvalds 				        snd_info_buffer_t * buffer)
239*1da177e4SLinus Torvalds {
240*1da177e4SLinus Torvalds 	u32 pc;
241*1da177e4SLinus Torvalds 	emu10k1_t *emu = entry->private_data;
242*1da177e4SLinus Torvalds 
243*1da177e4SLinus Torvalds 	snd_iprintf(buffer, "FX8010 Instruction List '%s'\n", emu->fx8010.name);
244*1da177e4SLinus Torvalds 	snd_iprintf(buffer, "  Code dump      :\n");
245*1da177e4SLinus Torvalds 	for (pc = 0; pc < (emu->audigy ? 1024 : 512); pc++) {
246*1da177e4SLinus Torvalds 		u32 low, high;
247*1da177e4SLinus Torvalds 
248*1da177e4SLinus Torvalds 		low = snd_emu10k1_efx_read(emu, pc * 2);
249*1da177e4SLinus Torvalds 		high = snd_emu10k1_efx_read(emu, pc * 2 + 1);
250*1da177e4SLinus Torvalds 		if (emu->audigy)
251*1da177e4SLinus Torvalds 			snd_iprintf(buffer, "    OP(0x%02x, 0x%03x, 0x%03x, 0x%03x, 0x%03x) /* 0x%04x: 0x%08x%08x */\n",
252*1da177e4SLinus Torvalds 				    (high >> 24) & 0x0f,
253*1da177e4SLinus Torvalds 				    (high >> 12) & 0x7ff,
254*1da177e4SLinus Torvalds 				    (high >> 0) & 0x7ff,
255*1da177e4SLinus Torvalds 				    (low >> 12) & 0x7ff,
256*1da177e4SLinus Torvalds 				    (low >> 0) & 0x7ff,
257*1da177e4SLinus Torvalds 				    pc,
258*1da177e4SLinus Torvalds 				    high, low);
259*1da177e4SLinus Torvalds 		else
260*1da177e4SLinus Torvalds 			snd_iprintf(buffer, "    OP(0x%02x, 0x%03x, 0x%03x, 0x%03x, 0x%03x) /* 0x%04x: 0x%08x%08x */\n",
261*1da177e4SLinus Torvalds 				    (high >> 20) & 0x0f,
262*1da177e4SLinus Torvalds 				    (high >> 10) & 0x3ff,
263*1da177e4SLinus Torvalds 				    (high >> 0) & 0x3ff,
264*1da177e4SLinus Torvalds 				    (low >> 10) & 0x3ff,
265*1da177e4SLinus Torvalds 				    (low >> 0) & 0x3ff,
266*1da177e4SLinus Torvalds 				    pc,
267*1da177e4SLinus Torvalds 				    high, low);
268*1da177e4SLinus Torvalds 	}
269*1da177e4SLinus Torvalds }
270*1da177e4SLinus Torvalds 
271*1da177e4SLinus Torvalds #define TOTAL_SIZE_GPR		(0x100*4)
272*1da177e4SLinus Torvalds #define A_TOTAL_SIZE_GPR	(0x200*4)
273*1da177e4SLinus Torvalds #define TOTAL_SIZE_TANKMEM_DATA	(0xa0*4)
274*1da177e4SLinus Torvalds #define TOTAL_SIZE_TANKMEM_ADDR (0xa0*4)
275*1da177e4SLinus Torvalds #define A_TOTAL_SIZE_TANKMEM_DATA (0x100*4)
276*1da177e4SLinus Torvalds #define A_TOTAL_SIZE_TANKMEM_ADDR (0x100*4)
277*1da177e4SLinus Torvalds #define TOTAL_SIZE_CODE		(0x200*8)
278*1da177e4SLinus Torvalds #define A_TOTAL_SIZE_CODE	(0x400*8)
279*1da177e4SLinus Torvalds 
280*1da177e4SLinus Torvalds static long snd_emu10k1_fx8010_read(snd_info_entry_t *entry, void *file_private_data,
281*1da177e4SLinus Torvalds 				    struct file *file, char __user *buf,
282*1da177e4SLinus Torvalds 				    unsigned long count, unsigned long pos)
283*1da177e4SLinus Torvalds {
284*1da177e4SLinus Torvalds 	long size;
285*1da177e4SLinus Torvalds 	emu10k1_t *emu = entry->private_data;
286*1da177e4SLinus Torvalds 	unsigned int offset;
287*1da177e4SLinus Torvalds 	int tram_addr = 0;
288*1da177e4SLinus Torvalds 
289*1da177e4SLinus Torvalds 	if (!strcmp(entry->name, "fx8010_tram_addr")) {
290*1da177e4SLinus Torvalds 		offset = TANKMEMADDRREGBASE;
291*1da177e4SLinus Torvalds 		tram_addr = 1;
292*1da177e4SLinus Torvalds 	} else if (!strcmp(entry->name, "fx8010_tram_data")) {
293*1da177e4SLinus Torvalds 		offset = TANKMEMDATAREGBASE;
294*1da177e4SLinus Torvalds 	} else if (!strcmp(entry->name, "fx8010_code")) {
295*1da177e4SLinus Torvalds 		offset = emu->audigy ? A_MICROCODEBASE : MICROCODEBASE;
296*1da177e4SLinus Torvalds 	} else {
297*1da177e4SLinus Torvalds 		offset = emu->audigy ? A_FXGPREGBASE : FXGPREGBASE;
298*1da177e4SLinus Torvalds 	}
299*1da177e4SLinus Torvalds 	size = count;
300*1da177e4SLinus Torvalds 	if (pos + size > entry->size)
301*1da177e4SLinus Torvalds 		size = (long)entry->size - pos;
302*1da177e4SLinus Torvalds 	if (size > 0) {
303*1da177e4SLinus Torvalds 		unsigned int *tmp;
304*1da177e4SLinus Torvalds 		long res;
305*1da177e4SLinus Torvalds 		unsigned int idx;
306*1da177e4SLinus Torvalds 		if ((tmp = kmalloc(size + 8, GFP_KERNEL)) == NULL)
307*1da177e4SLinus Torvalds 			return -ENOMEM;
308*1da177e4SLinus Torvalds 		for (idx = 0; idx < ((pos & 3) + size + 3) >> 2; idx++)
309*1da177e4SLinus Torvalds 			if (tram_addr && emu->audigy) {
310*1da177e4SLinus Torvalds 				tmp[idx] = snd_emu10k1_ptr_read(emu, offset + idx + (pos >> 2), 0) >> 11;
311*1da177e4SLinus Torvalds 				tmp[idx] |= snd_emu10k1_ptr_read(emu, 0x100 + idx + (pos >> 2), 0) << 20;
312*1da177e4SLinus Torvalds 			} else
313*1da177e4SLinus Torvalds 				tmp[idx] = snd_emu10k1_ptr_read(emu, offset + idx + (pos >> 2), 0);
314*1da177e4SLinus Torvalds 		if (copy_to_user(buf, ((char *)tmp) + (pos & 3), size))
315*1da177e4SLinus Torvalds 			res = -EFAULT;
316*1da177e4SLinus Torvalds 		else {
317*1da177e4SLinus Torvalds 			res = size;
318*1da177e4SLinus Torvalds 		}
319*1da177e4SLinus Torvalds 		kfree(tmp);
320*1da177e4SLinus Torvalds 		return res;
321*1da177e4SLinus Torvalds 	}
322*1da177e4SLinus Torvalds 	return 0;
323*1da177e4SLinus Torvalds }
324*1da177e4SLinus Torvalds 
325*1da177e4SLinus Torvalds static void snd_emu10k1_proc_voices_read(snd_info_entry_t *entry,
326*1da177e4SLinus Torvalds 				  snd_info_buffer_t * buffer)
327*1da177e4SLinus Torvalds {
328*1da177e4SLinus Torvalds 	emu10k1_t *emu = entry->private_data;
329*1da177e4SLinus Torvalds 	emu10k1_voice_t *voice;
330*1da177e4SLinus Torvalds 	int idx;
331*1da177e4SLinus Torvalds 
332*1da177e4SLinus Torvalds 	snd_iprintf(buffer, "ch\tuse\tpcm\tefx\tsynth\tmidi\n");
333*1da177e4SLinus Torvalds 	for (idx = 0; idx < NUM_G; idx++) {
334*1da177e4SLinus Torvalds 		voice = &emu->voices[idx];
335*1da177e4SLinus Torvalds 		snd_iprintf(buffer, "%i\t%i\t%i\t%i\t%i\t%i\n",
336*1da177e4SLinus Torvalds 			idx,
337*1da177e4SLinus Torvalds 			voice->use,
338*1da177e4SLinus Torvalds 			voice->pcm,
339*1da177e4SLinus Torvalds 			voice->efx,
340*1da177e4SLinus Torvalds 			voice->synth,
341*1da177e4SLinus Torvalds 			voice->midi);
342*1da177e4SLinus Torvalds 	}
343*1da177e4SLinus Torvalds }
344*1da177e4SLinus Torvalds 
345*1da177e4SLinus Torvalds #ifdef CONFIG_SND_DEBUG
346*1da177e4SLinus Torvalds static void snd_emu_proc_io_reg_read(snd_info_entry_t *entry,
347*1da177e4SLinus Torvalds 				     snd_info_buffer_t * buffer)
348*1da177e4SLinus Torvalds {
349*1da177e4SLinus Torvalds 	emu10k1_t *emu = entry->private_data;
350*1da177e4SLinus Torvalds 	unsigned long value;
351*1da177e4SLinus Torvalds 	unsigned long flags;
352*1da177e4SLinus Torvalds 	int i;
353*1da177e4SLinus Torvalds 	snd_iprintf(buffer, "IO Registers:\n\n");
354*1da177e4SLinus Torvalds 	for(i = 0; i < 0x40; i+=4) {
355*1da177e4SLinus Torvalds 		spin_lock_irqsave(&emu->emu_lock, flags);
356*1da177e4SLinus Torvalds 		value = inl(emu->port + i);
357*1da177e4SLinus Torvalds 		spin_unlock_irqrestore(&emu->emu_lock, flags);
358*1da177e4SLinus Torvalds 		snd_iprintf(buffer, "%02X: %08lX\n", i, value);
359*1da177e4SLinus Torvalds 	}
360*1da177e4SLinus Torvalds }
361*1da177e4SLinus Torvalds 
362*1da177e4SLinus Torvalds static void snd_emu_proc_io_reg_write(snd_info_entry_t *entry,
363*1da177e4SLinus Torvalds                                       snd_info_buffer_t * buffer)
364*1da177e4SLinus Torvalds {
365*1da177e4SLinus Torvalds 	emu10k1_t *emu = entry->private_data;
366*1da177e4SLinus Torvalds 	unsigned long flags;
367*1da177e4SLinus Torvalds 	char line[64];
368*1da177e4SLinus Torvalds 	u32 reg, val;
369*1da177e4SLinus Torvalds 	while (!snd_info_get_line(buffer, line, sizeof(line))) {
370*1da177e4SLinus Torvalds 		if (sscanf(line, "%x %x", &reg, &val) != 2)
371*1da177e4SLinus Torvalds 			continue;
372*1da177e4SLinus Torvalds 		if ((reg < 0x40) && (reg >=0) && (val <= 0xffffffff) ) {
373*1da177e4SLinus Torvalds 			spin_lock_irqsave(&emu->emu_lock, flags);
374*1da177e4SLinus Torvalds 			outl(val, emu->port + (reg & 0xfffffffc));
375*1da177e4SLinus Torvalds 			spin_unlock_irqrestore(&emu->emu_lock, flags);
376*1da177e4SLinus Torvalds 		}
377*1da177e4SLinus Torvalds 	}
378*1da177e4SLinus Torvalds }
379*1da177e4SLinus Torvalds 
380*1da177e4SLinus Torvalds static unsigned int snd_ptr_read(emu10k1_t * emu,
381*1da177e4SLinus Torvalds 				 unsigned int iobase,
382*1da177e4SLinus Torvalds 				 unsigned int reg,
383*1da177e4SLinus Torvalds 				 unsigned int chn)
384*1da177e4SLinus Torvalds {
385*1da177e4SLinus Torvalds 	unsigned long flags;
386*1da177e4SLinus Torvalds 	unsigned int regptr, val;
387*1da177e4SLinus Torvalds 
388*1da177e4SLinus Torvalds 	regptr = (reg << 16) | chn;
389*1da177e4SLinus Torvalds 
390*1da177e4SLinus Torvalds 	spin_lock_irqsave(&emu->emu_lock, flags);
391*1da177e4SLinus Torvalds 	outl(regptr, emu->port + iobase + PTR);
392*1da177e4SLinus Torvalds 	val = inl(emu->port + iobase + DATA);
393*1da177e4SLinus Torvalds 	spin_unlock_irqrestore(&emu->emu_lock, flags);
394*1da177e4SLinus Torvalds 	return val;
395*1da177e4SLinus Torvalds }
396*1da177e4SLinus Torvalds 
397*1da177e4SLinus Torvalds static void snd_ptr_write(emu10k1_t *emu,
398*1da177e4SLinus Torvalds 			  unsigned int iobase,
399*1da177e4SLinus Torvalds 			  unsigned int reg,
400*1da177e4SLinus Torvalds 			  unsigned int chn,
401*1da177e4SLinus Torvalds 			  unsigned int data)
402*1da177e4SLinus Torvalds {
403*1da177e4SLinus Torvalds 	unsigned int regptr;
404*1da177e4SLinus Torvalds 	unsigned long flags;
405*1da177e4SLinus Torvalds 
406*1da177e4SLinus Torvalds 	regptr = (reg << 16) | chn;
407*1da177e4SLinus Torvalds 
408*1da177e4SLinus Torvalds 	spin_lock_irqsave(&emu->emu_lock, flags);
409*1da177e4SLinus Torvalds 	outl(regptr, emu->port + iobase + PTR);
410*1da177e4SLinus Torvalds 	outl(data, emu->port + iobase + DATA);
411*1da177e4SLinus Torvalds 	spin_unlock_irqrestore(&emu->emu_lock, flags);
412*1da177e4SLinus Torvalds }
413*1da177e4SLinus Torvalds 
414*1da177e4SLinus Torvalds 
415*1da177e4SLinus Torvalds static void snd_emu_proc_ptr_reg_read(snd_info_entry_t *entry,
416*1da177e4SLinus Torvalds 				      snd_info_buffer_t * buffer, int iobase, int offset, int length, int voices)
417*1da177e4SLinus Torvalds {
418*1da177e4SLinus Torvalds 	emu10k1_t *emu = entry->private_data;
419*1da177e4SLinus Torvalds 	unsigned long value;
420*1da177e4SLinus Torvalds 	int i,j;
421*1da177e4SLinus Torvalds 	if (offset+length > 0x80) {
422*1da177e4SLinus Torvalds 		snd_iprintf(buffer, "Input values out of range\n");
423*1da177e4SLinus Torvalds 		return;
424*1da177e4SLinus Torvalds 	}
425*1da177e4SLinus Torvalds 	snd_iprintf(buffer, "Registers 0x%x\n", iobase);
426*1da177e4SLinus Torvalds 	for(i = offset; i < offset+length; i++) {
427*1da177e4SLinus Torvalds 		snd_iprintf(buffer, "%02X: ",i);
428*1da177e4SLinus Torvalds 		for (j = 0; j < voices; j++) {
429*1da177e4SLinus Torvalds 			if(iobase == 0)
430*1da177e4SLinus Torvalds                 		value = snd_ptr_read(emu, 0, i, j);
431*1da177e4SLinus Torvalds 			else
432*1da177e4SLinus Torvalds                 		value = snd_ptr_read(emu, 0x20, i, j);
433*1da177e4SLinus Torvalds 			snd_iprintf(buffer, "%08lX ", value);
434*1da177e4SLinus Torvalds 		}
435*1da177e4SLinus Torvalds 		snd_iprintf(buffer, "\n");
436*1da177e4SLinus Torvalds 	}
437*1da177e4SLinus Torvalds }
438*1da177e4SLinus Torvalds 
439*1da177e4SLinus Torvalds static void snd_emu_proc_ptr_reg_write(snd_info_entry_t *entry,
440*1da177e4SLinus Torvalds 				       snd_info_buffer_t * buffer, int iobase)
441*1da177e4SLinus Torvalds {
442*1da177e4SLinus Torvalds 	emu10k1_t *emu = entry->private_data;
443*1da177e4SLinus Torvalds 	char line[64];
444*1da177e4SLinus Torvalds 	unsigned int reg, channel_id , val;
445*1da177e4SLinus Torvalds 	while (!snd_info_get_line(buffer, line, sizeof(line))) {
446*1da177e4SLinus Torvalds 		if (sscanf(line, "%x %x %x", &reg, &channel_id, &val) != 3)
447*1da177e4SLinus Torvalds 			continue;
448*1da177e4SLinus Torvalds 		if ((reg < 0x80) && (reg >=0) && (val <= 0xffffffff) && (channel_id >=0) && (channel_id <= 3) )
449*1da177e4SLinus Torvalds 			snd_ptr_write(emu, iobase, reg, channel_id, val);
450*1da177e4SLinus Torvalds 	}
451*1da177e4SLinus Torvalds }
452*1da177e4SLinus Torvalds 
453*1da177e4SLinus Torvalds static void snd_emu_proc_ptr_reg_write00(snd_info_entry_t *entry,
454*1da177e4SLinus Torvalds 					 snd_info_buffer_t * buffer)
455*1da177e4SLinus Torvalds {
456*1da177e4SLinus Torvalds 	snd_emu_proc_ptr_reg_write(entry, buffer, 0);
457*1da177e4SLinus Torvalds }
458*1da177e4SLinus Torvalds 
459*1da177e4SLinus Torvalds static void snd_emu_proc_ptr_reg_write20(snd_info_entry_t *entry,
460*1da177e4SLinus Torvalds 					 snd_info_buffer_t * buffer)
461*1da177e4SLinus Torvalds {
462*1da177e4SLinus Torvalds 	snd_emu_proc_ptr_reg_write(entry, buffer, 0x20);
463*1da177e4SLinus Torvalds }
464*1da177e4SLinus Torvalds 
465*1da177e4SLinus Torvalds 
466*1da177e4SLinus Torvalds static void snd_emu_proc_ptr_reg_read00a(snd_info_entry_t *entry,
467*1da177e4SLinus Torvalds 					 snd_info_buffer_t * buffer)
468*1da177e4SLinus Torvalds {
469*1da177e4SLinus Torvalds 	snd_emu_proc_ptr_reg_read(entry, buffer, 0, 0, 0x40, 64);
470*1da177e4SLinus Torvalds }
471*1da177e4SLinus Torvalds 
472*1da177e4SLinus Torvalds static void snd_emu_proc_ptr_reg_read00b(snd_info_entry_t *entry,
473*1da177e4SLinus Torvalds 					 snd_info_buffer_t * buffer)
474*1da177e4SLinus Torvalds {
475*1da177e4SLinus Torvalds 	snd_emu_proc_ptr_reg_read(entry, buffer, 0, 0x40, 0x40, 64);
476*1da177e4SLinus Torvalds }
477*1da177e4SLinus Torvalds 
478*1da177e4SLinus Torvalds static void snd_emu_proc_ptr_reg_read20a(snd_info_entry_t *entry,
479*1da177e4SLinus Torvalds 					 snd_info_buffer_t * buffer)
480*1da177e4SLinus Torvalds {
481*1da177e4SLinus Torvalds 	snd_emu_proc_ptr_reg_read(entry, buffer, 0x20, 0, 0x40, 4);
482*1da177e4SLinus Torvalds }
483*1da177e4SLinus Torvalds 
484*1da177e4SLinus Torvalds static void snd_emu_proc_ptr_reg_read20b(snd_info_entry_t *entry,
485*1da177e4SLinus Torvalds 					 snd_info_buffer_t * buffer)
486*1da177e4SLinus Torvalds {
487*1da177e4SLinus Torvalds 	snd_emu_proc_ptr_reg_read(entry, buffer, 0x20, 0x40, 0x40, 4);
488*1da177e4SLinus Torvalds }
489*1da177e4SLinus Torvalds #endif
490*1da177e4SLinus Torvalds 
491*1da177e4SLinus Torvalds static struct snd_info_entry_ops snd_emu10k1_proc_ops_fx8010 = {
492*1da177e4SLinus Torvalds 	.read = snd_emu10k1_fx8010_read,
493*1da177e4SLinus Torvalds };
494*1da177e4SLinus Torvalds 
495*1da177e4SLinus Torvalds int __devinit snd_emu10k1_proc_init(emu10k1_t * emu)
496*1da177e4SLinus Torvalds {
497*1da177e4SLinus Torvalds 	snd_info_entry_t *entry;
498*1da177e4SLinus Torvalds #ifdef CONFIG_SND_DEBUG
499*1da177e4SLinus Torvalds 	if (! snd_card_proc_new(emu->card, "io_regs", &entry)) {
500*1da177e4SLinus Torvalds 		snd_info_set_text_ops(entry, emu, 1024, snd_emu_proc_io_reg_read);
501*1da177e4SLinus Torvalds 		entry->c.text.write_size = 64;
502*1da177e4SLinus Torvalds 		entry->c.text.write = snd_emu_proc_io_reg_write;
503*1da177e4SLinus Torvalds 	}
504*1da177e4SLinus Torvalds 	if (! snd_card_proc_new(emu->card, "ptr_regs00a", &entry)) {
505*1da177e4SLinus Torvalds 		snd_info_set_text_ops(entry, emu, 65536, snd_emu_proc_ptr_reg_read00a);
506*1da177e4SLinus Torvalds 		entry->c.text.write_size = 64;
507*1da177e4SLinus Torvalds 		entry->c.text.write = snd_emu_proc_ptr_reg_write00;
508*1da177e4SLinus Torvalds 	}
509*1da177e4SLinus Torvalds 	if (! snd_card_proc_new(emu->card, "ptr_regs00b", &entry)) {
510*1da177e4SLinus Torvalds 		snd_info_set_text_ops(entry, emu, 65536, snd_emu_proc_ptr_reg_read00b);
511*1da177e4SLinus Torvalds 		entry->c.text.write_size = 64;
512*1da177e4SLinus Torvalds 		entry->c.text.write = snd_emu_proc_ptr_reg_write00;
513*1da177e4SLinus Torvalds 	}
514*1da177e4SLinus Torvalds 	if (! snd_card_proc_new(emu->card, "ptr_regs20a", &entry)) {
515*1da177e4SLinus Torvalds 		snd_info_set_text_ops(entry, emu, 65536, snd_emu_proc_ptr_reg_read20a);
516*1da177e4SLinus Torvalds 		entry->c.text.write_size = 64;
517*1da177e4SLinus Torvalds 		entry->c.text.write = snd_emu_proc_ptr_reg_write20;
518*1da177e4SLinus Torvalds 	}
519*1da177e4SLinus Torvalds 	if (! snd_card_proc_new(emu->card, "ptr_regs20b", &entry)) {
520*1da177e4SLinus Torvalds 		snd_info_set_text_ops(entry, emu, 65536, snd_emu_proc_ptr_reg_read20b);
521*1da177e4SLinus Torvalds 		entry->c.text.write_size = 64;
522*1da177e4SLinus Torvalds 		entry->c.text.write = snd_emu_proc_ptr_reg_write20;
523*1da177e4SLinus Torvalds 	}
524*1da177e4SLinus Torvalds #endif
525*1da177e4SLinus Torvalds 
526*1da177e4SLinus Torvalds 	if (! snd_card_proc_new(emu->card, "emu10k1", &entry))
527*1da177e4SLinus Torvalds 		snd_info_set_text_ops(entry, emu, 2048, snd_emu10k1_proc_read);
528*1da177e4SLinus Torvalds 
529*1da177e4SLinus Torvalds 	if (! snd_card_proc_new(emu->card, "voices", &entry))
530*1da177e4SLinus Torvalds 		snd_info_set_text_ops(entry, emu, 2048, snd_emu10k1_proc_voices_read);
531*1da177e4SLinus Torvalds 
532*1da177e4SLinus Torvalds 	if (! snd_card_proc_new(emu->card, "fx8010_gpr", &entry)) {
533*1da177e4SLinus Torvalds 		entry->content = SNDRV_INFO_CONTENT_DATA;
534*1da177e4SLinus Torvalds 		entry->private_data = emu;
535*1da177e4SLinus Torvalds 		entry->mode = S_IFREG | S_IRUGO /*| S_IWUSR*/;
536*1da177e4SLinus Torvalds 		entry->size = emu->audigy ? A_TOTAL_SIZE_GPR : TOTAL_SIZE_GPR;
537*1da177e4SLinus Torvalds 		entry->c.ops = &snd_emu10k1_proc_ops_fx8010;
538*1da177e4SLinus Torvalds 	}
539*1da177e4SLinus Torvalds 	if (! snd_card_proc_new(emu->card, "fx8010_tram_data", &entry)) {
540*1da177e4SLinus Torvalds 		entry->content = SNDRV_INFO_CONTENT_DATA;
541*1da177e4SLinus Torvalds 		entry->private_data = emu;
542*1da177e4SLinus Torvalds 		entry->mode = S_IFREG | S_IRUGO /*| S_IWUSR*/;
543*1da177e4SLinus Torvalds 		entry->size = emu->audigy ? A_TOTAL_SIZE_TANKMEM_DATA : TOTAL_SIZE_TANKMEM_DATA ;
544*1da177e4SLinus Torvalds 		entry->c.ops = &snd_emu10k1_proc_ops_fx8010;
545*1da177e4SLinus Torvalds 	}
546*1da177e4SLinus Torvalds 	if (! snd_card_proc_new(emu->card, "fx8010_tram_addr", &entry)) {
547*1da177e4SLinus Torvalds 		entry->content = SNDRV_INFO_CONTENT_DATA;
548*1da177e4SLinus Torvalds 		entry->private_data = emu;
549*1da177e4SLinus Torvalds 		entry->mode = S_IFREG | S_IRUGO /*| S_IWUSR*/;
550*1da177e4SLinus Torvalds 		entry->size = emu->audigy ? A_TOTAL_SIZE_TANKMEM_ADDR : TOTAL_SIZE_TANKMEM_ADDR ;
551*1da177e4SLinus Torvalds 		entry->c.ops = &snd_emu10k1_proc_ops_fx8010;
552*1da177e4SLinus Torvalds 	}
553*1da177e4SLinus Torvalds 	if (! snd_card_proc_new(emu->card, "fx8010_code", &entry)) {
554*1da177e4SLinus Torvalds 		entry->content = SNDRV_INFO_CONTENT_DATA;
555*1da177e4SLinus Torvalds 		entry->private_data = emu;
556*1da177e4SLinus Torvalds 		entry->mode = S_IFREG | S_IRUGO /*| S_IWUSR*/;
557*1da177e4SLinus Torvalds 		entry->size = emu->audigy ? A_TOTAL_SIZE_CODE : TOTAL_SIZE_CODE;
558*1da177e4SLinus Torvalds 		entry->c.ops = &snd_emu10k1_proc_ops_fx8010;
559*1da177e4SLinus Torvalds 	}
560*1da177e4SLinus Torvalds 	if (! snd_card_proc_new(emu->card, "fx8010_acode", &entry)) {
561*1da177e4SLinus Torvalds 		entry->content = SNDRV_INFO_CONTENT_TEXT;
562*1da177e4SLinus Torvalds 		entry->private_data = emu;
563*1da177e4SLinus Torvalds 		entry->mode = S_IFREG | S_IRUGO /*| S_IWUSR*/;
564*1da177e4SLinus Torvalds 		entry->c.text.read_size = 128*1024;
565*1da177e4SLinus Torvalds 		entry->c.text.read = snd_emu10k1_proc_acode_read;
566*1da177e4SLinus Torvalds 	}
567*1da177e4SLinus Torvalds 	return 0;
568*1da177e4SLinus Torvalds }
569