Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 169 lines (145 sloc) 4.01 kB
12845e7 @gregkh initial pci structure for driver
authored
1 /*
0b769c0 @gregkh fix up the "if we don't find the device, what do we do?" logic a bit
authored
2 * Samsung N130 and NC10 Laptop Backlight driver
12845e7 @gregkh initial pci structure for driver
authored
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
53 current_brightness = bd->props.brightness;
54 set_brightness();
55 return 0;
56 }
57
58 static struct backlight_ops backlight_ops = {
59 .get_brightness = get_brightness,
60 .update_status = update_status,
61 };
62
12845e7 @gregkh initial pci structure for driver
authored
63 static int find_video_card(void)
64 {
488d2f8 @gregkh add backlight class support
authored
65 struct pci_dev *dev = NULL;
66
67 while ((dev = pci_get_device(0x8086, 0x27ae, dev)) != NULL) {
0b769c0 @gregkh fix up the "if we don't find the device, what do we do?" logic a bit
authored
68 /*
69 * Found one, so let's save it off and break
70 * Note that the reference is still raised on
71 * the PCI device here.
72 */
73 pci_device = dev;
74 break;
488d2f8 @gregkh add backlight class support
authored
75 }
12845e7 @gregkh initial pci structure for driver
authored
76
488d2f8 @gregkh add backlight class support
authored
77 if (!pci_device)
0b769c0 @gregkh fix up the "if we don't find the device, what do we do?" logic a bit
authored
78 return -ENODEV;
488d2f8 @gregkh add backlight class support
authored
79
80 /* create a backlight device to talk to this one */
81 backlight_device = backlight_device_register("samsung",
82 &pci_device->dev,
83 NULL, &backlight_ops);
84 if (IS_ERR(backlight_device))
85 return PTR_ERR(backlight_device);
86 read_brightness();
87 backlight_device->props.max_brightness = MAX_BRIGHT;
88 backlight_device->props.brightness = current_brightness;
89 backlight_device->props.power = FB_BLANK_UNBLANK;
90 backlight_update_status(backlight_device);
31a634d @gregkh initial commit
authored
91 return 0;
92 }
93
12845e7 @gregkh initial pci structure for driver
authored
94 static void remove_video_card(void)
95 {
488d2f8 @gregkh add backlight class support
authored
96 if (!pci_device)
12845e7 @gregkh initial pci structure for driver
authored
97 return;
488d2f8 @gregkh add backlight class support
authored
98
99 backlight_device_unregister(backlight_device);
100 backlight_device = NULL;
101
102 /* we are done with the PCI device, put it back */
103 pci_dev_put(pci_device);
104 pci_device = NULL;
12845e7 @gregkh initial pci structure for driver
authored
105 }
106
9253b12 @gregkh add dmi support to the driver
authored
107 static int dmi_check_cb(const struct dmi_system_id *id)
108 {
109 printk(KERN_INFO KBUILD_MODNAME ": found laptop model '%s'\n",
110 id->ident);
111 return 0;
112 }
113
114 static struct dmi_system_id __initdata samsung_dmi_table[] = {
115 {
116 .ident = "N130",
117 .matches = {
118 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
119 DMI_MATCH(DMI_PRODUCT_NAME, "N130"),
120 DMI_MATCH(DMI_BOARD_NAME, "N130"),
121 },
122 .callback = dmi_check_cb,
123 },
9045774 @gregkh Added support for Samsung NC10 laptop
authored
124 {
125 .ident = "NC10",
126 .matches = {
127 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
128 DMI_MATCH(DMI_PRODUCT_NAME, "NC10"),
129 DMI_MATCH(DMI_BOARD_NAME, "NC10"),
130 },
131 .callback = dmi_check_cb,
132 },
6ecfda3 @gregkh Support for the Samsung NP-Q45 from Jérémie Huchet added
authored
133 {
134 .ident = "NP-Q45",
135 .matches = {
136 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
137 DMI_MATCH(DMI_PRODUCT_NAME, "SQ45S70S"),
138 DMI_MATCH(DMI_BOARD_NAME, "SQ45S70S"),
139 },
140 .callback = dmi_check_cb,
141 },
9253b12 @gregkh add dmi support to the driver
authored
142 { },
143 };
144
12845e7 @gregkh initial pci structure for driver
authored
145 static int __init samsung_init(void)
146 {
9253b12 @gregkh add dmi support to the driver
authored
147 if (!dmi_check_system(samsung_dmi_table))
148 return -ENODEV;
149
12845e7 @gregkh initial pci structure for driver
authored
150 return find_video_card();
151 }
152
153 static void __exit samsung_exit(void)
31a634d @gregkh initial commit
authored
154 {
12845e7 @gregkh initial pci structure for driver
authored
155 remove_video_card();
31a634d @gregkh initial commit
authored
156 }
157
12845e7 @gregkh initial pci structure for driver
authored
158 module_init(samsung_init);
159 module_exit(samsung_exit);
31a634d @gregkh initial commit
authored
160
12845e7 @gregkh initial pci structure for driver
authored
161 MODULE_AUTHOR("Greg Kroah-Hartman <gregkh@suse.de>");
0b769c0 @gregkh fix up the "if we don't find the device, what do we do?" logic a bit
authored
162 MODULE_DESCRIPTION("Samsung Backlight driver");
31a634d @gregkh initial commit
authored
163 MODULE_LICENSE("GPL");
488d2f8 @gregkh add backlight class support
authored
164 module_param(offset, int, S_IRUGO | S_IWUSR);
165 MODULE_PARM_DESC(offset, "The offset into the PCI device for the brightness control");
9253b12 @gregkh add dmi support to the driver
authored
166 MODULE_ALIAS("dmi:*:svnSAMSUNGELECTRONICSCO.,LTD.:pnN130:*:rnN130:*");
9045774 @gregkh Added support for Samsung NC10 laptop
authored
167 MODULE_ALIAS("dmi:*:svnSAMSUNGELECTRONICSCO.,LTD.:pnNC10:*:rnNC10:*");
6ecfda3 @gregkh Support for the Samsung NP-Q45 from Jérémie Huchet added
authored
168 MODULE_ALIAS("dmi:*:svnSAMSUNGELECTRONICSCO.,LTD.:pnSQ45S70S:*:rnSQ45S70S:*");
Something went wrong with that request. Please try again.