video: use bpp conversion helpers consistently
Subsystems (7)
PATCH v2 1/1 video: use bpp conversion helpers consistently
Many places open-code the conversion between log2 bits-per-pixel and the actual number of bits or bytes per pixel, using expressions such as "1 << bpix", "(1 << bpix) / 8" and "((1 << bpix) >> 3)". Meanwhile, <video.h> already provides VNBITS() and VNBYTES() helpers for exactly these conversions. Replace the open-coded expressions with the helpers.
Using the helpers makes the intent of the expression clear, removes duplicated bit manipulation, and reduces the reliance on the specially crafted VIDEO_BPP* enum values, since callers no longer need to know that those values are log2 quantities which is also important for future extensions.
Note that VNBYTES() is only correct for 8bpp and above, since it returns a whole number of bytes per pixel and cannot represent sub-byte pixel sizes. Every site converted to VNBYTES() here uses 16bpp or 32bpp, so the result is identical to the original expression.
No functional change is made.
---
Changes in v2:
- Convert uncaught conversion cases in the following files:
- arch/sandbox/cpu/sdl.c
- boot/fdt_simplefb.c
- drivers/video/atmel_lcdfb.c
- drivers/video/rockchip/rk_vop.c
- drivers/video/sunxi/sunxi_de2.c
- drivers/video/tegra/tegra124/display.c
- Updated commit message
- Link to v1: https://patch.msgid.link/[email protected]
--- arch/sandbox/cpu/sdl.c | 4 ++-- boot/fdt_simplefb.c | 2 +- cmd/bdinfo.c | 2 +- drivers/video/atmel_hlcdfb.c | 2 +- drivers/video/atmel_lcdfb.c | 4 ++-- drivers/video/imx/mxc_ipuv3_fb.c | 2 +- drivers/video/meson/meson_vpu.c | 4 ++-- drivers/video/mvebu_lcd.c | 2 +- drivers/video/rockchip/rk_vop.c | 4 ++-- drivers/video/sunxi/sunxi_de2.c | 8 ++++---- drivers/video/tegra/dc.c | 4 ++-- drivers/video/tegra/tegra124/display.c | 4 ++-- drivers/video/ti/tilcdc.c | 4 ++-- drivers/video/tidss/tidss_drv.c | 4 ++-- test/cmd/bdinfo.c | 2 +- 15 files changed, 26 insertions(+), 26 deletions(-)
arch/sandbox/cpu/sdl.c +2 -2
@@ -152,10 +152,10 @@ int sandbox_sdl_init_display(int width, int height, int log2_bpp,if (!SDL_SetHint (SDL_HINT_RENDER_SCALE_QUALITY ,"1" ))printf ("Unable to init hinting: %s" ,SDL_GetError ()); - sdl.src_depth =1 << log2_bpp; + sdl.src_depth =VNBITS (log2_bpp);if (log2_bpp !=4 && log2_bpp !=5 ) log2_bpp =5 ; - sdl.depth =1 << log2_bpp; + sdl.depth =VNBITS (log2_bpp); sdl.pitch = sdl.width * sdl.depth /8 ; sdl.screen = SDL_CreateWindow("U-Boot", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, sdl.vis_width,
boot/fdt_simplefb.c +1 -1
@@ -59,7 +59,7 @@ static int fdt_simplefb_configure_node(void *blob, int off) }return fdt_setup_simplefb_node (blob, off, fb_base, xsize, ysize, - xsize * (1 << bpix) /8 , name); + xsize *VNBYTES (bpix), name); }int fdt_simplefb_add_node (void *blob)
cmd/bdinfo.c +1 -1
@@ -114,7 +114,7 @@ static void show_video_info(void) plat->copy_size); }printf ("%-12s= %dx%dx%d\n" ,"FB size" , upriv->xsize, - upriv->ysize,1 << upriv->bpix); + upriv->ysize,VNBITS (upriv->bpix)); } } }
drivers/video/atmel_hlcdfb.c +1 -1
@@ -315,7 +315,7 @@ static int atmel_hlcdc_bind(struct udevice *dev)struct video_uc_plat *uc_plat =dev_get_uclass_plat (dev); uc_plat->size =LCD_MAX_WIDTH *LCD_MAX_HEIGHT * - (1 <<LCD_MAX_LOG2_BPP ) /8 ; +VNBYTES (LCD_MAX_LOG2_BPP );debug ("%s: Frame buffer size %x\n" , __func__, uc_plat->size);
drivers/video/atmel_lcdfb.c +2 -2
@@ -69,7 +69,7 @@ static void atmel_fb_init(ulong addr, struct display_timing *timing, int bpix,/* ...set frame size and burst length = 8 words (?) */ value = (timing->hactive.typ * timing->vactive.typ * - (1 << bpix)) /32 ; +VNBITS (bpix)) /32 ; value |= ((ATMEL_LCDC_DMA_BURST_LEN -1 ) <<ATMEL_LCDC_BLENGTH_OFFSET );lcdc_writel (reg,ATMEL_LCDC_DMAFRMCFG , value);
@@ -187,7 +187,7 @@ static int atmel_fb_lcd_bind(struct udevice *dev)struct video_uc_plat *uc_plat =dev_get_uclass_plat (dev); uc_plat->size =LCD_MAX_WIDTH *LCD_MAX_HEIGHT * - (1 <<VIDEO_BPP16 ) /8 ; +VNBYTES (VIDEO_BPP16 );debug ("%s: Frame buffer size %x\n" , __func__, uc_plat->size);return 0 ;
drivers/video/imx/mxc_ipuv3_fb.c +1 -1
@@ -654,7 +654,7 @@ static int ipuv3_video_bind(struct udevice *dev) {struct video_uc_plat *plat =dev_get_uclass_plat (dev); - plat->size =LCD_MAX_WIDTH *LCD_MAX_HEIGHT * (1 <<VIDEO_BPP32 ) /8 ; + plat->size =LCD_MAX_WIDTH *LCD_MAX_HEIGHT *VNBYTES (VIDEO_BPP32 );return 0 ; }
drivers/video/meson/meson_vpu.c +2 -2
@@ -79,7 +79,7 @@ cvbs:/* Move the framebuffer to the end of addressable ram */ meson_fb.fb_size =ALIGN (meson_fb.xsize * meson_fb.ysize * - ((1 <<VPU_MAX_LOG2_BPP ) /8 ) + +VNBYTES (VPU_MAX_LOG2_BPP ) +MESON_VPU_OVERSCAN ,EFI_PAGE_SIZE ); meson_fb.base = gd->dram[0 ].start + gd->dram[0 ].size - meson_fb.fb_size;
@@ -141,7 +141,7 @@ static int meson_vpu_bind(struct udevice *dev)struct video_uc_plat *plat =dev_get_uclass_plat (dev); plat->size =VPU_MAX_WIDTH *VPU_MAX_HEIGHT * - (1 <<VPU_MAX_LOG2_BPP ) /8 ; +VNBYTES (VPU_MAX_LOG2_BPP );return 0 ; }
drivers/video/mvebu_lcd.c +1 -1
@@ -576,7 +576,7 @@ static int mvebu_video_bind(struct udevice *dev)struct video_uc_plat *plat =dev_get_uclass_plat (dev); plat->size =LCD_MAX_WIDTH *LCD_MAX_HEIGHT * - (1 <<LCD_MAX_LOG2_BPP ) /8 ; +VNBYTES (LCD_MAX_LOG2_BPP );return 0 ; }
drivers/video/rockchip/rk_vop.c +2 -2
@@ -381,9 +381,9 @@ static int rk_display_init(struct udevice *dev, ulong fbbase, ofnode ep_node)return ret; } -rkvop_enable (dev, fbbase,1 << l2bpp, &timing, &dclk_rst); +rkvop_enable (dev, fbbase,VNBITS (l2bpp), &timing, &dclk_rst); - ret =display_enable (disp,1 << l2bpp, &timing); + ret =display_enable (disp,VNBITS (l2bpp), &timing);if (ret)return ret;
drivers/video/sunxi/sunxi_de2.c +4 -4
@@ -202,9 +202,9 @@ static int sunxi_de2_init(struct udevice *dev, ulong fbbase, }sunxi_de2_composer_init (); -sunxi_de2_mode_set (mux, &timing,1 << l2bpp, fbbase, is_composite); +sunxi_de2_mode_set (mux, &timing,VNBITS (l2bpp), fbbase, is_composite); - ret =display_enable (disp,1 << l2bpp, &timing); + ret =display_enable (disp,VNBITS (l2bpp), &timing);if (ret) {debug ("%s: Failed to enable display\n" , __func__);return ret;
@@ -218,7 +218,7 @@ static int sunxi_de2_init(struct udevice *dev, ulong fbbase,#ifdef CONFIG_EFI_LOADER efi_add_memory_map (fbbase, timing.hactive.typ * timing.vactive.typ * - (1 << l2bpp) /8 , +VNBYTES (l2bpp),EFI_RESERVED_MEMORY_TYPE );#endif
@@ -279,7 +279,7 @@ static int sunxi_de2_bind(struct udevice *dev)struct video_uc_plat *plat =dev_get_uclass_plat (dev); plat->size =LCD_MAX_WIDTH *LCD_MAX_HEIGHT * - (1 <<LCD_MAX_LOG2_BPP ) /8 ; +VNBYTES (LCD_MAX_LOG2_BPP );return 0 ; }
drivers/video/tegra/dc.c +2 -2
@@ -278,7 +278,7 @@ static int setup_window(struct tegra_lcd_priv *priv, win->out_w = priv->width; win->out_h = priv->height; win->phys_addr = priv->frame_buffer; - win->stride = priv->width * (1 << priv->log2_bpp) /8 ; + win->stride = priv->width *VNBYTES (priv->log2_bpp);log_debug ("%s: depth = %d\n" , __func__, priv->log2_bpp);
@@ -646,7 +646,7 @@ static int tegra_lcd_bind(struct udevice *dev)struct video_uc_plat *plat =dev_get_uclass_plat (dev); plat->size =LCD_MAX_WIDTH *LCD_MAX_HEIGHT * - (1 <<LCD_MAX_LOG2_BPP ) /8 ; +VNBYTES (LCD_MAX_LOG2_BPP );return dm_scan_fdt_dev (dev); }
drivers/video/tegra/tegra124/display.c +2 -2
@@ -448,7 +448,7 @@ static int tegra124_lcd_init(struct udevice *dev, void *lcdbase,reset_set_enable (PERIPH_ID_DPAUX ,0 );reset_set_enable (PERIPH_ID_SOR0 ,0 ); - ret =display_init (dev, lcdbase,1 << l2bpp, &timing); + ret =display_init (dev, lcdbase,VNBITS (l2bpp), &timing);if (ret)return ret;
@@ -484,7 +484,7 @@ static int tegra124_lcd_bind(struct udevice *dev)struct video_uc_plat *uc_plat =dev_get_uclass_plat (dev); uc_plat->size =LCD_MAX_WIDTH *LCD_MAX_HEIGHT * - (1 <<VIDEO_BPP16 ) /8 ; +VNBYTES (VIDEO_BPP16 );debug ("%s: Frame buffer size %x\n" , __func__, uc_plat->size);return 0 ;
drivers/video/ti/tilcdc.c +2 -2
@@ -430,8 +430,8 @@ static int tilcdc_bind(struct udevice *dev) {struct video_uc_plat *uc_plat =dev_get_uclass_plat (dev); - uc_plat->size = ((LCDC_MAX_WIDTH *LCDC_MAX_HEIGHT * - (1 <<LCDC_MAX_LOG2_BPP )) >>3 ) +0x20 ; + uc_plat->size =LCDC_MAX_WIDTH *LCDC_MAX_HEIGHT * +VNBYTES (LCDC_MAX_LOG2_BPP ) +0x20 ;dev_dbg (dev,"frame buffer size 0x%x\n" , uc_plat->size);return 0 ;
drivers/video/tidss/tidss_drv.c +2 -2
@@ -986,8 +986,8 @@ static int tidss_drv_bind(struct udevice *dev) {struct video_uc_plat *uc_plat =dev_get_uclass_plat (dev); - uc_plat->size = ((LCD_MAX_WIDTH *LCD_MAX_HEIGHT * - (1 <<LCD_MAX_LOG2_BPP )) >>3 ) +0x20 ; + uc_plat->size =LCD_MAX_WIDTH *LCD_MAX_HEIGHT * +VNBYTES (LCD_MAX_LOG2_BPP ) +0x20 ;return 0 ; }
test/cmd/bdinfo.c +1 -1
@@ -91,7 +91,7 @@ static int test_video_info(struct unit_test_state *uts) }ut_assert_nextline ("%-12s= %dx%dx%d" ,"FB size" , upriv->xsize, upriv->ysize, -1 << upriv->bpix); +VNBITS (upriv->bpix)); } }
---
base-commit: ed869863c7e2aca50d57a05d843830dd843138c4
change-id: 20261006-bpp-helpers-d8d63b120d8a
Best regards,
Signature · 1 line
Reza Kurniawan <[email protected]>
Hi Reza,
Quoted 22 lines · Reza Kurniawan
video: use bpp conversion helpers consistently
Many places open-code the conversion between log2 bits-per-pixel and the actual number of bits or bytes per pixel, using expressions such as "1 << bpix", "(1 << bpix) / 8" and "((1 << bpix) >> 3)". Meanwhile, <
video.h> already providesVNBITS()andVNBYTES()helpers for exactly these conversions. Replace the open-coded expressions with the helpers.Using the helpers makes the intent of the expression clear, removes duplicated bit manipulation, and reduces the reliance on the specially crafted VIDEO_BPP* enum values, since callers no longer need to know that those values are log2 quantities which is also important for future extensions.
Note that
VNBYTES()is only correct for 8bpp and above, since it returns a whole number of bytes per pixel and cannot represent sub-byte pixel sizes. Every site converted toVNBYTES()here uses 16bpp or 32bpp, so the result is identical to the original expression.No functional change is made.
[...]
Quoted 16 lines
arch/sandbox/cpu/sdl.c | 4 ++-- boot/fdt_simplefb.c | 2 +- cmd/bdinfo.c | 2 +- drivers/video/atmel_hlcdfb.c | 2 +- drivers/video/atmel_lcdfb.c | 4 ++-- drivers/video/imx/mxc_ipuv3_fb.c | 2 +- drivers/video/meson/meson_vpu.c | 4 ++-- drivers/video/mvebu_lcd.c | 2 +- drivers/video/rockchip/rk_vop.c | 4 ++-- drivers/video/sunxi/sunxi_de2.c | 8 ++++---- drivers/video/tegra/dc.c | 4 ++-- drivers/video/tegra/tegra124/display.c | 4 ++-- drivers/video/ti/tilcdc.c | 4 ++-- drivers/video/tidss/tidss_drv.c | 4 ++-- test/cmd/bdinfo.c | 2 +- 15 files changed, 26 insertions(+), 26 deletions(-)
Thanks for the respin.
Hi Reza,
Quoted 31 lines · Reza Kurniawan
Many places open-code the conversion between log2 bits-per-pixel and the actual number of bits or bytes per pixel, using expressions such as "1 << bpix", "(1 << bpix) / 8" and "((1 << bpix) >> 3)". Meanwhile, <
video.h> already providesVNBITS()andVNBYTES()helpers for exactly these conversions. Replace the open-coded expressions with the helpers.Using the helpers makes the intent of the expression clear, removes duplicated bit manipulation, and reduces the reliance on the specially crafted VIDEO_BPP* enum values, since callers no longer need to know that those values are log2 quantities which is also important for future extensions.
Note that
VNBYTES()is only correct for 8bpp and above, since it returns a whole number of bytes per pixel and cannot represent sub-byte pixel sizes. Every site converted toVNBYTES()here uses 16bpp or 32bpp, so the result is identical to the original expression.No functional change is made.
Signed-off-by Reza Kurniawan <[email protected]>---
Changes in v2:
- Convert uncaught conversion cases in the following files:
-arch/sandbox/cpu/sdl.c
-boot/fdt_simplefb.c
-drivers/video/atmel_lcdfb.c
-drivers/video/rockchip/rk_vop.c
-drivers/video/sunxi/sunxi_de2.c
-drivers/video/tegra/tegra124/display.c
- Updated commit message
- Link to v1: https://patch.msgid.link/[email protected]
Quoted 10 lines
--- arch/sandbox/cpu/sdl.c | 4 ++-- boot/fdt_simplefb.c | 2 +- cmd/bdinfo.c | 2 +- drivers/video/atmel_hlcdfb.c | 2 +- drivers/video/atmel_lcdfb.c | 4 ++-- drivers/video/imx/mxc_ipuv3_fb.c | 2 +- drivers/video/meson/meson_vpu.c | 4 ++-- drivers/video/mvebu_lcd.c | 2 +- drivers/video/rockchip/rk_vop.c | 4 ++--
Cheers,
Quentin