Add another parameter to BUS_ADD_CHILD to allow children to inherit
[dragonfly.git] / sys / dev / sound / isa / es1888.c
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  * $FreeBSD: src/sys/dev/sound/isa/es1888.c,v 1.5.2.5 2002/04/22 15:49:30 cg Exp $
27  * $DragonFly: src/sys/dev/sound/isa/Attic/es1888.c,v 1.4 2005/10/30 04:41:15 dillon Exp $
28  */
29
30 #include <dev/sound/pcm/sound.h>
31 #include <dev/sound/isa/sb.h>
32
33 SND_DECLARE_FILE("$DragonFly: src/sys/dev/sound/isa/Attic/es1888.c,v 1.4 2005/10/30 04:41:15 dillon Exp $");
34
35 #ifdef __alpha__
36 static int
37 es1888_dspready(u_int32_t port)
38 {
39         return ((inb(port + SBDSP_STATUS) & 0x80) == 0);
40 }
41
42 static int
43 es1888_dspwr(u_int32_t port, u_char val)
44 {
45         int  i;
46
47         for (i = 0; i < 1000; i++) {
48                 if (es1888_dspready(port)) {
49                         outb(port + SBDSP_CMD, val);
50                         return 0;
51                 }
52                 if (i > 10) DELAY((i > 100)? 1000 : 10);
53         }
54         return ENXIO;
55 }
56
57 static u_int
58 es1888_get_byte(u_int32_t port)
59 {
60         int i;
61
62         for (i = 1000; i > 0; i--) {
63                 if (inb(port + DSP_DATA_AVAIL) & 0x80)
64                         return inb(port + DSP_READ);
65                 else
66                         DELAY(20);
67         }
68         return 0xffff;
69 }
70
71 static int
72 es1888_reset(u_int32_t port)
73 {
74         outb(port + SBDSP_RST, 3);
75         DELAY(100);
76         outb(port + SBDSP_RST, 0);
77         if (es1888_get_byte(port) != 0xAA) {
78                 return ENXIO;   /* Sorry */
79         }
80         return 0;
81 }
82
83 static void
84 es1888_configuration_mode(void)
85 {
86         /*
87          * Emit the Read-Sequence-Key to enter configuration
88          * mode. Note this only works after a reset (or after bit 2 of
89          * mixer register 0x40 is set).
90          *
91          * 3 reads from 0x229 in a row guarantees reset of key
92          * sequence to beginning.
93          */
94         inb(0x229);
95         inb(0x229);
96         inb(0x229);
97
98         inb(0x22b);             /* state 1 */
99         inb(0x229);             /* state 2 */
100         inb(0x22b);             /* state 3 */
101         inb(0x229);             /* state 4 */
102         inb(0x229);             /* state 5 */
103         inb(0x22b);             /* state 6 */
104         inb(0x229);             /* state 7 */
105 }
106
107 static void
108 es1888_set_port(u_int32_t port)
109 {
110         es1888_configuration_mode();
111         inb(port);
112 }
113 #endif
114
115 static int
116 es1888_identify(driver_t *driver, device_t parent)
117 {
118         /*
119          * We do not suppot rescans
120          */
121         if (device_get_state(parent) == DS_ATTACHED)
122                 return (0);
123
124         /*
125          * Only use this on alpha since PNPBIOS is a better solution on x86.
126          */
127 #ifdef __alpha__
128         u_int32_t lo, hi;
129         device_t dev;
130
131         es1888_set_port(0x220);
132         if (es1888_reset(0x220))
133                 return;
134
135         /*
136          * Check identification bytes for es1888.
137          */
138         if (es1888_dspwr(0x220, 0xe7))
139                 return (ENXIO);
140         hi = es1888_get_byte(0x220);
141         lo = es1888_get_byte(0x220);
142         if (hi != 0x68 || (lo & 0xf0) != 0x80)
143                 return (ENXIO);
144
145         /*
146          * Program irq and drq.
147          */
148         if (es1888_dspwr(0x220, 0xc6) /* enter extended mode */
149             || es1888_dspwr(0x220, 0xb1) /* write register b1 */
150             || es1888_dspwr(0x220, 0x14) /* enable irq 5 */
151             || es1888_dspwr(0x220, 0xb2) /* write register b1 */
152             || es1888_dspwr(0x220, 0x18)) /* enable drq 1 */
153                 return (ENXIO);
154
155         /*
156          * Create the device and program its resources.
157          */
158         dev = BUS_ADD_CHILD(parent, parent, ISA_ORDER_PNP, NULL, -1);
159         bus_set_resource(dev, SYS_RES_IOPORT, 0, 0x220, 0x10);
160         bus_set_resource(dev, SYS_RES_IRQ, 0, 5, 1);
161         bus_set_resource(dev, SYS_RES_DRQ, 0, 1, 1);
162         isa_set_vendorid(dev, PNP_EISAID("ESS1888"));
163         isa_set_logicalid(dev, PNP_EISAID("ESS1888"));
164         return (0);
165 #else
166         return (ENXIO);
167 #endif
168 }
169
170 static device_method_t es1888_methods[] = {
171         /* Device interface */
172         DEVMETHOD(device_identify,      es1888_identify),
173
174         { 0, 0 }
175 };
176
177 static driver_t es1888_driver = {
178         "pcm",
179         es1888_methods,
180         1,                      /* no softc */
181 };
182
183 DRIVER_MODULE(snd_es1888, isa, es1888_driver, pcm_devclass, 0, 0);
184 MODULE_DEPEND(snd_es1888, snd_pcm, PCM_MINVER, PCM_PREFVER, PCM_MAXVER);
185 MODULE_VERSION(snd_es1888, 1);
186
187