2 * Backlight Driver for Nvidia 8600 in Macbook Pro
4 * Copyright (c) Red Hat <mjg@redhat.com>
5 * Based on code from Pommed:
6 * Copyright (C) 2006 Nicolas Boichat <nicolas @boichat.ch>
7 * Copyright (C) 2006 Felipe Alfaro Solana <felipe_alfaro @linuxmail.org>
8 * Copyright (C) 2007 Julien BLACHE <jb@jblache.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
14 * This driver triggers SMIs which cause the firmware to change the
15 * backlight brightness. This is icky in many ways, but it's impractical to
16 * get at the firmware code in order to figure out what it's actually doing.
19 #include <linux/module.h>
20 #include <linux/kernel.h>
21 #include <linux/init.h>
22 #include <linux/platform_device.h>
23 #include <linux/backlight.h>
24 #include <linux/err.h>
25 #include <linux/dmi.h>
28 static struct backlight_device
*mbp_backlight_device
;
30 /* Structure to be passed to the DMI_MATCH function. */
31 struct dmi_match_data
{
32 /* I/O resource to allocate. */
33 unsigned long iostart
;
35 /* Backlight operations structure. */
36 const struct backlight_ops backlight_ops
;
39 /* Module parameters. */
41 module_param_named(debug
, debug
, int, 0644);
42 MODULE_PARM_DESC(debug
, "Set to one to enable debugging messages.");
45 * Implementation for MacBooks with Intel chipset.
47 static int intel_chipset_send_intensity(struct backlight_device
*bd
)
49 int intensity
= bd
->props
.brightness
;
52 printk(KERN_DEBUG
"mbp_nvidia_bl: setting brightness to %d\n",
55 outb(0x04 | (intensity
<< 4), 0xb3);
60 static int intel_chipset_get_intensity(struct backlight_device
*bd
)
66 intensity
= inb(0xb3) >> 4;
69 printk(KERN_DEBUG
"mbp_nvidia_bl: read brightness of %d\n",
75 static const struct dmi_match_data intel_chipset_data
= {
79 .options
= BL_CORE_SUSPENDRESUME
,
80 .get_brightness
= intel_chipset_get_intensity
,
81 .update_status
= intel_chipset_send_intensity
,
86 * Implementation for MacBooks with Nvidia chipset.
88 static int nvidia_chipset_send_intensity(struct backlight_device
*bd
)
90 int intensity
= bd
->props
.brightness
;
93 printk(KERN_DEBUG
"mbp_nvidia_bl: setting brightness to %d\n",
96 outb(0x04 | (intensity
<< 4), 0x52f);
101 static int nvidia_chipset_get_intensity(struct backlight_device
*bd
)
107 intensity
= inb(0x52f) >> 4;
110 printk(KERN_DEBUG
"mbp_nvidia_bl: read brightness of %d\n",
116 static const struct dmi_match_data nvidia_chipset_data
= {
120 .options
= BL_CORE_SUSPENDRESUME
,
121 .get_brightness
= nvidia_chipset_get_intensity
,
122 .update_status
= nvidia_chipset_send_intensity
129 static /* const */ struct dmi_match_data
*driver_data
;
131 static int mbp_dmi_match(const struct dmi_system_id
*id
)
133 driver_data
= id
->driver_data
;
135 printk(KERN_INFO
"mbp_nvidia_bl: %s detected\n", id
->ident
);
139 static const struct dmi_system_id __initdata mbp_device_table
[] = {
141 .callback
= mbp_dmi_match
,
142 .ident
= "MacBook 1,1",
144 DMI_MATCH(DMI_SYS_VENDOR
, "Apple Inc."),
145 DMI_MATCH(DMI_PRODUCT_NAME
, "MacBook1,1"),
147 .driver_data
= (void *)&intel_chipset_data
,
150 .callback
= mbp_dmi_match
,
151 .ident
= "MacBook 2,1",
153 DMI_MATCH(DMI_SYS_VENDOR
, "Apple Inc."),
154 DMI_MATCH(DMI_PRODUCT_NAME
, "MacBook2,1"),
156 .driver_data
= (void *)&intel_chipset_data
,
159 .callback
= mbp_dmi_match
,
160 .ident
= "MacBook 3,1",
162 DMI_MATCH(DMI_SYS_VENDOR
, "Apple Inc."),
163 DMI_MATCH(DMI_PRODUCT_NAME
, "MacBook3,1"),
165 .driver_data
= (void *)&intel_chipset_data
,
168 .callback
= mbp_dmi_match
,
169 .ident
= "MacBook 4,1",
171 DMI_MATCH(DMI_SYS_VENDOR
, "Apple Inc."),
172 DMI_MATCH(DMI_PRODUCT_NAME
, "MacBook4,1"),
174 .driver_data
= (void *)&intel_chipset_data
,
177 .callback
= mbp_dmi_match
,
178 .ident
= "MacBook 4,2",
180 DMI_MATCH(DMI_SYS_VENDOR
, "Apple Inc."),
181 DMI_MATCH(DMI_PRODUCT_NAME
, "MacBook4,2"),
183 .driver_data
= (void *)&intel_chipset_data
,
186 .callback
= mbp_dmi_match
,
187 .ident
= "MacBookPro 3,1",
189 DMI_MATCH(DMI_SYS_VENDOR
, "Apple Inc."),
190 DMI_MATCH(DMI_PRODUCT_NAME
, "MacBookPro3,1"),
192 .driver_data
= (void *)&intel_chipset_data
,
195 .callback
= mbp_dmi_match
,
196 .ident
= "MacBookPro 3,2",
198 DMI_MATCH(DMI_SYS_VENDOR
, "Apple Inc."),
199 DMI_MATCH(DMI_PRODUCT_NAME
, "MacBookPro3,2"),
201 .driver_data
= (void *)&intel_chipset_data
,
204 .callback
= mbp_dmi_match
,
205 .ident
= "MacBookPro 4,1",
207 DMI_MATCH(DMI_SYS_VENDOR
, "Apple Inc."),
208 DMI_MATCH(DMI_PRODUCT_NAME
, "MacBookPro4,1"),
210 .driver_data
= (void *)&intel_chipset_data
,
213 .callback
= mbp_dmi_match
,
214 .ident
= "MacBookAir 1,1",
216 DMI_MATCH(DMI_SYS_VENDOR
, "Apple Inc."),
217 DMI_MATCH(DMI_PRODUCT_NAME
, "MacBookAir1,1"),
219 .driver_data
= (void *)&intel_chipset_data
,
222 .callback
= mbp_dmi_match
,
223 .ident
= "MacBook 5,1",
225 DMI_MATCH(DMI_SYS_VENDOR
, "Apple Inc."),
226 DMI_MATCH(DMI_PRODUCT_NAME
, "MacBook5,1"),
228 .driver_data
= (void *)&nvidia_chipset_data
,
231 .callback
= mbp_dmi_match
,
232 .ident
= "MacBook 5,2",
234 DMI_MATCH(DMI_SYS_VENDOR
, "Apple Inc."),
235 DMI_MATCH(DMI_PRODUCT_NAME
, "MacBook5,2"),
237 .driver_data
= (void *)&nvidia_chipset_data
,
240 .callback
= mbp_dmi_match
,
241 .ident
= "MacBookAir 2,1",
243 DMI_MATCH(DMI_SYS_VENDOR
, "Apple Inc."),
244 DMI_MATCH(DMI_PRODUCT_NAME
, "MacBookAir2,1"),
246 .driver_data
= (void *)&nvidia_chipset_data
,
249 .callback
= mbp_dmi_match
,
250 .ident
= "MacBookPro 5,1",
252 DMI_MATCH(DMI_SYS_VENDOR
, "Apple Inc."),
253 DMI_MATCH(DMI_PRODUCT_NAME
, "MacBookPro5,1"),
255 .driver_data
= (void *)&nvidia_chipset_data
,
258 .callback
= mbp_dmi_match
,
259 .ident
= "MacBookPro 5,2",
261 DMI_MATCH(DMI_SYS_VENDOR
, "Apple Inc."),
262 DMI_MATCH(DMI_PRODUCT_NAME
, "MacBookPro5,2"),
264 .driver_data
= (void *)&nvidia_chipset_data
,
267 .callback
= mbp_dmi_match
,
268 .ident
= "MacBookPro 5,3",
270 DMI_MATCH(DMI_SYS_VENDOR
, "Apple Inc."),
271 DMI_MATCH(DMI_PRODUCT_NAME
, "MacBookPro5,3"),
273 .driver_data
= (void *)&nvidia_chipset_data
,
276 .callback
= mbp_dmi_match
,
277 .ident
= "MacBookPro 5,4",
279 DMI_MATCH(DMI_SYS_VENDOR
, "Apple Inc."),
280 DMI_MATCH(DMI_PRODUCT_NAME
, "MacBookPro5,4"),
282 .driver_data
= (void *)&nvidia_chipset_data
,
285 .callback
= mbp_dmi_match
,
286 .ident
= "MacBookPro 5,5",
288 DMI_MATCH(DMI_SYS_VENDOR
, "Apple Inc."),
289 DMI_MATCH(DMI_PRODUCT_NAME
, "MacBookPro5,5"),
291 .driver_data
= (void *)&nvidia_chipset_data
,
296 static int __init
mbp_init(void)
298 struct backlight_properties props
;
299 if (!dmi_check_system(mbp_device_table
))
302 if (!request_region(driver_data
->iostart
, driver_data
->iolen
,
303 "Macbook Pro backlight"))
306 memset(&props
, 0, sizeof(struct backlight_properties
));
307 props
.max_brightness
= 15;
308 mbp_backlight_device
= backlight_device_register("mbp_backlight", NULL
,
310 &driver_data
->backlight_ops
,
312 if (IS_ERR(mbp_backlight_device
)) {
313 release_region(driver_data
->iostart
, driver_data
->iolen
);
314 return PTR_ERR(mbp_backlight_device
);
317 mbp_backlight_device
->props
.brightness
=
318 driver_data
->backlight_ops
.get_brightness(mbp_backlight_device
);
319 backlight_update_status(mbp_backlight_device
);
324 static void __exit
mbp_exit(void)
326 backlight_device_unregister(mbp_backlight_device
);
328 release_region(driver_data
->iostart
, driver_data
->iolen
);
331 module_init(mbp_init
);
332 module_exit(mbp_exit
);
334 MODULE_AUTHOR("Matthew Garrett <mjg@redhat.com>");
335 MODULE_DESCRIPTION("Nvidia-based Macbook Pro Backlight Driver");
336 MODULE_LICENSE("GPL");
337 MODULE_DEVICE_TABLE(dmi
, mbp_device_table
);