xref: /original-bsd/sys/news3400/fb/fbbm_lcdm.c (revision 4670e840)
1 /*
2  * Copyright (c) 1992 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * This code is derived from software contributed to Berkeley by
6  * Sony Corp. and Kazumasa Utashiro of Software Research Associates, Inc.
7  *
8  * %sccs.include.redist.c%
9  *
10  * from: $Hdr: fbbm_lcdm.c,v 4.300 91/06/09 06:33:38 root Rel41 $ SONY
11  *
12  *	@(#)fbbm_lcdm.c	7.3 (Berkeley) 03/09/93
13  */
14 
15 /*
16  * LCD frame buffer driver
17  */
18 
19 #include "lfbm.h"
20 
21 #if NLFBM > 0
22 
23 #include <sys/param.h>
24 #include <news3400/iop/framebuf.h>
25 #include <news3400/iop/fbreg.h>
26 
27 #include <news3400/fb/fbdefs.h>
28 
29 extern int nofunc();
30 extern int error();
31 extern char *ext_fnt24_addr[];
32 extern char *ext_fnt_addr[];
33 
34 extern short zero[];
35 
36 extern unsigned int mfbmask32[];
37 extern unsigned int mfbrmask32[];
38 
39 #define NOP	for (j = 0; j < 40; j++)
40 
41 #ifdef news3200
42 #define LCD_PORT	(volatile unsigned long *)(0xb0000000)
43 #define DIMMER_PORT	(volatile unsigned long *)(0xb0100000)
44 #define LCD_CRTC	(volatile unsigned char *)(0xbff60000)
45 #define	KROM_START	(char *)(0x90000000)
46 #define	VRAM_START	(unsigned long *)(0x90200000)
47 #define VRAM_WIDTH	(1120/32)
48 #endif
49 
50 #ifdef news3200
51 static caddr_t
52 fblfbm_Krom_addr(fb, c, sr)
53 	struct fbdev *fb;
54 	register int c;
55 	lRectangle *sr;
56 {
57 	register int i;
58 	register u_short *tmp;
59 	static int tmpfnt[24];
60 
61 	if ((c >= 0x20) && (c <= 0x7e)) {
62 		/*
63 		 * ASCII char
64 		 */
65 		c -= ' ';
66 		c = ((c & 0x1f) | ((c & 0xe0) << 2)) << 7;
67 		tmp = (u_short *)(fb->Krom_base + (c + (sr->extent.y > 16 ? 0 : 96)) * 2);
68 	} else if ((c >= 0xa1) && (c <= 0xdf)) {
69 		/*
70 		 * KANA char
71 		 */
72 		if (sr->extent.y > 16)
73 			tmp =  (u_short *)ext_fnt24_addr[c + 64];
74 		else
75 			tmp =  (u_short *)ext_fnt_addr[c + 64];
76 	} else if ((c >= 0x2020) && (c <= 0x7e7e)) {
77 		/*
78 		 * KANJI char
79 		 */
80 		switch (c & 0x7000) {
81 		case 0x2000:
82 			c = ((c & 0x1f) | ((c & 0x60) << 5) | ((c & 0x700) >> 1)) << 7;
83 			break;
84 		case 0x3000:
85 		case 0x4000:
86 			c = ((c & 0x7f) | ((c & 0xf00) >> 1) | ((c & 0x4000) >> 3)) << 7;
87 			break;
88 		case 0x5000:
89 		case 0x6000:
90 			c = ((c & 0x7f) | ((c & 0xf00) >> 1) | ((c & 0x2000) >> 2)
91 				| 0x1000) << 7;
92 			break;
93 		case 0x7000:
94 			c = ((c & 0x1f) | ((c & 0x60) << 5) | ((c & 0x700) >> 1)
95 				| 0x1000) << 7;
96 			break;
97 		}
98 		tmp = (u_short *)(fb->Krom_base + (c + (sr->extent.y > 16 ? 0 : 96)) * 2);
99 	} else {
100 		/*
101 		 * UNKNOWN char
102 		 */
103 		return ((caddr_t)zero);
104 	}
105 
106 	if (sr->extent.y > 16) {
107 		for (i = 0; i < 24; i++) {
108 			tmpfnt[i] = (*tmp << 16) | *(tmp + 2);
109 			tmp += 4;
110 		}
111 	} else {
112 		for (i = 0; i < 16; i++) {
113 			tmpfnt[i] = (*tmp << 16) | *(tmp + 2);
114 			tmp += 4;
115 		}
116 	}
117 
118 	return ((caddr_t)tmpfnt);
119 }
120 #endif /* news3200 */
121 
122 static int
123 fblfbm_set_dimmer(fb, dim)
124 	struct fbdev *fb;
125 	int dim;
126 {
127 	int s;
128 
129 	fb->status_flag = dim ? 0xf1: 0xf0;
130 #ifdef news3200
131 	*DIMMER_PORT = fb->status_flag;
132 #endif
133 	return (FB_ROK);
134 }
135 
136 static int
137 fblfbm_get_dimmer(fb)
138 	struct fbdev *fb;
139 {
140 	return (fb->status_flag & 0x1);
141 }
142 
143 int
144 fblfbm_get_pixel(fb, pixel)
145 	struct fbdev *fb;
146 	register int pixel;
147 {
148 	return (pixel);
149 }
150 
151 int
152 fblfbm_get_page(fb, off)
153 	struct fbdev *fb;
154 	off_t off;
155 {
156 	if (off < 1120/8 * 930) {		/* X/8 * Y */
157 #ifdef news3200
158 		return (((unsigned int)0x10200000 + off) >> PGSHIFT);
159 #endif
160 	} else
161 		return (-1);
162 }
163 
164 int
165 fblfbm_probe(unit)
166 	int unit;
167 {
168 #ifdef news3200
169 	if (unit < NLFBM) {
170 		if (badaddr(0xbff50000, 1))
171 			return 0;
172 		else {
173 			if (*(volatile u_char *)(0xbff50000) == 0xff)
174 				return FB_LCDM;
175 			else
176 				return 0;
177 		}
178 	}
179 #endif /* news3200 */
180 	return 0;
181 }
182 
183 void fbmem_rop_init();
184 void fbmem_rop_copy();
185 void fbmem_rop_winit();
186 void fbmem_rop_write();
187 void fbmem_rop_read();
188 void fbmem_rop_cinit();
189 void fbmem_rop_clear();
190 void fbmem_rop_vect();
191 void fbmem_rop_dot();
192 
193 struct fbdev_ops fblfbm_ops = {
194 	fbmem_rop_init,			/* (*fb_rop_init)() */
195 	fbmem_rop_copy,			/* (*fb_rop_copy)() */
196 	fbmem_rop_winit,		/* (*fb_rop_winit)() */
197 	fbmem_rop_write,		/* (*fb_rop_write)() */
198 	fbmem_rop_read,			/* (*fb_rop_read)() */
199 	fbmem_rop_cinit,		/* (*fb_rop_cinit)() */
200 	fbmem_rop_clear,		/* (*fb_rop_clear)() */
201 	fbmem_rop_vect,			/* (*fb_rop_vect)() */
202 	fbmem_rop_dot,			/* (*fb_rop_dot)() */
203 	(void (*)())nofunc,		/* (*fb_rop_fillscan)() */
204 	(void (*)())error,		/* (*fb_rop_wait)() */
205 	(void (*)())error,		/* (*fb_rop_reset)() */
206 	fblfbm_Krom_addr,		/* *(*fb_Krom_addr)() */
207 	(void (*)())error,		/* (*fb_init_palette)() */
208 	error,				/* (*fb_set_palette)() */
209 	error,				/* (*fb_get_palette)() */
210 	fblfbm_get_pixel,		/* (*fb_get_pixel)() */
211 	fblfbm_set_dimmer,		/* (*fb_set_dimmer)() */
212 	fblfbm_get_dimmer,		/* (*fb_get_dimmer)() */
213 	nofunc,				/* (*fb_open)() */
214 	nofunc,				/* (*fb_close)() */
215 	nofunc,				/* (*fb_ioctl)() */
216 	fblfbm_get_page,		/* (*fb_get_page)() */
217 	(void (*)())nofunc,		/* (*fb_cursor_set)() */
218 	(void (*)())nofunc,		/* (*fb_cursor_on)() */
219 	(void (*)())nofunc,		/* (*fb_cursor_off)() */
220 	(void (*)())nofunc,		/* (*fb_cursor_move)() */
221 };
222 
223 static char lctc_data[] = {
224 	0, 47,
225 	1, 35,
226 	9, 0,
227 	10, 0,
228 	11, 0,
229 	12, 0,
230 	13, 0,
231 	14, 0,
232 	15, 0,
233 	18, 35,
234 	19, 0x01,
235 	20, 0x85,
236 	21, 0,
237 	22, 0x10
238 };
239 
240 struct mfbdev fblcd = { (caddr_t)VRAM_START, VRAM_WIDTH };
241 
242 void
243 fblfbm_setup(fb)
244 	register struct fbdev *fb;
245 {
246 	register int i;
247 	register volatile unsigned char *lctreg = LCD_CRTC;
248 
249 	if (fb->type) {
250 		fb->Mono = 1;
251 		fb->Colorwidth = 1;
252 		fb->fbNplane = 1;
253 		fb->planemask = 0x1;
254 		fb->Dimmer = 1;
255 
256 		fb->FrameRect.origin.x = 0;
257 		fb->FrameRect.origin.y = 0;
258 		fb->FrameRect.extent.x = 1120;
259 		fb->FrameRect.extent.y = 930;
260 		fb->VisRect.origin.x = 0;
261 		fb->VisRect.origin.y = 0;
262 		fb->VisRect.extent.x = 1120;
263 		fb->VisRect.extent.y = 780;
264 		fb->Krom_BM0.type = BM_MEM;
265 		fb->Krom_BM0.depth = 1;
266 		fb->Krom_BM0.width = 1;
267 		fb->Krom_BM0.rect.origin.x = 0;
268 		fb->Krom_BM0.rect.origin.y = 0;
269 		fb->Krom_BM0.rect.extent.x = 16;
270 		fb->Krom_BM0.rect.extent.y = 16;
271 		fb->Krom_BM1.type = BM_MEM;
272 		fb->Krom_BM1.depth = 1;
273 		fb->Krom_BM1.width = 2;
274 		fb->Krom_BM1.rect.origin.x = 0;
275 		fb->Krom_BM1.rect.origin.y = 0;
276 		fb->Krom_BM1.rect.extent.x = 32;
277 		fb->Krom_BM1.rect.extent.y = 32;
278 		fb->Krom_base = KROM_START;
279 		fb->Krom_font_extent0.x = 16;
280 		fb->Krom_font_extent0.y = 16;
281 		fb->Krom_font_extent1.x = 24;
282 		fb->Krom_font_extent1.y = 24;
283 		fb->font_w = 12;
284 		fb->font_h = 24;
285 		fb->char_w = 12;
286 		fb->char_h = 26;
287 		fb->scr_w = 1120;
288 		fb->scr_h = 780;
289 		fb->ch_pos = 0;
290 		fb->ul_pos = 24;
291 		fb->x_offset = (1120 - (80 * 12)) / 2;
292 		fb->y_offset = ( 780 - (29 * 26)) / 2;
293 		fb->rit_m = 80;
294 		fb->btm_m = 29;
295 		fb->cursorSet = 0;
296 		fb->cursorVis = 0;
297 		fb->cursorShow = 0;
298 		fb->cursorP.x = 1120/2;
299 		fb->cursorP.y = 780/2;
300 		fb->status_flag = 1;
301 		fb->run_flag = 0;
302 		fb->hard_cursor = 0;
303 
304 		fb->fbbm_op = &fblfbm_ops;
305 
306 		fb->private = (caddr_t)&fblcd;
307 
308 		for (i = 0; i < 28; i++)
309 			*lctreg++ = lctc_data[i];
310 		for (i = 0; i < 500000; i ++)
311 			;
312 		*LCD_PORT = 1;
313 	}
314 }
315 #endif /* NLFBM > 0 */
316