[media] go7007: add back 'repeat sequence header' control
[deliverable/linux.git] / drivers / staging / media / go7007 / go7007-priv.h
CommitLineData
866b8695
GKH
1/*
2 * Copyright (C) 2005-2006 Micronas USA Inc.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License (Version 2) as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software Foundation,
15 * Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
16 */
17
18/*
19 * This is the private include file for the go7007 driver. It should not
20 * be included by anybody but the driver itself, and especially not by
21 * user-space applications.
22 */
23
0b398f4f 24#include <media/v4l2-device.h>
9b8451d5 25#include <media/v4l2-ctrls.h>
bae74320 26#include <media/v4l2-fh.h>
ffcc1c08 27#include <media/videobuf2-core.h>
0b398f4f 28
866b8695
GKH
29struct go7007;
30
31/* IDs to activate board-specific support code */
32#define GO7007_BOARDID_MATRIX_II 0
33#define GO7007_BOARDID_MATRIX_RELOAD 1
34#define GO7007_BOARDID_STAR_TREK 2
35#define GO7007_BOARDID_PCI_VOYAGER 3
36#define GO7007_BOARDID_XMEN 4
37#define GO7007_BOARDID_XMEN_II 5
38#define GO7007_BOARDID_XMEN_III 6
39#define GO7007_BOARDID_MATRIX_REV 7
9ff76e36
HV
40#define GO7007_BOARDID_PX_M402U 8
41#define GO7007_BOARDID_PX_TV402U 9
42#define GO7007_BOARDID_LIFEVIEW_LR192 10 /* TV Walker Ultra */
43#define GO7007_BOARDID_ENDURA 11
44#define GO7007_BOARDID_ADLINK_MPG24 12
45#define GO7007_BOARDID_SENSORAY_2250 13 /* Sensoray 2250/2251 */
866b8695
GKH
46
47/* Various characteristics of each board */
48#define GO7007_BOARD_HAS_AUDIO (1<<0)
49#define GO7007_BOARD_USE_ONBOARD_I2C (1<<1)
50#define GO7007_BOARD_HAS_TUNER (1<<2)
51
52/* Characteristics of sensor devices */
53#define GO7007_SENSOR_VALID_POLAR (1<<0)
54#define GO7007_SENSOR_HREF_POLAR (1<<1)
55#define GO7007_SENSOR_VREF_POLAR (1<<2)
56#define GO7007_SENSOR_FIELD_ID_POLAR (1<<3)
57#define GO7007_SENSOR_BIT_WIDTH (1<<4)
58#define GO7007_SENSOR_VALID_ENABLE (1<<5)
59#define GO7007_SENSOR_656 (1<<6)
60#define GO7007_SENSOR_CONFIG_MASK 0x7f
61#define GO7007_SENSOR_TV (1<<7)
62#define GO7007_SENSOR_VBI (1<<8)
63#define GO7007_SENSOR_SCALING (1<<9)
b95dd82c 64#define GO7007_SENSOR_SAA7115 (1<<10)
866b8695
GKH
65
66/* Characteristics of audio sensor devices */
67#define GO7007_AUDIO_I2S_MODE_1 (1)
68#define GO7007_AUDIO_I2S_MODE_2 (2)
69#define GO7007_AUDIO_I2S_MODE_3 (3)
70#define GO7007_AUDIO_BCLK_POLAR (1<<2)
71#define GO7007_AUDIO_WORD_14 (14<<4)
72#define GO7007_AUDIO_WORD_16 (16<<4)
73#define GO7007_AUDIO_ONE_CHANNEL (1<<11)
74#define GO7007_AUDIO_I2S_MASTER (1<<16)
75#define GO7007_AUDIO_OKI_MODE (1<<17)
76
77struct go7007_board_info {
78 char *firmware;
79 unsigned int flags;
80 int hpi_buffer_cap;
81 unsigned int sensor_flags;
82 int sensor_width;
83 int sensor_height;
84 int sensor_framerate;
85 int sensor_h_offset;
86 int sensor_v_offset;
87 unsigned int audio_flags;
88 int audio_rate;
89 int audio_bclk_div;
90 int audio_main_div;
91 int num_i2c_devs;
dcafb6de 92 struct go_i2c {
7400516a 93 const char *type;
3acd16ab
HV
94 int is_video:1;
95 int is_audio:1;
866b8695 96 int addr;
dcafb6de 97 u32 flags;
3acd16ab 98 } i2c_devs[5];
866b8695
GKH
99 int num_inputs;
100 struct {
101 int video_input;
3acd16ab 102 int audio_index;
866b8695
GKH
103 char *name;
104 } inputs[4];
3acd16ab
HV
105 int video_config;
106 int num_aud_inputs;
107 struct {
108 int audio_input;
109 char *name;
110 } aud_inputs[3];
866b8695
GKH
111};
112
113struct go7007_hpi_ops {
114 int (*interface_reset)(struct go7007 *go);
115 int (*write_interrupt)(struct go7007 *go, int addr, int data);
116 int (*read_interrupt)(struct go7007 *go);
117 int (*stream_start)(struct go7007 *go);
118 int (*stream_stop)(struct go7007 *go);
119 int (*send_firmware)(struct go7007 *go, u8 *data, int len);
d73f822c 120 int (*send_command)(struct go7007 *go, unsigned int cmd, void *arg);
d5d3a7cc 121 void (*release)(struct go7007 *go);
866b8695
GKH
122};
123
124/* The video buffer size must be a multiple of PAGE_SIZE */
125#define GO7007_BUF_PAGES (128 * 1024 / PAGE_SIZE)
126#define GO7007_BUF_SIZE (GO7007_BUF_PAGES << PAGE_SHIFT)
127
128struct go7007_buffer {
ffcc1c08
HV
129 struct vb2_buffer vb;
130 struct list_head list;
866b8695
GKH
131 unsigned int frame_offset;
132 u32 modet_active;
866b8695
GKH
133};
134
866b8695
GKH
135#define GO7007_RATIO_1_1 0
136#define GO7007_RATIO_4_3 1
137#define GO7007_RATIO_16_9 2
138
139enum go7007_parser_state {
140 STATE_DATA,
141 STATE_00,
142 STATE_00_00,
143 STATE_00_00_01,
144 STATE_FF,
145 STATE_VBI_LEN_A,
146 STATE_VBI_LEN_B,
147 STATE_MODET_MAP,
148 STATE_UNPARSED,
149};
150
151struct go7007 {
152 struct device *dev;
4d217b83 153 u8 bus_info[32];
866b8695
GKH
154 struct go7007_board_info *board_info;
155 unsigned int board_id;
156 int tuner_type;
157 int channel_number; /* for multi-channel boards like Adlink PCI-MPG24 */
158 char name[64];
6bb0e65d 159 struct video_device vdev;
95ef3940
HV
160 void *boot_fw;
161 unsigned boot_fw_len;
0b398f4f 162 struct v4l2_device v4l2_dev;
9b8451d5 163 struct v4l2_ctrl_handler hdl;
35d2d76d
HV
164 struct v4l2_ctrl *mpeg_video_encoding;
165 struct v4l2_ctrl *mpeg_video_gop_size;
166 struct v4l2_ctrl *mpeg_video_gop_closure;
167 struct v4l2_ctrl *mpeg_video_bitrate;
168 struct v4l2_ctrl *mpeg_video_aspect_ratio;
7e4bfb9e 169 struct v4l2_ctrl *mpeg_video_b_frames;
778ca511 170 struct v4l2_ctrl *mpeg_video_rep_seqheader;
866b8695
GKH
171 enum { STATUS_INIT, STATUS_ONLINE, STATUS_SHUTDOWN } status;
172 spinlock_t spinlock;
fd9a40da 173 struct mutex hw_lock;
ffcc1c08 174 struct mutex serialize_lock;
866b8695 175 int audio_enabled;
3acd16ab
HV
176 struct v4l2_subdev *sd_video;
177 struct v4l2_subdev *sd_audio;
9b6ebf33 178 u8 usb_buf[16];
866b8695
GKH
179
180 /* Video input */
181 int input;
3acd16ab 182 int aud_input;
866b8695 183 enum { GO7007_STD_NTSC, GO7007_STD_PAL, GO7007_STD_OTHER } standard;
50deb749 184 v4l2_std_id std;
866b8695
GKH
185 int sensor_framerate;
186 int width;
187 int height;
188 int encoder_h_offset;
189 int encoder_v_offset;
190 unsigned int encoder_h_halve:1;
191 unsigned int encoder_v_halve:1;
192 unsigned int encoder_subsample:1;
193
194 /* Encoder config */
35d2d76d 195 u32 format;
866b8695
GKH
196 int bitrate;
197 int fps_scale;
198 int pali;
199 int aspect_ratio;
200 int gop_size;
201 unsigned int ipb:1;
202 unsigned int closed_gop:1;
203 unsigned int repeat_seqhead:1;
204 unsigned int seq_header_enable:1;
205 unsigned int gop_header_enable:1;
206 unsigned int dvd_mode:1;
207 unsigned int interlace_coding:1;
208
209 /* Motion detection */
210 unsigned int modet_enable:1;
211 struct {
212 unsigned int enable:1;
213 int pixel_threshold;
214 int motion_threshold;
215 int mb_threshold;
216 } modet[4];
217 unsigned char modet_map[1624];
218 unsigned char active_map[216];
219
220 /* Video streaming */
ffcc1c08
HV
221 struct mutex queue_lock;
222 struct vb2_queue vidq;
866b8695
GKH
223 enum go7007_parser_state state;
224 int parse_length;
225 u16 modet_word;
226 int seen_frame;
227 u32 next_seq;
ffcc1c08 228 struct list_head vidq_active;
866b8695 229 wait_queue_head_t frame_waitq;
ffcc1c08 230 struct go7007_buffer *active_buf;
866b8695
GKH
231
232 /* Audio streaming */
233 void (*audio_deliver)(struct go7007 *go, u8 *buf, int length);
234 void *snd_context;
235
236 /* I2C */
237 int i2c_adapter_online;
238 struct i2c_adapter i2c_adapter;
239
240 /* HPI driver */
241 struct go7007_hpi_ops *hpi_ops;
242 void *hpi_context;
243 int interrupt_available;
244 wait_queue_head_t interrupt_waitq;
245 unsigned short interrupt_value;
246 unsigned short interrupt_data;
247};
248
0b398f4f
PE
249static inline struct go7007 *to_go7007(struct v4l2_device *v4l2_dev)
250{
251 return container_of(v4l2_dev, struct go7007, v4l2_dev);
252}
253
fd9a40da 254/* All of these must be called with the hpi_lock mutex held! */
866b8695
GKH
255#define go7007_interface_reset(go) \
256 ((go)->hpi_ops->interface_reset(go))
257#define go7007_write_interrupt(go, x, y) \
258 ((go)->hpi_ops->write_interrupt)((go), (x), (y))
259#define go7007_stream_start(go) \
260 ((go)->hpi_ops->stream_start(go))
261#define go7007_stream_stop(go) \
262 ((go)->hpi_ops->stream_stop(go))
263#define go7007_send_firmware(go, x, y) \
264 ((go)->hpi_ops->send_firmware)((go), (x), (y))
265#define go7007_write_addr(go, x, y) \
266 ((go)->hpi_ops->write_interrupt)((go), (x)|0x8000, (y))
267
268/* go7007-driver.c */
269int go7007_read_addr(struct go7007 *go, u16 addr, u16 *data);
270int go7007_read_interrupt(struct go7007 *go, u16 *value, u16 *data);
271int go7007_boot_encoder(struct go7007 *go, int init_i2c);
272int go7007_reset_encoder(struct go7007 *go);
3acd16ab 273int go7007_register_encoder(struct go7007 *go, unsigned num_i2c_devs);
866b8695
GKH
274int go7007_start_encoder(struct go7007 *go);
275void go7007_parse_video_stream(struct go7007 *go, u8 *buf, int length);
276struct go7007 *go7007_alloc(struct go7007_board_info *board,
277 struct device *dev);
50deb749
HV
278void go7007_update_board(struct go7007 *go);
279
866b8695
GKH
280/* go7007-fw.c */
281int go7007_construct_fw_image(struct go7007 *go, u8 **fw, int *fwlen);
282
283/* go7007-i2c.c */
284int go7007_i2c_init(struct go7007 *go);
285int go7007_i2c_remove(struct go7007 *go);
286
287/* go7007-v4l2.c */
288int go7007_v4l2_init(struct go7007 *go);
9b8451d5 289int go7007_v4l2_ctrl_init(struct go7007 *go);
866b8695
GKH
290void go7007_v4l2_remove(struct go7007 *go);
291
292/* snd-go7007.c */
293int go7007_snd_init(struct go7007 *go);
294int go7007_snd_remove(struct go7007 *go);
This page took 0.45612 seconds and 5 git commands to generate.