一.HDMIOUT代码路径
DRM 全称是 Direct Rendering Manager 是 DRI ( Direct Rendering Infrastructure ) 框架的一个
组件。LINUX 4.4/4.19 内核采用 DRM 框架, HDMI 驱动的路径为:
kernel/drivers/gpu/drm/rockchip/dw_hdmi-Rockchip.c
kernel/drivers/gpu/drm/rockchip/inno_hdmi.c
kernel/drivers/gpu/drm/bridge/synopsys/
二.DTS修改
&hdmi0 {status = "okay";
};
在 Rockchip 的各个平台中,各种显示接口(HDMI、DP、CVBS等)输出的图像数据来自于 VOP:
HDMI 绑定到 VOPB 需要添加:
&hdmi0_in_vp1 {status = "okay";
};
打开开机 logo:
在 dts 里面将 route_hdmi 使能即可打开 U-Boot logo 支持:
&route_hdmi0 {status = "okay";
};
三.HDMIOUT调试
板子上电:插上hdmiout能显示输出的log打印:
[ 169.342420][ T467] dwhdmi-rockchip fde80000.hdmi: set ops ok!!
[ 169.342507][ T467] dwhdmi-rockchip fde80000.hdmi: use tmds mode
[ 169.342812][ T467] rockchip-vop2 fdd90000.vop: [drm:vop2_crtc_atomic_enable [rockchipdrm]] Update mode to 1920x1080p60, type: 11(if:800) for vp1 dclk: 148500000
[ 169.343293][ T467] rockchip-vop2 fdd90000.vop: [drm:vop2_crtc_atomic_enable [rockchipdrm]] dclk_out1 div: 0 dclk_core1 div: 2
[ 169.343538][ T467] rockchip-vop2 fdd90000.vop: [drm:vop2_crtc_atomic_enable [rockchipdrm]] set dclk_vop1 to 148500000, get 148500000
[ 169.343603][ T467] rockchip-hdptx-phy-hdmi fed60000.hdmiphy: hdptx_ropll_cmn_config bus_width:16a8c8 rate:1485000
[ 169.343941][ T467] rockchip-hdptx-phy-hdmi fed60000.hdmiphy: hdptx phy pll locked!
[ 169.343960][ T467] dwhdmi-rockchip fde80000.hdmi: final tmdsclk = 148500000
[ 169.344010][ T467] dwhdmi-rockchip fde80000.hdmi: don't use dsc mode
[ 169.344025][ T467] dwhdmi-rockchip fde80000.hdmi: dw hdmi qp use tmds mode
[ 169.344044][ T467] rockchip-hdptx-phy-hdmi fed60000.hdmiphy: bus_width:0x16a8c8,bit_rate:1485000
[ 169.344277][ T467] rockchip-hdptx-phy-hdmi fed60000.hdmiphy: hdptx phy lane locked!
[ 169.780527][ T458] dwhdmi-rockchip fde80000.hdmi: failed to get edid
[ 169.782177][ T458] dwhdmi-rockchip fde80000.hdmi: set ops ok!!
[ 169.782212][ T458] dwhdmi-rockchip fde80000.hdmi: use tmds mode
[ 173.866716][ T467] rockchip-vop2 fdd90000.vop: [drm:vop2_crtc_atomic_disable [rockchipdrm]] Crtc atomic disable vp1
[ 174.459116][ T467] dwhdmi-rockchip fde80000.hdmi: set ops ok!!
[ 174.459168][ T467] dwhdmi-rockchip fde80000.hdmi: use tmds mode
[ 174.459526][ T467] rockchip-vop2 fdd90000.vop: [drm:vop2_crtc_atomic_enable [rockchipdrm]] Update mode to 3840x2160p60, type: 11(if:800) for vp1 dclk: 594000000
[ 174.460048][ T467] rockchip-vop2 fdd90000.vop: [drm:vop2_crtc_atomic_enable [rockchipdrm]] dclk_out1 div: 0 dclk_core1 div: 1
[ 174.460572][ T467] rockchip-vop2 fdd90000.vop: [drm:vop2_crtc_atomic_enable [rockchipdrm]] set dclk_vop1 to 297000000, get 297000000
[ 174.460658][ T467] rockchip-hdptx-phy-hdmi fed60000.hdmiphy: hdptx_ropll_cmn_config bus_width:2d5190 rate:1485000
[ 174.460978][ T467] rockchip-hdptx-phy-hdmi fed60000.hdmiphy: hdptx phy pll locked!
[ 174.461050][ T467] rockchip-hdptx-phy-hdmi fed60000.hdmiphy: hdptx_ropll_cmn_config bus_width:2d5190 rate:2970000
[ 174.461570][ T467] rockchip-hdptx-phy-hdmi fed60000.hdmiphy: hdptx phy pll locked!
[ 174.461594][ T467] dwhdmi-rockchip fde80000.hdmi: final tmdsclk = 297000000
[ 174.466034][ T467] dwhdmi-rockchip fde80000.hdmi: don't use dsc mode
[ 174.466068][ T467] dwhdmi-rockchip fde80000.hdmi: dw hdmi qp use tmds mode
[ 174.466095][ T467] rockchip-hdptx-phy-hdmi fed60000.hdmiphy: bus_width:0x2d5190,bit_rate:2970000
[ 174.466324][ T467] rockchip-hdptx-phy-hdmi fed60000.hdmiphy: hdptx phy lane locked!
[ 174.715197][ T458] dwhdmi-rockchip fde80000.hdmi: set ops ok!!
[ 174.715257][ T458] dwhdmi-rockchip fde80000.hdmi: use tmds mode
[ 186.705988][ T597] healthd: battery none chg=au
在/dev/dri/ 目录下可以看到驱动注册的各个显卡:
130|console:/ # ls /dev/dri/ -l
total 0
crw-rw-rw- 1 root graphics 226, 0 2021-01-01 09:00 card0
crw-rw-rw- 1 root graphics 226, 1 2021-01-01 09:00 card1
crw-rw-rw- 1 root graphics 226, 128 2021-01-01 09:00 renderD128
crw-rw-rw- 1 root graphics 226, 129 2021-01-01 09:00 renderD129
console:/ # ls /sys/class/drm -l
total 0
lrwxrwxrwx 1 root root 0 2021-01-01 09:54 card0 -> ../../devices/platform/display-subsystem/drm/card0
lrwxrwxrwx 1 root root 0 2021-01-01 09:54 card0-DP-1 -> ../../devices/platform/display-subsystem/drm/card0/card0-DP-1
lrwxrwxrwx 1 root root 0 2021-01-01 09:08 card0-HDMI-A-1 -> ../../devices/platform/display-subsystem/drm/card0/card0-HDMI-A-1
lrwxrwxrwx 1 root root 0 2021-01-01 09:54 card0-HDMI-A-2 -> ../../devices/platform/display-subsystem/drm/card0/card0-HDMI-A-2
lrwxrwxrwx 1 root root 0 2021-01-01 09:54 card0-Writeback-1 -> ../../devices/platform/display-subsystem/drm/card0/card0-Writeback-1
lrwxrwxrwx 1 root root 0 2021-01-01 09:54 card1 -> ../../devices/platform/fdab0000.npu/drm/card1
lrwxrwxrwx 1 root root 0 2021-01-01 09:54 renderD128 -> ../../devices/platform/display-subsystem/drm/renderD128
lrwxrwxrwx 1 root root 0 2021-01-01 09:54 renderD129 -> ../../devices/platform/fdab0000.npu/drm/renderD129
lrwxrwxrwx 1 root root 0 2021-01-01 09:54 ttm -> ../../devices/virtual/drm/ttm
-r--r--r-- 1 root root 4096 2021-01-01 09:54 version
查看hdmi输出使能状态:
cat /sys/class/drm/card0-HDMI-A-1/enabled
enabled
在使用cat命令读取enabled文件时调用enabled_show方法:
static ssize_t enabled_show(struct device *device,struct device_attribute *attr,char *buf)
{struct drm_connector *connector = to_drm_connector(device);bool enabled;enabled = READ_ONCE(connector->encoder);return sysfs_emit(buf, enabled ? "enabled\n" : "disabled\n");
}
查看hdmi的插拔连接状态;
console:/ # cat /sys/class/drm/card0-HDMI-A-1/status
disconnected //拔掉状态console:/ # cat /sys/class/drm/card0-HDMI-A-1/status
connected //连接状态
在使用cat命令读取status文件时调用status_show方法:
static ssize_t status_show(struct device *device,struct device_attribute *attr,char *buf)
{struct drm_connector *connector = to_drm_connector(device);enum drm_connector_status status;status = READ_ONCE(connector->status);return sysfs_emit(buf, "%s\n",drm_get_connector_status_name(status));
}
通过如下命令可以查看edid信息:
console:/ # busybox hexdump /sys/class/drm/card0-HDMI-A-1/edid
0000000 ff00 ffff ffff 00ff d024 3588 0001 0000
0000010 202d 0301 7880 7844 cf0a a374 4c57 23b0
0000020 4809 214c 0008 4061 0101 0081 0095 c0a9
0000030 0101 0101 0101 e808 3000 70f2 805a 58b0
0000040 008a 8ec4 0021 1e00 3a02 1880 3871 402d
0000050 2c58 0045 a8b9 0042 1e00 0000 fc00 4900
0000060 5046 4420 7369 6c70 7961 200a 0000 fd00
0000070 3b00 1f46 3c8c 0a00 2020 2020 2020 dd01
0000080 0302 f235 0751 1416 0105 1203 8413 1f22
0000090 5d90 5f5e 6160 0923 0707 0183 0000 0365
00000a0 000c 0040 d867 c45d 7801 00c0 05e3 0103
00000b0 0fe4 8000 0801 00e8 f230 5a70 b080 8a58
00000c0 c400 218e 0000 021e 803a 7118 2d38 5840
00000d0 452c b900 42a8 0000 009e 0000 0000 0000
00000e0 0000 0000 0000 0000 0000 0000 0000 0000
00000f0 0000 0000 0000 0000 0000 0000 0000 1600
0000100
Established Timings其定义在drivers/gpu/drm/drm_edid.c文件的edid_est_modes数组中:
static const struct drm_display_mode drm_dmt_modes[] = {/* 0x55 - 1280x720@60Hz */{ DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 1390,1430, 1650, 0, 720, 725, 730, 750, 0,DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },/* 0x23 - 1280x1024@60Hz */{ DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 108000, 1280, 1328,1440, 1688, 0, 1024, 1025, 1028, 1066, 0,DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },/* 0x2f - 1440x900@60Hz */{ DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 106500, 1440, 1520,1672, 1904, 0, 900, 903, 909, 934, 0,DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },/* 0x53 - 1600x900@60Hz */{ DRM_MODE("1600x900", DRM_MODE_TYPE_DRIVER, 108000, 1600, 1624,1704, 1800, 0, 900, 901, 904, 1000, 0,DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },/* 0x3a - 1680x1050@60Hz */{ DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 146250, 1680, 1784,1960, 2240, 0, 1050, 1053, 1059, 1089, 0,DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },/* 0x52 - 1920x1080@60Hz */{ DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2008,2052, 2200, 0, 1080, 1084, 1089, 1125, 0,DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },/* 0x45 - 1920x1200@60Hz */{ DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 193250, 1920, 2056,2256, 2592, 0, 1200, 1203, 1209, 1245, 0,DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },......
}
使用命令查看这款HDMI显示屏支持:
3840x2160
1920x1080
1600x900
1440x900
1280x800
1280x720
1024x768
800x600
720x576
720x480
640x480
需要注意的是1152x864@60Hz并没有在drm_dmt_modes数组中定义,如果想要支持该显示模式,需要我们自己在数组里面添加分辨率1152x864。