1 /* $NetBSD: melody.c,v 1.19 2019/05/08 13:40:14 isaki Exp $ */
2
3 /*-
4 * Copyright (c) 1997 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Ignatios Souvatzis.
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 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: melody.c,v 1.19 2019/05/08 13:40:14 isaki Exp $");
34
35 /*
36 * Melody audio driver.
37 *
38 * Currently, only minimum support for audio output. For audio/video
39 * synchronization, more is needed.
40 */
41
42 #include <sys/types.h>
43 #include <sys/param.h>
44 #include <sys/systm.h>
45 #include <sys/kernel.h>
46 #include <sys/device.h>
47 #include <sys/bus.h>
48
49 #include <dev/ic/tms320av110reg.h>
50 #include <dev/ic/tms320av110var.h>
51
52 #include <amiga/dev/zbusvar.h>
53 #include <amiga/amiga/isr.h>
54
55 struct melody_softc {
56 struct tav_softc sc_tav;
57 struct bus_space_tag sc_bst_leftbyte;
58 struct isr sc_isr;
59 uint8_t * sc_intack;
60 };
61
62 int melody_match(device_t, cfdata_t, void *);
63 void melody_attach(device_t, device_t, void *);
64 void melody_intack(struct tav_softc *);
65
66 CFATTACH_DECL_NEW(melody, sizeof(struct melody_softc),
67 melody_match, melody_attach, NULL, NULL);
68
69 int
melody_match(device_t parent,cfdata_t cf,void * aux)70 melody_match(device_t parent, cfdata_t cf, void *aux)
71 {
72 struct zbus_args *zap;
73
74 zap = aux;
75 if (zap->manid != 2145)
76 return (0);
77
78 if (zap->prodid != 128)
79 return (0);
80
81 return (1);
82 }
83
84 void
melody_attach(device_t parent,device_t self,void * aux)85 melody_attach(device_t parent, device_t self, void *aux)
86 {
87 struct melody_softc *sc;
88 struct zbus_args *zap;
89 bus_space_tag_t iot;
90 bus_space_handle_t ioh;
91
92 sc = device_private(self);
93 zap = aux;
94
95 sc->sc_bst_leftbyte.base = (u_long)zap->va + 0;
96 sc->sc_bst_leftbyte.absm = &amiga_bus_stride_2;
97 sc->sc_intack = (uint8_t *)zap->va + 0xc000;
98
99 /* set up board specific part in sc_tav */
100
101 iot = &sc->sc_bst_leftbyte;
102
103 if (bus_space_map(iot, 0, 128, 0, &ioh)) {
104 panic("melody: cant bus_space_map");
105 /* NOTREACHED */
106 }
107 sc->sc_tav.sc_dev = self;
108 sc->sc_tav.sc_iot = iot;
109 sc->sc_tav.sc_ioh = ioh;
110 sc->sc_tav.sc_pcm_ord = 0;
111 sc->sc_tav.sc_pcm_18 = 0;
112 sc->sc_tav.sc_dif = 0;
113 sc->sc_tav.sc_pcm_div = 12;
114
115 mutex_init(&sc->sc_tav.sc_lock, MUTEX_DEFAULT, IPL_NONE);
116 mutex_init(&sc->sc_tav.sc_intr_lock, MUTEX_DEFAULT, IPL_SCHED);
117
118 /*
119 * Attach option boards now. They might provide additional
120 * functionality to our audio part.
121 */
122
123 /* attach our audio driver */
124
125 printf(" #%d", zap->serno);
126 tms320av110_attach_mi(&sc->sc_tav);
127 sc->sc_isr.isr_ipl = 6;
128 sc->sc_isr.isr_arg = &sc->sc_tav;
129 sc->sc_isr.isr_intr = tms320av110_intr;
130 add_isr(&sc->sc_isr);
131 }
132
133 void
melody_intack(struct tav_softc * p)134 melody_intack(struct tav_softc *p)
135 {
136 struct melody_softc *sc;
137
138 sc = (struct melody_softc *)p;
139 *sc->sc_intack = 0;
140 }
141