bivideo.c revision 1.3 1 /* $NetBSD: bivideo.c,v 1.3 2001/02/27 08:54:17 sato 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 #define FBDEBUG
37 static const char _copyright[] __attribute__ ((unused)) =
38 "Copyright (c) 1999 Shin Takemura. All rights reserved.";
39 static const char _rcsid[] __attribute__ ((unused)) =
40 "$Id: bivideo.c,v 1.3 2001/02/27 08:54:17 sato Exp $";
41
42 #include <sys/param.h>
43 #include <sys/systm.h>
44 #include <sys/device.h>
45 #include <sys/buf.h>
46 #include <sys/ioctl.h>
47 #include <sys/reboot.h>
48
49 #include <uvm/uvm_extern.h>
50
51 #include <machine/bus.h>
52 #include <machine/autoconf.h>
53 #include <machine/bootinfo.h>
54 #include <machine/config_hook.h>
55
56 #include <dev/wscons/wsconsio.h>
57 #include <dev/wscons/wsdisplayvar.h>
58
59 #include <dev/rasops/rasops.h>
60
61 #include <dev/hpc/hpcfbvar.h>
62 #include <dev/hpc/hpcfbio.h>
63 #include <dev/hpc/bivideovar.h>
64 #include <dev/hpc/hpccmapvar.h>
65
66 #define VPRINTF(arg) do { if (bootverbose) printf arg; } while(0);
67
68 /*
69 * global variables
70 */
71 int bivideo_dont_attach = 0;
72
73 /*
74 * function prototypes
75 */
76 int bivideomatch(struct device *, struct cfdata *, void *);
77 void bivideoattach(struct device *, struct device *, void *);
78 int bivideo_ioctl(void *, u_long, caddr_t, int, struct proc *);
79 paddr_t bivideo_mmap(void *, off_t, int);
80
81 struct bivideo_softc {
82 struct device sc_dev;
83 struct hpcfb_fbconf sc_fbconf;
84 struct hpcfb_dspconf sc_dspconf;
85 void *sc_powerhook; /* power management hook */
86 int sc_powerstate;
87 #define PWRSTAT_SUSPEND (1<<0)
88 #define PWRSTAT_LCD (1<<1)
89 #define PWRSTAT_BACKLIGHT (1<<2)
90 #define PWRSTAT_ALL (0xffffffff)
91 int sc_brightness;
92 int sc_brightness_save;
93 int sc_max_brightness;
94 int sc_contrast;
95 int sc_max_contrast;
96
97 };
98
99 static int bivideo_init(struct hpcfb_fbconf *);
100 static void bivideo_power(int, void *);
101 static void bivideo_update_powerstate(struct bivideo_softc *, int);
102 void bivideo_get_backlight(struct bivideo_softc *);
103 void bivideo_init_brightness(struct bivideo_softc *);
104 void bivideo_init_contrast(struct bivideo_softc *);
105 void bivideo_set_brightness(struct bivideo_softc *, int);
106 void bivideo_set_contrast(struct bivideo_softc *, int);
107
108 #if defined __mips__ || defined __sh__ || defined __arm__
109 #define __BTOP(x) ((paddr_t)(x) >> PGSHIFT)
110 #define __PTOB(x) ((paddr_t)(x) << PGSHIFT)
111 #else
112 #error "define btop, ptob."
113 #endif
114
115 /*
116 * static variables
117 */
118 struct cfattach bivideo_ca = {
119 sizeof(struct bivideo_softc), bivideomatch, bivideoattach,
120 };
121 struct hpcfb_accessops bivideo_ha = {
122 bivideo_ioctl, bivideo_mmap
123 };
124
125 static int console_flag = 0;
126 static int attach_flag = 0;
127
128 /*
129 * function bodies
130 */
131 int
132 bivideomatch(struct device *parent, struct cfdata *match, void *aux)
133 {
134 struct mainbus_attach_args *ma = aux;
135
136 if (bivideo_dont_attach ||
137 strcmp(ma->ma_name, match->cf_driver->cd_name))
138 return 0;
139
140 return (1);
141 }
142
143 void
144 bivideoattach(struct device *parent, struct device *self, void *aux)
145 {
146 struct bivideo_softc *sc = (struct bivideo_softc *)self;
147 struct hpcfb_attach_args ha;
148
149 if (attach_flag) {
150 panic("%s(%d): bivideo attached twice", __FILE__, __LINE__);
151 }
152 attach_flag = 1;
153
154 printf(": ");
155 if (bivideo_init(&sc->sc_fbconf) != 0) {
156 /* just return so that hpcfb will not be attached */
157 return;
158 }
159
160 printf("pseudo video controller");
161 if (console_flag) {
162 printf(", console");
163 }
164 printf("\n");
165 printf("%s: framebuffer address: 0x%08lx\n",
166 sc->sc_dev.dv_xname, (u_long)bootinfo->fb_addr);
167
168 /* Add a suspend hook to power saving */
169 sc->sc_powerstate = 0;
170 sc->sc_powerhook = powerhook_establish(bivideo_power, sc);
171 if (sc->sc_powerhook == NULL)
172 printf("%s: WARNING: unable to establish power hook\n",
173 sc->sc_dev.dv_xname);
174
175 /* initialize backlight brightness and lcd contrast */
176 sc->sc_brightness = sc->sc_contrast =
177 sc->sc_max_brightness = sc->sc_max_contrast = -1;
178 bivideo_get_backlight(sc);
179 bivideo_init_brightness(sc);
180 bivideo_init_contrast(sc);
181
182 ha.ha_console = console_flag;
183 ha.ha_accessops = &bivideo_ha;
184 ha.ha_accessctx = sc;
185 ha.ha_curfbconf = 0;
186 ha.ha_nfbconf = 1;
187 ha.ha_fbconflist = &sc->sc_fbconf;
188 ha.ha_curdspconf = 0;
189 ha.ha_ndspconf = 1;
190 ha.ha_dspconflist = &sc->sc_dspconf;
191
192 config_found(self, &ha, hpcfbprint);
193 }
194
195 int
196 bivideo_getcnfb(struct hpcfb_fbconf *fb)
197 {
198 console_flag = 1;
199
200 return bivideo_init(fb);
201 }
202
203 static int
204 bivideo_init(struct hpcfb_fbconf *fb)
205 {
206 /*
207 * get fb settings from bootinfo
208 */
209 if (bootinfo == NULL ||
210 bootinfo->fb_addr == 0 ||
211 bootinfo->fb_line_bytes == 0 ||
212 bootinfo->fb_width == 0 ||
213 bootinfo->fb_height == 0) {
214 printf("no frame buffer infomation.\n");
215 return (-1);
216 }
217
218 /* zero fill */
219 bzero(fb, sizeof(*fb));
220
221 fb->hf_conf_index = 0; /* configuration index */
222 fb->hf_nconfs = 1; /* how many configurations */
223 strcpy(fb->hf_name, "built-in video");
224 /* frame buffer name */
225 strcpy(fb->hf_conf_name, "default");
226 /* configuration name */
227 fb->hf_height = bootinfo->fb_height;
228 fb->hf_width = bootinfo->fb_width;
229 fb->hf_baseaddr = (u_long)bootinfo->fb_addr;
230 fb->hf_offset = (u_long)bootinfo->fb_addr -
231 __PTOB(__BTOP(bootinfo->fb_addr));
232 /* frame buffer start offset */
233 fb->hf_bytes_per_line = bootinfo->fb_line_bytes;
234 fb->hf_nplanes = 1;
235 fb->hf_bytes_per_plane = bootinfo->fb_height *
236 bootinfo->fb_line_bytes;
237
238 fb->hf_access_flags |= HPCFB_ACCESS_BYTE;
239 fb->hf_access_flags |= HPCFB_ACCESS_WORD;
240 fb->hf_access_flags |= HPCFB_ACCESS_DWORD;
241
242 switch (bootinfo->fb_type) {
243 /*
244 * gray scale
245 */
246 case BIFB_D2_M2L_3:
247 case BIFB_D2_M2L_3x2:
248 fb->hf_access_flags |= HPCFB_ACCESS_REVERSE;
249 /* fall through */
250 case BIFB_D2_M2L_0:
251 case BIFB_D2_M2L_0x2:
252 fb->hf_class = HPCFB_CLASS_GRAYSCALE;
253 fb->hf_access_flags |= HPCFB_ACCESS_STATIC;
254 fb->hf_pack_width = 8;
255 fb->hf_pixels_per_pack = 4;
256 fb->hf_pixel_width = 2;
257 fb->hf_class_data_length = sizeof(struct hf_gray_tag);
258 fb->hf_u.hf_gray.hf_flags = 0; /* reserved for future use */
259 break;
260
261 case BIFB_D4_M2L_F:
262 case BIFB_D4_M2L_Fx2:
263 fb->hf_access_flags |= HPCFB_ACCESS_REVERSE;
264 /* fall through */
265 case BIFB_D4_M2L_0:
266 case BIFB_D4_M2L_0x2:
267 fb->hf_class = HPCFB_CLASS_GRAYSCALE;
268 fb->hf_access_flags |= HPCFB_ACCESS_STATIC;
269 fb->hf_pack_width = 8;
270 fb->hf_pixels_per_pack = 2;
271 fb->hf_pixel_width = 4;
272 fb->hf_class_data_length = sizeof(struct hf_gray_tag);
273 fb->hf_u.hf_gray.hf_flags = 0; /* reserved for future use */
274 break;
275
276 /*
277 * indexed color
278 */
279 case BIFB_D8_FF:
280 fb->hf_access_flags |= HPCFB_ACCESS_REVERSE;
281 /* fall through */
282 case BIFB_D8_00:
283 fb->hf_class = HPCFB_CLASS_INDEXCOLOR;
284 fb->hf_access_flags |= HPCFB_ACCESS_STATIC;
285 fb->hf_pack_width = 8;
286 fb->hf_pixels_per_pack = 1;
287 fb->hf_pixel_width = 8;
288 fb->hf_class_data_length = sizeof(struct hf_indexed_tag);
289 fb->hf_u.hf_indexed.hf_flags = 0; /* reserved for future use */
290 break;
291
292 /*
293 * RGB color
294 */
295 case BIFB_D16_FFFF:
296 fb->hf_access_flags |= HPCFB_ACCESS_REVERSE;
297 /* fall through */
298 case BIFB_D16_0000:
299 fb->hf_class = HPCFB_CLASS_RGBCOLOR;
300 fb->hf_access_flags |= HPCFB_ACCESS_STATIC;
301 #if BYTE_ORDER == LITTLE_ENDIAN
302 fb->hf_swap_flags = HPCFB_SWAP_BYTE;
303 #endif
304 fb->hf_pack_width = 16;
305 fb->hf_pixels_per_pack = 1;
306 fb->hf_pixel_width = 16;
307
308 fb->hf_class_data_length = sizeof(struct hf_rgb_tag);
309 fb->hf_u.hf_rgb.hf_flags = 0; /* reserved for future use */
310
311 fb->hf_u.hf_rgb.hf_red_width = 5;
312 fb->hf_u.hf_rgb.hf_red_shift = 11;
313 fb->hf_u.hf_rgb.hf_green_width = 6;
314 fb->hf_u.hf_rgb.hf_green_shift = 5;
315 fb->hf_u.hf_rgb.hf_blue_width = 5;
316 fb->hf_u.hf_rgb.hf_blue_shift = 0;
317 fb->hf_u.hf_rgb.hf_alpha_width = 0;
318 fb->hf_u.hf_rgb.hf_alpha_shift = 0;
319 break;
320
321 default:
322 printf("unsupported type %d.\n", bootinfo->fb_type);
323 return (-1);
324 break;
325 }
326
327 return (0); /* no error */
328 }
329
330 static void
331 bivideo_power(int why, void *arg)
332 {
333 struct bivideo_softc *sc = arg;
334
335 switch (why) {
336 case PWR_SUSPEND:
337 case PWR_STANDBY:
338 sc->sc_powerstate |= PWRSTAT_SUSPEND;
339 bivideo_update_powerstate(sc, PWRSTAT_ALL);
340 break;
341 case PWR_RESUME:
342 sc->sc_powerstate &= ~PWRSTAT_SUSPEND;
343 bivideo_update_powerstate(sc, PWRSTAT_ALL);
344 break;
345 }
346 }
347
348 static void
349 bivideo_update_powerstate(struct bivideo_softc *sc, int updates)
350 {
351 if (updates & PWRSTAT_LCD)
352 config_hook_call(CONFIG_HOOK_POWERCONTROL,
353 CONFIG_HOOK_POWERCONTROL_LCD,
354 (void*)!(sc->sc_powerstate & PWRSTAT_SUSPEND));
355
356 if (updates & PWRSTAT_BACKLIGHT)
357 config_hook_call(CONFIG_HOOK_POWERCONTROL,
358 CONFIG_HOOK_POWERCONTROL_LCDLIGHT,
359 (void*)(!(sc->sc_powerstate & PWRSTAT_SUSPEND) &&
360 (sc->sc_powerstate & PWRSTAT_BACKLIGHT)));
361 }
362
363 int
364 bivideo_ioctl(void *v, u_long cmd, caddr_t data, int flag, struct proc *p)
365 {
366 struct bivideo_softc *sc = (struct bivideo_softc *)v;
367 struct hpcfb_fbconf *fbconf;
368 struct hpcfb_dspconf *dspconf;
369 struct wsdisplay_cmap *cmap;
370 struct wsdisplay_param *dispparam;
371
372 switch (cmd) {
373 case WSDISPLAYIO_GETCMAP:
374 cmap = (struct wsdisplay_cmap*)data;
375
376 if (sc->sc_fbconf.hf_class != HPCFB_CLASS_INDEXCOLOR ||
377 sc->sc_fbconf.hf_pack_width != 8 ||
378 256 <= cmap->index ||
379 256 < (cmap->index + cmap->count))
380 return (EINVAL);
381
382 if (!uvm_useracc(cmap->red, cmap->count, B_WRITE) ||
383 !uvm_useracc(cmap->green, cmap->count, B_WRITE) ||
384 !uvm_useracc(cmap->blue, cmap->count, B_WRITE))
385 return (EFAULT);
386
387 copyout(&bivideo_cmap_r[cmap->index], cmap->red, cmap->count);
388 copyout(&bivideo_cmap_g[cmap->index], cmap->green,cmap->count);
389 copyout(&bivideo_cmap_b[cmap->index], cmap->blue, cmap->count);
390
391 return (0);
392
393 case WSDISPLAYIO_PUTCMAP:
394 /*
395 * This driver can't set color map.
396 */
397 return (EINVAL);
398
399
400 case WSDISPLAYIO_GETPARAM:
401 dispparam = (struct wsdisplay_param*)data;
402 switch (dispparam->param) {
403 case WSDISPLAYIO_PARAM_BACKLIGHT:
404 VPRINTF(("bivideo_ioctl: GETPARAM:BACKLIGHT call\n"));
405 if (sc->sc_max_brightness == -1)
406 bivideo_init_brightness(sc);
407 bivideo_get_backlight(sc);
408 dispparam->min = 0;
409 dispparam->max = 1;
410 if (sc->sc_max_brightness > 0)
411 dispparam->curval = sc->sc_brightness > 0? 1: 0;
412 else
413 dispparam->curval =
414 (sc->sc_powerstate & PWRSTAT_BACKLIGHT) ? 1 : 0;
415 VPRINTF(("bivideo_ioctl: GETPARAM:BACKLIGHT:%d\n",
416 dispparam->curval));
417 return 0;
418 break;
419 case WSDISPLAYIO_PARAM_CONTRAST:
420 VPRINTF(("bivideo_ioctl: GETPARAM:CONTRAST call\n"));
421 if (sc->sc_max_contrast == -1)
422 bivideo_init_contrast(sc);
423 if (sc->sc_max_contrast > 0) {
424 dispparam->min = 0;
425 dispparam->max = sc->sc_max_contrast;
426 dispparam->curval = sc->sc_contrast;
427 VPRINTF(("bivideo_ioctl: GETPARAM:CONTRAST max=%d, current=%d\n", sc->sc_max_contrast, sc->sc_contrast));
428 return 0;
429 } else {
430 VPRINTF(("bivideo_ioctl: GETPARAM:CONTRAST ret\n"));
431 return (EINVAL);
432 }
433 break;
434 case WSDISPLAYIO_PARAM_BRIGHTNESS:
435 VPRINTF(("bivideo_ioctl: GETPARAM:BRIGHTNESS call\n"));
436 if (sc->sc_max_brightness == -1)
437 bivideo_init_brightness(sc);
438 if (sc->sc_max_brightness > 0) {
439 dispparam->min = 0;
440 dispparam->max = sc->sc_max_brightness;
441 dispparam->curval = sc->sc_brightness;
442 VPRINTF(("bivideo_ioctl: GETPARAM:BRIGHTNESS max=%d, current=%d\n", sc->sc_max_brightness, sc->sc_brightness));
443 return 0;
444 } else {
445 VPRINTF(("bivideo_ioctl: GETPARAM:BRIGHTNESS ret\n"));
446 return (EINVAL);
447 }
448 return (EINVAL);
449 default:
450 return (EINVAL);
451 }
452 return (0);
453
454 case WSDISPLAYIO_SETPARAM:
455 dispparam = (struct wsdisplay_param*)data;
456 switch (dispparam->param) {
457 case WSDISPLAYIO_PARAM_BACKLIGHT:
458 VPRINTF(("bivideo_ioctl: SETPARAM:BACKLIGHT call\n"));
459 if (dispparam->curval < 0 ||
460 1 < dispparam->curval)
461 return (EINVAL);
462 if (sc->sc_max_brightness == -1)
463 bivideo_init_brightness(sc);
464 VPRINTF(("bivideo_ioctl: SETPARAM:max brightness=%d\n", sc->sc_max_brightness));
465 if (sc->sc_max_brightness > 0) { /* dimmer */
466 if (dispparam->curval == 0){
467 sc->sc_brightness_save = sc->sc_brightness;
468 bivideo_set_brightness(sc, 0); /* min */
469 } else {
470 if (sc->sc_brightness_save == 0)
471 sc->sc_brightness_save = sc->sc_max_brightness;
472 bivideo_set_brightness(sc, sc->sc_brightness_save);
473 }
474 VPRINTF(("bivideo_ioctl: SETPARAM:BACKLIGHT: brightness=%d\n", sc->sc_brightness));
475 } else { /* off */
476 if (dispparam->curval == 0)
477 sc->sc_powerstate &= ~PWRSTAT_BACKLIGHT;
478 else
479 sc->sc_powerstate |= PWRSTAT_BACKLIGHT;
480 VPRINTF(("bivideo_ioctl: SETPARAM:BACKLIGHT: powerstate %d\n",
481 (sc->sc_powerstate & PWRSTAT_BACKLIGHT)?1:0));
482 bivideo_update_powerstate(sc, PWRSTAT_BACKLIGHT);
483 VPRINTF(("bivideo_ioctl: SETPARAM:BACKLIGHT:%d\n",
484 (sc->sc_powerstate & PWRSTAT_BACKLIGHT)?1:0));
485 }
486 return 0;
487 break;
488 case WSDISPLAYIO_PARAM_CONTRAST:
489 VPRINTF(("bivideo_ioctl: SETPARAM:CONTRAST call\n"));
490 if (sc->sc_max_contrast == -1)
491 bivideo_init_contrast(sc);
492 if (dispparam->curval < 0 ||
493 sc->sc_max_contrast < dispparam->curval)
494 return (EINVAL);
495 if (sc->sc_max_contrast > 0) {
496 int org = sc->sc_contrast;
497 bivideo_set_contrast(sc, dispparam->curval);
498 VPRINTF(("bivideo_ioctl: SETPARAM:CONTRAST org=%d, current=%d\n", org, sc->sc_contrast));
499 return 0;
500 } else {
501 VPRINTF(("bivideo_ioctl: SETPARAM:CONTRAST ret\n"));
502 return (EINVAL);
503 }
504 break;
505 case WSDISPLAYIO_PARAM_BRIGHTNESS:
506 VPRINTF(("bivideo_ioctl: SETPARAM:BRIGHTNESS call\n"));
507 if (sc->sc_max_brightness == -1)
508 bivideo_init_brightness(sc);
509 if (dispparam->curval < 0 ||
510 sc->sc_max_brightness < dispparam->curval)
511 return (EINVAL);
512 if (sc->sc_max_brightness > 0) {
513 int org = sc->sc_brightness;
514 bivideo_set_brightness(sc, dispparam->curval);
515 VPRINTF(("bivideo_ioctl: SETPARAM:BRIGHTNESS org=%d, current=%d\n", org, sc->sc_brightness));
516 return 0;
517 } else {
518 VPRINTF(("bivideo_ioctl: SETPARAM:BRIGHTNESS ret\n"));
519 return (EINVAL);
520 }
521 break;
522 default:
523 return (EINVAL);
524 }
525 return (0);
526
527 case HPCFBIO_GCONF:
528 fbconf = (struct hpcfb_fbconf *)data;
529 if (fbconf->hf_conf_index != 0 &&
530 fbconf->hf_conf_index != HPCFB_CURRENT_CONFIG) {
531 return (EINVAL);
532 }
533 *fbconf = sc->sc_fbconf; /* structure assignment */
534 return (0);
535 case HPCFBIO_SCONF:
536 fbconf = (struct hpcfb_fbconf *)data;
537 if (fbconf->hf_conf_index != 0 &&
538 fbconf->hf_conf_index != HPCFB_CURRENT_CONFIG) {
539 return (EINVAL);
540 }
541 /*
542 * nothing to do because we have only one configration
543 */
544 return (0);
545 case HPCFBIO_GDSPCONF:
546 dspconf = (struct hpcfb_dspconf *)data;
547 if ((dspconf->hd_unit_index != 0 &&
548 dspconf->hd_unit_index != HPCFB_CURRENT_UNIT) ||
549 (dspconf->hd_conf_index != 0 &&
550 dspconf->hd_conf_index != HPCFB_CURRENT_CONFIG)) {
551 return (EINVAL);
552 }
553 *dspconf = sc->sc_dspconf; /* structure assignment */
554 return (0);
555 case HPCFBIO_SDSPCONF:
556 dspconf = (struct hpcfb_dspconf *)data;
557 if ((dspconf->hd_unit_index != 0 &&
558 dspconf->hd_unit_index != HPCFB_CURRENT_UNIT) ||
559 (dspconf->hd_conf_index != 0 &&
560 dspconf->hd_conf_index != HPCFB_CURRENT_CONFIG)) {
561 return (EINVAL);
562 }
563 /*
564 * nothing to do
565 * because we have only one unit and one configration
566 */
567 return (0);
568 case HPCFBIO_GOP:
569 case HPCFBIO_SOP:
570 /*
571 * curently not implemented...
572 */
573 return (EINVAL);
574 }
575
576 return (ENOTTY);
577 }
578
579 paddr_t
580 bivideo_mmap(void *ctx, off_t offset, int prot)
581 {
582 struct bivideo_softc *sc = (struct bivideo_softc *)ctx;
583
584 if (offset < 0 ||
585 (sc->sc_fbconf.hf_bytes_per_plane +
586 sc->sc_fbconf.hf_offset) < offset)
587 return -1;
588
589 return __BTOP((u_long)bootinfo->fb_addr + offset);
590 }
591
592 void
593 bivideo_get_backlight(struct bivideo_softc *sc)
594 {
595 int val = -1;
596
597 if (sc->sc_max_brightness < 0) {
598 if (config_hook_call(CONFIG_HOOK_GET,
599 CONFIG_HOOK_POWER_LCDLIGHT, &val) != -1) {
600 if (val == 0)
601 sc->sc_powerstate &= ~PWRSTAT_BACKLIGHT;
602 else
603 sc->sc_powerstate |= PWRSTAT_BACKLIGHT;
604 }
605 }
606 }
607
608 void
609 bivideo_init_brightness(struct bivideo_softc *sc)
610 {
611 int val = -1;
612
613 if (config_hook_call(CONFIG_HOOK_GET,
614 CONFIG_HOOK_BRIGHTNESS, &val) != -1) {
615 sc->sc_brightness_save = sc->sc_brightness = val;
616 }
617 val = -1;
618 if (config_hook_call(CONFIG_HOOK_GET,
619 CONFIG_HOOK_BRIGHTNESS_MAX, &val) != -1) {
620 sc->sc_max_brightness = val;
621 }
622 return;
623 }
624
625
626 void
627 bivideo_init_contrast(struct bivideo_softc *sc)
628 {
629 int val = -1;
630
631 if (config_hook_call(CONFIG_HOOK_GET,
632 CONFIG_HOOK_CONTRAST, &val) != -1) {
633 sc->sc_contrast = val;
634 }
635 val = -1;
636 if (config_hook_call(CONFIG_HOOK_GET,
637 CONFIG_HOOK_CONTRAST_MAX, &val) != -1) {
638 sc->sc_max_contrast = val;
639 }
640 return;
641 }
642
643 void
644 bivideo_set_brightness(struct bivideo_softc *sc, int val)
645 {
646 sc->sc_brightness = val;
647
648 config_hook_call(CONFIG_HOOK_SET, CONFIG_HOOK_BRIGHTNESS, &val);
649 if (config_hook_call(CONFIG_HOOK_GET,
650 CONFIG_HOOK_BRIGHTNESS, &val) != -1) {
651 sc->sc_brightness = val;
652 }
653 }
654
655 void
656 bivideo_set_contrast(struct bivideo_softc *sc, int val)
657 {
658 sc->sc_contrast = val;
659
660 config_hook_call(CONFIG_HOOK_SET, CONFIG_HOOK_CONTRAST, &val);
661 if (config_hook_call(CONFIG_HOOK_GET,
662 CONFIG_HOOK_CONTRAST, &val) != -1) {
663 sc->sc_contrast = val;
664 }
665 }
666