]> Pileus Git - ~andy/linux/blob - drivers/staging/media/go7007/go7007-priv.h
Merge git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6
[~andy/linux] / drivers / staging / media / go7007 / go7007-priv.h
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
24 #include <media/v4l2-device.h>
25 #include <media/v4l2-ctrls.h>
26 #include <media/v4l2-fh.h>
27 #include <media/videobuf2-core.h>
28
29 struct 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
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 */
46 #define GO7007_BOARDID_ADS_USBAV_709    14
47
48 /* Various characteristics of each board */
49 #define GO7007_BOARD_HAS_AUDIO          (1<<0)
50 #define GO7007_BOARD_USE_ONBOARD_I2C    (1<<1)
51 #define GO7007_BOARD_HAS_TUNER          (1<<2)
52
53 /* Characteristics of sensor devices */
54 #define GO7007_SENSOR_VALID_POLAR       (1<<0)
55 #define GO7007_SENSOR_HREF_POLAR        (1<<1)
56 #define GO7007_SENSOR_VREF_POLAR        (1<<2)
57 #define GO7007_SENSOR_FIELD_ID_POLAR    (1<<3)
58 #define GO7007_SENSOR_BIT_WIDTH         (1<<4)
59 #define GO7007_SENSOR_VALID_ENABLE      (1<<5)
60 #define GO7007_SENSOR_656               (1<<6)
61 #define GO7007_SENSOR_CONFIG_MASK       0x7f
62 #define GO7007_SENSOR_TV                (1<<7)
63 #define GO7007_SENSOR_VBI               (1<<8)
64 #define GO7007_SENSOR_SCALING           (1<<9)
65 #define GO7007_SENSOR_SAA7115           (1<<10)
66
67 /* Characteristics of audio sensor devices */
68 #define GO7007_AUDIO_I2S_MODE_1         (1)
69 #define GO7007_AUDIO_I2S_MODE_2         (2)
70 #define GO7007_AUDIO_I2S_MODE_3         (3)
71 #define GO7007_AUDIO_BCLK_POLAR         (1<<2)
72 #define GO7007_AUDIO_WORD_14            (14<<4)
73 #define GO7007_AUDIO_WORD_16            (16<<4)
74 #define GO7007_AUDIO_ONE_CHANNEL        (1<<11)
75 #define GO7007_AUDIO_I2S_MASTER         (1<<16)
76 #define GO7007_AUDIO_OKI_MODE           (1<<17)
77
78 struct go7007_board_info {
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;
92         struct go_i2c {
93                 const char *type;
94                 unsigned int is_video:1;
95                 unsigned int is_audio:1;
96                 int addr;
97                 u32 flags;
98         } i2c_devs[5];
99         int num_inputs;
100         struct {
101                 int video_input;
102                 int audio_index;
103                 char *name;
104         } inputs[4];
105         int video_config;
106         int num_aud_inputs;
107         struct {
108                 int audio_input;
109                 char *name;
110         } aud_inputs[3];
111 };
112
113 struct 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);
120         int (*send_command)(struct go7007 *go, unsigned int cmd, void *arg);
121         void (*release)(struct go7007 *go);
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
128 struct go7007_buffer {
129         struct vb2_buffer vb;
130         struct list_head list;
131         unsigned int frame_offset;
132         u32 modet_active;
133 };
134
135 #define GO7007_RATIO_1_1        0
136 #define GO7007_RATIO_4_3        1
137 #define GO7007_RATIO_16_9       2
138
139 enum 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
151 struct go7007 {
152         struct device *dev;
153         u8 bus_info[32];
154         const 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];
159         struct video_device vdev;
160         void *boot_fw;
161         unsigned boot_fw_len;
162         struct v4l2_device v4l2_dev;
163         struct v4l2_ctrl_handler hdl;
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;
169         struct v4l2_ctrl *mpeg_video_b_frames;
170         struct v4l2_ctrl *mpeg_video_rep_seqheader;
171         enum { STATUS_INIT, STATUS_ONLINE, STATUS_SHUTDOWN } status;
172         spinlock_t spinlock;
173         struct mutex hw_lock;
174         struct mutex serialize_lock;
175         int audio_enabled;
176         struct v4l2_subdev *sd_video;
177         struct v4l2_subdev *sd_audio;
178         u8 usb_buf[16];
179
180         /* Video input */
181         int input;
182         int aud_input;
183         enum { GO7007_STD_NTSC, GO7007_STD_PAL, GO7007_STD_OTHER } standard;
184         v4l2_std_id std;
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 */
195         u32 format;
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 */
221         struct mutex queue_lock;
222         struct vb2_queue vidq;
223         enum go7007_parser_state state;
224         int parse_length;
225         u16 modet_word;
226         int seen_frame;
227         u32 next_seq;
228         struct list_head vidq_active;
229         wait_queue_head_t frame_waitq;
230         struct go7007_buffer *active_buf;
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
249 static inline struct go7007 *to_go7007(struct v4l2_device *v4l2_dev)
250 {
251         return container_of(v4l2_dev, struct go7007, v4l2_dev);
252 }
253
254 /* All of these must be called with the hpi_lock mutex held! */
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 */
269 int go7007_read_addr(struct go7007 *go, u16 addr, u16 *data);
270 int go7007_read_interrupt(struct go7007 *go, u16 *value, u16 *data);
271 int go7007_boot_encoder(struct go7007 *go, int init_i2c);
272 int go7007_reset_encoder(struct go7007 *go);
273 int go7007_register_encoder(struct go7007 *go, unsigned num_i2c_devs);
274 int go7007_start_encoder(struct go7007 *go);
275 void go7007_parse_video_stream(struct go7007 *go, u8 *buf, int length);
276 struct go7007 *go7007_alloc(const struct go7007_board_info *board,
277                                         struct device *dev);
278 void go7007_update_board(struct go7007 *go);
279
280 /* go7007-fw.c */
281 int go7007_construct_fw_image(struct go7007 *go, u8 **fw, int *fwlen);
282
283 /* go7007-i2c.c */
284 int go7007_i2c_init(struct go7007 *go);
285 int go7007_i2c_remove(struct go7007 *go);
286
287 /* go7007-v4l2.c */
288 int go7007_v4l2_init(struct go7007 *go);
289 int go7007_v4l2_ctrl_init(struct go7007 *go);
290 void go7007_v4l2_remove(struct go7007 *go);
291
292 /* snd-go7007.c */
293 int go7007_snd_init(struct go7007 *go);
294 int go7007_snd_remove(struct go7007 *go);