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

Commit cf29d5ea authored by Shantanu Jain's avatar Shantanu Jain Committed by Abinaya P
Browse files

input: touchscreen: Add debugfs support for suspend/resume.



Add debugfs entry for suspend/resume that allow suspending/
resuming of Goodix CTP driver from userspace. Also change
the return type of goodix_ts_resume and goodix_ts_suspend
functions and set the status of gtp_is_suspended in the last
of above functions.

Change-Id: Ic2b1b2562b63ccecdf15bdc64ad7e45996d196d3
Signed-off-by: default avatarShantanu Jain <shjain@codeaurora.org>
parent 740bb381
Loading
Loading
Loading
Loading
+78 −5
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@
#include <linux/irq.h>
#include <linux/module.h>
#include <linux/input/mt.h>
#include <linux/debugfs.h>

#define GOODIX_DEV_NAME	"Goodix-CTP"
#define CFG_MAX_TOUCH_POINTS	5
@@ -84,6 +85,8 @@ static int goodix_power_on(struct goodix_ts_data *ts);
#if defined(CONFIG_FB)
static int fb_notifier_callback(struct notifier_block *self,
				unsigned long event, void *data);
static int goodix_ts_suspend(struct device *dev);
static int goodix_ts_resume(struct device *dev);
#elif defined(CONFIG_HAS_EARLYSUSPEND)
static void goodix_ts_early_suspend(struct early_suspend *h);
static void goodix_ts_late_resume(struct early_suspend *h);
@@ -110,6 +113,9 @@ static u8 chip_gt9xxs; /* true if ic is gt9xxs, like gt915s */
u8 grp_cfg_version;
struct i2c_client  *i2c_connect_client;

#define GTP_DEBUGFS_DIR			"ts_debug"
#define GTP_DEBUGFS_FILE_SUSPEND	"suspend"

/*******************************************************
Function:
	Read data from the i2c slave device.
@@ -1556,6 +1562,56 @@ static const struct attribute_group gtp_attr_grp = {
	.attrs = gtp_attrs,
};

static int gtp_debug_suspend_set(void *_data, u64 val)
{
	struct goodix_ts_data *ts = _data;

	mutex_lock(&ts->input_dev->mutex);
	if (val)
		goodix_ts_suspend(&ts->client->dev);
	else
		goodix_ts_resume(&ts->client->dev);
	mutex_unlock(&ts->input_dev->mutex);

	return 0;
}

static int gtp_debug_suspend_get(void *_data, u64 *val)
{
	struct goodix_ts_data *ts = _data;

	mutex_lock(&ts->input_dev->mutex);
	*val = ts->gtp_is_suspend;
	mutex_unlock(&ts->input_dev->mutex);

	return 0;
}

DEFINE_SIMPLE_ATTRIBUTE(debug_suspend_fops, gtp_debug_suspend_get,
			gtp_debug_suspend_set, "%lld\n");

static int gtp_debugfs_init(struct goodix_ts_data *data)
{
	data->debug_base = debugfs_create_dir(GTP_DEBUGFS_DIR, NULL);

	if (IS_ERR_OR_NULL(data->debug_base)) {
		pr_err("Failed to create debugfs dir\n");
			return -EINVAL;
	}

	if ((IS_ERR_OR_NULL(debugfs_create_file(GTP_DEBUGFS_FILE_SUSPEND,
					S_IWUSR | S_IWGRP | S_IRUSR | S_IRGRP,
					data->debug_base,
					data,
					&debug_suspend_fops)))) {
		pr_err("Failed to create suspend file\n");
		debugfs_remove_recursive(data->debug_base);
		return -EINVAL;
	}

	return 0;
}

static int goodix_ts_get_dt_coords(struct device *dev, char *name,
				struct goodix_ts_platform_data *pdata)
{
@@ -1860,6 +1916,10 @@ static int goodix_ts_probe(struct i2c_client *client,
		goto exit_free_irq;
	}

	ret = gtp_debugfs_init(ts);
	if (ret != 0)
		goto exit_remove_sysfs;

	init_done = true;
	return 0;
exit_free_irq:
@@ -1884,6 +1944,8 @@ exit_free_irq:
		input_free_device(ts->input_dev);
		ts->input_dev = NULL;
	}
exit_remove_sysfs:
	sysfs_remove_group(&ts->input_dev->dev.kobj, &gtp_attr_grp);
exit_free_inputdev:
	kfree(ts->config_data);
exit_power_off:
@@ -1958,6 +2020,7 @@ static int goodix_ts_remove(struct i2c_client *client)
		goodix_power_deinit(ts);
		i2c_set_clientdata(client, NULL);
	}
	debugfs_remove_recursive(ts->debug_base);

	return 0;
}
@@ -1976,9 +2039,13 @@ static int goodix_ts_suspend(struct device *dev)
	struct goodix_ts_data *ts = dev_get_drvdata(dev);
	int ret = 0, i;

	if (ts->gtp_is_suspend) {
		dev_dbg(&ts->client->dev, "Already in suspend state\n");
		return 0;
	}

	mutex_lock(&ts->lock);
#if GTP_ESD_PROTECT
	ts->gtp_is_suspend = 1;
	gtp_esd_switch(ts->client, SWITCH_OFF);
#endif

@@ -1998,12 +2065,13 @@ static int goodix_ts_suspend(struct device *dev)
	ret = gtp_enter_sleep(ts);
#endif
	if (ret <= 0)
		dev_err(&ts->client->dev, "GTP early suspend failed.\n");
		dev_err(&ts->client->dev, "GTP early suspend failed\n");
	/* to avoid waking up while not sleeping,
	 * delay 48 + 10ms to ensure reliability
	 */
	msleep(58);
	mutex_unlock(&ts->lock);
	ts->gtp_is_suspend = 1;

	return ret;
}
@@ -2021,6 +2089,11 @@ static int goodix_ts_resume(struct device *dev)
	struct goodix_ts_data *ts = dev_get_drvdata(dev);
	int ret = 0;

	if (!ts->gtp_is_suspend) {
		dev_dbg(&ts->client->dev, "Already in awake state\n");
		return 0;
	}

	mutex_lock(&ts->lock);
	ret = gtp_wakeup_sleep(ts);

@@ -2029,7 +2102,7 @@ static int goodix_ts_resume(struct device *dev)
#endif

	if (ret <= 0)
		dev_err(&ts->client->dev, "GTP resume failed.\n");
		dev_err(&ts->client->dev, "GTP resume failed\n");

	if (ts->use_irq)
		gtp_irq_enable(ts);
@@ -2038,10 +2111,10 @@ static int goodix_ts_resume(struct device *dev)
			ktime_set(1, 0), HRTIMER_MODE_REL);

#if GTP_ESD_PROTECT
	ts->gtp_is_suspend = 0;
	gtp_esd_switch(ts->client, SWITCH_ON);
#endif
	mutex_unlock(&ts->lock);
	ts->gtp_is_suspend = 0;

	return ret;
}
+1 −0
Original line number Diff line number Diff line
@@ -96,6 +96,7 @@ struct goodix_ts_data {
#elif defined(CONFIG_HAS_EARLYSUSPEND)
	struct early_suspend early_suspend;
#endif
	struct dentry *debug_base;
};

extern u16 show_len;