CHROMIUM: chromeos_acpi: Enable USB wake from S3
[cascardo/linux.git] / drivers / platform / x86 / chromeos_acpi.c
index 6522464..37afad3 100644 (file)
@@ -37,6 +37,8 @@
 #include <linux/platform_device.h>
 #include <linux/acpi.h>
 
+#include "../chromeos.h"
+
 #define CHNV_DEBUG_RESET_FLAG  0x40         /* flag for S3 reboot */
 #define CHNV_RECOVERY_FLAG     0x80         /* flag for recovery reboot */
 
@@ -188,7 +190,7 @@ int chromeos_legacy_set_need_recovery(void)
  *
  * retrun number of bytes copied, or -1 on any error.
  */
-ssize_t chromeos_vbc_read(void *buf, size_t count)
+static ssize_t chromeos_vbc_nvram_read(void *buf, size_t count)
 {
 
        int base, size, i;
@@ -214,7 +216,7 @@ ssize_t chromeos_vbc_read(void *buf, size_t count)
        return size;
 }
 
-ssize_t chromeos_vbc_write(const void *buf, size_t count)
+static ssize_t chromeos_vbc_nvram_write(const void *buf, size_t count)
 {
        unsigned base, size, i;
 
@@ -440,7 +442,7 @@ static void handle_nested_acpi_package(union acpi_object *po, char *pm,
 
                case ACPI_TYPE_STRING:
                        copy_size = min(element->string.length,
-                                       sizeof(attr_value) - 1);
+                                       (u32)(sizeof(attr_value)) - 1);
                        memcpy(attr_value, element->string.pointer, copy_size);
                        attr_value[copy_size] = '\0';
                        paa = create_sysfs_attribute(attr_value, pm, count, i);
@@ -619,7 +621,7 @@ static void handle_acpi_package(union acpi_object *po, char *pm)
 
                case ACPI_TYPE_STRING:
                        copy_size = min(element->string.length,
-                                       sizeof(attr_value) - 1);
+                                       (u32)(sizeof(attr_value)) - 1);
                        memcpy(attr_value, element->string.pointer, copy_size);
                        attr_value[copy_size] = '\0';
                        add_sysfs_attribute(attr_value, pm, count, j);
@@ -752,13 +754,24 @@ static int chromeos_device_remove(struct acpi_device *device, int type)
        return 0;
 }
 
+static struct chromeos_vbc chromeos_vbc_nvram = {
+       .name = "chromeos_vbc_nvram",
+       .read = chromeos_vbc_nvram_read,
+       .write = chromeos_vbc_nvram_write,
+};
+
 static int __init chromeos_acpi_init(void)
 {
        int ret = 0;
+       acpi_status status;
 
        if (acpi_disabled)
                return -ENODEV;
 
+       ret = chromeos_vbc_register(&chromeos_vbc_nvram);
+       if (ret)
+               return ret;
+
        chromeos_acpi.p_dev = platform_device_register_simple("chromeos_acpi",
                                                              -1, NULL, 0);
        if (IS_ERR(chromeos_acpi.p_dev)) {
@@ -775,6 +788,12 @@ static int __init chromeos_acpi_init(void)
        }
        printk(MY_INFO "installed%s\n",
               chromeos_on_legacy_firmware() ? " (legacy mode)" : "");
+
+       printk(MY_INFO "chromeos_acpi: enabling S3 USB wake\n");
+       status = acpi_evaluate_object(NULL, "\\S3UE", NULL, NULL);
+       if (!ACPI_SUCCESS(status))
+               printk(MY_INFO "chromeos_acpi: failed to enable S3 USB wake\n");
+
        return 0;
 }