perf report: Fix --no-call-chain option handling
[safe/jmp/linux-2.6] / drivers / video / aty / aty128fb.c
index b0eba3a..e4e4d43 100644 (file)
  */
 
 
-#include <linux/config.h>
 #include <linux/module.h>
 #include <linux/moduleparam.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
 #include <linux/string.h>
 #include <linux/mm.h>
-#include <linux/tty.h>
 #include <linux/slab.h>
 #include <linux/vmalloc.h>
 #include <linux/delay.h>
 #include <linux/interrupt.h>
-#include <asm/uaccess.h>
+#include <linux/uaccess.h>
 #include <linux/fb.h>
 #include <linux/init.h>
 #include <linux/pci.h>
 #include <linux/ioport.h>
 #include <linux/console.h>
+#include <linux/backlight.h>
 #include <asm/io.h>
 
 #ifdef CONFIG_PPC_PMAC
+#include <asm/machdep.h>
 #include <asm/pmac_feature.h>
 #include <asm/prom.h>
 #include <asm/pci-bridge.h>
 #undef DEBUG
 
 #ifdef DEBUG
-#define DBG(fmt, args...)              printk(KERN_DEBUG "aty128fb: %s " fmt, __FUNCTION__, ##args);
+#define DBG(fmt, args...)              printk(KERN_DEBUG "aty128fb: %s " fmt, __func__, ##args);
 #else
 #define DBG(fmt, args...)
 #endif
 
 #ifndef CONFIG_PPC_PMAC
 /* default mode */
-static struct fb_var_screeninfo default_var __initdata = {
+static struct fb_var_screeninfo default_var __devinitdata = {
        /* 640x480, 60 Hz, Non-Interlaced (25.175 MHz dotclock) */
        640, 480, 640, 480, 0, 0, 8, 0,
        {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0},
@@ -121,7 +121,7 @@ static struct fb_var_screeninfo default_var = {
 
 /* default modedb mode */
 /* 640x480, 60 Hz, Non-Interlaced (25.172 MHz dotclock) */
-static struct fb_videomode defaultmode __initdata = {
+static struct fb_videomode defaultmode __devinitdata = {
        .refresh =      60,
        .xres =         640,
        .yres =         480,
@@ -333,7 +333,7 @@ static const struct aty128_meminfo sdr_sgram =
 static const struct aty128_meminfo ddr_sgram =
        { 4, 4, 3, 3, 2, 3, 1, 16, 31, 16, "64-bit DDR SGRAM" };
 
-static struct fb_fix_screeninfo aty128fb_fix __initdata = {
+static struct fb_fix_screeninfo aty128fb_fix __devinitdata = {
        .id             = "ATY Rage128",
        .type           = FB_TYPE_PACKED_PIXELS,
        .visual         = FB_VISUAL_PSEUDOCOLOR,
@@ -343,18 +343,24 @@ static struct fb_fix_screeninfo aty128fb_fix __initdata = {
        .accel          = FB_ACCEL_ATI_RAGE128,
 };
 
-static char *mode_option __initdata = NULL;
+static char *mode_option __devinitdata = NULL;
 
 #ifdef CONFIG_PPC_PMAC
-static int default_vmode __initdata = VMODE_1024_768_60;
-static int default_cmode __initdata = CMODE_8;
+static int default_vmode __devinitdata = VMODE_1024_768_60;
+static int default_cmode __devinitdata = CMODE_8;
 #endif
 
-static int default_crt_on __initdata = 0;
-static int default_lcd_on __initdata = 1;
+static int default_crt_on __devinitdata = 0;
+static int default_lcd_on __devinitdata = 1;
 
 #ifdef CONFIG_MTRR
-static int mtrr = 1;
+static bool mtrr = true;
+#endif
+
+#ifdef CONFIG_PMAC_BACKLIGHT
+static int backlight __devinitdata = 1;
+#else
+static int backlight __devinitdata = 0;
 #endif
 
 /* PLL constants */
@@ -431,8 +437,7 @@ static int aty128fb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
 static int aty128fb_pan_display(struct fb_var_screeninfo *var,
                           struct fb_info *fb);
 static int aty128fb_blank(int blank, struct fb_info *fb);
-static int aty128fb_ioctl(struct inode *inode, struct file *file, u_int cmd,
-                         u_long arg, struct fb_info *info);
+static int aty128fb_ioctl(struct fb_info *info, u_int cmd, unsigned long arg);
 static int aty128fb_sync(struct fb_info *info);
 
     /*
@@ -444,9 +449,9 @@ static int aty128_encode_var(struct fb_var_screeninfo *var,
 static int aty128_decode_var(struct fb_var_screeninfo *var,
                              struct aty128fb_par *par);
 #if 0
-static void __init aty128_get_pllinfo(struct aty128fb_par *par,
+static void __devinit aty128_get_pllinfo(struct aty128fb_par *par,
                                      void __iomem *bios);
-static void __init __iomem *aty128_map_ROM(struct pci_dev *pdev, const struct aty128fb_par *par);
+static void __devinit __iomem *aty128_map_ROM(struct pci_dev *pdev, const struct aty128fb_par *par);
 #endif
 static void aty128_timings(struct aty128fb_par *par);
 static void aty128_init_engine(struct aty128fb_par *par);
@@ -457,6 +462,10 @@ static void wait_for_fifo(u16 entries, struct aty128fb_par *par);
 static void wait_for_idle(struct aty128fb_par *par);
 static u32 depth_to_dst(u32 depth);
 
+#ifdef CONFIG_FB_ATY128_BACKLIGHT
+static void aty128_bl_set_power(struct fb_info *info, int power);
+#endif
+
 #define BIOS_IN8(v)    (readb(bios + (v)))
 #define BIOS_IN16(v)   (readb(bios + (v)) | \
                          (readb(bios + (v) + 1) << 8))
@@ -478,19 +487,8 @@ static struct fb_ops aty128fb_ops = {
        .fb_fillrect    = cfb_fillrect,
        .fb_copyarea    = cfb_copyarea,
        .fb_imageblit   = cfb_imageblit,
-       .fb_cursor      = soft_cursor,
 };
 
-#ifdef CONFIG_PMAC_BACKLIGHT
-static int aty128_set_backlight_enable(int on, int level, void* data);
-static int aty128_set_backlight_level(int level, void* data);
-
-static struct backlight_controller aty128_backlight_controller = {
-       aty128_set_backlight_enable,
-       aty128_set_backlight_level
-};
-#endif /* CONFIG_PMAC_BACKLIGHT */
-
     /*
      * Functions to read from/write to the mmio registers
      * - endian conversions may possibly be avoided by
@@ -583,7 +581,7 @@ static void aty_pll_writeupdate(const struct aty128fb_par *par)
 
 
 /* write to the scratch register to test r/w functionality */
-static int __init register_test(const struct aty128fb_par *par)
+static int __devinit register_test(const struct aty128fb_par *par)
 {
        u32 val;
        int flag = 0;
@@ -782,7 +780,7 @@ static u32 depth_to_dst(u32 depth)
 
 
 #ifndef __sparc__
-static void __iomem * __init aty128_map_ROM(const struct aty128fb_par *par, struct pci_dev *dev)
+static void __iomem * __devinit aty128_map_ROM(const struct aty128fb_par *par, struct pci_dev *dev)
 {
        u16 dptr;
        u8 rom_type;
@@ -806,8 +804,8 @@ static void __iomem * __init aty128_map_ROM(const struct aty128fb_par *par, stru
 
        /* Very simple test to make sure it appeared */
        if (BIOS_IN16(0) != 0xaa55) {
-               printk(KERN_ERR "aty128fb: Invalid ROM signature %x should be 0xaa55\n",
-                      BIOS_IN16(0));
+               printk(KERN_DEBUG "aty128fb: Invalid ROM signature %x should "
+                       " be 0xaa55\n", BIOS_IN16(0));
                goto failed;
        }
 
@@ -866,7 +864,7 @@ static void __iomem * __init aty128_map_ROM(const struct aty128fb_par *par, stru
        return NULL;
 }
 
-static void __init aty128_get_pllinfo(struct aty128fb_par *par, unsigned char __iomem *bios)
+static void __devinit aty128_get_pllinfo(struct aty128fb_par *par, unsigned char __iomem *bios)
 {
        unsigned int bios_hdr;
        unsigned int bios_pll;
@@ -913,7 +911,7 @@ static void __iomem *  __devinit aty128_find_mem_vbios(struct aty128fb_par *par)
 #endif /* ndef(__sparc__) */
 
 /* fill in known card constants if pll_block is not available */
-static void __init aty128_timings(struct aty128fb_par *par)
+static void __devinit aty128_timings(struct aty128fb_par *par)
 {
 #ifdef CONFIG_PPC_OF
        /* instead of a table lookup, assume OF has properly
@@ -1259,19 +1257,21 @@ static void aty128_set_crt_enable(struct aty128fb_par *par, int on)
 static void aty128_set_lcd_enable(struct aty128fb_par *par, int on)
 {
        u32 reg;
+#ifdef CONFIG_FB_ATY128_BACKLIGHT
+       struct fb_info *info = pci_get_drvdata(par->pdev);
+#endif
 
        if (on) {
                reg = aty_ld_le32(LVDS_GEN_CNTL);
                reg |= LVDS_ON | LVDS_EN | LVDS_BLON | LVDS_DIGION;
                reg &= ~LVDS_DISPLAY_DIS;
                aty_st_le32(LVDS_GEN_CNTL, reg);
-#ifdef CONFIG_PMAC_BACKLIGHT
-               aty128_set_backlight_enable(get_backlight_enable(),
-                                           get_backlight_level(), par);
+#ifdef CONFIG_FB_ATY128_BACKLIGHT
+               aty128_bl_set_power(info, FB_BLANK_UNBLANK);
 #endif 
        } else {
-#ifdef CONFIG_PMAC_BACKLIGHT
-               aty128_set_backlight_enable(0, 0, par);
+#ifdef CONFIG_FB_ATY128_BACKLIGHT
+               aty128_bl_set_power(info, FB_BLANK_POWERDOWN);
 #endif 
                reg = aty_ld_le32(LVDS_GEN_CNTL);
                reg |= LVDS_DISPLAY_DIS;
@@ -1328,7 +1328,7 @@ static int aty128_var_to_pll(u32 period_in_ps, struct aty128_pll *pll,
        unsigned char post_dividers[] = {1,2,4,8,3,6,12};
        u32 output_freq;
        u32 vclk;        /* in .01 MHz */
-       int i;
+       int i = 0;
        u32 n, d;
 
        vclk = 100000000 / period_in_ps;        /* convert units to 10 kHz */
@@ -1340,17 +1340,21 @@ static int aty128_var_to_pll(u32 period_in_ps, struct aty128_pll *pll,
                vclk = c.ppll_min/12;
 
        /* now, find an acceptable divider */
-       for (i = 0; i < sizeof(post_dividers); i++) {
+       for (i = 0; i < ARRAY_SIZE(post_dividers); i++) {
                output_freq = post_dividers[i] * vclk;
-               if (output_freq >= c.ppll_min && output_freq <= c.ppll_max)
+               if (output_freq >= c.ppll_min && output_freq <= c.ppll_max) {
+                       pll->post_divider = post_dividers[i];
                        break;
+               }
        }
 
+       if (i == ARRAY_SIZE(post_dividers))
+               return -EINVAL;
+
        /* calculate feedback divider */
        n = c.ref_divider * output_freq;
        d = c.ref_clk;
 
-       pll->post_divider = post_dividers[i];
        pll->feedback_divider = round_div(n, d);
        pll->vclk = vclk;
 
@@ -1471,7 +1475,7 @@ static int aty128fb_set_par(struct fb_info *info)
        aty128_set_pll(&par->pll, par);
        aty128_set_fifo(&par->fifo_reg, par);
 
-       config = aty_ld_le32(CONFIG_CNTL) & ~3;
+       config = aty_ld_le32(CNFG_CNTL) & ~3;
 
 #if defined(__BIG_ENDIAN)
        if (par->crtc.bpp == 32)
@@ -1480,7 +1484,7 @@ static int aty128fb_set_par(struct fb_info *info)
                config |= 1;    /* make aperture do 16 bit swapping */
 #endif
 
-       aty_st_le32(CONFIG_CNTL, config);
+       aty_st_le32(CNFG_CNTL, config);
        aty_st_8(CRTC_EXT_CNTL + 1, 0); /* turn the video back on */
 
        info->fix.line_length = (par->crtc.vxres * par->crtc.bpp) >> 3;
@@ -1638,7 +1642,7 @@ static int aty128fb_sync(struct fb_info *info)
 }
 
 #ifndef MODULE
-static int __init aty128fb_setup(char *options)
+static int __devinit aty128fb_setup(char *options)
 {
        char *this_opt;
 
@@ -1652,6 +1656,9 @@ static int __init aty128fb_setup(char *options)
                } else if (!strncmp(this_opt, "crt:", 4)) {
                        default_crt_on = simple_strtoul(this_opt+4, NULL, 0);
                        continue;
+               } else if (!strncmp(this_opt, "backlight:", 10)) {
+                       backlight = simple_strtoul(this_opt+10, NULL, 0);
+                       continue;
                }
 #ifdef CONFIG_MTRR
                if(!strncmp(this_opt, "nomtrr", 6)) {
@@ -1691,45 +1698,193 @@ static int __init aty128fb_setup(char *options)
 }
 #endif  /*  MODULE  */
 
+/* Backlight */
+#ifdef CONFIG_FB_ATY128_BACKLIGHT
+#define MAX_LEVEL 0xFF
+
+static int aty128_bl_get_level_brightness(struct aty128fb_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 = MAX_LEVEL -
+               (info->bl_curve[level] * FB_BACKLIGHT_MAX / MAX_LEVEL);
+
+       if (atylevel < 0)
+               atylevel = 0;
+       else if (atylevel > MAX_LEVEL)
+               atylevel = MAX_LEVEL;
+
+       return atylevel;
+}
+
+/* We turn off the LCD completely instead of just dimming the backlight.
+ * This provides greater power saving and the display is useless without
+ * backlight anyway
+ */
+#define BACKLIGHT_LVDS_OFF
+/* That one prevents proper CRT output with LCD off */
+#undef BACKLIGHT_DAC_OFF
+
+static int aty128_bl_update_status(struct backlight_device *bd)
+{
+       struct aty128fb_par *par = bl_get_data(bd);
+       unsigned int reg = aty_ld_le32(LVDS_GEN_CNTL);
+       int level;
+
+       if (bd->props.power != FB_BLANK_UNBLANK ||
+           bd->props.fb_blank != FB_BLANK_UNBLANK ||
+           !par->lcd_on)
+               level = 0;
+       else
+               level = bd->props.brightness;
+
+       reg |= LVDS_BL_MOD_EN | LVDS_BLON;
+       if (level > 0) {
+               reg |= LVDS_DIGION;
+               if (!(reg & LVDS_ON)) {
+                       reg &= ~LVDS_BLON;
+                       aty_st_le32(LVDS_GEN_CNTL, reg);
+                       aty_ld_le32(LVDS_GEN_CNTL);
+                       mdelay(10);
+                       reg |= LVDS_BLON;
+                       aty_st_le32(LVDS_GEN_CNTL, reg);
+               }
+               reg &= ~LVDS_BL_MOD_LEVEL_MASK;
+               reg |= (aty128_bl_get_level_brightness(par, level) << LVDS_BL_MOD_LEVEL_SHIFT);
+#ifdef BACKLIGHT_LVDS_OFF
+               reg |= LVDS_ON | LVDS_EN;
+               reg &= ~LVDS_DISPLAY_DIS;
+#endif
+               aty_st_le32(LVDS_GEN_CNTL, reg);
+#ifdef BACKLIGHT_DAC_OFF
+               aty_st_le32(DAC_CNTL, aty_ld_le32(DAC_CNTL) & (~DAC_PDWN));
+#endif
+       } else {
+               reg &= ~LVDS_BL_MOD_LEVEL_MASK;
+               reg |= (aty128_bl_get_level_brightness(par, 0) << LVDS_BL_MOD_LEVEL_SHIFT);
+#ifdef BACKLIGHT_LVDS_OFF
+               reg |= LVDS_DISPLAY_DIS;
+               aty_st_le32(LVDS_GEN_CNTL, reg);
+               aty_ld_le32(LVDS_GEN_CNTL);
+               udelay(10);
+               reg &= ~(LVDS_ON | LVDS_EN | LVDS_BLON | LVDS_DIGION);
+#endif
+               aty_st_le32(LVDS_GEN_CNTL, reg);
+#ifdef BACKLIGHT_DAC_OFF
+               aty_st_le32(DAC_CNTL, aty_ld_le32(DAC_CNTL) | DAC_PDWN);
+#endif
+       }
+
+       return 0;
+}
+
+static int aty128_bl_get_brightness(struct backlight_device *bd)
+{
+       return bd->props.brightness;
+}
+
+static struct backlight_ops aty128_bl_data = {
+       .get_brightness = aty128_bl_get_brightness,
+       .update_status  = aty128_bl_update_status,
+};
+
+static void aty128_bl_set_power(struct fb_info *info, int power)
+{
+       if (info->bl_dev) {
+               info->bl_dev->props.power = power;
+               backlight_update_status(info->bl_dev);
+       }
+}
+
+static void aty128_bl_init(struct aty128fb_par *par)
+{
+       struct fb_info *info = pci_get_drvdata(par->pdev);
+       struct backlight_device *bd;
+       char name[12];
+
+       /* Could be extended to Rage128Pro LVDS output too */
+       if (par->chip_gen != rage_M3)
+               return;
+
+#ifdef CONFIG_PMAC_BACKLIGHT
+       if (!pmac_has_backlight_type("ati"))
+               return;
+#endif
+
+       snprintf(name, sizeof(name), "aty128bl%d", info->node);
+
+       bd = backlight_device_register(name, info->dev, par, &aty128_bl_data);
+       if (IS_ERR(bd)) {
+               info->bl_dev = NULL;
+               printk(KERN_WARNING "aty128: Backlight registration failed\n");
+               goto error;
+       }
+
+       info->bl_dev = bd;
+       fb_bl_default_curve(info, 0,
+                63 * FB_BACKLIGHT_MAX / MAX_LEVEL,
+               219 * FB_BACKLIGHT_MAX / MAX_LEVEL);
+
+       bd->props.max_brightness = FB_BACKLIGHT_LEVELS - 1;
+       bd->props.brightness = bd->props.max_brightness;
+       bd->props.power = FB_BLANK_UNBLANK;
+       backlight_update_status(bd);
+
+       printk("aty128: Backlight initialized (%s)\n", name);
+
+       return;
+
+error:
+       return;
+}
+
+static void aty128_bl_exit(struct backlight_device *bd)
+{
+       backlight_device_unregister(bd);
+       printk("aty128: Backlight unloaded\n");
+}
+#endif /* CONFIG_FB_ATY128_BACKLIGHT */
 
 /*
  *  Initialisation
  */
 
-#ifdef CONFIG_PPC_PMAC
+#ifdef CONFIG_PPC_PMAC__disabled
 static void aty128_early_resume(void *data)
 {
         struct aty128fb_par *par = data;
 
        if (try_acquire_console_sem())
                return;
+       pci_restore_state(par->pdev);
        aty128_do_resume(par->pdev);
        release_console_sem();
 }
 #endif /* CONFIG_PPC_PMAC */
 
-static int __init aty128_init(struct pci_dev *pdev, const struct pci_device_id *ent)
+static int __devinit aty128_init(struct pci_dev *pdev, const struct pci_device_id *ent)
 {
        struct fb_info *info = pci_get_drvdata(pdev);
        struct aty128fb_par *par = info->par;
        struct fb_var_screeninfo var;
-       char video_card[DEVICE_NAME_SIZE];
+       char video_card[50];
        u8 chip_rev;
        u32 dac;
 
-       if (!par->vram_size)    /* may have already been probed */
-               par->vram_size = aty_ld_le32(CONFIG_MEMSIZE) & 0x03FFFFFF;
-
        /* Get the chip revision */
-       chip_rev = (aty_ld_le32(CONFIG_CNTL) >> 16) & 0x1F;
+       chip_rev = (aty_ld_le32(CNFG_CNTL) >> 16) & 0x1F;
 
        strcpy(video_card, "Rage128 XX ");
        video_card[8] = ent->device >> 8;
        video_card[9] = ent->device & 0xFF;
-           
+
        /* range check to make sure */
-       if (ent->driver_data < (sizeof(r128_family)/sizeof(char *)))
-           strncat(video_card, r128_family[ent->driver_data], sizeof(video_card));
+       if (ent->driver_data < ARRAY_SIZE(r128_family))
+           strlcat(video_card, r128_family[ent->driver_data], sizeof(video_card));
 
        printk(KERN_INFO "aty128fb: %s [chip rev 0x%x] ", video_card, chip_rev);
 
@@ -1749,11 +1904,18 @@ static int __init aty128_init(struct pci_dev *pdev, const struct pci_device_id *
 
        var = default_var;
 #ifdef CONFIG_PPC_PMAC
-       if (_machine == _MACH_Pmac) {
+       if (machine_is(powermac)) {
                /* Indicate sleep capability */
                if (par->chip_gen == rage_M3) {
                        pmac_call_feature(PMAC_FTR_DEVICE_CAN_WAKE, NULL, 0, 1);
+#if 0 /* Disable the early video resume hack for now as it's causing problems, among
+       * others we now rely on the PCI core restoring the config space for us, which
+       * isn't the case with that hack, and that code path causes various things to
+       * be called with interrupts off while they shouldn't. I'm leaving the code in
+       * as it can be useful for debugging purposes
+       */
                        pmac_set_early_video_resume(aty128_early_resume, par);
+#endif
                }
 
                /* Find default mode */
@@ -1832,20 +1994,19 @@ static int __init aty128_init(struct pci_dev *pdev, const struct pci_device_id *
 
        aty128_init_engine(par);
 
-       if (register_framebuffer(info) < 0)
-               return 0;
-
-#ifdef CONFIG_PMAC_BACKLIGHT
-       /* Could be extended to Rage128Pro LVDS output too */
-       if (par->chip_gen == rage_M3)
-               register_backlight_controller(&aty128_backlight_controller, par, "ati");
-#endif /* CONFIG_PMAC_BACKLIGHT */
-
        par->pm_reg = pci_find_capability(pdev, PCI_CAP_ID_PM);
        par->pdev = pdev;
        par->asleep = 0;
        par->lock_blank = 0;
-       
+
+#ifdef CONFIG_FB_ATY128_BACKLIGHT
+       if (backlight)
+               aty128_bl_init(par);
+#endif
+
+       if (register_framebuffer(info) < 0)
+               return 0;
+
        printk(KERN_INFO "fb%d: %s frame buffer device on %s\n",
               info->node, info->fix.id, video_card);
 
@@ -1854,7 +2015,7 @@ static int __init aty128_init(struct pci_dev *pdev, const struct pci_device_id *
 
 #ifdef CONFIG_PCI
 /* register a card    ++ajoshi */
-static int __init aty128_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
+static int __devinit aty128_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 {
        unsigned long fb_addr, reg_addr;
        struct aty128fb_par *par;
@@ -1895,17 +2056,16 @@ static int __init aty128_probe(struct pci_dev *pdev, const struct pci_device_id
        par = info->par;
 
        info->pseudo_palette = par->pseudo_palette;
-       info->fix = aty128fb_fix;
 
        /* Virtualize mmio region */
        info->fix.mmio_start = reg_addr;
-       par->regbase = ioremap(reg_addr, pci_resource_len(pdev, 2));
+       par->regbase = pci_ioremap_bar(pdev, 2);
        if (!par->regbase)
                goto err_free_info;
 
        /* Grab memory size from the card */
        // How does this relate to the resource length from the PCI hardware?
-       par->vram_size = aty_ld_le32(CONFIG_MEMSIZE) & 0x03FFFFFF;
+       par->vram_size = aty_ld_le32(CNFG_MEMSIZE) & 0x03FFFFFF;
 
        /* Virtualize the framebuffer */
        info->screen_base = ioremap(fb_addr, par->vram_size);
@@ -1982,6 +2142,11 @@ static void __devexit aty128_remove(struct pci_dev *pdev)
        par = info->par;
 
        unregister_framebuffer(info);
+
+#ifdef CONFIG_FB_ATY128_BACKLIGHT
+       aty128_bl_exit(info->bl_dev);
+#endif
+
 #ifdef CONFIG_MTRR
        if (par->mtrr.vram_valid)
                mtrr_del(par->mtrr.vram, info->fix.smem_start,
@@ -2006,33 +2171,36 @@ static void __devexit aty128_remove(struct pci_dev *pdev)
 static int aty128fb_blank(int blank, struct fb_info *fb)
 {
        struct aty128fb_par *par = fb->par;
-       u8 state = 0;
+       u8 state;
 
        if (par->lock_blank || par->asleep)
                return 0;
 
-#ifdef CONFIG_PMAC_BACKLIGHT
-       if ((_machine == _MACH_Pmac) && blank)
-               set_backlight_enable(0);
-#endif /* CONFIG_PMAC_BACKLIGHT */
-
-       if (blank & FB_BLANK_VSYNC_SUSPEND)
-               state |= 2;
-       if (blank & FB_BLANK_HSYNC_SUSPEND)
-               state |= 1;
-       if (blank & FB_BLANK_POWERDOWN)
-               state |= 4;
-
+       switch (blank) {
+       case FB_BLANK_NORMAL:
+               state = 4;
+               break;
+       case FB_BLANK_VSYNC_SUSPEND:
+               state = 6;
+               break;
+       case FB_BLANK_HSYNC_SUSPEND:
+               state = 5;
+               break;
+       case FB_BLANK_POWERDOWN:
+               state = 7;
+               break;
+       case FB_BLANK_UNBLANK:
+       default:
+               state = 0;
+               break;
+       }
        aty_st_8(CRTC_EXT_CNTL+1, state);
 
        if (par->chip_gen == rage_M3) {
                aty128_set_crt_enable(par, par->crt_on && !blank);
                aty128_set_lcd_enable(par, par->lcd_on && !blank);
        }
-#ifdef CONFIG_PMAC_BACKLIGHT
-       if ((_machine == _MACH_Pmac) && !blank)
-               set_backlight_enable(1);
-#endif /* CONFIG_PMAC_BACKLIGHT */
+
        return 0;
 }
 
@@ -2109,8 +2277,7 @@ static int aty128fb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
 /* in param: u32*      backlight value: 0 to 15 */
 #define FBIO_ATY128_SET_MIRROR _IOW('@', 2, __u32)
 
-static int aty128fb_ioctl(struct inode *inode, struct file *file, u_int cmd,
-                         u_long arg, struct fb_info *info)
+static int aty128fb_ioctl(struct fb_info *info, u_int cmd, u_long arg)
 {
        struct aty128fb_par *par = info->par;
        u32 value;
@@ -2139,73 +2306,6 @@ static int aty128fb_ioctl(struct inode *inode, struct file *file, u_int cmd,
        return -EINVAL;
 }
 
-#ifdef CONFIG_PMAC_BACKLIGHT
-static int backlight_conv[] = {
-       0xff, 0xc0, 0xb5, 0xaa, 0x9f, 0x94, 0x89, 0x7e,
-       0x73, 0x68, 0x5d, 0x52, 0x47, 0x3c, 0x31, 0x24
-};
-
-/* We turn off the LCD completely instead of just dimming the backlight.
- * This provides greater power saving and the display is useless without
- * backlight anyway
- */
-#define BACKLIGHT_LVDS_OFF
-/* That one prevents proper CRT output with LCD off */
-#undef BACKLIGHT_DAC_OFF
-
-static int aty128_set_backlight_enable(int on, int level, void *data)
-{
-       struct aty128fb_par *par = data;
-       unsigned int reg = aty_ld_le32(LVDS_GEN_CNTL);
-
-       if (!par->lcd_on)
-               on = 0;
-       reg |= LVDS_BL_MOD_EN | LVDS_BLON;
-       if (on && level > BACKLIGHT_OFF) {
-               reg |= LVDS_DIGION;
-               if (!(reg & LVDS_ON)) {
-                       reg &= ~LVDS_BLON;
-                       aty_st_le32(LVDS_GEN_CNTL, reg);
-                       (void)aty_ld_le32(LVDS_GEN_CNTL);
-                       mdelay(10);
-                       reg |= LVDS_BLON;
-                       aty_st_le32(LVDS_GEN_CNTL, reg);
-               }
-               reg &= ~LVDS_BL_MOD_LEVEL_MASK;
-               reg |= (backlight_conv[level] << LVDS_BL_MOD_LEVEL_SHIFT);
-#ifdef BACKLIGHT_LVDS_OFF
-               reg |= LVDS_ON | LVDS_EN;
-               reg &= ~LVDS_DISPLAY_DIS;
-#endif
-               aty_st_le32(LVDS_GEN_CNTL, reg);
-#ifdef BACKLIGHT_DAC_OFF
-               aty_st_le32(DAC_CNTL, aty_ld_le32(DAC_CNTL) & (~DAC_PDWN));
-#endif         
-       } else {
-               reg &= ~LVDS_BL_MOD_LEVEL_MASK;
-               reg |= (backlight_conv[0] << LVDS_BL_MOD_LEVEL_SHIFT);
-#ifdef BACKLIGHT_LVDS_OFF
-               reg |= LVDS_DISPLAY_DIS;
-               aty_st_le32(LVDS_GEN_CNTL, reg);
-               (void)aty_ld_le32(LVDS_GEN_CNTL);
-               udelay(10);
-               reg &= ~(LVDS_ON | LVDS_EN | LVDS_BLON | LVDS_DIGION);
-#endif         
-               aty_st_le32(LVDS_GEN_CNTL, reg);
-#ifdef BACKLIGHT_DAC_OFF
-               aty_st_le32(DAC_CNTL, aty_ld_le32(DAC_CNTL) | DAC_PDWN);
-#endif         
-       }
-
-       return 0;
-}
-
-static int aty128_set_backlight_level(int level, void* data)
-{
-       return aty128_set_backlight_enable(1, level, data);
-}
-#endif /* CONFIG_PMAC_BACKLIGHT */
-
 #if 0
     /*
      *  Accelerated functions
@@ -2273,7 +2373,6 @@ static void fbcon_aty128_bmove(struct display *p, int sy, int sx, int dy, int dx
 static void aty128_set_suspend(struct aty128fb_par *par, int suspend)
 {
        u32     pmgt;
-       u16     pwr_command;
        struct pci_dev *pdev = par->pdev;
 
        if (!par->pm_reg)
@@ -2282,6 +2381,8 @@ static void aty128_set_suspend(struct aty128fb_par *par, int suspend)
        /* Set the chip into the appropriate suspend mode (we use D2,
         * D3 would require a complete re-initialisation of the chip,
         * including PCI config registers, clocks, AGP configuration, ...)
+        *
+        * For resume, the core will have already brought us back to D0
         */
        if (suspend) {
                /* Make sure CRTC2 is reset. Remove that the day we decide to
@@ -2299,17 +2400,9 @@ static void aty128_set_suspend(struct aty128fb_par *par, int suspend)
                aty_st_le32(BUS_CNTL1, 0x00000010);
                aty_st_le32(MEM_POWER_MISC, 0x0c830000);
                mdelay(100);
-               pci_read_config_word(pdev, par->pm_reg+PCI_PM_CTRL, &pwr_command);
+
                /* Switch PCI power management to D2 */
-               pci_write_config_word(pdev, par->pm_reg+PCI_PM_CTRL,
-                       (pwr_command & ~PCI_PM_CTRL_STATE_MASK) | 2);
-               pci_read_config_word(pdev, par->pm_reg+PCI_PM_CTRL, &pwr_command);
-       } else {
-               /* Switch back PCI power management to D0 */
-               mdelay(100);
-               pci_write_config_word(pdev, par->pm_reg+PCI_PM_CTRL, 0);
-               pci_read_config_word(pdev, par->pm_reg+PCI_PM_CTRL, &pwr_command);
-               mdelay(100);
+               pci_set_power_state(pdev, PCI_D2);
        }
 }
 
@@ -2318,6 +2411,12 @@ static int aty128_pci_suspend(struct pci_dev *pdev, pm_message_t state)
        struct fb_info *info = pci_get_drvdata(pdev);
        struct aty128fb_par *par = info->par;
 
+       /* 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);
+
        /* We don't do anything but D2, for now we return 0, but
         * we may want to change that. How do we know if the BIOS
         * can properly take care of D3 ? Also, with swsusp, we
@@ -2347,7 +2446,7 @@ static int aty128_pci_suspend(struct pci_dev *pdev, pm_message_t state)
        wait_for_idle(par);
 
        /* Blank display and LCD */
-       aty128fb_blank(VESA_POWERDOWN, info);
+       aty128fb_blank(FB_BLANK_POWERDOWN, info);
 
        /* Sleep */
        par->asleep = 1;
@@ -2384,6 +2483,11 @@ static int aty128_do_resume(struct pci_dev *pdev)
        if (pdev->dev.power.power_state.event == PM_EVENT_ON)
                return 0;
 
+       /* PCI state will have been restored by the core, so
+        * we should be in D0 now with our config space fully
+        * restored
+        */
+
        /* Wakeup chip */
        aty128_set_suspend(par, 0);
        par->asleep = 0;
@@ -2429,7 +2533,7 @@ static int aty128_pci_resume(struct pci_dev *pdev)
 }
 
 
-static int __init aty128fb_init(void)
+static int __devinit aty128fb_init(void)
 {
 #ifndef MODULE
        char *option = NULL;