I.MX6Q(TQIMX6Q/TQE9)学习笔记——新版BSP之触摸屏驱动移植

之所以说是驱动移植是因为之前已经在TQ210、AM335x两个平台上移植过了,因此,仅需要少量修改就可以将驱动移植到imx6q。下面开始触摸驱动移植。

DTS编写

参考其它DTS的i2c设备写法,我们可以添加如下内容:

&i2c1 {
	clock-frequency = <100000>;
	pinctrl-names = "default";
	pinctrl-0 = <&pinctrl_i2c1_2>;
	status = "okay";

	gt811@5d {
		compatible = "gt811,gt811_ts";  
	    pinctrl-names = "default";  
		reg = <0x5d>;  
		interrupt-parent = <&gpio1>;  
		interrupts = <9 2>;  
		gpios = <&gpio1 5 0>;  
		  
		touchscreen-size-x = <800>;  
		touchscreen-size-y = <480>;  

		touchscreen-swap = <1>;  
		touchscreen-revert-x = <1>;  
		touchscreen-revert-y = <1>; 
	};
};

添加以上内容后重新编译并烧写DTB。

驱动编写

其实移植AM335x的时候就是以DTB方式移植的,因此,除内核api变更的部分需要修改一下,其它代码基本是不需要修改的。驱动代码如下(不含event上报代码):

#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>
#include <linux/io.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_tr
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值