Commit 105784bb authored by Laurent Pinchart's avatar Laurent Pinchart

fbdev: sh_mobile_lcdc: Add sh_mobile_format_info() function

The function returns a pointer to a structure describing a format based
on its fourcc. Use the function where applicable instead of hardcoded
switch-case statements.
Signed-off-by: default avatarLaurent Pinchart <laurent.pinchart@ideasonboard.com>
parent 740f802a
...@@ -449,6 +449,75 @@ static int sh_mobile_lcdc_display_notify(struct sh_mobile_lcdc_chan *ch, ...@@ -449,6 +449,75 @@ static int sh_mobile_lcdc_display_notify(struct sh_mobile_lcdc_chan *ch,
* Format helpers * Format helpers
*/ */
struct sh_mobile_lcdc_format_info {
u32 fourcc;
unsigned int bpp;
bool yuv;
u32 lddfr;
};
static const struct sh_mobile_lcdc_format_info sh_mobile_format_infos[] = {
{
.fourcc = V4L2_PIX_FMT_RGB565,
.bpp = 16,
.yuv = false,
.lddfr = LDDFR_PKF_RGB16,
}, {
.fourcc = V4L2_PIX_FMT_BGR24,
.bpp = 24,
.yuv = false,
.lddfr = LDDFR_PKF_RGB24,
}, {
.fourcc = V4L2_PIX_FMT_BGR32,
.bpp = 32,
.yuv = false,
.lddfr = LDDFR_PKF_ARGB32,
}, {
.fourcc = V4L2_PIX_FMT_NV12,
.bpp = 12,
.yuv = true,
.lddfr = LDDFR_CC | LDDFR_YF_420,
}, {
.fourcc = V4L2_PIX_FMT_NV21,
.bpp = 12,
.yuv = true,
.lddfr = LDDFR_CC | LDDFR_YF_420,
}, {
.fourcc = V4L2_PIX_FMT_NV16,
.bpp = 16,
.yuv = true,
.lddfr = LDDFR_CC | LDDFR_YF_422,
}, {
.fourcc = V4L2_PIX_FMT_NV61,
.bpp = 16,
.yuv = true,
.lddfr = LDDFR_CC | LDDFR_YF_422,
}, {
.fourcc = V4L2_PIX_FMT_NV24,
.bpp = 24,
.yuv = true,
.lddfr = LDDFR_CC | LDDFR_YF_444,
}, {
.fourcc = V4L2_PIX_FMT_NV42,
.bpp = 24,
.yuv = true,
.lddfr = LDDFR_CC | LDDFR_YF_444,
},
};
static const struct sh_mobile_lcdc_format_info *
sh_mobile_format_info(u32 fourcc)
{
unsigned int i;
for (i = 0; i < ARRAY_SIZE(sh_mobile_format_infos); ++i) {
if (sh_mobile_format_infos[i].fourcc == fourcc)
return &sh_mobile_format_infos[i];
}
return NULL;
}
static int sh_mobile_format_fourcc(const struct fb_var_screeninfo *var) static int sh_mobile_format_fourcc(const struct fb_var_screeninfo *var)
{ {
if (var->grayscale > 1) if (var->grayscale > 1)
...@@ -473,21 +542,13 @@ static int sh_mobile_format_is_fourcc(const struct fb_var_screeninfo *var) ...@@ -473,21 +542,13 @@ static int sh_mobile_format_is_fourcc(const struct fb_var_screeninfo *var)
static bool sh_mobile_format_is_yuv(const struct fb_var_screeninfo *var) static bool sh_mobile_format_is_yuv(const struct fb_var_screeninfo *var)
{ {
const struct sh_mobile_lcdc_format_info *format;
if (var->grayscale <= 1) if (var->grayscale <= 1)
return false; return false;
switch (var->grayscale) { format = sh_mobile_format_info(var->grayscale);
case V4L2_PIX_FMT_NV12: return format ? format->yuv : false;
case V4L2_PIX_FMT_NV21:
case V4L2_PIX_FMT_NV16:
case V4L2_PIX_FMT_NV61:
case V4L2_PIX_FMT_NV24:
case V4L2_PIX_FMT_NV42:
return true;
default:
return false;
}
} }
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
...@@ -667,37 +728,20 @@ static void __sh_mobile_lcdc_start(struct sh_mobile_lcdc_priv *priv) ...@@ -667,37 +728,20 @@ static void __sh_mobile_lcdc_start(struct sh_mobile_lcdc_priv *priv)
/* Setup geometry, format, frame buffer memory and operation mode. */ /* Setup geometry, format, frame buffer memory and operation mode. */
for (k = 0; k < ARRAY_SIZE(priv->ch); k++) { for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
const struct sh_mobile_lcdc_format_info *format;
u32 fourcc;
ch = &priv->ch[k]; ch = &priv->ch[k];
if (!ch->enabled) if (!ch->enabled)
continue; continue;
sh_mobile_lcdc_geometry(ch); sh_mobile_lcdc_geometry(ch);
switch (sh_mobile_format_fourcc(&ch->info->var)) { fourcc = sh_mobile_format_fourcc(&ch->info->var);
case V4L2_PIX_FMT_RGB565: format = sh_mobile_format_info(fourcc);
tmp = LDDFR_PKF_RGB16; tmp = format->lddfr;
break;
case V4L2_PIX_FMT_BGR24:
tmp = LDDFR_PKF_RGB24;
break;
case V4L2_PIX_FMT_BGR32:
tmp = LDDFR_PKF_ARGB32;
break;
case V4L2_PIX_FMT_NV12:
case V4L2_PIX_FMT_NV21:
tmp = LDDFR_CC | LDDFR_YF_420;
break;
case V4L2_PIX_FMT_NV16:
case V4L2_PIX_FMT_NV61:
tmp = LDDFR_CC | LDDFR_YF_422;
break;
case V4L2_PIX_FMT_NV24:
case V4L2_PIX_FMT_NV42:
tmp = LDDFR_CC | LDDFR_YF_444;
break;
}
if (sh_mobile_format_is_yuv(&ch->info->var)) { if (format->yuv) {
switch (ch->info->var.colorspace) { switch (ch->info->var.colorspace) {
case V4L2_COLORSPACE_REC709: case V4L2_COLORSPACE_REC709:
tmp |= LDDFR_CF1; tmp |= LDDFR_CF1;
...@@ -711,7 +755,7 @@ static void __sh_mobile_lcdc_start(struct sh_mobile_lcdc_priv *priv) ...@@ -711,7 +755,7 @@ static void __sh_mobile_lcdc_start(struct sh_mobile_lcdc_priv *priv)
lcdc_write_chan(ch, LDDFR, tmp); lcdc_write_chan(ch, LDDFR, tmp);
lcdc_write_chan(ch, LDMLSR, ch->pitch); lcdc_write_chan(ch, LDMLSR, ch->pitch);
lcdc_write_chan(ch, LDSA1R, ch->base_addr_y); lcdc_write_chan(ch, LDSA1R, ch->base_addr_y);
if (sh_mobile_format_is_yuv(&ch->info->var)) if (format->yuv)
lcdc_write_chan(ch, LDSA2R, ch->base_addr_c); lcdc_write_chan(ch, LDSA2R, ch->base_addr_c);
/* When using deferred I/O mode, configure the LCDC for one-shot /* When using deferred I/O mode, configure the LCDC for one-shot
...@@ -1228,32 +1272,17 @@ static int sh_mobile_check_var(struct fb_var_screeninfo *var, struct fb_info *in ...@@ -1228,32 +1272,17 @@ static int sh_mobile_check_var(struct fb_var_screeninfo *var, struct fb_info *in
var->yres_virtual = var->yres; var->yres_virtual = var->yres;
if (sh_mobile_format_is_fourcc(var)) { if (sh_mobile_format_is_fourcc(var)) {
switch (var->grayscale) { const struct sh_mobile_lcdc_format_info *format;
case V4L2_PIX_FMT_NV12:
case V4L2_PIX_FMT_NV21: format = sh_mobile_format_info(var->grayscale);
var->bits_per_pixel = 12; if (format == NULL)
break;
case V4L2_PIX_FMT_RGB565:
case V4L2_PIX_FMT_NV16:
case V4L2_PIX_FMT_NV61:
var->bits_per_pixel = 16;
break;
case V4L2_PIX_FMT_BGR24:
case V4L2_PIX_FMT_NV24:
case V4L2_PIX_FMT_NV42:
var->bits_per_pixel = 24;
break;
case V4L2_PIX_FMT_BGR32:
var->bits_per_pixel = 32;
break;
default:
return -EINVAL; return -EINVAL;
} var->bits_per_pixel = format->bpp;
/* Default to RGB and JPEG color-spaces for RGB and YUV formats /* Default to RGB and JPEG color-spaces for RGB and YUV formats
* respectively. * respectively.
*/ */
if (!sh_mobile_format_is_yuv(var)) if (!format->yuv)
var->colorspace = V4L2_COLORSPACE_SRGB; var->colorspace = V4L2_COLORSPACE_SRGB;
else if (var->colorspace != V4L2_COLORSPACE_REC709) else if (var->colorspace != V4L2_COLORSPACE_REC709)
var->colorspace = V4L2_COLORSPACE_JPEG; var->colorspace = V4L2_COLORSPACE_JPEG;
...@@ -1665,6 +1694,7 @@ static int __devinit ...@@ -1665,6 +1694,7 @@ static int __devinit
sh_mobile_lcdc_channel_init(struct sh_mobile_lcdc_priv *priv, sh_mobile_lcdc_channel_init(struct sh_mobile_lcdc_priv *priv,
struct sh_mobile_lcdc_chan *ch) struct sh_mobile_lcdc_chan *ch)
{ {
const struct sh_mobile_lcdc_format_info *format;
struct sh_mobile_lcdc_chan_cfg *cfg = &ch->cfg; struct sh_mobile_lcdc_chan_cfg *cfg = &ch->cfg;
const struct fb_videomode *max_mode; const struct fb_videomode *max_mode;
const struct fb_videomode *mode; const struct fb_videomode *mode;
...@@ -1679,6 +1709,13 @@ sh_mobile_lcdc_channel_init(struct sh_mobile_lcdc_priv *priv, ...@@ -1679,6 +1709,13 @@ sh_mobile_lcdc_channel_init(struct sh_mobile_lcdc_priv *priv,
mutex_init(&ch->open_lock); mutex_init(&ch->open_lock);
ch->notify = sh_mobile_lcdc_display_notify; ch->notify = sh_mobile_lcdc_display_notify;
/* Validate the format. */
format = sh_mobile_format_info(cfg->fourcc);
if (format == NULL) {
dev_err(priv->dev, "Invalid FOURCC %08x.\n", cfg->fourcc);
return -EINVAL;
}
/* Allocate the frame buffer device. */ /* Allocate the frame buffer device. */
ch->info = framebuffer_alloc(0, priv->dev); ch->info = framebuffer_alloc(0, priv->dev);
if (!ch->info) { if (!ch->info) {
...@@ -1756,20 +1793,13 @@ sh_mobile_lcdc_channel_init(struct sh_mobile_lcdc_priv *priv, ...@@ -1756,20 +1793,13 @@ sh_mobile_lcdc_channel_init(struct sh_mobile_lcdc_priv *priv,
var->yres_virtual = var->yres * 2; var->yres_virtual = var->yres * 2;
var->activate = FB_ACTIVATE_NOW; var->activate = FB_ACTIVATE_NOW;
switch (cfg->fourcc) { /* Use the legacy API by default for RGB formats, and the FOURCC API
case V4L2_PIX_FMT_RGB565: * for YUV formats.
var->bits_per_pixel = 16; */
break; if (!format->yuv)
case V4L2_PIX_FMT_BGR24: var->bits_per_pixel = format->bpp;
var->bits_per_pixel = 24; else
break;
case V4L2_PIX_FMT_BGR32:
var->bits_per_pixel = 32;
break;
default:
var->grayscale = cfg->fourcc; var->grayscale = cfg->fourcc;
break;
}
/* Make sure the memory size check won't fail. smem_len is initialized /* Make sure the memory size check won't fail. smem_len is initialized
* later based on var. * later based on var.
...@@ -1806,7 +1836,7 @@ sh_mobile_lcdc_channel_init(struct sh_mobile_lcdc_priv *priv, ...@@ -1806,7 +1836,7 @@ sh_mobile_lcdc_channel_init(struct sh_mobile_lcdc_priv *priv,
cfg->fourcc == V4L2_PIX_FMT_NV21) cfg->fourcc == V4L2_PIX_FMT_NV21)
info->fix.ypanstep = 2; info->fix.ypanstep = 2;
if (sh_mobile_format_is_yuv(var)) { if (format->yuv) {
info->fix.line_length = var->xres; info->fix.line_length = var->xres;
info->fix.visual = FB_VISUAL_FOURCC; info->fix.visual = FB_VISUAL_FOURCC;
} else { } else {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment