1 /* $NetBSD: pckbc_sableio.c,v 1.8 2008/04/28 20:23:12 martin Exp $ */
4 * Copyright (c) 1999 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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.
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.
32 #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
34 __KERNEL_RCSID(0, "$NetBSD: pckbc_sableio.c,v 1.8 2008/04/28 20:23:12 martin Exp $");
36 #include <sys/param.h>
37 #include <sys/systm.h>
38 #include <sys/kernel.h>
40 #include <sys/device.h>
41 #include <sys/malloc.h>
42 #include <sys/errno.h>
43 #include <sys/queue.h>
47 #include <dev/ic/i8042reg.h>
48 #include <dev/ic/pckbcvar.h>
50 #include <dev/pci/pcivar.h>
51 #include <dev/isa/isavar.h>
53 #include <alpha/sableio/sableiovar.h>
55 struct pckbc_sableio_softc
{
56 struct pckbc_softc sc_pckbc
; /* real "pckbc" softc */
58 /* STDIO-specific goo. */
59 void *sc_ih
[PCKBC_NSLOTS
]; /* interrupt handlers */
60 int sc_irq
[PCKBC_NSLOTS
]; /* Sable IRQs to use */
61 pci_chipset_tag_t sc_pc
; /* PCI chipset for registering intrs */
64 int pckbc_sableio_match(device_t
, cfdata_t
, void *);
65 void pckbc_sableio_attach(device_t
, device_t
, void *);
67 CFATTACH_DECL_NEW(pckbc_sableio
, sizeof(struct pckbc_sableio_softc
),
68 pckbc_sableio_match
, pckbc_sableio_attach
, NULL
, NULL
);
70 void pckbc_sableio_intr_establish(struct pckbc_softc
*, pckbc_slot_t
);
73 pckbc_sableio_match(device_t parent
, cfdata_t match
, void *aux
)
75 struct sableio_attach_args
*sa
= aux
;
78 if (strcmp(sa
->sa_name
, match
->cf_name
) == 0)
85 pckbc_sableio_attach(device_t parent
, device_t self
, void *aux
)
87 struct pckbc_sableio_softc
*ssc
= device_private(self
);
88 struct pckbc_softc
*sc
= &ssc
->sc_pckbc
;
89 struct sableio_attach_args
*sa
= aux
;
90 struct pckbc_internal
*t
;
91 bus_space_handle_t ioh_d
, ioh_c
;
94 ssc
->sc_pc
= sa
->sa_pc
;
99 ssc
->sc_irq
[PCKBC_KBD_SLOT
] = sa
->sa_sableirq
[0];
100 ssc
->sc_irq
[PCKBC_AUX_SLOT
] = sa
->sa_sableirq
[1];
102 sc
->intr_establish
= pckbc_sableio_intr_establish
;
104 if (pckbc_is_console(sa
->sa_iot
, sa
->sa_ioaddr
)) {
106 pckbc_console_attached
= 1;
107 /* t->t_cmdbyte was initialized by cnattach */
109 if (bus_space_map(sa
->sa_iot
, sa
->sa_ioaddr
+ KBDATAP
,
110 1, 0, &ioh_d
) != 0 ||
111 bus_space_map(sa
->sa_iot
, sa
->sa_ioaddr
+ KBCMDP
,
113 panic("pckbc_sableio_attach: couldn't map");
115 t
= malloc(sizeof(struct pckbc_internal
), M_DEVBUF
, M_WAITOK
);
116 memset(t
, 0, sizeof(struct pckbc_internal
));
117 t
->t_iot
= sa
->sa_iot
;
120 t
->t_addr
= sa
->sa_ioaddr
;
121 t
->t_cmdbyte
= KC8_CPU
; /* Enable ports */
129 /* Finish off the attach. */
134 pckbc_sableio_intr_establish(struct pckbc_softc
*sc
, pckbc_slot_t slot
)
136 struct pckbc_sableio_softc
*ssc
= (void *) sc
;
139 intrstr
= pci_intr_string(ssc
->sc_pc
, ssc
->sc_irq
[slot
]);
140 ssc
->sc_ih
[slot
] = pci_intr_establish(ssc
->sc_pc
, ssc
->sc_irq
[slot
],
141 IPL_TTY
, pckbcintr
, sc
);
142 if (ssc
->sc_ih
[slot
] == NULL
) {
143 aprint_error_dev(sc
->sc_dv
,
144 "unable to establish interrupt for %s slot",
145 pckbc_slot_names
[slot
]);
147 aprint_error(" at %s", intrstr
);
151 aprint_normal_dev(sc
->sc_dv
, "%s slot interrupting at %s\n",
152 pckbc_slot_names
[slot
], intrstr
);