Path: blob/master/drivers/gpu/drm/armada/armada_fbdev.c
26481 views
// SPDX-License-Identifier: GPL-2.0-only1/*2* Copyright (C) 2012 Russell King3* Written from the i915 driver.4*/56#include <linux/errno.h>7#include <linux/fb.h>8#include <linux/kernel.h>9#include <linux/module.h>1011#include <drm/drm_crtc_helper.h>12#include <drm/drm_drv.h>13#include <drm/drm_fb_helper.h>14#include <drm/drm_fourcc.h>1516#include "armada_crtc.h"17#include "armada_drm.h"18#include "armada_fb.h"19#include "armada_gem.h"2021static void armada_fbdev_fb_destroy(struct fb_info *info)22{23struct drm_fb_helper *fbh = info->par;2425drm_fb_helper_fini(fbh);2627fbh->fb->funcs->destroy(fbh->fb);2829drm_client_release(&fbh->client);30drm_fb_helper_unprepare(fbh);31kfree(fbh);32}3334static const struct fb_ops armada_fb_ops = {35.owner = THIS_MODULE,36FB_DEFAULT_IOMEM_OPS,37DRM_FB_HELPER_DEFAULT_OPS,38.fb_destroy = armada_fbdev_fb_destroy,39};4041static const struct drm_fb_helper_funcs armada_fbdev_helper_funcs;4243int armada_fbdev_driver_fbdev_probe(struct drm_fb_helper *fbh,44struct drm_fb_helper_surface_size *sizes)45{46struct drm_device *dev = fbh->dev;47struct drm_mode_fb_cmd2 mode;48struct armada_framebuffer *dfb;49struct armada_gem_object *obj;50struct fb_info *info;51int size, ret;52void *ptr;5354memset(&mode, 0, sizeof(mode));55mode.width = sizes->surface_width;56mode.height = sizes->surface_height;57mode.pitches[0] = armada_pitch(mode.width, sizes->surface_bpp);58mode.pixel_format = drm_mode_legacy_fb_format(sizes->surface_bpp,59sizes->surface_depth);6061size = mode.pitches[0] * mode.height;62obj = armada_gem_alloc_private_object(dev, size);63if (!obj) {64DRM_ERROR("failed to allocate fb memory\n");65return -ENOMEM;66}6768ret = armada_gem_linear_back(dev, obj);69if (ret) {70drm_gem_object_put(&obj->obj);71return ret;72}7374ptr = armada_gem_map_object(dev, obj);75if (!ptr) {76drm_gem_object_put(&obj->obj);77return -ENOMEM;78}7980dfb = armada_framebuffer_create(dev,81drm_get_format_info(dev, mode.pixel_format,82mode.modifier[0]),83&mode, obj);8485/*86* A reference is now held by the framebuffer object if87* successful, otherwise this drops the ref for the error path.88*/89drm_gem_object_put(&obj->obj);9091if (IS_ERR(dfb))92return PTR_ERR(dfb);9394info = drm_fb_helper_alloc_info(fbh);95if (IS_ERR(info)) {96ret = PTR_ERR(info);97goto err_fballoc;98}99100info->fbops = &armada_fb_ops;101info->fix.smem_start = obj->phys_addr;102info->fix.smem_len = obj->obj.size;103info->screen_size = obj->obj.size;104info->screen_base = ptr;105fbh->funcs = &armada_fbdev_helper_funcs;106fbh->fb = &dfb->fb;107108drm_fb_helper_fill_info(info, fbh, sizes);109110DRM_DEBUG_KMS("allocated %dx%d %dbpp fb: 0x%08llx\n",111dfb->fb.width, dfb->fb.height, dfb->fb.format->cpp[0] * 8,112(unsigned long long)obj->phys_addr);113114return 0;115116err_fballoc:117dfb->fb.funcs->destroy(&dfb->fb);118return ret;119}120121122