public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Greg KH <greg@kroah.com>
To: linux-kernel@vger.kernel.org
Cc: "Dmitry Torokhov" <dmitry.torokhov@gmail.com>,
	"Soeren Sonnenburg" <bugreports@nn7.de>,
	"Jérémie Huchet" <jeremie@lamah.info>
Subject: Re: [PATCH] Samsung backlight driver
Date: Fri, 14 Aug 2009 15:48:35 -0700	[thread overview]
Message-ID: <20090814224835.GA31585@kroah.com> (raw)
In-Reply-To: <20090814222533.26D94526EC9@mailhub.coreip.homeip.net>

Here's an updated version, with two more laptop models supported, and
the comments from Dmitry added in.

thanks,

greg k-h

----------------


From: Greg Kroah-Hartman <gregkh@suse.de>

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>

Cc: Soeren Sonnenburg <bugreports@nn7.de>
Cc: Jérémie Huchet <jeremie@lamah.info>
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 |  168 +++++++++++++++++++++++++++++++
 3 files changed, 181 insertions(+)

--- 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,168 @@
+/*
+ * 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 struct pci_dev *pci_device;
+static struct backlight_device *backlight_device;
+static int offset = OFFSET;
+static u8 current_brightness;
+
+static void read_brightness(void)
+{
+	if (!pci_device)
+		return;
+	pci_read_config_byte(pci_device, offset, &current_brightness);
+}
+
+static void set_brightness(void)
+{
+	if (!pci_device)
+		return;
+	pci_write_config_byte(pci_device, offset, current_brightness);
+}
+
+static int get_brightness(struct backlight_device *bd)
+{
+	return bd->props.brightness;
+}
+
+static int update_status(struct backlight_device *bd)
+{
+	if (!pci_device)
+		return -ENODEV;
+
+	current_brightness = bd->props.brightness;
+	set_brightness();
+	return 0;
+}
+
+static struct backlight_ops backlight_ops = {
+	.get_brightness	= get_brightness,
+	.update_status	= update_status,
+};
+
+static int find_video_card(void)
+{
+	struct pci_dev *dev = NULL;
+
+	while ((dev = pci_get_device(0x8086, 0x27ae, dev)) != NULL) {
+		/*
+		 * Found one, so let's save it off and break
+		 * Note that the reference is still raised on
+		 * the PCI device here.
+		 */
+		pci_device = dev;
+		break;
+	}
+
+	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))
+		return PTR_ERR(backlight_device);
+	read_brightness();
+	backlight_device->props.max_brightness = MAX_BRIGHT;
+	backlight_device->props.brightness = current_brightness;
+	backlight_device->props.power = FB_BLANK_UNBLANK;
+	backlight_update_status(backlight_device);
+	return 0;
+}
+
+static void remove_video_card(void)
+{
+	if (!pci_device)
+		return;
+
+	backlight_device_unregister(backlight_device);
+	backlight_device = NULL;
+
+	/* we are done with the PCI device, put it back */
+	pci_dev_put(pci_device);
+	pci_device = NULL;
+}
+
+static int 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 = "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;
+
+	return find_video_card();
+}
+
+static void __exit samsung_exit(void)
+{
+	remove_video_card();
+}
+
+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_param(offset, int, S_IRUGO | S_IWUSR);
+MODULE_PARM_DESC(offset, "The offset into the PCI device for the brightness control");
+MODULE_ALIAS("dmi:*:svnSAMSUNGELECTRONICSCO.,LTD.:pnN130:*:rnN130:*");
+MODULE_ALIAS("dmi:*:svnSAMSUNGELECTRONICSCO.,LTD.:pnNC10:*:rnNC10:*");
+MODULE_ALIAS("dmi:*:svnSAMSUNGELECTRONICSCO.,LTD.:pnSQ45S70S:*:rnSQ45S70S:*");

  parent reply	other threads:[~2009-08-14 22:55 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-14 19:48 [PATCH] Samsung backlight driver Greg KH
2009-08-14 21:43 ` [PATCH] samsung-backlight: Added support for Samsung NC10 laptop Greg KH
2009-08-14 21:54 ` [PATCH] Samsung backlight driver Dmitry Torokhov
2009-08-14 22:18   ` Greg KH
2009-08-14 22:48   ` Greg KH [this message]
2009-08-15  7:15     ` Dmitry Torokhov
2009-08-16 22:04       ` Greg KH

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090814224835.GA31585@kroah.com \
    --to=greg@kroah.com \
    --cc=bugreports@nn7.de \
    --cc=dmitry.torokhov@gmail.com \
    --cc=jeremie@lamah.info \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox