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