xref: /netbsd-src/sys/arch/hpc/hpc/debug_subr.c (revision 0dd5877adce57db949b16ae963e5a6831cccdfb6)
1 /*	$NetBSD: debug_subr.c,v 1.2 2002/02/13 16:25:33 uch Exp $	*/
2 
3 /*-
4  * Copyright (c) 2001, 2002 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by UCHIYAMA Yasushi.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:
20  *        This product includes software developed by the NetBSD
21  *        Foundation, Inc. and its contributors.
22  * 4. Neither the name of The NetBSD Foundation nor the names of its
23  *    contributors may be used to endorse or promote products derived
24  *    from this software without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36  * POSSIBILITY OF SUCH DAMAGE.
37  */
38 
39 #include "debug_hpc.h"
40 
41 #include <sys/param.h>
42 #include <sys/systm.h>
43 
44 #include <machine/debug.h>
45 #include <machine/bootinfo.h>
46 
47 #define BANNER_LENGTH		80
48 
49 static const char onoff[2] = "_x";
50 
51 void
52 __dbg_bit_print(u_int32_t a, int len, int start, int end, char *title,
53     int count)
54 {
55 	u_int32_t j, j1;
56 	int i, n;
57 	char buf[64];
58 
59 	n = len * NBBY - 1;
60 	j1 = 1 << n;
61 	end = end ? end : n;
62 
63 	printf(" ");
64 	if (title) {
65 		printf("[%-16s] ", title);
66 	}
67 
68 	for (j = j1, i = n; j > 0; j >>=1, i--) {
69 		if (i > end || i < start) {
70 			printf("%c", a & j ? '+' : '-'); /* out of range */
71 		} else {
72 			printf("%c", a & j ? '|' : '.');
73 		}
74 	}
75 
76 	snprintf(buf, sizeof buf, " [0x%%0%dx %%12d]", len << 1);
77 	printf(buf, a, a);
78 
79 	if (count) {
80 		for (j = j1, i = n; j > 0; j >>=1, i--) {
81 			if (!(i > end || i < start) && (a & j)) {
82 				printf(" %d", i);
83 			}
84 		}
85 	}
86 
87 	printf("\n");
88 }
89 
90 void
91 dbg_bitmask_print(u_int32_t reg, u_int32_t mask, const char *name)
92 {
93 
94 	printf("%s[%c] ", name, onoff[reg & mask ? 1 : 0]);
95 }
96 
97 void
98 dbg_banner_title(const char *name, size_t len)
99 {
100 	int n = (BANNER_LENGTH - (len + 2)) >> 1;
101 
102 	dbg_draw_line(n);
103 	printf("[%s]", name);
104 	dbg_draw_line(n);
105 	printf("\n");
106 }
107 
108 void
109 dbg_banner_line()
110 {
111 
112 	dbg_draw_line(BANNER_LENGTH);
113 	printf("\n");
114 }
115 
116 void
117 dbg_draw_line(int n)
118 {
119 	int i;
120 
121 	for (i = 0; i < n; i++)
122 		printf("-");
123 }
124 
125 #ifdef HPC_DEBUG_LCD
126 /*
127  * LCD test routines for 8bpp, 16bpp LCD.
128  */
129 static const u_int8_t img[1024] = {
130 	0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
131 	0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
132 	0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
133 	0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
134 	0xff,0xd5,0xff,0xc3,0xff,0xd5,0xff,0xc3,
135 	0xff,0xd5,0xff,0xc3,0xff,0xd5,0xff,0xc3,
136 	0xff,0xd5,0xff,0xc3,0xff,0xd5,0xc3,0xd5,
137 	0xff,0xc3,0xff,0xd5,0xff,0xc3,0xff,0xd5,
138 	0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
139 	0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
140 	0xff,0xff,0xff,0xff,0xff,0xff,0x82,0x82,
141 	0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xc3,
142 	0xff,0xc3,0xff,0xff,0xff,0xff,0xff,0xff,
143 	0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
144 	0xff,0xff,0xff,0xff,0xff,0xff,0xb9,0x82,
145 	0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xb9,
146 	0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
147 	0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
148 	0xff,0xff,0xff,0xff,0xff,0xff,0xd5,0x82,
149 	0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xd5,
150 	0xff,0xb9,0xff,0xff,0xff,0xff,0xff,0xff,
151 	0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
152 	0xff,0xff,0xff,0xff,0xff,0xff,0xc3,0x82,
153 	0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xc3,
154 	0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
155 	0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
156 	0xff,0xff,0xff,0xff,0xff,0xff,0xd5,0x82,
157 	0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xd5,
158 	0xff,0xd5,0xff,0xff,0xff,0xff,0xff,0xff,
159 	0xff,0xff,0xff,0xff,0xb9,0xd5,0xc3,0xd5,
160 	0xff,0xff,0xff,0xff,0xff,0xff,0x3d,0x82,
161 	0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xb9,
162 	0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
163 	0xff,0xff,0xd5,0x82,0x82,0x82,0x82,0x82,
164 	0x82,0x82,0xd5,0xff,0xff,0xff,0xd5,0x82,
165 	0xff,0xff,0xd5,0xc3,0xff,0xff,0xff,0xc3,
166 	0xff,0xc3,0xff,0xff,0xff,0xff,0xff,0xff,
167 	0xff,0xff,0x82,0x82,0xff,0xff,0xff,0xff,
168 	0xd5,0x3e,0x82,0x82,0x82,0xc3,0x82,0x3d,
169 	0xff,0xc3,0x82,0x3d,0xff,0xff,0xff,0xd5,
170 	0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
171 	0xff,0xd5,0x82,0xff,0xff,0xff,0xff,0xff,
172 	0xff,0xff,0xff,0xff,0x82,0x82,0x82,0x3d,
173 	0x82,0x82,0xd5,0xff,0xff,0xff,0xff,0xb9,
174 	0xff,0xb9,0xff,0xff,0xff,0xff,0xff,0xff,
175 	0xff,0x82,0x82,0xff,0xff,0xff,0xff,0xff,
176 	0xff,0xff,0xff,0xff,0xd5,0x82,0x82,0x82,
177 	0x82,0x82,0xb9,0xff,0xff,0xff,0xff,0xc3,
178 	0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
179 	0xff,0x82,0xd5,0xff,0xff,0xff,0xff,0xff,
180 	0xff,0xff,0xff,0xff,0xff,0x82,0x82,0x82,
181 	0xd5,0xff,0x82,0xd5,0xff,0xff,0xff,0xd5,
182 	0xff,0xd5,0xff,0xff,0xff,0xff,0xff,0xff,
183 	0xd5,0x82,0xff,0xff,0xff,0xff,0xff,0xff,
184 	0xff,0xff,0xff,0xff,0xff,0x82,0x82,0x3e,
185 	0xff,0xff,0xc3,0x82,0xff,0xff,0xff,0xb9,
186 	0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
187 	0x82,0x3e,0xff,0xff,0xff,0xff,0xff,0xff,
188 	0xff,0xff,0xff,0xff,0xff,0xd5,0x82,0xc3,
189 	0xff,0xff,0xff,0x82,0xf8,0xff,0xff,0xd5,
190 	0xff,0xc3,0xff,0xff,0xff,0xff,0xff,0xff,
191 	0x82,0xd5,0xff,0xff,0xff,0xff,0xff,0xff,
192 	0xff,0xff,0xff,0xff,0x3e,0x82,0x82,0x82,
193 	0x80,0x3d,0xff,0x3d,0x82,0xff,0xff,0xc3,
194 	0xff,0xff,0xff,0xff,0xd5,0xc3,0xd5,0xb9,
195 	0x82,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
196 	0xff,0xff,0xff,0xff,0x82,0x82,0xd5,0xff,
197 	0x82,0xd5,0xff,0xd5,0x82,0xff,0xff,0xb9,
198 	0xff,0xb9,0xff,0x82,0x82,0x82,0x82,0x82,
199 	0x82,0xc3,0xff,0xff,0xff,0xff,0xff,0xff,
200 	0xff,0xff,0xff,0x82,0x82,0x82,0x82,0x3d,
201 	0x82,0xb9,0xff,0xc3,0x82,0xff,0xff,0xd5,
202 	0xff,0xff,0xd5,0x82,0xd5,0xff,0xff,0xff,
203 	0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
204 	0xff,0xff,0xff,0x82,0x82,0xd5,0x3e,0x82,
205 	0x82,0xc3,0xff,0xb9,0x82,0xff,0xff,0xc3,
206 	0xff,0xc3,0x3e,0x82,0xff,0xff,0xff,0xff,
207 	0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
208 	0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
209 	0xff,0xff,0xff,0xd5,0x82,0xff,0xff,0xb9,
210 	0xff,0xff,0x82,0x3d,0xff,0xff,0x3e,0xd5,
211 	0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
212 	0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
213 	0xff,0xff,0xff,0xc3,0x82,0xff,0xff,0xd5,
214 	0xff,0xd5,0x82,0xd5,0xff,0xc3,0x82,0xff,
215 	0xc3,0xd5,0xb9,0xd5,0xff,0xff,0xff,0xff,
216 	0xff,0xff,0xff,0xff,0xff,0xff,0xc3,0xd5,
217 	0xb9,0xff,0xff,0xb9,0x82,0xff,0xff,0xc3,
218 	0xff,0xb9,0x82,0xb9,0xff,0x82,0x3d,0xff,
219 	0x82,0x82,0x82,0x82,0xff,0xff,0xff,0xff,
220 	0xff,0xff,0xff,0xff,0xff,0xd5,0x82,0x82,
221 	0x82,0x82,0xff,0xd5,0x82,0xff,0xff,0xd5,
222 	0xff,0x82,0x82,0x82,0x82,0x82,0x82,0x82,
223 	0x82,0x82,0x82,0x82,0x82,0xc3,0xb9,0xd5,
224 	0xc3,0xd5,0xff,0xff,0xc3,0x82,0x82,0x82,
225 	0x82,0x82,0xb9,0xc3,0x82,0xff,0xff,0xb9,
226 	0xff,0xd5,0xc3,0xd5,0xb9,0x82,0x3d,0xd5,
227 	0x82,0x82,0x3e,0x82,0x82,0x82,0x82,0x82,
228 	0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x3d,
229 	0x82,0x82,0x82,0x82,0x3d,0xff,0xff,0xc3,
230 	0xff,0xff,0xff,0xff,0xff,0xd5,0x82,0xc3,
231 	0x82,0xd5,0xff,0x82,0xd5,0xff,0xff,0xff,
232 	0xff,0xd5,0xb9,0xd5,0x82,0x82,0x82,0xd5,
233 	0x82,0x82,0x82,0xff,0xd5,0xff,0xff,0xd5,
234 	0xff,0xb9,0xff,0xff,0xff,0xff,0x82,0x82,
235 	0x82,0xc3,0x82,0x82,0xff,0xff,0xff,0xff,
236 	0xff,0xff,0xff,0xff,0xff,0x82,0x82,0x82,
237 	0x82,0x82,0x82,0xff,0xff,0xff,0xff,0xb9,
238 	0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x3d,
239 	0x82,0x82,0x3d,0xff,0xff,0xff,0xff,0xff,
240 	0xff,0xff,0xff,0xff,0xff,0xd5,0x82,0x82,
241 	0x82,0x82,0xd5,0xff,0xff,0xff,0xff,0xc3,
242 	0xff,0xc3,0xff,0xff,0xff,0xff,0xff,0xff,
243 	0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
244 	0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xc3,
245 	0xd5,0xff,0xff,0xff,0xff,0xff,0xff,0xd5,
246 	0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
247 	0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
248 	0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
249 	0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xb9,
250 	0xff,0xd5,0xff,0xff,0xff,0xff,0xff,0xff,
251 	0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
252 	0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
253 	0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xc3,
254 	0xff,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
255 	0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
256 	0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
257 	0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
258 };
259 
260 static const u_int16_t rgb565_clut[256] = {
261 	0x0000, 0x8000, 0x0400, 0x8400, 0x0080, 0x8080, 0x0480, 0x8480,
262 	0xc6e0, 0xa6f0, 0x29ea, 0x29ff, 0x2ae0, 0x2af5, 0x2aea, 0x2aff,
263 	0x2be0, 0x2bf5, 0x2bea, 0x2bff, 0x2ce0, 0x2cf5, 0x2cea, 0x2cff,
264 	0x2de0, 0x2df5, 0x2dea, 0x2dff, 0x2ee0, 0x2ef5, 0x2eea, 0x2eff,
265 	0x2fe0, 0x2ff5, 0x2fea, 0x2fff, 0x5000, 0x5055, 0x50aa, 0x50ff,
266 	0x50e0, 0x50f5, 0x50ea, 0x50ff, 0x51e0, 0x51f5, 0x51ea, 0x51ff,
267 	0x52e0, 0x52f5, 0x52ea, 0x52ff, 0x53e0, 0x53f5, 0x53ea, 0x53ff,
268 	0x54e0, 0x54f5, 0x54ea, 0x54ff, 0x55e0, 0x55f5, 0x55ea, 0x55ff,
269 	0x56e0, 0x56f5, 0x56ea, 0x56ff, 0x57e0, 0x57f5, 0x57ea, 0x57ff,
270 	0x7800, 0x7855, 0x78aa, 0x78ff, 0x78e0, 0x78f5, 0x78ea, 0x78ff,
271 	0x79e0, 0x79f5, 0x79ea, 0x79ff, 0x7ae0, 0x7af5, 0x7aea, 0x7aff,
272 	0x7be0, 0x7bf5, 0x7bea, 0x7bff, 0x7ce0, 0x7cf5, 0x7cea, 0x7cff,
273 	0x7de0, 0x7df5, 0x7dea, 0x7dff, 0x7ee0, 0x7ef5, 0x7eea, 0x7eff,
274 	0x7fe0, 0x7ff5, 0x7fea, 0x7fff, 0xa800, 0xa855, 0xa8aa, 0xa8ff,
275 	0xa8e0, 0xa8f5, 0xa8ea, 0xa8ff, 0xa9e0, 0xa9f5, 0xa9ea, 0xa9ff,
276 	0xaae0, 0xaaf5, 0xaaea, 0xaaff, 0xabe0, 0xabf5, 0xabea, 0xabff,
277 	0xace0, 0xacf5, 0xacea, 0xacff, 0xade0, 0xadf5, 0xadea, 0xadff,
278 	0xaee0, 0xaef5, 0xaeea, 0xaeff, 0xafe0, 0xaff5, 0xafea, 0xafff,
279 	0xd000, 0xd055, 0xd0aa, 0xd0ff, 0xd0e0, 0xd0f5, 0xd0ea, 0xd0ff,
280 	0xd1e0, 0xd1f5, 0xd1ea, 0xd1ff, 0xd2e0, 0xd2f5, 0xd2ea, 0xd2ff,
281 	0xd3e0, 0xd3f5, 0xd3ea, 0xd3ff, 0xd4e0, 0xd4f5, 0xd4ea, 0xd4ff,
282 	0xd5e0, 0xd5f5, 0xd5ea, 0xd5ff, 0xd6e0, 0xd6f5, 0xd6ea, 0xd6ff,
283 	0xd7e0, 0xd7f5, 0xd7ea, 0xd7ff, 0xf855, 0xf8aa, 0xf8e0, 0xf8f5,
284 	0xf8ea, 0xf8ff, 0xf9e0, 0xf9f5, 0xf9ea, 0xf9ff, 0xfae0, 0xfaf5,
285 	0xfaea, 0xfaff, 0xfbe0, 0xfbf5, 0xfbea, 0xfbff, 0xfce0, 0xfcf5,
286 	0xfcea, 0xfcff, 0xfde0, 0xfdf5, 0xfdea, 0xfdff, 0xfee0, 0xfef5,
287 	0xfeea, 0xfeff, 0xfff5, 0xffea, 0xceff, 0xfeff, 0x37ff, 0x67ff,
288 	0x9fff, 0xcfff, 0x03e0, 0x03f5, 0x03ea, 0x03ff, 0x04e0, 0x04f5,
289 	0x04ea, 0x04ff, 0x05e0, 0x05f5, 0x05ea, 0x05ff, 0x06e0, 0x06f5,
290 	0x06ea, 0x06ff, 0x07f5, 0x07ea, 0x2800, 0x2855, 0x28aa, 0x28ff,
291 	0x28e0, 0x28f5, 0x28ea, 0x28ff, 0x29e0, 0x29f5, 0xfff0, 0xa5a4,
292 	0x8480, 0xf800, 0x07e0, 0xffe0, 0x00ff, 0xf8ff, 0x07ff, 0xffff
293 };
294 
295 static u_int16_t __color_tab16[] = {
296 	RGB565_BLACK,
297 	RGB565_RED,
298 	RGB565_GREEN,
299 	RGB565_YELLOW,
300 	RGB565_BLUE,
301 	RGB565_MAGENTA,
302 	RGB565_CYAN,
303 	RGB565_WHITE
304 };
305 
306 static int bootinfo_fb_depth(void);
307 static void __dbg_lcd_test8(vaddr_t, int, int);
308 static void __dbg_lcd_test16(vaddr_t, int, int);
309 
310 void
311 dbg_lcd_test()
312 {
313 	vaddr_t fbaddr;
314 	int w, h;
315 
316 	if (bootinfo == NULL || bootinfo->fb_addr == NULL)
317 		return;
318 
319 	fbaddr = (vaddr_t)bootinfo->fb_addr;
320 	w = bootinfo->fb_width;
321 	h = bootinfo->fb_height;
322 
323 	switch (bootinfo_fb_depth()) {
324 	default:
325 		break;
326 	case 8:
327 		__dbg_lcd_test8(fbaddr, w, h);
328 		break;
329 	case 16:
330 		__dbg_lcd_test16(fbaddr, w, h);
331 		break;
332 	}
333 }
334 
335 /*
336  * 8bpp LCD test routine.
337  *  HP620LX, HPW50PAD are little-endian display.
338  */
339 void
340 __dbg_lcd_test8(vaddr_t fbaddr, int w, int h)
341 {
342 	u_int8_t *fb, *fb_start = (u_int8_t *)fbaddr;
343 	int i, x, y, y_start, y_end, len, skip;
344 	u_int16_t *fb16;
345 	u_int32_t *fb32;
346 
347 	/*
348 	 * Clear screen (BLACK)
349 	 */
350 	for (fb = fb_start, i = 0; i < w * h; i++)
351 		*fb++ = 0;
352 
353 	/*
354 	 * Color bar (I assume palette index is ANSI)
355 	 *	BLACK|RED|GREEN|YELLOW|BLUE|MAGENTA|CYAN|WHITE
356 	 */
357 	len = w / 8;
358 	y_start = 0;
359 	y_end = h / 2;
360 	skip = bootinfo->fb_line_bytes - w;
361 	for (fb = fb_start, y = y_start; y < y_end; y++, fb += skip) {
362 		for (i = 0; i < 8; i++) {
363 			for (x = 0; x < len; x++)
364 				*fb++ = i;
365 		}
366 	}
367 
368 	/*
369 	 * Byte order test. (display 32x32 bitmap)
370 	 */
371 	/* 8-bit access (reference) */
372 	y_start = y_end;
373 	y_end = y_start + 32;
374 	i = 0;
375 	fb += w / 2 - 16; /* center */
376 	skip = bootinfo->fb_line_bytes - 32;
377 	for (y = y_start; y < y_end; y++, fb += skip)
378 		for (x = 0; x < 32; x++)
379 			*fb++ = img[i++];
380 
381 	/*
382 	 * 16-bit access (test)
383 	 *   !HPCFB_REVORDER_BYTE test.
384 	 */
385 	y_start = y_end;
386 	y_end = y_start + 32;
387 	i = 0;
388 	fb16 = (u_int16_t *)fb;
389 	skip /= 2;
390 	for (y = y_start; y < y_end; y++, fb16 += skip)
391 		for (x = 0; x < 16; x++, i += 2)
392 			*fb16++ =
393 			    img[i + 1] << 8 |
394 			    img[i + 0];
395 
396 	/*
397 	 * 32-bit access (test)
398 	 *  !HPCFB_REVORDER_BYTE && !HPCFB_REVORDER_WORD test
399 	 */
400 	y_start = y_end;
401 	y_end = y_start + 32;
402 	i = 0;
403 	fb32 = (u_int32_t *)(fb + 32 * w);
404 	skip /= 2;
405 	for (y = y_start; y < y_end; y++, fb32 += skip)
406 		for (x = 0; x < 8; x++, i += 4)
407 			*fb32++ =
408 			    img[i + 3] << 24 |
409 			    img[i + 2] << 16 |
410 			    img[i + 1] <<  8 |
411 			    img[i + 0];
412 }
413 
414 /*
415  * 16bpp LCD test routine.
416  *  Jornada6[89]0, HPW650PA are big-endian display.
417  */
418 void
419 __dbg_lcd_test16(vaddr_t fbaddr, int w, int h)
420 {
421 	u_int16_t *fb, *fb_start = (u_int16_t *)fbaddr;
422 	u_int16_t pat;
423 	int i, x, y, y_start, y_end, len, skip;
424 	u_int32_t *fb32;
425 
426 	/*
427 	 * Clear screen (BLACK)
428 	 */
429 	pat = __color_tab16[0];
430 	for (fb = fb_start, i = 0; i < w * h; i++)
431 		*fb++ = pat;
432 
433 	/*
434 	 * Color bar
435 	 *	BLACK|RED|GREEN|YELLOW|BLUE|MAGENTA|CYAN|WHITE
436 	 */
437 	len = w / 8;
438 	y_start = 0;
439 	y_end = h / 2;
440 	for (fb = fb_start, y = y_start; y < y_end; y++) {
441 		for (i = 0; i < 8; i++) {
442 			pat = __color_tab16[i];
443 			for (x = 0; x < len; x++)
444 				*fb++ = pat;
445 		}
446 	}
447 	y_start = y_end;
448 
449 	/*
450 	 * Byte order test. (display 32x32 bitmap)
451 	 */
452 	/*
453 	 * 16-bit access (reference)
454 	 *   !HPCFB_REVORDER_BYTE test.
455 	 */
456 	y_start = y_end;
457 	y_end = y_start + 32;
458 	i = 0;
459 	fb += w / 2 - 16; /* center */
460 	skip = w - 32;
461 	for (y = y_start; y < y_end; y++, fb += skip)
462 		for (x = 0; x < 32; x++)
463 			*fb++ = rgb565_clut[img[i++]];
464 
465 	/*
466 	 * 32-bit access (test)
467 	 *  !HPCFB_REVORDER_BYTE && !HPCFB_REVORDER_WORD test
468 	 */
469 	y_start = y_end;
470 	y_end = y_start + 32;
471 	i = 0;
472 	fb32 = (u_int32_t *)fb;
473 	skip /= 2;
474 	for (y = y_start; y < y_end; y++, fb32 += skip)
475 		for (x = 0; x < 16; x++, i += 2)
476 			*fb32++ = (rgb565_clut[img[i + 1]] << 16) |
477 			    rgb565_clut[img[i]];
478 }
479 
480 int
481 bootinfo_fb_depth()
482 {
483 
484 	switch (bootinfo->fb_type) {
485 	case BIFB_D2_M2L_3:
486 		/* FALLTHROUGH */
487 	case BIFB_D2_M2L_0:
488 		return (2);
489 	case BIFB_D4_M2L_F:
490 		/* FALLTHROUGH */
491 	case BIFB_D4_M2L_0:
492 		return (4);
493 	case BIFB_D8_FF:
494 		/* FALLTHROUGH */
495 	case BIFB_D8_00:
496 		return (8);
497 	case BIFB_D16_FFFF:
498 		/* FALLTHROUGH */
499 	case BIFB_D16_0000:
500 		return (16);
501 	}
502 
503 	return (0);
504 }
505 
506 #endif /* HPC_DEBUG_LCD */
507