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