#
-# all auto touch screen drivers configuration\r
+# all auto touch screen drivers configuration
#
-\r
-menuconfig TS_AUTO\r
- bool "auto touch screen driver support"\r
+
+menuconfig TS_AUTO
+ bool "auto touch screen driver support"
default n
-if TS_AUTO\r
-\r
-source "drivers/input/ts/chips/Kconfig"\r
-\r
-endif\r
-\r
-\r
+if TS_AUTO
+
+source "drivers/input/ts/chips/Kconfig"
+
+endif
+
+
# auto touch screen drivers\r
+obj-$(CONFIG_TS_AUTO_I2C) += ts-i2c.o\r
+obj-$(CONFIG_TS_AUTO_SPI) += ts-spi.o\r
+obj-$(CONFIG_TS_AUTO_SERIAL) += ts-serial.o\r
obj-$(CONFIG_TS_AUTO) += chips/\r
-\r
-obj-$(CONFIG_TS_AUTO) += ts-i2c.o\r
-obj-$(CONFIG_TS_AUTO) += ts-auto.o\r
-\r
+obj-$(CONFIG_TS_AUTO) += ts-auto.o
\ No newline at end of file
+menuconfig TS_AUTO_I2C\r
+ bool "Support auto touch screen with I2C"\r
+ default n \r
+ \r
+if TS_AUTO_I2C\r
+\r
config TS_FT5306\r
- bool "touch screen ft5306"\r
- default n
+bool "touch screen ft5306"\r
+ default n\r
\r
config TS_GT8110\r
- bool "touch screen gt8110"\r
+ bool "touch screen gt8110"\r
default n \r
\r
config TS_GT828\r
- bool "touch screen gt828"\r
- default n
\ No newline at end of file
+ bool "touch screen gt828"\r
+ default n\r
+ \r
+endif\r
+\r
+config TS_AUTO_SPI
+ bool "Support auto touch screen with SPI"\r
+ depends on SPI_MASTER\r
+\r
+if TS_AUTO_SPI\r
+ \r
+endif\r
+
+config TS_AUTO_SERIAL
+ bool "Support auto touch screen with UART"\r
+ \r
+if TS_AUTO_SERIAL\r
+ \r
+endif\r
+\r
\r
/****************operate according to ts chip:start************/\r
\r
-static int ts_active(struct i2c_client *client, int enable)\r
-{\r
- struct ts_private_data *ts =\r
- (struct ts_private_data *) i2c_get_clientdata(client); \r
+static int ts_active(struct ts_private_data *ts, int enable)\r
+{ \r
int result = 0;\r
\r
if(enable)\r
return result;\r
}\r
\r
-static int ts_init(struct i2c_client *client)\r
+static int ts_init(struct ts_private_data *ts)\r
{\r
- struct ts_private_data *ts =\r
- (struct ts_private_data *) i2c_get_clientdata(client);\r
int irq_pin = irq_to_gpio(ts->pdata->irq);\r
int result = 0;\r
\r
}\r
\r
\r
-static int ts_report_value(struct i2c_client *client)\r
+static int ts_report_value(struct ts_private_data *ts)\r
{\r
- struct ts_private_data *ts =\r
- (struct ts_private_data *) i2c_get_clientdata(client); \r
struct ts_platform_data *pdata = ts->pdata;\r
struct ts_event *event = &ts->event;\r
unsigned char buf[32] = {0};\r
int result = 0 , i = 0, off = 0, id = 0;\r
\r
- buf[0] = ts->ops->read_reg;\r
- result = ts_rx_data(client, buf, ts->ops->read_len);\r
+ result = ts_bulk_read(ts, (unsigned short)ts->ops->read_reg, ts->ops->read_len, (unsigned short *)buf);\r
if(result < 0)\r
{\r
printk("%s:fail to init ts\n",__func__);\r
\r
event->touch_point = buf[2] & 0x07;// 0000 1111\r
\r
+ for(i=0; i<ts->ops->max_point; i++)\r
+ {\r
+ event->point[i].status = 0;\r
+ event->point[i].x = 0;\r
+ event->point[i].y = 0;\r
+ }\r
+\r
if(event->touch_point == 0)\r
{ \r
for(i=0; i<ts->ops->max_point; i++)\r
{\r
- if(event->point[i].status != 0)\r
+ if(event->point[i].last_status != 0)\r
{\r
- event->point[i].status = 0; \r
+ event->point[i].last_status = 0; \r
input_mt_slot(ts->input_dev, event->point[i].id); \r
input_report_abs(ts->input_dev, ABS_MT_TRACKING_ID, -1);\r
input_mt_report_slot_state(ts->input_dev, MT_TOOL_FINGER, false);\r
\r
return 0;\r
}\r
- \r
+\r
for(i = 0; i<event->touch_point; i++)\r
{\r
off = i*6+3;\r
\r
if(ts->ops->x_revert)\r
{\r
- event->point[id].x = ts->ops->pixel.max_x - event->point[id].x; \r
+ event->point[id].x = ts->ops->range[0] - event->point[id].x; \r
}\r
\r
if(ts->ops->y_revert)\r
{\r
- event->point[id].y = ts->ops->pixel.max_y - event->point[id].y;\r
- }\r
+ event->point[id].y = ts->ops->range[1] - event->point[id].y;\r
+ } \r
+ \r
+ }\r
\r
- if(event->point[id].status != 0)\r
+ for(i=0; i<ts->ops->max_point; i++)\r
+ {\r
+ if(event->point[i].status != 0)\r
{ \r
- input_mt_slot(ts->input_dev, event->point[id].id);\r
- input_report_abs(ts->input_dev, ABS_MT_TRACKING_ID, event->point[id].id);\r
+ input_mt_slot(ts->input_dev, event->point[i].id);\r
+ input_report_abs(ts->input_dev, ABS_MT_TRACKING_ID, event->point[i].id);\r
input_report_abs(ts->input_dev, ABS_MT_TOUCH_MAJOR, 1);\r
- input_report_abs(ts->input_dev, ABS_MT_POSITION_X, event->point[id].x);\r
- input_report_abs(ts->input_dev, ABS_MT_POSITION_Y, event->point[id].y);\r
+ input_report_abs(ts->input_dev, ABS_MT_POSITION_X, event->point[i].x);\r
+ input_report_abs(ts->input_dev, ABS_MT_POSITION_Y, event->point[i].y);\r
input_report_abs(ts->input_dev, ABS_MT_WIDTH_MAJOR, 1);\r
DBG("%s:%s press down,id=%d,x=%d,y=%d\n",__func__,ts->ops->name, event->point[id].id, event->point[id].x,event->point[id].y);\r
}\r
- \r
- \r
+ else if ((event->point[i].status == 0) && (event->point[i].last_status != 0))\r
+ { \r
+ input_mt_slot(ts->input_dev, event->point[i].id); \r
+ input_report_abs(ts->input_dev, ABS_MT_TRACKING_ID, -1);\r
+ input_mt_report_slot_state(ts->input_dev, MT_TOOL_FINGER, false);\r
+ DBG("%s:%s press up1,id=%d\n",__func__,ts->ops->name, event->point[i].id);\r
+ }\r
+\r
+ event->point[i].last_status = event->point[i].status;\r
}\r
- \r
input_sync(ts->input_dev);\r
\r
return 0;\r
}\r
\r
-static int ts_suspend(struct i2c_client *client)\r
+static int ts_suspend(struct ts_private_data *ts)\r
{\r
- struct ts_private_data *ts =\r
- (struct ts_private_data *) i2c_get_clientdata(client); \r
struct ts_platform_data *pdata = ts->pdata;\r
\r
if(ts->ops->active)\r
- ts->ops->active(client, 0);\r
+ ts->ops->active(ts, 0);\r
\r
return 0;\r
}\r
\r
\r
\r
-static int ts_resume(struct i2c_client *client)\r
+static int ts_resume(struct ts_private_data *ts)\r
{\r
- struct ts_private_data *ts =\r
- (struct ts_private_data *) i2c_get_clientdata(client); \r
struct ts_platform_data *pdata = ts->pdata;\r
\r
if(ts->ops->active)\r
- ts->ops->active(client, 1);\r
+ ts->ops->active(ts, 1);\r
return 0;\r
}\r
\r
struct ts_operate ts_ft5306_ops = {\r
.name = "ft5306",\r
.slave_addr = 0x3e,\r
- .id_i2c = TS_ID_FT5306, //i2c id number\r
+ .ts_id = TS_ID_FT5306, //i2c id number\r
+ .bus_type = TS_BUS_TYPE_I2C,\r
.reg_size = 1,\r
- .pixel = {1024,768},\r
.id_reg = FT5306_ID_REG,\r
.id_data = TS_UNKNOW_DATA,\r
.version_reg = TS_UNKNOW_DATA,\r
\r
/****************operate according to ts chip:start************/\r
\r
-static int ts_active(struct i2c_client *client, int enable)\r
+static int ts_active(struct ts_private_data *ts, int enable)\r
{\r
- struct ts_private_data *ts =\r
- (struct ts_private_data *) i2c_get_clientdata(client);\r
unsigned char buf_suspend[2] = {0x38, 0x56}; //suspend cmd\r
int result = 0;\r
\r
}\r
else\r
{\r
- result = ts_tx_data(client, buf_suspend, 2);\r
+ result = ts_bulk_write(ts, (unsigned short )buf_suspend[0], 2, (unsigned short *)&buf_suspend[1]);\r
if(result < 0)\r
{\r
printk("%s:fail to init ts\n",__func__);\r
return result;\r
}\r
\r
-static int ts_init(struct i2c_client *client)\r
+static int ts_init(struct ts_private_data *ts)\r
{\r
- struct ts_private_data *ts =\r
- (struct ts_private_data *) i2c_get_clientdata(client);\r
int irq_pin = irq_to_gpio(ts->pdata->irq);\r
char version_data[18] = {240};\r
char init_data[95] = {\r
};\r
int result = 0, i = 0;\r
\r
- //read version\r
- result = ts_rx_data(client, version_data, 17);\r
+ //read version \r
+ result = ts_bulk_read(ts, (unsigned short)version_data[0], 16, (unsigned short *)&version_data[1]);\r
if(result < 0)\r
{\r
printk("%s:fail to init ts\n",__func__);\r
printk("%s:%s version is %s\n",__func__,ts->ops->name, version_data);\r
#if 1\r
//init some register\r
- result = ts_tx_data(client, init_data, 95);\r
+ result = ts_bulk_write(ts, (unsigned short )init_data[0], 94, (unsigned short *)&init_data[1]);\r
if(result < 0)\r
{\r
printk("%s:fail to init ts\n",__func__);\r
return result;\r
}\r
#endif\r
- result = ts_rx_data(client, init_data, 95);\r
+ result = ts_bulk_read(ts, (unsigned short)init_data[0], 94, (unsigned short *)&init_data[1]);\r
if(result < 0)\r
{\r
printk("%s:fail to init ts\n",__func__);\r
}\r
\r
\r
- printk("%s:rx:",__func__);\r
+ DBG("%s:rx:",__func__);\r
for(i=0; i<95; i++)\r
- printk("0x%x,",init_data[i]);\r
+ DBG("0x%x,",init_data[i]);\r
\r
- printk("\n");\r
+ DBG("\n");\r
\r
return result;\r
}\r
\r
-static bool goodix_get_status(char *p1,int*p2)\r
+static bool goodix_get_status(int *p1,int*p2)\r
{\r
bool status = PEN_DOWN;\r
if((*p2==PEN_DOWN) && (*p1==PEN_RELEASE))\r
\r
\r
\r
-static int ts_check_irq(struct i2c_client *client)\r
+static int ts_check_irq(struct ts_private_data *ts)\r
{\r
- struct ts_private_data *ts =\r
- (struct ts_private_data *) i2c_get_clientdata(client); \r
struct ts_platform_data *pdata = ts->pdata; \r
struct ts_event *event = &ts->event;\r
int gpio_level_no_int = GPIO_HIGH;\r
\r
input_sync(ts->input_dev); \r
memset(event, 0x00, sizeof(struct ts_event)); \r
- enable_irq(ts->client->irq);\r
+ enable_irq(ts->irq);\r
}\r
else\r
schedule_delayed_work(&ts->delaywork, msecs_to_jiffies(ts->ops->poll_delay_ms));\r
+\r
+ return 0;\r
\r
}\r
\r
\r
-static int ts_report_value(struct i2c_client *client)\r
+static int ts_report_value(struct ts_private_data *ts)\r
{\r
- struct ts_private_data *ts =\r
- (struct ts_private_data *) i2c_get_clientdata(client); \r
struct ts_platform_data *pdata = ts->pdata;\r
struct ts_event *event = &ts->event;\r
unsigned char buf[54] = {0};\r
int result = 0 , i = 0, j = 0, off = 0, id = 0;\r
int temp = 0, num = 0;\r
\r
- buf[0] = ts->ops->read_reg;\r
- result = ts_rx_data(client, buf, ts->ops->read_len);\r
+ result = ts_bulk_read(ts, ts->ops->read_reg, ts->ops->read_len, (unsigned short *)buf);\r
if(result < 0)\r
{\r
printk("%s:fail to init ts\n",__func__);\r
\r
if(ts->ops->x_revert)\r
{\r
- event->point[id].x = ts->ops->pixel.max_x - event->point[id].x; \r
+ event->point[id].x = ts->ops->range[0] - event->point[id].x; \r
}\r
\r
if(ts->ops->y_revert)\r
{\r
- event->point[id].y = ts->ops->pixel.max_y - event->point[id].y;\r
+ event->point[id].y = ts->ops->range[1] - event->point[id].y;\r
}\r
\r
\r
return 0;\r
}\r
\r
-static int ts_suspend(struct i2c_client *client)\r
-{\r
- struct ts_private_data *ts =\r
- (struct ts_private_data *) i2c_get_clientdata(client); \r
+static int ts_suspend(struct ts_private_data *ts)\r
+{ \r
struct ts_platform_data *pdata = ts->pdata;\r
\r
if(ts->ops->active)\r
- ts->ops->active(client, 0);\r
+ ts->ops->active(ts, 0);\r
\r
return 0;\r
}\r
\r
\r
-static int ts_resume(struct i2c_client *client)\r
+static int ts_resume(struct ts_private_data *ts)\r
{\r
- struct ts_private_data *ts =\r
- (struct ts_private_data *) i2c_get_clientdata(client); \r
struct ts_platform_data *pdata = ts->pdata;\r
\r
if(ts->ops->active)\r
- ts->ops->active(client, 1);\r
+ ts->ops->active(ts, 1);\r
return 0;\r
}\r
\r
struct ts_operate ts_gt8110_ops = {\r
.name = "gt8110",\r
.slave_addr = 0x5c,\r
- .id_i2c = TS_ID_GT8110, //i2c id number\r
+ .ts_id = TS_ID_GT8110, //i2c id number\r
+ .bus_type = TS_BUS_TYPE_I2C,\r
.reg_size = 1,\r
- .pixel = {1280,800},\r
.id_reg = GT8110_ID_REG,\r
.id_data = TS_UNKNOW_DATA,\r
.version_reg = TS_UNKNOW_DATA,\r
#define GTP_REG_CONFIG_DATA 0x0F80\r
#define GTP_REG_VERSION 0x0F7D\r
\r
+#define GTP_CONFIG_LENGTH 112\r
+#define TRIGGER_LOC 64\r
+\r
+//STEP_1(REQUIRED):Change config table.\r
+/*TODO: puts the config info corresponded to your TP here, the following is just\r
+a sample config, send this config should cause the chip cannot work normally*/\r
+//default or float\r
+\r
+u8 cfg_info_group[][GTP_CONFIG_LENGTH] = \r
+{\r
+ {\r
+ 0x00,0x0F,0x01,0x10,0x02,0x11,0x03,0x12,0x04,0x13,\r
+ 0x05,0x14,0x06,0x15,0x07,0x16,0x08,0x17,0x09,0x18,\r
+ 0x0A,0x19,0x0B,0x1A,0x0C,0x1B,0x0D,0x1C,0xFF,0xFF,\r
+ 0x02,0x0C,0x03,0x0D,0x04,0x0E,0x05,0x0F,0x06,0x10,\r
+ 0x07,0x11,0x08,0x12,0x09,0x13,0xFF,0x11,0x12,0x13,\r
+ 0x0F,0x03,0x88,0x10,0x10,0x2A,0x00,0x00,0x00,0x00,\r
+ 0x00,0x0E,0x45,0x30,0x58,0x03,0x00,0x05,0x00,0x02,\r
+ 0x58,0x03,0x20,0x55,0x5E,0x50,0x58,0x27,0x00,0x05,\r
+ 0x19,0x05,0x14,0x10,0x00,0x05,0x00,0x00,0x00,0x00,\r
+ 0x00,0x00,0x40,0x30,0x30,0x3C,0x00,0x00,0x00,0x00,\r
+ 0x0F,0x88,0x28,0x05,0x00,0x00,0x00,0x00,0x00,0x00,\r
+ 0x00,0x01\r
+ },\r
+ {\r
+ 0x00,0x0F,0x01,0x10,0x02,0x11,0x03,0x12,0x04,0x13,\r
+ 0x05,0x14,0x06,0x15,0x07,0x16,0x08,0x17,0x09,0x18,\r
+ 0x0A,0x19,0x0B,0x1A,0x0C,0x1B,0x0D,0x1C,0xFF,0xFF,\r
+ 0x02,0x0C,0x03,0x0D,0x04,0x0E,0x05,0x0F,0x06,0x10,\r
+ 0x07,0x11,0x08,0x12,0x09,0x13,0xFF,0x11,0x12,0x13,\r
+ 0x0F,0x03,0x88,0x10,0x10,0x2A,0x00,0x00,0x00,0x00,\r
+ 0x00,0x0E,0x45,0x30,0x58,0x03,0x00,0x05,0x00,0x02,\r
+ 0x58,0x03,0x20,0x55,0x5E,0x50,0x58,0x27,0x00,0x05,\r
+ 0x19,0x05,0x14,0x10,0x00,0x05,0x00,0x00,0x00,0x00,\r
+ 0x00,0x00,0x40,0x30,0x30,0x3C,0x00,0x00,0x00,0x00,\r
+ 0x0F,0x88,0x28,0x05,0x00,0x00,0x00,0x00,0x00,0x00,\r
+ 0x00,0x01\r
+ },\r
+ \r
+ {\r
+ 0x00,0x0F,0x01,0x10,0x02,0x11,0x03,0x12,0x04,0x13,\r
+ 0x05,0x14,0x06,0x15,0x07,0x16,0x08,0x17,0x09,0x18,\r
+ 0x0A,0x19,0x0B,0x1A,0x0C,0x1B,0x0D,0x1C,0xFF,0xFF,\r
+ 0x02,0x0C,0x03,0x0D,0x04,0x0E,0x05,0x0F,0x06,0x10,\r
+ 0x07,0x11,0x08,0x12,0x09,0x13,0xFF,0x11,0x12,0x13,\r
+ 0x0F,0x03,0x88,0x10,0x10,0x2A,0x00,0x00,0x00,0x00,\r
+ 0x00,0x0E,0x45,0x30,0x58,0x03,0x00,0x05,0x00,0x02,\r
+ 0x58,0x03,0x20,0x55,0x5E,0x50,0x58,0x27,0x00,0x05,\r
+ 0x19,0x05,0x14,0x10,0x00,0x05,0x00,0x00,0x00,0x00,\r
+ 0x00,0x00,0x40,0x30,0x30,0x3C,0x00,0x00,0x00,0x00,\r
+ 0x0F,0x88,0x28,0x05,0x00,0x00,0x00,0x00,0x00,0x00,\r
+ 0x00,0x01\r
+ }\r
+\r
+};\r
+\r
+static u8 config[GTP_CONFIG_LENGTH+2] = {GTP_REG_CONFIG_DATA >> 8, GTP_REG_CONFIG_DATA & 0xff};\r
\r
\r
/****************operate according to ts chip:start************/\r
\r
-int ts_i2c_end_cmd(struct i2c_client *client)\r
+int ts_i2c_end_cmd(struct ts_private_data *ts)\r
{\r
int result = -1;\r
char end_cmd_data[2]={0x80, 0x00};\r
\r
- result = ts_tx_data(client, end_cmd_data, 2);\r
+ result = ts_reg_write(ts, end_cmd_data[0], end_cmd_data[1]);\r
if(result < 0)\r
{\r
printk("%s:fail to init ts\n",__func__);\r
}\r
\r
\r
-static int ts_active(struct i2c_client *client, int enable)\r
-{\r
- struct ts_private_data *ts =\r
- (struct ts_private_data *) i2c_get_clientdata(client); \r
+static int ts_active(struct ts_private_data *ts, int enable)\r
+{ \r
int result = 0;\r
\r
if(enable)\r
return result;\r
}\r
\r
-static int ts_init(struct i2c_client *client)\r
+static int ts_init(struct ts_private_data *ts)\r
{\r
- struct ts_private_data *ts =\r
- (struct ts_private_data *) i2c_get_clientdata(client);\r
int result = 0;\r
- char version_data[4] = {ts->ops->version_reg >> 8, ts->ops->version_reg & 0xff};\r
+ char version_data[5] = {ts->ops->version_reg >> 8, ts->ops->version_reg & 0xff};\r
+ u8 rd_cfg_buf[2];\r
\r
+ //init some register \r
+ result = ts_bulk_read(ts, ts->ops->version_reg, 1, (unsigned short *)rd_cfg_buf);\r
+ if(result < 0)\r
+ {\r
+ printk("%s:fail to read rd_cfg_buf\n",__func__);\r
+ return result;\r
+ }\r
+\r
+ result = ts_i2c_end_cmd(ts);\r
+ if(result < 0)\r
+ {\r
+ printk("%s:fail to end cmd\n",__func__); \r
+ rd_cfg_buf[0] = 0;\r
+ //return result;\r
+ }\r
+\r
+ rd_cfg_buf[0] &= 0x03;\r
+ \r
+ printk("%s:%s id is %d\n",__func__,ts->ops->name, rd_cfg_buf[0]);\r
+ \r
+ memcpy(&config[2], cfg_info_group[rd_cfg_buf[0]], GTP_CONFIG_LENGTH);\r
+\r
+ if((ts->ops->trig & IRQF_TRIGGER_FALLING) || (ts->ops->trig & IRQF_TRIGGER_LOW)) //FALLING\r
+ {\r
+ config[TRIGGER_LOC+2] &= 0xf7;\r
+ }\r
+ else if((ts->ops->trig & IRQF_TRIGGER_RISING) || (ts->ops->trig & IRQF_TRIGGER_HIGH)) //RISING\r
+ {\r
+ config[TRIGGER_LOC+2] |= 0x08;\r
+ }\r
+ \r
+ result = ts_bulk_write(ts, GTP_REG_CONFIG_DATA, GTP_CONFIG_LENGTH, (unsigned short *)config);\r
+ if(result < 0)\r
+ {\r
+ printk("%s:fail to send config data\n",__func__);\r
+ return result;\r
+ }\r
+\r
+ result = ts_i2c_end_cmd(ts);\r
+ if(result < 0)\r
+ {\r
+ printk("%s:fail to end cmd\n",__func__); \r
+ //return result;\r
+ }\r
+\r
//read version\r
- result = ts_rx_data(client, version_data, 4);\r
+ result = ts_bulk_read(ts, ts->ops->version_reg, 4, (unsigned short *)version_data);\r
if(result < 0)\r
{\r
printk("%s:fail to init ts\n",__func__);\r
}\r
version_data[4]='\0';\r
\r
- result = ts_i2c_end_cmd(client);\r
+ result = ts_i2c_end_cmd(ts);\r
if(result < 0)\r
{\r
- printk("%s:fail to end ts\n",__func__);\r
+ printk("%s:fail to end cmd\n",__func__);\r
//return result;\r
}\r
\r
printk("%s:%s version is %s\n",__func__,ts->ops->name, version_data);\r
-\r
- //init some register\r
- //to do\r
\r
return result;\r
}\r
\r
\r
-static int ts_report_value(struct i2c_client *client)\r
+static int ts_report_value(struct ts_private_data *ts)\r
{\r
- struct ts_private_data *ts =\r
- (struct ts_private_data *) i2c_get_clientdata(client); \r
struct ts_platform_data *pdata = ts->pdata;\r
struct ts_event *event = &ts->event;\r
unsigned char buf[2 + 2 + 5 * 5 + 1] = {0};\r
int finger = 0;\r
int checksum = 0;\r
\r
- buf[0] = ts->ops->read_reg >> 8;\r
- buf[1] = ts->ops->read_reg & 0xff;\r
- result = ts_rx_data_word(client, buf, ts->ops->read_len);\r
+ result = ts_bulk_read(ts, ts->ops->read_reg, ts->ops->read_len, (unsigned short *)buf);\r
if(result < 0)\r
{\r
printk("%s:fail to init ts\n",__func__);\r
return result;\r
}\r
\r
- result = ts_i2c_end_cmd(client);\r
+ result = ts_i2c_end_cmd(ts);\r
if(result < 0)\r
{\r
printk("%s:fail to end ts\n",__func__);\r
//for(i=0; i<ts->ops->read_len; i++)\r
//DBG("buf[%d]=0x%x\n",i,buf[i]);\r
finger = buf[0];\r
- if((finger & 0xc0) != 0x80)\r
+ if((finger & 0x80) != 0x80)\r
{\r
- DBG("%s:data not ready!\n",__func__);\r
- return -1;\r
+ DBG("%s:data not ready!,finger=0x%x\n",__func__,finger);\r
+ //return -1;\r
}\r
-\r
-\r
-#if 0 \r
- event->touch_point = 0;\r
- for(i=0; i<ts->ops->max_point; i++)\r
- {\r
- if(finger & (1<<i))\r
- event->touch_point++;\r
- }\r
-\r
- check_sum = 0;\r
- for ( i = 0; i < 5 * event->touch_point; i++)\r
- {\r
- check_sum += buf[2+i];\r
- }\r
- if (check_sum != buf[5 * event->touch_point])\r
- {\r
- DBG("%s:check sum error!\n",__func__);\r
- return -1;\r
- }\r
-#endif\r
\r
for(i = 0; i<ts->ops->max_point; i++)\r
{\r
event->point[id].y = (buf[off+2]<<8) | buf[off+3];\r
event->point[id].press = buf[off+4]; \r
\r
+ DBG("data:0x%x,0x%x,0x%x,0x%x\n",buf[off+0],buf[off+1],buf[off+2],buf[off+3]);\r
+ \r
if(ts->ops->xy_swap)\r
{\r
swap(event->point[id].x, event->point[id].y);\r
\r
if(ts->ops->x_revert)\r
{\r
- event->point[id].x = ts->ops->pixel.max_x - event->point[id].x; \r
+ event->point[id].x = ts->ops->range[0] - event->point[id].x; \r
}\r
\r
if(ts->ops->y_revert)\r
{\r
- event->point[id].y = ts->ops->pixel.max_y - event->point[id].y;\r
+ event->point[id].y = ts->ops->range[1] - event->point[id].y;\r
}\r
\r
if(event->point[id].status != 0)\r
return 0;\r
}\r
\r
-static int ts_suspend(struct i2c_client *client)\r
+static int ts_suspend(struct ts_private_data *ts)\r
{\r
- struct ts_private_data *ts =\r
- (struct ts_private_data *) i2c_get_clientdata(client); \r
struct ts_platform_data *pdata = ts->pdata;\r
\r
if(ts->ops->active)\r
- ts->ops->active(client, 0);\r
+ ts->ops->active(ts, 0);\r
\r
return 0;\r
}\r
\r
\r
\r
-static int ts_resume(struct i2c_client *client)\r
+static int ts_resume(struct ts_private_data *ts)\r
{\r
- struct ts_private_data *ts =\r
- (struct ts_private_data *) i2c_get_clientdata(client); \r
struct ts_platform_data *pdata = ts->pdata;\r
\r
if(ts->ops->active)\r
- ts->ops->active(client, 1);\r
+ ts->ops->active(ts, 1);\r
return 0;\r
}\r
\r
struct ts_operate ts_gt828_ops = {\r
.name = "gt828",\r
.slave_addr = 0x5d,\r
- .id_i2c = TS_ID_GT828, //i2c id number\r
+ .ts_id = TS_ID_GT828, //i2c id number\r
+ .bus_type = TS_BUS_TYPE_I2C,\r
.reg_size = 2,\r
- .pixel = {1024,600},\r
.id_reg = GTP_REG_SENSOR_ID,\r
.id_data = TS_UNKNOW_DATA,\r
.version_reg = 0x0F7D,\r
.xy_swap = 0,\r
.x_revert = 0,\r
.y_revert = 0,\r
- .range = {1024,600},\r
+ .range = {800,1280},\r
.irq_enable = 1,\r
.poll_delay_ms = 0,\r
.active = ts_active, \r
static struct class *g_ts_class;\r
static struct ts_operate *g_ts_ops[TS_NUM_ID]; \r
\r
-static int ts_get_id(struct ts_operate *ops, struct i2c_client *client, int *value)\r
+\r
+/**\r
+ * ts_reg_read: Read a single ts register.\r
+ *\r
+ * @ts: Device to read from.\r
+ * @reg: Register to read.\r
+ */\r
+int ts_reg_read(struct ts_private_data *ts, unsigned short reg)\r
+{\r
+ unsigned short val;\r
+ int ret;\r
+\r
+ mutex_lock(&ts->io_lock);\r
+\r
+ ret = ts->read_dev(ts, reg, ts->ops->reg_size, &val, ts->ops->reg_size);\r
+\r
+ mutex_unlock(&ts->io_lock);\r
+\r
+ if (ret < 0)\r
+ return ret;\r
+ else\r
+ return val;\r
+}\r
+EXPORT_SYMBOL_GPL(ts_reg_read);\r
+\r
+/**\r
+ * ts_bulk_read: Read multiple ts registers\r
+ *\r
+ * @ts: Device to read from\r
+ * @reg: First register\r
+ * @count: Number of registers\r
+ * @buf: Buffer to fill.\r
+ */\r
+int ts_bulk_read(struct ts_private_data *ts, unsigned short reg,\r
+ int count, u16 *buf)\r
+{\r
+ int ret;\r
+\r
+ mutex_lock(&ts->io_lock);\r
+\r
+ ret = ts->read_dev(ts, reg, count, buf, ts->ops->reg_size);\r
+\r
+ mutex_unlock(&ts->io_lock);\r
+\r
+ return ret;\r
+}\r
+EXPORT_SYMBOL_GPL(ts_bulk_read);\r
+\r
+\r
+/**\r
+ * ts_reg_write: Write a single ts register.\r
+ *\r
+ * @ts: Device to write to.\r
+ * @reg: Register to write to.\r
+ * @val: Value to write.\r
+ */\r
+int ts_reg_write(struct ts_private_data *ts, unsigned short reg,\r
+ unsigned short val)\r
{\r
- struct ts_private_data *ts =\r
- (struct ts_private_data *) i2c_get_clientdata(client); \r
+ int ret;\r
+\r
+ mutex_lock(&ts->io_lock);\r
+\r
+ ret = ts->write_dev(ts, reg, ts->ops->reg_size, &val, ts->ops->reg_size);\r
+\r
+ mutex_unlock(&ts->io_lock);\r
+\r
+ return ret;\r
+}\r
+EXPORT_SYMBOL_GPL(ts_reg_write);\r
+\r
+\r
+int ts_bulk_write(struct ts_private_data *ts, unsigned short reg,\r
+ int count, u16 *buf)\r
+{\r
+ int ret;\r
+\r
+ mutex_lock(&ts->io_lock);\r
+\r
+ ret = ts->write_dev(ts, reg, count, buf, ts->ops->reg_size);\r
+\r
+ mutex_unlock(&ts->io_lock);\r
+\r
+ return ret;\r
+}\r
+EXPORT_SYMBOL_GPL(ts_bulk_write);\r
+\r
+\r
+/**\r
+ * ts_set_bits: Set the value of a bitfield in a ts register\r
+ *\r
+ * @ts: Device to write to.\r
+ * @reg: Register to write to.\r
+ * @mask: Mask of bits to set.\r
+ * @val: Value to set (unshifted)\r
+ */\r
+int ts_set_bits(struct ts_private_data *ts, unsigned short reg,\r
+ unsigned short mask, unsigned short val)\r
+{\r
+ int ret;\r
+ u16 r;\r
+\r
+ mutex_lock(&ts->io_lock);\r
+\r
+ ret = ts->read_dev(ts, reg, ts->ops->reg_size, &r, ts->ops->reg_size);\r
+ if (ret < 0)\r
+ goto out;\r
+\r
+ r &= ~mask;\r
+ r |= val;\r
+\r
+ ret = ts->write_dev(ts, reg, ts->ops->reg_size, &r, ts->ops->reg_size);\r
+\r
+out:\r
+ mutex_unlock(&ts->io_lock);\r
+\r
+ return ret;\r
+}\r
+EXPORT_SYMBOL_GPL(ts_set_bits);\r
+\r
+static int ts_get_id(struct ts_operate *ops, struct ts_private_data *ts, int *value)\r
+{ \r
int result = 0;\r
char temp[4] = {ops->id_reg & 0xff};\r
int i = 0;\r
{\r
temp[0] = ops->id_reg >> 8;\r
temp[1] = ops->id_reg & 0xff;\r
- result = ts_rx_data_word(client, &temp, 2);\r
+ result = ts->read_dev(ts, ops->id_reg, 2, temp, ops->reg_size);\r
*value = (temp[0] << 8) | temp[1];\r
}\r
else\r
{\r
- result = ts_rx_data(client, &temp, 1);\r
+ result = ts->read_dev(ts, ops->id_reg, 1, temp, ops->reg_size);\r
*value = temp[0];\r
}\r
if(!result)\r
}\r
\r
\r
-static int ts_get_version(struct ts_operate *ops, struct i2c_client *client)\r
+static int ts_get_version(struct ts_operate *ops, struct ts_private_data *ts)\r
{\r
- struct ts_private_data *ts =\r
- (struct ts_private_data *) i2c_get_clientdata(client); \r
int result = 0;\r
char temp[TS_MAX_VER_LEN + 1] = {0};\r
int i = 0;\r
{\r
if((ops->version_len < 0) || (ops->version_len > TS_MAX_VER_LEN))\r
{\r
- printk("%s:version_len is error\n",__func__,ops->version_len);\r
+ printk("%s:version_len %d is error\n",__func__,ops->version_len);\r
ops->version_len = TS_MAX_VER_LEN;\r
}\r
\r
- if(ops->reg_size == 2)\r
- {\r
- result = ts_rx_data_word(client, temp, ops->version_len);\r
- }\r
- else\r
- {\r
- result = ts_rx_data(client, temp, ops->version_len);\r
- }\r
- \r
-\r
+ result = ts->read_dev(ts, ops->version_reg, ops->version_len, temp, ops->reg_size);\r
if(result)\r
return result;\r
\r
}\r
\r
\r
-static int ts_chip_init(struct i2c_client *client)\r
+static int ts_chip_init(struct ts_private_data *ts, int type)\r
{\r
- struct ts_private_data *ts =\r
- (struct ts_private_data *) i2c_get_clientdata(client); \r
struct ts_operate *ops = NULL;\r
int result = 0;\r
int i = 0;\r
+\r
+ if((type <= TS_BUS_TYPE_INVALID) || (type >= TS_BUS_TYPE_NUM_ID))\r
+ {\r
+ printk("%s:type=%d is error\n",__func__,type);\r
+ return -1; \r
+ }\r
\r
if(ts->pdata->init_platform_hw)\r
ts->pdata->init_platform_hw();\r
continue;\r
}\r
\r
- if(!ops->init || !ops->report)\r
- {\r
- printk("%s:error:%p,%p\n",__func__,ops->init,ops->report);\r
- result = -1;\r
- continue;\r
- }\r
-\r
- client->addr = ops->slave_addr; //use slave_addr of ops\r
-#if 0 \r
- if(ops->active)\r
+ if(ops->bus_type == type)\r
{\r
- result = ops->active(client, TS_ENABLE);\r
- if(result < 0)\r
+ \r
+ if(!ops->init || !ops->report)\r
{\r
- printk("%s:fail to active ts\n",__func__);\r
+ printk("%s:error:%p,%p\n",__func__,ops->init,ops->report);\r
+ result = -1;\r
continue;\r
}\r
- }\r
-#endif\r
- result = ts_get_id(ops, client, &ts->devid);//get id\r
- if(result < 0)\r
- { \r
- printk("%s:fail to read %s devid:0x%x\n",__func__, ops->name, ts->devid); \r
- continue;\r
- }\r
-\r
- result = ts_get_version(ops, client); //get version\r
- if(result < 0)\r
- { \r
- printk("%s:fail to read %s version\n",__func__, ops->name); \r
- continue;\r
- }\r
- \r
- ts->ops = ops; //save ops\r
+ \r
+ ts->ops = ops; //save ops\r
\r
- result = ops->init(client);\r
- if(result < 0)\r
- {\r
- printk("%s:fail to init ts\n",__func__); \r
- continue;\r
- }\r
-\r
- if(ops->firmware)\r
- {\r
- result = ops->firmware(client);\r
+ result = ts_get_id(ops, ts, &ts->devid);//get id\r
if(result < 0)\r
+ { \r
+ printk("%s:fail to read %s devid:0x%x\n",__func__, ops->name, ts->devid); \r
+ continue;\r
+ }\r
+ \r
+ result = ts_get_version(ops, ts); //get version\r
+ if(result < 0)\r
+ { \r
+ printk("%s:fail to read %s version\n",__func__, ops->name); \r
+ continue;\r
+ }\r
+ \r
+ result = ops->init(ts);\r
+ if(result < 0)\r
+ {\r
+ printk("%s:fail to init ts\n",__func__); \r
+ continue;\r
+ }\r
+ \r
+ if(ops->firmware)\r
{\r
- printk("%s:fail to updata firmware ts\n",__func__);\r
- return result;\r
+ result = ops->firmware(ts);\r
+ if(result < 0)\r
+ {\r
+ printk("%s:fail to updata firmware ts\n",__func__);\r
+ return result;\r
+ }\r
}\r
+ \r
+ printk("%s:%s devid:0x%x\n",__func__, ts->ops->name, ts->devid);\r
}\r
- \r
- printk("%s:%s devid:0x%x\n",__func__, ts->ops->name, ts->devid);\r
\r
break;\r
\r
\r
}\r
\r
-\r
-static int ts_get_data(struct i2c_client *client)\r
-{\r
- struct ts_private_data *ts =\r
- (struct ts_private_data *) i2c_get_clientdata(client); \r
- int result = 0;\r
- \r
- result = ts->ops->report(client);\r
- if(result)\r
- goto error;\r
- \r
-error: \r
- return result;\r
+static int ts_get_data(struct ts_private_data *ts)\r
+{ \r
+ return ts->ops->report(ts); \r
}\r
\r
\r
{\r
struct delayed_work *delaywork = container_of(work, struct delayed_work, work);\r
struct ts_private_data *ts = container_of(delaywork, struct ts_private_data, delaywork);\r
- struct i2c_client *client = ts->client;\r
\r
- mutex_lock(&ts->ts_mutex); \r
- if (ts_get_data(client) < 0) \r
+ mutex_lock(&ts->ts_lock); \r
+ if (ts_get_data(ts) < 0) \r
DBG(KERN_ERR "%s: Get data failed\n",__func__);\r
\r
if(!ts->ops->irq_enable)//restart work while polling\r
{\r
if(ts->ops->check_irq)\r
{\r
- ts->ops->check_irq(client); \r
+ ts->ops->check_irq(ts); \r
}\r
else\r
{\r
if((ts->ops->trig & IRQF_TRIGGER_LOW) || (ts->ops->trig & IRQF_TRIGGER_HIGH))\r
- enable_irq(ts->client->irq);\r
+ enable_irq(ts->irq);\r
}\r
}\r
- mutex_unlock(&ts->ts_mutex);\r
+ mutex_unlock(&ts->ts_lock);\r
\r
DBG("%s:%s\n",__func__,ts->i2c_id->name);\r
}\r
}\r
\r
\r
-static int ts_irq_init(struct i2c_client *client)\r
+static int ts_irq_init(struct ts_private_data *ts)\r
{\r
- struct ts_private_data *ts =\r
- (struct ts_private_data *) i2c_get_clientdata(client); \r
int result = 0;\r
int irq;\r
if((ts->ops->irq_enable)&&(ts->ops->trig != TS_UNKNOW_DATA))\r
if(ts->ops->poll_delay_ms < 0)\r
ts->ops->poll_delay_ms = 30;\r
\r
- result = gpio_request(client->irq, ts->i2c_id->name);\r
+ result = gpio_request(ts->irq, ts->i2c_id->name);\r
if (result)\r
{\r
- printk("%s:fail to request gpio :%d\n",__func__,client->irq);\r
+ printk("%s:fail to request gpio :%d\n",__func__,ts->irq);\r
}\r
\r
- gpio_pull_updown(client->irq, PullEnable);\r
- irq = gpio_to_irq(client->irq);\r
+ gpio_pull_updown(ts->irq, PullEnable);\r
+ irq = gpio_to_irq(ts->irq);\r
result = request_irq(irq, ts_interrupt, ts->ops->trig, ts->ops->name, ts);\r
//result = request_threaded_irq(irq, NULL, ts_interrupt, ts->ops->trig, ts->ops->name, ts);\r
if (result) {\r
printk(KERN_ERR "%s:fail to request irq = %d, ret = 0x%x\n",__func__, irq, result); \r
goto error; \r
}\r
- client->irq = irq;\r
+ ts->irq = irq;\r
printk("%s:use irq=%d\n",__func__,irq);\r
}\r
else if(!ts->ops->irq_enable)\r
return result;\r
}\r
\r
-#ifdef CONFIG_HAS_EARLYSUSPEND\r
-static void ts_suspend(struct early_suspend *h)\r
-{\r
- struct ts_private_data *ts = \r
- container_of(h, struct ts_private_data, early_suspend);\r
- \r
- if(ts->ops->suspend)\r
- ts->ops->suspend(ts->client);\r
-\r
- if(ts->ops->irq_enable) \r
- disable_irq_nosync(ts->client->irq);\r
- else\r
- cancel_delayed_work_sync(&ts->delaywork); \r
-\r
-}\r
-\r
-static void ts_resume(struct early_suspend *h)\r
-{\r
- struct ts_private_data *ts = \r
- container_of(h, struct ts_private_data, early_suspend);\r
-\r
- if(ts->ops->resume)\r
- ts->ops->resume(ts->client);\r
-\r
- if(ts->ops->irq_enable) \r
- enable_irq(ts->client->irq);\r
- else\r
- {\r
- PREPARE_DELAYED_WORK(&ts->delaywork, ts_delaywork_func);\r
- schedule_delayed_work(&ts->delaywork, msecs_to_jiffies(ts->ops->poll_delay_ms));\r
- }\r
-}\r
-#endif\r
-\r
-\r
-\r
-int ts_register_slave(struct i2c_client *client,\r
- struct ts_platform_data *slave_pdata,\r
- struct ts_operate *(*get_ts_ops)(void))\r
-{\r
- int result = 0;\r
- struct ts_operate *ops = get_ts_ops();\r
- if((ops->id_i2c >= TS_NUM_ID) || (ops->id_i2c <= TS_ID_INVALID))\r
- { \r
- printk("%s:%s id is error %d\n", __func__, ops->name, ops->id_i2c);\r
- return -1; \r
- }\r
- g_ts_ops[ops->id_i2c] = ops;\r
- printk("%s:%s,id=%d\n",__func__,g_ts_ops[ops->id_i2c]->name, ops->id_i2c);\r
- return result;\r
-}\r
-\r
\r
-int ts_unregister_slave(struct i2c_client *client,\r
- struct ts_platform_data *slave_pdata,\r
- struct ts_operate *(*get_ts_ops)(void))\r
-{\r
- int result = 0;\r
- struct ts_operate *ops = get_ts_ops();\r
- if((ops->id_i2c >= TS_NUM_ID) || (ops->id_i2c <= TS_ID_INVALID))\r
- { \r
- printk("%s:%s id is error %d\n", __func__, ops->name, ops->id_i2c);\r
- return -1; \r
- }\r
- printk("%s:%s,id=%d\n",__func__,g_ts_ops[ops->id_i2c]->name, ops->id_i2c);\r
- g_ts_ops[ops->id_i2c] = NULL; \r
- return result;\r
-}\r
\r
-\r
-int ts_probe(struct i2c_client *client, const struct i2c_device_id *devid)\r
+int ts_device_init(struct ts_private_data *ts, int type, int irq)\r
{\r
- struct ts_private_data *ts =\r
- (struct ts_private_data *) i2c_get_clientdata(client);\r
- struct ts_platform_data *pdata;\r
- int result = 0;\r
- dev_info(&client->adapter->dev, "%s: %s,0x%x\n", __func__, devid->name,(unsigned int)client);\r
+ struct ts_platform_data *pdata = ts->dev->platform_data;\r
+ int result = -1, i;\r
\r
- if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {\r
- result = -ENODEV;\r
- goto out_no_free;\r
- }\r
-\r
- pdata = client->dev.platform_data;\r
- if (!pdata) {\r
- dev_err(&client->adapter->dev,\r
- "Missing platform data for slave %s\n", devid->name);\r
- result = -EFAULT;\r
- goto out_no_free;\r
- }\r
-\r
- ts = kzalloc(sizeof(*ts), GFP_KERNEL);\r
- if (!ts) {\r
- result = -ENOMEM;\r
- goto out_no_free;\r
- }\r
- \r
- i2c_set_clientdata(client, ts);\r
- ts->client = client; \r
- ts->pdata = pdata; \r
- ts->i2c_id = (struct i2c_device_id *)devid;\r
-\r
- mutex_init(&ts->data_mutex); \r
- mutex_init(&ts->ts_mutex);\r
- mutex_init(&ts->i2c_mutex);\r
+ mutex_init(&ts->io_lock);\r
+ mutex_init(&ts->ts_lock);\r
+ dev_set_drvdata(ts->dev, ts);\r
\r
- result = ts_chip_init(ts->client);\r
+ ts->pdata = pdata;\r
+ result = ts_chip_init(ts, type);\r
if(result < 0)\r
+ {\r
+ printk("%s:touch screen with bus type %d is not exist\n",__func__,type);\r
goto out_free_memory;\r
- \r
- ts->client->addr = ts->ops->slave_addr; \r
- \r
+ }\r
+\r
ts->input_dev = input_allocate_device();\r
if (!ts->input_dev) {\r
result = -ENOMEM;\r
- dev_err(&client->dev,\r
+ dev_err(ts->dev,\r
"Failed to allocate input device %s\n", ts->input_dev->name);\r
goto out_free_memory;\r
} \r
-\r
- ts->input_dev->dev.parent = &client->dev;\r
+ \r
+ ts->input_dev->dev.parent = ts->dev;\r
ts->input_dev->name = ts->ops->name;\r
\r
result = input_register_device(ts->input_dev);\r
if (result) {\r
- dev_err(&client->dev,\r
+ dev_err(ts->dev,\r
"Unable to register input device %s\n", ts->input_dev->name);\r
goto out_input_register_device_failed;\r
}\r
\r
- result = ts_irq_init(ts->client);\r
+ result = ts_irq_init(ts);\r
if (result) {\r
- dev_err(&client->dev,\r
+ dev_err(ts->dev,\r
"fail to init ts irq,ret=%d\n",result);\r
goto out_input_register_device_failed;\r
}\r
\r
input_mt_init_slots(ts->input_dev, ts->ops->max_point);\r
- if((ts->ops->pixel.max_x <= 0) || (ts->ops->pixel.max_y <= 0))\r
+ if((ts->ops->range[0] <= 0) || (ts->ops->range[1] <= 0))\r
{
- ts->ops->pixel.max_x = 1024;\r
- ts->ops->pixel.max_y = 600;\r
+ ts->ops->range[0] = 1024;\r
+ ts->ops->range[1] = 600;\r
}\r
\r
input_set_abs_params(ts->input_dev,ABS_MT_POSITION_X, 0, ts->ops->range[0], 0, 0);\r
\r
g_ts = ts;\r
\r
-#ifdef CONFIG_HAS_EARLYSUSPEND\r
- if((ts->ops->suspend) && (ts->ops->resume))\r
- {\r
- ts->early_suspend.suspend = ts_suspend;\r
- ts->early_suspend.resume = ts_resume;\r
- ts->early_suspend.level = 0x02;\r
- register_early_suspend(&ts->early_suspend);\r
- }\r
-#endif\r
-\r
printk("%s:initialized ok,ts name:%s,devid=%d\n\n",__func__,ts->ops->name,ts->devid);\r
\r
return result;\r
input_free_device(ts->input_dev); \r
out_free_memory: \r
kfree(ts);\r
-out_no_free:\r
- dev_err(&client->adapter->dev, "%s failed %d\n", __func__, result);\r
+ \r
+ printk("%s:line=%d\n",__func__,__LINE__);\r
return result;\r
-\r
}\r
\r
-static void ts_shut_down(struct i2c_client *client)\r
-{\r
-#ifdef CONFIG_HAS_EARLYSUSPEND\r
- struct ts_private_data *ts =\r
- (struct ts_private_data *) i2c_get_clientdata(client);\r
- if((ts->ops->suspend) && (ts->ops->resume)) \r
- unregister_early_suspend(&ts->early_suspend);\r
- DBG("%s:%s\n",__func__,ts->i2c_id->name);\r
-#endif\r
-}\r
\r
-static int ts_remove(struct i2c_client *client)\r
+void ts_device_exit(struct ts_private_data *ts)\r
{\r
- struct ts_private_data *ts =\r
- (struct ts_private_data *) i2c_get_clientdata(client);\r
- int result = 0;\r
- \r
+ if(!ts->ops->irq_enable) \r
cancel_delayed_work_sync(&ts->delaywork);\r
input_unregister_device(ts->input_dev); \r
input_free_device(ts->input_dev); \r
- kfree(ts);\r
#ifdef CONFIG_HAS_EARLYSUSPEND\r
if((ts->ops->suspend) && (ts->ops->resume))\r
unregister_early_suspend(&ts->early_suspend);\r
#endif \r
- return result;\r
+ kfree(ts); \r
}\r
\r
-static const struct i2c_device_id ts_id_table[] = {\r
- {"auto_ts", 0},\r
- {},\r
-};\r
\r
+int ts_device_suspend(struct ts_private_data *ts)\r
+{\r
+ if(ts->ops->suspend)\r
+ ts->ops->suspend(ts);\r
+\r
+ if(ts->ops->irq_enable) \r
+ disable_irq_nosync(ts->irq);\r
+ else\r
+ cancel_delayed_work_sync(&ts->delaywork);\r
+\r
+ return 0;\r
+}\r
\r
-static struct i2c_driver ts_driver = {\r
- .probe = ts_probe,\r
- .remove = ts_remove,\r
- .shutdown = ts_shut_down,\r
- .id_table = ts_id_table,\r
- .driver = {\r
- .owner = THIS_MODULE,\r
- .name = "auto_ts",\r
- },\r
-};\r
\r
-static int __init ts_init(void)\r
+int ts_device_resume(struct ts_private_data *ts)\r
{\r
- int res = i2c_add_driver(&ts_driver);\r
- pr_info("%s: Probe name %s\n", __func__, ts_driver.driver.name);\r
- if (res)\r
- pr_err("%s failed\n", __func__);\r
- return res;\r
+ if(ts->ops->resume)\r
+ ts->ops->resume(ts);\r
+\r
+ if(ts->ops->irq_enable) \r
+ enable_irq(ts->irq);\r
+ else\r
+ {\r
+ PREPARE_DELAYED_WORK(&ts->delaywork, ts_delaywork_func);\r
+ schedule_delayed_work(&ts->delaywork, msecs_to_jiffies(ts->ops->poll_delay_ms));\r
+ }\r
+ \r
+ return 0;\r
}\r
\r
-static void __exit ts_exit(void)\r
+\r
+\r
+int ts_register_slave(struct ts_private_data *ts,\r
+ struct ts_platform_data *slave_pdata,\r
+ struct ts_operate *(*get_ts_ops)(void))\r
{\r
- pr_info("%s\n", __func__);\r
- i2c_del_driver(&ts_driver);\r
+ int result = 0;\r
+ struct ts_operate *ops = get_ts_ops();\r
+ if((ops->ts_id >= TS_NUM_ID) || (ops->ts_id <= TS_ID_INVALID))\r
+ { \r
+ printk("%s:%s id is error %d\n", __func__, ops->name, ops->ts_id);\r
+ return -1; \r
+ }\r
+ g_ts_ops[ops->ts_id] = ops;\r
+ printk("%s:%s,id=%d\n",__func__,g_ts_ops[ops->ts_id]->name, ops->ts_id);\r
+ return result;\r
+}\r
+\r
+\r
+int ts_unregister_slave(struct ts_private_data *ts,\r
+ struct ts_platform_data *slave_pdata,\r
+ struct ts_operate *(*get_ts_ops)(void))\r
+{\r
+ int result = 0;\r
+ struct ts_operate *ops = get_ts_ops();\r
+ if((ops->ts_id >= TS_NUM_ID) || (ops->ts_id <= TS_ID_INVALID))\r
+ { \r
+ printk("%s:%s id is error %d\n", __func__, ops->name, ops->ts_id);\r
+ return -1; \r
+ }\r
+ printk("%s:%s,id=%d\n",__func__,g_ts_ops[ops->ts_id]->name, ops->ts_id);\r
+ g_ts_ops[ops->ts_id] = NULL; \r
+ return result;\r
}\r
\r
-subsys_initcall_sync(ts_init);\r
-module_exit(ts_exit);\r
\r
MODULE_AUTHOR("ROCKCHIP Corporation:lw@rock-chips.com");\r
-MODULE_DESCRIPTION("User space character device interface for tss");\r
+MODULE_DESCRIPTION("device interface for auto touch screen");\r
MODULE_LICENSE("GPL");\r
\r
+\r
#define DBG(x...)\r
#endif\r
\r
-static int ts_i2c_write(struct i2c_adapter *i2c_adap,\r
- unsigned char address,\r
- unsigned int len, unsigned char const *data)\r
-{\r
- struct i2c_msg msgs[1];\r
- int res;\r
\r
- if (!data || !i2c_adap) {\r
+static int ts_i2c_read_device(struct ts_private_data *ts, unsigned short reg,\r
+ int bytes, void *dest, int reg_size)\r
+{\r
+ const struct i2c_client *client = ts->control_data;\r
+ struct i2c_adapter *i2c_adap = client->adapter;\r
+ struct i2c_msg msgs[2];\r
+ int i,res;\r
+ \r
+ if (!dest || !i2c_adap) {\r
printk("%s:line=%d,error\n",__func__,__LINE__);\r
return -EINVAL;\r
}\r
\r
- msgs[0].addr = address;\r
+ msgs[0].addr = client->addr;\r
msgs[0].flags = 0; /* write */\r
- msgs[0].buf = (unsigned char *)data;\r
- msgs[0].len = len;\r
+ msgs[0].buf = (unsigned char *)®\r
+ if(reg_size == 2) \r
+ msgs[0].len = 2;\r
+ else \r
+ msgs[0].len = 1;\r
msgs[0].scl_rate = TS_I2C_RATE;\r
+ \r
+ msgs[1].addr = client->addr;\r
+ msgs[1].flags = I2C_M_RD;\r
+ msgs[1].buf = dest;\r
+ msgs[1].len = bytes;\r
+ msgs[1].scl_rate = TS_I2C_RATE; \r
\r
- res = i2c_transfer(i2c_adap, msgs, 1);\r
- if (res == 1)\r
+ res = i2c_transfer(i2c_adap, msgs, 2);\r
+ if (res == 2)\r
return 0;\r
else if(res == 0)\r
return -EBUSY;\r
else\r
return res;\r
+ \r
+#ifdef TS_DEBUG_ENABLE\r
+ DBG("%s:reg=0x%x,len=%d,rxdata:",__func__, reg, bytes);\r
+ for(i=0; i<bytes; i++)\r
+ DBG("0x%x,",(unsigned char *)dest[i]);\r
+ DBG("\n");\r
+#endif \r
\r
+ \r
}\r
\r
-static int senosr_i2c_read(struct i2c_adapter *i2c_adap,\r
- unsigned char address, unsigned char reg,\r
- unsigned int tx_len, unsigned int rx_len, unsigned char *data)\r
+/* Currently we allocate the write buffer on the stack; this is OK for\r
+ * small writes - if we need to do large writes this will need to be\r
+ * revised.\r
+ */\r
+static int ts_i2c_write_device(struct ts_private_data *ts, unsigned short reg,\r
+ int bytes, void *src, int reg_size)\r
{\r
- struct i2c_msg msgs[2];\r
+ const struct i2c_client *client = ts->control_data;\r
+ struct i2c_adapter *i2c_adap = client->adapter;\r
+ struct i2c_msg msgs[1];\r
int res;\r
+ unsigned char buf[bytes + 2];\r
+ \r
+ if (!src || !i2c_adap) {\r
+ printk("%s:line=%d,error\n",__func__,__LINE__);\r
+ return -EINVAL;\r
+ }\r
+ \r
+ if(ts->ops->reg_size == 2)\r
+ {\r
+ buf[0] = (reg & 0xff00) >> 8;\r
+ buf[1] = (reg & 0x00ff) & 0xff;\r
+ memcpy(&buf[2], src, bytes);\r
+ }\r
+ else\r
+ {\r
+ buf[0] = reg & 0xff;\r
+ memcpy(&buf[1], src, bytes);\r
+ }\r
+\r
+#ifdef TS_DEBUG_ENABLE\r
+ int i = 0;\r
+ DBG("%s:reg=0x%x,len=%d,txdata:",__func__, reg, bytes);\r
+ for(i=0; i<length; i++)\r
+ DBG("0x%x,",buf[i]);\r
+ DBG("\n");\r
+#endif \r
\r
- if (!data || !i2c_adap) {\r
+ if (!src || !i2c_adap) {\r
printk("%s:line=%d,error\n",__func__,__LINE__);\r
return -EINVAL;\r
}\r
\r
- msgs[0].addr = address;\r
+ msgs[0].addr = client->addr;\r
msgs[0].flags = 0; /* write */\r
- msgs[0].buf = ®\r
- msgs[0].len = tx_len;\r
+ msgs[0].buf = buf;\r
+ msgs[0].len = bytes;\r
msgs[0].scl_rate = TS_I2C_RATE;\r
- \r
- msgs[1].addr = address;\r
- msgs[1].flags = I2C_M_RD;\r
- msgs[1].buf = data;\r
- msgs[1].len = rx_len;\r
- msgs[1].scl_rate = TS_I2C_RATE; \r
\r
- res = i2c_transfer(i2c_adap, msgs, 2);\r
- if (res == 2)\r
+ res = i2c_transfer(i2c_adap, msgs, 1);\r
+ if (res == 1)\r
return 0;\r
else if(res == 0)\r
return -EBUSY;\r
else\r
return res;\r
-\r
-}\r
-\r
-\r
-int ts_rx_data(struct i2c_client *client, char *rxData, int length)\r
-{\r
-#ifdef TS_DEBUG_ENABLE\r
- struct ts_private_data* ts = \r
- (struct ts_private_data *)i2c_get_clientdata(client);\r
- int i = 0;\r
-#endif\r
- int ret = 0;\r
- char reg = rxData[0];\r
- ret = senosr_i2c_read(client->adapter, client->addr, reg, 1, length, rxData);\r
- \r
-#ifdef TS_DEBUG_ENABLE\r
- DBG("addr=0x%x,len=%d,rxdata:",reg,length);\r
- for(i=0; i<length; i++)\r
- DBG("0x%x,",rxData[i]);\r
- DBG("\n");\r
-#endif \r
- return ret;\r
+ \r
}\r
-EXPORT_SYMBOL(ts_rx_data);\r
\r
-int ts_rx_data_word(struct i2c_client *client, char *rxData, int length)\r
+#ifdef CONFIG_HAS_EARLYSUSPEND\r
+static void ts_suspend(struct early_suspend *h)\r
{\r
-#ifdef TS_DEBUG_ENABLE\r
- struct ts_private_data* ts = \r
- (struct ts_private_data *)i2c_get_clientdata(client);\r
- int i = 0;\r
-#endif\r
- int ret = 0;\r
- char reg = rxData[0];\r
- ret = senosr_i2c_read(client->adapter, client->addr, reg, 2, length, rxData);\r
+ struct ts_private_data *ts = \r
+ container_of(h, struct ts_private_data, early_suspend);\r
\r
-#ifdef TS_DEBUG_ENABLE\r
- DBG("addr=0x%x,len=%d,rxdata:",reg,length);\r
- for(i=0; i<length; i++)\r
- DBG("0x%x,",rxData[i]);\r
- DBG("\n");\r
-#endif \r
- return ret;\r
+ return ts_device_suspend(ts);\r
}\r
-EXPORT_SYMBOL(ts_rx_data_word);\r
-\r
\r
-int ts_tx_data(struct i2c_client *client, char *txData, int length)\r
+static void ts_resume(struct early_suspend *h)\r
{\r
-#ifdef TS_DEBUG_ENABLE \r
- struct ts_private_data* ts = \r
- (struct ts_private_data *)i2c_get_clientdata(client);\r
- int i = 0;\r
-#endif\r
- int ret = 0;\r
-#ifdef TS_DEBUG_ENABLE \r
- DBG("addr=0x%x,len=%d,txdata:",txData[0],length);\r
- for(i=1; i<length; i++)\r
- DBG("0x%x,",txData[i]);\r
- DBG("\n");\r
-#endif\r
- ret = ts_i2c_write(client->adapter, client->addr, length, txData);\r
- return ret;\r
+ struct ts_private_data *ts = \r
+ container_of(h, struct ts_private_data, early_suspend);\r
\r
+ return ts_device_resume(ts);\r
}\r
-EXPORT_SYMBOL(ts_tx_data);\r
+#endif\r
\r
-int ts_write_reg(struct i2c_client *client, int addr, int value)\r
+static int ts_i2c_probe(struct i2c_client *i2c,\r
+ const struct i2c_device_id *id)\r
{\r
- char buffer[2];\r
- int ret = 0;\r
- struct ts_private_data* ts = \r
- (struct ts_private_data *)i2c_get_clientdata(client);\r
- \r
- mutex_lock(&ts->i2c_mutex); \r
- buffer[0] = addr;\r
- buffer[1] = value;\r
- ret = ts_tx_data(client, &buffer[0], 2); \r
- mutex_unlock(&ts->i2c_mutex); \r
- return ret;\r
-}\r
-EXPORT_SYMBOL(ts_write_reg);\r
+ struct ts_private_data *ts;\r
+ int ret,gpio,irq;\r
+ int type = TS_BUS_TYPE_I2C;\r
\r
-int ts_read_reg(struct i2c_client *client, int addr)\r
-{\r
- char tmp[1] = {0};\r
- int ret = 0; \r
- struct ts_private_data* ts = \r
- (struct ts_private_data *)i2c_get_clientdata(client);\r
+ if (!i2c_check_functionality(i2c->adapter, I2C_FUNC_I2C)) {\r
+ dev_err(&i2c->adapter->dev, "%s failed\n", __func__);\r
+ return -ENODEV;\r
+ }\r
\r
- mutex_lock(&ts->i2c_mutex); \r
- tmp[0] = addr;\r
- ret = ts_rx_data(client, tmp, 1);\r
- mutex_unlock(&ts->i2c_mutex);\r
+ ts = kzalloc(sizeof(struct ts_private_data), GFP_KERNEL);\r
+ if (ts == NULL)\r
+ return -ENOMEM;\r
+\r
+ i2c_set_clientdata(i2c, ts);\r
\r
- return tmp[0];\r
-}\r
+ ts->irq = i2c->irq;\r
+ ts->dev = &i2c->dev;\r
+ ts->control_data = i2c;\r
+ ts->read_dev = ts_i2c_read_device;\r
+ ts->write_dev = ts_i2c_write_device;\r
\r
-EXPORT_SYMBOL(ts_read_reg);\r
+ ret = ts_device_init(ts, type, ts->irq);\r
+ if(ret)\r
+ {\r
+ printk("%s:fail to regist touch, type is %d\n",__func__, type);\r
+ return -1;\r
+ }\r
+ \r
+#ifdef CONFIG_HAS_EARLYSUSPEND\r
+ if((ts->ops->suspend) && (ts->ops->resume))\r
+ {\r
+ ts->early_suspend.suspend = ts_suspend;\r
+ ts->early_suspend.resume = ts_resume;\r
+ ts->early_suspend.level = 0x02;\r
+ register_early_suspend(&ts->early_suspend);\r
+ }\r
+#endif\r
\r
+ return 0;\r
+}\r
\r
-int ts_tx_data_normal(struct i2c_client *client, char *buf, int num)\r
+static int ts_i2c_remove(struct i2c_client *i2c)\r
{\r
- int ret = 0;\r
- ret = i2c_master_normal_send(client, buf, num, TS_I2C_RATE);\r
- \r
- return (ret == num) ? 0 : ret;\r
-}\r
-EXPORT_SYMBOL(ts_tx_data_normal);\r
+ struct ts_private_data *ts = i2c_get_clientdata(i2c);\r
\r
+ ts_device_exit(ts);\r
\r
-int ts_rx_data_normal(struct i2c_client *client, char *buf, int num)\r
-{\r
- int ret = 0;\r
- ret = i2c_master_normal_recv(client, buf, num, TS_I2C_RATE);\r
- \r
- return (ret == num) ? 0 : ret;\r
+ return 0;\r
}\r
\r
-EXPORT_SYMBOL(ts_rx_data_normal);\r
\r
+static const struct i2c_device_id ts_i2c_id[] = {\r
+ {"auto_ts_i2c", 0},\r
+ {},\r
+};\r
+MODULE_DEVICE_TABLE(i2c, ts_i2c_id);\r
+\r
+static struct i2c_driver ts_i2c_driver = {\r
+ .driver = {\r
+ .name = "auto_ts_i2c",\r
+ .owner = THIS_MODULE,\r
+ },\r
+ .probe = ts_i2c_probe,\r
+ .remove = ts_i2c_remove,\r
+ .id_table = ts_i2c_id,\r
+};\r
\r
-int ts_write_reg_normal(struct i2c_client *client, char value)\r
+static int __init ts_i2c_init(void)\r
{\r
- char buffer[2];\r
- int ret = 0;\r
- struct ts_private_data* ts = \r
- (struct ts_private_data *)i2c_get_clientdata(client);\r
- \r
- mutex_lock(&ts->i2c_mutex); \r
- buffer[0] = value;\r
- ret = ts_tx_data_normal(client, &buffer[0], 1); \r
- mutex_unlock(&ts->i2c_mutex); \r
+ int ret;\r
+\r
+ printk("%s\n", __FUNCTION__);\r
+ ret = i2c_add_driver(&ts_i2c_driver);\r
+ if (ret != 0)\r
+ pr_err("Failed to register ts I2C driver: %d\n", ret);\r
+\r
return ret;\r
}\r
-EXPORT_SYMBOL(ts_write_reg_normal);\r
+subsys_initcall_sync(ts_i2c_init);\r
\r
-int ts_read_reg_normal(struct i2c_client *client)\r
+static void __exit ts_i2c_exit(void)\r
{\r
- char tmp[1] = {0};\r
- int ret = 0; \r
- struct ts_private_data* ts = \r
- (struct ts_private_data *)i2c_get_clientdata(client);\r
- \r
- mutex_lock(&ts->i2c_mutex); \r
- ret = ts_rx_data_normal(client, tmp, 1);\r
- mutex_unlock(&ts->i2c_mutex);\r
- \r
- return tmp[0];\r
+ i2c_del_driver(&ts_i2c_driver);\r
}\r
-\r
-EXPORT_SYMBOL(ts_read_reg_normal);\r
+module_exit(ts_i2c_exit);\r
\r
#define TS_MAX_POINT 20\r
#define TS_MAX_VER_LEN 64\r
\r
+struct ts_private_data;\r
+\r
+enum ts_bus_type{\r
+ TS_BUS_TYPE_INVALID = 0,\r
+ \r
+ TS_BUS_TYPE_I2C,\r
+ TS_BUS_TYPE_SPI,\r
+ TS_BUS_TYPE_SERIAL,\r
+ \r
+ TS_BUS_TYPE_NUM_ID,\r
+};\r
\r
enum ts_id {\r
TS_ID_INVALID = 0,\r
struct ts_operate {\r
char *name;\r
char slave_addr;\r
- int id_i2c;\r
+ int ts_id;\r
+ int bus_type;\r
struct ts_max_pixel pixel;\r
int reg_size;\r
int id_reg;\r
int irq_enable; //if irq_enable=1 then use irq else use polling \r
int poll_delay_ms; //polling\r
int gpio_level_no_int;\r
- int (*active)(struct i2c_client *client, int enable);\r
- int (*init)(struct i2c_client *client); \r
- int (*check_irq)(struct i2c_client *client);\r
- int (*report)(struct i2c_client *client);\r
- int (*firmware)(struct i2c_client *client);\r
- int (*suspend)(struct i2c_client *client);\r
- int (*resume)(struct i2c_client *client); \r
+ int (*active)(struct ts_private_data *ts, int enable);\r
+ int (*init)(struct ts_private_data *ts); \r
+ int (*check_irq)(struct ts_private_data *ts);\r
+ int (*report)(struct ts_private_data *ts);\r
+ int (*firmware)(struct ts_private_data *ts);\r
+ int (*suspend)(struct ts_private_data *ts);\r
+ int (*resume)(struct ts_private_data *ts); \r
struct miscdevice *misc_dev;\r
-\r
};\r
\r
\r
struct ts_private_data {\r
- struct i2c_client *client; \r
+ struct mutex io_lock;\r
+ struct device *dev;\r
+ int (*read_dev)(struct ts_private_data *ts, unsigned short reg,\r
+ int bytes, void *dest, int reg_size);\r
+ int (*write_dev)(struct ts_private_data *ts, unsigned short reg,\r
+ int bytes, void *src, int reg_size);\r
+ void *control_data;\r
+ int irq;\r
+ //struct i2c_client *client; \r
struct input_dev *input_dev;\r
struct ts_event event;\r
struct work_struct work;\r
struct delayed_work poll_work; /*poll at last*/ \r
char ts_data[40]; //max support40 bytes data\r
struct mutex data_mutex;\r
- struct mutex ts_mutex;\r
- struct mutex i2c_mutex;\r
+ struct mutex ts_lock;\r
int devid;\r
struct i2c_device_id *i2c_id;\r
struct ts_platform_data *pdata;\r
#endif\r
};\r
\r
-\r
-extern int ts_register_slave(struct i2c_client *client,\r
+extern int ts_device_init(struct ts_private_data *ts, int type, int irq);\r
+extern void ts_device_exit(struct ts_private_data *ts);\r
+extern int ts_register_slave(struct ts_private_data *ts,\r
struct ts_platform_data *slave_pdata,\r
struct ts_operate *(*get_ts_ops)(void));\r
-\r
-\r
-extern int ts_unregister_slave(struct i2c_client *client,\r
+extern int ts_unregister_slave(struct ts_private_data *ts,\r
struct ts_platform_data *slave_pdata,\r
struct ts_operate *(*get_ts_ops)(void));\r
-\r
-extern int ts_rx_data(struct i2c_client *client, char *rxData, int length);\r
-extern int ts_tx_data(struct i2c_client *client, char *txData, int length);\r
-extern int ts_rx_data_word(struct i2c_client *client, char *rxData, int length);\r
-extern int ts_write_reg(struct i2c_client *client, int addr, int value);\r
-extern int ts_read_reg(struct i2c_client *client, int addr);\r
-extern int ts_tx_data_normal(struct i2c_client *client, char *buf, int num);\r
-extern int ts_rx_data_normal(struct i2c_client *client, char *buf, int num);\r
-extern int ts_write_reg_normal(struct i2c_client *client, char value);\r
-extern int ts_read_reg_normal(struct i2c_client *client);\r
+extern int ts_reg_read(struct ts_private_data *ts, unsigned short reg);\r
+extern int ts_reg_write(struct ts_private_data *ts, unsigned short reg,\r
+ unsigned short val);\r
+extern int ts_bulk_read(struct ts_private_data *ts, unsigned short reg,\r
+ int count, u16 *buf);\r
+extern int ts_bulk_write(struct ts_private_data *ts, unsigned short reg,\r
+ int count, u16 *buf);\r
+extern int ts_set_bits(struct ts_private_data *ts, unsigned short reg,\r
+ unsigned short mask, unsigned short val);\r
+extern int ts_device_suspend(struct ts_private_data *ts);\r
+\r
+extern int ts_device_resume(struct ts_private_data *ts);\r
\r
#endif\r