xref: /netbsd-src/sys/dev/sbus/cs4231_sbus.c (revision 220b5c059a84c51ea44107ea8951a57ffaecdc8c)
1 /*	$NetBSD: cs4231_sbus.c,v 1.16 2001/11/13 06:58:17 lukem Exp $	*/
2 
3 /*-
4  * Copyright (c) 1998, 1999 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Paul Kranenburg.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:
20  *        This product includes software developed by the NetBSD
21  *        Foundation, Inc. and its contributors.
22  * 4. Neither the name of The NetBSD Foundation nor the names of its
23  *    contributors may be used to endorse or promote products derived
24  *    from this software without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36  * POSSIBILITY OF SUCH DAMAGE.
37  */
38 
39 #include <sys/cdefs.h>
40 __KERNEL_RCSID(0, "$NetBSD: cs4231_sbus.c,v 1.16 2001/11/13 06:58:17 lukem Exp $");
41 
42 #include "audio.h"
43 #if NAUDIO > 0
44 
45 #include <sys/param.h>
46 #include <sys/systm.h>
47 #include <sys/errno.h>
48 #include <sys/device.h>
49 #include <sys/malloc.h>
50 
51 #include <machine/bus.h>
52 #include <machine/intr.h>
53 
54 #include <dev/sbus/sbusvar.h>
55 
56 #include <sys/audioio.h>
57 #include <dev/audio_if.h>
58 
59 #include <dev/ic/ad1848reg.h>
60 #include <dev/ic/cs4231reg.h>
61 #include <dev/ic/ad1848var.h>
62 #include <dev/ic/cs4231var.h>
63 
64 #define AUDIO_ROM_NAME		"SUNW,CS4231"
65 #define CS4231_REG_SIZE		16
66 
67 /* autoconfiguration driver */
68 void	cs4231_attach_sbus __P((struct device *, struct device *, void *));
69 int	cs4231_match_sbus __P((struct device *, struct cfdata *, void *));
70 
71 struct cfattach audiocs_sbus_ca = {
72 	sizeof(struct cs4231_softc), cs4231_match_sbus, cs4231_attach_sbus
73 };
74 
75 /* autoconfig routines */
76 
77 int
78 cs4231_match_sbus(parent, cf, aux)
79 	struct device *parent;
80 	struct cfdata *cf;
81 	void *aux;
82 {
83 	struct sbus_attach_args *sa = aux;
84 
85 	return (strcmp(AUDIO_ROM_NAME, sa->sa_name) == 0);
86 }
87 
88 /*
89  * Audio chip found.
90  */
91 void
92 cs4231_attach_sbus(parent, self, aux)
93 	struct device *parent, *self;
94 	void *aux;
95 {
96 	struct cs4231_softc *sc = (struct cs4231_softc *)self;
97 	struct sbus_attach_args *sa = aux;
98 	bus_space_handle_t bh;
99 
100 	sc->sc_bustag = sa->sa_bustag;
101 	sc->sc_dmatag = sa->sa_dmatag;
102 
103 	sc->sc_ad1848.parent = sc;
104 	sc->sc_ad1848.sc_iot = sc->sc_bustag;
105 	sc->sc_ad1848.sc_readreg = cs4231_read;
106 	sc->sc_ad1848.sc_writereg = cs4231_write;
107 
108 	/*
109 	 * Map my registers in, if they aren't already in virtual
110 	 * address space.
111 	 */
112 	if (sa->sa_npromvaddrs) {
113 		bh = (bus_space_handle_t)sa->sa_promvaddrs[0];
114 	} else {
115 		if (sbus_bus_map(sa->sa_bustag, sa->sa_slot,
116 				 sa->sa_offset,
117 				 sa->sa_size,
118 				 BUS_SPACE_MAP_LINEAR,
119 				 0, &bh) != 0) {
120 			printf("%s @ sbus: cannot map registers\n",
121 				self->dv_xname);
122 			return;
123 		}
124 	}
125 
126 	sc->sc_ad1848.sc_ioh = bh;
127 	sc->sc_dmareg = (struct apc_dma *)(u_long)(bh + CS4231_REG_SIZE);
128 
129 	cs4231_init(sc);
130 
131 	/* Put ad1848 driver in `MODE 2' mode */
132 	sc->sc_ad1848.mode = 2;
133 	ad1848_attach(&sc->sc_ad1848);
134 
135 	printf("\n");
136 
137 	sbus_establish(&sc->sc_sd, &sc->sc_ad1848.sc_dev);
138 
139 	/* Establish interrupt channel */
140 	if (sa->sa_nintr)
141 		bus_intr_establish(sa->sa_bustag,
142 				   sa->sa_pri, IPL_AUDIO, 0,
143 				   cs4231_intr, sc);
144 
145 	evcnt_attach_dynamic(&sc->sc_intrcnt, EVCNT_TYPE_INTR, NULL,
146 	    sc->sc_ad1848.sc_dev.dv_xname, "intr");
147 	audio_attach_mi(&audiocs_hw_if, sc, &sc->sc_ad1848.sc_dev);
148 }
149 #endif
150