w100lcd.c revision 1.2.4.2 1 1.2.4.2 mrg /* $NetBSD: w100lcd.c,v 1.2.4.2 2012/02/18 07:33:49 mrg Exp $ */
2 1.2.4.2 mrg /*
3 1.2.4.2 mrg * Copyright (c) 2002, 2003 Genetec Corporation. All rights reserved.
4 1.2.4.2 mrg * Written by Hiroyuki Bessho for Genetec Corporation.
5 1.2.4.2 mrg *
6 1.2.4.2 mrg * Redistribution and use in source and binary forms, with or without
7 1.2.4.2 mrg * modification, are permitted provided that the following conditions
8 1.2.4.2 mrg * are met:
9 1.2.4.2 mrg * 1. Redistributions of source code must retain the above copyright
10 1.2.4.2 mrg * notice, this list of conditions and the following disclaimer.
11 1.2.4.2 mrg * 2. Redistributions in binary form must reproduce the above copyright
12 1.2.4.2 mrg * notice, this list of conditions and the following disclaimer in the
13 1.2.4.2 mrg * documentation and/or other materials provided with the distribution.
14 1.2.4.2 mrg * 3. The name of Genetec Corporation may not be used to endorse or
15 1.2.4.2 mrg * promote products derived from this software without specific prior
16 1.2.4.2 mrg * written permission.
17 1.2.4.2 mrg *
18 1.2.4.2 mrg * THIS SOFTWARE IS PROVIDED BY GENETEC CORPORATION ``AS IS'' AND
19 1.2.4.2 mrg * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20 1.2.4.2 mrg * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 1.2.4.2 mrg * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GENETEC CORPORATION
22 1.2.4.2 mrg * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 1.2.4.2 mrg * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 1.2.4.2 mrg * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 1.2.4.2 mrg * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 1.2.4.2 mrg * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 1.2.4.2 mrg * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 1.2.4.2 mrg * POSSIBILITY OF SUCH DAMAGE.
29 1.2.4.2 mrg */
30 1.2.4.2 mrg
31 1.2.4.2 mrg /*
32 1.2.4.2 mrg * LCD driver for Sharp Zaurus SL-C7x0/860, based on zlcd.c.
33 1.2.4.2 mrg *
34 1.2.4.2 mrg * Controlling LCD is done in w100.c.
35 1.2.4.2 mrg *
36 1.2.4.2 mrg * Codes in this file provide platform specific things including:
37 1.2.4.2 mrg * LCD panel geometry
38 1.2.4.2 mrg *
39 1.2.4.2 mrg * LCD on/off switch and backlight brightness are done in lcdctl.c.
40 1.2.4.2 mrg */
41 1.2.4.2 mrg #include <sys/cdefs.h>
42 1.2.4.2 mrg __KERNEL_RCSID(0, "$NetBSD: w100lcd.c,v 1.2.4.2 2012/02/18 07:33:49 mrg Exp $");
43 1.2.4.2 mrg
44 1.2.4.2 mrg #include <sys/param.h>
45 1.2.4.2 mrg #include <sys/systm.h>
46 1.2.4.2 mrg #include <sys/bus.h>
47 1.2.4.2 mrg
48 1.2.4.2 mrg #include <dev/cons.h>
49 1.2.4.2 mrg #include <dev/wscons/wsconsio.h>
50 1.2.4.2 mrg #include <dev/wscons/wsdisplayvar.h>
51 1.2.4.2 mrg #include <dev/rasops/rasops.h>
52 1.2.4.2 mrg #include <dev/wsfont/wsfont.h>
53 1.2.4.2 mrg
54 1.2.4.2 mrg #include <dev/hpc/hpcfbio.h>
55 1.2.4.2 mrg
56 1.2.4.2 mrg #include <arm/xscale/pxa2x0var.h>
57 1.2.4.2 mrg #include <zaurus/dev/w100var.h>
58 1.2.4.2 mrg
59 1.2.4.2 mrg #include <zaurus/zaurus/zaurus_var.h>
60 1.2.4.2 mrg #include <zaurus/dev/w100lcdvar.h>
61 1.2.4.2 mrg
62 1.2.4.2 mrg /*
63 1.2.4.2 mrg * wsdisplay glue
64 1.2.4.2 mrg */
65 1.2.4.2 mrg static struct w100_wsscreen_descr w100lcd_std_screen = {
66 1.2.4.2 mrg .c = {
67 1.2.4.2 mrg .name = "std",
68 1.2.4.2 mrg .textops = &w100_emulops,
69 1.2.4.2 mrg .fontwidth = 8,
70 1.2.4.2 mrg .fontheight = 16,
71 1.2.4.2 mrg .capabilities = WSSCREEN_WSCOLORS,
72 1.2.4.2 mrg },
73 1.2.4.2 mrg .depth = 16, /* bits per pixel */
74 1.2.4.2 mrg .flags = 0,
75 1.2.4.2 mrg };
76 1.2.4.2 mrg
77 1.2.4.2 mrg static const struct wsscreen_descr *w100lcd_scr_descr[] = {
78 1.2.4.2 mrg &w100lcd_std_screen.c
79 1.2.4.2 mrg };
80 1.2.4.2 mrg
81 1.2.4.2 mrg static const struct wsscreen_list w100lcd_screen_list = {
82 1.2.4.2 mrg .nscreens = __arraycount(w100lcd_scr_descr),
83 1.2.4.2 mrg .screens = w100lcd_scr_descr,
84 1.2.4.2 mrg };
85 1.2.4.2 mrg
86 1.2.4.2 mrg static int w100lcd_ioctl(void *, void *, u_long, void *, int,
87 1.2.4.2 mrg struct lwp *);
88 1.2.4.2 mrg static int w100lcd_show_screen(void *, void *, int,
89 1.2.4.2 mrg void (*)(void *, int, int), void *);
90 1.2.4.2 mrg
91 1.2.4.2 mrg struct wsdisplay_accessops w100lcd_accessops = {
92 1.2.4.2 mrg w100lcd_ioctl,
93 1.2.4.2 mrg w100_mmap,
94 1.2.4.2 mrg w100_alloc_screen,
95 1.2.4.2 mrg w100_free_screen,
96 1.2.4.2 mrg w100lcd_show_screen,
97 1.2.4.2 mrg NULL,
98 1.2.4.2 mrg NULL,
99 1.2.4.2 mrg NULL,
100 1.2.4.2 mrg };
101 1.2.4.2 mrg
102 1.2.4.2 mrg const struct w100_panel_geometry lcd_panel_geometry_c700 =
103 1.2.4.2 mrg {
104 1.2.4.2 mrg 480, /* Width */
105 1.2.4.2 mrg 640, /* Height */
106 1.2.4.2 mrg W100_PANEL_ROTATE_CW, /* Rotate */
107 1.2.4.2 mrg };
108 1.2.4.2 mrg
109 1.2.4.2 mrg static int w100lcd_match(device_t, cfdata_t, void *);
110 1.2.4.2 mrg static void w100lcd_attach(device_t, device_t, void *);
111 1.2.4.2 mrg
112 1.2.4.2 mrg CFATTACH_DECL_NEW(w100lcd, sizeof(struct w100_softc),
113 1.2.4.2 mrg w100lcd_match, w100lcd_attach, NULL, NULL);
114 1.2.4.2 mrg
115 1.2.4.2 mrg static bool w100lcd_suspend(device_t, const pmf_qual_t *);
116 1.2.4.2 mrg static bool w100lcd_resume(device_t, const pmf_qual_t *);
117 1.2.4.2 mrg
118 1.2.4.2 mrg static int
119 1.2.4.2 mrg w100lcd_match(device_t parent, cfdata_t cf, void *aux)
120 1.2.4.2 mrg {
121 1.2.4.2 mrg
122 1.2.4.2 mrg if (ZAURUS_ISC860)
123 1.2.4.2 mrg return 1;
124 1.2.4.2 mrg return 0;
125 1.2.4.2 mrg }
126 1.2.4.2 mrg
127 1.2.4.2 mrg static void
128 1.2.4.2 mrg w100lcd_attach(device_t parent, device_t self, void *aux)
129 1.2.4.2 mrg {
130 1.2.4.2 mrg struct w100_softc *sc = device_private(self);
131 1.2.4.2 mrg struct pxaip_attach_args *pxa = (struct pxaip_attach_args *)aux;
132 1.2.4.2 mrg struct wsemuldisplaydev_attach_args aa;
133 1.2.4.2 mrg
134 1.2.4.2 mrg sc->dev = self;
135 1.2.4.2 mrg
136 1.2.4.2 mrg w100_attach_subr(sc, pxa->pxa_iot, &lcd_panel_geometry_c700);
137 1.2.4.2 mrg
138 1.2.4.2 mrg aa.console = glass_console;
139 1.2.4.2 mrg aa.scrdata = &w100lcd_screen_list;
140 1.2.4.2 mrg aa.accessops = &w100lcd_accessops;
141 1.2.4.2 mrg aa.accesscookie = sc;
142 1.2.4.2 mrg
143 1.2.4.2 mrg (void)config_found(self, &aa, wsemuldisplaydevprint);
144 1.2.4.2 mrg
145 1.2.4.2 mrg if (!pmf_device_register(self, w100lcd_suspend, w100lcd_resume))
146 1.2.4.2 mrg aprint_error_dev(self, "couldn't establish power handler\n");
147 1.2.4.2 mrg }
148 1.2.4.2 mrg
149 1.2.4.2 mrg void
150 1.2.4.2 mrg w100lcd_cnattach(void)
151 1.2.4.2 mrg {
152 1.2.4.2 mrg
153 1.2.4.2 mrg if (ZAURUS_ISC860)
154 1.2.4.2 mrg w100_cnattach(&w100lcd_std_screen, &lcd_panel_geometry_c700);
155 1.2.4.2 mrg }
156 1.2.4.2 mrg
157 1.2.4.2 mrg /*
158 1.2.4.2 mrg * power management
159 1.2.4.2 mrg */
160 1.2.4.2 mrg static bool
161 1.2.4.2 mrg w100lcd_suspend(device_t dv, const pmf_qual_t *qual)
162 1.2.4.2 mrg {
163 1.2.4.2 mrg struct w100_softc *sc = device_private(dv);
164 1.2.4.2 mrg
165 1.2.4.2 mrg #if NLCDCTL > 0
166 1.2.4.2 mrg lcdctl_onoff(false);
167 1.2.4.2 mrg #endif
168 1.2.4.2 mrg w100_suspend(sc);
169 1.2.4.2 mrg
170 1.2.4.2 mrg return true;
171 1.2.4.2 mrg }
172 1.2.4.2 mrg
173 1.2.4.2 mrg static bool
174 1.2.4.2 mrg w100lcd_resume(device_t dv, const pmf_qual_t *qual)
175 1.2.4.2 mrg {
176 1.2.4.2 mrg struct w100_softc *sc = device_private(dv);
177 1.2.4.2 mrg
178 1.2.4.2 mrg w100_resume(sc);
179 1.2.4.2 mrg #if NLCDCTL > 0
180 1.2.4.2 mrg lcdctl_onoff(true);
181 1.2.4.2 mrg #endif
182 1.2.4.2 mrg
183 1.2.4.2 mrg return true;
184 1.2.4.2 mrg }
185 1.2.4.2 mrg
186 1.2.4.2 mrg /*
187 1.2.4.2 mrg * wsdisplay accessops overrides
188 1.2.4.2 mrg */
189 1.2.4.2 mrg static int
190 1.2.4.2 mrg w100lcd_ioctl(void *v, void *vs, u_long cmd, void *data, int flag,
191 1.2.4.2 mrg struct lwp *l)
192 1.2.4.2 mrg {
193 1.2.4.2 mrg struct w100_softc *sc = (struct w100_softc *)v;
194 1.2.4.2 mrg struct hpcfb_fbconf *fbconf;
195 1.2.4.2 mrg struct hpcfb_dspconf *dspconf;
196 1.2.4.2 mrg int res = EINVAL;
197 1.2.4.2 mrg
198 1.2.4.2 mrg switch (cmd) {
199 1.2.4.2 mrg #if NLCDCTL > 0
200 1.2.4.2 mrg case WSDISPLAYIO_GETPARAM:
201 1.2.4.2 mrg case WSDISPLAYIO_SETPARAM:
202 1.2.4.2 mrg res = lcdctl_param(cmd, (struct wsdisplay_param *)data);
203 1.2.4.2 mrg break;
204 1.2.4.2 mrg #endif
205 1.2.4.2 mrg case HPCFBIO_GCONF:
206 1.2.4.2 mrg fbconf = (struct hpcfb_fbconf *)data;
207 1.2.4.2 mrg if (fbconf->hf_conf_index != 0 &&
208 1.2.4.2 mrg fbconf->hf_conf_index != HPCFB_CURRENT_CONFIG) {
209 1.2.4.2 mrg break;
210 1.2.4.2 mrg }
211 1.2.4.2 mrg
212 1.2.4.2 mrg fbconf->hf_conf_index = 0;
213 1.2.4.2 mrg fbconf->hf_nconfs = 1;
214 1.2.4.2 mrg fbconf->hf_class = HPCFB_CLASS_RGBCOLOR;
215 1.2.4.2 mrg strlcpy(fbconf->hf_name, "Sharp Zaurus frame buffer",
216 1.2.4.2 mrg sizeof(fbconf->hf_name));
217 1.2.4.2 mrg strlcpy(fbconf->hf_conf_name, "default",
218 1.2.4.2 mrg sizeof(fbconf->hf_conf_name));
219 1.2.4.2 mrg fbconf->hf_width = sc->display_width;
220 1.2.4.2 mrg fbconf->hf_height = sc->display_height;
221 1.2.4.2 mrg fbconf->hf_baseaddr = (u_long)sc->active->buf_va;
222 1.2.4.2 mrg fbconf->hf_offset = 0;
223 1.2.4.2 mrg fbconf->hf_bytes_per_line = sc->display_width *
224 1.2.4.2 mrg sc->active->depth / 8;
225 1.2.4.2 mrg fbconf->hf_nplanes = 1;
226 1.2.4.2 mrg fbconf->hf_bytes_per_plane = sc->display_width *
227 1.2.4.2 mrg sc->display_height * sc->active->depth / 8;
228 1.2.4.2 mrg fbconf->hf_pack_width = sc->active->depth;
229 1.2.4.2 mrg fbconf->hf_pixels_per_pack = 1;
230 1.2.4.2 mrg fbconf->hf_pixel_width = sc->active->depth;
231 1.2.4.2 mrg fbconf->hf_access_flags = (0
232 1.2.4.2 mrg | HPCFB_ACCESS_BYTE
233 1.2.4.2 mrg | HPCFB_ACCESS_WORD
234 1.2.4.2 mrg | HPCFB_ACCESS_DWORD);
235 1.2.4.2 mrg fbconf->hf_order_flags = 0;
236 1.2.4.2 mrg fbconf->hf_reg_offset = 0;
237 1.2.4.2 mrg
238 1.2.4.2 mrg fbconf->hf_class_data_length = sizeof(struct hf_rgb_tag);
239 1.2.4.2 mrg fbconf->hf_u.hf_rgb.hf_flags = 0;
240 1.2.4.2 mrg fbconf->hf_u.hf_rgb.hf_red_width = 5;
241 1.2.4.2 mrg fbconf->hf_u.hf_rgb.hf_red_shift = 11;
242 1.2.4.2 mrg fbconf->hf_u.hf_rgb.hf_green_width = 6;
243 1.2.4.2 mrg fbconf->hf_u.hf_rgb.hf_green_shift = 5;
244 1.2.4.2 mrg fbconf->hf_u.hf_rgb.hf_blue_width = 5;
245 1.2.4.2 mrg fbconf->hf_u.hf_rgb.hf_blue_shift = 0;
246 1.2.4.2 mrg fbconf->hf_u.hf_rgb.hf_alpha_width = 0;
247 1.2.4.2 mrg fbconf->hf_u.hf_rgb.hf_alpha_shift = 0;
248 1.2.4.2 mrg
249 1.2.4.2 mrg fbconf->hf_ext_size = 0;
250 1.2.4.2 mrg fbconf->hf_ext_data = NULL;
251 1.2.4.2 mrg
252 1.2.4.2 mrg res = 0;
253 1.2.4.2 mrg break;
254 1.2.4.2 mrg
255 1.2.4.2 mrg case HPCFBIO_SCONF:
256 1.2.4.2 mrg fbconf = (struct hpcfb_fbconf *)data;
257 1.2.4.2 mrg if (fbconf->hf_conf_index != 0 &&
258 1.2.4.2 mrg fbconf->hf_conf_index != HPCFB_CURRENT_CONFIG) {
259 1.2.4.2 mrg break;
260 1.2.4.2 mrg }
261 1.2.4.2 mrg /* nothing to do because we have only one configuration */
262 1.2.4.2 mrg res = 0;
263 1.2.4.2 mrg break;
264 1.2.4.2 mrg
265 1.2.4.2 mrg case HPCFBIO_GDSPCONF:
266 1.2.4.2 mrg dspconf = (struct hpcfb_dspconf *)data;
267 1.2.4.2 mrg if ((dspconf->hd_unit_index != 0 &&
268 1.2.4.2 mrg dspconf->hd_unit_index != HPCFB_CURRENT_UNIT) ||
269 1.2.4.2 mrg (dspconf->hd_conf_index != 0 &&
270 1.2.4.2 mrg dspconf->hd_conf_index != HPCFB_CURRENT_CONFIG)) {
271 1.2.4.2 mrg break;
272 1.2.4.2 mrg }
273 1.2.4.2 mrg
274 1.2.4.2 mrg dspconf->hd_unit_index = 0;
275 1.2.4.2 mrg dspconf->hd_nunits = 1;
276 1.2.4.2 mrg dspconf->hd_class = HPCFB_DSP_CLASS_COLORLCD;
277 1.2.4.2 mrg strlcpy(dspconf->hd_name, "Sharp Zaurus LCD",
278 1.2.4.2 mrg sizeof(dspconf->hd_name));
279 1.2.4.2 mrg dspconf->hd_op_flags = 0;
280 1.2.4.2 mrg dspconf->hd_conf_index = 0;
281 1.2.4.2 mrg dspconf->hd_nconfs = 1;
282 1.2.4.2 mrg strlcpy(dspconf->hd_conf_name, "default",
283 1.2.4.2 mrg sizeof(dspconf->hd_conf_name));
284 1.2.4.2 mrg dspconf->hd_width = sc->display_width;
285 1.2.4.2 mrg dspconf->hd_height = sc->display_height;
286 1.2.4.2 mrg dspconf->hd_xdpi = HPCFB_DSP_DPI_UNKNOWN;
287 1.2.4.2 mrg dspconf->hd_ydpi = HPCFB_DSP_DPI_UNKNOWN;
288 1.2.4.2 mrg
289 1.2.4.2 mrg res = 0;
290 1.2.4.2 mrg break;
291 1.2.4.2 mrg
292 1.2.4.2 mrg case HPCFBIO_SDSPCONF:
293 1.2.4.2 mrg dspconf = (struct hpcfb_dspconf *)data;
294 1.2.4.2 mrg if ((dspconf->hd_unit_index != 0 &&
295 1.2.4.2 mrg dspconf->hd_unit_index != HPCFB_CURRENT_UNIT) ||
296 1.2.4.2 mrg (dspconf->hd_conf_index != 0 &&
297 1.2.4.2 mrg dspconf->hd_conf_index != HPCFB_CURRENT_CONFIG)) {
298 1.2.4.2 mrg break;
299 1.2.4.2 mrg }
300 1.2.4.2 mrg /*
301 1.2.4.2 mrg * nothing to do
302 1.2.4.2 mrg * because we have only one unit and one configuration
303 1.2.4.2 mrg */
304 1.2.4.2 mrg res = 0;
305 1.2.4.2 mrg break;
306 1.2.4.2 mrg
307 1.2.4.2 mrg case HPCFBIO_GOP:
308 1.2.4.2 mrg case HPCFBIO_SOP:
309 1.2.4.2 mrg /* curently not implemented... */
310 1.2.4.2 mrg break;
311 1.2.4.2 mrg
312 1.2.4.2 mrg default:
313 1.2.4.2 mrg break;
314 1.2.4.2 mrg }
315 1.2.4.2 mrg
316 1.2.4.2 mrg if (res == EINVAL)
317 1.2.4.2 mrg res = w100_ioctl(v, vs, cmd, data, flag, l);
318 1.2.4.2 mrg
319 1.2.4.2 mrg return res;
320 1.2.4.2 mrg }
321 1.2.4.2 mrg
322 1.2.4.2 mrg static int
323 1.2.4.2 mrg w100lcd_show_screen(void *v, void *cookie, int waitok,
324 1.2.4.2 mrg void (*cb_func)(void *, int, int), void *cb_arg)
325 1.2.4.2 mrg {
326 1.2.4.2 mrg int error;
327 1.2.4.2 mrg
328 1.2.4.2 mrg error = w100_show_screen(v, cookie, waitok, cb_func, cb_arg);
329 1.2.4.2 mrg if (error)
330 1.2.4.2 mrg return (error);
331 1.2.4.2 mrg
332 1.2.4.2 mrg /* Turn on LCD */
333 1.2.4.2 mrg #if NLCDCTL > 0
334 1.2.4.2 mrg lcdctl_onoff(true);
335 1.2.4.2 mrg #endif
336 1.2.4.2 mrg
337 1.2.4.2 mrg return 0;
338 1.2.4.2 mrg }
339