csc: support hardware CSC with G2D
authorGreg Hackmann <ghackmann@google.com>
Mon, 14 Jan 2013 23:54:46 +0000 (15:54 -0800)
committerGreg Hackmann <ghackmann@google.com>
Tue, 5 Feb 2013 17:56:43 +0000 (09:56 -0800)
Change-Id: Id6d16e4f79245e1895e8bc66372eef27509722b9
Signed-off-by: Greg Hackmann <ghackmann@google.com>
include/fimg2d.h [new file with mode: 0644]
libcsc/Android.mk
libcsc/csc.c
libcsc/csc.h
libcsc/csc_helper.c
original-kernel-headers/linux/fimg2d.h [new file with mode: 0644]

diff --git a/include/fimg2d.h b/include/fimg2d.h
new file mode 100644 (file)
index 0000000..59da4a6
--- /dev/null
@@ -0,0 +1,262 @@
+/****************************************************************************
+ ****************************************************************************
+ ***
+ ***   This header was automatically generated from a Linux kernel header
+ ***   of the same name, to make information necessary for userspace to
+ ***   call into the kernel available to libc.  It contains only constants,
+ ***   structures, and macros generated from the original header, and thus,
+ ***   contains no copyrightable information.
+ ***
+ ***   To edit the content of this header, modify the corresponding
+ ***   source file (e.g. under external/kernel-headers/original/) then
+ ***   run bionic/libc/kernel/tools/update_all.py
+ ***
+ ***   Any manual change here will be lost the next time this script will
+ ***   be run. You've been warned!
+ ***
+ ****************************************************************************
+ ****************************************************************************/
+#ifndef __FIMG2D_H
+#define __FIMG2D_H __FILE__
+#define FIMG2D_MAX_PLANES 2
+#define FIMG2D_IOCTL_MAGIC 'F'
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define FIMG2D_BITBLT_BLIT _IOWR(FIMG2D_IOCTL_MAGIC, 0, struct fimg2d_blit)
+#define FIMG2D_BITBLT_SYNC _IOW(FIMG2D_IOCTL_MAGIC, 1, int)
+#define FIMG2D_BITBLT_VERSION _IOR(FIMG2D_IOCTL_MAGIC, 2, struct fimg2d_version)
+struct fimg2d_version {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ unsigned int hw;
+ unsigned int sw;
+};
+enum blit_sync {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ BLIT_SYNC,
+ BLIT_ASYNC,
+};
+enum addr_space {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ ADDR_NONE = 0,
+ ADDR_DMA_BUF,
+};
+enum pixel_order {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ AX_RGB = 0,
+ RGB_AX,
+ AX_BGR,
+ BGR_AX,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ ARGB_ORDER_END,
+ P1_CRY1CBY0,
+ P1_CBY1CRY0,
+ P1_Y1CRY0CB,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ P1_Y1CBY0CR,
+ P1_ORDER_END,
+ P2_CRCB,
+ P2_CBCR,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ P2_ORDER_END,
+};
+enum color_format {
+ CF_XRGB_8888 = 0,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ CF_ARGB_8888,
+ CF_RGB_565,
+ CF_XRGB_1555,
+ CF_ARGB_1555,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ CF_XRGB_4444,
+ CF_ARGB_4444,
+ CF_RGB_888,
+ CF_YCBCR_444,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ CF_YCBCR_422,
+ CF_YCBCR_420,
+ CF_A8,
+ CF_L8,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ SRC_DST_FORMAT_END,
+ CF_MSK_1BIT,
+ CF_MSK_4BIT,
+ CF_MSK_8BIT,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ CF_MSK_16BIT_565,
+ CF_MSK_16BIT_1555,
+ CF_MSK_16BIT_4444,
+ CF_MSK_32BIT_8888,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ MSK_FORMAT_END,
+};
+enum rotation {
+ ORIGIN,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ ROT_90,
+ ROT_180,
+ ROT_270,
+ XFLIP,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ YFLIP,
+};
+enum repeat {
+ NO_REPEAT = 0,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ REPEAT_NORMAL,
+ REPEAT_PAD,
+ REPEAT_REFLECT, REPEAT_MIRROR = REPEAT_REFLECT,
+ REPEAT_CLAMP,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
+enum scaling {
+ NO_SCALING,
+ SCALING_NEAREST,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ SCALING_BILINEAR,
+};
+enum scaling_factor {
+ SCALING_PIXELS,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ SCALING_RATIO,
+};
+enum premultiplied {
+ PREMULTIPLIED,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NON_PREMULTIPLIED,
+};
+enum bluescreen {
+ OPAQUE,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ TRANSP,
+ BLUSCR,
+};
+enum blit_op {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ BLIT_OP_SOLID_FILL = 0,
+ BLIT_OP_CLR,
+ BLIT_OP_SRC, BLIT_OP_SRC_COPY = BLIT_OP_SRC,
+ BLIT_OP_DST,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ BLIT_OP_SRC_OVER,
+ BLIT_OP_DST_OVER, BLIT_OP_OVER_REV = BLIT_OP_DST_OVER,
+ BLIT_OP_SRC_IN,
+ BLIT_OP_DST_IN, BLIT_OP_IN_REV = BLIT_OP_DST_IN,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ BLIT_OP_SRC_OUT,
+ BLIT_OP_DST_OUT, BLIT_OP_OUT_REV = BLIT_OP_DST_OUT,
+ BLIT_OP_SRC_ATOP,
+ BLIT_OP_DST_ATOP, BLIT_OP_ATOP_REV = BLIT_OP_DST_ATOP,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ BLIT_OP_XOR,
+ BLIT_OP_ADD,
+ BLIT_OP_MULTIPLY,
+ BLIT_OP_SCREEN,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ BLIT_OP_DARKEN,
+ BLIT_OP_LIGHTEN,
+ BLIT_OP_DISJ_SRC_OVER,
+ BLIT_OP_DISJ_DST_OVER, BLIT_OP_SATURATE = BLIT_OP_DISJ_DST_OVER,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ BLIT_OP_DISJ_SRC_IN,
+ BLIT_OP_DISJ_DST_IN, BLIT_OP_DISJ_IN_REV = BLIT_OP_DISJ_DST_IN,
+ BLIT_OP_DISJ_SRC_OUT,
+ BLIT_OP_DISJ_DST_OUT, BLIT_OP_DISJ_OUT_REV = BLIT_OP_DISJ_DST_OUT,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ BLIT_OP_DISJ_SRC_ATOP,
+ BLIT_OP_DISJ_DST_ATOP, BLIT_OP_DISJ_ATOP_REV = BLIT_OP_DISJ_DST_ATOP,
+ BLIT_OP_DISJ_XOR,
+ BLIT_OP_CONJ_SRC_OVER,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ BLIT_OP_CONJ_DST_OVER, BLIT_OP_CONJ_OVER_REV = BLIT_OP_CONJ_DST_OVER,
+ BLIT_OP_CONJ_SRC_IN,
+ BLIT_OP_CONJ_DST_IN, BLIT_OP_CONJ_IN_REV = BLIT_OP_CONJ_DST_IN,
+ BLIT_OP_CONJ_SRC_OUT,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ BLIT_OP_CONJ_DST_OUT, BLIT_OP_CONJ_OUT_REV = BLIT_OP_CONJ_DST_OUT,
+ BLIT_OP_CONJ_SRC_ATOP,
+ BLIT_OP_CONJ_DST_ATOP, BLIT_OP_CONJ_ATOP_REV = BLIT_OP_CONJ_DST_ATOP,
+ BLIT_OP_CONJ_XOR,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ BLIT_OP_USER_COEFF,
+ BLIT_OP_USER_SRC_GA,
+ BLIT_OP_END,
+};
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define MAX_FIMG2D_BLIT_OP (int)BLIT_OP_END
+struct fimg2d_addr {
+ enum addr_space type;
+ int fd[FIMG2D_MAX_PLANES];
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
+struct fimg2d_rect {
+ int x1;
+ int y1;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ int x2;
+ int y2;
+};
+struct fimg2d_scale {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ enum scaling mode;
+ int src_w, src_h;
+ int dst_w, dst_h;
+};
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct fimg2d_clip {
+ __u32 enable;
+ int x1;
+ int y1;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ int x2;
+ int y2;
+};
+struct fimg2d_repeat {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ enum repeat mode;
+ unsigned long pad_color;
+};
+struct fimg2d_bluscr {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ enum bluescreen mode;
+ unsigned long bs_color;
+ unsigned long bg_color;
+};
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct fimg2d_image {
+ int width;
+ int height;
+ int stride;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ enum pixel_order order;
+ enum color_format fmt;
+ struct fimg2d_addr addr;
+ struct fimg2d_rect rect;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
+struct fimg2d_param {
+ unsigned long solid_color;
+ unsigned char g_alpha;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 dither;
+ enum rotation rotate;
+ enum premultiplied premult;
+ struct fimg2d_scale scaling;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ struct fimg2d_repeat repeat;
+ struct fimg2d_bluscr bluscr;
+ struct fimg2d_clip clipping;
+};
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct fimg2d_blit {
+ enum blit_op op;
+ struct fimg2d_param param;
+ struct fimg2d_image *src;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ struct fimg2d_image *msk;
+ struct fimg2d_image *tmp;
+ struct fimg2d_image *dst;
+ enum blit_sync sync;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ unsigned int seq_no;
+};
+#endif
+
index 8074695927f4faec19ec5f86a958daf2b56f1842..bbf0ece9eda0ef357145c51e94198497f741c3e3 100644 (file)
@@ -56,7 +56,7 @@ LOCAL_CFLAGS += -DUSE_SAMSUNG_COLORFORMAT
 
 LOCAL_C_INCLUDES += \
        $(LOCAL_PATH)/../include
-LOCAL_CFLAGS += -DENABLE_GSCALER
+LOCAL_CFLAGS += -DENABLE_GSCALER -DENABLE_G2D
 LOCAL_SHARED_LIBRARIES += libexynosgscaler
 
 LOCAL_CFLAGS += -DUSE_ION
index 11c5b1cb493cc5442bb774358a7dadd8193d334f..0831f612b1ecc5e446f4d376dcbdca8c4ae8560a 100644 (file)
 #include "exynos_gscaler.h"
 #endif
 
+#ifdef ENABLE_G2D
+#include <fcntl.h>
+#include <sys/ioctl.h>
+#include "fimg2d.h"
+
+typedef struct
+{
+    struct fimg2d_image src;
+    struct fimg2d_image dst;
+    int fd;
+} g2d_data;
+#endif
+
 #define GSCALER_IMG_ALIGN 16
 #define ALIGN(x, a)       (((x) + (a) - 1) & ~((a) - 1))
 
@@ -308,6 +321,29 @@ static CSC_ERRORCODE conv_hw(
             ret = CSC_Error;
         }
         break;
+#endif
+#ifdef ENABLE_G2D
+    case CSC_HW_TYPE_G2D:
+    {
+        g2d_data *g2d = (g2d_data *)handle->csc_hw_handle;
+        struct fimg2d_blit blit;
+        int err;
+
+        memset(&blit, 0, sizeof(blit));
+        blit.op = BLIT_OP_SRC_COPY;
+        blit.param.g_alpha = 0xFF;
+        blit.src = &g2d->src;
+        blit.dst = &g2d->dst;
+        blit.sync = BLIT_SYNC;
+
+        err = ioctl(g2d->fd, FIMG2D_BITBLT_BLIT, &blit);
+        if (err < 0) {
+            ALOGE("FIMG2D_BITBLT_BLIT ioctl failed: %s", strerror(errno));
+            ret = CSC_Error;
+        }
+
+        break;
+    }
 #endif
     default:
         ALOGE("%s:: unsupported csc_hw_type(%d)", __func__, handle->csc_hw_type);
@@ -341,10 +377,28 @@ static CSC_ERRORCODE csc_init_hw(
             csc_handle->csc_hw_handle = exynos_gsc_create();
             ALOGV("%s:: CSC_HW_TYPE_GSCALER", __func__);
             break;
+#endif
+#ifdef ENABLE_G2D
+        case CSC_HW_TYPE_G2D:
+        {
+            g2d_data *g2d = calloc(1, sizeof(g2d_data));
+            if (!g2d) {
+                ALOGE("failed to allocate G2D data");
+                break;
+            }
+            g2d->fd = open("/dev/fimg2d", O_RDWR);
+            if (g2d->fd < 0) {
+                ALOGE("failed to open G2D: %s", strerror(errno));
+                free(g2d);
+            } else {
+                csc_handle->csc_hw_handle = g2d;
+            }
+            break;
+        }
 #endif
         default:
             ALOGE("%s:: unsupported csc_hw_type, csc use sw", __func__);
-            csc_handle->csc_hw_handle == NULL;
+            csc_handle->csc_hw_handle = NULL;
             break;
         }
     }
@@ -402,6 +456,42 @@ static CSC_ERRORCODE csc_set_format(
                 csc_handle->hw_property.mode_drm,
                 0);
             break;
+#endif
+#ifdef ENABLE_G2D
+        case CSC_HW_TYPE_G2D:
+        {
+            g2d_data *g2d = (g2d_data *)csc_handle->csc_hw_handle;
+
+            g2d->src.width = ALIGN(csc_handle->src_format.width,
+                    GSCALER_IMG_ALIGN);
+            g2d->src.height = csc_handle->src_format.height;
+            g2d->src.stride = g2d->src.width *
+                    hal_2_g2d_bpp(csc_handle->src_format.color_format) >> 3;
+            g2d->src.order = hal_2_g2d_pixel_order(csc_handle->src_format.color_format);
+            g2d->src.fmt = hal_2_g2d_color_format(csc_handle->src_format.color_format);
+            g2d->src.rect.x1 = csc_handle->src_format.crop_left;
+            g2d->src.rect.y1 = csc_handle->src_format.crop_top;
+            g2d->src.rect.x2 = csc_handle->src_format.crop_left +
+                    csc_handle->src_format.crop_width;
+            g2d->src.rect.y2 = csc_handle->src_format.crop_top +
+                    csc_handle->src_format.crop_height;
+
+            g2d->dst.width = ALIGN(csc_handle->dst_format.width,
+                    GSCALER_IMG_ALIGN);
+            g2d->dst.height = csc_handle->dst_format.height;
+            g2d->dst.stride = g2d->dst.width *
+                    hal_2_g2d_bpp(csc_handle->dst_format.color_format) >> 3;
+            g2d->dst.order = hal_2_g2d_pixel_order(csc_handle->dst_format.color_format);
+            g2d->dst.fmt = hal_2_g2d_color_format(csc_handle->dst_format.color_format);
+            g2d->dst.rect.x1 = csc_handle->dst_format.crop_left;
+            g2d->dst.rect.y1 = csc_handle->dst_format.crop_top;
+            g2d->dst.rect.x2 = csc_handle->dst_format.crop_left +
+                    csc_handle->dst_format.crop_width;
+            g2d->dst.rect.y2 = csc_handle->dst_format.crop_top +
+                    csc_handle->dst_format.crop_height;
+
+            break;
+        }
 #endif
         default:
             ALOGE("%s:: unsupported csc_hw_type", __func__);
@@ -431,6 +521,22 @@ static CSC_ERRORCODE csc_set_buffer(
             exynos_gsc_set_src_addr(csc_handle->csc_hw_handle, csc_handle->src_buffer.planes, -1);
             exynos_gsc_set_dst_addr(csc_handle->csc_hw_handle, csc_handle->dst_buffer.planes, -1);
             break;
+#endif
+#ifdef ENABLE_G2D
+        case CSC_HW_TYPE_G2D:
+        {
+            g2d_data *g2d = (g2d_data *)csc_handle->csc_hw_handle;
+
+            g2d->src.addr.type = ADDR_DMA_BUF;
+            g2d->src.addr.fd[0] = (int)csc_handle->src_buffer.planes[0];
+            g2d->src.addr.fd[1] = (int)csc_handle->src_buffer.planes[1];
+
+            g2d->dst.addr.type = ADDR_DMA_BUF;
+            g2d->dst.addr.fd[0] = (int)csc_handle->dst_buffer.planes[0];
+            g2d->dst.addr.fd[1] = (int)csc_handle->dst_buffer.planes[1];
+
+            break;
+        }
 #endif
         default:
             ALOGE("%s:: unsupported csc_hw_type", __func__);
@@ -475,6 +581,15 @@ CSC_ERRORCODE csc_deinit(
         case CSC_HW_TYPE_GSCALER:
             exynos_gsc_destroy(csc_handle->csc_hw_handle);
             break;
+#endif
+#ifdef ENABLE_G2D
+        case CSC_HW_TYPE_G2D:
+        {
+            g2d_data *g2d = (g2d_data *)csc_handle->csc_hw_handle;
+            close(g2d->fd);
+            free(g2d);
+            break;
+        }
 #endif
         default:
             ALOGE("%s:: unsupported csc_hw_type", __func__);
index e580bd53c60885709c1d05ae5228a74ef66b6f48..9372610ade8713cce54cf7931f711eb47d846c4c 100644 (file)
@@ -87,6 +87,40 @@ unsigned int hal_2_omx_pixel_format(
 unsigned int omx_2_hal_pixel_format(
     unsigned int omx_format);
 
+/*
+ * change hal pixel format to g2d color format
+ *
+ * @param hal_format
+ *   hal pixel format[in]
+ *
+ * @return
+ *   g2d color format
+ */
+unsigned int hal_2_g2d_color_format(unsigned int hal_format);
+
+/*
+ * change hal pixel format to g2d pixel order
+ *
+ * @param hal_format
+ *   hal pixel format[in]
+ *
+ * @return
+ *   g2d pixel order
+ */
+unsigned int hal_2_g2d_pixel_order(unsigned int hal_format);
+
+/*
+ * change hal pixel format to g2d "bpp" (actual bpp for RGB formats, 8 bpp for
+ * YUV formats)
+ *
+ * @param hal_format
+ *   hal pixel format[in]
+ *
+ * @return
+ *   g2d bpp
+ */
+size_t hal_2_g2d_bpp(unsigned int hal_format);
+
 /*
  * Init CSC handle
  *
index c8f869fded1fd56ec43c36d23f699f8383b8ee3a..d5cb4fb2be5e0af1d9cebb8e07f7a6873d43b664 100644 (file)
@@ -24,6 +24,7 @@
 
 #include "csc.h"
 #include "exynos_format.h"
+#include "fimg2d.h"
 
 OMX_COLOR_FORMATTYPE hal_2_omx_pixel_format(
     unsigned int hal_format)
@@ -84,3 +85,89 @@ unsigned int omx_2_hal_pixel_format(
     }
     return hal_format;
 }
+
+unsigned int hal_2_g2d_color_format(unsigned int hal_format)
+{
+    switch (hal_format) {
+    case HAL_PIXEL_FORMAT_RGBA_8888:
+    case HAL_PIXEL_FORMAT_BGRA_8888:
+    case HAL_PIXEL_FORMAT_CUSTOM_ARGB_8888:
+        return CF_ARGB_8888;
+
+    case HAL_PIXEL_FORMAT_RGBX_8888:
+        return CF_XRGB_8888;
+
+    case HAL_PIXEL_FORMAT_RGB_888:
+        return CF_RGB_888;
+
+    case HAL_PIXEL_FORMAT_RGB_565:
+        return CF_RGB_565;
+
+    case HAL_PIXEL_FORMAT_RGBA_5551:
+        return CF_ARGB_1555;
+
+    case HAL_PIXEL_FORMAT_RGBA_4444:
+        return CF_ARGB_4444;
+
+    case HAL_PIXEL_FORMAT_YCbCr_422_I:
+        return CF_YCBCR_422;
+
+    case HAL_PIXEL_FORMAT_YCbCr_420_SP:
+        return CF_YCBCR_420;
+
+    default:
+        return SRC_DST_FORMAT_END;
+    }
+}
+
+unsigned int hal_2_g2d_pixel_order(unsigned int hal_format)
+{
+    switch (hal_format) {
+    case HAL_PIXEL_FORMAT_BGRA_8888:
+    case HAL_PIXEL_FORMAT_CUSTOM_ARGB_8888:
+        return AX_BGR;
+
+    case HAL_PIXEL_FORMAT_RGBA_8888:
+    case HAL_PIXEL_FORMAT_RGBX_8888:
+    case HAL_PIXEL_FORMAT_RGB_888:
+    case HAL_PIXEL_FORMAT_RGB_565:
+    case HAL_PIXEL_FORMAT_RGBA_5551:
+    case HAL_PIXEL_FORMAT_RGBA_4444:
+        return RGB_AX;
+
+    case HAL_PIXEL_FORMAT_YCbCr_422_I:
+        return P1_Y1CBY0CR;
+
+    case HAL_PIXEL_FORMAT_YCbCr_420_SP:
+        return P2_CBCR;
+
+    default:
+        return ARGB_ORDER_END;
+    }
+}
+
+size_t hal_2_g2d_bpp(unsigned int hal_format)
+{
+    switch (hal_format) {
+        case HAL_PIXEL_FORMAT_BGRA_8888:
+        case HAL_PIXEL_FORMAT_CUSTOM_ARGB_8888:
+        case HAL_PIXEL_FORMAT_RGBA_8888:
+        case HAL_PIXEL_FORMAT_RGBX_8888:
+            return 32;
+
+        case HAL_PIXEL_FORMAT_RGB_888:
+            return 24;
+
+        case HAL_PIXEL_FORMAT_RGB_565:
+        case HAL_PIXEL_FORMAT_RGBA_5551:
+        case HAL_PIXEL_FORMAT_RGBA_4444:
+            return 16;
+
+        case HAL_PIXEL_FORMAT_YCbCr_422_I:
+        case HAL_PIXEL_FORMAT_YCbCr_420_SP:
+            return 8;
+
+        default:
+            return 0;
+        }
+}
diff --git a/original-kernel-headers/linux/fimg2d.h b/original-kernel-headers/linux/fimg2d.h
new file mode 100644 (file)
index 0000000..ceda93c
--- /dev/null
@@ -0,0 +1,465 @@
+/* linux/drivers/media/video/samsung/fimg2d4x/fimg2d.h
+ *
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd.
+ *     http://www.samsung.com/
+ *
+ * Samsung Graphics 2D driver
+ *
+ * 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.
+*/
+
+#ifndef __FIMG2D_H
+#define __FIMG2D_H __FILE__
+
+#ifdef __KERNEL__
+
+#include <linux/clk.h>
+#include <linux/list.h>
+#include <linux/device.h>
+#include <linux/workqueue.h>
+#include <linux/platform_device.h>
+#include <linux/atomic.h>
+#include <linux/dma-mapping.h>
+#include <linux/dma-buf.h>
+
+#define FIMG2D_MINOR                   (240)
+#define to_fimg2d_plat(d)              (to_platform_device(d)->dev.platform_data)
+
+#ifdef CONFIG_VIDEO_FIMG2D_DEBUG
+#define fimg2d_debug(fmt, arg...)      printk(KERN_INFO "[%s] " fmt, __func__, ## arg)
+#else
+#define fimg2d_debug(fmt, arg...)      do { } while (0)
+#endif
+
+#endif /* __KERNEL__ */
+
+#define FIMG2D_MAX_PLANES      2
+
+/* ioctl commands */
+#define FIMG2D_IOCTL_MAGIC     'F'
+#define FIMG2D_BITBLT_BLIT     _IOWR(FIMG2D_IOCTL_MAGIC, 0, struct fimg2d_blit)
+#define FIMG2D_BITBLT_SYNC     _IOW(FIMG2D_IOCTL_MAGIC, 1, int)
+#define FIMG2D_BITBLT_VERSION  _IOR(FIMG2D_IOCTL_MAGIC, 2, struct fimg2d_version)
+
+struct fimg2d_version {
+       unsigned int hw;
+       unsigned int sw;
+};
+
+/**
+ * @BLIT_SYNC: sync mode, to wait for blit done irq
+ * @BLIT_ASYNC: async mode, not to wait for blit done irq
+ *
+ */
+enum blit_sync {
+       BLIT_SYNC,
+       BLIT_ASYNC,
+};
+
+/**
+ * @ADDR_NONE: no image/solid color
+ * @ADDR_DMA_BUF: dma-buf fds
+ */
+enum addr_space {
+       ADDR_NONE = 0,
+       ADDR_DMA_BUF,
+};
+
+/**
+ * Pixel order complies with little-endian style
+ *
+ * DO NOT CHANGE THIS ORDER
+ */
+enum pixel_order {
+       AX_RGB = 0,
+       RGB_AX,
+       AX_BGR,
+       BGR_AX,
+       ARGB_ORDER_END,
+
+       P1_CRY1CBY0,
+       P1_CBY1CRY0,
+       P1_Y1CRY0CB,
+       P1_Y1CBY0CR,
+       P1_ORDER_END,
+
+       P2_CRCB,
+       P2_CBCR,
+       P2_ORDER_END,
+};
+
+/**
+ * DO NOT CHANGE THIS ORDER
+ */
+enum color_format {
+       CF_XRGB_8888 = 0,
+       CF_ARGB_8888,
+       CF_RGB_565,
+       CF_XRGB_1555,
+       CF_ARGB_1555,
+       CF_XRGB_4444,
+       CF_ARGB_4444,
+       CF_RGB_888,
+       CF_YCBCR_444,
+       CF_YCBCR_422,
+       CF_YCBCR_420,
+       CF_A8,
+       CF_L8,
+       SRC_DST_FORMAT_END,
+
+       CF_MSK_1BIT,
+       CF_MSK_4BIT,
+       CF_MSK_8BIT,
+       CF_MSK_16BIT_565,
+       CF_MSK_16BIT_1555,
+       CF_MSK_16BIT_4444,
+       CF_MSK_32BIT_8888,
+       MSK_FORMAT_END,
+};
+
+enum rotation {
+       ORIGIN,
+       ROT_90, /* clockwise */
+       ROT_180,
+       ROT_270,
+       XFLIP,  /* x-axis flip */
+       YFLIP,  /* y-axis flip */
+};
+
+/**
+ * @NO_REPEAT: no effect
+ * @REPEAT_NORMAL: repeat horizontally and vertically
+ * @REPEAT_PAD: pad with pad color
+ * @REPEAT_REFLECT: reflect horizontally and vertically
+ * @REPEAT_CLAMP: pad with edge color of original image
+ *
+ * DO NOT CHANGE THIS ORDER
+ */
+enum repeat {
+       NO_REPEAT = 0,
+       REPEAT_NORMAL,  /* default setting */
+       REPEAT_PAD,
+       REPEAT_REFLECT, REPEAT_MIRROR = REPEAT_REFLECT,
+       REPEAT_CLAMP,
+};
+
+enum scaling {
+       NO_SCALING,
+       SCALING_NEAREST,
+       SCALING_BILINEAR,
+};
+
+/**
+ * @SCALING_PIXELS: ratio in pixels
+ * @SCALING_RATIO: ratio in fixed point 16
+ */
+enum scaling_factor {
+       SCALING_PIXELS,
+       SCALING_RATIO,
+};
+
+/**
+ * premultiplied alpha
+ */
+enum premultiplied {
+       PREMULTIPLIED,
+       NON_PREMULTIPLIED,
+};
+
+/**
+ * @TRANSP: discard bluescreen color
+ * @BLUSCR: replace bluescreen color with background color
+ */
+enum bluescreen {
+       OPAQUE,
+       TRANSP,
+       BLUSCR,
+};
+
+/**
+ * DO NOT CHANGE THIS ORDER
+ */
+enum blit_op {
+       BLIT_OP_SOLID_FILL = 0,
+
+       BLIT_OP_CLR,
+       BLIT_OP_SRC, BLIT_OP_SRC_COPY = BLIT_OP_SRC,
+       BLIT_OP_DST,
+       BLIT_OP_SRC_OVER,
+       BLIT_OP_DST_OVER, BLIT_OP_OVER_REV = BLIT_OP_DST_OVER,
+       BLIT_OP_SRC_IN,
+       BLIT_OP_DST_IN, BLIT_OP_IN_REV = BLIT_OP_DST_IN,
+       BLIT_OP_SRC_OUT,
+       BLIT_OP_DST_OUT, BLIT_OP_OUT_REV = BLIT_OP_DST_OUT,
+       BLIT_OP_SRC_ATOP,
+       BLIT_OP_DST_ATOP, BLIT_OP_ATOP_REV = BLIT_OP_DST_ATOP,
+       BLIT_OP_XOR,
+
+       BLIT_OP_ADD,
+       BLIT_OP_MULTIPLY,
+       BLIT_OP_SCREEN,
+       BLIT_OP_DARKEN,
+       BLIT_OP_LIGHTEN,
+
+       BLIT_OP_DISJ_SRC_OVER,
+       BLIT_OP_DISJ_DST_OVER, BLIT_OP_SATURATE = BLIT_OP_DISJ_DST_OVER,
+       BLIT_OP_DISJ_SRC_IN,
+       BLIT_OP_DISJ_DST_IN, BLIT_OP_DISJ_IN_REV = BLIT_OP_DISJ_DST_IN,
+       BLIT_OP_DISJ_SRC_OUT,
+       BLIT_OP_DISJ_DST_OUT, BLIT_OP_DISJ_OUT_REV = BLIT_OP_DISJ_DST_OUT,
+       BLIT_OP_DISJ_SRC_ATOP,
+       BLIT_OP_DISJ_DST_ATOP, BLIT_OP_DISJ_ATOP_REV = BLIT_OP_DISJ_DST_ATOP,
+       BLIT_OP_DISJ_XOR,
+
+       BLIT_OP_CONJ_SRC_OVER,
+       BLIT_OP_CONJ_DST_OVER, BLIT_OP_CONJ_OVER_REV = BLIT_OP_CONJ_DST_OVER,
+       BLIT_OP_CONJ_SRC_IN,
+       BLIT_OP_CONJ_DST_IN, BLIT_OP_CONJ_IN_REV = BLIT_OP_CONJ_DST_IN,
+       BLIT_OP_CONJ_SRC_OUT,
+       BLIT_OP_CONJ_DST_OUT, BLIT_OP_CONJ_OUT_REV = BLIT_OP_CONJ_DST_OUT,
+       BLIT_OP_CONJ_SRC_ATOP,
+       BLIT_OP_CONJ_DST_ATOP, BLIT_OP_CONJ_ATOP_REV = BLIT_OP_CONJ_DST_ATOP,
+       BLIT_OP_CONJ_XOR,
+
+       /* user select coefficient manually */
+       BLIT_OP_USER_COEFF,
+
+       BLIT_OP_USER_SRC_GA,
+
+       /* Add new operation type here */
+
+       /* end of blit operation */
+       BLIT_OP_END,
+};
+#define MAX_FIMG2D_BLIT_OP (int)BLIT_OP_END
+
+#ifdef __KERNEL__
+
+/**
+ * @TMP: temporary buffer for 2-step blit at a single command
+ *
+ * DO NOT CHANGE THIS ORDER
+ */
+enum image_object {
+       IMAGE_SRC = 0,
+       IMAGE_MSK,
+       IMAGE_TMP,
+       IMAGE_DST,
+       IMAGE_END,
+};
+#define MAX_IMAGES             IMAGE_END
+#define ISRC                   IMAGE_SRC
+#define IMSK                   IMAGE_MSK
+#define ITMP                   IMAGE_TMP
+#define IDST                   IMAGE_DST
+#define image_table(u)         \
+       {                       \
+               (u)->src,       \
+               (u)->msk,       \
+               (u)->tmp,       \
+               (u)->dst        \
+       }
+
+struct fimg2d_dma {
+       struct dma_buf *dma_buf;
+       struct dma_buf_attachment *attachment;
+       struct sg_table *sg_table;
+       dma_addr_t dma_addr;
+       enum dma_data_direction direction;
+};
+
+#endif /* __KERNEL__ */
+
+struct fimg2d_addr {
+       enum addr_space type;
+       int fd[FIMG2D_MAX_PLANES];
+};
+
+struct fimg2d_rect {
+       int x1;
+       int y1;
+       int x2; /* x1 + width */
+       int y2; /* y1 + height */
+};
+
+/**
+ * pixels can be different from src, dst or clip rect
+ */
+struct fimg2d_scale {
+       enum scaling mode;
+
+       /* ratio in pixels */
+       int src_w, src_h;
+       int dst_w, dst_h;
+};
+
+struct fimg2d_clip {
+       __u32 enable;
+       int x1;
+       int y1;
+       int x2; /* x1 + width */
+       int y2; /* y1 + height */
+};
+
+struct fimg2d_repeat {
+       enum repeat mode;
+       unsigned long pad_color;
+};
+
+/**
+ * @bg_color: bg_color is valid only if bluescreen mode is BLUSCR.
+ */
+struct fimg2d_bluscr {
+       enum bluescreen mode;
+       unsigned long bs_color;
+       unsigned long bg_color;
+};
+
+/**
+ * @plane2: address info for CbCr in YCbCr 2plane mode
+ * @rect: crop/clip rect
+ */
+struct fimg2d_image {
+       int width;
+       int height;
+       int stride;
+       enum pixel_order order;
+       enum color_format fmt;
+       struct fimg2d_addr addr;
+       struct fimg2d_rect rect;
+};
+
+/**
+ * @solid_color:
+ *         src color instead of src image
+ *         color format and order must be ARGB8888(A is MSB).
+ * @g_alpha: global(constant) alpha. 0xff is opaque, 0 is transparnet
+ * @dither: dithering
+ * @rotate: rotation degree in clockwise
+ * @premult: alpha premultiplied mode for read & write
+ * @scaling: common scaling info for src and mask image.
+ * @repeat: repeat type (tile mode)
+ * @bluscr: blue screen and transparent mode
+ * @clipping: clipping rect within dst rect
+ */
+struct fimg2d_param {
+       unsigned long solid_color;
+       unsigned char g_alpha;
+       __u32 dither;
+       enum rotation rotate;
+       enum premultiplied premult;
+       struct fimg2d_scale scaling;
+       struct fimg2d_repeat repeat;
+       struct fimg2d_bluscr bluscr;
+       struct fimg2d_clip clipping;
+};
+
+/**
+ * @op: blit operation mode
+ * @src: set when using src image
+ * @msk: set when using mask image
+ * @tmp: set when using 2-step blit at a single command
+ * @dst: dst must not be null
+ *         * tmp image must be the same to dst except memory address
+ * @seq_no: user debugging info.
+ *          for example, user can set sequence number or pid.
+ */
+struct fimg2d_blit {
+       enum blit_op op;
+       struct fimg2d_param param;
+       struct fimg2d_image *src;
+       struct fimg2d_image *msk;
+       struct fimg2d_image *tmp;
+       struct fimg2d_image *dst;
+       enum blit_sync sync;
+       unsigned int seq_no;
+};
+
+#ifdef __KERNEL__
+
+/**
+ * @ncmd: request count in blit command queue
+ * @wait_q: conext wait queue head
+*/
+struct fimg2d_context {
+       atomic_t ncmd;
+       wait_queue_head_t wait_q;
+};
+
+/**
+ * @op: blit operation mode
+ * @sync: sync/async blit mode (currently support sync mode only)
+ * @image: array of image object.
+ *         [0] is for src image
+ *         [1] is for mask image
+ *         [2] is for temporary buffer
+ *             set when using 2-step blit at a single command
+ *         [3] is for dst, dst must not be null
+ *         * tmp image must be the same to dst except memory address
+ * @seq_no: user debugging info.
+ *          for example, user can set sequence number or pid.
+ * @dma_all: total dma size of src, msk, dst
+ * @dma: array of dma info for each src, msk, tmp and dst
+ * @ctx: context is created when user open fimg2d device.
+ * @node: list head of blit command queue
+ */
+struct fimg2d_bltcmd {
+       enum blit_op op;
+       enum blit_sync sync;
+       unsigned int seq_no;
+       struct fimg2d_param param;
+       struct fimg2d_image image[MAX_IMAGES];
+       struct fimg2d_dma dma[MAX_IMAGES][FIMG2D_MAX_PLANES];
+       struct fimg2d_context *ctx;
+       struct list_head node;
+};
+
+/**
+ * @suspended: in suspend mode
+ * @clkon: power status for runtime pm
+ * @mem: resource platform device
+ * @regs: base address of hardware
+ * @dev: pointer to device struct
+ * @err: true if hardware is timed out while blitting
+ * @irq: irq number
+ * @nctx: context count
+ * @busy: 1 if hardware is running
+ * @bltlock: spinlock for blit
+ * @wait_q: blit wait queue head
+ * @cmd_q: blit command queue
+ * @workqueue: workqueue_struct for kfimg2dd
+*/
+struct fimg2d_control {
+       atomic_t suspended;
+       atomic_t clkon;
+       struct clk *clock;
+       struct device *dev;
+       struct resource *mem;
+       void __iomem *regs;
+
+       bool err;
+       int irq;
+       atomic_t nctx;
+       atomic_t busy;
+       atomic_t active;
+       spinlock_t bltlock;
+       wait_queue_head_t wait_q;
+       struct list_head cmd_q;
+       struct workqueue_struct *work_q;
+
+       void (*blit)(struct fimg2d_control *info);
+       int (*configure)(struct fimg2d_control *info,
+                       struct fimg2d_bltcmd *cmd);
+       void (*run)(struct fimg2d_control *info);
+       void (*stop)(struct fimg2d_control *info);
+       void (*dump)(struct fimg2d_control *info);
+       void (*finalize)(struct fimg2d_control *info);
+};
+
+int fimg2d_register_ops(struct fimg2d_control *info);
+
+#endif /* __KERNEL__ */
+
+#endif /* __FIMG2D_H__ */