1f7018c21STomi Valkeinen /* 2f7018c21STomi Valkeinen * linux/drivers/video/hgafb.c -- Hercules graphics adaptor frame buffer device 3f7018c21STomi Valkeinen * 4f7018c21STomi Valkeinen * Created 25 Nov 1999 by Ferenc Bakonyi (fero@drama.obuda.kando.hu) 5f7018c21STomi Valkeinen * Based on skeletonfb.c by Geert Uytterhoeven and 6f7018c21STomi Valkeinen * mdacon.c by Andrew Apted 7f7018c21STomi Valkeinen * 8f7018c21STomi Valkeinen * History: 9f7018c21STomi Valkeinen * 10f7018c21STomi Valkeinen * - Revision 0.1.8 (23 Oct 2002): Ported to new framebuffer api. 11f7018c21STomi Valkeinen * 12f7018c21STomi Valkeinen * - Revision 0.1.7 (23 Jan 2001): fix crash resulting from MDA only cards 13f7018c21STomi Valkeinen * being detected as Hercules. (Paul G.) 14f7018c21STomi Valkeinen * - Revision 0.1.6 (17 Aug 2000): new style structs 15f7018c21STomi Valkeinen * documentation 16f7018c21STomi Valkeinen * - Revision 0.1.5 (13 Mar 2000): spinlocks instead of saveflags();cli();etc 17f7018c21STomi Valkeinen * minor fixes 18f7018c21STomi Valkeinen * - Revision 0.1.4 (24 Jan 2000): fixed a bug in hga_card_detect() for 19f7018c21STomi Valkeinen * HGA-only systems 20f7018c21STomi Valkeinen * - Revision 0.1.3 (22 Jan 2000): modified for the new fb_info structure 21f7018c21STomi Valkeinen * screen is cleared after rmmod 22f7018c21STomi Valkeinen * virtual resolutions 23f7018c21STomi Valkeinen * module parameter 'nologo={0|1}' 24f7018c21STomi Valkeinen * the most important: boot logo :) 25f7018c21STomi Valkeinen * - Revision 0.1.0 (6 Dec 1999): faster scrolling and minor fixes 26f7018c21STomi Valkeinen * - First release (25 Nov 1999) 27f7018c21STomi Valkeinen * 28f7018c21STomi Valkeinen * This file is subject to the terms and conditions of the GNU General Public 29f7018c21STomi Valkeinen * License. See the file COPYING in the main directory of this archive 30f7018c21STomi Valkeinen * for more details. 31f7018c21STomi Valkeinen */ 32f7018c21STomi Valkeinen 33f7018c21STomi Valkeinen #include <linux/module.h> 34f7018c21STomi Valkeinen #include <linux/kernel.h> 35f7018c21STomi Valkeinen #include <linux/errno.h> 36f7018c21STomi Valkeinen #include <linux/spinlock.h> 37f7018c21STomi Valkeinen #include <linux/string.h> 38f7018c21STomi Valkeinen #include <linux/mm.h> 39f7018c21STomi Valkeinen #include <linux/delay.h> 40f7018c21STomi Valkeinen #include <linux/fb.h> 41f7018c21STomi Valkeinen #include <linux/init.h> 42f7018c21STomi Valkeinen #include <linux/ioport.h> 43f7018c21STomi Valkeinen #include <linux/platform_device.h> 44f7018c21STomi Valkeinen #include <asm/io.h> 45f7018c21STomi Valkeinen #include <asm/vga.h> 46f7018c21STomi Valkeinen 47f7018c21STomi Valkeinen #if 0 48f7018c21STomi Valkeinen #define DPRINTK(args...) printk(KERN_DEBUG __FILE__": " ##args) 49f7018c21STomi Valkeinen #else 50f7018c21STomi Valkeinen #define DPRINTK(args...) 51f7018c21STomi Valkeinen #endif 52f7018c21STomi Valkeinen 53f7018c21STomi Valkeinen #if 0 54f7018c21STomi Valkeinen #define CHKINFO(ret) if (info != &fb_info) { printk(KERN_DEBUG __FILE__": This should never happen, line:%d \n", __LINE__); return ret; } 55f7018c21STomi Valkeinen #else 56f7018c21STomi Valkeinen #define CHKINFO(ret) 57f7018c21STomi Valkeinen #endif 58f7018c21STomi Valkeinen 59f7018c21STomi Valkeinen /* Description of the hardware layout */ 60f7018c21STomi Valkeinen 61f7018c21STomi Valkeinen static void __iomem *hga_vram; /* Base of video memory */ 62f7018c21STomi Valkeinen static unsigned long hga_vram_len; /* Size of video memory */ 63f7018c21STomi Valkeinen 64f7018c21STomi Valkeinen #define HGA_ROWADDR(row) ((row%4)*8192 + (row>>2)*90) 65f7018c21STomi Valkeinen #define HGA_TXT 0 66f7018c21STomi Valkeinen #define HGA_GFX 1 67f7018c21STomi Valkeinen 68f7018c21STomi Valkeinen static inline u8 __iomem * rowaddr(struct fb_info *info, u_int row) 69f7018c21STomi Valkeinen { 70f7018c21STomi Valkeinen return info->screen_base + HGA_ROWADDR(row); 71f7018c21STomi Valkeinen } 72f7018c21STomi Valkeinen 73f7018c21STomi Valkeinen static int hga_mode = -1; /* 0 = txt, 1 = gfx mode */ 74f7018c21STomi Valkeinen 75f7018c21STomi Valkeinen static enum { TYPE_HERC, TYPE_HERCPLUS, TYPE_HERCCOLOR } hga_type; 76f7018c21STomi Valkeinen static char *hga_type_name; 77f7018c21STomi Valkeinen 78f7018c21STomi Valkeinen #define HGA_INDEX_PORT 0x3b4 /* Register select port */ 79f7018c21STomi Valkeinen #define HGA_VALUE_PORT 0x3b5 /* Register value port */ 80f7018c21STomi Valkeinen #define HGA_MODE_PORT 0x3b8 /* Mode control port */ 81f7018c21STomi Valkeinen #define HGA_STATUS_PORT 0x3ba /* Status and Config port */ 82f7018c21STomi Valkeinen #define HGA_GFX_PORT 0x3bf /* Graphics control port */ 83f7018c21STomi Valkeinen 84f7018c21STomi Valkeinen /* HGA register values */ 85f7018c21STomi Valkeinen 86f7018c21STomi Valkeinen #define HGA_CURSOR_BLINKING 0x00 87f7018c21STomi Valkeinen #define HGA_CURSOR_OFF 0x20 88f7018c21STomi Valkeinen #define HGA_CURSOR_SLOWBLINK 0x60 89f7018c21STomi Valkeinen 90f7018c21STomi Valkeinen #define HGA_MODE_GRAPHICS 0x02 91f7018c21STomi Valkeinen #define HGA_MODE_VIDEO_EN 0x08 92f7018c21STomi Valkeinen #define HGA_MODE_BLINK_EN 0x20 93f7018c21STomi Valkeinen #define HGA_MODE_GFX_PAGE1 0x80 94f7018c21STomi Valkeinen 95f7018c21STomi Valkeinen #define HGA_STATUS_HSYNC 0x01 96f7018c21STomi Valkeinen #define HGA_STATUS_VSYNC 0x80 97f7018c21STomi Valkeinen #define HGA_STATUS_VIDEO 0x08 98f7018c21STomi Valkeinen 99f7018c21STomi Valkeinen #define HGA_CONFIG_COL132 0x08 100f7018c21STomi Valkeinen #define HGA_GFX_MODE_EN 0x01 101f7018c21STomi Valkeinen #define HGA_GFX_PAGE_EN 0x02 102f7018c21STomi Valkeinen 103f7018c21STomi Valkeinen /* Global locks */ 104f7018c21STomi Valkeinen 105f7018c21STomi Valkeinen static DEFINE_SPINLOCK(hga_reg_lock); 106f7018c21STomi Valkeinen 107f7018c21STomi Valkeinen /* Framebuffer driver structures */ 108f7018c21STomi Valkeinen 109ca9384c5SJulia Lawall static const struct fb_var_screeninfo hga_default_var = { 110f7018c21STomi Valkeinen .xres = 720, 111f7018c21STomi Valkeinen .yres = 348, 112f7018c21STomi Valkeinen .xres_virtual = 720, 113f7018c21STomi Valkeinen .yres_virtual = 348, 114f7018c21STomi Valkeinen .bits_per_pixel = 1, 115f7018c21STomi Valkeinen .red = {0, 1, 0}, 116f7018c21STomi Valkeinen .green = {0, 1, 0}, 117f7018c21STomi Valkeinen .blue = {0, 1, 0}, 118f7018c21STomi Valkeinen .transp = {0, 0, 0}, 119f7018c21STomi Valkeinen .height = -1, 120f7018c21STomi Valkeinen .width = -1, 121f7018c21STomi Valkeinen }; 122f7018c21STomi Valkeinen 123f7018c21STomi Valkeinen static struct fb_fix_screeninfo hga_fix = { 124f7018c21STomi Valkeinen .id = "HGA", 125f7018c21STomi Valkeinen .type = FB_TYPE_PACKED_PIXELS, /* (not sure) */ 126f7018c21STomi Valkeinen .visual = FB_VISUAL_MONO10, 127f7018c21STomi Valkeinen .xpanstep = 8, 128f7018c21STomi Valkeinen .ypanstep = 8, 129f7018c21STomi Valkeinen .line_length = 90, 130f7018c21STomi Valkeinen .accel = FB_ACCEL_NONE 131f7018c21STomi Valkeinen }; 132f7018c21STomi Valkeinen 133f7018c21STomi Valkeinen /* Don't assume that tty1 will be the initial current console. */ 134f7018c21STomi Valkeinen static int release_io_port = 0; 135f7018c21STomi Valkeinen static int release_io_ports = 0; 136f7018c21STomi Valkeinen static bool nologo = 0; 137f7018c21STomi Valkeinen 138f7018c21STomi Valkeinen /* ------------------------------------------------------------------------- 139f7018c21STomi Valkeinen * 140f7018c21STomi Valkeinen * Low level hardware functions 141f7018c21STomi Valkeinen * 142f7018c21STomi Valkeinen * ------------------------------------------------------------------------- */ 143f7018c21STomi Valkeinen 144f7018c21STomi Valkeinen static void write_hga_b(unsigned int val, unsigned char reg) 145f7018c21STomi Valkeinen { 146f7018c21STomi Valkeinen outb_p(reg, HGA_INDEX_PORT); 147f7018c21STomi Valkeinen outb_p(val, HGA_VALUE_PORT); 148f7018c21STomi Valkeinen } 149f7018c21STomi Valkeinen 150f7018c21STomi Valkeinen static void write_hga_w(unsigned int val, unsigned char reg) 151f7018c21STomi Valkeinen { 152f7018c21STomi Valkeinen outb_p(reg, HGA_INDEX_PORT); outb_p(val >> 8, HGA_VALUE_PORT); 153f7018c21STomi Valkeinen outb_p(reg+1, HGA_INDEX_PORT); outb_p(val & 0xff, HGA_VALUE_PORT); 154f7018c21STomi Valkeinen } 155f7018c21STomi Valkeinen 156f7018c21STomi Valkeinen static int test_hga_b(unsigned char val, unsigned char reg) 157f7018c21STomi Valkeinen { 158f7018c21STomi Valkeinen outb_p(reg, HGA_INDEX_PORT); 159f7018c21STomi Valkeinen outb (val, HGA_VALUE_PORT); 160f7018c21STomi Valkeinen udelay(20); val = (inb_p(HGA_VALUE_PORT) == val); 161f7018c21STomi Valkeinen return val; 162f7018c21STomi Valkeinen } 163f7018c21STomi Valkeinen 164f7018c21STomi Valkeinen static void hga_clear_screen(void) 165f7018c21STomi Valkeinen { 166f7018c21STomi Valkeinen unsigned char fillchar = 0xbf; /* magic */ 167f7018c21STomi Valkeinen unsigned long flags; 168f7018c21STomi Valkeinen 169f7018c21STomi Valkeinen spin_lock_irqsave(&hga_reg_lock, flags); 170f7018c21STomi Valkeinen if (hga_mode == HGA_TXT) 171f7018c21STomi Valkeinen fillchar = ' '; 172f7018c21STomi Valkeinen else if (hga_mode == HGA_GFX) 173f7018c21STomi Valkeinen fillchar = 0x00; 174f7018c21STomi Valkeinen spin_unlock_irqrestore(&hga_reg_lock, flags); 175f7018c21STomi Valkeinen if (fillchar != 0xbf) 176f7018c21STomi Valkeinen memset_io(hga_vram, fillchar, hga_vram_len); 177f7018c21STomi Valkeinen } 178f7018c21STomi Valkeinen 179f7018c21STomi Valkeinen static void hga_txt_mode(void) 180f7018c21STomi Valkeinen { 181f7018c21STomi Valkeinen unsigned long flags; 182f7018c21STomi Valkeinen 183f7018c21STomi Valkeinen spin_lock_irqsave(&hga_reg_lock, flags); 184f7018c21STomi Valkeinen outb_p(HGA_MODE_VIDEO_EN | HGA_MODE_BLINK_EN, HGA_MODE_PORT); 185f7018c21STomi Valkeinen outb_p(0x00, HGA_GFX_PORT); 186f7018c21STomi Valkeinen outb_p(0x00, HGA_STATUS_PORT); 187f7018c21STomi Valkeinen 188f7018c21STomi Valkeinen write_hga_b(0x61, 0x00); /* horizontal total */ 189f7018c21STomi Valkeinen write_hga_b(0x50, 0x01); /* horizontal displayed */ 190f7018c21STomi Valkeinen write_hga_b(0x52, 0x02); /* horizontal sync pos */ 191f7018c21STomi Valkeinen write_hga_b(0x0f, 0x03); /* horizontal sync width */ 192f7018c21STomi Valkeinen 193f7018c21STomi Valkeinen write_hga_b(0x19, 0x04); /* vertical total */ 194f7018c21STomi Valkeinen write_hga_b(0x06, 0x05); /* vertical total adjust */ 195f7018c21STomi Valkeinen write_hga_b(0x19, 0x06); /* vertical displayed */ 196f7018c21STomi Valkeinen write_hga_b(0x19, 0x07); /* vertical sync pos */ 197f7018c21STomi Valkeinen 198f7018c21STomi Valkeinen write_hga_b(0x02, 0x08); /* interlace mode */ 199f7018c21STomi Valkeinen write_hga_b(0x0d, 0x09); /* maximum scanline */ 200f7018c21STomi Valkeinen write_hga_b(0x0c, 0x0a); /* cursor start */ 201f7018c21STomi Valkeinen write_hga_b(0x0d, 0x0b); /* cursor end */ 202f7018c21STomi Valkeinen 203f7018c21STomi Valkeinen write_hga_w(0x0000, 0x0c); /* start address */ 204f7018c21STomi Valkeinen write_hga_w(0x0000, 0x0e); /* cursor location */ 205f7018c21STomi Valkeinen 206f7018c21STomi Valkeinen hga_mode = HGA_TXT; 207f7018c21STomi Valkeinen spin_unlock_irqrestore(&hga_reg_lock, flags); 208f7018c21STomi Valkeinen } 209f7018c21STomi Valkeinen 210f7018c21STomi Valkeinen static void hga_gfx_mode(void) 211f7018c21STomi Valkeinen { 212f7018c21STomi Valkeinen unsigned long flags; 213f7018c21STomi Valkeinen 214f7018c21STomi Valkeinen spin_lock_irqsave(&hga_reg_lock, flags); 215f7018c21STomi Valkeinen outb_p(0x00, HGA_STATUS_PORT); 216f7018c21STomi Valkeinen outb_p(HGA_GFX_MODE_EN, HGA_GFX_PORT); 217f7018c21STomi Valkeinen outb_p(HGA_MODE_VIDEO_EN | HGA_MODE_GRAPHICS, HGA_MODE_PORT); 218f7018c21STomi Valkeinen 219f7018c21STomi Valkeinen write_hga_b(0x35, 0x00); /* horizontal total */ 220f7018c21STomi Valkeinen write_hga_b(0x2d, 0x01); /* horizontal displayed */ 221f7018c21STomi Valkeinen write_hga_b(0x2e, 0x02); /* horizontal sync pos */ 222f7018c21STomi Valkeinen write_hga_b(0x07, 0x03); /* horizontal sync width */ 223f7018c21STomi Valkeinen 224f7018c21STomi Valkeinen write_hga_b(0x5b, 0x04); /* vertical total */ 225f7018c21STomi Valkeinen write_hga_b(0x02, 0x05); /* vertical total adjust */ 226f7018c21STomi Valkeinen write_hga_b(0x57, 0x06); /* vertical displayed */ 227f7018c21STomi Valkeinen write_hga_b(0x57, 0x07); /* vertical sync pos */ 228f7018c21STomi Valkeinen 229f7018c21STomi Valkeinen write_hga_b(0x02, 0x08); /* interlace mode */ 230f7018c21STomi Valkeinen write_hga_b(0x03, 0x09); /* maximum scanline */ 231f7018c21STomi Valkeinen write_hga_b(0x00, 0x0a); /* cursor start */ 232f7018c21STomi Valkeinen write_hga_b(0x00, 0x0b); /* cursor end */ 233f7018c21STomi Valkeinen 234f7018c21STomi Valkeinen write_hga_w(0x0000, 0x0c); /* start address */ 235f7018c21STomi Valkeinen write_hga_w(0x0000, 0x0e); /* cursor location */ 236f7018c21STomi Valkeinen 237f7018c21STomi Valkeinen hga_mode = HGA_GFX; 238f7018c21STomi Valkeinen spin_unlock_irqrestore(&hga_reg_lock, flags); 239f7018c21STomi Valkeinen } 240f7018c21STomi Valkeinen 241f7018c21STomi Valkeinen static void hga_show_logo(struct fb_info *info) 242f7018c21STomi Valkeinen { 243f7018c21STomi Valkeinen /* 244f7018c21STomi Valkeinen void __iomem *dest = hga_vram; 245f7018c21STomi Valkeinen char *logo = linux_logo_bw; 246f7018c21STomi Valkeinen int x, y; 247f7018c21STomi Valkeinen 248f7018c21STomi Valkeinen for (y = 134; y < 134 + 80 ; y++) * this needs some cleanup * 249f7018c21STomi Valkeinen for (x = 0; x < 10 ; x++) 250f7018c21STomi Valkeinen writeb(~*(logo++),(dest + HGA_ROWADDR(y) + x + 40)); 251f7018c21STomi Valkeinen */ 252f7018c21STomi Valkeinen } 253f7018c21STomi Valkeinen 254f7018c21STomi Valkeinen static void hga_pan(unsigned int xoffset, unsigned int yoffset) 255f7018c21STomi Valkeinen { 256f7018c21STomi Valkeinen unsigned int base; 257f7018c21STomi Valkeinen unsigned long flags; 258f7018c21STomi Valkeinen 259f7018c21STomi Valkeinen base = (yoffset / 8) * 90 + xoffset; 260f7018c21STomi Valkeinen spin_lock_irqsave(&hga_reg_lock, flags); 261f7018c21STomi Valkeinen write_hga_w(base, 0x0c); /* start address */ 262f7018c21STomi Valkeinen spin_unlock_irqrestore(&hga_reg_lock, flags); 263f7018c21STomi Valkeinen DPRINTK("hga_pan: base:%d\n", base); 264f7018c21STomi Valkeinen } 265f7018c21STomi Valkeinen 266f7018c21STomi Valkeinen static void hga_blank(int blank_mode) 267f7018c21STomi Valkeinen { 268f7018c21STomi Valkeinen unsigned long flags; 269f7018c21STomi Valkeinen 270f7018c21STomi Valkeinen spin_lock_irqsave(&hga_reg_lock, flags); 271f7018c21STomi Valkeinen if (blank_mode) { 272f7018c21STomi Valkeinen outb_p(0x00, HGA_MODE_PORT); /* disable video */ 273f7018c21STomi Valkeinen } else { 274f7018c21STomi Valkeinen outb_p(HGA_MODE_VIDEO_EN | HGA_MODE_GRAPHICS, HGA_MODE_PORT); 275f7018c21STomi Valkeinen } 276f7018c21STomi Valkeinen spin_unlock_irqrestore(&hga_reg_lock, flags); 277f7018c21STomi Valkeinen } 278f7018c21STomi Valkeinen 279f7018c21STomi Valkeinen static int hga_card_detect(void) 280f7018c21STomi Valkeinen { 281f7018c21STomi Valkeinen int count = 0; 282f7018c21STomi Valkeinen void __iomem *p, *q; 283f7018c21STomi Valkeinen unsigned short p_save, q_save; 284f7018c21STomi Valkeinen 285f7018c21STomi Valkeinen hga_vram_len = 0x08000; 286f7018c21STomi Valkeinen 287f7018c21STomi Valkeinen hga_vram = ioremap(0xb0000, hga_vram_len); 288ec7f6aadSKangjie Lu if (!hga_vram) 289ec7f6aadSKangjie Lu goto error; 290f7018c21STomi Valkeinen 291f7018c21STomi Valkeinen if (request_region(0x3b0, 12, "hgafb")) 292f7018c21STomi Valkeinen release_io_ports = 1; 293f7018c21STomi Valkeinen if (request_region(0x3bf, 1, "hgafb")) 294f7018c21STomi Valkeinen release_io_port = 1; 295f7018c21STomi Valkeinen 296f7018c21STomi Valkeinen /* do a memory check */ 297f7018c21STomi Valkeinen 298f7018c21STomi Valkeinen p = hga_vram; 299f7018c21STomi Valkeinen q = hga_vram + 0x01000; 300f7018c21STomi Valkeinen 301f7018c21STomi Valkeinen p_save = readw(p); q_save = readw(q); 302f7018c21STomi Valkeinen 303f7018c21STomi Valkeinen writew(0xaa55, p); if (readw(p) == 0xaa55) count++; 304f7018c21STomi Valkeinen writew(0x55aa, p); if (readw(p) == 0x55aa) count++; 305f7018c21STomi Valkeinen writew(p_save, p); 306f7018c21STomi Valkeinen 307f7018c21STomi Valkeinen if (count != 2) 308f7018c21STomi Valkeinen goto error; 309f7018c21STomi Valkeinen 310f7018c21STomi Valkeinen /* Ok, there is definitely a card registering at the correct 311f7018c21STomi Valkeinen * memory location, so now we do an I/O port test. 312f7018c21STomi Valkeinen */ 313f7018c21STomi Valkeinen 314f7018c21STomi Valkeinen if (!test_hga_b(0x66, 0x0f)) /* cursor low register */ 315f7018c21STomi Valkeinen goto error; 316f7018c21STomi Valkeinen 317f7018c21STomi Valkeinen if (!test_hga_b(0x99, 0x0f)) /* cursor low register */ 318f7018c21STomi Valkeinen goto error; 319f7018c21STomi Valkeinen 320f7018c21STomi Valkeinen /* See if the card is a Hercules, by checking whether the vsync 321f7018c21STomi Valkeinen * bit of the status register is changing. This test lasts for 322f7018c21STomi Valkeinen * approximately 1/10th of a second. 323f7018c21STomi Valkeinen */ 324f7018c21STomi Valkeinen 325f7018c21STomi Valkeinen p_save = q_save = inb_p(HGA_STATUS_PORT) & HGA_STATUS_VSYNC; 326f7018c21STomi Valkeinen 327f7018c21STomi Valkeinen for (count=0; count < 50000 && p_save == q_save; count++) { 328f7018c21STomi Valkeinen q_save = inb(HGA_STATUS_PORT) & HGA_STATUS_VSYNC; 329f7018c21STomi Valkeinen udelay(2); 330f7018c21STomi Valkeinen } 331f7018c21STomi Valkeinen 332f7018c21STomi Valkeinen if (p_save == q_save) 333f7018c21STomi Valkeinen goto error; 334f7018c21STomi Valkeinen 335f7018c21STomi Valkeinen switch (inb_p(HGA_STATUS_PORT) & 0x70) { 336f7018c21STomi Valkeinen case 0x10: 337f7018c21STomi Valkeinen hga_type = TYPE_HERCPLUS; 338f7018c21STomi Valkeinen hga_type_name = "HerculesPlus"; 339f7018c21STomi Valkeinen break; 340f7018c21STomi Valkeinen case 0x50: 341f7018c21STomi Valkeinen hga_type = TYPE_HERCCOLOR; 342f7018c21STomi Valkeinen hga_type_name = "HerculesColor"; 343f7018c21STomi Valkeinen break; 344f7018c21STomi Valkeinen default: 345f7018c21STomi Valkeinen hga_type = TYPE_HERC; 346f7018c21STomi Valkeinen hga_type_name = "Hercules"; 347f7018c21STomi Valkeinen break; 348f7018c21STomi Valkeinen } 349f7018c21STomi Valkeinen return 1; 350f7018c21STomi Valkeinen error: 351f7018c21STomi Valkeinen if (release_io_ports) 352f7018c21STomi Valkeinen release_region(0x3b0, 12); 353f7018c21STomi Valkeinen if (release_io_port) 354f7018c21STomi Valkeinen release_region(0x3bf, 1); 355f7018c21STomi Valkeinen return 0; 356f7018c21STomi Valkeinen } 357f7018c21STomi Valkeinen 358f7018c21STomi Valkeinen /** 359f7018c21STomi Valkeinen * hgafb_open - open the framebuffer device 360f7018c21STomi Valkeinen * @info:pointer to fb_info object containing info for current hga board 361f7018c21STomi Valkeinen * @int:open by console system or userland. 362f7018c21STomi Valkeinen */ 363f7018c21STomi Valkeinen 364f7018c21STomi Valkeinen static int hgafb_open(struct fb_info *info, int init) 365f7018c21STomi Valkeinen { 366f7018c21STomi Valkeinen hga_gfx_mode(); 367f7018c21STomi Valkeinen hga_clear_screen(); 368f7018c21STomi Valkeinen if (!nologo) hga_show_logo(info); 369f7018c21STomi Valkeinen return 0; 370f7018c21STomi Valkeinen } 371f7018c21STomi Valkeinen 372f7018c21STomi Valkeinen /** 373f7018c21STomi Valkeinen * hgafb_open - open the framebuffer device 374f7018c21STomi Valkeinen * @info:pointer to fb_info object containing info for current hga board 375f7018c21STomi Valkeinen * @int:open by console system or userland. 376f7018c21STomi Valkeinen */ 377f7018c21STomi Valkeinen 378f7018c21STomi Valkeinen static int hgafb_release(struct fb_info *info, int init) 379f7018c21STomi Valkeinen { 380f7018c21STomi Valkeinen hga_txt_mode(); 381f7018c21STomi Valkeinen hga_clear_screen(); 382f7018c21STomi Valkeinen return 0; 383f7018c21STomi Valkeinen } 384f7018c21STomi Valkeinen 385f7018c21STomi Valkeinen /** 386f7018c21STomi Valkeinen * hgafb_setcolreg - set color registers 387f7018c21STomi Valkeinen * @regno:register index to set 388f7018c21STomi Valkeinen * @red:red value, unused 389f7018c21STomi Valkeinen * @green:green value, unused 390f7018c21STomi Valkeinen * @blue:blue value, unused 391f7018c21STomi Valkeinen * @transp:transparency value, unused 392f7018c21STomi Valkeinen * @info:unused 393f7018c21STomi Valkeinen * 394f7018c21STomi Valkeinen * This callback function is used to set the color registers of a HGA 395f7018c21STomi Valkeinen * board. Since we have only two fixed colors only @regno is checked. 396f7018c21STomi Valkeinen * A zero is returned on success and 1 for failure. 397f7018c21STomi Valkeinen */ 398f7018c21STomi Valkeinen 399f7018c21STomi Valkeinen static int hgafb_setcolreg(u_int regno, u_int red, u_int green, u_int blue, 400f7018c21STomi Valkeinen u_int transp, struct fb_info *info) 401f7018c21STomi Valkeinen { 402f7018c21STomi Valkeinen if (regno > 1) 403f7018c21STomi Valkeinen return 1; 404f7018c21STomi Valkeinen return 0; 405f7018c21STomi Valkeinen } 406f7018c21STomi Valkeinen 407f7018c21STomi Valkeinen /** 408f7018c21STomi Valkeinen * hga_pan_display - pan or wrap the display 409f7018c21STomi Valkeinen * @var:contains new xoffset, yoffset and vmode values 410f7018c21STomi Valkeinen * @info:pointer to fb_info object containing info for current hga board 411f7018c21STomi Valkeinen * 412f7018c21STomi Valkeinen * This function looks only at xoffset, yoffset and the %FB_VMODE_YWRAP 413f7018c21STomi Valkeinen * flag in @var. If input parameters are correct it calls hga_pan() to 414f7018c21STomi Valkeinen * program the hardware. @info->var is updated to the new values. 415f7018c21STomi Valkeinen * A zero is returned on success and %-EINVAL for failure. 416f7018c21STomi Valkeinen */ 417f7018c21STomi Valkeinen 418f7018c21STomi Valkeinen static int hgafb_pan_display(struct fb_var_screeninfo *var, 419f7018c21STomi Valkeinen struct fb_info *info) 420f7018c21STomi Valkeinen { 421f7018c21STomi Valkeinen if (var->vmode & FB_VMODE_YWRAP) { 422070a1783SSudip Mukherjee if (var->yoffset >= info->var.yres_virtual || 423f7018c21STomi Valkeinen var->xoffset) 424f7018c21STomi Valkeinen return -EINVAL; 425f7018c21STomi Valkeinen } else { 426f7018c21STomi Valkeinen if (var->xoffset + info->var.xres > info->var.xres_virtual 427f7018c21STomi Valkeinen || var->yoffset + info->var.yres > info->var.yres_virtual 428f7018c21STomi Valkeinen || var->yoffset % 8) 429f7018c21STomi Valkeinen return -EINVAL; 430f7018c21STomi Valkeinen } 431f7018c21STomi Valkeinen 432f7018c21STomi Valkeinen hga_pan(var->xoffset, var->yoffset); 433f7018c21STomi Valkeinen return 0; 434f7018c21STomi Valkeinen } 435f7018c21STomi Valkeinen 436f7018c21STomi Valkeinen /** 437f7018c21STomi Valkeinen * hgafb_blank - (un)blank the screen 438f7018c21STomi Valkeinen * @blank_mode:blanking method to use 439f7018c21STomi Valkeinen * @info:unused 440f7018c21STomi Valkeinen * 441f7018c21STomi Valkeinen * Blank the screen if blank_mode != 0, else unblank. 442f7018c21STomi Valkeinen * Implements VESA suspend and powerdown modes on hardware that supports 443f7018c21STomi Valkeinen * disabling hsync/vsync: 444f7018c21STomi Valkeinen * @blank_mode == 2 means suspend vsync, 445f7018c21STomi Valkeinen * @blank_mode == 3 means suspend hsync, 446f7018c21STomi Valkeinen * @blank_mode == 4 means powerdown. 447f7018c21STomi Valkeinen */ 448f7018c21STomi Valkeinen 449f7018c21STomi Valkeinen static int hgafb_blank(int blank_mode, struct fb_info *info) 450f7018c21STomi Valkeinen { 451f7018c21STomi Valkeinen hga_blank(blank_mode); 452f7018c21STomi Valkeinen return 0; 453f7018c21STomi Valkeinen } 454f7018c21STomi Valkeinen 455f7018c21STomi Valkeinen /* 456f7018c21STomi Valkeinen * Accel functions 457f7018c21STomi Valkeinen */ 458f7018c21STomi Valkeinen static void hgafb_fillrect(struct fb_info *info, const struct fb_fillrect *rect) 459f7018c21STomi Valkeinen { 460f7018c21STomi Valkeinen u_int rows, y; 461f7018c21STomi Valkeinen u8 __iomem *dest; 462f7018c21STomi Valkeinen 463f7018c21STomi Valkeinen y = rect->dy; 464f7018c21STomi Valkeinen 465f7018c21STomi Valkeinen for (rows = rect->height; rows--; y++) { 466f7018c21STomi Valkeinen dest = rowaddr(info, y) + (rect->dx >> 3); 467f7018c21STomi Valkeinen switch (rect->rop) { 468f7018c21STomi Valkeinen case ROP_COPY: 469f7018c21STomi Valkeinen memset_io(dest, rect->color, (rect->width >> 3)); 470f7018c21STomi Valkeinen break; 471f7018c21STomi Valkeinen case ROP_XOR: 472f7018c21STomi Valkeinen fb_writeb(~(fb_readb(dest)), dest); 473f7018c21STomi Valkeinen break; 474f7018c21STomi Valkeinen } 475f7018c21STomi Valkeinen } 476f7018c21STomi Valkeinen } 477f7018c21STomi Valkeinen 478f7018c21STomi Valkeinen static void hgafb_copyarea(struct fb_info *info, const struct fb_copyarea *area) 479f7018c21STomi Valkeinen { 480f7018c21STomi Valkeinen u_int rows, y1, y2; 481f7018c21STomi Valkeinen u8 __iomem *src; 482f7018c21STomi Valkeinen u8 __iomem *dest; 483f7018c21STomi Valkeinen 484f7018c21STomi Valkeinen if (area->dy <= area->sy) { 485f7018c21STomi Valkeinen y1 = area->sy; 486f7018c21STomi Valkeinen y2 = area->dy; 487f7018c21STomi Valkeinen 488f7018c21STomi Valkeinen for (rows = area->height; rows--; ) { 489f7018c21STomi Valkeinen src = rowaddr(info, y1) + (area->sx >> 3); 490f7018c21STomi Valkeinen dest = rowaddr(info, y2) + (area->dx >> 3); 491f7018c21STomi Valkeinen memmove(dest, src, (area->width >> 3)); 492f7018c21STomi Valkeinen y1++; 493f7018c21STomi Valkeinen y2++; 494f7018c21STomi Valkeinen } 495f7018c21STomi Valkeinen } else { 496f7018c21STomi Valkeinen y1 = area->sy + area->height - 1; 497f7018c21STomi Valkeinen y2 = area->dy + area->height - 1; 498f7018c21STomi Valkeinen 499f7018c21STomi Valkeinen for (rows = area->height; rows--;) { 500f7018c21STomi Valkeinen src = rowaddr(info, y1) + (area->sx >> 3); 501f7018c21STomi Valkeinen dest = rowaddr(info, y2) + (area->dx >> 3); 502f7018c21STomi Valkeinen memmove(dest, src, (area->width >> 3)); 503f7018c21STomi Valkeinen y1--; 504f7018c21STomi Valkeinen y2--; 505f7018c21STomi Valkeinen } 506f7018c21STomi Valkeinen } 507f7018c21STomi Valkeinen } 508f7018c21STomi Valkeinen 509f7018c21STomi Valkeinen static void hgafb_imageblit(struct fb_info *info, const struct fb_image *image) 510f7018c21STomi Valkeinen { 511f7018c21STomi Valkeinen u8 __iomem *dest; 512f7018c21STomi Valkeinen u8 *cdat = (u8 *) image->data; 513f7018c21STomi Valkeinen u_int rows, y = image->dy; 514f7018c21STomi Valkeinen u_int x; 515f7018c21STomi Valkeinen u8 d; 516f7018c21STomi Valkeinen 517f7018c21STomi Valkeinen for (rows = image->height; rows--; y++) { 518f7018c21STomi Valkeinen for (x = 0; x < image->width; x+= 8) { 519f7018c21STomi Valkeinen d = *cdat++; 520f7018c21STomi Valkeinen dest = rowaddr(info, y) + ((image->dx + x)>> 3); 521f7018c21STomi Valkeinen fb_writeb(d, dest); 522f7018c21STomi Valkeinen } 523f7018c21STomi Valkeinen } 524f7018c21STomi Valkeinen } 525f7018c21STomi Valkeinen 5268a48ac33SJani Nikula static const struct fb_ops hgafb_ops = { 527f7018c21STomi Valkeinen .owner = THIS_MODULE, 528f7018c21STomi Valkeinen .fb_open = hgafb_open, 529f7018c21STomi Valkeinen .fb_release = hgafb_release, 530f7018c21STomi Valkeinen .fb_setcolreg = hgafb_setcolreg, 531f7018c21STomi Valkeinen .fb_pan_display = hgafb_pan_display, 532f7018c21STomi Valkeinen .fb_blank = hgafb_blank, 533f7018c21STomi Valkeinen .fb_fillrect = hgafb_fillrect, 534f7018c21STomi Valkeinen .fb_copyarea = hgafb_copyarea, 535f7018c21STomi Valkeinen .fb_imageblit = hgafb_imageblit, 536f7018c21STomi Valkeinen }; 537f7018c21STomi Valkeinen 538f7018c21STomi Valkeinen /* ------------------------------------------------------------------------- * 539f7018c21STomi Valkeinen * 540f7018c21STomi Valkeinen * Functions in fb_info 541f7018c21STomi Valkeinen * 542f7018c21STomi Valkeinen * ------------------------------------------------------------------------- */ 543f7018c21STomi Valkeinen 544f7018c21STomi Valkeinen /* ------------------------------------------------------------------------- */ 545f7018c21STomi Valkeinen 546f7018c21STomi Valkeinen /* 547f7018c21STomi Valkeinen * Initialization 548f7018c21STomi Valkeinen */ 549f7018c21STomi Valkeinen 550f7018c21STomi Valkeinen static int hgafb_probe(struct platform_device *pdev) 551f7018c21STomi Valkeinen { 552f7018c21STomi Valkeinen struct fb_info *info; 553f7018c21STomi Valkeinen 554f7018c21STomi Valkeinen if (! hga_card_detect()) { 555f7018c21STomi Valkeinen printk(KERN_INFO "hgafb: HGA card not detected.\n"); 556f7018c21STomi Valkeinen if (hga_vram) 557f7018c21STomi Valkeinen iounmap(hga_vram); 558f7018c21STomi Valkeinen return -EINVAL; 559f7018c21STomi Valkeinen } 560f7018c21STomi Valkeinen 561f7018c21STomi Valkeinen printk(KERN_INFO "hgafb: %s with %ldK of memory detected.\n", 562f7018c21STomi Valkeinen hga_type_name, hga_vram_len/1024); 563f7018c21STomi Valkeinen 564f7018c21STomi Valkeinen info = framebuffer_alloc(0, &pdev->dev); 565f7018c21STomi Valkeinen if (!info) { 566f7018c21STomi Valkeinen iounmap(hga_vram); 567f7018c21STomi Valkeinen return -ENOMEM; 568f7018c21STomi Valkeinen } 569f7018c21STomi Valkeinen 570f7018c21STomi Valkeinen hga_fix.smem_start = (unsigned long)hga_vram; 571f7018c21STomi Valkeinen hga_fix.smem_len = hga_vram_len; 572f7018c21STomi Valkeinen 573f7018c21STomi Valkeinen info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN; 574f7018c21STomi Valkeinen info->var = hga_default_var; 575f7018c21STomi Valkeinen info->fix = hga_fix; 576f7018c21STomi Valkeinen info->monspecs.hfmin = 0; 577f7018c21STomi Valkeinen info->monspecs.hfmax = 0; 578f7018c21STomi Valkeinen info->monspecs.vfmin = 10000; 579f7018c21STomi Valkeinen info->monspecs.vfmax = 10000; 580f7018c21STomi Valkeinen info->monspecs.dpms = 0; 581f7018c21STomi Valkeinen info->fbops = &hgafb_ops; 582f7018c21STomi Valkeinen info->screen_base = hga_vram; 583f7018c21STomi Valkeinen 584f7018c21STomi Valkeinen if (register_framebuffer(info) < 0) { 585f7018c21STomi Valkeinen framebuffer_release(info); 586f7018c21STomi Valkeinen iounmap(hga_vram); 587f7018c21STomi Valkeinen return -EINVAL; 588f7018c21STomi Valkeinen } 589f7018c21STomi Valkeinen 590f7018c21STomi Valkeinen fb_info(info, "%s frame buffer device\n", info->fix.id); 591f7018c21STomi Valkeinen platform_set_drvdata(pdev, info); 592f7018c21STomi Valkeinen return 0; 593f7018c21STomi Valkeinen } 594f7018c21STomi Valkeinen 595f7018c21STomi Valkeinen static int hgafb_remove(struct platform_device *pdev) 596f7018c21STomi Valkeinen { 597f7018c21STomi Valkeinen struct fb_info *info = platform_get_drvdata(pdev); 598f7018c21STomi Valkeinen 599f7018c21STomi Valkeinen hga_txt_mode(); 600f7018c21STomi Valkeinen hga_clear_screen(); 601f7018c21STomi Valkeinen 602f7018c21STomi Valkeinen if (info) { 603f7018c21STomi Valkeinen unregister_framebuffer(info); 604f7018c21STomi Valkeinen framebuffer_release(info); 605f7018c21STomi Valkeinen } 606f7018c21STomi Valkeinen 607f7018c21STomi Valkeinen iounmap(hga_vram); 608f7018c21STomi Valkeinen 609f7018c21STomi Valkeinen if (release_io_ports) 610f7018c21STomi Valkeinen release_region(0x3b0, 12); 611f7018c21STomi Valkeinen 612f7018c21STomi Valkeinen if (release_io_port) 613f7018c21STomi Valkeinen release_region(0x3bf, 1); 614f7018c21STomi Valkeinen 615f7018c21STomi Valkeinen return 0; 616f7018c21STomi Valkeinen } 617f7018c21STomi Valkeinen 618f7018c21STomi Valkeinen static struct platform_driver hgafb_driver = { 619f7018c21STomi Valkeinen .probe = hgafb_probe, 620f7018c21STomi Valkeinen .remove = hgafb_remove, 621f7018c21STomi Valkeinen .driver = { 622f7018c21STomi Valkeinen .name = "hgafb", 623f7018c21STomi Valkeinen }, 624f7018c21STomi Valkeinen }; 625f7018c21STomi Valkeinen 626f7018c21STomi Valkeinen static struct platform_device *hgafb_device; 627f7018c21STomi Valkeinen 628f7018c21STomi Valkeinen static int __init hgafb_init(void) 629f7018c21STomi Valkeinen { 630f7018c21STomi Valkeinen int ret; 631f7018c21STomi Valkeinen 632f7018c21STomi Valkeinen if (fb_get_options("hgafb", NULL)) 633f7018c21STomi Valkeinen return -ENODEV; 634f7018c21STomi Valkeinen 635f7018c21STomi Valkeinen ret = platform_driver_register(&hgafb_driver); 636f7018c21STomi Valkeinen 637f7018c21STomi Valkeinen if (!ret) { 638f7018c21STomi Valkeinen hgafb_device = platform_device_register_simple("hgafb", 0, NULL, 0); 639f7018c21STomi Valkeinen 640f7018c21STomi Valkeinen if (IS_ERR(hgafb_device)) { 641f7018c21STomi Valkeinen platform_driver_unregister(&hgafb_driver); 642f7018c21STomi Valkeinen ret = PTR_ERR(hgafb_device); 643f7018c21STomi Valkeinen } 644f7018c21STomi Valkeinen } 645f7018c21STomi Valkeinen 646f7018c21STomi Valkeinen return ret; 647f7018c21STomi Valkeinen } 648f7018c21STomi Valkeinen 649f7018c21STomi Valkeinen static void __exit hgafb_exit(void) 650f7018c21STomi Valkeinen { 651f7018c21STomi Valkeinen platform_device_unregister(hgafb_device); 652f7018c21STomi Valkeinen platform_driver_unregister(&hgafb_driver); 653f7018c21STomi Valkeinen } 654f7018c21STomi Valkeinen 655f7018c21STomi Valkeinen /* ------------------------------------------------------------------------- 656f7018c21STomi Valkeinen * 657f7018c21STomi Valkeinen * Modularization 658f7018c21STomi Valkeinen * 659f7018c21STomi Valkeinen * ------------------------------------------------------------------------- */ 660f7018c21STomi Valkeinen 661f7018c21STomi Valkeinen MODULE_AUTHOR("Ferenc Bakonyi (fero@drama.obuda.kando.hu)"); 662f7018c21STomi Valkeinen MODULE_DESCRIPTION("FBDev driver for Hercules Graphics Adaptor"); 663f7018c21STomi Valkeinen MODULE_LICENSE("GPL"); 664f7018c21STomi Valkeinen 665f7018c21STomi Valkeinen module_param(nologo, bool, 0); 666f7018c21STomi Valkeinen MODULE_PARM_DESC(nologo, "Disables startup logo if != 0 (default=0)"); 667f7018c21STomi Valkeinen module_init(hgafb_init); 668f7018c21STomi Valkeinen module_exit(hgafb_exit); 669