#ifndef __LINUX_MSTAR_MSG2133_TS_H__
#define __LINUX_MSTAR_MSG2133_TS_H__
//#define TS_DEBUG_MSG 1
#define VIRTUAL_KEYS 1 //是否有按键
#define MSG2133_UPDATE 1 //T卡升级功能
#define TS_WIDTH_MAX 480 //LCD分辨率
#define TS_HEIGHT_MAX 800 //LCD分辨率 //使用虚拟按键,也不需要把这个分辨率提高到按键区域。
#define TS_ENPIN_LEVEL 0 //ENPIN(ResetPin)电压,如果TP上有反相MOS管,则设为1
#define MSG2133_BUS_NUM 2
#define MSG2133_TS_NAME "msg2133"
#define MSG2133_TS_ADDR 0x26
#define MSG2133_FW_ADDR 0x62
#define MSG2133_FW_UPDATE_ADDR 0x49
#define TPD_OK 0
#define TPD_REG_BASE 0x00
#define TPD_SOFT_RESET_MODE 0x01
#define TPD_OP_MODE 0x00
#define TPD_LOW_PWR_MODE 0x04
#define TPD_SYSINFO_MODE 0x10
#define GET_HSTMODE(reg) ((reg & 0x70) >> 4) // in op mode or not
#define GET_BOOTLOADERMODE(reg) ((reg & 0x10) >> 4) // in bl mode
struct ts_event {
u16 x1;
u16 y1;
u16 x2;
u16 y2;
u8 touch_point;
};
struct msg2133_ts_data {
struct input_dev *input_dev;
struct ts_event event;
struct work_struct pen_event_work;
struct workqueue_struct *ts_workqueue;
struct early_suspend early_suspend;
};
struct TouchScreenInfo_t{
unsigned char nTouchKeyMode;
unsigned char nTouchKeyCode;
//unsigned char nFingerNum;
} ;
#endif // end of __LINUX_MSTAR_MSG2133_TS_H__
================== 分割线 ======================================
/*
* drivers/input/touchscreen/msg2133_ts.c
*
* MStar msg2133 TouchScreen driver.
*
* Copyright (c) 2012 MStar Semiconductor, Inc.
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* 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.
*
* VERSION DATE AUTHOR
* 1.0 2010-01-05 WenFS
*
* note: only support mulititouch Wenfs 2010-10-01
*/
#include <linux/i2c.h>
#include <linux/input.h>
#include <linux/gpio.h>
#include <linux/earlysuspend.h>
#include <linux/interrupt.h>
#include <linux/delay.h>
#include <linux/firmware.h>
#include <linux/platform_device.h>
#include <linux/slab.h>
#include <mach/ldo.h>
#include "msg2133.h"
#define TS_DEBUG_MSG 1// use MSG2133_DBG
#if TS_DEBUG_MSG
#define MSG2133_DBG(format, ...) printk(KERN_INFO "MSG2133 " format "\n", ## __VA_ARGS__)
#else
#define MSG2133_DBG(format, ...)
#endif
extern int sprd_3rdparty_gpio_tp_rst;
extern int sprd_3rdparty_gpio_tp_irq;
static struct i2c_client *this_client;
static struct i2c_board_info msg2133_i2c_boardinfo = {
I2C_BOARD_INFO(MSG2133_TS_NAME, MSG2133_TS_ADDR),
};
static void msg2133_device_power_on();
#ifdef MSG2133_UPDATE
struct class *firmware_class;
struct device *firmware_cmd_dev;
static int update_switch = 0;
static int FwDataCnt;
static char *fw_version;
static unsigned char temp[94][1024];
static void msg2133_reset()
{
gpio_set_value(sprd_3rdparty_gpio_tp_rst, TS_ENPIN_LEVEL);
msg2133_device_power_on();
msleep(20);
gpio_set_value(sprd_3rdparty_gpio_tp_rst,!TS_ENPIN_LEVEL);
msleep(500);
}
static bool msg2133_i2c_read(char *pbt_buf, int dw_lenth)
{
int ret;
//MSG2133_DBG("The msg_i2c_client->addr=0x%x\n",i2c_client->addr);
ret = i2c_master_recv(this_client, pbt_buf, dw_lenth);
if(ret <= 0){
MSG2133_DBG("msg_i2c_read_interface error\n");
return false;
}
return true;
}
static bool msg2133_i2c_write(char *pbt_buf, int dw_lenth)
{
int ret;
//MSG2133_DBG("The msg_i2c_client->addr=0x%x\n",i2c_client->addr);
ret = i2c_master_send(this_client, pbt_buf, dw_lenth);
if(ret <= 0){
MSG2133_DBG("msg_i2c_read_interface error\n");
return false;
}
return true;
}
static void i2c_read_msg2133(unsigned char *pbt_buf, int dw_lenth)
{
this_client->addr = MSG2133_FW_ADDR;
i2c_master_recv(this_client, pbt_buf, dw_lenth); //0xC5_8bit
this_client->addr = MSG2133_TS_ADDR;
}
static void i2c_write_msg2133(unsigned char *pbt_buf, int dw_lenth)
{
this_client->addr = MSG2133_FW_ADDR;
i2c_master_send(this_client, pbt_buf, dw_lenth); //0xC4_8bit
this_client->addr = MSG2133_TS_ADDR;
}
static void i2c_read_update_msg2133(unsigned char *pbt_buf, int dw_lenth)
{
this_client->addr = MSG2133_FW_UPDATE_ADDR;
i2c_master_recv(this_client, pbt_buf, dw_lenth); //0x93_8bit
this_client->addr = MSG2133_TS_ADDR;
}
static void i2c_write_update_msg2133(unsigned char *pbt_buf, int dw_lenth)
{
this_client->addr = MSG2133_FW_UPDATE_ADDR;
i2c_master_send(this_client, pbt_buf, dw_lenth); //0x92_8bit
this_client->addr = MSG2133_TS_ADDR;
}
void dbbusDWIICEnterSerialDebugMode(void)
{
unsigned char data[5];
// Enter the Serial Debug Mode
data[0] = 0x53;
data[1] = 0x45;
data[2] = 0x52;
data[3] = 0x44;
data[4] = 0x42;
i2c_write_msg2133(data, 5);
}
void dbbusDWIICStopMCU(void)
{
unsigned char data[1];
// Stop the MCU
data[0] = 0x37;
i2c_write_msg2133(data, 1);
}
void dbbusDWIICIICUseBus(void)
{
unsigned char data[1];
// IIC Use Bus
data[0] = 0x35;
i2c_write_msg2133(data, 1);
}
void dbbusDWIICIICReshape(void)
{
unsigned char data[1];
// IIC Re-shape
data[0] = 0x71;
i2c_write_msg2133(data, 1);
}
void dbbusDWIICIICNotUseBus(void)
{
unsigned char data[1];
// IIC Not Use Bus
data[0] = 0x34;
i2c_write_msg2133(data, 1);
}
void dbbusDWIICNotStopMCU(void)
{
unsigned char data[1];
// Not Stop the MCU
data[0] = 0x36;
i2c_write_msg2133(data, 1);
}
void dbbusDWIICExitSerialDebugMode(void)
{
unsigned char data[1];
// Exit the Serial Debug Mode
data[0] = 0x45;
i2c_write_msg2133(data, 1);
// Delay some interval to guard the next transaction
}
void drvISP_EntryIspMode(void)
{
unsigned char bWriteData[5] =
{
0x4D, 0x53, 0x54, 0x41, 0x52
};
i2c_write_update_msg2133(bWriteData, 5);
msleep(10); // delay about 10ms
}
void drvISP_WriteEnable(void)
{
unsigned char bWriteData[2] =
{
0x10, 0x06
};
unsigned char bWriteData1 = 0x12;
i2c_write_update_msg2133(bWriteData, 2);
i2c_write_update_msg2133(&bWriteData1, 1);
}
unsigned char drvISP_Read(unsigned char n, unsigned char *pDataToRead) //First it needs send 0x11 to notify we want to get flash data back.
{
unsigned char Read_cmd = 0x11;
unsigned char i = 0;
unsigned char dbbus_rx_data[16] = {0};
i2c_write_update_msg2133(&Read_cmd, 1);
//if (n == 1)
{
i2c_read_update_msg2133(&dbbus_rx_data[0], n + 1);
for(i = 0; i < n; i++)
{
*(pDataToRead + i) = dbbus_rx_data[i + 1];
}
}
//else
{
// i2c_read_update_msg2133(pDataToRead, n);
}
return 0;
}
unsigned char drvISP_ReadStatus(void)
{
unsigned char bReadData = 0;
unsigned char bWriteData[2] =
{
0x10, 0x05
};
unsigned char bWriteData1 = 0x12;
// msleep(1); // delay about 100us
i2c_write_update_msg2133(bWriteData, 2);
// msleep(1); // delay about 100us