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