1*e622eac4Sisaki /* $NetBSD: melody.c,v 1.19 2019/05/08 13:40:14 isaki Exp $ */
211446b9bSis
311446b9bSis /*-
42c7fa23cSis * Copyright (c) 1997 The NetBSD Foundation, Inc.
5dc068e0dSis * All rights reserved.
6dc068e0dSis *
7dc068e0dSis * This code is derived from software contributed to The NetBSD Foundation
8dc068e0dSis * by Ignatios Souvatzis.
911446b9bSis *
1011446b9bSis * Redistribution and use in source and binary forms, with or without
1111446b9bSis * modification, are permitted provided that the following conditions
1211446b9bSis * are met:
1311446b9bSis * 1. Redistributions of source code must retain the above copyright
1411446b9bSis * notice, this list of conditions and the following disclaimer.
1511446b9bSis * 2. Redistributions in binary form must reproduce the above copyright
1611446b9bSis * notice, this list of conditions and the following disclaimer in the
1711446b9bSis * documentation and/or other materials provided with the distribution.
1811446b9bSis *
19dc068e0dSis * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20dc068e0dSis * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21dc068e0dSis * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22dc068e0dSis * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23dc068e0dSis * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24dc068e0dSis * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25dc068e0dSis * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26dc068e0dSis * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27dc068e0dSis * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28dc068e0dSis * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29dc068e0dSis * POSSIBILITY OF SUCH DAMAGE.
3011446b9bSis */
3111446b9bSis
321ea4df81Saymeric #include <sys/cdefs.h>
33*e622eac4Sisaki __KERNEL_RCSID(0, "$NetBSD: melody.c,v 1.19 2019/05/08 13:40:14 isaki Exp $");
341ea4df81Saymeric
3511446b9bSis /*
3611446b9bSis * Melody audio driver.
3711446b9bSis *
3811446b9bSis * Currently, only minimum support for audio output. For audio/video
3911446b9bSis * synchronization, more is needed.
4011446b9bSis */
4111446b9bSis
4211446b9bSis #include <sys/types.h>
4311446b9bSis #include <sys/param.h>
4411446b9bSis #include <sys/systm.h>
4511446b9bSis #include <sys/kernel.h>
4611446b9bSis #include <sys/device.h>
473a45360bSdyoung #include <sys/bus.h>
4811446b9bSis
4911446b9bSis #include <dev/ic/tms320av110reg.h>
5011446b9bSis #include <dev/ic/tms320av110var.h>
5111446b9bSis
5211446b9bSis #include <amiga/dev/zbusvar.h>
5311446b9bSis #include <amiga/amiga/isr.h>
5411446b9bSis
5511446b9bSis struct melody_softc {
5611446b9bSis struct tav_softc sc_tav;
5711446b9bSis struct bus_space_tag sc_bst_leftbyte;
5811446b9bSis struct isr sc_isr;
592c4f38e0Slukem uint8_t * sc_intack;
6011446b9bSis };
6111446b9bSis
62cbab9cadSchs int melody_match(device_t, cfdata_t, void *);
63cbab9cadSchs void melody_attach(device_t, device_t, void *);
649382c873Saymeric void melody_intack(struct tav_softc *);
6511446b9bSis
66cbab9cadSchs CFATTACH_DECL_NEW(melody, sizeof(struct melody_softc),
67c5e91d44Sthorpej melody_match, melody_attach, NULL, NULL);
6811446b9bSis
6911446b9bSis int
melody_match(device_t parent,cfdata_t cf,void * aux)70cbab9cadSchs melody_match(device_t parent, cfdata_t cf, void *aux)
7111446b9bSis {
7211446b9bSis struct zbus_args *zap;
7311446b9bSis
7411446b9bSis zap = aux;
7511446b9bSis if (zap->manid != 2145)
7611446b9bSis return (0);
7711446b9bSis
7811446b9bSis if (zap->prodid != 128)
7911446b9bSis return (0);
8011446b9bSis
8111446b9bSis return (1);
8211446b9bSis }
8311446b9bSis
8411446b9bSis void
melody_attach(device_t parent,device_t self,void * aux)85cbab9cadSchs melody_attach(device_t parent, device_t self, void *aux)
8611446b9bSis {
8711446b9bSis struct melody_softc *sc;
8811446b9bSis struct zbus_args *zap;
8911446b9bSis bus_space_tag_t iot;
9011446b9bSis bus_space_handle_t ioh;
9111446b9bSis
92cbab9cadSchs sc = device_private(self);
9311446b9bSis zap = aux;
9411446b9bSis
9511446b9bSis sc->sc_bst_leftbyte.base = (u_long)zap->va + 0;
96d7e70f70Saymeric sc->sc_bst_leftbyte.absm = &amiga_bus_stride_2;
972c4f38e0Slukem sc->sc_intack = (uint8_t *)zap->va + 0xc000;
9811446b9bSis
9911446b9bSis /* set up board specific part in sc_tav */
10011446b9bSis
10111446b9bSis iot = &sc->sc_bst_leftbyte;
10211446b9bSis
10311446b9bSis if (bus_space_map(iot, 0, 128, 0, &ioh)) {
10411446b9bSis panic("melody: cant bus_space_map");
10511446b9bSis /* NOTREACHED */
10611446b9bSis }
107cbab9cadSchs sc->sc_tav.sc_dev = self;
10811446b9bSis sc->sc_tav.sc_iot = iot;
10911446b9bSis sc->sc_tav.sc_ioh = ioh;
11011446b9bSis sc->sc_tav.sc_pcm_ord = 0;
11111446b9bSis sc->sc_tav.sc_pcm_18 = 0;
11211446b9bSis sc->sc_tav.sc_dif = 0;
11311446b9bSis sc->sc_tav.sc_pcm_div = 12;
11411446b9bSis
1158a962f23Sjmcneill mutex_init(&sc->sc_tav.sc_lock, MUTEX_DEFAULT, IPL_NONE);
1168a962f23Sjmcneill mutex_init(&sc->sc_tav.sc_intr_lock, MUTEX_DEFAULT, IPL_SCHED);
1178a962f23Sjmcneill
11811446b9bSis /*
11911446b9bSis * Attach option boards now. They might provide additional
12011446b9bSis * functionality to our audio part.
12111446b9bSis */
12211446b9bSis
12311446b9bSis /* attach our audio driver */
12411446b9bSis
12511446b9bSis printf(" #%d", zap->serno);
12611446b9bSis tms320av110_attach_mi(&sc->sc_tav);
12711446b9bSis sc->sc_isr.isr_ipl = 6;
12811446b9bSis sc->sc_isr.isr_arg = &sc->sc_tav;
12911446b9bSis sc->sc_isr.isr_intr = tms320av110_intr;
13011446b9bSis add_isr(&sc->sc_isr);
13111446b9bSis }
13211446b9bSis
13311446b9bSis void
melody_intack(struct tav_softc * p)1349382c873Saymeric melody_intack(struct tav_softc *p)
13511446b9bSis {
13611446b9bSis struct melody_softc *sc;
13711446b9bSis
13811446b9bSis sc = (struct melody_softc *)p;
13911446b9bSis *sc->sc_intack = 0;
14011446b9bSis }
141