sh_eth: fix EESIPR values for SH77{34|63}
[linux/fpc-iii.git] / drivers / video / console / mdacon.c
blobec192a1bf297232a183e1ae2f51f83b601649c15
1 /*
2 * linux/drivers/video/mdacon.c -- Low level MDA based console driver
4 * (c) 1998 Andrew Apted <ajapted@netspace.net.au>
6 * including portions (c) 1995-1998 Patrick Caulfield.
8 * slight improvements (c) 2000 Edward Betts <edward@debian.org>
10 * This file is based on the VGA console driver (vgacon.c):
12 * Created 28 Sep 1997 by Geert Uytterhoeven
14 * Rewritten by Martin Mares <mj@ucw.cz>, July 1998
16 * and on the old console.c, vga.c and vesa_blank.c drivers:
18 * Copyright (C) 1991, 1992 Linus Torvalds
19 * 1995 Jay Estabrook
21 * This file is subject to the terms and conditions of the GNU General Public
22 * License. See the file COPYING in the main directory of this archive for
23 * more details.
25 * Changelog:
26 * Paul G. (03/2001) Fix mdacon= boot prompt to use __setup().
29 #include <linux/types.h>
30 #include <linux/fs.h>
31 #include <linux/kernel.h>
32 #include <linux/module.h>
33 #include <linux/console.h>
34 #include <linux/string.h>
35 #include <linux/kd.h>
36 #include <linux/vt_kern.h>
37 #include <linux/vt_buffer.h>
38 #include <linux/selection.h>
39 #include <linux/spinlock.h>
40 #include <linux/ioport.h>
41 #include <linux/delay.h>
42 #include <linux/init.h>
44 #include <asm/io.h>
45 #include <asm/vga.h>
47 static DEFINE_SPINLOCK(mda_lock);
49 /* description of the hardware layout */
51 static unsigned long mda_vram_base; /* Base of video memory */
52 static unsigned long mda_vram_len; /* Size of video memory */
53 static unsigned int mda_num_columns; /* Number of text columns */
54 static unsigned int mda_num_lines; /* Number of text lines */
56 static unsigned int mda_index_port; /* Register select port */
57 static unsigned int mda_value_port; /* Register value port */
58 static unsigned int mda_mode_port; /* Mode control port */
59 static unsigned int mda_status_port; /* Status and Config port */
60 static unsigned int mda_gfx_port; /* Graphics control port */
62 /* current hardware state */
64 static int mda_cursor_loc=-1;
65 static int mda_cursor_size_from=-1;
66 static int mda_cursor_size_to=-1;
68 static enum { TYPE_MDA, TYPE_HERC, TYPE_HERCPLUS, TYPE_HERCCOLOR } mda_type;
69 static char *mda_type_name;
71 /* console information */
73 static int mda_first_vc = 13;
74 static int mda_last_vc = 16;
76 static struct vc_data *mda_display_fg = NULL;
78 module_param(mda_first_vc, int, 0);
79 MODULE_PARM_DESC(mda_first_vc, "First virtual console. Default: 13");
80 module_param(mda_last_vc, int, 0);
81 MODULE_PARM_DESC(mda_last_vc, "Last virtual console. Default: 16");
83 /* MDA register values
86 #define MDA_CURSOR_BLINKING 0x00
87 #define MDA_CURSOR_OFF 0x20
88 #define MDA_CURSOR_SLOWBLINK 0x60
90 #define MDA_MODE_GRAPHICS 0x02
91 #define MDA_MODE_VIDEO_EN 0x08
92 #define MDA_MODE_BLINK_EN 0x20
93 #define MDA_MODE_GFX_PAGE1 0x80
95 #define MDA_STATUS_HSYNC 0x01
96 #define MDA_STATUS_VSYNC 0x80
97 #define MDA_STATUS_VIDEO 0x08
99 #define MDA_CONFIG_COL132 0x08
100 #define MDA_GFX_MODE_EN 0x01
101 #define MDA_GFX_PAGE_EN 0x02
105 * MDA could easily be classified as "pre-dinosaur hardware".
108 static void write_mda_b(unsigned int val, unsigned char reg)
110 unsigned long flags;
112 spin_lock_irqsave(&mda_lock, flags);
114 outb_p(reg, mda_index_port);
115 outb_p(val, mda_value_port);
117 spin_unlock_irqrestore(&mda_lock, flags);
120 static void write_mda_w(unsigned int val, unsigned char reg)
122 unsigned long flags;
124 spin_lock_irqsave(&mda_lock, flags);
126 outb_p(reg, mda_index_port); outb_p(val >> 8, mda_value_port);
127 outb_p(reg+1, mda_index_port); outb_p(val & 0xff, mda_value_port);
129 spin_unlock_irqrestore(&mda_lock, flags);
132 #ifdef TEST_MDA_B
133 static int test_mda_b(unsigned char val, unsigned char reg)
135 unsigned long flags;
137 spin_lock_irqsave(&mda_lock, flags);
139 outb_p(reg, mda_index_port);
140 outb (val, mda_value_port);
142 udelay(20); val = (inb_p(mda_value_port) == val);
144 spin_unlock_irqrestore(&mda_lock, flags);
145 return val;
147 #endif
149 static inline void mda_set_cursor(unsigned int location)
151 if (mda_cursor_loc == location)
152 return;
154 write_mda_w(location >> 1, 0x0e);
156 mda_cursor_loc = location;
159 static inline void mda_set_cursor_size(int from, int to)
161 if (mda_cursor_size_from==from && mda_cursor_size_to==to)
162 return;
164 if (from > to) {
165 write_mda_b(MDA_CURSOR_OFF, 0x0a); /* disable cursor */
166 } else {
167 write_mda_b(from, 0x0a); /* cursor start */
168 write_mda_b(to, 0x0b); /* cursor end */
171 mda_cursor_size_from = from;
172 mda_cursor_size_to = to;
176 #ifndef MODULE
177 static int __init mdacon_setup(char *str)
179 /* command line format: mdacon=<first>,<last> */
181 int ints[3];
183 str = get_options(str, ARRAY_SIZE(ints), ints);
185 if (ints[0] < 2)
186 return 0;
188 if (ints[1] < 1 || ints[1] > MAX_NR_CONSOLES ||
189 ints[2] < 1 || ints[2] > MAX_NR_CONSOLES)
190 return 0;
192 mda_first_vc = ints[1];
193 mda_last_vc = ints[2];
194 return 1;
197 __setup("mdacon=", mdacon_setup);
198 #endif
200 static int mda_detect(void)
202 int count=0;
203 u16 *p, p_save;
204 u16 *q, q_save;
206 /* do a memory check */
208 p = (u16 *) mda_vram_base;
209 q = (u16 *) (mda_vram_base + 0x01000);
211 p_save = scr_readw(p); q_save = scr_readw(q);
213 scr_writew(0xAA55, p); if (scr_readw(p) == 0xAA55) count++;
214 scr_writew(0x55AA, p); if (scr_readw(p) == 0x55AA) count++;
215 scr_writew(p_save, p);
217 if (count != 2) {
218 return 0;
221 /* check if we have 4K or 8K */
223 scr_writew(0xA55A, q); scr_writew(0x0000, p);
224 if (scr_readw(q) == 0xA55A) count++;
226 scr_writew(0x5AA5, q); scr_writew(0x0000, p);
227 if (scr_readw(q) == 0x5AA5) count++;
229 scr_writew(p_save, p); scr_writew(q_save, q);
231 if (count == 4) {
232 mda_vram_len = 0x02000;
235 /* Ok, there is definitely a card registering at the correct
236 * memory location, so now we do an I/O port test.
239 #ifdef TEST_MDA_B
240 /* Edward: These two mess `tests' mess up my cursor on bootup */
242 /* cursor low register */
243 if (! test_mda_b(0x66, 0x0f)) {
244 return 0;
247 /* cursor low register */
248 if (! test_mda_b(0x99, 0x0f)) {
249 return 0;
251 #endif
253 /* See if the card is a Hercules, by checking whether the vsync
254 * bit of the status register is changing. This test lasts for
255 * approximately 1/10th of a second.
258 p_save = q_save = inb_p(mda_status_port) & MDA_STATUS_VSYNC;
260 for (count=0; count < 50000 && p_save == q_save; count++) {
261 q_save = inb(mda_status_port) & MDA_STATUS_VSYNC;
262 udelay(2);
265 if (p_save != q_save) {
266 switch (inb_p(mda_status_port) & 0x70) {
267 case 0x10:
268 mda_type = TYPE_HERCPLUS;
269 mda_type_name = "HerculesPlus";
270 break;
271 case 0x50:
272 mda_type = TYPE_HERCCOLOR;
273 mda_type_name = "HerculesColor";
274 break;
275 default:
276 mda_type = TYPE_HERC;
277 mda_type_name = "Hercules";
278 break;
282 return 1;
285 static void mda_initialize(void)
287 write_mda_b(97, 0x00); /* horizontal total */
288 write_mda_b(80, 0x01); /* horizontal displayed */
289 write_mda_b(82, 0x02); /* horizontal sync pos */
290 write_mda_b(15, 0x03); /* horizontal sync width */
292 write_mda_b(25, 0x04); /* vertical total */
293 write_mda_b(6, 0x05); /* vertical total adjust */
294 write_mda_b(25, 0x06); /* vertical displayed */
295 write_mda_b(25, 0x07); /* vertical sync pos */
297 write_mda_b(2, 0x08); /* interlace mode */
298 write_mda_b(13, 0x09); /* maximum scanline */
299 write_mda_b(12, 0x0a); /* cursor start */
300 write_mda_b(13, 0x0b); /* cursor end */
302 write_mda_w(0x0000, 0x0c); /* start address */
303 write_mda_w(0x0000, 0x0e); /* cursor location */
305 outb_p(MDA_MODE_VIDEO_EN | MDA_MODE_BLINK_EN, mda_mode_port);
306 outb_p(0x00, mda_status_port);
307 outb_p(0x00, mda_gfx_port);
310 static const char *mdacon_startup(void)
312 mda_num_columns = 80;
313 mda_num_lines = 25;
315 mda_vram_len = 0x01000;
316 mda_vram_base = VGA_MAP_MEM(0xb0000, mda_vram_len);
318 mda_index_port = 0x3b4;
319 mda_value_port = 0x3b5;
320 mda_mode_port = 0x3b8;
321 mda_status_port = 0x3ba;
322 mda_gfx_port = 0x3bf;
324 mda_type = TYPE_MDA;
325 mda_type_name = "MDA";
327 if (! mda_detect()) {
328 printk("mdacon: MDA card not detected.\n");
329 return NULL;
332 if (mda_type != TYPE_MDA) {
333 mda_initialize();
336 /* cursor looks ugly during boot-up, so turn it off */
337 mda_set_cursor(mda_vram_len - 1);
339 printk("mdacon: %s with %ldK of memory detected.\n",
340 mda_type_name, mda_vram_len/1024);
342 return "MDA-2";
345 static void mdacon_init(struct vc_data *c, int init)
347 c->vc_complement_mask = 0x0800; /* reverse video */
348 c->vc_display_fg = &mda_display_fg;
350 if (init) {
351 c->vc_cols = mda_num_columns;
352 c->vc_rows = mda_num_lines;
353 } else
354 vc_resize(c, mda_num_columns, mda_num_lines);
356 /* make the first MDA console visible */
358 if (mda_display_fg == NULL)
359 mda_display_fg = c;
362 static void mdacon_deinit(struct vc_data *c)
364 /* con_set_default_unimap(c->vc_num); */
366 if (mda_display_fg == c)
367 mda_display_fg = NULL;
370 static inline u16 mda_convert_attr(u16 ch)
372 u16 attr = 0x0700;
374 /* Underline and reverse-video are mutually exclusive on MDA.
375 * Since reverse-video is used for cursors and selected areas,
376 * it takes precedence.
379 if (ch & 0x0800) attr = 0x7000; /* reverse */
380 else if (ch & 0x0400) attr = 0x0100; /* underline */
382 return ((ch & 0x0200) << 2) | /* intensity */
383 (ch & 0x8000) | /* blink */
384 (ch & 0x00ff) | attr;
387 static u8 mdacon_build_attr(struct vc_data *c, u8 color, u8 intensity,
388 u8 blink, u8 underline, u8 reverse, u8 italic)
390 /* The attribute is just a bit vector:
392 * Bit 0..1 : intensity (0..2)
393 * Bit 2 : underline
394 * Bit 3 : reverse
395 * Bit 7 : blink
398 return (intensity & 3) |
399 ((underline & 1) << 2) |
400 ((reverse & 1) << 3) |
401 (!!italic << 4) |
402 ((blink & 1) << 7);
405 static void mdacon_invert_region(struct vc_data *c, u16 *p, int count)
407 for (; count > 0; count--) {
408 scr_writew(scr_readw(p) ^ 0x0800, p);
409 p++;
413 #define MDA_ADDR(x,y) ((u16 *) mda_vram_base + (y)*mda_num_columns + (x))
415 static void mdacon_putc(struct vc_data *c, int ch, int y, int x)
417 scr_writew(mda_convert_attr(ch), MDA_ADDR(x, y));
420 static void mdacon_putcs(struct vc_data *c, const unsigned short *s,
421 int count, int y, int x)
423 u16 *dest = MDA_ADDR(x, y);
425 for (; count > 0; count--) {
426 scr_writew(mda_convert_attr(scr_readw(s++)), dest++);
430 static void mdacon_clear(struct vc_data *c, int y, int x,
431 int height, int width)
433 u16 *dest = MDA_ADDR(x, y);
434 u16 eattr = mda_convert_attr(c->vc_video_erase_char);
436 if (width <= 0 || height <= 0)
437 return;
439 if (x==0 && width==mda_num_columns) {
440 scr_memsetw(dest, eattr, height*width*2);
441 } else {
442 for (; height > 0; height--, dest+=mda_num_columns)
443 scr_memsetw(dest, eattr, width*2);
447 static int mdacon_switch(struct vc_data *c)
449 return 1; /* redrawing needed */
452 static int mdacon_blank(struct vc_data *c, int blank, int mode_switch)
454 if (mda_type == TYPE_MDA) {
455 if (blank)
456 scr_memsetw((void *)mda_vram_base,
457 mda_convert_attr(c->vc_video_erase_char),
458 c->vc_screenbuf_size);
459 /* Tell console.c that it has to restore the screen itself */
460 return 1;
461 } else {
462 if (blank)
463 outb_p(0x00, mda_mode_port); /* disable video */
464 else
465 outb_p(MDA_MODE_VIDEO_EN | MDA_MODE_BLINK_EN,
466 mda_mode_port);
467 return 0;
471 static void mdacon_cursor(struct vc_data *c, int mode)
473 if (mode == CM_ERASE) {
474 mda_set_cursor(mda_vram_len - 1);
475 return;
478 mda_set_cursor(c->vc_y*mda_num_columns*2 + c->vc_x*2);
480 switch (c->vc_cursor_type & 0x0f) {
482 case CUR_LOWER_THIRD: mda_set_cursor_size(10, 13); break;
483 case CUR_LOWER_HALF: mda_set_cursor_size(7, 13); break;
484 case CUR_TWO_THIRDS: mda_set_cursor_size(4, 13); break;
485 case CUR_BLOCK: mda_set_cursor_size(1, 13); break;
486 case CUR_NONE: mda_set_cursor_size(14, 13); break;
487 default: mda_set_cursor_size(12, 13); break;
491 static bool mdacon_scroll(struct vc_data *c, unsigned int t, unsigned int b,
492 enum con_scroll dir, unsigned int lines)
494 u16 eattr = mda_convert_attr(c->vc_video_erase_char);
496 if (!lines)
497 return false;
499 if (lines > c->vc_rows) /* maximum realistic size */
500 lines = c->vc_rows;
502 switch (dir) {
504 case SM_UP:
505 scr_memmovew(MDA_ADDR(0,t), MDA_ADDR(0,t+lines),
506 (b-t-lines)*mda_num_columns*2);
507 scr_memsetw(MDA_ADDR(0,b-lines), eattr,
508 lines*mda_num_columns*2);
509 break;
511 case SM_DOWN:
512 scr_memmovew(MDA_ADDR(0,t+lines), MDA_ADDR(0,t),
513 (b-t-lines)*mda_num_columns*2);
514 scr_memsetw(MDA_ADDR(0,t), eattr, lines*mda_num_columns*2);
515 break;
518 return false;
523 * The console `switch' structure for the MDA based console
526 static const struct consw mda_con = {
527 .owner = THIS_MODULE,
528 .con_startup = mdacon_startup,
529 .con_init = mdacon_init,
530 .con_deinit = mdacon_deinit,
531 .con_clear = mdacon_clear,
532 .con_putc = mdacon_putc,
533 .con_putcs = mdacon_putcs,
534 .con_cursor = mdacon_cursor,
535 .con_scroll = mdacon_scroll,
536 .con_switch = mdacon_switch,
537 .con_blank = mdacon_blank,
538 .con_build_attr = mdacon_build_attr,
539 .con_invert_region = mdacon_invert_region,
542 int __init mda_console_init(void)
544 int err;
546 if (mda_first_vc > mda_last_vc)
547 return 1;
548 console_lock();
549 err = do_take_over_console(&mda_con, mda_first_vc-1, mda_last_vc-1, 0);
550 console_unlock();
551 return err;
554 static void __exit mda_console_exit(void)
556 give_up_console(&mda_con);
559 module_init(mda_console_init);
560 module_exit(mda_console_exit);
562 MODULE_LICENSE("GPL");