From: Andrew Morton <akpm@linux-foundation.org>
To: Matthew Garrett <mjg59@srcf.ucam.org>
Cc: rpurdie@rpsys.net, linux-kernel@vger.kernel.org, mzxreary@0pointer.de
Subject: Re: [PATCH] Add backlight driver for Nvidia-based Apple Macbook Pros
Date: Fri, 6 Jun 2008 23:07:45 -0700 [thread overview]
Message-ID: <20080606230745.304d116b.akpm@linux-foundation.org> (raw)
In-Reply-To: <20080607025436.GB24254@srcf.ucam.org>
On Sat, 7 Jun 2008 03:54:36 +0100 Matthew Garrett <mjg59@srcf.ucam.org> wrote:
> Nvidia-based Apple Macbook Pros don't appear to handle backlight control
> through the graphics card registers or ACPI, but instead trigger changes
> via SMI calls. This driver registers a generic backlight device that
> lets existing userspace deal with it. Code derived from Julien Blache's
> Pommed application.
>
> Signed-off-by: Matthew Garrett <mjg@redhat.com>
>
> ...
>
> --- /dev/null
> +++ b/drivers/video/backlight/mbp_nvidia_bl.c
> @@ -0,0 +1,114 @@
> +/*
> + * Backlight Driver for Nvidia 8600 in Macbook Pro
> + *
> + * Copyright (c) Red Hat <mjg@redhat.com>
> + * Based on code from Pommed:
> + * Copyright (C) 2006 Nicolas Boichat <nicolas @boichat.ch>
> + * Copyright (C) 2006 Felipe Alfaro Solana <felipe_alfaro @linuxmail.org>
> + * Copyright (C) 2007 Julien BLACHE <jb@jblache.org>
Did this patch have appropriate attribution and signoffs?
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2 as
> + * published by the Free Software Foundation.
> + *
> + * This driver triggers SMIs which cause the firmware to change the
> + * backlight brightness. This is icky in many ways, but it's impractical to
> + * get at the firmware code in order to figure out what it's actually doing.
> + */
> +
> +#include <linux/module.h>
> +#include <linux/kernel.h>
> +#include <linux/init.h>
> +#include <linux/platform_device.h>
> +#include <linux/backlight.h>
> +#include <linux/err.h>
> +#include <linux/dmi.h>
> +#include <linux/io.h>
> +
> +struct backlight_device *mbp_backlight_device;
> +
> +static struct dmi_system_id __initdata mbp_device_table[] = {
> + {
> + .ident = "3,1",
> + .matches = {
> + DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
> + DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro3,1"),
> + },
> + },
> + {
> + .ident = "3,2",
> + .matches = {
> + DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
> + DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro3,2"),
> + },
> + },
> + {
> + .ident = "4,1",
> + .matches = {
> + DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
> + DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro4,1"),
> + },
> + },
> + { }
> +};
> +
> +static int mbp_send_intensity(struct backlight_device *bd)
> +{
> + int intensity = bd->props.brightness;
> +
> + outb(0x04 | (intensity << 4), 0xb3);
> + outb(0xbf, 0xb2);
> +
> + return 0;
> +}
> +
> +static int mbp_get_intensity(struct backlight_device *bd)
> +{
> + outb(0x03, 0xb3);
> + outb(0xbf, 0xb2);
> + return inb(0xb3) >> 4;
> +}
> +
> +static struct backlight_ops mbp_ops = {
> + .get_brightness = mbp_get_intensity,
> + .update_status = mbp_send_intensity,
> +};
> +
> +static int __init mbp_init(void)
> +{
> + if (!dmi_check_system(mbp_device_table))
> + return -ENODEV;
> +
> + if (!request_region(0xb2, 2, "Macbook Pro backlight"))
> + return -ENXIO;
> +
> + mbp_backlight_device = backlight_device_register("mbp_backlight",
> + NULL, NULL,
> + &mbp_ops);
> + if (IS_ERR(mbp_backlight_device))
> + return PTR_ERR(mbp_backlight_device);
Missing release_region()?
> + mbp_backlight_device->props.max_brightness = 15;
> + mbp_backlight_device->props.brightness =
> + mbp_get_intensity(mbp_backlight_device);
> + backlight_update_status(mbp_backlight_device);
> +
> + return 0;
> +}
> +
> +static void __exit mbp_exit(void)
> +{
> + backlight_device_unregister(mbp_backlight_device);
> +
> + release_region(0xb2, 2);
> +}
> +
> +module_init(mbp_init);
> +module_exit(mbp_exit);
> +
> +MODULE_AUTHOR("Matthew Garrett <mjg@redhat.com>");
> +MODULE_DESCRIPTION("Nvidia-based Macbook Pro Backlight Driver");
> +MODULE_LICENSE("GPL");
> +MODULE_ALIAS("dmi:*:svnApple Inc.:pnMacBookPro3,1:*");
> +MODULE_ALIAS("dmi:*:svnApple Inc.:pnMacBookPro3,2:*");
> +MODULE_ALIAS("dmi:*:svnApple Inc.:pnMacBookPro4,1:*");
next prev parent reply other threads:[~2008-06-07 6:08 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-06-07 2:54 Matthew Garrett
2008-06-07 5:04 ` Andrey Panin
2008-06-07 6:07 ` Andrew Morton [this message]
2008-06-07 9:58 ` Matthew Garrett
2008-06-07 10:05 ` Pekka Enberg
2008-06-07 10:14 ` Matthew Garrett
2008-06-07 10:50 ` Pekka Enberg
2008-06-07 18:59 ` Andrew Morton
2008-06-07 10:01 ` [PATCH v2] " Matthew Garrett
2008-06-07 14:45 ` Julien BLACHE
2008-06-08 18:32 ` [PATCH] " Lennart Poettering
2008-06-09 0:03 ` Matthew Garrett
2008-06-09 0:05 ` [PATCH v2] " Matthew Garrett
2008-06-09 20:59 ` Richard Purdie
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20080606230745.304d116b.akpm@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mjg59@srcf.ucam.org \
--cc=mzxreary@0pointer.de \
--cc=rpurdie@rpsys.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome