Import 1.3.39
[davej-history.git] / drivers / sound / sound_pnp.c
blob86ea26aec68f63e17d723e5bb2ebad52445a0635
1 /*
2 * sound/sound_pnp.c
4 * PnP soundcard support (Linux spesific)
6 * Copyright by Hannu Savolainen 1995
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.
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.
29 #include "sound_config.h"
31 #if defined(CONFIGURE_SOUNDCARD) && !defined(EXCLUDE_PNP)
33 #include <linux/pnp.h>
35 static struct pnp_sounddev *pnp_devs[20] =
37 NULL
40 static int max_pnpdevs = 20;
41 static int nr_pnpdevs = 0;
42 static int pnp_sig = 0;
44 void
45 install_pnp_sounddrv (struct pnp_sounddev *drv)
47 if (nr_pnpdevs < max_pnpdevs)
49 pnp_devs[nr_pnpdevs++] = drv;
51 else
52 printk ("Sound: More than 20 PnP drivers defined\n");
55 void
56 cs4232_pnp (void *parm)
58 struct pnp_dev *dev = (struct pnp_dev *) parm;
59 char *name;
61 int portmask = 0x00, irqmask = 0x01, dmamask = 0x03;
62 int opl3_driver, wss_driver;
64 printk ("CS4232 driver waking up\n");
66 if (dev->card && dev->card->name)
67 name = dev->card->name;
68 else
69 name = "PnP WSS";
71 if ((wss_driver = sndtable_identify_card ("AD1848")))
72 portmask |= 0x01; /* MSS */
73 else
74 printk ("Sound: MSS/WSS device detected but no driver enabled\n");
76 if ((opl3_driver = sndtable_identify_card ("OPL3")))
77 portmask |= 0x02; /* OPL3 */
78 else
79 printk ("Sound: OPL3/4 device detected but no driver enabled\n");
81 printk ("WSS driver %d, OPL3 driver %d\n", wss_driver, opl3_driver);
83 if (!portmask) /* No drivers available */
84 return;
86 if (!pnp_allocate_device (pnp_sig, dev, portmask, irqmask, dmamask, 0x00))
87 printk ("Device activation failed\n");
88 else
90 struct address_info hw_config;
91 int wss_base, opl3_base;
92 int irq;
93 int dma1, dma2;
95 printk ("Device activation OK\n");
96 wss_base = pnp_get_port (dev, 0);
97 opl3_base = pnp_get_port (dev, 1);
98 irq = pnp_get_irq (dev, 0);
99 dma1 = pnp_get_dma (dev, 0);
100 dma2 = pnp_get_dma (dev, 1);
102 printk ("I/O0 %03x\n", wss_base);
103 printk ("I/O1 %03x\n", opl3_base);
104 printk ("IRQ %d\n", irq);
105 printk ("DMA0 %d\n", dma1);
106 printk ("DMA1 %d\n", dma2);
108 if (opl3_base && opl3_driver)
110 hw_config.io_base = opl3_base;
111 hw_config.irq = 0;
112 hw_config.dma = -1;
113 hw_config.dma2 = -1;
114 hw_config.always_detect = 0;
115 hw_config.name = "";
116 hw_config.driver_use_1 = 0;
117 hw_config.driver_use_2 = 0;
118 hw_config.osp = NULL;
119 hw_config.card_subtype = 0;
121 if (sndtable_probe (opl3_driver, &hw_config))
122 sndtable_init_card (opl3_driver, &hw_config);
126 if (wss_base && wss_driver)
128 hw_config.io_base = wss_base;
129 hw_config.irq = irq;
130 hw_config.dma = dma1;
131 hw_config.dma2 = (dma2 == NO_DMA) ? dma1 : dma2;
132 hw_config.always_detect = 0;
133 hw_config.name = name;
134 hw_config.driver_use_1 = 0;
135 hw_config.driver_use_2 = 0;
136 hw_config.osp = NULL;
137 hw_config.card_subtype = 0;
139 if (sndtable_probe (wss_driver, &hw_config))
140 sndtable_init_card (wss_driver, &hw_config);
146 static int
147 pnp_activate (int id, struct pnp_dev *dev)
149 int i;
151 for (i = 0; i < nr_pnpdevs; i++)
152 if (pnp_devs[i]->id == id)
155 printk ("PnP dev: %08x, %s\n", id,
156 pnp_devid2asc (id));
158 pnp_devs[i]->setup ((void *) dev);
159 return 1;
162 return 0;
165 void
166 sound_pnp_init (void)
168 static struct pnp_sounddev cs4232_dev =
169 {PNP_DEVID ('C', 'S', 'C', 0x0000), cs4232_pnp, "CS4232"};
171 struct pnp_dev *dev;
173 install_pnp_sounddrv (&cs4232_dev);
175 dev = NULL;
177 if ((pnp_sig = pnp_connect ("sound")) == -1)
179 printk ("Sound: Can't connect to kernel PnP services.\n");
180 return;
183 while ((dev = pnp_get_next_device (pnp_sig, dev)) != NULL)
185 if (!pnp_activate (dev->key, dev))
187 /* Scan all compatible devices */
189 int i;
191 for (i = 0; i < dev->ncompat; i++)
192 if (pnp_activate (dev->compat_keys[i], dev))
193 break;
198 void
199 sound_pnp_disconnect (void)
201 pnp_disconnect (pnp_sig);
203 #endif