Home | History | Annotate | Line # | Download | only in dev
      1  1.3  thorpej /*	$NetBSD: arcofi_dio.c,v 1.3 2024/01/16 05:48:28 thorpej Exp $	*/
      2  1.1  tsutsui /*	$OpenBSD: arcofi_dio.c,v 1.1 2011/12/21 23:12:03 miod Exp $	*/
      3  1.1  tsutsui 
      4  1.1  tsutsui /*
      5  1.1  tsutsui  * Copyright (c) 2011 Miodrag Vallat.
      6  1.1  tsutsui  *
      7  1.1  tsutsui  * Permission to use, copy, modify, and distribute this software for any
      8  1.1  tsutsui  * purpose with or without fee is hereby granted, provided that the above
      9  1.1  tsutsui  * copyright notice and this permission notice appear in all copies.
     10  1.1  tsutsui  *
     11  1.1  tsutsui  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
     12  1.1  tsutsui  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
     13  1.1  tsutsui  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
     14  1.1  tsutsui  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
     15  1.1  tsutsui  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
     16  1.1  tsutsui  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
     17  1.1  tsutsui  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
     18  1.1  tsutsui  */
     19  1.1  tsutsui 
     20  1.1  tsutsui #include <sys/param.h>
     21  1.1  tsutsui #include <sys/systm.h>
     22  1.1  tsutsui #include <sys/conf.h>
     23  1.1  tsutsui #include <sys/device.h>
     24  1.1  tsutsui #include <sys/bus.h>
     25  1.1  tsutsui #include <sys/intr.h>
     26  1.1  tsutsui 
     27  1.1  tsutsui #include <sys/audioio.h>
     28  1.2    isaki #include <dev/audio/audio_if.h>
     29  1.1  tsutsui #include <dev/ic/arcofivar.h>
     30  1.1  tsutsui 
     31  1.1  tsutsui #include <hp300/dev/dioreg.h>
     32  1.1  tsutsui #include <hp300/dev/diovar.h>
     33  1.1  tsutsui 
     34  1.1  tsutsui #include <hp300/dev/diodevs.h>
     35  1.1  tsutsui 
     36  1.1  tsutsui #define SOFTINT_AUDIO	SOFTINT_SERIAL	/* XXX */
     37  1.1  tsutsui 
     38  1.1  tsutsui static void	arcofi_dio_attach(device_t, device_t, void *);
     39  1.1  tsutsui static int	arcofi_dio_match(device_t, cfdata_t, void *);
     40  1.1  tsutsui 
     41  1.1  tsutsui struct arcofi_dio_softc {
     42  1.1  tsutsui 	struct arcofi_softc	sc_arcofi;
     43  1.1  tsutsui 
     44  1.1  tsutsui 	struct bus_space_tag sc_tag;
     45  1.1  tsutsui };
     46  1.1  tsutsui 
     47  1.1  tsutsui CFATTACH_DECL_NEW(arcofi_dio, sizeof(struct arcofi_dio_softc),
     48  1.1  tsutsui     arcofi_dio_match, arcofi_dio_attach, NULL, NULL);
     49  1.1  tsutsui 
     50  1.1  tsutsui static int
     51  1.1  tsutsui arcofi_dio_match(device_t parent, cfdata_t match, void *aux)
     52  1.1  tsutsui {
     53  1.1  tsutsui 	struct dio_attach_args *da = aux;
     54  1.1  tsutsui 
     55  1.1  tsutsui 	if (da->da_id != DIO_DEVICE_ID_AUDIO)
     56  1.1  tsutsui 		return 0;
     57  1.1  tsutsui 
     58  1.1  tsutsui 	return 1;
     59  1.1  tsutsui }
     60  1.1  tsutsui 
     61  1.1  tsutsui static void
     62  1.1  tsutsui arcofi_dio_attach(device_t parent, device_t self, void *aux)
     63  1.1  tsutsui {
     64  1.1  tsutsui 	struct arcofi_dio_softc *adsc = device_private(self);
     65  1.1  tsutsui 	struct arcofi_softc *sc = &adsc->sc_arcofi;
     66  1.1  tsutsui 	struct dio_attach_args *da = aux;
     67  1.1  tsutsui 	bus_space_tag_t iot = &adsc->sc_tag;
     68  1.1  tsutsui 	int ipl;
     69  1.1  tsutsui 
     70  1.1  tsutsui 	sc->sc_dev = self;
     71  1.1  tsutsui 
     72  1.1  tsutsui 	/* XXX is it better to use sc->sc_reg[] to handle odd sparse map? */
     73  1.1  tsutsui 	memcpy(iot, da->da_bst, sizeof(struct bus_space_tag));
     74  1.1  tsutsui 	dio_set_bus_space_oddbyte(iot);
     75  1.1  tsutsui 	sc->sc_iot = iot;
     76  1.1  tsutsui 
     77  1.1  tsutsui 	if (bus_space_map(iot, da->da_addr, DIOII_SIZEOFF, 0,
     78  1.1  tsutsui 	    &sc->sc_ioh) != 0) {
     79  1.1  tsutsui 		aprint_error(": can't map registers\n");
     80  1.1  tsutsui 		return;
     81  1.1  tsutsui 	}
     82  1.1  tsutsui 
     83  1.1  tsutsui 	ipl = da->da_ipl;
     84  1.3  thorpej 	dio_intr_establish(arcofi_hwintr, sc, ipl, ISRPRI_AUDIO);
     85  1.1  tsutsui 
     86  1.1  tsutsui 	aprint_normal("\n");
     87  1.1  tsutsui 
     88  1.1  tsutsui 	arcofi_attach(sc, "dio");
     89  1.1  tsutsui }
     90