Introduction
In a previous article, Hand-on Series Display Part (1) – Analysis of LCD and OLED Display Parameters, we analyzed the working principles of LCD screens and the meanings of various parameters. In this article, we will first calculate the total height and total width of a frame based on the screen parameters:
Subsequently, we can obtain the amount of data (Frame_Bit, in bits) needed for one frame based on the total length, total width, and the depth of display pixels (Pixel_Depth, unit bpp, bits per pixel):
Frame_Bit =
Total_Width x Total_Height x Pixel_Depth
For colored images, the pixel depth determines the number of possible colors for each pixel. Typically, each pixel of a colored image is represented by three components: R, G, and B. If each component uses 8 bits (RGB888), then a pixel is represented by 24 bits, and its pixel depth is 24 bpp (bits per pixel). In this case, the pixel can represent one of 2 to the power of 24 colors. Therefore, we can conclude that the greater the pixel depth of a pixel, the more colors it can represent. Below are some common color formats we often encounter:
-
RGB888 – Pixel Depth = 24 bpp
-
RGB666 – Pixel Depth = 18 bpp
-
RGB565 – Pixel Depth = 16 bpp
Additionally, a video stream consists of a series of display frames with fixed timing intervals. Therefore, we can calculate the number of pixels per second by introducing the frame rate (fps) to obtain the pixel clock (Pixel_Clk):
Furthermore, we can calculate the total system bandwidth, which is the amount of data that needs to be transmitted in one second (in bps):
We typically set the Pixel_Clk obtained from dividing the VIDEO PLL, and VIDEO PLL is derived from the CCM. Therefore, we need to further calculate the relationship between the VIDEO PLL required for the screen and its clock source and configure it:
When calculating the Clk-related parameters, we not only consider the effective resolution but also the front porch, back porch, and sync signals. However, it is important to note that when we calculate the size of the frame buffer needed to store one frame of image, we only need to consider the actual effective resolution and pixel depth:
Buffer_Size =
Active_Height x Active_Width
x Bits_per_Pixel
Based on RM67191 MIPI DSI Parameter Calculation
2.1 Calculation and Setting of Pixel Clk
-
RM67191 Driver:
drivers/gpu/drm/panel/panel-raydium-rm67191.c
-
DTB:
arch/arm64/boot/dts/freescale/imx8mp-evk-rm67191.dts
-
HFP, H-SYNC, HBP and HACTIVE
-
VFP, V-SYNC, VBP and Active Height
-
Pixel_Depth = 24 bpp
-
fps = 60
-
lane_number =4
First, we can calculate the total number of pixels in both length and width of one frame displayed on the screen
According to the previous formula, the pixel clock required for a frame rate of 60 FPS can be obtained by multiplying the total pixels per frame by the required frame rate:
Pixel_Clk =
1136 * 1936 x 60 = 131,957,760 Hz
Pixel_Clk ≈ 132MHz
The pixel format of the screen is RGB888, so the pixel depth is 24. We can also obtain the bandwidth:
Bit_per_Second =
131,957,760 x 24 = 3,166,986,240 bps
static const struct drm_display_mode default_mode = { .clock = 132000, .hdisplay = 1080, .hsync_start = 1080 + 20, .hsync_end = 1080 + 20 + 2, .htotal = 1080 + 20 + 2 + 34, .vdisplay = 1920, .vsync_start = 1920 + 10, .vsync_end = 1920 + 10 + 2, .vtotal = 1920 + 10 + 2 + 4, .width_mm = 68, .height_mm = 121, .flags = DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC,};
/* VIDEO_PLL m p s k*/static const struct imx_pll14xx_rate_table imx_pll1443x_tbl[] = { PLL_1443X_RATE(1039500000U, 173, 2, 1, 16384), PLL_1443X_RATE(650000000U, 325, 3, 2, 0), PLL_1443X_RATE(594000000U, 198, 2, 2, 0), PLL_1443X_RATE(519750000U, 173, 2, 2, 16384), PLL_1443X_RATE(393216000U, 262, 2, 3, 9437), PLL_1443X_RATE(361267200U, 361, 3, 3, 17511),};
After setting Pixel_Clk, we need to further set the VIDEO_PLL. If the VIDEO_PLL value we expect to use is not in the above PLL driver, we also need to add the VIDEO_PLL and its multiplier values m, k, p, and s in the structure. Below is a calculation demonstration using the VIDEO PLL value of ‘1039500000’:
In addition to adding the VIDEO PLL we are using in the structure, we also need to set it in the DTB:
media_blk_ctrl: blk-ctrl@32ec0000 { <...> assigned-clocks = <&clk IMX8MP_CLK_MEDIA_AXI>, <&clk IMX8MP_CLK_MEDIA_APB>, <&clk IMX8MP_CLK_MEDIA_DISP1_PIX>, <&clk IMX8MP_CLK_MEDIA_DISP2_PIX>, <&clk IMX8MP_VIDEO_PLL1>; assigned-clock-parents = <&clk IMX8MP_SYS_PLL2_1000M>, <&clk IMX8MP_SYS_PLL1_800M>, <&clk IMX8MP_VIDEO_PLL1_OUT>, <&clk IMX8MP_VIDEO_PLL1_OUT>; assigned-clock-rates = <500000000>, <200000000>, <0>, <0>, <1039500000>; };
In addition to understanding the frequency division relationship between VIDEO_PLL and Pixel_Clk at the register level, we can also confirm whether our settings are successful by reading the register values.
# /unit_tests/memtool -32 0x3038be00 10x3038BE00: 11000007
-
ENABLE(28) bit is 1: enables the clock root
-
MUX(26-24) bits are 001: Source is set to VIDEO_PLL_CLK
-
POST_PODF(5-0) bits are111: Pixel_Clk is obtained by dividing VIDEO_PLL by 8
In addition to accessing the register values, we can also see the set VIDEO PLL and Pixel_clock to confirm whether they are set successfully by the command cat /sys/kernel/debug/clk/clk_summary.
osc_24m 15 15 0 24000000 0 0 50000 Y video_pll1_ref_sel 1 1 0 24000000 0 0 50000 Y video_pll1 1 1 0 1039500000 0 0 50000 Y video_pll1_bypass 1 1 0 1039500000 0 0 50000 Y video_pll1_out 1 1 0 1039500000 0 0 50000 Y media_disp1_pix 1 1 0 129937500 0 0 50000 Y media_disp1_pix_root_clk 1 1 0 129937500 0 0 50000 Y
This article analyzed DSI, and using RM67191 as an example, calculated the parameters needed to enable MIPI-DSI screens. For any questions or suggestions regarding the article, please contact the author at [email protected]. We welcome discussions via email. In the coming period, we will gradually update the parameter analysis and calculations related to display modules (LVDS and MIPI-DSI), so stay tuned to the official account for the latest updates. If you have any questions about displays or other modules, please feel free to reach out for discussion.