Commit 91884734 authored by Kamil Debski's avatar Kamil Debski Committed by Mauro Carvalho Chehab

[media] v4l: add G2D driver for s5p device family

G2D is a 2D graphics accelerator engine present in the s5p family
of Samsung SoCs. It is capable of bitblt and raster operations on
images having dimensions of up to 8000x8000.
Signed-off-by: default avatarKamil Debski <k.debski@samsung.com>
Signed-off-by: default avatarKyungmin Park <kyungmin.park@samsung.com>
Signed-off-by: default avatarMarek Szyprowski <m.szyprowski@samsung.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent 8c8ee113
...@@ -1098,6 +1098,15 @@ config VIDEO_MEM2MEM_TESTDEV ...@@ -1098,6 +1098,15 @@ config VIDEO_MEM2MEM_TESTDEV
This is a virtual test device for the memory-to-memory driver This is a virtual test device for the memory-to-memory driver
framework. framework.
config VIDEO_SAMSUNG_S5P_G2D
tristate "Samsung S5P and EXYNOS4 G2D 2d graphics accelerator driver"
depends on VIDEO_DEV && VIDEO_V4L2 && PLAT_S5P
select VIDEOBUF2_DMA_CONTIG
select V4L2_MEM2MEM_DEV
default n
---help---
This is a v4l2 driver for Samsung S5P and EXYNOS4 G2D
2d graphics accelerator.
config VIDEO_SAMSUNG_S5P_MFC config VIDEO_SAMSUNG_S5P_MFC
tristate "Samsung S5P MFC 5.1 Video Codec" tristate "Samsung S5P MFC 5.1 Video Codec"
......
...@@ -180,6 +180,8 @@ obj-$(CONFIG_VIDEO_SAMSUNG_S5P_FIMC) += s5p-fimc/ ...@@ -180,6 +180,8 @@ obj-$(CONFIG_VIDEO_SAMSUNG_S5P_FIMC) += s5p-fimc/
obj-$(CONFIG_VIDEO_SAMSUNG_S5P_MFC) += s5p-mfc/ obj-$(CONFIG_VIDEO_SAMSUNG_S5P_MFC) += s5p-mfc/
obj-$(CONFIG_VIDEO_SAMSUNG_S5P_TV) += s5p-tv/ obj-$(CONFIG_VIDEO_SAMSUNG_S5P_TV) += s5p-tv/
obj-$(CONFIG_VIDEO_SAMSUNG_S5P_G2D) += s5p-g2d/
obj-$(CONFIG_ARCH_DAVINCI) += davinci/ obj-$(CONFIG_ARCH_DAVINCI) += davinci/
obj-$(CONFIG_VIDEO_SH_VOU) += sh_vou.o obj-$(CONFIG_VIDEO_SH_VOU) += sh_vou.o
......
s5p-g2d-objs := g2d.o g2d-hw.o
obj-$(CONFIG_VIDEO_SAMSUNG_S5P_G2D) += s5p-g2d.o
/*
* Samsung S5P G2D - 2D Graphics Accelerator Driver
*
* Copyright (c) 2011 Samsung Electronics Co., Ltd.
* Kamil Debski, <k.debski@samsung.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the
* License, or (at your option) any later version
*/
#include <linux/io.h>
#include "g2d.h"
#include "g2d-regs.h"
#define w(x, a) writel((x), d->regs + (a))
#define r(a) readl(d->regs + (a))
/* g2d_reset clears all g2d registers */
void g2d_reset(struct g2d_dev *d)
{
w(1, SOFT_RESET_REG);
}
void g2d_set_src_size(struct g2d_dev *d, struct g2d_frame *f)
{
u32 n;
u32 stride;
w(f->stride & 0xFFFF, SRC_STRIDE_REG);
n = f->o_height & 0xFFF;
n <<= 16;
n |= f->o_width & 0xFFF;
w(n, SRC_LEFT_TOP_REG);
n = f->bottom & 0xFFF;
n <<= 16;
n |= f->right & 0xFFF;
w(n, SRC_RIGHT_BOTTOM_REG);
w(f->fmt->hw, SRC_COLOR_MODE_REG);
}
void g2d_set_src_addr(struct g2d_dev *d, dma_addr_t a)
{
w(a, SRC_BASE_ADDR_REG);
}
void g2d_set_dst_size(struct g2d_dev *d, struct g2d_frame *f)
{
u32 n;
u32 stride;
w(f->stride & 0xFFFF, DST_STRIDE_REG);
n = f->o_height & 0xFFF;
n <<= 16;
n |= f->o_width & 0xFFF;
w(n, DST_LEFT_TOP_REG);
n = f->bottom & 0xFFF;
n <<= 16;
n |= f->right & 0xFFF;
w(n, DST_RIGHT_BOTTOM_REG);
w(f->fmt->hw, DST_COLOR_MODE_REG);
}
void g2d_set_dst_addr(struct g2d_dev *d, dma_addr_t a)
{
w(a, DST_BASE_ADDR_REG);
}
void g2d_set_rop4(struct g2d_dev *d, u32 r)
{
w(r, ROP4_REG);
}
u32 g2d_cmd_stretch(u32 e)
{
e &= 1;
return e << 4;
}
void g2d_set_cmd(struct g2d_dev *d, u32 c)
{
w(c, BITBLT_COMMAND_REG);
}
void g2d_start(struct g2d_dev *d)
{
/* Clear cache */
w(0x7, CACHECTL_REG);
/* Enable interrupt */
w(1, INTEN_REG);
/* Start G2D engine */
w(1, BITBLT_START_REG);
}
void g2d_clear_int(struct g2d_dev *d)
{
w(1, INTC_PEND_REG);
}
/*
* Samsung S5P G2D - 2D Graphics Accelerator Driver
*
* Copyright (c) 2011 Samsung Electronics Co., Ltd.
* Kamil Debski, <k.debski@samsung.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the
* License, or (at your option) any later version
*/
/* General Registers */
#define SOFT_RESET_REG 0x0000 /* Software reset reg */
#define INTEN_REG 0x0004 /* Interrupt Enable reg */
#define INTC_PEND_REG 0x000C /* Interrupt Control Pending reg */
#define FIFO_STAT_REG 0x0010 /* Command FIFO Status reg */
#define AXI_ID_MODE_REG 0x0014 /* AXI Read ID Mode reg */
#define CACHECTL_REG 0x0018 /* Cache & Buffer clear reg */
#define AXI_MODE_REG 0x001C /* AXI Mode reg */
/* Command Registers */
#define BITBLT_START_REG 0x0100 /* BitBLT Start reg */
#define BITBLT_COMMAND_REG 0x0104 /* Command reg for BitBLT */
/* Parameter Setting Registers (Rotate & Direction) */
#define ROTATE_REG 0x0200 /* Rotation reg */
#define SRC_MSK_DIRECT_REG 0x0204 /* Src and Mask Direction reg */
#define DST_PAT_DIRECT_REG 0x0208 /* Dest and Pattern Direction reg */
/* Parameter Setting Registers (Src) */
#define SRC_SELECT_REG 0x0300 /* Src Image Selection reg */
#define SRC_BASE_ADDR_REG 0x0304 /* Src Image Base Address reg */
#define SRC_STRIDE_REG 0x0308 /* Src Stride reg */
#define SRC_COLOR_MODE_REG 0x030C /* Src Image Color Mode reg */
#define SRC_LEFT_TOP_REG 0x0310 /* Src Left Top Coordinate reg */
#define SRC_RIGHT_BOTTOM_REG 0x0314 /* Src Right Bottom Coordinate reg */
/* Parameter Setting Registers (Dest) */
#define DST_SELECT_REG 0x0400 /* Dest Image Selection reg */
#define DST_BASE_ADDR_REG 0x0404 /* Dest Image Base Address reg */
#define DST_STRIDE_REG 0x0408 /* Dest Stride reg */
#define DST_COLOR_MODE_REG 0x040C /* Dest Image Color Mode reg */
#define DST_LEFT_TOP_REG 0x0410 /* Dest Left Top Coordinate reg */
#define DST_RIGHT_BOTTOM_REG 0x0414 /* Dest Right Bottom Coordinate reg */
/* Parameter Setting Registers (Pattern) */
#define PAT_BASE_ADDR_REG 0x0500 /* Pattern Image Base Address reg */
#define PAT_SIZE_REG 0x0504 /* Pattern Image Size reg */
#define PAT_COLOR_MODE_REG 0x0508 /* Pattern Image Color Mode reg */
#define PAT_OFFSET_REG 0x050C /* Pattern Left Top Coordinate reg */
#define PAT_STRIDE_REG 0x0510 /* Pattern Stride reg */
/* Parameter Setting Registers (Mask) */
#define MASK_BASE_ADDR_REG 0x0520 /* Mask Base Address reg */
#define MASK_STRIDE_REG 0x0524 /* Mask Stride reg */
/* Parameter Setting Registers (Clipping Window) */
#define CW_LT_REG 0x0600 /* LeftTop coordinates of Clip Window */
#define CW_RB_REG 0x0604 /* RightBottom coordinates of Clip
Window */
/* Parameter Setting Registers (ROP & Alpha Setting) */
#define THIRD_OPERAND_REG 0x0610 /* Third Operand Selection reg */
#define ROP4_REG 0x0614 /* Raster Operation reg */
#define ALPHA_REG 0x0618 /* Alpha value, Fading offset value */
/* Parameter Setting Registers (Color) */
#define FG_COLOR_REG 0x0700 /* Foreground Color reg */
#define BG_COLOR_REG 0x0704 /* Background Color reg */
#define BS_COLOR_REG 0x0708 /* Blue Screen Color reg */
/* Parameter Setting Registers (Color Key) */
#define SRC_COLORKEY_CTRL_REG 0x0710 /* Src Colorkey control reg */
#define SRC_COLORKEY_DR_MIN_REG 0x0714 /* Src Colorkey Decision Reference
Min reg */
#define SRC_COLORKEY_DR_MAX_REG 0x0718 /* Src Colorkey Decision Reference
Max reg */
#define DST_COLORKEY_CTRL_REG 0x071C /* Dest Colorkey control reg */
#define DST_COLORKEY_DR_MIN_REG 0x0720 /* Dest Colorkey Decision Reference
Min reg */
#define DST_COLORKEY_DR_MAX_REG 0x0724 /* Dest Colorkey Decision Reference
Max reg */
/* Color mode values */
#define ORDER_XRGB 0
#define ORDER_RGBX 1
#define ORDER_XBGR 2
#define ORDER_BGRX 3
#define MODE_XRGB_8888 0
#define MODE_ARGB_8888 1
#define MODE_RGB_565 2
#define MODE_XRGB_1555 3
#define MODE_ARGB_1555 4
#define MODE_XRGB_4444 5
#define MODE_ARGB_4444 6
#define MODE_PACKED_RGB_888 7
#define COLOR_MODE(o, m) (((o) << 4) | (m))
/* ROP4 operation values */
#define ROP4_COPY 0xCCCC
#define ROP4_INVERT 0x3333
/* Hardware limits */
#define MAX_WIDTH 8000
#define MAX_HEIGHT 8000
#define G2D_TIMEOUT 500
#define DEFAULT_WIDTH 100
#define DEFAULT_HEIGHT 100
This diff is collapsed.
/*
* Samsung S5P G2D - 2D Graphics Accelerator Driver
*
* Copyright (c) 2011 Samsung Electronics Co., Ltd.
* Kamil Debski, <k.debski@samsung.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the
* License, or (at your option) any later version
*/
#include <media/v4l2-device.h>
#include <media/v4l2-ctrls.h>
#define G2D_NAME "s5p-g2d"
struct g2d_dev {
struct v4l2_device v4l2_dev;
struct v4l2_m2m_dev *m2m_dev;
struct video_device *vfd;
struct mutex mutex;
spinlock_t irqlock;
atomic_t num_inst;
struct vb2_alloc_ctx *alloc_ctx;
struct resource *res_regs;
void __iomem *regs;
struct clk *clk;
struct clk *gate;
struct g2d_ctx *curr;
int irq;
wait_queue_head_t irq_queue;
};
struct g2d_frame {
/* Original dimensions */
u32 width;
u32 height;
/* Crop size */
u32 c_width;
u32 c_height;
/* Offset */
u32 o_width;
u32 o_height;
/* Image format */
struct g2d_fmt *fmt;
/* Variables that can calculated once and reused */
u32 stride;
u32 bottom;
u32 right;
u32 size;
};
struct g2d_ctx {
struct v4l2_fh fh;
struct g2d_dev *dev;
struct v4l2_m2m_ctx *m2m_ctx;
struct g2d_frame in;
struct g2d_frame out;
struct v4l2_ctrl_handler ctrl_handler;
u32 rop;
};
struct g2d_fmt {
char *name;
u32 fourcc;
int depth;
u32 hw;
};
void g2d_reset(struct g2d_dev *d);
void g2d_set_src_size(struct g2d_dev *d, struct g2d_frame *f);
void g2d_set_src_addr(struct g2d_dev *d, dma_addr_t a);
void g2d_set_dst_size(struct g2d_dev *d, struct g2d_frame *f);
void g2d_set_dst_addr(struct g2d_dev *d, dma_addr_t a);
void g2d_start(struct g2d_dev *d);
void g2d_clear_int(struct g2d_dev *d);
void g2d_set_rop4(struct g2d_dev *d, u32 r);
u32 g2d_cmd_stretch(u32 e);
void g2d_set_cmd(struct g2d_dev *d, u32 c);
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