ACPI: Schedule /proc/acpi/event for removal
[firefly-linux-kernel-4.4.55.git] / drivers / misc / thinkpad_acpi.c
index 623d36fd8dbeba215a78a35e4a4e4dac66200656..bb8956d0c1047fce4eb35f2323072b8438e59e40 100644 (file)
@@ -21,7 +21,7 @@
  *  02110-1301, USA.
  */
 
-#define IBM_VERSION "0.14"
+#define IBM_VERSION "0.15"
 #define TPACPI_SYSFS_VERSION 0x010000
 
 /*
@@ -411,12 +411,13 @@ static int __init register_tpacpi_subdriver(struct ibm_struct *ibm)
 
        sprintf(ibm->acpi->driver->name, "%s_%s", IBM_NAME, ibm->name);
        ibm->acpi->driver->ids = ibm->acpi->hid;
+
        ibm->acpi->driver->ops.add = &tpacpi_device_add;
 
        rc = acpi_bus_register_driver(ibm->acpi->driver);
        if (rc < 0) {
                printk(IBM_ERR "acpi_bus_register_driver(%s) failed: %d\n",
-                      ibm->acpi->hid, rc);
+                      ibm->name, rc);
                kfree(ibm->acpi->driver);
                ibm->acpi->driver = NULL;
        } else if (!rc)
@@ -1189,10 +1190,10 @@ static void hotkey_notify(struct ibm_struct *ibm, u32 event)
                }
 
                if (sendacpi)
-                       acpi_bus_generate_event(ibm->acpi->device, event, hkey);
+                       acpi_bus_generate_proc_event(ibm->acpi->device, event, hkey);
        } else {
                printk(IBM_ERR "unknown hotkey notification event %d\n", event);
-               acpi_bus_generate_event(ibm->acpi->device, event, 0);
+               acpi_bus_generate_proc_event(ibm->acpi->device, event, 0);
        }
 }
 
@@ -1316,8 +1317,13 @@ errexit:
        return res;
 }
 
+static const struct acpi_device_id ibm_htk_device_ids[] = {
+       {IBM_HKEY_HID, 0},
+       {"", 0},
+};
+
 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver = {
-       .hid = IBM_HKEY_HID,
+       .hid = ibm_htk_device_ids,
        .notify = hotkey_notify,
        .handle = &hkey_handle,
        .type = ACPI_DEVICE_NOTIFY,
@@ -2080,6 +2086,11 @@ IBM_HANDLE(dock, root, "\\_SB.GDCK",     /* X30, X31, X40 */
 /* don't list other alternatives as we install a notify handler on the 570 */
 IBM_HANDLE(pci, root, "\\_SB.PCI");    /* 570 */
 
+static const struct acpi_device_id ibm_pci_device_ids[] = {
+       {PCI_ROOT_HID_STRING, 0},
+       {"", 0},
+};
+
 static struct tp_acpi_drv_struct ibm_dock_acpidriver[2] = {
        {
         .notify = dock_notify,
@@ -2090,7 +2101,7 @@ static struct tp_acpi_drv_struct ibm_dock_acpidriver[2] = {
        /* THIS ONE MUST NEVER BE USED FOR DRIVER AUTOLOADING.
         * We just use it to get notifications of dock hotplug
         * in very old thinkpads */
-        .hid = PCI_ROOT_HID_STRING,
+        .hid = ibm_pci_device_ids,
         .notify = dock_notify,
         .handle = &pci_handle,
         .type = ACPI_SYSTEM_NOTIFY,
@@ -2149,23 +2160,29 @@ static int __init dock_init2(struct ibm_init_struct *iibm)
 static void dock_notify(struct ibm_struct *ibm, u32 event)
 {
        int docked = dock_docked();
-       int pci = ibm->acpi->hid && strstr(ibm->acpi->hid, PCI_ROOT_HID_STRING);
+       int pci = ibm->acpi->hid && ibm->acpi->device &&
+               acpi_match_device_ids(ibm->acpi->device, ibm_pci_device_ids);
+       int data;
 
        if (event == 1 && !pci) /* 570 */
-               acpi_bus_generate_event(ibm->acpi->device, event, 1);   /* button */
+               data = 1;       /* button */
        else if (event == 1 && pci)     /* 570 */
-               acpi_bus_generate_event(ibm->acpi->device, event, 3);   /* dock */
+               data = 3;       /* dock */
        else if (event == 3 && docked)
-               acpi_bus_generate_event(ibm->acpi->device, event, 1);   /* button */
+               data = 1;       /* button */
        else if (event == 3 && !docked)
-               acpi_bus_generate_event(ibm->acpi->device, event, 2);   /* undock */
+               data = 2;       /* undock */
        else if (event == 0 && docked)
-               acpi_bus_generate_event(ibm->acpi->device, event, 3);   /* dock */
+               data = 3;       /* dock */
        else {
                printk(IBM_ERR "unknown dock event %d, status %d\n",
                       event, _sta(dock_handle));
-               acpi_bus_generate_event(ibm->acpi->device, event, 0);   /* unknown */
+               data = 0;       /* unknown */
        }
+       acpi_bus_generate_proc_event(ibm->acpi->device, event, data);
+       acpi_bus_generate_netlink_event(ibm->acpi->device->pnp.device_class,
+                                         ibm->acpi->device->dev.bus_id,
+                                         event, data);
 }
 
 static int dock_read(char *p)
@@ -2263,7 +2280,10 @@ static int __init bay_init(struct ibm_init_struct *iibm)
 
 static void bay_notify(struct ibm_struct *ibm, u32 event)
 {
-       acpi_bus_generate_event(ibm->acpi->device, event, 0);
+       acpi_bus_generate_proc_event(ibm->acpi->device, event, 0);
+       acpi_bus_generate_netlink_event(ibm->acpi->device->pnp.device_class,
+                                         ibm->acpi->device->dev.bus_id,
+                                         event, 0);
 }
 
 #define bay_occupied(b) (_sta(b##_handle) & 1)
@@ -2709,7 +2729,7 @@ static int __init thermal_init(struct ibm_init_struct *iibm)
 
        acpi_tmp7 = acpi_evalf(ec_handle, NULL, "TMP7", "qv");
 
-       if (thinkpad_id.ec_model && experimental) {
+       if (thinkpad_id.ec_model) {
                /*
                 * Direct EC access mode: sensors at registers
                 * 0x78-0x7F, 0xC0-0xC7.  Registers return 0x00 for
@@ -2853,6 +2873,8 @@ static int thermal_get_sensor(int idx, s32 *value)
                        snprintf(tmpi, sizeof(tmpi), "TMP%c", '0' + idx);
                        if (!acpi_evalf(ec_handle, &t, tmpi, "d"))
                                return -EIO;
+                       if (t > 127 || t < -127)
+                               t = TP_EC_THERMAL_TMP_NA;
                        *value = t * 1000;
                        return 0;
                }
@@ -2998,12 +3020,16 @@ static struct backlight_ops ibm_backlight_data = {
         .update_status  = brightness_update_status,
 };
 
+static struct mutex brightness_mutex;
+
 static int __init brightness_init(struct ibm_init_struct *iibm)
 {
        int b;
 
        vdbg_printk(TPACPI_DBG_INIT, "initializing brightness subdriver\n");
 
+       mutex_init(&brightness_mutex);
+
        if (!brightness_mode) {
                if (thinkpad_id.vendor == PCI_VENDOR_ID_LENOVO)
                        brightness_mode = 2;
@@ -3090,27 +3116,44 @@ static int brightness_get(struct backlight_device *bd)
 
 static int brightness_set(int value)
 {
-       int cmos_cmd, inc, i;
-       int current_value = brightness_get(NULL);
+       int cmos_cmd, inc, i, res;
+       int current_value;
 
        if (value > 7)
                return -EINVAL;
 
+       res = mutex_lock_interruptible(&brightness_mutex);
+       if (res < 0)
+               return res;
+
+       current_value = brightness_get(NULL);
+       if (current_value < 0) {
+               res = current_value;
+               goto errout;
+       }
+
        cmos_cmd = value > current_value ?
                        TP_CMOS_BRIGHTNESS_UP :
                        TP_CMOS_BRIGHTNESS_DOWN;
        inc = value > current_value ? 1 : -1;
 
+       res = 0;
        for (i = current_value; i != value; i += inc) {
                if ((brightness_mode & 2) &&
-                   issue_thinkpad_cmos_command(cmos_cmd))
-                       return -EIO;
+                   issue_thinkpad_cmos_command(cmos_cmd)) {
+                       res = -EIO;
+                       goto errout;
+               }
                if ((brightness_mode & 1) &&
-                   !acpi_ec_write(brightness_offset, i + inc))
-                       return -EIO;
+                   !acpi_ec_write(brightness_offset, i + inc)) {
+                       res = -EIO;
+                       goto errout;;
+               }
        }
 
-       return 0;
+errout:
+       mutex_unlock(&brightness_mutex);
+       return res;
 }
 
 static int brightness_read(char *p)
@@ -4633,12 +4676,15 @@ static int __init thinkpad_acpi_module_init(void)
                thinkpad_acpi_module_exit();
                return ret;
        }
+       tp_features.platform_drv_registered = 1;
+
        ret = tpacpi_create_driver_attributes(&tpacpi_pdriver.driver);
        if (ret) {
                printk(IBM_ERR "unable to create sysfs driver attributes\n");
                thinkpad_acpi_module_exit();
                return ret;
        }
+       tp_features.platform_drv_attrs_registered = 1;
 
 
        /* Device initialization */
@@ -4721,8 +4767,11 @@ static void thinkpad_acpi_module_exit(void)
        if (tpacpi_pdev)
                platform_device_unregister(tpacpi_pdev);
 
-       tpacpi_remove_driver_attributes(&tpacpi_pdriver.driver);
-       platform_driver_unregister(&tpacpi_pdriver);
+       if (tp_features.platform_drv_attrs_registered)
+               tpacpi_remove_driver_attributes(&tpacpi_pdriver.driver);
+
+       if (tp_features.platform_drv_registered)
+               platform_driver_unregister(&tpacpi_pdriver);
 
        if (proc_dir)
                remove_proc_entry(IBM_PROC_DIR, acpi_root_dir);