File: es1688.c

package info (click to toggle)
alsadriver 0.4.1i-5
  • links: PTS
  • area: main
  • in suites: potato
  • size: 5,256 kB
  • ctags: 15,024
  • sloc: ansic: 96,846; makefile: 1,232; sh: 1,051; perl: 54
file content (270 lines) | stat: -rw-r--r-- 6,898 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
/*
 *  Copyright (c) by Jaroslav Kysela <perex@suse.cz>
 *  Detection routines for ESS ESx688/488 chip
 *
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program; if not, write to the Free Software
 *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 */

#include "../include/driver.h"
#include "../include/pcm.h"
#include "../include/mixer.h"
#include "../include/es1688.h"

#define DES1688P( port, reg ) ( port + e_s_s_ESS1688##reg )

#ifdef CONFIG_SND_GUS
extern int snd_detect_gus1(snd_card_t * card, char *rname,
                           unsigned int *rtype, unsigned short port);
#endif

static int snd_es1688_ddsp_command(unsigned short port, unsigned char val)
{
	int i;

	for (i = 10000; i; i--)
		if ((inb(DES1688P(port, STATUS)) & 0x80) == 0) {
			outb(val, DES1688P(port, COMMAND));
			return 1;
		}
	snd_printd("snd_es1688_dsp_command: timeout (0x%x)\n", val);
	return 0;
}

#if 0

static int snd_es1688_ddsp_get_byte(unsigned short port)
{
	int i;

	for (i = 1000; i; i--)
		if (inb(DES1688P(port, DATA_AVAIL)) & 0x80)
			return inb(DES1688P(port, READ));
	PRINTD("snd es1688 get byte failed: 0x%x = 0x%x!!!\n", DES1688P(port, DATA_AVAIL), inb(DES1688P(port, DATA_AVAIL)));
	return -ENODEV;
}

static int snd_es1688_dwrite(unsigned short port,
                             unsigned char reg, unsigned char data)
{
	if (!snd_es1688_ddsp_command(port, reg))
		return 0;
	return snd_es1688_ddsp_command(port, data);
}

static int snd_es1688_dread(unsigned short port, unsigned char reg)
{
	/* Read a byte from an extended mode register of ES1688 */
	if (!snd_es1688_ddsp_command(port, 0xc0))
		return -1;
	if (!snd_es1688_ddsp_command(port, reg))
		return -1;
	return snd_es1688_ddsp_get_byte(port);
}

#endif

#ifdef CONFIG_SND_GUS

static void snd_es1688_dmixer_write(unsigned short port,
			            unsigned char reg, unsigned char data)
{
	unsigned long flags;

	save_flags(flags);
	cli();
	outb(reg, DES1688P(port, MIXER_ADDR));
	snd_delay(1);
	outb(data, DES1688P(port, MIXER_DATA));
	snd_delay(1);
	restore_flags(flags);
}

#endif

#if 0

static unsigned char snd_es1688_dmixer_read(unsigned short port,
                                            unsigned char reg)
{
	unsigned long flags;
	unsigned char result;

	save_flags(flags);
	cli();
	outb(reg, DES1688P(port, MIXER_ADDR));
	snd_delay(1);
	result = inb(DES1688P(port, MIXER_DATA));
	snd_delay(1);
	restore_flags(flags);
	return result;
}

#endif

static int snd_es1688_reset(unsigned short port)
{
	int i;

	outb(3, DES1688P(port, RESET));		/* valid only for ESS chips, SB -> 1 */
	snd_delay(1);
	outb(0, DES1688P(port, RESET));
	snd_delay(3);
	for (i = 0; i < 1000 && !(inb(DES1688P(port, DATA_AVAIL)) & 0x80); i++);
	if (inb(DES1688P(port, READ)) != 0xaa) {
		snd_printdd("ess_reset: failed!!!\n");
		return -ENODEV;
	}
	snd_es1688_ddsp_command(port, 0xc6);	/* enable extended mode */
	return 0;
}

int snd_detect_es1688(snd_card_t * card, char *rname, unsigned int *rtype, unsigned short *rport)
{
	static short possible_ports[] =
	{0x220, 0x240, 0x260, -1};
	unsigned long flags;
	unsigned short major, minor, version;
	short *pport, port;
	int i;
#ifdef CONFIG_SND_GUS
	int gport;
#endif

	for (pport = possible_ports; *pport > 0; pport++) {
		port = *rport = *pport;

		if (snd_register_ioport(card, port, 16, "ESS AudioDrive", NULL) < 0)
			continue;

		/*
		 *  initialization sequence
		 */

		save_flags(flags);	/* Some ESS1688 cards need this */
		cli();
		inb(DES1688P(port, ENABLE1));
		inb(DES1688P(port, ENABLE1));
		inb(DES1688P(port, ENABLE1));
		inb(DES1688P(port, ENABLE2));
		inb(DES1688P(port, ENABLE1));
		inb(DES1688P(port, ENABLE2));
		inb(DES1688P(port, ENABLE1));
		inb(DES1688P(port, ENABLE1));
		inb(DES1688P(port, ENABLE2));
		inb(DES1688P(port, ENABLE1));
		inb(DES1688P(port, ENABLE0));
		restore_flags(flags);

		if (snd_es1688_reset(port) < 0) {
			snd_printdd("ESS: [0x%x] reset failed... 0x%x\n", port, inb(DES1688P(port, READ)));
			goto __nodev;
		}
		snd_es1688_ddsp_command(port, 0xe7);	/* return identification */

		for (i = 1000, major = minor = 0; i; i--) {
			if (inb(DES1688P(port, DATA_AVAIL)) & 0x80) {
				if (major == 0) {
					major = inb(DES1688P(port, READ));
				} else {
					minor = inb(DES1688P(port, READ));
				}
			}
		}

		snd_printdd("ESS: [0x%x] found.. major = 0x%x, minor = 0x%x\n", port, major, minor);

		version = (major << 8) | minor;
		if (!version)
			goto __nodev;	/* probably SB */
		switch (version & 0xfff0) {
		case 0x4880:
			strcpy(rname, "SoundBlaster Pro (ESS AudioDrive ES488)");
			*rtype = SND_CARD_TYPE_SB_PRO;
			return 0;
		case 0x6880:
			goto __es1688;
		default:
			snd_printk("detect: ESS AudioDrive chip found at 0x%x, but version 0x%x isn't known\n", port, version);
			goto __nodev;
		}

	      __es1688:

#ifdef CONFIG_SND_GUS
		/*
		 *  check if we have GUS Extreme, don't try initialize other ESS cards
		 */

		i = inb(DES1688P(port, INIT1));
		snd_printdd("ESS: [0x%x] (1) init1 = 0x%x\n", port, i);
		if (!(i & 0x40))
			goto __plain_es1688;
		outb(0, DES1688P(port, INIT1));
		i = inb(DES1688P(port, INIT1));
		snd_printdd("ESS: [0x%x] (2) init1 = 0x%x\n", port, i);
		if (i != 0x40)
			goto __plain_es1688;

		/*
		 * This is main stuff - enable access to GF1 chip...
		 * I'm not sure, if this will work for card which have
		 * ES 1688 chip in another place than 0x220.
		 *
		 * ULTRINIT.EXE:
		 * 0x230 = 0,2,3
		 * 0x240 = 2,0,1
		 * 0x250 = 2,0,3
		 * 0x260 = 2,2,1
		 */

		snd_es1688_dmixer_write(port, 0x40, 0x8b);

		for (gport = 0x210; gport < 0x270; gport += 0x20)
			if (snd_check_ioport(card, gport, 16) >= 0)
				break;

		if (gport > 0x270)
			goto __plain_es1688;

		save_flags(flags);
		cli();
		outb(gport & 0x0040 ? 2 : 0, DES1688P(port, INIT1));
		outb(0, 0x201);
		outb(gport & 0x0020 ? 2 : 0, DES1688P(port, INIT1));
		outb(0, 0x201);
		outb(gport & 0x0010 ? 3 : 1, DES1688P(port, INIT1));
		restore_flags(flags);

		if (!snd_detect_gus1(card, rname, rtype, gport))
			return 0;

		snd_unregister_ioports(card);
		if (snd_register_ioport(card, port, 16, "ESS AudioDrive", NULL) < 0)
			continue;

	      __plain_es1688:
#endif /* CONFIG_SND_GUS */
		strcpy(rname, "ESS AudioDrive ES1688");
		*rtype = SND_CARD_TYPE_ESS_ES1688;
		return 0;

	      __nodev:
		snd_unregister_ioports(card);
	}

	return -ENODEV;
}