1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright (C) 2005-2006 Micronas USA Inc.
7 * This is the private include file for the go7007 driver. It should not
8 * be included by anybody but the driver itself, and especially not by
9 * user-space applications.
12 #include <media/v4l2-device.h>
13 #include <media/v4l2-ctrls.h>
14 #include <media/v4l2-fh.h>
15 #include <media/videobuf2-v4l2.h>
19 /* IDs to activate board-specific support code */
20 #define GO7007_BOARDID_MATRIX_II 0
21 #define GO7007_BOARDID_MATRIX_RELOAD 1
22 #define GO7007_BOARDID_STAR_TREK 2
23 #define GO7007_BOARDID_PCI_VOYAGER 3
24 #define GO7007_BOARDID_XMEN 4
25 #define GO7007_BOARDID_XMEN_II 5
26 #define GO7007_BOARDID_XMEN_III 6
27 #define GO7007_BOARDID_MATRIX_REV 7
28 #define GO7007_BOARDID_PX_M402U 8
29 #define GO7007_BOARDID_PX_TV402U 9
30 #define GO7007_BOARDID_LIFEVIEW_LR192 10 /* TV Walker Ultra */
31 #define GO7007_BOARDID_ENDURA 11
32 #define GO7007_BOARDID_ADLINK_MPG24 12
33 #define GO7007_BOARDID_SENSORAY_2250 13 /* Sensoray 2250/2251 */
34 #define GO7007_BOARDID_ADS_USBAV_709 14
36 /* Various characteristics of each board */
37 #define GO7007_BOARD_HAS_AUDIO (1<<0)
38 #define GO7007_BOARD_USE_ONBOARD_I2C (1<<1)
39 #define GO7007_BOARD_HAS_TUNER (1<<2)
41 /* Characteristics of sensor devices */
42 #define GO7007_SENSOR_VALID_POLAR (1<<0)
43 #define GO7007_SENSOR_HREF_POLAR (1<<1)
44 #define GO7007_SENSOR_VREF_POLAR (1<<2)
45 #define GO7007_SENSOR_FIELD_ID_POLAR (1<<3)
46 #define GO7007_SENSOR_BIT_WIDTH (1<<4)
47 #define GO7007_SENSOR_VALID_ENABLE (1<<5)
48 #define GO7007_SENSOR_656 (1<<6)
49 #define GO7007_SENSOR_CONFIG_MASK 0x7f
50 #define GO7007_SENSOR_TV (1<<7)
51 #define GO7007_SENSOR_VBI (1<<8)
52 #define GO7007_SENSOR_SCALING (1<<9)
53 #define GO7007_SENSOR_SAA7115 (1<<10)
55 /* Characteristics of audio sensor devices */
56 #define GO7007_AUDIO_I2S_MODE_1 (1)
57 #define GO7007_AUDIO_I2S_MODE_2 (2)
58 #define GO7007_AUDIO_I2S_MODE_3 (3)
59 #define GO7007_AUDIO_BCLK_POLAR (1<<2)
60 #define GO7007_AUDIO_WORD_14 (14<<4)
61 #define GO7007_AUDIO_WORD_16 (16<<4)
62 #define GO7007_AUDIO_ONE_CHANNEL (1<<11)
63 #define GO7007_AUDIO_I2S_MASTER (1<<16)
64 #define GO7007_AUDIO_OKI_MODE (1<<17)
66 #define GO7007_CID_CUSTOM_BASE (V4L2_CID_DETECT_CLASS_BASE + 0x1000)
67 #define V4L2_CID_PIXEL_THRESHOLD0 (GO7007_CID_CUSTOM_BASE+1)
68 #define V4L2_CID_MOTION_THRESHOLD0 (GO7007_CID_CUSTOM_BASE+2)
69 #define V4L2_CID_MB_THRESHOLD0 (GO7007_CID_CUSTOM_BASE+3)
70 #define V4L2_CID_PIXEL_THRESHOLD1 (GO7007_CID_CUSTOM_BASE+4)
71 #define V4L2_CID_MOTION_THRESHOLD1 (GO7007_CID_CUSTOM_BASE+5)
72 #define V4L2_CID_MB_THRESHOLD1 (GO7007_CID_CUSTOM_BASE+6)
73 #define V4L2_CID_PIXEL_THRESHOLD2 (GO7007_CID_CUSTOM_BASE+7)
74 #define V4L2_CID_MOTION_THRESHOLD2 (GO7007_CID_CUSTOM_BASE+8)
75 #define V4L2_CID_MB_THRESHOLD2 (GO7007_CID_CUSTOM_BASE+9)
76 #define V4L2_CID_PIXEL_THRESHOLD3 (GO7007_CID_CUSTOM_BASE+10)
77 #define V4L2_CID_MOTION_THRESHOLD3 (GO7007_CID_CUSTOM_BASE+11)
78 #define V4L2_CID_MB_THRESHOLD3 (GO7007_CID_CUSTOM_BASE+12)
80 struct go7007_board_info
{
83 unsigned int sensor_flags
;
89 unsigned int audio_flags
;
96 unsigned int is_video
:1;
97 unsigned int is_audio
:1;
115 struct go7007_hpi_ops
{
116 int (*interface_reset
)(struct go7007
*go
);
117 int (*write_interrupt
)(struct go7007
*go
, int addr
, int data
);
118 int (*read_interrupt
)(struct go7007
*go
);
119 int (*stream_start
)(struct go7007
*go
);
120 int (*stream_stop
)(struct go7007
*go
);
121 int (*send_firmware
)(struct go7007
*go
, u8
*data
, int len
);
122 int (*send_command
)(struct go7007
*go
, unsigned int cmd
, void *arg
);
123 void (*release
)(struct go7007
*go
);
126 /* The video buffer size must be a multiple of PAGE_SIZE */
127 #define GO7007_BUF_PAGES (128 * 1024 / PAGE_SIZE)
128 #define GO7007_BUF_SIZE (GO7007_BUF_PAGES << PAGE_SHIFT)
130 struct go7007_buffer
{
131 struct vb2_v4l2_buffer vb
;
132 struct list_head list
;
133 unsigned int frame_offset
;
137 #define GO7007_RATIO_1_1 0
138 #define GO7007_RATIO_4_3 1
139 #define GO7007_RATIO_16_9 2
141 enum go7007_parser_state
{
156 const struct go7007_board_info
*board_info
;
157 unsigned int board_id
;
159 int channel_number
; /* for multi-channel boards like Adlink PCI-MPG24 */
161 struct video_device vdev
;
163 unsigned boot_fw_len
;
164 struct v4l2_device v4l2_dev
;
165 struct v4l2_ctrl_handler hdl
;
166 struct v4l2_ctrl
*mpeg_video_encoding
;
167 struct v4l2_ctrl
*mpeg_video_gop_size
;
168 struct v4l2_ctrl
*mpeg_video_gop_closure
;
169 struct v4l2_ctrl
*mpeg_video_bitrate
;
170 struct v4l2_ctrl
*mpeg_video_aspect_ratio
;
171 struct v4l2_ctrl
*mpeg_video_b_frames
;
172 struct v4l2_ctrl
*mpeg_video_rep_seqheader
;
173 struct v4l2_ctrl
*modet_mode
;
174 enum { STATUS_INIT
, STATUS_ONLINE
, STATUS_SHUTDOWN
} status
;
176 struct mutex hw_lock
;
177 struct mutex serialize_lock
;
179 struct v4l2_subdev
*sd_video
;
180 struct v4l2_subdev
*sd_audio
;
186 enum { GO7007_STD_NTSC
, GO7007_STD_PAL
, GO7007_STD_OTHER
} standard
;
188 int sensor_framerate
;
191 int encoder_h_offset
;
192 int encoder_v_offset
;
193 unsigned int encoder_h_halve
:1;
194 unsigned int encoder_v_halve
:1;
195 unsigned int encoder_subsample
:1;
205 unsigned int closed_gop
:1;
206 unsigned int repeat_seqhead
:1;
207 unsigned int seq_header_enable
:1;
208 unsigned int gop_header_enable
:1;
209 unsigned int dvd_mode
:1;
210 unsigned int interlace_coding
:1;
212 /* Motion detection */
213 unsigned int modet_enable
:1;
215 unsigned int enable
:1;
217 int motion_threshold
;
220 unsigned char modet_map
[1624];
221 unsigned char active_map
[216];
222 u32 modet_event_status
;
224 /* Video streaming */
225 struct mutex queue_lock
;
226 struct vb2_queue vidq
;
227 enum go7007_parser_state state
;
232 struct list_head vidq_active
;
233 wait_queue_head_t frame_waitq
;
234 struct go7007_buffer
*active_buf
;
236 /* Audio streaming */
237 void (*audio_deliver
)(struct go7007
*go
, u8
*buf
, int length
);
241 int i2c_adapter_online
;
242 struct i2c_adapter i2c_adapter
;
245 const struct go7007_hpi_ops
*hpi_ops
;
247 int interrupt_available
;
248 wait_queue_head_t interrupt_waitq
;
249 unsigned short interrupt_value
;
250 unsigned short interrupt_data
;
253 static inline struct go7007
*to_go7007(struct v4l2_device
*v4l2_dev
)
255 return container_of(v4l2_dev
, struct go7007
, v4l2_dev
);
258 /* All of these must be called with the hpi_lock mutex held! */
259 #define go7007_interface_reset(go) \
260 ((go)->hpi_ops->interface_reset(go))
261 #define go7007_write_interrupt(go, x, y) \
262 ((go)->hpi_ops->write_interrupt)((go), (x), (y))
263 #define go7007_stream_start(go) \
264 ((go)->hpi_ops->stream_start(go))
265 #define go7007_stream_stop(go) \
266 ((go)->hpi_ops->stream_stop(go))
267 #define go7007_send_firmware(go, x, y) \
268 ((go)->hpi_ops->send_firmware)((go), (x), (y))
269 #define go7007_write_addr(go, x, y) \
270 ((go)->hpi_ops->write_interrupt)((go), (x)|0x8000, (y))
272 /* go7007-driver.c */
273 int go7007_read_addr(struct go7007
*go
, u16 addr
, u16
*data
);
274 int go7007_read_interrupt(struct go7007
*go
, u16
*value
, u16
*data
);
275 int go7007_boot_encoder(struct go7007
*go
, int init_i2c
);
276 int go7007_reset_encoder(struct go7007
*go
);
277 int go7007_register_encoder(struct go7007
*go
, unsigned num_i2c_devs
);
278 int go7007_start_encoder(struct go7007
*go
);
279 void go7007_parse_video_stream(struct go7007
*go
, u8
*buf
, int length
);
280 struct go7007
*go7007_alloc(const struct go7007_board_info
*board
,
282 void go7007_update_board(struct go7007
*go
);
285 int go7007_construct_fw_image(struct go7007
*go
, u8
**fw
, int *fwlen
);
288 int go7007_i2c_init(struct go7007
*go
);
289 int go7007_i2c_remove(struct go7007
*go
);
292 int go7007_v4l2_init(struct go7007
*go
);
293 int go7007_v4l2_ctrl_init(struct go7007
*go
);
294 void go7007_v4l2_remove(struct go7007
*go
);
297 int go7007_snd_init(struct go7007
*go
);
298 int go7007_snd_remove(struct go7007
*go
);