Deleted Added
full compact
ad1816.c (67652) ad1816.c (70134)
1/*
2 * Copyright (c) 1999 Cameron Grant <gandalf@vilnya.demon.co.uk>
3 * Copyright Luigi Rizzo, 1997,1998
4 * Copyright by Hannu Savolainen 1994, 1995
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER 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 *
1/*
2 * Copyright (c) 1999 Cameron Grant <gandalf@vilnya.demon.co.uk>
3 * Copyright Luigi Rizzo, 1997,1998
4 * Copyright by Hannu Savolainen 1994, 1995
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER 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 * $FreeBSD: head/sys/dev/sound/isa/ad1816.c 67652 2000-10-26 20:46:58Z cg $
28 * $FreeBSD: head/sys/dev/sound/isa/ad1816.c 70134 2000-12-18 01:36:41Z cg $
29 */
30
31#include <dev/sound/pcm/sound.h>
32#include <dev/sound/isa/ad1816.h>
33
29 */
30
31#include <dev/sound/pcm/sound.h>
32#include <dev/sound/isa/ad1816.h>
33
34#include "mixer_if.h"
35
34struct ad1816_info;
35
36struct ad1816_chinfo {
37 struct ad1816_info *parent;
38 pcm_channel *channel;
39 snd_dbuf *buffer;
40 int dir;
41};
42
43struct ad1816_info {
44 struct resource *io_base; /* primary I/O address for the board */
45 int io_rid;
46 struct resource *irq;
47 int irq_rid;
48 struct resource *drq1; /* play */
49 int drq1_rid;
50 struct resource *drq2; /* rec */
51 int drq2_rid;
52 void *ih;
53 bus_dma_tag_t parent_dmat;
54
55 struct ad1816_chinfo pch, rch;
56};
57
58static driver_intr_t ad1816_intr;
59static int ad1816_probe(device_t dev);
60static int ad1816_attach(device_t dev);
61
62/* IO primitives */
63static int ad1816_wait_init(struct ad1816_info *ad1816, int x);
64static u_short ad1816_read(struct ad1816_info *ad1816, u_int reg);
65static void ad1816_write(struct ad1816_info *ad1816, u_int reg, u_short data);
66
36struct ad1816_info;
37
38struct ad1816_chinfo {
39 struct ad1816_info *parent;
40 pcm_channel *channel;
41 snd_dbuf *buffer;
42 int dir;
43};
44
45struct ad1816_info {
46 struct resource *io_base; /* primary I/O address for the board */
47 int io_rid;
48 struct resource *irq;
49 int irq_rid;
50 struct resource *drq1; /* play */
51 int drq1_rid;
52 struct resource *drq2; /* rec */
53 int drq2_rid;
54 void *ih;
55 bus_dma_tag_t parent_dmat;
56
57 struct ad1816_chinfo pch, rch;
58};
59
60static driver_intr_t ad1816_intr;
61static int ad1816_probe(device_t dev);
62static int ad1816_attach(device_t dev);
63
64/* IO primitives */
65static int ad1816_wait_init(struct ad1816_info *ad1816, int x);
66static u_short ad1816_read(struct ad1816_info *ad1816, u_int reg);
67static void ad1816_write(struct ad1816_info *ad1816, u_int reg, u_short data);
68
67static int ad1816mix_init(snd_mixer *m);
68static int ad1816mix_set(snd_mixer *m, unsigned dev, unsigned left, unsigned right);
69static int ad1816mix_setrecsrc(snd_mixer *m, u_int32_t src);
70static snd_mixer ad1816_mixer = {
71 "ad1816 mixer",
72 ad1816mix_init,
73 NULL,
74 NULL,
75 ad1816mix_set,
76 ad1816mix_setrecsrc,
77};
78
79static devclass_t pcm_devclass;
80
69static devclass_t pcm_devclass;
70
81/* channel interface */
82static void *ad1816chan_init(void *devinfo, snd_dbuf *b, pcm_channel *c, int dir);
83static int ad1816chan_setdir(void *data, int dir);
84static int ad1816chan_setformat(void *data, u_int32_t format);
85static int ad1816chan_setspeed(void *data, u_int32_t speed);
86static int ad1816chan_setblocksize(void *data, u_int32_t blocksize);
87static int ad1816chan_trigger(void *data, int go);
88static int ad1816chan_getptr(void *data);
89static pcmchan_caps *ad1816chan_getcaps(void *data);
90
91static u_int32_t ad1816_fmt[] = {
92 AFMT_U8,
93 AFMT_STEREO | AFMT_U8,
94 AFMT_S16_LE,
95 AFMT_STEREO | AFMT_S16_LE,
96 AFMT_MU_LAW,
97 AFMT_STEREO | AFMT_MU_LAW,
98 AFMT_A_LAW,
99 AFMT_STEREO | AFMT_A_LAW,
100 0
101};
102
103static pcmchan_caps ad1816_caps = {4000, 55200, ad1816_fmt, 0};
104
71static u_int32_t ad1816_fmt[] = {
72 AFMT_U8,
73 AFMT_STEREO | AFMT_U8,
74 AFMT_S16_LE,
75 AFMT_STEREO | AFMT_S16_LE,
76 AFMT_MU_LAW,
77 AFMT_STEREO | AFMT_MU_LAW,
78 AFMT_A_LAW,
79 AFMT_STEREO | AFMT_A_LAW,
80 0
81};
82
83static pcmchan_caps ad1816_caps = {4000, 55200, ad1816_fmt, 0};
84
105static pcm_channel ad1816_chantemplate = {
106 ad1816chan_init,
107 ad1816chan_setdir,
108 ad1816chan_setformat,
109 ad1816chan_setspeed,
110 ad1816chan_setblocksize,
111 ad1816chan_trigger,
112 ad1816chan_getptr,
113 ad1816chan_getcaps,
114 NULL, /* free */
115 NULL, /* nop1 */
116 NULL, /* nop2 */
117 NULL, /* nop3 */
118 NULL, /* nop4 */
119 NULL, /* nop5 */
120 NULL, /* nop6 */
121 NULL, /* nop7 */
122};
123
124#define AD1816_MUTE 31 /* value for mute */
125
126static int
127port_rd(struct resource *port, int off)
128{
129 if (port)
130 return bus_space_read_1(rman_get_bustag(port),
131 rman_get_bushandle(port),
132 off);
133 else
134 return -1;
135}
136
137static void
138port_wr(struct resource *port, int off, u_int8_t data)
139{
140 if (port)
141 return bus_space_write_1(rman_get_bustag(port),
142 rman_get_bushandle(port),
143 off, data);
144}
145
146static int
147io_rd(struct ad1816_info *ad1816, int reg)
148{
149 return port_rd(ad1816->io_base, reg);
150}
151
152static void
153io_wr(struct ad1816_info *ad1816, int reg, u_int8_t data)
154{
155 return port_wr(ad1816->io_base, reg, data);
156}
157
158static void
159ad1816_intr(void *arg)
160{
161 struct ad1816_info *ad1816 = (struct ad1816_info *)arg;
162 unsigned char c, served = 0;
163
164 /* get interupt status */
165 c = io_rd(ad1816, AD1816_INT);
166
167 /* check for stray interupts */
168 if (c & ~(AD1816_INTRCI | AD1816_INTRPI)) {
169 printf("pcm: stray int (%x)\n", c);
170 c &= AD1816_INTRCI | AD1816_INTRPI;
171 }
172 /* check for capture interupt */
173 if (ad1816->rch.buffer->dl && (c & AD1816_INTRCI)) {
174 chn_intr(ad1816->rch.channel);
175 served |= AD1816_INTRCI; /* cp served */
176 }
177 /* check for playback interupt */
178 if (ad1816->pch.buffer->dl && (c & AD1816_INTRPI)) {
179 chn_intr(ad1816->pch.channel);
180 served |= AD1816_INTRPI; /* pb served */
181 }
182 if (served == 0) {
183 /* this probably means this is not a (working) ad1816 chip, */
184 /* or an error in dma handling */
185 printf("pcm: int without reason (%x)\n", c);
186 c = 0;
187 } else c &= ~served;
188 io_wr(ad1816, AD1816_INT, c);
189 c = io_rd(ad1816, AD1816_INT);
190 if (c != 0) printf("pcm: int clear failed (%x)\n", c);
191}
192
193static int
194ad1816_wait_init(struct ad1816_info *ad1816, int x)
195{
196 int n = 0; /* to shut up the compiler... */
197
198 for (; x--;)
199 if ((n = (io_rd(ad1816, AD1816_ALE) & AD1816_BUSY)) == 0) DELAY(10);
200 else return n;
201 printf("ad1816_wait_init failed 0x%02x.\n", n);
202 return -1;
203}
204
205static unsigned short
206ad1816_read(struct ad1816_info *ad1816, unsigned int reg)
207{
208 int flags;
209 u_short x = 0;
210
211 /* we don't want to be blocked here */
212 flags = spltty();
213 if (ad1816_wait_init(ad1816, 100) == -1) return 0;
214 io_wr(ad1816, AD1816_ALE, 0);
215 io_wr(ad1816, AD1816_ALE, (reg & AD1816_ALEMASK));
216 if (ad1816_wait_init(ad1816, 100) == -1) return 0;
217 x = (io_rd(ad1816, AD1816_HIGH) << 8) | io_rd(ad1816, AD1816_LOW);
218 splx(flags);
219 return x;
220}
221
222static void
223ad1816_write(struct ad1816_info *ad1816, unsigned int reg, unsigned short data)
224{
225 int flags;
226
227 flags = spltty();
228 if (ad1816_wait_init(ad1816, 100) == -1) return;
229 io_wr(ad1816, AD1816_ALE, (reg & AD1816_ALEMASK));
230 io_wr(ad1816, AD1816_LOW, (data & 0x000000ff));
231 io_wr(ad1816, AD1816_HIGH, (data & 0x0000ff00) >> 8);
232 splx(flags);
233}
234
85#define AD1816_MUTE 31 /* value for mute */
86
87static int
88port_rd(struct resource *port, int off)
89{
90 if (port)
91 return bus_space_read_1(rman_get_bustag(port),
92 rman_get_bushandle(port),
93 off);
94 else
95 return -1;
96}
97
98static void
99port_wr(struct resource *port, int off, u_int8_t data)
100{
101 if (port)
102 return bus_space_write_1(rman_get_bustag(port),
103 rman_get_bushandle(port),
104 off, data);
105}
106
107static int
108io_rd(struct ad1816_info *ad1816, int reg)
109{
110 return port_rd(ad1816->io_base, reg);
111}
112
113static void
114io_wr(struct ad1816_info *ad1816, int reg, u_int8_t data)
115{
116 return port_wr(ad1816->io_base, reg, data);
117}
118
119static void
120ad1816_intr(void *arg)
121{
122 struct ad1816_info *ad1816 = (struct ad1816_info *)arg;
123 unsigned char c, served = 0;
124
125 /* get interupt status */
126 c = io_rd(ad1816, AD1816_INT);
127
128 /* check for stray interupts */
129 if (c & ~(AD1816_INTRCI | AD1816_INTRPI)) {
130 printf("pcm: stray int (%x)\n", c);
131 c &= AD1816_INTRCI | AD1816_INTRPI;
132 }
133 /* check for capture interupt */
134 if (ad1816->rch.buffer->dl && (c & AD1816_INTRCI)) {
135 chn_intr(ad1816->rch.channel);
136 served |= AD1816_INTRCI; /* cp served */
137 }
138 /* check for playback interupt */
139 if (ad1816->pch.buffer->dl && (c & AD1816_INTRPI)) {
140 chn_intr(ad1816->pch.channel);
141 served |= AD1816_INTRPI; /* pb served */
142 }
143 if (served == 0) {
144 /* this probably means this is not a (working) ad1816 chip, */
145 /* or an error in dma handling */
146 printf("pcm: int without reason (%x)\n", c);
147 c = 0;
148 } else c &= ~served;
149 io_wr(ad1816, AD1816_INT, c);
150 c = io_rd(ad1816, AD1816_INT);
151 if (c != 0) printf("pcm: int clear failed (%x)\n", c);
152}
153
154static int
155ad1816_wait_init(struct ad1816_info *ad1816, int x)
156{
157 int n = 0; /* to shut up the compiler... */
158
159 for (; x--;)
160 if ((n = (io_rd(ad1816, AD1816_ALE) & AD1816_BUSY)) == 0) DELAY(10);
161 else return n;
162 printf("ad1816_wait_init failed 0x%02x.\n", n);
163 return -1;
164}
165
166static unsigned short
167ad1816_read(struct ad1816_info *ad1816, unsigned int reg)
168{
169 int flags;
170 u_short x = 0;
171
172 /* we don't want to be blocked here */
173 flags = spltty();
174 if (ad1816_wait_init(ad1816, 100) == -1) return 0;
175 io_wr(ad1816, AD1816_ALE, 0);
176 io_wr(ad1816, AD1816_ALE, (reg & AD1816_ALEMASK));
177 if (ad1816_wait_init(ad1816, 100) == -1) return 0;
178 x = (io_rd(ad1816, AD1816_HIGH) << 8) | io_rd(ad1816, AD1816_LOW);
179 splx(flags);
180 return x;
181}
182
183static void
184ad1816_write(struct ad1816_info *ad1816, unsigned int reg, unsigned short data)
185{
186 int flags;
187
188 flags = spltty();
189 if (ad1816_wait_init(ad1816, 100) == -1) return;
190 io_wr(ad1816, AD1816_ALE, (reg & AD1816_ALEMASK));
191 io_wr(ad1816, AD1816_LOW, (data & 0x000000ff));
192 io_wr(ad1816, AD1816_HIGH, (data & 0x0000ff00) >> 8);
193 splx(flags);
194}
195
196/* -------------------------------------------------------------------- */
197
235static int
236ad1816mix_init(snd_mixer *m)
237{
238 mix_setdevs(m, AD1816_MIXER_DEVICES);
239 mix_setrecdevs(m, AD1816_REC_DEVICES);
240 return 0;
241}
242
243static int
244ad1816mix_set(snd_mixer *m, unsigned dev, unsigned left, unsigned right)
245{
246 struct ad1816_info *ad1816 = mix_getdevinfo(m);
247 u_short reg = 0;
248
249 /* Scale volumes */
250 left = AD1816_MUTE - (AD1816_MUTE * left) / 100;
251 right = AD1816_MUTE - (AD1816_MUTE * right) / 100;
252
253 reg = (left << 8) | right;
254
255 /* do channel selective muting if volume is zero */
256 if (left == AD1816_MUTE) reg |= 0x8000;
257 if (right == AD1816_MUTE) reg |= 0x0080;
258
259 switch (dev) {
260 case SOUND_MIXER_VOLUME: /* Register 14 master volume */
261 ad1816_write(ad1816, 14, reg);
262 break;
263
264 case SOUND_MIXER_CD: /* Register 15 cd */
265 case SOUND_MIXER_LINE1:
266 ad1816_write(ad1816, 15, reg);
267 break;
268
269 case SOUND_MIXER_SYNTH: /* Register 16 synth */
270 ad1816_write(ad1816, 16, reg);
271 break;
272
273 case SOUND_MIXER_PCM: /* Register 4 pcm */
274 ad1816_write(ad1816, 4, reg);
275 break;
276
277 case SOUND_MIXER_LINE:
278 case SOUND_MIXER_LINE3: /* Register 18 line in */
279 ad1816_write(ad1816, 18, reg);
280 break;
281
282 case SOUND_MIXER_MIC: /* Register 19 mic volume */
283 ad1816_write(ad1816, 19, reg & ~0xff); /* mic is mono */
284 break;
285
286 case SOUND_MIXER_IGAIN:
287 /* and now to something completely different ... */
288 ad1816_write(ad1816, 20, ((ad1816_read(ad1816, 20) & ~0x0f0f)
289 | (((AD1816_MUTE - left) / 2) << 8) /* four bits of adc gain */
290 | ((AD1816_MUTE - right) / 2)));
291 break;
292
293 default:
294 printf("ad1816_mixer_set(): unknown device.\n");
295 break;
296 }
297
298 left = ((AD1816_MUTE - left) * 100) / AD1816_MUTE;
299 right = ((AD1816_MUTE - right) * 100) / AD1816_MUTE;
300
301 return left | (right << 8);
302}
303
304static int
305ad1816mix_setrecsrc(snd_mixer *m, u_int32_t src)
306{
307 struct ad1816_info *ad1816 = mix_getdevinfo(m);
308 int dev;
309
310 switch (src) {
311 case SOUND_MASK_LINE:
312 case SOUND_MASK_LINE3:
313 dev = 0x00;
314 break;
315
316 case SOUND_MASK_CD:
317 case SOUND_MASK_LINE1:
318 dev = 0x20;
319 break;
320
321 case SOUND_MASK_MIC:
322 default:
323 dev = 0x50;
324 src = SOUND_MASK_MIC;
325 }
326
327 dev |= dev << 8;
328 ad1816_write(ad1816, 20, (ad1816_read(ad1816, 20) & ~0x7070) | dev);
329 return src;
330}
331
198static int
199ad1816mix_init(snd_mixer *m)
200{
201 mix_setdevs(m, AD1816_MIXER_DEVICES);
202 mix_setrecdevs(m, AD1816_REC_DEVICES);
203 return 0;
204}
205
206static int
207ad1816mix_set(snd_mixer *m, unsigned dev, unsigned left, unsigned right)
208{
209 struct ad1816_info *ad1816 = mix_getdevinfo(m);
210 u_short reg = 0;
211
212 /* Scale volumes */
213 left = AD1816_MUTE - (AD1816_MUTE * left) / 100;
214 right = AD1816_MUTE - (AD1816_MUTE * right) / 100;
215
216 reg = (left << 8) | right;
217
218 /* do channel selective muting if volume is zero */
219 if (left == AD1816_MUTE) reg |= 0x8000;
220 if (right == AD1816_MUTE) reg |= 0x0080;
221
222 switch (dev) {
223 case SOUND_MIXER_VOLUME: /* Register 14 master volume */
224 ad1816_write(ad1816, 14, reg);
225 break;
226
227 case SOUND_MIXER_CD: /* Register 15 cd */
228 case SOUND_MIXER_LINE1:
229 ad1816_write(ad1816, 15, reg);
230 break;
231
232 case SOUND_MIXER_SYNTH: /* Register 16 synth */
233 ad1816_write(ad1816, 16, reg);
234 break;
235
236 case SOUND_MIXER_PCM: /* Register 4 pcm */
237 ad1816_write(ad1816, 4, reg);
238 break;
239
240 case SOUND_MIXER_LINE:
241 case SOUND_MIXER_LINE3: /* Register 18 line in */
242 ad1816_write(ad1816, 18, reg);
243 break;
244
245 case SOUND_MIXER_MIC: /* Register 19 mic volume */
246 ad1816_write(ad1816, 19, reg & ~0xff); /* mic is mono */
247 break;
248
249 case SOUND_MIXER_IGAIN:
250 /* and now to something completely different ... */
251 ad1816_write(ad1816, 20, ((ad1816_read(ad1816, 20) & ~0x0f0f)
252 | (((AD1816_MUTE - left) / 2) << 8) /* four bits of adc gain */
253 | ((AD1816_MUTE - right) / 2)));
254 break;
255
256 default:
257 printf("ad1816_mixer_set(): unknown device.\n");
258 break;
259 }
260
261 left = ((AD1816_MUTE - left) * 100) / AD1816_MUTE;
262 right = ((AD1816_MUTE - right) * 100) / AD1816_MUTE;
263
264 return left | (right << 8);
265}
266
267static int
268ad1816mix_setrecsrc(snd_mixer *m, u_int32_t src)
269{
270 struct ad1816_info *ad1816 = mix_getdevinfo(m);
271 int dev;
272
273 switch (src) {
274 case SOUND_MASK_LINE:
275 case SOUND_MASK_LINE3:
276 dev = 0x00;
277 break;
278
279 case SOUND_MASK_CD:
280 case SOUND_MASK_LINE1:
281 dev = 0x20;
282 break;
283
284 case SOUND_MASK_MIC:
285 default:
286 dev = 0x50;
287 src = SOUND_MASK_MIC;
288 }
289
290 dev |= dev << 8;
291 ad1816_write(ad1816, 20, (ad1816_read(ad1816, 20) & ~0x7070) | dev);
292 return src;
293}
294
295static kobj_method_t ad1816mixer_methods[] = {
296 KOBJMETHOD(mixer_init, ad1816mix_init),
297 KOBJMETHOD(mixer_set, ad1816mix_set),
298 KOBJMETHOD(mixer_setrecsrc, ad1816mix_setrecsrc),
299 { 0, 0 }
300};
301MIXER_DECLARE(ad1816mixer);
302
303/* -------------------------------------------------------------------- */
332/* channel interface */
333static void *
304/* channel interface */
305static void *
334ad1816chan_init(void *devinfo, snd_dbuf *b, pcm_channel *c, int dir)
306ad1816chan_init(kobj_t obj, void *devinfo, snd_dbuf *b, pcm_channel *c, int dir)
335{
336 struct ad1816_info *ad1816 = devinfo;
337 struct ad1816_chinfo *ch = (dir == PCMDIR_PLAY)? &ad1816->pch : &ad1816->rch;
338
339 ch->parent = ad1816;
340 ch->channel = c;
341 ch->buffer = b;
342 ch->buffer->bufsize = DSP_BUFFSIZE;
343 if (chn_allocbuf(ch->buffer, ad1816->parent_dmat) == -1) return NULL;
344 return ch;
345}
346
347static int
307{
308 struct ad1816_info *ad1816 = devinfo;
309 struct ad1816_chinfo *ch = (dir == PCMDIR_PLAY)? &ad1816->pch : &ad1816->rch;
310
311 ch->parent = ad1816;
312 ch->channel = c;
313 ch->buffer = b;
314 ch->buffer->bufsize = DSP_BUFFSIZE;
315 if (chn_allocbuf(ch->buffer, ad1816->parent_dmat) == -1) return NULL;
316 return ch;
317}
318
319static int
348ad1816chan_setdir(void *data, int dir)
320ad1816chan_setdir(kobj_t obj, void *data, int dir)
349{
350 struct ad1816_chinfo *ch = data;
351 struct ad1816_info *ad1816 = ch->parent;
352
353 ch->buffer->chan = rman_get_start((dir == PCMDIR_PLAY)?
354 ad1816->drq1 : ad1816->drq2);
355 ch->dir = dir;
356 return 0;
357}
358
359static int
321{
322 struct ad1816_chinfo *ch = data;
323 struct ad1816_info *ad1816 = ch->parent;
324
325 ch->buffer->chan = rman_get_start((dir == PCMDIR_PLAY)?
326 ad1816->drq1 : ad1816->drq2);
327 ch->dir = dir;
328 return 0;
329}
330
331static int
360ad1816chan_setformat(void *data, u_int32_t format)
332ad1816chan_setformat(kobj_t obj, void *data, u_int32_t format)
361{
362 struct ad1816_chinfo *ch = data;
363 struct ad1816_info *ad1816 = ch->parent;
364
365 int fmt = AD1816_U8, reg;
366 if (ch->dir == PCMDIR_PLAY) {
367 reg = AD1816_PLAY;
368 ad1816_write(ad1816, 8, 0x0000); /* reset base and current counter */
369 ad1816_write(ad1816, 9, 0x0000); /* for playback and capture */
370 } else {
371 reg = AD1816_CAPT;
372 ad1816_write(ad1816, 10, 0x0000);
373 ad1816_write(ad1816, 11, 0x0000);
374 }
375 switch (format & ~AFMT_STEREO) {
376 case AFMT_A_LAW:
377 fmt = AD1816_ALAW;
378 break;
379
380 case AFMT_MU_LAW:
381 fmt = AD1816_MULAW;
382 break;
383
384 case AFMT_S16_LE:
385 fmt = AD1816_S16LE;
386 break;
387
388 case AFMT_S16_BE:
389 fmt = AD1816_S16BE;
390 break;
391
392 case AFMT_U8:
393 fmt = AD1816_U8;
394 break;
395 }
396 if (format & AFMT_STEREO) fmt |= AD1816_STEREO;
397 io_wr(ad1816, reg, fmt);
398 return format;
399}
400
401static int
333{
334 struct ad1816_chinfo *ch = data;
335 struct ad1816_info *ad1816 = ch->parent;
336
337 int fmt = AD1816_U8, reg;
338 if (ch->dir == PCMDIR_PLAY) {
339 reg = AD1816_PLAY;
340 ad1816_write(ad1816, 8, 0x0000); /* reset base and current counter */
341 ad1816_write(ad1816, 9, 0x0000); /* for playback and capture */
342 } else {
343 reg = AD1816_CAPT;
344 ad1816_write(ad1816, 10, 0x0000);
345 ad1816_write(ad1816, 11, 0x0000);
346 }
347 switch (format & ~AFMT_STEREO) {
348 case AFMT_A_LAW:
349 fmt = AD1816_ALAW;
350 break;
351
352 case AFMT_MU_LAW:
353 fmt = AD1816_MULAW;
354 break;
355
356 case AFMT_S16_LE:
357 fmt = AD1816_S16LE;
358 break;
359
360 case AFMT_S16_BE:
361 fmt = AD1816_S16BE;
362 break;
363
364 case AFMT_U8:
365 fmt = AD1816_U8;
366 break;
367 }
368 if (format & AFMT_STEREO) fmt |= AD1816_STEREO;
369 io_wr(ad1816, reg, fmt);
370 return format;
371}
372
373static int
402ad1816chan_setspeed(void *data, u_int32_t speed)
374ad1816chan_setspeed(kobj_t obj, void *data, u_int32_t speed)
403{
404 struct ad1816_chinfo *ch = data;
405 struct ad1816_info *ad1816 = ch->parent;
406
407 RANGE(speed, 4000, 55200);
408 ad1816_write(ad1816, (ch->dir == PCMDIR_PLAY)? 2 : 3, speed);
409 return speed;
410}
411
412static int
375{
376 struct ad1816_chinfo *ch = data;
377 struct ad1816_info *ad1816 = ch->parent;
378
379 RANGE(speed, 4000, 55200);
380 ad1816_write(ad1816, (ch->dir == PCMDIR_PLAY)? 2 : 3, speed);
381 return speed;
382}
383
384static int
413ad1816chan_setblocksize(void *data, u_int32_t blocksize)
385ad1816chan_setblocksize(kobj_t obj, void *data, u_int32_t blocksize)
414{
415 return blocksize;
416}
417
418static int
386{
387 return blocksize;
388}
389
390static int
419ad1816chan_trigger(void *data, int go)
391ad1816chan_trigger(kobj_t obj, void *data, int go)
420{
421 struct ad1816_chinfo *ch = data;
422 struct ad1816_info *ad1816 = ch->parent;
423 int wr, reg;
424
425 if (go == PCMTRIG_EMLDMAWR || go == PCMTRIG_EMLDMARD)
426 return 0;
427
428 buf_isadma(ch->buffer, go);
429 wr = (ch->dir == PCMDIR_PLAY);
430 reg = wr? AD1816_PLAY : AD1816_CAPT;
431 switch (go) {
432 case PCMTRIG_START:
433 /* start only if not already running */
434 if (!(io_rd(ad1816, reg) & AD1816_ENABLE)) {
435 int cnt = ((ch->buffer->dl) >> 2) - 1;
436 ad1816_write(ad1816, wr? 8 : 10, cnt); /* count */
437 ad1816_write(ad1816, wr? 9 : 11, 0); /* reset cur cnt */
438 ad1816_write(ad1816, 1, ad1816_read(ad1816, 1) |
439 (wr? 0x8000 : 0x4000)); /* enable int */
440 /* enable playback */
441 io_wr(ad1816, reg, io_rd(ad1816, reg) | AD1816_ENABLE);
442 if (!(io_rd(ad1816, reg) & AD1816_ENABLE))
443 printf("ad1816: failed to start %s DMA!\n",
444 wr? "play" : "rec");
445 }
446 break;
447
448 case PCMTRIG_STOP:
449 case PCMTRIG_ABORT: /* XXX check this... */
450 /* we don't test here if it is running... */
451 if (wr) {
452 ad1816_write(ad1816, 1, ad1816_read(ad1816, 1) &
453 ~(wr? 0x8000 : 0x4000));
454 /* disable int */
455 io_wr(ad1816, reg, io_rd(ad1816, reg) & ~AD1816_ENABLE);
456 /* disable playback */
457 if (io_rd(ad1816, reg) & AD1816_ENABLE)
458 printf("ad1816: failed to stop %s DMA!\n",
459 wr? "play" : "rec");
460 ad1816_write(ad1816, wr? 8 : 10, 0); /* reset base cnt */
461 ad1816_write(ad1816, wr? 9 : 11, 0); /* reset cur cnt */
462 }
463 break;
464 }
465 return 0;
466}
467
468static int
392{
393 struct ad1816_chinfo *ch = data;
394 struct ad1816_info *ad1816 = ch->parent;
395 int wr, reg;
396
397 if (go == PCMTRIG_EMLDMAWR || go == PCMTRIG_EMLDMARD)
398 return 0;
399
400 buf_isadma(ch->buffer, go);
401 wr = (ch->dir == PCMDIR_PLAY);
402 reg = wr? AD1816_PLAY : AD1816_CAPT;
403 switch (go) {
404 case PCMTRIG_START:
405 /* start only if not already running */
406 if (!(io_rd(ad1816, reg) & AD1816_ENABLE)) {
407 int cnt = ((ch->buffer->dl) >> 2) - 1;
408 ad1816_write(ad1816, wr? 8 : 10, cnt); /* count */
409 ad1816_write(ad1816, wr? 9 : 11, 0); /* reset cur cnt */
410 ad1816_write(ad1816, 1, ad1816_read(ad1816, 1) |
411 (wr? 0x8000 : 0x4000)); /* enable int */
412 /* enable playback */
413 io_wr(ad1816, reg, io_rd(ad1816, reg) | AD1816_ENABLE);
414 if (!(io_rd(ad1816, reg) & AD1816_ENABLE))
415 printf("ad1816: failed to start %s DMA!\n",
416 wr? "play" : "rec");
417 }
418 break;
419
420 case PCMTRIG_STOP:
421 case PCMTRIG_ABORT: /* XXX check this... */
422 /* we don't test here if it is running... */
423 if (wr) {
424 ad1816_write(ad1816, 1, ad1816_read(ad1816, 1) &
425 ~(wr? 0x8000 : 0x4000));
426 /* disable int */
427 io_wr(ad1816, reg, io_rd(ad1816, reg) & ~AD1816_ENABLE);
428 /* disable playback */
429 if (io_rd(ad1816, reg) & AD1816_ENABLE)
430 printf("ad1816: failed to stop %s DMA!\n",
431 wr? "play" : "rec");
432 ad1816_write(ad1816, wr? 8 : 10, 0); /* reset base cnt */
433 ad1816_write(ad1816, wr? 9 : 11, 0); /* reset cur cnt */
434 }
435 break;
436 }
437 return 0;
438}
439
440static int
469ad1816chan_getptr(void *data)
441ad1816chan_getptr(kobj_t obj, void *data)
470{
471 struct ad1816_chinfo *ch = data;
472 return buf_isadmaptr(ch->buffer);
473}
474
475static pcmchan_caps *
442{
443 struct ad1816_chinfo *ch = data;
444 return buf_isadmaptr(ch->buffer);
445}
446
447static pcmchan_caps *
476ad1816chan_getcaps(void *data)
448ad1816chan_getcaps(kobj_t obj, void *data)
477{
478 return &ad1816_caps;
479}
480
449{
450 return &ad1816_caps;
451}
452
453static kobj_method_t ad1816chan_methods[] = {
454 KOBJMETHOD(channel_init, ad1816chan_init),
455 KOBJMETHOD(channel_setdir, ad1816chan_setdir),
456 KOBJMETHOD(channel_setformat, ad1816chan_setformat),
457 KOBJMETHOD(channel_setspeed, ad1816chan_setspeed),
458 KOBJMETHOD(channel_setblocksize, ad1816chan_setblocksize),
459 KOBJMETHOD(channel_trigger, ad1816chan_trigger),
460 KOBJMETHOD(channel_getptr, ad1816chan_getptr),
461 KOBJMETHOD(channel_getcaps, ad1816chan_getcaps),
462 { 0, 0 }
463};
464CHANNEL_DECLARE(ad1816chan);
465
466/* -------------------------------------------------------------------- */
467
481static void
482ad1816_release_resources(struct ad1816_info *ad1816, device_t dev)
483{
484 if (ad1816->irq) {
485 if (ad1816->ih)
486 bus_teardown_intr(dev, ad1816->irq, ad1816->ih);
487 bus_release_resource(dev, SYS_RES_IRQ, ad1816->irq_rid,
488 ad1816->irq);
489 ad1816->irq = 0;
490 }
491 if (ad1816->drq1) {
492 bus_release_resource(dev, SYS_RES_DRQ, ad1816->drq1_rid,
493 ad1816->drq1);
494 ad1816->drq1 = 0;
495 }
496 if (ad1816->drq2) {
497 bus_release_resource(dev, SYS_RES_DRQ, ad1816->drq2_rid,
498 ad1816->drq2);
499 ad1816->drq2 = 0;
500 }
501 if (ad1816->io_base) {
502 bus_release_resource(dev, SYS_RES_IOPORT, ad1816->io_rid,
503 ad1816->io_base);
504 ad1816->io_base = 0;
505 }
506 if (ad1816->parent_dmat) {
507 bus_dma_tag_destroy(ad1816->parent_dmat);
508 ad1816->parent_dmat = 0;
509 }
510 free(ad1816, M_DEVBUF);
511}
512
513static int
514ad1816_alloc_resources(struct ad1816_info *ad1816, device_t dev)
515{
516 int ok = 1, pdma, rdma;
517 if (!ad1816->io_base)
518 ad1816->io_base = bus_alloc_resource(dev, SYS_RES_IOPORT, &ad1816->io_rid,
519 0, ~0, 1, RF_ACTIVE);
520 if (!ad1816->irq)
521 ad1816->irq = bus_alloc_resource(dev, SYS_RES_IRQ, &ad1816->irq_rid,
522 0, ~0, 1, RF_ACTIVE);
523 if (!ad1816->drq1)
524 ad1816->drq1 = bus_alloc_resource(dev, SYS_RES_DRQ, &ad1816->drq1_rid,
525 0, ~0, 1, RF_ACTIVE);
526 if (!ad1816->drq2)
527 ad1816->drq2 = bus_alloc_resource(dev, SYS_RES_DRQ, &ad1816->drq2_rid,
528 0, ~0, 1, RF_ACTIVE);
529
530 if (!ad1816->io_base || !ad1816->drq1 || !ad1816->irq) ok = 0;
531
532 if (ok) {
533 pdma = rman_get_start(ad1816->drq1);
534 isa_dma_acquire(pdma);
535 isa_dmainit(pdma, DSP_BUFFSIZE);
536 if (ad1816->drq2) {
537 rdma = rman_get_start(ad1816->drq2);
538 isa_dma_acquire(rdma);
539 isa_dmainit(rdma, DSP_BUFFSIZE);
540 } else rdma = pdma;
541 if (pdma == rdma)
542 pcm_setflags(dev, pcm_getflags(dev) | SD_F_SIMPLEX);
543 }
544 return ok;
545}
546
547static int
548ad1816_init(struct ad1816_info *ad1816, device_t dev)
549{
550 ad1816_write(ad1816, 1, 0x2); /* disable interrupts */
551 ad1816_write(ad1816, 32, 0x90F0); /* SoundSys Mode, split fmt */
552
553 ad1816_write(ad1816, 5, 0x8080); /* FM volume mute */
554 ad1816_write(ad1816, 6, 0x8080); /* I2S1 volume mute */
555 ad1816_write(ad1816, 7, 0x8080); /* I2S0 volume mute */
556 ad1816_write(ad1816, 17, 0x8888); /* VID Volume mute */
557 ad1816_write(ad1816, 20, 0x5050); /* recsrc mic, agc off */
558 /* adc gain is set to 0 */
559
560 return 0;
561}
562
563static int
564ad1816_probe(device_t dev)
565{
566 char *s = NULL;
567 u_int32_t logical_id = isa_get_logicalid(dev);
568
569 switch (logical_id) {
570 case 0x80719304: /* ADS7180 */
571 s = "AD1816";
572 break;
573 }
574
575 if (s) {
576 device_set_desc(dev, s);
577 return 0;
578 }
579 return ENXIO;
580}
581
582static int
583ad1816_attach(device_t dev)
584{
585 struct ad1816_info *ad1816;
586 char status[SND_STATUSLEN];
587
588 ad1816 = (struct ad1816_info *)malloc(sizeof *ad1816, M_DEVBUF, M_NOWAIT);
589 if (!ad1816) return ENXIO;
590 bzero(ad1816, sizeof *ad1816);
591
592 ad1816->io_rid = 2;
593 ad1816->irq_rid = 0;
594 ad1816->drq1_rid = 0;
595 ad1816->drq2_rid = 1;
596
597 if (!ad1816_alloc_resources(ad1816, dev)) goto no;
598 ad1816_init(ad1816, dev);
468static void
469ad1816_release_resources(struct ad1816_info *ad1816, device_t dev)
470{
471 if (ad1816->irq) {
472 if (ad1816->ih)
473 bus_teardown_intr(dev, ad1816->irq, ad1816->ih);
474 bus_release_resource(dev, SYS_RES_IRQ, ad1816->irq_rid,
475 ad1816->irq);
476 ad1816->irq = 0;
477 }
478 if (ad1816->drq1) {
479 bus_release_resource(dev, SYS_RES_DRQ, ad1816->drq1_rid,
480 ad1816->drq1);
481 ad1816->drq1 = 0;
482 }
483 if (ad1816->drq2) {
484 bus_release_resource(dev, SYS_RES_DRQ, ad1816->drq2_rid,
485 ad1816->drq2);
486 ad1816->drq2 = 0;
487 }
488 if (ad1816->io_base) {
489 bus_release_resource(dev, SYS_RES_IOPORT, ad1816->io_rid,
490 ad1816->io_base);
491 ad1816->io_base = 0;
492 }
493 if (ad1816->parent_dmat) {
494 bus_dma_tag_destroy(ad1816->parent_dmat);
495 ad1816->parent_dmat = 0;
496 }
497 free(ad1816, M_DEVBUF);
498}
499
500static int
501ad1816_alloc_resources(struct ad1816_info *ad1816, device_t dev)
502{
503 int ok = 1, pdma, rdma;
504 if (!ad1816->io_base)
505 ad1816->io_base = bus_alloc_resource(dev, SYS_RES_IOPORT, &ad1816->io_rid,
506 0, ~0, 1, RF_ACTIVE);
507 if (!ad1816->irq)
508 ad1816->irq = bus_alloc_resource(dev, SYS_RES_IRQ, &ad1816->irq_rid,
509 0, ~0, 1, RF_ACTIVE);
510 if (!ad1816->drq1)
511 ad1816->drq1 = bus_alloc_resource(dev, SYS_RES_DRQ, &ad1816->drq1_rid,
512 0, ~0, 1, RF_ACTIVE);
513 if (!ad1816->drq2)
514 ad1816->drq2 = bus_alloc_resource(dev, SYS_RES_DRQ, &ad1816->drq2_rid,
515 0, ~0, 1, RF_ACTIVE);
516
517 if (!ad1816->io_base || !ad1816->drq1 || !ad1816->irq) ok = 0;
518
519 if (ok) {
520 pdma = rman_get_start(ad1816->drq1);
521 isa_dma_acquire(pdma);
522 isa_dmainit(pdma, DSP_BUFFSIZE);
523 if (ad1816->drq2) {
524 rdma = rman_get_start(ad1816->drq2);
525 isa_dma_acquire(rdma);
526 isa_dmainit(rdma, DSP_BUFFSIZE);
527 } else rdma = pdma;
528 if (pdma == rdma)
529 pcm_setflags(dev, pcm_getflags(dev) | SD_F_SIMPLEX);
530 }
531 return ok;
532}
533
534static int
535ad1816_init(struct ad1816_info *ad1816, device_t dev)
536{
537 ad1816_write(ad1816, 1, 0x2); /* disable interrupts */
538 ad1816_write(ad1816, 32, 0x90F0); /* SoundSys Mode, split fmt */
539
540 ad1816_write(ad1816, 5, 0x8080); /* FM volume mute */
541 ad1816_write(ad1816, 6, 0x8080); /* I2S1 volume mute */
542 ad1816_write(ad1816, 7, 0x8080); /* I2S0 volume mute */
543 ad1816_write(ad1816, 17, 0x8888); /* VID Volume mute */
544 ad1816_write(ad1816, 20, 0x5050); /* recsrc mic, agc off */
545 /* adc gain is set to 0 */
546
547 return 0;
548}
549
550static int
551ad1816_probe(device_t dev)
552{
553 char *s = NULL;
554 u_int32_t logical_id = isa_get_logicalid(dev);
555
556 switch (logical_id) {
557 case 0x80719304: /* ADS7180 */
558 s = "AD1816";
559 break;
560 }
561
562 if (s) {
563 device_set_desc(dev, s);
564 return 0;
565 }
566 return ENXIO;
567}
568
569static int
570ad1816_attach(device_t dev)
571{
572 struct ad1816_info *ad1816;
573 char status[SND_STATUSLEN];
574
575 ad1816 = (struct ad1816_info *)malloc(sizeof *ad1816, M_DEVBUF, M_NOWAIT);
576 if (!ad1816) return ENXIO;
577 bzero(ad1816, sizeof *ad1816);
578
579 ad1816->io_rid = 2;
580 ad1816->irq_rid = 0;
581 ad1816->drq1_rid = 0;
582 ad1816->drq2_rid = 1;
583
584 if (!ad1816_alloc_resources(ad1816, dev)) goto no;
585 ad1816_init(ad1816, dev);
599 mixer_init(dev, &ad1816_mixer, ad1816);
586 if (mixer_init(dev, &ad1816mixer_class, ad1816)) goto no;
587
600 bus_setup_intr(dev, ad1816->irq, INTR_TYPE_TTY, ad1816_intr, ad1816, &ad1816->ih);
601 if (bus_dma_tag_create(/*parent*/NULL, /*alignment*/2, /*boundary*/0,
602 /*lowaddr*/BUS_SPACE_MAXADDR_24BIT,
603 /*highaddr*/BUS_SPACE_MAXADDR,
604 /*filter*/NULL, /*filterarg*/NULL,
605 /*maxsize*/DSP_BUFFSIZE, /*nsegments*/1,
606 /*maxsegz*/0x3ffff,
607 /*flags*/0, &ad1816->parent_dmat) != 0) {
608 device_printf(dev, "unable to create dma tag\n");
609 goto no;
610 }
611 snprintf(status, SND_STATUSLEN, "at io 0x%lx irq %ld drq %ld",
612 rman_get_start(ad1816->io_base),
613 rman_get_start(ad1816->irq),
614 rman_get_start(ad1816->drq1));
615 if (ad1816->drq2) snprintf(status + strlen(status),
616 SND_STATUSLEN - strlen(status), ":%ld",
617 rman_get_start(ad1816->drq2));
618
619 if (pcm_register(dev, ad1816, 1, 1)) goto no;
588 bus_setup_intr(dev, ad1816->irq, INTR_TYPE_TTY, ad1816_intr, ad1816, &ad1816->ih);
589 if (bus_dma_tag_create(/*parent*/NULL, /*alignment*/2, /*boundary*/0,
590 /*lowaddr*/BUS_SPACE_MAXADDR_24BIT,
591 /*highaddr*/BUS_SPACE_MAXADDR,
592 /*filter*/NULL, /*filterarg*/NULL,
593 /*maxsize*/DSP_BUFFSIZE, /*nsegments*/1,
594 /*maxsegz*/0x3ffff,
595 /*flags*/0, &ad1816->parent_dmat) != 0) {
596 device_printf(dev, "unable to create dma tag\n");
597 goto no;
598 }
599 snprintf(status, SND_STATUSLEN, "at io 0x%lx irq %ld drq %ld",
600 rman_get_start(ad1816->io_base),
601 rman_get_start(ad1816->irq),
602 rman_get_start(ad1816->drq1));
603 if (ad1816->drq2) snprintf(status + strlen(status),
604 SND_STATUSLEN - strlen(status), ":%ld",
605 rman_get_start(ad1816->drq2));
606
607 if (pcm_register(dev, ad1816, 1, 1)) goto no;
620 pcm_addchan(dev, PCMDIR_REC, &ad1816_chantemplate, ad1816);
621 pcm_addchan(dev, PCMDIR_PLAY, &ad1816_chantemplate, ad1816);
608 pcm_addchan(dev, PCMDIR_REC, &ad1816chan_class, ad1816);
609 pcm_addchan(dev, PCMDIR_PLAY, &ad1816chan_class, ad1816);
622 pcm_setstatus(dev, status);
623
624 return 0;
625no:
626 ad1816_release_resources(ad1816, dev);
627 return ENXIO;
628
629}
630
631static int
632ad1816_detach(device_t dev)
633{
634 int r;
635 struct ad1816_info *ad1816;
636
637 r = pcm_unregister(dev);
638 if (r)
639 return r;
640
641 ad1816 = pcm_getdevinfo(dev);
642 ad1816_release_resources(ad1816, dev);
643 return 0;
644}
645
646static device_method_t ad1816_methods[] = {
647 /* Device interface */
648 DEVMETHOD(device_probe, ad1816_probe),
649 DEVMETHOD(device_attach, ad1816_attach),
650 DEVMETHOD(device_detach, ad1816_detach),
651
652 { 0, 0 }
653};
654
655static driver_t ad1816_driver = {
656 "pcm",
657 ad1816_methods,
658 sizeof(snddev_info),
659};
660
661DRIVER_MODULE(snd_ad1816, isa, ad1816_driver, pcm_devclass, 0, 0);
662MODULE_DEPEND(snd_ad1816, snd_pcm, PCM_MINVER, PCM_PREFVER, PCM_MAXVER);
663MODULE_VERSION(snd_ad1816, 1);
664
665
610 pcm_setstatus(dev, status);
611
612 return 0;
613no:
614 ad1816_release_resources(ad1816, dev);
615 return ENXIO;
616
617}
618
619static int
620ad1816_detach(device_t dev)
621{
622 int r;
623 struct ad1816_info *ad1816;
624
625 r = pcm_unregister(dev);
626 if (r)
627 return r;
628
629 ad1816 = pcm_getdevinfo(dev);
630 ad1816_release_resources(ad1816, dev);
631 return 0;
632}
633
634static device_method_t ad1816_methods[] = {
635 /* Device interface */
636 DEVMETHOD(device_probe, ad1816_probe),
637 DEVMETHOD(device_attach, ad1816_attach),
638 DEVMETHOD(device_detach, ad1816_detach),
639
640 { 0, 0 }
641};
642
643static driver_t ad1816_driver = {
644 "pcm",
645 ad1816_methods,
646 sizeof(snddev_info),
647};
648
649DRIVER_MODULE(snd_ad1816, isa, ad1816_driver, pcm_devclass, 0, 0);
650MODULE_DEPEND(snd_ad1816, snd_pcm, PCM_MINVER, PCM_PREFVER, PCM_MAXVER);
651MODULE_VERSION(snd_ad1816, 1);
652
653