Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 63077eda authored by Amy Maloche's avatar Amy Maloche Committed by Sudhakar Manapati
Browse files

input: synaptics_i2c_rmi4: Add low power mode



Enable regulators to go into low power mode when
device enters suspend, to save power.  In resume,
return regulators to full power.

This patch is propagated from msm-3.4 kernel.
(commit: 827e8b0e09bead9a9d3cb26b2ffd4df0e5cdb16b
input: synaptics_i2c_rmi4: Add low power mode)

Change-Id: I6f5a6d398732b2e23aeba81b3569ae2c081f31e5
Signed-off-by: default avatarAmy Maloche <amaloche@codeaurora.org>
parent 71566426
Loading
Loading
Loading
Loading
+90 −6
Original line number Diff line number Diff line
@@ -103,6 +103,10 @@ static int synaptics_rmi4_i2c_write(struct synaptics_rmi4_data *rmi4_data,

static int synaptics_rmi4_reset_device(struct synaptics_rmi4_data *rmi4_data);

#ifdef CONFIG_PM
static int synaptics_rmi4_suspend(struct device *dev);

static int synaptics_rmi4_resume(struct device *dev);
#ifdef CONFIG_HAS_EARLYSUSPEND
static ssize_t synaptics_rmi4_full_pm_cycle_show(struct device *dev,
		struct device_attribute *attr, char *buf);
@@ -113,10 +117,7 @@ static ssize_t synaptics_rmi4_full_pm_cycle_store(struct device *dev,
static void synaptics_rmi4_early_suspend(struct early_suspend *h);

static void synaptics_rmi4_late_resume(struct early_suspend *h);

static int synaptics_rmi4_suspend(struct device *dev);

static int synaptics_rmi4_resume(struct device *dev);
#endif
#endif

static ssize_t synaptics_rmi4_f01_reset_store(struct device *dev,
@@ -2458,6 +2459,75 @@ static void synaptics_rmi4_late_resume(struct early_suspend *h)
}
#endif

static int synaptics_rmi4_regulator_lpm(struct synaptics_rmi4_data *rmi4_data,
						bool on)
{
	int retval;

	if (on == false)
		goto regulator_hpm;

	retval = reg_set_optimum_mode_check(rmi4_data->vdd, RMI4_LPM_LOAD_UA);
	if (retval < 0) {
		dev_err(&rmi4_data->i2c_client->dev,
			"Regulator vcc_ana set_opt failed rc=%d\n",
			retval);
		goto fail_regulator_lpm;
	}

	if (rmi4_data->board->i2c_pull_up) {
		retval = reg_set_optimum_mode_check(rmi4_data->vcc_i2c,
			RMI4_I2C_LOAD_UA);
		if (retval < 0) {
			dev_err(&rmi4_data->i2c_client->dev,
				"Regulator vcc_i2c set_opt failed rc=%d\n",
				retval);
			goto fail_regulator_lpm;
		}
	}

	return 0;

regulator_hpm:

	retval = reg_set_optimum_mode_check(rmi4_data->vdd,
				RMI4_ACTIVE_LOAD_UA);
	if (retval < 0) {
		dev_err(&rmi4_data->i2c_client->dev,
			"Regulator vcc_ana set_opt failed rc=%d\n",
			retval);
		goto fail_regulator_hpm;
	}

	if (rmi4_data->board->i2c_pull_up) {
		retval = reg_set_optimum_mode_check(rmi4_data->vcc_i2c,
			RMI4_I2C_LOAD_UA);
		if (retval < 0) {
			dev_err(&rmi4_data->i2c_client->dev,
				"Regulator vcc_i2c set_opt failed rc=%d\n",
				retval);
			goto fail_regulator_hpm;
		}
	}

	return 0;

fail_regulator_lpm:
	reg_set_optimum_mode_check(rmi4_data->vdd, RMI4_ACTIVE_LOAD_UA);
	if (rmi4_data->board->i2c_pull_up)
		reg_set_optimum_mode_check(rmi4_data->vcc_i2c,
						RMI4_I2C_LOAD_UA);

	return retval;

fail_regulator_hpm:
	reg_set_optimum_mode_check(rmi4_data->vdd, RMI4_LPM_LOAD_UA);
	if (rmi4_data->board->i2c_pull_up)
		reg_set_optimum_mode_check(rmi4_data->vcc_i2c,
						RMI4_I2C_LPM_LOAD_UA);
	return retval;
}

 /**
 * synaptics_rmi4_suspend()
 *
@@ -2471,6 +2541,7 @@ static void synaptics_rmi4_late_resume(struct early_suspend *h)
static int synaptics_rmi4_suspend(struct device *dev)
{
	struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev);
	int retval;

	if (!rmi4_data->sensor_sleep) {
		rmi4_data->touch_stopped = true;
@@ -2479,6 +2550,12 @@ static int synaptics_rmi4_suspend(struct device *dev)
		synaptics_rmi4_sensor_sleep(rmi4_data);
	}

	retval = synaptics_rmi4_regulator_lpm(rmi4_data, true);
	if (retval < 0) {
		dev_err(dev, "failed to enter low power mode\n");
		return retval;
	}

	return 0;
}

@@ -2495,6 +2572,13 @@ static int synaptics_rmi4_suspend(struct device *dev)
static int synaptics_rmi4_resume(struct device *dev)
{
	struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev);
	int retval;

	retval = synaptics_rmi4_regulator_lpm(rmi4_data, false);
	if (retval < 0) {
		dev_err(dev, "failed to enter active power mode\n");
		return retval;
	}

	synaptics_rmi4_sensor_wake(rmi4_data);
	rmi4_data->touch_stopped = false;