初级会员
- 积分
- 178
- 金钱
- 178
- 注册时间
- 2020-3-11
- 在线时间
- 17 小时
|
2金钱
问题描述:
1、设备树已经按照教程更改如下
ft5426: edt-ft5x06@38 {
compatible = "atk,ft5x06";
reg = <0x38>;
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_tsc>;
interrupt-parent = <&gpio1>;
interrupt-gpios = <&gpio1 9 GPIO_ACTIVE_LOW>;
interrupts = <9 0>;
reset-gpios = <&gpio5 9 GPIO_ACTIVE_LOW>;
};
pinctrl_tsc: tscgrp {
fsl,pins = <
MX6UL_PAD_GPIO1_IO09__GPIO1_IO09 0xf080
MX6UL_PAD_SNVS_TAMPER9__GPIO5_IO09 0x10b0
>;
};
pinctrl_i2c2: i2c2grp {
fsl,pins = <
MX6UL_PAD_UART5_TX_DATA__I2C2_SCL 0x4001b8b0
MX6UL_PAD_UART5_RX_DATA__I2C2_SDA 0x4001b8b0
>;
};
&tsc {
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_tsc>;
xnur-gpio = <&gpio1 3 GPIO_ACTIVE_LOW>;
measure-delay-time = <0xffff>;
pre-charge-time = <0xfff>;
status = "disable";
}; //原来tsc 上的status 是okay, 但是加载驱动的时候会报错,错误为:
/23_mulitiouch # insmod ft5x06.ko
[ 94.504859] imx6ul-pinctrl 20e0000.iomuxc: pin MX6UL_PAD_GPIO1_IO09 already requested by 2040000.tsc; cannot claim for 1-0038
[ 94.521168] imx6ul-pinctrl 20e0000.iomuxc: pin-32 (1-0038) status -22
[ 94.530066] imx6ul-pinctrl 20e0000.iomuxc: could not request pin 32 (MX6UL_PAD_GPIO1_IO09) from group tscgrp on device 20e0000.iomuxc
[ 94.547052] edt_ft5x06 1-0038: Error applying setting, reverse things back
[ 94.881608] input: ft5x06 as /devices/platform/soc/2100000.aips-bus/21a4000.i2c/i2c-1/1-0038/input/input3
将status 的值改为 disable后 已经可以正常加载
insmod ft5x06.ko
[ 26.361738] input: ft5x06 as /devices/platform/soc/2100000.aips-bus/21a4000.i2c/i2c-1/1-0038/input/input2
加载驱动之前 input中的设备:
/23_multitouch # ls /dev/input/
event0 mice
加载驱动后input中的设备
/23_multitouch # insmod ft5x06.ko
[ 4959.621623] input: ft5x06 as /devices/platform/soc/2100000.aips-bus/21a4000.i2c/i2c-1/1-0038/input/input3
/23_multitouch # ls /dev/input/
event0 event1 mice mouse0
现在使用 hexdump /dev/input/event1 然后触摸屏幕的任何地方,都没有input信息上报,请问各位大侠这是为什么呢?
贴出代码:
#include <linux/ide.h>
#include <linux/types.h>
#include <linux/kernel.h>
#include <linux/delay.h>
#include <linux/module.h>
#include <linux/i2c.h>
#include <linux/of.h>
#include <linux/input.h>
#include <linux/platform_device.h>
#include <linux/gpio.h>
#include <linux/of_address.h>
#include <linux/of_device.h>
#include <linux/of_gpio.h>
#include <linux/errno.h>
#include <linux/device.h>
#include <asm/mach/map.h>
#include <asm/uaccess.h>
#include <asm/io.h>
#include <linux/ratelimit.h>
#include <linux/interrupt.h>
#include <linux/input/mt.h>
#include <linux/input/touchscreen.h>
#define MAX_SUPPORT_POINTS 5
#define TOUCH_EVENT_DOWN 0x00
#define TOUCH_EVENT_UP 0x01
#define TOUCH_EVENT_ON 0x02
#define TOUCH_EVENT_RESERVED 0x03
#define FT5X06_TD_STATUS_REG 0x02
#define FT5x06_DEVICE_MODE_REG 0X00
#define FT5426_IDG_MODE_REG 0XA4
#define FT5X06_READLEN 29
struct ft5x06{
struct i2c_client *client;
struct input_dev *input;
struct device_node *nd;
int irq_pin;
int reset_pin;
int irqnum;
void *private_data;
};
struct ft5x06 ft5x06_dev;
static int ft5x06_ts_reset(struct i2c_client *client, struct ft5x06 *dev)
{
int error = 0;
if(gpio_is_valid(dev->reset_pin)){
error = devm_gpio_request_one(&client->dev,dev->reset_pin,GPIOF_OUT_INIT_LOW,"edt-ft5x06 wake");
if(error){
return error;
}
msleep(5);
gpio_set_value(dev->reset_pin, 1);
msleep(300);
}
return 0;
}
static int ft5x06_read_regs(struct ft5x06 *dev, u8 reg, u8 *buf, u8 len)
{
struct i2c_client *client = (struct i2c_client *)dev->client;
struct i2c_msg msg[2];
int ret;
msg[0].addr = client->addr;
msg[0].flags = 0;
msg[0].buf = ®
msg[0].len = 1;
msg[1].addr = client->addr;
msg[1].flags = client->flags | I2C_M_RD;
msg[1].buf = buf;
msg[1].len = len;
if ((ret =i2c_transfer(client->adapter, msg, 2)) != 2) {
dev_err(&client->dev, "i2c transfer failed\n");
return -EIO;
}
return ret;
}
static s32 ft5x06_write_regs(struct ft5x06 *dev, u8 reg, u8 *buf, u8 len)
{
struct i2c_client *client = (struct i2c_client *)dev->client;
struct i2c_msg msg;
u8 b[256];
int ret;
b[0] = reg;
memcpy(&b[1] ,buf ,len);
msg.addr = client->addr;
msg.flags = 0;
msg.buf = b;
msg.len = len+1;
ret = i2c_transfer(client->adapter, &msg,1);
return ret;
}
static void ft5x06_write_reg(struct ft5x06 *dev, u8 reg, u8 data )
{
u8 buf;
buf = data;
ft5x06_write_regs(dev, reg, &buf, 1);
}
static irqreturn_t ft5x06_handler(int irq, void *dev_id)
{
struct ft5x06 *mutitouch = dev_id;
//struct device *dev = &mutitouch->client->dev;
u8 rdbuf[29];
int i, type, x, y, id;
int offset = 1, tplen = 6;
int error = 0;
memset(rdbuf, 0, sizeof(rdbuf));
error = ft5x06_read_regs(&ft5x06_dev, FT5X06_TD_STATUS_REG, rdbuf, FT5X06_READLEN );
if(error){
goto out;
}
for(i = 0 ;i< MAX_SUPPORT_POINTS ; i++){
u8 *buf = &rdbuf[i * tplen + offset];
bool down;
type = buf[0] >> 6;
if (type == TOUCH_EVENT_RESERVED)
continue;
y = ((buf[0] << 8) | buf[1]) & 0x0fff;
x = ((buf[2] << 8) | buf[3]) & 0x0fff;
id = (buf[2] >> 4) & 0x0f;
down = type != TOUCH_EVENT_UP;
input_mt_slot(mutitouch->input, id);
input_mt_report_slot_state(mutitouch->input, MT_TOOL_FINGER, down);
if (!down)
continue;
input_report_abs(mutitouch->input, ABS_MT_POSITION_X, x);
input_report_abs(mutitouch->input, ABS_MT_POSITION_Y, y);
}
input_mt_report_pointer_emulation(mutitouch->input, true);
input_sync(mutitouch->input);
out:
return IRQ_HANDLED;
}
static int ft5x06_ts_irq(struct i2c_client *client, struct ft5x06 *dev)
{
int error = 0;
if (gpio_is_valid(dev->irq_pin)) {
error = devm_gpio_request_one(&client->dev, dev->irq_pin,
GPIOF_IN, "edt-ft5x06 irq");
if (error) {
dev_err(&client->dev,
"Failed to request GPIO %d, error %d\n",
dev->irq_pin, error);
return error;
}
}
error = devm_request_threaded_irq(&client->dev, client->irq, NULL,
ft5x06_handler,
IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
client->name, dev);
if (error) {
dev_err(&client->dev, "Unable to request touchscreen IRQ.\n");
return error;
}
return 0;
}
static int ft5x06_probe(struct i2c_client *client, const struct i2c_device_id *id)
{
int error = 0 ;
ft5x06_dev.client = client;
ft5x06_dev.irq_pin = of_get_named_gpio(client->dev.of_node,"interrupt-gpios",0);
ft5x06_dev.reset_pin = of_get_named_gpio(client->dev.of_node,"reset-gpios",0);
error = ft5x06_ts_reset(client, &ft5x06_dev);
if (error)
return error;
error = ft5x06_ts_irq(client, &ft5x06_dev);
if (error)
return error;
ft5x06_write_reg(&ft5x06_dev,FT5x06_DEVICE_MODE_REG,0);
ft5x06_write_reg(&ft5x06_dev,FT5426_IDG_MODE_REG,1);
ft5x06_dev.input = devm_input_allocate_device(&client->dev);
if (!ft5x06_dev.input) {
dev_err(&client->dev, "failed to allocate input device.\n");
return -ENOMEM;
}
ft5x06_dev.input->name = client->name;
ft5x06_dev.input->id.bustype = BUS_I2C;
ft5x06_dev.input->dev.parent = &client->dev;
__set_bit(EV_KEY, ft5x06_dev.input->evbit);
__set_bit(EV_ABS,ft5x06_dev.input->evbit);
__set_bit(BTN_TOUCH, ft5x06_dev.input->keybit);
input_set_abs_params(ft5x06_dev.input, ABS_X, 0, 800 , 0, 0);
input_set_abs_params(ft5x06_dev.input, ABS_Y, 0, 480, 0, 0);
input_set_abs_params(ft5x06_dev.input, ABS_MT_POSITION_X,0, 800, 0, 0);
input_set_abs_params(ft5x06_dev.input, ABS_MT_POSITION_Y, 0, 480, 0, 0);
error = input_mt_init_slots(ft5x06_dev.input, MAX_SUPPORT_POINTS, 0);
if (error) {
dev_err(&client->dev, "Unable to init MT slots.\n");
return error;
}
error = input_register_device(ft5x06_dev.input);
if (error)
goto err_remove_attrs;
err_remove_attrs:
return error;
}
static int ft5x06_remove(struct i2c_client *client)
{
input_unregister_device(ft5x06_dev.input);
return 0;
}
static const struct i2c_device_id ft5x06_tsid_table[] = {
{"edt-ft5206",0},
{"edt-ft5426",0},
{/*sential*/}
};
static const struct of_device_id ft5x06_of_match_table[] = {
{.compatible = "atk,ft5x06"},
{.compatible = "edt,edt-ft5426"},
{/****sential****/}
};
static struct i2c_driver ft5x06_driver = {
.probe = ft5x06_probe,
.remove = ft5x06_remove,
.driver = {
.of_match_table = of_match_ptr(ft5x06_of_match_table),
.owner = THIS_MODULE,
.name = "edt_ft5x06",
},
.id_table = ft5x06_tsid_table,
};
static int __init ft5x06_init(void)
{
int ret = 0 ;
ret = i2c_add_driver(&ft5x06_driver);
printk("touch enterance\r\n");
return ret;
}
static void __exit ft5x06_exit(void)
{
i2c_del_driver(&ft5x06_driver);
printk("touch exit\r\n");
}
module_init(ft5x06_init);
module_exit(ft5x06_exit);
MODULE_AUTHOR("123");
MODULE_LICENSE("GPL");
|
|