Merge branch 'iommu-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip...
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / video / backlight / mbp_nvidia_bl.c
blob65864c500455677a1ef540579c0817f32fd62478
1 /*
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>
26 #include <linux/io.h>
28 static struct backlight_device *mbp_backlight_device;
30 static struct dmi_system_id __initdata mbp_device_table[] = {
32 .ident = "3,1",
33 .matches = {
34 DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
35 DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro3,1"),
39 .ident = "3,2",
40 .matches = {
41 DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
42 DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro3,2"),
46 .ident = "4,1",
47 .matches = {
48 DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
49 DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro4,1"),
52 { }
55 static int mbp_send_intensity(struct backlight_device *bd)
57 int intensity = bd->props.brightness;
59 outb(0x04 | (intensity << 4), 0xb3);
60 outb(0xbf, 0xb2);
62 return 0;
65 static int mbp_get_intensity(struct backlight_device *bd)
67 outb(0x03, 0xb3);
68 outb(0xbf, 0xb2);
69 return inb(0xb3) >> 4;
72 static struct backlight_ops mbp_ops = {
73 .options = BL_CORE_SUSPENDRESUME,
74 .get_brightness = mbp_get_intensity,
75 .update_status = mbp_send_intensity,
78 static int __init mbp_init(void)
80 if (!dmi_check_system(mbp_device_table))
81 return -ENODEV;
83 if (!request_region(0xb2, 2, "Macbook Pro backlight"))
84 return -ENXIO;
86 mbp_backlight_device = backlight_device_register("mbp_backlight",
87 NULL, NULL,
88 &mbp_ops);
89 if (IS_ERR(mbp_backlight_device)) {
90 release_region(0xb2, 2);
91 return PTR_ERR(mbp_backlight_device);
94 mbp_backlight_device->props.max_brightness = 15;
95 mbp_backlight_device->props.brightness =
96 mbp_get_intensity(mbp_backlight_device);
97 backlight_update_status(mbp_backlight_device);
99 return 0;
102 static void __exit mbp_exit(void)
104 backlight_device_unregister(mbp_backlight_device);
106 release_region(0xb2, 2);
109 module_init(mbp_init);
110 module_exit(mbp_exit);
112 MODULE_AUTHOR("Matthew Garrett <mjg@redhat.com>");
113 MODULE_DESCRIPTION("Nvidia-based Macbook Pro Backlight Driver");
114 MODULE_LICENSE("GPL");
115 MODULE_DEVICE_TABLE(dmi, mbp_device_table);