我们自己打了几块调试的小板,
然后是接到开发板上准备调试
一、内核驱动
tsc2007的驱动源码在内核中是已经存在的,其路径如下:
kernel/drivers/input/touchscreen/tsc2007.c
所以,我们只需要在kernel目录下,通过 make menuconfig 命令来配置内核并重新编译即可;或者,在调试阶段,也可以用一种简单粗暴的方式——直接改Makefile(kernel/drivers/input/touchscreen/Makefile):
#
# Makefile for the touchscreen drivers.
#
...
#obj-$(CONFIG_TOUCHSCREEN_TSC2007) += tsc2007.o
obj-y += tsc2007.o
...
这里可以简单看一下 tsc2007 的设备结构体在驱动文件中的定义:
struct tsc2007 {
struct input_dev *input;
char phys[32];
struct i2c_client *client;
u16 model;
u16 x_plate_ohms;
u16 max_rt;
unsigned long poll_period; /* in jiffies */
int fuzzx;
int fuzzy;
int fuzzz;
unsigned gpio;
int irq;
wait_queue_head_t wait;
bool stopped;
int (*get_pendown_state)(struct device *);
void (*clear_penirq)(void);
};
二、设备树
内核的配置搞定了,接下来就是修改设备树文件,来把相关的硬件信息传给驱动。之前在Firefly的开发板上接了一LVDS接口的LCD屏幕,使用的是以下的dts:
kernel/arch/arm64/boot/dts/rockchip/rk3399-firefly-aioc-lvds-HSX101H40C.dts
在此基础上做修改。
那么,tsc2007的设备树节点应该怎么写呢?
首先,去看bindings。
打开 kernel/Documentation/devicetree/bindings/input/touchscreen/tsc2007.txt,可看到它给出了一个example:
Example:
&i2c1 {
/* ... */
tsc2007@49 {
compatible = "ti,tsc2007";
reg = <0x49>;
interrupt-parent = <&gpio4>;
interrupts = <0x0 0x8>;
gpios = <&gpio4 0 0>;
ti,x-plate-ohms = <180>;
};
/* ... */
};
对设备节点中各个属性的解释如下:
Required properties:
compatible: must be “ti,tsc2007”.
reg: I2C address of the chip.
ti,x-plate-ohms: X-plate resistance in ohms.
Optional properties:
gpios: the interrupt gpio the chip is connected to (trough the penirq pin).
The penirq pin goes to low when the panel is touched. (see GPIO binding[1] for more details).
interrupt-parent: the phandle for the gpio controller (see interrupt binding[0]).
interrupts: (gpio) interrupt to which the chip is connected (see interrupt binding[0]).
ti,max-rt: maximum pressure.
ti,fuzzx: specifies the absolute input fuzz x value. If set, it will permit noise in the data up to ± the value given to the fuzz parameter, that is used to filter noise from the event stream.
ti,fuzzy: specifies the absolute input fuzz y value.
ti,fuzzz: specifies the absolute input fuzz z value.
ti,poll-period: how much time to wait (in milliseconds) before reading again the values from the tsc2007.
– [0]: Documentation/devicetree/bindings/interrupt-controller/interrupts.txt
–[1]: Documentation/devicetree/bindings/gpio/gpio.txt
这里,列举几个主要的:
I2C从设备地址 —— reg
tsc2007的7位设备地址是由A0, A1两个引脚的连接方式确定的,在 Datasheet 有给出说明。