Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 157 lines (133 sloc) 3.67 kb
12845e7 @gregkh initial pci structure for driver
authored
1 /*
2 * Samsung N130 Laptop Backlight driver
3 *
4 * Copyright (C) 2009 Greg Kroah-Hartman (gregkh@suse.de)
5 * Copyright (C) 2009 Novell Inc.
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License version 2 as published by
9 * the Free Software Foundation.
10 *
11 */
12
31a634d @gregkh initial commit
authored
13 #include <linux/kernel.h>
14 #include <linux/init.h>
15 #include <linux/module.h>
12845e7 @gregkh initial pci structure for driver
authored
16 #include <linux/pci.h>
488d2f8 @gregkh add backlight class support
authored
17 #include <linux/backlight.h>
18 #include <linux/fb.h>
9253b12 @gregkh add dmi support to the driver
authored
19 #include <linux/dmi.h>
12845e7 @gregkh initial pci structure for driver
authored
20
488d2f8 @gregkh add backlight class support
authored
21 #define MAX_BRIGHT 0xff
22 #define OFFSET 0xf4
23
24 static struct pci_dev *pci_device;
25 static struct backlight_device *backlight_device;
26 static int offset = OFFSET;
27 static u8 current_brightness;
12845e7 @gregkh initial pci structure for driver
authored
28
488d2f8 @gregkh add backlight class support
authored
29 static void read_brightness(void)
30 {
31 if (!pci_device)
32 return;
33 pci_read_config_byte(pci_device, offset, &current_brightness);
34 }
35
36 static void set_brightness(void)
37 {
38 if (!pci_device)
39 return;
40 pci_write_config_byte(pci_device, offset, current_brightness);
41 }
42
43 static int get_brightness(struct backlight_device *bd)
44 {
45 return bd->props.brightness;
46 }
47
48 static int update_status(struct backlight_device *bd)
49 {
50 if (!pci_device)
51 return -ENODEV;
52 if (!backlight_device)
53 return -ENODEV;
54
55 current_brightness = bd->props.brightness;
56 set_brightness();
57 return 0;
58 }
59
60 static struct backlight_ops backlight_ops = {
61 .get_brightness = get_brightness,
62 .update_status = update_status,
63 };
64
12845e7 @gregkh initial pci structure for driver
authored
65 static int find_video_card(void)
66 {
488d2f8 @gregkh add backlight class support
authored
67 struct pci_dev *dev = NULL;
68
69 while ((dev = pci_get_device(0x8086, 0x27ae, dev)) != NULL) {
70 /* Found one, so let's save it off */
71 if (!pci_device)
72 pci_device = pci_dev_get(dev);
73 }
12845e7 @gregkh initial pci structure for driver
authored
74
488d2f8 @gregkh add backlight class support
authored
75 if (!pci_device)
76 return 0;
77
78 /* create a backlight device to talk to this one */
79 backlight_device = backlight_device_register("samsung",
80 &pci_device->dev,
81 NULL, &backlight_ops);
82 if (IS_ERR(backlight_device))
83 return PTR_ERR(backlight_device);
84 read_brightness();
85 backlight_device->props.max_brightness = MAX_BRIGHT;
86 backlight_device->props.brightness = current_brightness;
87 backlight_device->props.power = FB_BLANK_UNBLANK;
88 backlight_update_status(backlight_device);
31a634d @gregkh initial commit
authored
89 return 0;
90 }
91
12845e7 @gregkh initial pci structure for driver
authored
92 static void remove_video_card(void)
93 {
488d2f8 @gregkh add backlight class support
authored
94 if (!pci_device)
12845e7 @gregkh initial pci structure for driver
authored
95 return;
488d2f8 @gregkh add backlight class support
authored
96
97 backlight_device_unregister(backlight_device);
98 backlight_device = NULL;
99
100 /* we are done with the PCI device, put it back */
101 pci_dev_put(pci_device);
102 pci_device = NULL;
12845e7 @gregkh initial pci structure for driver
authored
103 }
104
9253b12 @gregkh add dmi support to the driver
authored
105 static int dmi_check_cb(const struct dmi_system_id *id)
106 {
107 printk(KERN_INFO KBUILD_MODNAME ": found laptop model '%s'\n",
108 id->ident);
109 return 0;
110 }
111
112 static struct dmi_system_id __initdata samsung_dmi_table[] = {
113 {
114 .ident = "N130",
115 .matches = {
116 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
117 DMI_MATCH(DMI_PRODUCT_NAME, "N130"),
118 DMI_MATCH(DMI_BOARD_NAME, "N130"),
119 },
120 .callback = dmi_check_cb,
121 },
9045774 @gregkh Added support for Samsung NC10 laptop
authored
122 {
123 .ident = "NC10",
124 .matches = {
125 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
126 DMI_MATCH(DMI_PRODUCT_NAME, "NC10"),
127 DMI_MATCH(DMI_BOARD_NAME, "NC10"),
128 },
129 .callback = dmi_check_cb,
130 },
9253b12 @gregkh add dmi support to the driver
authored
131 { },
132 };
133
12845e7 @gregkh initial pci structure for driver
authored
134 static int __init samsung_init(void)
135 {
9253b12 @gregkh add dmi support to the driver
authored
136 if (!dmi_check_system(samsung_dmi_table))
137 return -ENODEV;
138
12845e7 @gregkh initial pci structure for driver
authored
139 return find_video_card();
140 }
141
142 static void __exit samsung_exit(void)
31a634d @gregkh initial commit
authored
143 {
12845e7 @gregkh initial pci structure for driver
authored
144 remove_video_card();
31a634d @gregkh initial commit
authored
145 }
146
12845e7 @gregkh initial pci structure for driver
authored
147 module_init(samsung_init);
148 module_exit(samsung_exit);
31a634d @gregkh initial commit
authored
149
12845e7 @gregkh initial pci structure for driver
authored
150 MODULE_AUTHOR("Greg Kroah-Hartman <gregkh@suse.de>");
151 MODULE_DESCRIPTION("Samsung N130 Backlight driver");
31a634d @gregkh initial commit
authored
152 MODULE_LICENSE("GPL");
488d2f8 @gregkh add backlight class support
authored
153 module_param(offset, int, S_IRUGO | S_IWUSR);
154 MODULE_PARM_DESC(offset, "The offset into the PCI device for the brightness control");
9253b12 @gregkh add dmi support to the driver
authored
155 MODULE_ALIAS("dmi:*:svnSAMSUNGELECTRONICSCO.,LTD.:pnN130:*:rnN130:*");
9045774 @gregkh Added support for Samsung NC10 laptop
authored
156 MODULE_ALIAS("dmi:*:svnSAMSUNGELECTRONICSCO.,LTD.:pnNC10:*:rnNC10:*");
Something went wrong with that request. Please try again.