Merge branches 'for-4.13/multitouch', 'for-4.13/retrode', 'for-4.13/transport-open...
[platform/kernel/linux-rpi.git] / drivers / hid / i2c-hid / i2c-hid.c
index 8daa8ce..1c8a026 100644 (file)
@@ -40,7 +40,7 @@
 #include <linux/of.h>
 #include <linux/regulator/consumer.h>
 
-#include <linux/i2c/i2c-hid.h>
+#include <linux/platform_data/i2c-hid.h>
 
 #include "../hid-ids.h"
 
@@ -743,18 +743,12 @@ static int i2c_hid_open(struct hid_device *hid)
        struct i2c_hid *ihid = i2c_get_clientdata(client);
        int ret = 0;
 
-       mutex_lock(&i2c_hid_open_mut);
-       if (!hid->open++) {
-               ret = pm_runtime_get_sync(&client->dev);
-               if (ret < 0) {
-                       hid->open--;
-                       goto done;
-               }
-               set_bit(I2C_HID_STARTED, &ihid->flags);
-       }
-done:
-       mutex_unlock(&i2c_hid_open_mut);
-       return ret < 0 ? ret : 0;
+       ret = pm_runtime_get_sync(&client->dev);
+       if (ret < 0)
+               return ret;
+
+       set_bit(I2C_HID_STARTED, &ihid->flags);
+       return 0;
 }
 
 static void i2c_hid_close(struct hid_device *hid)
@@ -762,18 +756,10 @@ static void i2c_hid_close(struct hid_device *hid)
        struct i2c_client *client = hid->driver_data;
        struct i2c_hid *ihid = i2c_get_clientdata(client);
 
-       /* protecting hid->open to make sure we don't restart
-        * data acquistion due to a resumption we no longer
-        * care about
-        */
-       mutex_lock(&i2c_hid_open_mut);
-       if (!--hid->open) {
-               clear_bit(I2C_HID_STARTED, &ihid->flags);
+       clear_bit(I2C_HID_STARTED, &ihid->flags);
 
-               /* Save some power */
-               pm_runtime_put(&client->dev);
-       }
-       mutex_unlock(&i2c_hid_open_mut);
+       /* Save some power */
+       pm_runtime_put(&client->dev);
 }
 
 static int i2c_hid_power(struct hid_device *hid, int lvl)
@@ -897,6 +883,15 @@ static int i2c_hid_acpi_pdata(struct i2c_client *client,
        return 0;
 }
 
+static void i2c_hid_acpi_fix_up_power(struct device *dev)
+{
+       acpi_handle handle = ACPI_HANDLE(dev);
+       struct acpi_device *adev;
+
+       if (handle && acpi_bus_get_device(handle, &adev) == 0)
+               acpi_device_fix_up_power(adev);
+}
+
 static const struct acpi_device_id i2c_hid_acpi_match[] = {
        {"ACPI0C50", 0 },
        {"PNP0C50", 0 },
@@ -909,6 +904,8 @@ static inline int i2c_hid_acpi_pdata(struct i2c_client *client,
 {
        return -ENODEV;
 }
+
+static inline void i2c_hid_acpi_fix_up_power(struct device *dev) {}
 #endif
 
 #ifdef CONFIG_OF
@@ -1030,6 +1027,8 @@ static int i2c_hid_probe(struct i2c_client *client,
        if (ret < 0)
                goto err_regulator;
 
+       i2c_hid_acpi_fix_up_power(&client->dev);
+
        pm_runtime_get_noresume(&client->dev);
        pm_runtime_set_active(&client->dev);
        pm_runtime_enable(&client->dev);