blob: 7662c9c2578815d802bde82021141c86dc5360fd [file] [log] [blame]
Ed Tanous1ccd57c2017-03-21 13:15:58 -07001/*
2* The definition and structure for AST 2500 Video Capture Driver
3* Portions Copyright (C) 2015 Insyde Software Corp.
4*
5* This program is free software; you can redistribute it and/or modify it
6* under the terms and conditions of the GNU General Public License,
7* version 2, as published by the Free Software Foundation.
8*
9* This program is distributed in the hope it will be useful, but WITHOUT
10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12* more details.
13*/
14
15#ifndef _VIDEO_H_
16#define _VIDEO_H_
17
18#define DEF_Y_TBL 4
19#define DEF_UV_TBL (7 | 0x10)
20
21#define VIDEO_IOC_MAGIC 'i'
22#define VIDIOCMCAPTURE _IOW(VIDEO_IOC_MAGIC, 1, struct video_mmap*)
23#define VIDIOCGFBUF _IOR(VIDEO_IOC_MAGIC, 2, struct video_buffer*)
24#define VIDIOCCAPTURE _IOW(VIDEO_IOC_MAGIC, 3, unsigned long )
25#define VIDIOCGCAPTURE _IOR(VIDEO_IOC_MAGIC, 4, subcapture_info*)
26#define VIDIOCSCAPTURE _IOW(VIDEO_IOC_MAGIC, 5, subcapture_info*)
27#define VIDIOCGSEQ _IOR(VIDEO_IOC_MAGIC, 6, vseq_info*)
28#define VIDIOCSSEQ _IOW(VIDEO_IOC_MAGIC, 7, vseq_info*)
29#define VIDIOCGVIN _IOR(VIDEO_IOC_MAGIC, 8, vin_info*)
30#define VIDIOCSVIN _IOW(VIDEO_IOC_MAGIC, 9, vin_info*)
31#define VIDIOCGPROC _IOR(VIDEO_IOC_MAGIC, 10, vproc_info*)
32#define VIDIOCSPROC _IOW(VIDEO_IOC_MAGIC, 11, vproc_info*)
33#define VIDIOCGCOMP _IOR(VIDEO_IOC_MAGIC, 12, vcomp_info*)
34#define VIDIOCSCOMP _IOW(VIDEO_IOC_MAGIC, 13, vcomp_info*)
35#define VIDIOCDBG _IOR(VIDEO_IOC_MAGIC, 14, unsigned int*)
36#define VIDIOCIMGREFRESH _IOW(VIDEO_IOC_MAGIC, 15, unsigned int*)
37
38#define VIDEO_IOC_MAXNR 15
39
40#define DUAL_COMP_BUFFER
41#define V_MASK
42
43#define AST2500_DEVICEID 0x25032402
44#define AST2400_DEVICEID 0x00002402
45
46// FLAG_FRAME_SIZE = (x/8) * (y/8) * 4
47// 144K:(1920/8)*(1200/8)*4 (current set 1M)
48#define FLAG_FRAME_SIZE 0x100000 // 1*1024*1024
49// PROC_FRAME_SIZE = X * Y * 4
50// 9M:1920*1200*4, 8M:1600*1200*4, 5M:1280*1024*4, 3M:1024*768*4
51#define PROC_FRAME_SIZE 0x900000 // 9*1024*1024
52// According to VREG(VR_STREAM_BUF_SZ) Video Stream Buffer Size Register
53// bit[2:0] = 7 (128KB), bit[4:3] = 3 (32 packets), So max compression data
54// will be 128KB * 32 = 4 MB,
55// 4M: (128*1024)*32
56#define COMP_FRAME_SIZE 0x400000 // 4*1024*1024
57// Total Video Mem Buffer Size
58// 2 PROC + 2 COMP + 1 FLAG for Capture Eng, 1 PROC + 1 COMP + 1 FLAG for Jpeg Capture Eng
59#define VIDEO_MEM_BUF_SIZE 0x2900000
60// Define Video Memory Start Address According to Memory & Kernel Size
61// Total:128M, 80M for Kernel
62#define SDRAM_MEM_OFFSET_ADDR 0x80000000
63
64#define SYS_MEM_SZ_128M 0
65#define SYS_MEM_SZ_256M 1
66#define SYS_MEM_SZ_512M 2
67#define SYS_MEM_SZ_1024M 3
68
69#define V_MEM_SZ_8M 0
70#define V_MEM_SZ_16M 1
71#define V_MEM_SZ_32M 2
72#define V_MEM_SZ_64M 3
73
74#define MODE_DETECT 0
75#define MODE_CHANGE 1
76#define MAX_NO_SYNC_CNT 100
77#define V_BUSY_TIME_OUT 6 //time tick
78
79// Register Offset
80#define SDRAM_PHY_BASE 0x1E6E0000 //1E6E:0000-1E6E:1FFF
81#define SCU_PHY_BASE 0x1E6E2000 //1E6E:2000-1E6E:2FFF
82#define VIDEO_PHY_BASE 0x1E700000 //1E70:0000-1E7F:FFFF
83
84// IRQ NUMBER
85#define VIDEO_IRQ 7 // for video
86#define CURSOR_IRQ 21 // for quick cursor
87
88// Register Definition
89#define VREG(x) (*(volatile unsigned int *)(IO_ADDRESS(x + VIDEO_PHY_BASE)))
90#define SDRAMREG(x) (*(volatile unsigned int *)(IO_ADDRESS(x + SDRAM_PHY_BASE)))
91#define SCUREG(x) (*(volatile unsigned int *)(IO_ADDRESS(x + SCU_PHY_BASE)))
92
93// Register Protection Key
94#define SCU_UNLOCK_KEY 0x1688A8A8
95#define MCR_UNLOCK_KEY 0xFC600309
96#define VR_UNLOCK_KEY 0x1A038AA8
97
98// SDRAM Memory Controller Register Offset
99#define MCR_PROTECTION_KEY 0x000
100#define MCR_CONFIGURATION 0x004
101#define BACKWARD_SCU_MPLL 0x120
102
103// System Control Unit Register Offset
104#define SCU_PROTECTION_KEY 0x00
105#define SCU_SYSTEM_RESET_CTL 0x04
106#define SCU_CLOCK_SELECTION 0x08
107#define SCU_CLK_STOP_CTL 0x0C
108#define SCU_INTERRUPT_CTL 0x18
109#define SCU_MPLL_PARAMETER 0x20
110#define SCU_MISC1_CTL 0x2C
111#define SCU_SOC_SCRATCH1 0x40
112#define SCU_VGA_SCRATCH1 0x50
113#define SCU_VGA_SCRATCH2 0x54
114#define SCU_HW_STRAPPING 0x70
115#define SCU_SILICON_REV_ID 0x7C
116#define SCU_DEVICE_ID 0x1A4
117
118// Video Register Offset
119#define VR_PROTECT_KEY 0x000
120#define VIDEO_SEQ_CTL 0x004
121#define VIDEO_PASS1_CTL 0x008
122#define TIMING_GEN_SETTING1 0x00C // if VIDEO_CTL1[5] = 0
123#define TIMING_GEN_SETTING2 0x010 // if VIDEO_CTL1[5] = 0
124#define SCALING_FACTOR 0x014
125#define SCALING_FILTER_PARAMETER0 0x018
126#define SCALING_FILTER_PARAMETER1 0x01C
127#define SCALING_FILTER_PARAMETER2 0x020
128#define SCALING_FILTER_PARAMETER3 0x024
129#define BCD_CTL 0x02C
130#define CAPTURING_WINDOW_SETTING 0x030
131#define COMP_WINDOW_SETTING 0x034
132#define COMP_STREAM_BUF_PROC_OFFSET 0x038
133#define COMP_STREAM_BUF_READ_OFFSET 0x03C
134#define CRC_BUF_BASE_ADDR 0x040
135#define VIDEO_SOURCE_BUF1_BASE_ADDR 0x044
136#define SOURCE_BUF_SCANLINE_OFFSET 0x048
137#define VIDEO_SOURCE_BUF2_BASE_ADDR 0x04C
138#define BCD_FLAG_BUF_BASE_ADDR 0x050
139#define COMP_STREAM_BUF_BASE_ADDR 0x054
140#define VIDEO_STREAM_BUF_SIZE 0x058
141#define COMP_STREAM_BUF_WRITE_OFFSET 0x05C
142#define VIDEO_COMP_CTL 0x060
143#define JPEG_BIT_CTRL 0x064
144#define QUANTIZATION_VALUE 0x068
145#define COPY_BUF_BASE_ADDR 0x06C
146#define COMP_STREAM_SIZE 0x070
147#define COMP_BLOCK_NUM 0x074
148#define COMP_STREAM_BUF_END_OFFSET 0x078
149#define COMP_FRAME_COUNTER 0x07C
150#define USER_HDR_PARAM 0x080
151#define SOURCE_L_R_EDGE_DETECT 0x090
152#define SOURCE_T_B_EDGE_DETECT 0x094
153#define MODE_DETECT_STATUS 0x098
154
155/* Video Management Engine, i.e. 2nd Set Video Engine */
156#define VM_SEQ_CTRL 0x204
157#define VM_PASS_CTRL 0x208
158#define VM_SCALING_FACTOR 0x214
159#define VM_CAP_WINDOW_SETTING 0x230
160#define VM_COMP_WINDOW_SETTING 0x234
161#define VM_COMP_BUF_PROC_OFFSET 0x238
162#define VM_COMP_BUF_READ_OFFSET 0x23C
163#define VM_JPEG_HEADER_BUFF 0x240
164#define VM_SOURCE_BUFF0 0x244
165#define VM_SRC_BUF_SCANLINE_OFFSET 0x248
166#define VM_COMPRESS_BUFF 0x254
167#define VM_STREAM_SIZE 0x258
168#define VM_COMPRESS_CTRL 0x260
169#define VM_JPEG_BIT_CTRL 0x264
170#define VM_QUANTIZATION_VALUE 0x268
171#define VM_COPY_BUF_BASE_ADDR 0x26C
172#define VM_COMP_STREAM_SIZE 0x070
173#define VM_COMP_BLOCK_NUM 0x074
174#define VM_COMP_STREAM_BUF_END_OFFSET 0x278
175#define VM_USER_HDR_PARAM 0x280
176
177#define VIDEO_PASS3_CTRL 0x300
178#define INTERRUPT_CTL 0x304
179#define INTERRUPT_STATUS 0x308
180#define MODE_DETECT_PARAMETER 0x30C
181#define MEM_RESTRICT_START_ADDR 0x310
182#define MEM_RESTRICT_END_ADDR 0x314
183#define PRI_CRC_PARAMETER 0x320
184#define SEC_CRC_PARAMETER 0x324
185#define DATA_TRUNCATION 0x328
186#define VGA_SCRATCH_REMAP1 0x340
187#define VGA_SCRATCH_REMAP2 0x344
188#define VGA_SCRATCH_REMAP3 0x348
189#define VGA_SCRATCH_REMAP4 0x34C
190#define VGA_SCRATCH_REMAP5 0x350
191#define VGA_SCRATCH_REMAP6 0x354
192#define VGA_SCRATCH_REMAP7 0x358
193#define VGA_SCRATCH_REMAP8 0x35C
194#define RC4KEYS_REGISTER 0x400 //0x400~0x4FC RC4 Encryption Key Register #0~#63
195
196//
197// Cursor struct is used in User Mode
198//
199typedef struct _cursor_attribution_tag {
200 unsigned int posX;
201 unsigned int posY;
202 unsigned int cur_width;
203 unsigned int cur_height;
204 unsigned int cur_type; //0:mono 1:color 2:disappear cursor
205 unsigned int cur_change_flag;
206} AST_CUR_ATTRIBUTION_TAG;
207
208//
209// For storing Cursor Information
210//
211typedef struct _cursor_tag {
212 AST_CUR_ATTRIBUTION_TAG attr;
213 //unsigned char icon[MAX_CUR_OFFSETX*MAX_CUR_OFFSETY*2];
214 unsigned char *icon; //[64*64*2];
215} AST_CURSOR_TAG;
216
217//
218// For select image format, i.e. 422 JPG420, 444 JPG444, lumin/chrom table, 0 ~ 11, low to high
219//
220typedef struct _video_features {
221 short jpg_fmt; //422:JPG420, 444:JPG444
222 short lumin_tbl;
223 short chrom_tbl;
224 short tolerance_noise;
225 int w;
226 int h;
227 unsigned char *buf;
228} FEATURES_TAG;
229
230//
231// For configure video engine control registers
232//
233typedef struct _image_info {
234 short do_image_refresh; // Action 0:motion 1:fullframe 2:quick cursor
235 char qc_valid; // quick cursor enable/disable
236 unsigned int len;
237 int crypttype;
238 char cryptkey[16];
239 union {
240 FEATURES_TAG features;
241 AST_CURSOR_TAG cursor_info;
242 } parameter;
243} IMAGE_INFO;
244
245typedef struct _video_set_chk {
246 short get_qc_info; // Quick Cursor Info
247 short do_image_refresh;
248 FEATURES_TAG features;
249} video_set_chk;
250
251struct video_buffer {
252 void *base;
253 int height, width;
254 int depth;
255 int bytesperline;
256};
257
258//
259// Data Structure for Video Buffer Layout
260// kept information about video buffer layout, used in memory initialization.
261//
262typedef struct _buf_layout {
263 int c_proc;
264 int c_comp;
265 unsigned int in; // video in buffer
266 unsigned int proc [2]; // old and current proc buffer
267 unsigned int comp [2]; // compressed data buffer
268 unsigned int flag; // flag buffer
269 unsigned int jpgproc; // old and current proc buffer for jpeg
270 unsigned int jpgcomp; // compressed data buffer for jpeg
271 unsigned int jpgflag; // flag buffer for jpeg
272} buf_layout;
273
274//
275// subcapture_info:
276// linestep - byte per line after scaling, but 32 byte align
277// step - scaling step, decrease 8 pixels a step after scaling.
278// scaled_h - height after scaling.
279// scaled_w - width after scaling.
280// hor_factor, ver_factor - horizontal and vertical scaling factor
281// init - initialized = 0, not initialized = 1, set by mode_detect
282//
283typedef struct _subcature_info {
284 int linestep;
285 short x, y, width, height, scaled_h, scaled_w;
286 unsigned short hor_factor, ver_factor;
287 short step, init;
288} subcapture_info;
289
290//
291// video_hw_info:
292// cap_seq - capture orders, CAP_PASSX and CAP_INIT_FRAME
293// cap_int - interrupt to enable
294// cur_idx - current idx of resolution table content.
295//
296// mode_change must be
297// set by interrupt handler, and clear
298// when capture start.
299//
300
301//FK Comment :
302//interrupt handler for mode_chage
303//capture start, mode_chage, clear
304//cur_idx resolution state, Ex: 800x600 80Hz, ...
305//cap_int interrupt enable
306//cap_seq captor orders i.e. CAP_PASS1, CAP_PASS2..., or CAP_INIT_FRAME
307#define MCAP_FRAME 2
308typedef struct _mcap_info {
309 int offset;
310 int size;
311} mcap_info;
312
313typedef struct _video_hw_info {
314 int cap_seq;
315 mcap_info mcap [MCAP_FRAME]; // record each frame size of mcapture
316 //volatile short width, height, fix_x, fix_y, cur_idx;
317 short width, height, fix_x, fix_y, cur_idx;
318 short max_h, max_w, min_h, min_w;
319 short cap_int;
320
321 char mode_changed; //1130 modify
322 //volatile char mode_changed; //1130 modify
323 char cap_done, capturing, disconnect; //, mode_changed; //, cur_idx;
324 char can_capture; // prevent hardware error.
325 subcapture_info subcap;
326// VIDEO_ENGINE_INFO ve_info;
327} video_hw_info;
328
329struct video_mmap {
330 unsigned int frame; // Frame (0 - n) for double buffer
331 int height, width;
332 unsigned int format; // should be VIDEO_PALETTE_*
333};
334
335// Internal_Mode Table for resolution checking
336typedef struct {
337 unsigned short HorizontalActive;
338 unsigned short VerticalActive;
339 unsigned short RefreshRateIndex;
340 unsigned int PixelClock;
341} INTERNAL_MODE;
342
343INTERNAL_MODE Internal_Mode [] = {
344 // 1024x768
345 { 1024, 768, 0, 65 },
346 { 1024, 768, 1, 65 },
347 { 1024, 768, 2, 75 },
348 { 1024, 768, 3, 79 },
349 { 1024, 768, 4, 95 },
350
351 // 1280x1024
352 { 1280, 1024, 0, 108 },
353 { 1280, 1024, 1, 108 },
354 { 1280, 1024, 2, 135 },
355 { 1280, 1024, 3, 158 },
356
357 // 1600x1200
358 { 1600, 1200, 0, 162 },
359 { 1600, 1200, 1, 162 },
360 { 1600, 1200, 2, 176 },
361 { 1600, 1200, 3, 189 },
362 { 1600, 1200, 4, 203 },
363 { 1600, 1200, 5, 230 },
364
365 // 1920x1200 reduce blank
366 { 1920, 1200, 0, 157 },
367 { 1920, 1200, 1, 157 },
368};
369
370typedef enum vga_color_mode {
371 VGA_NO_SIGNAL = 0,
372 EGA_MODE,
373 VGA_MODE,
374 VGA_15BPP_MODE,
375 VGA_16BPP_MODE,
376 VGA_32BPP_MODE,
377} color_mode;
378#endif //_VIDEO_H_