Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 182 lines (157 sloc) 4.927 kb
12845e79 »
2009-08-14 initial pci structure for driver
1 /*
0b769c01 »
2009-08-14 fix up the "if we don't find the device, what do we do?" logic a bit
2 * Samsung N130 and NC10 Laptop Backlight driver
12845e79 »
2009-08-14 initial pci structure for 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
31a634df »
2009-08-14 initial commit
13 #include <linux/kernel.h>
14 #include <linux/init.h>
15 #include <linux/module.h>
12845e79 »
2009-08-14 initial pci structure for driver
16 #include <linux/pci.h>
488d2f88 »
2009-08-14 add backlight class support
17 #include <linux/backlight.h>
18 #include <linux/fb.h>
9253b128 »
2009-08-14 add dmi support to the driver
19 #include <linux/dmi.h>
12845e79 »
2009-08-14 initial pci structure for driver
20
886c2ee6 »
2009-08-17 first cut at moving the values to be between 0 and 7
21 #define MAX_BRIGHT 0x07
488d2f88 »
2009-08-14 add backlight class support
22 #define OFFSET 0xf4
23
886c2ee6 »
2009-08-17 first cut at moving the values to be between 0 and 7
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 *
cb0feb7b »
2009-08-19 make value 0 actually show something.
29 * userspace 0 1 2 3 4 5 6 7
30 * hardware 31 63 95 127 159 195 223 255
886c2ee6 »
2009-08-17 first cut at moving the values to be between 0 and 7
31 *
cb0feb7b »
2009-08-19 make value 0 actually show something.
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.
886c2ee6 »
2009-08-17 first cut at moving the values to be between 0 and 7
37 */
38
39
66973ab6 »
2009-08-16 added N120 support, and lots of cleanups from Dmitry
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
488d2f88 »
2009-08-14 add backlight class support
44 static struct pci_dev *pci_device;
45 static struct backlight_device *backlight_device;
12845e79 »
2009-08-14 initial pci structure for driver
46
66973ab6 »
2009-08-16 added N120 support, and lots of cleanups from Dmitry
47 static u8 read_brightness(void)
488d2f88 »
2009-08-14 add backlight class support
48 {
886c2ee6 »
2009-08-17 first cut at moving the values to be between 0 and 7
49 u8 kernel_brightness;
50 u8 user_brightness = 0;
66973ab6 »
2009-08-16 added N120 support, and lots of cleanups from Dmitry
51
886c2ee6 »
2009-08-17 first cut at moving the values to be between 0 and 7
52 pci_read_config_byte(pci_device, offset, &kernel_brightness);
cb0feb7b »
2009-08-19 make value 0 actually show something.
53 user_brightness = ((kernel_brightness + 1) / 32) - 1;
886c2ee6 »
2009-08-17 first cut at moving the values to be between 0 and 7
54 return user_brightness;
488d2f88 »
2009-08-14 add backlight class support
55 }
56
886c2ee6 »
2009-08-17 first cut at moving the values to be between 0 and 7
57 static void set_brightness(u8 user_brightness)
488d2f88 »
2009-08-14 add backlight class support
58 {
886c2ee6 »
2009-08-17 first cut at moving the values to be between 0 and 7
59 u16 kernel_brightness = 0;
60
cb0feb7b »
2009-08-19 make value 0 actually show something.
61 kernel_brightness = ((user_brightness + 1) * 32) - 1;
886c2ee6 »
2009-08-17 first cut at moving the values to be between 0 and 7
62 pci_write_config_byte(pci_device, offset, (u8)kernel_brightness);
488d2f88 »
2009-08-14 add backlight class support
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 {
66973ab6 »
2009-08-16 added N120 support, and lots of cleanups from Dmitry
72 set_brightness(bd->props.brightness);
488d2f88 »
2009-08-14 add backlight class support
73 return 0;
74 }
75
76 static struct backlight_ops backlight_ops = {
77 .get_brightness = get_brightness,
78 .update_status = update_status,
79 };
80
66973ab6 »
2009-08-16 added N120 support, and lots of cleanups from Dmitry
81 static int __init dmi_check_cb(const struct dmi_system_id *id)
9253b128 »
2009-08-14 add dmi support to the driver
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 {
66973ab6 »
2009-08-16 added N120 support, and lots of cleanups from Dmitry
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 {
9253b128 »
2009-08-14 add dmi support to the driver
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 },
9045774e »
2009-08-14 Added support for Samsung NC10 laptop
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 },
6ecfda3f »
2009-08-14 Support for the Samsung NP-Q45 from Jérémie Huchet added
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 },
9253b128 »
2009-08-14 add dmi support to the driver
125 { },
126 };
127
12845e79 »
2009-08-14 initial pci structure for driver
128 static int __init samsung_init(void)
129 {
5b4e3ed7 » Ben Arnold
2010-09-02 Fix driver to work with newer kernel versions
130 struct backlight_properties props;
131 memset(&props, 0, sizeof(struct backlight_properties));
132
9253b128 »
2009-08-14 add dmi support to the driver
133 if (!dmi_check_system(samsung_dmi_table))
134 return -ENODEV;
135
66973ab6 »
2009-08-16 added N120 support, and lots of cleanups from Dmitry
136 /*
137 * The Samsung N120, N130, and NC10 use pci device id 0x27ae, while the
138 * NP-Q45 uses 0x2a02. Odds are we might need to add more to the
139 * list over time...
140 */
141 pci_device = pci_get_device(PCI_VENDOR_ID_INTEL, 0x27ae, NULL);
142 if (!pci_device) {
143 pci_device = pci_get_device(PCI_VENDOR_ID_INTEL, 0x2a02, NULL);
144 if (!pci_device)
145 return -ENODEV;
146 }
147
148 /* create a backlight device to talk to this one */
149 backlight_device = backlight_device_register("samsung",
150 &pci_device->dev,
5b4e3ed7 » Ben Arnold
2010-09-02 Fix driver to work with newer kernel versions
151 NULL, &backlight_ops, &props);
66973ab6 »
2009-08-16 added N120 support, and lots of cleanups from Dmitry
152 if (IS_ERR(backlight_device)) {
153 pci_dev_put(pci_device);
154 return PTR_ERR(backlight_device);
155 }
156
157 backlight_device->props.max_brightness = MAX_BRIGHT;
158 backlight_device->props.brightness = read_brightness();
159 backlight_device->props.power = FB_BLANK_UNBLANK;
160 backlight_update_status(backlight_device);
161
162 return 0;
12845e79 »
2009-08-14 initial pci structure for driver
163 }
164
165 static void __exit samsung_exit(void)
31a634df »
2009-08-14 initial commit
166 {
66973ab6 »
2009-08-16 added N120 support, and lots of cleanups from Dmitry
167 backlight_device_unregister(backlight_device);
168
169 /* we are done with the PCI device, put it back */
170 pci_dev_put(pci_device);
31a634df »
2009-08-14 initial commit
171 }
172
12845e79 »
2009-08-14 initial pci structure for driver
173 module_init(samsung_init);
174 module_exit(samsung_exit);
31a634df »
2009-08-14 initial commit
175
12845e79 »
2009-08-14 initial pci structure for driver
176 MODULE_AUTHOR("Greg Kroah-Hartman <gregkh@suse.de>");
0b769c01 »
2009-08-14 fix up the "if we don't find the device, what do we do?" logic a bit
177 MODULE_DESCRIPTION("Samsung Backlight driver");
31a634df »
2009-08-14 initial commit
178 MODULE_LICENSE("GPL");
66973ab6 »
2009-08-16 added N120 support, and lots of cleanups from Dmitry
179 MODULE_ALIAS("dmi:*:svnSAMSUNGELECTRONICSCO.,LTD.:pnN120:*:rnN120:*");
9253b128 »
2009-08-14 add dmi support to the driver
180 MODULE_ALIAS("dmi:*:svnSAMSUNGELECTRONICSCO.,LTD.:pnN130:*:rnN130:*");
9045774e »
2009-08-14 Added support for Samsung NC10 laptop
181 MODULE_ALIAS("dmi:*:svnSAMSUNGELECTRONICSCO.,LTD.:pnNC10:*:rnNC10:*");
6ecfda3f »
2009-08-14 Support for the Samsung NP-Q45 from Jérémie Huchet added
182 MODULE_ALIAS("dmi:*:svnSAMSUNGELECTRONICSCO.,LTD.:pnSQ45S70S:*:rnSQ45S70S:*");
Something went wrong with that request. Please try again.