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