j720ssp.c revision 1.2.2.5 1 1.2.2.5 jdolecek /* $NetBSD: j720ssp.c,v 1.2.2.5 2002/10/10 18:32:50 jdolecek Exp $ */
2 1.1 toshii
3 1.1 toshii /*-
4 1.1 toshii * Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
5 1.1 toshii * All rights reserved.
6 1.1 toshii *
7 1.1 toshii * This code is derived from software contributed to The NetBSD Foundation
8 1.1 toshii * by Charles M. Hannum.
9 1.1 toshii *
10 1.1 toshii * Redistribution and use in source and binary forms, with or without
11 1.1 toshii * modification, are permitted provided that the following conditions
12 1.1 toshii * are met:
13 1.1 toshii * 1. Redistributions of source code must retain the above copyright
14 1.1 toshii * notice, this list of conditions and the following disclaimer.
15 1.1 toshii * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 toshii * notice, this list of conditions and the following disclaimer in the
17 1.1 toshii * documentation and/or other materials provided with the distribution.
18 1.1 toshii * 3. All advertising materials mentioning features or use of this software
19 1.1 toshii * must display the following acknowledgement:
20 1.1 toshii * This product includes software developed by the NetBSD
21 1.1 toshii * Foundation, Inc. and its contributors.
22 1.1 toshii * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1 toshii * contributors may be used to endorse or promote products derived
24 1.1 toshii * from this software without specific prior written permission.
25 1.1 toshii *
26 1.1 toshii * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1 toshii * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1 toshii * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1 toshii * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1 toshii * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1 toshii * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1 toshii * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1 toshii * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1 toshii * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1 toshii * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1 toshii * POSSIBILITY OF SUCH DAMAGE.
37 1.1 toshii */
38 1.1 toshii
39 1.1 toshii /*-
40 1.1 toshii * Copyright (c) 1990 The Regents of the University of California.
41 1.1 toshii * All rights reserved.
42 1.1 toshii *
43 1.1 toshii * This code is derived from software contributed to Berkeley by
44 1.1 toshii * William Jolitz and Don Ahn.
45 1.1 toshii *
46 1.1 toshii * Redistribution and use in source and binary forms, with or without
47 1.1 toshii * modification, are permitted provided that the following conditions
48 1.1 toshii * are met:
49 1.1 toshii * 1. Redistributions of source code must retain the above copyright
50 1.1 toshii * notice, this list of conditions and the following disclaimer.
51 1.1 toshii * 2. Redistributions in binary form must reproduce the above copyright
52 1.1 toshii * notice, this list of conditions and the following disclaimer in the
53 1.1 toshii * documentation and/or other materials provided with the distribution.
54 1.1 toshii * 3. All advertising materials mentioning features or use of this software
55 1.1 toshii * must display the following acknowledgement:
56 1.1 toshii * This product includes software developed by the University of
57 1.1 toshii * California, Berkeley and its contributors.
58 1.1 toshii * 4. Neither the name of the University nor the names of its contributors
59 1.1 toshii * may be used to endorse or promote products derived from this software
60 1.1 toshii * without specific prior written permission.
61 1.1 toshii *
62 1.1 toshii * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
63 1.1 toshii * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
64 1.1 toshii * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
65 1.1 toshii * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
66 1.1 toshii * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
67 1.1 toshii * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
68 1.1 toshii * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
69 1.1 toshii * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
70 1.1 toshii * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
71 1.1 toshii * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
72 1.1 toshii * SUCH DAMAGE.
73 1.1 toshii *
74 1.1 toshii * @(#)pccons.c 5.11 (Berkeley) 5/21/91
75 1.1 toshii */
76 1.1 toshii
77 1.2.2.5 jdolecek #include "apm.h"
78 1.2.2.5 jdolecek
79 1.1 toshii #include <sys/param.h>
80 1.1 toshii #include <sys/systm.h>
81 1.1 toshii #include <sys/device.h>
82 1.1 toshii #include <sys/kernel.h>
83 1.1 toshii #include <sys/malloc.h>
84 1.1 toshii #include <sys/ioctl.h>
85 1.2.2.5 jdolecek #include <sys/kthread.h>
86 1.2.2.5 jdolecek #include <sys/lock.h>
87 1.1 toshii
88 1.1 toshii #include <machine/bus.h>
89 1.1 toshii #include <machine/config_hook.h>
90 1.2.2.2 jdolecek #include <machine/bootinfo.h>
91 1.2.2.5 jdolecek #include <machine/apmvar.h>
92 1.1 toshii
93 1.1 toshii #include <hpcarm/dev/sed1356var.h>
94 1.2.2.4 jdolecek
95 1.2.2.4 jdolecek #include <arm/sa11x0/sa11x0_var.h>
96 1.2.2.4 jdolecek #include <arm/sa11x0/sa11x0_gpioreg.h>
97 1.2.2.4 jdolecek #include <arm/sa11x0/sa11x0_ppcreg.h>
98 1.2.2.4 jdolecek #include <arm/sa11x0/sa11x0_sspreg.h>
99 1.1 toshii
100 1.1 toshii #include <dev/wscons/wsconsio.h>
101 1.1 toshii #include <dev/wscons/wskbdvar.h>
102 1.1 toshii #include <dev/wscons/wsksymdef.h>
103 1.1 toshii #include <dev/wscons/wsksymvar.h>
104 1.2.2.4 jdolecek #include <dev/wscons/wsmousevar.h>
105 1.2.2.4 jdolecek #include <dev/hpc/tpcalibvar.h>
106 1.1 toshii
107 1.1 toshii extern const struct wscons_keydesc j720kbd_keydesctab[];
108 1.1 toshii
109 1.1 toshii struct j720ssp_softc {
110 1.1 toshii struct device sc_dev;
111 1.1 toshii
112 1.1 toshii bus_space_tag_t sc_iot;
113 1.1 toshii bus_space_handle_t sc_gpioh;
114 1.1 toshii bus_space_handle_t sc_ssph;
115 1.1 toshii
116 1.1 toshii struct device *sc_wskbddev;
117 1.2.2.4 jdolecek struct device *sc_wsmousedev;
118 1.2.2.4 jdolecek struct tpcalib_softc sc_tpcalib;
119 1.1 toshii
120 1.2.2.4 jdolecek void *sc_kbdsi;
121 1.2.2.4 jdolecek void *sc_tpsi;
122 1.1 toshii int sc_enabled;
123 1.2.2.5 jdolecek
124 1.2.2.5 jdolecek struct proc *sc_ssp_kthread;
125 1.2.2.5 jdolecek int sc_ssp_status;
126 1.2.2.5 jdolecek struct simplelock sc_ssp_status_lock;
127 1.1 toshii };
128 1.2.2.5 jdolecek /* Values for struct softc's sc_ssp_status */
129 1.2.2.5 jdolecek #define J720_SSP_STATUS_NONE 0
130 1.2.2.5 jdolecek #define J720_SSP_STATUS_TP 1
131 1.2.2.5 jdolecek #define J720_SSP_STATUS_KBD 2
132 1.2.2.5 jdolecek
133 1.2.2.5 jdolecek void j720ssp_create_kthread __P((void *));
134 1.2.2.5 jdolecek void j720ssp_kthread __P((void *));
135 1.2.2.5 jdolecek int j720kbd_intr __P((void *));
136 1.2.2.5 jdolecek int j720tp_intr __P((void *));
137 1.2.2.5 jdolecek void j720kbd_poll __P((void *));
138 1.2.2.5 jdolecek int j720tp_poll __P((void *));
139 1.2.2.5 jdolecek
140 1.2.2.5 jdolecek int j720lcdparam __P((void *, int, long, void *));
141 1.2.2.5 jdolecek static void j720kbd_read __P((struct j720ssp_softc *, char *));
142 1.2.2.5 jdolecek static int j720ssp_readwrite __P((struct j720ssp_softc *, int,
143 1.2.2.5 jdolecek int, int *, int));
144 1.2.2.5 jdolecek
145 1.2.2.5 jdolecek int j720sspprobe __P((struct device *, struct cfdata *, void *));
146 1.2.2.5 jdolecek void j720sspattach __P((struct device *, struct device *, void *));
147 1.2.2.5 jdolecek
148 1.2.2.5 jdolecek int j720kbd_submatch __P((struct device *, struct cfdata *, void *));
149 1.2.2.5 jdolecek int j720tp_submatch __P((struct device *, struct cfdata *, void *));
150 1.2.2.5 jdolecek int apm_submatch __P((struct device *, struct cfdata *, void *));
151 1.2.2.5 jdolecek
152 1.2.2.5 jdolecek int j720kbd_enable __P((void *, int));
153 1.2.2.5 jdolecek void j720kbd_set_leds __P((void *, int));
154 1.2.2.5 jdolecek int j720kbd_ioctl __P((void *, u_long, caddr_t, int, struct proc *));
155 1.1 toshii
156 1.2.2.5 jdolecek int hpcarm_apm_getpower __P((struct apm_power_info *, void *));
157 1.1 toshii
158 1.2.2.5 jdolecek CFATTACH_DECL(j720ssp, sizeof(struct j720ssp_softc),
159 1.2.2.5 jdolecek j720sspprobe, j720sspattach, NULL, NULL);
160 1.1 toshii
161 1.1 toshii const struct wskbd_accessops j720kbd_accessops = {
162 1.1 toshii j720kbd_enable,
163 1.1 toshii j720kbd_set_leds,
164 1.1 toshii j720kbd_ioctl,
165 1.1 toshii };
166 1.1 toshii
167 1.2.2.5 jdolecek void j720kbd_cngetc __P((void *, u_int *, int *));
168 1.2.2.5 jdolecek void j720kbd_cnpollc __P((void *, int));
169 1.2.2.5 jdolecek void j720kbd_cnbell __P((void *, u_int, u_int, u_int));
170 1.1 toshii
171 1.1 toshii const struct wskbd_consops j720kbd_consops = {
172 1.1 toshii j720kbd_cngetc,
173 1.1 toshii j720kbd_cnpollc,
174 1.1 toshii j720kbd_cnbell,
175 1.1 toshii };
176 1.1 toshii
177 1.1 toshii const struct wskbd_mapdata j720kbd_keymapdata = {
178 1.1 toshii j720kbd_keydesctab,
179 1.1 toshii #ifdef J720KBD_LAYOUT
180 1.1 toshii J720KBD_LAYOUT,
181 1.1 toshii #else
182 1.1 toshii KB_US,
183 1.1 toshii #endif
184 1.1 toshii };
185 1.1 toshii
186 1.2.2.5 jdolecek static int j720tp_enable __P((void *));
187 1.2.2.5 jdolecek static int j720tp_ioctl __P((void *, u_long, caddr_t, int, struct proc *));
188 1.2.2.5 jdolecek static void j720tp_disable __P((void *));
189 1.2.2.4 jdolecek
190 1.2.2.4 jdolecek const struct wsmouse_accessops j720tp_accessops = {
191 1.2.2.4 jdolecek j720tp_enable,
192 1.2.2.4 jdolecek j720tp_ioctl,
193 1.2.2.4 jdolecek j720tp_disable,
194 1.2.2.4 jdolecek };
195 1.2.2.4 jdolecek
196 1.1 toshii static int j720ssp_powerstate = 1;
197 1.1 toshii
198 1.1 toshii static struct j720ssp_softc j720kbdcons_sc;
199 1.2.2.1 thorpej static int j720kbdcons_initstate = 0;
200 1.1 toshii
201 1.1 toshii #define DEBUG
202 1.1 toshii #ifdef DEBUG
203 1.1 toshii int j720sspwaitcnt;
204 1.1 toshii int j720sspwaittime;
205 1.1 toshii extern int gettick();
206 1.1 toshii #endif
207 1.1 toshii
208 1.1 toshii #define BIT_INVERT(x) do { \
209 1.1 toshii (x) = ((((x) & 0xf0) >> 4) | (((x) & 0x0f) << 4)); \
210 1.1 toshii (x) = ((((x) & 0xcc) >> 2) | (((x) & 0x33) << 2)); \
211 1.1 toshii (x) = ((((x) & 0xaa) >> 1) | (((x) & 0x55) << 1)); \
212 1.1 toshii } while(0)
213 1.1 toshii
214 1.2.2.5 jdolecek
215 1.1 toshii int
216 1.2.2.5 jdolecek j720sspprobe(parent, cf, aux)
217 1.2.2.5 jdolecek struct device *parent;
218 1.2.2.5 jdolecek struct cfdata *cf;
219 1.2.2.5 jdolecek void *aux;
220 1.1 toshii {
221 1.1 toshii return (1);
222 1.1 toshii }
223 1.1 toshii
224 1.1 toshii void
225 1.2.2.5 jdolecek j720sspattach(parent, self, aux)
226 1.2.2.5 jdolecek struct device *parent;
227 1.2.2.5 jdolecek struct device *self;
228 1.2.2.5 jdolecek void *aux;
229 1.1 toshii {
230 1.1 toshii struct j720ssp_softc *sc = (void *)self;
231 1.1 toshii struct sa11x0_softc *psc = (void *)parent;
232 1.1 toshii struct sa11x0_attach_args *sa = aux;
233 1.2.2.5 jdolecek struct wskbddev_attach_args kbd_args;
234 1.2.2.5 jdolecek struct wsmousedev_attach_args mouse_args;
235 1.2.2.5 jdolecek #if NAPM > 0
236 1.2.2.5 jdolecek struct apm_attach_args apm_args;
237 1.2.2.5 jdolecek #endif
238 1.2 toshii
239 1.2 toshii printf("\n");
240 1.1 toshii
241 1.1 toshii sc->sc_iot = psc->sc_iot;
242 1.1 toshii sc->sc_gpioh = psc->sc_gpioh;
243 1.1 toshii if (bus_space_map(sc->sc_iot, sa->sa_addr, sa->sa_size, 0,
244 1.1 toshii &sc->sc_ssph)) {
245 1.1 toshii printf("%s: unable to map SSP registers\n",
246 1.1 toshii sc->sc_dev.dv_xname);
247 1.1 toshii return;
248 1.1 toshii }
249 1.1 toshii
250 1.2.2.5 jdolecek sc->sc_ssp_status = J720_SSP_STATUS_NONE;
251 1.2.2.5 jdolecek simple_lock_init(&sc->sc_ssp_status_lock);
252 1.2.2.5 jdolecek kthread_create(j720ssp_create_kthread, sc);
253 1.1 toshii
254 1.1 toshii sc->sc_enabled = 0;
255 1.1 toshii
256 1.2.2.5 jdolecek kbd_args.console = 0;
257 1.1 toshii
258 1.2.2.5 jdolecek kbd_args.keymap = &j720kbd_keymapdata;
259 1.1 toshii
260 1.2.2.5 jdolecek kbd_args.accessops = &j720kbd_accessops;
261 1.2.2.5 jdolecek kbd_args.accesscookie = sc;
262 1.1 toshii
263 1.2.2.1 thorpej /* Do console initialization */
264 1.2.2.1 thorpej if (! (bootinfo->bi_cnuse & BI_CNUSE_SERIAL)) {
265 1.2.2.1 thorpej j720kbdcons_sc = *sc;
266 1.2.2.5 jdolecek kbd_args.console = 1;
267 1.2.2.1 thorpej
268 1.2.2.1 thorpej wskbd_cnattach(&j720kbd_consops, NULL, &j720kbd_keymapdata);
269 1.2.2.1 thorpej j720kbdcons_initstate = 1;
270 1.2.2.1 thorpej }
271 1.2.2.1 thorpej
272 1.1 toshii /*
273 1.1 toshii * Attach the wskbd, saving a handle to it.
274 1.1 toshii * XXX XXX XXX
275 1.1 toshii */
276 1.2.2.5 jdolecek sc->sc_wskbddev = config_found_sm(self, &kbd_args, wskbddevprint,
277 1.2.2.4 jdolecek j720kbd_submatch);
278 1.1 toshii
279 1.1 toshii #ifdef DEBUG
280 1.1 toshii /* Zero the stat counters */
281 1.1 toshii j720sspwaitcnt = 0;
282 1.1 toshii j720sspwaittime = 0;
283 1.1 toshii #endif
284 1.1 toshii
285 1.2.2.1 thorpej if (j720kbdcons_initstate == 1)
286 1.2.2.1 thorpej j720kbd_enable(sc, 1);
287 1.2.2.1 thorpej
288 1.2.2.5 jdolecek mouse_args.accessops = &j720tp_accessops;
289 1.2.2.5 jdolecek mouse_args.accesscookie = sc;
290 1.2.2.4 jdolecek
291 1.2.2.5 jdolecek sc->sc_wsmousedev = config_found_sm(self, &mouse_args,
292 1.2.2.5 jdolecek wsmousedevprint, j720tp_submatch);
293 1.2.2.4 jdolecek tpcalib_init(&sc->sc_tpcalib);
294 1.2.2.4 jdolecek
295 1.2.2.4 jdolecek /* XXX fill in "default" calibrate param */
296 1.2.2.4 jdolecek {
297 1.2.2.4 jdolecek static const struct wsmouse_calibcoords j720_default_calib = {
298 1.2.2.4 jdolecek 0, 0, 639, 239,
299 1.2.2.4 jdolecek 4,
300 1.2.2.4 jdolecek { { 988, 80, 0, 0 },
301 1.2.2.4 jdolecek { 88, 84, 639, 0 },
302 1.2.2.4 jdolecek { 988, 927, 0, 239 },
303 1.2.2.4 jdolecek { 88, 940, 639, 239 } } };
304 1.2.2.4 jdolecek tpcalib_ioctl(&sc->sc_tpcalib, WSMOUSEIO_SCALIBCOORDS,
305 1.2.2.4 jdolecek (caddr_t)&j720_default_calib, 0, 0);
306 1.2.2.4 jdolecek }
307 1.2.2.4 jdolecek
308 1.2.2.4 jdolecek j720tp_disable(sc);
309 1.2.2.4 jdolecek
310 1.2.2.4 jdolecek /* Setup touchpad interrupt */
311 1.2.2.4 jdolecek sa11x0_intr_establish(0, 9, 1, IPL_BIO, j720tp_intr, sc);
312 1.2.2.4 jdolecek
313 1.1 toshii /* LCD control is on the same bus */
314 1.1 toshii config_hook(CONFIG_HOOK_SET, CONFIG_HOOK_BRIGHTNESS,
315 1.1 toshii CONFIG_HOOK_SHARE, j720lcdparam, sc);
316 1.1 toshii config_hook(CONFIG_HOOK_GET, CONFIG_HOOK_BRIGHTNESS,
317 1.1 toshii CONFIG_HOOK_SHARE, j720lcdparam, sc);
318 1.1 toshii config_hook(CONFIG_HOOK_GET, CONFIG_HOOK_BRIGHTNESS_MAX,
319 1.1 toshii CONFIG_HOOK_SHARE, j720lcdparam, sc);
320 1.1 toshii
321 1.1 toshii config_hook(CONFIG_HOOK_SET, CONFIG_HOOK_CONTRAST,
322 1.1 toshii CONFIG_HOOK_SHARE, j720lcdparam, sc);
323 1.1 toshii config_hook(CONFIG_HOOK_GET, CONFIG_HOOK_CONTRAST,
324 1.1 toshii CONFIG_HOOK_SHARE, j720lcdparam, sc);
325 1.1 toshii config_hook(CONFIG_HOOK_GET, CONFIG_HOOK_CONTRAST_MAX,
326 1.1 toshii CONFIG_HOOK_SHARE, j720lcdparam, sc);
327 1.2.2.5 jdolecek
328 1.2.2.5 jdolecek #if NAPM > 0
329 1.2.2.5 jdolecek /* attach APM emulation */
330 1.2.2.5 jdolecek apm_args.aaa_magic = APM_ATTACH_ARGS_MAGIC; /* magic number */
331 1.2.2.5 jdolecek (void)config_found_sm(self, &apm_args, NULL, apm_submatch);
332 1.2.2.5 jdolecek #endif
333 1.2.2.5 jdolecek
334 1.2.2.5 jdolecek return;
335 1.1 toshii }
336 1.1 toshii
337 1.2.2.5 jdolecek void
338 1.2.2.5 jdolecek j720ssp_create_kthread(arg)
339 1.2.2.5 jdolecek void *arg;
340 1.2.2.5 jdolecek {
341 1.2.2.5 jdolecek struct j720ssp_softc *sc = arg;
342 1.2.2.5 jdolecek
343 1.2.2.5 jdolecek if (kthread_create1(j720ssp_kthread, sc,
344 1.2.2.5 jdolecek &sc->sc_ssp_kthread, "j720ssp"))
345 1.2.2.5 jdolecek panic("j720ssp_create_kthread");
346 1.2.2.5 jdolecek
347 1.2.2.5 jdolecek return;
348 1.2.2.5 jdolecek }
349 1.2.2.5 jdolecek
350 1.2.2.5 jdolecek void
351 1.2.2.5 jdolecek j720ssp_kthread(arg)
352 1.2.2.5 jdolecek void *arg;
353 1.2.2.5 jdolecek {
354 1.2.2.5 jdolecek struct j720ssp_softc *sc = arg;
355 1.2.2.5 jdolecek int ssp_status;
356 1.2.2.5 jdolecek
357 1.2.2.5 jdolecek while (1) {
358 1.2.2.5 jdolecek if (ssp_status & J720_SSP_STATUS_TP)
359 1.2.2.5 jdolecek tsleep(&sc->sc_ssp_kthread, PRIBIO, "j720ssp", hz / 25);
360 1.2.2.5 jdolecek else
361 1.2.2.5 jdolecek tsleep(&sc->sc_ssp_kthread, PRIBIO, "j720ssp", 0);
362 1.2.2.5 jdolecek
363 1.2.2.5 jdolecek simple_lock(&sc->sc_ssp_status_lock);
364 1.2.2.5 jdolecek ssp_status = sc->sc_ssp_status;
365 1.2.2.5 jdolecek sc->sc_ssp_status &= ~J720_SSP_STATUS_KBD;
366 1.2.2.5 jdolecek simple_unlock(&sc->sc_ssp_status_lock);
367 1.2.2.5 jdolecek
368 1.2.2.5 jdolecek if (ssp_status & J720_SSP_STATUS_KBD)
369 1.2.2.5 jdolecek j720kbd_poll(sc);
370 1.2.2.5 jdolecek
371 1.2.2.5 jdolecek if (ssp_status & J720_SSP_STATUS_TP) {
372 1.2.2.5 jdolecek if (j720tp_poll(sc) == 0) {
373 1.2.2.5 jdolecek simple_lock(&sc->sc_ssp_status_lock);
374 1.2.2.5 jdolecek sc->sc_ssp_status &= ~J720_SSP_STATUS_TP;
375 1.2.2.5 jdolecek simple_unlock(&sc->sc_ssp_status_lock);
376 1.2.2.5 jdolecek }
377 1.2.2.5 jdolecek }
378 1.2.2.5 jdolecek }
379 1.2.2.5 jdolecek
380 1.2.2.5 jdolecek /* NOTREACHED */
381 1.2.2.5 jdolecek }
382 1.2.2.4 jdolecek
383 1.2.2.5 jdolecek
384 1.2.2.5 jdolecek int
385 1.2.2.5 jdolecek j720kbd_submatch(parent, cf, aux)
386 1.2.2.5 jdolecek struct device *parent;
387 1.2.2.5 jdolecek struct cfdata *cf;
388 1.2.2.5 jdolecek void *aux;
389 1.2.2.5 jdolecek {
390 1.2.2.5 jdolecek if (strcmp(cf->cf_name, "wskbd") == 0)
391 1.2.2.4 jdolecek return (1);
392 1.2.2.4 jdolecek return (0);
393 1.2.2.4 jdolecek }
394 1.2.2.4 jdolecek
395 1.2.2.4 jdolecek int
396 1.2.2.5 jdolecek j720tp_submatch(parent, cf, aux)
397 1.2.2.5 jdolecek struct device *parent;
398 1.2.2.5 jdolecek struct cfdata *cf;
399 1.2.2.5 jdolecek void *aux;
400 1.2.2.5 jdolecek {
401 1.2.2.5 jdolecek if (strcmp(cf->cf_name, "wsmouse") == 0)
402 1.2.2.5 jdolecek return (1);
403 1.2.2.5 jdolecek return (0);
404 1.2.2.5 jdolecek }
405 1.2.2.4 jdolecek
406 1.2.2.5 jdolecek int
407 1.2.2.5 jdolecek apm_submatch(parent, cf, aux)
408 1.2.2.5 jdolecek struct device *parent;
409 1.2.2.5 jdolecek struct cfdata *cf;
410 1.2.2.5 jdolecek void *aux;
411 1.2.2.5 jdolecek {
412 1.2.2.5 jdolecek if (strcmp(cf->cf_name, "apm") == 0)
413 1.2.2.4 jdolecek return (1);
414 1.2.2.4 jdolecek return (0);
415 1.2.2.4 jdolecek }
416 1.2.2.4 jdolecek
417 1.2.2.4 jdolecek int
418 1.2.2.5 jdolecek j720kbd_enable(v, on)
419 1.2.2.5 jdolecek void *v;
420 1.2.2.5 jdolecek int on;
421 1.1 toshii {
422 1.1 toshii struct j720ssp_softc *sc = v;
423 1.1 toshii
424 1.1 toshii if (! sc->sc_enabled) {
425 1.1 toshii sc->sc_enabled = 1;
426 1.1 toshii
427 1.1 toshii sa11x0_intr_establish(0, 0, 1, IPL_BIO, j720kbd_intr, sc);
428 1.1 toshii }
429 1.1 toshii /* XXX */
430 1.1 toshii return (0);
431 1.1 toshii }
432 1.1 toshii
433 1.1 toshii void
434 1.2.2.5 jdolecek j720kbd_set_leds(v, on)
435 1.2.2.5 jdolecek void *v;
436 1.2.2.5 jdolecek int on;
437 1.1 toshii {
438 1.1 toshii /* XXX */
439 1.1 toshii return;
440 1.1 toshii }
441 1.1 toshii
442 1.1 toshii int
443 1.2.2.4 jdolecek j720kbd_ioctl(v, cmd, data, flag, p)
444 1.2.2.4 jdolecek void *v;
445 1.2.2.4 jdolecek u_long cmd;
446 1.2.2.4 jdolecek caddr_t data;
447 1.2.2.4 jdolecek int flag;
448 1.2.2.4 jdolecek struct proc *p;
449 1.1 toshii {
450 1.2.2.4 jdolecek switch (cmd) {
451 1.2.2.4 jdolecek case WSKBDIO_GTYPE:
452 1.2.2.4 jdolecek *(int *)data = WSKBD_TYPE_HPC_KBD;
453 1.2.2.4 jdolecek return 0;
454 1.2.2.4 jdolecek }
455 1.2.2.4 jdolecek
456 1.2.2.3 jdolecek return (EPASSTHROUGH);
457 1.1 toshii }
458 1.1 toshii
459 1.1 toshii int
460 1.2.2.5 jdolecek j720kbd_intr(arg)
461 1.2.2.5 jdolecek void *arg;
462 1.1 toshii {
463 1.1 toshii struct j720ssp_softc *sc = arg;
464 1.1 toshii
465 1.1 toshii bus_space_write_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_EDR, 1);
466 1.1 toshii
467 1.2.2.5 jdolecek simple_lock(&sc->sc_ssp_status_lock);
468 1.2.2.5 jdolecek sc->sc_ssp_status |= J720_SSP_STATUS_KBD;
469 1.2.2.5 jdolecek simple_unlock(&sc->sc_ssp_status_lock);
470 1.2.2.5 jdolecek
471 1.2.2.5 jdolecek wakeup(&sc->sc_ssp_kthread);
472 1.2.2.4 jdolecek
473 1.2.2.4 jdolecek return (1);
474 1.2.2.4 jdolecek }
475 1.2.2.4 jdolecek
476 1.2.2.4 jdolecek int
477 1.2.2.5 jdolecek j720tp_intr(arg)
478 1.2.2.5 jdolecek void *arg;
479 1.2.2.4 jdolecek {
480 1.2.2.4 jdolecek struct j720ssp_softc *sc = arg;
481 1.2.2.4 jdolecek
482 1.2.2.4 jdolecek bus_space_write_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_EDR, 1 << 9);
483 1.2.2.4 jdolecek
484 1.2.2.5 jdolecek simple_lock(&sc->sc_ssp_status_lock);
485 1.2.2.5 jdolecek sc->sc_ssp_status |= J720_SSP_STATUS_TP;
486 1.2.2.5 jdolecek simple_unlock(&sc->sc_ssp_status_lock);
487 1.2.2.5 jdolecek
488 1.2.2.5 jdolecek j720tp_disable(sc);
489 1.2.2.5 jdolecek wakeup(&sc->sc_ssp_kthread);
490 1.1 toshii
491 1.1 toshii return (1);
492 1.1 toshii }
493 1.1 toshii
494 1.1 toshii void
495 1.2.2.5 jdolecek j720kbd_poll(arg)
496 1.2.2.5 jdolecek void *arg;
497 1.1 toshii {
498 1.1 toshii struct j720ssp_softc *sc = arg;
499 1.1 toshii int s, type, value;
500 1.1 toshii char buf[9], *p;
501 1.1 toshii
502 1.1 toshii j720kbd_read(sc, buf);
503 1.1 toshii
504 1.1 toshii for(p = buf; *p; p++) {
505 1.1 toshii type = *p & 0x80 ? WSCONS_EVENT_KEY_UP :
506 1.1 toshii WSCONS_EVENT_KEY_DOWN;
507 1.1 toshii value = *p & 0x7f;
508 1.1 toshii s = spltty();
509 1.1 toshii wskbd_input(sc->sc_wskbddev, type, value);
510 1.1 toshii splx(s);
511 1.1 toshii if (type == WSCONS_EVENT_KEY_DOWN &&
512 1.1 toshii value == 0x7f) {
513 1.1 toshii j720ssp_powerstate = ! j720ssp_powerstate;
514 1.1 toshii config_hook_call(CONFIG_HOOK_POWERCONTROL,
515 1.1 toshii CONFIG_HOOK_POWERCONTROL_LCDLIGHT,
516 1.1 toshii (void *)j720ssp_powerstate);
517 1.1 toshii }
518 1.1 toshii }
519 1.1 toshii
520 1.1 toshii return;
521 1.1 toshii }
522 1.1 toshii
523 1.1 toshii void
524 1.2.2.5 jdolecek j720kbd_read(sc, buf)
525 1.2.2.5 jdolecek struct j720ssp_softc *sc;
526 1.2.2.5 jdolecek char *buf;
527 1.1 toshii {
528 1.1 toshii int data, count;
529 1.1 toshii #ifdef DEBUG
530 1.1 toshii u_int32_t oscr;
531 1.1 toshii
532 1.1 toshii oscr = gettick();
533 1.1 toshii #endif
534 1.1 toshii bus_space_write_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_PCR, 0x2000000);
535 1.1 toshii
536 1.1 toshii /* send scan keycode command */
537 1.2.2.5 jdolecek if (j720ssp_readwrite(sc, 1, 0x900, &data, 100) < 0 ||
538 1.1 toshii data != 0x88)
539 1.1 toshii goto out;
540 1.1 toshii
541 1.1 toshii /* read numbers of scancode available */
542 1.2.2.5 jdolecek if (j720ssp_readwrite(sc, 0, 0x8800, &data, 100) < 0)
543 1.1 toshii goto out;
544 1.1 toshii BIT_INVERT(data);
545 1.1 toshii count = data;
546 1.1 toshii
547 1.1 toshii for(; count; count--) {
548 1.2.2.5 jdolecek if (j720ssp_readwrite(sc, 0, 0x8800, &data, 100) < 0)
549 1.1 toshii goto out;
550 1.1 toshii BIT_INVERT(data);
551 1.1 toshii *buf++ = data;
552 1.1 toshii }
553 1.1 toshii *buf = 0;
554 1.1 toshii bus_space_write_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_PSR, 0x2000000);
555 1.1 toshii
556 1.1 toshii #ifdef DEBUG
557 1.1 toshii oscr = (u_int32_t)gettick() - oscr;
558 1.1 toshii j720sspwaitcnt++;
559 1.1 toshii j720sspwaittime += oscr;
560 1.1 toshii #endif
561 1.1 toshii
562 1.1 toshii return;
563 1.1 toshii
564 1.1 toshii out:
565 1.1 toshii *buf = 0;
566 1.1 toshii bus_space_write_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_PSR, 0x2000000);
567 1.1 toshii
568 1.1 toshii /* reset SSP */
569 1.1 toshii bus_space_write_4(sc->sc_iot, sc->sc_ssph, SASSP_CR0, 0x307);
570 1.1 toshii delay(100);
571 1.1 toshii bus_space_write_4(sc->sc_iot, sc->sc_ssph, SASSP_CR0, 0x387);
572 1.2.2.5 jdolecek
573 1.2.2.5 jdolecek printf("j720kbd_read: error %x\n", data);
574 1.2.2.5 jdolecek return;
575 1.2.2.4 jdolecek }
576 1.2.2.4 jdolecek
577 1.2.2.5 jdolecek int
578 1.2.2.5 jdolecek j720tp_poll(arg)
579 1.2.2.5 jdolecek void *arg;
580 1.2.2.4 jdolecek {
581 1.2.2.4 jdolecek struct j720ssp_softc *sc = arg;
582 1.2.2.4 jdolecek int buf[8], data, i, x, y;
583 1.2.2.4 jdolecek
584 1.2.2.5 jdolecek /*
585 1.2.2.5 jdolecek * If touch panel is not touched anymore,
586 1.2.2.5 jdolecek * stop polling and re-enable interrupt
587 1.2.2.5 jdolecek */
588 1.2.2.5 jdolecek if (bus_space_read_4(sc->sc_iot,
589 1.2.2.5 jdolecek sc->sc_gpioh, SAGPIO_PLR) & (1 << 9)) {
590 1.2.2.5 jdolecek wsmouse_input(sc->sc_wsmousedev, 0, 0, 0, 0, 0);
591 1.2.2.5 jdolecek j720tp_enable(sc);
592 1.2.2.5 jdolecek return 0;
593 1.2.2.5 jdolecek }
594 1.2.2.5 jdolecek
595 1.2.2.4 jdolecek bus_space_write_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_PCR, 0x2000000);
596 1.2.2.4 jdolecek
597 1.2.2.4 jdolecek /* send read touchpanel command */
598 1.2.2.5 jdolecek if (j720ssp_readwrite(sc, 1, 0x500, &data, 100) < 0 ||
599 1.2.2.4 jdolecek data != 0x88)
600 1.2.2.4 jdolecek goto out;
601 1.2.2.4 jdolecek
602 1.2.2.4 jdolecek for(i = 0; i < 8; i++) {
603 1.2.2.5 jdolecek if (j720ssp_readwrite(sc, 0, 0x8800, &data, 100) < 0)
604 1.2.2.4 jdolecek goto out;
605 1.2.2.4 jdolecek BIT_INVERT(data);
606 1.2.2.4 jdolecek buf[i] = data;
607 1.2.2.4 jdolecek }
608 1.2.2.4 jdolecek
609 1.2.2.4 jdolecek bus_space_write_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_PSR, 0x2000000);
610 1.2.2.4 jdolecek
611 1.2.2.4 jdolecek buf[6] <<= 8;
612 1.2.2.4 jdolecek buf[7] <<= 8;
613 1.2.2.4 jdolecek for(i = 0; i < 3; i++) {
614 1.2.2.4 jdolecek buf[i] |= buf[6] & 0x300;
615 1.2.2.4 jdolecek buf[6] >>= 2;
616 1.2.2.4 jdolecek buf[i + 3] |= buf[7] & 0x300;
617 1.2.2.4 jdolecek buf[7] >>= 2;
618 1.2.2.4 jdolecek }
619 1.2.2.4 jdolecek #if 0
620 1.2.2.5 jdolecek printf("j720tp_poll: %d %d %d %d %d %d\n", buf[0], buf[1], buf[2],
621 1.2.2.4 jdolecek buf[3], buf[4], buf[5]);
622 1.2.2.4 jdolecek #endif
623 1.2.2.4 jdolecek
624 1.2.2.4 jdolecek /* XXX buf[1], buf[2], ... should also be used */
625 1.2.2.4 jdolecek tpcalib_trans(&sc->sc_tpcalib, buf[1], buf[4], &x, &y);
626 1.2.2.4 jdolecek wsmouse_input(sc->sc_wsmousedev, 1, x, y, 0,
627 1.2.2.4 jdolecek WSMOUSE_INPUT_ABSOLUTE_X | WSMOUSE_INPUT_ABSOLUTE_Y);
628 1.2.2.4 jdolecek
629 1.2.2.5 jdolecek return 1;
630 1.2.2.4 jdolecek
631 1.2.2.4 jdolecek out:
632 1.2.2.4 jdolecek *buf = 0;
633 1.2.2.4 jdolecek bus_space_write_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_PSR, 0x2000000);
634 1.2.2.4 jdolecek
635 1.2.2.4 jdolecek /* reset SSP */
636 1.2.2.4 jdolecek bus_space_write_4(sc->sc_iot, sc->sc_ssph, SASSP_CR0, 0x307);
637 1.2.2.4 jdolecek delay(100);
638 1.2.2.4 jdolecek bus_space_write_4(sc->sc_iot, sc->sc_ssph, SASSP_CR0, 0x387);
639 1.2.2.5 jdolecek printf("j720tp_poll: error %x\n", data);
640 1.2.2.4 jdolecek
641 1.2.2.5 jdolecek return 0;
642 1.2.2.4 jdolecek }
643 1.2.2.4 jdolecek
644 1.2.2.4 jdolecek static int
645 1.2.2.5 jdolecek j720tp_enable(arg)
646 1.2.2.5 jdolecek void *arg;
647 1.2.2.5 jdolecek {
648 1.2.2.4 jdolecek struct j720ssp_softc *sc = arg;
649 1.2.2.4 jdolecek int er, s;
650 1.2.2.4 jdolecek
651 1.2.2.4 jdolecek s = splhigh();
652 1.2.2.4 jdolecek er = bus_space_read_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_FER);
653 1.2.2.4 jdolecek er |= 1 << 9;
654 1.2.2.4 jdolecek bus_space_write_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_FER, er);
655 1.2.2.4 jdolecek splx(s);
656 1.2.2.4 jdolecek
657 1.2.2.4 jdolecek return (0);
658 1.2.2.4 jdolecek }
659 1.2.2.4 jdolecek
660 1.2.2.4 jdolecek static void
661 1.2.2.5 jdolecek j720tp_disable(arg)
662 1.2.2.5 jdolecek void *arg;
663 1.2.2.5 jdolecek {
664 1.2.2.4 jdolecek struct j720ssp_softc *sc = arg;
665 1.2.2.4 jdolecek int er, s;
666 1.2.2.4 jdolecek
667 1.2.2.4 jdolecek s = splhigh();
668 1.2.2.4 jdolecek er = bus_space_read_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_FER);
669 1.2.2.4 jdolecek er &= ~(1 << 9);
670 1.2.2.4 jdolecek bus_space_write_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_FER, er);
671 1.2.2.4 jdolecek splx(s);
672 1.2.2.4 jdolecek }
673 1.2.2.4 jdolecek
674 1.2.2.4 jdolecek static int
675 1.2.2.5 jdolecek j720tp_ioctl(arg, cmd, data, flag, p)
676 1.2.2.5 jdolecek void *arg;
677 1.2.2.5 jdolecek u_long cmd;
678 1.2.2.5 jdolecek caddr_t data;
679 1.2.2.5 jdolecek int flag;
680 1.2.2.5 jdolecek struct proc *p;
681 1.2.2.5 jdolecek {
682 1.2.2.4 jdolecek struct j720ssp_softc *sc = arg;
683 1.2.2.4 jdolecek
684 1.2.2.4 jdolecek switch (cmd) {
685 1.2.2.4 jdolecek case WSMOUSEIO_GTYPE:
686 1.2.2.4 jdolecek *(u_int *)data = WSMOUSE_TYPE_TPANEL;
687 1.2.2.4 jdolecek return (0);
688 1.2.2.4 jdolecek
689 1.2.2.4 jdolecek case WSMOUSEIO_SCALIBCOORDS:
690 1.2.2.4 jdolecek case WSMOUSEIO_GCALIBCOORDS:
691 1.2.2.4 jdolecek return tpcalib_ioctl(&sc->sc_tpcalib, cmd, data, flag, p);
692 1.2.2.4 jdolecek
693 1.2.2.4 jdolecek default:
694 1.2.2.4 jdolecek return (EPASSTHROUGH);
695 1.2.2.4 jdolecek }
696 1.1 toshii }
697 1.1 toshii
698 1.1 toshii int
699 1.2.2.5 jdolecek j720lcdparam(ctx, type, id, msg)
700 1.2.2.5 jdolecek void *ctx;
701 1.2.2.5 jdolecek int type;
702 1.2.2.5 jdolecek long id;
703 1.2.2.5 jdolecek void *msg;
704 1.1 toshii {
705 1.1 toshii struct j720ssp_softc *sc = ctx;
706 1.1 toshii int i, s;
707 1.1 toshii u_int32_t data[2], len;
708 1.1 toshii
709 1.1 toshii switch (type) {
710 1.1 toshii case CONFIG_HOOK_GET:
711 1.1 toshii switch (id) {
712 1.1 toshii case CONFIG_HOOK_BRIGHTNESS_MAX:
713 1.1 toshii case CONFIG_HOOK_CONTRAST_MAX:
714 1.1 toshii *(int *)msg = 255;
715 1.1 toshii return 1;
716 1.1 toshii case CONFIG_HOOK_BRIGHTNESS:
717 1.1 toshii data[0] = 0x6b00;
718 1.1 toshii data[1] = 0x8800;
719 1.1 toshii len = 2;
720 1.1 toshii break;
721 1.1 toshii case CONFIG_HOOK_CONTRAST:
722 1.1 toshii data[0] = 0x2b00;
723 1.1 toshii data[1] = 0x8800;
724 1.1 toshii len = 2;
725 1.1 toshii break;
726 1.1 toshii default:
727 1.1 toshii return 0;
728 1.1 toshii }
729 1.1 toshii break;
730 1.1 toshii
731 1.1 toshii case CONFIG_HOOK_SET:
732 1.1 toshii switch (id) {
733 1.1 toshii case CONFIG_HOOK_BRIGHTNESS:
734 1.1 toshii if (*(int *)msg >= 0) {
735 1.1 toshii data[0] = 0xcb00;
736 1.1 toshii data[1] = *(int *)msg;
737 1.1 toshii BIT_INVERT(data[1]);
738 1.1 toshii data[1] <<= 8;
739 1.1 toshii len = 2;
740 1.1 toshii } else {
741 1.1 toshii /* XXX hack */
742 1.1 toshii data[0] = 0xfb00;
743 1.1 toshii len = 1;
744 1.1 toshii }
745 1.1 toshii break;
746 1.1 toshii case CONFIG_HOOK_CONTRAST:
747 1.1 toshii data[0] = 0x8b00;
748 1.1 toshii data[1] = *(int *)msg;
749 1.1 toshii BIT_INVERT(data[1]);
750 1.1 toshii data[1] <<= 8;
751 1.1 toshii len = 2;
752 1.1 toshii break;
753 1.1 toshii default:
754 1.1 toshii return 0;
755 1.1 toshii }
756 1.1 toshii }
757 1.1 toshii
758 1.1 toshii s = splbio();
759 1.1 toshii bus_space_write_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_PCR, 0x2000000);
760 1.1 toshii
761 1.1 toshii for (i = 0; i < len; i++) {
762 1.2.2.5 jdolecek if (j720ssp_readwrite(sc, 1, data[i], &data[i], 500) < 0)
763 1.1 toshii goto out;
764 1.1 toshii }
765 1.1 toshii bus_space_write_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_PSR, 0x2000000);
766 1.1 toshii splx(s);
767 1.1 toshii
768 1.1 toshii if (type == CONFIG_HOOK_SET)
769 1.1 toshii return 1;
770 1.1 toshii
771 1.1 toshii BIT_INVERT(data[1]);
772 1.1 toshii *(int *)msg = data[1];
773 1.1 toshii
774 1.1 toshii return 1;
775 1.1 toshii
776 1.1 toshii out:
777 1.1 toshii bus_space_write_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_PSR, 0x2000000);
778 1.1 toshii
779 1.1 toshii /* reset SSP */
780 1.1 toshii bus_space_write_4(sc->sc_iot, sc->sc_ssph, SASSP_CR0, 0x307);
781 1.1 toshii delay(100);
782 1.1 toshii bus_space_write_4(sc->sc_iot, sc->sc_ssph, SASSP_CR0, 0x387);
783 1.1 toshii splx(s);
784 1.1 toshii return 0;
785 1.1 toshii }
786 1.1 toshii
787 1.1 toshii static int
788 1.2.2.5 jdolecek j720ssp_readwrite(sc, drainfifo, in, out, wait)
789 1.2.2.5 jdolecek struct j720ssp_softc *sc;
790 1.2.2.5 jdolecek int drainfifo;
791 1.2.2.5 jdolecek int in;
792 1.2.2.5 jdolecek int *out;
793 1.2.2.5 jdolecek int wait;
794 1.1 toshii {
795 1.1 toshii int timo;
796 1.1 toshii
797 1.1 toshii timo = 100000;
798 1.1 toshii while(bus_space_read_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_PLR) & 0x400)
799 1.1 toshii if (--timo == 0) {
800 1.1 toshii printf("timo0\n");
801 1.1 toshii return -1;
802 1.1 toshii }
803 1.1 toshii if (drainfifo) {
804 1.1 toshii while(bus_space_read_4(sc->sc_iot, sc->sc_ssph, SASSP_SR) &
805 1.1 toshii SR_RNE)
806 1.1 toshii bus_space_read_4(sc->sc_iot, sc->sc_ssph, SASSP_DR);
807 1.1 toshii #if 1
808 1.2.2.5 jdolecek delay(wait);
809 1.1 toshii #endif
810 1.1 toshii }
811 1.1 toshii
812 1.1 toshii bus_space_write_4(sc->sc_iot, sc->sc_ssph, SASSP_DR, in);
813 1.1 toshii
814 1.2.2.5 jdolecek delay(wait);
815 1.1 toshii timo = 100000;
816 1.1 toshii while(! (bus_space_read_4(sc->sc_iot, sc->sc_ssph, SASSP_SR) & SR_RNE))
817 1.1 toshii if (--timo == 0) {
818 1.1 toshii printf("timo1\n");
819 1.1 toshii return -1;
820 1.1 toshii }
821 1.1 toshii
822 1.1 toshii *out = bus_space_read_4(sc->sc_iot, sc->sc_ssph, SASSP_DR);
823 1.1 toshii
824 1.1 toshii return 0;
825 1.1 toshii }
826 1.1 toshii
827 1.1 toshii #if 0
828 1.1 toshii int
829 1.2.2.5 jdolecek j720kbd_cnattach(void)
830 1.1 toshii {
831 1.2.2.1 thorpej /* XXX defer initialization till j720sspattach */
832 1.2.2.1 thorpej
833 1.2.2.1 thorpej return (0);
834 1.1 toshii }
835 1.1 toshii #endif
836 1.1 toshii
837 1.1 toshii /* ARGSUSED */
838 1.1 toshii void
839 1.2.2.5 jdolecek j720kbd_cngetc(v, type, data)
840 1.2.2.5 jdolecek void *v;
841 1.2.2.5 jdolecek u_int *type;
842 1.2.2.5 jdolecek int *data;
843 1.1 toshii {
844 1.1 toshii char buf[9];
845 1.2.2.1 thorpej
846 1.2.2.1 thorpej if (j720kbdcons_initstate < 1)
847 1.2.2.1 thorpej return;
848 1.1 toshii
849 1.1 toshii for (;;) {
850 1.1 toshii j720kbd_read(&j720kbdcons_sc, buf);
851 1.1 toshii
852 1.1 toshii if (buf[0] != 0) {
853 1.1 toshii /* XXX we are discarding buffer contents */
854 1.1 toshii *type = buf[0] & 0x80 ? WSCONS_EVENT_KEY_UP :
855 1.1 toshii WSCONS_EVENT_KEY_DOWN;
856 1.1 toshii *data = buf[0] & 0x7f;
857 1.1 toshii return;
858 1.1 toshii }
859 1.1 toshii }
860 1.1 toshii }
861 1.1 toshii
862 1.1 toshii void
863 1.2.2.5 jdolecek j720kbd_cnpollc(v, on)
864 1.2.2.5 jdolecek void *v;
865 1.2.2.5 jdolecek int on;
866 1.1 toshii {
867 1.1 toshii #if 0
868 1.1 toshii /* XXX */
869 1.1 toshii struct j720kbd_internal *t = v;
870 1.1 toshii
871 1.1 toshii pckbc_set_poll(t->t_kbctag, t->t_kbcslot, on);
872 1.1 toshii #endif
873 1.1 toshii }
874 1.1 toshii
875 1.1 toshii void
876 1.2.2.5 jdolecek j720kbd_cnbell(v, pitch, period, volume)
877 1.2.2.5 jdolecek void *v;
878 1.2.2.5 jdolecek u_int pitch;
879 1.2.2.5 jdolecek u_int period;
880 1.2.2.5 jdolecek u_int volume;
881 1.1 toshii {
882 1.1 toshii }
883 1.1 toshii
884 1.1 toshii int
885 1.2.2.5 jdolecek j720lcdpower(ctx, type, id, msg)
886 1.2.2.5 jdolecek void *ctx;
887 1.2.2.5 jdolecek int type;
888 1.2.2.5 jdolecek long id;
889 1.2.2.5 jdolecek void *msg;
890 1.1 toshii {
891 1.1 toshii struct sed1356_softc *sc = ctx;
892 1.1 toshii struct sa11x0_softc *psc = sc->sc_parent;
893 1.1 toshii int val;
894 1.1 toshii u_int32_t reg;
895 1.1 toshii
896 1.1 toshii if (type != CONFIG_HOOK_POWERCONTROL ||
897 1.1 toshii id != CONFIG_HOOK_POWERCONTROL_LCDLIGHT)
898 1.1 toshii return 0;
899 1.1 toshii
900 1.1 toshii sed1356_init_brightness(sc, 0);
901 1.1 toshii sed1356_init_contrast(sc, 0);
902 1.1 toshii
903 1.1 toshii if (msg) {
904 1.1 toshii bus_space_write_1(sc->sc_iot, sc->sc_regh, 0x1f0, 0);
905 1.1 toshii
906 1.1 toshii reg = bus_space_read_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR);
907 1.1 toshii reg |= 0x1;
908 1.1 toshii bus_space_write_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR, reg);
909 1.1 toshii delay(50000);
910 1.1 toshii
911 1.1 toshii val = sc->sc_contrast;
912 1.1 toshii config_hook_call(CONFIG_HOOK_SET, CONFIG_HOOK_CONTRAST, &val);
913 1.1 toshii delay(100000);
914 1.1 toshii
915 1.1 toshii reg = bus_space_read_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR);
916 1.1 toshii reg |= 0x4;
917 1.1 toshii bus_space_write_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR, reg);
918 1.1 toshii
919 1.1 toshii val = sc->sc_brightness;
920 1.1 toshii config_hook_call(CONFIG_HOOK_SET, CONFIG_HOOK_BRIGHTNESS, &val);
921 1.1 toshii
922 1.1 toshii reg = bus_space_read_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR);
923 1.1 toshii reg |= 0x2;
924 1.1 toshii bus_space_write_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR, reg);
925 1.1 toshii } else {
926 1.1 toshii reg = bus_space_read_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR);
927 1.1 toshii reg &= ~0x2;
928 1.1 toshii bus_space_write_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR, reg);
929 1.1 toshii reg &= ~0x4;
930 1.1 toshii bus_space_write_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR, reg);
931 1.1 toshii delay(100000);
932 1.1 toshii
933 1.1 toshii val = -2;
934 1.1 toshii config_hook_call(CONFIG_HOOK_SET, CONFIG_HOOK_BRIGHTNESS, &val);
935 1.1 toshii
936 1.1 toshii bus_space_write_1(sc->sc_iot, sc->sc_regh, 0x1f0, 1);
937 1.1 toshii
938 1.1 toshii delay(100000);
939 1.1 toshii reg = bus_space_read_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR);
940 1.1 toshii reg &= ~0x1;
941 1.1 toshii bus_space_write_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR, reg);
942 1.1 toshii }
943 1.1 toshii return 1;
944 1.2.2.5 jdolecek }
945 1.2.2.5 jdolecek
946 1.2.2.5 jdolecek int
947 1.2.2.5 jdolecek hpcarm_apm_getpower(api, parent)
948 1.2.2.5 jdolecek struct apm_power_info *api;
949 1.2.2.5 jdolecek void *parent;
950 1.2.2.5 jdolecek {
951 1.2.2.5 jdolecek int data, pmdata[3], i;
952 1.2.2.5 jdolecek struct j720ssp_softc *sc = (struct j720ssp_softc *)parent;
953 1.2.2.5 jdolecek
954 1.2.2.5 jdolecek bus_space_write_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_PCR, 0x2000000);
955 1.2.2.5 jdolecek
956 1.2.2.5 jdolecek if (j720ssp_readwrite(sc, 1, 0x300, &data, 100) < 0 || data != 0x88)
957 1.2.2.5 jdolecek goto out;
958 1.2.2.5 jdolecek
959 1.2.2.5 jdolecek for (i = 0; i < 3; i++) {
960 1.2.2.5 jdolecek if (j720ssp_readwrite(sc, 0, 0x8800, &pmdata[i], 500) < 0)
961 1.2.2.5 jdolecek goto out;
962 1.2.2.5 jdolecek BIT_INVERT(pmdata[i]);
963 1.2.2.5 jdolecek #if 0
964 1.2.2.5 jdolecek printf("pmdata%d = %d ", i, pmdata[i]);
965 1.2.2.5 jdolecek #endif
966 1.2.2.5 jdolecek }
967 1.2.2.5 jdolecek printf("\n");
968 1.2.2.5 jdolecek
969 1.2.2.5 jdolecek bus_space_write_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_PSR, 0x2000000);
970 1.2.2.5 jdolecek
971 1.2.2.5 jdolecek bzero(api, sizeof(struct apm_power_info));
972 1.2.2.5 jdolecek api->ac_state = APM_AC_UNKNOWN;
973 1.2.2.5 jdolecek
974 1.2.2.5 jdolecek /*
975 1.2.2.5 jdolecek * pmdata[0] is the main battery level
976 1.2.2.5 jdolecek * pmdata[1] is the backup battery level
977 1.2.2.5 jdolecek * pmdata[2] tells which battery is present
978 1.2.2.5 jdolecek */
979 1.2.2.5 jdolecek switch(pmdata[2]) {
980 1.2.2.5 jdolecek case 14: /* backup battery present */
981 1.2.2.5 jdolecek case 2: /* backup battery absent */
982 1.2.2.5 jdolecek api->battery_state = APM_BATT_CHARGING;
983 1.2.2.5 jdolecek api->minutes_left = (pmdata[0] * 840) / 170;
984 1.2.2.5 jdolecek api->battery_life = (pmdata[0] * 100) / 170;
985 1.2.2.5 jdolecek api->nbattery = 1;
986 1.2.2.5 jdolecek break;
987 1.2.2.5 jdolecek case 15: /* backup battery present */
988 1.2.2.5 jdolecek case 3: /* backup battery absent */
989 1.2.2.5 jdolecek api->battery_state = APM_BATT_ABSENT;
990 1.2.2.5 jdolecek api->battery_life = 0;
991 1.2.2.5 jdolecek api->nbattery = 0;
992 1.2.2.5 jdolecek break;
993 1.2.2.5 jdolecek default:
994 1.2.2.5 jdolecek api->battery_state = APM_BATT_UNKNOWN;
995 1.2.2.5 jdolecek break;
996 1.2.2.5 jdolecek }
997 1.2.2.5 jdolecek
998 1.2.2.5 jdolecek return 0;
999 1.2.2.5 jdolecek
1000 1.2.2.5 jdolecek out:
1001 1.2.2.5 jdolecek bus_space_write_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_PSR, 0x2000000);
1002 1.2.2.5 jdolecek
1003 1.2.2.5 jdolecek /* reset SSP */
1004 1.2.2.5 jdolecek bus_space_write_4(sc->sc_iot, sc->sc_ssph, SASSP_CR0, 0x307);
1005 1.2.2.5 jdolecek delay(100);
1006 1.2.2.5 jdolecek bus_space_write_4(sc->sc_iot, sc->sc_ssph, SASSP_CR0, 0x387);
1007 1.2.2.5 jdolecek
1008 1.2.2.5 jdolecek printf("hpcarm_apm_getpower: error %x\n", data);
1009 1.2.2.5 jdolecek return EIO;
1010 1.1 toshii }
1011