ite8181.c revision 1.10 1 /* $NetBSD: ite8181.c,v 1.10 2001/03/12 08:54:26 sato Exp $ */
2
3 /*-
4 * Copyright (c) 2000,2001 SATO Kazumi
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 *
28 */
29
30 #include <sys/param.h>
31 #include <sys/kernel.h>
32 #include <sys/device.h>
33 #include <sys/systm.h>
34 #include <sys/boot_flag.h>
35 #include <sys/buf.h>
36
37 #include <uvm/uvm_extern.h>
38
39 #include <dev/wscons/wsconsio.h>
40
41 #include <machine/bootinfo.h>
42 #include <machine/bus.h>
43 #include <machine/autoconf.h>
44 #include <machine/config_hook.h>
45 #include <machine/platid.h>
46 #include <machine/platid_mask.h>
47
48 #include <hpcmips/dev/ite8181reg.h>
49 #include <hpcmips/dev/ite8181var.h>
50 #include "bivideo.h"
51 #if NBIVIDEO > 0
52 #include <dev/hpc/bivideovar.h>
53 #endif
54 #include <dev/hpc/hpccmapvar.h>
55
56 #define ITE8181DEBUG
57 #ifdef ITE8181DEBUG
58 #ifndef ITE8181DEBUG_CONF
59 #define ITE8181DEBUG_CONF 0
60 #endif
61 int ite8181_debug = ITE8181DEBUG_CONF;
62 #define DPRINTF(arg) if (ite8181_debug) printf arg
63 #define DPRINTFN(n, arg) if (ite8181_debug > (n)) printf arg
64 #define VPRINTF(arg) if (bootverbose || ite8181_debug) printf arg
65 #define VPRINTFN(n, arg) if (bootverbose || ite8181_debug > (n)) printf arg
66 #else
67 #define DPRINTF(arg)
68 #define DPRINTFN(n, arg)
69 #define VPRINTF(arg) if (bootverbose) printf arg
70 #define VPRINTFN(n, arg) if (bootverbose) printf arg
71 #endif
72
73 #ifndef ITE8181_LCD_CONTROL_ENABLE
74 int ite8181_lcd_control_disable = 1;
75 #else /* ITE8181_LCD_CONTROL_ENABLE */
76 int ite8181_lcd_control_disable = 0;
77 #endif /* ITE8181_LCD_CONTROL_ENABLE */
78
79 #define ITE8181_WINCE_CMAP
80
81 /*
82 * XXX:
83 * IBM WorkPad z50 power unit has too weak power.
84 * So we must wait too many times to access some device
85 * after LCD panel and BackLight on.
86 * Currently delay is not enough ??? FIXME
87 */
88 #ifndef ITE8181_LCD_ON_SELF_DELAY
89 #define ITE8181_LCD_ON_SELF_DELAY 1000
90 #endif /* ITE8181_LCD_ON__SELF_DELAY */
91 #ifndef ITE8181_LCD_ON_DELAY
92 #define ITE8181_LCD_ON_DELAY 2000
93 #endif /* ITE8181_LCD_ON_DELAY */
94 int ite8181_lcd_on_self_delay = ITE8181_LCD_ON_SELF_DELAY; /* msec */
95 int ite8181_lcd_on_delay = ITE8181_LCD_ON_DELAY; /* msec */
96
97 #define MSEC 1000
98 /*
99 * function prototypes
100 */
101 static void ite8181_config_write_4 __P((bus_space_tag_t, bus_space_handle_t, int, int));
102 static int ite8181_config_read_4 __P((bus_space_tag_t, bus_space_handle_t, int));
103
104 static void ite8181_gui_write_4 __P((struct ite8181_softc *, int, int));
105 static int ite8181_gui_read_4 __P((struct ite8181_softc *, int));
106
107 static void ite8181_gui_write_1 __P((struct ite8181_softc *, int, int));
108 static int ite8181_gui_read_1 __P((struct ite8181_softc *, int));
109
110 static void ite8181_graphics_write_1 __P((struct ite8181_softc *, int, int));
111 static int ite8181_graphics_read_1 __P((struct ite8181_softc *, int));
112
113 static void ite8181_ema_write_1 __P((struct ite8181_softc *, int, int));
114 static int ite8181_ema_read_1 __P((struct ite8181_softc *, int));
115
116 static void ite8181_power __P((int, void *));
117 static int ite8181_hardpower __P((void *, int, long, void *));
118 static int ite8181_fbinit __P((struct hpcfb_fbconf *));
119 static int ite8181_ioctl __P((void *, u_long, caddr_t, int, struct proc *));
120 static paddr_t ite8181_mmap __P((void *, off_t offset, int));
121 static void ite8181_erase_cursor __P((struct ite8181_softc *));
122 static int ite8181_lcd_power __P((struct ite8181_softc *, int));
123
124 static void ite8181_update_powerstate __P((struct ite8181_softc *, int));
125 void ite8181_get_backlight __P((struct ite8181_softc *));
126 void ite8181_init_brightness __P((struct ite8181_softc *));
127 void ite8181_init_contrast __P((struct ite8181_softc *));
128 void ite8181_set_brightness __P((struct ite8181_softc *, int));
129 void ite8181_set_contrast __P((struct ite8181_softc *, int));
130
131 /*
132 * static variables
133 */
134 struct hpcfb_accessops ite8181_ha = {
135 ite8181_ioctl, ite8181_mmap
136 };
137
138 inline int
139 ite8181_config_read_4(iot, ioh, byteoffset)
140 bus_space_tag_t iot;
141 bus_space_handle_t ioh;
142 int byteoffset;
143 {
144 return bus_space_read_4(iot, ioh, ITE8181_CONF_OFFSET + byteoffset);
145 }
146
147 inline void
148 ite8181_config_write_4(iot, ioh, byteoffset, data)
149 bus_space_tag_t iot;
150 bus_space_handle_t ioh;
151 int byteoffset;
152 int data;
153 {
154 bus_space_write_4(iot, ioh, ITE8181_CONF_OFFSET + byteoffset, data);
155 }
156
157 inline int
158 ite8181_gui_read_4(sc, byteoffset)
159 struct ite8181_softc *sc;
160 int byteoffset;
161 {
162 return bus_space_read_4(sc->sc_iot, sc->sc_ioh,
163 sc->sc_gba + byteoffset);
164 }
165
166 inline void
167 ite8181_gui_write_4(sc, byteoffset, data)
168 struct ite8181_softc *sc;
169 int byteoffset;
170 int data;
171 {
172 bus_space_write_4(sc->sc_iot, sc->sc_ioh, sc->sc_gba + byteoffset, data);
173 }
174
175 inline int
176 ite8181_gui_read_1(sc, byteoffset)
177 struct ite8181_softc *sc;
178 int byteoffset;
179 {
180 return bus_space_read_1(sc->sc_iot, sc->sc_ioh,
181 sc->sc_gba + byteoffset);
182 }
183
184 inline void
185 ite8181_gui_write_1(sc, byteoffset, data)
186 struct ite8181_softc *sc;
187 int byteoffset;
188 int data;
189 {
190 bus_space_write_1(sc->sc_iot, sc->sc_ioh, sc->sc_gba + byteoffset, data);
191 }
192
193 inline int
194 ite8181_graphics_read_1(sc, byteoffset)
195 struct ite8181_softc *sc;
196 int byteoffset;
197 {
198 return bus_space_read_1(sc->sc_iot, sc->sc_ioh,
199 sc->sc_sba + byteoffset);
200 }
201
202 inline void
203 ite8181_graphics_write_1(sc, byteoffset, data)
204 struct ite8181_softc *sc;
205 int byteoffset;
206 int data;
207 {
208 bus_space_write_1(sc->sc_iot, sc->sc_ioh, sc->sc_sba + byteoffset, data);
209 }
210
211 inline int
212 ite8181_ema_read_1(sc, byteoffset)
213 struct ite8181_softc *sc;
214 int byteoffset;
215 {
216 ite8181_graphics_write_1(sc, ITE8181_EMA_EXAX, byteoffset);
217 return ite8181_graphics_read_1(sc, ITE8181_EMA_EXADATA);
218 }
219
220 inline void
221 ite8181_ema_write_1(sc, byteoffset, data)
222 struct ite8181_softc *sc;
223 int byteoffset;
224 int data;
225 {
226 ite8181_graphics_write_1(sc, ITE8181_EMA_EXAX, byteoffset);
227 ite8181_graphics_write_1(sc, ITE8181_EMA_EXADATA, data);
228 }
229
230 int
231 ite8181_probe(iot, ioh)
232 bus_space_tag_t iot;
233 bus_space_handle_t ioh;
234 {
235 unsigned long regval;
236
237 #if NBIVIDEO > 0
238 if (bivideo_dont_attach) /* some video driver already attached */
239 return (0);
240 #endif /* NBIVIDEO > 0 */
241
242 regval = ite8181_config_read_4(iot, ioh, ITE8181_ID);
243 VPRINTF(("ite8181_probe: vendor id=%04lx product id=%04lx\n",
244 regval & 0xffff, (regval >> 16) & 0xffff));
245 if (regval != ((ITE8181_PRODUCT_ID << 16) | ITE8181_VENDER_ID))
246 return (0);
247
248 return (1);
249 }
250
251 void
252 ite8181_attach(sc)
253 struct ite8181_softc *sc;
254 {
255 unsigned long regval;
256 struct hpcfb_attach_args ha;
257 int console = (bootinfo->bi_cnuse & BI_CNUSE_SERIAL) ? 0 : 1;
258
259 printf(": ");
260 if (ite8181_fbinit(&sc->sc_fbconf) != 0) {
261 /* just return so that hpcfb will not be attached */
262 return;
263 }
264
265 regval = ite8181_config_read_4(sc->sc_iot, sc->sc_ioh, ITE8181_CLASS);
266 printf("ITE8181 Rev.%02lx", regval & ITE8181_REV_MASK);
267 if (console) {
268 printf(", console");
269 }
270 printf("\n");
271 printf("%s: framebuffer address: 0x%08lx\n",
272 sc->sc_dev.dv_xname, (u_long)bootinfo->fb_addr);
273 if (ite8181_lcd_control_disable)
274 printf("%s: ite8181 lcd coontrol is DISABLED.\n",
275 sc->sc_dev.dv_xname);
276
277 /* set base offsets */
278 sc->sc_mba = ite8181_config_read_4(sc->sc_iot, sc->sc_ioh, ITE8181_MBA);
279 DPRINTFN(1, ("ite8181: Memory base offset %08x\n", sc->sc_mba));
280 sc->sc_gba = ite8181_config_read_4(sc->sc_iot, sc->sc_ioh, ITE8181_GBA);
281 DPRINTFN(1, ("ite8181: GUI base offset %08x\n", sc->sc_gba));
282 sc->sc_sba = ite8181_config_read_4(sc->sc_iot, sc->sc_ioh, ITE8181_SBA);
283 DPRINTFN(1, ("ite8181: Graphics base offset %08x\n", sc->sc_sba));
284
285 /* assume lcd is on */
286 sc->sc_lcd = 1;
287
288 /* Add a power hook to power saving */
289 sc->sc_powerhook = powerhook_establish(ite8181_power, sc);
290 if (sc->sc_powerhook == NULL)
291 printf("%s: WARNING: unable to establish power hook\n",
292 sc->sc_dev.dv_xname);
293
294 /* Add a hard power hook to power saving */
295 sc->sc_hardpowerhook = config_hook(CONFIG_HOOK_PMEVENT,
296 CONFIG_HOOK_PMEVENT_HARDPOWER,
297 CONFIG_HOOK_SHARE,
298 ite8181_hardpower, sc);
299 if (sc->sc_hardpowerhook == NULL)
300 printf("%s: WARNING: unable to establish hard power hook\n",
301 sc->sc_dev.dv_xname);
302
303 ite8181_erase_cursor(sc);
304
305 /* initialize backlight brightness and lcd contrast */
306 sc->sc_brightness = sc->sc_contrast =
307 sc->sc_max_brightness = sc->sc_max_contrast = -1;
308 ite8181_get_backlight(sc);
309 ite8181_init_brightness(sc);
310 ite8181_init_contrast(sc);
311
312 if (console && hpcfb_cnattach(&sc->sc_fbconf) != 0) {
313 panic("ite8181_attach: can't init fb console");
314 }
315
316 ha.ha_console = console;
317 ha.ha_accessops = &ite8181_ha;
318 ha.ha_accessctx = sc;
319 ha.ha_curfbconf = 0;
320 ha.ha_nfbconf = 1;
321 ha.ha_fbconflist = &sc->sc_fbconf;
322 ha.ha_curdspconf = 0;
323 ha.ha_ndspconf = 1;
324 ha.ha_dspconflist = &sc->sc_dspconf;
325
326 config_found(&sc->sc_dev, &ha, hpcfbprint);
327
328 #if NBIVIDEO > 0
329 /*
330 * bivideo is no longer need
331 */
332 bivideo_dont_attach = 1;
333 #endif /* NBIVIDEO > 0 */
334 }
335
336 int ite8181_lcd_power(sc, on)
337 struct ite8181_softc *sc;
338 int on;
339 {
340 int lcd_p;
341 int lcd_s;
342 int lcd_seq;
343 int loop = 10;
344
345 if (ite8181_lcd_control_disable) {
346 VPRINTF(("ite8171_lcd_control_disable!: %s\n", on?"on":"off"));
347 return 0;
348 }
349
350 if (sc->sc_lcd != on) {
351 ite8181_ema_write_1(sc, ITE8181_EMA_ENABLEEMA,
352 ITE8181_EMA_ENABLEPASS);
353 lcd_p = ite8181_ema_read_1(sc, ITE8181_EMA_LCDPOWER);
354 lcd_s = ite8181_ema_read_1(sc, ITE8181_EMA_LCDPOWERSTAT);
355 lcd_seq = ite8181_ema_read_1(sc, ITE8181_EMA_LCDPOWERSEQ);
356 DPRINTFN(1,("ite8181_lcd_power(%d)< p=%x, s=%x, seq=%x\n",
357 on,
358 lcd_p, lcd_s, lcd_seq));
359 if (on) {
360 sc->sc_lcd = 1;
361 lcd_seq |= (ITE8181_PUP0|ITE8181_PUP1|ITE8181_PUP2);
362 ite8181_ema_write_1(sc, ITE8181_EMA_LCDPOWERSEQ, lcd_seq);
363 lcd_p &= ~ITE8181_LCDSTANDBY;
364 ite8181_ema_write_1(sc, ITE8181_EMA_LCDPOWER, lcd_p);
365 /*
366 * XXX:
367 * IBM WorkPad z50 power unit has too weak power.
368 * So we must wait too many times to access self device
369 * after LCD panel and BackLight on.
370 * Currently delay is not enough ??? FIXME
371 */
372 delay(ite8181_lcd_on_self_delay*MSEC);
373 while (loop--) {
374 lcd_p = ite8181_ema_read_1(sc, ITE8181_EMA_LCDPOWER);
375 lcd_s = ite8181_ema_read_1(sc, ITE8181_EMA_LCDPOWERSTAT);
376 lcd_seq = ite8181_ema_read_1(sc, ITE8181_EMA_LCDPOWERSEQ);
377 DPRINTFN(1,("ite8181_lcd_power(%d)%d| p=%x, s=%x, seq=%x\n",
378 on, loop,
379 lcd_p, lcd_s, lcd_seq));
380 /* XXX the states which are not described in manual.*/
381 if (!(lcd_s&ITE8181_LCDPSTANDBY) &&
382 !(lcd_s&ITE8181_LCDPUP) &&
383 (lcd_s&ITE8181_LCDPON))
384 break;
385 delay(100);
386 }
387 lcd_s |= ITE8181_PPTOBEON;
388 ite8181_ema_write_1(sc, ITE8181_EMA_LCDPOWERSTAT, lcd_s);
389 } else {
390 sc->sc_lcd = 0;
391 lcd_p |= ITE8181_LCDSTANDBY;
392 ite8181_ema_write_1(sc, ITE8181_EMA_LCDPOWER, lcd_p);
393 while (loop--) {
394 lcd_p = ite8181_ema_read_1(sc, ITE8181_EMA_LCDPOWER);
395 lcd_s = ite8181_ema_read_1(sc, ITE8181_EMA_LCDPOWERSTAT);
396 lcd_seq = ite8181_ema_read_1(sc, ITE8181_EMA_LCDPOWERSEQ);
397 DPRINTFN(1,("ite8181_lcd_power(%d)%d| p=%x, s=%x, seq=%x\n",
398 on, loop,
399 lcd_p, lcd_s, lcd_seq));
400 /* XXX the states which are not described in manual.*/
401 if ((lcd_s&ITE8181_LCDPSTANDBY) &&
402 !(lcd_s&ITE8181_LCDPDOWN) &&
403 !(lcd_s&ITE8181_LCDPON))
404 break;
405 delay(100);
406 }
407 lcd_s &= ~ITE8181_PPTOBEON;
408 ite8181_ema_write_1(sc, ITE8181_EMA_LCDPOWERSTAT, lcd_s);
409 }
410 DPRINTFN(1,("ite8181_lcd_power(%d)> p=%x, s=%x, seq=%x\n",
411 on,
412 ite8181_ema_read_1(sc, ITE8181_EMA_LCDPOWER),
413 ite8181_ema_read_1(sc, ITE8181_EMA_LCDPOWERSTAT),
414 ite8181_ema_read_1(sc, ITE8181_EMA_LCDPOWERSEQ)));
415 ite8181_ema_write_1(sc, ITE8181_EMA_ENABLEEMA,
416 ITE8181_EMA_DISABLEPASS);
417 }
418 return 0;
419 }
420
421 static void
422 ite8181_erase_cursor(sc)
423 struct ite8181_softc *sc;
424 {
425 ite8181_gui_write_1(sc, ITE8181_GUI_C1C, 0); /* Cursor 1 Control Reg. */
426 /* other ? */
427 }
428
429 static void
430 ite8181_update_powerstate(sc, updates)
431 struct ite8181_softc *sc;
432 int updates;
433 {
434 if (updates & PWRSTAT_LCD)
435 config_hook_call(CONFIG_HOOK_POWERCONTROL,
436 CONFIG_HOOK_POWERCONTROL_LCD,
437 (void*)!(sc->sc_powerstate &
438 (PWRSTAT_VIDEOOFF|PWRSTAT_SUSPEND)));
439
440 if (updates & PWRSTAT_BACKLIGHT)
441 config_hook_call(CONFIG_HOOK_POWERCONTROL,
442 CONFIG_HOOK_POWERCONTROL_LCDLIGHT,
443 (void*)(!(sc->sc_powerstate &
444 (PWRSTAT_VIDEOOFF|PWRSTAT_SUSPEND)) &&
445 (sc->sc_powerstate & PWRSTAT_BACKLIGHT)));
446 }
447
448 static void
449 ite8181_power(why, arg)
450 int why;
451 void *arg;
452 {
453 struct ite8181_softc *sc = arg;
454
455 switch (why) {
456 case PWR_STANDBY:
457 sc->sc_powerstate |= PWRSTAT_SUSPEND;
458 ite8181_update_powerstate(sc, PWRSTAT_ALL);
459 break;
460 case PWR_SUSPEND:
461 sc->sc_powerstate |= PWRSTAT_SUSPEND;
462 ite8181_update_powerstate(sc, PWRSTAT_ALL);
463 break;
464 case PWR_RESUME:
465 sc->sc_powerstate &= ~PWRSTAT_SUSPEND;
466 ite8181_update_powerstate(sc, PWRSTAT_ALL);
467 break;
468 }
469 }
470
471 static int
472 ite8181_hardpower(ctx, type, id, msg)
473 void *ctx;
474 int type;
475 long id;
476 void *msg;
477 {
478 struct ite8181_softc *sc = ctx;
479 int why = (int)msg;
480
481 switch (why) {
482 case PWR_STANDBY:
483 /* ite8181_lcd_power(sc, 0); */
484 delay(MSEC);
485 break;
486 case PWR_SUSPEND:
487 ite8181_lcd_power(sc, 0);
488 delay(MSEC);
489 break;
490 case PWR_RESUME:
491 delay(MSEC);
492 ite8181_lcd_power(sc, 1);
493 /*
494 * XXX:
495 * IBM WorkPad z50 power unit has too weak power.
496 * So we must wait too many times to access other devices
497 * after LCD panel and BackLight on.
498 */
499 delay(ite8181_lcd_on_delay*MSEC);
500 break;
501 }
502
503 /*
504 * you should wait until the
505 * power state transit sequence will end.
506 */
507
508 return (0);
509 }
510
511 static int
512 ite8181_fbinit(fb)
513 struct hpcfb_fbconf *fb;
514 {
515
516 /*
517 * get fb settings from bootinfo
518 */
519 if (bootinfo == NULL ||
520 bootinfo->fb_addr == 0 ||
521 bootinfo->fb_line_bytes == 0 ||
522 bootinfo->fb_width == 0 ||
523 bootinfo->fb_height == 0) {
524 printf("no frame buffer infomation.\n");
525 return (-1);
526 }
527
528 /* zero fill */
529 bzero(fb, sizeof(*fb));
530
531 fb->hf_conf_index = 0; /* configuration index */
532 fb->hf_nconfs = 1; /* how many configurations */
533 strcpy(fb->hf_name, "built-in video");
534 /* frame buffer name */
535 strcpy(fb->hf_conf_name, "default");
536 /* configuration name */
537 fb->hf_height = bootinfo->fb_height;
538 fb->hf_width = bootinfo->fb_width;
539 fb->hf_baseaddr = (u_long)bootinfo->fb_addr;
540 fb->hf_offset = (u_long)bootinfo->fb_addr -
541 mips_ptob(mips_btop(bootinfo->fb_addr));
542 /* frame buffer start offset */
543 fb->hf_bytes_per_line = bootinfo->fb_line_bytes;
544 fb->hf_nplanes = 1;
545 fb->hf_bytes_per_plane = bootinfo->fb_height *
546 bootinfo->fb_line_bytes;
547
548 fb->hf_access_flags |= HPCFB_ACCESS_BYTE;
549 fb->hf_access_flags |= HPCFB_ACCESS_WORD;
550 fb->hf_access_flags |= HPCFB_ACCESS_DWORD;
551
552 switch (bootinfo->fb_type) {
553 /*
554 * gray scale
555 */
556 case BIFB_D2_M2L_3:
557 case BIFB_D2_M2L_3x2:
558 fb->hf_access_flags |= HPCFB_ACCESS_REVERSE;
559 /* fall through */
560 case BIFB_D2_M2L_0:
561 case BIFB_D2_M2L_0x2:
562 fb->hf_class = HPCFB_CLASS_GRAYSCALE;
563 fb->hf_access_flags |= HPCFB_ACCESS_STATIC;
564 fb->hf_pack_width = 8;
565 fb->hf_pixels_per_pack = 4;
566 fb->hf_pixel_width = 2;
567 fb->hf_class_data_length = sizeof(struct hf_gray_tag);
568 fb->hf_u.hf_gray.hf_flags = 0; /* reserved for future use */
569 break;
570
571 case BIFB_D4_M2L_F:
572 case BIFB_D4_M2L_Fx2:
573 fb->hf_access_flags |= HPCFB_ACCESS_REVERSE;
574 /* fall through */
575 case BIFB_D4_M2L_0:
576 case BIFB_D4_M2L_0x2:
577 fb->hf_class = HPCFB_CLASS_GRAYSCALE;
578 fb->hf_access_flags |= HPCFB_ACCESS_STATIC;
579 fb->hf_pack_width = 8;
580 fb->hf_pixels_per_pack = 2;
581 fb->hf_pixel_width = 4;
582 fb->hf_class_data_length = sizeof(struct hf_gray_tag);
583 fb->hf_u.hf_gray.hf_flags = 0; /* reserved for future use */
584 break;
585
586 /*
587 * indexed color
588 */
589 case BIFB_D8_FF:
590 fb->hf_access_flags |= HPCFB_ACCESS_REVERSE;
591 /* fall through */
592 case BIFB_D8_00:
593 fb->hf_class = HPCFB_CLASS_INDEXCOLOR;
594 fb->hf_access_flags |= HPCFB_ACCESS_STATIC;
595 fb->hf_pack_width = 8;
596 fb->hf_pixels_per_pack = 1;
597 fb->hf_pixel_width = 8;
598 fb->hf_class_data_length = sizeof(struct hf_indexed_tag);
599 fb->hf_u.hf_indexed.hf_flags = 0; /* reserved for future use */
600 break;
601
602 /*
603 * RGB color
604 */
605 case BIFB_D16_FFFF:
606 fb->hf_access_flags |= HPCFB_ACCESS_REVERSE;
607 /* fall through */
608 case BIFB_D16_0000:
609 fb->hf_class = HPCFB_CLASS_RGBCOLOR;
610 fb->hf_access_flags |= HPCFB_ACCESS_STATIC;
611 #if BYTE_ORDER == LITTLE_ENDIAN
612 fb->hf_swap_flags = HPCFB_SWAP_BYTE;
613 #endif
614 fb->hf_pack_width = 16;
615 fb->hf_pixels_per_pack = 1;
616 fb->hf_pixel_width = 16;
617
618 fb->hf_class_data_length = sizeof(struct hf_rgb_tag);
619 fb->hf_u.hf_rgb.hf_flags = 0; /* reserved for future use */
620
621 fb->hf_u.hf_rgb.hf_red_width = 5;
622 fb->hf_u.hf_rgb.hf_red_shift = 11;
623 fb->hf_u.hf_rgb.hf_green_width = 6;
624 fb->hf_u.hf_rgb.hf_green_shift = 5;
625 fb->hf_u.hf_rgb.hf_blue_width = 5;
626 fb->hf_u.hf_rgb.hf_blue_shift = 0;
627 fb->hf_u.hf_rgb.hf_alpha_width = 0;
628 fb->hf_u.hf_rgb.hf_alpha_shift = 0;
629 break;
630
631 default:
632 printf("unknown type (=%d).\n", bootinfo->fb_type);
633 return (-1);
634 break;
635 }
636
637 return (0); /* no error */
638 }
639
640 int
641 ite8181_ioctl(v, cmd, data, flag, p)
642 void *v;
643 u_long cmd;
644 caddr_t data;
645 int flag;
646 struct proc *p;
647 {
648 struct ite8181_softc *sc = (struct ite8181_softc *)v;
649 struct hpcfb_fbconf *fbconf;
650 struct hpcfb_dspconf *dspconf;
651 struct wsdisplay_cmap *cmap;
652 struct wsdisplay_param *dispparam;
653
654 switch (cmd) {
655 case WSDISPLAYIO_GETCMAP:
656 cmap = (struct wsdisplay_cmap*)data;
657
658 if (sc->sc_fbconf.hf_class != HPCFB_CLASS_INDEXCOLOR ||
659 sc->sc_fbconf.hf_pack_width != 8 ||
660 256 <= cmap->index ||
661 256 < (cmap->index + cmap->count))
662 return (EINVAL);
663
664 if (!uvm_useracc(cmap->red, cmap->count, B_WRITE) ||
665 !uvm_useracc(cmap->green, cmap->count, B_WRITE) ||
666 !uvm_useracc(cmap->blue, cmap->count, B_WRITE))
667 return (EFAULT);
668
669 #ifdef ITE8181_WINCE_CMAP
670 copyout(&bivideo_cmap_r[cmap->index], cmap->red, cmap->count);
671 copyout(&bivideo_cmap_g[cmap->index], cmap->green,cmap->count);
672 copyout(&bivideo_cmap_b[cmap->index], cmap->blue, cmap->count);
673 return (0);
674 #else /* ITE8181_WINCE_CMAP */
675 return EINVAL;
676 #endif /* ITE8181_WINCE_CMAP */
677
678 case WSDISPLAYIO_PUTCMAP:
679 /*
680 * This driver can't set color map.
681 */
682 return (EINVAL);
683
684 case WSDISPLAYIO_SVIDEO:
685 if (*(int *)data == WSDISPLAYIO_VIDEO_OFF)
686 sc->sc_powerstate |= PWRSTAT_VIDEOOFF;
687 else
688 sc->sc_powerstate &= ~PWRSTAT_VIDEOOFF;
689 ite8181_update_powerstate(sc, PWRSTAT_ALL);
690 return 0;
691
692 case WSDISPLAYIO_GVIDEO:
693 *(int *)data = (sc->sc_powerstate&PWRSTAT_VIDEOOFF) ?
694 WSDISPLAYIO_VIDEO_OFF:WSDISPLAYIO_VIDEO_ON;
695 return 0;
696
697
698 case WSDISPLAYIO_GETPARAM:
699 dispparam = (struct wsdisplay_param*)data;
700 switch (dispparam->param) {
701 case WSDISPLAYIO_PARAM_BACKLIGHT:
702 VPRINTF(("ite8181_ioctl: GETPARAM:BACKLIGHT call\n"));
703 if (sc->sc_max_brightness == -1)
704 ite8181_init_brightness(sc);
705 ite8181_get_backlight(sc);
706 dispparam->min = 0;
707 dispparam->max = 1;
708 if (sc->sc_max_brightness > 0)
709 dispparam->curval = sc->sc_brightness > 0? 1: 0;
710 else
711 dispparam->curval =
712 (sc->sc_powerstate & PWRSTAT_BACKLIGHT) ? 1 : 0;
713 VPRINTF(("ite8181_ioctl: GETPARAM:BACKLIGHT:%d\n",
714 dispparam->curval));
715 return 0;
716 break;
717 case WSDISPLAYIO_PARAM_CONTRAST:
718 VPRINTF(("ite8181_ioctl: GETPARAM:CONTRAST call\n"));
719 if (sc->sc_max_contrast == -1)
720 ite8181_init_contrast(sc);
721 if (sc->sc_max_contrast > 0) {
722 dispparam->min = 0;
723 dispparam->max = sc->sc_max_contrast;
724 dispparam->curval = sc->sc_contrast;
725 VPRINTF(("ite8181_ioctl: GETPARAM:CONTRAST max=%d, current=%d\n", sc->sc_max_contrast, sc->sc_contrast));
726 return 0;
727 } else {
728 VPRINTF(("ite8181_ioctl: GETPARAM:CONTRAST ret\n"));
729 return (EINVAL);
730 }
731 break;
732 case WSDISPLAYIO_PARAM_BRIGHTNESS:
733 VPRINTF(("ite8181_ioctl: GETPARAM:BRIGHTNESS call\n"));
734 if (sc->sc_max_brightness == -1)
735 ite8181_init_brightness(sc);
736 if (sc->sc_max_brightness > 0) {
737 dispparam->min = 0;
738 dispparam->max = sc->sc_max_brightness;
739 dispparam->curval = sc->sc_brightness;
740 VPRINTF(("ite8181_ioctl: GETPARAM:BRIGHTNESS max=%d, current=%d\n", sc->sc_max_brightness, sc->sc_brightness));
741 return 0;
742 } else {
743 VPRINTF(("ite8181_ioctl: GETPARAM:BRIGHTNESS ret\n"));
744 return (EINVAL);
745 }
746 return (EINVAL);
747 default:
748 return (EINVAL);
749 }
750 return (0);
751
752 case WSDISPLAYIO_SETPARAM:
753 dispparam = (struct wsdisplay_param*)data;
754 switch (dispparam->param) {
755 case WSDISPLAYIO_PARAM_BACKLIGHT:
756 VPRINTF(("ite8181_ioctl: SETPARAM:BACKLIGHT call\n"));
757 if (dispparam->curval < 0 ||
758 1 < dispparam->curval)
759 return (EINVAL);
760 if (sc->sc_max_brightness == -1)
761 ite8181_init_brightness(sc);
762 VPRINTF(("ite8181_ioctl: SETPARAM:max brightness=%d\n", sc->sc_max_brightness));
763 if (sc->sc_max_brightness > 0) { /* dimmer */
764 if (dispparam->curval == 0){
765 sc->sc_brightness_save = sc->sc_brightness;
766 ite8181_set_brightness(sc, 0); /* min */
767 } else {
768 if (sc->sc_brightness_save == 0)
769 sc->sc_brightness_save = sc->sc_max_brightness;
770 ite8181_set_brightness(sc, sc->sc_brightness_save);
771 }
772 VPRINTF(("ite8181_ioctl: SETPARAM:BACKLIGHT: brightness=%d\n", sc->sc_brightness));
773 } else { /* off */
774 if (dispparam->curval == 0)
775 sc->sc_powerstate &= ~PWRSTAT_BACKLIGHT;
776 else
777 sc->sc_powerstate |= PWRSTAT_BACKLIGHT;
778 VPRINTF(("ite8181_ioctl: SETPARAM:BACKLIGHT: powerstate %d\n",
779 (sc->sc_powerstate & PWRSTAT_BACKLIGHT)?1:0));
780 ite8181_update_powerstate(sc, PWRSTAT_BACKLIGHT);
781 VPRINTF(("ite8181_ioctl: SETPARAM:BACKLIGHT:%d\n",
782 (sc->sc_powerstate & PWRSTAT_BACKLIGHT)?1:0));
783 }
784 return 0;
785 break;
786 case WSDISPLAYIO_PARAM_CONTRAST:
787 VPRINTF(("ite8181_ioctl: SETPARAM:CONTRAST call\n"));
788 if (sc->sc_max_contrast == -1)
789 ite8181_init_contrast(sc);
790 if (dispparam->curval < 0 ||
791 sc->sc_max_contrast < dispparam->curval)
792 return (EINVAL);
793 if (sc->sc_max_contrast > 0) {
794 int org = sc->sc_contrast;
795 ite8181_set_contrast(sc, dispparam->curval);
796 VPRINTF(("ite8181_ioctl: SETPARAM:CONTRAST org=%d, current=%d\n", org, sc->sc_contrast));
797 return 0;
798 } else {
799 VPRINTF(("ite8181_ioctl: SETPARAM:CONTRAST ret\n"));
800 return (EINVAL);
801 }
802 break;
803 case WSDISPLAYIO_PARAM_BRIGHTNESS:
804 VPRINTF(("ite8181_ioctl: SETPARAM:BRIGHTNESS call\n"));
805 if (sc->sc_max_brightness == -1)
806 ite8181_init_brightness(sc);
807 if (dispparam->curval < 0 ||
808 sc->sc_max_brightness < dispparam->curval)
809 return (EINVAL);
810 if (sc->sc_max_brightness > 0) {
811 int org = sc->sc_brightness;
812 ite8181_set_brightness(sc, dispparam->curval);
813 VPRINTF(("ite8181_ioctl: SETPARAM:BRIGHTNESS org=%d, current=%d\n", org, sc->sc_brightness));
814 return 0;
815 } else {
816 VPRINTF(("ite8181_ioctl: SETPARAM:BRIGHTNESS ret\n"));
817 return (EINVAL);
818 }
819 break;
820 default:
821 return (EINVAL);
822 }
823 return (0);
824
825 case HPCFBIO_GCONF:
826 fbconf = (struct hpcfb_fbconf *)data;
827 if (fbconf->hf_conf_index != 0 &&
828 fbconf->hf_conf_index != HPCFB_CURRENT_CONFIG) {
829 return (EINVAL);
830 }
831 *fbconf = sc->sc_fbconf; /* structure assignment */
832 return (0);
833 case HPCFBIO_SCONF:
834 fbconf = (struct hpcfb_fbconf *)data;
835 if (fbconf->hf_conf_index != 0 &&
836 fbconf->hf_conf_index != HPCFB_CURRENT_CONFIG) {
837 return (EINVAL);
838 }
839 /*
840 * nothing to do because we have only one configration
841 */
842 return (0);
843 case HPCFBIO_GDSPCONF:
844 dspconf = (struct hpcfb_dspconf *)data;
845 if ((dspconf->hd_unit_index != 0 &&
846 dspconf->hd_unit_index != HPCFB_CURRENT_UNIT) ||
847 (dspconf->hd_conf_index != 0 &&
848 dspconf->hd_conf_index != HPCFB_CURRENT_CONFIG)) {
849 return (EINVAL);
850 }
851 *dspconf = sc->sc_dspconf; /* structure assignment */
852 return (0);
853 case HPCFBIO_SDSPCONF:
854 dspconf = (struct hpcfb_dspconf *)data;
855 if ((dspconf->hd_unit_index != 0 &&
856 dspconf->hd_unit_index != HPCFB_CURRENT_UNIT) ||
857 (dspconf->hd_conf_index != 0 &&
858 dspconf->hd_conf_index != HPCFB_CURRENT_CONFIG)) {
859 return (EINVAL);
860 }
861 /*
862 * nothing to do
863 * because we have only one unit and one configration
864 */
865 return (0);
866 case HPCFBIO_GOP:
867 case HPCFBIO_SOP:
868 /*
869 * curently not implemented...
870 */
871 return (EINVAL);
872 }
873
874 return (ENOTTY);
875 }
876
877 paddr_t
878 ite8181_mmap(ctx, offset, prot)
879 void *ctx;
880 off_t offset;
881 int prot;
882 {
883 struct ite8181_softc *sc = (struct ite8181_softc *)ctx;
884
885 if (offset < 0 ||
886 (sc->sc_fbconf.hf_bytes_per_plane +
887 sc->sc_fbconf.hf_offset) < offset)
888 return -1;
889
890 return mips_btop((u_long)bootinfo->fb_addr + offset);
891 }
892
893 void
894 ite8181_get_backlight(sc)
895 struct ite8181_softc *sc;
896 {
897 int val = -1;
898
899 if (config_hook_call(CONFIG_HOOK_GET,
900 CONFIG_HOOK_POWER_LCDLIGHT, &val) != -1) {
901 if (val == 0)
902 sc->sc_powerstate &= ~PWRSTAT_BACKLIGHT;
903 else
904 sc->sc_powerstate |= PWRSTAT_BACKLIGHT;
905 } else /* assume backlight is on */
906 sc->sc_powerstate |= PWRSTAT_BACKLIGHT;
907 }
908
909 void
910 ite8181_init_brightness(sc)
911 struct ite8181_softc *sc;
912 {
913 int val = -1;
914
915 if (config_hook_call(CONFIG_HOOK_GET,
916 CONFIG_HOOK_BRIGHTNESS, &val) != -1) {
917 sc->sc_brightness = val;
918 }
919 val = -1;
920 if (config_hook_call(CONFIG_HOOK_GET,
921 CONFIG_HOOK_BRIGHTNESS_MAX, &val) != -1) {
922 sc->sc_brightness_save = sc->sc_max_brightness = val;
923 }
924 return;
925 }
926
927
928 void
929 ite8181_init_contrast(sc)
930 struct ite8181_softc *sc;
931 {
932 int val = -1;
933
934 if (config_hook_call(CONFIG_HOOK_GET,
935 CONFIG_HOOK_CONTRAST, &val) != -1) {
936 sc->sc_contrast = val;
937 }
938 val = -1;
939 if (config_hook_call(CONFIG_HOOK_GET,
940 CONFIG_HOOK_CONTRAST_MAX, &val) != -1) {
941 sc->sc_max_contrast = val;
942 }
943 return;
944 }
945
946 void
947 ite8181_set_brightness(sc, val)
948 struct ite8181_softc *sc;
949 int val;
950 {
951 sc->sc_brightness = val;
952
953 config_hook_call(CONFIG_HOOK_SET, CONFIG_HOOK_BRIGHTNESS, &val);
954 if (config_hook_call(CONFIG_HOOK_GET,
955 CONFIG_HOOK_BRIGHTNESS, &val) != -1) {
956 sc->sc_brightness = val;
957 }
958 }
959
960 void
961 ite8181_set_contrast(sc, val)
962 struct ite8181_softc *sc;
963 int val;
964 {
965 sc->sc_contrast = val;
966
967 config_hook_call(CONFIG_HOOK_SET, CONFIG_HOOK_CONTRAST, &val);
968 if (config_hook_call(CONFIG_HOOK_GET,
969 CONFIG_HOOK_CONTRAST, &val) != -1) {
970 sc->sc_contrast = val;
971 }
972 }
973