bivideo.c revision 1.23 1 /* $NetBSD: bivideo.c,v 1.23 2006/09/24 03:53:08 jmcneill Exp $ */
2
3 /*-
4 * Copyright (c) 1999-2001
5 * Shin Takemura and PocketBSD Project. 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 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by the PocketBSD project
18 * and its contributors.
19 * 4. Neither the name of the project nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 *
35 */
36
37 #include <sys/cdefs.h>
38 __KERNEL_RCSID(0, "$NetBSD: bivideo.c,v 1.23 2006/09/24 03:53:08 jmcneill Exp $");
39
40 #define FBDEBUG
41 static const char _copyright[] __attribute__ ((unused)) =
42 "Copyright (c) 1999 Shin Takemura. All rights reserved.";
43
44 #include <sys/param.h>
45 #include <sys/systm.h>
46 #include <sys/device.h>
47 #include <sys/buf.h>
48 #include <sys/ioctl.h>
49 #include <sys/reboot.h>
50
51 #include <uvm/uvm_extern.h>
52
53 #include <machine/bus.h>
54 #include <machine/autoconf.h>
55 #include <machine/bootinfo.h>
56 #include <machine/config_hook.h>
57
58 #include <dev/wscons/wsconsio.h>
59 #include <dev/wscons/wsdisplayvar.h>
60
61 #include <dev/rasops/rasops.h>
62
63 #include <dev/hpc/hpcfbvar.h>
64 #include <dev/hpc/hpcfbio.h>
65 #include <dev/hpc/bivideovar.h>
66 #include <dev/hpc/hpccmapvar.h>
67
68 #define VPRINTF(arg) do { if (bootverbose) printf arg; } while(0);
69
70 /*
71 * global variables
72 */
73 int bivideo_dont_attach = 0;
74
75 /*
76 * function prototypes
77 */
78 int bivideomatch(struct device *, struct cfdata *, void *);
79 void bivideoattach(struct device *, struct device *, void *);
80 int bivideo_ioctl(void *, u_long, caddr_t, int, struct lwp *);
81 paddr_t bivideo_mmap(void *, off_t, int);
82
83 struct bivideo_softc {
84 struct device sc_dev;
85 struct hpcfb_fbconf sc_fbconf;
86 struct hpcfb_dspconf sc_dspconf;
87 void *sc_powerhook; /* power management hook */
88 int sc_powerstate;
89 #define PWRSTAT_SUSPEND (1<<0)
90 #define PWRSTAT_VIDEOOFF (1<<1)
91 #define PWRSTAT_LCD (1<<2)
92 #define PWRSTAT_BACKLIGHT (1<<3)
93 #define PWRSTAT_ALL (0xffffffff)
94 int sc_lcd_inited;
95 #define BACKLIGHT_INITED (1<<0)
96 #define BRIGHTNESS_INITED (1<<1)
97 #define CONTRAST_INITED (1<<2)
98 int sc_brightness;
99 int sc_brightness_save;
100 int sc_max_brightness;
101 int sc_contrast;
102 int sc_max_contrast;
103
104 };
105
106 static int bivideo_init(struct hpcfb_fbconf *);
107 static void bivideo_power(int, void *);
108 static void bivideo_update_powerstate(struct bivideo_softc *, int);
109 void bivideo_init_backlight(struct bivideo_softc *, int);
110 void bivideo_init_brightness(struct bivideo_softc *, int);
111 void bivideo_init_contrast(struct bivideo_softc *, int);
112 void bivideo_set_brightness(struct bivideo_softc *, int);
113 void bivideo_set_contrast(struct bivideo_softc *, int);
114
115 #if defined __mips__ || defined __sh__ || defined __arm__
116 #define __BTOP(x) ((paddr_t)(x) >> PGSHIFT)
117 #define __PTOB(x) ((paddr_t)(x) << PGSHIFT)
118 #else
119 #error "define btop, ptob."
120 #endif
121
122 /*
123 * static variables
124 */
125 CFATTACH_DECL(bivideo, sizeof(struct bivideo_softc),
126 bivideomatch, bivideoattach, NULL, NULL);
127
128 struct hpcfb_accessops bivideo_ha = {
129 bivideo_ioctl, bivideo_mmap
130 };
131
132 static int console_flag = 0;
133 static int attach_flag = 0;
134
135 /*
136 * function bodies
137 */
138 int
139 bivideomatch(struct device *parent, struct cfdata *match, void *aux)
140 {
141 struct mainbus_attach_args *ma = aux;
142
143 if (bivideo_dont_attach ||
144 strcmp(ma->ma_name, match->cf_name))
145 return 0;
146
147 return (1);
148 }
149
150 void
151 bivideoattach(struct device *parent, struct device *self, void *aux)
152 {
153 struct bivideo_softc *sc = device_private(self);
154 struct hpcfb_attach_args ha;
155
156 if (attach_flag) {
157 panic("%s(%d): bivideo attached twice", __FILE__, __LINE__);
158 }
159 attach_flag = 1;
160
161 printf(": ");
162 if (bivideo_init(&sc->sc_fbconf) != 0) {
163 /* just return so that hpcfb will not be attached */
164 return;
165 }
166
167 printf("pseudo video controller");
168 if (console_flag) {
169 printf(", console");
170 }
171 printf("\n");
172 printf("%s: framebuffer address: 0x%08lx\n",
173 sc->sc_dev.dv_xname, (u_long)bootinfo->fb_addr);
174
175 /* Add a suspend hook to power saving */
176 sc->sc_powerstate = 0;
177 sc->sc_powerhook = powerhook_establish(sc->sc_dev.dv_xname,
178 bivideo_power, sc);
179 if (sc->sc_powerhook == NULL)
180 printf("%s: WARNING: unable to establish power hook\n",
181 sc->sc_dev.dv_xname);
182
183 /* initialize backlight brightness and lcd contrast */
184 sc->sc_lcd_inited = 0;
185 bivideo_init_brightness(sc, 1);
186 bivideo_init_contrast(sc, 1);
187 bivideo_init_backlight(sc, 1);
188
189 ha.ha_console = console_flag;
190 ha.ha_accessops = &bivideo_ha;
191 ha.ha_accessctx = sc;
192 ha.ha_curfbconf = 0;
193 ha.ha_nfbconf = 1;
194 ha.ha_fbconflist = &sc->sc_fbconf;
195 ha.ha_curdspconf = 0;
196 ha.ha_ndspconf = 1;
197 ha.ha_dspconflist = &sc->sc_dspconf;
198
199 config_found(self, &ha, hpcfbprint);
200 }
201
202 int
203 bivideo_getcnfb(struct hpcfb_fbconf *fb)
204 {
205 console_flag = 1;
206
207 return bivideo_init(fb);
208 }
209
210 static int
211 bivideo_init(struct hpcfb_fbconf *fb)
212 {
213 /*
214 * get fb settings from bootinfo
215 */
216 if (bootinfo == NULL ||
217 bootinfo->fb_addr == 0 ||
218 bootinfo->fb_line_bytes == 0 ||
219 bootinfo->fb_width == 0 ||
220 bootinfo->fb_height == 0) {
221 printf("no frame buffer information.\n");
222 return (-1);
223 }
224
225 /* zero fill */
226 memset(fb, 0, sizeof(*fb));
227
228 fb->hf_conf_index = 0; /* configuration index */
229 fb->hf_nconfs = 1; /* how many configurations */
230 strcpy(fb->hf_name, "built-in video");
231 /* frame buffer name */
232 strcpy(fb->hf_conf_name, "default");
233 /* configuration name */
234 fb->hf_height = bootinfo->fb_height;
235 fb->hf_width = bootinfo->fb_width;
236 fb->hf_baseaddr = (u_long)bootinfo->fb_addr;
237 fb->hf_offset = (u_long)bootinfo->fb_addr -
238 __PTOB(__BTOP(bootinfo->fb_addr));
239 /* frame buffer start offset */
240 fb->hf_bytes_per_line = bootinfo->fb_line_bytes;
241 fb->hf_nplanes = 1;
242 fb->hf_bytes_per_plane = bootinfo->fb_height *
243 bootinfo->fb_line_bytes;
244
245 fb->hf_access_flags |= HPCFB_ACCESS_BYTE;
246 fb->hf_access_flags |= HPCFB_ACCESS_WORD;
247 fb->hf_access_flags |= HPCFB_ACCESS_DWORD;
248
249 switch (bootinfo->fb_type) {
250 /*
251 * gray scale
252 */
253 case BIFB_D2_M2L_3:
254 case BIFB_D2_M2L_3x2:
255 fb->hf_access_flags |= HPCFB_ACCESS_REVERSE;
256 /* fall through */
257 case BIFB_D2_M2L_0:
258 case BIFB_D2_M2L_0x2:
259 fb->hf_class = HPCFB_CLASS_GRAYSCALE;
260 fb->hf_access_flags |= HPCFB_ACCESS_STATIC;
261 fb->hf_pack_width = 8;
262 fb->hf_pixels_per_pack = 4;
263 fb->hf_pixel_width = 2;
264 fb->hf_class_data_length = sizeof(struct hf_gray_tag);
265 fb->hf_u.hf_gray.hf_flags = 0; /* reserved for future use */
266 break;
267
268 case BIFB_D4_M2L_F:
269 case BIFB_D4_M2L_Fx2:
270 fb->hf_access_flags |= HPCFB_ACCESS_REVERSE;
271 /* fall through */
272 case BIFB_D4_M2L_0:
273 case BIFB_D4_M2L_0x2:
274 fb->hf_class = HPCFB_CLASS_GRAYSCALE;
275 fb->hf_access_flags |= HPCFB_ACCESS_STATIC;
276 fb->hf_pack_width = 8;
277 fb->hf_pixels_per_pack = 2;
278 fb->hf_pixel_width = 4;
279 fb->hf_class_data_length = sizeof(struct hf_gray_tag);
280 fb->hf_u.hf_gray.hf_flags = 0; /* reserved for future use */
281 break;
282
283 /*
284 * indexed color
285 */
286 case BIFB_D8_FF:
287 fb->hf_access_flags |= HPCFB_ACCESS_REVERSE;
288 /* fall through */
289 case BIFB_D8_00:
290 fb->hf_class = HPCFB_CLASS_INDEXCOLOR;
291 fb->hf_access_flags |= HPCFB_ACCESS_STATIC;
292 fb->hf_pack_width = 8;
293 fb->hf_pixels_per_pack = 1;
294 fb->hf_pixel_width = 8;
295 fb->hf_class_data_length = sizeof(struct hf_indexed_tag);
296 fb->hf_u.hf_indexed.hf_flags = 0; /* reserved for future use */
297 break;
298
299 /*
300 * RGB color
301 */
302 case BIFB_D16_FFFF:
303 fb->hf_access_flags |= HPCFB_ACCESS_REVERSE;
304 /* fall through */
305 case BIFB_D16_0000:
306 fb->hf_class = HPCFB_CLASS_RGBCOLOR;
307 fb->hf_access_flags |= HPCFB_ACCESS_STATIC;
308 #if BYTE_ORDER == LITTLE_ENDIAN
309 fb->hf_order_flags = HPCFB_REVORDER_BYTE;
310 #endif
311 fb->hf_pack_width = 16;
312 fb->hf_pixels_per_pack = 1;
313 fb->hf_pixel_width = 16;
314
315 fb->hf_class_data_length = sizeof(struct hf_rgb_tag);
316 fb->hf_u.hf_rgb.hf_flags = 0; /* reserved for future use */
317
318 fb->hf_u.hf_rgb.hf_red_width = 5;
319 fb->hf_u.hf_rgb.hf_red_shift = 11;
320 fb->hf_u.hf_rgb.hf_green_width = 6;
321 fb->hf_u.hf_rgb.hf_green_shift = 5;
322 fb->hf_u.hf_rgb.hf_blue_width = 5;
323 fb->hf_u.hf_rgb.hf_blue_shift = 0;
324 fb->hf_u.hf_rgb.hf_alpha_width = 0;
325 fb->hf_u.hf_rgb.hf_alpha_shift = 0;
326 break;
327
328 default:
329 printf("unsupported type %d.\n", bootinfo->fb_type);
330 return (-1);
331 break;
332 }
333
334 return (0); /* no error */
335 }
336
337 static void
338 bivideo_power(int why, void *arg)
339 {
340 struct bivideo_softc *sc = arg;
341
342 switch (why) {
343 case PWR_SUSPEND:
344 case PWR_STANDBY:
345 sc->sc_powerstate |= PWRSTAT_SUSPEND;
346 bivideo_update_powerstate(sc, PWRSTAT_ALL);
347 break;
348 case PWR_RESUME:
349 sc->sc_powerstate &= ~PWRSTAT_SUSPEND;
350 bivideo_update_powerstate(sc, PWRSTAT_ALL);
351 break;
352 }
353 }
354
355 static void
356 bivideo_update_powerstate(struct bivideo_softc *sc, int updates)
357 {
358 if (updates & PWRSTAT_LCD)
359 config_hook_call(CONFIG_HOOK_POWERCONTROL,
360 CONFIG_HOOK_POWERCONTROL_LCD,
361 (void*)!(sc->sc_powerstate &
362 (PWRSTAT_VIDEOOFF|PWRSTAT_SUSPEND)));
363
364 if (updates & PWRSTAT_BACKLIGHT)
365 config_hook_call(CONFIG_HOOK_POWERCONTROL,
366 CONFIG_HOOK_POWERCONTROL_LCDLIGHT,
367 (void*)(!(sc->sc_powerstate &
368 (PWRSTAT_VIDEOOFF|PWRSTAT_SUSPEND)) &&
369 (sc->sc_powerstate & PWRSTAT_BACKLIGHT)));
370 }
371
372 int
373 bivideo_ioctl(void *v, u_long cmd, caddr_t data, int flag, struct lwp *l)
374 {
375 struct bivideo_softc *sc = (struct bivideo_softc *)v;
376 struct hpcfb_fbconf *fbconf;
377 struct hpcfb_dspconf *dspconf;
378 struct wsdisplay_cmap *cmap;
379 struct wsdisplay_param *dispparam;
380 int error;
381
382 switch (cmd) {
383 case WSDISPLAYIO_GETCMAP:
384 cmap = (struct wsdisplay_cmap *)data;
385
386 if (sc->sc_fbconf.hf_class != HPCFB_CLASS_INDEXCOLOR ||
387 sc->sc_fbconf.hf_pack_width != 8 ||
388 256 <= cmap->index ||
389 256 < (cmap->index + cmap->count))
390 return (EINVAL);
391
392 error = copyout(&bivideo_cmap_r[cmap->index], cmap->red,
393 cmap->count);
394 if (error)
395 return error;
396 error = copyout(&bivideo_cmap_g[cmap->index], cmap->green,
397 cmap->count);
398 if (error)
399 return error;
400 error = copyout(&bivideo_cmap_b[cmap->index], cmap->blue,
401 cmap->count);
402 return error;
403
404 case WSDISPLAYIO_PUTCMAP:
405 /*
406 * This driver can't set color map.
407 */
408 return (EINVAL);
409
410 case WSDISPLAYIO_SVIDEO:
411 if (*(int *)data == WSDISPLAYIO_VIDEO_OFF)
412 sc->sc_powerstate |= PWRSTAT_VIDEOOFF;
413 else
414 sc->sc_powerstate &= ~PWRSTAT_VIDEOOFF;
415 bivideo_update_powerstate(sc, PWRSTAT_ALL);
416 return 0;
417
418 case WSDISPLAYIO_GVIDEO:
419 *(int *)data = (sc->sc_powerstate&PWRSTAT_VIDEOOFF) ?
420 WSDISPLAYIO_VIDEO_OFF:WSDISPLAYIO_VIDEO_ON;
421 return 0;
422
423
424 case WSDISPLAYIO_GETPARAM:
425 dispparam = (struct wsdisplay_param*)data;
426 switch (dispparam->param) {
427 case WSDISPLAYIO_PARAM_BACKLIGHT:
428 VPRINTF(("bivideo_ioctl: GET:BACKLIGHT\n"));
429 bivideo_init_brightness(sc, 0);
430 bivideo_init_backlight(sc, 0);
431 VPRINTF(("bivideo_ioctl: GET:(real)BACKLIGHT %d\n",
432 (sc->sc_powerstate&PWRSTAT_BACKLIGHT)? 1: 0));
433 dispparam->min = 0;
434 dispparam->max = 1;
435 if (sc->sc_max_brightness > 0)
436 dispparam->curval = sc->sc_brightness > 0? 1: 0;
437 else
438 dispparam->curval =
439 (sc->sc_powerstate&PWRSTAT_BACKLIGHT) ? 1: 0;
440 VPRINTF(("bivideo_ioctl: GET:BACKLIGHT:%d(%s)\n",
441 dispparam->curval,
442 sc->sc_max_brightness > 0? "brightness": "light"));
443 return 0;
444 break;
445 case WSDISPLAYIO_PARAM_CONTRAST:
446 VPRINTF(("bivideo_ioctl: GET:CONTRAST\n"));
447 bivideo_init_contrast(sc, 0);
448 if (sc->sc_max_contrast > 0) {
449 dispparam->min = 0;
450 dispparam->max = sc->sc_max_contrast;
451 dispparam->curval = sc->sc_contrast;
452 VPRINTF(("bivideo_ioctl: GET:CONTRAST max=%d, current=%d\n", sc->sc_max_contrast, sc->sc_contrast));
453 return 0;
454 } else {
455 VPRINTF(("bivideo_ioctl: GET:CONTRAST EINVAL\n"));
456 return (EINVAL);
457 }
458 break;
459 case WSDISPLAYIO_PARAM_BRIGHTNESS:
460 VPRINTF(("bivideo_ioctl: GET:BRIGHTNESS\n"));
461 bivideo_init_brightness(sc, 0);
462 if (sc->sc_max_brightness > 0) {
463 dispparam->min = 0;
464 dispparam->max = sc->sc_max_brightness;
465 dispparam->curval = sc->sc_brightness;
466 VPRINTF(("bivideo_ioctl: GET:BRIGHTNESS max=%d, current=%d\n", sc->sc_max_brightness, sc->sc_brightness));
467 return 0;
468 } else {
469 VPRINTF(("bivideo_ioctl: GET:BRIGHTNESS EINVAL\n"));
470 return (EINVAL);
471 }
472 return (EINVAL);
473 default:
474 return (EINVAL);
475 }
476 return (0);
477
478 case WSDISPLAYIO_SETPARAM:
479 dispparam = (struct wsdisplay_param*)data;
480 switch (dispparam->param) {
481 case WSDISPLAYIO_PARAM_BACKLIGHT:
482 VPRINTF(("bivideo_ioctl: SET:BACKLIGHT\n"));
483 if (dispparam->curval < 0 ||
484 1 < dispparam->curval)
485 return (EINVAL);
486 bivideo_init_brightness(sc, 0);
487 VPRINTF(("bivideo_ioctl: SET:max brightness=%d\n", sc->sc_max_brightness));
488 if (sc->sc_max_brightness > 0) { /* dimmer */
489 if (dispparam->curval == 0){
490 sc->sc_brightness_save = sc->sc_brightness;
491 bivideo_set_brightness(sc, 0); /* min */
492 } else {
493 if (sc->sc_brightness_save == 0)
494 sc->sc_brightness_save = sc->sc_max_brightness;
495 bivideo_set_brightness(sc, sc->sc_brightness_save);
496 }
497 VPRINTF(("bivideo_ioctl: SET:BACKLIGHT:brightness=%d\n", sc->sc_brightness));
498 } else { /* off */
499 if (dispparam->curval == 0)
500 sc->sc_powerstate &= ~PWRSTAT_BACKLIGHT;
501 else
502 sc->sc_powerstate |= PWRSTAT_BACKLIGHT;
503 VPRINTF(("bivideo_ioctl: SET:BACKLIGHT:powerstate %d\n",
504 (sc->sc_powerstate & PWRSTAT_BACKLIGHT)?1:0));
505 bivideo_update_powerstate(sc, PWRSTAT_BACKLIGHT);
506 VPRINTF(("bivideo_ioctl: SET:BACKLIGHT:%d\n",
507 (sc->sc_powerstate & PWRSTAT_BACKLIGHT)?1:0));
508 }
509 return 0;
510 break;
511 case WSDISPLAYIO_PARAM_CONTRAST:
512 VPRINTF(("bivideo_ioctl: SET:CONTRAST\n"));
513 bivideo_init_contrast(sc, 0);
514 if (dispparam->curval < 0 ||
515 sc->sc_max_contrast < dispparam->curval)
516 return (EINVAL);
517 if (sc->sc_max_contrast > 0) {
518 int org = sc->sc_contrast;
519 bivideo_set_contrast(sc, dispparam->curval);
520 VPRINTF(("bivideo_ioctl: SET:CONTRAST org=%d, current=%d\n", org, sc->sc_contrast));
521 return 0;
522 } else {
523 VPRINTF(("bivideo_ioctl: SET:CONTRAST EINVAL\n"));
524 return (EINVAL);
525 }
526 break;
527 case WSDISPLAYIO_PARAM_BRIGHTNESS:
528 VPRINTF(("bivideo_ioctl: SET:BRIGHTNESS\n"));
529 bivideo_init_brightness(sc, 0);
530 if (dispparam->curval < 0 ||
531 sc->sc_max_brightness < dispparam->curval)
532 return (EINVAL);
533 if (sc->sc_max_brightness > 0) {
534 int org = sc->sc_brightness;
535 bivideo_set_brightness(sc, dispparam->curval);
536 VPRINTF(("bivideo_ioctl: SET:BRIGHTNESS org=%d, current=%d\n", org, sc->sc_brightness));
537 return 0;
538 } else {
539 VPRINTF(("bivideo_ioctl: SET:BRIGHTNESS EINVAL\n"));
540 return (EINVAL);
541 }
542 break;
543 default:
544 return (EINVAL);
545 }
546 return (0);
547
548 case HPCFBIO_GCONF:
549 fbconf = (struct hpcfb_fbconf *)data;
550 if (fbconf->hf_conf_index != 0 &&
551 fbconf->hf_conf_index != HPCFB_CURRENT_CONFIG) {
552 return (EINVAL);
553 }
554 *fbconf = sc->sc_fbconf; /* structure assignment */
555 return (0);
556 case HPCFBIO_SCONF:
557 fbconf = (struct hpcfb_fbconf *)data;
558 if (fbconf->hf_conf_index != 0 &&
559 fbconf->hf_conf_index != HPCFB_CURRENT_CONFIG) {
560 return (EINVAL);
561 }
562 /*
563 * nothing to do because we have only one configuration
564 */
565 return (0);
566 case HPCFBIO_GDSPCONF:
567 dspconf = (struct hpcfb_dspconf *)data;
568 if ((dspconf->hd_unit_index != 0 &&
569 dspconf->hd_unit_index != HPCFB_CURRENT_UNIT) ||
570 (dspconf->hd_conf_index != 0 &&
571 dspconf->hd_conf_index != HPCFB_CURRENT_CONFIG)) {
572 return (EINVAL);
573 }
574 *dspconf = sc->sc_dspconf; /* structure assignment */
575 return (0);
576 case HPCFBIO_SDSPCONF:
577 dspconf = (struct hpcfb_dspconf *)data;
578 if ((dspconf->hd_unit_index != 0 &&
579 dspconf->hd_unit_index != HPCFB_CURRENT_UNIT) ||
580 (dspconf->hd_conf_index != 0 &&
581 dspconf->hd_conf_index != HPCFB_CURRENT_CONFIG)) {
582 return (EINVAL);
583 }
584 /*
585 * nothing to do
586 * because we have only one unit and one configuration
587 */
588 return (0);
589 case HPCFBIO_GOP:
590 case HPCFBIO_SOP:
591 /*
592 * curently not implemented...
593 */
594 return (EINVAL);
595 }
596
597 return (EPASSTHROUGH);
598 }
599
600 paddr_t
601 bivideo_mmap(void *ctx, off_t offset, int prot)
602 {
603 struct bivideo_softc *sc = (struct bivideo_softc *)ctx;
604
605 if (offset < 0 ||
606 (sc->sc_fbconf.hf_bytes_per_plane +
607 sc->sc_fbconf.hf_offset) < offset)
608 return -1;
609
610 return __BTOP((u_long)bootinfo->fb_addr + offset);
611 }
612
613
614 void
615 bivideo_init_backlight(struct bivideo_softc *sc, int inattach)
616 {
617 int val = -1;
618
619 if (sc->sc_lcd_inited&BACKLIGHT_INITED)
620 return;
621
622 if (config_hook_call(CONFIG_HOOK_GET,
623 CONFIG_HOOK_POWER_LCDLIGHT, &val) != -1) {
624 /* we can get real light state */
625 VPRINTF(("bivideo_init_backlight: real backlight=%d\n", val));
626 if (val == 0)
627 sc->sc_powerstate &= ~PWRSTAT_BACKLIGHT;
628 else
629 sc->sc_powerstate |= PWRSTAT_BACKLIGHT;
630 sc->sc_lcd_inited |= BACKLIGHT_INITED;
631 } else if (inattach) {
632 /*
633 we cannot get real light state in attach time
634 because light device not yet attached.
635 we will retry in !inattach.
636 temporary assume light is on.
637 */
638 sc->sc_powerstate |= PWRSTAT_BACKLIGHT;
639 } else {
640 /* we cannot get real light state, so work by myself state */
641 sc->sc_lcd_inited |= BACKLIGHT_INITED;
642 }
643 }
644
645 void
646 bivideo_init_brightness(struct bivideo_softc *sc, int inattach)
647 {
648 int val = -1;
649
650 if (sc->sc_lcd_inited&BRIGHTNESS_INITED)
651 return;
652
653 VPRINTF(("bivideo_init_brightness\n"));
654 if (config_hook_call(CONFIG_HOOK_GET,
655 CONFIG_HOOK_BRIGHTNESS_MAX, &val) != -1) {
656 /* we can get real brightness max */
657 VPRINTF(("bivideo_init_brightness: real brightness max=%d\n", val));
658 sc->sc_max_brightness = val;
659 val = -1;
660 if (config_hook_call(CONFIG_HOOK_GET,
661 CONFIG_HOOK_BRIGHTNESS, &val) != -1) {
662 /* we can get real brightness */
663 VPRINTF(("bivideo_init_brightness: real brightness=%d\n", val));
664 sc->sc_brightness_save = sc->sc_brightness = val;
665 } else {
666 sc->sc_brightness_save =
667 sc->sc_brightness = sc->sc_max_brightness;
668 }
669 sc->sc_lcd_inited |= BRIGHTNESS_INITED;
670 } else if (inattach) {
671 /*
672 we cannot get real brightness in attach time
673 because brightness device not yet attached.
674 we will retry in !inattach.
675 */
676 sc->sc_max_brightness = -1;
677 sc->sc_brightness = -1;
678 sc->sc_brightness_save = -1;
679 } else {
680 /* we cannot get real brightness */
681 sc->sc_lcd_inited |= BRIGHTNESS_INITED;
682 }
683
684 return;
685 }
686
687 void
688 bivideo_init_contrast(struct bivideo_softc *sc, int inattach)
689 {
690 int val = -1;
691
692 if (sc->sc_lcd_inited&CONTRAST_INITED)
693 return;
694
695 VPRINTF(("bivideo_init_contrast\n"));
696 if (config_hook_call(CONFIG_HOOK_GET,
697 CONFIG_HOOK_CONTRAST_MAX, &val) != -1) {
698 /* we can get real contrast max */
699 VPRINTF(("bivideo_init_contrast: real contrast max=%d\n", val));
700 sc->sc_max_contrast = val;
701 val = -1;
702 if (config_hook_call(CONFIG_HOOK_GET,
703 CONFIG_HOOK_CONTRAST, &val) != -1) {
704 /* we can get real contrast */
705 VPRINTF(("bivideo_init_contrast: real contrast=%d\n", val));
706 sc->sc_contrast = val;
707 } else {
708 sc->sc_contrast = sc->sc_max_contrast;
709 }
710 sc->sc_lcd_inited |= CONTRAST_INITED;
711 } else if (inattach) {
712 /*
713 we cannot get real contrast in attach time
714 because contrast device not yet attached.
715 we will retry in !inattach.
716 */
717 sc->sc_max_contrast = -1;
718 sc->sc_contrast = -1;
719 } else {
720 /* we cannot get real contrast */
721 sc->sc_lcd_inited |= CONTRAST_INITED;
722 }
723
724 return;
725 }
726
727 void
728 bivideo_set_brightness(struct bivideo_softc *sc, int val)
729 {
730 sc->sc_brightness = val;
731
732 config_hook_call(CONFIG_HOOK_SET, CONFIG_HOOK_BRIGHTNESS, &val);
733 if (config_hook_call(CONFIG_HOOK_GET,
734 CONFIG_HOOK_BRIGHTNESS, &val) != -1) {
735 sc->sc_brightness = val;
736 }
737 }
738
739 void
740 bivideo_set_contrast(struct bivideo_softc *sc, int val)
741 {
742 sc->sc_contrast = val;
743
744 config_hook_call(CONFIG_HOOK_SET, CONFIG_HOOK_CONTRAST, &val);
745 if (config_hook_call(CONFIG_HOOK_GET,
746 CONFIG_HOOK_CONTRAST, &val) != -1) {
747 sc->sc_contrast = val;
748 }
749 }
750