Commit | Line | Data |
---|---|---|
09c434b8 | 1 | // SPDX-License-Identifier: GPL-2.0-only |
1da177e4 LT |
2 | /* |
3 | * newport_con.c: Abscon for newport hardware | |
4 | * | |
5 | * (C) 1998 Thomas Bogendoerfer (tsbogend@alpha.franken.de) | |
6 | * (C) 1999 Ulf Carlsson (ulfc@thepuffingruop.com) | |
7 | * | |
8 | * This driver is based on sgicons.c and cons_newport. | |
9 | * | |
79add627 | 10 | * Copyright (C) 1996 David S. Miller (davem@davemloft.net) |
1da177e4 LT |
11 | * Copyright (C) 1997 Miguel de Icaza (miguel@nuclecu.unam.mx) |
12 | */ | |
13 | #include <linux/init.h> | |
14 | #include <linux/kernel.h> | |
15 | #include <linux/errno.h> | |
1da177e4 LT |
16 | #include <linux/kd.h> |
17 | #include <linux/selection.h> | |
18 | #include <linux/console.h> | |
19 | #include <linux/vt_kern.h> | |
20 | #include <linux/mm.h> | |
21 | #include <linux/module.h> | |
22 | #include <linux/slab.h> | |
23 | ||
24 | #include <asm/io.h> | |
7c0f6ba6 | 25 | #include <linux/uaccess.h> |
1da177e4 LT |
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 | ||
155957f5 | 301 | /* Can't be __init, do_take_over_console may call it later */ |
1da177e4 LT |
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 | { | |
fa4dbbc6 TB |
331 | int cols, rows; |
332 | ||
333 | cols = newport_xsize / 8; | |
334 | rows = newport_ysize / 16; | |
1da177e4 | 335 | vc->vc_can_do_color = 1; |
fa4dbbc6 TB |
336 | if (init) { |
337 | vc->vc_cols = cols; | |
338 | vc->vc_rows = rows; | |
339 | } else | |
340 | vc_resize(vc, cols, rows); | |
1da177e4 LT |
341 | } |
342 | ||
343 | static void newport_deinit(struct vc_data *c) | |
344 | { | |
e86bb8ac AD |
345 | if (!con_is_bound(&newport_con) && newport_has_init) { |
346 | newport_exit(); | |
347 | newport_has_init = 0; | |
348 | } | |
1da177e4 LT |
349 | } |
350 | ||
351 | static void newport_clear(struct vc_data *vc, int sy, int sx, int height, | |
352 | int width) | |
353 | { | |
354 | int xend = ((sx + width) << 3) - 1; | |
355 | int ystart = ((sy << 4) + topscan) & 0x3ff; | |
356 | int yend = (((sy + height) << 4) + topscan - 1) & 0x3ff; | |
357 | ||
358 | if (logo_active) | |
359 | return; | |
360 | ||
361 | if (ystart < yend) { | |
362 | newport_clear_screen(sx << 3, ystart, xend, yend, | |
363 | (vc->vc_color & 0xf0) >> 4); | |
364 | } else { | |
365 | newport_clear_screen(sx << 3, ystart, xend, 1023, | |
366 | (vc->vc_color & 0xf0) >> 4); | |
367 | newport_clear_screen(sx << 3, 0, xend, yend, | |
368 | (vc->vc_color & 0xf0) >> 4); | |
369 | } | |
370 | } | |
371 | ||
372 | static void newport_putc(struct vc_data *vc, int charattr, int ypos, | |
373 | int xpos) | |
374 | { | |
375 | unsigned char *p; | |
376 | ||
377 | p = &font_data[vc->vc_num][(charattr & 0xff) << 4]; | |
378 | charattr = (charattr >> 8) & 0xff; | |
379 | xpos <<= 3; | |
380 | ypos <<= 4; | |
381 | ||
382 | newport_render_background(xpos, ypos, xpos, ypos, | |
383 | (charattr & 0xf0) >> 4); | |
384 | ||
385 | /* Set the color and drawing mode. */ | |
386 | newport_wait(npregs); | |
387 | npregs->set.colori = charattr & 0xf; | |
388 | npregs->set.drawmode0 = (NPORT_DMODE0_DRAW | NPORT_DMODE0_BLOCK | | |
389 | NPORT_DMODE0_STOPX | NPORT_DMODE0_ZPENAB | | |
390 | NPORT_DMODE0_L32); | |
391 | ||
392 | /* Set coordinates for bitmap operation. */ | |
393 | npregs->set.xystarti = (xpos << 16) | ((ypos + topscan) & 0x3ff); | |
394 | npregs->set.xyendi = ((xpos + 7) << 16); | |
395 | newport_wait(npregs); | |
396 | ||
397 | /* Go, baby, go... */ | |
398 | RENDER(npregs, p); | |
399 | } | |
400 | ||
401 | static void newport_putcs(struct vc_data *vc, const unsigned short *s, | |
402 | int count, int ypos, int xpos) | |
403 | { | |
404 | int i; | |
405 | int charattr; | |
406 | unsigned char *p; | |
407 | ||
408 | charattr = (scr_readw(s) >> 8) & 0xff; | |
409 | ||
410 | xpos <<= 3; | |
411 | ypos <<= 4; | |
412 | ||
413 | if (!logo_active) | |
414 | /* Clear the area behing the string */ | |
415 | newport_render_background(xpos, ypos, | |
416 | xpos + ((count - 1) << 3), ypos, | |
417 | (charattr & 0xf0) >> 4); | |
418 | ||
419 | newport_wait(npregs); | |
420 | ||
421 | /* Set the color and drawing mode. */ | |
422 | npregs->set.colori = charattr & 0xf; | |
423 | npregs->set.drawmode0 = (NPORT_DMODE0_DRAW | NPORT_DMODE0_BLOCK | | |
424 | NPORT_DMODE0_STOPX | NPORT_DMODE0_ZPENAB | | |
425 | NPORT_DMODE0_L32); | |
426 | ||
427 | for (i = 0; i < count; i++, xpos += 8) { | |
428 | p = &font_data[vc->vc_num][(scr_readw(s++) & 0xff) << 4]; | |
429 | ||
430 | newport_wait(npregs); | |
431 | ||
432 | /* Set coordinates for bitmap operation. */ | |
433 | npregs->set.xystarti = | |
434 | (xpos << 16) | ((ypos + topscan) & 0x3ff); | |
435 | npregs->set.xyendi = ((xpos + 7) << 16); | |
436 | ||
437 | /* Go, baby, go... */ | |
438 | RENDER(npregs, p); | |
439 | } | |
440 | } | |
441 | ||
442 | static void newport_cursor(struct vc_data *vc, int mode) | |
443 | { | |
444 | unsigned short treg; | |
445 | int xcurs, ycurs; | |
446 | ||
447 | switch (mode) { | |
448 | case CM_ERASE: | |
449 | treg = newport_vc2_get(npregs, VC2_IREG_CONTROL); | |
450 | newport_vc2_set(npregs, VC2_IREG_CONTROL, | |
451 | (treg & ~(VC2_CTRL_ECDISP))); | |
452 | break; | |
453 | ||
454 | case CM_MOVE: | |
455 | case CM_DRAW: | |
456 | treg = newport_vc2_get(npregs, VC2_IREG_CONTROL); | |
457 | newport_vc2_set(npregs, VC2_IREG_CONTROL, | |
458 | (treg | VC2_CTRL_ECDISP)); | |
459 | xcurs = (vc->vc_pos - vc->vc_visible_origin) / 2; | |
460 | ycurs = ((xcurs / vc->vc_cols) << 4) + 31; | |
461 | xcurs = ((xcurs % vc->vc_cols) << 3) + xcurs_correction; | |
462 | newport_vc2_set(npregs, VC2_IREG_CURSX, xcurs); | |
463 | newport_vc2_set(npregs, VC2_IREG_CURSY, ycurs); | |
464 | } | |
465 | } | |
466 | ||
467 | static int newport_switch(struct vc_data *vc) | |
468 | { | |
469 | static int logo_drawn = 0; | |
470 | ||
471 | topscan = 0; | |
472 | npregs->cset.topscan = 0x3ff; | |
473 | ||
474 | if (!logo_drawn) { | |
accaa24c RD |
475 | if (newport_show_logo()) { |
476 | logo_drawn = 1; | |
477 | logo_active = 1; | |
478 | } | |
1da177e4 LT |
479 | } |
480 | ||
481 | return 1; | |
482 | } | |
483 | ||
484 | static int newport_blank(struct vc_data *c, int blank, int mode_switch) | |
485 | { | |
486 | unsigned short treg; | |
487 | ||
488 | if (blank == 0) { | |
489 | /* unblank console */ | |
490 | treg = newport_vc2_get(npregs, VC2_IREG_CONTROL); | |
491 | newport_vc2_set(npregs, VC2_IREG_CONTROL, | |
492 | (treg | VC2_CTRL_EDISP)); | |
493 | } else { | |
494 | /* blank console */ | |
495 | treg = newport_vc2_get(npregs, VC2_IREG_CONTROL); | |
496 | newport_vc2_set(npregs, VC2_IREG_CONTROL, | |
497 | (treg & ~(VC2_CTRL_EDISP))); | |
498 | } | |
499 | return 1; | |
500 | } | |
501 | ||
502 | static int newport_set_font(int unit, struct console_font *op) | |
503 | { | |
504 | int w = op->width; | |
505 | int h = op->height; | |
506 | int size = h * op->charcount; | |
507 | int i; | |
508 | unsigned char *new_data, *data = op->data, *p; | |
509 | ||
510 | /* ladis: when I grow up, there will be a day... and more sizes will | |
511 | * be supported ;-) */ | |
512 | if ((w != 8) || (h != 16) | |
513 | || (op->charcount != 256 && op->charcount != 512)) | |
514 | return -EINVAL; | |
515 | ||
516 | if (!(new_data = kmalloc(FONT_EXTRA_WORDS * sizeof(int) + size, | |
517 | GFP_USER))) return -ENOMEM; | |
518 | ||
519 | new_data += FONT_EXTRA_WORDS * sizeof(int); | |
520 | FNTSIZE(new_data) = size; | |
521 | FNTCHARCNT(new_data) = op->charcount; | |
522 | REFCOUNT(new_data) = 0; /* usage counter */ | |
523 | ||
524 | p = new_data; | |
525 | for (i = 0; i < op->charcount; i++) { | |
526 | memcpy(p, data, h); | |
527 | data += 32; | |
528 | p += h; | |
529 | } | |
530 | ||
531 | /* check if font is already used by other console */ | |
532 | for (i = 0; i < MAX_NR_CONSOLES; i++) { | |
533 | if (font_data[i] != FONT_DATA | |
534 | && FNTSIZE(font_data[i]) == size | |
535 | && !memcmp(font_data[i], new_data, size)) { | |
536 | kfree(new_data - FONT_EXTRA_WORDS * sizeof(int)); | |
537 | /* current font is the same as the new one */ | |
538 | if (i == unit) | |
539 | return 0; | |
540 | new_data = font_data[i]; | |
541 | break; | |
542 | } | |
543 | } | |
544 | /* old font is user font */ | |
545 | if (font_data[unit] != FONT_DATA) { | |
546 | if (--REFCOUNT(font_data[unit]) == 0) | |
547 | kfree(font_data[unit] - | |
548 | FONT_EXTRA_WORDS * sizeof(int)); | |
549 | } | |
550 | REFCOUNT(new_data)++; | |
551 | font_data[unit] = new_data; | |
552 | ||
553 | return 0; | |
554 | } | |
555 | ||
556 | static int newport_set_def_font(int unit, struct console_font *op) | |
557 | { | |
558 | if (font_data[unit] != FONT_DATA) { | |
559 | if (--REFCOUNT(font_data[unit]) == 0) | |
560 | kfree(font_data[unit] - | |
561 | FONT_EXTRA_WORDS * sizeof(int)); | |
562 | font_data[unit] = FONT_DATA; | |
563 | } | |
564 | ||
565 | return 0; | |
566 | } | |
567 | ||
568 | static int newport_font_default(struct vc_data *vc, struct console_font *op, char *name) | |
569 | { | |
570 | return newport_set_def_font(vc->vc_num, op); | |
571 | } | |
572 | ||
573 | static int newport_font_set(struct vc_data *vc, struct console_font *font, unsigned flags) | |
574 | { | |
575 | return newport_set_font(vc->vc_num, font); | |
576 | } | |
577 | ||
d705ff38 JS |
578 | static bool newport_scroll(struct vc_data *vc, unsigned int t, unsigned int b, |
579 | enum con_scroll dir, unsigned int lines) | |
1da177e4 LT |
580 | { |
581 | int count, x, y; | |
582 | unsigned short *s, *d; | |
583 | unsigned short chattr; | |
584 | ||
585 | logo_active = 0; /* it's time to disable the logo now.. */ | |
586 | ||
587 | if (t == 0 && b == vc->vc_rows) { | |
588 | if (dir == SM_UP) { | |
589 | topscan = (topscan + (lines << 4)) & 0x3ff; | |
590 | newport_clear_lines(vc->vc_rows - lines, | |
591 | vc->vc_rows - 1, | |
592 | (vc->vc_color & 0xf0) >> 4); | |
593 | } else { | |
594 | topscan = (topscan + (-lines << 4)) & 0x3ff; | |
595 | newport_clear_lines(0, lines - 1, | |
596 | (vc->vc_color & 0xf0) >> 4); | |
597 | } | |
598 | npregs->cset.topscan = (topscan - 1) & 0x3ff; | |
d705ff38 | 599 | return false; |
1da177e4 LT |
600 | } |
601 | ||
602 | count = (b - t - lines) * vc->vc_cols; | |
603 | if (dir == SM_UP) { | |
604 | x = 0; | |
605 | y = t; | |
606 | s = (unsigned short *) (vc->vc_origin + | |
607 | vc->vc_size_row * (t + lines)); | |
608 | d = (unsigned short *) (vc->vc_origin + | |
609 | vc->vc_size_row * t); | |
610 | while (count--) { | |
611 | chattr = scr_readw(s++); | |
612 | if (chattr != scr_readw(d)) { | |
613 | newport_putc(vc, chattr, y, x); | |
614 | scr_writew(chattr, d); | |
615 | } | |
616 | d++; | |
617 | if (++x == vc->vc_cols) { | |
618 | x = 0; | |
619 | y++; | |
620 | } | |
621 | } | |
622 | d = (unsigned short *) (vc->vc_origin + | |
623 | vc->vc_size_row * (b - lines)); | |
624 | x = 0; | |
625 | y = b - lines; | |
626 | for (count = 0; count < (lines * vc->vc_cols); count++) { | |
627 | if (scr_readw(d) != vc->vc_video_erase_char) { | |
628 | newport_putc(vc, vc->vc_video_erase_char, | |
629 | y, x); | |
630 | scr_writew(vc->vc_video_erase_char, d); | |
631 | } | |
632 | d++; | |
633 | if (++x == vc->vc_cols) { | |
634 | x = 0; | |
635 | y++; | |
636 | } | |
637 | } | |
638 | } else { | |
639 | x = vc->vc_cols - 1; | |
640 | y = b - 1; | |
641 | s = (unsigned short *) (vc->vc_origin + | |
642 | vc->vc_size_row * (b - lines) - 2); | |
643 | d = (unsigned short *) (vc->vc_origin + | |
644 | vc->vc_size_row * b - 2); | |
645 | while (count--) { | |
646 | chattr = scr_readw(s--); | |
647 | if (chattr != scr_readw(d)) { | |
648 | newport_putc(vc, chattr, y, x); | |
649 | scr_writew(chattr, d); | |
650 | } | |
651 | d--; | |
652 | if (x-- == 0) { | |
653 | x = vc->vc_cols - 1; | |
654 | y--; | |
655 | } | |
656 | } | |
657 | d = (unsigned short *) (vc->vc_origin + | |
658 | vc->vc_size_row * t); | |
659 | x = 0; | |
660 | y = t; | |
661 | for (count = 0; count < (lines * vc->vc_cols); count++) { | |
662 | if (scr_readw(d) != vc->vc_video_erase_char) { | |
663 | newport_putc(vc, vc->vc_video_erase_char, | |
664 | y, x); | |
665 | scr_writew(vc->vc_video_erase_char, d); | |
666 | } | |
667 | d++; | |
668 | if (++x == vc->vc_cols) { | |
669 | x = 0; | |
670 | y++; | |
671 | } | |
672 | } | |
673 | } | |
d705ff38 | 674 | return true; |
1da177e4 LT |
675 | } |
676 | ||
c396a5bf | 677 | static int newport_set_origin(struct vc_data *vc) |
1da177e4 LT |
678 | { |
679 | return 0; | |
680 | } | |
681 | ||
c396a5bf | 682 | static void newport_save_screen(struct vc_data *vc) { } |
1da177e4 | 683 | |
f54450ad | 684 | const struct consw newport_con = { |
1da177e4 LT |
685 | .owner = THIS_MODULE, |
686 | .con_startup = newport_startup, | |
687 | .con_init = newport_init, | |
688 | .con_deinit = newport_deinit, | |
689 | .con_clear = newport_clear, | |
690 | .con_putc = newport_putc, | |
691 | .con_putcs = newport_putcs, | |
692 | .con_cursor = newport_cursor, | |
693 | .con_scroll = newport_scroll, | |
1da177e4 LT |
694 | .con_switch = newport_switch, |
695 | .con_blank = newport_blank, | |
696 | .con_font_set = newport_font_set, | |
697 | .con_font_default = newport_font_default, | |
c396a5bf KC |
698 | .con_set_origin = newport_set_origin, |
699 | .con_save_screen = newport_save_screen | |
1da177e4 LT |
700 | }; |
701 | ||
e84de0c6 TB |
702 | static int newport_probe(struct gio_device *dev, |
703 | const struct gio_device_id *id) | |
1da177e4 | 704 | { |
e84de0c6 | 705 | unsigned long newport_addr; |
155957f5 | 706 | int err; |
e86bb8ac | 707 | |
e84de0c6 TB |
708 | if (!dev->resource.start) |
709 | return -EINVAL; | |
710 | ||
711 | if (npregs) | |
712 | return -EBUSY; /* we only support one Newport as console */ | |
713 | ||
714 | newport_addr = dev->resource.start + 0xF0000; | |
715 | if (!request_mem_region(newport_addr, 0x10000, "Newport")) | |
716 | return -ENODEV; | |
717 | ||
718 | npregs = (struct newport_regs *)/* ioremap cannot fail */ | |
719 | ioremap(newport_addr, sizeof(struct newport_regs)); | |
155957f5 WY |
720 | console_lock(); |
721 | err = do_take_over_console(&newport_con, 0, MAX_NR_CONSOLES - 1, 1); | |
722 | console_unlock(); | |
723 | return err; | |
1da177e4 LT |
724 | } |
725 | ||
e84de0c6 | 726 | static void newport_remove(struct gio_device *dev) |
1da177e4 LT |
727 | { |
728 | give_up_console(&newport_con); | |
729 | iounmap((void *)npregs); | |
730 | } | |
e84de0c6 TB |
731 | |
732 | static struct gio_device_id newport_ids[] = { | |
733 | { .id = 0x7e }, | |
734 | { .id = 0xff } | |
735 | }; | |
736 | ||
737 | MODULE_ALIAS("gio:7e"); | |
738 | ||
739 | static struct gio_driver newport_driver = { | |
740 | .name = "newport", | |
741 | .id_table = newport_ids, | |
742 | .probe = newport_probe, | |
743 | .remove = newport_remove, | |
744 | }; | |
745 | ||
746 | int __init newport_console_init(void) | |
747 | { | |
748 | return gio_register_driver(&newport_driver); | |
749 | } | |
750 | ||
751 | void __exit newport_console_exit(void) | |
752 | { | |
753 | gio_unregister_driver(&newport_driver); | |
754 | } | |
755 | ||
756 | module_init(newport_console_init); | |
1da177e4 | 757 | module_exit(newport_console_exit); |
1da177e4 LT |
758 | |
759 | MODULE_LICENSE("GPL"); |