linux 2.6.16.38 w/ vs2.0.3-rc1
[linux-2.6.git] / drivers / video / neofb.c
index 3b3f84f..b961d56 100644 (file)
@@ -93,7 +93,7 @@ static int external;
 static int libretto;
 static int nostretch;
 static int nopciburst;
-static char *mode_option __initdata = NULL;
+static char *mode_option __devinitdata = NULL;
 
 #ifdef MODULE
 
@@ -152,11 +152,6 @@ static biosMode bios32[] = {
 };
 #endif
 
-static inline u32 read_le32(int regindex, const struct neofb_par *par)
-{
-       return readl(par->neo2200 + par->cursorOff + regindex);
-}
-
 static inline void write_le32(int regindex, u32 val, const struct neofb_par *par)
 {
        writel(val, par->neo2200 + par->cursorOff + regindex);
@@ -405,21 +400,21 @@ static void neoUnlock(void)
  */
 static int paletteEnabled = 0;
 
-inline void VGAenablePalette(void)
+static inline void VGAenablePalette(void)
 {
        vga_r(NULL, VGA_IS1_RC);
        vga_w(NULL, VGA_ATT_W, 0x00);
        paletteEnabled = 1;
 }
 
-inline void VGAdisablePalette(void)
+static inline void VGAdisablePalette(void)
 {
        vga_r(NULL, VGA_IS1_RC);
        vga_w(NULL, VGA_ATT_W, 0x20);
        paletteEnabled = 0;
 }
 
-inline void VGAwATTR(u8 index, u8 value)
+static inline void VGAwATTR(u8 index, u8 value)
 {
        if (paletteEnabled)
                index &= ~0x20;
@@ -430,7 +425,7 @@ inline void VGAwATTR(u8 index, u8 value)
        vga_wattr(NULL, index, value);
 }
 
-void vgaHWProtect(int on)
+static void vgaHWProtect(int on)
 {
        unsigned char tmp;
 
@@ -490,11 +485,9 @@ static void vgaHWRestore(const struct fb_info *info,
  */
 static inline int neo2200_sync(struct fb_info *info)
 {
-       struct neofb_par *par = (struct neofb_par *) info->par;
-       int waitcycles;
+       struct neofb_par *par = info->par;
 
-       while (readl(&par->neo2200->bltStat) & 1)
-               waitcycles++;
+       while (readl(&par->neo2200->bltStat) & 1);
        return 0;
 }
 
@@ -530,7 +523,7 @@ static inline void neo2200_wait_fifo(struct fb_info *info,
 static inline void neo2200_accel_init(struct fb_info *info,
                                      struct fb_var_screeninfo *var)
 {
-       struct neofb_par *par = (struct neofb_par *) info->par;
+       struct neofb_par *par = info->par;
        Neo2200 __iomem *neo2200 = par->neo2200;
        u32 bltMod, pitch;
 
@@ -565,7 +558,7 @@ static inline void neo2200_accel_init(struct fb_info *info,
 static int
 neofb_open(struct fb_info *info, int user)
 {
-       struct neofb_par *par = (struct neofb_par *) info->par;
+       struct neofb_par *par = info->par;
        int cnt = atomic_read(&par->ref_count);
 
        if (!cnt) {
@@ -580,7 +573,7 @@ neofb_open(struct fb_info *info, int user)
 static int
 neofb_release(struct fb_info *info, int user)
 {
-       struct neofb_par *par = (struct neofb_par *) info->par;
+       struct neofb_par *par = info->par;
        int cnt = atomic_read(&par->ref_count);
 
        if (!cnt)
@@ -595,7 +588,7 @@ neofb_release(struct fb_info *info, int user)
 static int
 neofb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
 {
-       struct neofb_par *par = (struct neofb_par *) info->par;
+       struct neofb_par *par = info->par;
        unsigned int pixclock = var->pixclock;
        struct xtimings timings;
        int memlen, vramlen;
@@ -762,7 +755,7 @@ neofb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
 
 static int neofb_set_par(struct fb_info *info)
 {
-       struct neofb_par *par = (struct neofb_par *) info->par;
+       struct neofb_par *par = info->par;
        struct xtimings timings;
        unsigned char temp;
        int i, clock_hi = 0;
@@ -848,6 +841,9 @@ static int neofb_set_par(struct fb_info *info)
 
        par->SysIfaceCntl2 = 0xc0;      /* VESA Bios sets this to 0x80! */
 
+       /* Initialize: by default, we want display config register to be read */
+       par->PanelDispCntlRegRead = 1;
+
        /* Enable any user specified display devices. */
        par->PanelDispCntlReg1 = 0x00;
        if (par->internal_display)
@@ -858,7 +854,7 @@ static int neofb_set_par(struct fb_info *info)
        /* If the user did not specify any display devices, then... */
        if (par->PanelDispCntlReg1 == 0x00) {
                /* Default to internal (i.e., LCD) only. */
-               par->PanelDispCntlReg1 |= 0x02;
+               par->PanelDispCntlReg1 = vga_rgfx(NULL, 0x20) & 0x03;
        }
 
        /* If we are using a fixed mode, then tell the chip we are. */
@@ -1221,7 +1217,7 @@ static int neofb_set_par(struct fb_info *info)
 static void neofb_update_start(struct fb_info *info,
                               struct fb_var_screeninfo *var)
 {
-       struct neofb_par *par = (struct neofb_par *) info->par;
+       struct neofb_par *par = info->par;
        struct vgastate *state = &par->state;
        int oldExtCRTDispAddr;
        int Base;
@@ -1320,7 +1316,7 @@ static int neofb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
 /*
  *    (Un)Blank the display.
  */
-int neofb_blank(int blank_mode, struct fb_info *info)
+static int neofb_blank(int blank_mode, struct fb_info *info)
 {
        /*
         *  Blank the screen if blank_mode != 0, else unblank.
@@ -1336,9 +1332,21 @@ int neofb_blank(int blank_mode, struct fb_info *info)
         *  wms...Enable VESA DPMS compatible powerdown mode
         *  run "setterm -powersave powerdown" to take advantage
         */
-       struct neofb_par *par = (struct neofb_par *)info->par;
+       struct neofb_par *par = info->par;
        int seqflags, lcdflags, dpmsflags, reg;
 
+
+       /*
+        * Reload the value stored in the register, if sensible. It might have
+        * been changed via FN keystroke.
+        */
+       if (par->PanelDispCntlRegRead) {
+               neoUnlock();
+               par->PanelDispCntlReg1 = vga_rgfx(NULL, 0x20) & 0x03;
+               neoLock(&par->state);
+       }
+       par->PanelDispCntlRegRead = !blank_mode;
+
        switch (blank_mode) {
        case FB_BLANK_POWERDOWN:        /* powerdown - both sync lines down */
                seqflags = VGA_SR01_SCREEN_OFF; /* Disable sequencer */
@@ -1371,7 +1379,7 @@ int neofb_blank(int blank_mode, struct fb_info *info)
        case FB_BLANK_NORMAL:           /* just blank screen (backlight stays on) */
                seqflags = VGA_SR01_SCREEN_OFF; /* Disable sequencer */
                lcdflags = par->PanelDispCntlReg1 & 0x02; /* LCD normal */
-               dpmsflags = 0;                  /* no hsync/vsync suppression */
+               dpmsflags = 0x00;       /* no hsync/vsync suppression */
                break;
        case FB_BLANK_UNBLANK:          /* unblank */
                seqflags = 0;                   /* Enable sequencer */
@@ -1409,7 +1417,7 @@ int neofb_blank(int blank_mode, struct fb_info *info)
 static void
 neo2200_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
 {
-       struct neofb_par *par = (struct neofb_par *) info->par;
+       struct neofb_par *par = info->par;
        u_long dst, rop;
 
        dst = rect->dx + rect->dy * info->var.xres_virtual;
@@ -1445,7 +1453,7 @@ static void
 neo2200_copyarea(struct fb_info *info, const struct fb_copyarea *area)
 {
        u32 sx = area->sx, sy = area->sy, dx = area->dx, dy = area->dy;
-       struct neofb_par *par = (struct neofb_par *) info->par;
+       struct neofb_par *par = info->par;
        u_long src, dst, bltCntl;
 
        bltCntl = NEO_BC3_FIFO_EN | NEO_BC3_SKIP_MAPPING | 0x0C0000;
@@ -1477,7 +1485,7 @@ neo2200_copyarea(struct fb_info *info, const struct fb_copyarea *area)
 static void
 neo2200_imageblit(struct fb_info *info, const struct fb_image *image)
 {
-       struct neofb_par *par = (struct neofb_par *) info->par;
+       struct neofb_par *par = info->par;
        int s_pitch = (image->width * image->depth + 7) >> 3;
        int scan_align = info->pixmap.scan_align - 1;
        int buf_align = info->pixmap.buf_align - 1;
@@ -1670,7 +1678,6 @@ static struct fb_ops neofb_ops = {
        .fb_fillrect    = neofb_fillrect,
        .fb_copyarea    = neofb_copyarea,
        .fb_imageblit   = neofb_imageblit,
-       .fb_cursor      = soft_cursor,
 };
 
 /* --------------------------------------------------------------------- */
@@ -1692,11 +1699,31 @@ static struct fb_videomode __devinitdata mode800x480 = {
 static int __devinit neo_map_mmio(struct fb_info *info,
                                  struct pci_dev *dev)
 {
-       struct neofb_par *par = (struct neofb_par *) info->par;
+       struct neofb_par *par = info->par;
 
        DBG("neo_map_mmio");
 
-       info->fix.mmio_start = pci_resource_start(dev, 1);
+       switch (info->fix.accel) {
+               case FB_ACCEL_NEOMAGIC_NM2070:
+                       info->fix.mmio_start = pci_resource_start(dev, 0)+
+                               0x100000;
+                       break;
+               case FB_ACCEL_NEOMAGIC_NM2090:
+               case FB_ACCEL_NEOMAGIC_NM2093:
+                       info->fix.mmio_start = pci_resource_start(dev, 0)+
+                               0x200000;
+                       break;
+               case FB_ACCEL_NEOMAGIC_NM2160:
+               case FB_ACCEL_NEOMAGIC_NM2097:
+               case FB_ACCEL_NEOMAGIC_NM2200:
+               case FB_ACCEL_NEOMAGIC_NM2230:
+               case FB_ACCEL_NEOMAGIC_NM2360:
+               case FB_ACCEL_NEOMAGIC_NM2380:
+                       info->fix.mmio_start = pci_resource_start(dev, 1);
+                       break;
+               default:
+                       info->fix.mmio_start = pci_resource_start(dev, 0);
+       }
        info->fix.mmio_len = MMIO_SIZE;
 
        if (!request_mem_region
@@ -1719,7 +1746,7 @@ static int __devinit neo_map_mmio(struct fb_info *info,
 
 static void neo_unmap_mmio(struct fb_info *info)
 {
-       struct neofb_par *par = (struct neofb_par *) info->par;
+       struct neofb_par *par = info->par;
 
        DBG("neo_unmap_mmio");
 
@@ -1782,7 +1809,7 @@ static void neo_unmap_video(struct fb_info *info)
 
 #ifdef CONFIG_MTRR
        {
-               struct neofb_par *par = (struct neofb_par *) info->par;
+               struct neofb_par *par = info->par;
 
                mtrr_del(par->mtrr, info->fix.smem_start,
                         info->fix.smem_len);
@@ -1797,7 +1824,7 @@ static void neo_unmap_video(struct fb_info *info)
 
 static int __devinit neo_scan_monitor(struct fb_info *info)
 {
-       struct neofb_par *par = (struct neofb_par *) info->par;
+       struct neofb_par *par = info->par;
        unsigned char type, display;
        int w;
 
@@ -1876,7 +1903,7 @@ static int __devinit neo_scan_monitor(struct fb_info *info)
 
 static int __devinit neo_init_hw(struct fb_info *info)
 {
-       struct neofb_par *par = (struct neofb_par *) info->par;
+       struct neofb_par *par = info->par;
        int videoRam = 896;
        int maxClock = 65000;
        int CursorMem = 1024;
@@ -2000,7 +2027,7 @@ static struct fb_info *__devinit neo_alloc_fb_info(struct pci_dev *dev, const st
        struct fb_info *info;
        struct neofb_par *par;
 
-       info = framebuffer_alloc(sizeof(struct neofb_par) + sizeof(u32) * 256, &dev->dev);
+       info = framebuffer_alloc(sizeof(struct neofb_par), &dev->dev);
 
        if (!info)
                return NULL;
@@ -2015,6 +2042,7 @@ static struct fb_info *__devinit neo_alloc_fb_info(struct pci_dev *dev, const st
 
        par->internal_display = internal;
        par->external_display = external;
+       info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN;
 
        switch (info->fix.accel) {
        case FB_ACCEL_NEOMAGIC_NM2070:
@@ -2034,15 +2062,27 @@ static struct fb_info *__devinit neo_alloc_fb_info(struct pci_dev *dev, const st
                break;
        case FB_ACCEL_NEOMAGIC_NM2200:
                sprintf(info->fix.id, "MagicGraph 256AV");
+               info->flags |= FBINFO_HWACCEL_IMAGEBLIT |
+                              FBINFO_HWACCEL_COPYAREA |
+                              FBINFO_HWACCEL_FILLRECT;
                break;
        case FB_ACCEL_NEOMAGIC_NM2230:
                sprintf(info->fix.id, "MagicGraph 256AV+");
+               info->flags |= FBINFO_HWACCEL_IMAGEBLIT |
+                              FBINFO_HWACCEL_COPYAREA |
+                              FBINFO_HWACCEL_FILLRECT;
                break;
        case FB_ACCEL_NEOMAGIC_NM2360:
                sprintf(info->fix.id, "MagicGraph 256ZX");
+               info->flags |= FBINFO_HWACCEL_IMAGEBLIT |
+                              FBINFO_HWACCEL_COPYAREA |
+                              FBINFO_HWACCEL_FILLRECT;
                break;
        case FB_ACCEL_NEOMAGIC_NM2380:
                sprintf(info->fix.id, "MagicGraph 256XL+");
+               info->flags |= FBINFO_HWACCEL_IMAGEBLIT |
+                              FBINFO_HWACCEL_COPYAREA |
+                              FBINFO_HWACCEL_FILLRECT;
                break;
        }
 
@@ -2054,10 +2094,7 @@ static struct fb_info *__devinit neo_alloc_fb_info(struct pci_dev *dev, const st
        info->fix.accel = id->driver_data;
 
        info->fbops = &neofb_ops;
-       info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
-               FBINFO_HWACCEL_IMAGEBLIT | FBINFO_HWACCEL_COPYAREA |
-               FBINFO_HWACCEL_COPYAREA;
-       info->pseudo_palette = (void *) (par + 1);
+       info->pseudo_palette = par->palette;
        return info;
 }
 
@@ -2235,7 +2272,8 @@ static struct pci_driver neofb_driver = {
 
 /* ************************* init in-kernel code ************************** */
 
-int __init neofb_setup(char *options)
+#ifndef MODULE
+static int __init neofb_setup(char *options)
 {
        char *this_opt;
 
@@ -2263,8 +2301,9 @@ int __init neofb_setup(char *options)
        }
        return 0;
 }
+#endif  /*  MODULE  */
 
-int __init neofb_init(void)
+static int __init neofb_init(void)
 {
 #ifndef MODULE
        char *option = NULL;