RK3568
回帖(1)
2022-3-2 17:49:28
RK3568 SDK下kernel/arch/arm64/configs/*_defconfig已经把LCD相关的配置设置好了,如果自己做了修改,请注意把以下配置加上:
CONFIG_DRM_ROCKCHIP=y
CONFIG_ROCKCHIP_DW_MIPI_DSI=y
CONFIG_DRM_PANEL_SIMPLE=y
MIPI DTS配置
以RK3568的SDK 中MIPI DSI的DTS文件为例(
kernel/arch/arm64/boot/dts/rockchip/rk3568-mipi101_M101014_BE45_A1.dts),此DTS文件为MIPI_DSI0+HDMI屏配置,MIPI_DSI1 默认关闭,接下来以此DTS中的dsi0配置作为范例来进行相关的LCD驱动介绍。
从DTS文件中我们可以看到以下语句:
&dsi0 {
status = "okay";
//rockchip,lane-rate = <1000>;
dsi0_panel: panel@0 {
status = "okay";
......
//enable-gpios = <&gpio4 RK_PC5 GPIO_ACTIVE_HIGH>;
reset-gpios = <&gpio0 RK_PC5 GPIO_ACTIVE_LOW>;
enable-delay-ms = <35>;
prepare-delay-ms = <6>;
......
disp_timings0: display-timings {
native-mode = <&dsi0_timing0>;
dsi0_timing0: timing0 {
clock-frequency = <76000000>;//<80000000>;
hactive = <800>;//<768>;
vactive = <1280>;
hsync-len = <14>; //20, 50,10
hback-porch = <25>; //50, 56,10
hfront-porch = <25>;//50, 30,180
vsync-len = <8>;//4
vback-porch = <32>;//4
vfront-porch = <146>;//8
hsync-active = <0>;
vsync-active = <0>;
de-active = <0>;
pixelclk-active = <0>;
};
};
};
};
参数看起来挺多的,其实真正需要修改的并不多。究竟哪些都需要修改是根据不同的LCD参考其规格书修改的,dts中需要重点关注的有以下几个参数:
hactive 、vactive 、hsync-len、hback-porch、hfront-porch、 vsync-len、vback-porch、vfront-porch,相关的参数一般可以在屏的规格书中找到。上述六个参数按照规格书来填充(目前大多数屏都是DE mode,DE模式的话一般都会标明DE mode only),DE模式只需要关注两个参数Vertical section blanking和Horizontal section blanking。
背光配置
backlight: backlight {
status = "okay";
compatible = "pwm-backlight";
enable-gpios = <&gpio3 RK_PB0 GPIO_ACTIVE_HIGH>;
pwms = <&pwm4 0 50000 1>;
brightness-levels = <
60 60 60 61 61 61 62 62
62 63 63 63 64 64 64 65
65 65 66 66 66 67 67 67
68 68 68 69 69 69 70 70
70 71 71 71 72 72 72 73
73 73 74 74 74 75 75 75
76 76 76 77 77 77 78 78
78 79 79 79 80 80 80 81
81 81 82 82 82 83 83 83
84 84 84 85 85 85 86 86
86 87 87 87 88 88 88 89
89 89 90 91 92 93 94 95
96 97 98 99 100 101 102 103
104 105 106 107 108 109 110 111
112 113 114 115 116 117 118 119
120 121 122 123 124 125 126 127
128 129 130 131 132 133 134 135
136 137 138 139 140 141 142 143
144 145 146 147 148 149 150 151
152 153 154 155 156 157 158 159
160 161 162 163 164 165 166 167
168 169 170 171 172 173 174 175
176 177 178 179 180 181 182 183
184 185 186 187 188 189 190 191
192 193 194 195 196 197 198 199
200 201 202 203 204 205 206 207
208 209 210 211 212 213 214 215
216 217 218 219 220 221 222 223
224 225 226 227 228 229 230 231
232 233 234 235 236 237 238 239
240 241 242 243 244 245 246 247
248 249 250 251 252 253 254 255
>;
default-brightness-level = <200>;
};
enable-gpios:背光使能脚
pwms属性:配置PWM,范例里面默认使用pwm4,50000ns是周期(20 KHz),pwm为负极性。
brightness-levels属性:配置背光亮度数组,一般以值 255 为一个 scale,当 PWM 设置为正极性时,从 0~255 表示背光为正极,占空比从 0%~100% 变化,255~0 为负极性,占空比从 100%~0% 变化;当 PWM 设置为负极性时,反之。
default-brightness-level属性:开机时默认背光亮度,范围为0-255。
具体请参考kernel中的说明文档:
kernel/Documentation/devicetree/bindings/leds/backlight/pwm-backlight.txt
显示时序配置
Power on/off sequence
MIPI屏的上下电时序通常都在规格书的Power on/off sequence章节中,可根据规格书的上下电时序修改dts,panel节点中有如下属性:
&dsi0 {
status = "okay";
//rockchip,lane-rate = <1000>;
dsi0_panel: panel@0 {
status = "okay";
compatible = "simple-panel-dsi";
......
//enable-gpios = <&gpio0 RK_PC7 GPIO_ACTIVE_HIGH>;
reset-gpios = <&gpio3 RK_PB5 GPIO_ACTIVE_LOW>;
enable-delay-ms = <35>;
prepare-delay-ms = <6>;
reset-delay-ms = <0>;
init-delay-ms = <20>;
unprepare-delay-ms = <0>;
disable-delay-ms = <20>;
......
panel-init-sequence = [
15 00 02 E0 00
15 00 02 18 AF
15 00 02 19 01
...
];
panel-exit-sequence = [
05 05 01 28
05 78 01 10
];
};
};
调试屏幕时可根据本身上下电时序是否需要配置此属性。
dts中的init-sequence和panel-exit-sequence中配置了上电和下电初始化指令, 具体LCD配置参考其规格书和原厂提供的初始化代码修改的。
初始化代码解析
说明:前 3 个字节(16 进制),分别代表 Data Type,Delay,Payload Length。
从第四个字节开始的数据代表长度为 Length 的实际有效 Payload。
第一条命令的解析如下:
15 00 02 E0 00
Data Type:0x39 (DCS Long Write)
Delay:0x00 (0 ms)
Payload Length:0x06 (4 Bytes)
Payload:E0 00
/* dcs read/write */
#define DTYPE_DCS_WRITE 0x05 /* short write, 0 parameter */
#define DTYPE_DCS_WRITE1 0x15 /* short write, 1 parameter */
#define DTYPE_DCS_READ 0x06 /* read */
#define DTYPE_DCS_LWRITE 0x39 /* long write */
/* generic read/write */
#define DTYPE_GEN_WRITE 0x03 /* short write, 0 parameter */
#define DTYPE_GEN_WRITE1 0x13 /* short write, 1 parameter */
#define DTYPE_GEN_WRITE2 0x23 /* short write, 2 parameter */
#define DTYPE_GEN_LWRITE 0x29 /* long write */
#define DTYPE_GEN_READ 0x04 /* long read, 0 parameter */
#define DTYPE_GEN_READ1 0x14 /* long read, 1 parameter */
#define DTYPE_GEN_READ2 0x24 /* long read, 2 parameter */
接下来我们来看看上下电时序在驱动中的实现, 具体实现在kernel/drivers/gpu/drm/panel/panel-simple.c中:
static int panel_simple_disable(struct drm_panel *panel)
{
...
if (p->backlight) {
p->backlight->props.power = FB_BLANK_POWERDOWN;
p->backlight->props.state |= BL_CORE_FBBLANK;
backlight_update_status(p->backlight);
}
if (p->desc->delay.disable)
panel_simple_sleep(p->desc->delay.disable);
if (p->cmd_type == CMD_TYPE_MCU) {
err = panel_simple_xfer_mcu_cmd_seq(p, p->desc->exit_seq);
if (err)
dev_err(panel->dev, "failed to send exit cmds seqn");
}
...
}
static int panel_simple_unprepare(struct drm_panel *panel)
{
...
if (p->desc->exit_seq) {
if (p->dsi)
panel_simple_xfer_dsi_cmd_seq(p, p->desc->exit_seq);
else if (p->cmd_type == CMD_TYPE_SPI)
err = panel_simple_xfer_spi_cmd_seq(p, p->desc->exit_seq);
if (err)
dev_err(panel->dev, "failed to send exit cmds seqn");
}
gpiod_direction_output(p->reset_gpio, 1);
if(!p->enable_on_always){
gpiod_direction_output(p->enable_gpio, 0);
}
...
}
static int panel_simple_prepare(struct drm_panel *panel)
{
...
gpiod_direction_output(p->enable_gpio, 1);
if (p->desc->delay.prepare)
panel_simple_sleep(p->desc->delay.prepare);
...
gpiod_direction_output(p->reset_gpio, 1);
if (p->desc->delay.reset)
panel_simple_sleep(p->desc->delay.reset);
gpiod_direction_output(p->reset_gpio, 0);
//由于驱动在控制reset脚时序的时候使用了`gpiod`这类的API
//如果在DTS配置了低电平有效,那么这里就会将reset引脚拉高,即取反。
if (p->desc->delay.init)
panel_simple_sleep(p->desc->delay.init);
if (p->desc->init_seq) {
if (p->dsi)
panel_simple_xfer_dsi_cmd_seq(p, p->desc->init_seq);
else if (p->cmd_type == CMD_TYPE_SPI)
err = panel_simple_xfer_spi_cmd_seq(p, p->desc->init_seq);
if (err)
dev_err(panel->dev, "failed to send init cmds seqn");
}
if(p->desc->delay.mipi_data){
panel_simple_sleep(p->desc->delay.mipi_data);
}
...
}
static int panel_simple_enable(struct drm_panel *panel)
{
...
if (p->cmd_type == CMD_TYPE_MCU) {
err = panel_simple_xfer_mcu_cmd_seq(p, p->desc->init_seq);
if (err)
dev_err(panel->dev, "failed to send init cmds seqn");
}
if (p->desc->delay.enable)
panel_simple_sleep(p->desc->delay.enable);
if (p->backlight) {
p->backlight->props.state &= ~BL_CORE_FBBLANK;
p->backlight->props.power = FB_BLANK_UNBLANK;
backlight_update_status(p->backlight);
}
...
}
uboot实现在u-boot/drivers/video/drm/rockchip_panel.c中的panel_simple_unprepare、panel_simple_prepare、panel_simple_enable 、panel_simple_disable 4个函数中,具体实现可以自己查看。
RK3568 SDK下kernel/arch/arm64/configs/*_defconfig已经把LCD相关的配置设置好了,如果自己做了修改,请注意把以下配置加上:
CONFIG_DRM_ROCKCHIP=y
CONFIG_ROCKCHIP_DW_MIPI_DSI=y
CONFIG_DRM_PANEL_SIMPLE=y
MIPI DTS配置
以RK3568的SDK 中MIPI DSI的DTS文件为例(
kernel/arch/arm64/boot/dts/rockchip/rk3568-mipi101_M101014_BE45_A1.dts),此DTS文件为MIPI_DSI0+HDMI屏配置,MIPI_DSI1 默认关闭,接下来以此DTS中的dsi0配置作为范例来进行相关的LCD驱动介绍。
从DTS文件中我们可以看到以下语句:
&dsi0 {
status = "okay";
//rockchip,lane-rate = <1000>;
dsi0_panel: panel@0 {
status = "okay";
......
//enable-gpios = <&gpio4 RK_PC5 GPIO_ACTIVE_HIGH>;
reset-gpios = <&gpio0 RK_PC5 GPIO_ACTIVE_LOW>;
enable-delay-ms = <35>;
prepare-delay-ms = <6>;
......
disp_timings0: display-timings {
native-mode = <&dsi0_timing0>;
dsi0_timing0: timing0 {
clock-frequency = <76000000>;//<80000000>;
hactive = <800>;//<768>;
vactive = <1280>;
hsync-len = <14>; //20, 50,10
hback-porch = <25>; //50, 56,10
hfront-porch = <25>;//50, 30,180
vsync-len = <8>;//4
vback-porch = <32>;//4
vfront-porch = <146>;//8
hsync-active = <0>;
vsync-active = <0>;
de-active = <0>;
pixelclk-active = <0>;
};
};
};
};
参数看起来挺多的,其实真正需要修改的并不多。究竟哪些都需要修改是根据不同的LCD参考其规格书修改的,dts中需要重点关注的有以下几个参数:
hactive 、vactive 、hsync-len、hback-porch、hfront-porch、 vsync-len、vback-porch、vfront-porch,相关的参数一般可以在屏的规格书中找到。上述六个参数按照规格书来填充(目前大多数屏都是DE mode,DE模式的话一般都会标明DE mode only),DE模式只需要关注两个参数Vertical section blanking和Horizontal section blanking。
背光配置
backlight: backlight {
status = "okay";
compatible = "pwm-backlight";
enable-gpios = <&gpio3 RK_PB0 GPIO_ACTIVE_HIGH>;
pwms = <&pwm4 0 50000 1>;
brightness-levels = <
60 60 60 61 61 61 62 62
62 63 63 63 64 64 64 65
65 65 66 66 66 67 67 67
68 68 68 69 69 69 70 70
70 71 71 71 72 72 72 73
73 73 74 74 74 75 75 75
76 76 76 77 77 77 78 78
78 79 79 79 80 80 80 81
81 81 82 82 82 83 83 83
84 84 84 85 85 85 86 86
86 87 87 87 88 88 88 89
89 89 90 91 92 93 94 95
96 97 98 99 100 101 102 103
104 105 106 107 108 109 110 111
112 113 114 115 116 117 118 119
120 121 122 123 124 125 126 127
128 129 130 131 132 133 134 135
136 137 138 139 140 141 142 143
144 145 146 147 148 149 150 151
152 153 154 155 156 157 158 159
160 161 162 163 164 165 166 167
168 169 170 171 172 173 174 175
176 177 178 179 180 181 182 183
184 185 186 187 188 189 190 191
192 193 194 195 196 197 198 199
200 201 202 203 204 205 206 207
208 209 210 211 212 213 214 215
216 217 218 219 220 221 222 223
224 225 226 227 228 229 230 231
232 233 234 235 236 237 238 239
240 241 242 243 244 245 246 247
248 249 250 251 252 253 254 255
>;
default-brightness-level = <200>;
};
enable-gpios:背光使能脚
pwms属性:配置PWM,范例里面默认使用pwm4,50000ns是周期(20 KHz),pwm为负极性。
brightness-levels属性:配置背光亮度数组,一般以值 255 为一个 scale,当 PWM 设置为正极性时,从 0~255 表示背光为正极,占空比从 0%~100% 变化,255~0 为负极性,占空比从 100%~0% 变化;当 PWM 设置为负极性时,反之。
default-brightness-level属性:开机时默认背光亮度,范围为0-255。
具体请参考kernel中的说明文档:
kernel/Documentation/devicetree/bindings/leds/backlight/pwm-backlight.txt
显示时序配置
Power on/off sequence
MIPI屏的上下电时序通常都在规格书的Power on/off sequence章节中,可根据规格书的上下电时序修改dts,panel节点中有如下属性:
&dsi0 {
status = "okay";
//rockchip,lane-rate = <1000>;
dsi0_panel: panel@0 {
status = "okay";
compatible = "simple-panel-dsi";
......
//enable-gpios = <&gpio0 RK_PC7 GPIO_ACTIVE_HIGH>;
reset-gpios = <&gpio3 RK_PB5 GPIO_ACTIVE_LOW>;
enable-delay-ms = <35>;
prepare-delay-ms = <6>;
reset-delay-ms = <0>;
init-delay-ms = <20>;
unprepare-delay-ms = <0>;
disable-delay-ms = <20>;
......
panel-init-sequence = [
15 00 02 E0 00
15 00 02 18 AF
15 00 02 19 01
...
];
panel-exit-sequence = [
05 05 01 28
05 78 01 10
];
};
};
调试屏幕时可根据本身上下电时序是否需要配置此属性。
dts中的init-sequence和panel-exit-sequence中配置了上电和下电初始化指令, 具体LCD配置参考其规格书和原厂提供的初始化代码修改的。
初始化代码解析
说明:前 3 个字节(16 进制),分别代表 Data Type,Delay,Payload Length。
从第四个字节开始的数据代表长度为 Length 的实际有效 Payload。
第一条命令的解析如下:
15 00 02 E0 00
Data Type:0x39 (DCS Long Write)
Delay:0x00 (0 ms)
Payload Length:0x06 (4 Bytes)
Payload:E0 00
/* dcs read/write */
#define DTYPE_DCS_WRITE 0x05 /* short write, 0 parameter */
#define DTYPE_DCS_WRITE1 0x15 /* short write, 1 parameter */
#define DTYPE_DCS_READ 0x06 /* read */
#define DTYPE_DCS_LWRITE 0x39 /* long write */
/* generic read/write */
#define DTYPE_GEN_WRITE 0x03 /* short write, 0 parameter */
#define DTYPE_GEN_WRITE1 0x13 /* short write, 1 parameter */
#define DTYPE_GEN_WRITE2 0x23 /* short write, 2 parameter */
#define DTYPE_GEN_LWRITE 0x29 /* long write */
#define DTYPE_GEN_READ 0x04 /* long read, 0 parameter */
#define DTYPE_GEN_READ1 0x14 /* long read, 1 parameter */
#define DTYPE_GEN_READ2 0x24 /* long read, 2 parameter */
接下来我们来看看上下电时序在驱动中的实现, 具体实现在kernel/drivers/gpu/drm/panel/panel-simple.c中:
static int panel_simple_disable(struct drm_panel *panel)
{
...
if (p->backlight) {
p->backlight->props.power = FB_BLANK_POWERDOWN;
p->backlight->props.state |= BL_CORE_FBBLANK;
backlight_update_status(p->backlight);
}
if (p->desc->delay.disable)
panel_simple_sleep(p->desc->delay.disable);
if (p->cmd_type == CMD_TYPE_MCU) {
err = panel_simple_xfer_mcu_cmd_seq(p, p->desc->exit_seq);
if (err)
dev_err(panel->dev, "failed to send exit cmds seqn");
}
...
}
static int panel_simple_unprepare(struct drm_panel *panel)
{
...
if (p->desc->exit_seq) {
if (p->dsi)
panel_simple_xfer_dsi_cmd_seq(p, p->desc->exit_seq);
else if (p->cmd_type == CMD_TYPE_SPI)
err = panel_simple_xfer_spi_cmd_seq(p, p->desc->exit_seq);
if (err)
dev_err(panel->dev, "failed to send exit cmds seqn");
}
gpiod_direction_output(p->reset_gpio, 1);
if(!p->enable_on_always){
gpiod_direction_output(p->enable_gpio, 0);
}
...
}
static int panel_simple_prepare(struct drm_panel *panel)
{
...
gpiod_direction_output(p->enable_gpio, 1);
if (p->desc->delay.prepare)
panel_simple_sleep(p->desc->delay.prepare);
...
gpiod_direction_output(p->reset_gpio, 1);
if (p->desc->delay.reset)
panel_simple_sleep(p->desc->delay.reset);
gpiod_direction_output(p->reset_gpio, 0);
//由于驱动在控制reset脚时序的时候使用了`gpiod`这类的API
//如果在DTS配置了低电平有效,那么这里就会将reset引脚拉高,即取反。
if (p->desc->delay.init)
panel_simple_sleep(p->desc->delay.init);
if (p->desc->init_seq) {
if (p->dsi)
panel_simple_xfer_dsi_cmd_seq(p, p->desc->init_seq);
else if (p->cmd_type == CMD_TYPE_SPI)
err = panel_simple_xfer_spi_cmd_seq(p, p->desc->init_seq);
if (err)
dev_err(panel->dev, "failed to send init cmds seqn");
}
if(p->desc->delay.mipi_data){
panel_simple_sleep(p->desc->delay.mipi_data);
}
...
}
static int panel_simple_enable(struct drm_panel *panel)
{
...
if (p->cmd_type == CMD_TYPE_MCU) {
err = panel_simple_xfer_mcu_cmd_seq(p, p->desc->init_seq);
if (err)
dev_err(panel->dev, "failed to send init cmds seqn");
}
if (p->desc->delay.enable)
panel_simple_sleep(p->desc->delay.enable);
if (p->backlight) {
p->backlight->props.state &= ~BL_CORE_FBBLANK;
p->backlight->props.power = FB_BLANK_UNBLANK;
backlight_update_status(p->backlight);
}
...
}
uboot实现在u-boot/drivers/video/drm/rockchip_panel.c中的panel_simple_unprepare、panel_simple_prepare、panel_simple_enable 、panel_simple_disable 4个函数中,具体实现可以自己查看。
举报
更多回帖