33 #include <linux/module.h>
34 #include <linux/kernel.h>
35 #include <linux/errno.h>
37 #include <linux/string.h>
48 #define DPRINTK(args...) printk(KERN_DEBUG __FILE__": " ##args)
50 #define DPRINTK(args...)
54 #define CHKINFO(ret) if (info != &fb_info) { printk(KERN_DEBUG __FILE__": This should never happen, line:%d \n", __LINE__); return ret; }
62 static unsigned long hga_vram_len;
64 #define HGA_ROWADDR(row) ((row%4)*8192 + (row>>2)*90)
73 static int hga_mode = -1;
76 static char *hga_type_name;
78 #define HGA_INDEX_PORT 0x3b4
79 #define HGA_VALUE_PORT 0x3b5
80 #define HGA_MODE_PORT 0x3b8
81 #define HGA_STATUS_PORT 0x3ba
82 #define HGA_GFX_PORT 0x3bf
86 #define HGA_CURSOR_BLINKING 0x00
87 #define HGA_CURSOR_OFF 0x20
88 #define HGA_CURSOR_SLOWBLINK 0x60
90 #define HGA_MODE_GRAPHICS 0x02
91 #define HGA_MODE_VIDEO_EN 0x08
92 #define HGA_MODE_BLINK_EN 0x20
93 #define HGA_MODE_GFX_PAGE1 0x80
95 #define HGA_STATUS_HSYNC 0x01
96 #define HGA_STATUS_VSYNC 0x80
97 #define HGA_STATUS_VIDEO 0x08
99 #define HGA_CONFIG_COL132 0x08
100 #define HGA_GFX_MODE_EN 0x01
101 #define HGA_GFX_PAGE_EN 0x02
134 static int release_io_port = 0;
135 static int release_io_ports = 0;
136 static bool nologo = 0;
144 static void write_hga_b(
unsigned int val,
unsigned char reg)
150 static void write_hga_w(
unsigned int val,
unsigned char reg)
156 static int test_hga_b(
unsigned char val,
unsigned char reg)
164 static void hga_clear_screen(
void)
166 unsigned char fillchar = 0xbf;
174 spin_unlock_irqrestore(&hga_reg_lock, flags);
175 if (fillchar != 0xbf)
176 memset_io(hga_vram, fillchar, hga_vram_len);
179 static void hga_txt_mode(
void)
188 write_hga_b(0x61, 0x00);
189 write_hga_b(0x50, 0x01);
190 write_hga_b(0x52, 0x02);
191 write_hga_b(0x0f, 0x03);
193 write_hga_b(0x19, 0x04);
194 write_hga_b(0x06, 0x05);
195 write_hga_b(0x19, 0x06);
196 write_hga_b(0x19, 0x07);
198 write_hga_b(0x02, 0x08);
199 write_hga_b(0x0d, 0x09);
200 write_hga_b(0x0c, 0x0a);
201 write_hga_b(0x0d, 0x0b);
203 write_hga_w(0x0000, 0x0c);
204 write_hga_w(0x0000, 0x0e);
207 spin_unlock_irqrestore(&hga_reg_lock, flags);
210 static void hga_gfx_mode(
void)
219 write_hga_b(0x35, 0x00);
220 write_hga_b(0x2d, 0x01);
221 write_hga_b(0x2e, 0x02);
222 write_hga_b(0x07, 0x03);
224 write_hga_b(0x5b, 0x04);
225 write_hga_b(0x02, 0x05);
226 write_hga_b(0x57, 0x06);
227 write_hga_b(0x57, 0x07);
229 write_hga_b(0x02, 0x08);
230 write_hga_b(0x03, 0x09);
231 write_hga_b(0x00, 0x0a);
232 write_hga_b(0x00, 0x0b);
234 write_hga_w(0x0000, 0x0c);
235 write_hga_w(0x0000, 0x0e);
238 spin_unlock_irqrestore(&hga_reg_lock, flags);
254 static void hga_pan(
unsigned int xoffset,
unsigned int yoffset)
259 base = (yoffset / 8) * 90 + xoffset;
261 write_hga_w(base, 0x0c);
262 spin_unlock_irqrestore(&hga_reg_lock, flags);
263 DPRINTK(
"hga_pan: base:%d\n", base);
266 static void hga_blank(
int blank_mode)
276 spin_unlock_irqrestore(&hga_reg_lock, flags);
279 static int __devinit hga_card_detect(
void)
283 unsigned short p_save, q_save;
285 hga_vram_len = 0x08000;
287 hga_vram =
ioremap(0xb0000, hga_vram_len);
290 release_io_ports = 1;
297 q = hga_vram + 0x01000;
301 writew(0xaa55, p);
if (
readw(p) == 0xaa55) count++;
302 writew(0x55aa, p);
if (
readw(p) == 0x55aa) count++;
312 if (!test_hga_b(0x66, 0x0f))
315 if (!test_hga_b(0x99, 0x0f))
325 for (count=0; count < 50000 && p_save == q_save; count++) {
330 if (p_save == q_save)
336 hga_type_name =
"HerculesPlus";
340 hga_type_name =
"HerculesColor";
344 hga_type_name =
"Hercules";
349 if (release_io_ports)
366 if (!nologo) hga_show_logo(info);
376 static int hgafb_release(
struct fb_info *info,
int init)
448 static int hgafb_blank(
int blank_mode,
struct fb_info *info)
450 hga_blank(blank_mode);
464 for (rows = rect->
height; rows--; y++) {
465 dest = rowaddr(info, y) + (rect->
dx >> 3);
483 if (area->
dy <= area->
sy) {
487 for (rows = area->
height; rows--; ) {
488 src = rowaddr(info, y1) + (area->
sx >> 3);
489 dest = rowaddr(info, y2) + (area->
dx >> 3);
498 for (rows = area->
height; rows--;) {
499 src = rowaddr(info, y1) + (area->
sx >> 3);
500 dest = rowaddr(info, y2) + (area->
dx >> 3);
516 for (rows = image->
height; rows--; y++) {
517 for (
x = 0;
x < image->
width;
x+= 8) {
519 dest = rowaddr(info, y) + ((image->
dx +
x)>> 3);
525 static struct fb_ops hgafb_ops = {
527 .fb_open = hgafb_open,
528 .fb_release = hgafb_release,
529 .fb_setcolreg = hgafb_setcolreg,
530 .fb_pan_display = hgafb_pan_display,
531 .fb_blank = hgafb_blank,
532 .fb_fillrect = hgafb_fillrect,
533 .fb_copyarea = hgafb_copyarea,
534 .fb_imageblit = hgafb_imageblit,
553 if (! hga_card_detect()) {
561 hga_type_name, hga_vram_len/1024);
569 hga_fix.smem_start = (
unsigned long)hga_vram;
570 hga_fix.smem_len = hga_vram_len;
573 info->
var = hga_default_var;
580 info->
fbops = &hgafb_ops;
591 platform_set_drvdata(pdev, info);
597 struct fb_info *info = platform_get_drvdata(pdev);
609 if (release_io_ports)
619 .probe = hgafb_probe,
628 static int __init hgafb_init(
void)
638 hgafb_device = platform_device_register_simple(
"hgafb", 0,
NULL, 0);
640 if (IS_ERR(hgafb_device)) {
642 ret = PTR_ERR(hgafb_device);
649 static void __exit hgafb_exit(
void)