天天看點

nxp imx6添加自定義分辨率

NXP imx6 系列添加自定義hdmi分辨率

平台: nxp imx6dl

BSP: linux 4.1.15 x11

最近項目上的應用是 1024x768 分辨率, imx6dl hdmi 輸出預設是 [email protected]

支援清單裡也看不到,1024x768 的分辨率,在uboot裡傳參 1024x768 結果輸出是1280x720

這種情況下,要麼ui顯示不全,要麼ui縮在顯示器左上角,不純純要我命嗎。。。

nxp imx6添加自定義分辨率

可以采取以下解決方案,

一 縮放

通過以下設定把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 擷取支援的标準分辨率,如下:

nxp imx6添加自定義分辨率

該數組結構如下, 要添加自定義分辨率,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);