Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 178 lines (146 sloc) 3.936 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
29 static struct pci_device_id samsung_ids[] = {
30 { PCI_DEVICE(0x8086, 0x27ae) },
31 { },
32 };
33 MODULE_DEVICE_TABLE(pci, samsung_ids);
34
35 static int probe(struct pci_dev *pci_dev, const struct pci_device_id *id)
36 {
37 return -ENODEV;
38 }
31a634d @gregkh initial commit
authored
39
12845e7 @gregkh initial pci structure for driver
authored
40 static void remove(struct pci_dev *pci_dev)
31a634d @gregkh initial commit
authored
41 {
12845e7 @gregkh initial pci structure for driver
authored
42 }
43
44 static struct pci_driver samsung_driver = {
45 .name = "samsung-backlight",
46 .id_table = samsung_ids,
47 .probe = probe,
48 .remove = remove,
49 };
50
488d2f8 @gregkh add backlight class support
authored
51 static void read_brightness(void)
52 {
53 if (!pci_device)
54 return;
55 pci_read_config_byte(pci_device, offset, &current_brightness);
56 }
57
58 static void set_brightness(void)
59 {
60 if (!pci_device)
61 return;
62 pci_write_config_byte(pci_device, offset, current_brightness);
63 }
64
65
66 static int get_brightness(struct backlight_device *bd)
67 {
68 return bd->props.brightness;
69 }
70
71 static int update_status(struct backlight_device *bd)
72 {
73 if (!pci_device)
74 return -ENODEV;
75 if (!backlight_device)
76 return -ENODEV;
77
78 current_brightness = bd->props.brightness;
79 set_brightness();
80 return 0;
81 }
82
83 static struct backlight_ops backlight_ops = {
84 .get_brightness = get_brightness,
85 .update_status = update_status,
86 };
87
12845e7 @gregkh initial pci structure for driver
authored
88
89 static int find_video_card(void)
90 {
488d2f8 @gregkh add backlight class support
authored
91 struct pci_dev *dev = NULL;
92
93 while ((dev = pci_get_device(0x8086, 0x27ae, dev)) != NULL) {
94 /* Found one, so let's save it off */
95 if (!pci_device)
96 pci_device = pci_dev_get(dev);
97 }
12845e7 @gregkh initial pci structure for driver
authored
98
488d2f8 @gregkh add backlight class support
authored
99 if (!pci_device)
100 return 0;
101
102 /* create a backlight device to talk to this one */
103 backlight_device = backlight_device_register("samsung",
104 &pci_device->dev,
105 NULL, &backlight_ops);
106 if (IS_ERR(backlight_device))
107 return PTR_ERR(backlight_device);
108 read_brightness();
109 backlight_device->props.max_brightness = MAX_BRIGHT;
110 backlight_device->props.brightness = current_brightness;
111 backlight_device->props.power = FB_BLANK_UNBLANK;
112 backlight_update_status(backlight_device);
31a634d @gregkh initial commit
authored
113 return 0;
114 }
115
12845e7 @gregkh initial pci structure for driver
authored
116 static void remove_video_card(void)
117 {
488d2f8 @gregkh add backlight class support
authored
118 if (!pci_device)
12845e7 @gregkh initial pci structure for driver
authored
119 return;
488d2f8 @gregkh add backlight class support
authored
120
121 backlight_device_unregister(backlight_device);
122 backlight_device = NULL;
123
124 /* we are done with the PCI device, put it back */
125 pci_dev_put(pci_device);
126 pci_device = NULL;
12845e7 @gregkh initial pci structure for driver
authored
127 }
128
9253b12 @gregkh add dmi support to the driver
authored
129 static int dmi_check_cb(const struct dmi_system_id *id)
130 {
131 printk(KERN_INFO KBUILD_MODNAME ": found laptop model '%s'\n",
132 id->ident);
133 return 0;
134 }
135
136 static struct dmi_system_id __initdata samsung_dmi_table[] = {
137 {
138 .ident = "N130",
139 .matches = {
140 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
141 DMI_MATCH(DMI_PRODUCT_NAME, "N130"),
142 DMI_MATCH(DMI_BOARD_NAME, "N130"),
143 },
144 .callback = dmi_check_cb,
145 },
146 { },
147 };
148
12845e7 @gregkh initial pci structure for driver
authored
149 static int __init samsung_init(void)
150 {
151 int retval;
9253b12 @gregkh add dmi support to the driver
authored
152
153 if (!dmi_check_system(samsung_dmi_table))
154 return -ENODEV;
155
12845e7 @gregkh initial pci structure for driver
authored
156 retval = pci_register_driver(&samsung_driver);
157 if (retval)
158 return retval;
159
160 return find_video_card();
161 }
162
163 static void __exit samsung_exit(void)
31a634d @gregkh initial commit
authored
164 {
12845e7 @gregkh initial pci structure for driver
authored
165 pci_unregister_driver(&samsung_driver);
166 remove_video_card();
31a634d @gregkh initial commit
authored
167 }
168
12845e7 @gregkh initial pci structure for driver
authored
169 module_init(samsung_init);
170 module_exit(samsung_exit);
31a634d @gregkh initial commit
authored
171
12845e7 @gregkh initial pci structure for driver
authored
172 MODULE_AUTHOR("Greg Kroah-Hartman <gregkh@suse.de>");
173 MODULE_DESCRIPTION("Samsung N130 Backlight driver");
31a634d @gregkh initial commit
authored
174 MODULE_LICENSE("GPL");
488d2f8 @gregkh add backlight class support
authored
175 module_param(offset, int, S_IRUGO | S_IWUSR);
176 MODULE_PARM_DESC(offset, "The offset into the PCI device for the brightness control");
9253b12 @gregkh add dmi support to the driver
authored
177 MODULE_ALIAS("dmi:*:svnSAMSUNGELECTRONICSCO.,LTD.:pnN130:*:rnN130:*");
Something went wrong with that request. Please try again.