Skip to content

Commit 3a7f36e

Browse files
committed
Add some cedrus regs
1 parent 985e914 commit 3a7f36e

3 files changed

Lines changed: 54 additions & 28 deletions

File tree

cedrus.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ static struct cedrus
4747
pthread_mutex_t device_lock;
4848
} ve = { .fd = -1, .device_lock = PTHREAD_MUTEX_INITIALIZER };
4949

50-
EXPORT struct cedrus *cedrus_open(void)
50+
EXPORT cedrus_t *cedrus_open(void)
5151
{
5252
pthread_mutex_lock(&open_lock);
5353
if (ve.fd != -1) {
@@ -96,14 +96,16 @@ EXPORT struct cedrus *cedrus_open(void)
9696
ioctl(ve.fd, IOCTL_SET_VE_FREQ + ve.ioctl_offset, 320);
9797
ioctl(ve.fd, IOCTL_RESET_VE + ve.ioctl_offset, 0);
9898

99-
writel(0x00130007, ve.regs + VE_CTRL);
99+
writel(0x00130000 | VE_CTRL_ENGINE_RESET, ve.regs + VE_CTRL);
100100

101+
//printf("[libcedrus SUNXI] VE version 0x%04x opened\n", ve.version);
101102
open_count++;
102103
pthread_mutex_unlock(&open_lock);
103104
return &ve;
104105

105106
unmap:
106107
munmap(ve.regs, 0x800);
108+
107109
close:
108110
close(ve.fd);
109111
ve.fd = -1;
@@ -152,11 +154,11 @@ EXPORT int cedrus_ve_wait(struct cedrus *dev, int timeout)
152154
if (!dev)
153155
return -1;
154156

155-
if (((reg = readl(dev->regs + VE_CTRL)) & CEDRUS_ENGINE_H264_ENC) == CEDRUS_ENGINE_H264_ENC) {
157+
if (((reg = readl(dev->regs + VE_CTRL)) & VE_CTRL_ENGINE_FIELD) == VE_CTRL_ENGINE_AVC) {
156158
engine_wait = IOCTL_WAIT_VE_DE + dev->ioctl_offset;
157159
}
158160

159-
//printf("we engine %04X, we wait %d\n", reg, engine_wait);
161+
//printf("ve engine %04X, ve wait %d\n", reg, engine_wait);
160162

161163
return ioctl(dev->fd, engine_wait, timeout);
162164
}
@@ -166,7 +168,7 @@ EXPORT void *cedrus_ve_get(struct cedrus *dev, enum cedrus_engine engine, uint32
166168
if (!dev || pthread_mutex_lock(&dev->device_lock))
167169
return NULL;
168170

169-
writel(0x00130000 | (engine & 0xf) | (flags & ~0xf), dev->regs + VE_CTRL);
171+
writel(0x00130000 | (engine & VE_CTRL_ENGINE_FIELD) | (flags & ~VE_CTRL_ENGINE_FIELD), dev->regs + VE_CTRL);
170172

171173
return dev->regs;
172174
}
@@ -176,7 +178,7 @@ EXPORT void cedrus_ve_put(struct cedrus *dev)
176178
if (!dev)
177179
return;
178180

179-
writel(0x00130007, dev->regs + VE_CTRL);
181+
writel(0x00130000 | VE_CTRL_ENGINE_RESET, dev->regs + VE_CTRL);
180182
pthread_mutex_unlock(&dev->device_lock);
181183
}
182184

cedrus.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,16 @@
2222

2323
#include <stddef.h>
2424
#include <stdint.h>
25+
#include "cedrus_regs.h"
2526

2627
typedef struct cedrus cedrus_t;
2728

28-
enum cedrus_engine { CEDRUS_ENGINE_MPEG = 0x0, CEDRUS_ENGINE_H264 = 0x1, CEDRUS_ENGINE_HEVC = 0x4, CEDRUS_ENGINE_H264_ENC = 0xb };
29+
enum cedrus_engine {
30+
CEDRUS_ENGINE_MPEG = VE_CTRL_ENGINE_MPEG,
31+
CEDRUS_ENGINE_H264 = VE_CTRL_ENGINE_H264,
32+
CEDRUS_ENGINE_HEVC = VE_CTRL_ENGINE_HEVC,
33+
CEDRUS_ENGINE_AVC = VE_CTRL_ENGINE_AVC
34+
};
2935

3036
cedrus_t *cedrus_open(void);
3137
void cedrus_close(cedrus_t *dev);

cedrus_regs.h

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ static inline uint32_t readl(void *addr)
3232
return *((volatile uint32_t *) addr);
3333
}
3434

35+
// VE general registers
3536
#define VE_CTRL 0x000
3637
#define VE_RESET 0x004
3738
#define VE_OUTPUT_CHROMA_OFFSET 0x0c4
@@ -40,6 +41,17 @@ static inline uint32_t readl(void *addr)
4041
#define VE_OUTPUT_FORMAT 0x0ec
4142
#define VE_VERSION 0x0f0
4243

44+
// VE_CTRL register values
45+
#define VE_CTRL_ENGINE_MPEG 0x00
46+
#define VE_CTRL_ENGINE_H264 0x01
47+
#define VE_CTRL_ENGINE_HEVC 0x04
48+
#define VE_CTRL_ENGINE_RESET 0x07
49+
#define VE_CTRL_ENGINE_AVC 0x0b
50+
#define VE_CTRL_ENGINE_FIELD 0x0f
51+
#define VE_CTRL_ENABLE_ISP 0x40
52+
#define VE_CTRL_ENABLE_AVC 0x80
53+
54+
// VE MPEG engine registers
4355
#define VE_MPEG_PIC_HDR 0x100
4456
#define VE_MPEG_VOP_HDR 0x104
4557
#define VE_MPEG_SIZE 0x108
@@ -65,17 +77,15 @@ static inline uint32_t readl(void *addr)
6577
#define VE_MPEG_BACK_CHROMA 0x15c
6678
#define VE_MPEG_IQ_MIN_INPUT 0x180
6779
#define VE_MPEG_QP_INPUT 0x184
68-
6980
#define VE_MPEG_JPEG_SIZE 0x1b8
7081
#define VE_MPEG_JPEG_RES_INT 0x1c0
71-
7282
#define VE_MPEG_ROT_LUMA 0x1cc
7383
#define VE_MPEG_ROT_CHROMA 0x1d0
7484
#define VE_MPEG_SDROT_CTRL 0x1d4
85+
#define VE_MPEG_SRAM_ADDR 0x1e0
86+
#define VE_MPEG_SRAM_DATA 0x1e4
7587

76-
#define VE_MPEG_RAM_WRITE_PTR 0x1e0
77-
#define VE_MPEG_RAM_WRITE_DATA 0x1e4
78-
88+
// VE H264 engine registers
7989
#define VE_H264_FRAME_SIZE 0x200
8090
#define VE_H264_PIC_HDR 0x204
8191
#define VE_H264_SLICE_HDR 0x208
@@ -99,15 +109,17 @@ static inline uint32_t readl(void *addr)
99109
#define VE_H264_MB_ADDR 0x260
100110
#define VE_H264_ERROR 0x2b8
101111
#define VE_H264_BASIC_BITS 0x2dc
102-
#define VE_H264_RAM_WRITE_PTR 0x2e0
103-
#define VE_H264_RAM_WRITE_DATA 0x2e4
112+
#define VE_H264_SRAM_ADDR 0x2e0
113+
#define VE_H264_SRAM_DATA 0x2e4
104114

105-
#define VE_SRAM_H264_PRED_WEIGHT_TABLE 0x000
106-
#define VE_SRAM_H264_FRAMEBUFFER_LIST 0x400
107-
#define VE_SRAM_H264_REF_LIST0 0x640
108-
#define VE_SRAM_H264_REF_LIST1 0x664
109-
#define VE_SRAM_H264_SCALING_LISTS 0x800
115+
// VE_H264_SRAM_ADDR register values
116+
#define VE_H264_SRAM_PRED_WEIGHT_TABLE 0x000
117+
#define VE_H264_SRAM_FRAMEBUFFER_LIST 0x400
118+
#define VE_H264_SRAM_REF_LIST0 0x640
119+
#define VE_H264_SRAM_REF_LIST1 0x664
120+
#define VE_H264_SRAM_SCALING_LISTS 0x800
110121

122+
// VE HEVC engine registers
111123
#define VE_HEVC_NAL_HDR 0x500
112124
#define VE_HEVC_SPS 0x504
113125
#define VE_HEVC_PIC_SIZE 0x508
@@ -138,30 +150,36 @@ static inline uint32_t readl(void *addr)
138150
#define VE_HEVC_SRAM_ADDR 0x5e0
139151
#define VE_HEVC_SRAM_DATA 0x5e4
140152

141-
#define VE_SRAM_HEVC_PRED_WEIGHT_LUMA_L0 0x000
142-
#define VE_SRAM_HEVC_PRED_WEIGHT_CHROMA_L0 0x020
143-
#define VE_SRAM_HEVC_PRED_WEIGHT_LUMA_L1 0x060
144-
#define VE_SRAM_HEVC_PRED_WEIGHT_CHROMA_L1 0x080
145-
#define VE_SRAM_HEVC_PIC_LIST 0x400
146-
#define VE_SRAM_HEVC_SCALING_LISTS 0x800
147-
#define VE_SRAM_HEVC_REF_PIC_LIST0 0xc00
148-
#define VE_SRAM_HEVC_REF_PIC_LIST1 0xc10
149-
153+
// VE_HEVC_SRAM_ADDR register values
154+
#define VE_HEVC_SRAM_PRED_WEIGHT_LUMA_L0 0x000
155+
#define VE_HEVC_SRAM_PRED_WEIGHT_CHROMA_L0 0x020
156+
#define VE_HEVC_SRAM_PRED_WEIGHT_LUMA_L1 0x060
157+
#define VE_HEVC_SRAM_PRED_WEIGHT_CHROMA_L1 0x080
158+
#define VE_HEVC_SRAM_PIC_LIST 0x400
159+
#define VE_HEVC_SRAM_SCALING_LISTS 0x800
160+
#define VE_HEVC_SRAM_REF_PIC_LIST0 0xc00
161+
#define VE_HEVC_SRAM_REF_PIC_LIST1 0xc10
162+
163+
// VE ISP engine registers
150164
#define VE_ISP_INPUT_SIZE 0xa00
151165
#define VE_ISP_INPUT_STRIDE 0xa04
166+
#define VE_ISP_CTRL 0xa08
152167
#define VE_ISP_INPUT_LUMA 0xa78
153168
#define VE_ISP_INPUT_CHROMA 0xa7c
154169

170+
// VE AVC engine registers
155171
#define VE_AVC_PARAM 0xb04
156172
#define VE_AVC_QP 0xb08
157173
#define VE_AVC_MOTION_EST 0xb10
158174
#define VE_AVC_CTRL 0xb14
159175
#define VE_AVC_TRIGGER 0xb18
160176
#define VE_AVC_STATUS 0xb1c
161177
#define VE_AVC_BASIC_BITS 0xb20
178+
#define VE_AVC_UNK_BUF 0xb60
162179
#define VE_AVC_VLE_ADDR 0xb80
163180
#define VE_AVC_VLE_END 0xb84
164181
#define VE_AVC_VLE_OFFSET 0xb88
182+
#define VE_AVC_VLE_MAX 0xb8c
165183
#define VE_AVC_VLE_LENGTH 0xb90
166184
#define VE_AVC_REF_LUMA 0xba0
167185
#define VE_AVC_REF_CHROMA 0xba4

0 commit comments

Comments
 (0)