From: Guido Guenther - fixes the PCI-IDs (needed to get it to work on at least the NV17) - cleans up the DEBUG option (similar to the new radeonfb). This also makes it easy to replace printk by btext_printf() (on ppc) or similar to ease debugging of the fb code when all else fails. - adds backlight control for Apple powerbooks Signed-off-by: Guido Guenther Signed-off-by: Andrew Morton --- 25-akpm/drivers/video/Kconfig | 9 ++ 25-akpm/drivers/video/riva/fbdev.c | 157 +++++++++++++++++++++++++++++++------ 2 files changed, 144 insertions(+), 22 deletions(-) diff -puN drivers/video/Kconfig~fix-rivafbs-nv_arch_-cleanup-debug-backlight-control-on-ppc drivers/video/Kconfig --- 25/drivers/video/Kconfig~fix-rivafbs-nv_arch_-cleanup-debug-backlight-control-on-ppc 2004-07-10 17:56:16.620430488 -0700 +++ 25-akpm/drivers/video/Kconfig 2004-07-10 17:56:16.629429120 -0700 @@ -446,6 +446,15 @@ config FB_RIVA_I2C independently validate video mode parameters, you should say Y here. +config FB_RIVA_DEBUG + bool "Lots of debug output from Riva(nVidia) driver" + depends on FB_RIVA + default n + help + Say Y here if you want the Riva driver to output all sorts + of debugging informations to provide to the maintainer when + something goes wrong. + config FB_I810 tristate "Intel 810/815 support (EXPERIMENTAL)" depends on FB && AGP && AGP_INTEL && EXPERIMENTAL && PCI diff -puN drivers/video/riva/fbdev.c~fix-rivafbs-nv_arch_-cleanup-debug-backlight-control-on-ppc drivers/video/riva/fbdev.c --- 25/drivers/video/riva/fbdev.c~fix-rivafbs-nv_arch_-cleanup-debug-backlight-control-on-ppc 2004-07-10 17:56:16.621430336 -0700 +++ 25-akpm/drivers/video/riva/fbdev.c 2004-07-10 17:56:16.628429272 -0700 @@ -48,6 +48,9 @@ #include #include #endif +#ifdef CONFIG_PMAC_BACKLIGHT +#include +#endif #include "rivafb.h" #include "nvreg.h" @@ -64,15 +67,16 @@ * various helpful macros and constants * * ------------------------------------------------------------------------- */ - -#undef RIVAFBDEBUG -#ifdef RIVAFBDEBUG -#define DPRINTK(fmt, args...) printk(KERN_DEBUG "%s: " fmt, __FUNCTION__ , ## args) +#ifdef CONFIG_FB_RIVA_DEBUG +#define NVTRACE printk #else -#define DPRINTK(fmt, args...) +#define NVTRACE if(0) printk #endif -#ifndef RIVA_NDEBUG +#define NVTRACE_ENTER(...) NVTRACE("%s START\n", __FUNCTION__) +#define NVTRACE_LEAVE(...) NVTRACE("%s END\n", __FUNCTION__) + +#ifdef CONFIG_FB_RIVA_DEBUG #define assert(expr) \ if(!(expr)) { \ printk( "Assertion failed! %s,%s,%s,line=%d\n",\ @@ -173,18 +177,18 @@ static struct riva_chip_info { { "GeForce2-GTS", NV_ARCH_10 }, { "GeForce2-ULTRA", NV_ARCH_10 }, { "Quadro2-PRO", NV_ARCH_10 }, - { "GeForce4-MX-460", NV_ARCH_20 }, - { "GeForce4-MX-440", NV_ARCH_20 }, - { "GeForce4-MX-420", NV_ARCH_20 }, - { "GeForce4-440-GO", NV_ARCH_20 }, - { "GeForce4-420-GO", NV_ARCH_20 }, - { "GeForce4-420-GO-M32", NV_ARCH_20 }, - { "Quadro4-500-XGL", NV_ARCH_20 }, - { "GeForce4-440-GO-M64", NV_ARCH_20 }, - { "Quadro4-200", NV_ARCH_20 }, - { "Quadro4-550-XGL", NV_ARCH_20 }, - { "Quadro4-500-GOGL", NV_ARCH_20 }, - { "GeForce2", NV_ARCH_20 }, + { "GeForce4-MX-460", NV_ARCH_10 }, + { "GeForce4-MX-440", NV_ARCH_10 }, + { "GeForce4-MX-420", NV_ARCH_10 }, + { "GeForce4-440-GO", NV_ARCH_10 }, + { "GeForce4-420-GO", NV_ARCH_10 }, + { "GeForce4-420-GO-M32", NV_ARCH_10 }, + { "Quadro4-500-XGL", NV_ARCH_10 }, + { "GeForce4-440-GO-M64", NV_ARCH_10 }, + { "Quadro4-200", NV_ARCH_10 }, + { "Quadro4-550-XGL", NV_ARCH_10 }, + { "Quadro4-500-GOGL", NV_ARCH_10 }, + { "GeForce2", NV_ARCH_10 }, { "GeForce3", NV_ARCH_20 }, { "GeForce3 Ti 200", NV_ARCH_20 }, { "GeForce3 Ti 500", NV_ARCH_20 }, @@ -351,6 +355,38 @@ static const struct riva_regs reg_templa 0xEB /* MISC */ }; +/* + * Backlight control + */ +#ifdef CONFIG_PMAC_BACKLIGHT + +static int riva_backlight_levels[] = { + 0x158, + 0x192, + 0x1c6, + 0x200, + 0x234, + 0x268, + 0x2a2, + 0x2d6, + 0x310, + 0x344, + 0x378, + 0x3b2, + 0x3e6, + 0x41a, + 0x454, + 0x534, +}; + +static int riva_set_backlight_enable(int on, int level, void *data); +static int riva_set_backlight_level(int level, void *data); +static struct backlight_controller riva_backlight_controller = { + riva_set_backlight_enable, + riva_set_backlight_level +}; +#endif /* CONFIG_PMAC_BACKLIGHT */ + /* ------------------------------------------------------------------------- * * * MMIO access macros @@ -592,6 +628,7 @@ static void riva_save_state(struct riva_ { int i; + NVTRACE_ENTER(); par->riva.LockUnlock(&par->riva, 0); par->riva.UnloadStateExt(&par->riva, ®s->ext); @@ -609,6 +646,7 @@ static void riva_save_state(struct riva_ for (i = 0; i < NUM_SEQ_REGS; i++) regs->seq[i] = SEQin(par, i); + NVTRACE_LEAVE(); } /** @@ -630,6 +668,7 @@ static void riva_load_state(struct riva_ RIVA_HW_STATE *state = ®s->ext; int i; + NVTRACE_ENTER(); CRTCout(par, 0x11, 0x00); par->riva.LockUnlock(&par->riva, 0); @@ -656,6 +695,7 @@ static void riva_load_state(struct riva_ for (i = 0; i < NUM_SEQ_REGS; i++) SEQout(par, i, regs->seq[i]); + NVTRACE_LEAVE(); } /** @@ -676,6 +716,7 @@ static void riva_load_video_mode(struct struct riva_par *par = (struct riva_par *) info->par; struct riva_regs newmode; + NVTRACE_ENTER(); /* time to calculate */ rivafb_blank(1, info); @@ -806,10 +847,12 @@ static void riva_load_video_mode(struct riva_load_state(par, &par->current_state); par->riva.LockUnlock(&par->riva, 0); /* important for HW cursor */ rivafb_blank(0, info); + NVTRACE_LEAVE(); } static void riva_update_var(struct fb_var_screeninfo *var, struct fb_videomode *modedb) { + NVTRACE_ENTER(); var->xres = var->xres_virtual = modedb->xres; var->yres = modedb->yres; if (var->yres_virtual < var->yres) @@ -824,6 +867,7 @@ static void riva_update_var(struct fb_va var->vsync_len = modedb->vsync_len; var->sync = modedb->sync; var->vmode = modedb->vmode; + NVTRACE_LEAVE(); } /** @@ -859,6 +903,7 @@ static int rivafb_do_maximize(struct fb_ }; int i; + NVTRACE_ENTER(); /* use highest possible virtual resolution */ if (var->xres_virtual == -1 && var->yres_virtual == -1) { printk(KERN_WARNING PFX @@ -871,7 +916,7 @@ static int rivafb_do_maximize(struct fb_ if (modes[i].xres == -1) { printk(KERN_ERR PFX "could not find a virtual resolution that fits into video memory!!\n"); - DPRINTK("EXIT - EINVAL error\n"); + NVTRACE("EXIT - EINVAL error\n"); return -EINVAL; } var->xres_virtual = modes[i].xres; @@ -897,7 +942,7 @@ static int rivafb_do_maximize(struct fb_ printk(KERN_ERR PFX "mode %dx%dx%d rejected...resolution too high to fit into video memory!\n", var->xres, var->yres, var->bits_per_pixel); - DPRINTK("EXIT - EINVAL error\n"); + NVTRACE("EXIT - EINVAL error\n"); return -EINVAL; } } @@ -924,7 +969,7 @@ static int rivafb_do_maximize(struct fb_ var->yres_virtual = 0x7fff/nom; if (var->xres_virtual > 0x7fff/nom) var->xres_virtual = 0x7fff/nom; - + NVTRACE_LEAVE(); return 0; } @@ -1004,6 +1049,36 @@ static int riva_get_cmap_len(const struc /* ------------------------------------------------------------------------- * * + * Backlight operations + * + * ------------------------------------------------------------------------- */ + +#ifdef CONFIG_PMAC_BACKLIGHT +static int riva_set_backlight_enable(int on, int level, void *data) +{ + struct riva_par *par = (struct riva_par *)data; + U032 tmp_pcrt, tmp_pmc; + + tmp_pmc = par->riva.PMC[0x10F0/4] & 0x0000FFFF; + tmp_pcrt = par->riva.PCRTC0[0x081C/4] & 0xFFFFFFFC; + if(on && (level > BACKLIGHT_OFF)) { + tmp_pcrt |= 0x1; + tmp_pmc |= (1 << 31); // backlight bit + tmp_pmc |= riva_backlight_levels[level-1] << 16; // level + } + par->riva.PCRTC0[0x081C/4] = tmp_pcrt; + par->riva.PMC[0x10F0/4] = tmp_pmc; + return 0; +} + +static int riva_set_backlight_level(int level, void *data) +{ + return riva_set_backlight_enable(1, level, data); +} +#endif /* CONFIG_PMAC_BACKLIGHT */ + +/* ------------------------------------------------------------------------- * + * * framebuffer operations * * ------------------------------------------------------------------------- */ @@ -1013,6 +1088,7 @@ static int rivafb_open(struct fb_info *i struct riva_par *par = (struct riva_par *) info->par; int cnt = atomic_read(&par->ref_count); + NVTRACE_ENTER(); if (!cnt) { memset(&par->state, 0, sizeof(struct vgastate)); par->state.flags = VGA_SAVE_MODE | VGA_SAVE_FONTS; @@ -1029,6 +1105,7 @@ static int rivafb_open(struct fb_info *i riva_save_state(par, &par->initial_state); } atomic_inc(&par->ref_count); + NVTRACE_LEAVE(); return 0; } @@ -1037,6 +1114,7 @@ static int rivafb_release(struct fb_info struct riva_par *par = (struct riva_par *) info->par; int cnt = atomic_read(&par->ref_count); + NVTRACE_ENTER(); if (!cnt) return -EINVAL; if (cnt == 1) { @@ -1047,6 +1125,7 @@ static int rivafb_release(struct fb_info par->riva.LockUnlock(&par->riva, 1); } atomic_dec(&par->ref_count); + NVTRACE_LEAVE(); return 0; } @@ -1056,6 +1135,7 @@ static int rivafb_check_var(struct fb_va int nom, den; /* translating from pixels->bytes */ int mode_valid = 0; + NVTRACE_ENTER(); switch (var->bits_per_pixel) { case 1 ... 8: var->red.offset = var->green.offset = var->blue.offset = 0; @@ -1101,7 +1181,7 @@ static int rivafb_check_var(struct fb_va printk(KERN_ERR PFX "mode %dx%dx%d rejected...color depth not supported.\n", var->xres, var->yres, var->bits_per_pixel); - DPRINTK("EXIT, returning -EINVAL\n"); + NVTRACE("EXIT, returning -EINVAL\n"); return -EINVAL; } @@ -1191,6 +1271,7 @@ static int rivafb_check_var(struct fb_va var->green.msb_right = var->blue.msb_right = var->transp.offset = var->transp.length = var->transp.msb_right = 0; + NVTRACE_LEAVE(); return 0; } @@ -1198,6 +1279,7 @@ static int rivafb_set_par(struct fb_info { struct riva_par *par = (struct riva_par *) info->par; + NVTRACE_ENTER(); riva_common_setup(par); RivaGetConfig(&par->riva, par->Chipset); /* vgaHWunlock() + riva unlock (0x7F) */ @@ -1211,6 +1293,7 @@ static int rivafb_set_par(struct fb_info info->fix.line_length = (info->var.xres_virtual * (info->var.bits_per_pixel >> 3)); info->fix.visual = (info->var.bits_per_pixel == 8) ? FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_DIRECTCOLOR; + NVTRACE_LEAVE(); return 0; } @@ -1233,6 +1316,7 @@ static int rivafb_pan_display(struct fb_ struct riva_par *par = (struct riva_par *)info->par; unsigned int base; + NVTRACE_ENTER(); if (var->xoffset > (var->xres_virtual - var->xres)) return -EINVAL; if (var->yoffset > (var->yres_virtual - var->yres)) @@ -1259,6 +1343,7 @@ static int rivafb_pan_display(struct fb_ info->var.vmode |= FB_VMODE_YWRAP; else info->var.vmode &= ~FB_VMODE_YWRAP; + NVTRACE_LEAVE(); return 0; } @@ -1270,6 +1355,7 @@ static int rivafb_blank(int blank, struc tmp = SEQin(par, 0x01) & ~0x20; /* screen on/off */ vesa = CRTCin(par, 0x1a) & ~0xc0; /* sync on/off */ + NVTRACE_ENTER(); if (blank) { tmp |= 0x20; switch (blank - 1) { @@ -1288,6 +1374,14 @@ static int rivafb_blank(int blank, struc } SEQout(par, 0x01, tmp); CRTCout(par, 0x1a, vesa); + +#ifdef CONFIG_PMAC_BACKLIGHT + if ( par->FlatPanel && _machine == _MACH_Pmac) { + set_backlight_enable(!blank); + } +#endif + + NVTRACE_LEAVE(); return 0; } @@ -1676,6 +1770,7 @@ static int __devinit riva_set_fbinfo(str { unsigned int cmap_len; + NVTRACE_ENTER(); info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_XPAN | FBINFO_HWACCEL_YPAN @@ -1696,6 +1791,7 @@ static int __devinit riva_set_fbinfo(str info->pixmap.scan_align = 4; info->pixmap.flags = FB_PIXMAP_SYSTEM; info->var.yres_virtual = -1; + NVTRACE_LEAVE(); return (rivafb_check_var(&info->var, info)); } @@ -1710,6 +1806,7 @@ static int riva_get_EDID_OF(struct fb_in "DFP,EDID", "LCD,EDID", "EDID", "EDID1", "EDID,B", "EDID,A", NULL }; int i; + NVTRACE_ENTER(); dp = pci_device_to_OF_node(pd); for (; dp != NULL; dp = dp->child) { disptype = (unsigned char *)get_property(dp, "display-type", NULL); @@ -1726,6 +1823,7 @@ static int riva_get_EDID_OF(struct fb_in } } } + NVTRACE_LEAVE(); return 0; } #endif /* CONFIG_PPC_OF */ @@ -1735,6 +1833,7 @@ static void riva_update_default_var(stru struct fb_monspecs *specs = &info->monspecs; struct fb_videomode modedb; + NVTRACE_ENTER(); /* respect mode options */ if (mode_option) { fb_find_mode(var, info, mode_option, @@ -1759,11 +1858,13 @@ static void riva_update_default_var(stru riva_update_var(var, &modedb); } var->accel_flags |= FB_ACCELF_TEXT; + NVTRACE_LEAVE(); } static void riva_get_EDID(struct fb_info *info, struct pci_dev *pdev) { + NVTRACE_ENTER(); #ifdef CONFIG_PPC_OF if (!riva_get_EDID_OF(info, pdev)) printk("rivafb: could not retrieve EDID from OF\n"); @@ -1784,6 +1885,7 @@ static void riva_get_EDID(struct fb_info riva_delete_i2c_busses(par); #endif #endif + NVTRACE_LEAVE(); } @@ -1813,6 +1915,7 @@ static int __devinit rivafb_probe(struct struct riva_par *default_par; struct fb_info *info; + NVTRACE_ENTER(); assert(pd != NULL); assert(rci != NULL); @@ -1958,6 +2061,12 @@ static int __devinit rivafb_probe(struct info->fix.id, info->fix.smem_len / (1024 * 1024), info->fix.smem_start); +#ifdef CONFIG_PMAC_BACKLIGHT + if (default_par->FlatPanel && _machine == _MACH_Pmac) + register_backlight_controller(&riva_backlight_controller, + default_par, "mnca"); +#endif + NVTRACE_LEAVE(); return 0; err_out_iounmap_fb: @@ -1986,6 +2095,7 @@ static void __exit rivafb_remove(struct struct fb_info *info = pci_get_drvdata(pd); struct riva_par *par = (struct riva_par *) info->par; + NVTRACE_ENTER(); if (!info) return; @@ -2007,6 +2117,7 @@ static void __exit rivafb_remove(struct kfree(par); kfree(info); pci_set_drvdata(pd, NULL); + NVTRACE_LEAVE(); } /* ------------------------------------------------------------------------- * @@ -2020,6 +2131,7 @@ int __init rivafb_setup(char *options) { char *this_opt; + NVTRACE_ENTER(); if (!options || !*options) return 0; @@ -2043,6 +2155,7 @@ int __init rivafb_setup(char *options) } else mode_option = this_opt; } + NVTRACE_LEAVE(); return 0; } #endif /* !MODULE */ _