Skip to content

Commit

Permalink
[media] v4l: add G2D driver for s5p device family
Browse files Browse the repository at this point in the history
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: Kamil Debski <k.debski@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
  • Loading branch information
Kamil Debski authored and Mauro Carvalho Chehab committed Nov 8, 2011
1 parent 8c8ee11 commit 9188473
Show file tree
Hide file tree
Showing 7 changed files with 1,142 additions and 0 deletions.
9 changes: 9 additions & 0 deletions drivers/media/video/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -1098,6 +1098,15 @@ config VIDEO_MEM2MEM_TESTDEV
This is a virtual test device for the memory-to-memory driver
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
tristate "Samsung S5P MFC 5.1 Video Codec"
Expand Down
2 changes: 2 additions & 0 deletions drivers/media/video/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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_TV) += s5p-tv/

obj-$(CONFIG_VIDEO_SAMSUNG_S5P_G2D) += s5p-g2d/

obj-$(CONFIG_ARCH_DAVINCI) += davinci/

obj-$(CONFIG_VIDEO_SH_VOU) += sh_vou.o
Expand Down
3 changes: 3 additions & 0 deletions drivers/media/video/s5p-g2d/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
s5p-g2d-objs := g2d.o g2d-hw.o

obj-$(CONFIG_VIDEO_SAMSUNG_S5P_G2D) += s5p-g2d.o
106 changes: 106 additions & 0 deletions drivers/media/video/s5p-g2d/g2d-hw.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*
* 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);
}
115 changes: 115 additions & 0 deletions drivers/media/video/s5p-g2d/g2d-regs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/*
* 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

Loading

0 comments on commit 9188473

Please sign in to comment.