media: jpeg: add driver for a version 2.x of jpeg H/W
PATCH 1/1 media: jpeg: add driver for a version 2.x of jpeg H/W
This patch add a driver for a version 2.x of jpeg H/W in ths Samsung Exynos5 Soc.
A jpeg H/W version of Exynos4 SoC is 3.0
1. Encoding
- input format : V4L2_PIX_FMT_RGB565X and V4L2_PIX_FMT_YUYV
2. Decoding
- output format : V4L2_PIX_FMT_YUYV and V4L2_PIX_FMT_YUV420
--- drivers/media/video/Kconfig | 17 + drivers/media/video/s5p-jpeg/Makefile | 5 +- drivers/media/video/s5p-jpeg/jpeg-core.c | 303 +------------------- drivers/media/video/s5p-jpeg/jpeg-hw-common.h | 34 +++ drivers/media/video/s5p-jpeg/jpeg-hw-v2x.h | 387 +++++++++++++++++++++++++ drivers/media/video/s5p-jpeg/jpeg-regs-v2x.h | 150 ++++++++++ drivers/media/video/s5p-jpeg/jpeg-v2x.c | 129 ++++++++ drivers/media/video/s5p-jpeg/jpeg-v3.c | 340 ++++++++++++++++++++++ 8 files changed, 1066 insertions(+), 299 deletions(-) create mode 100644 drivers/media/video/s5p-jpeg/jpeg-hw-common.h create mode 100644 drivers/media/video/s5p-jpeg/jpeg-hw-v2x.h create mode 100644 drivers/media/video/s5p-jpeg/jpeg-regs-v2x.h create mode 100644 drivers/media/video/s5p-jpeg/jpeg-v2x.c create mode 100644 drivers/media/video/s5p-jpeg/jpeg-v3.c
drivers/media/video/Kconfig +17 -0
@@ -1167,6 +1167,23 @@ config VIDEO_SAMSUNG_S5P_JPEG select V4L2_MEM2MEM_DEV ---help--- This is a v4l2 driver for Samsung S5P and EXYNOS4 JPEG codec +choice + prompt "JPEG V4L2 Driver" + default S5P_JPEG_V3 + depends on VIDEO_SAMSUNG_S5P_JPEG + ---help--- + Select version of MFC driver + +config S5P_JPEG_V3 + bool "JPEG 3.x" + ---help--- + Use JPEG 3.x V4L2 Driver + +config S5P_JPEG_V2 + bool "JPEG 2.x" + ---help--- + Use JPEG 2.x V4L2 Driver +endchoice config VIDEO_SAMSUNG_S5P_MFC tristate "Samsung S5P MFC 5.1 Video Codec"
drivers/media/video/s5p-jpeg/Makefile +4 -1
@@ -1,2 +1,5 @@ -s5p-jpeg-objs := jpeg-core.o obj-$(CONFIG_VIDEO_SAMSUNG_S5P_JPEG) := s5p-jpeg.o + +s5p-jpeg-objs := jpeg-core.o +obj-$(CONFIG_S5P_JPEG_V3) += jpeg-v3.o +obj-$(CONFIG_S5P_JPEG_V2) += jpeg-v2x.o
drivers/media/video/s5p-jpeg/jpeg-core.c +5 -298
333 lines not on this page · raw message
drivers/media/video/s5p-jpeg/jpeg-hw-common.h new file +34 -0
@@ -0,0 +1,34 @@ +/* linux/drivers/media/video/s5p-jpeg/jpeg-hw.h +* +* Copyright (c) 2011 Samsung Electronics Co., Ltd. +* http://www.samsung.com +* +* Author: Andrzej Pietrasiewicz <[email protected]> +* +* 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 JPEG_HW_COMMON_H_ +#define JPEG_HW_COMMON_H_ + +#include <linux/io.h> +#include <linux/delay.h> + +void s5p_jpeg_execute (void *priv); +void s5p_jpeg_irq_execute (void *dev_id); +void s5p_jpeg_runtime_resume_execute (struct device *dev); + +#define S5P_JPEG_MIN_WIDTH 32 +#define S5P_JPEG_MIN_HEIGHT 32 +#define S5P_JPEG_MAX_WIDTH 8192 +#define S5P_JPEG_MAX_HEIGHT 8192 +#define S5P_JPEG_ENCODE 0 +#define S5P_JPEG_DECODE 1 +#define S5P_JPEG_RAW_IN_565 0 +#define S5P_JPEG_RAW_IN_422 1 +#define S5P_JPEG_SUBSAMPLING_422 0 +#define S5P_JPEG_SUBSAMPLING_420 1 +#define S5P_JPEG_RAW_OUT_422 0 +#define S5P_JPEG_RAW_OUT_420 1 +#endif /* JPEG_HW_COMMON_H_ */
drivers/media/video/s5p-jpeg/jpeg-hw-v2x.h new file +387 -0
387 lines not on this page · raw message
drivers/media/video/s5p-jpeg/jpeg-regs-v2x.h new file +150 -0
150 lines not on this page · raw message
drivers/media/video/s5p-jpeg/jpeg-v2x.c new file +129 -0
129 lines not on this page · raw message
drivers/media/video/s5p-jpeg/jpeg-v3.c new file +340 -0
340 lines not on this page · raw message
Signature · 1 line
1.7.1
Hi 송영목,
Quoted 1 line · 송영목
This patch add a driver for a version 2.x of jpeg H/W
s/add/adds
Quoted 1 line
in ths Samsung Exynos5 Soc.
s/ths/the
Quoted 7 lines
A jpeg H/W version of Exynos4 SoC is 3.0
1. Encoding
- input format :V4L2_PIX_FMT_RGB565XandV4L2_PIX_FMT_YUYV2. Decoding
- output format :V4L2_PIX_FMT_YUYVandV4L2_PIX_FMT_YUV420
Please consider reworking this patch so it can be applied on the latest s5p-jpeg driver changes adding JPEG controls:
http://git.infradead.org/users/kmpark/linux-2.6-samsung/shortlog/refs/heads/media-for-next
Quoted 1 line
Signed-off-by youngmok song<[email protected]>
Normally the full name starts with capital letters.
Quoted 21 lines
--- drivers/media/video/Kconfig | 17 + drivers/media/video/s5p-jpeg/Makefile | 5 +- drivers/media/video/s5p-jpeg/jpeg-core.c | 303 +------------------- drivers/media/video/s5p-jpeg/jpeg-hw-common.h | 34 +++ drivers/media/video/s5p-jpeg/jpeg-hw-v2x.h | 387 +++++++++++++++++++++++++ drivers/media/video/s5p-jpeg/jpeg-regs-v2x.h | 150 ++++++++++ drivers/media/video/s5p-jpeg/jpeg-v2x.c | 129 ++++++++ drivers/media/video/s5p-jpeg/jpeg-v3.c | 340 ++++++++++++++++++++++ 8 files changed, 1066 insertions(+), 299 deletions(-)create mode 100644
drivers/media/video/s5p-jpeg/jpeg-hw-common.hcreate mode 100644drivers/media/video/s5p-jpeg/jpeg-hw-v2x.hcreate mode 100644drivers/media/video/s5p-jpeg/jpeg-regs-v2x.hcreate mode 100644drivers/media/video/s5p-jpeg/jpeg-v2x.ccreate mode 100644drivers/media/video/s5p-jpeg/jpeg-v3.cdrivers/media/video/Kconfig +0
-0
drivers/media/video/Kconfig config VIDEO_SAMSUNG_S5P_JPEG · line 1175
Quoted 9 lines
drivers/media/video/Kconfig +6
-0@@ -1167,6 +1167,23 @@ config VIDEO_SAMSUNG_S5P_JPEG select V4L2_MEM2MEM_DEV ---help--- This is a v4l2 driver for Samsung S5P and EXYNOS4 JPEG codec +choice + prompt "JPEG V4L2 Driver" + default S5P_JPEG_V3 + depends on VIDEO_SAMSUNG_S5P_JPEG + ---help--- + Select version of MFC driver
MFC ?
drivers/media/video/Kconfig config VIDEO_SAMSUNG_S5P_JPEG · line 1186
Quoted 10 lines
drivers/media/video/Kconfig +10
-0+config S5P_JPEG_V3 + bool "JPEG 3.x" + ---help--- + Use JPEG 3.x V4L2 Driver + +config S5P_JPEG_V2 + bool "JPEG 2.x" + ---help--- + Use JPEG 2.x V4L2 Driver +endchoice
How the user is supposed to know which JPEG IP version applies to which SoC ?
Generally, resolving the hardware differences at compile time is not something that we would want. I suggest using struct platform_device_id for handling different H/W variants, like it is done for example in drivers/dma/imx-sdma.c (see sdma_devtypes table). It will ease the driver's adaptation to instantiation from the device tree, which is important, since the exynos5 is supposed to be a DT only platform.
Probably even function pointers at the variant data structure wouldn't hurt, if there is too many differences to handle them through single flags. From a quick review it feels like the code could be consolidated more, but I'm going to leave commenting on the details for Andrzej.
Please have a look at the JPEG controls:
http://git.infradead.org/users/kmpark/linux-samsung/commitdiff/e0122eabd2be3f0a3a9ff635df81e5c2509c4700
and feel free to propose anything you think is missing there (the Huffman and the quantization tables will need their own ioctl(s)).
As a side note, please don't use Korean characters in the patch message. This implies the character set other than ascii/utf-8 and and makes patches impossible to apply.
--
Regards,
Sylwester
Hello송영목,
In general I think the v2x support should be designed to require as little code changes as possible, and they should be related to pure hardware differences only. Please see comments inline.
The tables (quantization, Huffman) logically contain mostly the same data both in v3 and v2x and are defined by respective standards. Only the arrangement of data is slightly different (bytes vs 4-byte words). Please see comments inline.
On, March 02, 2012 12:47 AM 송영목 wrote:
<...>
Quoted 5 lines
drivers/media/video/s5p-jpeg/jpeg-core.c +0
-0
<...>
Quoted 1 line
(quoted diff) +0
-0
<...>
Quoted 1 line
drivers/media/video/s5p-jpeg/jpeg-core.c +0
-0@@ -0,0 +1,387 @@
<...>
drivers/media/video/s5p-jpeg/jpeg-core.c
Quoted 13 lines
drivers/media/video/s5p-jpeg/jpeg-core.c +13
-0+ +#define S5P_JPEG_MIN_WIDTH 32 +#define S5P_JPEG_MIN_HEIGHT 32 +#define S5P_JPEG_MAX_WIDTH 8192 +#define S5P_JPEG_MAX_HEIGHT 8192 +#define S5P_JPEG_ENCODE 0 +#define S5P_JPEG_DECODE 1 +#define S5P_JPEG_RAW_IN_565 0 +#define S5P_JPEG_RAW_IN_422 1 +#define S5P_JPEG_SUBSAMPLING_422 0 +#define S5P_JPEG_SUBSAMPLING_420 1 +#define S5P_JPEG_RAW_OUT_422 0 +#define S5P_JPEG_RAW_OUT_420 1
This is a verbatim copy of what is defined in jpeg-hw-common.h and should not be repeated here. Use jpeg-hw-common.h.
Quoted 15 lines
drivers/media/video/s5p-jpeg/jpeg-core.c +15
-0+/* Q-table for JPEG */ +/* ITU standard Q-table */ +static unsigned int ITU_Q_tbl[4 ][16 ] = { + { +0x01010101 ,0x01020303 ,0x01010101 ,0x01030303 ,/* Y */ +0x01010101 ,0x02030303 ,0x01010101 ,0x03040403 , +0x01010203 ,0x03050504 ,0x01020303 ,0x04050605 , +0x02030404 ,0x05060605 ,0x04050505 ,0x06050505 + } , { +0x01010102 ,0x05050505 ,0x01010103 ,0x05050505 ,/* CbCr */ +0x01010503 ,0x05050505 ,0x02030505 ,0x05050505 , +0x05050505 ,0x05050505 ,0x05050505 ,0x05050505 , +0x05050505 ,0x05050505 ,0x05050505 ,0x05050505 + } , { +0x05020205 ,0x0a161e25 ,0x02020307 ,0x0c232521 ,/* Y */
drivers/media/video/s5p-jpeg/jpeg-core.c
Quoted 10 lines
drivers/media/video/s5p-jpeg/jpeg-core.c +10
-0+ 0x0302050a, 0x16222b22, 0x0305090e, 0x1e393326, + 0x06091422, 0x2a384431, 0x0a122118, 0x34454b3c, + 0x1d283238, 0x44525142, 0x2d3c3e40, 0x4a424441 + } , { +0x05020205 ,0x251e160a ,0x07030202 ,0x2125230c ,/* CbCr */ +0x0a050203 ,0x222b2216 ,0x0e090503 ,0x2633391e , +0x22140906 ,0x3144382a ,0x1821120a ,0x3c4b4534 , +0x3832281d ,0x42515244 ,0x403e3c2d ,0x4144424a + } +};
This array is static so this makes all users of this header file allocate it. Why not put it into jpeg-v2x.c? (however, see below for considerations about duplication)
This comment applies to all array definitions of this kind in this file.
drivers/media/video/s5p-jpeg/jpeg-core.c
Quoted 5 lines
drivers/media/video/s5p-jpeg/jpeg-core.c +5
-0+ +/* ITU Luminace Huffman Table */ +static unsigned int ITU_H_tbl_len_DC_luminance[4 ] = { +0x01050100 ,0x01010101 ,0x00000001 ,0x00000000 +};
This is in fact the same thing as hdctbl0[16] in jpeg v3, only arranged in 4-byte words. It would be nice if the same definitions were used in both versions. This applies to all tables defined here.
drivers/media/video/s5p-jpeg/jpeg-core.c
Quoted 3 lines
drivers/media/video/s5p-jpeg/jpeg-core.c +3
-0+static unsigned int ITU_H_tbl_val_DC_luminance[3 ] = { +0x03020100 ,0x07060504 ,0x0b0a0908 +};
The same thing as hdctblg0[12] in jpeg v3.
<...>
drivers/media/video/s5p-jpeg/jpeg-core.c
Quoted 3 lines
drivers/media/video/s5p-jpeg/jpeg-core.c +3
-0+static unsigned int ITU_H_tbl_val_DC_chrominance[3 ] = { +0x03020100 ,0x07060504 ,0x0b0a0908 +};
The same thing as as hdctblg0[12] in jpeg v3 and
ITU_H_tbl_val_DC_luminance[3] in your code.
drivers/media/video/s5p-jpeg/jpeg-core.c
Quoted 5 lines
drivers/media/video/s5p-jpeg/jpeg-core.c +5
-0+ +static unsigned int ITU_H_tbl_len_AC_luminance[4 ] = { +0x03010200 ,0x03040203 ,0x04040505 ,0x7d010000 +}; +
The same thing as hactbl0[16] in jpeg v3.
Quoted 4 lines
drivers/media/video/s5p-jpeg/jpeg-core.c +4
-0+static unsigned int ITU_H_tbl_val_AC_luminance[41 ] = { +0x00030201 ,0x12051104 ,0x06413121 ,0x07615113 , +0x32147122 ,0x08a19181 ,0xc1b14223 ,0xf0d15215 , +0x72623324 ,0x160a0982 ,0x1a191817 ,0x28272625 ,
drivers/media/video/s5p-jpeg/jpeg-core.c
Quoted 10 lines
drivers/media/video/s5p-jpeg/jpeg-core.c +10
-0+0x35342a29 ,0x39383736 ,0x4544433a ,0x49484746 , +0x5554534a ,0x59585756 ,0x6564635a ,0x69686766 , +0x7574736a ,0x79787776 ,0x8584837a ,0x89888786 , +0x9493928a ,0x98979695 ,0xa3a29a99 ,0xa7a6a5a4 , +0xb2aaa9a8 ,0xb6b5b4b3 ,0xbab9b8b7 ,0xc5c4c3c2 , +0xc9c8c7c6 ,0xd4d3d2ca ,0xd8d7d6d5 ,0xe2e1dad9 , +0xe6e5e4e3 ,0xeae9e8e7 ,0xf4f3f2f1 ,0xf8f7f6f5 , +0x0000faf9 +}; +
The same thing as hactblg0[162] in jpeg v3.
<...>
drivers/media/video/s5p-jpeg/jpeg-core.c
Quoted 10 lines
drivers/media/video/s5p-jpeg/jpeg-core.c +10
-0+ +static inline void jpeg_reset (void __iomem *regs) +{ +unsigned long reg; + + reg =readl (regs +S5P_JPEG_CNTL_REG ); +writel (reg & ~S5P_JPEG_SOFT_RESET_HI , + regs +S5P_JPEG_CNTL_REG ); + +ndelay (100000 );
Why not use usleep_range?
<...>
Quoted 7 lines
drivers/media/video/s5p-jpeg/jpeg-core.c +7
-0+static inline void jpeg_proc_mode (void __iomem *regs,unsigned long mode) +{ +unsigned int reg, m; + + m =S5P_JPEG_DEC_MODE ; +if (mode ==S5P_JPEG_ENCODE ) + m =S5P_JPEG_ENC_MODE ;
drivers/media/video/s5p-jpeg/jpeg-core.c
Quoted 10 lines
drivers/media/video/s5p-jpeg/jpeg-core.c +10
-0+else + m =S5P_JPEG_DEC_MODE ; + + reg =readl (regs +S5P_JPEG_CNTL_REG ); + reg &=S5P_JPEG_ENC_DEC_MODE_MASK ; + reg |= m; + +writel (reg, regs +S5P_JPEG_CNTL_REG ); +} +
This function is in fact an exact copy of its counterpart in v3. The difference is in the name of the constant which names the register (S5P_JPEG_CNTL_REG vs S5P_JPEGMOD), however,
the value of this constant is 0x00 in both cases. The numeric values of ENC/COMPR and DEC/DECOMPR constants are different, but I believe this could be mitigated some other way. What is important is that the 2 functions serve the same purpose and so should be factored out to some common code.
<...>
Quoted 1 line
+static inline void jpeg_subsampling_mode(void
__iomem*regs, unsigned
long
Quoted 7 lines
mode)
drivers/media/video/s5p-jpeg/jpeg-core.c +6
-0+{ +unsigned long reg, m; + + m =S5P_JPEG_ENC_FMT_YUV_422 ; +if (mode ==S5P_JPEG_SUBSAMPLING_422 ) + m =S5P_JPEG_ENC_FMT_YUV_422 ;
drivers/media/video/s5p-jpeg/jpeg-core.c
Quoted 10 lines
drivers/media/video/s5p-jpeg/jpeg-core.c +10
-0+else if (mode ==S5P_JPEG_SUBSAMPLING_420 ) + m =S5P_JPEG_ENC_FMT_YUV_420 ; + + reg =readl (regs +S5P_JPEG_IMG_FMT_REG ); + reg &= ~S5P_JPEG_ENC_FMT_MASK ; + reg |= m; + +writel (reg, regs +S5P_JPEG_IMG_FMT_REG ); +} +
The same here.
<...>
drivers/media/video/s5p-jpeg/jpeg-core.c
Quoted 6 lines
drivers/media/video/s5p-jpeg/jpeg-core.c +6
-0+ +static inline void jpeg_jpgadr (void __iomem *regs,unsigned long addr) +{ +writel (addr, regs +S5P_JPEG_OUT_MEM_BASE_REG ); +} +
The same here.
<...>
Quoted 1 line
+static inline void jpeg_enc_imgadr(void
__iomem*regs, unsigned long
addr)
drivers/media/video/s5p-jpeg/jpeg-core.c
Quoted 4 lines
drivers/media/video/s5p-jpeg/jpeg-core.c +4
-0+{ +writel (addr, regs +S5P_JPEG_IMG_BA_PLANE_1_REG ); +} +
This looks like jpeg_imgadr() from v3.
<...>
Quoted 73 lines
drivers/media/video/s5p-jpeg/jpeg-regs-v2x.h new file +39
-0@@ -0,0 +1,150 @@ +/* linux/drivers/media/video/s5p-jpeg/jpeg-regs-v2x.h +* +* Register definition file for Samsung JPEG codec driver +* +* Copyright (c) 2012 Samsung Electronics Co., Ltd. +* http:www.samsung.com +* +* +* 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 JPEG_REGS_H_ +#define JPEG_REGS_H_ + +/* JPEG Codec Control Registers */ +#define S5P_JPEG_CNTL_REG 0x00 +#define S5P_JPEG_INT_EN_REG 0x04 +#define S5P_JPEG_INT_STATUS_REG 0x0c +#define S5P_JPEG_OUT_MEM_BASE_REG 0x10 +#define S5P_JPEG_IMG_SIZE_REG 0x14 +#define S5P_JPEG_IMG_BA_PLANE_1_REG 0x18 +#define S5P_JPEG_IMG_BA_PLANE_2_REG 0x24 +#define S5P_JPEG_IMG_BA_PLANE_3_REG 0x30 + +#define S5P_JPEG_TBL_SEL_REG 0x3c + +#define S5P_JPEG_IMG_FMT_REG 0x40 + +#define S5P_JPEG_BITSTREAM_SIZE_REG 0x44 +#define S5P_JPEG_HUFF_CNT_REG 0x4c + +#define S5P_JPEG_QUAN_TBL_ENTRY_REG 0x100 +#define S5P_JPEG_HUFF_TBL_ENTRY_REG 0x200 + + +/****************************************************************/ +/* Bit definition part */drivers/media/video/s5p-jpeg/jpeg-regs-v2x.h new file +26
-0+/****************************************************************/ + +/* JPEG CNTL Register bit */ +#define S5P_JPEG_ENC_DEC_MODE_MASK (0xfffffffc << 0) +#define S5P_JPEG_DEC_MODE (1 << 0) +#define S5P_JPEG_ENC_MODE (1 << 1) +#define S5P_JPEG_HUF_TBL_EN (1 << 19) +#define S5P_JPEG_HOR_SCALING_SHIFT 20 +#define S5P_JPEG_HOR_SCALING_MASK \ + (3 << S5P_JPEG_HOR_SCALING_SHIFT) +#define S5P_JPEG_HOR_SCALING (x) \ + (((x) & 0x3) << S5P_JPEG_HOR_SCALING_SHIFT) +#define S5P_JPEG_VER_SCALING_SHIFT 22 +#define S5P_JPEG_VER_SCALING_MASK \ + (3 << S5P_JPEG_VER_SCALING_SHIFT) +#define S5P_JPEG_VER_SCALING (x) \ + (((x) & 0x3) << S5P_JPEG_VER_SCALING_SHIFT) +#define S5P_JPEG_SOFT_RESET_HI (1 << 29) + +/* JPEG INT Register bit */ +#define S5P_JPEG_INT_EN_MASK (0x1f << 0) +#define S5P_JPEG_INT_EN_ALL (0x1f << 0) + +/* JPEG IMAGE SIZE Register bit */ +#define S5P_JPEG_X_SIZE_SHIFT 0 +#define S5P_JPEG_X_SIZE_MASK (0xffff << S5P_JPEG_X_SIZE_SHIFT)
drivers/media/video/s5p-jpeg/jpeg-regs-v2x.h line 75
Quoted 10 lines
drivers/media/video/s5p-jpeg/jpeg-regs-v2x.h new file +10
-0+#define S5P_JPEG_X_SIZE (x) \ + (((x) & 0xffff) << S5P_JPEG_X_SIZE_SHIFT) +#define S5P_JPEG_Y_SIZE_SHIFT 16 +#define S5P_JPEG_Y_SIZE_MASK (0xffff << S5P_JPEG_Y_SIZE_SHIFT) +#define S5P_JPEG_Y_SIZE (x) \ + (((x) & 0xffff) << S5P_JPEG_Y_SIZE_SHIFT) + +/* JPEG IMAGE FORMAT Register bit */ +#define S5P_JPEG_ENC_IN_FMT_MASK 0xffff0000 +#define S5P_JPEG_ENC_RGB_IMG (1 << 0)
This is used only in one place in jpeg_input_raw_mode together with
<...>
this:
Quoted 1 line
+#define
S5P_JPEG_RGB_IP_RGB_16BIT_IMG(4 <<
S5P_JPEG_RGB_IP_SHIFT)
To form one constant, while
drivers/media/video/s5p-jpeg/jpeg-regs-v2x.h line 88
Quoted 2 lines
drivers/media/video/s5p-jpeg/jpeg-regs-v2x.h new file +2
-0+#define S5P_JPEG_YUV_422_IP_YUV_422_1P_IMG \ + (4 << S5P_JPEG_YUV_422_IP_SHIFT)
is only used in two places to form another constant.
If the constants were defined not combined from parts then jpeg_input_raw_mode is effectively the same as in v3. And a good candidate to factor out to some common code.
drivers/media/video/s5p-jpeg/jpeg-regs-v2x.h
Quoted 3 lines
drivers/media/video/s5p-jpeg/jpeg-regs-v2x.h new file +3
-0+ +#define S5P_JPEG_YUV_420_IP_SHIFT 15 +#define S5P_JPEG_YUV_420_IP_MASK (7 <<
S5P_JPEG_YUV_420_IP_SHIFT)
drivers/media/video/s5p-jpeg/jpeg-regs-v2x.h
Quoted 5 lines
drivers/media/video/s5p-jpeg/jpeg-regs-v2x.h new file +5
-0+#define S5P_JPEG_YUV_420_IP_YUV_420_3P_IMG \ + (5 << S5P_JPEG_YUV_420_IP_SHIFT) + +#define S5P_JPEG_ENC_FMT_SHIFT 24 +#define S5P_JPEG_ENC_FMT_MASK (3 <<
S5P_JPEG_ENC_FMT_SHIFT)
Quoted 1 line
+#define
S5P_JPEG_ENC_FMT_YUV_444(1 <<
S5P_JPEG_ENC_FMT_SHIFT)
Quoted 1 line
+#define
S5P_JPEG_ENC_FMT_YUV_422(2 <<
S5P_JPEG_ENC_FMT_SHIFT)
Quoted 1 line
+#define
S5P_JPEG_ENC_FMT_YUV_420(3 <<
S5P_JPEG_ENC_FMT_SHIFT)
drivers/media/video/s5p-jpeg/jpeg-regs-v2x.h
Quoted 4 lines
drivers/media/video/s5p-jpeg/jpeg-regs-v2x.h new file +4
-0+ +/* JPEG TBL SEL Register bit */ +#define S5P_JPEG_Q_TBL_COMP1_SHIFT 0 +#define S5P_JPEG_Q_TBL_COMP1_0 (0 <<
S5P_JPEG_Q_TBL_COMP1_SHIFT)
Quoted 1 line
+#define
S5P_JPEG_Q_TBL_COMP1_1(1 <<
S5P_JPEG_Q_TBL_COMP1_SHIFT)
Quoted 1 line
+#define
S5P_JPEG_Q_TBL_COMP1_2(2 <<
S5P_JPEG_Q_TBL_COMP1_SHIFT)
Quoted 1 line
+#define
S5P_JPEG_Q_TBL_COMP1_3(3 <<
S5P_JPEG_Q_TBL_COMP1_SHIFT)
drivers/media/video/s5p-jpeg/jpeg-regs-v2x.h
Quoted 3 lines
drivers/media/video/s5p-jpeg/jpeg-regs-v2x.h new file +3
-0+ +#define S5P_JPEG_Q_TBL_COMP2_SHIFT 2 +#define S5P_JPEG_Q_TBL_COMP2_0 (0 <<
S5P_JPEG_Q_TBL_COMP2_SHIFT)
Quoted 1 line
+#define
S5P_JPEG_Q_TBL_COMP2_1(1 <<
S5P_JPEG_Q_TBL_COMP2_SHIFT)
Quoted 1 line
+#define
S5P_JPEG_Q_TBL_COMP2_2(2 <<
S5P_JPEG_Q_TBL_COMP2_SHIFT)
Quoted 1 line
+#define
S5P_JPEG_Q_TBL_COMP2_3(3 <<
S5P_JPEG_Q_TBL_COMP2_SHIFT)
drivers/media/video/s5p-jpeg/jpeg-regs-v2x.h
Quoted 3 lines
drivers/media/video/s5p-jpeg/jpeg-regs-v2x.h new file +3
-0+ +#define S5P_JPEG_Q_TBL_COMP3_SHIFT 4 +#define S5P_JPEG_Q_TBL_COMP3_0 (0 <<
S5P_JPEG_Q_TBL_COMP3_SHIFT)
Quoted 1 line
+#define
S5P_JPEG_Q_TBL_COMP3_1(1 <<
S5P_JPEG_Q_TBL_COMP2_SHIFT)
Quoted 1 line
+#define
S5P_JPEG_Q_TBL_COMP3_2(2 <<
S5P_JPEG_Q_TBL_COMP2_SHIFT)
Quoted 1 line
+#define
S5P_JPEG_Q_TBL_COMP3_3(3 <<
S5P_JPEG_Q_TBL_COMP2_SHIFT)
Quoted 21 lines
drivers/media/video/s5p-jpeg/jpeg-regs-v2x.h new file +21
-0+ +#define S5P_JPEG_HUFF_TBL_COMP1_SHIFT 6 +#define S5P_JPEG_HUFF_TBL_COMP1_AC_0_DC_0 \ + (0 << S5P_JPEG_HUFF_TBL_COMP1_SHIFT) +#define S5P_JPEG_HUFF_TBL_COMP1_AC_0_DC_1 \ + (1 << S5P_JPEG_HUFF_TBL_COMP1_SHIFT) +#define S5P_JPEG_HUFF_TBL_COMP1_AC_1_DC_0 \ + (2 << S5P_JPEG_HUFF_TBL_COMP1_SHIFT) +#define S5P_JPEG_HUFF_TBL_COMP1_AC_1_DC_1 \ + (3 << S5P_JPEG_HUFF_TBL_COMP1_SHIFT) + +#define S5P_JPEG_HUFF_TBL_COMP2_SHIFT 8 +#define S5P_JPEG_HUFF_TBL_COMP2_AC_0_DC_0 \ + (0 << S5P_JPEG_HUFF_TBL_COMP2_SHIFT) +#define S5P_JPEG_HUFF_TBL_COMP2_AC_0_DC_1 \ + (1 << S5P_JPEG_HUFF_TBL_COMP2_SHIFT) +#define S5P_JPEG_HUFF_TBL_COMP2_AC_1_DC_0 \ + (2 << S5P_JPEG_HUFF_TBL_COMP2_SHIFT) +#define S5P_JPEG_HUFF_TBL_COMP2_AC_1_DC_1 \ + (3 << S5P_JPEG_HUFF_TBL_COMP2_SHIFT) +
drivers/media/video/s5p-jpeg/jpeg-regs-v2x.h line 149
Quoted 10 lines
drivers/media/video/s5p-jpeg/jpeg-regs-v2x.h new file +10
-0+#define S5P_JPEG_HUFF_TBL_COMP3_SHIFT 10 +#define S5P_JPEG_HUFF_TBL_COMP3_AC_0_DC_0 \ + (0 << S5P_JPEG_HUFF_TBL_COMP3_SHIFT) +#define S5P_JPEG_HUFF_TBL_COMP3_AC_0_DC_1 \ + (1 << S5P_JPEG_HUFF_TBL_COMP3_SHIFT) +#define S5P_JPEG_HUFF_TBL_COMP3_AC_1_DC_0 \ + (2 << S5P_JPEG_HUFF_TBL_COMP3_SHIFT) +#define S5P_JPEG_HUFF_TBL_COMP3_AC_1_DC_1 \ + (3 << S5P_JPEG_HUFF_TBL_COMP3_SHIFT) +
Perhaps you could use some smarter macros, e.g. with parameters?
Quoted 32 lines
drivers/media/video/s5p-jpeg/jpeg-regs-v2x.h new file +1
-0+#endif /* JPEG_REGS_H_ */ drivers/media/video/s5p-jpeg/jpeg-v2x.c new file +23
-0@@ -0,0 +1,129 @@ +/* linux/drivers/media/video/s5p-jpeg/jpeg-v2x.c +* +* Copyright (c) 2012 Samsung Electronics Co., Ltd. +* http://www.samsung.com +* +* +* 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. +*/ + +#include <linux/clk.h> +#include <linux/err.h> +#include <linux/gfp.h> +#include <linux/interrupt.h> +#include <linux/io.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/platform_device.h> +#include <linux/pm_runtime.h> +#include <linux/slab.h> +#include <linux/spinlock.h> +#include <linux/string.h>
drivers/media/video/s5p-jpeg/jpeg-v2x.c line 33
Quoted 10 lines
drivers/media/video/s5p-jpeg/jpeg-v2x.c new file +10
-0+#include <media/v4l2-mem2mem.h> +#include <media/v4l2-ioctl.h> +#include <media/videobuf2-core.h> +#include <media/videobuf2-dma-contig.h> + +#include "jpeg-core.h" +#include "jpeg-hw-v2x.h" + +/* +*
============================================================================
drivers/media/video/s5p-jpeg/jpeg-v2x.c line 35
Quoted 3 lines
drivers/media/video/s5p-jpeg/jpeg-v2x.c new file +2
-0+* mem2mem callbacks +*
============================================================================
Quoted 21 lines
drivers/media/video/s5p-jpeg/jpeg-v2x.c new file +21
-0+*/ + +void s5p_jpeg_irq_execute (void *dev_id) +{ +struct s5p_jpeg *jpeg = dev_id; +struct s5p_jpeg_ctx *curr_ctx; +struct vb2_buffer *src_buf, *dst_buf; +unsigned long payload_size =0 ; +enum vb2_buffer_state state =VB2_BUF_STATE_DONE ; + +unsigned int int_status; + + curr_ctx =v4l2_m2m_get_curr_priv (jpeg->m2m_dev); + + src_buf =v4l2_m2m_src_buf_remove (curr_ctx->m2m_ctx); + dst_buf =v4l2_m2m_dst_buf_remove (curr_ctx->m2m_ctx); + + int_status =jpeg_get_int_status (jpeg->regs); + +if (int_status !=0x2 ) + state =VB2_BUF_STATE_ERROR ;
drivers/media/video/s5p-jpeg/jpeg-v2x.c line 66
Quoted 10 lines
drivers/media/video/s5p-jpeg/jpeg-v2x.c new file +10
-0+ +v4l2_m2m_buf_done (src_buf, state); +if (curr_ctx->mode ==S5P_JPEG_ENCODE && int_status ==0x2 ) { + payload_size =jpeg_compressed_size (jpeg->regs); +vb2_set_plane_payload (dst_buf,0 , payload_size); + } +v4l2_m2m_buf_done (dst_buf, state); +v4l2_m2m_job_finish (jpeg->m2m_dev, curr_ctx->m2m_ctx); +} +
This function is almost the same as its counterpart in jpeg v3. The difference is only in reading the interrupt cause, while mem2mem operations are exacty the same. This makes maintenance more difficult: whenever mem2mem usage changes, it needs to be updated in 2 places. I think that wherever mem2mem operations are the same in v2 and v3, they should be factored out to some common code.
Quoted 16 lines
drivers/media/video/s5p-jpeg/jpeg-v2x.c new file +16
-0+void s5p_jpeg_execute (void *priv) +{ +struct s5p_jpeg_ctx *ctx = priv; +struct s5p_jpeg *jpeg = ctx->jpeg; +struct vb2_buffer *src_buf, *dst_buf; +unsigned long src_addr, dst_addr; + + src_buf =v4l2_m2m_next_src_buf (ctx->m2m_ctx); + dst_buf =v4l2_m2m_next_dst_buf (ctx->m2m_ctx); + + src_addr =vb2_dma_contig_plane_dma_addr (src_buf,0 ); + dst_addr =vb2_dma_contig_plane_dma_addr (dst_buf,0 ); + +jpeg_reset (jpeg->regs); +jpeg_set_interrupt (jpeg->regs); +
drivers/media/video/s5p-jpeg/jpeg-v2x.c
Quoted 10 lines
drivers/media/video/s5p-jpeg/jpeg-v2x.c new file +10
-0+if (ctx->mode ==S5P_JPEG_ENCODE ) { +jpeg_set_huf_table_enable (jpeg->regs,1 ); +jpeg_qtbl (jpeg->regs); +jpeg_htbl_ac (jpeg->regs); +jpeg_htbl_dc (jpeg->regs); +jpeg_set_encode_tbl_select (jpeg->regs, ctx->compr_quality); +jpeg_x_y (jpeg->regs, ctx->out_q.w, ctx->out_q.h); + +if (ctx->out_q.fmt->fourcc ==V4L2_PIX_FMT_RGB565 ) + jpeg_input_raw_mode(jpeg->regs,
S5P_JPEG_RAW_IN_565);
drivers/media/video/s5p-jpeg/jpeg-v2x.c line 94
Quoted 2 lines
drivers/media/video/s5p-jpeg/jpeg-v2x.c new file +2
-0+else + jpeg_input_raw_mode(jpeg->regs,
S5P_JPEG_RAW_IN_422);
drivers/media/video/s5p-jpeg/jpeg-v2x.c line 104
Quoted 10 lines
drivers/media/video/s5p-jpeg/jpeg-v2x.c new file +10
-0+if (ctx->cap_q.fmt->fourcc ==V4L2_PIX_FMT_YUYV ) +jpeg_subsampling_mode (jpeg->regs, +S5P_JPEG_SUBSAMPLING_422 ); +else +jpeg_subsampling_mode (jpeg->regs, +S5P_JPEG_SUBSAMPLING_420 ); + +jpeg_enc_imgadr (jpeg->regs, src_addr); +jpeg_jpgadr (jpeg->regs, dst_addr); +jpeg_set_encode_hoff_cnt (jpeg->regs);
This part is almost a verbatim copy of its counterpart from v3, only the sequence of operations is different and some calls are grouped into separate functions (e.g. jpeg_htbl_ac, jpeg_htbl_dc, jpeg_qtbl). Why not factor out into some common piece of code?
Quoted 5 lines
drivers/media/video/s5p-jpeg/jpeg-v2x.c new file +5
-0+ }else { +jpeg_set_encode_tbl_select (jpeg->regs,0 ); +jpeg_set_dec_scaling (jpeg->regs,0 ,0 ); +jpeg_jpgadr (jpeg->regs, src_addr); +if (ctx->cap_q.fmt->fourcc ==V4L2_PIX_FMT_YUYV ) {
drivers/media/video/s5p-jpeg/jpeg-v2x.c line 119
Quoted 10 lines
drivers/media/video/s5p-jpeg/jpeg-v2x.c new file +10
-0+jpeg_dec_imgadr (jpeg->regs, dst_addr, +S5P_JPEG_RAW_OUT_422 , + ctx->out_q.w, ctx->out_q.h); +jpeg_outform_raw (jpeg->regs,S5P_JPEG_RAW_OUT_422 ); + }else { +jpeg_dec_imgadr (jpeg->regs, dst_addr, +S5P_JPEG_RAW_OUT_420 , + ctx->out_q.w, ctx->out_q.h); +jpeg_outform_raw (jpeg->regs,S5P_JPEG_RAW_OUT_420 ); + }
This looks like this patch: http://patchwork.linuxtv.org/patch/10004/
If you applied it to version 2x, it would be nice if you applied it to version 3, too.
Quoted 10 lines
drivers/media/video/s5p-jpeg/jpeg-v2x.c new file +10
-0+jpeg_set_dec_bitstream_size (jpeg->regs, + ctx->out_q.size /32 +1 ); + } +jpeg_proc_mode (jpeg->regs, ctx->mode); +} + +void s5p_jpeg_runtime_resume_execute (struct device *dev) +{ + +}
<...>
On Monday, March 05, 2012 3:00 PM Andrzej Pietrasiewicz wrote:
I forgot to sign my last post. One might think I was being rude. So I fix it below.
Quoted 143 lines
Hello송영목,
In general I think the v2x support should be designed to require as little code changes as possible, and they should be related to pure hardware differences only. Please see comments inline.
The tables (quantization, Huffman) logically contain mostly the same data both in v3 and v2x and are defined by respective standards. Only the arrangement of data is slightly different (bytes vs 4-byte words). Please see comments inline.
On, March 02, 2012 12:47 AM 송영목 wrote:
<...>
Quoted 5 lines
drivers/media/video/s5p-jpeg/jpeg-core.c +0
-0<...>
Quoted 1 line
(quoted diff) +0
-0<...>
Quoted 1 line
drivers/media/video/s5p-jpeg/jpeg-core.c +0
-0@@ -0,0 +1,387 @@<...>
drivers/media/video/s5p-jpeg/jpeg-core.c
Quoted 13 lines
drivers/media/video/s5p-jpeg/jpeg-core.c +13
-0+ +#define S5P_JPEG_MIN_WIDTH 32 +#define S5P_JPEG_MIN_HEIGHT 32 +#define S5P_JPEG_MAX_WIDTH 8192 +#define S5P_JPEG_MAX_HEIGHT 8192 +#define S5P_JPEG_ENCODE 0 +#define S5P_JPEG_DECODE 1 +#define S5P_JPEG_RAW_IN_565 0 +#define S5P_JPEG_RAW_IN_422 1 +#define S5P_JPEG_SUBSAMPLING_422 0 +#define S5P_JPEG_SUBSAMPLING_420 1 +#define S5P_JPEG_RAW_OUT_422 0 +#define S5P_JPEG_RAW_OUT_420 1This is a verbatim copy of what is defined in
jpeg-hw-common.hand should not be repeated here. Usejpeg-hw-common.h.Quoted 15 lines
drivers/media/video/s5p-jpeg/jpeg-core.c +15
-0+/* Q-table for JPEG */ +/* ITU standard Q-table */ +static unsigned int ITU_Q_tbl[4 ][16 ] = { + { +0x01010101 ,0x01020303 ,0x01010101 ,0x01030303 ,/* Y */ +0x01010101 ,0x02030303 ,0x01010101 ,0x03040403 , +0x01010203 ,0x03050504 ,0x01020303 ,0x04050605 , +0x02030404 ,0x05060605 ,0x04050505 ,0x06050505 + } , { +0x01010102 ,0x05050505 ,0x01010103 ,0x05050505 ,/* CbCr */ +0x01010503 ,0x05050505 ,0x02030505 ,0x05050505 , +0x05050505 ,0x05050505 ,0x05050505 ,0x05050505 , +0x05050505 ,0x05050505 ,0x05050505 ,0x05050505 + } , { +0x05020205 ,0x0a161e25 ,0x02020307 ,0x0c232521 ,/* Y */ drivers/media/video/s5p-jpeg/jpeg-core.c
Quoted 10 lines
drivers/media/video/s5p-jpeg/jpeg-core.c +10
-0+ 0x0302050a, 0x16222b22, 0x0305090e, 0x1e393326, + 0x06091422, 0x2a384431, 0x0a122118, 0x34454b3c, + 0x1d283238, 0x44525142, 0x2d3c3e40, 0x4a424441 + } , { +0x05020205 ,0x251e160a ,0x07030202 ,0x2125230c ,/* CbCr */ +0x0a050203 ,0x222b2216 ,0x0e090503 ,0x2633391e , +0x22140906 ,0x3144382a ,0x1821120a ,0x3c4b4534 , +0x3832281d ,0x42515244 ,0x403e3c2d ,0x4144424a + } +};This array is static so this makes all users of this header file allocate it. Why not put it into
jpeg-v2x.c? (however, see below for considerations about duplication)
This comment applies to all array definitions of this kind in this file.drivers/media/video/s5p-jpeg/jpeg-core.c
Quoted 5 lines
drivers/media/video/s5p-jpeg/jpeg-core.c +5
-0+ +/* ITU Luminace Huffman Table */ +static unsigned int ITU_H_tbl_len_DC_luminance[4 ] = { +0x01050100 ,0x01010101 ,0x00000001 ,0x00000000 +};This is in fact the same thing as hdctbl0[16] in jpeg v3, only arranged in 4-byte words. It would be nice if the same definitions were used in both versions. This applies to all tables defined here.
drivers/media/video/s5p-jpeg/jpeg-core.c
Quoted 3 lines
drivers/media/video/s5p-jpeg/jpeg-core.c +3
-0+static unsigned int ITU_H_tbl_val_DC_luminance[3 ] = { +0x03020100 ,0x07060504 ,0x0b0a0908 +};The same thing as hdctblg0[12] in jpeg v3.
<...>
drivers/media/video/s5p-jpeg/jpeg-core.c
Quoted 3 lines
drivers/media/video/s5p-jpeg/jpeg-core.c +3
-0+static unsigned int ITU_H_tbl_val_DC_chrominance[3 ] = { +0x03020100 ,0x07060504 ,0x0b0a0908 +};The same thing as as hdctblg0[12] in jpeg v3 and
ITU_H_tbl_val_DC_luminance[3] in your code.drivers/media/video/s5p-jpeg/jpeg-core.c
Quoted 5 lines
drivers/media/video/s5p-jpeg/jpeg-core.c +5
-0+ +static unsigned int ITU_H_tbl_len_AC_luminance[4 ] = { +0x03010200 ,0x03040203 ,0x04040505 ,0x7d010000 +}; +The same thing as hactbl0[16] in jpeg v3.
Quoted 4 lines
drivers/media/video/s5p-jpeg/jpeg-core.c +4
-0+static unsigned int ITU_H_tbl_val_AC_luminance[41 ] = { +0x00030201 ,0x12051104 ,0x06413121 ,0x07615113 , +0x32147122 ,0x08a19181 ,0xc1b14223 ,0xf0d15215 , +0x72623324 ,0x160a0982 ,0x1a191817 ,0x28272625 ,drivers/media/video/s5p-jpeg/jpeg-core.c
Quoted 10 lines
drivers/media/video/s5p-jpeg/jpeg-core.c +10
-0+0x35342a29 ,0x39383736 ,0x4544433a ,0x49484746 , +0x5554534a ,0x59585756 ,0x6564635a ,0x69686766 , +0x7574736a ,0x79787776 ,0x8584837a ,0x89888786 , +0x9493928a ,0x98979695 ,0xa3a29a99 ,0xa7a6a5a4 , +0xb2aaa9a8 ,0xb6b5b4b3 ,0xbab9b8b7 ,0xc5c4c3c2 , +0xc9c8c7c6 ,0xd4d3d2ca ,0xd8d7d6d5 ,0xe2e1dad9 , +0xe6e5e4e3 ,0xeae9e8e7 ,0xf4f3f2f1 ,0xf8f7f6f5 , +0x0000faf9 +}; +The same thing as hactblg0[162] in jpeg v3.
<...>
drivers/media/video/s5p-jpeg/jpeg-core.c
Quoted 10 lines
drivers/media/video/s5p-jpeg/jpeg-core.c +10
-0+ +static inline void jpeg_reset (void __iomem *regs) +{ +unsigned long reg; + + reg =readl (regs +S5P_JPEG_CNTL_REG ); +writel (reg & ~S5P_JPEG_SOFT_RESET_HI , + regs +S5P_JPEG_CNTL_REG ); + +ndelay (100000 );Why not use
usleep_range?
Quoted 3 lines
<...>
Quoted 1 line
+static inline void jpeg_proc_mode(void
__iomem*regs, unsigned long
mode)
Quoted 26 lines
Quoted 6 lines
drivers/media/video/s5p-jpeg/jpeg-core.c +6
-0+{ +unsigned int reg, m; + + m =S5P_JPEG_DEC_MODE ; +if (mode ==S5P_JPEG_ENCODE ) + m =S5P_JPEG_ENC_MODE ;drivers/media/video/s5p-jpeg/jpeg-core.c
Quoted 10 lines
drivers/media/video/s5p-jpeg/jpeg-core.c +10
-0+else + m =S5P_JPEG_DEC_MODE ; + + reg =readl (regs +S5P_JPEG_CNTL_REG ); + reg &=S5P_JPEG_ENC_DEC_MODE_MASK ; + reg |= m; + +writel (reg, regs +S5P_JPEG_CNTL_REG ); +} +This function is in fact an exact copy of its counterpart in v3. The difference is in the name of the constant which names the register (
S5P_JPEG_CNTL_REGvsS5P_JPEGMOD), however,
the value of this constant is0x00in both cases. The numeric values of ENC/COMPR and DEC/DECOMPR constants are different, but I believe this could be mitigated some other way. What is important is that the 2 functions serve the same purpose and so should be factored out to some common code.
Quoted 3 lines
<...>
Quoted 1 line
+static inline void jpeg_subsampling_mode(void
__iomem*regs, unsigned
long
Quoted 31 lines
Quoted 7 lines
mode)
drivers/media/video/s5p-jpeg/jpeg-core.c +6
-0+{ +unsigned long reg, m; + + m =S5P_JPEG_ENC_FMT_YUV_422 ; +if (mode ==S5P_JPEG_SUBSAMPLING_422 ) + m =S5P_JPEG_ENC_FMT_YUV_422 ;drivers/media/video/s5p-jpeg/jpeg-core.c
Quoted 10 lines
drivers/media/video/s5p-jpeg/jpeg-core.c +10
-0+else if (mode ==S5P_JPEG_SUBSAMPLING_420 ) + m =S5P_JPEG_ENC_FMT_YUV_420 ; + + reg =readl (regs +S5P_JPEG_IMG_FMT_REG ); + reg &= ~S5P_JPEG_ENC_FMT_MASK ; + reg |= m; + +writel (reg, regs +S5P_JPEG_IMG_FMT_REG ); +} +The same here.
<...>
drivers/media/video/s5p-jpeg/jpeg-core.c
Quoted 6 lines
drivers/media/video/s5p-jpeg/jpeg-core.c +6
-0+ +static inline void jpeg_jpgadr (void __iomem *regs,unsigned long addr) +{ +writel (addr, regs +S5P_JPEG_OUT_MEM_BASE_REG ); +} +The same here.
Quoted 3 lines
<...>
Quoted 1 line
+static inline void jpeg_enc_imgadr(void
__iomem*regs, unsigned long
addr)
Quoted 75 lines
drivers/media/video/s5p-jpeg/jpeg-core.c
Quoted 4 lines
drivers/media/video/s5p-jpeg/jpeg-core.c +4
-0+{ +writel (addr, regs +S5P_JPEG_IMG_BA_PLANE_1_REG ); +} +This looks like
jpeg_imgadr()from v3.<...>
Quoted 65 lines
drivers/media/video/s5p-jpeg/jpeg-regs-v2x.h new file +39
-0@@ -0,0 +1,150 @@ +/* linux/drivers/media/video/s5p-jpeg/jpeg-regs-v2x.h +* +* Register definition file for Samsung JPEG codec driver +* +* Copyright (c) 2012 Samsung Electronics Co., Ltd. +* http:www.samsung.com +* +* +* 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 JPEG_REGS_H_ +#define JPEG_REGS_H_ + +/* JPEG Codec Control Registers */ +#define S5P_JPEG_CNTL_REG 0x00 +#define S5P_JPEG_INT_EN_REG 0x04 +#define S5P_JPEG_INT_STATUS_REG 0x0c +#define S5P_JPEG_OUT_MEM_BASE_REG 0x10 +#define S5P_JPEG_IMG_SIZE_REG 0x14 +#define S5P_JPEG_IMG_BA_PLANE_1_REG 0x18 +#define S5P_JPEG_IMG_BA_PLANE_2_REG 0x24 +#define S5P_JPEG_IMG_BA_PLANE_3_REG 0x30 + +#define S5P_JPEG_TBL_SEL_REG 0x3c + +#define S5P_JPEG_IMG_FMT_REG 0x40 + +#define S5P_JPEG_BITSTREAM_SIZE_REG 0x44 +#define S5P_JPEG_HUFF_CNT_REG 0x4c + +#define S5P_JPEG_QUAN_TBL_ENTRY_REG 0x100 +#define S5P_JPEG_HUFF_TBL_ENTRY_REG 0x200 + + +/****************************************************************/ +/* Bit definition part */drivers/media/video/s5p-jpeg/jpeg-regs-v2x.h new file +18
-0+/****************************************************************/ + +/* JPEG CNTL Register bit */ +#define S5P_JPEG_ENC_DEC_MODE_MASK (0xfffffffc << 0) +#define S5P_JPEG_DEC_MODE (1 << 0) +#define S5P_JPEG_ENC_MODE (1 << 1) +#define S5P_JPEG_HUF_TBL_EN (1 << 19) +#define S5P_JPEG_HOR_SCALING_SHIFT 20 +#define S5P_JPEG_HOR_SCALING_MASK \ + (3 << S5P_JPEG_HOR_SCALING_SHIFT) +#define S5P_JPEG_HOR_SCALING (x) \ + (((x) & 0x3) << S5P_JPEG_HOR_SCALING_SHIFT) +#define S5P_JPEG_VER_SCALING_SHIFT 22 +#define S5P_JPEG_VER_SCALING_MASK \ + (3 << S5P_JPEG_VER_SCALING_SHIFT) +#define S5P_JPEG_VER_SCALING (x) \ + (((x) & 0x3) << S5P_JPEG_VER_SCALING_SHIFT) +#define S5P_JPEG_SOFT_RESET_HI (1 << 29)
Quoted 8 lines
drivers/media/video/s5p-jpeg/jpeg-regs-v2x.h
Quoted 8 lines
drivers/media/video/s5p-jpeg/jpeg-regs-v2x.h new file +8
-0+ +/* JPEG INT Register bit */ +#define S5P_JPEG_INT_EN_MASK (0x1f << 0) +#define S5P_JPEG_INT_EN_ALL (0x1f << 0) + +/* JPEG IMAGE SIZE Register bit */ +#define S5P_JPEG_X_SIZE_SHIFT 0 +#define S5P_JPEG_X_SIZE_MASK (0xffff <<
S5P_JPEG_X_SIZE_SHIFT)
Quoted 4 lines
drivers/media/video/s5p-jpeg/jpeg-regs-v2x.h
Quoted 4 lines
drivers/media/video/s5p-jpeg/jpeg-regs-v2x.h new file +4
-0+#define S5P_JPEG_X_SIZE (x) \ + (((x) & 0xffff) << S5P_JPEG_X_SIZE_SHIFT) +#define S5P_JPEG_Y_SIZE_SHIFT 16 +#define S5P_JPEG_Y_SIZE_MASK (0xffff <<
S5P_JPEG_Y_SIZE_SHIFT)
Quoted 23 lines
drivers/media/video/s5p-jpeg/jpeg-regs-v2x.h line 75
Quoted 6 lines
drivers/media/video/s5p-jpeg/jpeg-regs-v2x.h new file +6
-0+#define S5P_JPEG_Y_SIZE (x) \ + (((x) & 0xffff) << S5P_JPEG_Y_SIZE_SHIFT) + +/* JPEG IMAGE FORMAT Register bit */ +#define S5P_JPEG_ENC_IN_FMT_MASK 0xffff0000 +#define S5P_JPEG_ENC_RGB_IMG (1 << 0)This is used only in one place in
jpeg_input_raw_modetogether with<...>
this:
Quoted 1 line
+#define
S5P_JPEG_RGB_IP_RGB_16BIT_IMG(4 <<
S5P_JPEG_RGB_IP_SHIFT)To form one constant, while
drivers/media/video/s5p-jpeg/jpeg-regs-v2x.h line 88
Quoted 2 lines
drivers/media/video/s5p-jpeg/jpeg-regs-v2x.h new file +2
-0+#define S5P_JPEG_YUV_422_IP_YUV_422_1P_IMG \ + (4 << S5P_JPEG_YUV_422_IP_SHIFT)is only used in two places to form another constant.
Quoted 7 lines
If the constants were defined not combined from parts then
jpeg_input_raw_modeis effectively the same as in v3. And a good candidate to factor out to some common code.drivers/media/video/s5p-jpeg/jpeg-regs-v2x.h
Quoted 3 lines
drivers/media/video/s5p-jpeg/jpeg-regs-v2x.h new file +3
-0+ +#define S5P_JPEG_YUV_420_IP_SHIFT 15 +#define S5P_JPEG_YUV_420_IP_MASK (7 <<
S5P_JPEG_YUV_420_IP_SHIFT)
Quoted 5 lines
drivers/media/video/s5p-jpeg/jpeg-regs-v2x.h
Quoted 5 lines
drivers/media/video/s5p-jpeg/jpeg-regs-v2x.h new file +5
-0+#define S5P_JPEG_YUV_420_IP_YUV_420_3P_IMG \ + (5 << S5P_JPEG_YUV_420_IP_SHIFT) + +#define S5P_JPEG_ENC_FMT_SHIFT 24 +#define S5P_JPEG_ENC_FMT_MASK (3 <<
S5P_JPEG_ENC_FMT_SHIFT)
Quoted 1 line
Quoted 1 line
+#define
S5P_JPEG_ENC_FMT_YUV_444(1 <<
S5P_JPEG_ENC_FMT_SHIFT)
Quoted 1 line
Quoted 1 line
+#define
S5P_JPEG_ENC_FMT_YUV_422(2 <<
S5P_JPEG_ENC_FMT_SHIFT)
Quoted 1 line
Quoted 1 line
+#define
S5P_JPEG_ENC_FMT_YUV_420(3 <<
S5P_JPEG_ENC_FMT_SHIFT)
Quoted 4 lines
drivers/media/video/s5p-jpeg/jpeg-regs-v2x.h
Quoted 4 lines
drivers/media/video/s5p-jpeg/jpeg-regs-v2x.h new file +4
-0+ +/* JPEG TBL SEL Register bit */ +#define S5P_JPEG_Q_TBL_COMP1_SHIFT 0 +#define S5P_JPEG_Q_TBL_COMP1_0 (0 <<
S5P_JPEG_Q_TBL_COMP1_SHIFT)
Quoted 1 line
Quoted 1 line
+#define
S5P_JPEG_Q_TBL_COMP1_1(1 <<
S5P_JPEG_Q_TBL_COMP1_SHIFT)
Quoted 1 line
Quoted 1 line
+#define
S5P_JPEG_Q_TBL_COMP1_2(2 <<
S5P_JPEG_Q_TBL_COMP1_SHIFT)
Quoted 1 line
Quoted 1 line
+#define
S5P_JPEG_Q_TBL_COMP1_3(3 <<
S5P_JPEG_Q_TBL_COMP1_SHIFT)
Quoted 3 lines
drivers/media/video/s5p-jpeg/jpeg-regs-v2x.h
Quoted 3 lines
drivers/media/video/s5p-jpeg/jpeg-regs-v2x.h new file +3
-0+ +#define S5P_JPEG_Q_TBL_COMP2_SHIFT 2 +#define S5P_JPEG_Q_TBL_COMP2_0 (0 <<
S5P_JPEG_Q_TBL_COMP2_SHIFT)
Quoted 1 line
Quoted 1 line
+#define
S5P_JPEG_Q_TBL_COMP2_1(1 <<
S5P_JPEG_Q_TBL_COMP2_SHIFT)
Quoted 1 line
Quoted 1 line
+#define
S5P_JPEG_Q_TBL_COMP2_2(2 <<
S5P_JPEG_Q_TBL_COMP2_SHIFT)
Quoted 1 line
Quoted 1 line
+#define
S5P_JPEG_Q_TBL_COMP2_3(3 <<
S5P_JPEG_Q_TBL_COMP2_SHIFT)
Quoted 3 lines
drivers/media/video/s5p-jpeg/jpeg-regs-v2x.h
Quoted 3 lines
drivers/media/video/s5p-jpeg/jpeg-regs-v2x.h new file +3
-0+ +#define S5P_JPEG_Q_TBL_COMP3_SHIFT 4 +#define S5P_JPEG_Q_TBL_COMP3_0 (0 <<
S5P_JPEG_Q_TBL_COMP3_SHIFT)
Quoted 1 line
Quoted 1 line
+#define
S5P_JPEG_Q_TBL_COMP3_1(1 <<
S5P_JPEG_Q_TBL_COMP2_SHIFT)
Quoted 1 line
Quoted 1 line
+#define
S5P_JPEG_Q_TBL_COMP3_2(2 <<
S5P_JPEG_Q_TBL_COMP2_SHIFT)
Quoted 1 line
Quoted 1 line
+#define
S5P_JPEG_Q_TBL_COMP3_3(3 <<
S5P_JPEG_Q_TBL_COMP2_SHIFT)
Quoted 69 lines
Quoted 21 lines
drivers/media/video/s5p-jpeg/jpeg-regs-v2x.h new file +21
-0+ +#define S5P_JPEG_HUFF_TBL_COMP1_SHIFT 6 +#define S5P_JPEG_HUFF_TBL_COMP1_AC_0_DC_0 \ + (0 << S5P_JPEG_HUFF_TBL_COMP1_SHIFT) +#define S5P_JPEG_HUFF_TBL_COMP1_AC_0_DC_1 \ + (1 << S5P_JPEG_HUFF_TBL_COMP1_SHIFT) +#define S5P_JPEG_HUFF_TBL_COMP1_AC_1_DC_0 \ + (2 << S5P_JPEG_HUFF_TBL_COMP1_SHIFT) +#define S5P_JPEG_HUFF_TBL_COMP1_AC_1_DC_1 \ + (3 << S5P_JPEG_HUFF_TBL_COMP1_SHIFT) + +#define S5P_JPEG_HUFF_TBL_COMP2_SHIFT 8 +#define S5P_JPEG_HUFF_TBL_COMP2_AC_0_DC_0 \ + (0 << S5P_JPEG_HUFF_TBL_COMP2_SHIFT) +#define S5P_JPEG_HUFF_TBL_COMP2_AC_0_DC_1 \ + (1 << S5P_JPEG_HUFF_TBL_COMP2_SHIFT) +#define S5P_JPEG_HUFF_TBL_COMP2_AC_1_DC_0 \ + (2 << S5P_JPEG_HUFF_TBL_COMP2_SHIFT) +#define S5P_JPEG_HUFF_TBL_COMP2_AC_1_DC_1 \ + (3 << S5P_JPEG_HUFF_TBL_COMP2_SHIFT) +drivers/media/video/s5p-jpeg/jpeg-regs-v2x.h line 149
Quoted 10 lines
drivers/media/video/s5p-jpeg/jpeg-regs-v2x.h new file +10
-0+#define S5P_JPEG_HUFF_TBL_COMP3_SHIFT 10 +#define S5P_JPEG_HUFF_TBL_COMP3_AC_0_DC_0 \ + (0 << S5P_JPEG_HUFF_TBL_COMP3_SHIFT) +#define S5P_JPEG_HUFF_TBL_COMP3_AC_0_DC_1 \ + (1 << S5P_JPEG_HUFF_TBL_COMP3_SHIFT) +#define S5P_JPEG_HUFF_TBL_COMP3_AC_1_DC_0 \ + (2 << S5P_JPEG_HUFF_TBL_COMP3_SHIFT) +#define S5P_JPEG_HUFF_TBL_COMP3_AC_1_DC_1 \ + (3 << S5P_JPEG_HUFF_TBL_COMP3_SHIFT) +Perhaps you could use some smarter macros, e.g. with parameters?
Quoted 34 lines
drivers/media/video/s5p-jpeg/jpeg-regs-v2x.h new file +1
-0+#endif /* JPEG_REGS_H_ */ drivers/media/video/s5p-jpeg/jpeg-v2x.c new file +26
-0@@ -0,0 +1,129 @@ +/* linux/drivers/media/video/s5p-jpeg/jpeg-v2x.c +* +* Copyright (c) 2012 Samsung Electronics Co., Ltd. +* http://www.samsung.com +* +* +* 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. +*/ + +#include <linux/clk.h> +#include <linux/err.h> +#include <linux/gfp.h> +#include <linux/interrupt.h> +#include <linux/io.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/platform_device.h> +#include <linux/pm_runtime.h> +#include <linux/slab.h> +#include <linux/spinlock.h> +#include <linux/string.h> +#include <media/v4l2-mem2mem.h> +#include <media/v4l2-ioctl.h> +#include <media/videobuf2-core.h>
Quoted 8 lines
drivers/media/video/s5p-jpeg/jpeg-v2x.c
Quoted 8 lines
drivers/media/video/s5p-jpeg/jpeg-v2x.c new file +7
-0+#include <media/videobuf2-dma-contig.h> + +#include "jpeg-core.h" +#include "jpeg-hw-v2x.h" + +/* +*
============================================================================
Quoted 3 lines
drivers/media/video/s5p-jpeg/jpeg-v2x.c line 35
Quoted 3 lines
drivers/media/video/s5p-jpeg/jpeg-v2x.c new file +2
-0+* mem2mem callbacks +*
============================================================================
Quoted 58 lines
Quoted 21 lines
drivers/media/video/s5p-jpeg/jpeg-v2x.c new file +21
-0+*/ + +void s5p_jpeg_irq_execute (void *dev_id) +{ +struct s5p_jpeg *jpeg = dev_id; +struct s5p_jpeg_ctx *curr_ctx; +struct vb2_buffer *src_buf, *dst_buf; +unsigned long payload_size =0 ; +enum vb2_buffer_state state =VB2_BUF_STATE_DONE ; + +unsigned int int_status; + + curr_ctx =v4l2_m2m_get_curr_priv (jpeg->m2m_dev); + + src_buf =v4l2_m2m_src_buf_remove (curr_ctx->m2m_ctx); + dst_buf =v4l2_m2m_dst_buf_remove (curr_ctx->m2m_ctx); + + int_status =jpeg_get_int_status (jpeg->regs); + +if (int_status !=0x2 ) + state =VB2_BUF_STATE_ERROR ;drivers/media/video/s5p-jpeg/jpeg-v2x.c line 66
Quoted 10 lines
drivers/media/video/s5p-jpeg/jpeg-v2x.c new file +10
-0+ +v4l2_m2m_buf_done (src_buf, state); +if (curr_ctx->mode ==S5P_JPEG_ENCODE && int_status ==0x2 ) { + payload_size =jpeg_compressed_size (jpeg->regs); +vb2_set_plane_payload (dst_buf,0 , payload_size); + } +v4l2_m2m_buf_done (dst_buf, state); +v4l2_m2m_job_finish (jpeg->m2m_dev, curr_ctx->m2m_ctx); +} +This function is almost the same as its counterpart in jpeg v3. The difference is only in reading the interrupt cause, while mem2mem operations are exacty the same. This makes maintenance more difficult: whenever mem2mem usage changes, it needs to be updated in 2 places. I think that wherever mem2mem operations are the same in v2 and v3, they should be factored out to some common code.
Quoted 18 lines
drivers/media/video/s5p-jpeg/jpeg-v2x.c new file +18
-0+void s5p_jpeg_execute (void *priv) +{ +struct s5p_jpeg_ctx *ctx = priv; +struct s5p_jpeg *jpeg = ctx->jpeg; +struct vb2_buffer *src_buf, *dst_buf; +unsigned long src_addr, dst_addr; + + src_buf =v4l2_m2m_next_src_buf (ctx->m2m_ctx); + dst_buf =v4l2_m2m_next_dst_buf (ctx->m2m_ctx); + + src_addr =vb2_dma_contig_plane_dma_addr (src_buf,0 ); + dst_addr =vb2_dma_contig_plane_dma_addr (dst_buf,0 ); + +jpeg_reset (jpeg->regs); +jpeg_set_interrupt (jpeg->regs); + +if (ctx->mode ==S5P_JPEG_ENCODE ) { +jpeg_set_huf_table_enable (jpeg->regs,1 );
Quoted 8 lines
drivers/media/video/s5p-jpeg/jpeg-v2x.c
Quoted 8 lines
drivers/media/video/s5p-jpeg/jpeg-v2x.c new file +8
-0+jpeg_qtbl (jpeg->regs); +jpeg_htbl_ac (jpeg->regs); +jpeg_htbl_dc (jpeg->regs); +jpeg_set_encode_tbl_select (jpeg->regs, ctx->compr_quality); +jpeg_x_y (jpeg->regs, ctx->out_q.w, ctx->out_q.h); + +if (ctx->out_q.fmt->fourcc ==V4L2_PIX_FMT_RGB565 ) + jpeg_input_raw_mode(jpeg->regs,
S5P_JPEG_RAW_IN_565);
Quoted 2 lines
drivers/media/video/s5p-jpeg/jpeg-v2x.c line 94
Quoted 2 lines
drivers/media/video/s5p-jpeg/jpeg-v2x.c new file +2
-0+else + jpeg_input_raw_mode(jpeg->regs,
S5P_JPEG_RAW_IN_422);
Quoted 37 lines
drivers/media/video/s5p-jpeg/jpeg-v2x.c line 104
Quoted 10 lines
drivers/media/video/s5p-jpeg/jpeg-v2x.c new file +10
-0+if (ctx->cap_q.fmt->fourcc ==V4L2_PIX_FMT_YUYV ) +jpeg_subsampling_mode (jpeg->regs, +S5P_JPEG_SUBSAMPLING_422 ); +else +jpeg_subsampling_mode (jpeg->regs, +S5P_JPEG_SUBSAMPLING_420 ); + +jpeg_enc_imgadr (jpeg->regs, src_addr); +jpeg_jpgadr (jpeg->regs, dst_addr); +jpeg_set_encode_hoff_cnt (jpeg->regs);This part is almost a verbatim copy of its counterpart from v3, only the sequence of operations is different and some calls are grouped into separate functions (e.g.
jpeg_htbl_ac,jpeg_htbl_dc,jpeg_qtbl). Why not factor out into some common piece of code?Quoted 5 lines
drivers/media/video/s5p-jpeg/jpeg-v2x.c new file +5
-0+ }else { +jpeg_set_encode_tbl_select (jpeg->regs,0 ); +jpeg_set_dec_scaling (jpeg->regs,0 ,0 ); +jpeg_jpgadr (jpeg->regs, src_addr); +if (ctx->cap_q.fmt->fourcc ==V4L2_PIX_FMT_YUYV ) {drivers/media/video/s5p-jpeg/jpeg-v2x.c line 119
Quoted 10 lines
drivers/media/video/s5p-jpeg/jpeg-v2x.c new file +10
-0+jpeg_dec_imgadr (jpeg->regs, dst_addr, +S5P_JPEG_RAW_OUT_422 , + ctx->out_q.w, ctx->out_q.h); +jpeg_outform_raw (jpeg->regs,S5P_JPEG_RAW_OUT_422 ); + }else { +jpeg_dec_imgadr (jpeg->regs, dst_addr, +S5P_JPEG_RAW_OUT_420 , + ctx->out_q.w, ctx->out_q.h); +jpeg_outform_raw (jpeg->regs,S5P_JPEG_RAW_OUT_420 ); + }This looks like this patch: http://patchwork.linuxtv.org/patch/10004/
If you applied it to version 2x, it would be nice if you applied it to version 3, too.
Quoted 13 lines
Quoted 10 lines
drivers/media/video/s5p-jpeg/jpeg-v2x.c new file +10
-0+jpeg_set_dec_bitstream_size (jpeg->regs, + ctx->out_q.size /32 +1 ); + } +jpeg_proc_mode (jpeg->regs, ctx->mode); +} + +void s5p_jpeg_runtime_resume_execute (struct device *dev) +{ + +}<...>
Andrzej