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