zlcd.c revision 1.11 1 1.11 dyoung /* $NetBSD: zlcd.c,v 1.11 2010/02/24 22:37:56 dyoung Exp $ */
2 1.1 ober /* $OpenBSD: zaurus_lcd.c,v 1.20 2006/06/02 20:50:14 miod Exp $ */
3 1.1 ober /* NetBSD: lubbock_lcd.c,v 1.1 2003/08/09 19:38:53 bsh Exp */
4 1.1 ober
5 1.1 ober /*
6 1.1 ober * Copyright (c) 2002, 2003 Genetec Corporation. All rights reserved.
7 1.1 ober * Written by Hiroyuki Bessho for Genetec Corporation.
8 1.1 ober *
9 1.1 ober * Redistribution and use in source and binary forms, with or without
10 1.1 ober * modification, are permitted provided that the following conditions
11 1.1 ober * are met:
12 1.1 ober * 1. Redistributions of source code must retain the above copyright
13 1.1 ober * notice, this list of conditions and the following disclaimer.
14 1.1 ober * 2. Redistributions in binary form must reproduce the above copyright
15 1.1 ober * notice, this list of conditions and the following disclaimer in the
16 1.1 ober * documentation and/or other materials provided with the distribution.
17 1.1 ober * 3. The name of Genetec Corporation may not be used to endorse or
18 1.1 ober * promote products derived from this software without specific prior
19 1.1 ober * written permission.
20 1.1 ober *
21 1.1 ober * THIS SOFTWARE IS PROVIDED BY GENETEC CORPORATION ``AS IS'' AND
22 1.1 ober * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23 1.1 ober * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 1.1 ober * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GENETEC CORPORATION
25 1.1 ober * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 1.1 ober * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 1.1 ober * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 1.1 ober * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 1.1 ober * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 1.1 ober * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 1.1 ober * POSSIBILITY OF SUCH DAMAGE.
32 1.1 ober */
33 1.1 ober
34 1.1 ober /*
35 1.1 ober * LCD driver for Sharp Zaurus (based on the Intel Lubbock driver).
36 1.1 ober *
37 1.1 ober * Controlling LCD is almost completely done through PXA2X0's
38 1.1 ober * integrated LCD controller. Codes for it is arm/xscale/pxa2x0_lcd.c.
39 1.1 ober *
40 1.1 ober * Codes in this file provide platform specific things including:
41 1.1 ober * LCD on/off switch and backlight brightness
42 1.1 ober * LCD panel geometry
43 1.1 ober */
44 1.1 ober
45 1.1 ober #include <sys/cdefs.h>
46 1.11 dyoung __KERNEL_RCSID(0, "$NetBSD: zlcd.c,v 1.11 2010/02/24 22:37:56 dyoung Exp $");
47 1.1 ober
48 1.1 ober #include <sys/param.h>
49 1.1 ober #include <sys/systm.h>
50 1.1 ober #include <sys/conf.h>
51 1.1 ober #include <sys/uio.h>
52 1.1 ober #include <sys/malloc.h>
53 1.1 ober
54 1.1 ober #include <dev/cons.h>
55 1.1 ober #include <dev/wscons/wsconsio.h>
56 1.1 ober #include <dev/wscons/wsdisplayvar.h>
57 1.1 ober #include <dev/wscons/wscons_callbacks.h>
58 1.1 ober
59 1.6 nonaka #include <dev/hpc/hpcfbio.h>
60 1.6 nonaka
61 1.1 ober #include <machine/bus.h>
62 1.1 ober #include <arm/xscale/pxa2x0var.h>
63 1.1 ober #include <arm/xscale/pxa2x0reg.h>
64 1.1 ober #include <arm/xscale/pxa2x0_lcd.h>
65 1.1 ober
66 1.1 ober #include <zaurus/dev/scoopvar.h>
67 1.1 ober #include <zaurus/dev/zsspvar.h>
68 1.1 ober #include <zaurus/zaurus/zaurus_var.h>
69 1.1 ober
70 1.1 ober /*
71 1.1 ober * wsdisplay glue
72 1.1 ober */
73 1.2 peter static struct pxa2x0_wsscreen_descr lcd_std_screen = {
74 1.2 peter .c = {
75 1.2 peter .name = "std",
76 1.2 peter .textops = &pxa2x0_lcd_emulops,
77 1.2 peter .fontwidth = 8,
78 1.2 peter .fontheight = 16,
79 1.2 peter .capabilities = WSSCREEN_WSCOLORS,
80 1.1 ober },
81 1.2 peter .depth = 16, /* bits per pixel */
82 1.4 ober .flags = RI_ROTATE_CW, /* quarter clockwise rotation */
83 1.1 ober };
84 1.1 ober
85 1.1 ober static const struct wsscreen_descr *lcd_scr_descr[] = {
86 1.2 peter &lcd_std_screen.c
87 1.1 ober };
88 1.1 ober
89 1.2 peter static const struct wsscreen_list lcd_screen_list = {
90 1.2 peter .nscreens = __arraycount(lcd_scr_descr),
91 1.2 peter .screens = lcd_scr_descr,
92 1.1 ober };
93 1.1 ober
94 1.5 christos static int lcd_ioctl(void *, void *, u_long, void *, int, struct lwp *);
95 1.2 peter static int lcd_param(struct pxa2x0_lcd_softc *, u_long,
96 1.2 peter struct wsdisplay_param *);
97 1.2 peter static int lcd_show_screen(void *, void *, int,
98 1.2 peter void (*)(void *, int, int), void *);
99 1.1 ober
100 1.2 peter struct wsdisplay_accessops lcd_accessops = {
101 1.1 ober lcd_ioctl,
102 1.1 ober pxa2x0_lcd_mmap,
103 1.1 ober pxa2x0_lcd_alloc_screen,
104 1.1 ober pxa2x0_lcd_free_screen,
105 1.1 ober lcd_show_screen,
106 1.2 peter NULL,
107 1.2 peter NULL,
108 1.2 peter NULL,
109 1.1 ober };
110 1.1 ober
111 1.1 ober #define CURRENT_DISPLAY &sharp_zaurus_C3000
112 1.1 ober
113 1.1 ober const struct lcd_panel_geometry sharp_zaurus_C3000 =
114 1.1 ober {
115 1.1 ober 480, /* Width */
116 1.1 ober 640, /* Height */
117 1.1 ober 0, /* No extra lines */
118 1.1 ober
119 1.1 ober LCDPANEL_ACTIVE | LCDPANEL_VSP | LCDPANEL_HSP,
120 1.1 ober 1, /* clock divider */
121 1.1 ober 0, /* AC bias pin freq */
122 1.1 ober
123 1.1 ober 0x28, /* horizontal sync pulse width */
124 1.1 ober 0x2e, /* BLW */
125 1.1 ober 0x7d, /* ELW */
126 1.1 ober
127 1.1 ober 2, /* vertical sync pulse width */
128 1.1 ober 1, /* BFW */
129 1.1 ober 0, /* EFW */
130 1.1 ober };
131 1.1 ober
132 1.1 ober struct sharp_lcd_backlight {
133 1.1 ober int duty; /* LZ9JG18 DAC value */
134 1.1 ober int cont; /* BACKLIGHT_CONT signal */
135 1.1 ober int on; /* BACKLIGHT_ON signal */
136 1.1 ober };
137 1.1 ober
138 1.1 ober #define CURRENT_BACKLIGHT sharp_zaurus_C3000_bl
139 1.1 ober
140 1.1 ober const struct sharp_lcd_backlight sharp_zaurus_C3000_bl[] = {
141 1.2 peter { 0x00, 0, 0 }, /* 0: Off */
142 1.2 peter { 0x00, 0, 1 }, /* 1: 0% */
143 1.2 peter { 0x01, 0, 1 }, /* 2: 20% */
144 1.2 peter { 0x07, 0, 1 }, /* 3: 40% */
145 1.2 peter { 0x01, 1, 1 }, /* 4: 60% */
146 1.2 peter { 0x07, 1, 1 }, /* 5: 80% */
147 1.2 peter { 0x11, 1, 1 }, /* 6: 100% */
148 1.2 peter { -1, -1, -1 }, /* 7: Invalid */
149 1.1 ober };
150 1.1 ober
151 1.8 nonaka static int lcd_match(device_t, cfdata_t, void *);
152 1.8 nonaka static void lcd_attach(device_t, device_t, void *);
153 1.1 ober
154 1.8 nonaka CFATTACH_DECL_NEW(zlcd, sizeof(struct pxa2x0_lcd_softc),
155 1.1 ober lcd_match, lcd_attach, NULL, NULL);
156 1.1 ober
157 1.11 dyoung static bool lcd_suspend(device_t dv, const pmf_qual_t *);
158 1.11 dyoung static bool lcd_resume(device_t dv, const pmf_qual_t *);
159 1.9 nonaka
160 1.3 nonaka void lcd_cnattach(void);
161 1.1 ober int lcd_max_brightness(void);
162 1.1 ober int lcd_get_brightness(void);
163 1.1 ober void lcd_set_brightness(int);
164 1.1 ober void lcd_set_brightness_internal(int);
165 1.1 ober int lcd_get_backlight(void);
166 1.1 ober void lcd_set_backlight(int);
167 1.1 ober void lcd_blank(int);
168 1.1 ober
169 1.1 ober static int
170 1.8 nonaka lcd_match(device_t parent, cfdata_t cf, void *aux)
171 1.1 ober {
172 1.1 ober
173 1.1 ober return 1;
174 1.1 ober }
175 1.1 ober
176 1.1 ober static void
177 1.8 nonaka lcd_attach(device_t parent, device_t self, void *aux)
178 1.1 ober {
179 1.8 nonaka struct pxa2x0_lcd_softc *sc = device_private(self);
180 1.1 ober struct wsemuldisplaydev_attach_args aa;
181 1.1 ober
182 1.8 nonaka sc->dev = self;
183 1.8 nonaka
184 1.3 nonaka pxa2x0_lcd_attach_sub(sc, aux, CURRENT_DISPLAY);
185 1.1 ober
186 1.1 ober aa.console = glass_console;
187 1.1 ober aa.scrdata = &lcd_screen_list;
188 1.1 ober aa.accessops = &lcd_accessops;
189 1.1 ober aa.accesscookie = sc;
190 1.1 ober
191 1.2 peter (void) config_found(self, &aa, wsemuldisplaydevprint);
192 1.1 ober
193 1.1 ober /* Start with approximately 40% of full brightness. */
194 1.1 ober lcd_set_brightness(3);
195 1.1 ober
196 1.9 nonaka if (!pmf_device_register(sc->dev, lcd_suspend, lcd_resume))
197 1.9 nonaka aprint_error_dev(sc->dev, "couldn't establish power handler\n");
198 1.1 ober }
199 1.1 ober
200 1.3 nonaka void
201 1.3 nonaka lcd_cnattach(void)
202 1.3 nonaka {
203 1.3 nonaka
204 1.3 nonaka pxa2x0_lcd_cnattach(&lcd_std_screen, CURRENT_DISPLAY);
205 1.3 nonaka }
206 1.3 nonaka
207 1.1 ober /*
208 1.9 nonaka * power management
209 1.9 nonaka */
210 1.9 nonaka static bool
211 1.11 dyoung lcd_suspend(device_t dv, const pmf_qual_t *qual)
212 1.9 nonaka {
213 1.9 nonaka struct pxa2x0_lcd_softc *sc = device_private(dv);
214 1.9 nonaka
215 1.9 nonaka lcd_set_brightness(0);
216 1.9 nonaka pxa2x0_lcd_suspend(sc);
217 1.9 nonaka
218 1.9 nonaka return true;
219 1.9 nonaka }
220 1.9 nonaka
221 1.9 nonaka static bool
222 1.11 dyoung lcd_resume(device_t dv, const pmf_qual_t *qual)
223 1.9 nonaka {
224 1.9 nonaka struct pxa2x0_lcd_softc *sc = device_private(dv);
225 1.9 nonaka
226 1.9 nonaka pxa2x0_lcd_resume(sc);
227 1.9 nonaka lcd_set_brightness(lcd_get_brightness());
228 1.9 nonaka
229 1.9 nonaka return true;
230 1.9 nonaka }
231 1.9 nonaka
232 1.9 nonaka /*
233 1.1 ober * wsdisplay accessops overrides
234 1.1 ober */
235 1.2 peter static int
236 1.5 christos lcd_ioctl(void *v, void *vs, u_long cmd, void *data, int flag, struct lwp *l)
237 1.1 ober {
238 1.1 ober struct pxa2x0_lcd_softc *sc = (struct pxa2x0_lcd_softc *)v;
239 1.6 nonaka struct hpcfb_fbconf *fbconf;
240 1.6 nonaka struct hpcfb_dspconf *dspconf;
241 1.1 ober int res = EINVAL;
242 1.1 ober
243 1.1 ober switch (cmd) {
244 1.1 ober case WSDISPLAYIO_GETPARAM:
245 1.1 ober case WSDISPLAYIO_SETPARAM:
246 1.1 ober res = lcd_param(sc, cmd, (struct wsdisplay_param *)data);
247 1.1 ober break;
248 1.6 nonaka
249 1.6 nonaka case HPCFBIO_GCONF:
250 1.6 nonaka fbconf = (struct hpcfb_fbconf *)data;
251 1.6 nonaka if (fbconf->hf_conf_index != 0 &&
252 1.6 nonaka fbconf->hf_conf_index != HPCFB_CURRENT_CONFIG) {
253 1.6 nonaka break;
254 1.6 nonaka }
255 1.6 nonaka
256 1.6 nonaka fbconf->hf_conf_index = 0;
257 1.6 nonaka fbconf->hf_nconfs = 1;
258 1.6 nonaka fbconf->hf_class = HPCFB_CLASS_RGBCOLOR;
259 1.6 nonaka strlcpy(fbconf->hf_name, "Sharp Zaurus frame buffer",
260 1.6 nonaka sizeof(fbconf->hf_name));
261 1.6 nonaka strlcpy(fbconf->hf_conf_name, "default",
262 1.6 nonaka sizeof(fbconf->hf_conf_name));
263 1.6 nonaka fbconf->hf_width = sc->geometry->panel_width;
264 1.6 nonaka fbconf->hf_height = sc->geometry->panel_height;
265 1.6 nonaka fbconf->hf_baseaddr = (u_long)sc->active->buf_va;
266 1.6 nonaka fbconf->hf_offset = 0;
267 1.6 nonaka fbconf->hf_bytes_per_line = sc->geometry->panel_width *
268 1.6 nonaka sc->active->depth / 8;
269 1.6 nonaka fbconf->hf_nplanes = 1;
270 1.6 nonaka fbconf->hf_bytes_per_plane = sc->geometry->panel_width *
271 1.6 nonaka sc->geometry->panel_height * sc->active->depth / 8;
272 1.6 nonaka fbconf->hf_pack_width = sc->active->depth;
273 1.6 nonaka fbconf->hf_pixels_per_pack = 1;
274 1.6 nonaka fbconf->hf_pixel_width = sc->active->depth;
275 1.6 nonaka fbconf->hf_access_flags = (0
276 1.6 nonaka | HPCFB_ACCESS_BYTE
277 1.6 nonaka | HPCFB_ACCESS_WORD
278 1.6 nonaka | HPCFB_ACCESS_DWORD);
279 1.6 nonaka fbconf->hf_order_flags = 0;
280 1.6 nonaka fbconf->hf_reg_offset = 0;
281 1.6 nonaka
282 1.6 nonaka fbconf->hf_class_data_length = sizeof(struct hf_rgb_tag);
283 1.6 nonaka fbconf->hf_u.hf_rgb.hf_flags = 0;
284 1.6 nonaka fbconf->hf_u.hf_rgb.hf_red_width = 5;
285 1.6 nonaka fbconf->hf_u.hf_rgb.hf_red_shift = 11;
286 1.6 nonaka fbconf->hf_u.hf_rgb.hf_green_width = 6;
287 1.6 nonaka fbconf->hf_u.hf_rgb.hf_green_shift = 5;
288 1.6 nonaka fbconf->hf_u.hf_rgb.hf_blue_width = 5;
289 1.6 nonaka fbconf->hf_u.hf_rgb.hf_blue_shift = 0;
290 1.6 nonaka fbconf->hf_u.hf_rgb.hf_alpha_width = 0;
291 1.6 nonaka fbconf->hf_u.hf_rgb.hf_alpha_shift = 0;
292 1.6 nonaka
293 1.6 nonaka fbconf->hf_ext_size = 0;
294 1.6 nonaka fbconf->hf_ext_data = NULL;
295 1.6 nonaka
296 1.6 nonaka res = 0;
297 1.6 nonaka break;
298 1.6 nonaka
299 1.6 nonaka case HPCFBIO_SCONF:
300 1.6 nonaka fbconf = (struct hpcfb_fbconf *)data;
301 1.6 nonaka if (fbconf->hf_conf_index != 0 &&
302 1.6 nonaka fbconf->hf_conf_index != HPCFB_CURRENT_CONFIG) {
303 1.6 nonaka break;
304 1.6 nonaka }
305 1.6 nonaka /* nothing to do because we have only one configuration */
306 1.6 nonaka res = 0;
307 1.6 nonaka break;
308 1.6 nonaka
309 1.6 nonaka case HPCFBIO_GDSPCONF:
310 1.6 nonaka dspconf = (struct hpcfb_dspconf *)data;
311 1.6 nonaka if ((dspconf->hd_unit_index != 0 &&
312 1.6 nonaka dspconf->hd_unit_index != HPCFB_CURRENT_UNIT) ||
313 1.6 nonaka (dspconf->hd_conf_index != 0 &&
314 1.6 nonaka dspconf->hd_conf_index != HPCFB_CURRENT_CONFIG)) {
315 1.6 nonaka break;
316 1.6 nonaka }
317 1.6 nonaka
318 1.6 nonaka dspconf->hd_unit_index = 0;
319 1.6 nonaka dspconf->hd_nunits = 1;
320 1.6 nonaka dspconf->hd_class = HPCFB_DSP_CLASS_COLORLCD;
321 1.6 nonaka strlcpy(dspconf->hd_name, "Sharp Zaurus LCD",
322 1.6 nonaka sizeof(dspconf->hd_name));
323 1.6 nonaka dspconf->hd_op_flags = 0;
324 1.6 nonaka dspconf->hd_conf_index = 0;
325 1.6 nonaka dspconf->hd_nconfs = 1;
326 1.6 nonaka strlcpy(dspconf->hd_conf_name, "default",
327 1.6 nonaka sizeof(dspconf->hd_conf_name));
328 1.6 nonaka dspconf->hd_width = sc->geometry->panel_width;
329 1.6 nonaka dspconf->hd_height = sc->geometry->panel_height;
330 1.6 nonaka dspconf->hd_xdpi = HPCFB_DSP_DPI_UNKNOWN;
331 1.6 nonaka dspconf->hd_ydpi = HPCFB_DSP_DPI_UNKNOWN;
332 1.6 nonaka
333 1.6 nonaka res = 0;
334 1.6 nonaka break;
335 1.6 nonaka
336 1.6 nonaka case HPCFBIO_SDSPCONF:
337 1.6 nonaka dspconf = (struct hpcfb_dspconf *)data;
338 1.6 nonaka if ((dspconf->hd_unit_index != 0 &&
339 1.6 nonaka dspconf->hd_unit_index != HPCFB_CURRENT_UNIT) ||
340 1.6 nonaka (dspconf->hd_conf_index != 0 &&
341 1.6 nonaka dspconf->hd_conf_index != HPCFB_CURRENT_CONFIG)) {
342 1.6 nonaka break;
343 1.6 nonaka }
344 1.6 nonaka /*
345 1.6 nonaka * nothing to do
346 1.6 nonaka * because we have only one unit and one configuration
347 1.6 nonaka */
348 1.6 nonaka res = 0;
349 1.6 nonaka break;
350 1.6 nonaka
351 1.6 nonaka case HPCFBIO_GOP:
352 1.6 nonaka case HPCFBIO_SOP:
353 1.6 nonaka /* curently not implemented... */
354 1.6 nonaka break;
355 1.1 ober }
356 1.1 ober
357 1.1 ober if (res == EINVAL)
358 1.1 ober res = pxa2x0_lcd_ioctl(v, vs, cmd, data, flag, l);
359 1.1 ober return res;
360 1.1 ober }
361 1.1 ober
362 1.2 peter static int
363 1.1 ober lcd_show_screen(void *v, void *cookie, int waitok,
364 1.2 peter void (*cb_func)(void *, int, int), void *cb_arg)
365 1.1 ober {
366 1.1 ober int error;
367 1.1 ober
368 1.2 peter error = pxa2x0_lcd_show_screen(v, cookie, waitok, cb_func, cb_arg);
369 1.1 ober if (error)
370 1.1 ober return (error);
371 1.1 ober
372 1.1 ober /* Turn on LCD */
373 1.2 peter lcd_set_brightness(lcd_get_brightness());
374 1.1 ober
375 1.1 ober return 0;
376 1.1 ober }
377 1.1 ober
378 1.1 ober /*
379 1.1 ober * wsdisplay I/O controls
380 1.1 ober */
381 1.2 peter static int
382 1.6 nonaka lcd_param(struct pxa2x0_lcd_softc *sc, u_long cmd, struct wsdisplay_param *dp)
383 1.1 ober {
384 1.1 ober int res = EINVAL;
385 1.1 ober
386 1.1 ober switch (dp->param) {
387 1.1 ober case WSDISPLAYIO_PARAM_BACKLIGHT:
388 1.1 ober if (cmd == WSDISPLAYIO_GETPARAM) {
389 1.1 ober dp->min = 0;
390 1.1 ober dp->max = 1;
391 1.1 ober dp->curval = lcd_get_backlight();
392 1.1 ober res = 0;
393 1.1 ober } else if (cmd == WSDISPLAYIO_SETPARAM) {
394 1.1 ober lcd_set_backlight(dp->curval);
395 1.1 ober res = 0;
396 1.1 ober }
397 1.1 ober break;
398 1.1 ober
399 1.1 ober case WSDISPLAYIO_PARAM_CONTRAST:
400 1.1 ober /* unsupported */
401 1.1 ober res = ENOTTY;
402 1.1 ober break;
403 1.1 ober
404 1.1 ober case WSDISPLAYIO_PARAM_BRIGHTNESS:
405 1.1 ober if (cmd == WSDISPLAYIO_GETPARAM) {
406 1.1 ober dp->min = 1;
407 1.1 ober dp->max = lcd_max_brightness();
408 1.1 ober dp->curval = lcd_get_brightness();
409 1.1 ober res = 0;
410 1.1 ober } else if (cmd == WSDISPLAYIO_SETPARAM) {
411 1.1 ober lcd_set_brightness(dp->curval);
412 1.1 ober res = 0;
413 1.1 ober }
414 1.1 ober break;
415 1.1 ober }
416 1.1 ober
417 1.1 ober return res;
418 1.1 ober }
419 1.1 ober
420 1.1 ober /*
421 1.1 ober * LCD backlight
422 1.1 ober */
423 1.1 ober
424 1.1 ober static int lcdbrightnesscurval = 1;
425 1.1 ober static int lcdislit = 1;
426 1.1 ober static int lcdisblank = 0;
427 1.1 ober
428 1.1 ober int
429 1.1 ober lcd_max_brightness(void)
430 1.1 ober {
431 1.1 ober int i;
432 1.1 ober
433 1.1 ober for (i = 0; CURRENT_BACKLIGHT[i].duty != -1; i++)
434 1.1 ober continue;
435 1.1 ober return i - 1;
436 1.1 ober }
437 1.1 ober
438 1.1 ober int
439 1.1 ober lcd_get_brightness(void)
440 1.1 ober {
441 1.1 ober
442 1.1 ober return lcdbrightnesscurval;
443 1.1 ober }
444 1.1 ober
445 1.1 ober void
446 1.1 ober lcd_set_brightness(int newval)
447 1.1 ober {
448 1.1 ober int maxval;
449 1.1 ober
450 1.1 ober maxval = lcd_max_brightness();
451 1.1 ober if (newval < 0)
452 1.1 ober newval = 0;
453 1.1 ober else if (newval > maxval)
454 1.1 ober newval = maxval;
455 1.1 ober
456 1.1 ober if (lcd_get_backlight() && !lcdisblank)
457 1.1 ober lcd_set_brightness_internal(newval);
458 1.1 ober
459 1.1 ober if (newval > 0)
460 1.1 ober lcdbrightnesscurval = newval;
461 1.1 ober }
462 1.1 ober
463 1.1 ober void
464 1.1 ober lcd_set_brightness_internal(int newval)
465 1.1 ober {
466 1.1 ober static int curval = 1;
467 1.1 ober int i;
468 1.1 ober
469 1.1 ober /*
470 1.1 ober * It appears that the C3000 backlight can draw too much power if we
471 1.1 ober * switch it from a low to a high brightness. Increasing brightness
472 1.1 ober * in steps avoids this issue.
473 1.1 ober */
474 1.1 ober if (newval > curval) {
475 1.1 ober for (i = curval + 1; i <= newval; i++) {
476 1.1 ober (void)zssp_ic_send(ZSSP_IC_LZ9JG18,
477 1.1 ober CURRENT_BACKLIGHT[i].duty);
478 1.1 ober scoop_set_backlight(CURRENT_BACKLIGHT[i].on,
479 1.1 ober CURRENT_BACKLIGHT[i].cont);
480 1.1 ober delay(5000);
481 1.1 ober }
482 1.1 ober } else {
483 1.1 ober (void)zssp_ic_send(ZSSP_IC_LZ9JG18,
484 1.1 ober CURRENT_BACKLIGHT[newval].duty);
485 1.1 ober scoop_set_backlight(CURRENT_BACKLIGHT[newval].on,
486 1.1 ober CURRENT_BACKLIGHT[newval].cont);
487 1.1 ober }
488 1.1 ober
489 1.1 ober curval = newval;
490 1.1 ober }
491 1.1 ober
492 1.1 ober int
493 1.1 ober lcd_get_backlight(void)
494 1.1 ober {
495 1.1 ober
496 1.1 ober return lcdislit;
497 1.1 ober }
498 1.1 ober
499 1.1 ober void
500 1.2 peter lcd_set_backlight(int onoff)
501 1.1 ober {
502 1.1 ober
503 1.2 peter if (!onoff) {
504 1.1 ober lcd_set_brightness(0);
505 1.1 ober lcdislit = 0;
506 1.1 ober } else {
507 1.1 ober lcdislit = 1;
508 1.1 ober lcd_set_brightness(lcd_get_brightness());
509 1.1 ober }
510 1.1 ober }
511 1.1 ober
512 1.1 ober void
513 1.1 ober lcd_blank(int blank)
514 1.1 ober {
515 1.1 ober
516 1.1 ober if (blank) {
517 1.1 ober lcd_set_brightness(0);
518 1.1 ober lcdisblank = 1;
519 1.1 ober } else {
520 1.1 ober lcdisblank = 0;
521 1.1 ober lcd_set_brightness(lcd_get_brightness());
522 1.1 ober }
523 1.1 ober }
524