diff options
Diffstat (limited to 'drivers/video/nvidia')
-rw-r--r-- | drivers/video/nvidia/Makefile | 3 | ||||
-rw-r--r-- | drivers/video/nvidia/nv_backlight.c | 175 | ||||
-rw-r--r-- | drivers/video/nvidia/nv_proto.h | 10 | ||||
-rw-r--r-- | drivers/video/nvidia/nvidia.c | 95 |
4 files changed, 201 insertions, 82 deletions
diff --git a/drivers/video/nvidia/Makefile b/drivers/video/nvidia/Makefile index 690d37e8de5..ca47432113e 100644 --- a/drivers/video/nvidia/Makefile +++ b/drivers/video/nvidia/Makefile @@ -7,6 +7,7 @@ obj-$(CONFIG_FB_NVIDIA) += nvidiafb.o nvidiafb-y := nvidia.o nv_hw.o nv_setup.o \ nv_accel.o nvidiafb-$(CONFIG_FB_NVIDIA_I2C) += nv_i2c.o +nvidiafb-$(CONFIG_FB_NVIDIA_BACKLIGHT) += nv_backlight.o nvidiafb-$(CONFIG_PPC_OF) += nv_of.o -nvidiafb-objs := $(nvidiafb-y)
\ No newline at end of file +nvidiafb-objs := $(nvidiafb-y) diff --git a/drivers/video/nvidia/nv_backlight.c b/drivers/video/nvidia/nv_backlight.c new file mode 100644 index 00000000000..1c1c10c699c --- /dev/null +++ b/drivers/video/nvidia/nv_backlight.c @@ -0,0 +1,175 @@ +/* + * Backlight code for nVidia based graphic cards + * + * Copyright 2004 Antonino Daplas <adaplas@pol.net> + * Copyright (c) 2006 Michael Hanselmann <linux-kernel@hansmi.ch> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#include <linux/backlight.h> +#include <linux/fb.h> +#include <linux/pci.h> +#include "nv_local.h" +#include "nv_type.h" +#include "nv_proto.h" + +#ifdef CONFIG_PMAC_BACKLIGHT +#include <asm/backlight.h> +#include <asm/machdep.h> +#endif + +/* We do not have any information about which values are allowed, thus + * we used safe values. + */ +#define MIN_LEVEL 0x158 +#define MAX_LEVEL 0x534 + +static struct backlight_properties nvidia_bl_data; + +static int nvidia_bl_get_level_brightness(struct nvidia_par *par, + int level) +{ + struct fb_info *info = pci_get_drvdata(par->pci_dev); + int nlevel; + + /* Get and convert the value */ + mutex_lock(&info->bl_mutex); + nlevel = info->bl_curve[level] * FB_BACKLIGHT_MAX / MAX_LEVEL; + mutex_unlock(&info->bl_mutex); + + if (nlevel < 0) + nlevel = 0; + else if (nlevel < MIN_LEVEL) + nlevel = MIN_LEVEL; + else if (nlevel > MAX_LEVEL) + nlevel = MAX_LEVEL; + + return nlevel; +} + +static int nvidia_bl_update_status(struct backlight_device *bd) +{ + struct nvidia_par *par = class_get_devdata(&bd->class_dev); + u32 tmp_pcrt, tmp_pmc, fpcontrol; + int level; + + if (!par->FlatPanel) + return 0; + + if (bd->props->power != FB_BLANK_UNBLANK || + bd->props->fb_blank != FB_BLANK_UNBLANK) + level = 0; + else + level = bd->props->brightness; + + tmp_pmc = NV_RD32(par->PMC, 0x10F0) & 0x0000FFFF; + tmp_pcrt = NV_RD32(par->PCRTC0, 0x081C) & 0xFFFFFFFC; + fpcontrol = NV_RD32(par->PRAMDAC, 0x0848) & 0xCFFFFFCC; + + if (level > 0) { + tmp_pcrt |= 0x1; + tmp_pmc |= (1 << 31); /* backlight bit */ + tmp_pmc |= nvidia_bl_get_level_brightness(par, level) << 16; + fpcontrol |= par->fpSyncs; + } else + fpcontrol |= 0x20000022; + + NV_WR32(par->PCRTC0, 0x081C, tmp_pcrt); + NV_WR32(par->PMC, 0x10F0, tmp_pmc); + NV_WR32(par->PRAMDAC, 0x848, fpcontrol); + + return 0; +} + +static int nvidia_bl_get_brightness(struct backlight_device *bd) +{ + return bd->props->brightness; +} + +static struct backlight_properties nvidia_bl_data = { + .owner = THIS_MODULE, + .get_brightness = nvidia_bl_get_brightness, + .update_status = nvidia_bl_update_status, + .max_brightness = (FB_BACKLIGHT_LEVELS - 1), +}; + +void nvidia_bl_init(struct nvidia_par *par) +{ + struct fb_info *info = pci_get_drvdata(par->pci_dev); + struct backlight_device *bd; + char name[12]; + + if (!par->FlatPanel) + return; + +#ifdef CONFIG_PMAC_BACKLIGHT + if (!machine_is(powermac) || + !pmac_has_backlight_type("mnca")) + return; +#endif + + snprintf(name, sizeof(name), "nvidiabl%d", info->node); + + bd = backlight_device_register(name, par, &nvidia_bl_data); + if (IS_ERR(bd)) { + info->bl_dev = NULL; + printk("nvidia: Backlight registration failed\n"); + goto error; + } + + mutex_lock(&info->bl_mutex); + info->bl_dev = bd; + fb_bl_default_curve(info, 0, + 0x158 * FB_BACKLIGHT_MAX / MAX_LEVEL, + 0x534 * FB_BACKLIGHT_MAX / MAX_LEVEL); + mutex_unlock(&info->bl_mutex); + + up(&bd->sem); + bd->props->brightness = nvidia_bl_data.max_brightness; + bd->props->power = FB_BLANK_UNBLANK; + bd->props->update_status(bd); + down(&bd->sem); + +#ifdef CONFIG_PMAC_BACKLIGHT + mutex_lock(&pmac_backlight_mutex); + if (!pmac_backlight) + pmac_backlight = bd; + mutex_unlock(&pmac_backlight_mutex); +#endif + + printk("nvidia: Backlight initialized (%s)\n", name); + + return; + +error: + return; +} + +void nvidia_bl_exit(struct nvidia_par *par) +{ + struct fb_info *info = pci_get_drvdata(par->pci_dev); + +#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("nvidia: Backlight unloaded\n"); + } + mutex_unlock(&info->bl_mutex); + +#ifdef CONFIG_PMAC_BACKLIGHT + mutex_unlock(&pmac_backlight_mutex); +#endif +} diff --git a/drivers/video/nvidia/nv_proto.h b/drivers/video/nvidia/nv_proto.h index b149a690ee0..6fba656cd56 100644 --- a/drivers/video/nvidia/nv_proto.h +++ b/drivers/video/nvidia/nv_proto.h @@ -63,4 +63,14 @@ extern void nvidiafb_imageblit(struct fb_info *info, const struct fb_image *image); extern int nvidiafb_sync(struct fb_info *info); extern u8 byte_rev[256]; + +/* in nv_backlight.h */ +#ifdef CONFIG_FB_NVIDIA_BACKLIGHT +extern void nvidia_bl_init(struct nvidia_par *par); +extern void nvidia_bl_exit(struct nvidia_par *par); +#else +static inline void nvidia_bl_init(struct nvidia_par *par) {} +static inline void nvidia_bl_exit(struct nvidia_par *par) {} +#endif + #endif /* __NV_PROTO_H__ */ diff --git a/drivers/video/nvidia/nvidia.c b/drivers/video/nvidia/nvidia.c index 093ab9977c7..03a7c1e9ce3 100644 --- a/drivers/video/nvidia/nvidia.c +++ b/drivers/video/nvidia/nvidia.c @@ -22,6 +22,7 @@ #include <linux/init.h> #include <linux/pci.h> #include <linux/console.h> +#include <linux/backlight.h> #ifdef CONFIG_MTRR #include <asm/mtrr.h> #endif @@ -29,10 +30,6 @@ #include <asm/prom.h> #include <asm/pci-bridge.h> #endif -#ifdef CONFIG_PMAC_BACKLIGHT -#include <asm/machdep.h> -#include <asm/backlight.h> -#endif #include "nv_local.h" #include "nv_type.h" @@ -470,75 +467,6 @@ static struct fb_var_screeninfo __devinitdata nvidiafb_default_var = { .vmode = FB_VMODE_NONINTERLACED }; -/* - * Backlight control - */ -#ifdef CONFIG_PMAC_BACKLIGHT - -static int nvidia_backlight_levels[] = { - 0x158, - 0x192, - 0x1c6, - 0x200, - 0x234, - 0x268, - 0x2a2, - 0x2d6, - 0x310, - 0x344, - 0x378, - 0x3b2, - 0x3e6, - 0x41a, - 0x454, - 0x534, -}; - -/* ------------------------------------------------------------------------- * - * - * Backlight operations - * - * ------------------------------------------------------------------------- */ - -static int nvidia_set_backlight_enable(int on, int level, void *data) -{ - struct nvidia_par *par = data; - u32 tmp_pcrt, tmp_pmc, fpcontrol; - - tmp_pmc = NV_RD32(par->PMC, 0x10F0) & 0x0000FFFF; - tmp_pcrt = NV_RD32(par->PCRTC0, 0x081C) & 0xFFFFFFFC; - fpcontrol = NV_RD32(par->PRAMDAC, 0x0848) & 0xCFFFFFCC; - - if (on && (level > BACKLIGHT_OFF)) { - tmp_pcrt |= 0x1; - tmp_pmc |= (1 << 31); // backlight bit - tmp_pmc |= nvidia_backlight_levels[level - 1] << 16; - } - - if (on) - fpcontrol |= par->fpSyncs; - else - fpcontrol |= 0x20000022; - - NV_WR32(par->PCRTC0, 0x081C, tmp_pcrt); - NV_WR32(par->PMC, 0x10F0, tmp_pmc); - NV_WR32(par->PRAMDAC, 0x848, fpcontrol); - - return 0; -} - -static int nvidia_set_backlight_level(int level, void *data) -{ - return nvidia_set_backlight_enable(1, level, data); -} - -static struct backlight_controller nvidia_backlight_controller = { - nvidia_set_backlight_enable, - nvidia_set_backlight_level -}; - -#endif /* CONFIG_PMAC_BACKLIGHT */ - static void nvidiafb_load_cursor_image(struct nvidia_par *par, u8 * data8, u16 bg, u16 fg, u32 w, u32 h) { @@ -1355,10 +1283,15 @@ static int nvidiafb_blank(int blank, struct fb_info *info) NVWriteSeq(par, 0x01, tmp); NVWriteCrtc(par, 0x1a, vesa); -#ifdef CONFIG_PMAC_BACKLIGHT - if (par->FlatPanel && machine_is(powermac)) { - set_backlight_enable(!blank); +#ifdef CONFIG_FB_NVIDIA_BACKLIGHT + mutex_lock(&info->bl_mutex); + if (info->bl_dev) { + down(&info->bl_dev->sem); + info->bl_dev->props->power = blank; + info->bl_dev->props->update_status(info->bl_dev); + up(&info->bl_dev->sem); } + mutex_unlock(&info->bl_mutex); #endif NVTRACE_LEAVE(); @@ -1741,11 +1674,9 @@ static int __devinit nvidiafb_probe(struct pci_dev *pd, "PCI nVidia %s framebuffer (%dMB @ 0x%lX)\n", info->fix.id, par->FbMapSize / (1024 * 1024), info->fix.smem_start); -#ifdef CONFIG_PMAC_BACKLIGHT - if (par->FlatPanel && machine_is(powermac)) - register_backlight_controller(&nvidia_backlight_controller, - par, "mnca"); -#endif + + nvidia_bl_init(par); + NVTRACE_LEAVE(); return 0; @@ -1775,6 +1706,8 @@ static void __exit nvidiafb_remove(struct pci_dev *pd) NVTRACE_ENTER(); + nvidia_bl_exit(par); + unregister_framebuffer(info); #ifdef CONFIG_MTRR if (par->mtrr.vram_valid) |