gt811 driver
- #include <linux/module.h>
- #include <linux/i2c.h>
- #include <linux/platform_device.h>
- #include <linux/gpio.h>
- #include <linux/of.h>
- #include <linux/of_platform.h>
- #include <linux/of_gpio.h>
- #include <linux/input.h>
- #include <linux/input/mt.h>
- #include <linux/interrupt.h>
- #include <linux/delay.h>
- struct gt811_ts_platdata
- {
- u32 size_x;
- u32 size_y;
- u32 size_p;
- u32 swap;
- u32 revert_x;
- u32 revert_y;
- u32 reset_pin;
- u32 interrupt_pin;
- u32 ponits_max;
- struct i2c_client *client;
- struct input_dev *input;
- struct work_struct work;
- };
- static const struct of_device_id gt811_ts_of_match[] = {
- { .compatible = "gt811,gt811_ts", .data = NULL },
- { }
- };
- static int i2c_write_bytes(struct i2c_client *client, uint8_t *data, int len){
- struct i2c_msg msg;
- msg.flags=!I2C_M_RD;
- msg.addr=client->addr;
- msg.len=len;
- msg.buf=data;
- return i2c_transfer(client->adapter,&msg, 1);
- }
- static int i2c_read_bytes(struct i2c_client *client, uint8_t *buf, int len){
- struct i2c_msg msgs[2];
- msgs[0].flags=!I2C_M_RD;
- msgs[0].addr=client->addr;
- msgs[0].len=2;
- msgs[0].buf=&buf[0];
- msgs[1].flags=I2C_M_RD;
- msgs[1].addr=client->addr;
- msgs[1].len=len-2;
- msgs[1].buf=&buf[2];
- return i2c_transfer(client->adapter,msgs, 2);
- }
- static void gt811_ts_handler(struct work_struct *work)
- {
- struct gt811_ts_platdata *pdata = container_of(work, struct gt811_ts_platdata, work);
- struct device *dev = &pdata->client->dev;
- uint8_t buffer[36] = {0x07, 0x21, 0};
- uint8_t count, index, flags, position;
- int x, y;
- buffer[0] = 0x0f;
- buffer[1] = 0xff;
- if (i2c_write_bytes(pdata->client,buffer,2) < 0) {
- dev_err(dev, "Failed to write wakeup message.\n");
- goto reenable_irq;
- }
- buffer[0] = 0x07;
- buffer[1] = 0x21;
- if (i2c_read_bytes(pdata->client, buffer, sizeof(buffer)) < 0) {
- dev_err(dev, "Failed to read touch message.\n");
- goto reenable_irq;
- }
- buffer[0] = 0x80;
- buffer[1] = 0x00;
- if (i2c_write_bytes(pdata->client, buffer, 2) < 0) {
- dev_err(dev, "Failed to write sleep message.\n");
- goto reenable_irq;
- }
- buffer[25] = buffer[19];
- buffer[19] = 0;
- flags = buffer[2]&0x1f;
- while (flags) {
- if (!(flags&0x1)) {
- continue;
- }
- if (index < 3) {
- position = 4 + index * 5;
- }
- else{
- position = 25 + (index - 3) * 5;
- }
- x = (buffer[position] << 8) | buffer[position + 1];
- y = (buffer[position + 2] << 8) | buffer[position + 3];
- if(pdata->swap) {
- swap(x, y);
- }
- if(pdata->revert_x){
- x = pdata->size_x - x;
- }
- if(pdata->revert_y){
- y = pdata->size_y - y;
- }
- printk("point:(x:%03d, y:%03d)\n", x, y);
- }
- // 组织检测出来的触摸点信息上报到输入子系统节点即可
- reenable_irq:
- enable_irq(pdata->client->irq);
- }
- static irqreturn_t gt811_ts_isr(int irq, void *dev_id)
- {
- struct gt811_ts_platdata* pdata = (struct gt811_ts_platdata*)dev_id;
- disable_irq_nosync(pdata->client->irq);
- schedule_work(&pdata->work);
- return IRQ_HANDLED;
- }
- static int gt811_ts_initilize(struct i2c_client *client)
- {
- struct device *dev = &client->dev;
- struct gt811_ts_platdata *pdata = (struct gt811_ts_platdata*)i2c_get_clientdata(client);
- int status = 0, count = 0;
- uint8_t version[4] = {0x7, 0x17, 0};
- uint8_t config[] = {
- 0x06,0xA2,
- 0x12,0x10,0x0E,0x0C,0x0A,0x08,0x06,0x04,0x02,0x00,0xE2,0x53,0xD2,0x53,0xC2,0x53,
- 0xB2,0x53,0xA2,0x53,0x92,0x53,0x82,0x53,0x72,0x53,0x62,0x53,0x52,0x53,0x42,0x53,
- 0x32,0x53,0x22,0x53,0x12,0x53,0x02,0x53,0xF2,0x53,0x0F,0x13,0x40,0x40,0x40,0x10,
- 0x10,0x10,0x0F,0x0F,0x0A,0x35,0x25,0x0C,0x03,0x00,0x05,0x20,0x03,0xE0,0x01,0x00,
- 0x00,0x34,0x2C,0x36,0x2E,0x00,0x00,0x03,0x19,0x03,0x08,0x00,0x00,0x00,0x00,0x00,
- 0x14,0x10,0xEC,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0D,0x40,
- 0x30,0x3C,0x28,0x00,0x00,0x00,0x00,0xC0,0x12,0x01
- };
- config[62] = 480 >> 8;
- config[61] = 480 & 0xff;
- config[64] = 800 >> 8;
- config[63] = 800 & 0xff;
- if (!gpio_is_valid(pdata->reset_pin)) {
- dev_err(dev, "The reset pin number is invalid.\n");
- return -EINVAL;
- }
- count = 3;
- while (count--) {
- gpio_direction_output(pdata->reset_pin, 0);
- msleep(10);
- gpio_direction_output(pdata->reset_pin, 1);
- msleep(100);
- if (i2c_read_bytes(client, version, sizeof(version)) < 0) {
- dev_err(dev, "Failed to get the version of GT811, try again...\n");
- status = -ENODEV;
- }
- else {
- dev_info(dev, "Gt811 detected, version(%04x)...\n", (version[2]<<8)|version[3]);
- status = 0;
- break;
- }
- }
- if (status) {
- return status;
- }
- count = 3;
- while (count--) {
- if (i2c_write_bytes(client, config, sizeof(config)) < 0) {
- dev_err(dev, "Failed to configure the GT811, try again...\n");
- status = -EINVAL;
- }
- else {
- dev_info(dev, "Gt811 configue succeed\n");
- status = 0;
- break;
- }
- }
- return status;
- }
- static struct gt811_ts_platdata *gt811_ts_parse_devtree(struct i2c_client *client)
- {
- struct device *dev = &client->dev;
- struct device_node *node;
- struct gt811_ts_platdata *pdata;
- enum of_gpio_flags flags;
- node = dev->of_node;
- if (!node) {
- dev_err(dev, "The of_node is NULL.\n");
- return ERR_PTR(-ENODEV);
- }
- pdata = devm_kzalloc(dev, sizeof(struct device_node), GFP_KERNEL);
- if (!pdata) {
- dev_err(dev, "No enough memory left.\n");
- return ERR_PTR(-ENOMEM);
- }
- pdata->reset_pin = of_get_gpio_flags(node, 0, &flags);
- if (pdata->reset_pin < 0) {
- dev_err(dev, "Get RST pin failed!\n");
- return ERR_PTR(-EINVAL);
- }
- if (of_property_read_u32(node, "touchscreen-size-x", &pdata->size_x )) {
- dev_err(dev, "Failed to get the touch screen x size.\n");
- return ERR_PTR(-EINVAL);
- }
- if (of_property_read_u32(node, "touchscreen-size-y", &pdata->size_y)) {
- dev_err(dev, "Failed to get the touch screen y size.\n");
- return ERR_PTR(-EINVAL);
- }
- if (of_property_read_u32(node, "touchscreen-size-p", &pdata->size_p)) {
- pdata->size_p = 255;
- }
- if (of_property_read_u32(node, "touchscreen-swap", &pdata->swap)) {
- pdata->swap = 1;
- }
- if (of_property_read_u32(node, "touchscreen-revert-x", &pdata->revert_x)) {
- pdata->revert_x = 1;
- }
- if (of_property_read_u32(node, "touchscreen-revert-x", &pdata->revert_y)) {
- pdata->revert_y = 1;
- }
- return pdata;
- }
- static int gt811_ts_probe(struct i2c_client *client, const struct i2c_device_id *id)
- {
- struct device *dev = &client->dev;
- struct gt811_ts_platdata *pdata = dev_get_platdata(dev);
- struct input_dev *input;
- int error = 0;
- if (!of_match_device(of_match_ptr(gt811_ts_of_match), dev)) {
- dev_err(dev, "Failed to match.\n");
- return -EINVAL;
- }
- if (!pdata) {
- pdata = gt811_ts_parse_devtree(client);
- if (IS_ERR(pdata)) {
- dev_err(dev, "Get device data from device tree failed!\n");
- error = -EINVAL;
- goto failed_exit;
- }
- }
- pdata->client = client;
- i2c_set_clientdata(client, pdata);
- input = devm_input_allocate_device(dev);
- if (!input) {
- dev_err(dev, "Failed to allocate input device\n");
- error = -ENOMEM;
- goto pdata_free;
- }
- pdata->input = input;
- input->name = client->name;
- input->id.bustype = BUS_I2C;
- input->id.product = 0xBEEF;
- input->id.vendor =0xDEAD;
- input->dev.parent = &client->dev;
- __set_bit(EV_KEY, input->evbit);
- __set_bit(EV_ABS, input->evbit);
- __set_bit(BTN_TOUCH, input->keybit);
- input_set_abs_params(input, ABS_X, 0, pdata->size_x, 0, 0);
- input_set_abs_params(input, ABS_Y, 0, pdata->size_y, 0, 0);
- input_set_abs_params(input, ABS_MT_POSITION_X, 0, pdata->size_x, 0, 0);
- input_set_abs_params(input, ABS_MT_POSITION_Y, 0, pdata->size_y, 0, 0);
- error = input_mt_init_slots(input, 5, INPUT_MT_DIRECT | INPUT_MT_DROP_UNUSED);
- if (error) {
- dev_err(dev, "Failed to initialize the multi-touch slots.\n");
- goto input_free;
- }
- input_set_drvdata(input, pdata);
- error = input_register_device(input);
- if (error) {
- dev_err(dev, "Register input device failed!\n");
- goto input_free;
- }
- if (gt811_ts_initilize(client)) {
- dev_err(dev, "Failed to initialize GT811.\n");
- }
- INIT_WORK(&pdata->work, gt811_ts_handler);
- error = devm_request_any_context_irq(dev, client->irq, gt811_ts_isr,
- IRQF_TRIGGER_FALLING, client->name, pdata);
- if (error) {
- dev_err(dev, "Failed to request irq(number:%d)\n", client->irq);
- goto input_free;
- }
- return 0;
- input_free:
- devm_kfree(dev, input);
- pdata_free:
- devm_kfree(dev, pdata);
- failed_exit:
- return error;
- }
- static int gt811_ts_remove(struct i2c_client *client)
- {
- struct gt811_ts_platdata *pdata = (struct gt811_ts_platdata*)i2c_get_clientdata(client);
- devm_free_irq(&client->dev, client->irq, i2c_get_clientdata(client));
- input_unregister_device(pdata->input);
- devm_kfree(&client->dev, pdata);
- return 0;
- }
- static const struct i2c_device_id gt811_ts_id[] = {
- { "gt811_ts", 0 },
- { }
- };
- static struct i2c_driver gt811_ts_driver = {
- .driver = {
- .owner = THIS_MODULE,
- .name = "gt811_ts",
- .of_match_table = of_match_ptr(gt811_ts_of_match),
- },
- .probe = gt811_ts_probe,
- .remove = gt811_ts_remove,
- .id_table = gt811_ts_id,
- };
- module_i2c_driver(gt811_ts_driver);
- MODULE_AUTHOR("girlkoo <nightmeng@gmail.com>");
- MODULE_DESCRIPTION("Gt811 I2C Touchscreen Driver");
- MODULE_LICENSE("GPL");
gt811 driver的更多相关文章
- 深入linux kernel内核配置选项
============================================================================== 深入linux kernel内核配置选项 ...
- MongoDB Java Driver操作指南
MongoDB为Java提供了非常丰富的API操作,相比关系型数据库,这种NoSQL本身的数据也有点面向对象的意思,所以对于Java来说,Mongo的数据结构更加友好. MongoDB在今年做了一次重 ...
- c#操作MangoDB 之MangoDB CSharp Driver驱动详解
序言 MangoDB CSharp Driver是c#操作mongodb的官方驱动. 官方Api文档:http://api.mongodb.org/csharp/2.2/html/R_Project_ ...
- Java JDBC Thin Driver 连接 Oracle 三种方法说明(转载)
一.JDBC 连接Oracle 说明 JDBC 的应用连接Oracle 遇到问题,错误如下: ORA-12505,TNS:listener does not currently know of SID ...
- 设备模型(device-model)之平台总线(bus),驱动(driver),设备(device)
关于关于驱动设备模型相关概念请参考<Linux Device Drivers>等相关书籍,和内核源码目录...\Documentation\driver-model 简单来说总线(bus) ...
- AM335x tscadc platform driver 相关代码跟踪
TI AM335x ti am335x_tsc.c 代码跟踪 在kernel 首层目录: 先运行make ARCH=arm tags 这个作用是建立tags文件,只含有arm架构的,利用ctag即可进 ...
- selenium web driver 实现截图功能
在验证某些关键步骤时,需要截个图来记录一下当时的情况 Webdriver截图时,需要引入 import java.io.File; import java.io.IOException; import ...
- selenium web driver 使用JS修改input属性
selenium获取input时候,发现type=”hidden” 的input无法修改value,经牛人指点,可以使用js修改 首先html源文件如下,设置为text .hidden.submit ...
- 转载:安装ie driver和chrome driver
很多同学在使用webdriver的时候总是忘了安装ie driver和chrome driver, 因此在这里简单介绍一下这2个driver的安装方式. IE driver 在新版本的webdrive ...
随机推荐
- [Big Data] Week 5 A (Advance)
Question 1 Consider the diagonal matrix M = 1 0 0 0 2 0 0 0 0 . Compute its Moore-Penrose pseudoinve ...
- 理解JAVASCRIPT 中hasOwnProperty()和isPrototypeOf的作用
hasOwnProperty:是用来判断一个对象是否有你给出名称的属性或对象.不过需要注意的是,此方法无法检查该对象的原型链中是否具有该属性,该属性必须是对象本身的一个成员.格式如下: 1. 示例一: ...
- WCF 之 已知类型(KnownType)
已知类型(Known types)允许在服务契约中使用多态的行为,在服务操作中暴露基本类型.将已知类型(known types)相关到基本类型(基类类型)自身;特定操作;整个服务契约采用属性声明或者配 ...
- Matlab矩阵基本操作(定义,运算)
转自:http://blog.csdn.net/perfumekristy/article/details/8119861 一.矩阵的表示在MATLAB中创建矩阵有以下规则: a.矩阵元素必须在”[ ...
- IOS客户端Coding项目记录(二)
9:第三方插件整理 JSON转实体:jsonModel https://github.com/icanzilb/JSONModel/ 美化按键:BButton https://github.com/m ...
- myDate97 设置开始时间和结束时间
myDate97 设置开始时间和结束时间 CreationTime--2018年8月28日16点46分 Author:Marydon 1.简单示例 第一步:引入My97DatePicker/Wda ...
- 〖Qt编程〗Qt编程中的各种数据类型的相互转换
char * 与 const char *的转换 char *ch1=”hello11″; const char *ch2=”hello22″; ch2 = ch1;//不报错,但有警告 ch1 = ...
- ORA-12519:数据的连接池访问过多
今天服务部同事问我一个问题,客户处的报表一半能打开,一半报错如下: Io 异常: Connection refused(DESCRIPTION=(TMP=)(VSNNUM=185599744)(ERR ...
- C3P0连接参数解释
<c3p0-config> <default-config> <!--当连接池中的连接耗尽的时候c3p0一次同时获取的连接数.Default: 3 --> < ...
- mysql root用户密码个性
对名为“mysql”数据库下的表“user”进行操作如下语句:update user set password=PASSWORD("your_password") where us ...