Commit 9e69bcd8 authored by Thomas Zimmermann's avatar Thomas Zimmermann Committed by Tomi Valkeinen

drm/omapdrm: Implement fbdev emulation as in-kernel client

Move code from ad-hoc fbdev callbacks into DRM client functions
and remove the old callbacks. The functions instruct the client
to poll for changed output or restore the display. The DRM core
calls both, the old callbacks and the new client helpers, from
the same places. The new functions perform the same operation as
before, so there's no change in functionality.

Replace all code that initializes or releases fbdev emulation
throughout the driver. Instead initialize the fbdev client by a
single call to omapdrm_fbdev_setup() after omapdrm has registered
its DRM device. As in most drivers, omapdrm's fbdev emulation now
acts like a regular DRM client.

The fbdev client setup consists of the initial preparation and the
hot-plugging of the display. The latter creates the fbdev device
and sets up the fbdev framebuffer. The setup performs display
hot-plugging once. If no display can be detected, DRM probe helpers
re-run the detection on each hotplug event.

A call to drm_dev_unregister() releases the client automatically.
No further action is required within omapdrm. If the fbdev
framebuffer has been fully set up, struct fb_ops.fb_destroy
implements the release. For partially initialized emulation, the
fbdev client reverts the initial setup.

v2:
	* init drm_client in this patch (Tomi)
	* don't handle non-atomic modesetting (Tomi)
Signed-off-by: default avatarThomas Zimmermann <tzimmermann@suse.de>
Reviewed-by: default avatarTomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Reviewed-by: default avatarEmil Velikov <emil.l.velikov@gmail.com>
Signed-off-by: default avatarTomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20230403104035.15288-6-tzimmermann@suse.de
parent 8e3aac3b
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
#include <drm/drm_bridge.h> #include <drm/drm_bridge.h>
#include <drm/drm_bridge_connector.h> #include <drm/drm_bridge_connector.h>
#include <drm/drm_drv.h> #include <drm/drm_drv.h>
#include <drm/drm_fb_helper.h>
#include <drm/drm_file.h> #include <drm/drm_file.h>
#include <drm/drm_ioctl.h> #include <drm/drm_ioctl.h>
#include <drm/drm_panel.h> #include <drm/drm_panel.h>
...@@ -221,7 +220,6 @@ static const struct drm_mode_config_helper_funcs omap_mode_config_helper_funcs = ...@@ -221,7 +220,6 @@ static const struct drm_mode_config_helper_funcs omap_mode_config_helper_funcs =
static const struct drm_mode_config_funcs omap_mode_config_funcs = { static const struct drm_mode_config_funcs omap_mode_config_funcs = {
.fb_create = omap_framebuffer_create, .fb_create = omap_framebuffer_create,
.output_poll_changed = drm_fb_helper_output_poll_changed,
.atomic_check = omap_atomic_check, .atomic_check = omap_atomic_check,
.atomic_commit = drm_atomic_helper_commit, .atomic_commit = drm_atomic_helper_commit,
}; };
...@@ -654,7 +652,6 @@ static const struct drm_driver omap_drm_driver = { ...@@ -654,7 +652,6 @@ static const struct drm_driver omap_drm_driver = {
.driver_features = DRIVER_MODESET | DRIVER_GEM | .driver_features = DRIVER_MODESET | DRIVER_GEM |
DRIVER_ATOMIC | DRIVER_RENDER, DRIVER_ATOMIC | DRIVER_RENDER,
.open = dev_open, .open = dev_open,
.lastclose = drm_fb_helper_lastclose,
#ifdef CONFIG_DEBUG_FS #ifdef CONFIG_DEBUG_FS
.debugfs_init = omap_debugfs_init, .debugfs_init = omap_debugfs_init,
#endif #endif
...@@ -743,8 +740,6 @@ static int omapdrm_init(struct omap_drm_private *priv, struct device *dev) ...@@ -743,8 +740,6 @@ static int omapdrm_init(struct omap_drm_private *priv, struct device *dev)
goto err_cleanup_modeset; goto err_cleanup_modeset;
} }
omap_fbdev_init(ddev);
drm_kms_helper_poll_init(ddev); drm_kms_helper_poll_init(ddev);
/* /*
...@@ -755,12 +750,12 @@ static int omapdrm_init(struct omap_drm_private *priv, struct device *dev) ...@@ -755,12 +750,12 @@ static int omapdrm_init(struct omap_drm_private *priv, struct device *dev)
if (ret) if (ret)
goto err_cleanup_helpers; goto err_cleanup_helpers;
omap_fbdev_setup(ddev);
return 0; return 0;
err_cleanup_helpers: err_cleanup_helpers:
drm_kms_helper_poll_fini(ddev); drm_kms_helper_poll_fini(ddev);
omap_fbdev_fini(ddev);
err_cleanup_modeset: err_cleanup_modeset:
omap_modeset_fini(ddev); omap_modeset_fini(ddev);
err_free_overlays: err_free_overlays:
...@@ -786,8 +781,6 @@ static void omapdrm_cleanup(struct omap_drm_private *priv) ...@@ -786,8 +781,6 @@ static void omapdrm_cleanup(struct omap_drm_private *priv)
drm_kms_helper_poll_fini(ddev); drm_kms_helper_poll_fini(ddev);
omap_fbdev_fini(ddev);
drm_atomic_helper_shutdown(ddev); drm_atomic_helper_shutdown(ddev);
omap_modeset_fini(ddev); omap_modeset_fini(ddev);
......
...@@ -4,13 +4,14 @@ ...@@ -4,13 +4,14 @@
* Author: Rob Clark <rob@ti.com> * Author: Rob Clark <rob@ti.com>
*/ */
#include <drm/drm_crtc.h> #include <drm/drm_drv.h>
#include <drm/drm_util.h> #include <drm/drm_crtc_helper.h>
#include <drm/drm_fb_helper.h> #include <drm/drm_fb_helper.h>
#include <drm/drm_file.h> #include <drm/drm_file.h>
#include <drm/drm_fourcc.h> #include <drm/drm_fourcc.h>
#include <drm/drm_framebuffer.h> #include <drm/drm_framebuffer.h>
#include <drm/drm_gem_framebuffer_helper.h> #include <drm/drm_gem_framebuffer_helper.h>
#include <drm/drm_util.h>
#include "omap_drv.h" #include "omap_drv.h"
#include "omap_fbdev.h" #include "omap_fbdev.h"
...@@ -73,6 +74,25 @@ static int omap_fbdev_pan_display(struct fb_var_screeninfo *var, ...@@ -73,6 +74,25 @@ static int omap_fbdev_pan_display(struct fb_var_screeninfo *var,
return drm_fb_helper_pan_display(var, fbi); return drm_fb_helper_pan_display(var, fbi);
} }
static void omap_fbdev_fb_destroy(struct fb_info *info)
{
struct drm_fb_helper *helper = info->par;
struct drm_framebuffer *fb = helper->fb;
struct drm_gem_object *bo = drm_gem_fb_get_obj(fb, 0);
struct omap_fbdev *fbdev = to_omap_fbdev(helper);
DBG();
drm_fb_helper_fini(helper);
omap_gem_unpin(bo);
drm_framebuffer_remove(fb);
drm_client_release(&helper->client);
drm_fb_helper_unprepare(helper);
kfree(fbdev);
}
static const struct fb_ops omap_fb_ops = { static const struct fb_ops omap_fb_ops = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
...@@ -88,6 +108,8 @@ static const struct fb_ops omap_fb_ops = { ...@@ -88,6 +108,8 @@ static const struct fb_ops omap_fb_ops = {
.fb_fillrect = drm_fb_helper_sys_fillrect, .fb_fillrect = drm_fb_helper_sys_fillrect,
.fb_copyarea = drm_fb_helper_sys_copyarea, .fb_copyarea = drm_fb_helper_sys_copyarea,
.fb_imageblit = drm_fb_helper_sys_imageblit, .fb_imageblit = drm_fb_helper_sys_imageblit,
.fb_destroy = omap_fbdev_fb_destroy,
}; };
static int omap_fbdev_create(struct drm_fb_helper *helper, static int omap_fbdev_create(struct drm_fb_helper *helper,
...@@ -222,76 +244,94 @@ static struct drm_fb_helper *get_fb(struct fb_info *fbi) ...@@ -222,76 +244,94 @@ static struct drm_fb_helper *get_fb(struct fb_info *fbi)
return fbi->par; return fbi->par;
} }
/* initialize fbdev helper */ /*
void omap_fbdev_init(struct drm_device *dev) * struct drm_client
*/
static void omap_fbdev_client_unregister(struct drm_client_dev *client)
{ {
struct omap_drm_private *priv = dev->dev_private; struct drm_fb_helper *fb_helper = drm_fb_helper_from_client(client);
struct omap_fbdev *fbdev = NULL;
struct drm_fb_helper *helper;
int ret = 0;
if (!priv->num_pipes) if (fb_helper->info) {
return; drm_fb_helper_unregister_info(fb_helper);
} else {
drm_client_release(&fb_helper->client);
drm_fb_helper_unprepare(fb_helper);
kfree(fb_helper);
}
}
fbdev = kzalloc(sizeof(*fbdev), GFP_KERNEL); static int omap_fbdev_client_restore(struct drm_client_dev *client)
if (!fbdev) {
return; drm_fb_helper_lastclose(client->dev);
INIT_WORK(&fbdev->work, pan_worker); return 0;
}
helper = &fbdev->base; static int omap_fbdev_client_hotplug(struct drm_client_dev *client)
{
struct drm_fb_helper *fb_helper = drm_fb_helper_from_client(client);
struct drm_device *dev = client->dev;
int ret;
drm_fb_helper_prepare(dev, helper, 32, &omap_fb_helper_funcs); if (dev->fb_helper)
return drm_fb_helper_hotplug_event(dev->fb_helper);
ret = drm_fb_helper_init(dev, helper); ret = drm_fb_helper_init(dev, fb_helper);
if (ret) if (ret)
goto fail; goto err_drm_err;
ret = drm_fb_helper_initial_config(helper); ret = drm_fb_helper_initial_config(fb_helper);
if (ret) if (ret)
goto fini; goto err_drm_fb_helper_fini;
return;
fini: return 0;
drm_fb_helper_fini(helper);
fail:
drm_fb_helper_unprepare(helper);
kfree(fbdev);
dev_warn(dev->dev, "omap_fbdev_init failed\n"); err_drm_fb_helper_fini:
drm_fb_helper_fini(fb_helper);
err_drm_err:
drm_err(dev, "Failed to setup fbdev emulation (ret=%d)\n", ret);
return ret;
} }
void omap_fbdev_fini(struct drm_device *dev) static const struct drm_client_funcs omap_fbdev_client_funcs = {
.owner = THIS_MODULE,
.unregister = omap_fbdev_client_unregister,
.restore = omap_fbdev_client_restore,
.hotplug = omap_fbdev_client_hotplug,
};
void omap_fbdev_setup(struct drm_device *dev)
{ {
struct drm_fb_helper *helper = dev->fb_helper;
struct drm_framebuffer *fb;
struct drm_gem_object *bo;
struct omap_fbdev *fbdev; struct omap_fbdev *fbdev;
struct drm_fb_helper *helper;
int ret;
DBG(); drm_WARN(dev, !dev->registered, "Device has not been registered.\n");
drm_WARN(dev, dev->fb_helper, "fb_helper is already set!\n");
if (!helper) fbdev = kzalloc(sizeof(*fbdev), GFP_KERNEL);
if (!fbdev)
return; return;
helper = &fbdev->base;
fb = helper->fb; drm_fb_helper_prepare(dev, helper, 32, &omap_fb_helper_funcs);
drm_fb_helper_unregister_info(helper);
drm_fb_helper_fini(helper); ret = drm_client_init(dev, &helper->client, "fbdev", &omap_fbdev_client_funcs);
if (ret)
goto err_drm_client_init;
fbdev = to_omap_fbdev(helper); INIT_WORK(&fbdev->work, pan_worker);
bo = drm_gem_fb_get_obj(fb, 0); ret = omap_fbdev_client_hotplug(&helper->client);
if (ret)
drm_dbg_kms(dev, "client hotplug ret=%d\n", ret);
/* unpin the GEM object pinned in omap_fbdev_create() */ drm_client_register(&helper->client);
if (bo)
omap_gem_unpin(bo);
/* this will free the backing object */ return;
if (fb)
drm_framebuffer_remove(fb);
err_drm_client_init:
drm_fb_helper_unprepare(helper); drm_fb_helper_unprepare(helper);
kfree(fbdev); kfree(fbdev);
} }
...@@ -10,16 +10,11 @@ ...@@ -10,16 +10,11 @@
#define __OMAPDRM_FBDEV_H__ #define __OMAPDRM_FBDEV_H__
struct drm_device; struct drm_device;
struct drm_fb_helper;
#ifdef CONFIG_DRM_FBDEV_EMULATION #ifdef CONFIG_DRM_FBDEV_EMULATION
void omap_fbdev_init(struct drm_device *dev); void omap_fbdev_setup(struct drm_device *dev);
void omap_fbdev_fini(struct drm_device *dev);
#else #else
static inline void omap_fbdev_init(struct drm_device *dev) static inline void omap_fbdev_setup(struct drm_device *dev)
{
}
static inline void omap_fbdev_fini(struct drm_device *dev)
{ {
} }
#endif #endif
......
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