melody.c revision 1.17
1/*	$NetBSD: melody.c,v 1.17 2011/11/23 23:07:28 jmcneill 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.17 2011/11/23 23:07:28 jmcneill 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
55struct 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
62int melody_match(struct device *, struct cfdata *, void *);
63void melody_attach(struct device *, struct device *, void *);
64void melody_intack(struct tav_softc *);
65
66CFATTACH_DECL(melody, sizeof(struct melody_softc),
67    melody_match, melody_attach, NULL, NULL);
68
69int
70melody_match(struct device *parent, struct cfdata *cfp, 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
84void
85melody_attach(struct device *parent, struct device *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 = (struct melody_softc *)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_iot = iot;
108	sc->sc_tav.sc_ioh = ioh;
109	sc->sc_tav.sc_pcm_ord = 0;
110	sc->sc_tav.sc_pcm_18 = 0;
111	sc->sc_tav.sc_dif = 0;
112	sc->sc_tav.sc_pcm_div = 12;
113
114	mutex_init(&sc->sc_tav.sc_lock, MUTEX_DEFAULT, IPL_NONE);
115	mutex_init(&sc->sc_tav.sc_intr_lock, MUTEX_DEFAULT, IPL_SCHED);
116	cv_init(&sc->sc_tav.sc_cv, device_xname(self));
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
133void
134melody_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