之所以说是驱动移植是因为之前已经在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