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