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