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