继续设备树的移植
适配lcd
查看内核文档
lcdif设备树
根据imx6ull.dtsi里面有的soc厂商设备树找到compile内容 compatible = “fsl,imx6ul-lcdif”, “fsl,imx28-lcdif”;
根据这两个匹配项去document里面查找相关文档
alientek_linux/Documentation/devicetree/bindings/fb/mxsfb.txt
compatible: 照着写
reg: lcd寄存器初始和长度
interrupts:
display子节点
bits-per-pixel
bus-width
display-timings子节点
根据描述查看 display-timing.txt
大概设备树里面描写的是一个lcd时钟频率和各种参数
参数查询
找到lcd的datasheet
因为有24条数据线所以每个像素占24位,
bits-per-pixel : <16> for RGB565, <32> for RGB888/666. bus-width : number of data lines. Could be <8>, <16>, <18> or <24>.
有8位灰度值,pixel使用32,同时位宽24
DOT CLOCK 确定基本时钟频率,标准取51.2MHz
在设备树里写就行了,驱动应该会自动调整取到这个频率
display-timing 参数查询
这几个参数用其他的lcd屏幕举例子,韦老师给的时序图比较模糊,其实这几个参数
随便设置应该没问题,差不多在这个范围里面
例子:
上图是一帧图像的显示时序图。的上图显示,up_margin = 13-1=12,, yres= 240,
整个场周期为263,所以lower_margin= 263-13-240 = 10
同时看到,列同步信号高电平有效,行同步信号也是高电平有效。
上图是一行的时序图。
可以看到,left_margin = 69, xres = 320, right_margin = 408 -320 - 70 = 18
数据在上升沿有效,输出使能是高电平有效
设备树编写
hactive : 1024 横向有效
vsync-active : 600纵向有效
hfront-porch: 图上
hback-porch: 图上
hsync-len: 图上
所以说横竖信号的脉冲激活可以忽略
hsync-active = “ignored”;
vsync-active = “ignored”;
但是数据都是高脉冲
de-active = “active high”;
整个lcd设备树这样写就行了,pinctrl子系统不用改,正点用的lcd已经复用好了
&lcdif {
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_lcdif_dat
&pinctrl_lcdif_ctrl>;
display = <&display0>;
status = "okay";
display0: display {
bits-per-pixel = <32>;
bus-width = <24>;
display-timings {
native-mode = <&timing0>;
timing0: timing0 {
clock-frequency = <51200000>;
hactive = <1024>;
vactive = <600>;
hfront-porch = <180>;
hback-porch = <140>;
hsync-len = <20>;
vback-porch = <20>;
vfront-porch = <12>;
vsync-len = <3>;
hsync-active = <2>;
vsync-active = <2>;
de-active = <1>;
};
};
};
};
背光适配
电路图分析
在lcd的datasheet 里面 我们可以知道背光就是LED+LED-
那么在原理图里面找到这两个引脚
发现背光正是在电源上,负极BL_CN才连接开发板
也就是下面图片的第32引脚
回到开发板原理图,在开发板里面这个引脚是 B_LCD_PWM,一个pwm引脚 最后得到 GPIO1_IO08 引脚
文档查询
既然是pwm引脚,那就去/alientek_linux/Documentation/devicetree/bindings/video/backlight
查看相关文档,大概也就这三个就能写出设备树文件了
在开发板datasheet里面 进行查找为接下来pinctrl 复用做准备
在soc厂家给的dtsi里面已经写好了pwm,我们直接引用进行pinctrl修改
按照设备树文档里面的进行修改
pwm-backlight bindings
Required properties:
- compatible: “pwm-backlight”
- pwms: OF device-tree PWM specification (see PWM binding[0])
- brightness-levels: Array of distinct brightness levels. Typically these
are in the range from 0 to 255, but any range starting at 0 will do.
The actual brightness level (PWM duty cycle) will be interpolated
from these values. 0 means a 0% duty cycle (darkest/off), while the
last value in the array represents a 100% duty cycle (brightest). - default-brightness-level: the default brightness level (index into the
array defined by the “brightness-levels” property) - power-supply: regulator for supply voltage
Optional properties:
- pwm-names: a list of names for the PWM devices specified in the
“pwms” property (see PWM binding[0]) - enable-gpios: contains a single GPIO specifier for the GPIO which enables
and disables the backlight (see GPIO binding[1])
//对该pwm进行io复用映射
&pwm1 {
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_pwm1>;
status = "okay";
};
pinctrl_pwm1: pwm1grp {
fsl,pins = <
MX6UL_PAD_GPIO1_IO08__PWM1_OUT 0x110b0
>;
};
根据文档写出backlight
backlight {
compatible = "pwm-backlight";
pwms = <&pwm1 0 5000000>;
brightness-levels = <0 4 8 16 32 64 128 255>;
default-brightness-level = <7>;
status = "okay";
};
触摸屏适配
电路图分析
很正常的IIC通信,四条线就行
同时连接进soc的也就是下面的这四条线,tc的连接是通过IIC2传递信息
在开发板中两条线的名称是UART5_TXD UART5_RXD
LCD_TP_RST ->SNVS_TAMPER2 LCD_TP_INT->GPIO1_IO05
文档分析
触摸屏用的是汇顶家的 gt911 所以对应的设备树文档在
Linux-4.9.88/Documentation/devicetree/bindings/input/touchscreen/goodix.txt
- compatible : Should be "goodix,gt911"
or "goodix,gt9110"
or "goodix,gt912"
or "goodix,gt927"
or "goodix,gt9271"
or "goodix,gt928"
or "goodix,gt967"
- reg : I2C address of the chip. Should be 0x5d or 0x14
- interrupt-parent : Interrupt controller to which the chip is connected
- interrupts : Interrupt to which the chip is connected
Optional properties:
- irq-gpios : GPIO pin used for IRQ. The driver uses the
interrupt gpio pin as output to reset the device.
- reset-gpios : GPIO pin used for reset
- touchscreen-inverted-x : X axis is inverted (boolean)
- touchscreen-inverted-y : Y axis is inverted (boolean)
- touchscreen-swapped-x-y : X and Y axis are swapped (boolean)
(swapping is done after inverting the axis)
找着这个写,再写出pinctrl系统,对这四个引脚进行复用就行了
设备树中断编写
IIC2 的中断编号是37,但是后面的共享中断号是物理中断号-32,所以是5
触摸屏肯定是下降沿触发
Z:触发方式
1 = low-to-high edge triggered
2 = high-to-low edge triggered (invalid for SPIs)
4 = active high level-sensitive
8 = active low level-sensitive (invalid for SPIs).
现在设备树写成这样,IIC因为7位地址,所以减少了一位,进行了更改,但是还启动不了,IIC是可以ask成功的
深入驱动
查看内核用的是什么驱动
把gt9xx的改为n
同时进入内核的gt9xx文件,编译出ko文件
直接在这个界面编译出ko文件
安装驱动gt9xx.ko
insmod gt9xx.ko
在驱动里设置自己的打印信息
这图说明,连probe都进不去,那肯定就是.of_match_table 里面不匹配
这样子修改就行了
修改event事件下标
内核里面用 input_allocate_device() 构造input 输入子系统的设备
拿出来重构
error: 'input_dev_type' undeclared (first use in this function)
这个结构体没有引用出来
event注册
input_register_device
->input_attach_handler
->handler->connect(handler, dev, id);