Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4.16 hdmi #23

Merged
merged 3 commits into from
May 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions arch/arm/configs/mt7623n_evb_fwu_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -410,4 +410,5 @@ CONFIG_COMMON_CLK_MT2701_MMSYS=y
CONFIG_COMMON_CLK_MT2701_IMGSYS=y
CONFIG_COMMON_CLK_MT2701_VDECSYS=y
CONFIG_FRAMEBUFFER_CONSOLE=y
CONFIG_DRM_FBDEV_EMULATION=y

4 changes: 3 additions & 1 deletion drivers/gpu/drm/mediatek/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ mediatek-drm-y := mtk_disp_color.o \
mtk_drm_plane.o \
mtk_dsi.o \
mtk_mipi_tx.o \
mtk_dpi.o
mtk_dpi.o \

mediatek-drm-$(CONFIG_DRM_FBDEV_EMULATION) += mtk_drm_fbdev.o

obj-$(CONFIG_DRM_MEDIATEK) += mediatek-drm.o

Expand Down
50 changes: 29 additions & 21 deletions drivers/gpu/drm/mediatek/mtk_drm_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "mtk_drm_ddp_comp.h"
#include "mtk_drm_drv.h"
#include "mtk_drm_fb.h"
#include "mtk_drm_fbdev.h"
#include "mtk_drm_gem.h"

#define DRIVER_NAME "mediatek"
Expand Down Expand Up @@ -148,6 +149,7 @@ static enum mtk_ddp_comp_id mt2701_mtk_ddp_ext[] = {
DDP_COMPONENT_DPI0,
};


static enum mtk_ddp_comp_id mt8173_mtk_ddp_main[] = {
DDP_COMPONENT_OVL0,
DDP_COMPONENT_COLOR0,
Expand Down Expand Up @@ -259,6 +261,10 @@ static int mtk_drm_kms_init(struct drm_device *drm)
drm_kms_helper_poll_init(drm);
drm_mode_config_reset(drm);

ret = mtk_fbdev_init(drm);
if (ret)
goto err_component_unbind;

return 0;

err_component_unbind:
Expand All @@ -271,6 +277,7 @@ static int mtk_drm_kms_init(struct drm_device *drm)

static void mtk_drm_kms_deinit(struct drm_device *drm)
{
mtk_fbdev_fini(drm);
drm_kms_helper_poll_fini(drm);

component_unbind_all(drm->dev, drm);
Expand All @@ -289,29 +296,30 @@ static const struct file_operations mtk_drm_fops = {
};

static struct drm_driver mtk_drm_driver = {
.driver_features = DRIVER_MODESET | DRIVER_GEM | DRIVER_PRIME |
DRIVER_ATOMIC,

.gem_free_object_unlocked = mtk_drm_gem_free_object,
.gem_vm_ops = &drm_gem_cma_vm_ops,
.dumb_create = mtk_drm_gem_dumb_create,

.prime_handle_to_fd = drm_gem_prime_handle_to_fd,
.prime_fd_to_handle = drm_gem_prime_fd_to_handle,
.gem_prime_export = drm_gem_prime_export,
.gem_prime_import = drm_gem_prime_import,
.gem_prime_get_sg_table = mtk_gem_prime_get_sg_table,
.gem_prime_import_sg_table = mtk_gem_prime_import_sg_table,
.gem_prime_mmap = mtk_drm_gem_mmap_buf,
.fops = &mtk_drm_fops,

.name = DRIVER_NAME,
.desc = DRIVER_DESC,
.date = DRIVER_DATE,
.major = DRIVER_MAJOR,
.minor = DRIVER_MINOR,
.driver_features = DRIVER_MODESET | DRIVER_GEM | DRIVER_PRIME |
DRIVER_ATOMIC,

.gem_free_object_unlocked = mtk_drm_gem_free_object,
.gem_vm_ops = &drm_gem_cma_vm_ops,
.dumb_create = mtk_drm_gem_dumb_create,

.prime_handle_to_fd = drm_gem_prime_handle_to_fd,
.prime_fd_to_handle = drm_gem_prime_fd_to_handle,
.gem_prime_export = drm_gem_prime_export,
.gem_prime_import = drm_gem_prime_import,
.gem_prime_get_sg_table = mtk_gem_prime_get_sg_table,
.gem_prime_import_sg_table = mtk_gem_prime_import_sg_table,
.gem_prime_mmap = mtk_drm_gem_mmap_buf,
.fops = &mtk_drm_fops,

.name = DRIVER_NAME,
.desc = DRIVER_DESC,
.date = DRIVER_DATE,
.major = DRIVER_MAJOR,
.minor = DRIVER_MINOR,
};


static int compare_of(struct device *dev, void *data)
{
return dev->of_node == data;
Expand Down
4 changes: 4 additions & 0 deletions drivers/gpu/drm/mediatek/mtk_drm_drv.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#ifndef MTK_DRM_DRV_H
#define MTK_DRM_DRV_H

#include <drm/drm_fb_helper.h>
#include <linux/io.h>
#include "mtk_drm_ddp_comp.h"

Expand All @@ -40,6 +41,7 @@ struct mtk_drm_private {
struct drm_device *drm;
struct device *dma_dev;

struct drm_crtc *crtc[MAX_CRTC];
unsigned int num_pipes;

struct device_node *mutex_node;
Expand All @@ -56,6 +58,8 @@ struct mtk_drm_private {
} commit;

struct drm_atomic_state *suspend_state;
struct drm_fb_helper fb_helper;
struct drm_gem_object *fbdev_bo;
};

extern struct platform_driver mtk_ddp_driver;
Expand Down
13 changes: 13 additions & 0 deletions drivers/gpu/drm/mediatek/mtk_drm_fb.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,19 @@ static struct mtk_drm_fb *mtk_drm_framebuffer_init(struct drm_device *dev,
return mtk_fb;
}

struct drm_framebuffer *mtk_drm_framebuffer_create(struct drm_device *dev,
const struct drm_mode_fb_cmd2 *mode,
struct drm_gem_object *obj)
{
struct mtk_drm_fb *mtk_fb;

mtk_fb = mtk_drm_framebuffer_init(dev, mode, obj);
if (IS_ERR(mtk_fb))
return ERR_CAST(mtk_fb);

return &mtk_fb->base;
}

/*
* Wait for any exclusive fence in fb's gem object's reservation object.
*
Expand Down
3 changes: 3 additions & 0 deletions drivers/gpu/drm/mediatek/mtk_drm_fb.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,8 @@ int mtk_fb_wait(struct drm_framebuffer *fb);
struct drm_framebuffer *mtk_drm_mode_fb_create(struct drm_device *dev,
struct drm_file *file,
const struct drm_mode_fb_cmd2 *cmd);
struct drm_framebuffer *mtk_drm_framebuffer_create(struct drm_device *dev,
const struct drm_mode_fb_cmd2 *mode,
struct drm_gem_object *obj);

#endif /* MTK_DRM_FB_H */
181 changes: 181 additions & 0 deletions drivers/gpu/drm/mediatek/mtk_drm_fbdev.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
/*
* Copyright (c) 2016 MediaTek Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/

#include <drm/drmP.h>
#include <drm/drm_crtc_helper.h>
#include <drm/drm_fb_helper.h>
#include <drm/drm_gem.h>

#include "mtk_drm_drv.h"
#include "mtk_drm_fb.h"
#include "mtk_drm_gem.h"
#include "mtk_drm_fbdev.h"

#define to_drm_private(x) \
container_of(x, struct mtk_drm_private, fb_helper)

static int mtk_drm_fbdev_mmap(struct fb_info *info, struct vm_area_struct *vma)
{
struct drm_fb_helper *helper = info->par;
struct mtk_drm_private *private = to_drm_private(helper);

return mtk_drm_gem_mmap_buf(private->fbdev_bo, vma);
}

static struct fb_ops mtk_fbdev_ops = {
.owner = THIS_MODULE,
DRM_FB_HELPER_DEFAULT_OPS,
.fb_fillrect = drm_fb_helper_cfb_fillrect,
.fb_copyarea = drm_fb_helper_cfb_copyarea,
.fb_imageblit = drm_fb_helper_cfb_imageblit,
.fb_check_var = drm_fb_helper_check_var,
.fb_set_par = drm_fb_helper_set_par,
.fb_blank = drm_fb_helper_blank,
.fb_pan_display = drm_fb_helper_pan_display,
.fb_setcmap = drm_fb_helper_setcmap,
.fb_mmap = mtk_drm_fbdev_mmap,
};

static int mtk_fbdev_probe(struct drm_fb_helper *helper,
struct drm_fb_helper_surface_size *sizes)
{
struct drm_device *dev = helper->dev;
struct mtk_drm_private *private = to_drm_private(helper);
struct drm_mode_fb_cmd2 mode = { 0 };
struct mtk_drm_gem_obj *mtk_gem;
struct fb_info *info;
struct drm_framebuffer *fb;
unsigned int bytes_per_pixel;
unsigned long offset;
size_t size;
int err;

bytes_per_pixel = DIV_ROUND_UP(sizes->surface_bpp, 8);

mode.width = sizes->surface_width;
mode.height = sizes->surface_height;
mode.pitches[0] = sizes->surface_width * bytes_per_pixel;
mode.pixel_format = drm_mode_legacy_fb_format(sizes->surface_bpp,
sizes->surface_depth);

size = mode.pitches[0] * mode.height;

mtk_gem = mtk_drm_gem_create(dev, size, true);
if (IS_ERR(mtk_gem))
return PTR_ERR(mtk_gem);

private->fbdev_bo = &mtk_gem->base;

info = drm_fb_helper_alloc_fbi(helper);
if (IS_ERR(info)) {
DRM_DEV_ERROR(dev->dev, "failed to allocate framebuffer info, %d\n",
err);
err = PTR_ERR(info);
goto out;
}

fb = mtk_drm_framebuffer_create(dev, &mode, private->fbdev_bo);
if (IS_ERR(fb)) {
DRM_DEV_ERROR(dev->dev, "failed to allocate DRM framebuffer, %d\n",
err);
err = PTR_ERR(fb);
goto out;
}
helper->fb = fb;

info->par = helper;
info->flags = FBINFO_FLAG_DEFAULT;
info->fbops = &mtk_fbdev_ops;

drm_fb_helper_fill_fix(info, fb->pitches[0], fb->format->depth);
drm_fb_helper_fill_var(info, helper, sizes->fb_width, sizes->fb_height);

offset = info->var.xoffset * bytes_per_pixel;
offset += info->var.yoffset * fb->pitches[0];

dev->mode_config.fb_base = 0;
info->screen_base = mtk_gem->kvaddr + offset;
info->screen_size = size;
info->fix.smem_len = size;

DRM_DEBUG_KMS("FB [%ux%u]-%u offset=%lu size=%zd\n",
fb->width, fb->height, fb->format->depth, offset, size);

info->skip_vt_switch = true;

return 0;

out:


mtk_drm_gem_free_object(&mtk_gem->base);
return err;
}

static const struct drm_fb_helper_funcs mtk_drm_fb_helper_funcs = {
.fb_probe = mtk_fbdev_probe,
};

int mtk_fbdev_init(struct drm_device *dev)
{
struct mtk_drm_private *priv = dev->dev_private;
struct drm_fb_helper *helper = &priv->fb_helper;
int ret;

if (!dev->mode_config.num_crtc || !dev->mode_config.num_connector)
return -EINVAL;

drm_fb_helper_prepare(dev, helper, &mtk_drm_fb_helper_funcs);

ret = drm_fb_helper_init(dev, helper, dev->mode_config.num_connector);
if (ret < 0) {
DRM_DEV_ERROR(dev->dev, "failed to initialize DRM FB helper, %d\n",
ret);
// goto fini;
return ret;
}

ret = drm_fb_helper_single_add_all_connectors(helper);
if (ret < 0) {
DRM_DEV_ERROR(dev->dev, "failed to add connectors, %d\n", ret);
goto fini;
}

ret = drm_fb_helper_initial_config(helper, 32);
if (ret < 0) {
DRM_DEV_ERROR(dev->dev, "failed to set initial configuration, %d\n",
ret);
goto fini;
}

return 0;

fini:
drm_fb_helper_fini(helper);
return ret;
}

void mtk_fbdev_fini(struct drm_device *dev)
{
struct mtk_drm_private *priv = dev->dev_private;
struct drm_fb_helper *helper = &priv->fb_helper;

drm_fb_helper_unregister_fbi(helper);

if (helper->fb) {
drm_framebuffer_unregister_private(helper->fb);
drm_framebuffer_remove(helper->fb);
}

drm_fb_helper_fini(helper);
}
32 changes: 32 additions & 0 deletions drivers/gpu/drm/mediatek/mtk_drm_fbdev.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2016 MediaTek Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/

#ifndef MTK_DRM_FBDEV_H
#define MTK_DRM_FBDEV_H

#ifdef CONFIG_DRM_FBDEV_EMULATION
int mtk_fbdev_init(struct drm_device *dev);
void mtk_fbdev_fini(struct drm_device *dev);
#else
int mtk_fbdev_init(struct drm_device *dev)
{
return 0;
}

void mtk_fbdev_fini(struct drm_device *dev)
{

}
#endif /* CONFIG_DRM_FBDEV_EMULATION */

#endif /* MTK_DRM_FBDEV_H */