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