1 /* $OpenBSD: necsb.c,v 1.6 2024/06/01 00:48:16 aoyama Exp $ */
2 /* $NecBSD: nec86_isa.c,v 1.9 1998/09/26 11:31:11 kmatsuda Exp $ */
3 /* $NetBSD$ */
4
5 /*
6 * [NetBSD for NEC PC-98 series]
7 * Copyright (c) 1995, 1996, 1997, 1998
8 * NetBSD/pc98 porting staff. All rights reserved.
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 * 3. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
25 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
29 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
32 */
33
34 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/device.h>
37
38 #include <machine/board.h> /* PC_BASE */
39 #include <machine/bus.h>
40
41 #include <sys/audioio.h>
42 #include <dev/audio_if.h>
43
44 #include <luna88k/cbus/nec86reg.h>
45 #include <luna88k/cbus/nec86hwvar.h>
46 #include <luna88k/cbus/nec86var.h>
47
48 #include <luna88k/cbus/cbusvar.h> /* cbus_isrlink() */
49
50 #define NECSB_BASE (PCEXIO_BASE + 0xa460)
51
52 int necsb_match(struct device *, void *, void *);
53 void necsb_attach(struct device *, struct device *, void *);
54
55 const struct cfattach necsb_ca = {
56 sizeof(struct nec86_softc), necsb_match, necsb_attach
57 };
58
59 struct cfdriver necsb_cd = {
60 NULL, "necsb", DV_DULL
61 };
62
63 /* bus space tag for necsb */
64 struct luna88k_bus_space_tag necsb_bst = {
65 0, /* when reading/writing 1 byte, no shift is needed. */
66 0,
67 0,
68 0,
69 0, /* no offset */
70 };
71
72 int
necsb_match(struct device * parent,void * cf,void * aux)73 necsb_match(struct device *parent, void *cf, void *aux)
74 {
75 struct cbus_attach_args *caa = aux;
76
77 if (strcmp(caa->ca_name, necsb_cd.cd_name))
78 return 0;
79
80 return 1;
81 }
82
83 void
necsb_attach(struct device * parent,struct device * self,void * aux)84 necsb_attach(struct device *parent, struct device *self, void *aux)
85 {
86 struct nec86_softc *nsc = (struct nec86_softc *)self;
87 struct nec86hw_softc *ysc = &nsc->sc_nec86hw;
88 #if 0
89 struct cbus_attach_args *caa = aux;
90 #endif
91
92 bus_space_tag_t iot = &necsb_bst;
93
94 nsc->sc_n86iot = iot;
95 nsc->sc_n86ioh =
96 (bus_space_handle_t)(NECSB_BASE + NEC86_SOUND_ID);
97
98 ysc->sc_iot = iot;
99 ysc->sc_ioh =
100 (bus_space_handle_t)(NECSB_BASE + NEC86_COREOFFSET);
101 ysc->sc_cfgflags = 0; /* original 'PC-9801-86' */
102
103 nsc->sc_ym_iot = iot;
104 nsc->sc_ym_iobase = (bus_space_handle_t)PCEXIO_BASE;
105 nsc->sc_ym_ioh = (bus_space_handle_t)0; /* default */
106
107 nec86_attachsubr(nsc);
108
109 if (nsc->sc_intlevel == -1)
110 return;
111
112 if ((nsc->sc_intlevel < 0) || (nsc->sc_intlevel >= NCBUSISR))
113 panic("necsb_attach: bad INT level");
114
115 /* XXX: check return value ? */
116 cbus_isrlink(nec86hw_intr, ysc, nsc->sc_intlevel, IPL_AUDIO,
117 self->dv_xname);
118 }
119