input: sensor: add power control in sensor enable sysfs for mpu3050

Add the sensor power management in the enable sysfs interface,
through which the HAL layer could enable/disable the sensor.

Change-Id: I68d77a5085e2d80deedb273f0ff1e0d5664ba71c
Signed-off-by: Xiaocheng Li <lix@codeaurora.org>
diff --git a/drivers/input/misc/mpu3050.c b/drivers/input/misc/mpu3050.c
index 519b7e4..ded2b6e 100644
--- a/drivers/input/misc/mpu3050.c
+++ b/drivers/input/misc/mpu3050.c
@@ -302,9 +302,6 @@
 
 /**
  *  Set/get enable function is just needed by sensor HAL.
- *  Normally, the open function does all the initialization
- *  and power work. And close undo that open does.
- *  Just keeping the function simple.
  */
 
 static ssize_t mpu3050_attr_set_enable(struct device *dev,
@@ -316,8 +313,25 @@
 
 	if (kstrtoul(buf, 10, &val))
 		return -EINVAL;
-	sensor->enable = (u32)val;
-
+	sensor->enable = (u32)val == 0 ? 0 : 1;
+	if (sensor->enable) {
+		pm_runtime_get_sync(sensor->dev);
+		gpio_set_value(sensor->enable_gpio, 1);
+		if (sensor->use_poll)
+			schedule_delayed_work(&sensor->input_work,
+				msecs_to_jiffies(sensor->poll_interval));
+		else
+			i2c_smbus_write_byte_data(sensor->client,
+					MPU3050_INT_CFG,
+					MPU3050_ACTIVE_LOW |
+					MPU3050_OPEN_DRAIN |
+					MPU3050_RAW_RDY_EN);
+	} else {
+		if (sensor->use_poll)
+			cancel_delayed_work_sync(&sensor->input_work);
+		gpio_set_value(sensor->enable_gpio, 0);
+		pm_runtime_put(sensor->dev);
+	}
 	return count;
 }
 
@@ -792,14 +806,8 @@
 		goto err_input_cleanup;
 	}
 
-	if (sensor->use_poll)
-		schedule_delayed_work(&sensor->input_work,
-				msecs_to_jiffies(sensor->poll_interval));
-	else
-		i2c_smbus_write_byte_data(sensor->client, MPU3050_INT_CFG,
-				MPU3050_ACTIVE_LOW |
-				MPU3050_OPEN_DRAIN |
-				MPU3050_RAW_RDY_EN);
+	pm_runtime_enable(&client->dev);
+	pm_runtime_set_autosuspend_delay(&client->dev, MPU3050_AUTO_DELAY);
 
 	return 0;