zlcd.c revision 1.16 1 1.16 tsutsui /* $NetBSD: zlcd.c,v 1.16 2012/01/25 16:51:17 tsutsui 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.16 tsutsui __KERNEL_RCSID(0, "$NetBSD: zlcd.c,v 1.16 2012/01/25 16:51:17 tsutsui Exp $");
47 1.16 tsutsui
48 1.16 tsutsui #include "lcdctl.h"
49 1.1 ober
50 1.1 ober #include <sys/param.h>
51 1.1 ober #include <sys/systm.h>
52 1.16 tsutsui #include <sys/device.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
58 1.6 nonaka #include <dev/hpc/hpcfbio.h>
59 1.6 nonaka
60 1.1 ober #include <arm/xscale/pxa2x0var.h>
61 1.1 ober #include <arm/xscale/pxa2x0_lcd.h>
62 1.1 ober
63 1.12 nonaka #include <zaurus/zaurus/zaurus_var.h>
64 1.12 nonaka #include <zaurus/dev/zlcdvar.h>
65 1.16 tsutsui #if NLCDCTL > 0
66 1.16 tsutsui #include <zaurus/dev/lcdctlvar.h>
67 1.16 tsutsui #endif
68 1.1 ober
69 1.1 ober /*
70 1.1 ober * wsdisplay glue
71 1.1 ober */
72 1.2 peter static struct pxa2x0_wsscreen_descr lcd_std_screen = {
73 1.2 peter .c = {
74 1.2 peter .name = "std",
75 1.2 peter .textops = &pxa2x0_lcd_emulops,
76 1.2 peter .fontwidth = 8,
77 1.2 peter .fontheight = 16,
78 1.2 peter .capabilities = WSSCREEN_WSCOLORS,
79 1.1 ober },
80 1.2 peter .depth = 16, /* bits per pixel */
81 1.4 ober .flags = RI_ROTATE_CW, /* quarter clockwise rotation */
82 1.1 ober };
83 1.1 ober
84 1.1 ober static const struct wsscreen_descr *lcd_scr_descr[] = {
85 1.2 peter &lcd_std_screen.c
86 1.1 ober };
87 1.1 ober
88 1.2 peter static const struct wsscreen_list lcd_screen_list = {
89 1.2 peter .nscreens = __arraycount(lcd_scr_descr),
90 1.2 peter .screens = lcd_scr_descr,
91 1.1 ober };
92 1.1 ober
93 1.5 christos static int lcd_ioctl(void *, void *, u_long, void *, int, struct lwp *);
94 1.2 peter static int lcd_show_screen(void *, void *, int,
95 1.2 peter void (*)(void *, int, int), void *);
96 1.1 ober
97 1.2 peter struct wsdisplay_accessops lcd_accessops = {
98 1.1 ober lcd_ioctl,
99 1.1 ober pxa2x0_lcd_mmap,
100 1.1 ober pxa2x0_lcd_alloc_screen,
101 1.1 ober pxa2x0_lcd_free_screen,
102 1.1 ober lcd_show_screen,
103 1.2 peter NULL,
104 1.2 peter NULL,
105 1.2 peter NULL,
106 1.1 ober };
107 1.1 ober
108 1.16 tsutsui const struct lcd_panel_geometry lcd_panel_geometry_c3000 =
109 1.1 ober {
110 1.1 ober 480, /* Width */
111 1.1 ober 640, /* Height */
112 1.1 ober 0, /* No extra lines */
113 1.1 ober
114 1.1 ober LCDPANEL_ACTIVE | LCDPANEL_VSP | LCDPANEL_HSP,
115 1.1 ober 1, /* clock divider */
116 1.1 ober 0, /* AC bias pin freq */
117 1.1 ober
118 1.1 ober 0x28, /* horizontal sync pulse width */
119 1.1 ober 0x2e, /* BLW */
120 1.1 ober 0x7d, /* ELW */
121 1.1 ober
122 1.1 ober 2, /* vertical sync pulse width */
123 1.1 ober 1, /* BFW */
124 1.1 ober 0, /* EFW */
125 1.1 ober };
126 1.1 ober
127 1.8 nonaka static int lcd_match(device_t, cfdata_t, void *);
128 1.8 nonaka static void lcd_attach(device_t, device_t, void *);
129 1.1 ober
130 1.8 nonaka CFATTACH_DECL_NEW(zlcd, sizeof(struct pxa2x0_lcd_softc),
131 1.1 ober lcd_match, lcd_attach, NULL, NULL);
132 1.1 ober
133 1.12 nonaka static bool lcd_suspend(device_t, const pmf_qual_t *);
134 1.12 nonaka static bool lcd_resume(device_t, const pmf_qual_t *);
135 1.1 ober
136 1.1 ober static int
137 1.8 nonaka lcd_match(device_t parent, cfdata_t cf, void *aux)
138 1.1 ober {
139 1.1 ober
140 1.12 nonaka if (ZAURUS_ISC1000 || ZAURUS_ISC3000)
141 1.12 nonaka return 1;
142 1.12 nonaka return 0;
143 1.1 ober }
144 1.1 ober
145 1.1 ober static void
146 1.8 nonaka lcd_attach(device_t parent, device_t self, void *aux)
147 1.1 ober {
148 1.8 nonaka struct pxa2x0_lcd_softc *sc = device_private(self);
149 1.1 ober struct wsemuldisplaydev_attach_args aa;
150 1.1 ober
151 1.8 nonaka sc->dev = self;
152 1.8 nonaka
153 1.16 tsutsui pxa2x0_lcd_attach_sub(sc, aux, &lcd_panel_geometry_c3000);
154 1.1 ober
155 1.1 ober aa.console = glass_console;
156 1.1 ober aa.scrdata = &lcd_screen_list;
157 1.1 ober aa.accessops = &lcd_accessops;
158 1.1 ober aa.accesscookie = sc;
159 1.1 ober
160 1.2 peter (void) config_found(self, &aa, wsemuldisplaydevprint);
161 1.1 ober
162 1.12 nonaka if (!pmf_device_register(self, lcd_suspend, lcd_resume))
163 1.12 nonaka aprint_error_dev(self, "couldn't establish power handler\n");
164 1.1 ober }
165 1.1 ober
166 1.3 nonaka void
167 1.3 nonaka lcd_cnattach(void)
168 1.3 nonaka {
169 1.3 nonaka
170 1.16 tsutsui pxa2x0_lcd_cnattach(&lcd_std_screen, &lcd_panel_geometry_c3000);
171 1.3 nonaka }
172 1.3 nonaka
173 1.1 ober /*
174 1.9 nonaka * power management
175 1.9 nonaka */
176 1.9 nonaka static bool
177 1.11 dyoung lcd_suspend(device_t dv, const pmf_qual_t *qual)
178 1.9 nonaka {
179 1.9 nonaka struct pxa2x0_lcd_softc *sc = device_private(dv);
180 1.9 nonaka
181 1.16 tsutsui #if NLCDCTL > 0
182 1.16 tsutsui lcdctl_onoff(false);
183 1.16 tsutsui #endif
184 1.9 nonaka pxa2x0_lcd_suspend(sc);
185 1.9 nonaka
186 1.9 nonaka return true;
187 1.9 nonaka }
188 1.9 nonaka
189 1.9 nonaka static bool
190 1.11 dyoung lcd_resume(device_t dv, const pmf_qual_t *qual)
191 1.9 nonaka {
192 1.9 nonaka struct pxa2x0_lcd_softc *sc = device_private(dv);
193 1.9 nonaka
194 1.9 nonaka pxa2x0_lcd_resume(sc);
195 1.16 tsutsui #if NLCDCTL > 0
196 1.16 tsutsui lcdctl_onoff(true);
197 1.16 tsutsui #endif
198 1.9 nonaka
199 1.9 nonaka return true;
200 1.9 nonaka }
201 1.9 nonaka
202 1.9 nonaka /*
203 1.1 ober * wsdisplay accessops overrides
204 1.1 ober */
205 1.2 peter static int
206 1.5 christos lcd_ioctl(void *v, void *vs, u_long cmd, void *data, int flag, struct lwp *l)
207 1.1 ober {
208 1.1 ober struct pxa2x0_lcd_softc *sc = (struct pxa2x0_lcd_softc *)v;
209 1.6 nonaka struct hpcfb_fbconf *fbconf;
210 1.6 nonaka struct hpcfb_dspconf *dspconf;
211 1.1 ober int res = EINVAL;
212 1.1 ober
213 1.1 ober switch (cmd) {
214 1.16 tsutsui #if NLCDCTL > 0
215 1.1 ober case WSDISPLAYIO_GETPARAM:
216 1.1 ober case WSDISPLAYIO_SETPARAM:
217 1.16 tsutsui res = lcdctl_param(cmd, (struct wsdisplay_param *)data);
218 1.1 ober break;
219 1.16 tsutsui #endif
220 1.6 nonaka
221 1.6 nonaka case HPCFBIO_GCONF:
222 1.6 nonaka fbconf = (struct hpcfb_fbconf *)data;
223 1.6 nonaka if (fbconf->hf_conf_index != 0 &&
224 1.6 nonaka fbconf->hf_conf_index != HPCFB_CURRENT_CONFIG) {
225 1.6 nonaka break;
226 1.6 nonaka }
227 1.6 nonaka
228 1.6 nonaka fbconf->hf_conf_index = 0;
229 1.6 nonaka fbconf->hf_nconfs = 1;
230 1.6 nonaka fbconf->hf_class = HPCFB_CLASS_RGBCOLOR;
231 1.6 nonaka strlcpy(fbconf->hf_name, "Sharp Zaurus frame buffer",
232 1.6 nonaka sizeof(fbconf->hf_name));
233 1.6 nonaka strlcpy(fbconf->hf_conf_name, "default",
234 1.6 nonaka sizeof(fbconf->hf_conf_name));
235 1.6 nonaka fbconf->hf_width = sc->geometry->panel_width;
236 1.6 nonaka fbconf->hf_height = sc->geometry->panel_height;
237 1.6 nonaka fbconf->hf_baseaddr = (u_long)sc->active->buf_va;
238 1.6 nonaka fbconf->hf_offset = 0;
239 1.6 nonaka fbconf->hf_bytes_per_line = sc->geometry->panel_width *
240 1.6 nonaka sc->active->depth / 8;
241 1.6 nonaka fbconf->hf_nplanes = 1;
242 1.6 nonaka fbconf->hf_bytes_per_plane = sc->geometry->panel_width *
243 1.6 nonaka sc->geometry->panel_height * sc->active->depth / 8;
244 1.6 nonaka fbconf->hf_pack_width = sc->active->depth;
245 1.6 nonaka fbconf->hf_pixels_per_pack = 1;
246 1.6 nonaka fbconf->hf_pixel_width = sc->active->depth;
247 1.6 nonaka fbconf->hf_access_flags = (0
248 1.6 nonaka | HPCFB_ACCESS_BYTE
249 1.6 nonaka | HPCFB_ACCESS_WORD
250 1.6 nonaka | HPCFB_ACCESS_DWORD);
251 1.6 nonaka fbconf->hf_order_flags = 0;
252 1.6 nonaka fbconf->hf_reg_offset = 0;
253 1.6 nonaka
254 1.6 nonaka fbconf->hf_class_data_length = sizeof(struct hf_rgb_tag);
255 1.6 nonaka fbconf->hf_u.hf_rgb.hf_flags = 0;
256 1.6 nonaka fbconf->hf_u.hf_rgb.hf_red_width = 5;
257 1.6 nonaka fbconf->hf_u.hf_rgb.hf_red_shift = 11;
258 1.6 nonaka fbconf->hf_u.hf_rgb.hf_green_width = 6;
259 1.6 nonaka fbconf->hf_u.hf_rgb.hf_green_shift = 5;
260 1.6 nonaka fbconf->hf_u.hf_rgb.hf_blue_width = 5;
261 1.6 nonaka fbconf->hf_u.hf_rgb.hf_blue_shift = 0;
262 1.6 nonaka fbconf->hf_u.hf_rgb.hf_alpha_width = 0;
263 1.6 nonaka fbconf->hf_u.hf_rgb.hf_alpha_shift = 0;
264 1.6 nonaka
265 1.6 nonaka fbconf->hf_ext_size = 0;
266 1.6 nonaka fbconf->hf_ext_data = NULL;
267 1.6 nonaka
268 1.6 nonaka res = 0;
269 1.6 nonaka break;
270 1.6 nonaka
271 1.6 nonaka case HPCFBIO_SCONF:
272 1.6 nonaka fbconf = (struct hpcfb_fbconf *)data;
273 1.6 nonaka if (fbconf->hf_conf_index != 0 &&
274 1.6 nonaka fbconf->hf_conf_index != HPCFB_CURRENT_CONFIG) {
275 1.6 nonaka break;
276 1.6 nonaka }
277 1.6 nonaka /* nothing to do because we have only one configuration */
278 1.6 nonaka res = 0;
279 1.6 nonaka break;
280 1.6 nonaka
281 1.6 nonaka case HPCFBIO_GDSPCONF:
282 1.6 nonaka dspconf = (struct hpcfb_dspconf *)data;
283 1.6 nonaka if ((dspconf->hd_unit_index != 0 &&
284 1.6 nonaka dspconf->hd_unit_index != HPCFB_CURRENT_UNIT) ||
285 1.6 nonaka (dspconf->hd_conf_index != 0 &&
286 1.6 nonaka dspconf->hd_conf_index != HPCFB_CURRENT_CONFIG)) {
287 1.6 nonaka break;
288 1.6 nonaka }
289 1.6 nonaka
290 1.6 nonaka dspconf->hd_unit_index = 0;
291 1.6 nonaka dspconf->hd_nunits = 1;
292 1.6 nonaka dspconf->hd_class = HPCFB_DSP_CLASS_COLORLCD;
293 1.6 nonaka strlcpy(dspconf->hd_name, "Sharp Zaurus LCD",
294 1.6 nonaka sizeof(dspconf->hd_name));
295 1.6 nonaka dspconf->hd_op_flags = 0;
296 1.6 nonaka dspconf->hd_conf_index = 0;
297 1.6 nonaka dspconf->hd_nconfs = 1;
298 1.6 nonaka strlcpy(dspconf->hd_conf_name, "default",
299 1.6 nonaka sizeof(dspconf->hd_conf_name));
300 1.6 nonaka dspconf->hd_width = sc->geometry->panel_width;
301 1.6 nonaka dspconf->hd_height = sc->geometry->panel_height;
302 1.6 nonaka dspconf->hd_xdpi = HPCFB_DSP_DPI_UNKNOWN;
303 1.6 nonaka dspconf->hd_ydpi = HPCFB_DSP_DPI_UNKNOWN;
304 1.6 nonaka
305 1.6 nonaka res = 0;
306 1.6 nonaka break;
307 1.6 nonaka
308 1.6 nonaka case HPCFBIO_SDSPCONF:
309 1.6 nonaka dspconf = (struct hpcfb_dspconf *)data;
310 1.6 nonaka if ((dspconf->hd_unit_index != 0 &&
311 1.6 nonaka dspconf->hd_unit_index != HPCFB_CURRENT_UNIT) ||
312 1.6 nonaka (dspconf->hd_conf_index != 0 &&
313 1.6 nonaka dspconf->hd_conf_index != HPCFB_CURRENT_CONFIG)) {
314 1.6 nonaka break;
315 1.6 nonaka }
316 1.6 nonaka /*
317 1.6 nonaka * nothing to do
318 1.6 nonaka * because we have only one unit and one configuration
319 1.6 nonaka */
320 1.6 nonaka res = 0;
321 1.6 nonaka break;
322 1.6 nonaka
323 1.6 nonaka case HPCFBIO_GOP:
324 1.6 nonaka case HPCFBIO_SOP:
325 1.6 nonaka /* curently not implemented... */
326 1.6 nonaka break;
327 1.1 ober }
328 1.1 ober
329 1.1 ober if (res == EINVAL)
330 1.1 ober res = pxa2x0_lcd_ioctl(v, vs, cmd, data, flag, l);
331 1.1 ober return res;
332 1.1 ober }
333 1.1 ober
334 1.2 peter static int
335 1.1 ober lcd_show_screen(void *v, void *cookie, int waitok,
336 1.2 peter void (*cb_func)(void *, int, int), void *cb_arg)
337 1.1 ober {
338 1.1 ober int error;
339 1.1 ober
340 1.2 peter error = pxa2x0_lcd_show_screen(v, cookie, waitok, cb_func, cb_arg);
341 1.1 ober if (error)
342 1.1 ober return (error);
343 1.1 ober
344 1.16 tsutsui #if NLCDCTL > 0
345 1.1 ober /* Turn on LCD */
346 1.16 tsutsui lcdctl_onoff(true);
347 1.16 tsutsui #endif
348 1.1 ober
349 1.1 ober return 0;
350 1.1 ober }
351