From 28dee592a326ae9919b17f5e8685df9c6254f440 Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Mon, 9 Oct 2023 01:14:32 +0800 Subject: [PATCH] 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 --- drivers/video/fb.c | 82 ++++++++++++++++++++++++++++------------ include/nuttx/video/fb.h | 27 +++++++++++++ 2 files changed, 85 insertions(+), 24 deletions(-) diff --git a/drivers/video/fb.c b/drivers/video/fb.c index 97515eb00b..63930a5174 100644 --- a/drivers/video/fb.c +++ b/drivers/video/fb.c @@ -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); +} diff --git a/include/nuttx/video/fb.h b/include/nuttx/video/fb.h index f597f502e6..f247f73752 100644 --- a/include/nuttx/video/fb.h +++ b/include/nuttx/video/fb.h @@ -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 *