setup enviroment for compilation
[linux-2.4.21-pre4.git] / drivers / video / hgafb.c
1 /*
2  * linux/drivers/video/hgafb.c -- Hercules graphics adaptor frame buffer device
3  * 
4  *      Created 25 Nov 1999 by Ferenc Bakonyi (fero@drama.obuda.kando.hu)
5  *      Based on skeletonfb.c by Geert Uytterhoeven and
6  *               mdacon.c by Andrew Apted
7  *
8  * History:
9  *
10  * - Revision 0.1.7 (23 Jan 2001): fix crash resulting from MDA only cards 
11  *                                 being detected as Hercules.   (Paul G.)
12  * - Revision 0.1.6 (17 Aug 2000): new style structs
13  *                                 documentation
14  * - Revision 0.1.5 (13 Mar 2000): spinlocks instead of saveflags();cli();etc
15  *                                 minor fixes
16  * - Revision 0.1.4 (24 Jan 2000): fixed a bug in hga_card_detect() for 
17  *                                  HGA-only systems
18  * - Revision 0.1.3 (22 Jan 2000): modified for the new fb_info structure
19  *                                 screen is cleared after rmmod
20  *                                 virtual resolutions
21  *                                 kernel parameter 'video=hga:font:{fontname}'
22  *                                 module parameter 'font={fontname}'
23  *                                 module parameter 'nologo={0|1}'
24  *                                 the most important: boot logo :)
25  * - Revision 0.1.0  (6 Dec 1999): faster scrolling and minor fixes
26  * - First release  (25 Nov 1999)
27  *
28  * This file is subject to the terms and conditions of the GNU General Public
29  * License.  See the file COPYING in the main directory of this archive
30  * for more details.
31  */
32
33 #include <linux/module.h>
34 #include <linux/kernel.h>
35 #include <linux/errno.h>
36 #include <linux/spinlock.h>
37 #include <linux/string.h>
38 #include <linux/mm.h>
39 #include <linux/tty.h>
40 #include <linux/slab.h>
41 #include <linux/delay.h>
42 #include <linux/fb.h>
43 #include <linux/init.h>
44 #include <linux/ioport.h>
45 #include <asm/io.h>
46 #include <asm/vga.h>
47 #include <video/fbcon.h>
48 #include <video/fbcon-hga.h>
49
50 #ifdef MODULE
51
52 #define INCLUDE_LINUX_LOGO_DATA
53 #include <linux/linux_logo.h>
54
55 #endif /* MODULE */
56
57 #if 0
58 #define DPRINTK(args...) printk(KERN_DEBUG __FILE__": " ##args)
59 #else
60 #define DPRINTK(args...)
61 #endif
62
63 #if 0
64 #define CHKINFO(ret) if (info != &fb_info) { printk(KERN_DEBUG __FILE__": This should never happen, line:%d \n", __LINE__); return ret; }
65 #else
66 #define CHKINFO(ret)
67 #endif
68
69 /* Description of the hardware layout */
70
71 static unsigned long hga_vram_base;             /* Base of video memory */
72 static unsigned long hga_vram_len;              /* Size of video memory */
73
74 #define HGA_TXT                 0
75 #define HGA_GFX                 1
76
77 static int hga_mode = -1;                       /* 0 = txt, 1 = gfx mode */
78
79 static enum { TYPE_HERC, TYPE_HERCPLUS, TYPE_HERCCOLOR } hga_type;
80 static char *hga_type_name;
81
82 #define HGA_INDEX_PORT          0x3b4           /* Register select port */
83 #define HGA_VALUE_PORT          0x3b5           /* Register value port */
84 #define HGA_MODE_PORT           0x3b8           /* Mode control port */
85 #define HGA_STATUS_PORT         0x3ba           /* Status and Config port */
86 #define HGA_GFX_PORT            0x3bf           /* Graphics control port */
87
88 /* HGA register values */
89
90 #define HGA_CURSOR_BLINKING     0x00
91 #define HGA_CURSOR_OFF          0x20
92 #define HGA_CURSOR_SLOWBLINK    0x60
93
94 #define HGA_MODE_GRAPHICS       0x02
95 #define HGA_MODE_VIDEO_EN       0x08
96 #define HGA_MODE_BLINK_EN       0x20
97 #define HGA_MODE_GFX_PAGE1      0x80
98
99 #define HGA_STATUS_HSYNC        0x01
100 #define HGA_STATUS_VSYNC        0x80
101 #define HGA_STATUS_VIDEO        0x08
102
103 #define HGA_CONFIG_COL132       0x08
104 #define HGA_GFX_MODE_EN         0x01
105 #define HGA_GFX_PAGE_EN         0x02
106
107 /* Global locks */
108
109 static spinlock_t hga_reg_lock = SPIN_LOCK_UNLOCKED;
110
111 /* Framebuffer driver structures */
112
113 static struct fb_var_screeninfo hga_default_var = {
114         xres:           720,
115         yres:           348,
116         xres_virtual:   720,
117         yres_virtual:   348,
118         xoffset:        0,
119         yoffset:        0,
120         bits_per_pixel: 1,
121         grayscale:      0,
122         red:            {0, 1, 0},
123         green:          {0, 1, 0},
124         blue:           {0, 1, 0},
125         transp:         {0, 0, 0},
126         nonstd:         0,                      /* (FB_NONSTD_HGA ?) */
127         activate:       0,
128         height:         -1,
129         width:          -1,
130         accel_flags:    0,
131         /* pixclock */
132         /* left_margin, right_margin */
133         /* upper_margin, lower_margin */
134         /* hsync_len, vsync_len */
135         /* sync */
136         /* vmode */
137 };
138
139 static struct fb_fix_screeninfo hga_fix = {
140         id:             "HGA",
141         smem_start:     (unsigned long) NULL,
142         smem_len:       0,
143         type:           FB_TYPE_PACKED_PIXELS,  /* (not sure) */
144         type_aux:       0,                      /* (not sure) */
145         visual:         FB_VISUAL_MONO10,
146         xpanstep:       8,
147         ypanstep:       8,
148         ywrapstep:      0,
149         line_length:    90,
150         mmio_start:     0,
151         mmio_len:       0,
152         accel:          FB_ACCEL_NONE
153 };
154
155 static struct fb_info fb_info;
156 static struct display disp;
157
158 /* Don't assume that tty1 will be the initial current console. */
159 static int currcon = -1; 
160 static int release_io_port = 0;
161 static int release_io_ports = 0;
162
163 #ifdef MODULE
164 static char *font = NULL;
165 static int nologo = 0;
166 #endif
167
168 /* -------------------------------------------------------------------------
169  *
170  * Low level hardware functions
171  *
172  * ------------------------------------------------------------------------- */
173
174 static void write_hga_b(unsigned int val, unsigned char reg)
175 {
176         outb_p(reg, HGA_INDEX_PORT); 
177         outb_p(val, HGA_VALUE_PORT);
178 }
179
180 static void write_hga_w(unsigned int val, unsigned char reg)
181 {
182         outb_p(reg,   HGA_INDEX_PORT); outb_p(val >> 8,   HGA_VALUE_PORT);
183         outb_p(reg+1, HGA_INDEX_PORT); outb_p(val & 0xff, HGA_VALUE_PORT);
184 }
185
186 static int test_hga_b(unsigned char val, unsigned char reg)
187 {
188         outb_p(reg, HGA_INDEX_PORT); 
189         outb  (val, HGA_VALUE_PORT);
190         udelay(20); val = (inb_p(HGA_VALUE_PORT) == val);
191         return val;
192 }
193
194 static void hga_clear_screen(void)
195 {
196         unsigned char fillchar = 0xbf; /* magic */
197         unsigned long flags;
198
199         spin_lock_irqsave(&hga_reg_lock, flags);
200         if (hga_mode == HGA_TXT)
201                 fillchar = ' ';
202         else if (hga_mode == HGA_GFX)
203                 fillchar = 0x00;
204         spin_unlock_irqrestore(&hga_reg_lock, flags);
205         if (fillchar != 0xbf)
206                 isa_memset_io(hga_vram_base, fillchar, hga_vram_len);
207 }
208
209
210 #ifdef MODULE
211 static void hga_txt_mode(void)
212 {
213         unsigned long flags;
214
215         spin_lock_irqsave(&hga_reg_lock, flags);
216         outb_p(HGA_MODE_VIDEO_EN | HGA_MODE_BLINK_EN, HGA_MODE_PORT);
217         outb_p(0x00, HGA_GFX_PORT);
218         outb_p(0x00, HGA_STATUS_PORT);
219
220         write_hga_b(0x61, 0x00);        /* horizontal total */
221         write_hga_b(0x50, 0x01);        /* horizontal displayed */
222         write_hga_b(0x52, 0x02);        /* horizontal sync pos */
223         write_hga_b(0x0f, 0x03);        /* horizontal sync width */
224
225         write_hga_b(0x19, 0x04);        /* vertical total */
226         write_hga_b(0x06, 0x05);        /* vertical total adjust */
227         write_hga_b(0x19, 0x06);        /* vertical displayed */
228         write_hga_b(0x19, 0x07);        /* vertical sync pos */
229
230         write_hga_b(0x02, 0x08);        /* interlace mode */
231         write_hga_b(0x0d, 0x09);        /* maximum scanline */
232         write_hga_b(0x0c, 0x0a);        /* cursor start */
233         write_hga_b(0x0d, 0x0b);        /* cursor end */
234
235         write_hga_w(0x0000, 0x0c);      /* start address */
236         write_hga_w(0x0000, 0x0e);      /* cursor location */
237
238         hga_mode = HGA_TXT;
239         spin_unlock_irqrestore(&hga_reg_lock, flags);
240 }
241 #endif /* MODULE */
242
243 static void hga_gfx_mode(void)
244 {
245         unsigned long flags;
246
247         spin_lock_irqsave(&hga_reg_lock, flags);
248         outb_p(0x00, HGA_STATUS_PORT);
249         outb_p(HGA_GFX_MODE_EN, HGA_GFX_PORT);
250         outb_p(HGA_MODE_VIDEO_EN | HGA_MODE_GRAPHICS, HGA_MODE_PORT);
251
252         write_hga_b(0x35, 0x00);        /* horizontal total */
253         write_hga_b(0x2d, 0x01);        /* horizontal displayed */
254         write_hga_b(0x2e, 0x02);        /* horizontal sync pos */
255         write_hga_b(0x07, 0x03);        /* horizontal sync width */
256
257         write_hga_b(0x5b, 0x04);        /* vertical total */
258         write_hga_b(0x02, 0x05);        /* vertical total adjust */
259         write_hga_b(0x57, 0x06);        /* vertical displayed */
260         write_hga_b(0x57, 0x07);        /* vertical sync pos */
261
262         write_hga_b(0x02, 0x08);        /* interlace mode */
263         write_hga_b(0x03, 0x09);        /* maximum scanline */
264         write_hga_b(0x00, 0x0a);        /* cursor start */
265         write_hga_b(0x00, 0x0b);        /* cursor end */
266
267         write_hga_w(0x0000, 0x0c);      /* start address */
268         write_hga_w(0x0000, 0x0e);      /* cursor location */
269
270         hga_mode = HGA_GFX;
271         spin_unlock_irqrestore(&hga_reg_lock, flags);
272 }
273
274 #ifdef MODULE
275 static void hga_show_logo(void)
276 {
277         int x, y;
278         unsigned long dest = hga_vram_base;
279         char *logo = linux_logo_bw;
280         for (y = 134; y < 134 + 80 ; y++) /* this needs some cleanup */
281                 for (x = 0; x < 10 ; x++)
282                         isa_writeb(~*(logo++),
283                                    (dest + (y%4)*8192 + (y>>2)*90 + x + 40));
284 }
285 #endif /* MODULE */     
286
287 static void hga_pan(unsigned int xoffset, unsigned int yoffset)
288 {
289         unsigned int base;
290         unsigned long flags;
291         
292         base = (yoffset / 8) * 90 + xoffset;
293         spin_lock_irqsave(&hga_reg_lock, flags);
294         write_hga_w(base, 0x0c);        /* start address */
295         spin_unlock_irqrestore(&hga_reg_lock, flags);
296         DPRINTK("hga_pan: base:%d\n", base);
297 }
298
299 static void hga_blank(int blank_mode)
300 {
301         unsigned long flags;
302
303         spin_lock_irqsave(&hga_reg_lock, flags);
304         if (blank_mode) {
305                 outb_p(0x00, HGA_MODE_PORT);    /* disable video */
306         } else {
307                 outb_p(HGA_MODE_VIDEO_EN | HGA_MODE_GRAPHICS, HGA_MODE_PORT);
308         }
309         spin_unlock_irqrestore(&hga_reg_lock, flags);
310 }
311
312 static int __init hga_card_detect(void)
313 {
314         int count=0;
315         unsigned long p, q;
316         unsigned short p_save, q_save;
317
318         hga_vram_base = 0xb0000;
319         hga_vram_len  = 0x08000;
320
321         if (request_region(0x3b0, 12, "hgafb"))
322                 release_io_ports = 1;
323         if (request_region(0x3bf, 1, "hgafb"))
324                 release_io_port = 1;
325
326         /* do a memory check */
327
328         p = hga_vram_base;
329         q = hga_vram_base + 0x01000;
330
331         p_save = isa_readw(p); q_save = isa_readw(q);
332
333         isa_writew(0xaa55, p); if (isa_readw(p) == 0xaa55) count++;
334         isa_writew(0x55aa, p); if (isa_readw(p) == 0x55aa) count++;
335         isa_writew(p_save, p);
336
337         if (count != 2) {
338                 return 0;
339         }
340
341         /* Ok, there is definitely a card registering at the correct
342          * memory location, so now we do an I/O port test.
343          */
344         
345         if (!test_hga_b(0x66, 0x0f)) {      /* cursor low register */
346                 return 0;
347         }
348         if (!test_hga_b(0x99, 0x0f)) {     /* cursor low register */
349                 return 0;
350         }
351
352         /* See if the card is a Hercules, by checking whether the vsync
353          * bit of the status register is changing.  This test lasts for
354          * approximately 1/10th of a second.
355          */
356         
357         p_save = q_save = inb_p(HGA_STATUS_PORT) & HGA_STATUS_VSYNC;
358
359         for (count=0; count < 50000 && p_save == q_save; count++) {
360                 q_save = inb(HGA_STATUS_PORT) & HGA_STATUS_VSYNC;
361                 udelay(2);
362         }
363
364         if (p_save == q_save) 
365                 return 0;
366
367         switch (inb_p(HGA_STATUS_PORT) & 0x70) {
368                 case 0x10:
369                         hga_type = TYPE_HERCPLUS;
370                         hga_type_name = "HerculesPlus";
371                         break;
372                 case 0x50:
373                         hga_type = TYPE_HERCCOLOR;
374                         hga_type_name = "HerculesColor";
375                         break;
376                 default:
377                         hga_type = TYPE_HERC;
378                         hga_type_name = "Hercules";
379                         break;
380         }
381         return 1;
382 }
383
384 /* ------------------------------------------------------------------------- *
385  *
386  * dispsw functions
387  *
388  * ------------------------------------------------------------------------- */
389
390 /**
391  *      hga_get_fix - get the fixed part of the display
392  *      @fix:struct fb_fix_screeninfo to fill in
393  *      @con:unused
394  *      @info:pointer to fb_info object containing info for current hga board
395  *
396  *      This wrapper function copies @info->fix to @fix.
397  *      A zero is returned on success and %-EINVAL for failure.
398  */
399
400 int hga_get_fix(struct fb_fix_screeninfo *fix, int con, struct fb_info *info)
401 {
402         CHKINFO(-EINVAL);
403         DPRINTK("hga_get_fix: con:%d, info:%x, fb_info:%x\n", con, (unsigned)info, (unsigned)&fb_info);
404
405         *fix = info->fix;
406         return 0;
407 }
408
409 /**
410  *      hga_get_var - get the user defined part of the display
411  *      @var:struct fb_var_screeninfo to fill in
412  *      @con:unused
413  *      @info:pointer to fb_info object containing info for current hga board
414  *
415  *      This wrapper function copies @info->var to @var.
416  *      A zero is returned on success and %-EINVAL for failure.
417  */
418
419 int hga_get_var(struct fb_var_screeninfo *var, int con, struct fb_info *info)
420 {
421         CHKINFO(-EINVAL);
422         DPRINTK("hga_get_var: con:%d, info:%x, fb_info:%x\n", con, (unsigned)info, (unsigned)&fb_info);
423
424         *var = info->var;
425         return 0;
426 }
427
428 /**
429  *      hga_set_var - set the user defined part of the display
430  *      @var:new video mode
431  *      @con:unused
432  *      @info:pointer to fb_info object containing info for current hga board
433  *      
434  *      This function is called for changing video modes. Since HGA cards have
435  *      only one fixed mode we have not much to do. After checking input 
436  *      parameters @var is copied to @info->var and @info->changevar is called.
437  *      A zero is returned on success and %-EINVAL for failure.
438  *      
439  *      FIXME:
440  *      This is the most mystical function (at least for me).
441  *      What is the exact specification of xxx_set_var()?
442  *      Should it handle xoffset, yoffset? Should it do panning?
443  *      What does vmode mean?
444  */
445
446 int hga_set_var(struct fb_var_screeninfo *var, int con, struct fb_info *info)
447 {
448         CHKINFO(-EINVAL);
449         DPRINTK("hga_set_var: con:%d, activate:%x, info:0x%x, fb_info:%x\n", con, var->activate, (unsigned)info, (unsigned)&fb_info);
450         
451         if (var->xres != 720 || var->yres != 348 ||
452             var->xres_virtual != 720 ||
453             var->yres_virtual < 348 || var->yres_virtual > 348 + 16 ||
454             var->bits_per_pixel != 1 || var->grayscale != 0) {
455                 return -EINVAL;
456         }
457         if ((var->activate & FB_ACTIVATE_MASK) == FB_ACTIVATE_NOW) {
458                 info->var = *var;
459                 if (info->changevar) 
460                         (*info->changevar)(con);
461         }
462         return 0;
463 }
464
465 /**
466  *      hga_getcolreg - read color registers
467  *      @regno:register index to read out
468  *      @red:red value
469  *      @green:green value
470  *      @blue:blue value
471  *      @transp:transparency value
472  *      @info:unused
473  *
474  *      This callback function is used to read the color registers of a HGA
475  *      board. Since we have only two fixed colors, RGB values are 0x0000 
476  *      for register0 and 0xaaaa for register1.
477  *      A zero is returned on success and 1 for failure.
478  */
479
480 static int hga_getcolreg(u_int regno, u_int *red, u_int *green, u_int *blue,
481                          u_int *transp, struct fb_info *info)
482 {
483         if (regno == 0) {
484                 *red = *green = *blue = 0x0000;
485                 *transp = 0;
486         } else if (regno == 1) {
487                 *red = *green = *blue = 0xaaaa;
488                 *transp = 0;
489         } else
490                 return 1;
491         return 0;
492 }
493
494 /**
495  *      hga_get_cmap - get the colormap
496  *      @cmap:struct fb_cmap to fill in
497  *      @kspc:called from kernel space?
498  *      @con:unused
499  *      @info:pointer to fb_info object containing info for current hga board
500  *
501  *      This wrapper function passes it's input parameters to fb_get_cmap().
502  *      Callback function hga_getcolreg() is used to read the color registers.
503  */
504
505 int hga_get_cmap(struct fb_cmap *cmap, int kspc, int con,
506                  struct fb_info *info)
507 {
508         CHKINFO(-EINVAL);
509         DPRINTK("hga_get_cmap: con:%d\n", con);
510         return fb_get_cmap(cmap, kspc, hga_getcolreg, info);
511 }
512         
513 /**
514  *      hga_setcolreg - set color registers
515  *      @regno:register index to set
516  *      @red:red value, unused
517  *      @green:green value, unused
518  *      @blue:blue value, unused
519  *      @transp:transparency value, unused
520  *      @info:unused
521  *
522  *      This callback function is used to set the color registers of a HGA
523  *      board. Since we have only two fixed colors only @regno is checked.
524  *      A zero is returned on success and 1 for failure.
525  */
526
527 static int hga_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
528                          u_int transp, struct fb_info *info)
529 {
530         if (regno > 1)
531                 return 1;
532         return 0;
533 }
534
535 /**
536  *      hga_set_cmap - set the colormap
537  *      @cmap:struct fb_cmap to set
538  *      @kspc:called from kernel space?
539  *      @con:unused
540  *      @info:pointer to fb_info object containing info for current hga board
541  *
542  *      This wrapper function passes it's input parameters to fb_set_cmap().
543  *      Callback function hga_setcolreg() is used to set the color registers.
544  */
545
546 int hga_set_cmap(struct fb_cmap *cmap, int kspc, int con,
547                  struct fb_info *info)
548 {
549         CHKINFO(-EINVAL);
550         DPRINTK("hga_set_cmap: con:%d\n", con);
551         return fb_set_cmap(cmap, kspc, hga_setcolreg, info);
552 }
553
554 /**
555  *      hga_pan_display - pan or wrap the display
556  *      @var:contains new xoffset, yoffset and vmode values
557  *      @con:unused
558  *      @info:pointer to fb_info object containing info for current hga board
559  *
560  *      This function looks only at xoffset, yoffset and the %FB_VMODE_YWRAP
561  *      flag in @var. If input parameters are correct it calls hga_pan() to 
562  *      program the hardware. @info->var is updated to the new values.
563  *      A zero is returned on success and %-EINVAL for failure.
564  */
565
566 int hga_pan_display(struct fb_var_screeninfo *var, int con,
567                     struct fb_info *info)
568 {
569         CHKINFO(-EINVAL);
570         DPRINTK("pan_disp: con:%d, wrap:%d, xoff:%d, yoff:%d\n", con, var->vmode & FB_VMODE_YWRAP, var->xoffset, var->yoffset);
571
572         if (var->vmode & FB_VMODE_YWRAP) {
573                 if (var->yoffset < 0 || 
574                     var->yoffset >= info->var.yres_virtual ||
575                     var->xoffset)
576                         return -EINVAL;
577         } else {
578                 if (var->xoffset + var->xres > info->var.xres_virtual
579                  || var->yoffset + var->yres > info->var.yres_virtual
580                  || var->yoffset % 8)
581                         return -EINVAL;
582         }
583
584         hga_pan(var->xoffset, var->yoffset);
585
586         info->var.xoffset = var->xoffset;
587         info->var.yoffset = var->yoffset;
588         if (var->vmode & FB_VMODE_YWRAP)
589                 info->var.vmode |= FB_VMODE_YWRAP;
590         else
591                 info->var.vmode &= ~FB_VMODE_YWRAP;
592         return 0;
593 }
594
595     
596 static struct fb_ops hgafb_ops = {
597         owner:          THIS_MODULE,
598         fb_get_fix:     hga_get_fix,
599         fb_get_var:     hga_get_var,
600         fb_set_var:     hga_set_var,
601         fb_get_cmap:    hga_get_cmap,
602         fb_set_cmap:    hga_set_cmap,
603         fb_pan_display: hga_pan_display,
604 };
605                 
606
607 /* ------------------------------------------------------------------------- *
608  *
609  * Functions in fb_info
610  * 
611  * ------------------------------------------------------------------------- */
612
613 /**
614  *      hgafbcon_switch - switch console
615  *      @con:new console to switch to
616  *      @info:pointer to fb_info object containing info for current hga board
617  *
618  *      This function should install a new colormap and change the video mode.
619  *      Since we have fixed colors and only one video mode we have nothing to 
620  *      do.
621  *      Only console administration is done but it should go to fbcon.c IMHO.
622  *      A zero is returned on success and %-EINVAL for failure.
623  */
624
625 static int hgafbcon_switch(int con, struct fb_info *info)
626 {
627         CHKINFO(-EINVAL);
628         DPRINTK("hgafbcon_switch: currcon:%d, con:%d, info:%x, fb_info:%x\n", currcon, con, (unsigned)info, (unsigned)&fb_info);
629
630         /* Save the colormap and video mode */
631 #if 0   /* Not necessary in hgafb, we use fixed colormap */
632         fb_copy_cmap(&info->cmap, &fb_display[currcon].cmap, 0);
633 #endif
634
635         if (currcon != -1) /* this check is absolute necessary! */
636                 memcpy(&fb_display[currcon].var, &info->var,
637                                 sizeof(struct fb_var_screeninfo));
638
639         /* Install a new colormap and change the video mode. By default fbcon
640          * sets all the colormaps and video modes to the default values at
641          * bootup.
642          */
643 #if 0
644         fb_copy_cmap(&fb_display[con].cmap, &info->cmap, 0);
645         fb_set_cmap(&info->cmap, 1, hga_setcolreg, info);
646 #endif
647
648         memcpy(&info->var, &fb_display[con].var,
649                         sizeof(struct fb_var_screeninfo));
650         /* hga_set_var(&info->var, con, &fb_info); is it necessary? */
651         currcon = con;
652
653         /* Hack to work correctly with XF86_Mono */
654         hga_gfx_mode();
655         return 0;
656 }
657
658 /**
659  *      hgafbcon_updatevar - update the user defined part of the display
660  *      @con:console to update or -1 when no consoles defined on this fb
661  *      @info:pointer to fb_info object containing info for current hga board
662  *
663  *      This function is called when @var is changed by fbcon.c without calling 
664  *      hga_set_var(). It usually means scrolling.  hga_pan_display() is called
665  *      to update the hardware and @info->var.
666  *      A zero is returned on success and %-EINVAL for failure.
667  */
668
669 static int hgafbcon_updatevar(int con, struct fb_info *info)
670 {
671         CHKINFO(-EINVAL);
672         DPRINTK("hga_update_var: con:%d, info:%x, fb_info:%x\n", con, (unsigned)info, (unsigned)&fb_info);
673         return (con < 0) ? -EINVAL : hga_pan_display(&fb_display[con].var, con, info);
674 }
675
676 /**
677  *      hgafbcon_blank - (un)blank the screen
678  *      @blank_mode:blanking method to use
679  *      @info:unused
680  *      
681  *      Blank the screen if blank_mode != 0, else unblank. 
682  *      Implements VESA suspend and powerdown modes on hardware that supports 
683  *      disabling hsync/vsync:
684  *              @blank_mode == 2 means suspend vsync,
685  *              @blank_mode == 3 means suspend hsync,
686  *              @blank_mode == 4 means powerdown.
687  */
688
689 static void hgafbcon_blank(int blank_mode, struct fb_info *info)
690 {
691         CHKINFO( );
692         DPRINTK("hga_blank: blank_mode:%d, info:%x, fb_info:%x\n", blank_mode, (unsigned)info, (unsigned)&fb_info);
693
694         hga_blank(blank_mode);
695 }
696
697
698 /* ------------------------------------------------------------------------- */
699     
700         /*
701          *  Initialization
702          */
703
704 int __init hgafb_init(void)
705 {
706         if (! hga_card_detect()) {
707                 printk(KERN_ERR "hgafb: HGA card not detected.\n");
708                 return -EINVAL;
709         }
710
711         printk(KERN_INFO "hgafb: %s with %ldK of memory detected.\n",
712                 hga_type_name, hga_vram_len/1024);
713
714         hga_gfx_mode();
715         hga_clear_screen();
716 #ifdef MODULE
717         if (!nologo) hga_show_logo();
718 #endif /* MODULE */
719
720         hga_fix.smem_start = VGA_MAP_MEM(hga_vram_base);
721         hga_fix.smem_len = hga_vram_len;
722
723         disp.var = hga_default_var;
724 /*      disp.cmap = ???; */
725         disp.screen_base = (char*)hga_fix.smem_start;
726         disp.visual = hga_fix.visual;
727         disp.type = hga_fix.type;
728         disp.type_aux = hga_fix.type_aux;
729         disp.ypanstep = hga_fix.ypanstep;
730         disp.ywrapstep = hga_fix.ywrapstep;
731         disp.line_length = hga_fix.line_length;
732         disp.can_soft_blank = 1;
733         disp.inverse = 0;
734 #ifdef FBCON_HAS_HGA
735         disp.dispsw = &fbcon_hga;
736 #else
737 #warning HGAFB will not work as a console!
738         disp.dispsw = &fbcon_dummy;
739 #endif
740         disp.dispsw_data = NULL;
741
742         disp.scrollmode = SCROLL_YREDRAW;
743         
744         strcpy (fb_info.modename, hga_fix.id);
745         fb_info.node = -1;
746         fb_info.flags = FBINFO_FLAG_DEFAULT;
747 /*      fb_info.open = ??? */
748         fb_info.var = hga_default_var;
749         fb_info.fix = hga_fix;
750         fb_info.monspecs.hfmin = 0;
751         fb_info.monspecs.hfmax = 0;
752         fb_info.monspecs.vfmin = 10000;
753         fb_info.monspecs.vfmax = 10000;
754         fb_info.monspecs.dpms = 0;
755         fb_info.fbops = &hgafb_ops;
756         fb_info.screen_base = (char *)hga_fix.smem_start;
757         fb_info.disp = &disp;
758 /*      fb_info.display_fg = ??? */
759 /*      fb_info.fontname initialized later */
760         fb_info.changevar = NULL;
761         fb_info.switch_con = hgafbcon_switch;
762         fb_info.updatevar = hgafbcon_updatevar;
763         fb_info.blank = hgafbcon_blank;
764         fb_info.pseudo_palette = NULL; /* ??? */
765         fb_info.par = NULL;
766
767         if (register_framebuffer(&fb_info) < 0)
768                 return -EINVAL;
769
770         printk(KERN_INFO "fb%d: %s frame buffer device\n",
771                GET_FB_IDX(fb_info.node), fb_info.modename);
772         
773         return 0;
774 }
775
776         /*
777          *  Setup
778          */
779
780 #ifndef MODULE
781 int __init hgafb_setup(char *options)
782 {
783         /* 
784          * Parse user speficied options
785          * `video=hga:font:VGA8x16' or
786          * `video=hga:font:SUN8x16' recommended
787          * Other supported fonts: VGA8x8, Acorn8x8, PEARL8x8
788          * More different fonts can be used with the `setfont' utility.
789          */
790
791         char *this_opt;
792
793         fb_info.fontname[0] = '\0';
794
795         if (!options || !*options)
796                 return 0;
797
798         while ((this_opt = strsep(&options, ","))) {
799                 if (!strncmp(this_opt, "font:", 5))
800                         strcpy(fb_info.fontname, this_opt+5);
801         }
802         return 0;
803 }
804 #endif /* !MODULE */
805
806
807         /*
808          * Cleanup
809          */
810
811 #ifdef MODULE
812 static void hgafb_cleanup(struct fb_info *info)
813 {
814         hga_txt_mode();
815         hga_clear_screen();
816         unregister_framebuffer(info);
817         if (release_io_ports) release_region(0x3b0, 12);
818         if (release_io_port) release_region(0x3bf, 1);
819 }
820 #endif /* MODULE */
821
822
823
824 /* -------------------------------------------------------------------------
825  *
826  *  Modularization
827  *
828  * ------------------------------------------------------------------------- */
829
830 #ifdef MODULE
831 int init_module(void)
832 {
833         if (font)
834                 strncpy(fb_info.fontname, font, sizeof(fb_info.fontname)-1);
835         else
836                 fb_info.fontname[0] = '\0';
837
838         return hgafb_init();
839 }
840
841 void cleanup_module(void)
842 {
843         hgafb_cleanup(&fb_info);
844 }
845
846 MODULE_AUTHOR("Ferenc Bakonyi (fero@drama.obuda.kando.hu)");
847 MODULE_DESCRIPTION("FBDev driver for Hercules Graphics Adaptor");
848 MODULE_LICENSE("GPL");
849
850 MODULE_PARM(font, "s");
851 MODULE_PARM_DESC(font, "Specifies one of the compiled-in fonts (VGA8x8, VGA8x16, SUN8x16, Acorn8x8, PEARL8x8) (default=none)");
852 MODULE_PARM(nologo, "i");
853 MODULE_PARM_DESC(nologo, "Disables startup logo if != 0 (default=0)");
854
855 #endif /* MODULE */