include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit...
[safe/jmp/linux-2.6] / drivers / platform / x86 / dell-laptop.c
index b4c2190..661e3ac 100644 (file)
@@ -22,7 +22,9 @@
 #include <linux/rfkill.h>
 #include <linux/power_supply.h>
 #include <linux/acpi.h>
+#include <linux/mm.h>
 #include <linux/i8042.h>
+#include <linux/slab.h>
 #include "../../firmware/dcdbas.h"
 
 #define BRIGHTNESS_TOKEN 0x7d
@@ -80,9 +82,73 @@ static const struct dmi_system_id __initdata dell_device_table[] = {
                        DMI_MATCH(DMI_CHASSIS_TYPE, "8"),
                },
        },
+       {
+               .ident = "Dell Computer Corporation",
+               .matches = {
+                       DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer Corporation"),
+                       DMI_MATCH(DMI_CHASSIS_TYPE, "8"),
+               },
+       },
        { }
 };
 
+static struct dmi_system_id __devinitdata dell_blacklist[] = {
+       /* Supported by compal-laptop */
+       {
+               .ident = "Dell Mini 9",
+               .matches = {
+                       DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
+                       DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 910"),
+               },
+       },
+       {
+               .ident = "Dell Mini 10",
+               .matches = {
+                       DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
+                       DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 1010"),
+               },
+       },
+       {
+               .ident = "Dell Mini 10v",
+               .matches = {
+                       DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
+                       DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 1011"),
+               },
+       },
+       {
+               .ident = "Dell Inspiron 11z",
+               .matches = {
+                       DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
+                       DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 1110"),
+               },
+       },
+       {
+               .ident = "Dell Mini 12",
+               .matches = {
+                       DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
+                       DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 1210"),
+               },
+       },
+       {}
+};
+
+static struct calling_interface_buffer *buffer;
+static struct page *bufferpage;
+static DEFINE_MUTEX(buffer_mutex);
+
+static int hwswitch_state;
+
+static void get_buffer(void)
+{
+       mutex_lock(&buffer_mutex);
+       memset(buffer, 0, sizeof(struct calling_interface_buffer));
+}
+
+static void release_buffer(void)
+{
+       mutex_unlock(&buffer_mutex);
+}
+
 static void __init parse_da_table(const struct dmi_header *dm)
 {
        /* Final token is a terminator, so we don't want to copy it */
@@ -161,6 +227,8 @@ dell_send_request(struct calling_interface_buffer *buffer, int class,
 /* Derived from information in DellWirelessCtl.cpp:
    Class 17, select 11 is radio control. It returns an array of 32-bit values.
 
+   Input byte 0 = 0: Wireless information
+
    result[0]: return code
    result[1]:
      Bit 0:      Hardware switch supported
@@ -181,33 +249,62 @@ dell_send_request(struct calling_interface_buffer *buffer, int class,
      Bits 20-31: Reserved
    result[2]: NVRAM size in bytes
    result[3]: NVRAM format version number
+
+   Input byte 0 = 2: Wireless switch configuration
+   result[0]: return code
+   result[1]:
+     Bit 0:      Wifi controlled by switch
+     Bit 1:      Bluetooth controlled by switch
+     Bit 2:      WWAN controlled by switch
+     Bits 3-6:   Reserved
+     Bit 7:      Wireless switch config locked
+     Bit 8:      Wifi locator enabled
+     Bits 9-14:  Reserved
+     Bit 15:     Wifi locator setting locked
+     Bits 16-31: Reserved
 */
 
 static int dell_rfkill_set(void *data, bool blocked)
 {
-       struct calling_interface_buffer buffer;
        int disable = blocked ? 1 : 0;
        unsigned long radio = (unsigned long)data;
+       int hwswitch_bit = (unsigned long)data - 1;
+       int ret = 0;
+
+       get_buffer();
+       dell_send_request(buffer, 17, 11);
+
+       /* If the hardware switch controls this radio, and the hardware
+          switch is disabled, don't allow changing the software state */
+       if ((hwswitch_state & BIT(hwswitch_bit)) &&
+           !(buffer->output[1] & BIT(16))) {
+               ret = -EINVAL;
+               goto out;
+       }
 
-       memset(&buffer, 0, sizeof(struct calling_interface_buffer));
-       buffer.input[0] = (1 | (radio<<8) | (disable << 16));
-       dell_send_request(&buffer, 17, 11);
+       buffer->input[0] = (1 | (radio<<8) | (disable << 16));
+       dell_send_request(buffer, 17, 11);
 
-       return 0;
+out:
+       release_buffer();
+       return ret;
 }
 
 static void dell_rfkill_query(struct rfkill *rfkill, void *data)
 {
-       struct calling_interface_buffer buffer;
        int status;
        int bit = (unsigned long)data + 16;
+       int hwswitch_bit = (unsigned long)data - 1;
 
-       memset(&buffer, 0, sizeof(struct calling_interface_buffer));
-       dell_send_request(&buffer, 17, 11);
-       status = buffer.output[1];
+       get_buffer();
+       dell_send_request(buffer, 17, 11);
+       status = buffer->output[1];
+       release_buffer();
 
        rfkill_set_sw_state(rfkill, !!(status & BIT(bit)));
-       rfkill_set_hw_state(rfkill, !(status & BIT(16)));
+
+       if (hwswitch_state & (BIT(hwswitch_bit)))
+               rfkill_set_hw_state(rfkill, !(status & BIT(16)));
 }
 
 static const struct rfkill_ops dell_rfkill_ops = {
@@ -229,13 +326,22 @@ static DECLARE_DELAYED_WORK(dell_rfkill_work, dell_update_rfkill);
 
 static int __init dell_setup_rfkill(void)
 {
-       struct calling_interface_buffer buffer;
        int status;
        int ret;
 
-       memset(&buffer, 0, sizeof(struct calling_interface_buffer));
-       dell_send_request(&buffer, 17, 11);
-       status = buffer.output[1];
+       if (dmi_check_system(dell_blacklist)) {
+               printk(KERN_INFO "dell-laptop: Blacklisted hardware detected - "
+                               "not enabling rfkill\n");
+               return 0;
+       }
+
+       get_buffer();
+       dell_send_request(buffer, 17, 11);
+       status = buffer->output[1];
+       buffer->input[0] = 0x2;
+       dell_send_request(buffer, 17, 11);
+       hwswitch_state = buffer->output[1];
+       release_buffer();
 
        if ((status & (1<<2|1<<8)) == (1<<2|1<<8)) {
                wifi_rfkill = rfkill_alloc("dell-wifi", &platform_device->dev,
@@ -311,39 +417,49 @@ static void dell_cleanup_rfkill(void)
 
 static int dell_send_intensity(struct backlight_device *bd)
 {
-       struct calling_interface_buffer buffer;
+       int ret = 0;
 
-       memset(&buffer, 0, sizeof(struct calling_interface_buffer));
-       buffer.input[0] = find_token_location(BRIGHTNESS_TOKEN);
-       buffer.input[1] = bd->props.brightness;
+       get_buffer();
+       buffer->input[0] = find_token_location(BRIGHTNESS_TOKEN);
+       buffer->input[1] = bd->props.brightness;
 
-       if (buffer.input[0] == -1)
-               return -ENODEV;
+       if (buffer->input[0] == -1) {
+               ret = -ENODEV;
+               goto out;
+       }
 
        if (power_supply_is_system_supplied() > 0)
-               dell_send_request(&buffer, 1, 2);
+               dell_send_request(buffer, 1, 2);
        else
-               dell_send_request(&buffer, 1, 1);
+               dell_send_request(buffer, 1, 1);
 
+out:
+       release_buffer();
        return 0;
 }
 
 static int dell_get_intensity(struct backlight_device *bd)
 {
-       struct calling_interface_buffer buffer;
+       int ret = 0;
 
-       memset(&buffer, 0, sizeof(struct calling_interface_buffer));
-       buffer.input[0] = find_token_location(BRIGHTNESS_TOKEN);
+       get_buffer();
+       buffer->input[0] = find_token_location(BRIGHTNESS_TOKEN);
 
-       if (buffer.input[0] == -1)
-               return -ENODEV;
+       if (buffer->input[0] == -1) {
+               ret = -ENODEV;
+               goto out;
+       }
 
        if (power_supply_is_system_supplied() > 0)
-               dell_send_request(&buffer, 0, 2);
+               dell_send_request(buffer, 0, 2);
        else
-               dell_send_request(&buffer, 0, 1);
+               dell_send_request(buffer, 0, 1);
 
-       return buffer.output[1];
+out:
+       release_buffer();
+       if (ret)
+               return ret;
+       return buffer->output[1];
 }
 
 static struct backlight_ops dell_ops = {
@@ -377,7 +493,6 @@ bool dell_laptop_i8042_filter(unsigned char data, unsigned char str,
 
 static int __init dell_init(void)
 {
-       struct calling_interface_buffer buffer;
        int max_intensity = 0;
        int ret;
 
@@ -403,6 +518,17 @@ static int __init dell_init(void)
        if (ret)
                goto fail_platform_device2;
 
+       /*
+        * Allocate buffer below 4GB for SMI data--only 32-bit physical addr
+        * is passed to SMI handler.
+        */
+       bufferpage = alloc_page(GFP_KERNEL | GFP_DMA32);
+
+       if (!bufferpage)
+               goto fail_buffer;
+       buffer = page_address(bufferpage);
+       mutex_init(&buffer_mutex);
+
        ret = dell_setup_rfkill();
 
        if (ret) {
@@ -425,19 +551,23 @@ static int __init dell_init(void)
                return 0;
 #endif
 
-       memset(&buffer, 0, sizeof(struct calling_interface_buffer));
-       buffer.input[0] = find_token_location(BRIGHTNESS_TOKEN);
-
-       if (buffer.input[0] != -1) {
-               dell_send_request(&buffer, 0, 2);
-               max_intensity = buffer.output[3];
+       get_buffer();
+       buffer->input[0] = find_token_location(BRIGHTNESS_TOKEN);
+       if (buffer->input[0] != -1) {
+               dell_send_request(buffer, 0, 2);
+               max_intensity = buffer->output[3];
        }
+       release_buffer();
 
        if (max_intensity) {
-               dell_backlight_device = backlight_device_register(
-                       "dell_backlight",
-                       &platform_device->dev, NULL,
-                       &dell_ops);
+               struct backlight_properties props;
+               memset(&props, 0, sizeof(struct backlight_properties));
+               props.max_brightness = max_intensity;
+               dell_backlight_device = backlight_device_register("dell_backlight",
+                                                                 &platform_device->dev,
+                                                                 NULL,
+                                                                 &dell_ops,
+                                                                 &props);
 
                if (IS_ERR(dell_backlight_device)) {
                        ret = PTR_ERR(dell_backlight_device);
@@ -445,7 +575,6 @@ static int __init dell_init(void)
                        goto fail_backlight;
                }
 
-               dell_backlight_device->props.max_brightness = max_intensity;
                dell_backlight_device->props.brightness =
                        dell_get_intensity(dell_backlight_device);
                backlight_update_status(dell_backlight_device);
@@ -455,9 +584,12 @@ static int __init dell_init(void)
 
 fail_backlight:
        i8042_remove_filter(dell_laptop_i8042_filter);
+       cancel_delayed_work_sync(&dell_rfkill_work);
 fail_filter:
        dell_cleanup_rfkill();
 fail_rfkill:
+       free_page((unsigned long)bufferpage);
+fail_buffer:
        platform_device_del(platform_device);
 fail_platform_device2:
        platform_device_put(platform_device);
@@ -470,14 +602,16 @@ fail_platform_driver:
 
 static void __exit dell_exit(void)
 {
-       cancel_delayed_work_sync(&dell_rfkill_work);
        i8042_remove_filter(dell_laptop_i8042_filter);
+       cancel_delayed_work_sync(&dell_rfkill_work);
        backlight_device_unregister(dell_backlight_device);
        dell_cleanup_rfkill();
        if (platform_device) {
-               platform_device_del(platform_device);
+               platform_device_unregister(platform_device);
                platform_driver_unregister(&platform_driver);
        }
+       kfree(da_tokens);
+       free_page((unsigned long)buffer);
 }
 
 module_init(dell_init);
@@ -487,3 +621,4 @@ MODULE_AUTHOR("Matthew Garrett <mjg@redhat.com>");
 MODULE_DESCRIPTION("Dell laptop driver");
 MODULE_LICENSE("GPL");
 MODULE_ALIAS("dmi:*svnDellInc.:*:ct8:*");
+MODULE_ALIAS("dmi:*svnDellComputerCorporation.:*:ct8:*");