fbdev: move FBIO_WAITFORVSYNC to linux/fb.h
[safe/jmp/linux-2.6] / drivers / video / aty / atyfb_base.c
index 9ea75f1..f8d69ad 100644 (file)
@@ -26,7 +26,7 @@
  *                        Anthony Tong <atong@uiuc.edu>
  *
  *  Generic LCD support written by Daniel Mantione, ported from 2.4.20 by Alex Kern
- *  Many Thanks to Ville Syrjälä for patches and fixing nasting 16 bit color bug.
+ *  Many Thanks to Ville Syrjälä for patches and fixing nasting 16 bit color bug.
  *
  *  This file is subject to the terms and conditions of the GNU General Public
  *  License. See the file COPYING in the main directory of this archive for
 #include <linux/spinlock.h>
 #include <linux/wait.h>
 #include <linux/backlight.h>
+#include <linux/reboot.h>
+#include <linux/dmi.h>
 
 #include <asm/io.h>
-#include <asm/uaccess.h>
+#include <linux/uaccess.h>
 
 #include <video/mach64.h>
 #include "atyfb.h"
@@ -80,8 +82,9 @@
 #include "../macmodes.h"
 #endif
 #ifdef __sparc__
-#include <asm/pbm.h>
 #include <asm/fbio.h>
+#include <asm/oplib.h>
+#include <asm/prom.h>
 #endif
 
 #ifdef CONFIG_ADB_PMU
 #endif
 
 #define PRINTKI(fmt, args...)  printk(KERN_INFO "atyfb: " fmt, ## args)
-#define PRINTKE(fmt, args...)   printk(KERN_ERR "atyfb: " fmt, ## args)
+#define PRINTKE(fmt, args...)  printk(KERN_ERR "atyfb: " fmt, ## args)
 
-#if defined(CONFIG_PM) || defined(CONFIG_PMAC_BACKLIGHT) || defined (CONFIG_FB_ATY_GENERIC_LCD)
+#if defined(CONFIG_PM) || defined(CONFIG_PMAC_BACKLIGHT) || \
+defined (CONFIG_FB_ATY_GENERIC_LCD) || defined(CONFIG_FB_ATY_BACKLIGHT)
 static const u32 lt_lcd_regs[] = {
-       CONFIG_PANEL_LG,
+       CNFG_PANEL_LG,
        LCD_GEN_CNTL_LG,
        DSTN_CONTROL_LG,
        HFB_PITCH_ADDR_LG,
@@ -184,32 +188,23 @@ u32 aty_ld_lcd(int index, const struct atyfb_par *par)
  */
 static void ATIReduceRatio(int *Numerator, int *Denominator)
 {
-    int Multiplier, Divider, Remainder;
+       int Multiplier, Divider, Remainder;
 
-    Multiplier = *Numerator;
-    Divider = *Denominator;
+       Multiplier = *Numerator;
+       Divider = *Denominator;
 
-    while ((Remainder = Multiplier % Divider))
-    {
-        Multiplier = Divider;
-        Divider = Remainder;
-    }
+       while ((Remainder = Multiplier % Divider)) {
+               Multiplier = Divider;
+               Divider = Remainder;
+       }
 
-    *Numerator /= Divider;
-    *Denominator /= Divider;
+       *Numerator /= Divider;
+       *Denominator /= Divider;
 }
 #endif
-    /*
-     *  The Hardware parameters for each card
-     */
-
-struct aty_cmap_regs {
-       u8 windex;
-       u8 lut;
-       u8 mask;
-       u8 rindex;
-       u8 cntl;
-};
+/*
+ * The Hardware parameters for each card
+ */
 
 struct pci_mmap_map {
        unsigned long voff;
@@ -227,17 +222,19 @@ static struct fb_fix_screeninfo atyfb_fix __devinitdata = {
        .ypanstep       = 1,
 };
 
-    /*
    *  Frame buffer device API
    */
+/*
* Frame buffer device API
+ */
 
 static int atyfb_open(struct fb_info *info, int user);
 static int atyfb_release(struct fb_info *info, int user);
-static int atyfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info);
+static int atyfb_check_var(struct fb_var_screeninfo *var,
+                          struct fb_info *info);
 static int atyfb_set_par(struct fb_info *info);
 static int atyfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
-       u_int transp, struct fb_info *info);
-static int atyfb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info);
+                          u_int transp, struct fb_info *info);
+static int atyfb_pan_display(struct fb_var_screeninfo *var,
+                            struct fb_info *info);
 static int atyfb_blank(int blank, struct fb_info *info);
 static int atyfb_ioctl(struct fb_info *info, u_int cmd, u_long arg);
 #ifdef __sparc__
@@ -245,31 +242,35 @@ static int atyfb_mmap(struct fb_info *info, struct vm_area_struct *vma);
 #endif
 static int atyfb_sync(struct fb_info *info);
 
-    /*
-     *  Internal routines
-     */
+/*
+ * Internal routines
+ */
+
+static int aty_init(struct fb_info *info);
 
-static int aty_init(struct fb_info *info, const char *name);
 #ifdef CONFIG_ATARI
 static int store_video_par(char *videopar, unsigned char m64_num);
 #endif
 
-static struct crtc saved_crtc;
-static union aty_pll saved_pll;
 static void aty_get_crtc(const struct atyfb_par *par, struct crtc *crtc);
 
 static void aty_set_crtc(const struct atyfb_par *par, const struct crtc *crtc);
-static int aty_var_to_crtc(const struct fb_info *info, const struct fb_var_screeninfo *var, struct crtc *crtc);
-static int aty_crtc_to_var(const struct crtc *crtc, struct fb_var_screeninfo *var);
+static int aty_var_to_crtc(const struct fb_info *info,
+                          const struct fb_var_screeninfo *var,
+                          struct crtc *crtc);
+static int aty_crtc_to_var(const struct crtc *crtc,
+                          struct fb_var_screeninfo *var);
 static void set_off_pitch(struct atyfb_par *par, const struct fb_info *info);
 #ifdef CONFIG_PPC
 static int read_aty_sense(const struct atyfb_par *par);
 #endif
 
+static DEFINE_MUTEX(reboot_lock);
+static struct fb_info *reboot_info;
 
-    /*
    *  Interface used by the world
    */
+/*
* Interface used by the world
+ */
 
 static struct fb_var_screeninfo default_var = {
        /* 640x480, 60 Hz, Non-Interlaced (25.175 MHz dotclock) */
@@ -315,6 +316,12 @@ static int xclk;
 static int comp_sync __devinitdata = -1;
 static char *mode;
 
+#ifdef CONFIG_PMAC_BACKLIGHT
+static int backlight __devinitdata = 1;
+#else
+static int backlight __devinitdata = 0;
+#endif
+
 #ifdef CONFIG_PPC
 static int default_vmode __devinitdata = VMODE_CHOOSE;
 static int default_cmode __devinitdata = CMODE_CHOOSE;
@@ -360,8 +367,8 @@ static unsigned long phys_guiregbase[FB_MAX] __devinitdata = { 0, };
 #define ATI_CHIP_264GTPRO  (ATI_MODERN_SET | M64F_SDRAM_MAGIC_PLL | M64F_HW_TRIPLE | M64F_FIFO_32 | M64F_RESET_3D)
 #define ATI_CHIP_264LTPRO  (ATI_MODERN_SET | M64F_HW_TRIPLE | M64F_FIFO_32 | M64F_RESET_3D)
 
-#define ATI_CHIP_264XL     (ATI_MODERN_SET | M64F_HW_TRIPLE | M64F_FIFO_32 | M64F_RESET_3D | M64F_XL_DLL | M64F_MFB_FORCE_4)
-#define ATI_CHIP_MOBILITY  (ATI_MODERN_SET | M64F_HW_TRIPLE | M64F_FIFO_32 | M64F_RESET_3D | M64F_XL_DLL | M64F_MFB_FORCE_4 | M64F_MOBIL_BUS)
+#define ATI_CHIP_264XL     (ATI_MODERN_SET | M64F_HW_TRIPLE | M64F_FIFO_32 | M64F_RESET_3D | M64F_XL_DLL | M64F_MFB_FORCE_4 | M64F_XL_MEM)
+#define ATI_CHIP_MOBILITY  (ATI_MODERN_SET | M64F_HW_TRIPLE | M64F_FIFO_32 | M64F_RESET_3D | M64F_XL_DLL | M64F_MFB_FORCE_4 | M64F_XL_MEM | M64F_MOBIL_BUS)
 
 static struct {
        u16 pci_id;
@@ -423,7 +430,6 @@ static struct {
 #endif /* CONFIG_FB_ATY_CT */
 };
 
-/* can not fail */
 static int __devinit correct_chipset(struct atyfb_par *par)
 {
        u8 rev;
@@ -436,6 +442,9 @@ static int __devinit correct_chipset(struct atyfb_par *par)
                if (par->pci_id == aty_chips[i].pci_id)
                        break;
 
+       if (i < 0)
+               return -ENODEV;
+
        name = aty_chips[i].name;
        par->pll_limits.pll_max = aty_chips[i].pll;
        par->pll_limits.mclk = aty_chips[i].mclk;
@@ -443,18 +452,18 @@ static int __devinit correct_chipset(struct atyfb_par *par)
        par->pll_limits.ecp_max = aty_chips[i].ecp_max;
        par->features = aty_chips[i].features;
 
-       chip_id = aty_ld_le32(CONFIG_CHIP_ID, par);
+       chip_id = aty_ld_le32(CNFG_CHIP_ID, par);
        type = chip_id & CFG_CHIP_TYPE;
        rev = (chip_id & CFG_CHIP_REV) >> 24;
 
-       switch(par->pci_id) {
+       switch (par->pci_id) {
 #ifdef CONFIG_FB_ATY_GX
        case PCI_CHIP_MACH64GX:
-               if(type != 0x00d7)
+               if (type != 0x00d7)
                        return -ENODEV;
                break;
        case PCI_CHIP_MACH64CX:
-               if(type != 0x0057)
+               if (type != 0x0057)
                        return -ENODEV;
                break;
 #endif
@@ -536,12 +545,11 @@ static char ram_edo[] __devinitdata = "EDO";
 static char ram_sdram[] __devinitdata = "SDRAM (1:1)";
 static char ram_sgram[] __devinitdata = "SGRAM (1:1)";
 static char ram_sdram32[] __devinitdata = "SDRAM (2:1) (32-bit)";
+static char ram_wram[] __devinitdata = "WRAM";
 static char ram_off[] __devinitdata = "OFF";
 #endif /* CONFIG_FB_ATY_CT */
 
 
-static u32 pseudo_palette[17];
-
 #ifdef CONFIG_FB_ATY_GX
 static char *aty_gx_ram[8] __devinitdata = {
        ram_dram, ram_vram, ram_vram, ram_dram,
@@ -552,11 +560,16 @@ static char *aty_gx_ram[8] __devinitdata = {
 #ifdef CONFIG_FB_ATY_CT
 static char *aty_ct_ram[8] __devinitdata = {
        ram_off, ram_dram, ram_edo, ram_edo,
+       ram_sdram, ram_sgram, ram_wram, ram_resv
+};
+static char *aty_xl_ram[8] __devinitdata = {
+       ram_off, ram_dram, ram_edo, ram_edo,
        ram_sdram, ram_sgram, ram_sdram32, ram_resv
 };
 #endif /* CONFIG_FB_ATY_CT */
 
-static u32 atyfb_get_pixclock(struct fb_var_screeninfo *var, struct atyfb_par *par)
+static u32 atyfb_get_pixclock(struct fb_var_screeninfo *var,
+                             struct atyfb_par *par)
 {
        u32 pixclock = var->pixclock;
 #ifdef CONFIG_FB_ATY_GENERIC_LCD
@@ -564,7 +577,7 @@ static u32 atyfb_get_pixclock(struct fb_var_screeninfo *var, struct atyfb_par *p
        par->pll.ct.xres = 0;
        if (par->lcd_table != 0) {
                lcd_on_off = aty_ld_lcd(LCD_GEN_CNTL, par);
-               if(lcd_on_off & LCD_ON) {
+               if (lcd_on_off & LCD_ON) {
                        par->pll.ct.xres = var->xres;
                        pixclock = par->lcd_pixclock;
                }
@@ -576,7 +589,7 @@ static u32 atyfb_get_pixclock(struct fb_var_screeninfo *var, struct atyfb_par *p
 #if defined(CONFIG_PPC)
 
 /*
- *  Apple monitor sense
+ * Apple monitor sense
  */
 
 static int __devinit read_aty_sense(const struct atyfb_par *par)
@@ -617,24 +630,24 @@ static int __devinit read_aty_sense(const struct atyfb_par *par)
 /* ------------------------------------------------------------------------- */
 
 /*
- *  CRTC programming
+ * CRTC programming
  */
 
 static void aty_get_crtc(const struct atyfb_par *par, struct crtc *crtc)
 {
 #ifdef CONFIG_FB_ATY_GENERIC_LCD
        if (par->lcd_table != 0) {
-               if(!M64_HAS(LT_LCD_REGS)) {
-                   crtc->lcd_index = aty_ld_le32(LCD_INDEX, par);
-                   aty_st_le32(LCD_INDEX, crtc->lcd_index, par);
+               if (!M64_HAS(LT_LCD_REGS)) {
+                       crtc->lcd_index = aty_ld_le32(LCD_INDEX, par);
+                       aty_st_le32(LCD_INDEX, crtc->lcd_index, par);
                }
-               crtc->lcd_config_panel = aty_ld_lcd(CONFIG_PANEL, par);
+               crtc->lcd_config_panel = aty_ld_lcd(CNFG_PANEL, par);
                crtc->lcd_gen_cntl = aty_ld_lcd(LCD_GEN_CNTL, par);
 
 
                /* switch to non shadow registers */
                aty_st_lcd(LCD_GEN_CNTL, crtc->lcd_gen_cntl &
-                    ~(CRTC_RW_SELECT | SHADOW_EN | SHADOW_RW_EN), par);
+                          ~(CRTC_RW_SELECT | SHADOW_EN | SHADOW_RW_EN), par);
 
                /* save stretching */
                crtc->horz_stretching = aty_ld_lcd(HORZ_STRETCHING, par);
@@ -655,7 +668,7 @@ static void aty_get_crtc(const struct atyfb_par *par, struct crtc *crtc)
        if (par->lcd_table != 0) {
                /* switch to shadow registers */
                aty_st_lcd(LCD_GEN_CNTL, (crtc->lcd_gen_cntl & ~CRTC_RW_SELECT) |
-                       SHADOW_EN | SHADOW_RW_EN, par);
+                          SHADOW_EN | SHADOW_RW_EN, par);
 
                crtc->shadow_h_tot_disp = aty_ld_le32(CRTC_H_TOTAL_DISP, par);
                crtc->shadow_h_sync_strt_wid = aty_ld_le32(CRTC_H_SYNC_STRT_WID, par);
@@ -672,21 +685,20 @@ static void aty_set_crtc(const struct atyfb_par *par, const struct crtc *crtc)
 #ifdef CONFIG_FB_ATY_GENERIC_LCD
        if (par->lcd_table != 0) {
                /* stop CRTC */
-               aty_st_le32(CRTC_GEN_CNTL, crtc->gen_cntl & ~(CRTC_EXT_DISP_EN | CRTC_EN), par);
+               aty_st_le32(CRTC_GEN_CNTL, crtc->gen_cntl &
+                           ~(CRTC_EXT_DISP_EN | CRTC_EN), par);
 
                /* update non-shadow registers first */
-               aty_st_lcd(CONFIG_PANEL, crtc->lcd_config_panel, par);
+               aty_st_lcd(CNFG_PANEL, crtc->lcd_config_panel, par);
                aty_st_lcd(LCD_GEN_CNTL, crtc->lcd_gen_cntl &
-                       ~(CRTC_RW_SELECT | SHADOW_EN | SHADOW_RW_EN), par);
+                          ~(CRTC_RW_SELECT | SHADOW_EN | SHADOW_RW_EN), par);
 
                /* temporarily disable stretching */
-               aty_st_lcd(HORZ_STRETCHING,
-                       crtc->horz_stretching &
-                       ~(HORZ_STRETCH_MODE | HORZ_STRETCH_EN), par);
-               aty_st_lcd(VERT_STRETCHING,
-                       crtc->vert_stretching &
-                       ~(VERT_STRETCH_RATIO1 | VERT_STRETCH_RATIO2 |
-                       VERT_STRETCH_USE0 | VERT_STRETCH_EN), par);
+               aty_st_lcd(HORZ_STRETCHING, crtc->horz_stretching &
+                          ~(HORZ_STRETCH_MODE | HORZ_STRETCH_EN), par);
+               aty_st_lcd(VERT_STRETCHING, crtc->vert_stretching &
+                          ~(VERT_STRETCH_RATIO1 | VERT_STRETCH_RATIO2 |
+                            VERT_STRETCH_USE0 | VERT_STRETCH_EN), par);
        }
 #endif
        /* turn off CRT */
@@ -694,17 +706,19 @@ static void aty_set_crtc(const struct atyfb_par *par, const struct crtc *crtc)
 
        DPRINTK("setting up CRTC\n");
        DPRINTK("set primary CRT to %ix%i %c%c composite %c\n",
-           ((((crtc->h_tot_disp>>16) & 0xff) + 1)<<3), (((crtc->v_tot_disp>>16) & 0x7ff) + 1),
-           (crtc->h_sync_strt_wid & 0x200000)?'N':'P', (crtc->v_sync_strt_wid & 0x200000)?'N':'P',
-           (crtc->gen_cntl & CRTC_CSYNC_EN)?'P':'N');
-
-       DPRINTK("CRTC_H_TOTAL_DISP: %x\n",crtc->h_tot_disp);
-       DPRINTK("CRTC_H_SYNC_STRT_WID: %x\n",crtc->h_sync_strt_wid);
-       DPRINTK("CRTC_V_TOTAL_DISP: %x\n",crtc->v_tot_disp);
-       DPRINTK("CRTC_V_SYNC_STRT_WID: %x\n",crtc->v_sync_strt_wid);
+               ((((crtc->h_tot_disp >> 16) & 0xff) + 1) << 3),
+               (((crtc->v_tot_disp >> 16) & 0x7ff) + 1),
+               (crtc->h_sync_strt_wid & 0x200000) ? 'N' : 'P',
+               (crtc->v_sync_strt_wid & 0x200000) ? 'N' : 'P',
+               (crtc->gen_cntl & CRTC_CSYNC_EN) ? 'P' : 'N');
+
+       DPRINTK("CRTC_H_TOTAL_DISP: %x\n", crtc->h_tot_disp);
+       DPRINTK("CRTC_H_SYNC_STRT_WID: %x\n", crtc->h_sync_strt_wid);
+       DPRINTK("CRTC_V_TOTAL_DISP: %x\n", crtc->v_tot_disp);
+       DPRINTK("CRTC_V_SYNC_STRT_WID: %x\n", crtc->v_sync_strt_wid);
        DPRINTK("CRTC_OFF_PITCH: %x\n", crtc->off_pitch);
        DPRINTK("CRTC_VLINE_CRNT_VLINE: %x\n", crtc->vline_crnt_vline);
-       DPRINTK("CRTC_GEN_CNTL: %x\n",crtc->gen_cntl);
+       DPRINTK("CRTC_GEN_CNTL: %x\n", crtc->gen_cntl);
 
        aty_st_le32(CRTC_H_TOTAL_DISP, crtc->h_tot_disp, par);
        aty_st_le32(CRTC_H_SYNC_STRT_WID, crtc->h_sync_strt_wid, par);
@@ -724,16 +738,22 @@ static void aty_set_crtc(const struct atyfb_par *par, const struct crtc *crtc)
        if (par->lcd_table != 0) {
                /* switch to shadow registers */
                aty_st_lcd(LCD_GEN_CNTL, (crtc->lcd_gen_cntl & ~CRTC_RW_SELECT) |
-                       (SHADOW_EN | SHADOW_RW_EN), par);
+                          SHADOW_EN | SHADOW_RW_EN, par);
 
                DPRINTK("set shadow CRT to %ix%i %c%c\n",
-                   ((((crtc->shadow_h_tot_disp>>16) & 0xff) + 1)<<3), (((crtc->shadow_v_tot_disp>>16) & 0x7ff) + 1),
-                   (crtc->shadow_h_sync_strt_wid & 0x200000)?'N':'P', (crtc->shadow_v_sync_strt_wid & 0x200000)?'N':'P');
-
-               DPRINTK("SHADOW CRTC_H_TOTAL_DISP: %x\n", crtc->shadow_h_tot_disp);
-               DPRINTK("SHADOW CRTC_H_SYNC_STRT_WID: %x\n", crtc->shadow_h_sync_strt_wid);
-               DPRINTK("SHADOW CRTC_V_TOTAL_DISP: %x\n", crtc->shadow_v_tot_disp);
-               DPRINTK("SHADOW CRTC_V_SYNC_STRT_WID: %x\n", crtc->shadow_v_sync_strt_wid);
+                       ((((crtc->shadow_h_tot_disp >> 16) & 0xff) + 1) << 3),
+                       (((crtc->shadow_v_tot_disp >> 16) & 0x7ff) + 1),
+                       (crtc->shadow_h_sync_strt_wid & 0x200000) ? 'N' : 'P',
+                       (crtc->shadow_v_sync_strt_wid & 0x200000) ? 'N' : 'P');
+
+               DPRINTK("SHADOW CRTC_H_TOTAL_DISP: %x\n",
+                       crtc->shadow_h_tot_disp);
+               DPRINTK("SHADOW CRTC_H_SYNC_STRT_WID: %x\n",
+                       crtc->shadow_h_sync_strt_wid);
+               DPRINTK("SHADOW CRTC_V_TOTAL_DISP: %x\n",
+                       crtc->shadow_v_tot_disp);
+               DPRINTK("SHADOW CRTC_V_SYNC_STRT_WID: %x\n",
+                       crtc->shadow_v_sync_strt_wid);
 
                aty_st_le32(CRTC_H_TOTAL_DISP, crtc->shadow_h_tot_disp, par);
                aty_st_le32(CRTC_H_SYNC_STRT_WID, crtc->shadow_h_sync_strt_wid, par);
@@ -744,23 +764,35 @@ static void aty_set_crtc(const struct atyfb_par *par, const struct crtc *crtc)
                DPRINTK("LCD_GEN_CNTL: %x\n", crtc->lcd_gen_cntl);
                DPRINTK("HORZ_STRETCHING: %x\n", crtc->horz_stretching);
                DPRINTK("VERT_STRETCHING: %x\n", crtc->vert_stretching);
-               if(!M64_HAS(LT_LCD_REGS))
-                   DPRINTK("EXT_VERT_STRETCH: %x\n", crtc->ext_vert_stretch);
+               if (!M64_HAS(LT_LCD_REGS))
+                       DPRINTK("EXT_VERT_STRETCH: %x\n", crtc->ext_vert_stretch);
 
                aty_st_lcd(LCD_GEN_CNTL, crtc->lcd_gen_cntl, par);
                aty_st_lcd(HORZ_STRETCHING, crtc->horz_stretching, par);
                aty_st_lcd(VERT_STRETCHING, crtc->vert_stretching, par);
-               if(!M64_HAS(LT_LCD_REGS)) {
-                   aty_st_lcd(EXT_VERT_STRETCH, crtc->ext_vert_stretch, par);
-                   aty_ld_le32(LCD_INDEX, par);
-                   aty_st_le32(LCD_INDEX, crtc->lcd_index, par);
+               if (!M64_HAS(LT_LCD_REGS)) {
+                       aty_st_lcd(EXT_VERT_STRETCH, crtc->ext_vert_stretch, par);
+                       aty_ld_le32(LCD_INDEX, par);
+                       aty_st_le32(LCD_INDEX, crtc->lcd_index, par);
                }
        }
 #endif /* CONFIG_FB_ATY_GENERIC_LCD */
 }
 
+static u32 calc_line_length(struct atyfb_par *par, u32 vxres, u32 bpp)
+{
+       u32 line_length = vxres * bpp / 8;
+
+       if (par->ram_type == SGRAM ||
+           (!M64_HAS(XL_MEM) && par->ram_type == WRAM))
+               line_length = (line_length + 63) & ~63;
+
+       return line_length;
+}
+
 static int aty_var_to_crtc(const struct fb_info *info,
-       const struct fb_var_screeninfo *var, struct crtc *crtc)
+                          const struct fb_var_screeninfo *var,
+                          struct crtc *crtc)
 {
        struct atyfb_par *par = (struct atyfb_par *) info->par;
        u32 xres, yres, vxres, vyres, xoffset, yoffset, bpp;
@@ -768,13 +800,14 @@ static int aty_var_to_crtc(const struct fb_info *info,
        u32 h_total, h_disp, h_sync_strt, h_sync_end, h_sync_dly, h_sync_wid, h_sync_pol;
        u32 v_total, v_disp, v_sync_strt, v_sync_end, v_sync_wid, v_sync_pol, c_sync;
        u32 pix_width, dp_pix_width, dp_chain_mask;
+       u32 line_length;
 
        /* input */
-       xres = var->xres;
+       xres = (var->xres + 7) & ~7;
        yres = var->yres;
-       vxres = var->xres_virtual;
+       vxres = (var->xres_virtual + 7) & ~7;
        vyres = var->yres_virtual;
-       xoffset = var->xoffset;
+       xoffset = (var->xoffset + 7) & ~7;
        yoffset = var->yoffset;
        bpp = var->bits_per_pixel;
        if (bpp == 16)
@@ -794,47 +827,47 @@ static int aty_var_to_crtc(const struct fb_info *info,
        if (bpp <= 8) {
                bpp = 8;
                pix_width = CRTC_PIX_WIDTH_8BPP;
-               dp_pix_width =
-                   HOST_8BPP | SRC_8BPP | DST_8BPP |
-                   BYTE_ORDER_LSB_TO_MSB;
+               dp_pix_width = HOST_8BPP | SRC_8BPP | DST_8BPP |
+                       BYTE_ORDER_LSB_TO_MSB;
                dp_chain_mask = DP_CHAIN_8BPP;
        } else if (bpp <= 15) {
                bpp = 16;
                pix_width = CRTC_PIX_WIDTH_15BPP;
                dp_pix_width = HOST_15BPP | SRC_15BPP | DST_15BPP |
-                   BYTE_ORDER_LSB_TO_MSB;
+                       BYTE_ORDER_LSB_TO_MSB;
                dp_chain_mask = DP_CHAIN_15BPP;
        } else if (bpp <= 16) {
                bpp = 16;
                pix_width = CRTC_PIX_WIDTH_16BPP;
                dp_pix_width = HOST_16BPP | SRC_16BPP | DST_16BPP |
-                   BYTE_ORDER_LSB_TO_MSB;
+                       BYTE_ORDER_LSB_TO_MSB;
                dp_chain_mask = DP_CHAIN_16BPP;
        } else if (bpp <= 24 && M64_HAS(INTEGRATED)) {
                bpp = 24;
                pix_width = CRTC_PIX_WIDTH_24BPP;
-               dp_pix_width =
-                   HOST_8BPP | SRC_8BPP | DST_8BPP |
-                   BYTE_ORDER_LSB_TO_MSB;
+               dp_pix_width = HOST_8BPP | SRC_8BPP | DST_8BPP |
+                       BYTE_ORDER_LSB_TO_MSB;
                dp_chain_mask = DP_CHAIN_24BPP;
        } else if (bpp <= 32) {
                bpp = 32;
                pix_width = CRTC_PIX_WIDTH_32BPP;
                dp_pix_width = HOST_32BPP | SRC_32BPP | DST_32BPP |
-                   BYTE_ORDER_LSB_TO_MSB;
+                       BYTE_ORDER_LSB_TO_MSB;
                dp_chain_mask = DP_CHAIN_32BPP;
        } else
                FAIL("invalid bpp");
 
-       if (vxres * vyres * bpp / 8 > info->fix.smem_len)
+       line_length = calc_line_length(par, vxres, bpp);
+
+       if (vyres * line_length > info->fix.smem_len)
                FAIL("not enough video RAM");
 
        h_sync_pol = sync & FB_SYNC_HOR_HIGH_ACT ? 0 : 1;
        v_sync_pol = sync & FB_SYNC_VERT_HIGH_ACT ? 0 : 1;
 
-       if((xres > 1600) || (yres > 1200)) {
+       if ((xres > 1600) || (yres > 1200)) {
                FAIL("MACH64 chips are designed for max 1600x1200\n"
-               "select anoter resolution.");
+                    "select anoter resolution.");
        }
        h_sync_strt = h_disp + var->right_margin;
        h_sync_end = h_sync_strt + var->hsync_len;
@@ -847,17 +880,18 @@ static int aty_var_to_crtc(const struct fb_info *info,
 
 #ifdef CONFIG_FB_ATY_GENERIC_LCD
        if (par->lcd_table != 0) {
-               if(!M64_HAS(LT_LCD_REGS)) {
-                   u32 lcd_index = aty_ld_le32(LCD_INDEX, par);
-                   crtc->lcd_index = lcd_index &
-                       ~(LCD_INDEX_MASK | LCD_DISPLAY_DIS | LCD_SRC_SEL | CRTC2_DISPLAY_DIS);
-                   aty_st_le32(LCD_INDEX, lcd_index, par);
+               if (!M64_HAS(LT_LCD_REGS)) {
+                       u32 lcd_index = aty_ld_le32(LCD_INDEX, par);
+                       crtc->lcd_index = lcd_index &
+                               ~(LCD_INDEX_MASK | LCD_DISPLAY_DIS |
+                                 LCD_SRC_SEL | CRTC2_DISPLAY_DIS);
+                       aty_st_le32(LCD_INDEX, lcd_index, par);
                }
 
                if (!M64_HAS(MOBIL_BUS))
                        crtc->lcd_index |= CRTC2_DISPLAY_DIS;
 
-               crtc->lcd_config_panel = aty_ld_lcd(CONFIG_PANEL, par) | 0x4000;
+               crtc->lcd_config_panel = aty_ld_lcd(CNFG_PANEL, par) | 0x4000;
                crtc->lcd_gen_cntl = aty_ld_lcd(LCD_GEN_CNTL, par) & ~CRTC_RW_SELECT;
 
                crtc->lcd_gen_cntl &=
@@ -866,12 +900,14 @@ static int aty_var_to_crtc(const struct fb_info *info,
                        USE_SHADOWED_ROWCUR | SHADOW_EN | SHADOW_RW_EN);
                crtc->lcd_gen_cntl |= DONT_SHADOW_VPAR | LOCK_8DOT;
 
-               if((crtc->lcd_gen_cntl & LCD_ON) &&
-                       ((xres > par->lcd_width) || (yres > par->lcd_height))) {
-                       /* We cannot display the mode on the LCD. If the CRT is enabled
-                          we can turn off the LCD.
-                          If the CRT is off, it isn't a good idea to switch it on; we don't
-                          know if one is connected. So it's better to fail then.
+               if ((crtc->lcd_gen_cntl & LCD_ON) &&
+                   ((xres > par->lcd_width) || (yres > par->lcd_height))) {
+                       /*
+                        * We cannot display the mode on the LCD. If the CRT is
+                        * enabled we can turn off the LCD.
+                        * If the CRT is off, it isn't a good idea to switch it
+                        * on; we don't know if one is connected. So it's better
+                        * to fail then.
                         */
                        if (crtc->lcd_gen_cntl & CRT_ON) {
                                if (!(var->activate & FB_ACTIVATE_TEST))
@@ -894,17 +930,18 @@ static int aty_var_to_crtc(const struct fb_info *info,
 
                vmode &= ~(FB_VMODE_DOUBLE | FB_VMODE_INTERLACED);
 
-               /* This is horror! When we simulate, say 640x480 on an 800x600
-                  LCD monitor, the CRTC should be programmed 800x600 values for
-                  the non visible part, but 640x480 for the visible part.
-                  This code has been tested on a laptop with it's 1400x1050 LCD
-                  monitor and a conventional monitor both switched on.
-                  Tested modes: 1280x1024, 1152x864, 1024x768, 800x600,
-                   works with little glitches also with DOUBLESCAN modes
+               /*
+                * This is horror! When we simulate, say 640x480 on an 800x600
+                * LCD monitor, the CRTC should be programmed 800x600 values for
+                * the non visible part, but 640x480 for the visible part.
+                * This code has been tested on a laptop with it's 1400x1050 LCD
+                * monitor and a conventional monitor both switched on.
+                * Tested modes: 1280x1024, 1152x864, 1024x768, 800x600,
+                * works with little glitches also with DOUBLESCAN modes
                 */
                if (yres < par->lcd_height) {
                        VScan = par->lcd_height / yres;
-                       if(VScan > 1) {
+                       if (VScan > 1) {
                                VScan = 2;
                                vmode |= FB_VMODE_DOUBLE;
                        }
@@ -930,7 +967,7 @@ static int aty_var_to_crtc(const struct fb_info *info,
        FAIL_MAX("h_disp too large", h_disp, 0xff);
        FAIL_MAX("h_sync_strt too large", h_sync_strt, 0x1ff);
        /*FAIL_MAX("h_sync_wid too large", h_sync_wid, 0x1f);*/
-       if(h_sync_wid > 0x1f)
+       if (h_sync_wid > 0x1f)
                h_sync_wid = 0x1f;
        FAIL_MAX("h_total too large", h_total, 0x1ff);
 
@@ -956,7 +993,7 @@ static int aty_var_to_crtc(const struct fb_info *info,
        FAIL_MAX("v_disp too large", v_disp, 0x7ff);
        FAIL_MAX("v_sync_stsrt too large", v_sync_strt, 0x7ff);
        /*FAIL_MAX("v_sync_wid too large", v_sync_wid, 0x1f);*/
-       if(v_sync_wid > 0x1f)
+       if (v_sync_wid > 0x1f)
                v_sync_wid = 0x1f;
        FAIL_MAX("v_total too large", v_total, 0x7ff);
 
@@ -968,14 +1005,18 @@ static int aty_var_to_crtc(const struct fb_info *info,
        crtc->xoffset = xoffset;
        crtc->yoffset = yoffset;
        crtc->bpp = bpp;
-       crtc->off_pitch = ((yoffset*vxres+xoffset)*bpp/64) | (vxres<<19);
+       crtc->off_pitch =
+               ((yoffset * line_length + xoffset * bpp / 8) / 8) |
+               ((line_length / bpp) << 22);
        crtc->vline_crnt_vline = 0;
 
-       crtc->h_tot_disp = h_total | (h_disp<<16);
-       crtc->h_sync_strt_wid = (h_sync_strt & 0xff) | (h_sync_dly<<8) |
-               ((h_sync_strt & 0x100)<<4) | (h_sync_wid<<16) | (h_sync_pol<<21);
-       crtc->v_tot_disp = v_total | (v_disp<<16);
-       crtc->v_sync_strt_wid = v_sync_strt | (v_sync_wid<<16) | (v_sync_pol<<21);
+       crtc->h_tot_disp = h_total | (h_disp << 16);
+       crtc->h_sync_strt_wid = (h_sync_strt & 0xff) | (h_sync_dly << 8) |
+               ((h_sync_strt & 0x100) << 4) | (h_sync_wid << 16) |
+               (h_sync_pol << 21);
+       crtc->v_tot_disp = v_total | (v_disp << 16);
+       crtc->v_sync_strt_wid = v_sync_strt | (v_sync_wid << 16) |
+               (v_sync_pol << 21);
 
        /* crtc->gen_cntl = aty_ld_le32(CRTC_GEN_CNTL, par) & CRTC_PRESERVED_MASK; */
        crtc->gen_cntl = CRTC_EXT_DISP_EN | CRTC_EN | pix_width | c_sync;
@@ -990,13 +1031,15 @@ static int aty_var_to_crtc(const struct fb_info *info,
 #ifdef CONFIG_FB_ATY_GENERIC_LCD
        if (par->lcd_table != 0) {
                vdisplay = yres;
-               if(vmode & FB_VMODE_DOUBLE)
+               if (vmode & FB_VMODE_DOUBLE)
                        vdisplay <<= 1;
                crtc->gen_cntl &= ~(CRTC2_EN | CRTC2_PIX_WIDTH);
                crtc->lcd_gen_cntl &= ~(HORZ_DIVBY2_EN | DIS_HOR_CRT_DIVBY2 |
-                       /*TVCLK_PM_EN | VCLK_DAC_PM_EN |*/
-                       USE_SHADOWED_VEND | USE_SHADOWED_ROWCUR | SHADOW_EN | SHADOW_RW_EN);
-               crtc->lcd_gen_cntl |= (DONT_SHADOW_VPAR/* | LOCK_8DOT*/);
+                                       /*TVCLK_PM_EN | VCLK_DAC_PM_EN |*/
+                                       USE_SHADOWED_VEND |
+                                       USE_SHADOWED_ROWCUR |
+                                       SHADOW_EN | SHADOW_RW_EN);
+               crtc->lcd_gen_cntl |= DONT_SHADOW_VPAR/* | LOCK_8DOT*/;
 
                /* MOBILITY M1 tested, FIXME: LT */
                crtc->horz_stretching = aty_ld_lcd(HORZ_STRETCHING, par);
@@ -1004,28 +1047,32 @@ static int aty_var_to_crtc(const struct fb_info *info,
                        crtc->ext_vert_stretch = aty_ld_lcd(EXT_VERT_STRETCH, par) &
                                ~(AUTO_VERT_RATIO | VERT_STRETCH_MODE | VERT_STRETCH_RATIO3);
 
-               crtc->horz_stretching &=
-                       ~(HORZ_STRETCH_RATIO | HORZ_STRETCH_LOOP | AUTO_HORZ_RATIO |
-                       HORZ_STRETCH_MODE | HORZ_STRETCH_EN);
+               crtc->horz_stretching &= ~(HORZ_STRETCH_RATIO |
+                                          HORZ_STRETCH_LOOP | AUTO_HORZ_RATIO |
+                                          HORZ_STRETCH_MODE | HORZ_STRETCH_EN);
                if (xres < par->lcd_width && crtc->lcd_gen_cntl & LCD_ON) {
                        do {
                                /*
-                               * The horizontal blender misbehaves when HDisplay is less than a
-                               * a certain threshold (440 for a 1024-wide panel).  It doesn't
-                               * stretch such modes enough.  Use pixel replication instead of
-                               * blending to stretch modes that can be made to exactly fit the
-                               * panel width.  The undocumented "NoLCDBlend" option allows the
-                               * pixel-replicated mode to be slightly wider or narrower than the
-                               * panel width.  It also causes a mode that is exactly half as wide
-                               * as the panel to be pixel-replicated, rather than blended.
-                               */
+                                * The horizontal blender misbehaves when
+                                * HDisplay is less than a certain threshold
+                                * (440 for a 1024-wide panel).  It doesn't
+                                * stretch such modes enough.  Use pixel
+                                * replication instead of blending to stretch
+                                * modes that can be made to exactly fit the
+                                * panel width.  The undocumented "NoLCDBlend"
+                                * option allows the pixel-replicated mode to
+                                * be slightly wider or narrower than the
+                                * panel width.  It also causes a mode that is
+                                * exactly half as wide as the panel to be
+                                * pixel-replicated, rather than blended.
+                                */
                                int HDisplay  = xres & ~7;
                                int nStretch  = par->lcd_width / HDisplay;
                                int Remainder = par->lcd_width % HDisplay;
 
                                if ((!Remainder && ((nStretch > 2))) ||
-                                       (((HDisplay * 16) / par->lcd_width) < 7)) {
-                                       static const char StretchLoops[] = {10, 12, 13, 15, 16};
+                                   (((HDisplay * 16) / par->lcd_width) < 7)) {
+                                       static const char StretchLoops[] = { 10, 12, 13, 15, 16 };
                                        int horz_stretch_loop = -1, BestRemainder;
                                        int Numerator = HDisplay, Denominator = par->lcd_width;
                                        int Index = 5;
@@ -1074,12 +1121,12 @@ static int aty_var_to_crtc(const struct fb_info *info,
                                (((vdisplay * (VERT_STRETCH_RATIO0 + 1)) / par->lcd_height) & VERT_STRETCH_RATIO0));
 
                        if (!M64_HAS(LT_LCD_REGS) &&
-                           xres <= (M64_HAS(MOBIL_BUS)?1024:800))
+                           xres <= (M64_HAS(MOBIL_BUS) ? 1024 : 800))
                                crtc->ext_vert_stretch |= VERT_STRETCH_MODE;
                } else {
                        /*
-                        * Don't use vertical blending if the mode is too wide or not
-                        * vertically stretched.
+                        * Don't use vertical blending if the mode is too wide
+                        * or not vertically stretched.
                         */
                        crtc->vert_stretching = 0;
                }
@@ -1101,11 +1148,11 @@ static int aty_var_to_crtc(const struct fb_info *info,
        return 0;
 }
 
-static int aty_crtc_to_var(const struct crtc *crtc, struct fb_var_screeninfo *var)
+static int aty_crtc_to_var(const struct crtc *crtc,
+                          struct fb_var_screeninfo *var)
 {
        u32 xres, yres, bpp, left, right, upper, lower, hslen, vslen, sync;
-       u32 h_total, h_disp, h_sync_strt, h_sync_dly, h_sync_wid,
-           h_sync_pol;
+       u32 h_total, h_disp, h_sync_strt, h_sync_dly, h_sync_wid, h_sync_pol;
        u32 v_total, v_disp, v_sync_strt, v_sync_wid, v_sync_pol, c_sync;
        u32 pix_width;
        u32 double_scan, interlace;
@@ -1137,8 +1184,8 @@ static int aty_crtc_to_var(const struct crtc *crtc, struct fb_var_screeninfo *va
        lower = v_sync_strt - v_disp;
        vslen = v_sync_wid;
        sync = (h_sync_pol ? 0 : FB_SYNC_HOR_HIGH_ACT) |
-           (v_sync_pol ? 0 : FB_SYNC_VERT_HIGH_ACT) |
-           (c_sync ? FB_SYNC_COMP_HIGH_ACT : 0);
+               (v_sync_pol ? 0 : FB_SYNC_VERT_HIGH_ACT) |
+               (c_sync ? FB_SYNC_COMP_HIGH_ACT : 0);
 
        switch (pix_width) {
 #if 0
@@ -1228,20 +1275,21 @@ static int aty_crtc_to_var(const struct crtc *crtc, struct fb_var_screeninfo *va
        var->vsync_len = vslen;
        var->sync = sync;
        var->vmode = FB_VMODE_NONINTERLACED;
-       /* In double scan mode, the vertical parameters are doubled, so we need to
-          half them to get the right values.
-          In interlaced mode the values are already correct, so no correction is
-          necessary.
+       /*
+        * In double scan mode, the vertical parameters are doubled,
+        * so we need to halve them to get the right values.
+        * In interlaced mode the values are already correct,
+        * so no correction is necessary.
         */
        if (interlace)
                var->vmode = FB_VMODE_INTERLACED;
 
        if (double_scan) {
                var->vmode = FB_VMODE_DOUBLE;
-               var->yres>>=1;
-               var->upper_margin>>=1;
-               var->lower_margin>>=1;
-               var->vsync_len>>=1;
+               var->yres >>= 1;
+               var->upper_margin >>= 1;
+               var->lower_margin >>= 1;
+               var->vsync_len >>= 1;
        }
 
        return 0;
@@ -1262,7 +1310,8 @@ static int atyfb_set_par(struct fb_info *info)
        if (par->asleep)
                return 0;
 
-       if ((err = aty_var_to_crtc(info, var, &par->crtc)))
+       err = aty_var_to_crtc(info, var, &par->crtc);
+       if (err)
                return err;
 
        pixclock = atyfb_get_pixclock(var, par);
@@ -1271,7 +1320,9 @@ static int atyfb_set_par(struct fb_info *info)
                PRINTKE("Invalid pixclock\n");
                return -EINVAL;
        } else {
-               if((err = par->pll_ops->var_to_pll(info, pixclock, var->bits_per_pixel, &par->pll)))
+               err = par->pll_ops->var_to_pll(info, pixclock,
+                                              var->bits_per_pixel, &par->pll);
+               if (err)
                        return err;
        }
 
@@ -1289,22 +1340,23 @@ static int atyfb_set_par(struct fb_info *info)
                wait_for_idle(par);
 
        aty_set_crtc(par, &par->crtc);
-       par->dac_ops->set_dac(info, &par->pll, var->bits_per_pixel, par->accel_flags);
+       par->dac_ops->set_dac(info, &par->pll,
+                             var->bits_per_pixel, par->accel_flags);
        par->pll_ops->set_pll(info, &par->pll);
 
 #ifdef DEBUG
-       if(par->pll_ops && par->pll_ops->pll_to_var)
-               pixclock_in_ps = par->pll_ops->pll_to_var(info, &(par->pll));
+       if (par->pll_ops && par->pll_ops->pll_to_var)
+               pixclock_in_ps = par->pll_ops->pll_to_var(info, &par->pll);
        else
                pixclock_in_ps = 0;
 
-       if(0 == pixclock_in_ps) {
+       if (0 == pixclock_in_ps) {
                PRINTKE("ALERT ops->pll_to_var get 0\n");
                pixclock_in_ps = pixclock;
        }
 
        memset(&debug, 0, sizeof(debug));
-       if(!aty_crtc_to_var(&(par->crtc), &debug)) {
+       if (!aty_crtc_to_var(&par->crtc, &debug)) {
                u32 hSync, vRefresh;
                u32 h_disp, h_sync_strt, h_sync_end, h_total;
                u32 v_disp, v_sync_strt, v_sync_end, v_total;
@@ -1320,16 +1372,20 @@ static int atyfb_set_par(struct fb_info *info)
 
                hSync = 1000000000 / (pixclock_in_ps * h_total);
                vRefresh = (hSync * 1000) / v_total;
-               if (par->crtc.gen_cntl & CRTC_INTERLACE_EN)
-               vRefresh *= 2;
-               if (par->crtc.gen_cntl & CRTC_DBL_SCAN_EN)
-               vRefresh /= 2;
+               if (par->crtc.gen_cntl & CRTC_INTERLACE_EN)
+                       vRefresh *= 2;
+               if (par->crtc.gen_cntl & CRTC_DBL_SCAN_EN)
+                       vRefresh /= 2;
 
                DPRINTK("atyfb_set_par\n");
-               DPRINTK(" Set Visible Mode to %ix%i-%i\n", var->xres, var->yres, var->bits_per_pixel);
-               DPRINTK(" Virtual resolution %ix%i, pixclock_in_ps %i (calculated %i)\n",
-                       var->xres_virtual, var->yres_virtual, pixclock, pixclock_in_ps);
-               DPRINTK(" Dot clock:           %i MHz\n", 1000000 / pixclock_in_ps);
+               DPRINTK(" Set Visible Mode to %ix%i-%i\n",
+                       var->xres, var->yres, var->bits_per_pixel);
+               DPRINTK(" Virtual resolution %ix%i, "
+                       "pixclock_in_ps %i (calculated %i)\n",
+                       var->xres_virtual, var->yres_virtual,
+                       pixclock, pixclock_in_ps);
+               DPRINTK(" Dot clock:           %i MHz\n",
+                       1000000 / pixclock_in_ps);
                DPRINTK(" Horizontal sync:     %i kHz\n", hSync);
                DPRINTK(" Vertical refresh:    %i Hz\n", vRefresh);
                DPRINTK(" x  style: %i.%03i %i %i %i %i   %i %i %i %i\n",
@@ -1393,7 +1449,9 @@ static int atyfb_set_par(struct fb_info *info)
        }
        aty_st_8(DAC_MASK, 0xff, par);
 
-       info->fix.line_length = var->xres_virtual * var->bits_per_pixel/8;
+       info->fix.line_length = calc_line_length(par, var->xres_virtual,
+                                                var->bits_per_pixel);
+
        info->fix.visual = var->bits_per_pixel <= 8 ?
                FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_DIRECTCOLOR;
 
@@ -1422,7 +1480,8 @@ static int atyfb_set_par(struct fb_info *info)
        base = 0x2000;
        printk("debug atyfb: Mach64 non-shadow register values:");
        for (i = 0; i < 256; i = i+4) {
-               if(i%16 == 0) printk("\ndebug atyfb: 0x%04X: ", base + i);
+               if (i % 16 == 0)
+                       printk("\ndebug atyfb: 0x%04X: ", base + i);
                printk(" %08X", aty_ld_le32(i, par));
        }
        printk("\n\n");
@@ -1432,8 +1491,10 @@ static int atyfb_set_par(struct fb_info *info)
        base = 0x00;
        printk("debug atyfb: Mach64 PLL register values:");
        for (i = 0; i < 64; i++) {
-               if(i%16 == 0) printk("\ndebug atyfb: 0x%02X: ", base + i);
-               if(i%4 == 0)  printk(" ");
+               if (i % 16 == 0)
+                       printk("\ndebug atyfb: 0x%02X: ", base + i);
+               if (i % 4 == 0)
+                       printk(" ");
                printk("%02X", aty_ld_pll_ct(i, par));
        }
        printk("\n\n");
@@ -1444,19 +1505,21 @@ static int atyfb_set_par(struct fb_info *info)
                /* LCD registers */
                base = 0x00;
                printk("debug atyfb: LCD register values:");
-               if(M64_HAS(LT_LCD_REGS)) {
-                   for(i = 0; i <= POWER_MANAGEMENT; i++) {
-                       if(i == EXT_VERT_STRETCH)
-                           continue;
-                       printk("\ndebug atyfb: 0x%04X: ", lt_lcd_regs[i]);
-                       printk(" %08X", aty_ld_lcd(i, par));
-                   }
-
+               if (M64_HAS(LT_LCD_REGS)) {
+                       for (i = 0; i <= POWER_MANAGEMENT; i++) {
+                               if (i == EXT_VERT_STRETCH)
+                                       continue;
+                               printk("\ndebug atyfb: 0x%04X: ",
+                                      lt_lcd_regs[i]);
+                               printk(" %08X", aty_ld_lcd(i, par));
+                       }
                } else {
-                   for (i = 0; i < 64; i++) {
-                       if(i%4 == 0) printk("\ndebug atyfb: 0x%02X: ", base + i);
-                       printk(" %08X", aty_ld_lcd(i, par));
-                   }
+                       for (i = 0; i < 64; i++) {
+                               if (i % 4 == 0)
+                                       printk("\ndebug atyfb: 0x%02X: ",
+                                              base + i);
+                               printk(" %08X", aty_ld_lcd(i, par));
+                       }
                }
                printk("\n\n");
        }
@@ -1474,9 +1537,10 @@ static int atyfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
        union aty_pll pll;
        u32 pixclock;
 
-       memcpy(&pll, &(par->pll), sizeof(pll));
+       memcpy(&pll, &par->pll, sizeof(pll));
 
-       if((err = aty_var_to_crtc(info, var, &crtc)))
+       err = aty_var_to_crtc(info, var, &crtc);
+       if (err)
                return err;
 
        pixclock = atyfb_get_pixclock(var, par);
@@ -1486,7 +1550,9 @@ static int atyfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
                        PRINTKE("Invalid pixclock\n");
                return -EINVAL;
        } else {
-               if((err = par->pll_ops->var_to_pll(info, pixclock, var->bits_per_pixel, &pll)))
+               err = par->pll_ops->var_to_pll(info, pixclock,
+                                              var->bits_per_pixel, &pll);
+               if (err)
                        return err;
        }
 
@@ -1495,10 +1561,6 @@ static int atyfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
        else
                info->var.accel_flags = 0;
 
-#if 0 /* fbmon is not done. uncomment for 2.5.x -brad */
-       if (!fbmon_valid_timings(pixclock, htotal, vtotal, info))
-               return -EINVAL;
-#endif
        aty_crtc_to_var(&crtc, var);
        var->pixclock = par->pll_ops->pll_to_var(info, &pll);
        return 0;
@@ -1508,16 +1570,18 @@ static void set_off_pitch(struct atyfb_par *par, const struct fb_info *info)
 {
        u32 xoffset = info->var.xoffset;
        u32 yoffset = info->var.yoffset;
-       u32 vxres = par->crtc.vxres;
+       u32 line_length = info->fix.line_length;
        u32 bpp = info->var.bits_per_pixel;
 
-       par->crtc.off_pitch = ((yoffset * vxres + xoffset) * bpp / 64) | (vxres << 19);
+       par->crtc.off_pitch =
+               ((yoffset * line_length + xoffset * bpp / 8) / 8) |
+               ((line_length / bpp) << 22);
 }
 
 
-    /*
    *  Open/Release the frame buffer device
    */
+/*
* Open/Release the frame buffer device
+ */
 
 static int atyfb_open(struct fb_info *info, int user)
 {
@@ -1529,7 +1593,7 @@ static int atyfb_open(struct fb_info *info, int user)
                par->mmaped = 0;
 #endif
        }
-       return (0);
+       return 0;
 }
 
 static irqreturn_t aty_irq(int irq, void *dev_id)
@@ -1544,7 +1608,8 @@ static irqreturn_t aty_irq(int irq, void *dev_id)
 
        if (int_cntl & CRTC_VBLANK_INT) {
                /* clear interrupt */
-               aty_st_le32(CRTC_INT_CNTL, (int_cntl & CRTC_INT_EN_MASK) | CRTC_VBLANK_INT_AK, par);
+               aty_st_le32(CRTC_INT_CNTL, (int_cntl & CRTC_INT_EN_MASK) |
+                           CRTC_VBLANK_INT_AK, par);
                par->vblank.count++;
                if (par->vblank.pan_display) {
                        par->vblank.pan_display = 0;
@@ -1579,9 +1644,11 @@ static int aty_enable_irq(struct atyfb_par *par, int reenable)
                spin_lock_irq(&par->int_lock);
                int_cntl = aty_ld_le32(CRTC_INT_CNTL, par) & CRTC_INT_EN_MASK;
                if (!(int_cntl & CRTC_VBLANK_INT_EN)) {
-                       printk("atyfb: someone disabled IRQ [%08x]\n", int_cntl);
+                       printk("atyfb: someone disabled IRQ [%08x]\n",
+                              int_cntl);
                        /* re-enable interrupt */
-                       aty_st_le32(CRTC_INT_CNTL, int_cntl | CRTC_VBLANK_INT_EN, par );
+                       aty_st_le32(CRTC_INT_CNTL, int_cntl |
+                                   CRTC_VBLANK_INT_EN, par);
                }
                spin_unlock_irq(&par->int_lock);
        }
@@ -1601,7 +1668,7 @@ static int aty_disable_irq(struct atyfb_par *par)
                spin_lock_irq(&par->int_lock);
                int_cntl = aty_ld_le32(CRTC_INT_CNTL, par) & CRTC_INT_EN_MASK;
                /* disable interrupt */
-               aty_st_le32(CRTC_INT_CNTL, int_cntl & ~CRTC_VBLANK_INT_EN, par );
+               aty_st_le32(CRTC_INT_CNTL, int_cntl & ~CRTC_VBLANK_INT_EN, par);
                spin_unlock_irq(&par->int_lock);
                free_irq(par->irq, par);
        }
@@ -1612,50 +1679,62 @@ static int aty_disable_irq(struct atyfb_par *par)
 static int atyfb_release(struct fb_info *info, int user)
 {
        struct atyfb_par *par = (struct atyfb_par *) info->par;
-       if (user) {
-               par->open--;
-               mdelay(1);
-               wait_for_idle(par);
-               if (!par->open) {
 #ifdef __sparc__
-                       int was_mmaped = par->mmaped;
+       int was_mmaped;
+#endif
+
+       if (!user)
+               return 0;
 
-                       par->mmaped = 0;
+       par->open--;
+       mdelay(1);
+       wait_for_idle(par);
 
-                       if (was_mmaped) {
-                               struct fb_var_screeninfo var;
+       if (par->open)
+               return 0;
 
-                               /* Now reset the default display config, we have no
-                                * idea what the program(s) which mmap'd the chip did
-                                * to the configuration, nor whether it restored it
-                                * correctly.
-                                */
-                               var = default_var;
-                               if (noaccel)
-                                       var.accel_flags &= ~FB_ACCELF_TEXT;
-                               else
-                                       var.accel_flags |= FB_ACCELF_TEXT;
-                               if (var.yres == var.yres_virtual) {
-                                       u32 videoram = (info->fix.smem_len - (PAGE_SIZE << 2));
-                                       var.yres_virtual = ((videoram * 8) / var.bits_per_pixel) / var.xres_virtual;
-                                       if (var.yres_virtual < var.yres)
-                                               var.yres_virtual = var.yres;
-                               }
-                       }
-#endif
-                       aty_disable_irq(par);
+#ifdef __sparc__
+       was_mmaped = par->mmaped;
+
+       par->mmaped = 0;
+
+       if (was_mmaped) {
+               struct fb_var_screeninfo var;
+
+               /*
+                * Now reset the default display config, we have
+                * no idea what the program(s) which mmap'd the
+                * chip did to the configuration, nor whether it
+                * restored it correctly.
+                */
+               var = default_var;
+               if (noaccel)
+                       var.accel_flags &= ~FB_ACCELF_TEXT;
+               else
+                       var.accel_flags |= FB_ACCELF_TEXT;
+               if (var.yres == var.yres_virtual) {
+                       u32 videoram = (info->fix.smem_len - (PAGE_SIZE << 2));
+                       var.yres_virtual =
+                               ((videoram * 8) / var.bits_per_pixel) /
+                               var.xres_virtual;
+                       if (var.yres_virtual < var.yres)
+                               var.yres_virtual = var.yres;
                }
        }
-       return (0);
+#endif
+       aty_disable_irq(par);
+
+       return 0;
 }
 
-    /*
    *  Pan or Wrap the Display
    *
    *  This call looks only at xoffset, yoffset and the FB_VMODE_YWRAP flag
    */
+/*
* Pan or Wrap the Display
+ *
* This call looks only at xoffset, yoffset and the FB_VMODE_YWRAP flag
+ */
 
-static int atyfb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
+static int atyfb_pan_display(struct fb_var_screeninfo *var,
+                            struct fb_info *info)
 {
        struct atyfb_par *par = (struct atyfb_par *) info->par;
        u32 xres, yres, xoffset, yoffset;
@@ -1666,7 +1745,8 @@ static int atyfb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info
                yres >>= 1;
        xoffset = (var->xoffset + 7) & ~7;
        yoffset = var->yoffset;
-       if (xoffset + xres > par->crtc.vxres || yoffset + yres > par->crtc.vyres)
+       if (xoffset + xres > par->crtc.vxres ||
+           yoffset + yres > par->crtc.vyres)
                return -EINVAL;
        info->var.xoffset = xoffset;
        info->var.yoffset = yoffset;
@@ -1703,10 +1783,10 @@ static int aty_waitforvblank(struct atyfb_par *par, u32 crtc)
                return ret;
 
        count = vbl->count;
-       ret = wait_event_interruptible_timeout(vbl->wait, count != vbl->count, HZ/10);
-       if (ret < 0) {
+       ret = wait_event_interruptible_timeout(vbl->wait,
+                                              count != vbl->count, HZ/10);
+       if (ret < 0)
                return ret;
-       }
        if (ret == 0) {
                aty_enable_irq(par, 1);
                return -ETIMEDOUT;
@@ -1740,10 +1820,6 @@ struct atyclk {
 #define ATYIO_FEATW            0x41545903      /* ATY\03 */
 #endif
 
-#ifndef FBIO_WAITFORVSYNC
-#define FBIO_WAITFORVSYNC _IOW('F', 0x20, __u32)
-#endif
-
 static int atyfb_ioctl(struct fb_info *info, u_int cmd, u_long arg)
 {
        struct atyfb_par *par = (struct atyfb_par *) info->par;
@@ -1760,7 +1836,8 @@ static int atyfb_ioctl(struct fb_info *info, u_int cmd, u_long arg)
                fbtyp.fb_depth = info->var.bits_per_pixel;
                fbtyp.fb_cmsize = info->cmap.len;
                fbtyp.fb_size = info->fix.smem_len;
-               if (copy_to_user((struct fbtype __user *) arg, &fbtyp, sizeof(fbtyp)))
+               if (copy_to_user((struct fbtype __user *) arg, &fbtyp,
+                                sizeof(fbtyp)))
                        return -EFAULT;
                break;
 #endif /* __sparc__ */
@@ -1780,7 +1857,7 @@ static int atyfb_ioctl(struct fb_info *info, u_int cmd, u_long arg)
        case ATYIO_CLKR:
                if (M64_HAS(INTEGRATED)) {
                        struct atyclk clk;
-                       union aty_pll *pll = &(par->pll);
+                       union aty_pll *pll = &par->pll;
                        u32 dsp_config = pll->ct.dsp_config;
                        u32 dsp_on_off = pll->ct.dsp_on_off;
                        clk.ref_clk_per = par->ref_clk_per;
@@ -1805,8 +1882,9 @@ static int atyfb_ioctl(struct fb_info *info, u_int cmd, u_long arg)
        case ATYIO_CLKW:
                if (M64_HAS(INTEGRATED)) {
                        struct atyclk clk;
-                       union aty_pll *pll = &(par->pll);
-                       if (copy_from_user(&clk, (struct atyclk __user *) arg, sizeof(clk)))
+                       union aty_pll *pll = &par->pll;
+                       if (copy_from_user(&clk, (struct atyclk __user *) arg,
+                                          sizeof(clk)))
                                return -EFAULT;
                        par->ref_clk_per = clk.ref_clk_per;
                        pll->ct.pll_ref_div = clk.pll_ref_div;
@@ -1817,8 +1895,10 @@ static int atyfb_ioctl(struct fb_info *info, u_int cmd, u_long arg)
                        pll->ct.vclk_fb_div = clk.vclk_fb_div;
                        pll->ct.vclk_post_div_real = clk.vclk_post_div;
                        pll->ct.dsp_config = (clk.dsp_xclks_per_row & 0x3fff) |
-                               ((clk.dsp_loop_latency & 0xf)<<16)| ((clk.dsp_precision & 7)<<20);
-                       pll->ct.dsp_on_off = (clk.dsp_off & 0x7ff) | ((clk.dsp_on & 0x7ff)<<16);
+                               ((clk.dsp_loop_latency & 0xf) << 16) |
+                               ((clk.dsp_precision & 7) << 20);
+                       pll->ct.dsp_on_off = (clk.dsp_off & 0x7ff) |
+                               ((clk.dsp_on & 0x7ff) << 16);
                        /*aty_calc_pll_ct(info, &pll->ct);*/
                        aty_set_pll_ct(info, pll);
                } else
@@ -1889,8 +1969,7 @@ static int atyfb_mmap(struct fb_info *info, struct vm_area_struct *vma)
                                continue;
 
                        map_size = par->mmap_map[i].size - (offset - start);
-                       map_offset =
-                           par->mmap_map[i].poff + (offset - start);
+                       map_offset = par->mmap_map[i].poff + (offset - start);
                        break;
                }
                if (!map_size) {
@@ -1900,8 +1979,7 @@ static int atyfb_mmap(struct fb_info *info, struct vm_area_struct *vma)
                if (page + map_size > size)
                        map_size = size - page;
 
-               pgprot_val(vma->vm_page_prot) &=
-                   ~(par->mmap_map[i].prot_mask);
+               pgprot_val(vma->vm_page_prot) &= ~(par->mmap_map[i].prot_mask);
                pgprot_val(vma->vm_page_prot) |= par->mmap_map[i].prot_flag;
 
                if (remap_pfn_range(vma, vma->vm_start + page,
@@ -1918,70 +1996,13 @@ static int atyfb_mmap(struct fb_info *info, struct vm_area_struct *vma)
                par->mmaped = 1;
        return 0;
 }
-
-static struct {
-       u32 yoffset;
-       u8 r[2][256];
-       u8 g[2][256];
-       u8 b[2][256];
-} atyfb_save;
-
-static void atyfb_save_palette(struct atyfb_par *par, int enter)
-{
-       int i, tmp;
-
-       for (i = 0; i < 256; i++) {
-               tmp = aty_ld_8(DAC_CNTL, par) & 0xfc;
-               if (M64_HAS(EXTRA_BRIGHT))
-                       tmp |= 0x2;
-               aty_st_8(DAC_CNTL, tmp, par);
-               aty_st_8(DAC_MASK, 0xff, par);
-
-               writeb(i, &par->aty_cmap_regs->rindex);
-               atyfb_save.r[enter][i] = readb(&par->aty_cmap_regs->lut);
-               atyfb_save.g[enter][i] = readb(&par->aty_cmap_regs->lut);
-               atyfb_save.b[enter][i] = readb(&par->aty_cmap_regs->lut);
-               writeb(i, &par->aty_cmap_regs->windex);
-               writeb(atyfb_save.r[1 - enter][i],
-                      &par->aty_cmap_regs->lut);
-               writeb(atyfb_save.g[1 - enter][i],
-                      &par->aty_cmap_regs->lut);
-               writeb(atyfb_save.b[1 - enter][i],
-                      &par->aty_cmap_regs->lut);
-       }
-}
-
-static void atyfb_palette(int enter)
-{
-       struct atyfb_par *par;
-       struct fb_info *info;
-       int i;
-
-       for (i = 0; i < FB_MAX; i++) {
-               info = registered_fb[i];
-               if (info && info->fbops == &atyfb_ops) {
-                       par = (struct atyfb_par *) info->par;
-                       
-                       atyfb_save_palette(par, enter);
-                       if (enter) {
-                               atyfb_save.yoffset = info->var.yoffset;
-                               info->var.yoffset = 0;
-                               set_off_pitch(par, info);
-                       } else {
-                               info->var.yoffset = atyfb_save.yoffset;
-                               set_off_pitch(par, info);
-                       }
-                       aty_st_le32(CRTC_OFF_PITCH, par->crtc.off_pitch, par);
-                       break;
-               }
-       }
-}
 #endif /* __sparc__ */
 
 
 
 #if defined(CONFIG_PM) && defined(CONFIG_PCI)
 
+#ifdef CONFIG_PPC_PMAC
 /* Power management routines. Those are used for PowerBook sleep.
  */
 static int aty_power_mgmt(int sleep, struct atyfb_par *par)
@@ -2038,21 +2059,13 @@ static int aty_power_mgmt(int sleep, struct atyfb_par *par)
 
        return timeout ? 0 : -EIO;
 }
+#endif /* CONFIG_PPC_PMAC */
 
 static int atyfb_pci_suspend(struct pci_dev *pdev, pm_message_t state)
 {
        struct fb_info *info = pci_get_drvdata(pdev);
        struct atyfb_par *par = (struct atyfb_par *) info->par;
 
-#ifndef CONFIG_PPC_PMAC
-       /* HACK ALERT ! Once I find a proper way to say to each driver
-        * individually what will happen with it's PCI slot, I'll change
-        * that. On laptops, the AGP slot is just unclocked, so D2 is
-        * expected, while on desktops, the card is powered off
-        */
-       return 0;
-#endif /* CONFIG_PPC_PMAC */
-
        if (state.event == pdev->dev.power.power_state.event)
                return 0;
 
@@ -2070,8 +2083,16 @@ static int atyfb_pci_suspend(struct pci_dev *pdev, pm_message_t state)
        par->asleep = 1;
        par->lock_blank = 1;
 
+       /*
+        * Because we may change PCI D state ourselves, we need to
+        * first save the config space content so the core can
+        * restore it properly on resume.
+        */
+       pci_save_state(pdev);
+
+#ifdef CONFIG_PPC_PMAC
        /* Set chip to "suspend" mode */
-       if (aty_power_mgmt(1, par)) {
+       if (machine_is(powermac) && aty_power_mgmt(1, par)) {
                par->asleep = 0;
                par->lock_blank = 0;
                atyfb_blank(FB_BLANK_UNBLANK, info);
@@ -2079,6 +2100,9 @@ static int atyfb_pci_suspend(struct pci_dev *pdev, pm_message_t state)
                release_console_sem();
                return -EIO;
        }
+#else
+       pci_set_power_state(pdev, pci_choose_state(pdev, state));
+#endif
 
        release_console_sem();
 
@@ -2087,6 +2111,20 @@ static int atyfb_pci_suspend(struct pci_dev *pdev, pm_message_t state)
        return 0;
 }
 
+static void aty_resume_chip(struct fb_info *info)
+{
+       struct atyfb_par *par = info->par;
+
+       aty_st_le32(MEM_CNTL, par->mem_cntl, par);
+
+       if (par->pll_ops->resume_pll)
+               par->pll_ops->resume_pll(info, &par->pll);
+
+       if (par->aux_start)
+               aty_st_le32(BUS_CNTL,
+                       aty_ld_le32(BUS_CNTL, par) | BUS_APER_REG_DIS, par);
+}
+
 static int atyfb_pci_resume(struct pci_dev *pdev)
 {
        struct fb_info *info = pci_get_drvdata(pdev);
@@ -2097,8 +2135,20 @@ static int atyfb_pci_resume(struct pci_dev *pdev)
 
        acquire_console_sem();
 
-       if (pdev->dev.power.power_state.event == 2)
+       /*
+        * PCI state will have been restored by the core, so
+        * we should be in D0 now with our config space fully
+        * restored
+        */
+
+#ifdef CONFIG_PPC_PMAC
+       if (machine_is(powermac) &&
+           pdev->dev.power.power_state.event == PM_EVENT_SUSPEND)
                aty_power_mgmt(0, par);
+#endif
+
+       aty_resume_chip(info);
+
        par->asleep = 0;
 
        /* Restore display */
@@ -2124,15 +2174,13 @@ static int atyfb_pci_resume(struct pci_dev *pdev)
 #ifdef CONFIG_FB_ATY_BACKLIGHT
 #define MAX_LEVEL 0xFF
 
-static struct backlight_properties aty_bl_data;
-
-/* Call with fb_info->bl_mutex held */
 static int aty_bl_get_level_brightness(struct atyfb_par *par, int level)
 {
        struct fb_info *info = pci_get_drvdata(par->pdev);
        int atylevel;
 
        /* Get and convert the value */
+       /* No locking of bl_curve since we read a single value */
        atylevel = info->bl_curve[level] * FB_BACKLIGHT_MAX / MAX_LEVEL;
 
        if (atylevel < 0)
@@ -2143,18 +2191,17 @@ static int aty_bl_get_level_brightness(struct atyfb_par *par, int level)
        return atylevel;
 }
 
-/* Call with fb_info->bl_mutex held */
-static int __aty_bl_update_status(struct backlight_device *bd)
+static int aty_bl_update_status(struct backlight_device *bd)
 {
-       struct atyfb_par *par = class_get_devdata(&bd->class_dev);
+       struct atyfb_par *par = bl_get_data(bd);
        unsigned int reg = aty_ld_lcd(LCD_MISC_CNTL, par);
        int level;
 
-       if (bd->props->power != FB_BLANK_UNBLANK ||
-           bd->props->fb_blank != FB_BLANK_UNBLANK)
+       if (bd->props.power != FB_BLANK_UNBLANK ||
+           bd->props.fb_blank != FB_BLANK_UNBLANK)
                level = 0;
        else
-               level = bd->props->brightness;
+               level = bd->props.brightness;
 
        reg |= (BLMOD_EN | BIASMOD_EN);
        if (level > 0) {
@@ -2169,47 +2216,19 @@ static int __aty_bl_update_status(struct backlight_device *bd)
        return 0;
 }
 
-static int aty_bl_update_status(struct backlight_device *bd)
-{
-       struct atyfb_par *par = class_get_devdata(&bd->class_dev);
-       struct fb_info *info = pci_get_drvdata(par->pdev);
-       int ret;
-
-       mutex_lock(&info->bl_mutex);
-       ret = __aty_bl_update_status(bd);
-       mutex_unlock(&info->bl_mutex);
-
-       return ret;
-}
-
 static int aty_bl_get_brightness(struct backlight_device *bd)
 {
-       return bd->props->brightness;
+       return bd->props.brightness;
 }
 
-static struct backlight_properties aty_bl_data = {
-       .owner    = THIS_MODULE,
+static struct backlight_ops aty_bl_data = {
        .get_brightness = aty_bl_get_brightness,
        .update_status  = aty_bl_update_status,
-       .max_brightness = (FB_BACKLIGHT_LEVELS - 1),
 };
 
-static void aty_bl_set_power(struct fb_info *info, int power)
-{
-       mutex_lock(&info->bl_mutex);
-
-       if (info->bl_dev) {
-               down(&info->bl_dev->sem);
-               info->bl_dev->props->power = power;
-               __aty_bl_update_status(info->bl_dev);
-               up(&info->bl_dev->sem);
-       }
-
-       mutex_unlock(&info->bl_mutex);
-}
-
 static void aty_bl_init(struct atyfb_par *par)
 {
+       struct backlight_properties props;
        struct fb_info *info = pci_get_drvdata(par->pdev);
        struct backlight_device *bd;
        char name[12];
@@ -2221,32 +2240,24 @@ static void aty_bl_init(struct atyfb_par *par)
 
        snprintf(name, sizeof(name), "atybl%d", info->node);
 
-       bd = backlight_device_register(name, par, &aty_bl_data);
+       memset(&props, 0, sizeof(struct backlight_properties));
+       props.max_brightness = FB_BACKLIGHT_LEVELS - 1;
+       bd = backlight_device_register(name, info->dev, par, &aty_bl_data,
+                                      &props);
        if (IS_ERR(bd)) {
                info->bl_dev = NULL;
                printk(KERN_WARNING "aty: Backlight registration failed\n");
                goto error;
        }
 
-       mutex_lock(&info->bl_mutex);
        info->bl_dev = bd;
        fb_bl_default_curve(info, 0,
-               0x3F * FB_BACKLIGHT_MAX / MAX_LEVEL,
-               0xFF * FB_BACKLIGHT_MAX / MAX_LEVEL);
-       mutex_unlock(&info->bl_mutex);
-
-       down(&bd->sem);
-       bd->props->brightness = aty_bl_data.max_brightness;
-       bd->props->power = FB_BLANK_UNBLANK;
-       bd->props->update_status(bd);
-       up(&bd->sem);
+                           0x3F * FB_BACKLIGHT_MAX / MAX_LEVEL,
+                           0xFF * FB_BACKLIGHT_MAX / MAX_LEVEL);
 
-#ifdef CONFIG_PMAC_BACKLIGHT
-       mutex_lock(&pmac_backlight_mutex);
-       if (!pmac_backlight)
-               pmac_backlight = bd;
-       mutex_unlock(&pmac_backlight_mutex);
-#endif
+       bd->props.brightness = bd->props.max_brightness;
+       bd->props.power = FB_BLANK_UNBLANK;
+       backlight_update_status(bd);
 
        printk("aty: Backlight initialized (%s)\n", name);
 
@@ -2256,30 +2267,10 @@ error:
        return;
 }
 
-static void aty_bl_exit(struct atyfb_par *par)
+static void aty_bl_exit(struct backlight_device *bd)
 {
-       struct fb_info *info = pci_get_drvdata(par->pdev);
-
-#ifdef CONFIG_PMAC_BACKLIGHT
-       mutex_lock(&pmac_backlight_mutex);
-#endif
-
-       mutex_lock(&info->bl_mutex);
-       if (info->bl_dev) {
-#ifdef CONFIG_PMAC_BACKLIGHT
-               if (pmac_backlight == info->bl_dev)
-                       pmac_backlight = NULL;
-#endif
-
-               backlight_device_unregister(info->bl_dev);
-
-               printk("aty: Backlight unloaded\n");
-       }
-       mutex_unlock(&info->bl_mutex);
-
-#ifdef CONFIG_PMAC_BACKLIGHT
-       mutex_unlock(&pmac_backlight_mutex);
-#endif
+       backlight_device_unregister(bd);
+       printk("aty: Backlight unloaded\n");
 }
 
 #endif /* CONFIG_FB_ATY_BACKLIGHT */
@@ -2296,7 +2287,7 @@ static void __devinit aty_calc_mem_refresh(struct atyfb_par *par, int xclk)
        const int *refresh_tbl;
        int i, size;
 
-       if (IS_XL(par->pci_id) || IS_MOBILITY(par->pci_id)) {
+       if (M64_HAS(XL_MEM)) {
                refresh_tbl = ragexl_tbl;
                size = ARRAY_SIZE(ragexl_tbl);
        } else {
@@ -2304,16 +2295,16 @@ static void __devinit aty_calc_mem_refresh(struct atyfb_par *par, int xclk)
                size = ARRAY_SIZE(ragepro_tbl);
        }
 
-       for (i=0; i < size; i++) {
+       for (i = 0; i < size; i++) {
                if (xclk < refresh_tbl[i])
-               break;
+                       break;
        }
        par->mem_refresh_rate = i;
 }
 
-    /*
    *  Initialisation
    */
+/*
* Initialisation
+ */
 
 static struct fb_info *fb_list = NULL;
 
@@ -2344,48 +2335,22 @@ static int __devinit atyfb_get_timings_from_lcd(struct atyfb_par *par,
 }
 #endif /* defined(__i386__) && defined(CONFIG_FB_ATY_GENERIC_LCD) */
 
-static int __devinit aty_init(struct fb_info *info, const char *name)
+static int __devinit aty_init(struct fb_info *info)
 {
        struct atyfb_par *par = (struct atyfb_par *) info->par;
        const char *ramname = NULL, *xtal;
        int gtb_memsize, has_var = 0;
        struct fb_var_screeninfo var;
-       u32 i;
+       int ret;
 
        init_waitqueue_head(&par->vblank.wait);
        spin_lock_init(&par->int_lock);
 
-       par->aty_cmap_regs =
-           (struct aty_cmap_regs __iomem *) (par->ati_regbase + 0xc0);
-
-#ifdef CONFIG_PPC_PMAC
-       /* The Apple iBook1 uses non-standard memory frequencies. We detect it
-        * and set the frequency manually. */
-       if (machine_is_compatible("PowerBook2,1")) {
-               par->pll_limits.mclk = 70;
-               par->pll_limits.xclk = 53;
-       }
-#endif
-       if (pll)
-               par->pll_limits.pll_max = pll;
-       if (mclk)
-               par->pll_limits.mclk = mclk;
-       if (xclk)
-               par->pll_limits.xclk = xclk;
-
-       aty_calc_mem_refresh(par, par->pll_limits.xclk);
-       par->pll_per = 1000000/par->pll_limits.pll_max;
-       par->mclk_per = 1000000/par->pll_limits.mclk;
-       par->xclk_per = 1000000/par->pll_limits.xclk;
-
-       par->ref_clk_per = 1000000000000ULL / 14318180;
-       xtal = "14.31818";
-
 #ifdef CONFIG_FB_ATY_GX
        if (!M64_HAS(INTEGRATED)) {
                u32 stat0;
                u8 dac_type, dac_subtype, clk_type;
-               stat0 = aty_ld_le32(CONFIG_STAT0, par);
+               stat0 = aty_ld_le32(CNFG_STAT0, par);
                par->bus_type = (stat0 >> 0) & 0x07;
                par->ram_type = (stat0 >> 3) & 0x07;
                ramname = aty_gx_ram[par->ram_type];
@@ -2407,6 +2372,7 @@ static int __devinit aty_init(struct fb_info *info, const char *name)
                case DAC_IBMRGB514:
                        par->dac_ops = &aty_dac_ibm514;
                        break;
+#ifdef CONFIG_ATARI
                case DAC_ATI68860_B:
                case DAC_ATI68860_C:
                        par->dac_ops = &aty_dac_ati68860b;
@@ -2415,6 +2381,7 @@ static int __devinit aty_init(struct fb_info *info, const char *name)
                case DAC_ATT21C498:
                        par->dac_ops = &aty_dac_att21c498;
                        break;
+#endif
                default:
                        PRINTKI("aty_init: DAC type not implemented yet!\n");
                        par->dac_ops = &aty_dac_unsupported;
@@ -2453,13 +2420,47 @@ static int __devinit aty_init(struct fb_info *info, const char *name)
                par->dac_ops = &aty_dac_ct;
                par->pll_ops = &aty_pll_ct;
                par->bus_type = PCI;
-               par->ram_type = (aty_ld_le32(CONFIG_STAT0, par) & 0x07);
-               ramname = aty_ct_ram[par->ram_type];
+               par->ram_type = (aty_ld_le32(CNFG_STAT0, par) & 0x07);
+               if (M64_HAS(XL_MEM))
+                       ramname = aty_xl_ram[par->ram_type];
+               else
+                       ramname = aty_ct_ram[par->ram_type];
                /* for many chips, the mclk is 67 MHz for SDRAM, 63 MHz otherwise */
                if (par->pll_limits.mclk == 67 && par->ram_type < SDRAM)
                        par->pll_limits.mclk = 63;
+               /* Mobility + 32bit memory interface need halved XCLK. */
+               if (M64_HAS(MOBIL_BUS) && par->ram_type == SDRAM32)
+                       par->pll_limits.xclk = (par->pll_limits.xclk + 1) >> 1;
+       }
+#endif
+#ifdef CONFIG_PPC_PMAC
+       /*
+        * The Apple iBook1 uses non-standard memory frequencies.
+        * We detect it and set the frequency manually.
+        */
+       if (of_machine_is_compatible("PowerBook2,1")) {
+               par->pll_limits.mclk = 70;
+               par->pll_limits.xclk = 53;
        }
+#endif
+
+       /* Allow command line to override clocks. */
+       if (pll)
+               par->pll_limits.pll_max = pll;
+       if (mclk)
+               par->pll_limits.mclk = mclk;
+       if (xclk)
+               par->pll_limits.xclk = xclk;
+
+       aty_calc_mem_refresh(par, par->pll_limits.xclk);
+       par->pll_per = 1000000/par->pll_limits.pll_max;
+       par->mclk_per = 1000000/par->pll_limits.mclk;
+       par->xclk_per = 1000000/par->pll_limits.xclk;
+
+       par->ref_clk_per = 1000000000000ULL / 14318180;
+       xtal = "14.31818";
 
+#ifdef CONFIG_FB_ATY_CT
        if (M64_HAS(GTB_DSP)) {
                u8 pll_ref_div = aty_ld_pll_ct(PLL_REF_DIV, par);
 
@@ -2480,14 +2481,15 @@ static int __devinit aty_init(struct fb_info *info, const char *name)
 #endif /* CONFIG_FB_ATY_CT */
 
        /* save previous video mode */
-       aty_get_crtc(par, &saved_crtc);
-       if(par->pll_ops->get_pll)
-               par->pll_ops->get_pll(info, &saved_pll);
+       aty_get_crtc(par, &par->saved_crtc);
+       if (par->pll_ops->get_pll)
+               par->pll_ops->get_pll(info, &par->saved_pll);
 
-       i = aty_ld_le32(MEM_CNTL, par);
+       par->mem_cntl = aty_ld_le32(MEM_CNTL, par);
        gtb_memsize = M64_HAS(GTB_DSP);
        if (gtb_memsize)
-               switch (i & 0xF) {      /* 0xF used instead of MEM_SIZE_ALIAS */
+               /* 0xF used instead of MEM_SIZE_ALIAS */
+               switch (par->mem_cntl & 0xF) {
                case MEM_SIZE_512K:
                        info->fix.smem_len = 0x80000;
                        break;
@@ -2509,7 +2511,7 @@ static int __devinit aty_init(struct fb_info *info, const char *name)
                default:
                        info->fix.smem_len = 0x80000;
        } else
-               switch (i & MEM_SIZE_ALIAS) {
+               switch (par->mem_cntl & MEM_SIZE_ALIAS) {
                case MEM_SIZE_512K:
                        info->fix.smem_len = 0x80000;
                        break;
@@ -2533,31 +2535,31 @@ static int __devinit aty_init(struct fb_info *info, const char *name)
                }
 
        if (M64_HAS(MAGIC_VRAM_SIZE)) {
-               if (aty_ld_le32(CONFIG_STAT1, par) & 0x40000000)
+               if (aty_ld_le32(CNFG_STAT1, par) & 0x40000000)
                        info->fix.smem_len += 0x400000;
        }
 
        if (vram) {
                info->fix.smem_len = vram * 1024;
-               i = i & ~(gtb_memsize ? 0xF : MEM_SIZE_ALIAS);
+               par->mem_cntl &= ~(gtb_memsize ? 0xF : MEM_SIZE_ALIAS);
                if (info->fix.smem_len <= 0x80000)
-                       i |= MEM_SIZE_512K;
+                       par->mem_cntl |= MEM_SIZE_512K;
                else if (info->fix.smem_len <= 0x100000)
-                       i |= MEM_SIZE_1M;
+                       par->mem_cntl |= MEM_SIZE_1M;
                else if (info->fix.smem_len <= 0x200000)
-                       i |= gtb_memsize ? MEM_SIZE_2M_GTB : MEM_SIZE_2M;
+                       par->mem_cntl |= gtb_memsize ? MEM_SIZE_2M_GTB : MEM_SIZE_2M;
                else if (info->fix.smem_len <= 0x400000)
-                       i |= gtb_memsize ? MEM_SIZE_4M_GTB : MEM_SIZE_4M;
+                       par->mem_cntl |= gtb_memsize ? MEM_SIZE_4M_GTB : MEM_SIZE_4M;
                else if (info->fix.smem_len <= 0x600000)
-                       i |= gtb_memsize ? MEM_SIZE_6M_GTB : MEM_SIZE_6M;
+                       par->mem_cntl |= gtb_memsize ? MEM_SIZE_6M_GTB : MEM_SIZE_6M;
                else
-                       i |= gtb_memsize ? MEM_SIZE_8M_GTB : MEM_SIZE_8M;
-               aty_st_le32(MEM_CNTL, i, par);
+                       par->mem_cntl |= gtb_memsize ? MEM_SIZE_8M_GTB : MEM_SIZE_8M;
+               aty_st_le32(MEM_CNTL, par->mem_cntl, par);
        }
 
        /*
-        *  Reg Block 0 (CT-compatible block) is at mmio_start
-        *  Reg Block 1 (multimedia extensions) is at mmio_start - 0x400
+        * Reg Block 0 (CT-compatible block) is at mmio_start
+        * Reg Block 1 (multimedia extensions) is at mmio_start - 0x400
         */
        if (M64_HAS(GX)) {
                info->fix.mmio_len = 0x400;
@@ -2576,82 +2578,98 @@ static int __devinit aty_init(struct fb_info *info, const char *name)
        }
 
        PRINTKI("%d%c %s, %s MHz XTAL, %d MHz PLL, %d Mhz MCLK, %d MHz XCLK\n",
-              info->fix.smem_len == 0x80000 ? 512 : (info->fix.smem_len >> 20),
-              info->fix.smem_len == 0x80000 ? 'K' : 'M', ramname, xtal, par->pll_limits.pll_max,
-              par->pll_limits.mclk, par->pll_limits.xclk);
+               info->fix.smem_len == 0x80000 ? 512 : (info->fix.smem_len>>20),
+               info->fix.smem_len == 0x80000 ? 'K' : 'M', ramname, xtal,
+               par->pll_limits.pll_max, par->pll_limits.mclk,
+               par->pll_limits.xclk);
 
-#if defined(DEBUG) && defined(CONFIG_ATY_CT)
+#if defined(DEBUG) && defined(CONFIG_FB_ATY_CT)
        if (M64_HAS(INTEGRATED)) {
                int i;
-               printk("debug atyfb: BUS_CNTL DAC_CNTL MEM_CNTL EXT_MEM_CNTL CRTC_GEN_CNTL "
-                      "DSP_CONFIG DSP_ON_OFF CLOCK_CNTL\n"
-                      "debug atyfb: %08x %08x %08x %08x     %08x      %08x   %08x   %08x\n"
+               printk("debug atyfb: BUS_CNTL DAC_CNTL MEM_CNTL "
+                      "EXT_MEM_CNTL CRTC_GEN_CNTL DSP_CONFIG "
+                      "DSP_ON_OFF CLOCK_CNTL\n"
+                      "debug atyfb: %08x %08x %08x "
+                      "%08x     %08x      %08x   "
+                      "%08x   %08x\n"
                       "debug atyfb: PLL",
-                       aty_ld_le32(BUS_CNTL, par), aty_ld_le32(DAC_CNTL, par),
-                       aty_ld_le32(MEM_CNTL, par), aty_ld_le32(EXT_MEM_CNTL, par),
-                       aty_ld_le32(CRTC_GEN_CNTL, par), aty_ld_le32(DSP_CONFIG, par),
-                       aty_ld_le32(DSP_ON_OFF, par), aty_ld_le32(CLOCK_CNTL, par));
+                      aty_ld_le32(BUS_CNTL, par),
+                      aty_ld_le32(DAC_CNTL, par),
+                      aty_ld_le32(MEM_CNTL, par),
+                      aty_ld_le32(EXT_MEM_CNTL, par),
+                      aty_ld_le32(CRTC_GEN_CNTL, par),
+                      aty_ld_le32(DSP_CONFIG, par),
+                      aty_ld_le32(DSP_ON_OFF, par),
+                      aty_ld_le32(CLOCK_CNTL, par));
                for (i = 0; i < 40; i++)
                        printk(" %02x", aty_ld_pll_ct(i, par));
                printk("\n");
        }
 #endif
-       if(par->pll_ops->init_pll)
+       if (par->pll_ops->init_pll)
                par->pll_ops->init_pll(info, &par->pll);
+       if (par->pll_ops->resume_pll)
+               par->pll_ops->resume_pll(info, &par->pll);
 
        /*
-        *  Last page of 8 MB (4 MB on ISA) aperture is MMIO,
-        *  unless the auxiliary register aperture is used.
+        * Last page of 8 MB (4 MB on ISA) aperture is MMIO,
+        * unless the auxiliary register aperture is used.
         */
-
        if (!par->aux_start &&
-               (info->fix.smem_len == 0x800000 || (par->bus_type == ISA && info->fix.smem_len == 0x400000)))
+           (info->fix.smem_len == 0x800000 ||
+            (par->bus_type == ISA && info->fix.smem_len == 0x400000)))
                info->fix.smem_len -= GUI_RESERVE;
 
        /*
-        *  Disable register access through the linear aperture
-        *  if the auxiliary aperture is used so we can access
-        *  the full 8 MB of video RAM on 8 MB boards.
+        * Disable register access through the linear aperture
+        * if the auxiliary aperture is used so we can access
+        * the full 8 MB of video RAM on 8 MB boards.
         */
        if (par->aux_start)
-               aty_st_le32(BUS_CNTL, aty_ld_le32(BUS_CNTL, par) | BUS_APER_REG_DIS, par);
+               aty_st_le32(BUS_CNTL, aty_ld_le32(BUS_CNTL, par) |
+                           BUS_APER_REG_DIS, par);
 
 #ifdef CONFIG_MTRR
        par->mtrr_aper = -1;
        par->mtrr_reg = -1;
        if (!nomtrr) {
                /* Cover the whole resource. */
-                par->mtrr_aper = mtrr_add(par->res_start, par->res_size, MTRR_TYPE_WRCOMB, 1);
-                if (par->mtrr_aper >= 0 && !par->aux_start) {
+               par->mtrr_aper = mtrr_add(par->res_start, par->res_size,
+                                         MTRR_TYPE_WRCOMB, 1);
+               if (par->mtrr_aper >= 0 && !par->aux_start) {
                        /* Make a hole for mmio. */
-                       par->mtrr_reg = mtrr_add(par->res_start + 0x800000 - GUI_RESERVE,
-                               GUI_RESERVE, MTRR_TYPE_UNCACHABLE, 1);
+                       par->mtrr_reg = mtrr_add(par->res_start + 0x800000 -
+                                                GUI_RESERVE, GUI_RESERVE,
+                                                MTRR_TYPE_UNCACHABLE, 1);
                        if (par->mtrr_reg < 0) {
                                mtrr_del(par->mtrr_aper, 0, 0);
                                par->mtrr_aper = -1;
                        }
-                }
+               }
        }
 #endif
 
        info->fbops = &atyfb_ops;
-       info->pseudo_palette = pseudo_palette;
+       info->pseudo_palette = par->pseudo_palette;
        info->flags = FBINFO_DEFAULT           |
-                     FBINFO_HWACCEL_IMAGEBLIT |
-                     FBINFO_HWACCEL_FILLRECT  |
-                     FBINFO_HWACCEL_COPYAREA  |
-                     FBINFO_HWACCEL_YPAN;
+                     FBINFO_HWACCEL_IMAGEBLIT |
+                     FBINFO_HWACCEL_FILLRECT  |
+                     FBINFO_HWACCEL_COPYAREA  |
+                     FBINFO_HWACCEL_YPAN;
 
 #ifdef CONFIG_PMAC_BACKLIGHT
-       if (M64_HAS(G3_PB_1_1) && machine_is_compatible("PowerBook1,1")) {
-               /* these bits let the 101 powerbook wake up from sleep -- paulus */
-               aty_st_lcd(POWER_MANAGEMENT, aty_ld_lcd(POWER_MANAGEMENT, par)
-                          | (USE_F32KHZ | TRISTATE_MEM_EN), par);
+       if (M64_HAS(G3_PB_1_1) && of_machine_is_compatible("PowerBook1,1")) {
+               /*
+                * these bits let the 101 powerbook
+                * wake up from sleep -- paulus
+                */
+               aty_st_lcd(POWER_MANAGEMENT, aty_ld_lcd(POWER_MANAGEMENT, par) |
+                          USE_F32KHZ | TRISTATE_MEM_EN, par);
        } else
 #endif
-       if (M64_HAS(MOBIL_BUS)) {
+       if (M64_HAS(MOBIL_BUS) && backlight) {
 #ifdef CONFIG_FB_ATY_BACKLIGHT
-               aty_bl_init (par);
+               aty_bl_init(par);
 #endif
        }
 
@@ -2659,8 +2677,8 @@ static int __devinit aty_init(struct fb_info *info, const char *name)
 #ifdef CONFIG_PPC
        if (machine_is(powermac)) {
                /*
-                *  FIXME: The NVRAM stuff should be put in a Mac-specific file, as it
-                *         applies to all Mac video cards
+                * FIXME: The NVRAM stuff should be put in a Mac-specific file,
+                *        as it applies to all Mac video cards
                 */
                if (mode) {
                        if (mac_find_mode(&var, info, mode, 8))
@@ -2671,10 +2689,9 @@ static int __devinit aty_init(struct fb_info *info, const char *name)
                                if (M64_HAS(G3_PB_1024x768))
                                        /* G3 PowerBook with 1024x768 LCD */
                                        default_vmode = VMODE_1024_768_60;
-                               else if (machine_is_compatible("iMac"))
+                               else if (of_machine_is_compatible("iMac"))
                                        default_vmode = VMODE_1024_768_75;
-                               else if (machine_is_compatible
-                                        ("PowerBook2,1"))
+                               else if (of_machine_is_compatible("PowerBook2,1"))
                                        /* iBook with 800x600 LCD */
                                        default_vmode = VMODE_800_600_60;
                                else
@@ -2688,7 +2705,7 @@ static int __devinit aty_init(struct fb_info *info, const char *name)
                        if (default_cmode < CMODE_8 || default_cmode > CMODE_32)
                                default_cmode = CMODE_8;
                        if (!mac_vmode_to_var(default_vmode, default_cmode,
-                                              &var))
+                                             &var))
                                has_var = 1;
                }
        }
@@ -2725,48 +2742,50 @@ static int __devinit aty_init(struct fb_info *info, const char *name)
                        var.yres_virtual = var.yres;
        }
 
-       if (atyfb_check_var(&var, info)) {
+       ret = atyfb_check_var(&var, info);
+       if (ret) {
                PRINTKE("can't set default video mode\n");
                goto aty_init_exit;
        }
 
-#ifdef __sparc__
-       atyfb_save_palette(par, 0);
-#endif
-
 #ifdef CONFIG_FB_ATY_CT
        if (!noaccel && M64_HAS(INTEGRATED))
                aty_init_cursor(info);
 #endif /* CONFIG_FB_ATY_CT */
        info->var = var;
 
-       fb_alloc_cmap(&info->cmap, 256, 0);
+       ret = fb_alloc_cmap(&info->cmap, 256, 0);
+       if (ret < 0)
+               goto aty_init_exit;
 
-       if (register_framebuffer(info) < 0)
+       ret = register_framebuffer(info);
+       if (ret < 0) {
+               fb_dealloc_cmap(&info->cmap);
                goto aty_init_exit;
+       }
 
        fb_list = info;
 
        PRINTKI("fb%d: %s frame buffer device on %s\n",
-              info->node, info->fix.id, name);
+               info->node, info->fix.id, par->bus_type == ISA ? "ISA" : "PCI");
        return 0;
 
 aty_init_exit:
        /* restore video mode */
-       aty_set_crtc(par, &saved_crtc);
-       par->pll_ops->set_pll(info, &saved_pll);
+       aty_set_crtc(par, &par->saved_crtc);
+       par->pll_ops->set_pll(info, &par->saved_pll);
 
 #ifdef CONFIG_MTRR
        if (par->mtrr_reg >= 0) {
-           mtrr_del(par->mtrr_reg, 0, 0);
-           par->mtrr_reg = -1;
+               mtrr_del(par->mtrr_reg, 0, 0);
+               par->mtrr_reg = -1;
        }
        if (par->mtrr_aper >= 0) {
-           mtrr_del(par->mtrr_aper, 0, 0);
-           par->mtrr_aper = -1;
+               mtrr_del(par->mtrr_aper, 0, 0);
+               par->mtrr_aper = -1;
        }
 #endif
-       return -1;
+       return ret;
 }
 
 #ifdef CONFIG_ATARI
@@ -2791,18 +2810,18 @@ static int __devinit store_video_par(char *video_str, unsigned char m64_num)
        phys_size[m64_num] = size;
        phys_guiregbase[m64_num] = guiregbase;
        PRINTKI("stored them all: $%08lX $%08lX $%08lX \n", vmembase, size,
-              guiregbase);
+               guiregbase);
        return 0;
 
     mach64_invalid:
+ mach64_invalid:
        phys_vmembase[m64_num] = 0;
        return -1;
 }
 #endif /* CONFIG_ATARI */
 
-    /*
    *  Blank the display.
    */
+/*
* Blank the display.
+ */
 
 static int atyfb_blank(int blank, struct fb_info *info)
 {
@@ -2812,10 +2831,7 @@ static int atyfb_blank(int blank, struct fb_info *info)
        if (par->lock_blank || par->asleep)
                return 0;
 
-#ifdef CONFIG_FB_ATY_BACKLIGHT
-       if (machine_is(powermac) && blank > FB_BLANK_NORMAL)
-               aty_bl_set_power(info, FB_BLANK_POWERDOWN);
-#elif defined(CONFIG_FB_ATY_GENERIC_LCD)
+#ifdef CONFIG_FB_ATY_GENERIC_LCD
        if (par->lcd_table && blank > FB_BLANK_NORMAL &&
            (aty_ld_lcd(LCD_GEN_CNTL, par) & LCD_ON)) {
                u32 pm = aty_ld_lcd(POWER_MANAGEMENT, par);
@@ -2825,29 +2841,26 @@ static int atyfb_blank(int blank, struct fb_info *info)
 #endif
 
        gen_cntl = aty_ld_le32(CRTC_GEN_CNTL, par);
+       gen_cntl &= ~0x400004c;
        switch (blank) {
-               case FB_BLANK_UNBLANK:
-                       gen_cntl &= ~0x400004c;
-                       break;
-               case FB_BLANK_NORMAL:
-                       gen_cntl |= 0x4000040;
-                       break;
-               case FB_BLANK_VSYNC_SUSPEND:
-                       gen_cntl |= 0x4000048;
-                       break;
-               case FB_BLANK_HSYNC_SUSPEND:
-                       gen_cntl |= 0x4000044;
-                       break;
-               case FB_BLANK_POWERDOWN:
-                       gen_cntl |= 0x400004c;
-                       break;
+       case FB_BLANK_UNBLANK:
+               break;
+       case FB_BLANK_NORMAL:
+               gen_cntl |= 0x4000040;
+               break;
+       case FB_BLANK_VSYNC_SUSPEND:
+               gen_cntl |= 0x4000048;
+               break;
+       case FB_BLANK_HSYNC_SUSPEND:
+               gen_cntl |= 0x4000044;
+               break;
+       case FB_BLANK_POWERDOWN:
+               gen_cntl |= 0x400004c;
+               break;
        }
        aty_st_le32(CRTC_GEN_CNTL, gen_cntl, par);
 
-#ifdef CONFIG_FB_ATY_BACKLIGHT
-       if (machine_is(powermac) && blank <= FB_BLANK_NORMAL)
-               aty_bl_set_power(info, FB_BLANK_UNBLANK);
-#elif defined(CONFIG_FB_ATY_GENERIC_LCD)
+#ifdef CONFIG_FB_ATY_GENERIC_LCD
        if (par->lcd_table && blank <= FB_BLANK_NORMAL &&
            (aty_ld_lcd(LCD_GEN_CNTL, par) & LCD_ON)) {
                u32 pm = aty_ld_lcd(POWER_MANAGEMENT, par);
@@ -2862,28 +2875,21 @@ static int atyfb_blank(int blank, struct fb_info *info)
 static void aty_st_pal(u_int regno, u_int red, u_int green, u_int blue,
                       const struct atyfb_par *par)
 {
-#ifdef CONFIG_ATARI
-       out_8(&par->aty_cmap_regs->windex, regno);
-       out_8(&par->aty_cmap_regs->lut, red);
-       out_8(&par->aty_cmap_regs->lut, green);
-       out_8(&par->aty_cmap_regs->lut, blue);
-#else
-       writeb(regno, &par->aty_cmap_regs->windex);
-       writeb(red, &par->aty_cmap_regs->lut);
-       writeb(green, &par->aty_cmap_regs->lut);
-       writeb(blue, &par->aty_cmap_regs->lut);
-#endif
+       aty_st_8(DAC_W_INDEX, regno, par);
+       aty_st_8(DAC_DATA, red, par);
+       aty_st_8(DAC_DATA, green, par);
+       aty_st_8(DAC_DATA, blue, par);
 }
 
-    /*
    *  Set a single color register. The values supplied are already
    *  rounded down to the hardware's capabilities (according to the
    *  entries in the var structure). Return != 0 for invalid regno.
    *  !! 4 & 8 =  PSEUDO, > 8 = DIRECTCOLOR
    */
+/*
* Set a single color register. The values supplied are already
* rounded down to the hardware's capabilities (according to the
* entries in the var structure). Return != 0 for invalid regno.
* !! 4 & 8 =  PSEUDO, > 8 = DIRECTCOLOR
+ */
 
 static int atyfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
-       u_int transp, struct fb_info *info)
+                          u_int transp, struct fb_info *info)
 {
        struct atyfb_par *par = (struct atyfb_par *) info->par;
        int i, depth;
@@ -2937,16 +2943,15 @@ static int atyfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
                if (depth == 16) {
                        if (regno < 32)
                                aty_st_pal(regno << 3, red,
-                                          par->palette[regno<<1].green,
+                                          par->palette[regno << 1].green,
                                           blue, par);
-                       red = par->palette[regno>>1].red;
-                       blue = par->palette[regno>>1].blue;
+                       red = par->palette[regno >> 1].red;
+                       blue = par->palette[regno >> 1].blue;
                        regno <<= 2;
                } else if (depth == 15) {
                        regno <<= 3;
-                       for(i = 0; i < 8; i++) {
-                           aty_st_pal(regno + i, red, green, blue, par);
-                       }
+                       for (i = 0; i < 8; i++)
+                               aty_st_pal(regno + i, red, green, blue, par);
                }
        }
        aty_st_pal(regno, red, green, blue, par);
@@ -2958,23 +2963,16 @@ static int atyfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
 
 #ifdef __sparc__
 
-extern void (*prom_palette) (int);
-
 static int __devinit atyfb_setup_sparc(struct pci_dev *pdev,
-                       struct fb_info *info, unsigned long addr)
+                                      struct fb_info *info,
+                                      unsigned long addr)
 {
-       extern int con_is_present(void);
-
        struct atyfb_par *par = info->par;
-       struct pcidev_cookie *pcp;
+       struct device_node *dp;
        char prop[128];
        int node, len, i, j, ret;
        u32 mem, chip_id;
 
-       /* Do not attach when we have a serial console. */
-       if (!con_is_present())
-               return -ENXIO;
-
        /*
         * Map memory-mapped registers.
         */
@@ -2995,12 +2993,11 @@ static int __devinit atyfb_setup_sparc(struct pci_dev *pdev,
                /* nothing */ ;
        j = i + 4;
 
-       par->mmap_map = kmalloc(j * sizeof(*par->mmap_map), GFP_ATOMIC);
+       par->mmap_map = kcalloc(j, sizeof(*par->mmap_map), GFP_ATOMIC);
        if (!par->mmap_map) {
                PRINTKE("atyfb_setup_sparc() can't alloc mmap_map\n");
                return -ENOMEM;
        }
-       memset(par->mmap_map, 0, j * sizeof(*par->mmap_map));
 
        for (i = 0, j = 2; i < 6 && pdev->resource[i].start; i++) {
                struct resource *rp = &pdev->resource[i];
@@ -3056,7 +3053,8 @@ static int __devinit atyfb_setup_sparc(struct pci_dev *pdev,
                j++;
        }
 
-       if((ret = correct_chipset(par)))
+       ret = correct_chipset(par);
+       if (ret)
                return ret;
 
        if (IS_XL(pdev->device)) {
@@ -3064,7 +3062,7 @@ static int __devinit atyfb_setup_sparc(struct pci_dev *pdev,
                 * Fix PROMs idea of MEM_CNTL settings...
                 */
                mem = aty_ld_le32(MEM_CNTL, par);
-               chip_id = aty_ld_le32(CONFIG_CHIP_ID, par);
+               chip_id = aty_ld_le32(CNFG_CHIP_ID, par);
                if (((chip_id & CFG_CHIP_TYPE) == VT_CHIP_ID) && !((chip_id >> 24) & 1)) {
                        switch (mem & 0x0f) {
                        case 3:
@@ -3082,7 +3080,7 @@ static int __devinit atyfb_setup_sparc(struct pci_dev *pdev,
                        default:
                                break;
                        }
-                       if ((aty_ld_le32(CONFIG_STAT0, par) & 7) >= SDRAM)
+                       if ((aty_ld_le32(CNFG_STAT0, par) & 7) >= SDRAM)
                                mem &= ~(0x00700000);
                }
                mem &= ~(0xcf80e000);   /* Turn off all undocumented bits. */
@@ -3104,8 +3102,8 @@ static int __devinit atyfb_setup_sparc(struct pci_dev *pdev,
                        node = 0;
        }
 
-       pcp = pdev->sysdata;
-       if (node == pcp->prom_node->node) {
+       dp = pci_device_to_OF_node(pdev);
+       if (node == dp->phandle) {
                struct fb_var_screeninfo *var = &default_var;
                unsigned int N, P, Q, M, T, R;
                u32 v_total, h_total;
@@ -3181,33 +3179,33 @@ static int __devinit atyfb_setup_sparc(struct pci_dev *pdev,
 
 #ifdef __i386__
 #ifdef CONFIG_FB_ATY_GENERIC_LCD
-static void aty_init_lcd(struct atyfb_par *par, u32 bios_base)
+static void __devinit aty_init_lcd(struct atyfb_par *par, u32 bios_base)
 {
        u32 driv_inf_tab, sig;
        u16 lcd_ofs;
 
-       /* To support an LCD panel, we should know it's dimensions and
+       /*
+        * To support an LCD panel, we should know it's dimensions and
         *  it's desired pixel clock.
         * There are two ways to do it:
         *  - Check the startup video mode and calculate the panel
         *    size from it. This is unreliable.
         *  - Read it from the driver information table in the video BIOS.
-       */
+        */
        /* Address of driver information table is at offset 0x78. */
        driv_inf_tab = bios_base + *((u16 *)(bios_base+0x78));
 
        /* Check for the driver information table signature. */
-       sig = (*(u32 *)driv_inf_tab);
+       sig = *(u32 *)driv_inf_tab;
        if ((sig == 0x54504c24) || /* Rage LT pro */
-               (sig == 0x544d5224) || /* Rage mobility */
-               (sig == 0x54435824) || /* Rage XC */
-               (sig == 0x544c5824)) { /* Rage XL */
+           (sig == 0x544d5224) || /* Rage mobility */
+           (sig == 0x54435824) || /* Rage XC */
+           (sig == 0x544c5824)) { /* Rage XL */
                PRINTKI("BIOS contains driver information table.\n");
-               lcd_ofs = (*(u16 *)(driv_inf_tab + 10));
+               lcd_ofs = *(u16 *)(driv_inf_tab + 10);
                par->lcd_table = 0;
-               if (lcd_ofs != 0) {
+               if (lcd_ofs != 0)
                        par->lcd_table = bios_base + lcd_ofs;
-               }
        }
 
        if (par->lcd_table != 0) {
@@ -3222,14 +3220,16 @@ static void aty_init_lcd(struct atyfb_par *par, u32 bios_base)
                u16 width, height, panel_type, refresh_rates;
                u16 *lcdmodeptr;
                u32 format;
-               u8 lcd_refresh_rates[16] = {50,56,60,67,70,72,75,76,85,90,100,120,140,150,160,200};
-               /* The most important information is the panel size at
+               u8 lcd_refresh_rates[16] = { 50, 56, 60, 67, 70, 72, 75, 76, 85,
+                                            90, 100, 120, 140, 150, 160, 200 };
+               /*
+                * The most important information is the panel size at
                 * offset 25 and 27, but there's some other nice information
                 * which we print to the screen.
                 */
                id = *(u8 *)par->lcd_table;
-               strncpy(model,(char *)par->lcd_table+1,24);
-               model[23]=0;
+               strncpy(model, (char *)par->lcd_table+1, 24);
+               model[23] = 0;
 
                width = par->lcd_width = *(u16 *)(par->lcd_table+25);
                height = par->lcd_height = *(u16 *)(par->lcd_table+27);
@@ -3242,7 +3242,7 @@ static void aty_init_lcd(struct atyfb_par *par, u32 bios_base)
                        txtdual = "dual (split) ";
                else
                        txtdual = "";
-               tech = (panel_type>>2) & 63;
+               tech = (panel_type >> 2) & 63;
                switch (tech) {
                case 0:
                        txtmonitor = "passive matrix";
@@ -3275,7 +3275,7 @@ static void aty_init_lcd(struct atyfb_par *par, u32 bios_base)
                                txtformat = "24 bit interface";
                                break;
                        default:
-                               txtformat = "unkown format";
+                               txtformat = "unknown format";
                        }
                } else {
                        switch (format & 7) {
@@ -3298,26 +3298,28 @@ static void aty_init_lcd(struct atyfb_par *par, u32 bios_base)
                                txtformat = "262144 colours (FDPI-2 mode)";
                                break;
                        default:
-                               txtformat = "unkown format";
+                               txtformat = "unknown format";
                        }
                }
                PRINTKI("%s%s %s monitor detected: %s\n",
-                       txtdual ,txtcolour, txtmonitor, model);
+                       txtdualtxtcolour, txtmonitor, model);
                PRINTKI("       id=%d, %dx%d pixels, %s\n",
                        id, width, height, txtformat);
                refresh_rates_buf[0] = 0;
                refresh_rates = *(u16 *)(par->lcd_table+62);
                m = 1;
                f = 0;
-               for (i=0;i<16;i++) {
+               for (i = 0; i < 16; i++) {
                        if (refresh_rates & m) {
                                if (f == 0) {
-                                       sprintf(strbuf, "%d", lcd_refresh_rates[i]);
+                                       sprintf(strbuf, "%d",
+                                               lcd_refresh_rates[i]);
                                        f++;
                                } else {
-                                       sprintf(strbuf, ",%d", lcd_refresh_rates[i]);
+                                       sprintf(strbuf, ",%d",
+                                               lcd_refresh_rates[i]);
                                }
-                               strcat(refresh_rates_buf,strbuf);
+                               strcat(refresh_rates_buf, strbuf);
                        }
                        m = m << 1;
                }
@@ -3325,7 +3327,8 @@ static void aty_init_lcd(struct atyfb_par *par, u32 bios_base)
                PRINTKI("       supports refresh rates [%s], default %d Hz\n",
                        refresh_rates_buf, lcd_refresh_rates[default_refresh_rate]);
                par->lcd_refreshrate = lcd_refresh_rates[default_refresh_rate];
-               /* We now need to determine the crtc parameters for the
+               /*
+                * We now need to determine the crtc parameters for the
                 * LCD monitor. This is tricky, because they are not stored
                 * individually in the BIOS. Instead, the BIOS contains a
                 * table of display modes that work for this monitor.
@@ -3454,13 +3457,15 @@ static int __devinit init_from_bios(struct atyfb_par *par)
                PRINTKE("no BIOS frequency table found, use parameters\n");
                ret = -ENXIO;
        }
-       iounmap((void* __iomem )bios_base);
+       iounmap((void __iomem *)bios_base);
 
        return ret;
 }
 #endif /* __i386__ */
 
-static int __devinit atyfb_setup_generic(struct pci_dev *pdev, struct fb_info *info, unsigned long addr)
+static int __devinit atyfb_setup_generic(struct pci_dev *pdev,
+                                        struct fb_info *info,
+                                        unsigned long addr)
 {
        struct atyfb_par *par = info->par;
        u16 tmp;
@@ -3479,7 +3484,7 @@ static int __devinit atyfb_setup_generic(struct pci_dev *pdev, struct fb_info *i
 
        info->fix.mmio_start = raddr;
        par->ati_regbase = ioremap(info->fix.mmio_start, 0x1000);
-       if (par->ati_regbase == 0)
+       if (par->ati_regbase == NULL)
                return -ENOMEM;
 
        info->fix.mmio_start += par->aux_start ? 0x400 : 0xc00;
@@ -3507,10 +3512,12 @@ static int __devinit atyfb_setup_generic(struct pci_dev *pdev, struct fb_info *i
                goto atyfb_setup_generic_fail;
        }
 
-       if((ret = correct_chipset(par)))
+       ret = correct_chipset(par);
+       if (ret)
                goto atyfb_setup_generic_fail;
 #ifdef __i386__
-       if((ret = init_from_bios(par)))
+       ret = init_from_bios(par);
+       if (ret)
                goto atyfb_setup_generic_fail;
 #endif
        if (!(aty_ld_le32(CRTC_GEN_CNTL, par) & CRTC_EXT_DISP_EN))
@@ -3535,20 +3542,14 @@ atyfb_setup_generic_fail:
 
 #endif /* !__sparc__ */
 
-static int __devinit atyfb_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
+static int __devinit atyfb_pci_probe(struct pci_dev *pdev,
+                                    const struct pci_device_id *ent)
 {
        unsigned long addr, res_start, res_size;
        struct fb_info *info;
        struct resource *rp;
        struct atyfb_par *par;
-       int i, rc = -ENOMEM;
-
-       for (i = ARRAY_SIZE(aty_chips) - 1; i >= 0; i--)
-               if (pdev->device == aty_chips[i].pci_id)
-                       break;
-
-       if (i < 0)
-               return -ENODEV;
+       int rc = -ENOMEM;
 
        /* Enable device in PCI config */
        if (pci_enable_device(pdev)) {
@@ -3567,10 +3568,10 @@ static int __devinit atyfb_pci_probe(struct pci_dev *pdev, const struct pci_devi
        /* Reserve space */
        res_start = rp->start;
        res_size = rp->end - rp->start + 1;
-       if (!request_mem_region (res_start, res_size, "atyfb"))
+       if (!request_mem_region(res_start, res_size, "atyfb"))
                return -EBUSY;
 
-        /* Allocate framebuffer */
+       /* Allocate framebuffer */
        info = framebuffer_alloc(sizeof(struct atyfb_par), &pdev->dev);
        if (!info) {
                PRINTKE("atyfb_pci_probe() can't alloc fb_info\n");
@@ -3579,7 +3580,7 @@ static int __devinit atyfb_pci_probe(struct pci_dev *pdev, const struct pci_devi
        par = info->par;
        info->fix = atyfb_fix;
        info->device = &pdev->dev;
-       par->pci_id = aty_chips[i].pci_id;
+       par->pci_id = pdev->device;
        par->res_start = res_start;
        par->res_size = res_size;
        par->irq = pdev->irq;
@@ -3597,13 +3598,11 @@ static int __devinit atyfb_pci_probe(struct pci_dev *pdev, const struct pci_devi
        pci_set_drvdata(pdev, info);
 
        /* Init chip & register framebuffer */
-       if (aty_init(info, "PCI"))
+       rc = aty_init(info);
+       if (rc)
                goto err_release_io;
 
 #ifdef __sparc__
-       if (!prom_palette)
-               prom_palette = atyfb_palette;
-
        /*
         * Add /dev/fb mmap values.
         */
@@ -3619,6 +3618,11 @@ static int __devinit atyfb_pci_probe(struct pci_dev *pdev, const struct pci_devi
        par->mmap_map[1].prot_flag = _PAGE_E;
 #endif /* __sparc__ */
 
+       mutex_lock(&reboot_lock);
+       if (!reboot_info)
+               reboot_info = info;
+       mutex_unlock(&reboot_lock);
+
        return 0;
 
 err_release_io:
@@ -3644,17 +3648,19 @@ err_release_mem:
 
 #ifdef CONFIG_ATARI
 
-static int __devinit atyfb_atari_probe(void)
+static int __init atyfb_atari_probe(void)
 {
        struct atyfb_par *par;
        struct fb_info *info;
        int m64_num;
        u32 clock_r;
+       int num_found = 0;
 
        for (m64_num = 0; m64_num < mach64_count; m64_num++) {
                if (!phys_vmembase[m64_num] || !phys_size[m64_num] ||
                    !phys_guiregbase[m64_num]) {
-                   PRINTKI("phys_*[%d] parameters not set => returning early. \n", m64_num);
+                       PRINTKI("phys_*[%d] parameters not set => "
+                               "returning early. \n", m64_num);
                        continue;
                }
 
@@ -3670,8 +3676,8 @@ static int __devinit atyfb_atari_probe(void)
                par->irq = (unsigned int) -1; /* something invalid */
 
                /*
-                *  Map the video memory (physical address given) to somewhere in the
-                *  kernel address space.
+                * Map the video memory (physical address given)
+                * to somewhere in the kernel address space.
                 */
                info->screen_base = ioremap(phys_vmembase[m64_num], phys_size[m64_num]);
                info->fix.smem_start = (unsigned long)info->screen_base; /* Fake! */
@@ -3697,16 +3703,28 @@ static int __devinit atyfb_atari_probe(void)
                        break;
                }
 
-               if (aty_init(info, "ISA bus")) {
-                       if (info->screen_base)
-                               iounmap(info->screen_base);
-                       if (par->ati_regbase)
-                               iounmap(par->ati_regbase);
+               /* Fake pci_id for correct_chipset() */
+               switch (aty_ld_le32(CNFG_CHIP_ID, par) & CFG_CHIP_TYPE) {
+               case 0x00d7:
+                       par->pci_id = PCI_CHIP_MACH64GX;
+                       break;
+               case 0x0057:
+                       par->pci_id = PCI_CHIP_MACH64CX;
+                       break;
+               default:
+                       break;
+               }
+
+               if (correct_chipset(par) || aty_init(info)) {
+                       iounmap(info->screen_base);
+                       iounmap(par->ati_regbase);
                        framebuffer_release(info);
-                       /* This is insufficient! kernel_map has added two large chunks!! */
-                       return -ENXIO;
+               } else {
+                       num_found++;
                }
        }
+
+       return num_found ? 0 : -ENXIO;
 }
 
 #endif /* CONFIG_ATARI */
@@ -3718,24 +3736,24 @@ static void __devexit atyfb_remove(struct fb_info *info)
        struct atyfb_par *par = (struct atyfb_par *) info->par;
 
        /* restore video mode */
-       aty_set_crtc(par, &saved_crtc);
-       par->pll_ops->set_pll(info, &saved_pll);
+       aty_set_crtc(par, &par->saved_crtc);
+       par->pll_ops->set_pll(info, &par->saved_pll);
+
+       unregister_framebuffer(info);
 
 #ifdef CONFIG_FB_ATY_BACKLIGHT
        if (M64_HAS(MOBIL_BUS))
-               aty_bl_exit(par);
+               aty_bl_exit(info->bl_dev);
 #endif
 
-       unregister_framebuffer(info);
-
 #ifdef CONFIG_MTRR
        if (par->mtrr_reg >= 0) {
-           mtrr_del(par->mtrr_reg, 0, 0);
-           par->mtrr_reg = -1;
+               mtrr_del(par->mtrr_reg, 0, 0);
+               par->mtrr_reg = -1;
        }
        if (par->mtrr_aper >= 0) {
-           mtrr_del(par->mtrr_aper, 0, 0);
-           par->mtrr_aper = -1;
+               mtrr_del(par->mtrr_aper, 0, 0);
+               par->mtrr_aper = -1;
        }
 #endif
 #ifndef __sparc__
@@ -3765,21 +3783,70 @@ static void __devexit atyfb_pci_remove(struct pci_dev *pdev)
 {
        struct fb_info *info = pci_get_drvdata(pdev);
 
+       mutex_lock(&reboot_lock);
+       if (reboot_info == info)
+               reboot_info = NULL;
+       mutex_unlock(&reboot_lock);
+
        atyfb_remove(info);
 }
 
-/*
- * This driver uses its own matching table. That will be more difficult
- * to fix, so for now, we just match against any ATI ID and let the
- * probe() function find out what's up. That also mean we don't have
- * a module ID table though.
- */
 static struct pci_device_id atyfb_pci_tbl[] = {
-       { PCI_VENDOR_ID_ATI, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
-         PCI_BASE_CLASS_DISPLAY << 16, 0xff0000, 0 },
-       { 0, }
+#ifdef CONFIG_FB_ATY_GX
+       { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_CHIP_MACH64GX) },
+       { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_CHIP_MACH64CX) },
+#endif /* CONFIG_FB_ATY_GX */
+
+#ifdef CONFIG_FB_ATY_CT
+       { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_CHIP_MACH64CT) },
+       { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_CHIP_MACH64ET) },
+
+       { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_CHIP_MACH64LT) },
+
+       { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_CHIP_MACH64VT) },
+       { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_CHIP_MACH64GT) },
+
+       { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_CHIP_MACH64VU) },
+       { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_CHIP_MACH64GU) },
+
+       { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_CHIP_MACH64LG) },
+
+       { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_CHIP_MACH64VV) },
+
+       { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_CHIP_MACH64GV) },
+       { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_CHIP_MACH64GW) },
+       { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_CHIP_MACH64GY) },
+       { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_CHIP_MACH64GZ) },
+
+       { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_CHIP_MACH64GB) },
+       { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_CHIP_MACH64GD) },
+       { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_CHIP_MACH64GI) },
+       { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_CHIP_MACH64GP) },
+       { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_CHIP_MACH64GQ) },
+
+       { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_CHIP_MACH64LB) },
+       { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_CHIP_MACH64LD) },
+       { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_CHIP_MACH64LI) },
+       { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_CHIP_MACH64LP) },
+       { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_CHIP_MACH64LQ) },
+
+       { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_CHIP_MACH64GM) },
+       { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_CHIP_MACH64GN) },
+       { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_CHIP_MACH64GO) },
+       { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_CHIP_MACH64GL) },
+       { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_CHIP_MACH64GR) },
+       { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_CHIP_MACH64GS) },
+
+       { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_CHIP_MACH64LM) },
+       { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_CHIP_MACH64LN) },
+       { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_CHIP_MACH64LR) },
+       { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_CHIP_MACH64LS) },
+#endif /* CONFIG_FB_ATY_CT */
+       { }
 };
 
+MODULE_DEVICE_TABLE(pci, atyfb_pci_tbl);
+
 static struct pci_driver atyfb_driver = {
        .name           = "atyfb",
        .id_table       = atyfb_pci_tbl,
@@ -3794,7 +3861,7 @@ static struct pci_driver atyfb_driver = {
 #endif /* CONFIG_PCI */
 
 #ifndef MODULE
-static int __devinit atyfb_setup(char *options)
+static int __init atyfb_setup(char *options)
 {
        char *this_opt;
 
@@ -3818,6 +3885,8 @@ static int __devinit atyfb_setup(char *options)
                        xclk = simple_strtoul(this_opt+5, NULL, 0);
                else if (!strncmp(this_opt, "comp_sync:", 10))
                        comp_sync = simple_strtoul(this_opt+10, NULL, 0);
+               else if (!strncmp(this_opt, "backlight:", 10))
+                       backlight = simple_strtoul(this_opt+10, NULL, 0);
 #ifdef CONFIG_PPC
                else if (!strncmp(this_opt, "vmode:", 6)) {
                        unsigned int vmode =
@@ -3866,29 +3935,88 @@ static int __devinit atyfb_setup(char *options)
 }
 #endif  /*  MODULE  */
 
-static int __devinit atyfb_init(void)
+static int atyfb_reboot_notify(struct notifier_block *nb,
+                              unsigned long code, void *unused)
 {
-    int err1 = 1, err2 = 1;
+       struct atyfb_par *par;
+
+       if (code != SYS_RESTART)
+               return NOTIFY_DONE;
+
+       mutex_lock(&reboot_lock);
+
+       if (!reboot_info)
+               goto out;
+
+       if (!lock_fb_info(reboot_info))
+               goto out;
+
+       par = reboot_info->par;
+
+       /*
+        * HP OmniBook 500's BIOS doesn't like the state of the
+        * hardware after atyfb has been used. Restore the hardware
+        * to the original state to allow successful reboots.
+        */
+       aty_set_crtc(par, &par->saved_crtc);
+       par->pll_ops->set_pll(reboot_info, &par->saved_pll);
+
+       unlock_fb_info(reboot_info);
+ out:
+       mutex_unlock(&reboot_lock);
+
+       return NOTIFY_DONE;
+}
+
+static struct notifier_block atyfb_reboot_notifier = {
+       .notifier_call = atyfb_reboot_notify,
+};
+
+static const struct dmi_system_id atyfb_reboot_ids[] = {
+       {
+               .ident = "HP OmniBook 500",
+               .matches = {
+                       DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
+                       DMI_MATCH(DMI_PRODUCT_NAME, "HP OmniBook PC"),
+                       DMI_MATCH(DMI_PRODUCT_VERSION, "HP OmniBook 500 FA"),
+               },
+       },
+
+       { }
+};
+
+static int __init atyfb_init(void)
+{
+       int err1 = 1, err2 = 1;
 #ifndef MODULE
-    char *option = NULL;
+       char *option = NULL;
 
-    if (fb_get_options("atyfb", &option))
-       return -ENODEV;
-    atyfb_setup(option);
+       if (fb_get_options("atyfb", &option))
+               return -ENODEV;
+       atyfb_setup(option);
 #endif
 
 #ifdef CONFIG_PCI
-    err1 = pci_register_driver(&atyfb_driver);
+       err1 = pci_register_driver(&atyfb_driver);
 #endif
 #ifdef CONFIG_ATARI
-    err2 = atyfb_atari_probe();
+       err2 = atyfb_atari_probe();
 #endif
 
-    return (err1 && err2) ? -ENODEV : 0;
+       if (err1 && err2)
+               return -ENODEV;
+
+       if (dmi_check_system(atyfb_reboot_ids))
+               register_reboot_notifier(&atyfb_reboot_notifier);
+
+       return 0;
 }
 
 static void __exit atyfb_exit(void)
 {
+       if (dmi_check_system(atyfb_reboot_ids))
+               unregister_reboot_notifier(&atyfb_reboot_notifier);
+
 #ifdef CONFIG_PCI
        pci_unregister_driver(&atyfb_driver);
 #endif
@@ -3910,8 +4038,7 @@ MODULE_PARM_DESC(mclk, "int: override memory clock");
 module_param(xclk, int, 0);
 MODULE_PARM_DESC(xclk, "int: override accelerated engine clock");
 module_param(comp_sync, int, 0);
-MODULE_PARM_DESC(comp_sync,
-                "Set composite sync signal to low (0) or high (1)");
+MODULE_PARM_DESC(comp_sync, "Set composite sync signal to low (0) or high (1)");
 module_param(mode, charp, 0);
 MODULE_PARM_DESC(mode, "Specify resolution as \"<xres>x<yres>[-<bpp>][@<refresh>]\" ");
 #ifdef CONFIG_MTRR