Matthew Garrett 0988eed
Various fixes to the Apple backlight driver. Upstream in .38?
Matthew Garrett 0988eed
Matthew Garrett 0988eed
diff --git a/drivers/video/backlight/Kconfig b/drivers/video/backlight/Kconfig
Matthew Garrett 0988eed
index e54a337..fb5df46 100644
Matthew Garrett 0988eed
--- a/drivers/video/backlight/Kconfig
Matthew Garrett 0988eed
+++ b/drivers/video/backlight/Kconfig
Matthew Garrett 0988eed
@@ -236,12 +236,12 @@ config BACKLIGHT_MAX8925
Matthew Garrett 0988eed
 	  If you have a LCD backlight connected to the WLED output of MAX8925
Matthew Garrett 0988eed
 	  WLED output, say Y here to enable this driver.
Matthew Garrett 0988eed
 
Matthew Garrett 0988eed
-config BACKLIGHT_MBP_NVIDIA
Matthew Garrett 0988eed
-       tristate "MacBook Pro Nvidia Backlight Driver"
Matthew Garrett 0988eed
+config BACKLIGHT_APPLE
Matthew Garrett 0988eed
+       tristate "Apple Backlight Driver"
Matthew Garrett 0988eed
        depends on X86
Matthew Garrett 0988eed
        help
Matthew Garrett 0988eed
-         If you have an Apple Macbook Pro with Nvidia graphics hardware say Y
Matthew Garrett 0988eed
-	 to enable a driver for its backlight
Matthew Garrett 0988eed
+         If you have an Intel-based Apple say Y to enable a driver for its
Matthew Garrett 0988eed
+	 backlight
Matthew Garrett 0988eed
 
Matthew Garrett 0988eed
 config BACKLIGHT_TOSA
Matthew Garrett 0988eed
 	tristate "Sharp SL-6000 Backlight Driver"
Matthew Garrett 0988eed
diff --git a/drivers/video/backlight/Makefile b/drivers/video/backlight/Makefile
Matthew Garrett 0988eed
index 44c0f81..ebaecc0 100644
Matthew Garrett 0988eed
--- a/drivers/video/backlight/Makefile
Matthew Garrett 0988eed
+++ b/drivers/video/backlight/Makefile
Matthew Garrett 0988eed
@@ -26,7 +26,7 @@ obj-$(CONFIG_BACKLIGHT_CARILLO_RANCH) += cr_bllcd.o
Matthew Garrett 0988eed
 obj-$(CONFIG_BACKLIGHT_PWM)	+= pwm_bl.o
Matthew Garrett 0988eed
 obj-$(CONFIG_BACKLIGHT_DA903X)	+= da903x_bl.o
Matthew Garrett 0988eed
 obj-$(CONFIG_BACKLIGHT_MAX8925)	+= max8925_bl.o
Matthew Garrett 0988eed
-obj-$(CONFIG_BACKLIGHT_MBP_NVIDIA) += mbp_nvidia_bl.o
Matthew Garrett 0988eed
+obj-$(CONFIG_BACKLIGHT_APPLE)	+= apple_bl.o
Matthew Garrett 0988eed
 obj-$(CONFIG_BACKLIGHT_TOSA)	+= tosa_bl.o
Matthew Garrett 0988eed
 obj-$(CONFIG_BACKLIGHT_SAHARA)	+= kb3886_bl.o
Matthew Garrett 0988eed
 obj-$(CONFIG_BACKLIGHT_WM831X)	+= wm831x_bl.o
Matthew Garrett 0988eed
diff --git a/drivers/video/backlight/apple_bl.c b/drivers/video/backlight/apple_bl.c
Matthew Garrett 0988eed
new file mode 100644
Matthew Garrett 0988eed
index 0000000..8f808c7
Matthew Garrett 0988eed
--- /dev/null
Matthew Garrett 0988eed
+++ b/drivers/video/backlight/apple_bl.c
Matthew Garrett 0988eed
@@ -0,0 +1,240 @@
Matthew Garrett 0988eed
+/*
Matthew Garrett 0988eed
+ *  Backlight Driver for Intel-based Apples
Matthew Garrett 0988eed
+ *
Matthew Garrett 0988eed
+ *  Copyright (c) Red Hat <mjg@redhat.com>
Matthew Garrett 0988eed
+ *  Based on code from Pommed:
Matthew Garrett 0988eed
+ *  Copyright (C) 2006 Nicolas Boichat <nicolas @boichat.ch>
Matthew Garrett 0988eed
+ *  Copyright (C) 2006 Felipe Alfaro Solana <felipe_alfaro @linuxmail.org>
Matthew Garrett 0988eed
+ *  Copyright (C) 2007 Julien BLACHE <jb@jblache.org>
Matthew Garrett 0988eed
+ *
Matthew Garrett 0988eed
+ *  This program is free software; you can redistribute it and/or modify
Matthew Garrett 0988eed
+ *  it under the terms of the GNU General Public License version 2 as
Matthew Garrett 0988eed
+ *  published by the Free Software Foundation.
Matthew Garrett 0988eed
+ *
Matthew Garrett 0988eed
+ *  This driver triggers SMIs which cause the firmware to change the
Matthew Garrett 0988eed
+ *  backlight brightness. This is icky in many ways, but it's impractical to
Matthew Garrett 0988eed
+ *  get at the firmware code in order to figure out what it's actually doing.
Matthew Garrett 0988eed
+ */
Matthew Garrett 0988eed
+
Matthew Garrett 0988eed
+#include <linux/module.h>
Matthew Garrett 0988eed
+#include <linux/kernel.h>
Matthew Garrett 0988eed
+#include <linux/init.h>
Matthew Garrett 0988eed
+#include <linux/backlight.h>
Matthew Garrett 0988eed
+#include <linux/err.h>
Matthew Garrett 0988eed
+#include <linux/io.h>
Matthew Garrett 0988eed
+#include <linux/pci.h>
Matthew Garrett 0988eed
+#include <linux/acpi.h>
Matthew Garrett 0988eed
+
Matthew Garrett 0988eed
+static struct backlight_device *apple_backlight_device;
Matthew Garrett 0988eed
+
Matthew Garrett 0988eed
+struct hw_data {
Matthew Garrett 0988eed
+	/* I/O resource to allocate. */
Matthew Garrett 0988eed
+	unsigned long iostart;
Matthew Garrett 0988eed
+	unsigned long iolen;
Matthew Garrett 0988eed
+	/* Backlight operations structure. */
Matthew Garrett 0988eed
+	const struct backlight_ops backlight_ops;
Matthew Garrett 0988eed
+	void (*set_brightness)(int);
Matthew Garrett 0988eed
+};
Matthew Garrett 0988eed
+
Matthew Garrett 0988eed
+static const struct hw_data *hw_data;
Matthew Garrett 0988eed
+
Matthew Garrett 0988eed
+#define DRIVER "apple_backlight: "
Matthew Garrett 0988eed
+
Matthew Garrett 0988eed
+/* Module parameters. */
Matthew Garrett 0988eed
+static int debug;
Matthew Garrett 0988eed
+module_param_named(debug, debug, int, 0644);
Matthew Garrett 0988eed
+MODULE_PARM_DESC(debug, "Set to one to enable debugging messages.");
Matthew Garrett 0988eed
+
Matthew Garrett 0988eed
+/*
Matthew Garrett 0988eed
+ * Implementation for machines with Intel chipset.
Matthew Garrett 0988eed
+ */
Matthew Garrett 0988eed
+static void intel_chipset_set_brightness(int intensity)
Matthew Garrett 0988eed
+{
Matthew Garrett 0988eed
+	outb(0x04 | (intensity << 4), 0xb3);
Matthew Garrett 0988eed
+	outb(0xbf, 0xb2);
Matthew Garrett 0988eed
+}
Matthew Garrett 0988eed
+
Matthew Garrett 0988eed
+static int intel_chipset_send_intensity(struct backlight_device *bd)
Matthew Garrett 0988eed
+{
Matthew Garrett 0988eed
+	int intensity = bd->props.brightness;
Matthew Garrett 0988eed
+
Matthew Garrett 0988eed
+	if (debug)
Matthew Garrett 0988eed
+		printk(KERN_DEBUG DRIVER "setting brightness to %d\n",
Matthew Garrett 0988eed
+		       intensity);
Matthew Garrett 0988eed
+
Matthew Garrett 0988eed
+	intel_chipset_set_brightness(intensity);
Matthew Garrett 0988eed
+	return 0;
Matthew Garrett 0988eed
+}
Matthew Garrett 0988eed
+
Matthew Garrett 0988eed
+static int intel_chipset_get_intensity(struct backlight_device *bd)
Matthew Garrett 0988eed
+{
Matthew Garrett 0988eed
+	int intensity;
Matthew Garrett 0988eed
+
Matthew Garrett 0988eed
+	outb(0x03, 0xb3);
Matthew Garrett 0988eed
+	outb(0xbf, 0xb2);
Matthew Garrett 0988eed
+	intensity = inb(0xb3) >> 4;
Matthew Garrett 0988eed
+
Matthew Garrett 0988eed
+	if (debug)
Matthew Garrett 0988eed
+		printk(KERN_DEBUG DRIVER "read brightness of %d\n",
Matthew Garrett 0988eed
+		       intensity);
Matthew Garrett 0988eed
+
Matthew Garrett 0988eed
+	return intensity;
Matthew Garrett 0988eed
+}
Matthew Garrett 0988eed
+
Matthew Garrett 0988eed
+static const struct hw_data intel_chipset_data = {
Matthew Garrett 0988eed
+	.iostart = 0xb2,
Matthew Garrett 0988eed
+	.iolen = 2,
Matthew Garrett 0988eed
+	.backlight_ops	= {
Matthew Garrett 0988eed
+		.options	= BL_CORE_SUSPENDRESUME,
Matthew Garrett 0988eed
+		.get_brightness	= intel_chipset_get_intensity,
Matthew Garrett 0988eed
+		.update_status	= intel_chipset_send_intensity,
Matthew Garrett 0988eed
+	},
Matthew Garrett 0988eed
+	.set_brightness = intel_chipset_set_brightness,
Matthew Garrett 0988eed
+};
Matthew Garrett 0988eed
+
Matthew Garrett 0988eed
+/*
Matthew Garrett 0988eed
+ * Implementation for machines with Nvidia chipset.
Matthew Garrett 0988eed
+ */
Matthew Garrett 0988eed
+static void nvidia_chipset_set_brightness(int intensity)
Matthew Garrett 0988eed
+{
Matthew Garrett 0988eed
+	outb(0x04 | (intensity << 4), 0x52f);
Matthew Garrett 0988eed
+	outb(0xbf, 0x52e);
Matthew Garrett 0988eed
+}
Matthew Garrett 0988eed
+
Matthew Garrett 0988eed
+static int nvidia_chipset_send_intensity(struct backlight_device *bd)
Matthew Garrett 0988eed
+{
Matthew Garrett 0988eed
+	int intensity = bd->props.brightness;
Matthew Garrett 0988eed
+
Matthew Garrett 0988eed
+	if (debug)
Matthew Garrett 0988eed
+		printk(KERN_DEBUG DRIVER "setting brightness to %d\n",
Matthew Garrett 0988eed
+		       intensity);
Matthew Garrett 0988eed
+
Matthew Garrett 0988eed
+	nvidia_chipset_set_brightness(intensity);
Matthew Garrett 0988eed
+	return 0;
Matthew Garrett 0988eed
+}
Matthew Garrett 0988eed
+
Matthew Garrett 0988eed
+static int nvidia_chipset_get_intensity(struct backlight_device *bd)
Matthew Garrett 0988eed
+{
Matthew Garrett 0988eed
+	int intensity;
Matthew Garrett 0988eed
+
Matthew Garrett 0988eed
+	outb(0x03, 0x52f);
Matthew Garrett 0988eed
+	outb(0xbf, 0x52e);
Matthew Garrett 0988eed
+	intensity = inb(0x52f) >> 4;
Matthew Garrett 0988eed
+
Matthew Garrett 0988eed
+	if (debug)
Matthew Garrett 0988eed
+		printk(KERN_DEBUG DRIVER "read brightness of %d\n",
Matthew Garrett 0988eed
+		       intensity);
Matthew Garrett 0988eed
+
Matthew Garrett 0988eed
+	return intensity;
Matthew Garrett 0988eed
+}
Matthew Garrett 0988eed
+
Matthew Garrett 0988eed
+static const struct hw_data nvidia_chipset_data = {
Matthew Garrett 0988eed
+	.iostart = 0x52e,
Matthew Garrett 0988eed
+	.iolen = 2,
Matthew Garrett 0988eed
+	.backlight_ops		= {
Matthew Garrett 0988eed
+		.options	= BL_CORE_SUSPENDRESUME,
Matthew Garrett 0988eed
+		.get_brightness	= nvidia_chipset_get_intensity,
Matthew Garrett 0988eed
+		.update_status	= nvidia_chipset_send_intensity
Matthew Garrett 0988eed
+	},
Matthew Garrett 0988eed
+	.set_brightness = nvidia_chipset_set_brightness,
Matthew Garrett 0988eed
+};
Matthew Garrett 0988eed
+
Matthew Garrett 0988eed
+static int __devinit apple_bl_add(struct acpi_device *dev)
Matthew Garrett 0988eed
+{
Matthew Garrett 0988eed
+	struct backlight_properties props;
Matthew Garrett 0988eed
+	struct pci_dev *host;
Matthew Garrett 0988eed
+	int intensity;
Matthew Garrett 0988eed
+
Matthew Garrett 0988eed
+	host = pci_get_bus_and_slot(0, 0);
Matthew Garrett 0988eed
+
Matthew Garrett 0988eed
+	if (!host) {
Matthew Garrett 0988eed
+		printk(KERN_ERR DRIVER "unable to find PCI host\n");
Matthew Garrett 0988eed
+		return -ENODEV;
Matthew Garrett 0988eed
+	}
Matthew Garrett 0988eed
+
Matthew Garrett 0988eed
+	if (host->vendor == PCI_VENDOR_ID_INTEL)
Matthew Garrett 0988eed
+		hw_data = &intel_chipset_data;
Matthew Garrett 0988eed
+	else if (host->vendor == PCI_VENDOR_ID_NVIDIA)
Matthew Garrett 0988eed
+		hw_data = &nvidia_chipset_data;
Matthew Garrett 0988eed
+
Matthew Garrett 0988eed
+	pci_dev_put(host);
Matthew Garrett 0988eed
+
Matthew Garrett 0988eed
+	if (!hw_data) {
Matthew Garrett 0988eed
+		printk(KERN_ERR DRIVER "unknown hardware\n");
Matthew Garrett 0988eed
+		return -ENODEV;
Matthew Garrett 0988eed
+	}
Matthew Garrett 0988eed
+
Matthew Garrett 0988eed
+	/* Check that the hardware responds - this may not work under EFI */
Matthew Garrett 0988eed
+
Matthew Garrett 0988eed
+	intensity = hw_data->backlight_ops.get_brightness(NULL);
Matthew Garrett 0988eed
+
Matthew Garrett 0988eed
+	if (!intensity) {
Matthew Garrett 0988eed
+		hw_data->set_brightness(1);
Matthew Garrett 0988eed
+		if (!hw_data->backlight_ops.get_brightness(NULL))
Matthew Garrett 0988eed
+			return -ENODEV;
Matthew Garrett 0988eed
+
Matthew Garrett 0988eed
+		hw_data->set_brightness(0);
Matthew Garrett 0988eed
+	}
Matthew Garrett 0988eed
+
Matthew Garrett 0988eed
+	if (!request_region(hw_data->iostart, hw_data->iolen,
Matthew Garrett 0988eed
+			    "Apple backlight"))
Matthew Garrett 0988eed
+		return -ENXIO;
Matthew Garrett 0988eed
+
Matthew Garrett 0988eed
+	memset(&props, 0, sizeof(struct backlight_properties));
Matthew Garrett 0988eed
+	props.max_brightness = 15;
Matthew Garrett 0988eed
+	apple_backlight_device = backlight_device_register("apple_backlight",
Matthew Garrett 0988eed
+				  NULL, NULL, &hw_data->backlight_ops, &props;;
Matthew Garrett 0988eed
+
Matthew Garrett 0988eed
+	if (IS_ERR(apple_backlight_device)) {
Matthew Garrett 0988eed
+		release_region(hw_data->iostart, hw_data->iolen);
Matthew Garrett 0988eed
+		return PTR_ERR(apple_backlight_device);
Matthew Garrett 0988eed
+	}
Matthew Garrett 0988eed
+
Matthew Garrett 0988eed
+	apple_backlight_device->props.brightness =
Matthew Garrett 0988eed
+		hw_data->backlight_ops.get_brightness(apple_backlight_device);
Matthew Garrett 0988eed
+	backlight_update_status(apple_backlight_device);
Matthew Garrett 0988eed
+
Matthew Garrett 0988eed
+	return 0;
Matthew Garrett 0988eed
+}
Matthew Garrett 0988eed
+
Matthew Garrett 0988eed
+static int __devexit apple_bl_remove(struct acpi_device *dev, int type)
Matthew Garrett 0988eed
+{
Matthew Garrett 0988eed
+	backlight_device_unregister(apple_backlight_device);
Matthew Garrett 0988eed
+
Matthew Garrett 0988eed
+	release_region(hw_data->iostart, hw_data->iolen);
Matthew Garrett 0988eed
+	hw_data = NULL;
Matthew Garrett 0988eed
+	return 0;
Matthew Garrett 0988eed
+}
Matthew Garrett 0988eed
+
Matthew Garrett 0988eed
+static const struct acpi_device_id apple_bl_ids[] = {
Matthew Garrett 0988eed
+	{"APP0002", 0},
Matthew Garrett 0988eed
+	{"", 0},
Matthew Garrett 0988eed
+};
Matthew Garrett 0988eed
+
Matthew Garrett 0988eed
+static struct acpi_driver apple_bl_driver = {
Matthew Garrett 0988eed
+	.name = "Apple backlight",
Matthew Garrett 0988eed
+	.ids = apple_bl_ids,
Matthew Garrett 0988eed
+	.ops = {
Matthew Garrett 0988eed
+		.add = apple_bl_add,
Matthew Garrett 0988eed
+		.remove = apple_bl_remove,
Matthew Garrett 0988eed
+	},
Matthew Garrett 0988eed
+};
Matthew Garrett 0988eed
+
Matthew Garrett 0988eed
+static int __init apple_bl_init(void)
Matthew Garrett 0988eed
+{
Matthew Garrett 0988eed
+	return acpi_bus_register_driver(&apple_bl_driver);
Matthew Garrett 0988eed
+}
Matthew Garrett 0988eed
+
Matthew Garrett 0988eed
+static void __exit apple_bl_exit(void)
Matthew Garrett 0988eed
+{
Matthew Garrett 0988eed
+	acpi_bus_unregister_driver(&apple_bl_driver);
Matthew Garrett 0988eed
+}
Matthew Garrett 0988eed
+
Matthew Garrett 0988eed
+module_init(apple_bl_init);
Matthew Garrett 0988eed
+module_exit(apple_bl_exit);
Matthew Garrett 0988eed
+
Matthew Garrett 0988eed
+MODULE_AUTHOR("Matthew Garrett <mjg@redhat.com>");
Matthew Garrett 0988eed
+MODULE_DESCRIPTION("Apple Backlight Driver");
Matthew Garrett 0988eed
+MODULE_LICENSE("GPL");
Matthew Garrett 0988eed
+MODULE_DEVICE_TABLE(acpi, apple_bl_ids);
Matthew Garrett 0988eed
+MODULE_ALIAS("mbp_nvidia_bl");
Matthew Garrett 0988eed
diff --git a/drivers/video/backlight/mbp_nvidia_bl.c b/drivers/video/backlight/mbp_nvidia_bl.c
Matthew Garrett 0988eed
deleted file mode 100644
Matthew Garrett 0988eed
index 1485f73..0000000
Matthew Garrett 0988eed
--- a/drivers/video/backlight/mbp_nvidia_bl.c
Matthew Garrett 0988eed
+++ /dev/null
Matthew Garrett 0988eed
@@ -1,400 +0,0 @@
Matthew Garrett 0988eed
-/*
Matthew Garrett 0988eed
- *  Backlight Driver for Nvidia 8600 in Macbook Pro
Matthew Garrett 0988eed
- *
Matthew Garrett 0988eed
- *  Copyright (c) Red Hat <mjg@redhat.com>
Matthew Garrett 0988eed
- *  Based on code from Pommed:
Matthew Garrett 0988eed
- *  Copyright (C) 2006 Nicolas Boichat <nicolas @boichat.ch>
Matthew Garrett 0988eed
- *  Copyright (C) 2006 Felipe Alfaro Solana <felipe_alfaro @linuxmail.org>
Matthew Garrett 0988eed
- *  Copyright (C) 2007 Julien BLACHE <jb@jblache.org>
Matthew Garrett 0988eed
- *
Matthew Garrett 0988eed
- *  This program is free software; you can redistribute it and/or modify
Matthew Garrett 0988eed
- *  it under the terms of the GNU General Public License version 2 as
Matthew Garrett 0988eed
- *  published by the Free Software Foundation.
Matthew Garrett 0988eed
- *
Matthew Garrett 0988eed
- *  This driver triggers SMIs which cause the firmware to change the
Matthew Garrett 0988eed
- *  backlight brightness. This is icky in many ways, but it's impractical to
Matthew Garrett 0988eed
- *  get at the firmware code in order to figure out what it's actually doing.
Matthew Garrett 0988eed
- */
Matthew Garrett 0988eed
-
Matthew Garrett 0988eed
-#include <linux/module.h>
Matthew Garrett 0988eed
-#include <linux/kernel.h>
Matthew Garrett 0988eed
-#include <linux/init.h>
Matthew Garrett 0988eed
-#include <linux/platform_device.h>
Matthew Garrett 0988eed
-#include <linux/backlight.h>
Matthew Garrett 0988eed
-#include <linux/err.h>
Matthew Garrett 0988eed
-#include <linux/dmi.h>
Matthew Garrett 0988eed
-#include <linux/io.h>
Matthew Garrett 0988eed
-
Matthew Garrett 0988eed
-static struct backlight_device *mbp_backlight_device;
Matthew Garrett 0988eed
-
Matthew Garrett 0988eed
-/* Structure to be passed to the DMI_MATCH function. */
Matthew Garrett 0988eed
-struct dmi_match_data {
Matthew Garrett 0988eed
-	/* I/O resource to allocate. */
Matthew Garrett 0988eed
-	unsigned long iostart;
Matthew Garrett 0988eed
-	unsigned long iolen;
Matthew Garrett 0988eed
-	/* Backlight operations structure. */
Matthew Garrett 0988eed
-	const struct backlight_ops backlight_ops;
Matthew Garrett 0988eed
-};
Matthew Garrett 0988eed
-
Matthew Garrett 0988eed
-/* Module parameters. */
Matthew Garrett 0988eed
-static int debug;
Matthew Garrett 0988eed
-module_param_named(debug, debug, int, 0644);
Matthew Garrett 0988eed
-MODULE_PARM_DESC(debug, "Set to one to enable debugging messages.");
Matthew Garrett 0988eed
-
Matthew Garrett 0988eed
-/*
Matthew Garrett 0988eed
- * Implementation for MacBooks with Intel chipset.
Matthew Garrett 0988eed
- */
Matthew Garrett 0988eed
-static int intel_chipset_send_intensity(struct backlight_device *bd)
Matthew Garrett 0988eed
-{
Matthew Garrett 0988eed
-	int intensity = bd->props.brightness;
Matthew Garrett 0988eed
-
Matthew Garrett 0988eed
-	if (debug)
Matthew Garrett 0988eed
-		printk(KERN_DEBUG "mbp_nvidia_bl: setting brightness to %d\n",
Matthew Garrett 0988eed
-		       intensity);
Matthew Garrett 0988eed
-
Matthew Garrett 0988eed
-	outb(0x04 | (intensity << 4), 0xb3);
Matthew Garrett 0988eed
-	outb(0xbf, 0xb2);
Matthew Garrett 0988eed
-	return 0;
Matthew Garrett 0988eed
-}
Matthew Garrett 0988eed
-
Matthew Garrett 0988eed
-static int intel_chipset_get_intensity(struct backlight_device *bd)
Matthew Garrett 0988eed
-{
Matthew Garrett 0988eed
-	int intensity;
Matthew Garrett 0988eed
-
Matthew Garrett 0988eed
-	outb(0x03, 0xb3);
Matthew Garrett 0988eed
-	outb(0xbf, 0xb2);
Matthew Garrett 0988eed
-	intensity = inb(0xb3) >> 4;
Matthew Garrett 0988eed
-
Matthew Garrett 0988eed
-	if (debug)
Matthew Garrett 0988eed
-		printk(KERN_DEBUG "mbp_nvidia_bl: read brightness of %d\n",
Matthew Garrett 0988eed
-		       intensity);
Matthew Garrett 0988eed
-
Matthew Garrett 0988eed
-	return intensity;
Matthew Garrett 0988eed
-}
Matthew Garrett 0988eed
-
Matthew Garrett 0988eed
-static const struct dmi_match_data intel_chipset_data = {
Matthew Garrett 0988eed
-	.iostart = 0xb2,
Matthew Garrett 0988eed
-	.iolen = 2,
Matthew Garrett 0988eed
-	.backlight_ops	= {
Matthew Garrett 0988eed
-		.options	= BL_CORE_SUSPENDRESUME,
Matthew Garrett 0988eed
-		.get_brightness	= intel_chipset_get_intensity,
Matthew Garrett 0988eed
-		.update_status	= intel_chipset_send_intensity,
Matthew Garrett 0988eed
-	}
Matthew Garrett 0988eed
-};
Matthew Garrett 0988eed
-
Matthew Garrett 0988eed
-/*
Matthew Garrett 0988eed
- * Implementation for MacBooks with Nvidia chipset.
Matthew Garrett 0988eed
- */
Matthew Garrett 0988eed
-static int nvidia_chipset_send_intensity(struct backlight_device *bd)
Matthew Garrett 0988eed
-{
Matthew Garrett 0988eed
-	int intensity = bd->props.brightness;
Matthew Garrett 0988eed
-
Matthew Garrett 0988eed
-	if (debug)
Matthew Garrett 0988eed
-		printk(KERN_DEBUG "mbp_nvidia_bl: setting brightness to %d\n",
Matthew Garrett 0988eed
-		       intensity);
Matthew Garrett 0988eed
-
Matthew Garrett 0988eed
-	outb(0x04 | (intensity << 4), 0x52f);
Matthew Garrett 0988eed
-	outb(0xbf, 0x52e);
Matthew Garrett 0988eed
-	return 0;
Matthew Garrett 0988eed
-}
Matthew Garrett 0988eed
-
Matthew Garrett 0988eed
-static int nvidia_chipset_get_intensity(struct backlight_device *bd)
Matthew Garrett 0988eed
-{
Matthew Garrett 0988eed
-	int intensity;
Matthew Garrett 0988eed
-
Matthew Garrett 0988eed
-	outb(0x03, 0x52f);
Matthew Garrett 0988eed
-	outb(0xbf, 0x52e);
Matthew Garrett 0988eed
-	intensity = inb(0x52f) >> 4;
Matthew Garrett 0988eed
-
Matthew Garrett 0988eed
-	if (debug)
Matthew Garrett 0988eed
-		printk(KERN_DEBUG "mbp_nvidia_bl: read brightness of %d\n",
Matthew Garrett 0988eed
-		       intensity);
Matthew Garrett 0988eed
-
Matthew Garrett 0988eed
-	return intensity;
Matthew Garrett 0988eed
-}
Matthew Garrett 0988eed
-
Matthew Garrett 0988eed
-static const struct dmi_match_data nvidia_chipset_data = {
Matthew Garrett 0988eed
-	.iostart = 0x52e,
Matthew Garrett 0988eed
-	.iolen = 2,
Matthew Garrett 0988eed
-	.backlight_ops		= {
Matthew Garrett 0988eed
-		.options	= BL_CORE_SUSPENDRESUME,
Matthew Garrett 0988eed
-		.get_brightness	= nvidia_chipset_get_intensity,
Matthew Garrett 0988eed
-		.update_status	= nvidia_chipset_send_intensity
Matthew Garrett 0988eed
-	}
Matthew Garrett 0988eed
-};
Matthew Garrett 0988eed
-
Matthew Garrett 0988eed
-/*
Matthew Garrett 0988eed
- * DMI matching.
Matthew Garrett 0988eed
- */
Matthew Garrett 0988eed
-static /* const */ struct dmi_match_data *driver_data;
Matthew Garrett 0988eed
-
Matthew Garrett 0988eed
-static int mbp_dmi_match(const struct dmi_system_id *id)
Matthew Garrett 0988eed
-{
Matthew Garrett 0988eed
-	driver_data = id->driver_data;
Matthew Garrett 0988eed
-
Matthew Garrett 0988eed
-	printk(KERN_INFO "mbp_nvidia_bl: %s detected\n", id->ident);
Matthew Garrett 0988eed
-	return 1;
Matthew Garrett 0988eed
-}
Matthew Garrett 0988eed
-
Matthew Garrett 0988eed
-static const struct dmi_system_id __initdata mbp_device_table[] = {
Matthew Garrett 0988eed
-	{
Matthew Garrett 0988eed
-		.callback	= mbp_dmi_match,
Matthew Garrett 0988eed
-		.ident		= "MacBook 1,1",
Matthew Garrett 0988eed
-		.matches	= {
Matthew Garrett 0988eed
-			DMI_MATCH(DMI_SYS_VENDOR, "Apple Computer, Inc."),
Matthew Garrett 0988eed
-			DMI_MATCH(DMI_PRODUCT_NAME, "MacBook1,1"),
Matthew Garrett 0988eed
-		},
Matthew Garrett 0988eed
-		.driver_data	= (void *)&intel_chipset_data,
Matthew Garrett 0988eed
-	},
Matthew Garrett 0988eed
-	{
Matthew Garrett 0988eed
-		.callback	= mbp_dmi_match,
Matthew Garrett 0988eed
-		.ident		= "MacBook 2,1",
Matthew Garrett 0988eed
-		.matches	= {
Matthew Garrett 0988eed
-			DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
Matthew Garrett 0988eed
-			DMI_MATCH(DMI_PRODUCT_NAME, "MacBook2,1"),
Matthew Garrett 0988eed
-		},
Matthew Garrett 0988eed
-		.driver_data	= (void *)&intel_chipset_data,
Matthew Garrett 0988eed
-	},
Matthew Garrett 0988eed
-	{
Matthew Garrett 0988eed
-		.callback	= mbp_dmi_match,
Matthew Garrett 0988eed
-		.ident		= "MacBook 3,1",
Matthew Garrett 0988eed
-		.matches	= {
Matthew Garrett 0988eed
-			DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
Matthew Garrett 0988eed
-			DMI_MATCH(DMI_PRODUCT_NAME, "MacBook3,1"),
Matthew Garrett 0988eed
-		},
Matthew Garrett 0988eed
-		.driver_data	= (void *)&intel_chipset_data,
Matthew Garrett 0988eed
-	},
Matthew Garrett 0988eed
-	{
Matthew Garrett 0988eed
-		.callback	= mbp_dmi_match,
Matthew Garrett 0988eed
-		.ident		= "MacBook 4,1",
Matthew Garrett 0988eed
-		.matches	= {
Matthew Garrett 0988eed
-			DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
Matthew Garrett 0988eed
-			DMI_MATCH(DMI_PRODUCT_NAME, "MacBook4,1"),
Matthew Garrett 0988eed
-		},
Matthew Garrett 0988eed
-		.driver_data	= (void *)&intel_chipset_data,
Matthew Garrett 0988eed
-	},
Matthew Garrett 0988eed
-	{
Matthew Garrett 0988eed
-		.callback	= mbp_dmi_match,
Matthew Garrett 0988eed
-		.ident		= "MacBook 4,2",
Matthew Garrett 0988eed
-		.matches	= {
Matthew Garrett 0988eed
-			DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
Matthew Garrett 0988eed
-			DMI_MATCH(DMI_PRODUCT_NAME, "MacBook4,2"),
Matthew Garrett 0988eed
-		},
Matthew Garrett 0988eed
-		.driver_data	= (void *)&intel_chipset_data,
Matthew Garrett 0988eed
-	},
Matthew Garrett 0988eed
-	{
Matthew Garrett 0988eed
-		.callback	= mbp_dmi_match,
Matthew Garrett 0988eed
-		.ident		= "MacBookPro 1,1",
Matthew Garrett 0988eed
-		.matches	= {
Matthew Garrett 0988eed
-			DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
Matthew Garrett 0988eed
-			DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro1,1"),
Matthew Garrett 0988eed
-		},
Matthew Garrett 0988eed
-		.driver_data	= (void *)&intel_chipset_data,
Matthew Garrett 0988eed
-	},
Matthew Garrett 0988eed
-	{
Matthew Garrett 0988eed
-		.callback	= mbp_dmi_match,
Matthew Garrett 0988eed
-		.ident		= "MacBookPro 1,2",
Matthew Garrett 0988eed
-		.matches	= {
Matthew Garrett 0988eed
-			DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
Matthew Garrett 0988eed
-			DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro1,2"),
Matthew Garrett 0988eed
-		},
Matthew Garrett 0988eed
-		.driver_data	= (void *)&intel_chipset_data,
Matthew Garrett 0988eed
-	},
Matthew Garrett 0988eed
-	{
Matthew Garrett 0988eed
-		.callback	= mbp_dmi_match,
Matthew Garrett 0988eed
-		.ident		= "MacBookPro 2,1",
Matthew Garrett 0988eed
-		.matches	= {
Matthew Garrett 0988eed
-			DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
Matthew Garrett 0988eed
-			DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro2,1"),
Matthew Garrett 0988eed
-		},
Matthew Garrett 0988eed
-		.driver_data	= (void *)&intel_chipset_data,
Matthew Garrett 0988eed
-	},
Matthew Garrett 0988eed
-	{
Matthew Garrett 0988eed
-		.callback	= mbp_dmi_match,
Matthew Garrett 0988eed
-		.ident		= "MacBookPro 2,2",
Matthew Garrett 0988eed
-		.matches	= {
Matthew Garrett 0988eed
-			DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
Matthew Garrett 0988eed
-			DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro2,2"),
Matthew Garrett 0988eed
-		},
Matthew Garrett 0988eed
-		.driver_data	= (void *)&intel_chipset_data,
Matthew Garrett 0988eed
-	},
Matthew Garrett 0988eed
-	{
Matthew Garrett 0988eed
-		.callback	= mbp_dmi_match,
Matthew Garrett 0988eed
-		.ident		= "MacBookPro 3,1",
Matthew Garrett 0988eed
-		.matches	= {
Matthew Garrett 0988eed
-			DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
Matthew Garrett 0988eed
-			DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro3,1"),
Matthew Garrett 0988eed
-		},
Matthew Garrett 0988eed
-		.driver_data	= (void *)&intel_chipset_data,
Matthew Garrett 0988eed
-	},
Matthew Garrett 0988eed
-	{
Matthew Garrett 0988eed
-		.callback	= mbp_dmi_match,
Matthew Garrett 0988eed
-		.ident		= "MacBookPro 3,2",
Matthew Garrett 0988eed
-		.matches	= {
Matthew Garrett 0988eed
-			DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
Matthew Garrett 0988eed
-			DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro3,2"),
Matthew Garrett 0988eed
-		},
Matthew Garrett 0988eed
-		.driver_data	= (void *)&intel_chipset_data,
Matthew Garrett 0988eed
-	},
Matthew Garrett 0988eed
-	{
Matthew Garrett 0988eed
-		.callback	= mbp_dmi_match,
Matthew Garrett 0988eed
-		.ident		= "MacBookPro 4,1",
Matthew Garrett 0988eed
-		.matches	= {
Matthew Garrett 0988eed
-			DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
Matthew Garrett 0988eed
-			DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro4,1"),
Matthew Garrett 0988eed
-		},
Matthew Garrett 0988eed
-		.driver_data	= (void *)&intel_chipset_data,
Matthew Garrett 0988eed
-	},
Matthew Garrett 0988eed
-	{
Matthew Garrett 0988eed
-		.callback	= mbp_dmi_match,
Matthew Garrett 0988eed
-		.ident		= "MacBookAir 1,1",
Matthew Garrett 0988eed
-		.matches	= {
Matthew Garrett 0988eed
-			DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
Matthew Garrett 0988eed
-			DMI_MATCH(DMI_PRODUCT_NAME, "MacBookAir1,1"),
Matthew Garrett 0988eed
-		},
Matthew Garrett 0988eed
-		.driver_data	= (void *)&intel_chipset_data,
Matthew Garrett 0988eed
-	},
Matthew Garrett 0988eed
-	{
Matthew Garrett 0988eed
-		.callback	= mbp_dmi_match,
Matthew Garrett 0988eed
-		.ident		= "MacBook 5,1",
Matthew Garrett 0988eed
-		.matches	= {
Matthew Garrett 0988eed
-			DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
Matthew Garrett 0988eed
-			DMI_MATCH(DMI_PRODUCT_NAME, "MacBook5,1"),
Matthew Garrett 0988eed
-		},
Matthew Garrett 0988eed
-		.driver_data	= (void *)&nvidia_chipset_data,
Matthew Garrett 0988eed
-	},
Matthew Garrett 0988eed
-	{
Matthew Garrett 0988eed
-		.callback	= mbp_dmi_match,
Matthew Garrett 0988eed
-		.ident		= "MacBook 5,2",
Matthew Garrett 0988eed
-		.matches	= {
Matthew Garrett 0988eed
-			DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
Matthew Garrett 0988eed
-			DMI_MATCH(DMI_PRODUCT_NAME, "MacBook5,2"),
Matthew Garrett 0988eed
-		},
Matthew Garrett 0988eed
-		.driver_data	= (void *)&nvidia_chipset_data,
Matthew Garrett 0988eed
-	},
Matthew Garrett 0988eed
-	{
Matthew Garrett 0988eed
-		.callback	= mbp_dmi_match,
Matthew Garrett 0988eed
-		.ident		= "MacBook 6,1",
Matthew Garrett 0988eed
-		.matches	= {
Matthew Garrett 0988eed
-			DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
Matthew Garrett 0988eed
-			DMI_MATCH(DMI_PRODUCT_NAME, "MacBook6,1"),
Matthew Garrett 0988eed
-		},
Matthew Garrett 0988eed
-		.driver_data	= (void *)&nvidia_chipset_data,
Matthew Garrett 0988eed
-	},
Matthew Garrett 0988eed
-	{
Matthew Garrett 0988eed
-		.callback	= mbp_dmi_match,
Matthew Garrett 0988eed
-		.ident		= "MacBookAir 2,1",
Matthew Garrett 0988eed
-		.matches	= {
Matthew Garrett 0988eed
-			DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
Matthew Garrett 0988eed
-			DMI_MATCH(DMI_PRODUCT_NAME, "MacBookAir2,1"),
Matthew Garrett 0988eed
-		},
Matthew Garrett 0988eed
-		.driver_data	= (void *)&nvidia_chipset_data,
Matthew Garrett 0988eed
-	},
Matthew Garrett 0988eed
-	{
Matthew Garrett 0988eed
-		.callback	= mbp_dmi_match,
Matthew Garrett 0988eed
-		.ident		= "MacBookPro 5,1",
Matthew Garrett 0988eed
-		.matches	= {
Matthew Garrett 0988eed
-			DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
Matthew Garrett 0988eed
-			DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro5,1"),
Matthew Garrett 0988eed
-		},
Matthew Garrett 0988eed
-		.driver_data	= (void *)&nvidia_chipset_data,
Matthew Garrett 0988eed
-	},
Matthew Garrett 0988eed
-	{
Matthew Garrett 0988eed
-		.callback	= mbp_dmi_match,
Matthew Garrett 0988eed
-		.ident		= "MacBookPro 5,2",
Matthew Garrett 0988eed
-		.matches	= {
Matthew Garrett 0988eed
-			DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
Matthew Garrett 0988eed
-			DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro5,2"),
Matthew Garrett 0988eed
-		},
Matthew Garrett 0988eed
-		.driver_data	= (void *)&nvidia_chipset_data,
Matthew Garrett 0988eed
-	},
Matthew Garrett 0988eed
-	{
Matthew Garrett 0988eed
-		.callback	= mbp_dmi_match,
Matthew Garrett 0988eed
-		.ident		= "MacBookPro 5,3",
Matthew Garrett 0988eed
-		.matches	= {
Matthew Garrett 0988eed
-			DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
Matthew Garrett 0988eed
-			DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro5,3"),
Matthew Garrett 0988eed
-		},
Matthew Garrett 0988eed
-		.driver_data	= (void *)&nvidia_chipset_data,
Matthew Garrett 0988eed
-	},
Matthew Garrett 0988eed
-	{
Matthew Garrett 0988eed
-		.callback	= mbp_dmi_match,
Matthew Garrett 0988eed
-		.ident		= "MacBookPro 5,4",
Matthew Garrett 0988eed
-		.matches	= {
Matthew Garrett 0988eed
-			DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
Matthew Garrett 0988eed
-			DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro5,4"),
Matthew Garrett 0988eed
-		},
Matthew Garrett 0988eed
-		.driver_data	= (void *)&nvidia_chipset_data,
Matthew Garrett 0988eed
-	},
Matthew Garrett 0988eed
-	{
Matthew Garrett 0988eed
-		.callback	= mbp_dmi_match,
Matthew Garrett 0988eed
-		.ident		= "MacBookPro 5,5",
Matthew Garrett 0988eed
-		.matches	= {
Matthew Garrett 0988eed
-			DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
Matthew Garrett 0988eed
-			DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro5,5"),
Matthew Garrett 0988eed
-		},
Matthew Garrett 0988eed
-		.driver_data	= (void *)&nvidia_chipset_data,
Matthew Garrett 0988eed
-	},
Matthew Garrett 0988eed
-	{
Matthew Garrett 0988eed
-		.callback	= mbp_dmi_match,
Matthew Garrett 0988eed
-		.ident		= "MacBookAir 3,1",
Matthew Garrett 0988eed
-		.matches	= {
Matthew Garrett 0988eed
-			DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
Matthew Garrett 0988eed
-			DMI_MATCH(DMI_PRODUCT_NAME, "MacBookAir3,1"),
Matthew Garrett 0988eed
-		},
Matthew Garrett 0988eed
-		.driver_data	= (void *)&nvidia_chipset_data,
Matthew Garrett 0988eed
-	},
Matthew Garrett 0988eed
-	{
Matthew Garrett 0988eed
-		.callback	= mbp_dmi_match,
Matthew Garrett 0988eed
-		.ident		= "MacBookAir 3,2",
Matthew Garrett 0988eed
-		.matches	= {
Matthew Garrett 0988eed
-			DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
Matthew Garrett 0988eed
-			DMI_MATCH(DMI_PRODUCT_NAME, "MacBookAir3,2"),
Matthew Garrett 0988eed
-		},
Matthew Garrett 0988eed
-		.driver_data	= (void *)&nvidia_chipset_data,
Matthew Garrett 0988eed
-	},
Matthew Garrett 0988eed
-	{ }
Matthew Garrett 0988eed
-};
Matthew Garrett 0988eed
-
Matthew Garrett 0988eed
-static int __init mbp_init(void)
Matthew Garrett 0988eed
-{
Matthew Garrett 0988eed
-	struct backlight_properties props;
Matthew Garrett 0988eed
-	if (!dmi_check_system(mbp_device_table))
Matthew Garrett 0988eed
-		return -ENODEV;
Matthew Garrett 0988eed
-
Matthew Garrett 0988eed
-	if (!request_region(driver_data->iostart, driver_data->iolen, 
Matthew Garrett 0988eed
-						"Macbook Pro backlight"))
Matthew Garrett 0988eed
-		return -ENXIO;
Matthew Garrett 0988eed
-
Matthew Garrett 0988eed
-	memset(&props, 0, sizeof(struct backlight_properties));
Matthew Garrett 0988eed
-	props.max_brightness = 15;
Matthew Garrett 0988eed
-	mbp_backlight_device = backlight_device_register("mbp_backlight", NULL,
Matthew Garrett 0988eed
-							 NULL,
Matthew Garrett 0988eed
-							 &driver_data->backlight_ops,
Matthew Garrett 0988eed
-							 &props;;
Matthew Garrett 0988eed
-	if (IS_ERR(mbp_backlight_device)) {
Matthew Garrett 0988eed
-		release_region(driver_data->iostart, driver_data->iolen);
Matthew Garrett 0988eed
-		return PTR_ERR(mbp_backlight_device);
Matthew Garrett 0988eed
-	}
Matthew Garrett 0988eed
-
Matthew Garrett 0988eed
-	mbp_backlight_device->props.brightness =
Matthew Garrett 0988eed
-		driver_data->backlight_ops.get_brightness(mbp_backlight_device);
Matthew Garrett 0988eed
-	backlight_update_status(mbp_backlight_device);
Matthew Garrett 0988eed
-
Matthew Garrett 0988eed
-	return 0;
Matthew Garrett 0988eed
-}
Matthew Garrett 0988eed
-
Matthew Garrett 0988eed
-static void __exit mbp_exit(void)
Matthew Garrett 0988eed
-{
Matthew Garrett 0988eed
-	backlight_device_unregister(mbp_backlight_device);
Matthew Garrett 0988eed
-
Matthew Garrett 0988eed
-	release_region(driver_data->iostart, driver_data->iolen);
Matthew Garrett 0988eed
-}
Matthew Garrett 0988eed
-
Matthew Garrett 0988eed
-module_init(mbp_init);
Matthew Garrett 0988eed
-module_exit(mbp_exit);
Matthew Garrett 0988eed
-
Matthew Garrett 0988eed
-MODULE_AUTHOR("Matthew Garrett <mjg@redhat.com>");
Matthew Garrett 0988eed
-MODULE_DESCRIPTION("Nvidia-based Macbook Pro Backlight Driver");
Matthew Garrett 0988eed
-MODULE_LICENSE("GPL");
Matthew Garrett 0988eed
-MODULE_DEVICE_TABLE(dmi, mbp_device_table);