Add some additional support for Apple hardware
This commit is contained in:
parent
52f64574fa
commit
f1d2f5da9e
|
@ -0,0 +1,384 @@
|
|||
commit 9964e2a108292685fbbf0980493c5e9776eac762
|
||||
Author: Seth Forshee <seth.forshee@canonical.com>
|
||||
Date: Fri Mar 16 14:41:21 2012 -0500
|
||||
|
||||
apple_bl: Add register/unregister functions
|
||||
|
||||
Add functions to allow other modules to enable or disable apple_bl. This
|
||||
will be used by the gmux driver to disable apple_bl when the gmux is
|
||||
present, as it is a better and more reliable option for brightness
|
||||
control.
|
||||
|
||||
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
|
||||
Signed-off-by: Matthew Garrett <mjg@redhat.com>
|
||||
|
||||
diff --git a/drivers/video/backlight/apple_bl.c b/drivers/video/backlight/apple_bl.c
|
||||
index be98d15..a523b25 100644
|
||||
--- a/drivers/video/backlight/apple_bl.c
|
||||
+++ b/drivers/video/backlight/apple_bl.c
|
||||
@@ -24,6 +24,7 @@
|
||||
#include <linux/io.h>
|
||||
#include <linux/pci.h>
|
||||
#include <linux/acpi.h>
|
||||
+#include <linux/atomic.h>
|
||||
|
||||
static struct backlight_device *apple_backlight_device;
|
||||
|
||||
@@ -221,14 +222,32 @@ static struct acpi_driver apple_bl_driver = {
|
||||
},
|
||||
};
|
||||
|
||||
+static atomic_t apple_bl_registered = ATOMIC_INIT(0);
|
||||
+
|
||||
+int apple_bl_register(void)
|
||||
+{
|
||||
+ if (atomic_xchg(&apple_bl_registered, 1) == 0)
|
||||
+ return acpi_bus_register_driver(&apple_bl_driver);
|
||||
+
|
||||
+ return 0;
|
||||
+}
|
||||
+EXPORT_SYMBOL_GPL(apple_bl_register);
|
||||
+
|
||||
+void apple_bl_unregister(void)
|
||||
+{
|
||||
+ if (atomic_xchg(&apple_bl_registered, 0) == 1)
|
||||
+ acpi_bus_unregister_driver(&apple_bl_driver);
|
||||
+}
|
||||
+EXPORT_SYMBOL_GPL(apple_bl_unregister);
|
||||
+
|
||||
static int __init apple_bl_init(void)
|
||||
{
|
||||
- return acpi_bus_register_driver(&apple_bl_driver);
|
||||
+ return apple_bl_register();
|
||||
}
|
||||
|
||||
static void __exit apple_bl_exit(void)
|
||||
{
|
||||
- acpi_bus_unregister_driver(&apple_bl_driver);
|
||||
+ apple_bl_unregister();
|
||||
}
|
||||
|
||||
module_init(apple_bl_init);
|
||||
diff --git a/include/linux/apple_bl.h b/include/linux/apple_bl.h
|
||||
new file mode 100644
|
||||
index 0000000..47bedc0
|
||||
--- /dev/null
|
||||
+++ b/include/linux/apple_bl.h
|
||||
@@ -0,0 +1,26 @@
|
||||
+/*
|
||||
+ * apple_bl exported symbols
|
||||
+ */
|
||||
+
|
||||
+#ifndef _LINUX_APPLE_BL_H
|
||||
+#define _LINUX_APPLE_BL_H
|
||||
+
|
||||
+#ifdef CONFIG_BACKLIGHT_APPLE
|
||||
+
|
||||
+extern int apple_bl_register(void);
|
||||
+extern void apple_bl_unregister(void);
|
||||
+
|
||||
+#else /* !CONFIG_BACKLIGHT_APPLE */
|
||||
+
|
||||
+static inline int apple_bl_register(void)
|
||||
+{
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
+static inline void apple_bl_unregister(void)
|
||||
+{
|
||||
+}
|
||||
+
|
||||
+#endif /* !CONFIG_BACKLIGHT_APPLE */
|
||||
+
|
||||
+#endif /* _LINUX_APPLE_BL_H */
|
||||
commit 89c093937dc8b07db4652251c83ec3710e5f15a2
|
||||
Author: Seth Forshee <seth.forshee@canonical.com>
|
||||
Date: Fri Mar 16 14:41:22 2012 -0500
|
||||
|
||||
platform/x86: Add driver for Apple gmux device
|
||||
|
||||
Apple laptops with hybrid graphics have a device named gmux that
|
||||
controls the muxing of the LVDS panel between the GPUs as well as screen
|
||||
brightness. This driver adds support for the gmux device. Only backlight
|
||||
control is supported initially.
|
||||
|
||||
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
|
||||
Signed-off-by: Matthew Garrett <mjg@redhat.com>
|
||||
Tested-by: Grant Likely <grant.likely@secretlab.ca>
|
||||
|
||||
diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig
|
||||
index ce10f03..c5b4bfe 100644
|
||||
--- a/drivers/platform/x86/Kconfig
|
||||
+++ b/drivers/platform/x86/Kconfig
|
||||
@@ -752,4 +752,14 @@ config SAMSUNG_Q10
|
||||
This driver provides support for backlight control on Samsung Q10
|
||||
and related laptops, including Dell Latitude X200.
|
||||
|
||||
+config APPLE_GMUX
|
||||
+ tristate "Apple Gmux Driver"
|
||||
+ depends on PNP
|
||||
+ select BACKLIGHT_CLASS_DEVICE
|
||||
+ ---help---
|
||||
+ This driver provides support for the gmux device found on many
|
||||
+ Apple laptops, which controls the display mux for the hybrid
|
||||
+ graphics as well as the backlight. Currently only backlight
|
||||
+ control is supported by the driver.
|
||||
+
|
||||
endif # X86_PLATFORM_DEVICES
|
||||
diff --git a/drivers/platform/x86/Makefile b/drivers/platform/x86/Makefile
|
||||
index dcfee6b..bf7e4f9 100644
|
||||
--- a/drivers/platform/x86/Makefile
|
||||
+++ b/drivers/platform/x86/Makefile
|
||||
@@ -49,3 +49,4 @@ obj-$(CONFIG_MXM_WMI) += mxm-wmi.o
|
||||
obj-$(CONFIG_INTEL_MID_POWER_BUTTON) += intel_mid_powerbtn.o
|
||||
obj-$(CONFIG_INTEL_OAKTRAIL) += intel_oaktrail.o
|
||||
obj-$(CONFIG_SAMSUNG_Q10) += samsung-q10.o
|
||||
+obj-$(CONFIG_APPLE_GMUX) += apple-gmux.o
|
||||
diff --git a/drivers/platform/x86/apple-gmux.c b/drivers/platform/x86/apple-gmux.c
|
||||
new file mode 100644
|
||||
index 0000000..c81e31f
|
||||
--- /dev/null
|
||||
+++ b/drivers/platform/x86/apple-gmux.c
|
||||
@@ -0,0 +1,242 @@
|
||||
+/*
|
||||
+ * Gmux driver for Apple laptops
|
||||
+ *
|
||||
+ * Copyright (C) Canonical Ltd. <seth.forshee@canonical.com>
|
||||
+ *
|
||||
+ * 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.
|
||||
+ */
|
||||
+
|
||||
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
||||
+
|
||||
+#include <linux/module.h>
|
||||
+#include <linux/kernel.h>
|
||||
+#include <linux/init.h>
|
||||
+#include <linux/backlight.h>
|
||||
+#include <linux/acpi.h>
|
||||
+#include <linux/pnp.h>
|
||||
+#include <linux/apple_bl.h>
|
||||
+#include <acpi/video.h>
|
||||
+
|
||||
+struct apple_gmux_data {
|
||||
+ unsigned long iostart;
|
||||
+ unsigned long iolen;
|
||||
+
|
||||
+ struct backlight_device *bdev;
|
||||
+};
|
||||
+
|
||||
+/*
|
||||
+ * gmux port offsets. Many of these are not yet used, but may be in the
|
||||
+ * future, and it's useful to have them documented here anyhow.
|
||||
+ */
|
||||
+#define GMUX_PORT_VERSION_MAJOR 0x04
|
||||
+#define GMUX_PORT_VERSION_MINOR 0x05
|
||||
+#define GMUX_PORT_VERSION_RELEASE 0x06
|
||||
+#define GMUX_PORT_SWITCH_DISPLAY 0x10
|
||||
+#define GMUX_PORT_SWITCH_GET_DISPLAY 0x11
|
||||
+#define GMUX_PORT_INTERRUPT_ENABLE 0x14
|
||||
+#define GMUX_PORT_INTERRUPT_STATUS 0x16
|
||||
+#define GMUX_PORT_SWITCH_DDC 0x28
|
||||
+#define GMUX_PORT_SWITCH_EXTERNAL 0x40
|
||||
+#define GMUX_PORT_SWITCH_GET_EXTERNAL 0x41
|
||||
+#define GMUX_PORT_DISCRETE_POWER 0x50
|
||||
+#define GMUX_PORT_MAX_BRIGHTNESS 0x70
|
||||
+#define GMUX_PORT_BRIGHTNESS 0x74
|
||||
+
|
||||
+#define GMUX_MIN_IO_LEN (GMUX_PORT_BRIGHTNESS + 4)
|
||||
+
|
||||
+#define GMUX_INTERRUPT_ENABLE 0xff
|
||||
+#define GMUX_INTERRUPT_DISABLE 0x00
|
||||
+
|
||||
+#define GMUX_INTERRUPT_STATUS_ACTIVE 0
|
||||
+#define GMUX_INTERRUPT_STATUS_DISPLAY (1 << 0)
|
||||
+#define GMUX_INTERRUPT_STATUS_POWER (1 << 2)
|
||||
+#define GMUX_INTERRUPT_STATUS_HOTPLUG (1 << 3)
|
||||
+
|
||||
+#define GMUX_BRIGHTNESS_MASK 0x00ffffff
|
||||
+#define GMUX_MAX_BRIGHTNESS GMUX_BRIGHTNESS_MASK
|
||||
+
|
||||
+static inline u8 gmux_read8(struct apple_gmux_data *gmux_data, int port)
|
||||
+{
|
||||
+ return inb(gmux_data->iostart + port);
|
||||
+}
|
||||
+
|
||||
+static inline void gmux_write8(struct apple_gmux_data *gmux_data, int port,
|
||||
+ u8 val)
|
||||
+{
|
||||
+ outb(val, gmux_data->iostart + port);
|
||||
+}
|
||||
+
|
||||
+static inline u32 gmux_read32(struct apple_gmux_data *gmux_data, int port)
|
||||
+{
|
||||
+ return inl(gmux_data->iostart + port);
|
||||
+}
|
||||
+
|
||||
+static int gmux_get_brightness(struct backlight_device *bd)
|
||||
+{
|
||||
+ struct apple_gmux_data *gmux_data = bl_get_data(bd);
|
||||
+ return gmux_read32(gmux_data, GMUX_PORT_BRIGHTNESS) &
|
||||
+ GMUX_BRIGHTNESS_MASK;
|
||||
+}
|
||||
+
|
||||
+static int gmux_update_status(struct backlight_device *bd)
|
||||
+{
|
||||
+ struct apple_gmux_data *gmux_data = bl_get_data(bd);
|
||||
+ u32 brightness = bd->props.brightness;
|
||||
+
|
||||
+ /*
|
||||
+ * Older gmux versions require writing out lower bytes first then
|
||||
+ * setting the upper byte to 0 to flush the values. Newer versions
|
||||
+ * accept a single u32 write, but the old method also works, so we
|
||||
+ * just use the old method for all gmux versions.
|
||||
+ */
|
||||
+ gmux_write8(gmux_data, GMUX_PORT_BRIGHTNESS, brightness);
|
||||
+ gmux_write8(gmux_data, GMUX_PORT_BRIGHTNESS + 1, brightness >> 8);
|
||||
+ gmux_write8(gmux_data, GMUX_PORT_BRIGHTNESS + 2, brightness >> 16);
|
||||
+ gmux_write8(gmux_data, GMUX_PORT_BRIGHTNESS + 3, 0);
|
||||
+
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
+static const struct backlight_ops gmux_bl_ops = {
|
||||
+ .get_brightness = gmux_get_brightness,
|
||||
+ .update_status = gmux_update_status,
|
||||
+};
|
||||
+
|
||||
+static int __devinit gmux_probe(struct pnp_dev *pnp,
|
||||
+ const struct pnp_device_id *id)
|
||||
+{
|
||||
+ struct apple_gmux_data *gmux_data;
|
||||
+ struct resource *res;
|
||||
+ struct backlight_properties props;
|
||||
+ struct backlight_device *bdev;
|
||||
+ u8 ver_major, ver_minor, ver_release;
|
||||
+ int ret = -ENXIO;
|
||||
+
|
||||
+ gmux_data = kzalloc(sizeof(*gmux_data), GFP_KERNEL);
|
||||
+ if (!gmux_data)
|
||||
+ return -ENOMEM;
|
||||
+ pnp_set_drvdata(pnp, gmux_data);
|
||||
+
|
||||
+ res = pnp_get_resource(pnp, IORESOURCE_IO, 0);
|
||||
+ if (!res) {
|
||||
+ pr_err("Failed to find gmux I/O resource\n");
|
||||
+ goto err_free;
|
||||
+ }
|
||||
+
|
||||
+ gmux_data->iostart = res->start;
|
||||
+ gmux_data->iolen = res->end - res->start;
|
||||
+
|
||||
+ if (gmux_data->iolen < GMUX_MIN_IO_LEN) {
|
||||
+ pr_err("gmux I/O region too small (%lu < %u)\n",
|
||||
+ gmux_data->iolen, GMUX_MIN_IO_LEN);
|
||||
+ goto err_free;
|
||||
+ }
|
||||
+
|
||||
+ if (!request_region(gmux_data->iostart, gmux_data->iolen,
|
||||
+ "Apple gmux")) {
|
||||
+ pr_err("gmux I/O already in use\n");
|
||||
+ goto err_free;
|
||||
+ }
|
||||
+
|
||||
+ /*
|
||||
+ * On some machines the gmux is in ACPI even thought the machine
|
||||
+ * doesn't really have a gmux. Check for invalid version information
|
||||
+ * to detect this.
|
||||
+ */
|
||||
+ ver_major = gmux_read8(gmux_data, GMUX_PORT_VERSION_MAJOR);
|
||||
+ ver_minor = gmux_read8(gmux_data, GMUX_PORT_VERSION_MINOR);
|
||||
+ ver_release = gmux_read8(gmux_data, GMUX_PORT_VERSION_RELEASE);
|
||||
+ if (ver_major == 0xff && ver_minor == 0xff && ver_release == 0xff) {
|
||||
+ pr_info("gmux device not present\n");
|
||||
+ ret = -ENODEV;
|
||||
+ goto err_release;
|
||||
+ }
|
||||
+
|
||||
+ pr_info("Found gmux version %d.%d.%d\n", ver_major, ver_minor,
|
||||
+ ver_release);
|
||||
+
|
||||
+ memset(&props, 0, sizeof(props));
|
||||
+ props.type = BACKLIGHT_PLATFORM;
|
||||
+ props.max_brightness = gmux_read32(gmux_data, GMUX_PORT_MAX_BRIGHTNESS);
|
||||
+
|
||||
+ /*
|
||||
+ * Currently it's assumed that the maximum brightness is less than
|
||||
+ * 2^24 for compatibility with old gmux versions. Cap the max
|
||||
+ * brightness at this value, but print a warning if the hardware
|
||||
+ * reports something higher so that it can be fixed.
|
||||
+ */
|
||||
+ if (WARN_ON(props.max_brightness > GMUX_MAX_BRIGHTNESS))
|
||||
+ props.max_brightness = GMUX_MAX_BRIGHTNESS;
|
||||
+
|
||||
+ bdev = backlight_device_register("gmux_backlight", &pnp->dev,
|
||||
+ gmux_data, &gmux_bl_ops, &props);
|
||||
+ if (IS_ERR(bdev)) {
|
||||
+ ret = PTR_ERR(bdev);
|
||||
+ goto err_release;
|
||||
+ }
|
||||
+
|
||||
+ gmux_data->bdev = bdev;
|
||||
+ bdev->props.brightness = gmux_get_brightness(bdev);
|
||||
+ backlight_update_status(bdev);
|
||||
+
|
||||
+ /*
|
||||
+ * The backlight situation on Macs is complicated. If the gmux is
|
||||
+ * present it's the best choice, because it always works for
|
||||
+ * backlight control and supports more levels than other options.
|
||||
+ * Disable the other backlight choices.
|
||||
+ */
|
||||
+ acpi_video_unregister();
|
||||
+ apple_bl_unregister();
|
||||
+
|
||||
+ return 0;
|
||||
+
|
||||
+err_release:
|
||||
+ release_region(gmux_data->iostart, gmux_data->iolen);
|
||||
+err_free:
|
||||
+ kfree(gmux_data);
|
||||
+ return ret;
|
||||
+}
|
||||
+
|
||||
+static void __devexit gmux_remove(struct pnp_dev *pnp)
|
||||
+{
|
||||
+ struct apple_gmux_data *gmux_data = pnp_get_drvdata(pnp);
|
||||
+
|
||||
+ backlight_device_unregister(gmux_data->bdev);
|
||||
+ release_region(gmux_data->iostart, gmux_data->iolen);
|
||||
+ kfree(gmux_data);
|
||||
+
|
||||
+ acpi_video_register();
|
||||
+ apple_bl_register();
|
||||
+}
|
||||
+
|
||||
+static const struct pnp_device_id gmux_device_ids[] = {
|
||||
+ {"APP000B", 0},
|
||||
+ {"", 0}
|
||||
+};
|
||||
+
|
||||
+static struct pnp_driver gmux_pnp_driver = {
|
||||
+ .name = "apple-gmux",
|
||||
+ .probe = gmux_probe,
|
||||
+ .remove = __devexit_p(gmux_remove),
|
||||
+ .id_table = gmux_device_ids,
|
||||
+};
|
||||
+
|
||||
+static int __init apple_gmux_init(void)
|
||||
+{
|
||||
+ return pnp_register_driver(&gmux_pnp_driver);
|
||||
+}
|
||||
+
|
||||
+static void __exit apple_gmux_exit(void)
|
||||
+{
|
||||
+ pnp_unregister_driver(&gmux_pnp_driver);
|
||||
+}
|
||||
+
|
||||
+module_init(apple_gmux_init);
|
||||
+module_exit(apple_gmux_exit);
|
||||
+
|
||||
+MODULE_AUTHOR("Seth Forshee <seth.forshee@canonical.com>");
|
||||
+MODULE_DESCRIPTION("Apple Gmux Driver");
|
||||
+MODULE_LICENSE("GPL");
|
||||
+MODULE_DEVICE_TABLE(pnp, gmux_device_ids);
|
|
@ -0,0 +1,274 @@
|
|||
diff --git a/arch/x86/include/asm/vga.h b/arch/x86/include/asm/vga.h
|
||||
index c4b9dc2..2723c07 100644
|
||||
--- a/arch/x86/include/asm/vga.h
|
||||
+++ b/arch/x86/include/asm/vga.h
|
||||
@@ -17,4 +17,10 @@
|
||||
#define vga_readb(x) (*(x))
|
||||
#define vga_writeb(x, y) (*(y) = (x))
|
||||
|
||||
+#if CONFIG_FB_EFI
|
||||
+#define __ARCH_HAS_VGA_DEFAULT_DEVICE
|
||||
+extern struct pci_dev *vga_default_device(void);
|
||||
+extern void vga_set_default_device(struct pci_dev *pdev);
|
||||
+#endif
|
||||
+
|
||||
#endif /* _ASM_X86_VGA_H */
|
||||
diff --git a/arch/x86/video/fbdev.c b/arch/x86/video/fbdev.c
|
||||
index c5ffb6a..d5644bb 100644
|
||||
--- a/arch/x86/video/fbdev.c
|
||||
+++ b/arch/x86/video/fbdev.c
|
||||
@@ -9,24 +9,34 @@
|
||||
#include <linux/fb.h>
|
||||
#include <linux/pci.h>
|
||||
#include <linux/module.h>
|
||||
+#include <linux/vgaarb.h>
|
||||
|
||||
int fb_is_primary_device(struct fb_info *info)
|
||||
{
|
||||
struct device *device = info->device;
|
||||
struct pci_dev *pci_dev = NULL;
|
||||
+ struct pci_dev *default_device = vga_default_device();
|
||||
struct resource *res = NULL;
|
||||
- int retval = 0;
|
||||
|
||||
if (device)
|
||||
pci_dev = to_pci_dev(device);
|
||||
|
||||
- if (pci_dev)
|
||||
- res = &pci_dev->resource[PCI_ROM_RESOURCE];
|
||||
+ if (!pci_dev)
|
||||
+ return 0;
|
||||
+
|
||||
+ if (default_device) {
|
||||
+ if (pci_dev == default_device)
|
||||
+ return 1;
|
||||
+ else
|
||||
+ return 0;
|
||||
+ }
|
||||
+
|
||||
+ res = &pci_dev->resource[PCI_ROM_RESOURCE];
|
||||
|
||||
if (res && res->flags & IORESOURCE_ROM_SHADOW)
|
||||
- retval = 1;
|
||||
+ return 1;
|
||||
|
||||
- return retval;
|
||||
+ return 0;
|
||||
}
|
||||
EXPORT_SYMBOL(fb_is_primary_device);
|
||||
MODULE_LICENSE("GPL");
|
||||
diff --git a/drivers/gpu/vga/vga_switcheroo.c b/drivers/gpu/vga/vga_switcheroo.c
|
||||
index 9a2c805..44c664e 100644
|
||||
--- a/drivers/gpu/vga/vga_switcheroo.c
|
||||
+++ b/drivers/gpu/vga/vga_switcheroo.c
|
||||
@@ -28,6 +28,8 @@
|
||||
#include <linux/pci.h>
|
||||
#include <linux/vga_switcheroo.h>
|
||||
|
||||
+#include <linux/vgaarb.h>
|
||||
+
|
||||
struct vga_switcheroo_client {
|
||||
struct pci_dev *pdev;
|
||||
struct fb_info *fb_info;
|
||||
@@ -140,7 +142,7 @@ int vga_switcheroo_register_client(struct pci_dev *pdev,
|
||||
vgasr_priv.clients[index].reprobe = reprobe;
|
||||
vgasr_priv.clients[index].can_switch = can_switch;
|
||||
vgasr_priv.clients[index].id = -1;
|
||||
- if (pdev->resource[PCI_ROM_RESOURCE].flags & IORESOURCE_ROM_SHADOW)
|
||||
+ if (pdev == vga_default_device())
|
||||
vgasr_priv.clients[index].active = true;
|
||||
|
||||
vgasr_priv.registered_clients |= (1 << index);
|
||||
@@ -248,9 +250,8 @@ static int vga_switchto_stage1(struct vga_switcheroo_client *new_client)
|
||||
if (new_client->pwr_state == VGA_SWITCHEROO_OFF)
|
||||
vga_switchon(new_client);
|
||||
|
||||
- /* swap shadow resource to denote boot VGA device has changed so X starts on new device */
|
||||
- active->pdev->resource[PCI_ROM_RESOURCE].flags &= ~IORESOURCE_ROM_SHADOW;
|
||||
- new_client->pdev->resource[PCI_ROM_RESOURCE].flags |= IORESOURCE_ROM_SHADOW;
|
||||
+ vga_set_default_device(new_client->pdev);
|
||||
+
|
||||
return 0;
|
||||
}
|
||||
|
||||
diff --git a/drivers/gpu/vga/vgaarb.c b/drivers/gpu/vga/vgaarb.c
|
||||
index 111d956..e223b96 100644
|
||||
--- a/drivers/gpu/vga/vgaarb.c
|
||||
+++ b/drivers/gpu/vga/vgaarb.c
|
||||
@@ -136,6 +136,11 @@ struct pci_dev *vga_default_device(void)
|
||||
{
|
||||
return vga_default;
|
||||
}
|
||||
+
|
||||
+void vga_set_default_device(struct pci_dev *pdev)
|
||||
+{
|
||||
+ vga_default = pdev;
|
||||
+}
|
||||
#endif
|
||||
|
||||
static inline void vga_irq_set_state(struct vga_device *vgadev, bool state)
|
||||
@@ -605,10 +610,12 @@ static bool vga_arbiter_del_pci_device(struct pci_dev *pdev)
|
||||
goto bail;
|
||||
}
|
||||
|
||||
+#ifndef __ARCH_HAS_VGA_DEFAULT_DEVICE
|
||||
if (vga_default == pdev) {
|
||||
pci_dev_put(vga_default);
|
||||
vga_default = NULL;
|
||||
}
|
||||
+#endif
|
||||
|
||||
if (vgadev->decodes & (VGA_RSRC_LEGACY_IO | VGA_RSRC_LEGACY_MEM))
|
||||
vga_decode_count--;
|
||||
diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
|
||||
index a3cd8ca..7dd9f2b 100644
|
||||
--- a/drivers/pci/pci-sysfs.c
|
||||
+++ b/drivers/pci/pci-sysfs.c
|
||||
@@ -27,6 +27,7 @@
|
||||
#include <linux/security.h>
|
||||
#include <linux/pci-aspm.h>
|
||||
#include <linux/slab.h>
|
||||
+#include <linux/vgaarb.h>
|
||||
#include "pci.h"
|
||||
|
||||
static int sysfs_initialized; /* = 0 */
|
||||
@@ -414,6 +415,10 @@ static ssize_t
|
||||
boot_vga_show(struct device *dev, struct device_attribute *attr, char *buf)
|
||||
{
|
||||
struct pci_dev *pdev = to_pci_dev(dev);
|
||||
+ struct pci_dev *vga_dev = vga_default_device();
|
||||
+
|
||||
+ if (vga_dev)
|
||||
+ return sprintf(buf, "%u\n", (pdev == vga_dev));
|
||||
|
||||
return sprintf(buf, "%u\n",
|
||||
!!(pdev->resource[PCI_ROM_RESOURCE].flags &
|
||||
diff --git a/drivers/video/efifb.c b/drivers/video/efifb.c
|
||||
index 784139a..66ed991 100644
|
||||
--- a/drivers/video/efifb.c
|
||||
+++ b/drivers/video/efifb.c
|
||||
@@ -18,6 +18,8 @@
|
||||
|
||||
static bool request_mem_succeeded = false;
|
||||
|
||||
+static struct pci_dev *default_vga;
|
||||
+
|
||||
static struct fb_var_screeninfo efifb_defined __devinitdata = {
|
||||
.activate = FB_ACTIVATE_NOW,
|
||||
.height = -1,
|
||||
@@ -298,35 +300,70 @@ static struct fb_ops efifb_ops = {
|
||||
.fb_imageblit = cfb_imageblit,
|
||||
};
|
||||
|
||||
+struct pci_dev *vga_default_device(void)
|
||||
+{
|
||||
+ return default_vga;
|
||||
+}
|
||||
+
|
||||
+void vga_set_default_device(struct pci_dev *pdev)
|
||||
+{
|
||||
+ default_vga = pdev;
|
||||
+}
|
||||
+
|
||||
static int __init efifb_setup(char *options)
|
||||
{
|
||||
char *this_opt;
|
||||
int i;
|
||||
+ struct pci_dev *dev = NULL;
|
||||
+
|
||||
+ if (options && *options) {
|
||||
+ while ((this_opt = strsep(&options, ",")) != NULL) {
|
||||
+ if (!*this_opt) continue;
|
||||
+
|
||||
+ for (i = 0; i < M_UNKNOWN; i++) {
|
||||
+ if (!strcmp(this_opt, dmi_list[i].optname) &&
|
||||
+ dmi_list[i].base != 0) {
|
||||
+ screen_info.lfb_base = dmi_list[i].base;
|
||||
+ screen_info.lfb_linelength = dmi_list[i].stride;
|
||||
+ screen_info.lfb_width = dmi_list[i].width;
|
||||
+ screen_info.lfb_height = dmi_list[i].height;
|
||||
+ }
|
||||
+ }
|
||||
+ if (!strncmp(this_opt, "base:", 5))
|
||||
+ screen_info.lfb_base = simple_strtoul(this_opt+5, NULL, 0);
|
||||
+ else if (!strncmp(this_opt, "stride:", 7))
|
||||
+ screen_info.lfb_linelength = simple_strtoul(this_opt+7, NULL, 0) * 4;
|
||||
+ else if (!strncmp(this_opt, "height:", 7))
|
||||
+ screen_info.lfb_height = simple_strtoul(this_opt+7, NULL, 0);
|
||||
+ else if (!strncmp(this_opt, "width:", 6))
|
||||
+ screen_info.lfb_width = simple_strtoul(this_opt+6, NULL, 0);
|
||||
+ }
|
||||
+ }
|
||||
|
||||
- if (!options || !*options)
|
||||
- return 0;
|
||||
+ for_each_pci_dev(dev) {
|
||||
+ int i;
|
||||
|
||||
- while ((this_opt = strsep(&options, ",")) != NULL) {
|
||||
- if (!*this_opt) continue;
|
||||
+ if ((dev->class >> 8) != PCI_CLASS_DISPLAY_VGA)
|
||||
+ continue;
|
||||
|
||||
- for (i = 0; i < M_UNKNOWN; i++) {
|
||||
- if (!strcmp(this_opt, dmi_list[i].optname) &&
|
||||
- dmi_list[i].base != 0) {
|
||||
- screen_info.lfb_base = dmi_list[i].base;
|
||||
- screen_info.lfb_linelength = dmi_list[i].stride;
|
||||
- screen_info.lfb_width = dmi_list[i].width;
|
||||
- screen_info.lfb_height = dmi_list[i].height;
|
||||
- }
|
||||
+ for (i=0; i < DEVICE_COUNT_RESOURCE; i++) {
|
||||
+ resource_size_t start, end;
|
||||
+
|
||||
+ if (!(pci_resource_flags(dev, i) & IORESOURCE_MEM))
|
||||
+ continue;
|
||||
+
|
||||
+ start = pci_resource_start(dev, i);
|
||||
+ end = pci_resource_end(dev, i);
|
||||
+
|
||||
+ if (!start || !end)
|
||||
+ continue;
|
||||
+
|
||||
+ if (screen_info.lfb_base >= start &&
|
||||
+ (screen_info.lfb_base + screen_info.lfb_size) < end)
|
||||
+ default_vga = dev;
|
||||
}
|
||||
- if (!strncmp(this_opt, "base:", 5))
|
||||
- screen_info.lfb_base = simple_strtoul(this_opt+5, NULL, 0);
|
||||
- else if (!strncmp(this_opt, "stride:", 7))
|
||||
- screen_info.lfb_linelength = simple_strtoul(this_opt+7, NULL, 0) * 4;
|
||||
- else if (!strncmp(this_opt, "height:", 7))
|
||||
- screen_info.lfb_height = simple_strtoul(this_opt+7, NULL, 0);
|
||||
- else if (!strncmp(this_opt, "width:", 6))
|
||||
- screen_info.lfb_width = simple_strtoul(this_opt+6, NULL, 0);
|
||||
}
|
||||
+
|
||||
return 0;
|
||||
}
|
||||
|
||||
diff --git a/include/linux/vgaarb.h b/include/linux/vgaarb.h
|
||||
index 9c3120d..7ad7f2a 100644
|
||||
--- a/include/linux/vgaarb.h
|
||||
+++ b/include/linux/vgaarb.h
|
||||
@@ -31,6 +31,7 @@
|
||||
#ifndef LINUX_VGA_H
|
||||
#define LINUX_VGA_H
|
||||
|
||||
+#include <video/vga.h>
|
||||
|
||||
/* Legacy VGA regions */
|
||||
#define VGA_RSRC_NONE 0x00
|
||||
@@ -177,10 +178,12 @@ extern void vga_put(struct pci_dev *pdev, unsigned int rsrc);
|
||||
* I suppose it's a matter of having the proper arch hook telling
|
||||
* us about it, so we basically never allow anybody to succeed a
|
||||
* vga_get()...
|
||||
+ *
|
||||
*/
|
||||
|
||||
#ifndef __ARCH_HAS_VGA_DEFAULT_DEVICE
|
||||
extern struct pci_dev *vga_default_device(void);
|
||||
+extern void vga_set_default_device(struct pci_dev *pdev)
|
||||
#endif
|
||||
|
||||
/**
|
Loading…
Reference in New Issue