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