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