Linux Audio

Check our new training course

Loading...
v6.13.7
  1// SPDX-License-Identifier: GPL-2.0-only
  2/*
  3 * Copyright (C) 2012 Russell King
  4 *  Written from the i915 driver.
  5 */
  6
  7#include <linux/errno.h>
  8#include <linux/fb.h>
  9#include <linux/kernel.h>
 10#include <linux/module.h>
 11
 12#include <drm/drm_crtc_helper.h>
 13#include <drm/drm_drv.h>
 14#include <drm/drm_fb_helper.h>
 15#include <drm/drm_fourcc.h>
 16
 17#include "armada_crtc.h"
 18#include "armada_drm.h"
 19#include "armada_fb.h"
 20#include "armada_gem.h"
 21
 22static void armada_fbdev_fb_destroy(struct fb_info *info)
 23{
 24	struct drm_fb_helper *fbh = info->par;
 25
 26	drm_fb_helper_fini(fbh);
 27
 28	fbh->fb->funcs->destroy(fbh->fb);
 29
 30	drm_client_release(&fbh->client);
 31	drm_fb_helper_unprepare(fbh);
 32	kfree(fbh);
 33}
 34
 35static const struct fb_ops armada_fb_ops = {
 36	.owner		= THIS_MODULE,
 37	FB_DEFAULT_IOMEM_OPS,
 38	DRM_FB_HELPER_DEFAULT_OPS,
 39	.fb_destroy	= armada_fbdev_fb_destroy,
 
 
 
 
 40};
 41
 42static const struct drm_fb_helper_funcs armada_fbdev_helper_funcs;
 43
 44int armada_fbdev_driver_fbdev_probe(struct drm_fb_helper *fbh,
 45				    struct drm_fb_helper_surface_size *sizes)
 46{
 47	struct drm_device *dev = fbh->dev;
 48	struct drm_mode_fb_cmd2 mode;
 49	struct armada_framebuffer *dfb;
 50	struct armada_gem_object *obj;
 51	struct fb_info *info;
 52	int size, ret;
 53	void *ptr;
 54
 55	memset(&mode, 0, sizeof(mode));
 56	mode.width = sizes->surface_width;
 57	mode.height = sizes->surface_height;
 58	mode.pitches[0] = armada_pitch(mode.width, sizes->surface_bpp);
 59	mode.pixel_format = drm_mode_legacy_fb_format(sizes->surface_bpp,
 60					sizes->surface_depth);
 61
 62	size = mode.pitches[0] * mode.height;
 63	obj = armada_gem_alloc_private_object(dev, size);
 64	if (!obj) {
 65		DRM_ERROR("failed to allocate fb memory\n");
 66		return -ENOMEM;
 67	}
 68
 69	ret = armada_gem_linear_back(dev, obj);
 70	if (ret) {
 71		drm_gem_object_put(&obj->obj);
 72		return ret;
 73	}
 74
 75	ptr = armada_gem_map_object(dev, obj);
 76	if (!ptr) {
 77		drm_gem_object_put(&obj->obj);
 78		return -ENOMEM;
 79	}
 80
 81	dfb = armada_framebuffer_create(dev, &mode, obj);
 82
 83	/*
 84	 * A reference is now held by the framebuffer object if
 85	 * successful, otherwise this drops the ref for the error path.
 86	 */
 87	drm_gem_object_put(&obj->obj);
 88
 89	if (IS_ERR(dfb))
 90		return PTR_ERR(dfb);
 91
 92	info = drm_fb_helper_alloc_info(fbh);
 93	if (IS_ERR(info)) {
 94		ret = PTR_ERR(info);
 95		goto err_fballoc;
 96	}
 97
 98	info->fbops = &armada_fb_ops;
 99	info->fix.smem_start = obj->phys_addr;
100	info->fix.smem_len = obj->obj.size;
101	info->screen_size = obj->obj.size;
102	info->screen_base = ptr;
103	fbh->funcs = &armada_fbdev_helper_funcs;
104	fbh->fb = &dfb->fb;
105
106	drm_fb_helper_fill_info(info, fbh, sizes);
107
108	DRM_DEBUG_KMS("allocated %dx%d %dbpp fb: 0x%08llx\n",
109		dfb->fb.width, dfb->fb.height, dfb->fb.format->cpp[0] * 8,
110		(unsigned long long)obj->phys_addr);
111
112	return 0;
113
114 err_fballoc:
115	dfb->fb.funcs->destroy(&dfb->fb);
116	return ret;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
117}
v6.2
  1// SPDX-License-Identifier: GPL-2.0-only
  2/*
  3 * Copyright (C) 2012 Russell King
  4 *  Written from the i915 driver.
  5 */
  6
  7#include <linux/errno.h>
 
  8#include <linux/kernel.h>
  9#include <linux/module.h>
 10
 
 
 11#include <drm/drm_fb_helper.h>
 12#include <drm/drm_fourcc.h>
 13
 14#include "armada_crtc.h"
 15#include "armada_drm.h"
 16#include "armada_fb.h"
 17#include "armada_gem.h"
 18
 
 
 
 
 
 
 
 
 
 
 
 
 
 19static const struct fb_ops armada_fb_ops = {
 20	.owner		= THIS_MODULE,
 
 21	DRM_FB_HELPER_DEFAULT_OPS,
 22	.fb_read	= drm_fb_helper_cfb_read,
 23	.fb_write	= drm_fb_helper_cfb_write,
 24	.fb_fillrect	= drm_fb_helper_cfb_fillrect,
 25	.fb_copyarea	= drm_fb_helper_cfb_copyarea,
 26	.fb_imageblit	= drm_fb_helper_cfb_imageblit,
 27};
 28
 29static int armada_fbdev_create(struct drm_fb_helper *fbh,
 30	struct drm_fb_helper_surface_size *sizes)
 
 
 31{
 32	struct drm_device *dev = fbh->dev;
 33	struct drm_mode_fb_cmd2 mode;
 34	struct armada_framebuffer *dfb;
 35	struct armada_gem_object *obj;
 36	struct fb_info *info;
 37	int size, ret;
 38	void *ptr;
 39
 40	memset(&mode, 0, sizeof(mode));
 41	mode.width = sizes->surface_width;
 42	mode.height = sizes->surface_height;
 43	mode.pitches[0] = armada_pitch(mode.width, sizes->surface_bpp);
 44	mode.pixel_format = drm_mode_legacy_fb_format(sizes->surface_bpp,
 45					sizes->surface_depth);
 46
 47	size = mode.pitches[0] * mode.height;
 48	obj = armada_gem_alloc_private_object(dev, size);
 49	if (!obj) {
 50		DRM_ERROR("failed to allocate fb memory\n");
 51		return -ENOMEM;
 52	}
 53
 54	ret = armada_gem_linear_back(dev, obj);
 55	if (ret) {
 56		drm_gem_object_put(&obj->obj);
 57		return ret;
 58	}
 59
 60	ptr = armada_gem_map_object(dev, obj);
 61	if (!ptr) {
 62		drm_gem_object_put(&obj->obj);
 63		return -ENOMEM;
 64	}
 65
 66	dfb = armada_framebuffer_create(dev, &mode, obj);
 67
 68	/*
 69	 * A reference is now held by the framebuffer object if
 70	 * successful, otherwise this drops the ref for the error path.
 71	 */
 72	drm_gem_object_put(&obj->obj);
 73
 74	if (IS_ERR(dfb))
 75		return PTR_ERR(dfb);
 76
 77	info = drm_fb_helper_alloc_info(fbh);
 78	if (IS_ERR(info)) {
 79		ret = PTR_ERR(info);
 80		goto err_fballoc;
 81	}
 82
 83	info->fbops = &armada_fb_ops;
 84	info->fix.smem_start = obj->phys_addr;
 85	info->fix.smem_len = obj->obj.size;
 86	info->screen_size = obj->obj.size;
 87	info->screen_base = ptr;
 
 88	fbh->fb = &dfb->fb;
 89
 90	drm_fb_helper_fill_info(info, fbh, sizes);
 91
 92	DRM_DEBUG_KMS("allocated %dx%d %dbpp fb: 0x%08llx\n",
 93		dfb->fb.width, dfb->fb.height, dfb->fb.format->cpp[0] * 8,
 94		(unsigned long long)obj->phys_addr);
 95
 96	return 0;
 97
 98 err_fballoc:
 99	dfb->fb.funcs->destroy(&dfb->fb);
100	return ret;
101}
102
103static int armada_fb_probe(struct drm_fb_helper *fbh,
104	struct drm_fb_helper_surface_size *sizes)
105{
106	int ret = 0;
107
108	if (!fbh->fb) {
109		ret = armada_fbdev_create(fbh, sizes);
110		if (ret == 0)
111			ret = 1;
112	}
113	return ret;
114}
115
116static const struct drm_fb_helper_funcs armada_fb_helper_funcs = {
117	.fb_probe	= armada_fb_probe,
118};
119
120int armada_fbdev_init(struct drm_device *dev)
121{
122	struct armada_private *priv = drm_to_armada_dev(dev);
123	struct drm_fb_helper *fbh;
124	int ret;
125
126	fbh = devm_kzalloc(dev->dev, sizeof(*fbh), GFP_KERNEL);
127	if (!fbh)
128		return -ENOMEM;
129
130	priv->fbdev = fbh;
131
132	drm_fb_helper_prepare(dev, fbh, &armada_fb_helper_funcs);
133
134	ret = drm_fb_helper_init(dev, fbh);
135	if (ret) {
136		DRM_ERROR("failed to initialize drm fb helper\n");
137		goto err_fb_helper;
138	}
139
140	ret = drm_fb_helper_initial_config(fbh, 32);
141	if (ret) {
142		DRM_ERROR("failed to set initial config\n");
143		goto err_fb_setup;
144	}
145
146	return 0;
147 err_fb_setup:
148	drm_fb_helper_fini(fbh);
149 err_fb_helper:
150	priv->fbdev = NULL;
151	return ret;
152}
153
154void armada_fbdev_fini(struct drm_device *dev)
155{
156	struct armada_private *priv = drm_to_armada_dev(dev);
157	struct drm_fb_helper *fbh = priv->fbdev;
158
159	if (fbh) {
160		drm_fb_helper_unregister_info(fbh);
161
162		drm_fb_helper_fini(fbh);
163
164		if (fbh->fb)
165			fbh->fb->funcs->destroy(fbh->fb);
166
167		priv->fbdev = NULL;
168	}
169}