1 /*
2 * Copyright (c) 1999 Doug Rabson
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27 #include <dev/sound/pcm/sound.h>
28 #include <dev/sound/isa/sb.h>
29
30 SND_DECLARE_FILE("$FreeBSD: releng/5.0/sys/dev/sound/isa/es1888.c 82180 2001-08-23 11:30:52Z cg $");
31
32 #ifdef __alpha__
33 static int
34 es1888_dspready(u_int32_t port)
35 {
36 return ((inb(port + SBDSP_STATUS) & 0x80) == 0);
37 }
38
39 static int
40 es1888_dspwr(u_int32_t port, u_char val)
41 {
42 int i;
43
44 for (i = 0; i < 1000; i++) {
45 if (es1888_dspready(port)) {
46 outb(port + SBDSP_CMD, val);
47 return 0;
48 }
49 if (i > 10) DELAY((i > 100)? 1000 : 10);
50 }
51 return ENXIO;
52 }
53
54 static u_int
55 es1888_get_byte(u_int32_t port)
56 {
57 int i;
58
59 for (i = 1000; i > 0; i--) {
60 if (inb(port + DSP_DATA_AVAIL) & 0x80)
61 return inb(port + DSP_READ);
62 else
63 DELAY(20);
64 }
65 return 0xffff;
66 }
67
68 static int
69 es1888_reset(u_int32_t port)
70 {
71 outb(port + SBDSP_RST, 3);
72 DELAY(100);
73 outb(port + SBDSP_RST, 0);
74 if (es1888_get_byte(port) != 0xAA) {
75 return ENXIO; /* Sorry */
76 }
77 return 0;
78 }
79
80 static void
81 es1888_configuration_mode(void)
82 {
83 /*
84 * Emit the Read-Sequence-Key to enter configuration
85 * mode. Note this only works after a reset (or after bit 2 of
86 * mixer register 0x40 is set).
87 *
88 * 3 reads from 0x229 in a row guarantees reset of key
89 * sequence to beginning.
90 */
91 inb(0x229);
92 inb(0x229);
93 inb(0x229);
94
95 inb(0x22b); /* state 1 */
96 inb(0x229); /* state 2 */
97 inb(0x22b); /* state 3 */
98 inb(0x229); /* state 4 */
99 inb(0x229); /* state 5 */
100 inb(0x22b); /* state 6 */
101 inb(0x229); /* state 7 */
102 }
103
104 static void
105 es1888_set_port(u_int32_t port)
106 {
107 es1888_configuration_mode();
108 inb(port);
109 }
110 #endif
111
112 static void
113 es1888_identify(driver_t *driver, device_t parent)
114 {
115 /*
116 * Only use this on alpha since PNPBIOS is a better solution on x86.
117 */
118 #ifdef __alpha__
119 u_int32_t lo, hi;
120 device_t dev;
121
122 es1888_set_port(0x220);
123 if (es1888_reset(0x220))
124 return;
125
126 /*
127 * Check identification bytes for es1888.
128 */
129 if (es1888_dspwr(0x220, 0xe7))
130 return;
131 hi = es1888_get_byte(0x220);
132 lo = es1888_get_byte(0x220);
133 if (hi != 0x68 || (lo & 0xf0) != 0x80)
134 return;
135
136 /*
137 * Program irq and drq.
138 */
139 if (es1888_dspwr(0x220, 0xc6) /* enter extended mode */
140 || es1888_dspwr(0x220, 0xb1) /* write register b1 */
141 || es1888_dspwr(0x220, 0x14) /* enable irq 5 */
142 || es1888_dspwr(0x220, 0xb2) /* write register b1 */
143 || es1888_dspwr(0x220, 0x18)) /* enable drq 1 */
144 return;
145
146 /*
147 * Create the device and program its resources.
148 */
149 dev = BUS_ADD_CHILD(parent, ISA_ORDER_PNP, NULL, -1);
150 bus_set_resource(dev, SYS_RES_IOPORT, 0, 0x220, 0x10);
151 bus_set_resource(dev, SYS_RES_IRQ, 0, 5, 1);
152 bus_set_resource(dev, SYS_RES_DRQ, 0, 1, 1);
153 isa_set_vendorid(dev, PNP_EISAID("ESS1888"));
154 isa_set_logicalid(dev, PNP_EISAID("ESS1888"));
155 #endif
156 }
157
158 static device_method_t es1888_methods[] = {
159 /* Device interface */
160 DEVMETHOD(device_identify, es1888_identify),
161
162 { 0, 0 }
163 };
164
165 static driver_t es1888_driver = {
166 "pcm",
167 es1888_methods,
168 1, /* no softc */
169 };
170
171 DRIVER_MODULE(snd_es1888, isa, es1888_driver, pcm_devclass, 0, 0);
172 MODULE_DEPEND(snd_es1888, snd_pcm, PCM_MINVER, PCM_PREFVER, PCM_MAXVER);
173 MODULE_VERSION(snd_es1888, 1);
174
175
Cache object: 6a749b9ca71ae3b84924f8bb7c973d91
|