melody.c revision 1.16
11.16Sdyoung/*	$NetBSD: melody.c,v 1.16 2011/07/19 15:55:27 dyoung Exp $ */
21.1Sis
31.1Sis/*-
41.5Sis * Copyright (c) 1997 The NetBSD Foundation, Inc.
51.4Sis * All rights reserved.
61.4Sis *
71.4Sis * This code is derived from software contributed to The NetBSD Foundation
81.4Sis * by Ignatios Souvatzis.
91.1Sis *
101.1Sis * Redistribution and use in source and binary forms, with or without
111.1Sis * modification, are permitted provided that the following conditions
121.1Sis * are met:
131.1Sis * 1. Redistributions of source code must retain the above copyright
141.1Sis *    notice, this list of conditions and the following disclaimer.
151.1Sis * 2. Redistributions in binary form must reproduce the above copyright
161.1Sis *    notice, this list of conditions and the following disclaimer in the
171.1Sis *    documentation and/or other materials provided with the distribution.
181.1Sis *
191.4Sis * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
201.4Sis * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
211.4Sis * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
221.4Sis * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
231.4Sis * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
241.4Sis * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
251.4Sis * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
261.4Sis * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
271.4Sis * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
281.4Sis * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
291.4Sis * POSSIBILITY OF SUCH DAMAGE.
301.1Sis */
311.9Saymeric
321.9Saymeric#include <sys/cdefs.h>
331.16Sdyoung__KERNEL_RCSID(0, "$NetBSD: melody.c,v 1.16 2011/07/19 15:55:27 dyoung Exp $");
341.1Sis
351.1Sis/*
361.1Sis * Melody audio driver.
371.1Sis *
381.1Sis * Currently, only minimum support for audio output. For audio/video
391.1Sis * synchronization, more is needed.
401.1Sis */
411.1Sis
421.1Sis#include <sys/types.h>
431.1Sis#include <sys/param.h>
441.1Sis#include <sys/systm.h>
451.1Sis#include <sys/kernel.h>
461.8Saymeric#include <sys/device.h>
471.16Sdyoung#include <sys/bus.h>
481.1Sis
491.1Sis#include <dev/ic/tms320av110reg.h>
501.1Sis#include <dev/ic/tms320av110var.h>
511.1Sis
521.1Sis#include <amiga/dev/zbusvar.h>
531.1Sis#include <amiga/amiga/isr.h>
541.1Sis
551.1Sisstruct melody_softc {
561.1Sis	struct tav_softc	sc_tav;
571.1Sis	struct bus_space_tag	sc_bst_leftbyte;
581.1Sis	struct isr		sc_isr;
591.13Slukem	uint8_t *		sc_intack;
601.1Sis};
611.1Sis
621.8Saymericint melody_match(struct device *, struct cfdata *, void *);
631.8Saymericvoid melody_attach(struct device *, struct device *, void *);
641.8Saymericvoid melody_intack(struct tav_softc *);
651.1Sis
661.11SthorpejCFATTACH_DECL(melody, sizeof(struct melody_softc),
671.11Sthorpej    melody_match, melody_attach, NULL, NULL);
681.1Sis
691.1Sisint
701.8Saymericmelody_match(struct device *parent, struct cfdata *cfp, void *aux)
711.1Sis{
721.1Sis	struct zbus_args *zap;
731.8Saymeric
741.1Sis	zap = aux;
751.1Sis	if (zap->manid != 2145)
761.1Sis		return (0);
771.1Sis
781.1Sis	if (zap->prodid != 128)
791.1Sis		return (0);
801.1Sis
811.1Sis	return (1);
821.1Sis}
831.1Sis
841.1Sisvoid
851.8Saymericmelody_attach(struct device *parent, struct device *self, void *aux)
861.1Sis{
871.1Sis	struct melody_softc *sc;
881.1Sis	struct zbus_args *zap;
891.1Sis	bus_space_tag_t iot;
901.1Sis	bus_space_handle_t ioh;
911.1Sis
921.1Sis	sc = (struct melody_softc *)self;
931.1Sis	zap = aux;
941.1Sis
951.1Sis	sc->sc_bst_leftbyte.base = (u_long)zap->va + 0;
961.7Saymeric	sc->sc_bst_leftbyte.absm = &amiga_bus_stride_2;
971.13Slukem	sc->sc_intack = (uint8_t *)zap->va + 0xc000;
981.1Sis
991.1Sis	/* set up board specific part in sc_tav */
1001.1Sis
1011.1Sis	iot = &sc->sc_bst_leftbyte;
1021.1Sis
1031.1Sis	if (bus_space_map(iot, 0, 128, 0, &ioh)) {
1041.1Sis		panic("melody: cant bus_space_map");
1051.1Sis		/* NOTREACHED */
1061.1Sis	}
1071.1Sis	sc->sc_tav.sc_iot = iot;
1081.1Sis	sc->sc_tav.sc_ioh = ioh;
1091.1Sis	sc->sc_tav.sc_pcm_ord = 0;
1101.1Sis	sc->sc_tav.sc_pcm_18 = 0;
1111.1Sis	sc->sc_tav.sc_dif = 0;
1121.1Sis	sc->sc_tav.sc_pcm_div = 12;
1131.1Sis
1141.1Sis	/*
1151.1Sis	 * Attach option boards now. They might provide additional
1161.1Sis	 * functionality to our audio part.
1171.1Sis	 */
1181.1Sis
1191.1Sis	/* attach our audio driver */
1201.8Saymeric
1211.1Sis	printf(" #%d", zap->serno);
1221.1Sis	tms320av110_attach_mi(&sc->sc_tav);
1231.1Sis	sc->sc_isr.isr_ipl = 6;
1241.1Sis	sc->sc_isr.isr_arg = &sc->sc_tav;
1251.1Sis	sc->sc_isr.isr_intr = tms320av110_intr;
1261.1Sis	add_isr(&sc->sc_isr);
1271.1Sis}
1281.1Sis
1291.1Sisvoid
1301.8Saymericmelody_intack(struct tav_softc *p)
1311.1Sis{
1321.1Sis	struct melody_softc *sc;
1331.1Sis
1341.1Sis	sc = (struct melody_softc *)p;
1351.8Saymeric	*sc->sc_intack = 0;
1361.1Sis}
137