1 /* $NetBSD: pckbc_hpc.c,v 1.11 2020/11/21 17:18:31 thorpej Exp $ */
2
3 /*
4 * Copyright (c) 2003 Christopher SEKIYA
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed for the
18 * NetBSD Project. See http://www.NetBSD.org/ for
19 * information about NetBSD.
20 * 4. The name of the author may not be used to endorse or promote products
21 * derived from this software without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */
34
35 #include <sys/cdefs.h>
36 __KERNEL_RCSID(0, "$NetBSD: pckbc_hpc.c,v 1.11 2020/11/21 17:18:31 thorpej Exp $");
37
38 #include <sys/param.h>
39 #include <sys/systm.h>
40 #include <sys/kernel.h>
41 #include <sys/proc.h>
42 #include <sys/device.h>
43 #include <sys/kmem.h>
44 #include <sys/errno.h>
45 #include <sys/queue.h>
46 #include <sys/bus.h>
47
48 #include <machine/autoconf.h>
49 #include <machine/machtype.h>
50
51 #include <dev/ic/i8042reg.h>
52 #include <dev/ic/pckbcvar.h>
53
54 #include <sgimips/hpc/hpcreg.h>
55 #include <sgimips/hpc/hpcvar.h>
56
57 struct pckbc_hpc_softc {
58 struct pckbc_softc sc_pckbc;
59
60 int sc_irq;
61 int sc_hasintr;
62 };
63
64 static int pckbc_hpc_match(device_t, cfdata_t, void *);
65 static void pckbc_hpc_attach(device_t, device_t, void *);
66 static void pckbc_hpc_intr_establish(struct pckbc_softc *, pckbc_slot_t);
67
68 CFATTACH_DECL_NEW(pckbc_hpc, sizeof(struct pckbc_hpc_softc),
69 pckbc_hpc_match, pckbc_hpc_attach, NULL, NULL);
70
71 static int
pckbc_hpc_match(device_t parent,cfdata_t cf,void * aux)72 pckbc_hpc_match(device_t parent, cfdata_t cf, void *aux)
73 {
74 struct hpc_attach_args *ha = aux;
75
76 if (strcmp(ha->ha_name, cf->cf_name) == 0)
77 return (1);
78
79 return (0);
80 }
81
82 static void
pckbc_hpc_attach(device_t parent,device_t self,void * aux)83 pckbc_hpc_attach(device_t parent, device_t self, void *aux)
84 {
85 struct pckbc_hpc_softc *msc = device_private(self);
86 struct pckbc_softc *sc = &msc->sc_pckbc;
87 struct hpc_attach_args *haa = aux;
88 struct pckbc_internal *t;
89 bus_space_handle_t ioh_d, ioh_c;
90
91 sc->sc_dv = self;
92
93 msc->sc_irq = haa->ha_irq;
94
95 msc->sc_hasintr = 0;
96
97 sc->intr_establish = pckbc_hpc_intr_establish;
98
99 /* XXX Ugly hack & kludge XXX */
100 if (pckbc_is_console(haa->ha_st, MIPS_KSEG1_TO_PHYS(haa->ha_sh +
101 haa->ha_devoff))) {
102 t = &pckbc_consdata;
103 pckbc_console_attached = 1;
104 } else {
105 /* XXX should be bus_space_map() */
106 if (bus_space_subregion(haa->ha_st, haa->ha_sh,
107 haa->ha_devoff + KBDATAP, 1, &ioh_d) ||
108 bus_space_subregion(haa->ha_st, haa->ha_sh,
109 haa->ha_devoff + KBCMDP, 1, &ioh_c))
110 panic("pckbc_hpc_attach: couldn't map");
111
112 t = kmem_zalloc(sizeof(struct pckbc_internal), KM_SLEEP);
113 t->t_iot = hpc_memt;
114 t->t_ioh_d = ioh_d;
115 t->t_ioh_c = ioh_c;
116 t->t_addr = haa->ha_sh;
117 t->t_cmdbyte = KC8_CPU; /* Enable ports */
118 callout_init(&t->t_cleanup, 0);
119 }
120
121 t->t_sc = sc;
122 sc->id = t;
123
124 aprint_normal("\n");
125
126 /* Finish off the attach. */
127 pckbc_attach(sc);
128 }
129
130 static void
pckbc_hpc_intr_establish(struct pckbc_softc * sc,pckbc_slot_t slot)131 pckbc_hpc_intr_establish(struct pckbc_softc * sc, pckbc_slot_t slot)
132 {
133 struct pckbc_hpc_softc *msc = (void *) sc;
134
135 if (msc->sc_hasintr)
136 return;
137
138 if (cpu_intr_establish(msc->sc_irq, IPL_TTY, pckbcintr, sc) == NULL) {
139 aprint_error_dev(sc->sc_dv,
140 "unable to establish interrupt for %s slot\n",
141 pckbc_slot_names[slot]);
142 } else {
143 msc->sc_hasintr = 1;
144 }
145 }
146