ad1816.c revision 67652
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 $
29 */
30
31#include <dev/sound/pcm/sound.h>
32#include <dev/sound/isa/ad1816.h>
33
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
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
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
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
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
332/* channel interface */
333static void *
334ad1816chan_init(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
348ad1816chan_setdir(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
360ad1816chan_setformat(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
402ad1816chan_setspeed(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
413ad1816chan_setblocksize(void *data, u_int32_t blocksize)
414{
415	return blocksize;
416}
417
418static int
419ad1816chan_trigger(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
469ad1816chan_getptr(void *data)
470{
471	struct ad1816_chinfo *ch = data;
472	return buf_isadmaptr(ch->buffer);
473}
474
475static pcmchan_caps *
476ad1816chan_getcaps(void *data)
477{
478	return &ad1816_caps;
479}
480
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);
599    	mixer_init(dev, &ad1816_mixer, ad1816);
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;
620    	pcm_addchan(dev, PCMDIR_REC, &ad1816_chantemplate, ad1816);
621    	pcm_addchan(dev, PCMDIR_PLAY, &ad1816_chantemplate, 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
666