diff mbox

Legacy backlight control with KMS and BACKLIGHT property

Message ID 20090816220827.GB20988@kroah.com (mailing list archive)
State Not Applicable
Headers show

Commit Message

Greg KH Aug. 16, 2009, 10:08 p.m. UTC
On Sat, Aug 15, 2009 at 01:33:13PM +0100, Mike Lothian wrote:
> 2009/8/15 Jesse Barnes <jbarnes@virtuousgeek.org>:
> > On Fri, 14 Aug 2009 12:28:47 -0700
> > Greg KH <greg@kroah.com> wrote:
> >
> >> On Fri, Aug 14, 2009 at 12:08:21PM -0700, Greg KH wrote:
> >> > Here's a first cut at such a driver.  It works for me on this
> >> > laptop, but note that it will try to work on _any_ Intel-based
> >> > system.  I'll figure out how to do this only for specific machines
> >> > based on DMI data next.
> >>
> >> And here's one that is set for DMI data to only load on the proper
> >> ones.
> >>
> >> I'll push this upstream now, if there are no objections.
> >
> > Yeah, looks fairly reasonable.  This code should work on most pre-965
> > chipsets too, since they share the LBB regs.  There are a couple of
> > other things to take into consideration: I think the VBIOS indicates
> > whether the controls are inverted (i.e. a value of 0xff is minimum
> > brightness) and there may also be some stepping info.
> >
> > So ultimately I'd like to see this be part of the i915 driver as one of
> > a few different methods supported (hopefully we can autodetect them
> > better than the 2D driver though, using the VBIOS and DMI in the
> > kernel).
> >
> > The other three methods that need to export sysfs interfaces are
> > OpRegion (already done), i2c (some machines have external controllers;
> > the VBIOS describes how to interact with them) and PWM (the "native"
> > power modulation regs).
> 
> This is great news guys, hopefully I'll finally be able to control the
> screen brightness of my GM45 in my Samsung R510
> 
> If you want a guinea pig to test your code please feel free to forward patches

A driver for other Samsung devices is below.  If you think your laptop
also works this way (by changing the brightness value by reading and
writing the 0xf4 pci config value directly), then we can add support for
your laptop to this driver as well, just send me the output of:
	lspci
	lspci -n
	grep . /sys/class/dmi/id/*

thanks,

greg k-h

-----------
From: Greg Kroah-Hartman <gregkh@suse.de>
Subject: Samsung backlight driver

This driver implements backlight controls for Samsung laptops that
currently do not have ACPI support for this control.

It has been tested on the N130 laptop and properly works there.

Info for the NC10 was provided by Soeren Sonnenburg <bugreports@nn7.de>
Info for the NP-Q45 from Jérémie Huchet <jeremie@lamah.info>

Many thanks to Dmitry Torokhov <dmitry.torokhov@gmail.com> for cleanups
and other suggestions on how to make the driver simpler.

Cc: Soeren Sonnenburg <bugreports@nn7.de>
Cc: Jérémie Huchet <jeremie@lamah.info>
Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

---
 drivers/platform/x86/Kconfig             |   12 ++
 drivers/platform/x86/Makefile            |    1 
 drivers/platform/x86/samsung-backlight.c |  157 +++++++++++++++++++++++++++++++
 3 files changed, 170 insertions(+)

Comments

Mike Lothian Aug. 17, 2009, 12:41 a.m. UTC | #1
2009/8/16 Greg KH <greg@kroah.com>:
> On Sat, Aug 15, 2009 at 01:33:13PM +0100, Mike Lothian wrote:
>> 2009/8/15 Jesse Barnes <jbarnes@virtuousgeek.org>:
>> > On Fri, 14 Aug 2009 12:28:47 -0700
>> > Greg KH <greg@kroah.com> wrote:
>> >
>> >> On Fri, Aug 14, 2009 at 12:08:21PM -0700, Greg KH wrote:
>> >> > Here's a first cut at such a driver.  It works for me on this
>> >> > laptop, but note that it will try to work on _any_ Intel-based
>> >> > system.  I'll figure out how to do this only for specific machines
>> >> > based on DMI data next.
>> >>
>> >> And here's one that is set for DMI data to only load on the proper
>> >> ones.
>> >>
>> >> I'll push this upstream now, if there are no objections.
>> >
>> > Yeah, looks fairly reasonable.  This code should work on most pre-965
>> > chipsets too, since they share the LBB regs.  There are a couple of
>> > other things to take into consideration: I think the VBIOS indicates
>> > whether the controls are inverted (i.e. a value of 0xff is minimum
>> > brightness) and there may also be some stepping info.
>> >
>> > So ultimately I'd like to see this be part of the i915 driver as one of
>> > a few different methods supported (hopefully we can autodetect them
>> > better than the 2D driver though, using the VBIOS and DMI in the
>> > kernel).
>> >
>> > The other three methods that need to export sysfs interfaces are
>> > OpRegion (already done), i2c (some machines have external controllers;
>> > the VBIOS describes how to interact with them) and PWM (the "native"
>> > power modulation regs).
>>
>> This is great news guys, hopefully I'll finally be able to control the
>> screen brightness of my GM45 in my Samsung R510
>>
>> If you want a guinea pig to test your code please feel free to forward patches
>
> A driver for other Samsung devices is below.  If you think your laptop
> also works this way (by changing the brightness value by reading and
> writing the 0xf4 pci config value directly), then we can add support for
> your laptop to this driver as well, just send me the output of:
>        lspci
>        lspci -n
>        grep . /sys/class/dmi/id/*
>
> thanks,
>


> +       {
> +               .ident = "NP-Q45",
> +               .matches = {
> +                       DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
> +                       DMI_MATCH(DMI_PRODUCT_NAME, "SQ45S70S"),
> +                       DMI_MATCH(DMI_BOARD_NAME, "SQ45S70S"),
> +               },
> +               .callback = dmi_check_cb,
> +       },

> +        */
> +       pci_device = pci_get_device(PCI_VENDOR_ID_INTEL, 0x27ae, NULL);
> +       if (!pci_device) {
> +               pci_device = pci_get_device(PCI_VENDOR_ID_INTEL, 0x2a02, NULL);
> +               if (!pci_device)
> +                       return -ENODEV;


You are an absolute STAR Greg!!!

Finally I have brightness control for this laptop on Linux

I needed to set the DMI names to "R510/P510" and the pci device to
0x2a42 but apart from that it works!!!

Now I just have to get the keys working :D

Mike
Greg KH Aug. 17, 2009, 4:10 p.m. UTC | #2
On Mon, Aug 17, 2009 at 01:41:03AM +0100, Mike Lothian wrote:
> 2009/8/16 Greg KH <greg@kroah.com>:
> > On Sat, Aug 15, 2009 at 01:33:13PM +0100, Mike Lothian wrote:
> >> 2009/8/15 Jesse Barnes <jbarnes@virtuousgeek.org>:
> >> > On Fri, 14 Aug 2009 12:28:47 -0700
> >> > Greg KH <greg@kroah.com> wrote:
> >> >
> >> >> On Fri, Aug 14, 2009 at 12:08:21PM -0700, Greg KH wrote:
> >> >> > Here's a first cut at such a driver.  It works for me on this
> >> >> > laptop, but note that it will try to work on _any_ Intel-based
> >> >> > system.  I'll figure out how to do this only for specific machines
> >> >> > based on DMI data next.
> >> >>
> >> >> And here's one that is set for DMI data to only load on the proper
> >> >> ones.
> >> >>
> >> >> I'll push this upstream now, if there are no objections.
> >> >
> >> > Yeah, looks fairly reasonable.  This code should work on most pre-965
> >> > chipsets too, since they share the LBB regs.  There are a couple of
> >> > other things to take into consideration: I think the VBIOS indicates
> >> > whether the controls are inverted (i.e. a value of 0xff is minimum
> >> > brightness) and there may also be some stepping info.
> >> >
> >> > So ultimately I'd like to see this be part of the i915 driver as one of
> >> > a few different methods supported (hopefully we can autodetect them
> >> > better than the 2D driver though, using the VBIOS and DMI in the
> >> > kernel).
> >> >
> >> > The other three methods that need to export sysfs interfaces are
> >> > OpRegion (already done), i2c (some machines have external controllers;
> >> > the VBIOS describes how to interact with them) and PWM (the "native"
> >> > power modulation regs).
> >>
> >> This is great news guys, hopefully I'll finally be able to control the
> >> screen brightness of my GM45 in my Samsung R510
> >>
> >> If you want a guinea pig to test your code please feel free to forward patches
> >
> > A driver for other Samsung devices is below.  If you think your laptop
> > also works this way (by changing the brightness value by reading and
> > writing the 0xf4 pci config value directly), then we can add support for
> > your laptop to this driver as well, just send me the output of:
> >        lspci
> >        lspci -n
> >        grep . /sys/class/dmi/id/*
> >
> > thanks,
> >
> 
> 
> > +       {
> > +               .ident = "NP-Q45",
> > +               .matches = {
> > +                       DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
> > +                       DMI_MATCH(DMI_PRODUCT_NAME, "SQ45S70S"),
> > +                       DMI_MATCH(DMI_BOARD_NAME, "SQ45S70S"),
> > +               },
> > +               .callback = dmi_check_cb,
> > +       },
> 
> > +        */
> > +       pci_device = pci_get_device(PCI_VENDOR_ID_INTEL, 0x27ae, NULL);
> > +       if (!pci_device) {
> > +               pci_device = pci_get_device(PCI_VENDOR_ID_INTEL, 0x2a02, NULL);
> > +               if (!pci_device)
> > +                       return -ENODEV;
> 
> 
> You are an absolute STAR Greg!!!
> 
> Finally I have brightness control for this laptop on Linux
> 
> I needed to set the DMI names to "R510/P510" and the pci device to
> 0x2a42 but apart from that it works!!!

Care to send me a patch for the driver to add support for this device?

Or just send me the output of:
	grep . /sys/class/dmi/id/*
and I'll add it myself.

thanks,

greg k-h
Mike Lothian Aug. 19, 2009, 12:10 a.m. UTC | #3
2009/8/17 Greg KH <greg@kroah.com>:
> On Mon, Aug 17, 2009 at 01:41:03AM +0100, Mike Lothian wrote:
>> 2009/8/16 Greg KH <greg@kroah.com>:
>> > On Sat, Aug 15, 2009 at 01:33:13PM +0100, Mike Lothian wrote:
>> >> 2009/8/15 Jesse Barnes <jbarnes@virtuousgeek.org>:
>> >> > On Fri, 14 Aug 2009 12:28:47 -0700
>> >> > Greg KH <greg@kroah.com> wrote:
>> >> >
>> >> >> On Fri, Aug 14, 2009 at 12:08:21PM -0700, Greg KH wrote:
>> >> >> > Here's a first cut at such a driver.  It works for me on this
>> >> >> > laptop, but note that it will try to work on _any_ Intel-based
>> >> >> > system.  I'll figure out how to do this only for specific machines
>> >> >> > based on DMI data next.
>> >> >>
>> >> >> And here's one that is set for DMI data to only load on the proper
>> >> >> ones.
>> >> >>
>> >> >> I'll push this upstream now, if there are no objections.
>> >> >
>> >> > Yeah, looks fairly reasonable.  This code should work on most pre-965
>> >> > chipsets too, since they share the LBB regs.  There are a couple of
>> >> > other things to take into consideration: I think the VBIOS indicates
>> >> > whether the controls are inverted (i.e. a value of 0xff is minimum
>> >> > brightness) and there may also be some stepping info.
>> >> >
>> >> > So ultimately I'd like to see this be part of the i915 driver as one of
>> >> > a few different methods supported (hopefully we can autodetect them
>> >> > better than the 2D driver though, using the VBIOS and DMI in the
>> >> > kernel).
>> >> >
>> >> > The other three methods that need to export sysfs interfaces are
>> >> > OpRegion (already done), i2c (some machines have external controllers;
>> >> > the VBIOS describes how to interact with them) and PWM (the "native"
>> >> > power modulation regs).
>> >>
>> >> This is great news guys, hopefully I'll finally be able to control the
>> >> screen brightness of my GM45 in my Samsung R510
>> >>
>> >> If you want a guinea pig to test your code please feel free to forward patches
>> >
>> > A driver for other Samsung devices is below.  If you think your laptop
>> > also works this way (by changing the brightness value by reading and
>> > writing the 0xf4 pci config value directly), then we can add support for
>> > your laptop to this driver as well, just send me the output of:
>> >        lspci
>> >        lspci -n
>> >        grep . /sys/class/dmi/id/*
>> >
>> > thanks,
>> >
>>
>>
>> > +       {
>> > +               .ident = "NP-Q45",
>> > +               .matches = {
>> > +                       DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
>> > +                       DMI_MATCH(DMI_PRODUCT_NAME, "SQ45S70S"),
>> > +                       DMI_MATCH(DMI_BOARD_NAME, "SQ45S70S"),
>> > +               },
>> > +               .callback = dmi_check_cb,
>> > +       },
>>
>> > +        */
>> > +       pci_device = pci_get_device(PCI_VENDOR_ID_INTEL, 0x27ae, NULL);
>> > +       if (!pci_device) {
>> > +               pci_device = pci_get_device(PCI_VENDOR_ID_INTEL, 0x2a02, NULL);
>> > +               if (!pci_device)
>> > +                       return -ENODEV;
>>
>>
>> You are an absolute STAR Greg!!!
>>
>> Finally I have brightness control for this laptop on Linux
>>
>> I needed to set the DMI names to "R510/P510" and the pci device to
>> 0x2a42 but apart from that it works!!!
>
> Care to send me a patch for the driver to add support for this device?
>
> Or just send me the output of:
>        grep . /sys/class/dmi/id/*
> and I'll add it myself.
>
> thanks,
>
> greg k-h
>

tau fireburn # grep . /sys/class/dmi/id/*
/sys/class/dmi/id/bios_date:09/26/2008
/sys/class/dmi/id/bios_vendor:Phoenix Technologies Ltd.
/sys/class/dmi/id/bios_version:07LI.MP00.20080926.SCY
/sys/class/dmi/id/board_name:R510/P510
/sys/class/dmi/id/board_serial:123490EN400015
/sys/class/dmi/id/board_vendor:SAMSUNG ELECTRONICS CO., LTD.
/sys/class/dmi/id/board_version:Not Applicable
/sys/class/dmi/id/chassis_asset_tag:No Asset Tag
/sys/class/dmi/id/chassis_serial:None
/sys/class/dmi/id/chassis_type:10
/sys/class/dmi/id/chassis_vendor:SAMSUNG ELECTRONICS CO., LTD.
/sys/class/dmi/id/chassis_version:N/A
/sys/class/dmi/id/modalias:dmi:bvnPhoenixTechnologiesLtd.:bvr07LI.MP00.20080926.SCY:bd09/26/2008:svnSAMSUNGELECTRONICSCO.,LTD.:pnR510/P510:pvrNotApplicable:rvnSAMSUNGELECTRONICSCO.,LTD.:rnR510/P510:rvrNotApplicable:cvnSAMSUNGELECTRONICSCO.,LTD.:ct10:cvrN/A:
/sys/class/dmi/id/product_name:R510/P510
/sys/class/dmi/id/product_serial:EJ1893DQ700599
/sys/class/dmi/id/product_uuid:60B6C327-D21D-B211-8000-B5CE02D5709F
/sys/class/dmi/id/product_version:Not Applicable
/sys/class/dmi/id/sys_vendor:SAMSUNG ELECTRONICS CO., LTD.
/sys/class/dmi/id/uevent:MODALIAS=dmi:bvnPhoenixTechnologiesLtd.:bvr07LI.MP00.20080926.SCY:bd09/26/2008:svnSAMSUNGELECTRONICSCO.,LTD.:pnR510/P510:pvrNotApplicable:rvnSAMSUNGELECTRONICSCO.,LTD.:rnR510/P510:rvrNotApplicable:cvnSAMSUNGELECTRONICSCO.,LTD.:ct10:cvrN/A:
diff mbox

Patch

--- a/drivers/platform/x86/Kconfig
+++ b/drivers/platform/x86/Kconfig
@@ -425,4 +425,16 @@  config ACPI_TOSHIBA
 
 	  If you have a legacy free Toshiba laptop (such as the Libretto L1
 	  series), say Y.
+
+config SAMSUNG_BACKLIGHT
+	tristate "Samsung Backlight driver"
+	depends on BACKLIGHT_CLASS_DEVICE
+	depends on DMI
+	---help---
+	  This driver adds support to control the backlight on a number of
+	  Samsung laptops, like the N130.
+
+	  It will only be loaded on laptops that properly need it, so it is
+	  safe to say Y here.
+
 endif # X86_PLATFORM_DEVICES
--- a/drivers/platform/x86/Makefile
+++ b/drivers/platform/x86/Makefile
@@ -20,3 +20,4 @@  obj-$(CONFIG_INTEL_MENLOW)	+= intel_menl
 obj-$(CONFIG_ACPI_WMI)		+= wmi.o
 obj-$(CONFIG_ACPI_ASUS)		+= asus_acpi.o
 obj-$(CONFIG_ACPI_TOSHIBA)	+= toshiba_acpi.o
+obj-$(CONFIG_SAMSUNG_BACKLIGHT)	+= samsung-backlight.o
--- /dev/null
+++ b/drivers/platform/x86/samsung-backlight.c
@@ -0,0 +1,157 @@ 
+/*
+ * Samsung N130 and NC10 Laptop Backlight driver
+ *
+ * Copyright (C) 2009 Greg Kroah-Hartman (gregkh@suse.de)
+ * Copyright (C) 2009 Novell Inc.
+ *
+ * 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/kernel.h>
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/pci.h>
+#include <linux/backlight.h>
+#include <linux/fb.h>
+#include <linux/dmi.h>
+
+#define MAX_BRIGHT	0xff
+#define OFFSET		0xf4
+
+static int offset = OFFSET;
+module_param(offset, int, S_IRUGO | S_IWUSR);
+MODULE_PARM_DESC(offset, "The offset into the PCI device for the brightness control");
+
+static struct pci_dev *pci_device;
+static struct backlight_device *backlight_device;
+
+static u8 read_brightness(void)
+{
+	u8 brightness;
+
+	pci_read_config_byte(pci_device, offset, &brightness);
+	return brightness;
+}
+
+static void set_brightness(u8 brightness)
+{
+	pci_write_config_byte(pci_device, offset, brightness);
+}
+
+static int get_brightness(struct backlight_device *bd)
+{
+	return bd->props.brightness;
+}
+
+static int update_status(struct backlight_device *bd)
+{
+	set_brightness(bd->props.brightness);
+	return 0;
+}
+
+static struct backlight_ops backlight_ops = {
+	.get_brightness	= get_brightness,
+	.update_status	= update_status,
+};
+
+static int __init dmi_check_cb(const struct dmi_system_id *id)
+{
+	printk(KERN_INFO KBUILD_MODNAME ": found laptop model '%s'\n",
+		id->ident);
+	return 0;
+}
+
+static struct dmi_system_id __initdata samsung_dmi_table[] = {
+	{
+		.ident = "N120",
+		.matches = {
+			DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
+			DMI_MATCH(DMI_PRODUCT_NAME, "N120"),
+			DMI_MATCH(DMI_BOARD_NAME, "N120"),
+		},
+		.callback = dmi_check_cb,
+	},
+	{
+		.ident = "N130",
+		.matches = {
+			DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
+			DMI_MATCH(DMI_PRODUCT_NAME, "N130"),
+			DMI_MATCH(DMI_BOARD_NAME, "N130"),
+		},
+		.callback = dmi_check_cb,
+	},
+	{
+		.ident = "NC10",
+		.matches = {
+			DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
+			DMI_MATCH(DMI_PRODUCT_NAME, "NC10"),
+			DMI_MATCH(DMI_BOARD_NAME, "NC10"),
+		},
+		.callback = dmi_check_cb,
+	},
+	{
+		.ident = "NP-Q45",
+		.matches = {
+			DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
+			DMI_MATCH(DMI_PRODUCT_NAME, "SQ45S70S"),
+			DMI_MATCH(DMI_BOARD_NAME, "SQ45S70S"),
+		},
+		.callback = dmi_check_cb,
+	},
+	{ },
+};
+
+static int __init samsung_init(void)
+{
+	if (!dmi_check_system(samsung_dmi_table))
+		return -ENODEV;
+
+	/*
+	 * The Samsung N120, N130, and NC10 use pci device id 0x27ae, while the
+	 * NP-Q45 uses 0x2a02.  Odds are we might need to add more to the
+	 * list over time...
+	 */
+	pci_device = pci_get_device(PCI_VENDOR_ID_INTEL, 0x27ae, NULL);
+	if (!pci_device) {
+		pci_device = pci_get_device(PCI_VENDOR_ID_INTEL, 0x2a02, NULL);
+		if (!pci_device)
+			return -ENODEV;
+	}
+
+	/* create a backlight device to talk to this one */
+	backlight_device = backlight_device_register("samsung",
+						     &pci_device->dev,
+						     NULL, &backlight_ops);
+	if (IS_ERR(backlight_device)) {
+		pci_dev_put(pci_device);
+		return PTR_ERR(backlight_device);
+	}
+
+	backlight_device->props.max_brightness = MAX_BRIGHT;
+	backlight_device->props.brightness = read_brightness();
+	backlight_device->props.power = FB_BLANK_UNBLANK;
+	backlight_update_status(backlight_device);
+
+	return 0;
+}
+
+static void __exit samsung_exit(void)
+{
+	backlight_device_unregister(backlight_device);
+
+	/* we are done with the PCI device, put it back */
+	pci_dev_put(pci_device);
+}
+
+module_init(samsung_init);
+module_exit(samsung_exit);
+
+MODULE_AUTHOR("Greg Kroah-Hartman <gregkh@suse.de>");
+MODULE_DESCRIPTION("Samsung Backlight driver");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("dmi:*:svnSAMSUNGELECTRONICSCO.,LTD.:pnN120:*:rnN120:*");
+MODULE_ALIAS("dmi:*:svnSAMSUNGELECTRONICSCO.,LTD.:pnN130:*:rnN130:*");
+MODULE_ALIAS("dmi:*:svnSAMSUNGELECTRONICSCO.,LTD.:pnNC10:*:rnNC10:*");
+MODULE_ALIAS("dmi:*:svnSAMSUNGELECTRONICSCO.,LTD.:pnSQ45S70S:*:rnSQ45S70S:*");