j720ssp.c revision 1.8 1 /* $NetBSD: j720ssp.c,v 1.8 2002/07/22 20:55:48 manu Exp $ */
2
3 /*-
4 * Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Charles M. Hannum.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 /*-
40 * Copyright (c) 1990 The Regents of the University of California.
41 * All rights reserved.
42 *
43 * This code is derived from software contributed to Berkeley by
44 * William Jolitz and Don Ahn.
45 *
46 * Redistribution and use in source and binary forms, with or without
47 * modification, are permitted provided that the following conditions
48 * are met:
49 * 1. Redistributions of source code must retain the above copyright
50 * notice, this list of conditions and the following disclaimer.
51 * 2. Redistributions in binary form must reproduce the above copyright
52 * notice, this list of conditions and the following disclaimer in the
53 * documentation and/or other materials provided with the distribution.
54 * 3. All advertising materials mentioning features or use of this software
55 * must display the following acknowledgement:
56 * This product includes software developed by the University of
57 * California, Berkeley and its contributors.
58 * 4. Neither the name of the University nor the names of its contributors
59 * may be used to endorse or promote products derived from this software
60 * without specific prior written permission.
61 *
62 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
63 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
64 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
65 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
66 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
67 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
68 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
69 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
70 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
71 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
72 * SUCH DAMAGE.
73 *
74 * @(#)pccons.c 5.11 (Berkeley) 5/21/91
75 */
76
77 #include <sys/param.h>
78 #include <sys/systm.h>
79 #include <sys/device.h>
80 #include <sys/callout.h>
81 #include <sys/kernel.h>
82 #include <sys/malloc.h>
83 #include <sys/ioctl.h>
84
85 #include <machine/bus.h>
86 #include <machine/config_hook.h>
87 #include <machine/bootinfo.h>
88
89 #include <hpcarm/dev/sed1356var.h>
90
91 #include <arm/sa11x0/sa11x0_var.h>
92 #include <arm/sa11x0/sa11x0_gpioreg.h>
93 #include <arm/sa11x0/sa11x0_ppcreg.h>
94 #include <arm/sa11x0/sa11x0_sspreg.h>
95
96 #include <dev/wscons/wsconsio.h>
97 #include <dev/wscons/wskbdvar.h>
98 #include <dev/wscons/wsksymdef.h>
99 #include <dev/wscons/wsksymvar.h>
100 #include <dev/wscons/wsmousevar.h>
101 #include <dev/hpc/tpcalibvar.h>
102
103 extern const struct wscons_keydesc j720kbd_keydesctab[];
104
105 struct j720ssp_softc {
106 struct device sc_dev;
107
108 bus_space_tag_t sc_iot;
109 bus_space_handle_t sc_gpioh;
110 bus_space_handle_t sc_ssph;
111
112 struct device *sc_wskbddev;
113 struct device *sc_wsmousedev;
114 struct tpcalib_softc sc_tpcalib;
115
116 void *sc_kbdsi;
117 void *sc_tpsi;
118 struct callout sc_tptimeout;
119 int sc_enabled;
120 };
121
122 int j720kbd_intr(void *);
123 int j720tp_intr(void *);
124 void j720kbdsoft(void *);
125 void j720tpsoft(void *);
126 void j720tp_timeout(void *);
127 int j720lcdparam(void *, int, long, void *);
128 static void j720kbd_read(struct j720ssp_softc *, char *);
129 static int j720ssp_readwrite(struct j720ssp_softc *, int, int, int *);
130
131 int j720sspprobe(struct device *, struct cfdata *, void *);
132 void j720sspattach(struct device *, struct device *, void *);
133
134 int j720kbd_submatch(struct device *, struct cfdata *, void *);
135 int j720tp_submatch(struct device *, struct cfdata *, void *);
136
137 int j720kbd_enable(void *, int);
138 void j720kbd_set_leds(void *, int);
139 int j720kbd_ioctl(void *, u_long, caddr_t, int, struct proc *);
140
141 struct cfattach j720ssp_ca = {
142 sizeof(struct j720ssp_softc), j720sspprobe, j720sspattach,
143 };
144
145 const struct wskbd_accessops j720kbd_accessops = {
146 j720kbd_enable,
147 j720kbd_set_leds,
148 j720kbd_ioctl,
149 };
150
151 void j720kbd_cngetc(void *, u_int *, int *);
152 void j720kbd_cnpollc(void *, int);
153 void j720kbd_cnbell(void *, u_int, u_int, u_int);
154
155 const struct wskbd_consops j720kbd_consops = {
156 j720kbd_cngetc,
157 j720kbd_cnpollc,
158 j720kbd_cnbell,
159 };
160
161 const struct wskbd_mapdata j720kbd_keymapdata = {
162 j720kbd_keydesctab,
163 #ifdef J720KBD_LAYOUT
164 J720KBD_LAYOUT,
165 #else
166 KB_US,
167 #endif
168 };
169
170 static int j720tp_enable(void *);
171 static int j720tp_ioctl(void *, u_long, caddr_t, int, struct proc *);
172 static void j720tp_disable(void *);
173
174 const struct wsmouse_accessops j720tp_accessops = {
175 j720tp_enable,
176 j720tp_ioctl,
177 j720tp_disable,
178 };
179
180 static int j720ssp_powerstate = 1;
181
182 static struct j720ssp_softc j720kbdcons_sc;
183 static int j720kbdcons_initstate = 0;
184
185 #define DEBUG
186 #ifdef DEBUG
187 int j720sspwaitcnt;
188 int j720sspwaittime;
189 extern int gettick();
190 #endif
191
192 #define BIT_INVERT(x) do { \
193 (x) = ((((x) & 0xf0) >> 4) | (((x) & 0x0f) << 4)); \
194 (x) = ((((x) & 0xcc) >> 2) | (((x) & 0x33) << 2)); \
195 (x) = ((((x) & 0xaa) >> 1) | (((x) & 0x55) << 1)); \
196 } while(0)
197
198 int
199 j720sspprobe(struct device *parent, struct cfdata *cf, void *aux)
200 {
201 return (1);
202 }
203
204 void
205 j720sspattach(struct device *parent, struct device *self, void *aux)
206 {
207 struct j720ssp_softc *sc = (void *)self;
208 struct sa11x0_softc *psc = (void *)parent;
209 struct sa11x0_attach_args *sa = aux;
210 struct wskbddev_attach_args a;
211 struct wsmousedev_attach_args ma;
212
213 printf("\n");
214
215 sc->sc_iot = psc->sc_iot;
216 sc->sc_gpioh = psc->sc_gpioh;
217 if (bus_space_map(sc->sc_iot, sa->sa_addr, sa->sa_size, 0,
218 &sc->sc_ssph)) {
219 printf("%s: unable to map SSP registers\n",
220 sc->sc_dev.dv_xname);
221 return;
222 }
223
224 sc->sc_kbdsi = softintr_establish(IPL_SOFTCLOCK, j720kbdsoft, sc);
225
226 sc->sc_enabled = 0;
227
228 a.console = 0;
229
230 a.keymap = &j720kbd_keymapdata;
231
232 a.accessops = &j720kbd_accessops;
233 a.accesscookie = sc;
234
235 /* Do console initialization */
236 if (! (bootinfo->bi_cnuse & BI_CNUSE_SERIAL)) {
237 j720kbdcons_sc = *sc;
238 a.console = 1;
239
240 wskbd_cnattach(&j720kbd_consops, NULL, &j720kbd_keymapdata);
241 j720kbdcons_initstate = 1;
242 }
243
244 /*
245 * Attach the wskbd, saving a handle to it.
246 * XXX XXX XXX
247 */
248 sc->sc_wskbddev = config_found_sm(self, &a, wskbddevprint,
249 j720kbd_submatch);
250
251 #ifdef DEBUG
252 /* Zero the stat counters */
253 j720sspwaitcnt = 0;
254 j720sspwaittime = 0;
255 #endif
256
257 if (j720kbdcons_initstate == 1)
258 j720kbd_enable(sc, 1);
259
260 ma.accessops = &j720tp_accessops;
261 ma.accesscookie = sc;
262
263 sc->sc_wsmousedev = config_found_sm(self, &ma, wsmousedevprint,
264 j720tp_submatch);
265 tpcalib_init(&sc->sc_tpcalib);
266
267 /* XXX fill in "default" calibrate param */
268 {
269 static const struct wsmouse_calibcoords j720_default_calib = {
270 0, 0, 639, 239,
271 4,
272 { { 988, 80, 0, 0 },
273 { 88, 84, 639, 0 },
274 { 988, 927, 0, 239 },
275 { 88, 940, 639, 239 } } };
276 tpcalib_ioctl(&sc->sc_tpcalib, WSMOUSEIO_SCALIBCOORDS,
277 (caddr_t)&j720_default_calib, 0, 0);
278 }
279
280 j720tp_disable(sc);
281 callout_init(&sc->sc_tptimeout);
282
283 /* Setup touchpad interrupt */
284 sc->sc_tpsi = softintr_establish(IPL_SOFTCLOCK, j720tpsoft, sc);
285 sa11x0_intr_establish(0, 9, 1, IPL_BIO, j720tp_intr, sc);
286
287 /* LCD control is on the same bus */
288 config_hook(CONFIG_HOOK_SET, CONFIG_HOOK_BRIGHTNESS,
289 CONFIG_HOOK_SHARE, j720lcdparam, sc);
290 config_hook(CONFIG_HOOK_GET, CONFIG_HOOK_BRIGHTNESS,
291 CONFIG_HOOK_SHARE, j720lcdparam, sc);
292 config_hook(CONFIG_HOOK_GET, CONFIG_HOOK_BRIGHTNESS_MAX,
293 CONFIG_HOOK_SHARE, j720lcdparam, sc);
294
295 config_hook(CONFIG_HOOK_SET, CONFIG_HOOK_CONTRAST,
296 CONFIG_HOOK_SHARE, j720lcdparam, sc);
297 config_hook(CONFIG_HOOK_GET, CONFIG_HOOK_CONTRAST,
298 CONFIG_HOOK_SHARE, j720lcdparam, sc);
299 config_hook(CONFIG_HOOK_GET, CONFIG_HOOK_CONTRAST_MAX,
300 CONFIG_HOOK_SHARE, j720lcdparam, sc);
301 }
302
303 int
304 j720kbd_submatch(struct device *parant, struct cfdata *cf, void *aux) {
305
306 if (strcmp(cf->cf_driver->cd_name, "wskbd") == 0)
307 return (1);
308 return (0);
309 }
310
311 int
312 j720tp_submatch(struct device *parant, struct cfdata *cf, void *aux) {
313
314 if (strcmp(cf->cf_driver->cd_name, "wsmouse") == 0)
315 return (1);
316 return (0);
317 }
318
319 int
320 j720kbd_enable(void *v, int on)
321 {
322 struct j720ssp_softc *sc = v;
323
324 if (! sc->sc_enabled) {
325 sc->sc_enabled = 1;
326
327 sa11x0_intr_establish(0, 0, 1, IPL_BIO, j720kbd_intr, sc);
328 }
329 /* XXX */
330 return (0);
331 }
332
333 void
334 j720kbd_set_leds(void *v, int on)
335 {
336 /* XXX */
337 return;
338 }
339
340 int
341 j720kbd_ioctl(v, cmd, data, flag, p)
342 void *v;
343 u_long cmd;
344 caddr_t data;
345 int flag;
346 struct proc *p;
347 {
348 switch (cmd) {
349 case WSKBDIO_GTYPE:
350 *(int *)data = WSKBD_TYPE_HPC_KBD;
351 return 0;
352 }
353
354 return (EPASSTHROUGH);
355 }
356
357 int
358 j720kbd_intr(void *arg)
359 {
360 struct j720ssp_softc *sc = arg;
361
362 bus_space_write_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_EDR, 1);
363
364 /*
365 * Schedule a soft interrupt to process at lower priority,
366 * as reading keycodes takes time.
367 *
368 * Interrupts are generated every 25-33ms as long as there
369 * are unprocessed key events. So it is not a good idea to
370 * use callout to call j720kbdsoft after some delay in hope
371 * of reducing interrupts.
372 */
373 softintr_schedule(sc->sc_kbdsi);
374
375 return (1);
376 }
377
378 int
379 j720tp_intr(void *arg)
380 {
381 struct j720ssp_softc *sc = arg;
382
383 bus_space_write_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_EDR, 1 << 9);
384
385 softintr_schedule(sc->sc_tpsi);
386
387 return (1);
388 }
389
390 void
391 j720kbdsoft(void *arg)
392 {
393 struct j720ssp_softc *sc = arg;
394 int s, type, value;
395 char buf[9], *p;
396
397 j720kbd_read(sc, buf);
398
399 for(p = buf; *p; p++) {
400 type = *p & 0x80 ? WSCONS_EVENT_KEY_UP :
401 WSCONS_EVENT_KEY_DOWN;
402 value = *p & 0x7f;
403 s = spltty();
404 wskbd_input(sc->sc_wskbddev, type, value);
405 splx(s);
406 if (type == WSCONS_EVENT_KEY_DOWN &&
407 value == 0x7f) {
408 j720ssp_powerstate = ! j720ssp_powerstate;
409 config_hook_call(CONFIG_HOOK_POWERCONTROL,
410 CONFIG_HOOK_POWERCONTROL_LCDLIGHT,
411 (void *)j720ssp_powerstate);
412 }
413 }
414
415 return;
416 }
417
418 void
419 j720kbd_read(struct j720ssp_softc *sc, char *buf)
420 {
421 int data, count;
422 #ifdef DEBUG
423 u_int32_t oscr;
424
425 oscr = gettick();
426 #endif
427 bus_space_write_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_PCR, 0x2000000);
428
429 /* send scan keycode command */
430 if (j720ssp_readwrite(sc, 1, 0x900, &data) < 0 ||
431 data != 0x88)
432 goto out;
433
434 /* read numbers of scancode available */
435 if (j720ssp_readwrite(sc, 0, 0x8800, &data) < 0)
436 goto out;
437 BIT_INVERT(data);
438 count = data;
439
440 for(; count; count--) {
441 if (j720ssp_readwrite(sc, 0, 0x8800, &data) < 0)
442 goto out;
443 BIT_INVERT(data);
444 *buf++ = data;
445 }
446 *buf = 0;
447 bus_space_write_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_PSR, 0x2000000);
448
449 #ifdef DEBUG
450 oscr = (u_int32_t)gettick() - oscr;
451 j720sspwaitcnt++;
452 j720sspwaittime += oscr;
453 #endif
454
455 return;
456
457 out:
458 *buf = 0;
459 bus_space_write_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_PSR, 0x2000000);
460
461 /* reset SSP */
462 bus_space_write_4(sc->sc_iot, sc->sc_ssph, SASSP_CR0, 0x307);
463 delay(100);
464 bus_space_write_4(sc->sc_iot, sc->sc_ssph, SASSP_CR0, 0x387);
465 printf("j720kbd_read: error %x\n", data);
466 }
467
468 void
469 j720tpsoft(void *arg)
470 {
471 struct j720ssp_softc *sc = arg;
472 int buf[8], data, i, x, y;
473
474 bus_space_write_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_PCR, 0x2000000);
475
476 /* send read touchpanel command */
477 if (j720ssp_readwrite(sc, 1, 0x500, &data) < 0 ||
478 data != 0x88)
479 goto out;
480
481 for(i = 0; i < 8; i++) {
482 if (j720ssp_readwrite(sc, 0, 0x8800, &data) < 0)
483 goto out;
484 BIT_INVERT(data);
485 buf[i] = data;
486 }
487
488 bus_space_write_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_PSR, 0x2000000);
489
490 buf[6] <<= 8;
491 buf[7] <<= 8;
492 for(i = 0; i < 3; i++) {
493 buf[i] |= buf[6] & 0x300;
494 buf[6] >>= 2;
495 buf[i + 3] |= buf[7] & 0x300;
496 buf[7] >>= 2;
497 }
498 #if 0
499 printf("j720tpsoft: %d %d %d %d %d %d\n", buf[0], buf[1], buf[2],
500 buf[3], buf[4], buf[5]);
501 #endif
502
503 /* XXX buf[1], buf[2], ... should also be used */
504 tpcalib_trans(&sc->sc_tpcalib, buf[1], buf[4], &x, &y);
505 wsmouse_input(sc->sc_wsmousedev, 1, x, y, 0,
506 WSMOUSE_INPUT_ABSOLUTE_X | WSMOUSE_INPUT_ABSOLUTE_Y);
507
508 callout_reset(&sc->sc_tptimeout, hz / 10, j720tp_timeout, sc);
509
510 return;
511
512 out:
513 *buf = 0;
514 bus_space_write_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_PSR, 0x2000000);
515
516 /* reset SSP */
517 bus_space_write_4(sc->sc_iot, sc->sc_ssph, SASSP_CR0, 0x307);
518 delay(100);
519 bus_space_write_4(sc->sc_iot, sc->sc_ssph, SASSP_CR0, 0x387);
520 printf("j720tpsoft: error %x\n", data);
521 }
522
523 void
524 j720tp_timeout(void *arg)
525 {
526 struct j720ssp_softc *sc = arg;
527
528 #if 0
529 /* XXX I don't this this is necessary (untested) */
530 if (bus_space_read_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_PLR) &
531 (1 << 9)) {
532 /* Touchpad is still pressed */
533 callout_reset(&sc->sc_tptimeout, hz / 10, j720tp_timeout, sc);
534 return;
535 }
536 #endif
537
538 wsmouse_input(sc->sc_wsmousedev, 0, 0, 0, 0, 0);
539 }
540
541 static int
542 j720tp_enable(void *arg) {
543 struct j720ssp_softc *sc = arg;
544 int er, s;
545
546 s = splhigh();
547 er = bus_space_read_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_FER);
548 er |= 1 << 9;
549 bus_space_write_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_FER, er);
550 splx(s);
551
552 return (0);
553 }
554
555 static void
556 j720tp_disable(void *arg) {
557 struct j720ssp_softc *sc = arg;
558 int er, s;
559
560 s = splhigh();
561 er = bus_space_read_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_FER);
562 er &= ~(1 << 9);
563 bus_space_write_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_FER, er);
564 splx(s);
565 }
566
567 static int
568 j720tp_ioctl(void *arg, u_long cmd, caddr_t data, int flag, struct proc *p) {
569 struct j720ssp_softc *sc = arg;
570
571 switch (cmd) {
572 case WSMOUSEIO_GTYPE:
573 *(u_int *)data = WSMOUSE_TYPE_TPANEL;
574 return (0);
575
576 case WSMOUSEIO_SCALIBCOORDS:
577 case WSMOUSEIO_GCALIBCOORDS:
578 return tpcalib_ioctl(&sc->sc_tpcalib, cmd, data, flag, p);
579
580 default:
581 return (EPASSTHROUGH);
582 }
583 }
584
585 int
586 j720lcdparam(void *ctx, int type, long id, void *msg)
587 {
588 struct j720ssp_softc *sc = ctx;
589 int i, s;
590 u_int32_t data[2], len;
591
592 switch (type) {
593 case CONFIG_HOOK_GET:
594 switch (id) {
595 case CONFIG_HOOK_BRIGHTNESS_MAX:
596 case CONFIG_HOOK_CONTRAST_MAX:
597 *(int *)msg = 255;
598 return 1;
599 case CONFIG_HOOK_BRIGHTNESS:
600 data[0] = 0x6b00;
601 data[1] = 0x8800;
602 len = 2;
603 break;
604 case CONFIG_HOOK_CONTRAST:
605 data[0] = 0x2b00;
606 data[1] = 0x8800;
607 len = 2;
608 break;
609 default:
610 return 0;
611 }
612 break;
613
614 case CONFIG_HOOK_SET:
615 switch (id) {
616 case CONFIG_HOOK_BRIGHTNESS:
617 if (*(int *)msg >= 0) {
618 data[0] = 0xcb00;
619 data[1] = *(int *)msg;
620 BIT_INVERT(data[1]);
621 data[1] <<= 8;
622 len = 2;
623 } else {
624 /* XXX hack */
625 data[0] = 0xfb00;
626 len = 1;
627 }
628 break;
629 case CONFIG_HOOK_CONTRAST:
630 data[0] = 0x8b00;
631 data[1] = *(int *)msg;
632 BIT_INVERT(data[1]);
633 data[1] <<= 8;
634 len = 2;
635 break;
636 default:
637 return 0;
638 }
639 }
640
641 s = splbio();
642 bus_space_write_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_PCR, 0x2000000);
643
644 for (i = 0; i < len; i++) {
645 if (j720ssp_readwrite(sc, 1, data[i], &data[i]) < 0)
646 goto out;
647 }
648 bus_space_write_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_PSR, 0x2000000);
649 splx(s);
650
651 if (type == CONFIG_HOOK_SET)
652 return 1;
653
654 BIT_INVERT(data[1]);
655 *(int *)msg = data[1];
656
657 return 1;
658
659 out:
660 bus_space_write_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_PSR, 0x2000000);
661
662 /* reset SSP */
663 bus_space_write_4(sc->sc_iot, sc->sc_ssph, SASSP_CR0, 0x307);
664 delay(100);
665 bus_space_write_4(sc->sc_iot, sc->sc_ssph, SASSP_CR0, 0x387);
666 splx(s);
667 return 0;
668 }
669
670 static int
671 j720ssp_readwrite(struct j720ssp_softc *sc, int drainfifo, int in, int *out)
672 {
673 int timo;
674
675 timo = 100000;
676 while(bus_space_read_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_PLR) & 0x400)
677 if (--timo == 0) {
678 printf("timo0\n");
679 return -1;
680 }
681 if (drainfifo) {
682 while(bus_space_read_4(sc->sc_iot, sc->sc_ssph, SASSP_SR) &
683 SR_RNE)
684 bus_space_read_4(sc->sc_iot, sc->sc_ssph, SASSP_DR);
685 #if 1
686 delay(5000);
687 #endif
688 }
689
690 bus_space_write_4(sc->sc_iot, sc->sc_ssph, SASSP_DR, in);
691
692 delay(5000);
693 timo = 100000;
694 while(! (bus_space_read_4(sc->sc_iot, sc->sc_ssph, SASSP_SR) & SR_RNE))
695 if (--timo == 0) {
696 printf("timo1\n");
697 return -1;
698 }
699
700 *out = bus_space_read_4(sc->sc_iot, sc->sc_ssph, SASSP_DR);
701
702 return 0;
703 }
704
705 #if 0
706 int
707 j720kbd_cnattach()
708 {
709 /* XXX defer initialization till j720sspattach */
710
711 return (0);
712 }
713 #endif
714
715 /* ARGSUSED */
716 void
717 j720kbd_cngetc(void *v, u_int *type, int *data)
718 {
719 char buf[9];
720
721 if (j720kbdcons_initstate < 1)
722 return;
723
724 for (;;) {
725 j720kbd_read(&j720kbdcons_sc, buf);
726
727 if (buf[0] != 0) {
728 /* XXX we are discarding buffer contents */
729 *type = buf[0] & 0x80 ? WSCONS_EVENT_KEY_UP :
730 WSCONS_EVENT_KEY_DOWN;
731 *data = buf[0] & 0x7f;
732 return;
733 }
734 }
735 }
736
737 void
738 j720kbd_cnpollc(void *v, int on)
739 {
740 #if 0
741 /* XXX */
742 struct j720kbd_internal *t = v;
743
744 pckbc_set_poll(t->t_kbctag, t->t_kbcslot, on);
745 #endif
746 }
747
748 void
749 j720kbd_cnbell(void *v, u_int pitch, u_int period, u_int volume)
750 {
751 }
752
753 int
754 j720lcdpower(void *ctx, int type, long id, void *msg)
755 {
756 struct sed1356_softc *sc = ctx;
757 struct sa11x0_softc *psc = sc->sc_parent;
758 int val;
759 u_int32_t reg;
760
761 if (type != CONFIG_HOOK_POWERCONTROL ||
762 id != CONFIG_HOOK_POWERCONTROL_LCDLIGHT)
763 return 0;
764
765 sed1356_init_brightness(sc, 0);
766 sed1356_init_contrast(sc, 0);
767
768 if (msg) {
769 bus_space_write_1(sc->sc_iot, sc->sc_regh, 0x1f0, 0);
770
771 reg = bus_space_read_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR);
772 reg |= 0x1;
773 bus_space_write_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR, reg);
774 delay(50000);
775
776 val = sc->sc_contrast;
777 config_hook_call(CONFIG_HOOK_SET, CONFIG_HOOK_CONTRAST, &val);
778 delay(100000);
779
780 reg = bus_space_read_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR);
781 reg |= 0x4;
782 bus_space_write_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR, reg);
783
784 val = sc->sc_brightness;
785 config_hook_call(CONFIG_HOOK_SET, CONFIG_HOOK_BRIGHTNESS, &val);
786
787 reg = bus_space_read_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR);
788 reg |= 0x2;
789 bus_space_write_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR, reg);
790 } else {
791 reg = bus_space_read_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR);
792 reg &= ~0x2;
793 bus_space_write_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR, reg);
794 reg &= ~0x4;
795 bus_space_write_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR, reg);
796 delay(100000);
797
798 val = -2;
799 config_hook_call(CONFIG_HOOK_SET, CONFIG_HOOK_BRIGHTNESS, &val);
800
801 bus_space_write_1(sc->sc_iot, sc->sc_regh, 0x1f0, 1);
802
803 delay(100000);
804 reg = bus_space_read_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR);
805 reg &= ~0x1;
806 bus_space_write_4(psc->sc_iot, psc->sc_ppch, SAPPC_PSR, reg);
807 }
808 return 1;
809 }
810