1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
|
/* $NetBSD: j720kbd.c,v 1.8 2021/08/07 16:18:53 thorpej Exp $ */
/*-
* Copyright (c) 2006 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by IWAMOTO Toshihiro and Peter Postma.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/* Jornada 720 keyboard driver. */
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: j720kbd.c,v 1.8 2021/08/07 16:18:53 thorpej Exp $");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/device.h>
#include <sys/kernel.h>
#include <machine/bootinfo.h>
#include <machine/config_hook.h>
#include <machine/platid.h>
#include <machine/platid_mask.h>
#include <arm/sa11x0/sa11x0_var.h>
#include <arm/sa11x0/sa11x0_gpioreg.h>
#include <arm/sa11x0/sa11x0_ppcreg.h>
#include <arm/sa11x0/sa11x0_sspreg.h>
#include <dev/hpc/hpckbdvar.h>
#include <hpcarm/dev/j720sspvar.h>
#ifdef DEBUG
#define DPRINTF(arg) aprint_normal arg
#else
#define DPRINTF(arg) /* nothing */
#endif
struct j720kbd_chip {
int scc_enabled;
struct j720ssp_softc *scc_ssp;
struct hpckbd_ic_if scc_if;
struct hpckbd_if *scc_hpckbd;
};
struct j720kbd_softc {
device_t sc_dev;
struct j720kbd_chip *sc_chip;
};
static struct j720kbd_chip j720kbd_chip;
static int j720kbd_match(device_t, cfdata_t, void *);
static void j720kbd_attach(device_t, device_t, void *);
static void j720kbd_cnattach(void);
static void j720kbd_ifsetup(struct j720kbd_chip *);
static int j720kbd_input_establish(void *, struct hpckbd_if *);
static int j720kbd_intr(void *);
static int j720kbd_poll(void *);
static void j720kbd_read(struct j720kbd_chip *, char *);
CFATTACH_DECL_NEW(j720kbd, sizeof(struct j720kbd_softc),
j720kbd_match, j720kbd_attach, NULL, NULL);
static int
j720kbd_match(device_t parent, cfdata_t cf, void *aux)
{
if (!platid_match(&platid, &platid_mask_MACH_HP_JORNADA_7XX))
return 0;
if (strcmp(cf->cf_name, "j720kbd") != 0)
return 0;
return 1;
}
static void
j720kbd_attach(device_t parent, device_t self, void *aux)
{
struct j720kbd_softc *sc = device_private(self);
struct hpckbd_attach_args haa;
aprint_normal("\n");
sc->sc_dev = self;
sc->sc_chip = &j720kbd_chip;
sc->sc_chip->scc_ssp = device_private(parent);
sc->sc_chip->scc_enabled = 0;
/* Attach console if not using serial. */
if (!(bootinfo->bi_cnuse & BI_CNUSE_SERIAL))
j720kbd_cnattach();
j720kbd_ifsetup(sc->sc_chip);
/* Install interrupt handler. */
sa11x0_intr_establish(0, 0, 1, IPL_TTY, j720kbd_intr, sc);
/* Attach hpckbd. */
haa.haa_ic = &sc->sc_chip->scc_if;
config_found(self, &haa, hpckbd_print, CFARGS_NONE);
}
static void
j720kbd_cnattach(void)
{
struct j720kbd_chip *scc = &j720kbd_chip;
/* Initialize interface. */
j720kbd_ifsetup(scc);
/* Attach console. */
hpckbd_cnattach(&scc->scc_if);
}
static void
j720kbd_ifsetup(struct j720kbd_chip *scc)
{
scc->scc_if.hii_ctx = scc;
scc->scc_if.hii_establish = j720kbd_input_establish;
scc->scc_if.hii_poll = j720kbd_poll;
}
static int
j720kbd_input_establish(void *ic, struct hpckbd_if *kbdif)
{
struct j720kbd_chip *scc = ic;
/* Save hpckbd interface. */
scc->scc_hpckbd = kbdif;
scc->scc_enabled = 1;
return 0;
}
static int
j720kbd_intr(void *arg)
{
struct j720kbd_softc *sc = arg;
struct j720ssp_softc *ssp = sc->sc_chip->scc_ssp;
bus_space_write_4(ssp->sc_iot, ssp->sc_gpioh, SAGPIO_EDR, 1);
return j720kbd_poll(sc->sc_chip);
}
static int
j720kbd_poll(void *arg)
{
struct j720kbd_chip *scc = arg;
int type, key;
char buf[9], *p;
if (!scc->scc_enabled) {
DPRINTF(("j720kbd_poll: !scc_enabled\n"));
return 0;
}
j720kbd_read(scc, buf);
for (p = buf; *p; p++) {
type = *p & 0x80 ? 0 : 1;
key = *p & 0x7f;
hpckbd_input(scc->scc_hpckbd, type, key);
}
return 1;
}
static void
j720kbd_read(struct j720kbd_chip *scc, char *buf)
{
struct j720ssp_softc *ssp = scc->scc_ssp;
int data, count;
bus_space_write_4(ssp->sc_iot, ssp->sc_gpioh, SAGPIO_PCR, 0x2000000);
/* Send scan keycode command. */
if (j720ssp_readwrite(ssp, 1, 0x90, &data, 500) < 0 || data != 0x11) {
DPRINTF(("j720kbd_read: no dummy received\n"));
goto out;
}
/* Read number of scancodes available. */
if (j720ssp_readwrite(ssp, 0, 0x11, &data, 500) < 0) {
DPRINTF(("j720kbd_read: unable to read number of scancodes\n"));
goto out;
}
count = data;
for (; count; count--) {
if (j720ssp_readwrite(ssp, 0, 0x11, &data, 100) < 0)
goto out;
*buf++ = data;
}
*buf = 0;
bus_space_write_4(ssp->sc_iot, ssp->sc_gpioh, SAGPIO_PSR, 0x2000000);
return;
out:
*buf = 0;
bus_space_write_4(ssp->sc_iot, ssp->sc_gpioh, SAGPIO_PSR, 0x2000000);
/* reset SSP */
bus_space_write_4(ssp->sc_iot, ssp->sc_ssph, SASSP_CR0, 0x307);
delay(100);
bus_space_write_4(ssp->sc_iot, ssp->sc_ssph, SASSP_CR0, 0x387);
DPRINTF(("j720kbd_read: error %x\n", data));
}
|