Path: blob/master/drivers/gpu/drm/armada/armada_fbdev.c
49147 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>15#include <drm/drm_print.h>1617#include "armada_crtc.h"18#include "armada_drm.h"19#include "armada_fb.h"20#include "armada_gem.h"2122static void armada_fbdev_fb_destroy(struct fb_info *info)23{24struct drm_fb_helper *fbh = info->par;2526drm_fb_helper_fini(fbh);2728fbh->fb->funcs->destroy(fbh->fb);2930drm_client_release(&fbh->client);31}3233static const struct fb_ops armada_fb_ops = {34.owner = THIS_MODULE,35FB_DEFAULT_IOMEM_OPS,36DRM_FB_HELPER_DEFAULT_OPS,37.fb_destroy = armada_fbdev_fb_destroy,38};3940static const struct drm_fb_helper_funcs armada_fbdev_helper_funcs;4142int armada_fbdev_driver_fbdev_probe(struct drm_fb_helper *fbh,43struct drm_fb_helper_surface_size *sizes)44{45struct drm_device *dev = fbh->dev;46struct fb_info *info = fbh->info;47struct drm_mode_fb_cmd2 mode;48struct armada_framebuffer *dfb;49struct armada_gem_object *obj;50int size, ret;51void *ptr;5253memset(&mode, 0, sizeof(mode));54mode.width = sizes->surface_width;55mode.height = sizes->surface_height;56mode.pitches[0] = armada_pitch(mode.width, sizes->surface_bpp);57mode.pixel_format = drm_mode_legacy_fb_format(sizes->surface_bpp,58sizes->surface_depth);5960size = mode.pitches[0] * mode.height;61obj = armada_gem_alloc_private_object(dev, size);62if (!obj) {63DRM_ERROR("failed to allocate fb memory\n");64return -ENOMEM;65}6667ret = armada_gem_linear_back(dev, obj);68if (ret) {69drm_gem_object_put(&obj->obj);70return ret;71}7273ptr = armada_gem_map_object(dev, obj);74if (!ptr) {75drm_gem_object_put(&obj->obj);76return -ENOMEM;77}7879dfb = armada_framebuffer_create(dev,80drm_get_format_info(dev, mode.pixel_format,81mode.modifier[0]),82&mode, obj);8384/*85* A reference is now held by the framebuffer object if86* successful, otherwise this drops the ref for the error path.87*/88drm_gem_object_put(&obj->obj);8990if (IS_ERR(dfb))91return PTR_ERR(dfb);9293info->fbops = &armada_fb_ops;94info->fix.smem_start = obj->phys_addr;95info->fix.smem_len = obj->obj.size;96info->screen_size = obj->obj.size;97info->screen_base = ptr;98fbh->funcs = &armada_fbdev_helper_funcs;99fbh->fb = &dfb->fb;100101drm_fb_helper_fill_info(info, fbh, sizes);102103DRM_DEBUG_KMS("allocated %dx%d %dbpp fb: 0x%08llx\n",104dfb->fb.width, dfb->fb.height, dfb->fb.format->cpp[0] * 8,105(unsigned long long)obj->phys_addr);106107return 0;108}109110111