/*
 * Synaptics DSX touchscreen driver
 *
 * Copyright (C) 2012 Synaptics Incorporated
 *
 * Copyright (C) 2012 Alexandra Chin <alexandra.chin@tw.synaptics.com>
 * Copyright (C) 2012 Scott Lin <scott.lin@tw.synaptics.com>
 *
 * 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
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */
#define pr_fmt(fmt) "%s: " fmt, __func__

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/i2c.h>
#include <linux/of.h>
#include <linux/of_gpio.h>
#include <linux/interrupt.h>
#include <linux/delay.h>
#include <linux/input.h>
#include <linux/gpio.h>
#include <linux/ctype.h>
#include <linux/jiffies.h>
#include <linux/semaphore.h>
#include <linux/regulator/consumer.h>
#include <linux/input/synaptics_rmi_dsx.h>
#include "synaptics_dsx_i2c.h"
#ifdef KERNEL_ABOVE_2_6_38
#include <linux/input/mt.h>
#endif

#define DRIVER_NAME "synaptics_dsx_i2c"
#define INPUT_PHYS_NAME "synaptics_dsx_i2c/input0"
#define TYPE_B_PROTOCOL

#define NO_0D_WHILE_2D
/*
#define REPORT_2D_Z
*/
#define REPORT_2D_W

#define RPT_TYPE (1 << 0)
#define RPT_X_LSB (1 << 1)
#define RPT_X_MSB (1 << 2)
#define RPT_Y_LSB (1 << 3)
#define RPT_Y_MSB (1 << 4)
#define RPT_Z (1 << 5)
#define RPT_WX (1 << 6)
#define RPT_WY (1 << 7)
#define RPT_DEFAULT (RPT_TYPE | RPT_X_LSB | RPT_X_MSB | RPT_Y_LSB | RPT_Y_MSB)

#define EXP_FN_DET_INTERVAL 1000 /* ms */
#define POLLING_PERIOD 1 /* ms */
#define SYN_I2C_RETRY_TIMES 10
#define MAX_ABS_MT_TOUCH_MAJOR 15
#define SYN_MAX_BUTTONS 4

#define F01_STD_QUERY_LEN 21
#define F01_BUID_ID_OFFSET 18
#define F11_STD_QUERY_LEN 9
#define F11_STD_CTRL_LEN 10
#define F11_STD_DATA_LEN 12
#define F12_STD_QUERY_LEN 10
#define F12_STD_CTRL_LEN 4
#define F12_STD_DATA_LEN 80

#define NORMAL_OPERATION (0 << 0)
#define SENSOR_SLEEP (1 << 0)
#define NO_SLEEP_OFF (0 << 2)
#define NO_SLEEP_ON (1 << 2)

#define ONE_TOUCH_RECALIBRATION 49
#define ONE_TOUCH_SUPPRESSION 5
#define MULTI_TOUCH_SUPPRESSION 1
#define F11_DELTA_MAX (2*MULTI_TOUCH_SUPPRESSION)

#define X_1T_SUPPRESSION ONE_TOUCH_SUPPRESSION
#define Y_1T_SUPPRESSION ONE_TOUCH_SUPPRESSION
#define X_MT_SUPPRESSION MULTI_TOUCH_SUPPRESSION
#define Y_MT_SUPPRESSION MULTI_TOUCH_SUPPRESSION

#define TYPE_FINGER (1 << 0)
#define TYPE_STYLUS (1 << 1)

#define RESET_GPIO_NAME "touch_reset"
#define IRQ_GPIO_NAME "touch_irq"

#define SYDBG(fmt, args...)	printk(KERN_ERR "%s: " fmt, __func__, ##args)
#define SYDBG_REG(subpkt, fld) SYDBG(#subpkt "." #fld " = 0x%02X\n", subpkt.fld)

/* F12 packet register description */

static struct {
	unsigned char max_x_lsb;
	unsigned char max_x_msb;
	unsigned char max_y_lsb;
	unsigned char max_y_msb;
} f12_c08_0;

static struct {
	unsigned char recv_pitch_lsb;
	unsigned char recv_pitch_msb;
	unsigned char trans_pitch_lsb;
	unsigned char trans_pitch_msb;
} f12_c08_1;

static struct {
	unsigned char low_recv_clip;
	unsigned char high_recv_clip;
	unsigned char low_trans_clip;
	unsigned char high_trans_clip;
} f12_c08_2;

static struct {
	unsigned char num_2d_recv;
	unsigned char num_2d_trans;
} f12_c08_3;

static struct f12_c20_0_type {
	unsigned char x_suppression;
	unsigned char y_suppression;
} f12_c20_0;

static struct {
	union {
		struct {
			unsigned char report_always:1;
			unsigned char reserved:7;
		} __packed;
		unsigned char data[1];
	};
} f12_c20_1;

static struct f12_c23_0_type {
	union {
		struct {
			unsigned char finger:1;
			unsigned char stylus:1;
			unsigned char palm:1;
			unsigned char unclassified:1;
			unsigned char reserved:4;
		} __packed;
		unsigned char data[1];
	};
} f12_c23_0;

static struct f12_c23_1_type {
	unsigned char max_num_reported_objects;
} f12_c23_1;

static struct {
	unsigned char reported_bytes_per_object;
} f12_c28_0;

static struct synaptics_rmi4_subpkt f12_c08[] = {
	RMI4_SUBPKT(f12_c08_0),
	RMI4_SUBPKT(f12_c08_1),
	RMI4_SUBPKT(f12_c08_2),
	RMI4_SUBPKT(f12_c08_3),
};

static struct synaptics_rmi4_subpkt f12_c20[] = {
	RMI4_SUBPKT(f12_c20_0),
	RMI4_SUBPKT(f12_c20_1),
};

static struct synaptics_rmi4_subpkt f12_c23[] = {
	RMI4_SUBPKT(f12_c23_0),
	RMI4_SUBPKT(f12_c23_1),
};

static struct synaptics_rmi4_subpkt f12_c28[] = {
	RMI4_SUBPKT(f12_c28_0),
};

static struct synaptics_rmi4_packet_reg f12_ctrl_reg_array[] = {
	RMI4_NO_REG(),		/*00*/
	RMI4_NO_REG(),		/*01*/
	RMI4_NO_REG(),		/*02*/
	RMI4_NO_REG(),		/*03*/
	RMI4_NO_REG(),		/*04*/
	RMI4_NO_REG(),		/*05*/
	RMI4_NO_REG(),		/*06*/
	RMI4_NO_REG(),		/*07*/
	RMI4_REG(f12_c08),	/*08*/
	RMI4_NO_REG(),		/*09*/
	RMI4_NO_REG(),		/*10*/
	RMI4_NO_REG(),		/*11*/
	RMI4_NO_REG(),		/*12*/
	RMI4_NO_REG(),		/*13*/
	RMI4_NO_REG(),		/*14*/
	RMI4_NO_REG(),		/*15*/
	RMI4_NO_REG(),		/*16*/
	RMI4_NO_REG(),		/*17*/
	RMI4_NO_REG(),		/*18*/
	RMI4_NO_REG(),		/*19*/
	RMI4_REG(f12_c20),	/*20*/
	RMI4_NO_REG(),		/*21*/
	RMI4_NO_REG(),		/*22*/
	RMI4_REG(f12_c23),	/*23*/
	RMI4_NO_REG(),		/*24*/
	RMI4_NO_REG(),		/*25*/
	RMI4_NO_REG(),		/*26*/
	RMI4_NO_REG(),		/*27*/
	RMI4_REG(f12_c28),	/*28*/
};

static struct synaptics_rmi4_func_packet_regs f12_ctrl_regs = {
	.base_addr = 0,
	.nr_regs = ARRAY_SIZE(f12_ctrl_reg_array),
	.regs = f12_ctrl_reg_array
};

struct synaptics_dsx_hob {
	struct f12_c20_0_type f12_c20_0;
	struct f12_c23_0_type f12_c23_0;
	struct f12_c23_1_type f12_c23_1;
	unsigned char f01_c9;
};

/* global variable init-ed from kernel cmd line */
static int touch_test_mode;

int __init touch_test_mode_init(char *s)
{
	touch_test_mode = 1;
	pr_info("touch driver in TEST mode\n");
	return 1;
}

__setup("touch_test_mode", touch_test_mode_init);

static struct synaptics_dsx_hob hob_data;
static unsigned char tsb_buff_clean_flag = 1;

#define LAST_SUBPACKET_ROW_IND_MASK 0x80
#define NR_SUBPKT_PRESENCE_BITS 7

int synaptics_rmi4_scan_packet_reg_info(
	struct synaptics_rmi4_data *rmi4_data,
	unsigned short query_addr,
	unsigned short regs_base_addr,
	struct synaptics_rmi4_func_packet_regs *regs)
{
	unsigned char sz, mask;
	int ii, jj, r, s, retval;
	unsigned short r_offset;
	unsigned short addr = query_addr;
	unsigned char data[255];

	for (r = 0; r < regs->nr_regs; ++r) {
		regs->regs[r].offset = -1;
		regs->regs[r].size = 0;
		for (s = 0; s < regs->regs[r].nr_subpkts; ++s) {
			regs->regs[r].subpkt[s].present = 0;
			if (regs->regs[r].subpkt[s].data &&
					regs->regs[r].subpkt[s].size)
				memset(regs->regs[r].subpkt[s].data, 0,
					regs->regs[r].subpkt[s].size);
		}
	}

	regs->base_addr = regs_base_addr;
	retval = rmi4_data->i2c_read(rmi4_data, addr, &sz, 1);
	pr_debug("size of reg presence = %d\n",	sz);
	if (retval < 0)
		return retval;
	if (!sz)
		return -EIO;
	/* Scan register presence */
	retval = rmi4_data->i2c_read(rmi4_data, ++addr, data, sz);
	if (retval < 0)
		return retval;
	if (!data[0]) {
		pr_err("packet register size greater 255 bytes"
			" not supported\n");
		return -ENOSYS;
	}
	ii = 1;
	for (r = 0, r_offset = 0; ii < sz; ++ii) {
		pr_debug("reg presence [%d] = 0x%02x\n", ii, data[ii]);
		for (jj = 0, mask = 1; jj < 8; ++jj, ++r, mask <<= 1) {
			struct synaptics_rmi4_packet_reg *reg = regs->regs + r;
			int present = (data[ii] & mask) != 0;
			int allocated = r < regs->nr_regs;
			int expected = allocated && reg->expected;
			if (!present || !expected) {
				if (allocated && present)
					reg->offset = r_offset++;
				if (present != expected)
					pr_debug("  reg: r%d"
						" is%s present, but was%s"
						" expected\n", r,
						present ? "" : " NOT",
						expected ? "" : " NOT");
				continue;
			}
			pr_debug("  r%d offset = %d\n", r, r_offset);
			reg->offset = r_offset++;
		}
	}

	/* Scan register size and subpacket presence*/
	sz = data[0];
	pr_debug("subpacket presence sz = %d\n", sz);
	retval = rmi4_data->i2c_read(rmi4_data, ++addr, data, sz);
	if (retval < 0)
		return retval;
	for (r = 0, ii = 0; r < regs->nr_regs && ii < sz; ++r) {
		unsigned int expected_reg_size;
		struct synaptics_rmi4_packet_reg *reg = regs->regs + r;
		if (reg->offset == -1)
			continue;
		reg->size = data[ii++];
		pr_debug("r%d sz = %d\n", r, reg->size);
		if (!reg->size) {
			pr_err("packet register size greater 255 bytes"
				" not supported\n");
			return -ENOSYS;
		}
		expected_reg_size = 0;
		for (s = 0; ii < sz;) {
			pr_debug("  subpkt presence [%d] = 0x%02x\n",
				ii, data[ii]);
			for (jj = 0, mask = 1; jj < NR_SUBPKT_PRESENCE_BITS;
					++jj, ++s, mask <<= 1) {
				struct synaptics_rmi4_subpkt *subpkt =
							reg->subpkt + s;
				int present = (data[ii] & mask) != 0;
				int expected = (s < reg->nr_subpkts) &&
					subpkt->expected;
				if (!present || !expected) {
					if (present != expected)
						pr_debug("    subpacket:"
							" r%d s%d is%s present,"
							" but was%s expected\n",
							r, s,
							present ? "" : " NOT",
							expected ? "" : " NOT");
					continue;
				}
				pr_debug("    r%d.s%d is present\n", r, s);
				subpkt->present = 1;
				expected_reg_size += subpkt->size;
			}
			if ((data[ii++] & LAST_SUBPACKET_ROW_IND_MASK) == 0)
				break;
		}
		if (reg->expected && reg->size != expected_reg_size) {
			pr_debug("  r%d size error:"
				" expected %d actual is %d\n",
				r, expected_reg_size, reg->size);
		}
	}
	return 0;
}

int synaptics_rmi4_read_packet_reg(
	struct synaptics_rmi4_data *rmi4_data,
	struct synaptics_rmi4_func_packet_regs *regs, unsigned char r)
{
	int s, retval, offset;
	static unsigned char data[255];
	struct synaptics_rmi4_packet_reg *reg = regs->regs + r;

	if (r >= regs->nr_regs || !reg->size)
		return -EINVAL;

	if (reg->offset == -1) {
		pr_err("touch register error: can't read r%d - not present\n",
			r);
		return -ENOENT;
	}

	retval = rmi4_data->i2c_read(
			rmi4_data,
			regs->base_addr + reg->offset,
			data,
			reg->size);

	if (retval < 0)
		return retval;

	for (s = 0, offset = 0; s < reg->nr_subpkts; ++s) {
		struct synaptics_rmi4_subpkt *subpkt = reg->subpkt + s;
		if (!subpkt->present)
			continue;

		if ((reg->size - offset) < subpkt->size) {
			pr_err("subpkt size error: expected %d bytes,"
				" only %d present\n", subpkt->size,
				(reg->size - offset));
			break;
		}

		memcpy(subpkt->data, data+offset, subpkt->size);
		offset += subpkt->size;
#if defined(CONFIG_DYNAMIC_DEBUG) || defined(DEBUG)
		{
			int kk;
			pr_debug("read r%d.s%d =\n", r, s);
			for (kk = 0; kk < subpkt->size; ++kk)
				pr_debug("%02x\n",
					((unsigned char *)subpkt->data)[kk]);
		}
#endif
	}
	return retval;
}

int synaptics_rmi4_read_packet_regs(
	struct synaptics_rmi4_data *rmi4_data,
	struct synaptics_rmi4_func_packet_regs *regs)
{
	int r;
	int retval = 0;

	for (r = 0; r < regs->nr_regs; ++r) {
		if (regs->regs[r].expected && regs->regs[r].offset >= 0) {
			retval = synaptics_rmi4_read_packet_reg(
				rmi4_data, regs, r);
			if (retval < 0)
				break;
		}
	}
	return retval;
}

static int synaptics_rmi4_write_packet_reg(
	struct synaptics_rmi4_data *rmi4_data,
	struct synaptics_rmi4_func_packet_regs *regs, unsigned char r)
{
	unsigned char data[255];
	struct synaptics_rmi4_packet_reg *reg = regs->regs + r;
	int sz, ii, offset, retval;

	if (r >= regs->nr_regs || !reg->size)
		return -EINVAL;
	if (reg->offset == -1) {
		pr_err("touch register error: writing to absent register r%d\n",
			r);
		return -ENOENT;
	}

	for (ii = 0, sz = 0, offset = 0; ii < reg->nr_subpkts; ++ii) {
		struct synaptics_rmi4_subpkt *subpkt = reg->subpkt + ii;
		if (!subpkt->present)
			continue;

		if (subpkt->data && subpkt->size &&
			(offset + subpkt->size) < sizeof(data)) {
			if ((reg->size - offset) >= subpkt->size) {
				memcpy(data + sz, subpkt->data, subpkt->size);
				sz += subpkt->size;
			} else {
				pr_err("expected %d bytes, only %d present\n",
					offset + subpkt->size, reg->size);
				break;
			}
		} else {
			retval = -EINVAL;
			pr_err("bad subpacket or register greater %d bytes\n",
					sizeof(data));
			goto out;
		}
	}
	retval = rmi4_data->i2c_write(rmi4_data, regs->base_addr + reg->offset,
		data, sz);
out:
	return retval;
}

int synaptics_dsx_gpio_config(
		struct synaptics_dsx_platform_data *pdata, bool enable)
{
	int retval = 0;

	if (enable) {
		if (!gpio_is_valid(pdata->irq_gpio)) {
			pr_err("invalid %s\n", IRQ_GPIO_NAME);
			retval = -EINVAL;
		}
		retval = gpio_request(pdata->irq_gpio, IRQ_GPIO_NAME);
		if (retval) {
			pr_err("unable to request %s [%d]: rc=%d\n",
				IRQ_GPIO_NAME, pdata->irq_gpio, retval);
			goto err_gpio;
		}
		retval = gpio_direction_input(pdata->irq_gpio);
		if (retval) {
			pr_err("unable to set %s [%d] dir: rc=%d\n",
				IRQ_GPIO_NAME, pdata->irq_gpio, retval);
			goto err_gpio;
		}

		if (!gpio_is_valid(pdata->reset_gpio)) {
			pr_err("invalid %s\n", RESET_GPIO_NAME);
			retval = -EINVAL;
		}
		retval = gpio_request(pdata->reset_gpio, RESET_GPIO_NAME);
		if (retval) {
			pr_err("unable to request %s [%d]: rc=%d\n",
				RESET_GPIO_NAME, pdata->reset_gpio, retval);
			goto err_gpio;
		}
		retval = gpio_direction_output(pdata->reset_gpio, 1);
		if (retval) {
			pr_err("unable to set %s [%d] dir: rc=%d\n",
				RESET_GPIO_NAME, pdata->reset_gpio, retval);
			goto err_gpio;
		}
	} else {
		gpio_free(pdata->irq_gpio);
		gpio_free(pdata->reset_gpio);
	}

err_gpio:
	return retval;
}

#ifdef CONFIG_OF
static struct synaptics_dsx_platform_data *
		synaptics_dsx_of_init(struct i2c_client *client,
				struct synaptics_rmi4_data *rmi4_data)
{
	int retval;
	unsigned key_codes[SYN_MAX_BUTTONS];
	struct synaptics_dsx_platform_data *pdata;
	struct device_node *np = client->dev.of_node;
	struct synaptics_dsx_cap_button_map *button_map = NULL;

	pdata = devm_kzalloc(&client->dev, sizeof(*pdata), GFP_KERNEL);
	if (!pdata) {
		dev_err(&client->dev, "pdata allocation failure\n");
		return NULL;
	}

	pdata->irq_gpio = of_get_gpio(np, 0);
	pdata->reset_gpio = of_get_gpio(np, 1);

	memset(key_codes, 0, sizeof(key_codes));
	retval = of_property_read_u32_array(np, "synaptics,key-buttons",
			 key_codes, SYN_MAX_BUTTONS);
	if (!retval) {
		int ii;
		unsigned char *button_codes;

		button_map = kzalloc(sizeof(*button_map), GFP_KERNEL);
		if (IS_ERR_OR_NULL(button_map)) {
			dev_err(&client->dev, "button allocation failure\n");
			return NULL;
		}

		for (ii = 0; ii < SYN_MAX_BUTTONS; ii++)
			if (key_codes[ii])
				button_map->nbuttons++;

		button_codes = kzalloc(button_map->nbuttons, GFP_KERNEL);
		if (IS_ERR_OR_NULL(button_codes)) {
			dev_err(&client->dev, "button allocation failure\n");
			kfree(button_map);
			return NULL;
		}

		for (ii = 0; ii < button_map->nbuttons; ii++)
			*(button_codes + ii) = (unsigned char)key_codes[ii];

		button_map->map = button_codes;
	}

	pdata->irq_flags = IRQF_TRIGGER_LOW | IRQF_ONESHOT;
	pdata->cap_button_map = button_map;

	if (of_property_read_bool(np, "synaptics,gpio-config")) {
		pr_notice("using gpio config\n");
		pdata->gpio_config = synaptics_dsx_gpio_config;
	}

	if (of_property_read_bool(np, "synaptics,x-flip")) {
		pr_notice("using flipped X axis\n");
		pdata->x_flip = true;
	}

	if (of_property_read_bool(np, "synaptics,y-flip")) {
		pr_notice("using flipped Y axis\n");
		pdata->y_flip = true;
	}

	if (of_property_read_bool(np, "synaptics,purge-enabled")) {
		pr_notice("using purge\n");
		rmi4_data->purge_enabled = true;
	}

	if (of_property_read_bool(np, "synaptics,reset-on-resume")) {
		pr_notice("using reset ic on resume\n");
		rmi4_data->reset_on_resume = true;
	}

	if (of_property_read_bool(np, "synaptics,one-touch-enabled")) {
		pr_notice("using one touch while suspended\n");
		rmi4_data->one_touch_enabled = true;
	}

	if (!of_property_read_bool(np, "synaptics,normal-mode")) {
		pr_notice("using normal mode settings from tdat\n");
		rmi4_data->normal_mode = -1;
	} else {
		of_property_read_u32(np, "synaptics,normal-mode",
					&rmi4_data->normal_mode);
		pr_notice("%s mode\n", rmi4_data->normal_mode ?
				"using normal" : "enforce no sleep");
	}

	if (of_property_read_bool(np, "synaptics,hw-reset")) {
		pr_notice("using hard ic reset\n");
		rmi4_data->hw_reset = true;
	}

	return pdata;
} 
#else
static inline struct synaptics_dsx_platform_data *
		synaptics_dsx_of_init(struct i2c_client *client)
{
	return NULL;
}
#endif

#define HYPHEN		'-'
#define letter_i	'i'
#define letter_s	's'
#define letter_t	't'

static void synaptics_dsx_darn_product_string(unsigned char *id, size_t len)
{
	unsigned char *hyphen;

	hyphen = strnchr(id, len, HYPHEN);
	if (hyphen) {
		if (*(hyphen+1) == toupper(letter_t)) {
			memmove(id+1, id, hyphen-id);
			hyphen++;
			*hyphen++ = letter_t;
		} else if (*(hyphen+1) == toupper(letter_i))
			*hyphen++ = letter_i;
		*id = letter_s;
		*hyphen = 0;
	} else {
		int i;
		for (i = 0; *(id+i) != 0; i++)
			if (isupper(*(id+i)))
				*(id+i) = tolower(*(id+i));
	}
}

static int synaptics_rmi4_i2c_read(struct synaptics_rmi4_data *rmi4_data,
		unsigned short addr, unsigned char *data,
		unsigned short length);

static int synaptics_rmi4_i2c_write(struct synaptics_rmi4_data *rmi4_data,
		unsigned short addr, unsigned char *data,
		unsigned short length);

static int synaptics_rmi4_reset_device(struct synaptics_rmi4_data *rmi4_data,
		unsigned char *f01_cmd_base_addr);

static void synaptics_rmi4_sensor_sleep(struct synaptics_rmi4_data *rmi4_data);

static void synaptics_rmi4_sensor_wake(struct synaptics_rmi4_data *rmi4_data);

static void synaptics_rmi4_sensor_one_touch(
		struct synaptics_rmi4_data *rmi4_data, bool enable);

static void synaptics_rmi4_sensor_multi_touch(
		struct synaptics_rmi4_data *rmi4_data, unsigned char function);

static int synaptics_rmi4_irq_enable(struct synaptics_rmi4_data *rmi4_data,
		bool enable);

static void synaptics_dsx_sensor_state(struct synaptics_rmi4_data *rmi4_data,
		int state);

#if defined(CONFIG_FB) && !defined(CONFIG_MMI_PANEL_NOTIFICATIONS)
static int synaptics_dsx_panel_cb(struct notifier_block *nb,
		unsigned long event, void *data);
#endif

static int synaptics_rmi4_suspend(struct device *dev);

static int synaptics_rmi4_resume(struct device *dev);

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

static ssize_t synaptics_rmi4_f01_productinfo_show(struct device *dev,
		struct device_attribute *attr, char *buf);

static ssize_t synaptics_rmi4_f01_buildid_show(struct device *dev,
		struct device_attribute *attr, char *buf);

static ssize_t synaptics_rmi4_f01_flashprog_show(struct device *dev,
		struct device_attribute *attr, char *buf);

static ssize_t synaptics_rmi4_0dbutton_show(struct device *dev,
		struct device_attribute *attr, char *buf);

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

static ssize_t synaptics_rmi4_resume_show(struct device *dev,
		struct device_attribute *attr, char *buf);

static ssize_t synaptics_rmi4_irqtimes_show(struct device *dev,
		struct device_attribute *attr, char *buf);

static ssize_t synaptics_rmi4_drv_irq_show(struct device *dev,
		struct device_attribute *attr, char *buf);

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

static ssize_t synaptics_rmi4_hw_irqstat_show(struct device *dev,
		struct device_attribute *attr, char *buf);

static ssize_t synaptics_rmi4_ic_ver_show(struct device *dev,
		struct device_attribute *attr, char *buf);

static ssize_t synaptics_rmi4_poweron_show(struct device *dev,
		struct device_attribute *attr, char *buf);

struct synaptics_rmi4_f01_device_status {
	union {
		struct {
			unsigned char status_code:4;
			unsigned char reserved:2;
			unsigned char flash_prog:1;
			unsigned char unconfigured:1;
		} __packed;
		unsigned char data[1];
	};
};

struct synaptics_rmi4_f1a_query {
	union {
		struct {
			unsigned char max_button_count:3;
			unsigned char reserved:5;
			unsigned char has_general_control:1;
			unsigned char has_interrupt_enable:1;
			unsigned char has_multibutton_select:1;
			unsigned char has_tx_rx_map:1;
			unsigned char has_perbutton_threshold:1;
			unsigned char has_release_threshold:1;
			unsigned char has_strongestbtn_hysteresis:1;
			unsigned char has_filter_strength:1;
		} __packed;
		unsigned char data[2];
	};
};

struct synaptics_rmi4_f1a_control_0 {
	union {
		struct {
			unsigned char multibutton_report:2;
			unsigned char filter_mode:2;
			unsigned char reserved:4;
		} __packed;
		unsigned char data[1];
	};
};

struct synaptics_rmi4_f1a_control_3_4 {
	unsigned char transmitterbutton;
	unsigned char receiverbutton;
};

struct synaptics_rmi4_f1a_control {
	struct synaptics_rmi4_f1a_control_0 general_control;
	unsigned char *button_int_enable;
	unsigned char *multi_button;
	struct synaptics_rmi4_f1a_control_3_4 *electrode_map;
	unsigned char *button_threshold;
	unsigned char button_release_threshold;
	unsigned char strongest_button_hysteresis;
	unsigned char filter_strength;
};

struct synaptics_rmi4_f1a_handle {
	int button_bitmask_size;
	unsigned char button_count;
	unsigned char valid_button_count;
	unsigned char *button_data_buffer;
	unsigned char *button_map;
	struct synaptics_rmi4_f1a_query button_query;
	struct synaptics_rmi4_f1a_control button_control;
};

struct synaptics_rmi4_exp_fn {
	enum exp_fn fn_type;
	enum ic_modes mode;
	bool inserted;
	int (*func_init)(struct synaptics_rmi4_data *rmi4_data);
	void (*func_remove)(struct synaptics_rmi4_data *rmi4_data);
	void (*func_attn)(struct synaptics_rmi4_data *rmi4_data,
			unsigned char intr_mask);
	struct list_head link;
};

static struct device_attribute attrs[] = {
	__ATTR(reset, S_IWUSR | S_IWGRP,
			synaptics_rmi4_show_error,
			synaptics_rmi4_f01_reset_store),
	__ATTR(productinfo, S_IRUGO,
			synaptics_rmi4_f01_productinfo_show,
			synaptics_rmi4_store_error),
	__ATTR(buildid, S_IRUGO,
			synaptics_rmi4_f01_buildid_show,
			synaptics_rmi4_store_error),
	__ATTR(flashprog, S_IRUSR | S_IRGRP,
			synaptics_rmi4_f01_flashprog_show,
			synaptics_rmi4_store_error),
	__ATTR(0dbutton, (S_IRUSR | S_IRGRP | S_IWUSR | S_IWGRP),
			synaptics_rmi4_0dbutton_show,
			synaptics_rmi4_0dbutton_store),
	__ATTR(resumeinfo, S_IRUSR | S_IRGRP,
			synaptics_rmi4_resume_show,
			synaptics_rmi4_store_error),
	__ATTR(drv_irq, (S_IRUSR | S_IRGRP | S_IWUSR | S_IWGRP),
			synaptics_rmi4_drv_irq_show,
			synaptics_rmi4_drv_irq_store),
	__ATTR(hw_irqstat, S_IRUSR | S_IRGRP,
			synaptics_rmi4_hw_irqstat_show,
			synaptics_rmi4_store_error),
	__ATTR(ic_ver, S_IRUGO,
			synaptics_rmi4_ic_ver_show,
			synaptics_rmi4_store_error),
	__ATTR(irqinfo, S_IRUSR | S_IRGRP,
			synaptics_rmi4_irqtimes_show,
			synaptics_rmi4_store_error),
	__ATTR(poweron, S_IRUSR | S_IRGRP,
			synaptics_rmi4_poweron_show,
			synaptics_rmi4_store_error),
};

struct synaptics_exp_fn_ctrl {
	bool inited;
	struct mutex list_mutex;
	struct list_head fn_list;
	struct delayed_work det_work;
	struct workqueue_struct *det_workqueue;
	struct synaptics_rmi4_data *rmi4_data_ptr;
};

DEFINE_MUTEX(exp_fn_ctrl_mutex);
static struct synaptics_exp_fn_ctrl exp_fn_ctrl;
static struct semaphore reset_semaphore;

static irqreturn_t synaptics_dsx_reset_irq(int irq, void *data)
{
	struct semaphore *sema = data;
	up(sema);
	return IRQ_HANDLED;
}

static int synaptics_dsx_ic_reset(
		struct synaptics_rmi4_data *rmi4_data, bool hw_reset)
{
	int retval;
	unsigned long start = jiffies;
	const struct synaptics_dsx_platform_data *platform_data =
			rmi4_data->board;

	sema_init(&reset_semaphore, 0);

	if (hw_reset) {
		gpio_set_value(platform_data->reset_gpio, 0);
		udelay(1500);
	}

	retval = request_irq(rmi4_data->irq, synaptics_dsx_reset_irq,
			IRQF_TRIGGER_RISING, "synaptics_reset",
			&reset_semaphore);
	if (retval < 0)
		dev_err(&rmi4_data->i2c_client->dev,
				"%s: Failed to request irq: %d\n",
				__func__, retval);

	if (hw_reset)
		gpio_set_value(platform_data->reset_gpio, 1);

	retval = down_timeout(&reset_semaphore, msecs_to_jiffies(100));
	if (retval) {
		dev_err(&rmi4_data->i2c_client->dev,
				"timed out waiting for reset to complete\n");
		retval = -ETIMEDOUT;
	} else {
		retval = (int)jiffies_to_msecs(jiffies-start);
		/* delay extra 0.5 ms to ensure 1st i2c bus access succeeds */
		udelay(500);
	}

	free_irq(rmi4_data->irq, &reset_semaphore);

	return retval;
}

static int synaptics_dsx_alloc_input(struct synaptics_rmi4_data *rmi4_data)
{
	rmi4_data->input_dev = input_allocate_device();
	if (IS_ERR_OR_NULL(rmi4_data->input_dev))
		return PTR_ERR(rmi4_data->input_dev);

	rmi4_data->input_dev->name = DRIVER_NAME;
	rmi4_data->input_dev->phys = INPUT_PHYS_NAME;
	rmi4_data->input_dev->id.bustype = BUS_I2C;
	rmi4_data->input_dev->dev.parent = &rmi4_data->i2c_client->dev;

	set_bit(EV_SYN, rmi4_data->input_dev->evbit);
	input_set_drvdata(rmi4_data->input_dev, rmi4_data);

	pr_debug("allocated input device\n");

	return 0;
}

#define DSX(a)	(#a)
static const char * const synaptics_state_names[] = SYNAPTICS_DSX_STATES;
#undef DSX

static const char *synaptics_dsx_state_name(int state)
{
	int index = state < 0 || state > STATE_INVALID ? STATE_INVALID : state;
	return synaptics_state_names[index];
}

static int synaptics_dsx_get_state_safe(struct synaptics_rmi4_data *rmi4_data)
{
	int state;
	mutex_lock(&(rmi4_data->state_mutex));
	state = rmi4_data->state;
	mutex_unlock(&(rmi4_data->state_mutex));
	return state;
}

static void synaptics_dsx_set_state_safe(struct synaptics_rmi4_data *rmi4_data,
		int state)
{
	mutex_lock(&(rmi4_data->state_mutex));
	rmi4_data->state = state;
	mutex_unlock(&(rmi4_data->state_mutex));
}

static int synaptics_dsx_wait_for_idle(struct synaptics_rmi4_data *rmi4_data)
{
	unsigned long start_wait_jiffies = jiffies;

	do {
		int current_state;

		current_state = synaptics_dsx_get_state_safe(rmi4_data);
		if (!(current_state == STATE_INIT ||
			current_state == STATE_FLASH ||
			current_state == STATE_UNKNOWN ||
			touch_test_mode))
			break;

		usleep_range(1000, 1000);

	} while (1);

	if ((jiffies - start_wait_jiffies))
		pr_info("entering suspend delayed for %ums\n",
			jiffies_to_msecs(jiffies - start_wait_jiffies));
	return 0;
}

static int synaptics_dsx_sensor_ready_state(
		struct synaptics_rmi4_data *rmi4_data, bool standby)
{
	bool ui_mode;
	int retval, state;
	struct synaptics_rmi4_f01_device_status status;

	/* ensure ic is woken up, since older beta firmware cannot */
	/* access device status register when ic is in sleep mode */
	if (rmi4_data->sensor_sleep)
		synaptics_rmi4_sensor_wake(rmi4_data);

	retval = synaptics_rmi4_i2c_read(rmi4_data,
				rmi4_data->f01_data_base_addr,
				status.data,
				sizeof(status.data));
	if (retval < 0) {
		pr_err("failed to query touch ic status\n");
		return retval;
	}

	state = synaptics_dsx_get_state_safe(rmi4_data);

	ui_mode = status.flash_prog == 0;
	pr_debug("UI mode: %s\n", ui_mode ? "true" : "false");

	if (ui_mode) {
		state = standby ? STATE_STANDBY : STATE_ACTIVE;
		state = touch_test_mode ? STATE_ACTIVE : state;
	} else
		if (!(state == STATE_INIT || state == STATE_FLASH))
			state = STATE_BL;

	synaptics_dsx_sensor_state(rmi4_data, state);

	return 0;
}

static void synaptics_dsx_sensor_state(struct synaptics_rmi4_data *rmi4_data,
		int state)
{
	if (synaptics_dsx_get_state_safe(rmi4_data) == state)
		return;

	switch (state) {
	case STATE_UNKNOWN:
	case STATE_FLASH:
		/* no special handling for these states */
			break;

	case STATE_SUSPEND:
		synaptics_dsx_wait_for_idle(rmi4_data);
		synaptics_rmi4_irq_enable(rmi4_data, false);

		if (rmi4_data->one_touch_enabled)
			synaptics_rmi4_sensor_one_touch(rmi4_data, true);

		if (!rmi4_data->sensor_sleep)
			synaptics_rmi4_sensor_sleep(rmi4_data);
			break;

	case STATE_ACTIVE:
		if (rmi4_data->sensor_sleep)
			synaptics_rmi4_sensor_wake(rmi4_data);

		if (rmi4_data->one_touch_enabled)
			synaptics_rmi4_sensor_one_touch(rmi4_data, false);

		synaptics_rmi4_irq_enable(rmi4_data, true);
			break;

	case STATE_STANDBY:
		synaptics_rmi4_irq_enable(rmi4_data, false);
		/* put sensor to sleep to ensure the same */
		/* initial conditions apply to all */
		if (!rmi4_data->sensor_sleep)
			synaptics_rmi4_sensor_sleep(rmi4_data);
			break;

	case STATE_BL:
		if (!rmi4_data->in_bootloader)
			rmi4_data->in_bootloader = true;
	case STATE_INIT:
		synaptics_rmi4_irq_enable(rmi4_data, false);
		if (rmi4_data->sensor_sleep)
			synaptics_rmi4_sensor_wake(rmi4_data);
			break;
	}

	pr_info("state change %s -> %s\n",
			synaptics_dsx_state_name(rmi4_data->state),
			synaptics_dsx_state_name(state));

	synaptics_dsx_set_state_safe(rmi4_data, state);
}

static ssize_t synaptics_rmi4_f01_reset_store(struct device *dev,
		struct device_attribute *attr, const char *buf, size_t count)
{
	int retval;
	unsigned int reset;
	struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev);

	if (sscanf(buf, "%u", &reset) != 1)
		return -EINVAL;

	if (reset != 1)
		return -EINVAL;

	retval = synaptics_rmi4_reset_device(rmi4_data, NULL);
	if (retval < 0) {
		dev_err(dev,
				"%s: Failed to issue reset command, error = %d\n",
				__func__, retval);
		return retval;
	}

	return count;
}

static ssize_t synaptics_rmi4_f01_productinfo_show(struct device *dev,
		struct device_attribute *attr, char *buf)
{
	struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev);

	return scnprintf(buf, PAGE_SIZE, "%s\n",
			rmi4_data->rmi4_mod_info.product_id_string);
}

static ssize_t synaptics_rmi4_f01_buildid_show(struct device *dev,
		struct device_attribute *attr, char *buf)
{
	unsigned int firmware_id;
	unsigned int config_id;
	struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev);
	struct synaptics_rmi4_device_info *rmi;

	rmi = &(rmi4_data->rmi4_mod_info);

	batohui(&firmware_id, rmi->build_id, sizeof(rmi->build_id));
	batohui(&config_id, rmi->config_id, sizeof(rmi->config_id));

	return scnprintf(buf, PAGE_SIZE, "%x-%08x\n", firmware_id, config_id);
}

static ssize_t synaptics_rmi4_resume_show(struct device *dev,
		struct device_attribute *attr, char *buf)
{
	struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev);
	int i;
	int c_res;
	int offset = 0;

	c_res = rmi4_data->last_resume;
	/* Resume buffer not allocated or there were no resumes yet */
	if (rmi4_data->number_resumes <= 0 || c_res < 0)
		return scnprintf(buf, PAGE_SIZE,
				"No resume information found.\n");

	offset += scnprintf(buf + offset, PAGE_SIZE - offset,
		"Count\tStart\t\tFinish\t# no-events\t"
		"ISR\t\tpurge off\tsendevent\n");

	for (i = 0; i < rmi4_data->number_resumes; i++) {
		offset += scnprintf(buf + offset, PAGE_SIZE - offset,
			"%d\t%4ld.%03ld\t%4ld.%03ld\t%d\t%4ld.%03ld\t"
			"%4ld.%03ld\t%4ld.%03ld\n",
		i+1,
		rmi4_data->resume_info[c_res].start.tv_sec%1000,
		rmi4_data->resume_info[c_res].start.tv_nsec/1000000,
		rmi4_data->resume_info[c_res].finish.tv_sec%1000,
		rmi4_data->resume_info[c_res].finish.tv_nsec/1000000,
		rmi4_data->resume_info[c_res].ignored_events,
		rmi4_data->resume_info[c_res].isr.tv_sec%1000,
		rmi4_data->resume_info[c_res].isr.tv_nsec/1000000,
		rmi4_data->resume_info[c_res].purge_off.tv_sec%1000,
		rmi4_data->resume_info[c_res].purge_off.tv_nsec/1000000,
		rmi4_data->resume_info[c_res].send_touch.tv_sec%1000,
		rmi4_data->resume_info[c_res].send_touch.tv_nsec/1000000);

		if (c_res <= 0)
			c_res = rmi4_data->number_resumes-1;
		else
			c_res--;
	}
	return offset;
}

static ssize_t synaptics_rmi4_irqtimes_show(struct device *dev,
		struct device_attribute *attr, char *buf)
{
	struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev);
	int i;
	int c_res;
	int offset = 0;

	c_res = rmi4_data->last_irq;
	/* Resume buffer not allocated or there were no irq data collected yet*/
	if (rmi4_data->number_irq <= 0 || c_res < 0)
		return scnprintf(buf, PAGE_SIZE,
				"No resume information found.\n");

	offset += scnprintf(buf + offset, PAGE_SIZE - offset,
		"Count\tIRQ Start\n");

	for (i = 0; i < rmi4_data->number_irq; i++) {
		offset += scnprintf(buf + offset, PAGE_SIZE - offset,
			"%d\t%4ld.%03ld\n",
		i+1,
		rmi4_data->irq_info[i].irq_time.tv_sec%1000,
		rmi4_data->irq_info[i].irq_time.tv_nsec/1000000);

		if (c_res <= 0)
			c_res = rmi4_data->number_irq-1;
		else
			c_res--;
	}
	return offset;
}

static ssize_t synaptics_rmi4_f01_flashprog_show(struct device *dev,
		struct device_attribute *attr, char *buf)
{
	int retval;
	struct synaptics_rmi4_f01_device_status device_status;
	struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev);

	retval = synaptics_rmi4_i2c_read(rmi4_data,
			rmi4_data->f01_data_base_addr,
			device_status.data,
			sizeof(device_status.data));
	if (retval < 0) {
		dev_err(dev,
				"%s: Failed to read device status, error = %d\n",
				__func__, retval);
		return retval;
	}

	return scnprintf(buf, PAGE_SIZE, "%u\n",
			device_status.flash_prog);
}

static ssize_t synaptics_rmi4_hw_irqstat_show(struct device *dev,
		struct device_attribute *attr, char *buf)
{
	struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev);

	switch (gpio_get_value(rmi4_data->board->irq_gpio)) {
	case 0:
		return scnprintf(buf, PAGE_SIZE, "Low\n");
	case 1:
		return scnprintf(buf, PAGE_SIZE, "High\n");
	default:
		printk(KERN_ERR "%s: Failed to get GPIO for irq %d.\n",
				__func__,
				rmi4_data->irq);
		return scnprintf(buf, PAGE_SIZE, "Unknown\n");
	}
}

static ssize_t synaptics_rmi4_drv_irq_show(struct device *dev,
		struct device_attribute *attr, char *buf)
{
	struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev);

	return scnprintf(buf, PAGE_SIZE, "%s\n",
			rmi4_data->irq_enabled ? "ENABLED" : "DISABLED");
}

static ssize_t synaptics_rmi4_drv_irq_store(struct device *dev,
		struct device_attribute *attr, const char *buf, size_t count)
{
	struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev);
	unsigned long value = 0;
	int err = 0;

	err = kstrtoul(buf, 10, &value);
	if (err < 0) {
		printk(KERN_ERR "%s: Failed to convert value.\n", __func__);
		return -EINVAL;
	}

	switch (value) {
	case 0:
		/* Disable irq */
		synaptics_rmi4_irq_enable(rmi4_data, false);
		break;
	case 1:
		/* Enable irq */
		synaptics_rmi4_irq_enable(rmi4_data, true);
		break;
	default:
		printk(KERN_ERR "%s: Invalid value\n", __func__);
		return -EINVAL;
	}
	return count;
}

static ssize_t synaptics_rmi4_0dbutton_show(struct device *dev,
		struct device_attribute *attr, char *buf)
{
	struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev);

	return scnprintf(buf, PAGE_SIZE, "%u\n",
			rmi4_data->button_0d_enabled);
}

static ssize_t synaptics_rmi4_0dbutton_store(struct device *dev,
		struct device_attribute *attr, const char *buf, size_t count)
{
	int retval;
	unsigned int input;
	unsigned char ii;
	unsigned char intr_enable;
	struct synaptics_rmi4_fn *fhandler;
	struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev);
	struct synaptics_rmi4_device_info *rmi;

	rmi = &(rmi4_data->rmi4_mod_info);

	if (sscanf(buf, "%u", &input) != 1)
		return -EINVAL;

	input = input > 0 ? 1 : 0;

	if (rmi4_data->button_0d_enabled == input)
		return count;

	list_for_each_entry(fhandler, &rmi->support_fn_list, link) {
		if (fhandler->fn_number == SYNAPTICS_RMI4_F1A) {
			ii = fhandler->intr_reg_num;

			retval = synaptics_rmi4_i2c_read(rmi4_data,
					rmi4_data->f01_ctrl_base_addr + 1 + ii,
					&intr_enable,
					sizeof(intr_enable));
			if (retval < 0)
				return retval;

			if (input == 1)
				intr_enable |= fhandler->intr_mask;
			else
				intr_enable &= ~fhandler->intr_mask;

			retval = synaptics_rmi4_i2c_write(rmi4_data,
					rmi4_data->f01_ctrl_base_addr + 1 + ii,
					&intr_enable,
					sizeof(intr_enable));
			if (retval < 0)
				return retval;
		}
	}

	rmi4_data->button_0d_enabled = input;

	return count;
}

static ssize_t synaptics_rmi4_ic_ver_show(struct device *dev,
		struct device_attribute *attr, char *buf)
{
	unsigned int build_id, config_id;
	struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev);
	struct synaptics_rmi4_device_info *rmi;
	rmi = &(rmi4_data->rmi4_mod_info);
	batohui(&build_id, rmi->build_id, sizeof(rmi->build_id));
	batohui(&config_id, rmi->config_id, sizeof(rmi->config_id));
	return scnprintf(buf, PAGE_SIZE,
			"%s%s\n%s%x\n%s%x\n",
			"Product ID: ", rmi->product_id_string,
			"Build ID: ", build_id,
			"Config ID: ", config_id);
}

static ssize_t synaptics_rmi4_poweron_show(struct device *dev,
		struct device_attribute *attr, char *buf)
{
	struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev);
	return scnprintf(buf, PAGE_SIZE, "%d\n", rmi4_data->poweron);
}

 /**
 * synaptics_rmi4_set_page()
 *
 * Called by synaptics_rmi4_i2c_read() and synaptics_rmi4_i2c_write().
 *
 * This function writes to the page select register to switch to the
 * assigned page.
 */
static int synaptics_rmi4_set_page(struct synaptics_rmi4_data *rmi4_data,
		unsigned int address)
{
	int retval = 0;
	unsigned char retry;
	unsigned char buf[PAGE_SELECT_LEN];
	unsigned char page;
	struct i2c_client *i2c = rmi4_data->i2c_client;

	page = ((address >> 8) & MASK_8BIT);
	if (page != rmi4_data->current_page) {
		buf[0] = MASK_8BIT;
		buf[1] = page;
		for (retry = 0; retry < SYN_I2C_RETRY_TIMES; retry++) {
			retval = i2c_master_send(i2c, buf, PAGE_SELECT_LEN);
			if (retval != PAGE_SELECT_LEN) {
				dev_err(&i2c->dev,
						"%s: I2C retry %d\n",
						__func__, retry + 1);
				msleep(20);
			} else {
				rmi4_data->current_page = page;
				break;
			}
		}
	} else
		return PAGE_SELECT_LEN;
	return (retval == PAGE_SELECT_LEN) ? retval : -EIO;
}

 /**
 * synaptics_rmi4_i2c_read()
 *
 * Called by various functions in this driver, and also exported to
 * other expansion Function modules such as rmi_dev.
 *
 * This function reads data of an arbitrary length from the sensor,
 * starting from an assigned register address of the sensor, via I2C
 * with a retry mechanism.
 */
static int synaptics_rmi4_i2c_read(struct synaptics_rmi4_data *rmi4_data,
		unsigned short addr, unsigned char *data, unsigned short length)
{
	int retval;
	unsigned char retry;
	unsigned char buf;
	struct i2c_msg msg[] = {
		{
			.addr = rmi4_data->i2c_client->addr,
			.flags = 0,
			.len = 1,
			.buf = &buf,
		},
		{
			.addr = rmi4_data->i2c_client->addr,
			.flags = I2C_M_RD,
			.len = length,
			.buf = data,
		},
	};

	buf = addr & MASK_8BIT;

	mutex_lock(&(rmi4_data->rmi4_io_ctrl_mutex));

	retval = synaptics_rmi4_set_page(rmi4_data, addr);
	if (retval != PAGE_SELECT_LEN)
		goto exit;

	for (retry = 0; retry < SYN_I2C_RETRY_TIMES; retry++) {
		if (i2c_transfer(rmi4_data->i2c_client->adapter, msg, 2) == 2) {
			retval = length;
			break;
		}
		dev_err(&rmi4_data->i2c_client->dev,
				"%s: I2C retry %d\n",
				__func__, retry + 1);
		msleep(20);
	}

	if (retry == SYN_I2C_RETRY_TIMES) {
		dev_err(&rmi4_data->i2c_client->dev,
				"%s: I2C read %db@x%x over retry limit\n",
				__func__, length, addr);
		retval = -EIO;
	}

exit:
	mutex_unlock(&(rmi4_data->rmi4_io_ctrl_mutex));

	return retval;
}

 /**
 * synaptics_rmi4_i2c_write()
 *
 * Called by various functions in this driver, and also exported to
 * other expansion Function modules such as rmi_dev.
 *
 * This function writes data of an arbitrary length to the sensor,
 * starting from an assigned register address of the sensor, via I2C with
 * a retry mechanism.
 */
static int synaptics_rmi4_i2c_write(struct synaptics_rmi4_data *rmi4_data,
		unsigned short addr, unsigned char *data, unsigned short length)
{
	int retval;
	unsigned char retry;
	unsigned char buf[length + 1];
	struct i2c_msg msg[] = {
		{
			.addr = rmi4_data->i2c_client->addr,
			.flags = 0,
			.len = length + 1,
			.buf = buf,
		}
	};

	mutex_lock(&(rmi4_data->rmi4_io_ctrl_mutex));

	retval = synaptics_rmi4_set_page(rmi4_data, addr);
	if (retval != PAGE_SELECT_LEN)
		goto exit;

	buf[0] = addr & MASK_8BIT;
	memcpy(&buf[1], &data[0], length);

	for (retry = 0; retry < SYN_I2C_RETRY_TIMES; retry++) {
		if (i2c_transfer(rmi4_data->i2c_client->adapter, msg, 1) == 1) {
			retval = length;
			break;
		}
		dev_err(&rmi4_data->i2c_client->dev,
				"%s: I2C retry %d\n",
				__func__, retry + 1);
		msleep(20);
	}

	if (retry == SYN_I2C_RETRY_TIMES) {
		dev_err(&rmi4_data->i2c_client->dev,
				"%s: I2C write %db@x%x over retry limit\n",
				__func__, length, addr);
		retval = -EIO;
	}

exit:
	mutex_unlock(&(rmi4_data->rmi4_io_ctrl_mutex));

	return retval;
}

 /**
 * synaptics_rmi4_f12_abs_report()
 *
 * Called by synaptics_rmi4_report_touch() when valid Function $12
 * finger data has been detected.
 *
 * This function reads the Function $12 data registers, determines the
 * status of each finger supported by the Function, processes any
 * necessary coordinate manipulation, reports the finger data to
 * the input subsystem, and returns the number of fingers detected.
 */
static int synaptics_rmi4_f12_abs_report(struct synaptics_rmi4_data *rmi4_data,
		struct synaptics_rmi4_fn *fhandler)
{
	struct synaptics_rmi4_resume_info *tmp_resume_i = NULL;
	int retval;
	unsigned char touch_count = 0; /* number of touch points */
	unsigned char index = 0;
	unsigned char finger;
	unsigned char fingers_supported;
	unsigned char finger_data[F12_STD_DATA_LEN];
	unsigned short data_addr;
	unsigned short data_size;
	int x;
	int y;
	int p;
	int w;
	int id;

	fingers_supported = fhandler->num_of_data_points;
	data_addr = fhandler->full_addr.data_base;
	data_size = fingers_supported * fhandler->size_of_data_register_block;

	retval = synaptics_rmi4_i2c_read(rmi4_data,
			data_addr,
			finger_data,
			data_size);
	if (retval < 0)
		return 0;

	if (rmi4_data->number_resumes > 0) {
		tmp_resume_i =
			&(rmi4_data->resume_info[rmi4_data->last_resume]);

		if (atomic_read(&rmi4_data->panel_off_flag)) {
			tmp_resume_i->ignored_events++;
			return 0;
		}
		if (tmp_resume_i->purge_off.tv_sec == 0)
			getnstimeofday(&(tmp_resume_i->purge_off));
	} else {
		if (atomic_read(&rmi4_data->panel_off_flag)) {
			return 0;
		}
	}

	for (finger = 0; finger < fingers_supported; finger++,
			 index += fhandler->size_of_data_register_block) {
		if (finger_data[index] == 0)
			continue;

		x = finger_data[index+1] | (finger_data[index+2] << 8);
		y = finger_data[index+3] | (finger_data[index+4] << 8);
		p = finger_data[index+5];
		w = finger_data[index+5];
		id = finger;

		if (rmi4_data->board->x_flip)
			x = rmi4_data->sensor_max_x - x;
		if (rmi4_data->board->y_flip)
			y = rmi4_data->sensor_max_y - y;

		dev_dbg(&rmi4_data->i2c_client->dev,
					"%s: Finger %d:\n"
					"x = %d\n"
					"y = %d\n"
					"p = %d\n"
					"w = %d\n",
					__func__, finger,
					x, y, p, w);

		input_report_abs(rmi4_data->input_dev,
					ABS_MT_POSITION_X, x);
		input_report_abs(rmi4_data->input_dev,
					ABS_MT_POSITION_Y, y);
		input_report_abs(rmi4_data->input_dev,
					ABS_MT_PRESSURE, p);
		input_report_abs(rmi4_data->input_dev,
					ABS_MT_TOUCH_MAJOR, w);
		input_report_abs(rmi4_data->input_dev,
					ABS_MT_TRACKING_ID, id);
		input_mt_sync(rmi4_data->input_dev);
		touch_count++;

		if (rmi4_data->number_resumes > 0 &&
			tmp_resume_i->send_touch.tv_sec == 0)
			getnstimeofday(&(tmp_resume_i->send_touch));
	}

	if (!touch_count)
		input_mt_sync(rmi4_data->input_dev);

	input_sync(rmi4_data->input_dev);

	return touch_count;
}

 /**
 * synaptics_rmi4_f11_abs_report()
 *
 * Called by synaptics_rmi4_report_touch() when valid Function $11
 * finger data has been detected.
 *
 * This function reads the Function $11 data registers, determines the
 * status of each finger supported by the Function, processes any
 * necessary coordinate manipulation, reports the finger data to
 * the input subsystem, and returns the number of fingers detected.
 */
static int synaptics_rmi4_f11_abs_report(struct synaptics_rmi4_data *rmi4_data,
		struct synaptics_rmi4_fn *fhandler)
{
	int retval;
	unsigned char touch_count = 0; /* number of touch points */
	unsigned char reg_index;
	unsigned char finger;
	unsigned char fingers_supported;
	unsigned char num_of_finger_status_regs;
	unsigned char finger_shift;
	unsigned char finger_status;
	unsigned char data_reg_blk_size;
	unsigned char finger_status_reg[3];
	unsigned char data[F11_STD_DATA_LEN];
	unsigned short data_addr;
	unsigned short data_offset;
	int x;
	int y;
	int wx;
	int wy;
	int z;
	struct timespec hw_time = ktime_to_timespec(ktime_get());

	/*
	 * The number of finger status registers is determined by the
	 * maximum number of fingers supported - 2 bits per finger. So
	 * the number of finger status registers to read is:
	 * register_count = ceil(max_num_of_fingers / 4)
	 */
	fingers_supported = fhandler->num_of_data_points;
	num_of_finger_status_regs = (fingers_supported + 3) / 4;
	data_addr = fhandler->full_addr.data_base;
	data_reg_blk_size = fhandler->size_of_data_register_block;

	retval = synaptics_rmi4_i2c_read(rmi4_data,
			data_addr,
			finger_status_reg,
			num_of_finger_status_regs);
	if (retval < 0)
		return 0;

	if (atomic_read(&rmi4_data->panel_off_flag))
		return 0;

	input_event(rmi4_data->input_dev, EV_SYN,
			SYN_TIME_SEC, hw_time.tv_sec);
	input_event(rmi4_data->input_dev, EV_SYN,
			SYN_TIME_NSEC, hw_time.tv_nsec);

	for (finger = 0; finger < fingers_supported; finger++) {
		reg_index = finger / 4;
		finger_shift = (finger % 4) * 2;
		finger_status = (finger_status_reg[reg_index] >> finger_shift)
				& MASK_2BIT;

		/*
		 * Each 2-bit finger status field represents the following:
		 * 00 = finger not present
		 * 01 = finger present and data accurate
		 * 10 = finger present but data may be inaccurate
		 * 11 = reserved
		 */
#ifdef TYPE_B_PROTOCOL
		input_mt_slot(rmi4_data->input_dev, finger);
		input_mt_report_slot_state(rmi4_data->input_dev,
					MT_TOOL_FINGER, finger_status);
#endif
		if (finger_status) {
			data_offset = data_addr +
					num_of_finger_status_regs +
					(finger * data_reg_blk_size);
			retval = synaptics_rmi4_i2c_read(rmi4_data,
					data_offset,
					data,
					data_reg_blk_size);
			if (retval < 0)
				goto end;

			x = (data[0] << 4) | (data[2] & MASK_4BIT);
			y = (data[1] << 4) | ((data[2] >> 4) & MASK_4BIT);
			wx = (data[3] & MASK_4BIT);
			wy = (data[3] >> 4) & MASK_4BIT;
			z = data[4];

			if (rmi4_data->board->x_flip)
				x = rmi4_data->sensor_max_x - x;
			if (rmi4_data->board->y_flip)
				y = rmi4_data->sensor_max_y - y;

			dev_dbg(&rmi4_data->i2c_client->dev,
					"%s: Finger %d:\n"
					"status = 0x%02x\n"
					"x = %d\n"
					"y = %d\n"
					"wx = %d\n"
					"wy = %d\n"
					"z = %d\n",
					__func__, finger,
					finger_status,
					x, y, wx, wy, z);

			input_report_abs(rmi4_data->input_dev,
					ABS_MT_POSITION_X, x);
			input_report_abs(rmi4_data->input_dev,
					ABS_MT_POSITION_Y, y);
			input_report_abs(rmi4_data->input_dev,
					ABS_MT_PRESSURE, z);

#ifdef REPORT_2D_W
			input_report_abs(rmi4_data->input_dev,
					ABS_MT_TOUCH_MAJOR, max(wx, wy));
			input_report_abs(rmi4_data->input_dev,
					ABS_MT_TOUCH_MINOR, min(wx, wy));
#endif
#ifndef TYPE_B_PROTOCOL
			input_mt_sync(rmi4_data->input_dev);
#endif
			touch_count++;
		}
	}

end:
#ifndef TYPE_B_PROTOCOL
	if (!touch_count)
		input_mt_sync(rmi4_data->input_dev);
#endif

	input_sync(rmi4_data->input_dev);

	return touch_count;
}

static void synaptics_rmi4_f1a_report(struct synaptics_rmi4_data *rmi4_data,
		struct synaptics_rmi4_fn *fhandler)
{
	int retval;
	unsigned char button;
	unsigned char index;
	unsigned char shift;
	unsigned char status;
	unsigned char *data;
	unsigned short data_addr = fhandler->full_addr.data_base;
	struct synaptics_rmi4_f1a_handle *f1a = fhandler->data;
	static bool current_status[MAX_NUMBER_OF_BUTTONS];
#ifdef NO_0D_WHILE_2D
	static bool before_2d_status[MAX_NUMBER_OF_BUTTONS];
	static bool while_2d_status[MAX_NUMBER_OF_BUTTONS];
#endif

	if (tsb_buff_clean_flag) {
		memset(current_status, 0, sizeof(current_status));
#ifdef NO_0D_WHILE_2D
		memset(before_2d_status, 0, sizeof(before_2d_status));
		memset(while_2d_status, 0, sizeof(while_2d_status));
#endif
		tsb_buff_clean_flag = 0;
	}

	retval = synaptics_rmi4_i2c_read(rmi4_data,
			data_addr,
			f1a->button_data_buffer,
			f1a->button_bitmask_size);
	if (retval < 0) {
		dev_err(&rmi4_data->i2c_client->dev,
				"%s: Failed to read button data registers\n",
				__func__);
		return;
	}

	if (atomic_read(&rmi4_data->panel_off_flag))
		return;

	data = f1a->button_data_buffer;

	for (button = 0; button < f1a->valid_button_count; button++) {
		index = button / 8;
		shift = button % 8;
		status = ((data[index] >> shift) & MASK_1BIT);

		if (current_status[button] == status)
			continue;
		else
			current_status[button] = status;

		dev_dbg(&rmi4_data->i2c_client->dev,
				"%s: Button %d (code %d) ->%d\n",
				__func__, button,
				f1a->button_map[button],
				status);
#ifdef NO_0D_WHILE_2D
		if (rmi4_data->fingers_on_2d == false) {
			if (status == 1) {
				before_2d_status[button] = 1;
			} else {
				if (while_2d_status[button] == 1) {
					while_2d_status[button] = 0;
					continue;
				} else {
					before_2d_status[button] = 0;
				}
			}
			input_report_key(rmi4_data->input_dev,
					f1a->button_map[button],
					status);
		} else {
			if (before_2d_status[button] == 1) {
				before_2d_status[button] = 0;
				input_report_key(rmi4_data->input_dev,
						f1a->button_map[button],
						status);
			} else {
				if (status == 1)
					while_2d_status[button] = 1;
				else
					while_2d_status[button] = 0;
			}
		}
#else
		input_report_key(rmi4_data->input_dev,
				f1a->button_map[button],
				status);
#endif
	}

	input_sync(rmi4_data->input_dev);

	return;
}

static void synaptics_rmi4_f01_handler(struct synaptics_rmi4_data *rmi4_data,
		struct synaptics_rmi4_fn *fhandler)
{
	int retval;
	unsigned short data_addr = fhandler->full_addr.data_base;
	struct synaptics_rmi4_f01_device_status status;

	retval = synaptics_rmi4_i2c_read(rmi4_data,
			data_addr,
			status.data,
			sizeof(status.data));
	if (retval < 0)
		return;

	switch (status.status_code) {
	case 0x00:
		printk(KERN_INFO "%s: No error.\n", __func__);
		break;

	case 0x01:
		printk(KERN_INFO "%s: Touch IC reset complete.\n", __func__);
		break;

	case 0x02:
		printk(KERN_ERR "%s: Touch IC configuration error--%s.\n",
			__func__, "check platform settings");
		break;

	case 0x03:
		printk(KERN_ERR "%s: Touch IC device failure.\n", __func__);
		break;

	case 0x04:
		printk(KERN_ERR "%s: Configuration CRC failure.\n", __func__);
		break;

	case 0x05:
		printk(KERN_ERR "%s: Firmware CRC failure.\n", __func__);
		break;

	case 0x06:
		printk(KERN_ERR "%s: CRC in progress.\n", __func__);
		break;

	default:
		printk(KERN_ERR "%s: Unknown error 0x%02X received.\n",
			__func__, status.status_code);
		break;
	}
}

 /**
 * synaptics_rmi4_report_touch()
 *
 * Called by synaptics_rmi4_sensor_report().
 *
 * This function calls the appropriate finger data reporting function
 * based on the function handler it receives and returns the number of
 * fingers detected.
 */
static void synaptics_rmi4_report_touch(struct synaptics_rmi4_data *rmi4_data,
		struct synaptics_rmi4_fn *fhandler,
		unsigned char *touch_count)
{
	unsigned char touch_count_2d;

	dev_dbg(&rmi4_data->i2c_client->dev,
			"%s: Function %02x reporting\n",
			__func__, fhandler->fn_number);

	switch (fhandler->fn_number) {
	case SYNAPTICS_RMI4_F01:
		synaptics_rmi4_f01_handler(rmi4_data, fhandler);
		break;

	case SYNAPTICS_RMI4_F11:
		touch_count_2d = synaptics_rmi4_f11_abs_report(rmi4_data,
				fhandler);

		*touch_count += touch_count_2d;

		if (touch_count_2d)
			rmi4_data->fingers_on_2d = true;
		else
			rmi4_data->fingers_on_2d = false;
		break;

	case SYNAPTICS_RMI4_F12:
		touch_count_2d = synaptics_rmi4_f12_abs_report(rmi4_data,
				fhandler);

		*touch_count += touch_count_2d;

		if (touch_count_2d)
			rmi4_data->fingers_on_2d = true;
		else
			rmi4_data->fingers_on_2d = false;
		break;

	case SYNAPTICS_RMI4_F1A:
		synaptics_rmi4_f1a_report(rmi4_data, fhandler);
		break;

	default:
		break;
	}

	return;
}

 /**
 * synaptics_rmi4_sensor_report()
 *
 * Called by synaptics_rmi4_irq().
 *
 * This function determines the interrupt source(s) from the sensor
 * and calls synaptics_rmi4_report_touch() with the appropriate
 * function handler for each function with valid data inputs.
 */
static int synaptics_rmi4_sensor_report(struct synaptics_rmi4_data *rmi4_data)
{
	int retval;
	unsigned char touch_count = 0;
	unsigned char intr[MAX_INTR_REGISTERS];
	unsigned int intr_status_mask;
	struct synaptics_rmi4_fn *fhandler;
	struct synaptics_rmi4_exp_fn *exp_fhandler;
	struct synaptics_rmi4_device_info *rmi;

	rmi = &(rmi4_data->rmi4_mod_info);

	/*
	 * Get interrupt status information from F01 Data1 register to
	 * determine the source(s) that are flagging the interrupt.
	 */
	retval = synaptics_rmi4_i2c_read(rmi4_data,
			rmi4_data->f01_data_base_addr + 1,
			intr,
			rmi4_data->num_of_intr_regs);
	if (retval < 0)
		return retval;

	/*
	 * Traverse the function handler list and service the source(s)
	 * of the interrupt accordingly.
	 */
	list_for_each_entry(fhandler, &rmi->support_fn_list, link) {
		if (fhandler->num_of_data_sources) {
			if (fhandler->intr_mask &
					intr[fhandler->intr_reg_num]) {
				synaptics_rmi4_report_touch(rmi4_data,
						fhandler, &touch_count);
			}
		}
	}

	batohui(&intr_status_mask, intr, rmi4_data->num_of_intr_regs);
	/*
	 * Go through external handlers list only when interrupt
	 * is not handled by currently active internal functions.
	 */
	if (intr_status_mask & (~rmi4_data->active_fn_intr_mask)) {
		mutex_lock(&exp_fn_ctrl.list_mutex);
		if (!list_empty(&exp_fn_ctrl.fn_list)) {
			list_for_each_entry(exp_fhandler,
					&exp_fn_ctrl.fn_list, link) {
				if (exp_fhandler->inserted &&
					(exp_fhandler->func_attn != NULL))
					exp_fhandler->func_attn(
							rmi4_data, intr[0]);
			}
		}
		mutex_unlock(&exp_fn_ctrl.list_mutex);
	}

	return touch_count;
}

 /**
 * synaptics_rmi4_irq()
 *
 * Called by the kernel when an interrupt occurs (when the sensor
 * asserts the attention irq).
 *
 * This function is the ISR thread and handles the acquisition
 * and the reporting of finger data when the presence of fingers
 * is detected.
 */
static irqreturn_t synaptics_rmi4_irq(int irq, void *data)
{
	struct synaptics_rmi4_data *rmi4_data = data;
	struct synaptics_rmi4_resume_info *tmp_resume_i;
	struct synaptics_rmi4_irq_info *tmp_q;

	if (rmi4_data->number_irq > 0) {
		rmi4_data->last_irq++;
		if (rmi4_data->last_irq >= rmi4_data->number_irq)
			rmi4_data->last_irq = 0;
		tmp_q =
			&(rmi4_data->irq_info[rmi4_data->last_irq]);
		getnstimeofday(&(tmp_q->irq_time));
	}

	if (rmi4_data->number_resumes > 0) {
		tmp_resume_i =
			&(rmi4_data->resume_info[rmi4_data->last_resume]);
		if (tmp_resume_i->isr.tv_sec == 0)
			getnstimeofday(&(tmp_resume_i->isr));
	}

	synaptics_rmi4_sensor_report(rmi4_data);

	return IRQ_HANDLED;
}

 /**
 * synaptics_rmi4_irq_enable()
 *
 * Called by synaptics_rmi4_probe() and the power management functions
 * in this driver and also exported to other expansion Function modules
 * such as rmi_dev.
 *
 * This function handles the enabling and disabling of the attention
 * irq including the setting up of the ISR thread.
 */
static int synaptics_rmi4_irq_enable(struct synaptics_rmi4_data *rmi4_data,
		bool enable)
{
	int retval = 0;
	unsigned char intr_status;
	const struct synaptics_dsx_platform_data *platform_data =
			rmi4_data->board;

	if (enable) {
		if (rmi4_data->irq_enabled)
			return retval;

		/* Clear interrupts first */
		retval = synaptics_rmi4_i2c_read(rmi4_data,
				rmi4_data->f01_data_base_addr + 1,
				&intr_status,
				rmi4_data->num_of_intr_regs);
		if (retval < 0)
			return retval;

		retval = request_threaded_irq(rmi4_data->irq, NULL,
				synaptics_rmi4_irq, platform_data->irq_flags,
				DRIVER_NAME, rmi4_data);
		if (retval < 0) {
			dev_err(&rmi4_data->i2c_client->dev,
					"%s: Failed to create irq thread\n",
					__func__);
			return retval;
		}

		dev_dbg(&rmi4_data->i2c_client->dev,
				"%s: Started irq thread\n", __func__);

		rmi4_data->irq_enabled = true;
	} else {
		if (rmi4_data->irq_enabled) {
			disable_irq(rmi4_data->irq);
			free_irq(rmi4_data->irq, rmi4_data);
			rmi4_data->irq_enabled = false;

		dev_dbg(&rmi4_data->i2c_client->dev,
				"%s: Stopped irq thread\n", __func__);
		}
	}

	return retval;
}

 /**
 * synaptics_rmi4_f11_init()
 *
 * Called by synaptics_rmi4_query_device().
 *
 * This funtion parses information from the Function 11 registers
 * and determines the number of fingers supported, x and y data ranges,
 * offset to the associated interrupt status register, interrupt bit
 * mask, and gathers finger data acquisition capabilities from the query
 * registers.
 */
static int synaptics_rmi4_f11_init(struct synaptics_rmi4_data *rmi4_data,
		struct synaptics_rmi4_fn *fhandler,
		struct synaptics_rmi4_fn_desc *fd,
		unsigned int intr_count)
{
	int retval;
	unsigned char ii;
	unsigned char intr_offset;
	unsigned char abs_data_size;
	unsigned char abs_data_blk_size;
	unsigned char query[F11_STD_QUERY_LEN];
	unsigned char control[F11_STD_CTRL_LEN];

	fhandler->fn_number = fd->fn_number;
	fhandler->num_of_data_sources = (fd->intr_src_count  & MASK_3BIT);

	retval = synaptics_rmi4_i2c_read(rmi4_data,
			fhandler->full_addr.query_base,
			query,
			sizeof(query));
	if (retval < 0)
		return retval;

	/* Maximum number of fingers supported */
	if ((query[1] & MASK_3BIT) <= 4)
		fhandler->num_of_data_points = (query[1] & MASK_3BIT) + 1;
	else if ((query[1] & MASK_3BIT) == 5)
		fhandler->num_of_data_points = 10;

	rmi4_data->num_of_fingers = fhandler->num_of_data_points;

	retval = synaptics_rmi4_i2c_read(rmi4_data,
			fhandler->full_addr.ctrl_base,
			control,
			sizeof(control));
	if (retval < 0)
		return retval;

	/* Maximum x and y */
	rmi4_data->sensor_max_x = ((control[6] & MASK_8BIT) << 0) |
			((control[7] & MASK_4BIT) << 8);
	rmi4_data->sensor_max_y = ((control[8] & MASK_8BIT) << 0) |
			((control[9] & MASK_4BIT) << 8);
	dev_dbg(&rmi4_data->i2c_client->dev,
			"%s: Function %02x max x = %d max y = %d\n",
			__func__, fhandler->fn_number,
			rmi4_data->sensor_max_x,
			rmi4_data->sensor_max_y);

	/* Reporting mode */
	if (!(control[0] & MASK_3BIT)) {
		pr_warn("Reporting mode: continuous\n");
	} else {
		dev_dbg(&rmi4_data->i2c_client->dev,
			"%s: thresholds: x=0x%x, y=0x%x\n",
			__func__, control[2], control[3]);
		/* Delta thresholds */
		if (control[2] > F11_DELTA_MAX)
			pr_warn("excessive x threshold: 0x%x\n", control[2]);
		if (control[3] > F11_DELTA_MAX)
			pr_warn("excessive y threshold: 0x%x\n", control[3]);
	}

	fhandler->intr_reg_num = (intr_count + 7) / 8;
	if (fhandler->intr_reg_num != 0)
		fhandler->intr_reg_num -= 1;

	/* Set an enable bit for each data source */
	intr_offset = intr_count % 8;
	fhandler->intr_mask = 0;
	for (ii = intr_offset;
			ii < ((fd->intr_src_count & MASK_3BIT) +
			intr_offset);
			ii++)
		fhandler->intr_mask |= 1 << ii;

	abs_data_size = query[5] & MASK_2BIT;
	abs_data_blk_size = 3 + (2 * (abs_data_size == 0 ? 1 : 0));
	fhandler->size_of_data_register_block = abs_data_blk_size;

#ifdef INPUT_PROP_DIRECT
	set_bit(INPUT_PROP_DIRECT, rmi4_data->input_dev->propbit);
#endif
	set_bit(EV_ABS, rmi4_data->input_dev->evbit);

	input_set_abs_params(rmi4_data->input_dev,
			ABS_MT_POSITION_X, 0,
			rmi4_data->sensor_max_x, 0, 0);
	input_set_abs_params(rmi4_data->input_dev,
			ABS_MT_POSITION_Y, 0,
			rmi4_data->sensor_max_y, 0, 0);
	input_set_abs_params(rmi4_data->input_dev,
			ABS_MT_PRESSURE, 0,
			255, 0, 0);
#ifdef REPORT_2D_W
	input_set_abs_params(rmi4_data->input_dev,
			ABS_MT_TOUCH_MAJOR, 0,
			15, 0, 0);
	input_set_abs_params(rmi4_data->input_dev,
			ABS_MT_TOUCH_MINOR, 0,
			15, 0, 0);
#endif
#ifdef TYPE_B_PROTOCOL
	input_mt_init_slots(rmi4_data->input_dev,
			rmi4_data->num_of_fingers);
#else
	input_set_abs_params(rmi4_data->input_dev,
			ABS_MT_TRACKING_ID, 0,
			rmi4_data->num_of_fingers - 1, 0, 0);
	input_set_events_per_packet(rmi4_data->input_dev, 64);
#endif

	return retval;
}

static int synaptics_rmi4_f1a_alloc_mem(struct synaptics_rmi4_data *rmi4_data,
		struct synaptics_rmi4_fn *fhandler)
{
	int retval;
	struct synaptics_rmi4_f1a_handle *f1a;

	f1a = kzalloc(sizeof(*f1a), GFP_KERNEL);
	if (!f1a) {
		dev_err(&rmi4_data->i2c_client->dev,
				"%s: Failed to alloc mem for function handle\n",
				__func__);
		return -ENOMEM;
	}

	fhandler->data = (void *)f1a;

	retval = synaptics_rmi4_i2c_read(rmi4_data,
			fhandler->full_addr.query_base,
			f1a->button_query.data,
			sizeof(f1a->button_query.data));
	if (retval < 0) {
		dev_err(&rmi4_data->i2c_client->dev,
				"%s: Failed to read query registers\n",
				__func__);
		return retval;
	}

	f1a->button_count = f1a->button_query.max_button_count + 1;
	f1a->button_bitmask_size = (f1a->button_count + 7) / 8;

	f1a->button_data_buffer = kcalloc(f1a->button_bitmask_size,
			sizeof(*(f1a->button_data_buffer)), GFP_KERNEL);
	if (!f1a->button_data_buffer) {
		dev_err(&rmi4_data->i2c_client->dev,
				"%s: Failed to alloc mem for data buffer\n",
				__func__);
		return -ENOMEM;
	}

	f1a->button_map = kcalloc(f1a->button_count,
			sizeof(*(f1a->button_map)), GFP_KERNEL);
	if (!f1a->button_map) {
		dev_err(&rmi4_data->i2c_client->dev,
				"%s: Failed to alloc mem for button map\n",
				__func__);
		return -ENOMEM;
	}

	return 0;
}

 /**
 * synaptics_rmi4_f12_init()
 *
 * Called by synaptics_rmi4_query_device().
 *
 * This funtion parses information from the Function 12 registers
 * and determines the number of fingers supported, x and y data ranges,
 * offset to the associated interrupt status register, interrupt bit
 * mask, and gathers finger data acquisition capabilities from the query
 * registers.
 */
static int synaptics_rmi4_f12_init(struct synaptics_rmi4_data *rmi4_data,
		struct synaptics_rmi4_fn *fhandler,
		struct synaptics_rmi4_fn_desc *fd,
		unsigned int intr_count)
{
	int retval;
	unsigned char ii;
	unsigned char intr_offset;

	fhandler->fn_number = fd->fn_number;
	fhandler->num_of_data_sources = (fd->intr_src_count  & MASK_3BIT);

	pr_debug("scan F12 ctrl registers\n");
	retval = synaptics_rmi4_scan_packet_reg_info(
			rmi4_data,
			fhandler->full_addr.query_base + 4,
			fhandler->full_addr.ctrl_base,
			&f12_ctrl_regs);
	if (retval < 0)
		return retval;

	retval = synaptics_rmi4_read_packet_regs(rmi4_data, &f12_ctrl_regs);
	if (retval < 0)
		return retval;

	/* Maximum number of fingers supported */
	if (f12_c23[1].present) {
		fhandler->num_of_data_points =
			f12_c23_1.max_num_reported_objects;
		rmi4_data->num_of_fingers = f12_c23_1.max_num_reported_objects;
	} else
		return -ENOENT;

	if (f12_c08[0].present) {
		rmi4_data->sensor_max_x =
			(f12_c08_0.max_x_msb << 8) | f12_c08_0.max_x_lsb;
		rmi4_data->sensor_max_y =
			(f12_c08_0.max_y_msb << 8) | f12_c08_0.max_y_lsb;
	} else
		return -ENOENT;

	fhandler->intr_reg_num = (intr_count + 7) / 8;
	if (fhandler->intr_reg_num != 0)
		fhandler->intr_reg_num -= 1;

	/* Set an enable bit for each data source */
	intr_offset = intr_count % 8;
	fhandler->intr_mask = 0;
	for (ii = intr_offset;
			ii < ((fd->intr_src_count & MASK_3BIT) +
			intr_offset);
			ii++)
		fhandler->intr_mask |= 1 << ii;

	/* Data size per touch */
	if (f12_c28[0].present) {
		for (ii = 0; ii < 8; ii++)
			if (f12_c28_0.reported_bytes_per_object & (1 << ii))
				fhandler->size_of_data_register_block++;
	} else
		return -ENOENT;

#ifdef INPUT_PROP_DIRECT
	set_bit(INPUT_PROP_DIRECT, rmi4_data->input_dev->propbit);
#endif
	set_bit(EV_ABS, rmi4_data->input_dev->evbit);

	input_set_abs_params(rmi4_data->input_dev,
			ABS_MT_POSITION_X, 0,
			rmi4_data->sensor_max_x, 0, 0);
	input_set_abs_params(rmi4_data->input_dev,
			ABS_MT_POSITION_Y, 0,
			rmi4_data->sensor_max_y, 0, 0);
	input_set_abs_params(rmi4_data->input_dev,
			ABS_MT_PRESSURE, 0,
			255, 0, 0);
#ifdef REPORT_2D_W
	input_set_abs_params(rmi4_data->input_dev,
			ABS_MT_TOUCH_MAJOR, 0,
			255, 0, 0);
#endif
	input_set_abs_params(rmi4_data->input_dev,
			ABS_MT_TRACKING_ID, 0,
			rmi4_data->num_of_fingers - 1, 0, 0);

	input_set_events_per_packet(rmi4_data->input_dev, 64);

	return retval;
}

static int synaptics_rmi4_cap_button_map(
				struct synaptics_rmi4_data *rmi4_data,
				struct synaptics_rmi4_fn *fhandler)
{
	unsigned char ii;
	struct synaptics_rmi4_f1a_handle *f1a = fhandler->data;
	const struct synaptics_dsx_platform_data *pdata = rmi4_data->board;

	if (!pdata->cap_button_map) {
		dev_err(&rmi4_data->i2c_client->dev,
				"%s: cap_button_map is \
				NULL in board file\n",
				__func__);
		return -ENODEV;
	} else if (!pdata->cap_button_map->map) {
		dev_err(&rmi4_data->i2c_client->dev,
				"%s: Button map is missing in board file\n",
				__func__);
		return -ENODEV;
	} else {
		if (pdata->cap_button_map->nbuttons !=
			f1a->button_count) {
			f1a->valid_button_count = min(f1a->button_count,
				pdata->cap_button_map->nbuttons);
		} else {
			f1a->valid_button_count = f1a->button_count;
		}

		set_bit(EV_KEY, rmi4_data->input_dev->evbit);

		for (ii = 0; ii < f1a->valid_button_count; ii++) {
			f1a->button_map[ii] =
					pdata->cap_button_map->map[ii];
			set_bit(f1a->button_map[ii],
					rmi4_data->input_dev->keybit);
			input_set_capability(rmi4_data->input_dev,
					EV_KEY, f1a->button_map[ii]);
		}
	}

	return 0;
}

static void synaptics_rmi4_f1a_kfree(struct synaptics_rmi4_fn *fhandler)
{
	struct synaptics_rmi4_f1a_handle *f1a = fhandler->data;

	if (f1a) {
		kfree(f1a->button_data_buffer);
		kfree(f1a->button_map);
		kfree(f1a);
		fhandler->data = NULL;
	}

	return;
}

static int synaptics_rmi4_f1a_init(struct synaptics_rmi4_data *rmi4_data,
		struct synaptics_rmi4_fn *fhandler,
		struct synaptics_rmi4_fn_desc *fd,
		unsigned int intr_count)
{
	int retval;
	unsigned char ii;
	unsigned short intr_offset;

	fhandler->fn_number = fd->fn_number;
	fhandler->num_of_data_sources = (fd->intr_src_count  & MASK_3BIT);

	fhandler->intr_reg_num = (intr_count + 7) / 8;
	if (fhandler->intr_reg_num != 0)
		fhandler->intr_reg_num -= 1;

	/* Set an enable bit for each data source */
	intr_offset = intr_count % 8;
	fhandler->intr_mask = 0;
	for (ii = intr_offset;
			ii < ((fd->intr_src_count & MASK_3BIT) +
			intr_offset);
			ii++)
		fhandler->intr_mask |= 1 << ii;

	retval = synaptics_rmi4_f1a_alloc_mem(rmi4_data, fhandler);
	if (retval < 0)
		goto error_exit;

	retval = synaptics_rmi4_cap_button_map(rmi4_data, fhandler);
	if (retval < 0)
		goto error_exit;

	rmi4_data->button_0d_enabled = 1;

	return 0;

error_exit:
	synaptics_rmi4_f1a_kfree(fhandler);

	return retval;
}

static int synaptics_rmi4_alloc_fh(struct synaptics_rmi4_fn **fhandler,
		struct synaptics_rmi4_fn_desc *rmi_fd, int page_number)
{
	*fhandler = kzalloc(sizeof(**fhandler), GFP_KERNEL);
	if (!(*fhandler))
		return -ENOMEM;

	(*fhandler)->full_addr.data_base =
			(rmi_fd->data_base_addr |
			(page_number << 8));
	(*fhandler)->full_addr.ctrl_base =
			(rmi_fd->ctrl_base_addr |
			(page_number << 8));
	(*fhandler)->full_addr.cmd_base =
			(rmi_fd->cmd_base_addr |
			(page_number << 8));
	(*fhandler)->full_addr.query_base =
			(rmi_fd->query_base_addr |
			(page_number << 8));

	return 0;
}

 /**
 * synaptics_rmi4_query_device()
 *
 * Called by synaptics_rmi4_probe().
 *
 * This funtion scans the page description table, records the offsets
 * to the register types of Function $01, sets up the function handlers
 * for Function $11 and Function $12, determines the number of interrupt
 * sources from the sensor, adds valid Functions with data inputs to the
 * Function linked list, parses information from the query registers of
 * Function $01, and enables the interrupt sources from the valid Functions
 * with data inputs.
 */
static int synaptics_rmi4_query_device(struct synaptics_rmi4_data *rmi4_data)
{
	int retval;
	unsigned char page_number;
	unsigned char intr_count = 0;
	unsigned char data_sources = 0;
	unsigned char f01_query[F01_STD_QUERY_LEN] = {0};
	unsigned short pdt_entry_addr;
	struct synaptics_rmi4_fn_desc rmi_fd;
	struct synaptics_rmi4_fn *fhandler;
	struct synaptics_rmi4_device_info *rmi;
	struct f34_properties f34_query;
	struct synaptics_rmi4_f01_device_status status;

	rmi = &(rmi4_data->rmi4_mod_info);

	INIT_LIST_HEAD(&rmi->support_fn_list);

	/* Scan the page description tables of the pages to service */
	for (page_number = 0; page_number < PAGES_TO_SERVICE; page_number++) {
		for (pdt_entry_addr = PDT_START; pdt_entry_addr > PDT_END;
				pdt_entry_addr -= PDT_ENTRY_SIZE) {
			pdt_entry_addr |= (page_number << 8);

			retval = synaptics_rmi4_i2c_read(rmi4_data,
					pdt_entry_addr,
					(unsigned char *)&rmi_fd,
					sizeof(rmi_fd));
			if (retval < 0)
				return retval;

			fhandler = NULL;

			if (rmi_fd.fn_number == 0) {
				dev_dbg(&rmi4_data->i2c_client->dev,
						"%s: Reached end of PDT\n",
						__func__);
				break;
			}

			dev_dbg(&rmi4_data->i2c_client->dev,
					"%s: F%02x found (page %d)\n",
					__func__, rmi_fd.fn_number,
					page_number);

			switch (rmi_fd.fn_number) {
			case SYNAPTICS_RMI4_F34:
				retval = synaptics_rmi4_i2c_read(rmi4_data,
						rmi_fd.query_base_addr +
							F34_PROPERTIES_OFFSET,
						&f34_query.data[0],
						sizeof(f34_query));
				if (retval < 0)
					return retval;

				if (f34_query.has_config_id) {
					retval = synaptics_rmi4_i2c_read(
							rmi4_data,
							rmi_fd.ctrl_base_addr,
							rmi->config_id,
							sizeof(rmi->config_id));
					if (retval < 0)
						return retval;
				}
				break;

			case SYNAPTICS_RMI4_F01:
				rmi4_data->f01_query_base_addr =
						rmi_fd.query_base_addr;
				rmi4_data->f01_ctrl_base_addr =
						rmi_fd.ctrl_base_addr;
				rmi4_data->f01_data_base_addr =
						rmi_fd.data_base_addr;
				rmi4_data->f01_cmd_base_addr =
						rmi_fd.cmd_base_addr;

				retval = synaptics_rmi4_i2c_read(rmi4_data,
						rmi4_data->f01_data_base_addr,
						status.data,
						sizeof(status.data));
				if (retval < 0)
					return retval;

				synaptics_rmi4_sensor_multi_touch(
						rmi4_data, SYNAPTICS_RMI4_F01);

				rmi4_data->in_bootloader =
						status.flash_prog == 1;
				break;

			case SYNAPTICS_RMI4_F11:
				if (rmi_fd.intr_src_count == 0)
					break;

				retval = synaptics_rmi4_alloc_fh(&fhandler,
						&rmi_fd, page_number);
				if (retval < 0) {
					dev_err(&rmi4_data->i2c_client->dev,
							"%s: Failed to alloc for F%d\n",
							__func__,
							rmi_fd.fn_number);
					return retval;
				}

				retval = synaptics_rmi4_f11_init(rmi4_data,
						fhandler, &rmi_fd, intr_count);
				if (retval < 0)
					return retval;
				break;

			case SYNAPTICS_RMI4_F12:
				if (rmi_fd.intr_src_count == 0)
					break;

				retval = synaptics_rmi4_alloc_fh(&fhandler,
						&rmi_fd, page_number);
				if (retval < 0) {
					dev_err(&rmi4_data->i2c_client->dev,
							"%s: Failed to alloc for F%d\n",
							__func__,
							rmi_fd.fn_number);
					return retval;
				}

				retval = synaptics_rmi4_f12_init(rmi4_data,
						fhandler, &rmi_fd, intr_count);
				if (retval < 0)
					return retval;

				synaptics_rmi4_sensor_multi_touch(
						rmi4_data, SYNAPTICS_RMI4_F12);
				break;

			case SYNAPTICS_RMI4_F1A:
				if (rmi_fd.intr_src_count == 0)
					break;

				retval = synaptics_rmi4_alloc_fh(&fhandler,
						&rmi_fd, page_number);
				if (retval < 0) {
					dev_err(&rmi4_data->i2c_client->dev,
							"%s: Failed to alloc for F%d\n",
							__func__,
							rmi_fd.fn_number);
					return retval;
				}

				retval = synaptics_rmi4_f1a_init(rmi4_data,
						fhandler, &rmi_fd, intr_count);
				switch (retval) {
				case -ENOMEM:
					return retval;
				case -ENODEV:
					/* removing buttons handler if there */
					/* were no key codes in platform data */
					kfree(fhandler);
					fhandler = NULL;
					rmi_fd.intr_src_count = 0;
					break;
				}
				break;
			}

			/* Accumulate the interrupt count */
			intr_count += (rmi_fd.intr_src_count & MASK_3BIT);

			if (fhandler && rmi_fd.intr_src_count) {
				list_add_tail(&fhandler->link,
						&rmi->support_fn_list);
			}
		}
	}

	rmi4_data->num_of_intr_regs = (intr_count + 7) / 8;
	dev_dbg(&rmi4_data->i2c_client->dev,
			"%s: Number of interrupt registers = %d\n",
			__func__, rmi4_data->num_of_intr_regs);

	retval = synaptics_rmi4_i2c_read(rmi4_data,
			rmi4_data->f01_query_base_addr,
			f01_query,
			sizeof(f01_query));
	if (retval < 0)
		return retval;

	/* RMI Version 4.0 currently supported */
	rmi->version_major = 4;
	rmi->version_minor = 0;

	rmi->manufacturer_id = f01_query[0];
	rmi->product_props = f01_query[1];
	memcpy(&rmi->product_info[0], &f01_query[2],
					SYNAPTICS_RMI4_PRODUCT_INFO_SIZE);
	memcpy(rmi->serial, &f01_query[4], SYNAPTICS_RMI4_SERIAL_SIZE);
	memcpy(rmi->product_id_string, &f01_query[11],
					SYNAPTICS_RMI4_PRODUCT_ID_SIZE);
	rmi->product_id_string[SYNAPTICS_RMI4_PRODUCT_ID_SIZE] = 0;

	/* handle wrongfully programmed product id strings here */
	synaptics_dsx_darn_product_string(rmi->product_id_string,
					SYNAPTICS_RMI4_PRODUCT_ID_SIZE);

	retval = synaptics_rmi4_i2c_read(rmi4_data,
			rmi4_data->f01_query_base_addr+PACKAGE_ID_OFFSET,
			rmi->package_id,
			sizeof(rmi->package_id));
	if (retval < 0)
		return retval;

	retval = synaptics_rmi4_i2c_read(rmi4_data,
			rmi4_data->f01_query_base_addr+FW_VERSION_OFFSET,
			rmi->build_id,
			sizeof(rmi->build_id));
	if (retval < 0)
		return retval;

	if (rmi->manufacturer_id != 1) {
		dev_err(&rmi4_data->i2c_client->dev,
				"%s: Non-Synaptics device found, manufacturer ID = %d\n",
				__func__, rmi->manufacturer_id);
	}

	if (!rmi4_data->in_bootloader && !rmi4_data->input_registered) {
		retval = input_register_device(rmi4_data->input_dev);
		if (retval < 0) {
			dev_err(&rmi4_data->i2c_client->dev,
				"%s: Failed to register input device\n",
				__func__);
			return retval;
		}
		rmi4_data->input_registered = true;
	}

	memset(rmi4_data->intr_mask, 0x00, sizeof(rmi4_data->intr_mask));

	/*
	 * Map out the interrupt bit masks for the interrupt sources
	 * from the registered function handlers.
	 */
	list_for_each_entry(fhandler, &rmi->support_fn_list, link)
		data_sources += fhandler->num_of_data_sources;
	if (data_sources) {
		list_for_each_entry(fhandler, &rmi->support_fn_list, link) {
			if (fhandler->num_of_data_sources) {
				rmi4_data->intr_mask[fhandler->intr_reg_num] |=
						fhandler->intr_mask;
			}
		}
	}

	/* interrupt mask for currently active functions */
	batohui(&rmi4_data->active_fn_intr_mask,
			rmi4_data->intr_mask, rmi4_data->num_of_intr_regs);
	pr_debug("active func intr_mask 0x%x\n",
			rmi4_data->active_fn_intr_mask);

	if (rmi4_data->in_bootloader)
		pr_info("Product: %s is in bootloader mode\n",
			rmi->product_id_string);
	else {
		unsigned int config_id, firmware_id;

		batohui(&firmware_id, rmi->build_id, sizeof(rmi->build_id));
		batohui(&config_id, rmi->config_id, sizeof(config_id));
		pr_info("Product: %s, firmware id: %x, config id: %08x\n",
			rmi->product_id_string, firmware_id, config_id);
	}

	return 0;
}

static void synaptics_rmi4_cleanup(struct synaptics_rmi4_data *rmi4_data)
{
	struct synaptics_rmi4_fn *fhandler, *next_list_entry;
	struct synaptics_rmi4_device_info *rmi;

	rmi = &(rmi4_data->rmi4_mod_info);

	list_for_each_entry_safe(fhandler, next_list_entry,
					&rmi->support_fn_list, link) {
		if (fhandler->fn_number == SYNAPTICS_RMI4_F1A)
			synaptics_rmi4_f1a_kfree(fhandler);
		else
			kfree(fhandler->data);
		list_del(&fhandler->link);
		kfree(fhandler);
	}
}

static void synaptics_dsx_on_resume(struct synaptics_rmi4_data *rmi4_data)
{
	/*
	 * Enforce touch release event report to work-around such event
	 * missing while touch IC is off.
	 */
#ifdef TYPE_B_PROTOCOL
	int i;
	for (i = 0; i < rmi4_data->num_of_fingers; i++) {
		input_mt_slot(rmi4_data->input_dev, i);
		input_mt_report_slot_state(rmi4_data->input_dev,
				MT_TOOL_FINGER, false);
	}
#else
	input_mt_sync(rmi4_data->input_dev);
#endif
	input_sync(rmi4_data->input_dev);

	/* reset some TSB global vars like fingers_on_2d after resume
	 * of reset touch IC
	 */
	if (rmi4_data->button_0d_enabled) {
		tsb_buff_clean_flag = 1;
		rmi4_data->fingers_on_2d = false;
	}
}

static int synaptics_rmi4_reset_device(struct synaptics_rmi4_data *rmi4_data,
		unsigned char *f01_cmd_base_addr)
{
	int current_state, retval;
	bool need_to_query = false;
	unsigned char command = 0x01;

	current_state = synaptics_dsx_get_state_safe(rmi4_data);
	if (current_state == STATE_UNKNOWN) {
		synaptics_rmi4_cleanup(rmi4_data);

		if (rmi4_data->input_registered) {
			input_unregister_device(rmi4_data->input_dev);
			rmi4_data->input_dev = NULL;
			rmi4_data->input_registered = false;

			pr_debug("de-allocated input device\n");
		}
		need_to_query = true;
	}

	if (rmi4_data->hw_reset)
		/* do hard reset instead of soft */
		synaptics_dsx_ic_reset(rmi4_data, true);
	else {
		retval = synaptics_rmi4_i2c_write(rmi4_data,
			f01_cmd_base_addr ? *f01_cmd_base_addr :
			rmi4_data->f01_cmd_base_addr,
			&command,
			sizeof(command));
		if (retval < 0) {
			dev_err(&rmi4_data->i2c_client->dev,
				"%s: Failed to issue reset command, error = %d\n",
				__func__, retval);
			return retval;
		}
		msleep(100);
	}

	if (need_to_query) {
		if (!rmi4_data->input_dev) {
			retval = synaptics_dsx_alloc_input(rmi4_data);
			if (retval < 0) {
				dev_err(&rmi4_data->i2c_client->dev,
					"%s: Failed to allocate input device\n",
					__func__);
				return retval;
			}
		}

		retval = synaptics_rmi4_query_device(rmi4_data);
		if (retval < 0) {
			dev_err(&rmi4_data->i2c_client->dev,
				"%s: Failed to query device\n",
				__func__);
			return retval;
		}
		/* kick off detection work after touch ic changes its mode */
		if (exp_fn_ctrl.det_workqueue)
			queue_delayed_work(exp_fn_ctrl.det_workqueue,
					&exp_fn_ctrl.det_work, 0);
	}

	return 0;
}

/**
* synaptics_rmi4_detection_work()
*
* Called by the kernel at the scheduled time.
*
* This function is armed by synaptics_new_function call. It checks for
* the insertion and removal of other expansion Function modules such as
* rmi_dev and calls their initialization and removal callback functions
* accordingly.
*/
static void synaptics_rmi4_detection_work(struct work_struct *work)
{
	struct synaptics_rmi4_exp_fn *exp_fhandler, *next_list_entry;
	struct synaptics_rmi4_data *rmi4_data;
	int state;

	mutex_lock(&exp_fn_ctrl_mutex);
	rmi4_data = exp_fn_ctrl.rmi4_data_ptr;
	mutex_unlock(&exp_fn_ctrl_mutex);

	if (rmi4_data == NULL) {
		if (exp_fn_ctrl.det_workqueue)
			queue_delayed_work(exp_fn_ctrl.det_workqueue,
				&exp_fn_ctrl.det_work,
				msecs_to_jiffies(EXP_FN_DET_INTERVAL));
		return;
	}

	mutex_lock(&exp_fn_ctrl.list_mutex);
	if (list_empty(&exp_fn_ctrl.fn_list))
		goto release_mutex;

	list_for_each_entry_safe(exp_fhandler,
				next_list_entry,
				&exp_fn_ctrl.fn_list,
				link) {
		if ((exp_fhandler->func_init != NULL) &&
				(exp_fhandler->inserted == false)) {
			if (rmi4_data->in_bootloader &&
			   (exp_fhandler->mode == IC_MODE_UI))
				continue;
			if (rmi4_data->sensor_sleep)
				synaptics_rmi4_sensor_wake(rmi4_data);
			exp_fhandler->func_init(rmi4_data);
			state = synaptics_dsx_get_state_safe(rmi4_data);
			if (state == STATE_STANDBY)
				synaptics_rmi4_sensor_sleep(rmi4_data);
			exp_fhandler->inserted = true;
		} else if ((exp_fhandler->func_init == NULL) &&
			   (exp_fhandler->inserted == true)) {
			exp_fhandler->func_remove(rmi4_data);
			list_del(&exp_fhandler->link);
			kfree(exp_fhandler);
		}
	}

release_mutex:
	mutex_unlock(&exp_fn_ctrl.list_mutex);

	return;
}

/**
* synaptics_rmi4_new_function()
*
* Called by other expansion Function modules in their module init and
* module exit functions.
*
* This function is used by other expansion Function modules such as
* rmi_dev to register themselves with the driver by providing their
* initialization and removal callback function pointers so that they
* can be inserted or removed dynamically at module init and exit times,
* respectively.
*/
void synaptics_rmi4_new_function(enum exp_fn fn_type, bool insert,
		int (*func_init)(struct synaptics_rmi4_data *rmi4_data),
		void (*func_remove)(struct synaptics_rmi4_data *rmi4_data),
		void (*func_attn)(struct synaptics_rmi4_data *rmi4_data,
		unsigned char intr_mask), enum ic_modes mode)
{
	struct synaptics_rmi4_exp_fn *exp_fhandler;

	mutex_lock(&exp_fn_ctrl_mutex);
	if (!exp_fn_ctrl.inited) {
		mutex_init(&exp_fn_ctrl.list_mutex);
		INIT_LIST_HEAD(&exp_fn_ctrl.fn_list);
		exp_fn_ctrl.det_workqueue =
			create_singlethread_workqueue("rmi_det_workqueue");
		if (IS_ERR_OR_NULL(exp_fn_ctrl.det_workqueue))
			pr_err("unable to create a workqueue\n");
		INIT_DELAYED_WORK(&exp_fn_ctrl.det_work,
			synaptics_rmi4_detection_work);
		exp_fn_ctrl.inited = true;
	}
	mutex_unlock(&exp_fn_ctrl_mutex);

	mutex_lock(&exp_fn_ctrl.list_mutex);
	if (insert) {
		exp_fhandler = kzalloc(sizeof(*exp_fhandler), GFP_KERNEL);
		if (!exp_fhandler) {
			pr_err("failed to alloc mem for expansion function\n");
			goto exit;
		}
		exp_fhandler->fn_type = fn_type;
		exp_fhandler->func_init = func_init;
		exp_fhandler->func_attn = func_attn;
		exp_fhandler->func_remove = func_remove;
		exp_fhandler->inserted = false;
		exp_fhandler->mode = mode;
		list_add_tail(&exp_fhandler->link, &exp_fn_ctrl.fn_list);
	} else {
		list_for_each_entry(exp_fhandler, &exp_fn_ctrl.fn_list, link) {
			if (exp_fhandler->func_init == func_init) {
				exp_fhandler->inserted = false;
				exp_fhandler->func_init = NULL;
				exp_fhandler->func_attn = NULL;
				goto exit;
			}
		}
	}

exit:
	mutex_unlock(&exp_fn_ctrl.list_mutex);
	if (exp_fn_ctrl.det_workqueue)
		queue_delayed_work(exp_fn_ctrl.det_workqueue,
					&exp_fn_ctrl.det_work, 0);
	return;
}
EXPORT_SYMBOL(synaptics_rmi4_new_function);

 /**
 * synaptics_rmi4_probe()
 *
 * Called by the kernel when an association with an I2C device of the
 * same name is made (after doing i2c_add_driver).
 *
 * This funtion allocates and initializes the resources for the driver
 * as an input driver, turns on the power to the sensor, queries the
 * sensor for its supported Functions and characteristics, registers
 * the driver to the input subsystem, sets up the interrupt, and creates
 * a work queue for detection of other expansion Function modules.
 */
static int __devinit synaptics_rmi4_probe(struct i2c_client *client,
		const struct i2c_device_id *dev_id)
{
	int retval;
	unsigned char attr_count;
	struct synaptics_rmi4_data *rmi4_data;
	struct synaptics_rmi4_device_info *rmi;
	struct synaptics_dsx_platform_data *platform_data;

	if (!i2c_check_functionality(client->adapter,
			I2C_FUNC_SMBUS_BYTE_DATA)) {
		dev_err(&client->dev,
				"%s: SMBus byte data not supported\n",
				__func__);
		return -EIO;
	}

	rmi4_data = kzalloc(sizeof(*rmi4_data), GFP_KERNEL);
	if (!rmi4_data) {
		dev_err(&client->dev,
				"%s: Failed to alloc mem for rmi4_data\n",
				__func__);
		return -ENOMEM;
	}

	if (client->dev.of_node)
		platform_data = synaptics_dsx_of_init(client, rmi4_data);
	else {
		platform_data = client->dev.platform_data;
		rmi4_data->purge_enabled =  platform_data->purge_enabled;
		rmi4_data->reset_on_resume = platform_data->reset_on_resume;
		rmi4_data->one_touch_enabled = platform_data->one_touch_enabled;
		rmi4_data->normal_mode = platform_data->normal_mode;
		rmi4_data->hw_reset = platform_data->hw_reset;
	}

	if (!platform_data) {
		dev_err(&client->dev,
				"%s: No platform data found\n",
				__func__);
		kfree(rmi4_data);
		return -EINVAL;
	}

	rmi = &(rmi4_data->rmi4_mod_info);

	rmi4_data->i2c_client = client;
	rmi4_data->current_page = MASK_8BIT;
	rmi4_data->board = platform_data;
	rmi4_data->touch_stopped = false;
	rmi4_data->sensor_sleep = false;
	rmi4_data->irq_enabled = false;

	rmi4_data->i2c_read = synaptics_rmi4_i2c_read;
	rmi4_data->i2c_write = synaptics_rmi4_i2c_write;
	rmi4_data->set_state = synaptics_dsx_sensor_state;
	rmi4_data->ready_state = synaptics_dsx_sensor_ready_state;
	rmi4_data->irq_enable = synaptics_rmi4_irq_enable;
	rmi4_data->reset_device = synaptics_rmi4_reset_device;

	/* Initialize some resume debug information */
	rmi4_data->resume_info = kzalloc(
		sizeof(struct synaptics_rmi4_resume_info) *
			 MAX_NUMBER_TRACKED_RESUMES,
		GFP_KERNEL);
	if (!rmi4_data->resume_info) {
		dev_err(&client->dev,
		"%s: Failed to allocate memory for resume information\n",
				__func__);
		rmi4_data->number_resumes = 0;
	} else
		rmi4_data->number_resumes = MAX_NUMBER_TRACKED_RESUMES;
	rmi4_data->last_resume = -1;

	/* Initialize some interrupit timing debug information */
	rmi4_data->irq_info = kzalloc(
		sizeof(struct synaptics_rmi4_irq_info) *
			 MAX_NUMBER_TRACKED_IRQS,
		GFP_KERNEL);
	if (!rmi4_data->irq_info) {
		dev_err(&client->dev,
		"%s: Failed to allocate memory for IRQ debug information\n",
				__func__);
		rmi4_data->number_irq = 0;
	} else
		rmi4_data->number_irq = MAX_NUMBER_TRACKED_IRQS;
	rmi4_data->last_irq = -1;

	mutex_init(&(rmi4_data->rmi4_io_ctrl_mutex));
	mutex_init(&(rmi4_data->state_mutex));

	if (platform_data->gpio_config)
		retval = platform_data->gpio_config(platform_data, true);
	else {
		retval = gpio_request(platform_data->reset_gpio,
						RESET_GPIO_NAME);
		if (!retval)
			retval = gpio_direction_output(
						platform_data->reset_gpio, 1);
	}
	if (retval < 0) {
		dev_err(&client->dev,
				"%s: Failed to configure GPIO\n",
				__func__);
		goto err_input_device;
	}

	/* get irq number initialized before calling reset */
	rmi4_data->irq = gpio_to_irq(platform_data->irq_gpio);

	i2c_set_clientdata(client, rmi4_data);

	retval = synaptics_dsx_alloc_input(rmi4_data);
	if (retval < 0) {
		dev_err(&client->dev,
				"%s: Failed to allocate input device\n",
				__func__);
		goto err_input_device;
	}

	rmi4_data->regulator = regulator_get(&client->dev, "touch_vdd");
	if (IS_ERR(rmi4_data->regulator)) {
		dev_err(&client->dev,
				"%s: Failed to get regulator\n",
				__func__);
	} else {
		platform_data->regulator_en = true;
		regulator_enable(rmi4_data->regulator);
		pr_debug("touch-vdd regulator is %s\n",
			regulator_is_enabled(rmi4_data->regulator) ?
			"on" : "off");
	}

	retval = synaptics_dsx_ic_reset(rmi4_data, true);
	if (retval > 0)
		pr_debug("successful reset took %dms\n", retval);

	retval = synaptics_rmi4_query_device(rmi4_data);
	if (retval < 0) {
		dev_err(&client->dev,
				"%s: Failed to query device\n",
				__func__);
		goto err_query_device;
	}

	init_waitqueue_head(&rmi4_data->wait);

#if defined(CONFIG_MMI_PANEL_NOTIFICATIONS)
	rmi4_data->panel_nb.suspend = synaptics_rmi4_suspend;
	rmi4_data->panel_nb.resume = synaptics_rmi4_resume;
	rmi4_data->panel_nb.dev = &client->dev;
	if (!mmi_panel_register_notifier(&rmi4_data->panel_nb))
		pr_info("registered MMI panel notifier\n");
	else
		dev_err(&client->dev,
				"%s: Unable to register MMI notifier\n",
				__func__);
#elif defined(CONFIG_FB)
	rmi4_data->panel_nb.notifier_call = synaptics_dsx_panel_cb;
	if (!fb_register_client(&rmi4_data->panel_nb))
		pr_debug("registered FB notifier\n");
	else
		dev_err(&client->dev,
				"%s: Unable to register FB notifier\n",
				__func__);
#endif
	mutex_lock(&exp_fn_ctrl_mutex);
	if (!exp_fn_ctrl.inited) {
		mutex_init(&exp_fn_ctrl.list_mutex);
		INIT_LIST_HEAD(&exp_fn_ctrl.fn_list);
		exp_fn_ctrl.det_workqueue =
			create_singlethread_workqueue("rmi_det_workqueue");
		if (IS_ERR_OR_NULL(exp_fn_ctrl.det_workqueue))
			pr_err("unable to create a workqueue\n");
		INIT_DELAYED_WORK(&exp_fn_ctrl.det_work,
			synaptics_rmi4_detection_work);
		exp_fn_ctrl.inited = true;
	}
	mutex_unlock(&exp_fn_ctrl_mutex);

	for (attr_count = 0; attr_count < ARRAY_SIZE(attrs); attr_count++) {
		retval = sysfs_create_file(&rmi4_data->i2c_client->dev.kobj,
				&attrs[attr_count].attr);
		if (retval < 0) {
			dev_err(&client->dev,
					"%s: Failed to create sysfs attributes\n",
					__func__);
			goto err_sysfs;
		}
	}

	synaptics_dsx_sensor_ready_state(rmi4_data, true);

	mutex_lock(&exp_fn_ctrl_mutex);
	exp_fn_ctrl.rmi4_data_ptr = rmi4_data;
	mutex_unlock(&exp_fn_ctrl_mutex);

	return retval;

err_sysfs:
	for (attr_count--; attr_count >= 0; attr_count--) {
		sysfs_remove_file(&rmi4_data->i2c_client->dev.kobj,
				&attrs[attr_count].attr);
	}

#if defined(CONFIG_MMI_PANEL_NOTIFICATIONS)
	mmi_panel_unregister_notifier(&rmi4_data->panel_nb);
#elif defined(CONFIG_FB)
	fb_unregister_client(&rmi4_data->panel_nb);
#endif

err_query_device:
	if (rmi4_data->input_registered) {
		input_unregister_device(rmi4_data->input_dev);
		rmi4_data->input_dev = NULL;
	}

	if (platform_data->regulator_en) {
		regulator_disable(rmi4_data->regulator);
		regulator_put(rmi4_data->regulator);
	}

	synaptics_rmi4_cleanup(rmi4_data);
	input_free_device(rmi4_data->input_dev);

err_input_device:
	kfree(rmi4_data);

	return retval;
}

 /**
 * synaptics_rmi4_remove()
 *
 * Called by the kernel when the association with an I2C device of the
 * same name is broken (when the driver is unloaded).
 *
 * This funtion terminates the work queue, stops sensor data acquisition,
 * frees the interrupt, unregisters the driver from the input subsystem,
 * turns off the power to the sensor, and frees other allocated resources.
 */
static int __devexit synaptics_rmi4_remove(struct i2c_client *client)
{
	unsigned char attr_count;
	struct synaptics_rmi4_data *rmi4_data = i2c_get_clientdata(client);
	struct synaptics_rmi4_device_info *rmi;
	const struct synaptics_dsx_platform_data *platform_data =
			rmi4_data->board;

	rmi = &(rmi4_data->rmi4_mod_info);

	if (exp_fn_ctrl.inited) {
		cancel_delayed_work_sync(&exp_fn_ctrl.det_work);
		flush_workqueue(exp_fn_ctrl.det_workqueue);
		destroy_workqueue(exp_fn_ctrl.det_workqueue);
	}

	rmi4_data->touch_stopped = true;
	wake_up(&rmi4_data->wait);

	synaptics_rmi4_irq_enable(rmi4_data, false);

	for (attr_count = 0; attr_count < ARRAY_SIZE(attrs); attr_count++) {
		sysfs_remove_file(&rmi4_data->i2c_client->dev.kobj,
				&attrs[attr_count].attr);
	}

	if (rmi4_data->input_registered) {
		input_unregister_device(rmi4_data->input_dev);
		rmi4_data->input_dev = NULL;
	}

	if (platform_data->regulator_en) {
		regulator_disable(rmi4_data->regulator);
		regulator_put(rmi4_data->regulator);
	}

#if defined(CONFIG_MMI_PANEL_NOTIFICATIONS)
	mmi_panel_unregister_notifier(&rmi4_data->panel_nb);
#elif defined(CONFIG_FB)
	fb_unregister_client(&rmi4_data->panel_nb);
#endif
	synaptics_rmi4_cleanup(rmi4_data);
	kfree(rmi4_data);

	return 0;
}

static void synaptics_rmi4_sensor_multi_touch(
		struct synaptics_rmi4_data *rmi4_data, unsigned char function)
{
	int retval;

	switch (function) {
	case SYNAPTICS_RMI4_F12:
		/* Store multitouch config registers */
		hob_data.f12_c20_0 = f12_c20_0;
		hob_data.f12_c23_0 = f12_c23_0;
		hob_data.f12_c23_1 = f12_c23_1;

		if (!hob_data.f12_c20_0.x_suppression)
			hob_data.f12_c20_0.x_suppression = X_MT_SUPPRESSION;

		if (!hob_data.f12_c20_0.y_suppression)
			hob_data.f12_c20_0.y_suppression = Y_MT_SUPPRESSION;
		break;
	case SYNAPTICS_RMI4_F01:
		retval = synaptics_rmi4_i2c_read(rmi4_data,
			rmi4_data->f01_ctrl_base_addr + 5,
			&hob_data.f01_c9,
			sizeof(hob_data.f01_c9));
		if (retval < 0)
			pr_err("error storing recalibration interval\n");
		break;
	}
}

 /**
 * synaptics_rmi4_sensor_one_touch()
 *
 * Called on suspend and resume.
 *
 * This function reconfigures finger data acquisition.
 */
static void synaptics_rmi4_sensor_one_touch(
		struct synaptics_rmi4_data *rmi4_data, bool enable)
{
	int retval;
	unsigned char recalibration;
	if (enable) {
		f12_c20_0.x_suppression = X_1T_SUPPRESSION;
		f12_c20_0.y_suppression = Y_1T_SUPPRESSION;
		f12_c23_0.data[0] = TYPE_FINGER | TYPE_STYLUS;
		f12_c23_1.max_num_reported_objects = 1;
		recalibration = ONE_TOUCH_RECALIBRATION;
	} else {
		f12_c20_0 = hob_data.f12_c20_0;
		f12_c23_0 = hob_data.f12_c23_0;
		f12_c23_1 = hob_data.f12_c23_1;
		recalibration = hob_data.f01_c9;
	}

	synaptics_rmi4_write_packet_reg(rmi4_data, &f12_ctrl_regs, 20);
	synaptics_rmi4_write_packet_reg(rmi4_data, &f12_ctrl_regs, 23);
	retval = synaptics_rmi4_i2c_write(rmi4_data,
			rmi4_data->f01_ctrl_base_addr + 5,
			&recalibration,
			sizeof(recalibration));
	if (retval < 0)
		pr_err("error setting recalibration interval\n");
}

 /**
 * synaptics_rmi4_sensor_sleep()
 *
 * Called by synaptics_dsx_sensor_state().
 *
 * This function stops finger data acquisition and puts the sensor to sleep.
 */
static void synaptics_rmi4_sensor_sleep(struct synaptics_rmi4_data *rmi4_data)
{
	int retval;
	unsigned char device_ctrl;
	unsigned char clear_mask = MASK_2BIT;
	unsigned char set_mask = SENSOR_SLEEP;

	retval = synaptics_rmi4_i2c_read(rmi4_data,
			rmi4_data->f01_ctrl_base_addr,
			&device_ctrl,
			sizeof(device_ctrl));
	if (retval < 0) {
		dev_err(&(rmi4_data->input_dev->dev),
				"%s: Failed to enter sleep mode\n",
				__func__);
		rmi4_data->sensor_sleep = false;
		return;
	}

	if (rmi4_data->normal_mode >= 0) {
		clear_mask = MASK_3BIT;
		set_mask |= NO_SLEEP_OFF;
	}

	/* store ctrl register value to avoid being */
	/* have to read its value when waking ic up */
	rmi4_data->f01_ctrl_register_0 = device_ctrl;

	device_ctrl = (device_ctrl & ~clear_mask);
	device_ctrl = (device_ctrl | set_mask);

	dev_dbg(&(rmi4_data->input_dev->dev),
			"%s: Sleep mode 0x%x\n", __func__, device_ctrl);

	retval = synaptics_rmi4_i2c_write(rmi4_data,
			rmi4_data->f01_ctrl_base_addr,
			&device_ctrl,
			sizeof(device_ctrl));
	if (retval < 0) {
		dev_err(&(rmi4_data->input_dev->dev),
				"%s: Failed to enter sleep mode\n",
				__func__);
		rmi4_data->sensor_sleep = false;
		return;
	} else {
		rmi4_data->sensor_sleep = true;
	}

	return;
}

 /**
 * synaptics_rmi4_sensor_wake()
 *
 * Called by synaptics_dsx_sensor_state().
 *
 * This function wakes the sensor from sleep.
 */
static void synaptics_rmi4_sensor_wake(struct synaptics_rmi4_data *rmi4_data)
{
	int retval;
	unsigned char device_ctrl;
	unsigned char clear_mask = MASK_3BIT;
	unsigned char set_mask = NORMAL_OPERATION;

	/* use ctrl register value stored when ic is put in sleep */
	device_ctrl = rmi4_data->f01_ctrl_register_0;

	if (rmi4_data->normal_mode < 0)
		clear_mask = MASK_2BIT;
	else if (rmi4_data->normal_mode == 0)
		set_mask |= NO_SLEEP_ON;

	device_ctrl = (device_ctrl & ~clear_mask);
	device_ctrl = (device_ctrl | set_mask);

	dev_dbg(&(rmi4_data->input_dev->dev),
			"%s: Wake up to mode 0x%x\n", __func__, device_ctrl);

	retval = synaptics_rmi4_i2c_write(rmi4_data,
			rmi4_data->f01_ctrl_base_addr,
			&device_ctrl,
			sizeof(device_ctrl));
	if (retval < 0) {
		dev_err(&(rmi4_data->input_dev->dev),
				"%s: Failed to wake from sleep mode\n",
				__func__);
		rmi4_data->sensor_sleep = true;
		return;
	} else {
		rmi4_data->sensor_sleep = false;
	}

	return;
}

#if defined(CONFIG_FB) && !defined(CONFIG_MMI_PANEL_NOTIFICATIONS)
static int synaptics_dsx_panel_cb(struct notifier_block *nb,
		unsigned long event, void *data)
{
	struct fb_event *evdata = data;
	int *blank;
	int value = -1;
	struct synaptics_rmi4_data *rmi4_data =
		container_of(nb, struct synaptics_rmi4_data, panel_nb);

	if (evdata && evdata->data && event == FB_EVENT_BLANK) {
		blank = evdata->data;
		if (*blank == FB_BLANK_UNBLANK) {
			synaptics_rmi4_resume(&(rmi4_data->input_dev->dev));
			value = 0; /* clear flag */
		} else if (*blank == FB_BLANK_POWERDOWN) {
			synaptics_rmi4_suspend(&(rmi4_data->input_dev->dev));
			value = 1; /* set flag */
		}
	}

	if (rmi4_data->purge_enabled && value != -1) {
		atomic_set(&rmi4_data->panel_off_flag, value);
		pr_debug("touches purge is %s\n", value ? "ON" : "OFF");
	}

	return 0;
}
#endif

 /**
 * synaptics_rmi4_suspend()
 *
 * Called by the kernel during the suspend phase when the system
 * enters suspend.
 *
 * This function stops finger data acquisition and puts the sensor to
 * sleep, disables the interrupt, and turns off the power to the sensor.
 */
static int synaptics_rmi4_suspend(struct device *dev)
{
	struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev);
	const struct synaptics_dsx_platform_data *platform_data =
			rmi4_data->board;

	synaptics_dsx_sensor_state(rmi4_data, STATE_SUSPEND);
	rmi4_data->poweron = false;

	if (!rmi4_data->touch_stopped) {
		if (platform_data->regulator_en) {
			regulator_disable(rmi4_data->regulator);
			pr_debug("touch-vdd regulator is %s\n",
				regulator_is_enabled(rmi4_data->regulator) ?
				"on" : "off");
		}

		gpio_free(platform_data->reset_gpio);

		rmi4_data->touch_stopped = true;
	}

	return 0;
}

 /**
 * synaptics_rmi4_resume()
 *
 * Called by the kernel during the resume phase when the system
 * wakes up from suspend.
 *
 * This function turns on the power to the sensor, wakes the sensor
 * from sleep, enables the interrupt, and starts finger data
 * acquisition.
 */
static int synaptics_rmi4_resume(struct device *dev)
{
	struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev);

	if (rmi4_data->touch_stopped) {
		int retval;
		bool wait4idle = false;
		const struct synaptics_dsx_platform_data *platform_data =
						rmi4_data->board;
		if (platform_data->regulator_en) {
			regulator_enable(rmi4_data->regulator);
			pr_debug("touch-vdd regulator is %s\n",
				regulator_is_enabled(rmi4_data->regulator) ?
				"on" : "off");
		}

		retval = gpio_get_value(platform_data->reset_gpio);
		pr_debug("reset gpio state: %d\n", retval);
		if (retval == 0)
			wait4idle = true;

		if (gpio_request(platform_data->reset_gpio,
						RESET_GPIO_NAME) < 0)
			pr_err("failed to request reset gpio\n");

		rmi4_data->touch_stopped = false;
		/*
		 * Decouple device reset and sending touch release, since
		 * on resume resetting ic can be optional, while sending
		 * release event is not
		 */
		synaptics_dsx_on_resume(rmi4_data);

		if (rmi4_data->reset_on_resume)
			synaptics_rmi4_reset_device(rmi4_data, NULL);
		else if (wait4idle) {
			retval = synaptics_dsx_ic_reset(rmi4_data, false);
			pr_debug("waited for idle %dms\n", retval);
		}
	}

	synaptics_dsx_sensor_ready_state(rmi4_data, false);
	rmi4_data->poweron = true;

	return 0;
}

static const struct dev_pm_ops synaptics_rmi4_dev_pm_ops = {
	.suspend = synaptics_rmi4_suspend,
	.resume  = synaptics_rmi4_resume,
};

#ifdef CONFIG_OF
static const struct of_device_id synaptics_rmi4_match_tbl[] = {
	{ .compatible = "synaptics," DRIVER_NAME },
	{ },
};
MODULE_DEVICE_TABLE(of, synaptics_rmi4_match_tbl);
#endif

static const struct i2c_device_id synaptics_rmi4_id_table[] = {
	{DRIVER_NAME, 0},
	{},
};
MODULE_DEVICE_TABLE(i2c, synaptics_rmi4_id_table);

static struct i2c_driver synaptics_rmi4_driver = {
	.driver = {
		.name = DRIVER_NAME,
		.owner = THIS_MODULE,
#if !defined(CONFIG_FB) && defined(CONFIG_PM)
		.pm = &synaptics_rmi4_dev_pm_ops,
#endif
	},
	.probe = synaptics_rmi4_probe,
	.remove = __devexit_p(synaptics_rmi4_remove),
	.id_table = synaptics_rmi4_id_table,
};

 /**
 * synaptics_rmi4_init()
 *
 * Called by the kernel during do_initcalls (if built-in)
 * or when the driver is loaded (if a module).
 *
 * This function registers the driver to the I2C subsystem.
 *
 */
static int __init synaptics_rmi4_init(void)
{
	return i2c_add_driver(&synaptics_rmi4_driver);
}

 /**
 * synaptics_rmi4_exit()
 *
 * Called by the kernel when the driver is unloaded.
 *
 * This funtion unregisters the driver from the I2C subsystem.
 *
 */
static void __exit synaptics_rmi4_exit(void)
{
	i2c_del_driver(&synaptics_rmi4_driver);
}

module_init(synaptics_rmi4_init);
module_exit(synaptics_rmi4_exit);

MODULE_AUTHOR("Synaptics, Inc.");
MODULE_DESCRIPTION("Synaptics DSX I2C Touch Driver");
MODULE_LICENSE("GPL v2");
MODULE_VERSION(SYNAPTICS_DSX_DRIVER_VERSION);
