pckbc_jensenio.c revision 1.15 1 /* $NetBSD: pckbc_jensenio.c,v 1.15 2020/11/18 02:04:29 thorpej Exp $ */
2
3 /*-
4 * Copyright (c) 1999 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe.
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 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
33
34 __KERNEL_RCSID(0, "$NetBSD: pckbc_jensenio.c,v 1.15 2020/11/18 02:04:29 thorpej Exp $");
35
36 #include <sys/param.h>
37 #include <sys/systm.h>
38 #include <sys/kernel.h>
39 #include <sys/proc.h>
40 #include <sys/device.h>
41 #include <sys/kmem.h>
42 #include <sys/errno.h>
43 #include <sys/queue.h>
44 #include <sys/intr.h>
45 #include <sys/bus.h>
46 #include <sys/cpu.h>
47
48 #include <dev/ic/i8042reg.h>
49 #include <dev/ic/pckbcvar.h>
50
51 #include <dev/eisa/eisavar.h>
52
53 #include <dev/isa/isavar.h>
54
55 #include <alpha/jensenio/jenseniovar.h>
56
57 struct pckbc_jensenio_softc {
58 struct pckbc_softc sc_pckbc; /* real "pckbc" softc */
59
60 /* Jensen-specific goo. */
61 struct jensenio_scb_intrhand sc_jih[PCKBC_NSLOTS];
62 };
63
64 int pckbc_jensenio_match(device_t, cfdata_t, void *);
65 void pckbc_jensenio_attach(device_t, device_t, void *);
66
67 CFATTACH_DECL_NEW(pckbc_jensenio, sizeof(struct pckbc_jensenio_softc),
68 pckbc_jensenio_match, pckbc_jensenio_attach, NULL, NULL);
69
70 void pckbc_jensenio_intr_establish(struct pckbc_softc *, pckbc_slot_t);
71
72 int
73 pckbc_jensenio_match(device_t parent, cfdata_t match, void *aux)
74 {
75 struct jensenio_attach_args *ja = aux;
76
77 /* Always present. */
78 if (strcmp(ja->ja_name, match->cf_name) == 0)
79 return (1);
80
81 return (0);
82 }
83
84 void
85 pckbc_jensenio_attach(device_t parent, device_t self, void *aux)
86 {
87 struct pckbc_jensenio_softc *jsc = device_private(self);
88 struct pckbc_softc *sc = &jsc->sc_pckbc;
89 struct jensenio_attach_args *ja = aux;
90 struct pckbc_internal *t;
91 bus_space_handle_t ioh_d, ioh_c;
92
93 sc->sc_dv = self;
94
95 /*
96 * Set up IRQs.
97 */
98 jsc->sc_jih[PCKBC_KBD_SLOT].jih_vec = ja->ja_irq[0];
99 jsc->sc_jih[PCKBC_AUX_SLOT].jih_vec = ja->ja_irq[1];
100
101 sc->intr_establish = pckbc_jensenio_intr_establish;
102
103 if (pckbc_is_console(ja->ja_iot, ja->ja_ioaddr)) {
104 t = &pckbc_consdata;
105 pckbc_console_attached = 1;
106 /* t->t_cmdbyte was initialized by cnattach */
107 } else {
108 if (bus_space_map(ja->ja_iot, ja->ja_ioaddr + KBDATAP,
109 1, 0, &ioh_d) != 0 ||
110 bus_space_map(ja->ja_iot, ja->ja_ioaddr + KBCMDP,
111 1, 0, &ioh_c) != 0)
112 panic("pckbc_jensenio_attach: couldn't map");
113
114 t = kmem_zalloc(sizeof(struct pckbc_internal), KM_SLEEP);
115 t->t_iot = ja->ja_iot;
116 t->t_ioh_d = ioh_d;
117 t->t_ioh_c = ioh_c;
118 t->t_addr = ja->ja_ioaddr;
119 t->t_cmdbyte = KC8_CPU; /* Enable ports */
120 }
121
122 t->t_sc = sc;
123 sc->id = t;
124
125 aprint_normal("\n");
126
127 /* Finish off the attach. */
128 pckbc_attach(sc);
129 }
130
131 void
132 pckbc_jensenio_intr_establish(struct pckbc_softc *sc, pckbc_slot_t slot)
133 {
134 struct pckbc_jensenio_softc *jsc = (void *) sc;
135
136 jensenio_intr_establish(&jsc->sc_jih[slot],
137 jsc->sc_jih[slot].jih_vec, 0, pckbcintr, sc);
138
139 aprint_normal_dev(sc->sc_dv, "%s slot interrupting at vector 0x%lx\n",
140 pckbc_slot_names[slot], jsc->sc_jih[slot].jih_vec);
141 }
142