kernel tree reorganization stage 1: Major cvs repository work (not logged as
[dragonfly.git] / sys / dev / sound / isa / i386 / sound_pnp.c
1 /*
2  * sound/sound_pnp.c
3  * 
4  * PnP soundcard support (Linux spesific)
5  * 
6  * Copyright by Hannu Savolainen 1995
7  * 
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions are
10  * met: 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer. 2.
12  * Redistributions in binary form must reproduce the above copyright notice,
13  * this list of conditions and the following disclaimer in the documentation
14  * and/or other materials provided with the distribution.
15  * 
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY
17  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
20  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  * 
28  * $DragonFly: src/sys/dev/sound/isa/i386/Attic/sound_pnp.c,v 1.2 2003/08/07 21:17:12 dillon Exp $
29  */
30 #include "sound_config.h"
31
32 /*
33  * XXX check what to use in place of CONFIG_PNP
34  */
35 #if (NSND > 0) && defined(CONFIG_PNP)
36
37 #include <linux/pnp.h>
38
39 static struct pnp_sounddev *pnp_devs[20] = { NULL };
40
41 static int      max_pnpdevs = 20;
42 static int      nr_pnpdevs = 0;
43 static int      pnp_sig = 0;
44
45 void
46 install_pnp_sounddrv(struct pnp_sounddev * drv)
47 {
48     if (nr_pnpdevs < max_pnpdevs) {
49         pnp_devs[nr_pnpdevs++] = drv;
50     } else
51         printf("Sound: More than 20 PnP drivers defined\n");
52 }
53
54 void
55 cs4232_pnp(void *parm)
56 {
57     struct pnp_dev *dev = (struct pnp_dev *) parm;
58     char           *name;
59
60     int             portmask = 0x00, irqmask = 0x01, dmamask = 0x03;
61     int             opl3_driver, wss_driver;
62
63     printf("CS4232 driver waking up\n");
64
65     if (dev->card && dev->card->name)
66         name = dev->card->name;
67     else
68         name = "PnP WSS";
69
70     if ((wss_driver = sndtable_identify_card("AD1848")))
71         portmask |= 0x01;       /* MSS */
72     else
73         printf("Sound: MSS/WSS device detected but no driver enabled\n");
74
75     if ((opl3_driver = sndtable_identify_card("OPL3")))
76         portmask |= 0x02;       /* OPL3 */
77     else
78         printf("Sound: OPL3/4 device detected but no driver enabled\n");
79
80     printf("WSS driver %d, OPL3 driver %d\n", wss_driver, opl3_driver);
81
82     if (!portmask)              /* No drivers available */
83         return;
84
85     if (!pnp_allocate_device(pnp_sig, dev, portmask, irqmask, dmamask, 0x00))
86         printf("Device activation failed\n");
87     else {
88         struct address_info hw_config;
89         int             wss_base, opl3_base;
90         int             irq;
91         int             dma1, dma2;
92
93         printf("Device activation OK\n");
94         wss_base = pnp_get_port(dev, 0);
95         opl3_base = pnp_get_port(dev, 1);
96         irq = pnp_get_irq(dev, 0);
97         dma1 = pnp_get_dma(dev, 0);
98         dma2 = pnp_get_dma(dev, 1);
99
100         printf("I/O0 %03x\n", wss_base);
101         printf("I/O1 %03x\n", opl3_base);
102         printf("IRQ %d\n", irq);
103         printf("DMA0 %d\n", dma1);
104         printf("DMA1 %d\n", dma2);
105
106         if (opl3_base && opl3_driver) {
107             hw_config.io_base = opl3_base;
108             hw_config.irq = 0;
109             hw_config.dma = -1;
110             hw_config.dma2 = -1;
111             hw_config.always_detect = 0;
112             hw_config.name = "";
113             hw_config.osp = NULL;
114             hw_config.card_subtype = 0;
115
116             if (sndtable_probe(opl3_driver, &hw_config))
117                 sndtable_init_card(opl3_driver, &hw_config);
118
119         }
120         if (wss_base && wss_driver) {
121             hw_config.io_base = wss_base;
122             hw_config.irq = irq;
123             hw_config.dma = dma1;
124             hw_config.dma2 = (dma2 == NO_DMA) ? dma1 : dma2;
125             hw_config.always_detect = 0;
126             hw_config.name = name;
127             hw_config.osp = NULL;
128             hw_config.card_subtype = 0;
129
130             if (sndtable_probe(wss_driver, &hw_config))
131                 sndtable_init_card(wss_driver, &hw_config);
132
133         }
134     }
135 }
136
137 static int
138 pnp_activate(int id, struct pnp_dev * dev)
139 {
140     int             i;
141
142     for (i = 0; i < nr_pnpdevs; i++)
143         if (pnp_devs[i]->id == id) {
144
145             printf("PnP dev: %08x, %s\n", id, pnp_devid2asc(id));
146
147             pnp_devs[i]->setup((void *) dev);
148             return 1;
149         }
150     return 0;
151 }
152
153 void
154 sound_pnp_init(void)
155 {
156     static struct pnp_sounddev cs4232_dev =
157         {PNP_DEVID('C', 'S', 'C', 0x0000), cs4232_pnp, "CS4232"};
158
159     struct pnp_dev *dev;
160
161     install_pnp_sounddrv(&cs4232_dev);
162
163     dev = NULL;
164
165     if ((pnp_sig = pnp_connect("sound")) == -1) {
166         printf("Sound: Can't connect to kernel PnP services.\n");
167         return;
168     }
169     while ((dev = pnp_get_next_device(pnp_sig, dev)) != NULL) {
170         if (!pnp_activate(dev->key, dev)) {
171             /* Scan all compatible devices */
172
173             int             i;
174
175             for (i = 0; i < dev->ncompat; i++)
176                 if (pnp_activate(dev->compat_keys[i], dev))
177                     break;
178         }
179     }
180 }
181
182 void
183 sound_pnp_disconnect(void)
184 {
185     pnp_disconnect(pnp_sig);
186 }
187 #endif