zlcd.c revision 1.1 1 1.1 ober /* $NetBSD: zlcd.c,v 1.1 2006/12/16 05:23:06 ober 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.1 ober __KERNEL_RCSID(0, "$NetBSD: zlcd.c,v 1.1 2006/12/16 05:23:06 ober 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.1 ober #include <machine/bus.h>
60 1.1 ober #include <arm/xscale/pxa2x0var.h>
61 1.1 ober #include <arm/xscale/pxa2x0reg.h>
62 1.1 ober #include <arm/xscale/pxa2x0_lcd.h>
63 1.1 ober
64 1.1 ober #include <zaurus/dev/scoopvar.h>
65 1.1 ober #include <zaurus/dev/zsspvar.h>
66 1.1 ober #include <zaurus/zaurus/zaurus_var.h>
67 1.1 ober
68 1.1 ober /*
69 1.1 ober * wsdisplay glue
70 1.1 ober */
71 1.1 ober struct pxa2x0_wsscreen_descr lcd_bpp16_screen = {
72 1.1 ober {
73 1.1 ober "std"
74 1.1 ober },
75 1.1 ober 16, /* bits per pixel */
76 1.1 ober 0/*RI_ROTATE_CW*/ /* quarter clockwise rotation */
77 1.1 ober };
78 1.1 ober
79 1.1 ober static const struct wsscreen_descr *lcd_scr_descr[] = {
80 1.1 ober &lcd_bpp16_screen.c
81 1.1 ober };
82 1.1 ober
83 1.1 ober const struct wsscreen_list lcd_screen_list = {
84 1.1 ober sizeof lcd_scr_descr / sizeof lcd_scr_descr[0], lcd_scr_descr
85 1.1 ober };
86 1.1 ober
87 1.1 ober int lcd_ioctl(void *, void *, u_long, caddr_t, int, struct lwp *);
88 1.1 ober int lcd_param(struct pxa2x0_lcd_softc *, u_long,
89 1.1 ober struct wsdisplay_param *);
90 1.1 ober int lcd_show_screen(void *, void *, int,
91 1.1 ober void (*)(void *, int, int), void *);
92 1.1 ober void lcd_burner(void *, u_int, u_int);
93 1.1 ober
94 1.1 ober const struct wsdisplay_accessops lcd_accessops = {
95 1.1 ober lcd_ioctl,
96 1.1 ober pxa2x0_lcd_mmap,
97 1.1 ober pxa2x0_lcd_alloc_screen,
98 1.1 ober pxa2x0_lcd_free_screen,
99 1.1 ober lcd_show_screen,
100 1.1 ober NULL, /* load_font */
101 1.1 ober NULL, /* pollc */
102 1.1 ober NULL, /* scroll */
103 1.1 ober };
104 1.1 ober
105 1.1 ober #define CURRENT_DISPLAY &sharp_zaurus_C3000
106 1.1 ober
107 1.1 ober const struct lcd_panel_geometry sharp_zaurus_C3000 =
108 1.1 ober {
109 1.1 ober 480, /* Width */
110 1.1 ober 640, /* Height */
111 1.1 ober 0, /* No extra lines */
112 1.1 ober
113 1.1 ober LCDPANEL_ACTIVE | LCDPANEL_VSP | LCDPANEL_HSP,
114 1.1 ober 1, /* clock divider */
115 1.1 ober 0, /* AC bias pin freq */
116 1.1 ober
117 1.1 ober 0x28, /* horizontal sync pulse width */
118 1.1 ober 0x2e, /* BLW */
119 1.1 ober 0x7d, /* ELW */
120 1.1 ober
121 1.1 ober 2, /* vertical sync pulse width */
122 1.1 ober 1, /* BFW */
123 1.1 ober 0, /* EFW */
124 1.1 ober };
125 1.1 ober
126 1.1 ober struct sharp_lcd_backlight {
127 1.1 ober int duty; /* LZ9JG18 DAC value */
128 1.1 ober int cont; /* BACKLIGHT_CONT signal */
129 1.1 ober int on; /* BACKLIGHT_ON signal */
130 1.1 ober };
131 1.1 ober
132 1.1 ober #define CURRENT_BACKLIGHT sharp_zaurus_C3000_bl
133 1.1 ober
134 1.1 ober const struct sharp_lcd_backlight sharp_zaurus_C3000_bl[] = {
135 1.1 ober { 0x00, 0, 0 }, /* 0: Off */
136 1.1 ober { 0x00, 0, 1 }, /* 1: 0% */
137 1.1 ober { 0x01, 0, 1 }, /* 2: 20% */
138 1.1 ober { 0x07, 0, 1 }, /* 3: 40% */
139 1.1 ober { 0x01, 1, 1 }, /* 4: 60% */
140 1.1 ober { 0x07, 1, 1 }, /* 5: 80% */
141 1.1 ober { 0x11, 1, 1 }, /* 6: 100% */
142 1.1 ober { -1, -1, -1 } /* 7: Invalid */
143 1.1 ober };
144 1.1 ober
145 1.1 ober static int lcd_match(struct device *, struct cfdata *, void *);
146 1.1 ober static void lcd_attach(struct device *, struct device *, void *);
147 1.1 ober int lcd_cnattach(void);
148 1.1 ober
149 1.1 ober CFATTACH_DECL(zlcd, sizeof(struct pxa2x0_lcd_softc),
150 1.1 ober lcd_match, lcd_attach, NULL, NULL);
151 1.1 ober
152 1.1 ober int lcd_max_brightness(void);
153 1.1 ober int lcd_get_brightness(void);
154 1.1 ober void lcd_set_brightness(int);
155 1.1 ober void lcd_set_brightness_internal(int);
156 1.1 ober int lcd_get_backlight(void);
157 1.1 ober void lcd_set_backlight(int);
158 1.1 ober void lcd_blank(int);
159 1.1 ober void lcd_power(int, void *);
160 1.1 ober
161 1.1 ober static int
162 1.1 ober lcd_match(struct device *parent, struct cfdata *cf, void *aux)
163 1.1 ober {
164 1.1 ober
165 1.1 ober return 1;
166 1.1 ober }
167 1.1 ober
168 1.1 ober static void
169 1.1 ober lcd_attach(struct device *parent, struct device *self, void *aux)
170 1.1 ober {
171 1.1 ober struct pxa2x0_lcd_softc *sc = (struct pxa2x0_lcd_softc *)self;
172 1.1 ober struct wsemuldisplaydev_attach_args aa;
173 1.1 ober
174 1.1 ober printf("\n");
175 1.1 ober
176 1.1 ober pxa2x0_lcd_attach_sub(sc, aux, &lcd_bpp16_screen, CURRENT_DISPLAY,
177 1.1 ober glass_console);
178 1.1 ober
179 1.1 ober aa.console = glass_console;
180 1.1 ober aa.scrdata = &lcd_screen_list;
181 1.1 ober aa.accessops = &lcd_accessops;
182 1.1 ober aa.accesscookie = sc;
183 1.1 ober
184 1.1 ober (void)config_found(self, &aa, wsemuldisplaydevprint);
185 1.1 ober
186 1.1 ober /* Start with approximately 40% of full brightness. */
187 1.1 ober lcd_set_brightness(3);
188 1.1 ober
189 1.1 ober (void)powerhook_establish(sc->dev.dv_xname, lcd_power, sc);
190 1.1 ober }
191 1.1 ober
192 1.1 ober int
193 1.1 ober lcd_cnattach(void)
194 1.1 ober {
195 1.1 ober
196 1.1 ober return pxa2x0_lcd_cnattach(&lcd_bpp16_screen, CURRENT_DISPLAY);
197 1.1 ober }
198 1.1 ober
199 1.1 ober /*
200 1.1 ober * wsdisplay accessops overrides
201 1.1 ober */
202 1.1 ober int
203 1.1 ober lcd_ioctl(void *v, void *vs, u_long cmd, caddr_t data, int flag, struct lwp *l)
204 1.1 ober {
205 1.1 ober struct pxa2x0_lcd_softc *sc = (struct pxa2x0_lcd_softc *)v;
206 1.1 ober int res = EINVAL;
207 1.1 ober
208 1.1 ober switch (cmd) {
209 1.1 ober case WSDISPLAYIO_GETPARAM:
210 1.1 ober case WSDISPLAYIO_SETPARAM:
211 1.1 ober res = lcd_param(sc, cmd, (struct wsdisplay_param *)data);
212 1.1 ober break;
213 1.1 ober }
214 1.1 ober
215 1.1 ober if (res == EINVAL)
216 1.1 ober res = pxa2x0_lcd_ioctl(v, vs, cmd, data, flag, l);
217 1.1 ober return res;
218 1.1 ober }
219 1.1 ober
220 1.1 ober void
221 1.1 ober lcd_burner(void *v, u_int on, u_int flags)
222 1.1 ober {
223 1.1 ober
224 1.1 ober lcd_set_brightness(on ? lcd_get_brightness() : 0);
225 1.1 ober }
226 1.1 ober
227 1.1 ober int
228 1.1 ober lcd_show_screen(void *v, void *cookie, int waitok,
229 1.1 ober void (*cb)(void *, int, int), void *cbarg)
230 1.1 ober {
231 1.1 ober int error;
232 1.1 ober
233 1.1 ober error = pxa2x0_lcd_show_screen(v, cookie, waitok, cb, cbarg);
234 1.1 ober if (error)
235 1.1 ober return (error);
236 1.1 ober
237 1.1 ober /* Turn on LCD */
238 1.1 ober lcd_burner(v, 1, 0);
239 1.1 ober
240 1.1 ober return 0;
241 1.1 ober }
242 1.1 ober
243 1.1 ober /*
244 1.1 ober * wsdisplay I/O controls
245 1.1 ober */
246 1.1 ober int
247 1.1 ober lcd_param(struct pxa2x0_lcd_softc *sc, u_long cmd,
248 1.1 ober struct wsdisplay_param *dp)
249 1.1 ober {
250 1.1 ober int res = EINVAL;
251 1.1 ober
252 1.1 ober switch (dp->param) {
253 1.1 ober case WSDISPLAYIO_PARAM_BACKLIGHT:
254 1.1 ober if (cmd == WSDISPLAYIO_GETPARAM) {
255 1.1 ober dp->min = 0;
256 1.1 ober dp->max = 1;
257 1.1 ober dp->curval = lcd_get_backlight();
258 1.1 ober res = 0;
259 1.1 ober } else if (cmd == WSDISPLAYIO_SETPARAM) {
260 1.1 ober lcd_set_backlight(dp->curval);
261 1.1 ober res = 0;
262 1.1 ober }
263 1.1 ober break;
264 1.1 ober
265 1.1 ober case WSDISPLAYIO_PARAM_CONTRAST:
266 1.1 ober /* unsupported */
267 1.1 ober res = ENOTTY;
268 1.1 ober break;
269 1.1 ober
270 1.1 ober case WSDISPLAYIO_PARAM_BRIGHTNESS:
271 1.1 ober if (cmd == WSDISPLAYIO_GETPARAM) {
272 1.1 ober dp->min = 1;
273 1.1 ober dp->max = lcd_max_brightness();
274 1.1 ober dp->curval = lcd_get_brightness();
275 1.1 ober res = 0;
276 1.1 ober } else if (cmd == WSDISPLAYIO_SETPARAM) {
277 1.1 ober lcd_set_brightness(dp->curval);
278 1.1 ober res = 0;
279 1.1 ober }
280 1.1 ober break;
281 1.1 ober }
282 1.1 ober
283 1.1 ober return res;
284 1.1 ober }
285 1.1 ober
286 1.1 ober /*
287 1.1 ober * LCD backlight
288 1.1 ober */
289 1.1 ober
290 1.1 ober static int lcdbrightnesscurval = 1;
291 1.1 ober static int lcdislit = 1;
292 1.1 ober static int lcdisblank = 0;
293 1.1 ober
294 1.1 ober int
295 1.1 ober lcd_max_brightness(void)
296 1.1 ober {
297 1.1 ober int i;
298 1.1 ober
299 1.1 ober for (i = 0; CURRENT_BACKLIGHT[i].duty != -1; i++)
300 1.1 ober continue;
301 1.1 ober return i - 1;
302 1.1 ober }
303 1.1 ober
304 1.1 ober int
305 1.1 ober lcd_get_brightness(void)
306 1.1 ober {
307 1.1 ober
308 1.1 ober return lcdbrightnesscurval;
309 1.1 ober }
310 1.1 ober
311 1.1 ober void
312 1.1 ober lcd_set_brightness(int newval)
313 1.1 ober {
314 1.1 ober int maxval;
315 1.1 ober
316 1.1 ober maxval = lcd_max_brightness();
317 1.1 ober if (newval < 0)
318 1.1 ober newval = 0;
319 1.1 ober else if (newval > maxval)
320 1.1 ober newval = maxval;
321 1.1 ober
322 1.1 ober if (lcd_get_backlight() && !lcdisblank)
323 1.1 ober lcd_set_brightness_internal(newval);
324 1.1 ober
325 1.1 ober if (newval > 0)
326 1.1 ober lcdbrightnesscurval = newval;
327 1.1 ober }
328 1.1 ober
329 1.1 ober void
330 1.1 ober lcd_set_brightness_internal(int newval)
331 1.1 ober {
332 1.1 ober static int curval = 1;
333 1.1 ober int i;
334 1.1 ober
335 1.1 ober /*
336 1.1 ober * It appears that the C3000 backlight can draw too much power if we
337 1.1 ober * switch it from a low to a high brightness. Increasing brightness
338 1.1 ober * in steps avoids this issue.
339 1.1 ober */
340 1.1 ober if (newval > curval) {
341 1.1 ober for (i = curval + 1; i <= newval; i++) {
342 1.1 ober (void)zssp_ic_send(ZSSP_IC_LZ9JG18,
343 1.1 ober CURRENT_BACKLIGHT[i].duty);
344 1.1 ober scoop_set_backlight(CURRENT_BACKLIGHT[i].on,
345 1.1 ober CURRENT_BACKLIGHT[i].cont);
346 1.1 ober delay(5000);
347 1.1 ober }
348 1.1 ober } else {
349 1.1 ober (void)zssp_ic_send(ZSSP_IC_LZ9JG18,
350 1.1 ober CURRENT_BACKLIGHT[newval].duty);
351 1.1 ober scoop_set_backlight(CURRENT_BACKLIGHT[newval].on,
352 1.1 ober CURRENT_BACKLIGHT[newval].cont);
353 1.1 ober }
354 1.1 ober
355 1.1 ober curval = newval;
356 1.1 ober }
357 1.1 ober
358 1.1 ober int
359 1.1 ober lcd_get_backlight(void)
360 1.1 ober {
361 1.1 ober
362 1.1 ober return lcdislit;
363 1.1 ober }
364 1.1 ober
365 1.1 ober void
366 1.1 ober lcd_set_backlight(int on)
367 1.1 ober {
368 1.1 ober
369 1.1 ober if (!on) {
370 1.1 ober lcd_set_brightness(0);
371 1.1 ober lcdislit = 0;
372 1.1 ober } else {
373 1.1 ober lcdislit = 1;
374 1.1 ober lcd_set_brightness(lcd_get_brightness());
375 1.1 ober }
376 1.1 ober }
377 1.1 ober
378 1.1 ober void
379 1.1 ober lcd_blank(int blank)
380 1.1 ober {
381 1.1 ober
382 1.1 ober if (blank) {
383 1.1 ober lcd_set_brightness(0);
384 1.1 ober lcdisblank = 1;
385 1.1 ober } else {
386 1.1 ober lcdisblank = 0;
387 1.1 ober lcd_set_brightness(lcd_get_brightness());
388 1.1 ober }
389 1.1 ober }
390 1.1 ober
391 1.1 ober void
392 1.1 ober lcd_power(int why, void *v)
393 1.1 ober {
394 1.1 ober
395 1.1 ober switch (why) {
396 1.1 ober case PWR_SUSPEND:
397 1.1 ober case PWR_STANDBY:
398 1.1 ober lcd_set_brightness(0);
399 1.1 ober pxa2x0_lcd_power(why, v);
400 1.1 ober break;
401 1.1 ober
402 1.1 ober case PWR_RESUME:
403 1.1 ober pxa2x0_lcd_power(why, v);
404 1.1 ober lcd_set_brightness(lcd_get_brightness());
405 1.1 ober break;
406 1.1 ober }
407 1.1 ober }
408