Permalink
Browse files

added N120 support, and lots of cleanups from Dmitry

  • Loading branch information...
1 parent 6ecfda3 commit 66973ab6a58161afcc00a2fba10ab6d905e87b98 @gregkh committed Aug 16, 2009
Showing with 54 additions and 64 deletions.
  1. +54 −64 samsung-backlight.c
View
@@ -21,23 +21,24 @@
#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 int offset = OFFSET;
-static u8 current_brightness;
-static void read_brightness(void)
+static u8 read_brightness(void)
{
- if (!pci_device)
- return;
- pci_read_config_byte(pci_device, offset, &current_brightness);
+ u8 brightness;
+
+ pci_read_config_byte(pci_device, offset, &brightness);
+ return brightness;
}
-static void set_brightness(void)
+static void set_brightness(u8 brightness)
{
- if (!pci_device)
- return;
- pci_write_config_byte(pci_device, offset, current_brightness);
+ pci_write_config_byte(pci_device, offset, brightness);
}
static int get_brightness(struct backlight_device *bd)
@@ -47,11 +48,7 @@ static int get_brightness(struct backlight_device *bd)
static int update_status(struct backlight_device *bd)
{
- if (!pci_device)
- return -ENODEV;
-
- current_brightness = bd->props.brightness;
- set_brightness();
+ set_brightness(bd->props.brightness);
return 0;
}
@@ -60,58 +57,23 @@ static struct backlight_ops backlight_ops = {
.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)
+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 = {
@@ -147,12 +109,41 @@ static int __init samsung_init(void)
if (!dmi_check_system(samsung_dmi_table))
return -ENODEV;
- return find_video_card();
+ /*
+ * 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)
{
- remove_video_card();
+ backlight_device_unregister(backlight_device);
+
+ /* we are done with the PCI device, put it back */
+ pci_dev_put(pci_device);
}
module_init(samsung_init);
@@ -161,8 +152,7 @@ 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.:pnN120:*:rnN120:*");
MODULE_ALIAS("dmi:*:svnSAMSUNGELECTRONICSCO.,LTD.:pnN130:*:rnN130:*");
MODULE_ALIAS("dmi:*:svnSAMSUNGELECTRONICSCO.,LTD.:pnNC10:*:rnNC10:*");
MODULE_ALIAS("dmi:*:svnSAMSUNGELECTRONICSCO.,LTD.:pnSQ45S70S:*:rnSQ45S70S:*");

0 comments on commit 66973ab

Please sign in to comment.