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

Commit 37e98e10 authored by Sudhakar Manapati's avatar Sudhakar Manapati
Browse files

input: synaptics: secure touch support



Add secure touch support to the synaptics RMI4 and DSX drivers.
Expose the new interface through sysfs, to enable/disable
secure touch, and to wait for touch events.

When secure touch is active, interrupts are forwarded via sysfs
to a listening layer in userspace and processed in TrustZone.
Secure touch is aborted on power events.

This patch is propagated from msm-3.10 kernel
(commit: f5e0a47f2e6bca2f1f0ba4114a6ea94725430a8b
input: synaptics: secure touch support)
Also cleaned copyright error on msm-3.18 kernel.

Change-Id: If4c6b76d020ef061338378a8737702cec7bada33
Acked-by: default avatarChristian Bolis <cbolis@qti.qualcomm.com>
Signed-off-by: default avatarKeith Fallows <keithf@codeaurora.org>
Signed-off-by: default avatarSudhakar Manapati <smanap@codeaurora.org>
parent fc66e37e
Loading
Loading
Loading
Loading
+216 −7
Original line number Diff line number Diff line
@@ -30,6 +30,13 @@
#include <linux/pinctrl/consumer.h>
#include <linux/input/synaptics_dsx.h>
#include <linux/of_gpio.h>

#if defined(CONFIG_SECURE_TOUCH)
#include <linux/pm_runtime.h>
#include <linux/errno.h>
#include <asm/system.h>
#endif

#include "synaptics_i2c_rmi4.h"
#include <linux/input/mt.h>

@@ -185,6 +192,20 @@ static int synaptics_rmi4_capacitance_button_map(
				struct synaptics_rmi4_data *rmi4_data,
				struct synaptics_rmi4_fn *fhandler);


static irqreturn_t synaptics_rmi4_irq(int irq, void *data);

#if defined(CONFIG_SECURE_TOUCH)
static ssize_t synaptics_secure_touch_enable_show(struct device *dev,
		struct device_attribute *attr, char *buf);

static ssize_t synaptics_secure_touch_enable_store(struct device *dev,
		struct device_attribute *attr, const char *buf, size_t count);

static ssize_t synaptics_secure_touch_show(struct device *dev,
	    struct device_attribute *attr, char *buf);
#endif

struct synaptics_rmi4_f01_device_status {
	union {
		struct {
@@ -433,12 +454,181 @@ static struct device_attribute attrs[] = {
	__ATTR(flipy, (S_IRUGO | S_IWUSR | S_IWGRP),
			synaptics_rmi4_flipy_show,
			synaptics_rmi4_flipy_store),
#if defined(CONFIG_SECURE_TOUCH)
	__ATTR(secure_touch_enable, (S_IRUGO | S_IWUGO),
			synaptics_secure_touch_enable_show,
			synaptics_secure_touch_enable_store),
	__ATTR(secure_touch, S_IRUGO ,
			synaptics_secure_touch_show,
			NULL),
#endif
};

static bool exp_fn_inited;
static struct mutex exp_fn_list_mutex;
static struct list_head exp_fn_list;

#if defined(CONFIG_SECURE_TOUCH)
static void synaptics_secure_touch_init(struct synaptics_rmi4_data *data)
{
	init_completion(&data->st_powerdown);
	init_completion(&data->st_irq_processed);
}
static void synaptics_secure_touch_notify(struct synaptics_rmi4_data *data)
{
	sysfs_notify(&data->i2c_client->dev.kobj, NULL, "secure_touch");
}
static irqreturn_t synaptics_filter_interrupt(struct synaptics_rmi4_data *data)
{
	if (atomic_read(&data->st_enabled)) {
		if (atomic_cmpxchg(&data->st_pending_irqs, 0, 1) == 0) {
			synaptics_secure_touch_notify(data);
			wait_for_completion_interruptible(
				&data->st_irq_processed);
		}
		return IRQ_HANDLED;
	}
	return IRQ_NONE;
}
static void synaptics_secure_touch_stop(
	struct synaptics_rmi4_data *data,
	int blocking)
{
	if (atomic_read(&data->st_enabled)) {
		atomic_set(&data->st_pending_irqs, -1);
		synaptics_secure_touch_notify(data);
		if (blocking)
			wait_for_completion_interruptible(&data->st_powerdown);
	}
}
#else
static void synaptics_secure_touch_init(struct synaptics_rmi4_data *data)
{
}
static irqreturn_t synaptics_filter_interrupt(struct synaptics_rmi4_data *data)
{
	return IRQ_NONE;
}
static void synaptics_secure_touch_stop(
	struct synaptics_rmi4_data *data,
	int blocking)
{
}
#endif

#if defined(CONFIG_SECURE_TOUCH)
static ssize_t synaptics_secure_touch_enable_show(struct device *dev,
				    struct device_attribute *attr, char *buf)
{
	struct synaptics_rmi4_data *data = dev_get_drvdata(dev);

	return scnprintf(buf, PAGE_SIZE, "%d", atomic_read(&data->st_enabled));
}
/*
 * Accept only "0" and "1" valid values.
 * "0" will reset the st_enabled flag, then wake up the reading process and
 * the interrupt handler.
 * The bus driver is notified via pm_runtime that it is not required to stay
 * awake anymore.
 * It will also make sure the queue of events is emptied in the controller,
 * in case a touch happened in between the secure touch being disabled and
 * the local ISR being ungated.
 * "1" will set the st_enabled flag and clear the st_pending_irqs flag.
 * The bus driver is requested via pm_runtime to stay awake.
 */
static ssize_t synaptics_secure_touch_enable_store(struct device *dev,
				    struct device_attribute *attr,
				    const char *buf, size_t count)
{
	struct synaptics_rmi4_data *data = dev_get_drvdata(dev);
	unsigned long value;
	int err = 0;

	if (count > 2)
		return -EINVAL;

	err = kstrtoul(buf, 10, &value);
	if (err != 0)
		return err;

	err = count;

	switch (value) {
	case 0:
		if (atomic_read(&data->st_enabled) == 0)
			break;

		pm_runtime_put_sync(data->i2c_client->adapter->dev.parent);
		atomic_set(&data->st_enabled, 0);
		synaptics_secure_touch_notify(data);
		complete(&data->st_irq_processed);
		synaptics_rmi4_irq(data->irq, data);
		complete(&data->st_powerdown);

		break;
	case 1:
		if (atomic_read(&data->st_enabled)) {
			err = -EBUSY;
			break;
		}

		synchronize_irq(data->irq);

		if (pm_runtime_get_sync(
			data->i2c_client->adapter->dev.parent) < 0) {
			dev_err(&data->i2c_client->dev,
				"pm_runtime_get failed\n");
			err = -EIO;
			break;
		}
		INIT_COMPLETION(data->st_powerdown);
		INIT_COMPLETION(data->st_irq_processed);
		atomic_set(&data->st_enabled, 1);
		atomic_set(&data->st_pending_irqs,  0);
		break;
	default:
		dev_err(&data->i2c_client->dev,
			"unsupported value: %lu\n", value);
		err = -EINVAL;
		break;
	}
	return err;
}

/*
 * This function returns whether there are pending interrupts, or
 * other error conditions that need to be signaled to the userspace library,
 * according tot he following logic:
 * - st_enabled is 0 if secure touch is not enabled, returning -EBADF
 * - st_pending_irqs is -1 to signal that secure touch is in being stopped,
 *   returning -EINVAL
 * - st_pending_irqs is 1 to signal that there is a pending irq, returning
 *   the value "1" to the sysfs read operation
 * - st_pending_irqs is 0 (only remaining case left) if the pending interrupt
 *   has been processed, so the interrupt handler can be allowed to continue.
 */
static ssize_t synaptics_secure_touch_show(struct device *dev,
				    struct device_attribute *attr, char *buf)
{
	struct synaptics_rmi4_data *data = dev_get_drvdata(dev);
	int val = 0;

	if (atomic_read(&data->st_enabled) == 0)
		return -EBADF;

	if (atomic_cmpxchg(&data->st_pending_irqs, -1, 0) == -1)
		return -EINVAL;

	if (atomic_cmpxchg(&data->st_pending_irqs, 1, 0) == 1)
		val = 1;
	else
		complete(&data->st_irq_processed);

	return scnprintf(buf, PAGE_SIZE, "%u", val);

}
#endif

static int synaptics_rmi4_debug_suspend_set(void *_data, u64 val)
{
	struct synaptics_rmi4_data *rmi4_data = _data;
@@ -1365,6 +1555,9 @@ static irqreturn_t synaptics_rmi4_irq(int irq, void *data)
{
	struct synaptics_rmi4_data *rmi4_data = data;

	if (IRQ_HANDLED == synaptics_filter_interrupt(data))
		return IRQ_HANDLED;

	synaptics_rmi4_sensor_report(rmi4_data);

	return IRQ_HANDLED;
@@ -3396,6 +3589,9 @@ static int synaptics_rmi4_probe(struct i2c_client *client,
		goto err_sysfs;
	}

	synaptics_secure_touch_init(rmi4_data);
	synaptics_secure_touch_stop(rmi4_data, 1);

	retval = synaptics_rmi4_check_configuration(rmi4_data);
	if (retval < 0) {
		dev_err(&client->dev, "Failed to check configuration\n");
@@ -3627,13 +3823,18 @@ static int fb_notifier_callback(struct notifier_block *self,
	struct synaptics_rmi4_data *rmi4_data =
		container_of(self, struct synaptics_rmi4_data, fb_notif);

	if (evdata && evdata->data && event == FB_EVENT_BLANK &&
		rmi4_data && rmi4_data->i2c_client) {
	if (evdata && evdata->data && rmi4_data && rmi4_data->i2c_client) {
		if (event == FB_EARLY_EVENT_BLANK)
			synaptics_secure_touch_stop(rmi4_data, 0);
		else if (event == FB_EVENT_BLANK) {
			blank = evdata->data;
			if (*blank == FB_BLANK_UNBLANK)
			synaptics_rmi4_resume(&(rmi4_data->input_dev->dev));
				synaptics_rmi4_resume(
					&(rmi4_data->input_dev->dev));
			else if (*blank == FB_BLANK_POWERDOWN)
			synaptics_rmi4_suspend(&(rmi4_data->input_dev->dev));
				synaptics_rmi4_suspend(
					&(rmi4_data->input_dev->dev));
		}
	}

	return 0;
@@ -3659,6 +3860,8 @@ static void synaptics_rmi4_early_suspend(struct early_suspend *h)
	else
		rmi4_data->staying_awake = false;

	synaptics_secure_touch_stop(rmi4_data, 0);

	rmi4_data->touch_stopped = true;
	wake_up(&rmi4_data->wait);
	synaptics_rmi4_irq_enable(rmi4_data, false);
@@ -3686,6 +3889,8 @@ static void synaptics_rmi4_late_resume(struct early_suspend *h)
	if (rmi4_data->staying_awake)
		return;

	synaptics_secure_touch_stop(rmi4_data, 0);

	if (rmi4_data->full_pm_cycle)
		synaptics_rmi4_resume(&(rmi4_data->input_dev->dev));

@@ -3885,6 +4090,8 @@ static int synaptics_rmi4_suspend(struct device *dev)
		return 0;
	}

	synaptics_secure_touch_stop(rmi4_data, 1);

	if (!rmi4_data->fw_updating) {
		if (!rmi4_data->sensor_sleep) {
			rmi4_data->touch_stopped = true;
@@ -3965,6 +4172,8 @@ static int synaptics_rmi4_resume(struct device *dev)
		return 0;
	}

	synaptics_secure_touch_stop(rmi4_data, 1);

	retval = synaptics_rmi4_regulator_lpm(rmi4_data, false);
	if (retval < 0) {
		dev_err(dev, "Failed to enter active power mode\n");
+11 −1
Original line number Diff line number Diff line
@@ -5,7 +5,7 @@
 *
 * Copyright (C) 2012 Alexandra Chin <alexandra.chin@tw.synaptics.com>
 * Copyright (C) 2012 Scott Lin <scott.lin@tw.synaptics.com>
 * Copyright (c) 2013-2014, The Linux Foundation. All rights reserved.
 * Copyright (c) 2013-2015, The Linux Foundation. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
@@ -35,6 +35,10 @@
#include <linux/earlysuspend.h>
#endif
#include <linux/debugfs.h>
#if defined(CONFIG_SECURE_TOUCH)
#include <linux/completion.h>
#include <linux/atomic.h>
#endif

#define PDT_PROPS (0x00EF)
#define PDT_START (0x00E9)
@@ -268,6 +272,12 @@ struct synaptics_rmi4_data {
	struct pinctrl *ts_pinctrl;
	struct pinctrl_state *gpio_state_active;
	struct pinctrl_state *gpio_state_suspend;
#if defined(CONFIG_SECURE_TOUCH)
	atomic_t st_enabled;
	atomic_t st_pending_irqs;
	struct completion st_powerdown;
	struct completion st_irq_processed;
#endif
};

enum exp_fn {