Refactor reused code for updating fb_info
cover Refactor reused code for updating fb_info
This patch set will unify reused switch statement updating fb_info by creating inline functions.
Tested only by compilation.
Matej Dujava (3):
staging: sm750fb: add missing case while setting FB_VISUAL
staging: sm750fb: add common function to set color offsets and visual
mode
staging: sm750fb: print error message with actual value
drivers/staging/sm750fb/sm750.c | 150 +++++++++++++++----------------- 1 file changed, 68 insertions(+), 82 deletions(-)
Signature · 1 line
2.26.2
PATCH 1/3 staging: sm750fb: add missing case while setting FB_VISUAL
Switch statement does not contain all cases: 8, 16, 24, 32. This patch will add missing one (24)
--- drivers/staging/sm750fb/sm750.c | 1 + 1 file changed, 1 insertion(+)
drivers/staging/sm750fb/sm750.c +1 -0
@@ -900,6 +900,7 @@ static int lynxfb_set_fbinfo(struct fb_info *info, int index) fix->visual =FB_VISUAL_PSEUDOCOLOR ;break ;case 16 : +case 24 :case 32 : fix->visual =FB_VISUAL_TRUECOLOR ;break ;
Signature · 1 line
2.26.2
PATCH 2/3 staging: sm750fb: add common function to set color offsets and visual mode
In reply to Matej DujavaThis patch will unify code for updating color offsets and frame buffer visual mode.
--- drivers/staging/sm750fb/sm750.c | 149 ++++++++++++++------------------ 1 file changed, 67 insertions(+), 82 deletions(-)
drivers/staging/sm750fb/sm750.c +67 -82
@@ -297,6 +297,62 @@ static int lynxfb_ops_pan_display(struct fb_var_screeninfo *var,return hw_sm750_pan_display (crtc, var, info); } +static inline void lynxfb_set_visual_mode (struct fb_info *info) +{ +switch (info->var.bits_per_pixel) { +case 8 : + info->fix.visual =FB_VISUAL_PSEUDOCOLOR ; +break ; +case 16 : +case 24 : +case 32 : + info->fix.visual =FB_VISUAL_TRUECOLOR ; +break ; +default : +break ; + } +} + +static inline int lynxfb_set_color_offsets (struct fb_info *info) +{ +lynxfb_set_visual_mode (info); + +switch (info->var.bits_per_pixel) { +case 8 : + info->var.red.offset =0 ; + info->var.red.length =8 ; + info->var.green.offset =0 ; + info->var.green.length =8 ; + info->var.blue.offset =0 ; + info->var.blue.length =8 ; + info->var.transp.length =0 ; + info->var.transp.offset =0 ; +break ; +case 16 : + info->var.red.offset =11 ; + info->var.red.length =5 ; + info->var.green.offset =5 ; + info->var.green.length =6 ; + info->var.blue.offset =0 ; + info->var.blue.length =5 ; + info->var.transp.length =0 ; + info->var.transp.offset =0 ; +break ; +case 24 : +case 32 : + info->var.red.offset =16 ; + info->var.red.length =8 ; + info->var.green.offset =8 ; + info->var.green.length =8 ; + info->var.blue.offset =0 ; + info->var.blue.length =8 ; +break ; +default : +return -EINVAL ; + } +return 0 ; +} +static int lynxfb_ops_set_par (struct fb_info *info) {struct lynxfb_par *par;
@@ -328,43 +384,8 @@ static int lynxfb_ops_set_par(struct fb_info *info)* and these data should be set before setcolreg routine */ -switch (var->bits_per_pixel) { -case 8 : - fix->visual =FB_VISUAL_PSEUDOCOLOR ; - var->red.offset =0 ; - var->red.length =8 ; - var->green.offset =0 ; - var->green.length =8 ; - var->blue.offset =0 ; - var->blue.length =8 ; - var->transp.length =0 ; - var->transp.offset =0 ; -break ; -case 16 : - var->red.offset =11 ; - var->red.length =5 ; - var->green.offset =5 ; - var->green.length =6 ; - var->blue.offset =0 ; - var->blue.length =5 ; - var->transp.length =0 ; - var->transp.offset =0 ; - fix->visual =FB_VISUAL_TRUECOLOR ; -break ; -case 24 : -case 32 : - var->red.offset =16 ; - var->red.length =8 ; - var->green.offset =8 ; - var->green.length =8 ; - var->blue.offset =0 ; - var->blue.length =8 ; - fix->visual =FB_VISUAL_TRUECOLOR ; -break ; -default : - ret = -EINVAL ; -break ; - } + ret =lynxfb_set_color_offsets (info); + var->height = var->width =-1 ; var->accel_flags =0 ;/*FB_ACCELF_TEXT;*/
@@ -511,10 +532,12 @@ static int lynxfb_resume(struct pci_dev *pdev)static int lynxfb_ops_check_var (struct fb_var_screeninfo *var,struct fb_info *info) { +int ret;struct lynxfb_par *par;struct lynxfb_crtc *crtc;resource_size_t request; + ret =0 ; par = info->par; crtc = &par->crtc;
@@ -523,43 +546,13 @@ static int lynxfb_ops_check_var(struct fb_var_screeninfo *var, var->yres, var->bits_per_pixel); -switch (var->bits_per_pixel) { -case 8 : - info->fix.visual =FB_VISUAL_PSEUDOCOLOR ; - var->red.offset =0 ; - var->red.length =8 ; - var->green.offset =0 ; - var->green.length =8 ; - var->blue.offset =0 ; - var->blue.length =8 ; - var->transp.length =0 ; - var->transp.offset =0 ; -break ; -case 16 : - var->red.offset =11 ; - var->red.length =5 ; - var->green.offset =5 ; - var->green.length =6 ; - var->blue.offset =0 ; - var->blue.length =5 ; - var->transp.length =0 ; - var->transp.offset =0 ; - info->fix.visual =FB_VISUAL_TRUECOLOR ; -break ; -case 24 : -case 32 : - var->red.offset =16 ; - var->red.length =8 ; - var->green.offset =8 ; - var->green.length =8 ; - var->blue.offset =0 ; - var->blue.length =8 ; - info->fix.visual =FB_VISUAL_TRUECOLOR ; -break ; -default : + ret =lynxfb_set_color_offsets (info); + +if (ret) {pr_err ("bpp %d not supported\n" , var->bits_per_pixel); -return -EINVAL ; +return ret; } + var->height = var->width =-1 ; var->accel_flags =0 ;/* FB_ACCELF_TEXT; */
@@ -895,16 +888,8 @@ static int lynxfb_set_fbinfo(struct fb_info *info, int index)pr_info ("fix->mmio_start = %lx\n" , fix->mmio_start); fix->mmio_len = sm750_dev->vidreg_size;pr_info ("fix->mmio_len = %x\n" , fix->mmio_len); -switch (var->bits_per_pixel) { -case 8 : - fix->visual =FB_VISUAL_PSEUDOCOLOR ; -break ; -case 16 : -case 24 : -case 32 : - fix->visual =FB_VISUAL_TRUECOLOR ; -break ; - } + +lynxfb_set_visual_mode (info);/* set var */ var->activate =FB_ACTIVATE_NOW ;
Signature · 1 line
2.26.2
PATCH 3/3 staging: sm750fb: print error message with actual value
In reply to Matej DujavaThis patch will update error message, so it is same as error message in another function.
--- drivers/staging/sm750fb/sm750.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/sm750fb/sm750.c +1 -1
@@ -390,7 +390,7 @@ static int lynxfb_ops_set_par(struct fb_info *info) var->accel_flags =0 ;/*FB_ACCELF_TEXT;*/ if (ret) { -pr_err ("pixel bpp format not satisfied\n." ); +pr_err ("bpp %d not supported\n" , var->bits_per_pixel);return ret; } ret =hw_sm750_crtc_setMode (crtc, var, fix);
Signature · 1 line
2.26.2