Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * newport_con.c: Abscon for newport hardware | |
3 | * | |
4 | * (C) 1998 Thomas Bogendoerfer (tsbogend@alpha.franken.de) | |
5 | * (C) 1999 Ulf Carlsson (ulfc@thepuffingruop.com) | |
6 | * | |
7 | * This driver is based on sgicons.c and cons_newport. | |
8 | * | |
79add627 | 9 | * Copyright (C) 1996 David S. Miller (davem@davemloft.net) |
1da177e4 LT |
10 | * Copyright (C) 1997 Miguel de Icaza (miguel@nuclecu.unam.mx) |
11 | */ | |
12 | #include <linux/init.h> | |
13 | #include <linux/kernel.h> | |
14 | #include <linux/errno.h> | |
1da177e4 LT |
15 | #include <linux/kd.h> |
16 | #include <linux/selection.h> | |
17 | #include <linux/console.h> | |
18 | #include <linux/vt_kern.h> | |
19 | #include <linux/mm.h> | |
20 | #include <linux/module.h> | |
21 | #include <linux/slab.h> | |
22 | ||
23 | #include <asm/io.h> | |
24 | #include <asm/uaccess.h> | |
25 | #include <asm/system.h> | |
26 | #include <asm/page.h> | |
27 | #include <asm/pgtable.h> | |
e84de0c6 TB |
28 | #include <asm/gio_device.h> |
29 | ||
1da177e4 LT |
30 | #include <video/newport.h> |
31 | ||
32 | #include <linux/linux_logo.h> | |
33 | #include <linux/font.h> | |
34 | ||
1da177e4 LT |
35 | #define FONT_DATA ((unsigned char *)font_vga_8x16.data) |
36 | ||
37 | /* borrowed from fbcon.c */ | |
38 | #define REFCOUNT(fd) (((int *)(fd))[-1]) | |
39 | #define FNTSIZE(fd) (((int *)(fd))[-2]) | |
40 | #define FNTCHARCNT(fd) (((int *)(fd))[-3]) | |
41 | #define FONT_EXTRA_WORDS 3 | |
42 | ||
43 | static unsigned char *font_data[MAX_NR_CONSOLES]; | |
44 | ||
45 | static struct newport_regs *npregs; | |
46 | ||
47 | static int logo_active; | |
48 | static int topscan; | |
49 | static int xcurs_correction = 29; | |
50 | static int newport_xsize; | |
51 | static int newport_ysize; | |
e86bb8ac | 52 | static int newport_has_init; |
1da177e4 LT |
53 | |
54 | static int newport_set_def_font(int unit, struct console_font *op); | |
55 | ||
56 | #define BMASK(c) (c << 24) | |
57 | ||
58 | #define RENDER(regs, cp) do { \ | |
59 | (regs)->go.zpattern = BMASK((cp)[0x0]); (regs)->go.zpattern = BMASK((cp)[0x1]); \ | |
60 | (regs)->go.zpattern = BMASK((cp)[0x2]); (regs)->go.zpattern = BMASK((cp)[0x3]); \ | |
61 | (regs)->go.zpattern = BMASK((cp)[0x4]); (regs)->go.zpattern = BMASK((cp)[0x5]); \ | |
62 | (regs)->go.zpattern = BMASK((cp)[0x6]); (regs)->go.zpattern = BMASK((cp)[0x7]); \ | |
63 | (regs)->go.zpattern = BMASK((cp)[0x8]); (regs)->go.zpattern = BMASK((cp)[0x9]); \ | |
64 | (regs)->go.zpattern = BMASK((cp)[0xa]); (regs)->go.zpattern = BMASK((cp)[0xb]); \ | |
65 | (regs)->go.zpattern = BMASK((cp)[0xc]); (regs)->go.zpattern = BMASK((cp)[0xd]); \ | |
66 | (regs)->go.zpattern = BMASK((cp)[0xe]); (regs)->go.zpattern = BMASK((cp)[0xf]); \ | |
67 | } while(0) | |
68 | ||
69 | #define TESTVAL 0xdeadbeef | |
70 | #define XSTI_TO_FXSTART(val) (((val) & 0xffff) << 11) | |
71 | ||
72 | static inline void newport_render_background(int xstart, int ystart, | |
73 | int xend, int yend, int ci) | |
74 | { | |
75 | newport_wait(npregs); | |
76 | npregs->set.wrmask = 0xffffffff; | |
77 | npregs->set.drawmode0 = (NPORT_DMODE0_DRAW | NPORT_DMODE0_BLOCK | | |
78 | NPORT_DMODE0_DOSETUP | NPORT_DMODE0_STOPX | |
79 | | NPORT_DMODE0_STOPY); | |
80 | npregs->set.colori = ci; | |
81 | npregs->set.xystarti = | |
82 | (xstart << 16) | ((ystart + topscan) & 0x3ff); | |
83 | npregs->go.xyendi = | |
84 | ((xend + 7) << 16) | ((yend + topscan + 15) & 0x3ff); | |
85 | } | |
86 | ||
87 | static inline void newport_init_cmap(void) | |
88 | { | |
89 | unsigned short i; | |
90 | ||
91 | for (i = 0; i < 16; i++) { | |
92 | newport_bfwait(npregs); | |
93 | newport_cmap_setaddr(npregs, color_table[i]); | |
94 | newport_cmap_setrgb(npregs, | |
95 | default_red[i], | |
96 | default_grn[i], default_blu[i]); | |
97 | } | |
98 | } | |
99 | ||
53da0563 | 100 | static const struct linux_logo *newport_show_logo(void) |
1da177e4 LT |
101 | { |
102 | #ifdef CONFIG_LOGO_SGI_CLUT224 | |
103 | const struct linux_logo *logo = fb_find_logo(8); | |
accaa24c RD |
104 | const unsigned char *clut; |
105 | const unsigned char *data; | |
1da177e4 LT |
106 | unsigned long i; |
107 | ||
accaa24c RD |
108 | if (!logo) |
109 | return NULL; | |
53da0563 RB |
110 | clut = logo->clut; |
111 | data = logo->data; | |
accaa24c | 112 | |
1da177e4 LT |
113 | for (i = 0; i < logo->clutsize; i++) { |
114 | newport_bfwait(npregs); | |
115 | newport_cmap_setaddr(npregs, i + 0x20); | |
116 | newport_cmap_setrgb(npregs, clut[0], clut[1], clut[2]); | |
117 | clut += 3; | |
118 | } | |
119 | ||
120 | newport_wait(npregs); | |
121 | npregs->set.drawmode0 = (NPORT_DMODE0_DRAW | NPORT_DMODE0_BLOCK | | |
122 | NPORT_DMODE0_CHOST); | |
123 | ||
124 | npregs->set.xystarti = ((newport_xsize - logo->width) << 16) | (0); | |
125 | npregs->set.xyendi = ((newport_xsize - 1) << 16); | |
126 | newport_wait(npregs); | |
127 | ||
128 | for (i = 0; i < logo->width*logo->height; i++) | |
129 | npregs->go.hostrw0 = *data++ << 24; | |
accaa24c RD |
130 | |
131 | return logo; | |
1da177e4 LT |
132 | #endif /* CONFIG_LOGO_SGI_CLUT224 */ |
133 | } | |
134 | ||
135 | static inline void newport_clear_screen(int xstart, int ystart, int xend, | |
136 | int yend, int ci) | |
137 | { | |
138 | if (logo_active) | |
139 | return; | |
140 | ||
141 | newport_wait(npregs); | |
142 | npregs->set.wrmask = 0xffffffff; | |
143 | npregs->set.drawmode0 = (NPORT_DMODE0_DRAW | NPORT_DMODE0_BLOCK | | |
144 | NPORT_DMODE0_DOSETUP | NPORT_DMODE0_STOPX | |
145 | | NPORT_DMODE0_STOPY); | |
146 | npregs->set.colori = ci; | |
147 | npregs->set.xystarti = (xstart << 16) | ystart; | |
148 | npregs->go.xyendi = (xend << 16) | yend; | |
149 | } | |
150 | ||
151 | static inline void newport_clear_lines(int ystart, int yend, int ci) | |
152 | { | |
153 | ystart = ((ystart << 4) + topscan) & 0x3ff; | |
154 | yend = ((yend << 4) + topscan + 15) & 0x3ff; | |
155 | newport_clear_screen(0, ystart, 1280 + 63, yend, ci); | |
156 | } | |
157 | ||
ac3f9087 | 158 | static void newport_reset(void) |
1da177e4 LT |
159 | { |
160 | unsigned short treg; | |
161 | int i; | |
162 | ||
163 | newport_wait(npregs); | |
164 | treg = newport_vc2_get(npregs, VC2_IREG_CONTROL); | |
165 | newport_vc2_set(npregs, VC2_IREG_CONTROL, | |
166 | (treg | VC2_CTRL_EVIDEO)); | |
167 | ||
168 | treg = newport_vc2_get(npregs, VC2_IREG_CENTRY); | |
169 | newport_vc2_set(npregs, VC2_IREG_RADDR, treg); | |
170 | npregs->set.dcbmode = (NPORT_DMODE_AVC2 | VC2_REGADDR_RAM | | |
171 | NPORT_DMODE_W2 | VC2_PROTOCOL); | |
172 | for (i = 0; i < 128; i++) { | |
173 | newport_bfwait(npregs); | |
174 | if (i == 92 || i == 94) | |
175 | npregs->set.dcbdata0.byshort.s1 = 0xff00; | |
176 | else | |
177 | npregs->set.dcbdata0.byshort.s1 = 0x0000; | |
178 | } | |
179 | ||
180 | newport_init_cmap(); | |
181 | ||
182 | /* turn off popup plane */ | |
183 | npregs->set.dcbmode = (DCB_XMAP0 | R_DCB_XMAP9_PROTOCOL | | |
184 | XM9_CRS_CONFIG | NPORT_DMODE_W1); | |
185 | npregs->set.dcbdata0.bybytes.b3 &= ~XM9_PUPMODE; | |
186 | npregs->set.dcbmode = (DCB_XMAP1 | R_DCB_XMAP9_PROTOCOL | | |
187 | XM9_CRS_CONFIG | NPORT_DMODE_W1); | |
188 | npregs->set.dcbdata0.bybytes.b3 &= ~XM9_PUPMODE; | |
189 | ||
190 | topscan = 0; | |
191 | npregs->cset.topscan = 0x3ff; | |
192 | npregs->cset.xywin = (4096 << 16) | 4096; | |
193 | ||
194 | /* Clear the screen. */ | |
195 | newport_clear_screen(0, 0, 1280 + 63, 1024, 0); | |
196 | } | |
197 | ||
198 | /* | |
199 | * calculate the actual screen size by reading | |
200 | * the video timing out of the VC2 | |
201 | */ | |
ac3f9087 | 202 | static void newport_get_screensize(void) |
1da177e4 LT |
203 | { |
204 | int i, cols; | |
205 | unsigned short ventry, treg; | |
206 | unsigned short linetable[128]; /* should be enough */ | |
207 | ||
208 | ventry = newport_vc2_get(npregs, VC2_IREG_VENTRY); | |
209 | newport_vc2_set(npregs, VC2_IREG_RADDR, ventry); | |
210 | npregs->set.dcbmode = (NPORT_DMODE_AVC2 | VC2_REGADDR_RAM | | |
211 | NPORT_DMODE_W2 | VC2_PROTOCOL); | |
212 | for (i = 0; i < 128; i++) { | |
213 | newport_bfwait(npregs); | |
214 | linetable[i] = npregs->set.dcbdata0.byshort.s1; | |
215 | } | |
216 | ||
217 | newport_xsize = newport_ysize = 0; | |
f7a595e9 | 218 | for (i = 0; i < ARRAY_SIZE(linetable) - 1 && linetable[i + 1]; i += 2) { |
1da177e4 LT |
219 | cols = 0; |
220 | newport_vc2_set(npregs, VC2_IREG_RADDR, linetable[i]); | |
221 | npregs->set.dcbmode = (NPORT_DMODE_AVC2 | VC2_REGADDR_RAM | | |
222 | NPORT_DMODE_W2 | VC2_PROTOCOL); | |
223 | do { | |
224 | newport_bfwait(npregs); | |
225 | treg = npregs->set.dcbdata0.byshort.s1; | |
226 | if ((treg & 1) == 0) | |
227 | cols += (treg >> 7) & 0xfe; | |
228 | if ((treg & 0x80) == 0) { | |
229 | newport_bfwait(npregs); | |
230 | treg = npregs->set.dcbdata0.byshort.s1; | |
231 | } | |
232 | } while ((treg & 0x8000) == 0); | |
233 | if (cols) { | |
234 | if (cols > newport_xsize) | |
235 | newport_xsize = cols; | |
236 | newport_ysize += linetable[i + 1]; | |
237 | } | |
238 | } | |
239 | printk("NG1: Screensize %dx%d\n", newport_xsize, newport_ysize); | |
240 | } | |
241 | ||
242 | static void newport_get_revisions(void) | |
243 | { | |
244 | unsigned int tmp; | |
245 | unsigned int board_rev; | |
246 | unsigned int rex3_rev; | |
247 | unsigned int vc2_rev; | |
248 | unsigned int cmap_rev; | |
249 | unsigned int xmap9_rev; | |
250 | unsigned int bt445_rev; | |
251 | unsigned int bitplanes; | |
252 | ||
253 | rex3_rev = npregs->cset.status & NPORT_STAT_VERS; | |
254 | ||
255 | npregs->set.dcbmode = (DCB_CMAP0 | NCMAP_PROTOCOL | | |
256 | NCMAP_REGADDR_RREG | NPORT_DMODE_W1); | |
257 | tmp = npregs->set.dcbdata0.bybytes.b3; | |
258 | cmap_rev = tmp & 7; | |
259 | board_rev = (tmp >> 4) & 7; | |
260 | bitplanes = ((board_rev > 1) && (tmp & 0x80)) ? 8 : 24; | |
261 | ||
262 | npregs->set.dcbmode = (DCB_CMAP1 | NCMAP_PROTOCOL | | |
263 | NCMAP_REGADDR_RREG | NPORT_DMODE_W1); | |
264 | tmp = npregs->set.dcbdata0.bybytes.b3; | |
265 | if ((tmp & 7) < cmap_rev) | |
266 | cmap_rev = (tmp & 7); | |
267 | ||
268 | vc2_rev = (newport_vc2_get(npregs, VC2_IREG_CONFIG) >> 5) & 7; | |
269 | ||
270 | npregs->set.dcbmode = (DCB_XMAP0 | R_DCB_XMAP9_PROTOCOL | | |
271 | XM9_CRS_REVISION | NPORT_DMODE_W1); | |
272 | xmap9_rev = npregs->set.dcbdata0.bybytes.b3 & 7; | |
273 | ||
274 | npregs->set.dcbmode = (DCB_BT445 | BT445_PROTOCOL | | |
275 | BT445_CSR_ADDR_REG | NPORT_DMODE_W1); | |
276 | npregs->set.dcbdata0.bybytes.b3 = BT445_REVISION_REG; | |
277 | npregs->set.dcbmode = (DCB_BT445 | BT445_PROTOCOL | | |
278 | BT445_CSR_REVISION | NPORT_DMODE_W1); | |
279 | bt445_rev = (npregs->set.dcbdata0.bybytes.b3 >> 4) - 0x0a; | |
280 | ||
281 | #define L(a) (char)('A'+(a)) | |
282 | printk | |
283 | ("NG1: Revision %d, %d bitplanes, REX3 revision %c, VC2 revision %c, xmap9 revision %c, cmap revision %c, bt445 revision %c\n", | |
284 | board_rev, bitplanes, L(rex3_rev), L(vc2_rev), L(xmap9_rev), | |
285 | L(cmap_rev ? (cmap_rev + 1) : 0), L(bt445_rev)); | |
286 | #undef L | |
287 | ||
288 | if (board_rev == 3) /* I don't know all affected revisions */ | |
289 | xcurs_correction = 21; | |
290 | } | |
291 | ||
e86bb8ac AD |
292 | static void newport_exit(void) |
293 | { | |
294 | int i; | |
295 | ||
296 | /* free memory used by user font */ | |
297 | for (i = 0; i < MAX_NR_CONSOLES; i++) | |
298 | newport_set_def_font(i, NULL); | |
299 | } | |
300 | ||
1da177e4 LT |
301 | /* Can't be __init, take_over_console may call it later */ |
302 | static const char *newport_startup(void) | |
303 | { | |
304 | int i; | |
305 | ||
1da177e4 LT |
306 | npregs->cset.config = NPORT_CFG_GD0; |
307 | ||
308 | if (newport_wait(npregs)) | |
309 | goto out_unmap; | |
310 | ||
311 | npregs->set.xstarti = TESTVAL; | |
312 | if (npregs->set._xstart.word != XSTI_TO_FXSTART(TESTVAL)) | |
313 | goto out_unmap; | |
314 | ||
315 | for (i = 0; i < MAX_NR_CONSOLES; i++) | |
316 | font_data[i] = FONT_DATA; | |
317 | ||
318 | newport_reset(); | |
319 | newport_get_revisions(); | |
320 | newport_get_screensize(); | |
e86bb8ac | 321 | newport_has_init = 1; |
1da177e4 LT |
322 | |
323 | return "SGI Newport"; | |
324 | ||
325 | out_unmap: | |
1da177e4 LT |
326 | return NULL; |
327 | } | |
328 | ||
329 | static void newport_init(struct vc_data *vc, int init) | |
330 | { | |
331 | vc->vc_cols = newport_xsize / 8; | |
332 | vc->vc_rows = newport_ysize / 16; | |
333 | vc->vc_can_do_color = 1; | |
334 | } | |
335 | ||
336 | static void newport_deinit(struct vc_data *c) | |
337 | { | |
e86bb8ac AD |
338 | if (!con_is_bound(&newport_con) && newport_has_init) { |
339 | newport_exit(); | |
340 | newport_has_init = 0; | |
341 | } | |
1da177e4 LT |
342 | } |
343 | ||
344 | static void newport_clear(struct vc_data *vc, int sy, int sx, int height, | |
345 | int width) | |
346 | { | |
347 | int xend = ((sx + width) << 3) - 1; | |
348 | int ystart = ((sy << 4) + topscan) & 0x3ff; | |
349 | int yend = (((sy + height) << 4) + topscan - 1) & 0x3ff; | |
350 | ||
351 | if (logo_active) | |
352 | return; | |
353 | ||
354 | if (ystart < yend) { | |
355 | newport_clear_screen(sx << 3, ystart, xend, yend, | |
356 | (vc->vc_color & 0xf0) >> 4); | |
357 | } else { | |
358 | newport_clear_screen(sx << 3, ystart, xend, 1023, | |
359 | (vc->vc_color & 0xf0) >> 4); | |
360 | newport_clear_screen(sx << 3, 0, xend, yend, | |
361 | (vc->vc_color & 0xf0) >> 4); | |
362 | } | |
363 | } | |
364 | ||
365 | static void newport_putc(struct vc_data *vc, int charattr, int ypos, | |
366 | int xpos) | |
367 | { | |
368 | unsigned char *p; | |
369 | ||
370 | p = &font_data[vc->vc_num][(charattr & 0xff) << 4]; | |
371 | charattr = (charattr >> 8) & 0xff; | |
372 | xpos <<= 3; | |
373 | ypos <<= 4; | |
374 | ||
375 | newport_render_background(xpos, ypos, xpos, ypos, | |
376 | (charattr & 0xf0) >> 4); | |
377 | ||
378 | /* Set the color and drawing mode. */ | |
379 | newport_wait(npregs); | |
380 | npregs->set.colori = charattr & 0xf; | |
381 | npregs->set.drawmode0 = (NPORT_DMODE0_DRAW | NPORT_DMODE0_BLOCK | | |
382 | NPORT_DMODE0_STOPX | NPORT_DMODE0_ZPENAB | | |
383 | NPORT_DMODE0_L32); | |
384 | ||
385 | /* Set coordinates for bitmap operation. */ | |
386 | npregs->set.xystarti = (xpos << 16) | ((ypos + topscan) & 0x3ff); | |
387 | npregs->set.xyendi = ((xpos + 7) << 16); | |
388 | newport_wait(npregs); | |
389 | ||
390 | /* Go, baby, go... */ | |
391 | RENDER(npregs, p); | |
392 | } | |
393 | ||
394 | static void newport_putcs(struct vc_data *vc, const unsigned short *s, | |
395 | int count, int ypos, int xpos) | |
396 | { | |
397 | int i; | |
398 | int charattr; | |
399 | unsigned char *p; | |
400 | ||
401 | charattr = (scr_readw(s) >> 8) & 0xff; | |
402 | ||
403 | xpos <<= 3; | |
404 | ypos <<= 4; | |
405 | ||
406 | if (!logo_active) | |
407 | /* Clear the area behing the string */ | |
408 | newport_render_background(xpos, ypos, | |
409 | xpos + ((count - 1) << 3), ypos, | |
410 | (charattr & 0xf0) >> 4); | |
411 | ||
412 | newport_wait(npregs); | |
413 | ||
414 | /* Set the color and drawing mode. */ | |
415 | npregs->set.colori = charattr & 0xf; | |
416 | npregs->set.drawmode0 = (NPORT_DMODE0_DRAW | NPORT_DMODE0_BLOCK | | |
417 | NPORT_DMODE0_STOPX | NPORT_DMODE0_ZPENAB | | |
418 | NPORT_DMODE0_L32); | |
419 | ||
420 | for (i = 0; i < count; i++, xpos += 8) { | |
421 | p = &font_data[vc->vc_num][(scr_readw(s++) & 0xff) << 4]; | |
422 | ||
423 | newport_wait(npregs); | |
424 | ||
425 | /* Set coordinates for bitmap operation. */ | |
426 | npregs->set.xystarti = | |
427 | (xpos << 16) | ((ypos + topscan) & 0x3ff); | |
428 | npregs->set.xyendi = ((xpos + 7) << 16); | |
429 | ||
430 | /* Go, baby, go... */ | |
431 | RENDER(npregs, p); | |
432 | } | |
433 | } | |
434 | ||
435 | static void newport_cursor(struct vc_data *vc, int mode) | |
436 | { | |
437 | unsigned short treg; | |
438 | int xcurs, ycurs; | |
439 | ||
440 | switch (mode) { | |
441 | case CM_ERASE: | |
442 | treg = newport_vc2_get(npregs, VC2_IREG_CONTROL); | |
443 | newport_vc2_set(npregs, VC2_IREG_CONTROL, | |
444 | (treg & ~(VC2_CTRL_ECDISP))); | |
445 | break; | |
446 | ||
447 | case CM_MOVE: | |
448 | case CM_DRAW: | |
449 | treg = newport_vc2_get(npregs, VC2_IREG_CONTROL); | |
450 | newport_vc2_set(npregs, VC2_IREG_CONTROL, | |
451 | (treg | VC2_CTRL_ECDISP)); | |
452 | xcurs = (vc->vc_pos - vc->vc_visible_origin) / 2; | |
453 | ycurs = ((xcurs / vc->vc_cols) << 4) + 31; | |
454 | xcurs = ((xcurs % vc->vc_cols) << 3) + xcurs_correction; | |
455 | newport_vc2_set(npregs, VC2_IREG_CURSX, xcurs); | |
456 | newport_vc2_set(npregs, VC2_IREG_CURSY, ycurs); | |
457 | } | |
458 | } | |
459 | ||
460 | static int newport_switch(struct vc_data *vc) | |
461 | { | |
462 | static int logo_drawn = 0; | |
463 | ||
464 | topscan = 0; | |
465 | npregs->cset.topscan = 0x3ff; | |
466 | ||
467 | if (!logo_drawn) { | |
accaa24c RD |
468 | if (newport_show_logo()) { |
469 | logo_drawn = 1; | |
470 | logo_active = 1; | |
471 | } | |
1da177e4 LT |
472 | } |
473 | ||
474 | return 1; | |
475 | } | |
476 | ||
477 | static int newport_blank(struct vc_data *c, int blank, int mode_switch) | |
478 | { | |
479 | unsigned short treg; | |
480 | ||
481 | if (blank == 0) { | |
482 | /* unblank console */ | |
483 | treg = newport_vc2_get(npregs, VC2_IREG_CONTROL); | |
484 | newport_vc2_set(npregs, VC2_IREG_CONTROL, | |
485 | (treg | VC2_CTRL_EDISP)); | |
486 | } else { | |
487 | /* blank console */ | |
488 | treg = newport_vc2_get(npregs, VC2_IREG_CONTROL); | |
489 | newport_vc2_set(npregs, VC2_IREG_CONTROL, | |
490 | (treg & ~(VC2_CTRL_EDISP))); | |
491 | } | |
492 | return 1; | |
493 | } | |
494 | ||
495 | static int newport_set_font(int unit, struct console_font *op) | |
496 | { | |
497 | int w = op->width; | |
498 | int h = op->height; | |
499 | int size = h * op->charcount; | |
500 | int i; | |
501 | unsigned char *new_data, *data = op->data, *p; | |
502 | ||
503 | /* ladis: when I grow up, there will be a day... and more sizes will | |
504 | * be supported ;-) */ | |
505 | if ((w != 8) || (h != 16) | |
506 | || (op->charcount != 256 && op->charcount != 512)) | |
507 | return -EINVAL; | |
508 | ||
509 | if (!(new_data = kmalloc(FONT_EXTRA_WORDS * sizeof(int) + size, | |
510 | GFP_USER))) return -ENOMEM; | |
511 | ||
512 | new_data += FONT_EXTRA_WORDS * sizeof(int); | |
513 | FNTSIZE(new_data) = size; | |
514 | FNTCHARCNT(new_data) = op->charcount; | |
515 | REFCOUNT(new_data) = 0; /* usage counter */ | |
516 | ||
517 | p = new_data; | |
518 | for (i = 0; i < op->charcount; i++) { | |
519 | memcpy(p, data, h); | |
520 | data += 32; | |
521 | p += h; | |
522 | } | |
523 | ||
524 | /* check if font is already used by other console */ | |
525 | for (i = 0; i < MAX_NR_CONSOLES; i++) { | |
526 | if (font_data[i] != FONT_DATA | |
527 | && FNTSIZE(font_data[i]) == size | |
528 | && !memcmp(font_data[i], new_data, size)) { | |
529 | kfree(new_data - FONT_EXTRA_WORDS * sizeof(int)); | |
530 | /* current font is the same as the new one */ | |
531 | if (i == unit) | |
532 | return 0; | |
533 | new_data = font_data[i]; | |
534 | break; | |
535 | } | |
536 | } | |
537 | /* old font is user font */ | |
538 | if (font_data[unit] != FONT_DATA) { | |
539 | if (--REFCOUNT(font_data[unit]) == 0) | |
540 | kfree(font_data[unit] - | |
541 | FONT_EXTRA_WORDS * sizeof(int)); | |
542 | } | |
543 | REFCOUNT(new_data)++; | |
544 | font_data[unit] = new_data; | |
545 | ||
546 | return 0; | |
547 | } | |
548 | ||
549 | static int newport_set_def_font(int unit, struct console_font *op) | |
550 | { | |
551 | if (font_data[unit] != FONT_DATA) { | |
552 | if (--REFCOUNT(font_data[unit]) == 0) | |
553 | kfree(font_data[unit] - | |
554 | FONT_EXTRA_WORDS * sizeof(int)); | |
555 | font_data[unit] = FONT_DATA; | |
556 | } | |
557 | ||
558 | return 0; | |
559 | } | |
560 | ||
561 | static int newport_font_default(struct vc_data *vc, struct console_font *op, char *name) | |
562 | { | |
563 | return newport_set_def_font(vc->vc_num, op); | |
564 | } | |
565 | ||
566 | static int newport_font_set(struct vc_data *vc, struct console_font *font, unsigned flags) | |
567 | { | |
568 | return newport_set_font(vc->vc_num, font); | |
569 | } | |
570 | ||
571 | static int newport_set_palette(struct vc_data *vc, unsigned char *table) | |
572 | { | |
573 | return -EINVAL; | |
574 | } | |
575 | ||
576 | static int newport_scrolldelta(struct vc_data *vc, int lines) | |
577 | { | |
578 | /* there is (nearly) no off-screen memory, so we can't scroll back */ | |
579 | return 0; | |
580 | } | |
581 | ||
582 | static int newport_scroll(struct vc_data *vc, int t, int b, int dir, | |
583 | int lines) | |
584 | { | |
585 | int count, x, y; | |
586 | unsigned short *s, *d; | |
587 | unsigned short chattr; | |
588 | ||
589 | logo_active = 0; /* it's time to disable the logo now.. */ | |
590 | ||
591 | if (t == 0 && b == vc->vc_rows) { | |
592 | if (dir == SM_UP) { | |
593 | topscan = (topscan + (lines << 4)) & 0x3ff; | |
594 | newport_clear_lines(vc->vc_rows - lines, | |
595 | vc->vc_rows - 1, | |
596 | (vc->vc_color & 0xf0) >> 4); | |
597 | } else { | |
598 | topscan = (topscan + (-lines << 4)) & 0x3ff; | |
599 | newport_clear_lines(0, lines - 1, | |
600 | (vc->vc_color & 0xf0) >> 4); | |
601 | } | |
602 | npregs->cset.topscan = (topscan - 1) & 0x3ff; | |
603 | return 0; | |
604 | } | |
605 | ||
606 | count = (b - t - lines) * vc->vc_cols; | |
607 | if (dir == SM_UP) { | |
608 | x = 0; | |
609 | y = t; | |
610 | s = (unsigned short *) (vc->vc_origin + | |
611 | vc->vc_size_row * (t + lines)); | |
612 | d = (unsigned short *) (vc->vc_origin + | |
613 | vc->vc_size_row * t); | |
614 | while (count--) { | |
615 | chattr = scr_readw(s++); | |
616 | if (chattr != scr_readw(d)) { | |
617 | newport_putc(vc, chattr, y, x); | |
618 | scr_writew(chattr, d); | |
619 | } | |
620 | d++; | |
621 | if (++x == vc->vc_cols) { | |
622 | x = 0; | |
623 | y++; | |
624 | } | |
625 | } | |
626 | d = (unsigned short *) (vc->vc_origin + | |
627 | vc->vc_size_row * (b - lines)); | |
628 | x = 0; | |
629 | y = b - lines; | |
630 | for (count = 0; count < (lines * vc->vc_cols); count++) { | |
631 | if (scr_readw(d) != vc->vc_video_erase_char) { | |
632 | newport_putc(vc, vc->vc_video_erase_char, | |
633 | y, x); | |
634 | scr_writew(vc->vc_video_erase_char, d); | |
635 | } | |
636 | d++; | |
637 | if (++x == vc->vc_cols) { | |
638 | x = 0; | |
639 | y++; | |
640 | } | |
641 | } | |
642 | } else { | |
643 | x = vc->vc_cols - 1; | |
644 | y = b - 1; | |
645 | s = (unsigned short *) (vc->vc_origin + | |
646 | vc->vc_size_row * (b - lines) - 2); | |
647 | d = (unsigned short *) (vc->vc_origin + | |
648 | vc->vc_size_row * b - 2); | |
649 | while (count--) { | |
650 | chattr = scr_readw(s--); | |
651 | if (chattr != scr_readw(d)) { | |
652 | newport_putc(vc, chattr, y, x); | |
653 | scr_writew(chattr, d); | |
654 | } | |
655 | d--; | |
656 | if (x-- == 0) { | |
657 | x = vc->vc_cols - 1; | |
658 | y--; | |
659 | } | |
660 | } | |
661 | d = (unsigned short *) (vc->vc_origin + | |
662 | vc->vc_size_row * t); | |
663 | x = 0; | |
664 | y = t; | |
665 | for (count = 0; count < (lines * vc->vc_cols); count++) { | |
666 | if (scr_readw(d) != vc->vc_video_erase_char) { | |
667 | newport_putc(vc, vc->vc_video_erase_char, | |
668 | y, x); | |
669 | scr_writew(vc->vc_video_erase_char, d); | |
670 | } | |
671 | d++; | |
672 | if (++x == vc->vc_cols) { | |
673 | x = 0; | |
674 | y++; | |
675 | } | |
676 | } | |
677 | } | |
678 | return 1; | |
679 | } | |
680 | ||
681 | static void newport_bmove(struct vc_data *vc, int sy, int sx, int dy, | |
682 | int dx, int h, int w) | |
683 | { | |
684 | short xs, ys, xe, ye, xoffs, yoffs, tmp; | |
685 | ||
686 | xs = sx << 3; | |
687 | xe = ((sx + w) << 3) - 1; | |
688 | /* | |
689 | * as bmove is only used to move stuff around in the same line | |
690 | * (h == 1), we don't care about wrap arounds caused by topscan != 0 | |
691 | */ | |
692 | ys = ((sy << 4) + topscan) & 0x3ff; | |
693 | ye = (((sy + h) << 4) - 1 + topscan) & 0x3ff; | |
694 | xoffs = (dx - sx) << 3; | |
695 | yoffs = (dy - sy) << 4; | |
696 | if (xoffs > 0) { | |
697 | /* move to the right, exchange starting points */ | |
698 | tmp = xe; | |
699 | xe = xs; | |
700 | xs = tmp; | |
701 | } | |
702 | newport_wait(npregs); | |
703 | npregs->set.drawmode0 = (NPORT_DMODE0_S2S | NPORT_DMODE0_BLOCK | | |
704 | NPORT_DMODE0_DOSETUP | NPORT_DMODE0_STOPX | |
705 | | NPORT_DMODE0_STOPY); | |
706 | npregs->set.xystarti = (xs << 16) | ys; | |
707 | npregs->set.xyendi = (xe << 16) | ye; | |
708 | npregs->go.xymove = (xoffs << 16) | yoffs; | |
709 | } | |
710 | ||
711 | static int newport_dummy(struct vc_data *c) | |
712 | { | |
713 | return 0; | |
714 | } | |
715 | ||
716 | #define DUMMY (void *) newport_dummy | |
717 | ||
718 | const struct consw newport_con = { | |
719 | .owner = THIS_MODULE, | |
720 | .con_startup = newport_startup, | |
721 | .con_init = newport_init, | |
722 | .con_deinit = newport_deinit, | |
723 | .con_clear = newport_clear, | |
724 | .con_putc = newport_putc, | |
725 | .con_putcs = newport_putcs, | |
726 | .con_cursor = newport_cursor, | |
727 | .con_scroll = newport_scroll, | |
728 | .con_bmove = newport_bmove, | |
729 | .con_switch = newport_switch, | |
730 | .con_blank = newport_blank, | |
731 | .con_font_set = newport_font_set, | |
732 | .con_font_default = newport_font_default, | |
733 | .con_set_palette = newport_set_palette, | |
734 | .con_scrolldelta = newport_scrolldelta, | |
735 | .con_set_origin = DUMMY, | |
736 | .con_save_screen = DUMMY | |
737 | }; | |
738 | ||
e84de0c6 TB |
739 | static int newport_probe(struct gio_device *dev, |
740 | const struct gio_device_id *id) | |
1da177e4 | 741 | { |
e84de0c6 | 742 | unsigned long newport_addr; |
e86bb8ac | 743 | |
e84de0c6 TB |
744 | if (!dev->resource.start) |
745 | return -EINVAL; | |
746 | ||
747 | if (npregs) | |
748 | return -EBUSY; /* we only support one Newport as console */ | |
749 | ||
750 | newport_addr = dev->resource.start + 0xF0000; | |
751 | if (!request_mem_region(newport_addr, 0x10000, "Newport")) | |
752 | return -ENODEV; | |
753 | ||
754 | npregs = (struct newport_regs *)/* ioremap cannot fail */ | |
755 | ioremap(newport_addr, sizeof(struct newport_regs)); | |
e86bb8ac | 756 | |
1da177e4 LT |
757 | return take_over_console(&newport_con, 0, MAX_NR_CONSOLES - 1, 1); |
758 | } | |
759 | ||
e84de0c6 | 760 | static void newport_remove(struct gio_device *dev) |
1da177e4 LT |
761 | { |
762 | give_up_console(&newport_con); | |
763 | iounmap((void *)npregs); | |
764 | } | |
e84de0c6 TB |
765 | |
766 | static struct gio_device_id newport_ids[] = { | |
767 | { .id = 0x7e }, | |
768 | { .id = 0xff } | |
769 | }; | |
770 | ||
771 | MODULE_ALIAS("gio:7e"); | |
772 | ||
773 | static struct gio_driver newport_driver = { | |
774 | .name = "newport", | |
775 | .id_table = newport_ids, | |
776 | .probe = newport_probe, | |
777 | .remove = newport_remove, | |
778 | }; | |
779 | ||
780 | int __init newport_console_init(void) | |
781 | { | |
782 | return gio_register_driver(&newport_driver); | |
783 | } | |
784 | ||
785 | void __exit newport_console_exit(void) | |
786 | { | |
787 | gio_unregister_driver(&newport_driver); | |
788 | } | |
789 | ||
790 | module_init(newport_console_init); | |
1da177e4 | 791 | module_exit(newport_console_exit); |
1da177e4 LT |
792 | |
793 | MODULE_LICENSE("GPL"); |