NXP imx6 系列添加自定义hdmi分辨率
平台: nxp imx6dl
BSP: linux 4.1.15 x11
最近项目上的应用是 1024x768 分辨率, imx6dl hdmi 输出默认是 1920x1080@60
支持列表里也看不到,1024x768 的分辨率,在uboot里传参 1024x768 结果输出是1280x720
这种情况下,要么ui显示不全,要么ui缩在显示器左上角,不纯纯要我命吗。。。
可以采取以下解决方案,
一 缩放
通过以下设置把ui缩放到满屏
xrandr --output ‘DISP3 BG - DI1’ --scale-from 1024x768
其中DISP3 BG - DI1 是 fbdev name,执行xrandr 可以看到
1024x768 是ui原始分辨率。
二 通过cvt 和 xrandr设置需要的分辨率
//用cvt得到新分辨率的参数
cvt 1024 768 60
//添加新分辨率
xrandr --newmode “1024x768_60.00” 63.50 1024 1072 1176 1328 768 771 775 798 -hsync +vsync
//把新分辨率添加到模式列表
xrandr --addmode ‘DISP3 BG - DI1’ “1024x768_60.00”
//设置新分辨率
xrandr --output ‘DISP3 BG - DI1’ --mode “1024x768_60.00”
或者
xrandr -s 1024x768
三 在内核中默认支持自定义的分辨率
hdmi初始化期间会从linux-4.1.15\drivers\video\fbdev\core\modedb.c 获取支持的标准分辨率,如下:
该数组结构如下, 要添加自定义分辨率,xres yres refresh 是知道的,其他成员怎么赋值呢?
struct fb_videomode {
const char *name; /* optional */
u32 refresh; /* optional */
u32 xres;
u32 yres;
u32 pixclock;
u32 left_margin;
u32 right_margin;
u32 upper_margin;
u32 lower_margin;
u32 hsync_len;
u32 vsync_len;
u32 sync;
u32 vmode;
u32 flag;
};
百度搜索可以看到很多人在通过公式计算 分辨率相关参数。这个我不懂,咱也不会,哈哈。
fbcvt 可以做的事情,我直接用就好了,懒得用公式一步步计算了。
fb_find_mode_cvt 的函数声明可以看到,参数至少需要 xres, yres, refresh 和vmode
vmode 参数可选
#define FB_VMODE_NONINTERLACED 0 /* non interlaced */
#define FB_VMODE_INTERLACED 1 /* interlaced */
我的参数是 1024 768 60 FB_VMODE_NONINTERLACED
赋给 struct fb_videomode 对应的成员后,fb_find_mode_cvt 会把其他的成员计算出来。并填充struct fb_videomode
/*
* fb_find_mode_cvt - calculate mode using VESA(TM) CVT
* @mode: pointer to fb_videomode; xres, yres, refresh and vmode must be
* pre-filled with the desired values
* @margins: add margin to calculation (1.8% of xres and yres)
* @rb: compute with reduced blanking (for flatpanels)
*
* RETURNS:
* 0 for success
* @mode is filled with computed values. If interlaced, the refresh field
* will be filled with the field rate (2x the frame rate)
*
* DESCRIPTION:
* Computes video timings using VESA(TM) Coordinated Video Timings
*/
int fb_find_mode_cvt(struct fb_videomode *mode, int margins, int rb)
所以,fbcvt 得到自定义分辨率的参数,然后加到hdmi 支持列表里。
最后把新的分辨率设置下去,具体流程不再分析,百度可以看到很多大佬的流程分析
我们需要用到三个接口
// 得到新分辨率参数
int fb_find_mode_cvt(struct fb_videomode *mode, int margins, int rb)
// 把新分辨率添加到支持列表
fb_add_videomint fb_add_videomode(const struct fb_videomode *mode, struct list_head *head)
// 设置分辨率
void mxc_hdmi_set_mode(struct mxc_hdmi *hdmi)
具体修改如下:
--- a/linux-4.1.15/drivers/video/fbdev/mxc/mxc_hdmi.c
+++ b/linux-4.1.15/drivers/video/fbdev/mxc/mxc_hdmi.c
@@ -1955,6 +1955,14 @@ static void mxc_hdmi_cable_connected(struct mxc_hdmi *hdmi)
break;
}
+ /* Bruce Su 20210913. add 1024*768 resolution */
+ struct fb_videomode tlfs_mode = {};
+ tlfs_mode.vmode = FB_VMODE_NONINTERLACED;
+ tlfs_mode.xres = 1024;
+ tlfs_mode.yres = 768;
+ tlfs_mode.refresh = 60;
+ fb_find_mode_cvt(&tlfs_mode, 0, 0);
+ fb_add_videomode(&tlfs_mode, &hdmi->fbi->modelist);
/* Setting video mode */
mxc_hdmi_set_mode(hdmi);