in drivers/video/fb.c [747:1323]
static int fb_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
{
FAR struct inode *inode;
FAR struct fb_chardev_s *fb;
int ret = OK;
ginfo("cmd: %d arg: %ld\n", cmd, arg);
/* Get the framebuffer instance */
inode = filep->f_inode;
fb = inode->i_private;
/* Process the IOCTL command */
switch (cmd)
{
case FBIOGET_VIDEOINFO: /* Get color plane info */
{
FAR struct fb_videoinfo_s *vinfo =
(FAR struct fb_videoinfo_s *)((uintptr_t)arg);
DEBUGASSERT(vinfo != NULL && fb->vtable != NULL);
if (fb->vtable->getvideoinfo == NULL)
{
ret = -ENOTTY;
break;
}
ret = fb->vtable->getvideoinfo(fb->vtable, vinfo);
}
break;
case FBIOGET_PLANEINFO: /* Get video plane info */
{
FAR struct fb_planeinfo_s *pinfo =
(FAR struct fb_planeinfo_s *)((uintptr_t)arg);
DEBUGASSERT(pinfo != NULL);
ret = fb_get_planeinfo(fb, pinfo, pinfo->display);
}
break;
#ifdef CONFIG_FB_CMAP
case FBIOGET_CMAP: /* Get RGB color mapping */
{
FAR struct fb_cmap_s *cmap =
(FAR struct fb_cmap_s *)((uintptr_t)arg);
DEBUGASSERT(cmap != NULL && fb->vtable != NULL);
if (fb->vtable->getcmap == NULL)
{
ret = -ENOTTY;
break;
}
ret = fb->vtable->getcmap(fb->vtable, cmap);
}
break;
case FBIOPUT_CMAP: /* Put RGB color mapping */
{
FAR const struct fb_cmap_s *cmap =
(FAR struct fb_cmap_s *)((uintptr_t)arg);
DEBUGASSERT(cmap != NULL && fb->vtable != NULL);
if (fb->vtable->putcmap == NULL)
{
ret = -ENOTTY;
break;
}
ret = fb->vtable->putcmap(fb->vtable, cmap);
}
break;
#endif
#ifdef CONFIG_FB_HWCURSOR
case FBIOGET_CURSOR: /* Get cursor attributes */
{
FAR struct fb_cursorattrib_s *attrib =
(FAR struct fb_cursorattrib_s *)((uintptr_t)arg);
DEBUGASSERT(attrib != NULL && fb->vtable != NULL);
if (fb->vtable->getcursor == NULL)
{
ret = -ENOTTY;
}
ret = fb->vtable->getcursor(fb->vtable, attrib);
}
break;
case FBIOPUT_CURSOR: /* Set cursor attributes */
{
FAR struct fb_setcursor_s *cursor =
(FAR struct fb_setcursor_s *)((uintptr_t)arg);
DEBUGASSERT(cursor != NULL && fb->vtable != NULL);
if (fb->vtable->setcursor == NULL)
{
ret = -ENOTTY;
break;
}
ret = fb->vtable->setcursor(fb->vtable, cursor);
}
break;
#endif
#ifdef CONFIG_FB_UPDATE
case FBIO_UPDATE: /* Update the modified framebuffer data */
{
struct fb_area_s *area = (FAR struct fb_area_s *)((uintptr_t)arg);
DEBUGASSERT(fb->vtable != NULL);
if (fb->vtable->updatearea == NULL)
{
ret = -ENOTTY;
break;
}
ret = fb->vtable->updatearea(fb->vtable, area);
}
break;
#endif
#ifdef CONFIG_FB_SYNC
case FBIO_WAITFORVSYNC: /* Wait upon vertical sync */
{
FAR struct fb_priv_s *priv = (FAR struct fb_priv_s *)filep->f_priv;
DEBUGASSERT(fb->vtable != NULL);
if (fb->vtable->waitforvsync != NULL)
{
ret = fb->vtable->waitforvsync(fb->vtable);
break;
}
ret = fb_sem_wait(fb, priv, priv->overlay);
}
break;
#endif
#ifdef CONFIG_FB_OVERLAY
case FBIO_SELECT_OVERLAY: /* Select video overlay */
{
struct fb_overlayinfo_s oinfo;
FAR struct fb_priv_s *priv = filep->f_priv;
DEBUGASSERT(priv != NULL && fb->vtable != NULL);
if (fb->vtable->getoverlayinfo == NULL)
{
ret = -ENOTTY;
break;
}
if (arg != FB_NO_OVERLAY)
{
memset(&oinfo, 0, sizeof(oinfo));
ret = fb->vtable->getoverlayinfo(fb->vtable, arg, &oinfo);
}
if (ret >= 0)
{
priv->overlay = arg;
}
}
break;
case FBIOGET_OVERLAYINFO: /* Get video overlay info */
{
FAR struct fb_overlayinfo_s *oinfo =
(FAR struct fb_overlayinfo_s *)((uintptr_t)arg);
DEBUGASSERT(oinfo != NULL && fb->vtable != NULL);
if (fb->vtable->getoverlayinfo == NULL)
{
ret = -ENOTTY;
break;
}
ret = fb->vtable->getoverlayinfo(fb->vtable,
oinfo->overlay, oinfo);
}
break;
case FBIOSET_TRANSP: /* Set video overlay transparency */
{
FAR struct fb_overlayinfo_s *oinfo =
(FAR struct fb_overlayinfo_s *)((uintptr_t)arg);
DEBUGASSERT(oinfo != NULL && fb->vtable != NULL);
if (fb->vtable->settransp == NULL)
{
ret = -ENOTTY;
break;
}
ret = fb->vtable->settransp(fb->vtable, oinfo);
}
break;
case FBIOSET_CHROMAKEY: /* Set video overlay chroma key */
{
FAR struct fb_overlayinfo_s *oinfo =
(FAR struct fb_overlayinfo_s *)((uintptr_t)arg);
DEBUGASSERT(oinfo != NULL && fb->vtable != NULL);
if (fb->vtable->setchromakey == NULL)
{
ret = -ENOTTY;
break;
}
ret = fb->vtable->setchromakey(fb->vtable, oinfo);
}
break;
case FBIOSET_COLOR: /* Set video overlay color */
{
FAR struct fb_overlayinfo_s *oinfo =
(FAR struct fb_overlayinfo_s *)((uintptr_t)arg);
DEBUGASSERT(oinfo != NULL && fb->vtable != NULL);
if (fb->vtable->setcolor == NULL)
{
ret = -ENOTTY;
break;
}
ret = fb->vtable->setcolor(fb->vtable, oinfo);
}
break;
case FBIOSET_BLANK: /* Blank or unblank video overlay */
{
FAR struct fb_overlayinfo_s *oinfo =
(FAR struct fb_overlayinfo_s *)((uintptr_t)arg);
DEBUGASSERT(oinfo != NULL && fb->vtable != NULL);
if (fb->vtable->setblank == NULL)
{
ret = -ENOTTY;
break;
}
ret = fb->vtable->setblank(fb->vtable, oinfo);
}
break;
case FBIOSET_AREA: /* Set active video overlay area */
{
FAR struct fb_overlayinfo_s *oinfo =
(FAR struct fb_overlayinfo_s *)((uintptr_t)arg);
DEBUGASSERT(oinfo != NULL && fb->vtable != NULL);
if (fb->vtable->setarea == NULL)
{
ret = -ENOTTY;
break;
}
ret = fb->vtable->setarea(fb->vtable, oinfo);
}
break;
case FBIOSET_DESTAREA: /* Set destination area on the primary FB */
{
FAR struct fb_overlayinfo_s *oinfo =
(FAR struct fb_overlayinfo_s *)((uintptr_t)arg);
DEBUGASSERT(oinfo != NULL && fb->vtable != NULL);
if (fb->vtable->setdestarea == NULL)
{
ret = -ENOTTY;
break;
}
ret = fb->vtable->setdestarea(fb->vtable, oinfo);
}
break;
#ifdef CONFIG_FB_OVERLAY_BLIT
case FBIOSET_BLIT: /* Blit operation between video overlays */
{
FAR struct fb_overlayblit_s *blit =
(FAR struct fb_overlayblit_s *)((uintptr_t)arg);
DEBUGASSERT(blit != NULL && fb->vtable != NULL);
if (fb->vtable->blit == NULL)
{
ret = -ENOTTY;
break;
}
ret = fb->vtable->blit(fb->vtable, blit);
}
break;
case FBIOSET_BLEND: /* Blend operation between video overlays */
{
FAR struct fb_overlayblend_s *blend =
(FAR struct fb_overlayblend_s *)((uintptr_t)arg);
DEBUGASSERT(blend != NULL && fb->vtable != NULL);
if (fb->vtable->blend == NULL)
{
ret = -ENOTTY;
break;
}
ret = fb->vtable->blend(fb->vtable, blend);
}
break;
#endif
case FBIOPAN_OVERLAY:
{
FAR struct fb_overlayinfo_s *oinfo =
(FAR struct fb_overlayinfo_s *)((uintptr_t)arg);
union fb_paninfo_u paninfo;
DEBUGASSERT(oinfo != NULL && fb->vtable != NULL);
memcpy(&paninfo, oinfo, sizeof(*oinfo));
if (fb->vtable->panoverlay != NULL)
{
fb->vtable->panoverlay(fb->vtable, oinfo);
}
ret = fb_add_paninfo(fb, &paninfo, oinfo->overlay);
}
break;
#endif /* CONFIG_FB_OVERLAY */
case FBIOSET_POWER:
{
DEBUGASSERT(fb->vtable != NULL);
if (fb->vtable->setpower == NULL)
{
ret = -ENOTTY;
break;
}
ret = fb->vtable->setpower(fb->vtable, (int)arg);
}
break;
case FBIOGET_POWER:
{
FAR int *power = (FAR int *)((uintptr_t)arg);
DEBUGASSERT(power != NULL && fb->vtable != NULL);
if (fb->vtable->getpower == NULL)
{
ret = -ENOTTY;
break;
}
*power = fb->vtable->getpower(fb->vtable);
}
break;
case FBIOGET_FRAMERATE:
{
FAR int *rate = (FAR int *)((uintptr_t)arg);
DEBUGASSERT(rate != NULL && fb->vtable != NULL);
if (fb->vtable->getframerate == NULL)
{
ret = -ENOTTY;
break;
}
*rate = fb->vtable->getframerate(fb->vtable);
}
break;
case FBIOSET_FRAMERATE:
{
DEBUGASSERT(fb->vtable != NULL &&
fb->vtable->setframerate != NULL);
ret = fb->vtable->setframerate(fb->vtable, (int)arg);
}
break;
case FBIOPAN_DISPLAY:
{
FAR struct fb_planeinfo_s *pinfo =
(FAR struct fb_planeinfo_s *)((uintptr_t)arg);
union fb_paninfo_u paninfo;
DEBUGASSERT(pinfo != NULL && fb->vtable != NULL);
memcpy(&paninfo, pinfo, sizeof(*pinfo));
if (fb->vtable->pandisplay != NULL)
{
ret = fb->vtable->pandisplay(fb->vtable, pinfo);
if (ret < 0)
{
break;
}
}
ret = fb_add_paninfo(fb, &paninfo, FB_NO_OVERLAY);
}
break;
case FBIOPAN_CLEAR:
{
ret = fb_clear_paninfo(fb, (int)arg);
}
break;
case FBIOSET_VSYNCOFFSET:
{
fb->vsyncoffset = USEC2TICK(arg);
}
break;
case FBIOGET_VSCREENINFO:
{
struct fb_videoinfo_s vinfo;
struct fb_planeinfo_s pinfo;
FAR struct fb_var_screeninfo *varinfo =
(FAR struct fb_var_screeninfo *)((uintptr_t)arg);
DEBUGASSERT(varinfo != NULL && fb->vtable != NULL);
if (fb->vtable->getvideoinfo == NULL)
{
ret = -ENOTTY;
break;
}
ret = fb->vtable->getvideoinfo(fb->vtable, &vinfo);
if (ret < 0)
{
break;
}
ret = fb_get_planeinfo(fb, &pinfo, 0);
if (ret < 0)
{
break;
}
memset(varinfo, 0, sizeof(struct fb_var_screeninfo));
varinfo->xres = vinfo.xres;
varinfo->yres = vinfo.yres;
varinfo->xres_virtual = pinfo.xres_virtual;
varinfo->yres_virtual = pinfo.yres_virtual;
varinfo->xoffset = pinfo.xoffset;
varinfo->yoffset = pinfo.yoffset;
varinfo->bits_per_pixel = pinfo.bpp;
varinfo->grayscale = FB_ISMONO(vinfo.fmt);
switch (vinfo.fmt)
{
case FB_FMT_Y1:
varinfo->red.offset = 0;
varinfo->green.offset = 0;
varinfo->blue.offset = 0;
varinfo->red.length = 1;
varinfo->green.length = 1;
varinfo->blue.length = 1;
break;
case FB_FMT_Y8:
varinfo->red.offset = 0;
varinfo->green.offset = 0;
varinfo->blue.offset = 0;
varinfo->red.length = 8;
varinfo->green.length = 8;
varinfo->blue.length = 8;
break;
case FB_FMT_RGB16_555:
varinfo->red.offset = 10;
varinfo->green.offset = 5;
varinfo->blue.offset = 0;
varinfo->red.length = 5;
varinfo->green.length = 5;
varinfo->blue.length = 5;
break;
case FB_FMT_RGB16_565:
varinfo->red.offset = 11;
varinfo->green.offset = 5;
varinfo->blue.offset = 0;
varinfo->red.length = 5;
varinfo->green.length = 6;
varinfo->blue.length = 5;
break;
case FB_FMT_RGB24:
case FB_FMT_RGB32:
varinfo->red.offset = 16;
varinfo->green.offset = 8;
varinfo->blue.offset = 0;
varinfo->red.length = 8;
varinfo->green.length = 8;
varinfo->blue.length = 8;
break;
case FB_FMT_RGBA32:
varinfo->red.offset = 16;
varinfo->green.offset = 8;
varinfo->blue.offset = 0;
varinfo->transp.offset = 24;
varinfo->red.length = 8;
varinfo->green.length = 8;
varinfo->blue.length = 8;
varinfo->transp.length = 8;
break;
}
}
break;
case FBIOGET_FSCREENINFO:
{
struct fb_videoinfo_s vinfo;
struct fb_planeinfo_s pinfo;
FAR struct fb_fix_screeninfo *fixinfo =
(FAR struct fb_fix_screeninfo *)((uintptr_t)arg);
DEBUGASSERT(fixinfo != NULL && fb->vtable != NULL);
if (fb->vtable->getvideoinfo == NULL)
{
ret = -ENOTTY;
break;
}
ret = fb->vtable->getvideoinfo(fb->vtable, &vinfo);
if (ret < 0)
{
break;
}
ret = fb_get_planeinfo(fb, &pinfo, 0);
if (ret < 0)
{
break;
}
memset(fixinfo, 0, sizeof(struct fb_fix_screeninfo));
#ifdef CONFIG_FB_MODULEINFO
strlcpy(fixinfo->id, (FAR const char *)vinfo.moduleinfo,
sizeof(fixinfo->id));
#endif
fixinfo->smem_start = (unsigned long)pinfo.fbmem;
fixinfo->smem_len = pinfo.fblen;
fixinfo->type = FB_ISYUVPLANAR(vinfo.fmt) ?
FB_TYPE_INTERLEAVED_PLANES :
FB_TYPE_PACKED_PIXELS;
fixinfo->visual = FB_ISMONO(vinfo.fmt) ?
FB_VISUAL_MONO10 : FB_VISUAL_TRUECOLOR;
fixinfo->line_length = pinfo.stride;
}
break;
default:
if (fb->vtable->ioctl != NULL)
{
ret = fb->vtable->ioctl(fb->vtable, cmd, arg);
}
else
{
gerr("ERROR: Unsupported IOCTL command: %d\n", cmd);
ret = -ENOTTY;
}
break;
}
return ret;
}