fbdev: fix integer as NULL pointer warning
[safe/jmp/linux-2.6] / drivers / video / aty / radeon_base.c
index 0ed577e..400e926 100644 (file)
 
 #define RADEON_VERSION "0.2.0"
 
+#include "radeonfb.h"
+
 #include <linux/module.h>
 #include <linux/moduleparam.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
 #include <linux/string.h>
+#include <linux/ctype.h>
 #include <linux/mm.h>
 #include <linux/slab.h>
 #include <linux/delay.h>
@@ -69,7 +72,7 @@
 #include <linux/device.h>
 
 #include <asm/io.h>
-#include <asm/uaccess.h>
+#include <linux/uaccess.h>
 
 #ifdef CONFIG_PPC_OF
 
@@ -91,7 +94,6 @@
 
 #include "../edid.h" // MOVE THAT TO include/video
 #include "ati_ids.h"
-#include "radeonfb.h"              
 
 #define MAX_MAPPED_VRAM        (2048*2048*4)
 #define MIN_MAPPED_VRAM        (1024*768*1)
        { PCI_VENDOR_ID_ATI, id, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (flags) | (CHIP_FAMILY_##family) }
 
 static struct pci_device_id radeonfb_pci_table[] = {
+        /* Radeon Xpress 200m */
+       CHIP_DEF(PCI_CHIP_RS480_5955,   RS480,  CHIP_HAS_CRTC2 | CHIP_IS_IGP | CHIP_IS_MOBILITY),
+       CHIP_DEF(PCI_CHIP_RS482_5975,   RS480,  CHIP_HAS_CRTC2 | CHIP_IS_IGP | CHIP_IS_MOBILITY),
        /* Mobility M6 */
        CHIP_DEF(PCI_CHIP_RADEON_LY,    RV100,  CHIP_HAS_CRTC2 | CHIP_IS_MOBILITY),
        CHIP_DEF(PCI_CHIP_RADEON_LZ,    RV100,  CHIP_HAS_CRTC2 | CHIP_IS_MOBILITY),
@@ -142,6 +147,8 @@ static struct pci_device_id radeonfb_pci_table[] = {
        /* 9000/Pro */
        CHIP_DEF(PCI_CHIP_RV250_If,     RV250,  CHIP_HAS_CRTC2),
        CHIP_DEF(PCI_CHIP_RV250_Ig,     RV250,  CHIP_HAS_CRTC2),
+
+       CHIP_DEF(PCI_CHIP_RC410_5A62,   RC410,  CHIP_HAS_CRTC2 | CHIP_IS_IGP | CHIP_IS_MOBILITY),
        /* Mobility 9100 IGP (U3) */
        CHIP_DEF(PCI_CHIP_RS300_5835,   RS300,  CHIP_HAS_CRTC2 | CHIP_IS_IGP | CHIP_IS_MOBILITY),
        CHIP_DEF(PCI_CHIP_RS350_7835,   RS300,  CHIP_HAS_CRTC2 | CHIP_IS_IGP | CHIP_IS_MOBILITY),
@@ -197,6 +204,7 @@ static struct pci_device_id radeonfb_pci_table[] = {
        CHIP_DEF(PCI_CHIP_RV380_3154,   RV380,  CHIP_HAS_CRTC2 | CHIP_IS_MOBILITY),
        CHIP_DEF(PCI_CHIP_RV370_5B60,   RV380,  CHIP_HAS_CRTC2),
        CHIP_DEF(PCI_CHIP_RV370_5B62,   RV380,  CHIP_HAS_CRTC2),
+       CHIP_DEF(PCI_CHIP_RV370_5B63,   RV380,  CHIP_HAS_CRTC2),
        CHIP_DEF(PCI_CHIP_RV370_5B64,   RV380,  CHIP_HAS_CRTC2),
        CHIP_DEF(PCI_CHIP_RV370_5B65,   RV380,  CHIP_HAS_CRTC2),
        CHIP_DEF(PCI_CHIP_RV370_5460,   RV380,  CHIP_HAS_CRTC2 | CHIP_IS_MOBILITY),
@@ -268,6 +276,11 @@ static int nomtrr = 0;
 #endif
 static int force_sleep;
 static int ignore_devlist;
+#ifdef CONFIG_PMAC_BACKLIGHT
+static int backlight = 1;
+#else
+static int backlight = 0;
+#endif
 
 /*
  * prototypes
@@ -405,7 +418,7 @@ static int  __devinit radeon_find_mem_vbios(struct radeonfb_info *rinfo)
 }
 #endif
 
-#ifdef CONFIG_PPC_OF
+#if defined(CONFIG_PPC_OF) || defined(CONFIG_SPARC)
 /*
  * Read XTAL (ref clock), SCLK and MCLK from Open Firmware device
  * tree. Hopefully, ATI OF driver is kind enough to fill these
@@ -417,7 +430,7 @@ static int __devinit radeon_read_xtal_OF (struct radeonfb_info *rinfo)
 
        if (dp == NULL)
                return -ENODEV;
-       val = get_property(dp, "ATY,RefCLK", NULL);
+       val = of_get_property(dp, "ATY,RefCLK", NULL);
        if (!val || !*val) {
                printk(KERN_WARNING "radeonfb: No ATY,RefCLK property !\n");
                return -EINVAL;
@@ -425,17 +438,17 @@ static int __devinit radeon_read_xtal_OF (struct radeonfb_info *rinfo)
 
        rinfo->pll.ref_clk = (*val) / 10;
 
-       val = get_property(dp, "ATY,SCLK", NULL);
+       val = of_get_property(dp, "ATY,SCLK", NULL);
        if (val && *val)
                rinfo->pll.sclk = (*val) / 10;
 
-       val = get_property(dp, "ATY,MCLK", NULL);
+       val = of_get_property(dp, "ATY,MCLK", NULL);
        if (val && *val)
                rinfo->pll.mclk = (*val) / 10;
 
                return 0;
 }
-#endif /* CONFIG_PPC_OF */
+#endif /* CONFIG_PPC_OF || CONFIG_SPARC */
 
 /*
  * Read PLL infos from chip registers
@@ -640,7 +653,7 @@ static void __devinit radeon_get_pllinfo(struct radeonfb_info *rinfo)
        rinfo->pll.ref_div = INPLL(PPLL_REF_DIV) & PPLL_REF_DIV_MASK;
 
 
-#ifdef CONFIG_PPC_OF
+#if defined(CONFIG_PPC_OF) || defined(CONFIG_SPARC)
        /*
         * Retrieve PLL infos from Open Firmware first
         */
@@ -648,7 +661,7 @@ static void __devinit radeon_get_pllinfo(struct radeonfb_info *rinfo)
                        printk(KERN_INFO "radeonfb: Retrieved PLL infos from Open Firmware\n");
                goto found;
        }
-#endif /* CONFIG_PPC_OF */
+#endif /* CONFIG_PPC_OF || CONFIG_SPARC */
 
        /*
         * Check out if we have an X86 which gave us some PLL informations
@@ -1026,8 +1039,7 @@ int radeon_screen_blank(struct radeonfb_info *rinfo, int blank, int mode_switch)
                break;
        }
 
-       /* let fbcon do a soft blank for us */
-       return (blank == FB_BLANK_NORMAL) ? -EINVAL : 0;
+       return 0;
 }
 
 static int radeonfb_blank (int blank, struct fb_info *info)
@@ -1277,7 +1289,8 @@ static void radeon_write_pll_regs(struct radeonfb_info *rinfo, struct radeon_reg
        if (rinfo->family == CHIP_FAMILY_R300 ||
            rinfo->family == CHIP_FAMILY_RS300 ||
            rinfo->family == CHIP_FAMILY_R350 ||
-           rinfo->family == CHIP_FAMILY_RV350) {
+           rinfo->family == CHIP_FAMILY_RV350 ||
+           rinfo->family == CHIP_FAMILY_RV380 ) {
                if (mode->ppll_ref_div & R300_PPLL_REF_DIV_ACC_MASK) {
                        /* When restoring console mode, use saved PPLL_REF_DIV
                         * setting.
@@ -1477,7 +1490,7 @@ static void radeon_calc_pll_regs(struct radeonfb_info *rinfo, struct radeon_regs
                freq = rinfo->pll.ppll_max;
        if (freq*12 < rinfo->pll.ppll_min)
                freq = rinfo->pll.ppll_min / 12;
-       RTRACE("freq = %lu, PLL min = %u, PLL max = %u\n",
+       pr_debug("freq = %lu, PLL min = %u, PLL max = %u\n",
               freq, rinfo->pll.ppll_min, rinfo->pll.ppll_max);
 
        for (post_div = &post_divs[0]; post_div->divider; ++post_div) {
@@ -1498,7 +1511,7 @@ static void radeon_calc_pll_regs(struct radeonfb_info *rinfo, struct radeon_regs
                post_div = &post_divs[post_div->bitvalue];
                pll_output_freq = post_div->divider * freq;
        }
-       RTRACE("ref_div = %d, ref_clk = %d, output_freq = %d\n",
+       pr_debug("ref_div = %d, ref_clk = %d, output_freq = %d\n",
               rinfo->pll.ref_div, rinfo->pll.ref_clk,
               pll_output_freq);
 
@@ -1508,7 +1521,7 @@ static void radeon_calc_pll_regs(struct radeonfb_info *rinfo, struct radeon_regs
                post_div = &post_divs[post_div->bitvalue];
                pll_output_freq = post_div->divider * freq;
        }
-       RTRACE("ref_div = %d, ref_clk = %d, output_freq = %d\n",
+       pr_debug("ref_div = %d, ref_clk = %d, output_freq = %d\n",
               rinfo->pll.ref_div, rinfo->pll.ref_clk,
               pll_output_freq);
 
@@ -1517,9 +1530,9 @@ static void radeon_calc_pll_regs(struct radeonfb_info *rinfo, struct radeon_regs
        regs->ppll_ref_div = rinfo->pll.ref_div;
        regs->ppll_div_3 = fb_div | (post_div->bitvalue << 16);
 
-       RTRACE("post div = 0x%x\n", post_div->bitvalue);
-       RTRACE("fb_div = 0x%x\n", fb_div);
-       RTRACE("ppll_div_3 = 0x%x\n", regs->ppll_div_3);
+       pr_debug("post div = 0x%x\n", post_div->bitvalue);
+       pr_debug("fb_div = 0x%x\n", fb_div);
+       pr_debug("ppll_div_3 = 0x%x\n", regs->ppll_div_3);
 }
 
 static int radeonfb_set_par(struct fb_info *info)
@@ -1591,9 +1604,9 @@ static int radeonfb_set_par(struct fb_info *info)
        dotClock = 1000000000 / pixClock;
        freq = dotClock / 10; /* x100 */
 
-       RTRACE("hStart = %d, hEnd = %d, hTotal = %d\n",
+       pr_debug("hStart = %d, hEnd = %d, hTotal = %d\n",
                hSyncStart, hSyncEnd, hTotal);
-       RTRACE("vStart = %d, vEnd = %d, vTotal = %d\n",
+       pr_debug("vStart = %d, vEnd = %d, vTotal = %d\n",
                vSyncStart, vSyncEnd, vTotal);
 
        hsync_wid = (hSyncEnd - hSyncStart) / 8;
@@ -1702,16 +1715,16 @@ static int radeonfb_set_par(struct fb_info *info)
                newmode->surf_info[i] = 0;
        }
 
-       RTRACE("h_total_disp = 0x%x\t   hsync_strt_wid = 0x%x\n",
+       pr_debug("h_total_disp = 0x%x\t   hsync_strt_wid = 0x%x\n",
                newmode->crtc_h_total_disp, newmode->crtc_h_sync_strt_wid);
-       RTRACE("v_total_disp = 0x%x\t   vsync_strt_wid = 0x%x\n",
+       pr_debug("v_total_disp = 0x%x\t   vsync_strt_wid = 0x%x\n",
                newmode->crtc_v_total_disp, newmode->crtc_v_sync_strt_wid);
 
        rinfo->bpp = mode->bits_per_pixel;
        rinfo->depth = depth;
 
-       RTRACE("pixclock = %lu\n", (unsigned long)pixClock);
-       RTRACE("freq = %lu\n", (unsigned long)freq);
+       pr_debug("pixclock = %lu\n", (unsigned long)pixClock);
+       pr_debug("freq = %lu\n", (unsigned long)freq);
 
        /* We use PPLL_DIV_3 */
        newmode->clk_cntl_index = 0x300;
@@ -1975,7 +1988,7 @@ static void fixup_memory_mappings(struct radeonfb_info *rinfo)
        if (rinfo->has_CRTC2)
                OUTREG(CRTC2_GEN_CNTL, save_crtc2_gen_cntl);    
 
-       RTRACE("aper_base: %08x MC_FB_LOC to: %08x, MC_AGP_LOC to: %08x\n",
+       pr_debug("aper_base: %08x MC_FB_LOC to: %08x, MC_AGP_LOC to: %08x\n",
                aper_base,
                ((aper_base + aper_size - 1) & 0xffff0000) | (aper_base >> 16),
                0xffff0000 | (agp_base >> 16));
@@ -1990,7 +2003,9 @@ static void radeon_identify_vram(struct radeonfb_info *rinfo)
        /* framebuffer size */
         if ((rinfo->family == CHIP_FAMILY_RS100) ||
             (rinfo->family == CHIP_FAMILY_RS200) ||
-            (rinfo->family == CHIP_FAMILY_RS300)) {
+            (rinfo->family == CHIP_FAMILY_RS300) ||
+            (rinfo->family == CHIP_FAMILY_RC410) ||
+           (rinfo->family == CHIP_FAMILY_RS480) ) {
           u32 tom = INREG(NB_TOM);
           tmp = ((((tom >> 16) - (tom & 0xffff) + 1) << 6) * 1024);
 
@@ -2070,7 +2085,7 @@ static void radeon_identify_vram(struct radeonfb_info *rinfo)
         * ToDo: identify these cases
         */
 
-       RTRACE("radeonfb (%s): Found %ldk of %s %d bits wide videoram\n",
+       pr_debug("radeonfb (%s): Found %ldk of %s %d bits wide videoram\n",
               pci_name(rinfo->pdev),
               rinfo->video_ram / 1024,
               rinfo->vram_ddr ? "DDR" : "SDRAM",
@@ -2095,7 +2110,9 @@ static ssize_t radeon_show_one_edid(char *buf, loff_t off, size_t count, const u
 }
 
 
-static ssize_t radeon_show_edid1(struct kobject *kobj, char *buf, loff_t off, size_t count)
+static ssize_t radeon_show_edid1(struct kobject *kobj,
+                                struct bin_attribute *bin_attr,
+                                char *buf, loff_t off, size_t count)
 {
        struct device *dev = container_of(kobj, struct device, kobj);
        struct pci_dev *pdev = to_pci_dev(dev);
@@ -2106,7 +2123,9 @@ static ssize_t radeon_show_edid1(struct kobject *kobj, char *buf, loff_t off, si
 }
 
 
-static ssize_t radeon_show_edid2(struct kobject *kobj, char *buf, loff_t off, size_t count)
+static ssize_t radeon_show_edid2(struct kobject *kobj,
+                                struct bin_attribute *bin_attr,
+                                char *buf, loff_t off, size_t count)
 {
        struct device *dev = container_of(kobj, struct device, kobj);
        struct pci_dev *pdev = to_pci_dev(dev);
@@ -2119,7 +2138,6 @@ static ssize_t radeon_show_edid2(struct kobject *kobj, char *buf, loff_t off, si
 static struct bin_attribute edid1_attr = {
        .attr   = {
                .name   = "edid1",
-               .owner  = THIS_MODULE,
                .mode   = 0444,
        },
        .size   = EDID_LENGTH,
@@ -2129,7 +2147,6 @@ static struct bin_attribute edid1_attr = {
 static struct bin_attribute edid2_attr = {
        .attr   = {
                .name   = "edid2",
-               .owner  = THIS_MODULE,
                .mode   = 0444,
        },
        .size   = EDID_LENGTH,
@@ -2143,8 +2160,9 @@ static int __devinit radeonfb_pci_register (struct pci_dev *pdev,
        struct fb_info *info;
        struct radeonfb_info *rinfo;
        int ret;
+       unsigned char c1, c2;
 
-       RTRACE("radeonfb_pci_register BEGIN\n");
+       pr_debug("radeonfb_pci_register BEGIN\n");
        
        /* Enable device in PCI config */
        ret = pci_enable_device(pdev);
@@ -2170,9 +2188,15 @@ static int __devinit radeonfb_pci_register (struct pci_dev *pdev,
        rinfo->lvds_timer.function = radeon_lvds_timer_func;
        rinfo->lvds_timer.data = (unsigned long)rinfo;
 
-       strcpy(rinfo->name, "ATI Radeon XX ");
-       rinfo->name[11] = ent->device >> 8;
-       rinfo->name[12] = ent->device & 0xFF;
+       c1 = ent->device >> 8;
+       c2 = ent->device & 0xff;
+       if (isprint(c1) && isprint(c2))
+               snprintf(rinfo->name, sizeof(rinfo->name),
+                        "ATI Radeon %x \"%c%c\"", ent->device & 0xffff, c1, c2);
+       else
+               snprintf(rinfo->name, sizeof(rinfo->name),
+                        "ATI Radeon %x", ent->device & 0xffff);
+
        rinfo->family = ent->driver_data & CHIP_FAMILY_MASK;
        rinfo->chipset = pdev->device;
        rinfo->has_CRTC2 = (ent->driver_data & CHIP_HAS_CRTC2) != 0;
@@ -2227,7 +2251,7 @@ static int __devinit radeonfb_pci_register (struct pci_dev *pdev,
            rinfo->family == CHIP_FAMILY_RS200)
                rinfo->errata |= CHIP_ERRATA_PLL_DELAY;
 
-#ifdef CONFIG_PPC_OF
+#if defined(CONFIG_PPC_OF) || defined(CONFIG_SPARC)
        /* On PPC, we obtain the OF device-node pointer to the firmware
         * data for this chip
         */
@@ -2236,6 +2260,8 @@ static int __devinit radeonfb_pci_register (struct pci_dev *pdev,
                printk(KERN_WARNING "radeonfb (%s): Cannot match card to OF node !\n",
                       pci_name(rinfo->pdev));
 
+#endif /* CONFIG_PPC_OF || CONFIG_SPARC */
+#ifdef CONFIG_PPC_OF
        /* On PPC, the firmware sets up a memory mapping that tends
         * to cause lockups when enabling the engine. We reconfigure
         * the card internal memory mappings properly
@@ -2251,8 +2277,8 @@ static int __devinit radeonfb_pci_register (struct pci_dev *pdev,
        do {
                rinfo->fb_base = ioremap (rinfo->fb_base_phys,
                                          rinfo->mapped_vram);
-       } while (   rinfo->fb_base == 0 &&
-                 ((rinfo->mapped_vram /=2) >= MIN_MAPPED_VRAM) );
+       } while (rinfo->fb_base == NULL &&
+                ((rinfo->mapped_vram /= 2) >= MIN_MAPPED_VRAM));
 
        if (rinfo->fb_base == NULL) {
                printk (KERN_ERR "radeonfb (%s): cannot map FB\n",
@@ -2261,7 +2287,7 @@ static int __devinit radeonfb_pci_register (struct pci_dev *pdev,
                goto err_unmap_rom;
        }
 
-       RTRACE("radeonfb (%s): mapped %ldk videoram\n", pci_name(rinfo->pdev),
+       pr_debug("radeonfb (%s): mapped %ldk videoram\n", pci_name(rinfo->pdev),
               rinfo->mapped_vram/1024);
 
        /*
@@ -2349,13 +2375,14 @@ static int __devinit radeonfb_pci_register (struct pci_dev *pdev,
                                                 MTRR_TYPE_WRCOMB, 1);
 #endif
 
-       radeonfb_bl_init(rinfo);
+       if (backlight)
+               radeonfb_bl_init(rinfo);
 
        printk ("radeonfb (%s): %s\n", pci_name(rinfo->pdev), rinfo->name);
 
        if (rinfo->bios_seg)
                radeon_unmap_ROM(rinfo, pdev);
-       RTRACE("radeonfb_pci_register END\n");
+       pr_debug("radeonfb_pci_register END\n");
 
        return 0;
 err_unmap_fb:
@@ -2393,7 +2420,6 @@ static void __devexit radeonfb_pci_unregister (struct pci_dev *pdev)
         if (!rinfo)
                 return;
 
-       radeonfb_bl_exit(rinfo);
        radeonfb_pm_exit(rinfo);
 
        if (rinfo->mon1_EDID)
@@ -2420,6 +2446,8 @@ static void __devexit radeonfb_pci_unregister (struct pci_dev *pdev)
 
         unregister_framebuffer(info);
 
+        radeonfb_bl_exit(rinfo);
+
         iounmap(rinfo->mmio_base);
         iounmap(rinfo->fb_base);
  
@@ -2469,6 +2497,8 @@ static int __init radeonfb_setup (char *options)
                        force_dfp = 1;
                } else if (!strncmp(this_opt, "panel_yres:", 11)) {
                        panel_yres = simple_strtoul((this_opt+11), NULL, 0);
+               } else if (!strncmp(this_opt, "backlight:", 10)) {
+                       backlight = simple_strtoul(this_opt+10, NULL, 0);
 #ifdef CONFIG_MTRR
                } else if (!strncmp(this_opt, "nomtrr", 6)) {
                        nomtrr = 1;