Pull platform-drivers into test branch
[safe/jmp/linux-2.6] / drivers / video / aty / aty128fb.c
index db878fd..2e976ff 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>
 
 #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},
@@ -123,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,
@@ -335,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,
@@ -345,15 +343,15 @@ 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;
@@ -445,9 +443,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);
@@ -458,6 +456,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))
@@ -573,7 +575,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;
@@ -772,7 +774,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;
@@ -856,7 +858,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;
@@ -903,7 +905,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,25 +1261,11 @@ static void aty128_set_lcd_enable(struct aty128fb_par *par, int on)
                reg &= ~LVDS_DISPLAY_DIS;
                aty_st_le32(LVDS_GEN_CNTL, reg);
 #ifdef CONFIG_FB_ATY128_BACKLIGHT
-               mutex_lock(&info->bl_mutex);
-               if (info->bl_dev) {
-                       down(&info->bl_dev->sem);
-                       info->bl_dev->props->update_status(info->bl_dev);
-                       up(&info->bl_dev->sem);
-               }
-               mutex_unlock(&info->bl_mutex);
+               aty128_bl_set_power(info, FB_BLANK_UNBLANK);
 #endif 
        } else {
 #ifdef CONFIG_FB_ATY128_BACKLIGHT
-               mutex_lock(&info->bl_mutex);
-               if (info->bl_dev) {
-                       down(&info->bl_dev->sem);
-                       info->bl_dev->props->brightness = 0;
-                       info->bl_dev->props->power = FB_BLANK_POWERDOWN;
-                       info->bl_dev->props->update_status(info->bl_dev);
-                       up(&info->bl_dev->sem);
-               }
-               mutex_unlock(&info->bl_mutex);
+               aty128_bl_set_power(info, FB_BLANK_POWERDOWN);
 #endif 
                reg = aty_ld_le32(LVDS_GEN_CNTL);
                reg |= LVDS_DISPLAY_DIS;
@@ -1345,6 +1333,8 @@ static int aty128_var_to_pll(u32 period_in_ps, struct aty128_pll *pll,
        if (vclk * 12 < c.ppll_min)
                vclk = c.ppll_min/12;
 
+       pll->post_divider = -1;
+
        /* now, find an acceptable divider */
        for (i = 0; i < sizeof(post_dividers); i++) {
                output_freq = post_dividers[i] * vclk;
@@ -1354,6 +1344,9 @@ static int aty128_var_to_pll(u32 period_in_ps, struct aty128_pll *pll,
                }
        }
 
+       if (pll->post_divider < 0)
+               return -EINVAL;
+
        /* calculate feedback divider */
        n = c.ref_divider * output_freq;
        d = c.ref_clk;
@@ -1645,7 +1638,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;
 
@@ -1704,6 +1697,7 @@ static int __init aty128fb_setup(char *options)
 
 static struct backlight_properties aty128_bl_data;
 
+/* Call with fb_info->bl_mutex held */
 static int aty128_bl_get_level_brightness(struct aty128fb_par *par,
                int level)
 {
@@ -1711,10 +1705,8 @@ static int aty128_bl_get_level_brightness(struct aty128fb_par *par,
        int atylevel;
 
        /* Get and convert the value */
-       mutex_lock(&info->bl_mutex);
        atylevel = MAX_LEVEL -
                (info->bl_curve[level] * FB_BACKLIGHT_MAX / MAX_LEVEL);
-       mutex_unlock(&info->bl_mutex);
 
        if (atylevel < 0)
                atylevel = 0;
@@ -1732,7 +1724,8 @@ static int aty128_bl_get_level_brightness(struct aty128fb_par *par,
 /* That one prevents proper CRT output with LCD off */
 #undef BACKLIGHT_DAC_OFF
 
-static int aty128_bl_update_status(struct backlight_device *bd)
+/* Call with fb_info->bl_mutex held */
+static int __aty128_bl_update_status(struct backlight_device *bd)
 {
        struct aty128fb_par *par = class_get_devdata(&bd->class_dev);
        unsigned int reg = aty_ld_le32(LVDS_GEN_CNTL);
@@ -1785,6 +1778,19 @@ static int aty128_bl_update_status(struct backlight_device *bd)
        return 0;
 }
 
+static int aty128_bl_update_status(struct backlight_device *bd)
+{
+       struct aty128fb_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 = __aty128_bl_update_status(bd);
+       mutex_unlock(&info->bl_mutex);
+
+       return ret;
+}
+
 static int aty128_bl_get_brightness(struct backlight_device *bd)
 {
        return bd->props->brightness;
@@ -1797,6 +1803,20 @@ static struct backlight_properties aty128_bl_data = {
        .max_brightness = (FB_BACKLIGHT_LEVELS - 1),
 };
 
+static void aty128_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;
+               __aty128_bl_update_status(info->bl_dev);
+               up(&info->bl_dev->sem);
+       }
+
+       mutex_unlock(&info->bl_mutex);
+}
+
 static void aty128_bl_init(struct aty128fb_par *par)
 {
        struct fb_info *info = pci_get_drvdata(par->pdev);
@@ -1814,10 +1834,10 @@ static void aty128_bl_init(struct aty128fb_par *par)
 
        snprintf(name, sizeof(name), "aty128bl%d", info->node);
 
-       bd = backlight_device_register(name, par, &aty128_bl_data);
+       bd = backlight_device_register(name, info->dev, par, &aty128_bl_data);
        if (IS_ERR(bd)) {
                info->bl_dev = NULL;
-               printk("aty128: Backlight registration failed\n");
+               printk(KERN_WARNING "aty128: Backlight registration failed\n");
                goto error;
        }
 
@@ -1828,11 +1848,11 @@ static void aty128_bl_init(struct aty128fb_par *par)
                219 * FB_BACKLIGHT_MAX / MAX_LEVEL);
        mutex_unlock(&info->bl_mutex);
 
-       up(&bd->sem);
+       down(&bd->sem);
        bd->props->brightness = aty128_bl_data.max_brightness;
        bd->props->power = FB_BLANK_UNBLANK;
        bd->props->update_status(bd);
-       down(&bd->sem);
+       up(&bd->sem);
 
 #ifdef CONFIG_PMAC_BACKLIGHT
        mutex_lock(&pmac_backlight_mutex);
@@ -1893,7 +1913,7 @@ static void aty128_early_resume(void *data)
 }
 #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;
@@ -1902,9 +1922,6 @@ static int __init aty128_init(struct pci_dev *pdev, const struct pci_device_id *
        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;
 
@@ -2017,9 +2034,6 @@ 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;
-
        par->pm_reg = pci_find_capability(pdev, PCI_CAP_ID_PM);
        par->pdev = pdev;
        par->asleep = 0;
@@ -2029,6 +2043,9 @@ static int __init aty128_init(struct pci_dev *pdev, const struct pci_device_id *
        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);
 
@@ -2037,7 +2054,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;
@@ -2078,7 +2095,6 @@ 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;
@@ -2199,12 +2215,8 @@ static int aty128fb_blank(int blank, struct fb_info *fb)
                return 0;
 
 #ifdef CONFIG_FB_ATY128_BACKLIGHT
-       if (machine_is(powermac) && blank) {
-               down(&fb->bl_dev->sem);
-               fb->bl_dev->props->power = FB_BLANK_POWERDOWN;
-               fb->bl_dev->props->update_status(fb->bl_dev);
-               up(&fb->bl_dev->sem);
-       }
+       if (machine_is(powermac) && blank)
+               aty128_bl_set_power(fb, FB_BLANK_POWERDOWN);
 #endif
 
        if (blank & FB_BLANK_VSYNC_SUSPEND)
@@ -2220,14 +2232,12 @@ static int aty128fb_blank(int blank, struct fb_info *fb)
                aty128_set_crt_enable(par, par->crt_on && !blank);
                aty128_set_lcd_enable(par, par->lcd_on && !blank);
        }
+
 #ifdef CONFIG_FB_ATY128_BACKLIGHT
-       if (machine_is(powermac) && !blank) {
-               down(&fb->bl_dev->sem);
-               fb->bl_dev->props->power = FB_BLANK_UNBLANK;
-               fb->bl_dev->props->update_status(fb->bl_dev);
-               up(&fb->bl_dev->sem);
-       }
+       if (machine_is(powermac) && !blank)
+               aty128_bl_set_power(fb, FB_BLANK_UNBLANK);
 #endif
+
        return 0;
 }
 
@@ -2556,7 +2566,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;