Skip to content
Newer
Older
100644 180 lines (155 sloc) 4.71 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
886c2ee @gregkh first cut at moving the values to be between 0 and 7
authored
21 #define MAX_BRIGHT 0x07
488d2f8 @gregkh add backlight class support
authored
22 #define OFFSET 0xf4
23
886c2ee @gregkh first cut at moving the values to be between 0 and 7
authored
24 /*
25 * HAL/gnome-display-manager really wants us to only set 8 different levels for
26 * the brightness control. And since 256 different levels seems a bit
27 * overkill, that's fine. So let's map the 256 values to 8 different ones:
28 *
cb0feb7 @gregkh make value 0 actually show something.
authored
29 * userspace 0 1 2 3 4 5 6 7
30 * hardware 31 63 95 127 159 195 223 255
886c2ee @gregkh first cut at moving the values to be between 0 and 7
authored
31 *
cb0feb7 @gregkh make value 0 actually show something.
authored
32 * or hardware = ((userspace + 1) * 32)-1
33 *
34 * Note, we keep value 0 at a positive value, otherwise the screen goes
35 * blank because HAL likes to set the backlight to 0 at startup when there is
36 * no power plugged in.
886c2ee @gregkh first cut at moving the values to be between 0 and 7
authored
37 */
38
39
66973ab @gregkh added N120 support, and lots of cleanups from Dmitry
authored
40 static int offset = OFFSET;
41 module_param(offset, int, S_IRUGO | S_IWUSR);
42 MODULE_PARM_DESC(offset, "The offset into the PCI device for the brightness control");
43
488d2f8 @gregkh add backlight class support
authored
44 static struct pci_dev *pci_device;
45 static struct backlight_device *backlight_device;
12845e7 @gregkh initial pci structure for driver
authored
46
66973ab @gregkh added N120 support, and lots of cleanups from Dmitry
authored
47 static u8 read_brightness(void)
488d2f8 @gregkh add backlight class support
authored
48 {
886c2ee @gregkh first cut at moving the values to be between 0 and 7
authored
49 u8 kernel_brightness;
50 u8 user_brightness = 0;
66973ab @gregkh added N120 support, and lots of cleanups from Dmitry
authored
51
886c2ee @gregkh first cut at moving the values to be between 0 and 7
authored
52 pci_read_config_byte(pci_device, offset, &kernel_brightness);
cb0feb7 @gregkh make value 0 actually show something.
authored
53 user_brightness = ((kernel_brightness + 1) / 32) - 1;
886c2ee @gregkh first cut at moving the values to be between 0 and 7
authored
54 return user_brightness;
488d2f8 @gregkh add backlight class support
authored
55 }
56
886c2ee @gregkh first cut at moving the values to be between 0 and 7
authored
57 static void set_brightness(u8 user_brightness)
488d2f8 @gregkh add backlight class support
authored
58 {
886c2ee @gregkh first cut at moving the values to be between 0 and 7
authored
59 u16 kernel_brightness = 0;
60
cb0feb7 @gregkh make value 0 actually show something.
authored
61 kernel_brightness = ((user_brightness + 1) * 32) - 1;
886c2ee @gregkh first cut at moving the values to be between 0 and 7
authored
62 pci_write_config_byte(pci_device, offset, (u8)kernel_brightness);
488d2f8 @gregkh add backlight class support
authored
63 }
64
65 static int get_brightness(struct backlight_device *bd)
66 {
67 return bd->props.brightness;
68 }
69
70 static int update_status(struct backlight_device *bd)
71 {
66973ab @gregkh added N120 support, and lots of cleanups from Dmitry
authored
72 set_brightness(bd->props.brightness);
488d2f8 @gregkh add backlight class support
authored
73 return 0;
74 }
75
76 static struct backlight_ops backlight_ops = {
77 .get_brightness = get_brightness,
78 .update_status = update_status,
79 };
80
66973ab @gregkh added N120 support, and lots of cleanups from Dmitry
authored
81 static int __init dmi_check_cb(const struct dmi_system_id *id)
9253b12 @gregkh add dmi support to the driver
authored
82 {
83 printk(KERN_INFO KBUILD_MODNAME ": found laptop model '%s'\n",
84 id->ident);
85 return 0;
86 }
87
88 static struct dmi_system_id __initdata samsung_dmi_table[] = {
89 {
66973ab @gregkh added N120 support, and lots of cleanups from Dmitry
authored
90 .ident = "N120",
91 .matches = {
92 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
93 DMI_MATCH(DMI_PRODUCT_NAME, "N120"),
94 DMI_MATCH(DMI_BOARD_NAME, "N120"),
95 },
96 .callback = dmi_check_cb,
97 },
98 {
9253b12 @gregkh add dmi support to the driver
authored
99 .ident = "N130",
100 .matches = {
101 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
102 DMI_MATCH(DMI_PRODUCT_NAME, "N130"),
103 DMI_MATCH(DMI_BOARD_NAME, "N130"),
104 },
105 .callback = dmi_check_cb,
106 },
9045774 @gregkh Added support for Samsung NC10 laptop
authored
107 {
108 .ident = "NC10",
109 .matches = {
110 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
111 DMI_MATCH(DMI_PRODUCT_NAME, "NC10"),
112 DMI_MATCH(DMI_BOARD_NAME, "NC10"),
113 },
114 .callback = dmi_check_cb,
115 },
6ecfda3 @gregkh Support for the Samsung NP-Q45 from Jérémie Huchet added
authored
116 {
117 .ident = "NP-Q45",
118 .matches = {
119 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
120 DMI_MATCH(DMI_PRODUCT_NAME, "SQ45S70S"),
121 DMI_MATCH(DMI_BOARD_NAME, "SQ45S70S"),
122 },
123 .callback = dmi_check_cb,
124 },
9253b12 @gregkh add dmi support to the driver
authored
125 { },
126 };
127
12845e7 @gregkh initial pci structure for driver
authored
128 static int __init samsung_init(void)
129 {
9253b12 @gregkh add dmi support to the driver
authored
130 if (!dmi_check_system(samsung_dmi_table))
131 return -ENODEV;
132
66973ab @gregkh added N120 support, and lots of cleanups from Dmitry
authored
133 /*
134 * The Samsung N120, N130, and NC10 use pci device id 0x27ae, while the
135 * NP-Q45 uses 0x2a02. Odds are we might need to add more to the
136 * list over time...
137 */
138 pci_device = pci_get_device(PCI_VENDOR_ID_INTEL, 0x27ae, NULL);
139 if (!pci_device) {
140 pci_device = pci_get_device(PCI_VENDOR_ID_INTEL, 0x2a02, NULL);
141 if (!pci_device)
142 return -ENODEV;
143 }
144
145 /* create a backlight device to talk to this one */
146 backlight_device = backlight_device_register("samsung",
147 &pci_device->dev,
148 NULL, &backlight_ops);
149 if (IS_ERR(backlight_device)) {
150 pci_dev_put(pci_device);
151 return PTR_ERR(backlight_device);
152 }
153
154 backlight_device->props.max_brightness = MAX_BRIGHT;
155 backlight_device->props.brightness = read_brightness();
156 backlight_device->props.power = FB_BLANK_UNBLANK;
157 backlight_update_status(backlight_device);
158
159 return 0;
12845e7 @gregkh initial pci structure for driver
authored
160 }
161
162 static void __exit samsung_exit(void)
31a634d @gregkh initial commit
authored
163 {
66973ab @gregkh added N120 support, and lots of cleanups from Dmitry
authored
164 backlight_device_unregister(backlight_device);
165
166 /* we are done with the PCI device, put it back */
167 pci_dev_put(pci_device);
31a634d @gregkh initial commit
authored
168 }
169
12845e7 @gregkh initial pci structure for driver
authored
170 module_init(samsung_init);
171 module_exit(samsung_exit);
31a634d @gregkh initial commit
authored
172
12845e7 @gregkh initial pci structure for driver
authored
173 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
174 MODULE_DESCRIPTION("Samsung Backlight driver");
31a634d @gregkh initial commit
authored
175 MODULE_LICENSE("GPL");
66973ab @gregkh added N120 support, and lots of cleanups from Dmitry
authored
176 MODULE_ALIAS("dmi:*:svnSAMSUNGELECTRONICSCO.,LTD.:pnN120:*:rnN120:*");
9253b12 @gregkh add dmi support to the driver
authored
177 MODULE_ALIAS("dmi:*:svnSAMSUNGELECTRONICSCO.,LTD.:pnN130:*:rnN130:*");
9045774 @gregkh Added support for Samsung NC10 laptop
authored
178 MODULE_ALIAS("dmi:*:svnSAMSUNGELECTRONICSCO.,LTD.:pnNC10:*:rnNC10:*");
6ecfda3 @gregkh Support for the Samsung NP-Q45 from Jérémie Huchet added
authored
179 MODULE_ALIAS("dmi:*:svnSAMSUNGELECTRONICSCO.,LTD.:pnSQ45S70S:*:rnSQ45S70S:*");
Something went wrong with that request. Please try again.