1 /* $NetBSD: j720kbd.c,v 1.5 2008/04/28 20:23:21 martin Exp $ */
4 * Copyright (c) 2006 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by IWAMOTO Toshihiro and Peter Postma.
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 /* Jornada 720 keyboard driver. */
34 #include <sys/cdefs.h>
35 __KERNEL_RCSID(0, "$NetBSD: j720kbd.c,v 1.5 2008/04/28 20:23:21 martin Exp $");
37 #include <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/device.h>
40 #include <sys/kernel.h>
42 #include <machine/bootinfo.h>
43 #include <machine/config_hook.h>
44 #include <machine/platid.h>
45 #include <machine/platid_mask.h>
47 #include <arm/sa11x0/sa11x0_var.h>
48 #include <arm/sa11x0/sa11x0_gpioreg.h>
49 #include <arm/sa11x0/sa11x0_ppcreg.h>
50 #include <arm/sa11x0/sa11x0_sspreg.h>
52 #include <dev/hpc/hpckbdvar.h>
54 #include <hpcarm/dev/j720sspvar.h>
57 #define DPRINTF(arg) aprint_normal arg
59 #define DPRINTF(arg) /* nothing */
65 struct j720ssp_softc
*scc_ssp
;
67 struct hpckbd_ic_if scc_if
;
68 struct hpckbd_if
*scc_hpckbd
;
71 struct j720kbd_softc
{
74 struct j720kbd_chip
*sc_chip
;
77 static struct j720kbd_chip j720kbd_chip
;
79 static int j720kbd_match(device_t
, cfdata_t
, void *);
80 static void j720kbd_attach(device_t
, device_t
, void *);
82 static void j720kbd_cnattach(void);
83 static void j720kbd_ifsetup(struct j720kbd_chip
*);
84 static int j720kbd_input_establish(void *, struct hpckbd_if
*);
85 static int j720kbd_intr(void *);
86 static int j720kbd_poll(void *);
87 static void j720kbd_read(struct j720kbd_chip
*, char *);
89 CFATTACH_DECL_NEW(j720kbd
, sizeof(struct j720kbd_softc
),
90 j720kbd_match
, j720kbd_attach
, NULL
, NULL
);
94 j720kbd_match(device_t parent
, cfdata_t cf
, void *aux
)
97 if (!platid_match(&platid
, &platid_mask_MACH_HP_JORNADA_7XX
))
99 if (strcmp(cf
->cf_name
, "j720kbd") != 0)
106 j720kbd_attach(device_t parent
, device_t self
, void *aux
)
108 struct j720kbd_softc
*sc
= device_private(self
);
109 struct hpckbd_attach_args haa
;
114 sc
->sc_chip
= &j720kbd_chip
;
115 sc
->sc_chip
->scc_ssp
= device_private(parent
);
116 sc
->sc_chip
->scc_enabled
= 0;
118 /* Attach console if not using serial. */
119 if (!(bootinfo
->bi_cnuse
& BI_CNUSE_SERIAL
))
122 j720kbd_ifsetup(sc
->sc_chip
);
124 /* Install interrupt handler. */
125 sa11x0_intr_establish(0, 0, 1, IPL_TTY
, j720kbd_intr
, sc
);
128 haa
.haa_ic
= &sc
->sc_chip
->scc_if
;
129 config_found(self
, &haa
, hpckbd_print
);
133 j720kbd_cnattach(void)
135 struct j720kbd_chip
*scc
= &j720kbd_chip
;
137 /* Initialize interface. */
138 j720kbd_ifsetup(scc
);
140 /* Attach console. */
141 hpckbd_cnattach(&scc
->scc_if
);
145 j720kbd_ifsetup(struct j720kbd_chip
*scc
)
148 scc
->scc_if
.hii_ctx
= scc
;
149 scc
->scc_if
.hii_establish
= j720kbd_input_establish
;
150 scc
->scc_if
.hii_poll
= j720kbd_poll
;
154 j720kbd_input_establish(void *ic
, struct hpckbd_if
*kbdif
)
156 struct j720kbd_chip
*scc
= ic
;
158 /* Save hpckbd interface. */
159 scc
->scc_hpckbd
= kbdif
;
161 scc
->scc_enabled
= 1;
167 j720kbd_intr(void *arg
)
169 struct j720kbd_softc
*sc
= arg
;
170 struct j720ssp_softc
*ssp
= sc
->sc_chip
->scc_ssp
;
172 bus_space_write_4(ssp
->sc_iot
, ssp
->sc_gpioh
, SAGPIO_EDR
, 1);
174 return j720kbd_poll(sc
->sc_chip
);
178 j720kbd_poll(void *arg
)
180 struct j720kbd_chip
*scc
= arg
;
184 if (!scc
->scc_enabled
) {
185 DPRINTF(("j720kbd_poll: !scc_enabled\n"));
189 j720kbd_read(scc
, buf
);
191 for (p
= buf
; *p
; p
++) {
192 type
= *p
& 0x80 ? 0 : 1;
195 hpckbd_input(scc
->scc_hpckbd
, type
, key
);
202 j720kbd_read(struct j720kbd_chip
*scc
, char *buf
)
204 struct j720ssp_softc
*ssp
= scc
->scc_ssp
;
207 bus_space_write_4(ssp
->sc_iot
, ssp
->sc_gpioh
, SAGPIO_PCR
, 0x2000000);
209 /* Send scan keycode command. */
210 if (j720ssp_readwrite(ssp
, 1, 0x90, &data
, 500) < 0 || data
!= 0x11) {
211 DPRINTF(("j720kbd_read: no dummy received\n"));
215 /* Read number of scancodes available. */
216 if (j720ssp_readwrite(ssp
, 0, 0x11, &data
, 500) < 0) {
217 DPRINTF(("j720kbd_read: unable to read number of scancodes\n"));
222 for (; count
; count
--) {
223 if (j720ssp_readwrite(ssp
, 0, 0x11, &data
, 100) < 0)
228 bus_space_write_4(ssp
->sc_iot
, ssp
->sc_gpioh
, SAGPIO_PSR
, 0x2000000);
234 bus_space_write_4(ssp
->sc_iot
, ssp
->sc_gpioh
, SAGPIO_PSR
, 0x2000000);
237 bus_space_write_4(ssp
->sc_iot
, ssp
->sc_ssph
, SASSP_CR0
, 0x307);
239 bus_space_write_4(ssp
->sc_iot
, ssp
->sc_ssph
, SASSP_CR0
, 0x387);
241 DPRINTF(("j720kbd_read: error %x\n", data
));