video/fb: Add fb_register_device

so the user could register fb device directly instead
go through the sequence of up_fbinitialize/up_fbgetvplane

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
Xiang Xiao 2023-10-09 01:14:32 +08:00 committed by Petro Karashchenko
parent 4f8a2b3874
commit 28dee592a3
2 changed files with 85 additions and 24 deletions

View File

@ -1386,7 +1386,7 @@ int fb_paninfo_count(FAR struct fb_vtable_s *vtable, int overlay)
}
/****************************************************************************
* Name: fb_register
* Name: fb_register_device
*
* Description:
* Register the framebuffer character device at /dev/fbN where N is the
@ -1401,6 +1401,7 @@ int fb_paninfo_count(FAR struct fb_vtable_s *vtable, int overlay)
* layers (each layer is consider a display). Typically zero.
* plane - Identifies the color plane on hardware that supports separate
* framebuffer "planes" for each color component.
* vtable - Pointer to framebuffer's virtual table.
*
* Returned Value:
* Zero (OK) is returned success; a negated errno value is returned on any
@ -1408,7 +1409,8 @@ int fb_paninfo_count(FAR struct fb_vtable_s *vtable, int overlay)
*
****************************************************************************/
int fb_register(int display, int plane)
int fb_register_device(int display, int plane,
FAR struct fb_vtable_s *vtable)
{
FAR struct fb_chardev_s *fb;
struct fb_panelinfo_s panelinfo;
@ -1426,30 +1428,15 @@ int fb_register(int display, int plane)
return -ENOMEM;
}
/* Initialize the frame buffer device. */
ret = up_fbinitialize(display);
if (ret < 0)
{
gerr("ERROR: up_fbinitialize() failed for display %d: %d\n",
display, ret);
goto errout_with_fb;
}
DEBUGASSERT((unsigned)plane <= UINT8_MAX);
DEBUGASSERT(vtable != NULL);
fb->plane = plane;
fb->vtable = up_fbgetvplane(display, plane);
if (fb->vtable == NULL)
{
gerr("ERROR: up_fbgetvplane() failed, vplane=%d\n", plane);
goto errout_with_fb;
}
fb->vtable = vtable;
/* Initialize the frame buffer instance. */
DEBUGASSERT(fb->vtable->getvideoinfo != NULL);
ret = fb->vtable->getvideoinfo(fb->vtable, &vinfo);
DEBUGASSERT(vtable->getvideoinfo != NULL);
ret = vtable->getvideoinfo(vtable, &vinfo);
if (ret < 0)
{
gerr("ERROR: getvideoinfo() failed: %d\n", ret);
@ -1505,15 +1492,14 @@ int fb_register(int display, int plane)
nxmutex_init(&fb->lock);
ret = register_driver(devname, &g_fb_fops, 0666, (FAR void *)fb);
ret = register_driver(devname, &g_fb_fops, 0666, fb);
if (ret < 0)
{
gerr("ERROR: register_driver() failed: %d\n", ret);
goto errout_with_nxmutex;
}
fb->vtable->priv = fb;
vtable->priv = fb;
return OK;
errout_with_nxmutex:
@ -1529,3 +1515,51 @@ errout_with_fb:
kmm_free(fb);
return ret;
}
/****************************************************************************
* Name: fb_register
*
* Description:
* Register the framebuffer character device at /dev/fbN where N is the
* display number if the devices supports only a single plane. If the
* hardware supports multiple color planes, then the device will be
* registered at /dev/fbN.M where N is the again display number but M
* is the display plane.
*
* Input Parameters:
* display - The display number for the case of boards supporting multiple
* displays or for hardware that supports multiple
* layers (each layer is consider a display). Typically zero.
* plane - Identifies the color plane on hardware that supports separate
* framebuffer "planes" for each color component.
*
* Returned Value:
* Zero (OK) is returned success; a negated errno value is returned on any
* failure.
*
****************************************************************************/
int fb_register(int display, int plane)
{
FAR struct fb_vtable_s *vtable;
int ret;
/* Initialize the frame buffer device. */
ret = up_fbinitialize(display);
if (ret < 0)
{
gerr("ERROR: up_fbinitialize() failed for display %d: %d\n",
display, ret);
return ret;
}
vtable = up_fbgetvplane(display, plane);
if (vtable == NULL)
{
gerr("ERROR: up_fbgetvplane() failed, vplane=%d\n", plane);
return -EINVAL;
}
return fb_register_device(display, plane, vtable);
}

View File

@ -1056,6 +1056,33 @@ int fb_remove_paninfo(FAR struct fb_vtable_s *vtable, int overlay);
int fb_paninfo_count(FAR struct fb_vtable_s *vtable, int overlay);
/****************************************************************************
* Name: fb_register_device
*
* Description:
* Register the framebuffer character device at /dev/fbN where N is the
* display number if the devices supports only a single plane. If the
* hardware supports multiple color planes, then the device will be
* registered at /dev/fbN.M where N is the again display number but M
* is the display plane.
*
* Input Parameters:
* display - The display number for the case of boards supporting multiple
* displays or for hardware that supports multiple
* layers (each layer is consider a display). Typically zero.
* plane - Identifies the color plane on hardware that supports separate
* framebuffer "planes" for each color component.
* vtable - Pointer to framebuffer's virtual table.
*
* Returned Value:
* Zero (OK) is returned success; a negated errno value is returned on any
* failure.
*
****************************************************************************/
int fb_register_device(int display, int plane,
FAR struct fb_vtable_s *vtable);
/****************************************************************************
* Name: fb_register
*