Pull auto-load-modules into release branch
[pandora-kernel.git] / drivers / misc / asus-laptop.c
index 65c32a9..d0fc4fd 100644 (file)
@@ -30,7 +30,7 @@
  *  Eric Burghard  - LED display support for W1N
  *  Josh Green     - Light Sens support
  *  Thomas Tuttle  - His first patch for led support was very helpfull
- *
+ *  Sam Lin        - GPS support
  */
 
 #include <linux/autoconf.h>
 #include <acpi/acpi_bus.h>
 #include <asm/uaccess.h>
 
-#define ASUS_LAPTOP_VERSION "0.41"
+#define ASUS_LAPTOP_VERSION "0.42"
 
 #define ASUS_HOTK_NAME          "Asus Laptop Support"
 #define ASUS_HOTK_CLASS         "hotkey"
 #define ASUS_HOTK_DEVICE_NAME   "Hotkey"
-#define ASUS_HOTK_HID           "ATK0100"
 #define ASUS_HOTK_FILE          "asus-laptop"
 #define ASUS_HOTK_PREFIX        "\\_SB.ATKD."
 
@@ -83,6 +82,7 @@
 #define PLED_ON     0x20       //Phone LED
 #define GLED_ON     0x40       //Gaming LED
 #define LCD_ON      0x80       //LCD backlight
+#define GPS_ON      0x100      //GPS
 
 #define ASUS_LOG    ASUS_HOTK_FILE ": "
 #define ASUS_ERR    KERN_ERR    ASUS_LOG
@@ -148,7 +148,7 @@ ASUS_HANDLE(display_set, ASUS_HOTK_PREFIX "SDSP");
 ASUS_HANDLE(display_get, "\\_SB.PCI0.P0P1.VGA.GETD",   /*  A6B, A6K A6R A7D F3JM L4R M6R A3G
                                                           M6A M6V VX-1 V6J V6V W3Z */
            "\\_SB.PCI0.P0P2.VGA.GETD", /* A3E A4K, A4D A4L A6J A7J A8J Z71V M9V
-                                          S5A M5A z33A W1Jc W2V */
+                                          S5A M5A z33A W1Jc W2V G1 */
            "\\_SB.PCI0.P0P3.VGA.GETD", /* A6V A6Q */
            "\\_SB.PCI0.P0PA.VGA.GETD", /* A6T, A6M */
            "\\_SB.PCI0.PCI1.VGAC.NMAP",        /* L3C */
@@ -162,6 +162,12 @@ ASUS_HANDLE(display_get, "\\_SB.PCI0.P0P1.VGA.GETD",       /*  A6B, A6K A6R A7D F3JM L
 ASUS_HANDLE(ls_switch, ASUS_HOTK_PREFIX "ALSC");       /* Z71A Z71V */
 ASUS_HANDLE(ls_level, ASUS_HOTK_PREFIX "ALSL");        /* Z71A Z71V */
 
+/* GPS */
+/* R2H use different handle for GPS on/off */
+ASUS_HANDLE(gps_on, ASUS_HOTK_PREFIX "SDON");  /* R2H */
+ASUS_HANDLE(gps_off, ASUS_HOTK_PREFIX "SDOF"); /* R2H */
+ASUS_HANDLE(gps_status, ASUS_HOTK_PREFIX "GPST");
+
 /*
  * This is the main structure, we can use it to store anything interesting
  * about the hotk device
@@ -190,12 +196,18 @@ static struct asus_hotk *hotk;
 /*
  * The hotkey driver declaration
  */
+static const struct acpi_device_id asus_device_ids[] = {
+       {"ATK0100", 0},
+       {"", 0},
+};
+MODULE_DEVICE_TABLE(acpi, asus_device_ids);
+
 static int asus_hotk_add(struct acpi_device *device);
 static int asus_hotk_remove(struct acpi_device *device, int type);
 static struct acpi_driver asus_hotk_driver = {
        .name = ASUS_HOTK_NAME,
        .class = ASUS_HOTK_CLASS,
-       .ids = ASUS_HOTK_HID,
+       .ids = asus_device_ids,
        .ops = {
                .add = asus_hotk_add,
                .remove = asus_hotk_remove,
@@ -278,12 +290,28 @@ static int read_wireless_status(int mask)
        return (hotk->status & mask) ? 1 : 0;
 }
 
+static int read_gps_status(void)
+{
+       ulong status;
+       acpi_status rv = AE_OK;
+
+       rv = acpi_evaluate_integer(gps_status_handle, NULL, NULL, &status);
+       if (ACPI_FAILURE(rv))
+               printk(ASUS_WARNING "Error reading GPS status\n");
+       else
+               return status ? 1 : 0;
+
+       return (hotk->status & GPS_ON) ? 1 : 0;
+}
+
 /* Generic LED functions */
 static int read_status(int mask)
 {
        /* There is a special method for both wireless devices */
        if (mask == BT_ON || mask == WL_ON)
                return read_wireless_status(mask);
+       else if (mask == GPS_ON)
+               return read_gps_status();
 
        return (hotk->status & mask) ? 1 : 0;
 }
@@ -299,6 +327,10 @@ static void write_status(acpi_handle handle, int out, int mask)
        case GLED_ON:
                out = (out & 0x1) + 1;
                break;
+       case GPS_ON:
+               handle = (out) ? gps_on_handle : gps_off_handle;
+               out = 0x02;
+               break;
        default:
                out &= 0x1;
                break;
@@ -667,6 +699,21 @@ static ssize_t store_lslvl(struct device *dev, struct device_attribute *attr,
        return rv;
 }
 
+/*
+ * GPS
+ */
+static ssize_t show_gps(struct device *dev,
+                       struct device_attribute *attr, char *buf)
+{
+       return sprintf(buf, "%d\n", read_status(GPS_ON));
+}
+
+static ssize_t store_gps(struct device *dev, struct device_attribute *attr,
+                        const char *buf, size_t count)
+{
+       return store_status(buf, count, NULL, GPS_ON);
+}
+
 static void asus_hotk_notify(acpi_handle handle, u32 event, void *data)
 {
        /* TODO Find a better way to handle events count. */
@@ -695,8 +742,7 @@ static void asus_hotk_notify(acpi_handle handle, u32 event, void *data)
        struct device_attribute dev_attr_##_name = {                    \
                .attr = {                                               \
                        .name = __stringify(_name),                     \
-                       .mode = 0,                                      \
-                       .owner = THIS_MODULE },                         \
+                       .mode = 0 },                                    \
                .show   = NULL,                                         \
                .store  = NULL,                                         \
        }
@@ -715,6 +761,7 @@ static ASUS_CREATE_DEVICE_ATTR(display);
 static ASUS_CREATE_DEVICE_ATTR(ledd);
 static ASUS_CREATE_DEVICE_ATTR(ls_switch);
 static ASUS_CREATE_DEVICE_ATTR(ls_level);
+static ASUS_CREATE_DEVICE_ATTR(gps);
 
 static struct attribute *asuspf_attributes[] = {
        &dev_attr_infos.attr,
@@ -724,6 +771,7 @@ static struct attribute *asuspf_attributes[] = {
        &dev_attr_ledd.attr,
        &dev_attr_ls_switch.attr,
        &dev_attr_ls_level.attr,
+       &dev_attr_gps.attr,
        NULL
 };
 
@@ -763,6 +811,9 @@ static void asus_hotk_add_fs(void)
                ASUS_SET_DEVICE_ATTR(ls_level, 0644, show_lslvl, store_lslvl);
                ASUS_SET_DEVICE_ATTR(ls_switch, 0644, show_lssw, store_lssw);
        }
+
+       if (gps_status_handle && gps_on_handle && gps_off_handle)
+               ASUS_SET_DEVICE_ATTR(gps, 0644, show_gps, store_gps);
 }
 
 static int asus_handle_init(char *name, acpi_handle * handle,
@@ -890,9 +941,13 @@ static int asus_hotk_get_info(void)
 
        /* There is a lot of models with "ALSL", but a few get
           a real light sens, so we need to check it. */
-       if (ASUS_HANDLE_INIT(ls_switch))
+       if (!ASUS_HANDLE_INIT(ls_switch))
                ASUS_HANDLE_INIT(ls_level);
 
+       ASUS_HANDLE_INIT(gps_on);
+       ASUS_HANDLE_INIT(gps_off);
+       ASUS_HANDLE_INIT(gps_status);
+
        kfree(model);
 
        return AE_OK;
@@ -929,10 +984,9 @@ static int asus_hotk_add(struct acpi_device *device)
        printk(ASUS_NOTICE "Asus Laptop Support version %s\n",
               ASUS_LAPTOP_VERSION);
 
-       hotk = kmalloc(sizeof(struct asus_hotk), GFP_KERNEL);
+       hotk = kzalloc(sizeof(struct asus_hotk), GFP_KERNEL);
        if (!hotk)
                return -ENOMEM;
-       memset(hotk, 0, sizeof(struct asus_hotk));
 
        hotk->handle = device->handle;
        strcpy(acpi_device_name(device), ASUS_HOTK_DEVICE_NAME);
@@ -950,7 +1004,7 @@ static int asus_hotk_add(struct acpi_device *device)
         * We install the handler, it will receive the hotk in parameter, so, we
         * could add other data to the hotk struct
         */
-       status = acpi_install_notify_handler(hotk->handle, ACPI_SYSTEM_NOTIFY,
+       status = acpi_install_notify_handler(hotk->handle, ACPI_ALL_NOTIFY,
                                             asus_hotk_notify, hotk);
        if (ACPI_FAILURE(status))
                printk(ASUS_ERR "Error installing notify handler\n");
@@ -981,6 +1035,9 @@ static int asus_hotk_add(struct acpi_device *device)
        if (ls_level_handle)
                set_light_sens_level(hotk->light_level);
 
+       /* GPS is on by default */
+       write_status(NULL, 1, GPS_ON);
+
       end:
        if (result) {
                kfree(hotk->name);
@@ -997,7 +1054,7 @@ static int asus_hotk_remove(struct acpi_device *device, int type)
        if (!device || !acpi_driver_data(device))
                return -EINVAL;
 
-       status = acpi_remove_notify_handler(hotk->handle, ACPI_SYSTEM_NOTIFY,
+       status = acpi_remove_notify_handler(hotk->handle, ACPI_ALL_NOTIFY,
                                            asus_hotk_notify);
        if (ACPI_FAILURE(status))
                printk(ASUS_ERR "Error removing notify handler\n");
@@ -1015,19 +1072,16 @@ static void asus_backlight_exit(void)
 }
 
 #define  ASUS_LED_UNREGISTER(object)                           \
-       if(object##_led.class_dev                               \
-          && !IS_ERR(object##_led.class_dev))                  \
-               led_classdev_unregister(&object##_led)
+       led_classdev_unregister(&object##_led)
 
 static void asus_led_exit(void)
 {
+       destroy_workqueue(led_workqueue);
        ASUS_LED_UNREGISTER(mled);
        ASUS_LED_UNREGISTER(tled);
        ASUS_LED_UNREGISTER(pled);
        ASUS_LED_UNREGISTER(rled);
        ASUS_LED_UNREGISTER(gled);
-
-       destroy_workqueue(led_workqueue);
 }
 
 static void __exit asus_laptop_exit(void)
@@ -1083,29 +1137,42 @@ static int asus_led_init(struct device *dev)
 
        rv = ASUS_LED_REGISTER(mled, dev);
        if (rv)
-               return rv;
+               goto out;
 
        rv = ASUS_LED_REGISTER(tled, dev);
        if (rv)
-               return rv;
+               goto out1;
 
        rv = ASUS_LED_REGISTER(rled, dev);
        if (rv)
-               return rv;
+               goto out2;
 
        rv = ASUS_LED_REGISTER(pled, dev);
        if (rv)
-               return rv;
+               goto out3;
 
        rv = ASUS_LED_REGISTER(gled, dev);
        if (rv)
-               return rv;
+               goto out4;
 
        led_workqueue = create_singlethread_workqueue("led_workqueue");
        if (!led_workqueue)
-               return -ENOMEM;
+               goto out5;
 
        return 0;
+out5:
+       rv = -ENOMEM;
+       ASUS_LED_UNREGISTER(gled);
+out4:
+       ASUS_LED_UNREGISTER(pled);
+out3:
+       ASUS_LED_UNREGISTER(rled);
+out2:
+       ASUS_LED_UNREGISTER(tled);
+out1:
+       ASUS_LED_UNREGISTER(mled);
+out:
+       return rv;
 }
 
 static int __init asus_laptop_init(void)