Go Back   nV News Forums > Linux Support Forums > NVIDIA Linux

Newegg Daily Deals

Reply
 
Thread Tools
Old 04-28-10, 04:29 PM   #49
damdim
Registered User
 
Join Date: Jan 2010
Posts: 21
Default Re: Linux backlight driver

You have to edit the file "/usr/src/nvidia_bl-0.52/nvidia_bl.c", find the "static struct driver_data nv5x_driver_data" section and change .min and .max values. Then rebuild the module. With the latest nvidia driver I had to change .min to 1024 and .max to 133000 for a vaio vpccw1s1e with gt230m. You can try different values, but be carefull because if you change .min to a very low value the screen might turn off completely.
damdim is offline   Reply With Quote
Old 04-28-10, 05:35 PM   #50
achim123
Registered User
 
Join Date: Dec 2009
Posts: 10
Default Re: Linux backlight driver

step 5
Quote:
sudo dkms add build install -m nvidia_bl -v 0.52
gives me this error:
Quote:
Error! DKMS tree already contains: nividia_bl.52
You cannot add the same module/version combo more than once
it works without 'add':
Code:
sudo dkms build install -m nvidia_bl -v 0.52
but my problem are also the values:
now I'm able to write values between 0 and 127, but the screen changes its brightness just between 0 (dark) and 30 (bright)

I also tried damdim's hint, but nothing changed.
I would be happy, if sb. was able to tell me how I get 30 as max value
and how to control it with gnome-power-manager =)

greetz

PS:brx' patch doesn't change anything .. :/
achim123 is offline   Reply With Quote
Old 04-30-10, 02:53 PM   #51
muddenhed
Creator of oBacklight
 
Join Date: Apr 2010
Posts: 19
Default Re: Linux backlight driver

Quote:
Originally Posted by damdim View Post
You have to edit the file "/usr/src/nvidia_bl-0.52/nvidia_bl.c", find the "static struct driver_data nv5x_driver_data" section and change .min and .max values. Then rebuild the module. With the latest nvidia driver I had to change .min to 1024 and .max to 133000 for a vaio vpccw1s1e with gt230m. You can try different values, but be carefull because if you change .min to a very low value the screen might turn off completely.
Thanks this is getting me 99% towards a solution, just one question, on every reboot/startup the /sys/class/backlight/nvidia_backlight/brightness returns a 0, is there a way for it to keep its previous setting or make it have 7 as default?

/Marcus
muddenhed is offline   Reply With Quote
Old 04-30-10, 04:50 PM   #52
achim123
Registered User
 
Join Date: Dec 2009
Posts: 10
Default Re: Linux backlight driver

I would write
Quote:
echo 7 > /sys/class/backlight/nvidia_backlight/brightness
in the rc.local as a workaround
achim123 is offline   Reply With Quote
Old 05-01-10, 09:52 AM   #53
muddenhed
Creator of oBacklight
 
Join Date: Apr 2010
Posts: 19
Default Re: Linux backlight driver

Now i'm in total bliss, i got the backlight working on my laptop.

Below is how i did and i have attached the script i used to accomplish the FN functionality.

This how-to and the script is based on my system, a Sony VAIO VPCCW1S1E and openSUSE 11.2 but should with minor modification work on other systems & distributions to.

Code:
Get backlight to work on Sony laptops with nVidia GT 230M & nvidia_bl on openSUSE 11.2
--------------------------------------------------------------------------------------

Install DKMS.
-------------
- Download DKMS fom http://linux.dell.com/dkms/, choose the rpm format.

- Install the rpm package by doubleclick on it.

Install nvidia_bl.
------------------
- Download nvidia_bl from http://www.nvnews.net/vbulletin/showthread.php?t=143025.

- Open up a terminal window and enter sudo mode.
  $ sudo -i

- Change to the folder where you unpacked the nvidia_bl.
  # cd /folder/of/nvidia_bl

- Run following command to unpack it into /usr/src folder
  # dkms ldtarball --archive=nvidia_bl-0.xx.tar.gz

- Change folder to /usr/src/nvidia_bl-0.xx where 0.xx is the version number of nvidia_bl
  # cd /usr/src/nvidia_bl-x.xx

- Start editing the nvidia_bl.c file
  # nano nvidia_bl.c

- Find the static struct driver_data nv5x_driver_data section and edit the min & max values.
  static struct driver_data nv5x_driver_data = {
	.bar           = 0,
	.reg_offset    = NV5X_PDISPLAY_OFFSET + NV5X_PDISPLAY_SOR0_BRIGHTNESS,
	.reg_size      = 4,
	.off           = 0,
	.min           = 7000,
	.max           = 2500000,

- Now find the static DEFINE_PCI_DEVICE_TABLE(nvidia_bl_device_table) and add the GT 230M chipset.
  static DEFINE_PCI_DEVICE_TABLE(nvidia_bl_device_table) = {
  /* NVIDIA Geforce 230M */
	{ PCI_VDEVICE(NVIDIA, 0x0A2A), (kernel_ulong_t)&nv5x_driver_data },

- Save nvidia_bl.c

- Time to build and install. Match 0.xx with correct version of nvidia_bl. The ldtarball command above did some prep work and we need to unload them to.
  # dkms remove -m nvidia_bl -v 0.xx --all
  # dkms add build install -m nvidia_bl -v 0.xx

- Now we need to add nvidia_bl to module startup. Edit the /etc/sysconfig/kernel file and modify MODULE_LOADED_ON_BOOT row to have nvidia_bl included & save it.
  # nano /etc/sysconfig/kernel
  MODULES_LOADED_ON_BOOT="nvidia_bl"

- Reboot your machine and check so that the nvidia_bl got loaded during startup. Open up a terminal window.
  $ lsmod | grep nvidia_bl
  Should produce an output like this.
  nvidia_bl               9792  0

- To test it do the following and you should see a change of brightness on your display.
  $ sudo echo 3 | sudo tee -a /sys/class/backlight/nvidia_backlight/brightness

Now you should be able to change your backlight.
If you spot any errors in the how to please let me know so i can correct them.

Last edited by muddenhed; 06-23-10 at 04:55 AM. Reason: Added better min & max values
muddenhed is offline   Reply With Quote
Old 05-05-10, 10:38 AM   #54
cfraz89
Registered User
 
Join Date: May 2010
Posts: 1
Default Re: Linux backlight driver

Just managed to get the nvidia-bl driver from Mactel Repos working perfect on my arch install. Here's what I needed to do for my Sony Vaio CW (VPCCW27FX -> GT330M):
  1. Downloaded nvidia-bl 0.16.7 from launcpad
  2. Downloaded nvidia-bl pkgbuil (refers to old version). Then copied source from new version over the one in the pkgbuild, and used makepkg -g to generate new md5sum, save that in PKGBUILD, and makepkg to compile the module, pacman -U to install it.
  3. This is the trick, since the driver by default maxes at 127 for my vaio (according to the source). But that was way to dark, I needed to set it 127000 to get full brightness. Likely a bug
  4. so make a file called /etc/modprobe.d/nvidia-bl containing the line "options nvidia_bl max_level=127000 shift=7".
  5. The shift=7 reduces the reported brightness enough that KDE PowerDevil will change the brightness. Powerdevil refuses to change brightnesses over 1024, probably due to a HAL limitation. The shift fixes that. If you need a higher max_level, you'll want to increase shift by 1 or 2 (its a division by 2 for each increase).
  6. Either modprobe nvidia-bl or reboot, and SWEET! have screen brightness control with FN keys working. WIN. Thanks everyone that worked on this driver.

Now if only the nouveau drivers worked on this card (stupid EDID in the ACPI). There are patches floating around to make them work, but as far as I know they've only been integrated into FC13. Randr 1.2 and modesetting sure would be nice.
cfraz89 is offline   Reply With Quote
Old 05-07-10, 08:17 AM   #55
tgui
Registered User
 
Join Date: Jan 2010
Posts: 8
Default Re: Linux backlight driver

Work perfectly with Ubuntu 10.04 on my Sony VAIO CW w/330m

- run: sudo gedit /etc/apt/sources.list
- append :
deb http://ppa.launchpad.net/mactel-support/ppa/ubuntu lucid main
deb-src http://ppa.launchpad.net/mactel-support/ppa/ubuntu lucid main

- save & close
- run: sudo apt-get update
- run: sudo apt-get install nvidia-bl-dkms
- restart machine
- use FN keys to change brightness!!!

tgui is offline   Reply With Quote
Old 05-07-10, 02:23 PM   #56
julien321
Registered User
 
Join Date: May 2010
Posts: 1
Default Re: Linux backlight driver

Hello,

Great Jobs! Thanks to your work, at last, now I can modify the backlight level on a Toshiba U500 with a g210m nvidia video. To do that, I had to add to the source code file nvidia_bl.c, PCI_VENDOR_ID_TOSHIBA in the struct "nvidia_bl_subvendors".
Also, in order to be compatible with power-manager, I create in /usr/modprobe.d folder
a nvidia_bl.conf file with the string "nvidia_bl max_level=0x7000 shift=8" in it. Indeed it seems that the maximum level is around 0x7000.

Finally, I used the trick of damdim with
<match key="linux.sysfs_path" string="/sys/devices/virtual/backlight/acpi_video0">
instead of
<match key="linux.sysfs_path" string="/sys/devices/virtual/backlight/sony">


Julien

PS. I made a confusion with the mactel version of the nvidia_bl.c source. The options are only valid for the mactel version. For people that wants to use the nvidia_bl driver (mactel or this one) be careful that in the /etc/X11/xorg.conf file, there is no the line 'Option "RegistryDwords" "EnableBrightnessControl=1"' in device section. Indeed, with this option the behaviour is quite strange, for low value, there is a crackling and the lightening is not uniform. Without this option, the maximum value seems to be equal to be 0x20000.

Last edited by julien321; 05-08-10 at 03:01 PM. Reason: corrections
julien321 is offline   Reply With Quote

Old 05-08-10, 12:52 PM   #57
superlex88
Registered User
 
Join Date: May 2010
Posts: 4
Default Re: Linux backlight driver

Hello!
I'm using openSUSE with kernel 2.6.34-rc6 and my PC is a Sony Vaio FZ31M with Nvidia 8400M GT. I have tested nvidia_bl-0.52 and it works very well with kernel 2.6.31-12, but it fails to compile in kernel 2.6.34-rc6. The file make.log reports:

Code:
DKMS make.log for nvidia_bl-0.52 for kernel 2.6.34-rc6-29-default (i586)
sab mag  8 19:49:57 CEST 2010
make: Entering directory `/usr/src/linux-2.6.34-rc6-29-obj/i386/default'
make -C ../../../linux-2.6.34-rc6-29 O=/usr/src/linux-2.6.34-rc6-29-obj/i386/default/. modules
  CC [M]  /var/lib/dkms/nvidia_bl/0.52/build/nvidia_bl.o
/var/lib/dkms/nvidia_bl/0.52/build/nvidia_bl.c:34:3: warning: #warning USE_BACKLIGHT_SUSPEND
/var/lib/dkms/nvidia_bl/0.52/build/nvidia_bl.c: In function ‘nvidia_bl_init’:
/var/lib/dkms/nvidia_bl/0.52/build/nvidia_bl.c:525: error: too few arguments to function ‘backlight_device_register’
make[3]: *** [/var/lib/dkms/nvidia_bl/0.52/build/nvidia_bl.o] Error 1
make[2]: *** [_module_/var/lib/dkms/nvidia_bl/0.52/build] Error 2
make[1]: *** [sub-make] Error 2
make: *** [all] Error 2
make: Leaving directory `/usr/src/linux-2.6.34-rc6-29-obj/i386/default'
Any suggestions?
superlex88 is offline   Reply With Quote
Old 05-22-10, 06:49 AM   #58
damdim
Registered User
 
Join Date: Jan 2010
Posts: 21
Default Re: Linux backlight driver

I changed a little the source so it can compile against a 2.6.34 kernel. The changes were copied from MacTel Team latest module (https://launchpad.net/~mactel-support/+archive/ppa). Change the .min and .max values to fit your hardware and add the pci id to "static DEFINE_PCI_DEVICE_TABLE(nvidia_bl_device_table)" section accordingly from http://us.download.nvidia.com/XFree8...ppendix-a.html if your card is not already there.
P.S. It will compile only against a 2.6.34 kernel. For a previous kernel use the original source from guillaumezin in the first post.

Code:
/*
 * Backlight driver for Nvidia graphics adapters.
 *
 * Copyright (c) 2008-2009 Mario Schwalbe <schwalbe@inf.tu-dresden.de>
 * Based on the mechanism dicovered by the author of NvClock:
 * Copyright (c) 2001-2009 Roderick Colenbrander
 *     Site: http://nvclock.sourceforge.net
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 */

/*
 * Maybe the check against the subsystem vendor should be removed,
 * but there's no guarantee that the chip's smartdimmer signals
 * are actually connected to the display logic. Right now, these
 * are the supported (read connected) vendors according to NvClock.
 */

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/platform_device.h>
#include <linux/backlight.h>
#include <linux/dmi.h>
#include <linux/pci.h>
#include <linux/err.h>
#include <linux/fb.h>

/* Check for the new backlight suspend/resume feature */
#if defined(BL_CORE_SUSPENDRESUME)
	#warning USE_BACKLIGHT_SUSPEND
	#define USE_BACKLIGHT_SUSPEND
/* Otherwise use a platform driver if PM is enabled */
#elif defined(CONFIG_PM)
	#warning USE_PLATFORM_DRIVER
	#define USE_PLATFORM_DRIVER
#endif

/* Register constants */
#define INIT_BACKLIGHT_PROPS
#define NV5X_PDISPLAY_OFFSET				0x00610000
#define NV5X_PDISPLAY_SOR0_BRIGHTNESS			0x0000c084
#define NV5X_PDIPSLAY_SOR0_BRIGHTNESS_CONTROL_ENABLED	0x80000000

/* Driver private data structure */
struct driver_data {
	/* PCI region (BAR) the smartdimmer register is in */
	unsigned bar;
	/* Register offset into this region */
	unsigned long reg_offset;
	/* Register size in byte */
	unsigned reg_size;

	/* off, min and max value for intensity in register */
	unsigned off, min, max;

	/* Backlight operations structure */
	struct backlight_ops backlight_ops;

	/* The device we drive */
	struct pci_dev *dev;
	/* Pointer to the mapped smartdimmer register */
	/* volatile */ void __iomem *smartdimmer;
};

static unsigned int nvidia_bl_ignore_device = 0;
static unsigned long pci_id = PCI_ANY_ID;

static inline unsigned int get_intensity(unsigned int reg_value, int off, int min, int max) {
       
        if (reg_value == off)
                return 0;
        else
                return (reg_value - min) * (FB_BACKLIGHT_LEVELS - 1) / (max - min);
}

static inline unsigned int set_intensity(unsigned int intensity, int off, int min, int max, int forceoff) {
        if (forceoff)
                return off;
        else
                return min + (intensity * (max - min) / (FB_BACKLIGHT_LEVELS - 1));
}

/*
 * Implementation for NV4X chips
 * (NV40, NV41, NV43, NV44, NV46, NV47, NV49, NV4B, C51)
 */
static int nv4x_get_intensity(struct backlight_device *bd)
{
	struct driver_data *dd = bl_get_data(bd);
	unsigned short intensity = ioread16(dd->smartdimmer) & 0x1f;

        intensity = get_intensity(intensity, dd->off, dd->min, dd->max);

	return intensity;
}

static int nv4x_set_intensity(struct backlight_device *bd)
{
	struct driver_data *dd = bl_get_data(bd);
	unsigned intensity;
        
        intensity = set_intensity(
                bd->props.brightness, 
                dd->off, 
                dd->min, 
                dd->max, 
                (bd->props.power != FB_BLANK_UNBLANK || bd->props.fb_blank != FB_BLANK_UNBLANK)
        );
        
        iowrite16((ioread16(dd->smartdimmer) & ~0x1f) | intensity,
	          dd->smartdimmer);
	return 0;
}

static struct driver_data nv4x_driver_data = {
	.bar           = 0,
	.reg_offset    = 0x15f2,
	.reg_size      = 2,
        .off           = 0,
        .min           = 4,
        .max           = 21,
	.backlight_ops = {
#ifdef USE_BACKLIGHT_SUSPEND
		.options        = BL_CORE_SUSPENDRESUME,
#endif
		.get_brightness = nv4x_get_intensity,
		.update_status  = nv4x_set_intensity,
	}
};

/*
 * Implementation for NV5X chips
 * (NV50, G84, G86, G92, G94, G96, GT200)
 */
static int nv5x_get_intensity(struct backlight_device *bd)
{
	struct driver_data *dd = bl_get_data(bd);
	unsigned intensity = ioread32(dd->smartdimmer) &
		~NV5X_PDIPSLAY_SOR0_BRIGHTNESS_CONTROL_ENABLED;

        intensity = get_intensity(intensity, dd->off, dd->min, dd->max);

	return intensity;
}

static int nv5x_set_intensity(struct backlight_device *bd)
{
	struct driver_data *dd = bl_get_data(bd);
        unsigned intensity;
        
        intensity = set_intensity(
                bd->props.brightness, 
                dd->off, 
                dd->min, 
                dd->max, 
                (bd->props.power != FB_BLANK_UNBLANK || bd->props.fb_blank != FB_BLANK_UNBLANK)
        );
        
	iowrite32(intensity | NV5X_PDIPSLAY_SOR0_BRIGHTNESS_CONTROL_ENABLED,
		  dd->smartdimmer);
	return 0;
}

static struct driver_data nv5x_driver_data = {
	.bar           = 0,
	.reg_offset    = NV5X_PDISPLAY_OFFSET + NV5X_PDISPLAY_SOR0_BRIGHTNESS,
	.reg_size      = 4,
	.off           = 0,
	.min           = 1024,
	.max           = 140000,
	.backlight_ops = {
#ifdef USE_BACKLIGHT_SUSPEND
		.options        = BL_CORE_SUSPENDRESUME,
#endif
		.get_brightness = nv5x_get_intensity,
		.update_status  = nv5x_set_intensity,
	}
};

/*
 * Device matching.
 * The list of supported devices was primarily taken from NvClock,
 * but only contains the mobile chips.
 */
static DEFINE_PCI_DEVICE_TABLE(nvidia_bl_device_table) = {
	/* nVidia Geforce Go 7800GTX */
	{ PCI_VDEVICE(NVIDIA, 0x0099), (kernel_ulong_t)&nv4x_driver_data },
	/* nVidia Geforce Go 6800 */
	{ PCI_VDEVICE(NVIDIA, 0x00c8), (kernel_ulong_t)&nv4x_driver_data },
	/* nVidia Geforce Go 6800Ultra */
	{ PCI_VDEVICE(NVIDIA, 0x00c9), (kernel_ulong_t)&nv4x_driver_data },
	/* nVidia QuadroFX Go 1400 */
	{ PCI_VDEVICE(NVIDIA, 0x00cc), (kernel_ulong_t)&nv4x_driver_data },
	/* nVidia Geforce Go 6600 */
	{ PCI_VDEVICE(NVIDIA, 0x0144), (kernel_ulong_t)&nv4x_driver_data },
	/* nVidia GeForce Go 6600TE/6200TE */
	{ PCI_VDEVICE(NVIDIA, 0x0146), (kernel_ulong_t)&nv4x_driver_data },
	/* nVidia Geforce Go 6600 */
	{ PCI_VDEVICE(NVIDIA, 0x0148), (kernel_ulong_t)&nv4x_driver_data },
	/* nVidia Geforce Go 6600GT */
	{ PCI_VDEVICE(NVIDIA, 0x0149), (kernel_ulong_t)&nv4x_driver_data },
	/* nVidia Geforce Go 6200 */
	{ PCI_VDEVICE(NVIDIA, 0x0164), (kernel_ulong_t)&nv4x_driver_data },
	/* nVidia Geforce Go 6400 */
	{ PCI_VDEVICE(NVIDIA, 0x0166), (kernel_ulong_t)&nv4x_driver_data },
	/* nVidia Geforce Go 6200 */
	{ PCI_VDEVICE(NVIDIA, 0x0167), (kernel_ulong_t)&nv4x_driver_data },
	/* nVidia Geforce Go 6400 */
	{ PCI_VDEVICE(NVIDIA, 0x0168), (kernel_ulong_t)&nv4x_driver_data },
	/* nVidia Geforce Go 7300 */
	{ PCI_VDEVICE(NVIDIA, 0x01d7), (kernel_ulong_t)&nv4x_driver_data },
	/* nVidia Geforce Go 7400 */
	{ PCI_VDEVICE(NVIDIA, 0x01d8), (kernel_ulong_t)&nv4x_driver_data },
	/* nVidia Geforce Go 7400GS */
	{ PCI_VDEVICE(NVIDIA, 0x01d9), (kernel_ulong_t)&nv4x_driver_data },
	/* nVidia Quadro NVS 110M */
	{ PCI_VDEVICE(NVIDIA, 0x01da), (kernel_ulong_t)&nv4x_driver_data },
	/* nVidia Quadro NVS 120M */
	{ PCI_VDEVICE(NVIDIA, 0x01db), (kernel_ulong_t)&nv4x_driver_data },
	/* nVidia QuadroFX 350M */
	{ PCI_VDEVICE(NVIDIA, 0x01dc), (kernel_ulong_t)&nv4x_driver_data },
	/* nVidia Geforce 7500LE */
	{ PCI_VDEVICE(NVIDIA, 0x01dd), (kernel_ulong_t)&nv4x_driver_data },
	/* NV44M */
	{ PCI_VDEVICE(NVIDIA, 0x0228), (kernel_ulong_t)&nv4x_driver_data },
	/* nVidia Geforce Go 7950GTX */
	{ PCI_VDEVICE(NVIDIA, 0x0297), (kernel_ulong_t)&nv4x_driver_data },
	/* nVidia Geforce Go 7900GS */
	{ PCI_VDEVICE(NVIDIA, 0x0298), (kernel_ulong_t)&nv4x_driver_data },
	/* nVidia Geforce Go 7900GTX */
	{ PCI_VDEVICE(NVIDIA, 0x0299), (kernel_ulong_t)&nv4x_driver_data },
	/* nVidia QuadroFX 2500M */
	{ PCI_VDEVICE(NVIDIA, 0x029a), (kernel_ulong_t)&nv4x_driver_data },
	/* nVidia QuadroFX 1500M */
	{ PCI_VDEVICE(NVIDIA, 0x029b), (kernel_ulong_t)&nv4x_driver_data },
	/* nVidia Geforce Go 7700 */
	{ PCI_VDEVICE(NVIDIA, 0x0397), (kernel_ulong_t)&nv4x_driver_data },
	/* nVidia Geforce Go 7600 */
	{ PCI_VDEVICE(NVIDIA, 0x0398), (kernel_ulong_t)&nv4x_driver_data },
	/* nVidia Geforce Go 7600GT */
	{ PCI_VDEVICE(NVIDIA, 0x0399), (kernel_ulong_t)&nv4x_driver_data },
	/* nVidia Quadro NVS 300M */
	{ PCI_VDEVICE(NVIDIA, 0x039a), (kernel_ulong_t)&nv4x_driver_data },
	/* nVidia Geforce Go 7900SE */
	{ PCI_VDEVICE(NVIDIA, 0x039b), (kernel_ulong_t)&nv4x_driver_data },
	/* nVidia QuadroFX 550M */
	{ PCI_VDEVICE(NVIDIA, 0x039c), (kernel_ulong_t)&nv4x_driver_data },
	/* nVidia Geforce 9500M GS */
	{ PCI_VDEVICE(NVIDIA, 0x0405), (kernel_ulong_t)&nv5x_driver_data },
	/* nVidia Geforce NB9P-GE */
	{ PCI_VDEVICE(NVIDIA, 0x0406), (kernel_ulong_t)&nv5x_driver_data },
	/* nVidia Geforce 8600M GT */
	{ PCI_VDEVICE(NVIDIA, 0x0407), (kernel_ulong_t)&nv5x_driver_data },
	/* nVidia Geforce 8600M GTS */
	{ PCI_VDEVICE(NVIDIA, 0x0408), (kernel_ulong_t)&nv5x_driver_data },
	/* nVidia Geforce 8700M GT */
	{ PCI_VDEVICE(NVIDIA, 0x0409), (kernel_ulong_t)&nv5x_driver_data },
	/* nVidia Quadro NVS 370M */
	{ PCI_VDEVICE(NVIDIA, 0x040a), (kernel_ulong_t)&nv5x_driver_data },
	/* nVidia Quadro NVS 320M */
	{ PCI_VDEVICE(NVIDIA, 0x040b), (kernel_ulong_t)&nv5x_driver_data },
	/* nVidia QuadroFX 570M */
	{ PCI_VDEVICE(NVIDIA, 0x040c), (kernel_ulong_t)&nv5x_driver_data },
	/* nVidia QuadroFX 1600M */
	{ PCI_VDEVICE(NVIDIA, 0x040d), (kernel_ulong_t)&nv5x_driver_data },
	/* nVidia Geforce 8600M GS */
	{ PCI_VDEVICE(NVIDIA, 0x0425), (kernel_ulong_t)&nv5x_driver_data },
	/* nVidia Geforce 8400M GT */
	{ PCI_VDEVICE(NVIDIA, 0x0426), (kernel_ulong_t)&nv5x_driver_data },
	/* nVidia Geforce 8400M GS */
	{ PCI_VDEVICE(NVIDIA, 0x0427), (kernel_ulong_t)&nv5x_driver_data },
	/* nVidia Geforce 8400M G */
	{ PCI_VDEVICE(NVIDIA, 0x0428), (kernel_ulong_t)&nv5x_driver_data },
	/* nVidia Quadro NVS 140M */
	{ PCI_VDEVICE(NVIDIA, 0x0429), (kernel_ulong_t)&nv5x_driver_data },
	/* nVidia Quadro NVS 130M */
	{ PCI_VDEVICE(NVIDIA, 0x042a), (kernel_ulong_t)&nv5x_driver_data },
	/* nVidia Quadro NVS 135M */
	{ PCI_VDEVICE(NVIDIA, 0x042b), (kernel_ulong_t)&nv5x_driver_data },
	/* nVidia Quadro FX 360M */
	{ PCI_VDEVICE(NVIDIA, 0x042d), (kernel_ulong_t)&nv5x_driver_data },
	/* nVidia Geforce 9300M G */
	{ PCI_VDEVICE(NVIDIA, 0x042e), (kernel_ulong_t)&nv5x_driver_data },
	/* nVidia Geforce 8800M GTS */
	{ PCI_VDEVICE(NVIDIA, 0x0609), (kernel_ulong_t)&nv5x_driver_data },
	/* nVidia Geforce 8800M GTX */
	{ PCI_VDEVICE(NVIDIA, 0x060c), (kernel_ulong_t)&nv5x_driver_data },
	/* nVidia QuadroFX 3600M */
	{ PCI_VDEVICE(NVIDIA, 0x061c), (kernel_ulong_t)&nv5x_driver_data },
	/* nVidia Geforce 9600M GT */
	{ PCI_VDEVICE(NVIDIA, 0x0647), (kernel_ulong_t)&nv5x_driver_data },
	/* nVidia Geforce 9600M GS */
	{ PCI_VDEVICE(NVIDIA, 0x0648), (kernel_ulong_t)&nv5x_driver_data },
	/* nVidia Geforce 9600M GT */
	{ PCI_VDEVICE(NVIDIA, 0x0649), (kernel_ulong_t)&nv5x_driver_data },
	/* nVidia Geforce 9500M G */
	{ PCI_VDEVICE(NVIDIA, 0x064b), (kernel_ulong_t)&nv5x_driver_data },
	/* nVidia Geforce 9300M GS */
	{ PCI_VDEVICE(NVIDIA, 0x06e5), (kernel_ulong_t)&nv5x_driver_data },
	/* nVidia Geforce 9200M GS */
	{ PCI_VDEVICE(NVIDIA, 0x06e8), (kernel_ulong_t)&nv5x_driver_data },
	/* nVidia Geforce 9300M GS */
	{ PCI_VDEVICE(NVIDIA, 0x06e9), (kernel_ulong_t)&nv5x_driver_data },
	/* nVidia Quadro NVS 150M */
	{ PCI_VDEVICE(NVIDIA, 0x06ea), (kernel_ulong_t)&nv5x_driver_data },
	/* nVidia Quadro NVS 160M */
	{ PCI_VDEVICE(NVIDIA, 0x06eb), (kernel_ulong_t)&nv5x_driver_data },
	/* nVidia Geforce G105M */
	{ PCI_VDEVICE(NVIDIA, 0x06ec), (kernel_ulong_t)&nv5x_driver_data },
	/* nVidia QuadroFX 370M */
	{ PCI_VDEVICE(NVIDIA, 0x06fb), (kernel_ulong_t)&nv5x_driver_data },
	/* nVidia Geforce 9400M */
	{ PCI_VDEVICE(NVIDIA, 0x0863), (kernel_ulong_t)&nv5x_driver_data },
	/* NVIDIA GeForce 9400M */
	{ PCI_VDEVICE(NVIDIA, 0x0870), (kernel_ulong_t)&nv5x_driver_data },
	/* NVIDIA GeForce 9200 */
	{ PCI_VDEVICE(NVIDIA, 0x0871), (kernel_ulong_t)&nv5x_driver_data },
	/* NVIDIA GeForce G102M */
	{ PCI_VDEVICE(NVIDIA, 0x0872), (kernel_ulong_t)&nv5x_driver_data },
	/* NVIDIA GeForce G102M */
	{ PCI_VDEVICE(NVIDIA, 0x0873), (kernel_ulong_t)&nv5x_driver_data },
	/* NVIDIA GeForce GT 230M */
	{ PCI_VDEVICE(NVIDIA, 0x0A2A), (kernel_ulong_t)&nv5x_driver_data },
	/* end of list */
	{ }
};

/*
 * DMI matching.
 * Used to ignore the wrong device on machines incorporating 2
 * graphics adapters, such as the Apple MacBook Pro 5.
 */
static int nvidia_bl_wrong_dmi_match(const struct dmi_system_id *id)
{
        printk(KERN_INFO "nvidia_bl: %s model detected in ignore tables\n", id->ident);
        nvidia_bl_ignore_device = (unsigned long)id->driver_data;
        return 1;
}

static const struct dmi_system_id /* __initdata */ nvidia_bl_ignore_table[] = {
	{
		.callback	= &nvidia_bl_wrong_dmi_match,
		.ident		= "MacBookPro 5,1",
		.matches	= {
			DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
			DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro5,1"),
		},
		.driver_data	= (void *)0x0863, /* nVidia Geforce 9400M */
	},
	{
		.callback	= &nvidia_bl_wrong_dmi_match,
		.ident		= "MacBookPro 5,2",
		.matches	= {
			DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
			DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro5,2"),
		},
		.driver_data	= (void *)0x0863, /* nVidia Geforce 9400M */
	},
	{
		.callback	= &nvidia_bl_wrong_dmi_match,
		.ident		= "MacBookPro 5,5",
		.matches	= {
			DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
			DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro5,5"),
		},
		.driver_data	= (void *)0x0863, /* nVidia Geforce 9400M */
	},
        /* end of list */
        { }
};

/*
 * DMI matching.
 * Used to autoload driver
 */
static int nvidia_bl_dmi_match(const struct dmi_system_id *id)
{
        printk(KERN_INFO "nvidia_bl: %s model detected in DMI tables\n", id->ident);
        pci_id = (unsigned long)id->driver_data;
        return 1;
}

static const struct dmi_system_id /* __initdata */ nvidia_bl_dmi_table[] = {
        {
                .callback       = &nvidia_bl_dmi_match,
                .ident          = "VGN-AW11",
                .matches        = {
                        DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
                        DMI_MATCH(DMI_PRODUCT_NAME, "VGN-AW11"),
                },
                .driver_data    = (void *)0x06e9,       /* nVidia Geforce 9300M GS - obtained from lspci -nn */
        },
        {
                .callback       = &nvidia_bl_dmi_match,
                .ident          = "VGN-FZ11",
                .matches        = {
                        DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
                        DMI_MATCH(DMI_PRODUCT_NAME, "VGN-FZ11"),
                },
                .driver_data    = (void *)0x0426,       /* nVidia Geforce 8400M GS - obtained from lspci -nn */
        },
        {
                .callback       = &nvidia_bl_dmi_match,
                .ident          = "VGN-FZ38",
                .matches        = {
                        DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
                        DMI_MATCH(DMI_PRODUCT_NAME, "VGN-FZ38"),
                },
                .driver_data    = (void *)0x0426,       /* nVidia Geforce 8400M GS - obtained from lspci -nn */
        },
        /* end of list */
        { }
};

/*
 * Driver data implementation
 */
static const struct pci_device_id *nvidia_bl_match_id(struct pci_dev *dev)
{
	/* Search id in table */
	const struct pci_device_id *id = pci_match_id(nvidia_bl_device_table, dev);

	return id;
}

static int nvidia_bl_find_device(struct driver_data **dd, unsigned pci_device, unsigned ignore_device)
{
	struct pci_dev *dev = NULL;
	const struct pci_device_id *id;

	/* For each PCI device */
	while ((dev = pci_get_device(PCI_VENDOR_ID_NVIDIA, pci_device, dev))) {
		/* ... lookup id struct */
                id = nvidia_bl_match_id(dev);
                if (id && (!ignore_device || (dev->device != ignore_device))) {
                        printk(KERN_INFO "nvidia_bl: Supported Nvidia graphics"
                              " adapter %04x:%04x:%04x:%04x detected\n",
                              id->vendor, id->device,
                              dev->subsystem_vendor, dev->subsystem_device);

                        /* Setup driver data */
                        *dd = (struct driver_data *)id->driver_data;
                        (*dd)->dev = dev;
                        return 0;
                }
	}

	printk(KERN_INFO "nvidia_bl: No supported Nvidia graphics adapter"
	       " found\n");
	return -ENODEV;
}

static int nvidia_bl_map_smartdimmer(struct driver_data *dd)
{
	/* Get resource properties */
	const unsigned long bar_start = pci_resource_start(dd->dev, dd->bar),
			    bar_end   = pci_resource_end(dd->dev, dd->bar),
			    bar_flags = pci_resource_flags(dd->dev, dd->bar);
	/* Calculate register address */
	const unsigned long reg_addr  = bar_start + dd->reg_offset;

	/* Sanity check 1: Should be a memory region containing registers */
	if (!(bar_flags & IORESOURCE_MEM))
		return -ENODEV;
	if (bar_flags & IORESOURCE_PREFETCH)
		return -ENODEV;

	/* Sanity check 2: Address should not exceed the PCI BAR */
	if (reg_addr + dd->reg_size - 1 > bar_end)
		return -ENODEV;

	/* Now really map (The address need not be page-aligned.) */
	dd->smartdimmer = ioremap_nocache(reg_addr, dd->reg_size);
	if (!dd->smartdimmer)
		return -ENXIO;

	return 0;
}

static void nvidia_bl_unmap_smartdimmer(struct driver_data *dd)
{
	iounmap(dd->smartdimmer);
	dd->smartdimmer = NULL;
}

/*
 * Driver implementation
 */
static struct driver_data *driver_data = NULL;
static struct backlight_device *nvidia_bl_device;

#ifdef USE_PLATFORM_DRIVER
static int nvidia_bl_probe(struct platform_device *pdev)
#else
static int __init nvidia_bl_init(void)
#endif
{
 struct backlight_properties props;
 
	int err;

	/* Bail-out if PCI subsystem is not initialized */
	if (no_pci_devices())
		return -ENODEV;

	/* Check DMI whether we need to ignore some device */
	dmi_check_system(nvidia_bl_ignore_table);
        
        /* Check DMI whether we have a known system */
        dmi_check_system(nvidia_bl_dmi_table);

        err = nvidia_bl_find_device(&driver_data, pci_id, nvidia_bl_ignore_device);
        if (err)
                return err;
        
        /* Map smartdimmer */
	err = nvidia_bl_map_smartdimmer(driver_data);
	if (err)
		return err;

	/* Register at backlight framework */
	memset(&props, 0, sizeof(struct backlight_properties));
	nvidia_bl_device = backlight_device_register("nvidia_backlight", NULL,
	                                             driver_data,
	                                             &driver_data->backlight_ops,
						     &props);
	if (IS_ERR(nvidia_bl_device)) {
		nvidia_bl_unmap_smartdimmer(driver_data);
		return PTR_ERR(nvidia_bl_device);
	}

	/* Set up backlight device */
        nvidia_bl_device->props.max_brightness = FB_BACKLIGHT_LEVELS - 1;
	nvidia_bl_device->props.brightness =
		nvidia_bl_device->ops->get_brightness(nvidia_bl_device);
	backlight_update_status(nvidia_bl_device);
	return 0;
}

#ifdef USE_PLATFORM_DRIVER
static int nvidia_bl_remove(struct platform_device *pdev)
#else
static void __exit nvidia_bl_exit(void)
#endif
{
	/* Unregister at backlight framework */
	if (nvidia_bl_device)
		backlight_device_unregister(nvidia_bl_device);

	/* Unmap smartdimmer */
	if (driver_data->smartdimmer)
		nvidia_bl_unmap_smartdimmer(driver_data);

	/* Release PCI device */
	if (driver_data->dev)
		pci_dev_put(driver_data->dev);
#ifdef USE_PLATFORM_DRIVER
	return 0;
#endif
}

/*
 * Platform driver implementation
 */
#ifdef USE_PLATFORM_DRIVER

static int nvidia_bl_resume(struct platform_device *pdev)
{
	backlight_update_status(nvidia_bl_device);
	return 0;
}

static struct platform_driver nvidia_bl_driver = {
	.probe          = nvidia_bl_probe,
	.remove         = nvidia_bl_remove,
	.resume         = nvidia_bl_resume,
	.driver         = {
		.owner  = THIS_MODULE,
		.name   = "nvidia_bl"
	},
};

static struct platform_device *nvidia_bl_platform_device;

static int __init nvidia_bl_init(void)
{
	int err;

	err = platform_driver_register(&nvidia_bl_driver);
	if (err)
		return err;

	nvidia_bl_platform_device =
		platform_device_register_simple("nvidia_bl", -1, NULL, 0);
	if (!nvidia_bl_platform_device) {
		platform_driver_unregister(&nvidia_bl_driver);
		return -ENOMEM;
	}

	return 0;
}

static void __exit nvidia_bl_exit(void)
{
	platform_device_unregister(nvidia_bl_platform_device);
	platform_driver_unregister(&nvidia_bl_driver);
}

#endif /* USE_PLATFORM_DRIVER */

module_init(nvidia_bl_init);
module_exit(nvidia_bl_exit);

MODULE_AUTHOR("Mario Schwalbe <schwalbe@inf.tu-dresden.de>");
MODULE_DESCRIPTION("Nvidia-based graphics adapter backlight driver");
MODULE_LICENSE("GPL");

MODULE_DEVICE_TABLE(dmi, nvidia_bl_dmi_table);
damdim is offline   Reply With Quote
Old 05-25-10, 06:11 PM   #59
superlex88
Registered User
 
Join Date: May 2010
Posts: 4
Smile Re: Linux backlight driver

I have tested this in openSUSE 11.3 with kernel 2.6.34-8, and it work very well

Thanks a lot
superlex88 is offline   Reply With Quote
Old 07-01-10, 03:32 PM   #60
muddenhed
Creator of oBacklight
 
Join Date: Apr 2010
Posts: 19
Default Re: Linux backlight driver

I have tested it with openSUSE 11.3 to and it works great with the changes done by damdim did in combination with my own script which i would be glad if anyone could like to try out.

You can find it here..., it's called oBacklight.

/Marcus
muddenhed is offline   Reply With Quote
Reply


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 01:20 AM.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Copyright ©1998 - 2014, nV News.