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