2 * Copyright (C) 2005-2006 Micronas USA Inc.
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.
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.
15 * This is the private include file for the go7007 driver. It should not
16 * be included by anybody but the driver itself, and especially not by
17 * user-space applications.
20 #include <media/v4l2-device.h>
21 #include <media/v4l2-ctrls.h>
22 #include <media/v4l2-fh.h>
23 #include <media/videobuf2-v4l2.h>
27 /* IDs to activate board-specific support code */
28 #define GO7007_BOARDID_MATRIX_II 0
29 #define GO7007_BOARDID_MATRIX_RELOAD 1
30 #define GO7007_BOARDID_STAR_TREK 2
31 #define GO7007_BOARDID_PCI_VOYAGER 3
32 #define GO7007_BOARDID_XMEN 4
33 #define GO7007_BOARDID_XMEN_II 5
34 #define GO7007_BOARDID_XMEN_III 6
35 #define GO7007_BOARDID_MATRIX_REV 7
36 #define GO7007_BOARDID_PX_M402U 8
37 #define GO7007_BOARDID_PX_TV402U 9
38 #define GO7007_BOARDID_LIFEVIEW_LR192 10 /* TV Walker Ultra */
39 #define GO7007_BOARDID_ENDURA 11
40 #define GO7007_BOARDID_ADLINK_MPG24 12
41 #define GO7007_BOARDID_SENSORAY_2250 13 /* Sensoray 2250/2251 */
42 #define GO7007_BOARDID_ADS_USBAV_709 14
44 /* Various characteristics of each board */
45 #define GO7007_BOARD_HAS_AUDIO (1<<0)
46 #define GO7007_BOARD_USE_ONBOARD_I2C (1<<1)
47 #define GO7007_BOARD_HAS_TUNER (1<<2)
49 /* Characteristics of sensor devices */
50 #define GO7007_SENSOR_VALID_POLAR (1<<0)
51 #define GO7007_SENSOR_HREF_POLAR (1<<1)
52 #define GO7007_SENSOR_VREF_POLAR (1<<2)
53 #define GO7007_SENSOR_FIELD_ID_POLAR (1<<3)
54 #define GO7007_SENSOR_BIT_WIDTH (1<<4)
55 #define GO7007_SENSOR_VALID_ENABLE (1<<5)
56 #define GO7007_SENSOR_656 (1<<6)
57 #define GO7007_SENSOR_CONFIG_MASK 0x7f
58 #define GO7007_SENSOR_TV (1<<7)
59 #define GO7007_SENSOR_VBI (1<<8)
60 #define GO7007_SENSOR_SCALING (1<<9)
61 #define GO7007_SENSOR_SAA7115 (1<<10)
63 /* Characteristics of audio sensor devices */
64 #define GO7007_AUDIO_I2S_MODE_1 (1)
65 #define GO7007_AUDIO_I2S_MODE_2 (2)
66 #define GO7007_AUDIO_I2S_MODE_3 (3)
67 #define GO7007_AUDIO_BCLK_POLAR (1<<2)
68 #define GO7007_AUDIO_WORD_14 (14<<4)
69 #define GO7007_AUDIO_WORD_16 (16<<4)
70 #define GO7007_AUDIO_ONE_CHANNEL (1<<11)
71 #define GO7007_AUDIO_I2S_MASTER (1<<16)
72 #define GO7007_AUDIO_OKI_MODE (1<<17)
74 #define GO7007_CID_CUSTOM_BASE (V4L2_CID_DETECT_CLASS_BASE + 0x1000)
75 #define V4L2_CID_PIXEL_THRESHOLD0 (GO7007_CID_CUSTOM_BASE+1)
76 #define V4L2_CID_MOTION_THRESHOLD0 (GO7007_CID_CUSTOM_BASE+2)
77 #define V4L2_CID_MB_THRESHOLD0 (GO7007_CID_CUSTOM_BASE+3)
78 #define V4L2_CID_PIXEL_THRESHOLD1 (GO7007_CID_CUSTOM_BASE+4)
79 #define V4L2_CID_MOTION_THRESHOLD1 (GO7007_CID_CUSTOM_BASE+5)
80 #define V4L2_CID_MB_THRESHOLD1 (GO7007_CID_CUSTOM_BASE+6)
81 #define V4L2_CID_PIXEL_THRESHOLD2 (GO7007_CID_CUSTOM_BASE+7)
82 #define V4L2_CID_MOTION_THRESHOLD2 (GO7007_CID_CUSTOM_BASE+8)
83 #define V4L2_CID_MB_THRESHOLD2 (GO7007_CID_CUSTOM_BASE+9)
84 #define V4L2_CID_PIXEL_THRESHOLD3 (GO7007_CID_CUSTOM_BASE+10)
85 #define V4L2_CID_MOTION_THRESHOLD3 (GO7007_CID_CUSTOM_BASE+11)
86 #define V4L2_CID_MB_THRESHOLD3 (GO7007_CID_CUSTOM_BASE+12)
88 struct go7007_board_info
{
91 unsigned int sensor_flags
;
97 unsigned int audio_flags
;
104 unsigned int is_video
:1;
105 unsigned int is_audio
:1;
123 struct go7007_hpi_ops
{
124 int (*interface_reset
)(struct go7007
*go
);
125 int (*write_interrupt
)(struct go7007
*go
, int addr
, int data
);
126 int (*read_interrupt
)(struct go7007
*go
);
127 int (*stream_start
)(struct go7007
*go
);
128 int (*stream_stop
)(struct go7007
*go
);
129 int (*send_firmware
)(struct go7007
*go
, u8
*data
, int len
);
130 int (*send_command
)(struct go7007
*go
, unsigned int cmd
, void *arg
);
131 void (*release
)(struct go7007
*go
);
134 /* The video buffer size must be a multiple of PAGE_SIZE */
135 #define GO7007_BUF_PAGES (128 * 1024 / PAGE_SIZE)
136 #define GO7007_BUF_SIZE (GO7007_BUF_PAGES << PAGE_SHIFT)
138 struct go7007_buffer
{
139 struct vb2_v4l2_buffer vb
;
140 struct list_head list
;
141 unsigned int frame_offset
;
145 #define GO7007_RATIO_1_1 0
146 #define GO7007_RATIO_4_3 1
147 #define GO7007_RATIO_16_9 2
149 enum go7007_parser_state
{
164 const struct go7007_board_info
*board_info
;
165 unsigned int board_id
;
167 int channel_number
; /* for multi-channel boards like Adlink PCI-MPG24 */
169 struct video_device vdev
;
171 unsigned boot_fw_len
;
172 struct v4l2_device v4l2_dev
;
173 struct v4l2_ctrl_handler hdl
;
174 struct v4l2_ctrl
*mpeg_video_encoding
;
175 struct v4l2_ctrl
*mpeg_video_gop_size
;
176 struct v4l2_ctrl
*mpeg_video_gop_closure
;
177 struct v4l2_ctrl
*mpeg_video_bitrate
;
178 struct v4l2_ctrl
*mpeg_video_aspect_ratio
;
179 struct v4l2_ctrl
*mpeg_video_b_frames
;
180 struct v4l2_ctrl
*mpeg_video_rep_seqheader
;
181 struct v4l2_ctrl
*modet_mode
;
182 enum { STATUS_INIT
, STATUS_ONLINE
, STATUS_SHUTDOWN
} status
;
184 struct mutex hw_lock
;
185 struct mutex serialize_lock
;
187 struct v4l2_subdev
*sd_video
;
188 struct v4l2_subdev
*sd_audio
;
194 enum { GO7007_STD_NTSC
, GO7007_STD_PAL
, GO7007_STD_OTHER
} standard
;
196 int sensor_framerate
;
199 int encoder_h_offset
;
200 int encoder_v_offset
;
201 unsigned int encoder_h_halve
:1;
202 unsigned int encoder_v_halve
:1;
203 unsigned int encoder_subsample
:1;
213 unsigned int closed_gop
:1;
214 unsigned int repeat_seqhead
:1;
215 unsigned int seq_header_enable
:1;
216 unsigned int gop_header_enable
:1;
217 unsigned int dvd_mode
:1;
218 unsigned int interlace_coding
:1;
220 /* Motion detection */
221 unsigned int modet_enable
:1;
223 unsigned int enable
:1;
225 int motion_threshold
;
228 unsigned char modet_map
[1624];
229 unsigned char active_map
[216];
230 u32 modet_event_status
;
232 /* Video streaming */
233 struct mutex queue_lock
;
234 struct vb2_queue vidq
;
235 enum go7007_parser_state state
;
240 struct list_head vidq_active
;
241 wait_queue_head_t frame_waitq
;
242 struct go7007_buffer
*active_buf
;
244 /* Audio streaming */
245 void (*audio_deliver
)(struct go7007
*go
, u8
*buf
, int length
);
249 int i2c_adapter_online
;
250 struct i2c_adapter i2c_adapter
;
253 const struct go7007_hpi_ops
*hpi_ops
;
255 int interrupt_available
;
256 wait_queue_head_t interrupt_waitq
;
257 unsigned short interrupt_value
;
258 unsigned short interrupt_data
;
261 static inline struct go7007
*to_go7007(struct v4l2_device
*v4l2_dev
)
263 return container_of(v4l2_dev
, struct go7007
, v4l2_dev
);
266 /* All of these must be called with the hpi_lock mutex held! */
267 #define go7007_interface_reset(go) \
268 ((go)->hpi_ops->interface_reset(go))
269 #define go7007_write_interrupt(go, x, y) \
270 ((go)->hpi_ops->write_interrupt)((go), (x), (y))
271 #define go7007_stream_start(go) \
272 ((go)->hpi_ops->stream_start(go))
273 #define go7007_stream_stop(go) \
274 ((go)->hpi_ops->stream_stop(go))
275 #define go7007_send_firmware(go, x, y) \
276 ((go)->hpi_ops->send_firmware)((go), (x), (y))
277 #define go7007_write_addr(go, x, y) \
278 ((go)->hpi_ops->write_interrupt)((go), (x)|0x8000, (y))
280 /* go7007-driver.c */
281 int go7007_read_addr(struct go7007
*go
, u16 addr
, u16
*data
);
282 int go7007_read_interrupt(struct go7007
*go
, u16
*value
, u16
*data
);
283 int go7007_boot_encoder(struct go7007
*go
, int init_i2c
);
284 int go7007_reset_encoder(struct go7007
*go
);
285 int go7007_register_encoder(struct go7007
*go
, unsigned num_i2c_devs
);
286 int go7007_start_encoder(struct go7007
*go
);
287 void go7007_parse_video_stream(struct go7007
*go
, u8
*buf
, int length
);
288 struct go7007
*go7007_alloc(const struct go7007_board_info
*board
,
290 void go7007_update_board(struct go7007
*go
);
293 int go7007_construct_fw_image(struct go7007
*go
, u8
**fw
, int *fwlen
);
296 int go7007_i2c_init(struct go7007
*go
);
297 int go7007_i2c_remove(struct go7007
*go
);
300 int go7007_v4l2_init(struct go7007
*go
);
301 int go7007_v4l2_ctrl_init(struct go7007
*go
);
302 void go7007_v4l2_remove(struct go7007
*go
);
305 int go7007_snd_init(struct go7007
*go
);
306 int go7007_snd_remove(struct go7007
*go
);