ite8181.c revision 1.6 1 /* $NetBSD: ite8181.c,v 1.6 2001/02/15 09:17:18 sato Exp $ */
2
3 /*-
4 * Copyright (c) 2000 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 <hpcmips/dev/bivideovar.h>
53 #endif
54 #include <hpcmips/dev/hpccmapvar.h>
55
56
57 #define ITE8181DEBUG
58 #ifdef ITE8181DEBUG
59 #ifndef ITE8181DEBUG_CONF
60 #define ITE8181DEBUG_CONF 0
61 #endif
62 int ite8181_debug = ITE8181DEBUG_CONF;
63 #define DPRINTF(arg) if (ite8181_debug) printf arg
64 #define DPRINTFN(n, arg) if (ite8181_debug > (n)) printf arg
65 #define VPRINTF(arg) if (bootverbose || ite8181_debug) printf arg
66 #define VPRINTFN(n, arg) if (bootverbose || ite8181_debug > (n)) printf arg
67 #else
68 #define DPRINTF(arg)
69 #define DPRINTFN(n, arg)
70 #define VPRINTF(arg) if (bootverbose) printf arg
71 #define VPRINTFN(n, arg) if (bootverbose) printf arg
72 #endif
73
74 #ifndef ITE8181_LCD_CONTROL_ENABLE
75 int ite8181_lcd_control_disable = 1;
76 #else /* ITE8181_LCD_CONTROL_ENABLE */
77 int ite8181_lcd_control_disable = 0;
78 #endif /* ITE8181_LCD_CONTROL_ENABLE */
79
80 #define ITE8181_WINCE_CMAP
81
82 /*
83 * XXX:
84 * IBM WorkPad z50 power unit has too weak power.
85 * So we must wait too many times to access some device
86 * after LCD panel and BackLight on.
87 * Currently delay is not enough ??? FIXME
88 */
89 #ifndef ITE8181_LCD_ON_SELF_DELAY
90 #define ITE8181_LCD_ON_SELF_DELAY 1000
91 #endif /* ITE8181_LCD_ON__SELF_DELAY */
92 #ifndef ITE8181_LCD_ON_DELAY
93 #define ITE8181_LCD_ON_DELAY 2000
94 #endif /* ITE8181_LCD_ON_DELAY */
95 int ite8181_lcd_on_self_delay = ITE8181_LCD_ON_SELF_DELAY; /* msec */
96 int ite8181_lcd_on_delay = ITE8181_LCD_ON_DELAY; /* msec */
97
98 #define MSEC 1000
99 /*
100 * function prototypes
101 */
102 static void ite8181_config_write_4 __P((bus_space_tag_t, bus_space_handle_t, int, int));
103 static int ite8181_config_read_4 __P((bus_space_tag_t, bus_space_handle_t, int));
104
105 static void ite8181_gui_write_4 __P((struct ite8181_softc *, int, int));
106 static int ite8181_gui_read_4 __P((struct ite8181_softc *, int));
107
108 static void ite8181_gui_write_1 __P((struct ite8181_softc *, int, int));
109 static int ite8181_gui_read_1 __P((struct ite8181_softc *, int));
110
111 static void ite8181_graphics_write_1 __P((struct ite8181_softc *, int, int));
112 static int ite8181_graphics_read_1 __P((struct ite8181_softc *, int));
113
114 static void ite8181_ema_write_1 __P((struct ite8181_softc *, int, int));
115 static int ite8181_ema_read_1 __P((struct ite8181_softc *, int));
116
117 static void ite8181_power __P((int, void *));
118 static int ite8181_hardpower __P((void *, int, long, void *));
119 static int ite8181_fbinit __P((struct hpcfb_fbconf *));
120 static int ite8181_ioctl __P((void *, u_long, caddr_t, int, struct proc *));
121 static paddr_t ite8181_mmap __P((void *, off_t offset, int));
122 static void ite8181_erase_cursor __P((struct ite8181_softc *));
123 static int ite8181_lcd_power __P((struct ite8181_softc *, int));
124 /*
125 * static variables
126 */
127 struct hpcfb_accessops ite8181_ha = {
128 ite8181_ioctl, ite8181_mmap
129 };
130
131 inline int
132 ite8181_config_read_4(iot, ioh, byteoffset)
133 bus_space_tag_t iot;
134 bus_space_handle_t ioh;
135 int byteoffset;
136 {
137 return bus_space_read_4(iot, ioh, ITE8181_CONF_OFFSET + byteoffset);
138 }
139
140 inline void
141 ite8181_config_write_4(iot, ioh, byteoffset, data)
142 bus_space_tag_t iot;
143 bus_space_handle_t ioh;
144 int byteoffset;
145 int data;
146 {
147 bus_space_write_4(iot, ioh, ITE8181_CONF_OFFSET + byteoffset, data);
148 }
149
150 inline int
151 ite8181_gui_read_4(sc, byteoffset)
152 struct ite8181_softc *sc;
153 int byteoffset;
154 {
155 return bus_space_read_4(sc->sc_iot, sc->sc_ioh,
156 sc->sc_gba + byteoffset);
157 }
158
159 inline void
160 ite8181_gui_write_4(sc, byteoffset, data)
161 struct ite8181_softc *sc;
162 int byteoffset;
163 int data;
164 {
165 bus_space_write_4(sc->sc_iot, sc->sc_ioh, sc->sc_gba + byteoffset, data);
166 }
167
168 inline int
169 ite8181_gui_read_1(sc, byteoffset)
170 struct ite8181_softc *sc;
171 int byteoffset;
172 {
173 return bus_space_read_1(sc->sc_iot, sc->sc_ioh,
174 sc->sc_gba + byteoffset);
175 }
176
177 inline void
178 ite8181_gui_write_1(sc, byteoffset, data)
179 struct ite8181_softc *sc;
180 int byteoffset;
181 int data;
182 {
183 bus_space_write_1(sc->sc_iot, sc->sc_ioh, sc->sc_gba + byteoffset, data);
184 }
185
186 inline int
187 ite8181_graphics_read_1(sc, byteoffset)
188 struct ite8181_softc *sc;
189 int byteoffset;
190 {
191 return bus_space_read_1(sc->sc_iot, sc->sc_ioh,
192 sc->sc_sba + byteoffset);
193 }
194
195 inline void
196 ite8181_graphics_write_1(sc, byteoffset, data)
197 struct ite8181_softc *sc;
198 int byteoffset;
199 int data;
200 {
201 bus_space_write_1(sc->sc_iot, sc->sc_ioh, sc->sc_sba + byteoffset, data);
202 }
203
204 inline int
205 ite8181_ema_read_1(sc, byteoffset)
206 struct ite8181_softc *sc;
207 int byteoffset;
208 {
209 ite8181_graphics_write_1(sc, ITE8181_EMA_EXAX, byteoffset);
210 return ite8181_graphics_read_1(sc, ITE8181_EMA_EXADATA);
211 }
212
213 inline void
214 ite8181_ema_write_1(sc, byteoffset, data)
215 struct ite8181_softc *sc;
216 int byteoffset;
217 int data;
218 {
219 ite8181_graphics_write_1(sc, ITE8181_EMA_EXAX, byteoffset);
220 ite8181_graphics_write_1(sc, ITE8181_EMA_EXADATA, data);
221 }
222
223 int
224 ite8181_probe(iot, ioh)
225 bus_space_tag_t iot;
226 bus_space_handle_t ioh;
227 {
228 unsigned long regval;
229
230 #if NBIVIDEO > 0
231 if (bivideo_dont_attach) /* some video driver already attached */
232 return (0);
233 #endif /* NBIVIDEO > 0 */
234
235 regval = ite8181_config_read_4(iot, ioh, ITE8181_ID);
236 VPRINTF(("ite8181_probe: vendor id=%04lx product id=%04lx\n",
237 regval & 0xffff, (regval >> 16) & 0xffff));
238 if (regval != ((ITE8181_PRODUCT_ID << 16) | ITE8181_VENDER_ID))
239 return (0);
240
241 return (1);
242 }
243
244 void
245 ite8181_attach(sc)
246 struct ite8181_softc *sc;
247 {
248 unsigned long regval;
249 struct hpcfb_attach_args ha;
250 int console = (bootinfo->bi_cnuse & BI_CNUSE_SERIAL) ? 0 : 1;
251
252 printf(": ");
253 if (ite8181_fbinit(&sc->sc_fbconf) != 0) {
254 /* just return so that hpcfb will not be attached */
255 return;
256 }
257
258 regval = ite8181_config_read_4(sc->sc_iot, sc->sc_ioh, ITE8181_CLASS);
259 printf("ITE8181 Rev.%02lx", regval & ITE8181_REV_MASK);
260 if (console) {
261 printf(", console");
262 }
263 printf("\n");
264 printf("%s: framebuffer address: 0x%08lx\n",
265 sc->sc_dev.dv_xname, (u_long)bootinfo->fb_addr);
266
267 /* set base offsets */
268 sc->sc_mba = ite8181_config_read_4(sc->sc_iot, sc->sc_ioh, ITE8181_MBA);
269 DPRINTFN(1, ("ite8181: Memory base offset %08x\n", sc->sc_mba));
270 sc->sc_gba = ite8181_config_read_4(sc->sc_iot, sc->sc_ioh, ITE8181_GBA);
271 DPRINTFN(1, ("ite8181: GUI base offset %08x\n", sc->sc_gba));
272 sc->sc_sba = ite8181_config_read_4(sc->sc_iot, sc->sc_ioh, ITE8181_SBA);
273 DPRINTFN(1, ("ite8181: Graphics base offset %08x\n", sc->sc_sba));
274
275 /* assume lcd is on */
276 sc->sc_lcd = 1;
277
278 /* Add a power hook to power saving */
279 sc->sc_powerstate = ITE8181_POWERSTATE_D0;
280 sc->sc_powerhook = powerhook_establish(ite8181_power, sc);
281 if (sc->sc_powerhook == NULL)
282 printf("%s: WARNING: unable to establish power hook\n",
283 sc->sc_dev.dv_xname);
284
285 /* Add a hard power hook to power saving */
286 sc->sc_hardpowerhook = config_hook(CONFIG_HOOK_PMEVENT,
287 CONFIG_HOOK_PMEVENT_HARDPOWER,
288 CONFIG_HOOK_SHARE,
289 ite8181_hardpower, sc);
290 if (sc->sc_hardpowerhook == NULL)
291 printf("%s: WARNING: unable to establish hard power hook\n",
292 sc->sc_dev.dv_xname);
293
294 ite8181_erase_cursor(sc);
295
296 if (console && hpcfb_cnattach(&sc->sc_fbconf) != 0) {
297 panic("ite8181_attach: can't init fb console");
298 }
299
300 ha.ha_console = console;
301 ha.ha_accessops = &ite8181_ha;
302 ha.ha_accessctx = sc;
303 ha.ha_curfbconf = 0;
304 ha.ha_nfbconf = 1;
305 ha.ha_fbconflist = &sc->sc_fbconf;
306 ha.ha_curdspconf = 0;
307 ha.ha_ndspconf = 1;
308 ha.ha_dspconflist = &sc->sc_dspconf;
309
310 config_found(&sc->sc_dev, &ha, hpcfbprint);
311
312 #if NBIVIDEO > 0
313 /*
314 * bivideo is no longer need
315 */
316 bivideo_dont_attach = 1;
317 #endif /* NBIVIDEO > 0 */
318 }
319
320 int ite8181_lcd_power(sc, on)
321 struct ite8181_softc *sc;
322 int on;
323 {
324 int lcd_p;
325 int lcd_s;
326 int lcd_seq;
327 int loop = 10;
328
329 if (ite8181_lcd_control_disable) {
330 VPRINTF(("ite8171_lcd_control_disable!: %s\n", on?"on":"off"));
331 return 0;
332 }
333
334 if (sc->sc_lcd != on) {
335 ite8181_ema_write_1(sc, ITE8181_EMA_ENABLEEMA,
336 ITE8181_EMA_ENABLEPASS);
337 lcd_p = ite8181_ema_read_1(sc, ITE8181_EMA_LCDPOWER);
338 lcd_s = ite8181_ema_read_1(sc, ITE8181_EMA_LCDPOWERSTAT);
339 lcd_seq = ite8181_ema_read_1(sc, ITE8181_EMA_LCDPOWERSEQ);
340 DPRINTFN(1,("ite8181_lcd_power(%d)< p=%x, s=%x, seq=%x\n",
341 on,
342 lcd_p, lcd_s, lcd_seq));
343 if (on) {
344 sc->sc_lcd = 1;
345 lcd_seq |= (ITE8181_PUP0|ITE8181_PUP1|ITE8181_PUP2);
346 ite8181_ema_write_1(sc, ITE8181_EMA_LCDPOWERSEQ, lcd_seq);
347 lcd_p &= ~ITE8181_LCDSTANDBY;
348 ite8181_ema_write_1(sc, ITE8181_EMA_LCDPOWER, lcd_p);
349 /*
350 * XXX:
351 * IBM WorkPad z50 power unit has too weak power.
352 * So we must wait too many times to access self device
353 * after LCD panel and BackLight on.
354 * Currently delay is not enough ??? FIXME
355 */
356 delay(ite8181_lcd_on_self_delay*MSEC);
357 while (loop--) {
358 lcd_p = ite8181_ema_read_1(sc, ITE8181_EMA_LCDPOWER);
359 lcd_s = ite8181_ema_read_1(sc, ITE8181_EMA_LCDPOWERSTAT);
360 lcd_seq = ite8181_ema_read_1(sc, ITE8181_EMA_LCDPOWERSEQ);
361 DPRINTFN(1,("ite8181_lcd_power(%d)%d| p=%x, s=%x, seq=%x\n",
362 on, loop,
363 lcd_p, lcd_s, lcd_seq));
364 /* XXX the states which are not described in manual.*/
365 if (!(lcd_s&ITE8181_LCDPSTANDBY) &&
366 !(lcd_s&ITE8181_LCDPUP) &&
367 (lcd_s&ITE8181_LCDPON))
368 break;
369 delay(100);
370 }
371 lcd_s |= ITE8181_PPTOBEON;
372 ite8181_ema_write_1(sc, ITE8181_EMA_LCDPOWERSTAT, lcd_s);
373 } else {
374 sc->sc_lcd = 0;
375 lcd_p |= ITE8181_LCDSTANDBY;
376 ite8181_ema_write_1(sc, ITE8181_EMA_LCDPOWER, lcd_p);
377 while (loop--) {
378 lcd_p = ite8181_ema_read_1(sc, ITE8181_EMA_LCDPOWER);
379 lcd_s = ite8181_ema_read_1(sc, ITE8181_EMA_LCDPOWERSTAT);
380 lcd_seq = ite8181_ema_read_1(sc, ITE8181_EMA_LCDPOWERSEQ);
381 DPRINTFN(1,("ite8181_lcd_power(%d)%d| p=%x, s=%x, seq=%x\n",
382 on, loop,
383 lcd_p, lcd_s, lcd_seq));
384 /* XXX the states which are not described in manual.*/
385 if ((lcd_s&ITE8181_LCDPSTANDBY) &&
386 !(lcd_s&ITE8181_LCDPDOWN) &&
387 !(lcd_s&ITE8181_LCDPON))
388 break;
389 delay(100);
390 }
391 lcd_s &= ~ITE8181_PPTOBEON;
392 ite8181_ema_write_1(sc, ITE8181_EMA_LCDPOWERSTAT, lcd_s);
393 }
394 DPRINTFN(1,("ite8181_lcd_power(%d)> p=%x, s=%x, seq=%x\n",
395 on,
396 ite8181_ema_read_1(sc, ITE8181_EMA_LCDPOWER),
397 ite8181_ema_read_1(sc, ITE8181_EMA_LCDPOWERSTAT),
398 ite8181_ema_read_1(sc, ITE8181_EMA_LCDPOWERSEQ)));
399 ite8181_ema_write_1(sc, ITE8181_EMA_ENABLEEMA,
400 ITE8181_EMA_DISABLEPASS);
401 }
402 return 0;
403 }
404
405 static void
406 ite8181_erase_cursor(sc)
407 struct ite8181_softc *sc;
408 {
409 ite8181_gui_write_1(sc, ITE8181_GUI_C1C, 0); /* Cursor 1 Control Reg. */
410 /* other ? */
411 }
412
413 static void
414 ite8181_power(why, arg)
415 int why;
416 void *arg;
417 {
418 }
419
420 static int
421 ite8181_hardpower(ctx, type, id, msg)
422 void *ctx;
423 int type;
424 long id;
425 void *msg;
426 {
427 struct ite8181_softc *sc = ctx;
428 int why = (int)msg;
429
430 switch (why) {
431 case PWR_STANDBY:
432 sc->sc_powerstate = ITE8181_POWERSTATE_D3;
433 /* ite8181_lcd_power(sc, 0); */
434 delay(MSEC);
435 break;
436 case PWR_SUSPEND:
437 sc->sc_powerstate = ITE8181_POWERSTATE_D2;
438 ite8181_lcd_power(sc, 0);
439 delay(MSEC);
440 break;
441 case PWR_RESUME:
442 delay(MSEC);
443 sc->sc_powerstate = ITE8181_POWERSTATE_D0;
444 ite8181_lcd_power(sc, 1);
445 /*
446 * XXX:
447 * IBM WorkPad z50 power unit has too weak power.
448 * So we must wait too many times to access other devices
449 * after LCD panel and BackLight on.
450 */
451 delay(ite8181_lcd_on_delay*MSEC);
452 break;
453 }
454
455 /*
456 * you should wait until the
457 * power state transit sequence will end.
458 */
459
460 return (0);
461 }
462
463
464 static int
465 ite8181_fbinit(fb)
466 struct hpcfb_fbconf *fb;
467 {
468
469 /*
470 * get fb settings from bootinfo
471 */
472 if (bootinfo == NULL ||
473 bootinfo->fb_addr == 0 ||
474 bootinfo->fb_line_bytes == 0 ||
475 bootinfo->fb_width == 0 ||
476 bootinfo->fb_height == 0) {
477 printf("no frame buffer infomation.\n");
478 return (-1);
479 }
480
481 /* zero fill */
482 bzero(fb, sizeof(*fb));
483
484 fb->hf_conf_index = 0; /* configuration index */
485 fb->hf_nconfs = 1; /* how many configurations */
486 strcpy(fb->hf_name, "built-in video");
487 /* frame buffer name */
488 strcpy(fb->hf_conf_name, "default");
489 /* configuration name */
490 fb->hf_height = bootinfo->fb_height;
491 fb->hf_width = bootinfo->fb_width;
492 fb->hf_baseaddr = (u_long)bootinfo->fb_addr;
493 fb->hf_offset = (u_long)bootinfo->fb_addr -
494 mips_ptob(mips_btop(bootinfo->fb_addr));
495 /* frame buffer start offset */
496 fb->hf_bytes_per_line = bootinfo->fb_line_bytes;
497 fb->hf_nplanes = 1;
498 fb->hf_bytes_per_plane = bootinfo->fb_height *
499 bootinfo->fb_line_bytes;
500
501 fb->hf_access_flags |= HPCFB_ACCESS_BYTE;
502 fb->hf_access_flags |= HPCFB_ACCESS_WORD;
503 fb->hf_access_flags |= HPCFB_ACCESS_DWORD;
504
505 switch (bootinfo->fb_type) {
506 /*
507 * gray scale
508 */
509 case BIFB_D2_M2L_3:
510 case BIFB_D2_M2L_3x2:
511 fb->hf_access_flags |= HPCFB_ACCESS_REVERSE;
512 /* fall through */
513 case BIFB_D2_M2L_0:
514 case BIFB_D2_M2L_0x2:
515 fb->hf_class = HPCFB_CLASS_GRAYSCALE;
516 fb->hf_access_flags |= HPCFB_ACCESS_STATIC;
517 fb->hf_pack_width = 8;
518 fb->hf_pixels_per_pack = 4;
519 fb->hf_pixel_width = 2;
520 fb->hf_class_data_length = sizeof(struct hf_gray_tag);
521 fb->hf_u.hf_gray.hf_flags = 0; /* reserved for future use */
522 break;
523
524 case BIFB_D4_M2L_F:
525 case BIFB_D4_M2L_Fx2:
526 fb->hf_access_flags |= HPCFB_ACCESS_REVERSE;
527 /* fall through */
528 case BIFB_D4_M2L_0:
529 case BIFB_D4_M2L_0x2:
530 fb->hf_class = HPCFB_CLASS_GRAYSCALE;
531 fb->hf_access_flags |= HPCFB_ACCESS_STATIC;
532 fb->hf_pack_width = 8;
533 fb->hf_pixels_per_pack = 2;
534 fb->hf_pixel_width = 4;
535 fb->hf_class_data_length = sizeof(struct hf_gray_tag);
536 fb->hf_u.hf_gray.hf_flags = 0; /* reserved for future use */
537 break;
538
539 /*
540 * indexed color
541 */
542 case BIFB_D8_FF:
543 fb->hf_access_flags |= HPCFB_ACCESS_REVERSE;
544 /* fall through */
545 case BIFB_D8_00:
546 fb->hf_class = HPCFB_CLASS_INDEXCOLOR;
547 fb->hf_access_flags |= HPCFB_ACCESS_STATIC;
548 fb->hf_pack_width = 8;
549 fb->hf_pixels_per_pack = 1;
550 fb->hf_pixel_width = 8;
551 fb->hf_class_data_length = sizeof(struct hf_indexed_tag);
552 fb->hf_u.hf_indexed.hf_flags = 0; /* reserved for future use */
553 break;
554
555 /*
556 * RGB color
557 */
558 case BIFB_D16_FFFF:
559 fb->hf_access_flags |= HPCFB_ACCESS_REVERSE;
560 /* fall through */
561 case BIFB_D16_0000:
562 fb->hf_class = HPCFB_CLASS_RGBCOLOR;
563 fb->hf_access_flags |= HPCFB_ACCESS_STATIC;
564 #if BYTE_ORDER == LITTLE_ENDIAN
565 fb->hf_swap_flags = HPCFB_SWAP_BYTE;
566 #endif
567 fb->hf_pack_width = 16;
568 fb->hf_pixels_per_pack = 1;
569 fb->hf_pixel_width = 16;
570
571 fb->hf_class_data_length = sizeof(struct hf_rgb_tag);
572 fb->hf_u.hf_rgb.hf_flags = 0; /* reserved for future use */
573
574 fb->hf_u.hf_rgb.hf_red_width = 5;
575 fb->hf_u.hf_rgb.hf_red_shift = 11;
576 fb->hf_u.hf_rgb.hf_green_width = 6;
577 fb->hf_u.hf_rgb.hf_green_shift = 5;
578 fb->hf_u.hf_rgb.hf_blue_width = 5;
579 fb->hf_u.hf_rgb.hf_blue_shift = 0;
580 fb->hf_u.hf_rgb.hf_alpha_width = 0;
581 fb->hf_u.hf_rgb.hf_alpha_shift = 0;
582 break;
583
584 default:
585 printf("unknown type (=%d).\n", bootinfo->fb_type);
586 return (-1);
587 break;
588 }
589
590 return (0); /* no error */
591 }
592
593 int
594 ite8181_ioctl(v, cmd, data, flag, p)
595 void *v;
596 u_long cmd;
597 caddr_t data;
598 int flag;
599 struct proc *p;
600 {
601 struct ite8181_softc *sc = (struct ite8181_softc *)v;
602 struct hpcfb_fbconf *fbconf;
603 struct hpcfb_dspconf *dspconf;
604 struct wsdisplay_cmap *cmap;
605
606 switch (cmd) {
607 case WSDISPLAYIO_GETCMAP:
608 cmap = (struct wsdisplay_cmap*)data;
609
610 if (sc->sc_fbconf.hf_class != HPCFB_CLASS_INDEXCOLOR ||
611 sc->sc_fbconf.hf_pack_width != 8 ||
612 256 <= cmap->index ||
613 256 < (cmap->index + cmap->count))
614 return (EINVAL);
615
616 if (!uvm_useracc(cmap->red, cmap->count, B_WRITE) ||
617 !uvm_useracc(cmap->green, cmap->count, B_WRITE) ||
618 !uvm_useracc(cmap->blue, cmap->count, B_WRITE))
619 return (EFAULT);
620
621 #ifdef ITE8181_WINCE_CMAP
622 copyout(&bivideo_cmap_r[cmap->index], cmap->red, cmap->count);
623 copyout(&bivideo_cmap_g[cmap->index], cmap->green,cmap->count);
624 copyout(&bivideo_cmap_b[cmap->index], cmap->blue, cmap->count);
625 return (0);
626 #else /* ITE8181_WINCE_CMAP */
627 return EINVAL;
628 #endif /* ITE8181_WINCE_CMAP */
629
630 case WSDISPLAYIO_PUTCMAP:
631 /*
632 * This driver can't set color map.
633 */
634 return (EINVAL);
635
636 case HPCFBIO_GCONF:
637 fbconf = (struct hpcfb_fbconf *)data;
638 if (fbconf->hf_conf_index != 0 &&
639 fbconf->hf_conf_index != HPCFB_CURRENT_CONFIG) {
640 return (EINVAL);
641 }
642 *fbconf = sc->sc_fbconf; /* structure assignment */
643 return (0);
644 case HPCFBIO_SCONF:
645 fbconf = (struct hpcfb_fbconf *)data;
646 if (fbconf->hf_conf_index != 0 &&
647 fbconf->hf_conf_index != HPCFB_CURRENT_CONFIG) {
648 return (EINVAL);
649 }
650 /*
651 * nothing to do because we have only one configration
652 */
653 return (0);
654 case HPCFBIO_GDSPCONF:
655 dspconf = (struct hpcfb_dspconf *)data;
656 if ((dspconf->hd_unit_index != 0 &&
657 dspconf->hd_unit_index != HPCFB_CURRENT_UNIT) ||
658 (dspconf->hd_conf_index != 0 &&
659 dspconf->hd_conf_index != HPCFB_CURRENT_CONFIG)) {
660 return (EINVAL);
661 }
662 *dspconf = sc->sc_dspconf; /* structure assignment */
663 return (0);
664 case HPCFBIO_SDSPCONF:
665 dspconf = (struct hpcfb_dspconf *)data;
666 if ((dspconf->hd_unit_index != 0 &&
667 dspconf->hd_unit_index != HPCFB_CURRENT_UNIT) ||
668 (dspconf->hd_conf_index != 0 &&
669 dspconf->hd_conf_index != HPCFB_CURRENT_CONFIG)) {
670 return (EINVAL);
671 }
672 /*
673 * nothing to do
674 * because we have only one unit and one configration
675 */
676 return (0);
677 case HPCFBIO_GOP:
678 case HPCFBIO_SOP:
679 /*
680 * curently not implemented...
681 */
682 return (EINVAL);
683 }
684
685 return (ENOTTY);
686 }
687
688 paddr_t
689 ite8181_mmap(ctx, offset, prot)
690 void *ctx;
691 off_t offset;
692 int prot;
693 {
694 struct ite8181_softc *sc = (struct ite8181_softc *)ctx;
695
696 if (offset < 0 ||
697 (sc->sc_fbconf.hf_bytes_per_plane +
698 sc->sc_fbconf.hf_offset) < offset)
699 return -1;
700
701 return mips_btop((u_long)bootinfo->fb_addr + offset);
702 }
703