diff options
Diffstat (limited to 'drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h')
-rw-r--r-- | drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h | 371 |
1 files changed, 371 insertions, 0 deletions
diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h new file mode 100644 index 000000000000..217bbe5d5c80 --- /dev/null +++ b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h | |||
@@ -0,0 +1,371 @@ | |||
1 | /* | ||
2 | * | ||
3 | * $Id$ | ||
4 | * | ||
5 | * Copyright (C) 2005 Mike Isely <isely@pobox.com> | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License as published by | ||
9 | * the Free Software Foundation; either version 2 of the License | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, | ||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | * GNU General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU General Public License | ||
17 | * along with this program; if not, write to the Free Software | ||
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
19 | * | ||
20 | */ | ||
21 | #ifndef __PVRUSB2_HDW_INTERNAL_H | ||
22 | #define __PVRUSB2_HDW_INTERNAL_H | ||
23 | |||
24 | /* | ||
25 | |||
26 | This header sets up all the internal structures and definitions needed to | ||
27 | track and coordinate the driver's interaction with the hardware. ONLY | ||
28 | source files which actually implement part of that whole circus should be | ||
29 | including this header. Higher levels, like the external layers to the | ||
30 | various public APIs (V4L, sysfs, etc) should NOT ever include this | ||
31 | private, internal header. This means that pvrusb2-hdw, pvrusb2-encoder, | ||
32 | etc will include this, but pvrusb2-v4l should not. | ||
33 | |||
34 | */ | ||
35 | |||
36 | #include <linux/config.h> | ||
37 | #include <linux/videodev2.h> | ||
38 | #include <linux/i2c.h> | ||
39 | #include <linux/mutex.h> | ||
40 | #include "pvrusb2-hdw.h" | ||
41 | #include "pvrusb2-io.h" | ||
42 | |||
43 | /* Legal values for the SRATE state variable */ | ||
44 | #define PVR2_CVAL_SRATE_48 0 | ||
45 | #define PVR2_CVAL_SRATE_44_1 1 | ||
46 | |||
47 | /* Legal values for the AUDIOBITRATE state variable */ | ||
48 | #define PVR2_CVAL_AUDIOBITRATE_384 0 | ||
49 | #define PVR2_CVAL_AUDIOBITRATE_320 1 | ||
50 | #define PVR2_CVAL_AUDIOBITRATE_256 2 | ||
51 | #define PVR2_CVAL_AUDIOBITRATE_224 3 | ||
52 | #define PVR2_CVAL_AUDIOBITRATE_192 4 | ||
53 | #define PVR2_CVAL_AUDIOBITRATE_160 5 | ||
54 | #define PVR2_CVAL_AUDIOBITRATE_128 6 | ||
55 | #define PVR2_CVAL_AUDIOBITRATE_112 7 | ||
56 | #define PVR2_CVAL_AUDIOBITRATE_96 8 | ||
57 | #define PVR2_CVAL_AUDIOBITRATE_80 9 | ||
58 | #define PVR2_CVAL_AUDIOBITRATE_64 10 | ||
59 | #define PVR2_CVAL_AUDIOBITRATE_56 11 | ||
60 | #define PVR2_CVAL_AUDIOBITRATE_48 12 | ||
61 | #define PVR2_CVAL_AUDIOBITRATE_32 13 | ||
62 | #define PVR2_CVAL_AUDIOBITRATE_VBR 14 | ||
63 | |||
64 | /* Legal values for the AUDIOEMPHASIS state variable */ | ||
65 | #define PVR2_CVAL_AUDIOEMPHASIS_NONE 0 | ||
66 | #define PVR2_CVAL_AUDIOEMPHASIS_50_15 1 | ||
67 | #define PVR2_CVAL_AUDIOEMPHASIS_CCITT 2 | ||
68 | |||
69 | /* Legal values for PVR2_CID_HSM */ | ||
70 | #define PVR2_CVAL_HSM_FAIL 0 | ||
71 | #define PVR2_CVAL_HSM_FULL 1 | ||
72 | #define PVR2_CVAL_HSM_HIGH 2 | ||
73 | |||
74 | #define PVR2_VID_ENDPOINT 0x84 | ||
75 | #define PVR2_UNK_ENDPOINT 0x86 /* maybe raw yuv ? */ | ||
76 | #define PVR2_VBI_ENDPOINT 0x88 | ||
77 | |||
78 | #define PVR2_CTL_BUFFSIZE 64 | ||
79 | |||
80 | #define FREQTABLE_SIZE 500 | ||
81 | |||
82 | #define LOCK_TAKE(x) do { mutex_lock(&x##_mutex); x##_held = !0; } while (0) | ||
83 | #define LOCK_GIVE(x) do { x##_held = 0; mutex_unlock(&x##_mutex); } while (0) | ||
84 | |||
85 | struct pvr2_decoder; | ||
86 | |||
87 | typedef int (*pvr2_ctlf_is_dirty)(struct pvr2_ctrl *); | ||
88 | typedef void (*pvr2_ctlf_clear_dirty)(struct pvr2_ctrl *); | ||
89 | typedef int (*pvr2_ctlf_get_value)(struct pvr2_ctrl *,int *); | ||
90 | typedef int (*pvr2_ctlf_set_value)(struct pvr2_ctrl *,int msk,int val); | ||
91 | typedef int (*pvr2_ctlf_val_to_sym)(struct pvr2_ctrl *,int msk,int val, | ||
92 | char *,unsigned int,unsigned int *); | ||
93 | typedef int (*pvr2_ctlf_sym_to_val)(struct pvr2_ctrl *, | ||
94 | const char *,unsigned int, | ||
95 | int *mskp,int *valp); | ||
96 | |||
97 | /* This structure describes a specific control. A table of these is set up | ||
98 | in pvrusb2-hdw.c. */ | ||
99 | struct pvr2_ctl_info { | ||
100 | /* Control's name suitable for use as an identifier */ | ||
101 | const char *name; | ||
102 | |||
103 | /* Short description of control */ | ||
104 | const char *desc; | ||
105 | |||
106 | /* Control's implementation */ | ||
107 | pvr2_ctlf_get_value get_value; /* Get its value */ | ||
108 | pvr2_ctlf_set_value set_value; /* Set its value */ | ||
109 | pvr2_ctlf_val_to_sym val_to_sym; /* Custom convert value->symbol */ | ||
110 | pvr2_ctlf_sym_to_val sym_to_val; /* Custom convert symbol->value */ | ||
111 | pvr2_ctlf_is_dirty is_dirty; /* Return true if dirty */ | ||
112 | pvr2_ctlf_clear_dirty clear_dirty; /* Clear dirty state */ | ||
113 | |||
114 | /* Control's type (int, enum, bitmask) */ | ||
115 | enum pvr2_ctl_type type; | ||
116 | |||
117 | /* Associated V4L control ID, if any */ | ||
118 | int v4l_id; | ||
119 | |||
120 | /* Associated driver internal ID, if any */ | ||
121 | int internal_id; | ||
122 | |||
123 | /* Don't implicitly initialize this control's value */ | ||
124 | int skip_init; | ||
125 | |||
126 | /* Starting value for this control */ | ||
127 | int default_value; | ||
128 | |||
129 | /* Type-specific control information */ | ||
130 | union { | ||
131 | struct { /* Integer control */ | ||
132 | long min_value; /* lower limit */ | ||
133 | long max_value; /* upper limit */ | ||
134 | } type_int; | ||
135 | struct { /* enumerated control */ | ||
136 | unsigned int count; /* enum value count */ | ||
137 | const char **value_names; /* symbol names */ | ||
138 | } type_enum; | ||
139 | struct { /* bitmask control */ | ||
140 | unsigned int valid_bits; /* bits in use */ | ||
141 | const char **bit_names; /* symbol name/bit */ | ||
142 | } type_bitmask; | ||
143 | } def; | ||
144 | }; | ||
145 | |||
146 | |||
147 | struct pvr2_ctrl { | ||
148 | const struct pvr2_ctl_info *info; | ||
149 | struct pvr2_hdw *hdw; | ||
150 | }; | ||
151 | |||
152 | |||
153 | struct pvr2_audio_stat { | ||
154 | void *ctxt; | ||
155 | void (*detach)(void *); | ||
156 | int (*status)(void *); | ||
157 | }; | ||
158 | |||
159 | struct pvr2_decoder_ctrl { | ||
160 | void *ctxt; | ||
161 | void (*detach)(void *); | ||
162 | void (*enable)(void *,int); | ||
163 | int (*tuned)(void *); | ||
164 | void (*force_reset)(void *); | ||
165 | }; | ||
166 | |||
167 | #define PVR2_I2C_PEND_DETECT 0x01 /* Need to detect a client type */ | ||
168 | #define PVR2_I2C_PEND_CLIENT 0x02 /* Client needs a specific update */ | ||
169 | #define PVR2_I2C_PEND_REFRESH 0x04 /* Client has specific pending bits */ | ||
170 | #define PVR2_I2C_PEND_STALE 0x08 /* Broadcast pending bits */ | ||
171 | |||
172 | #define PVR2_I2C_PEND_ALL (PVR2_I2C_PEND_DETECT |\ | ||
173 | PVR2_I2C_PEND_CLIENT |\ | ||
174 | PVR2_I2C_PEND_REFRESH |\ | ||
175 | PVR2_I2C_PEND_STALE) | ||
176 | |||
177 | /* Disposition of firmware1 loading situation */ | ||
178 | #define FW1_STATE_UNKNOWN 0 | ||
179 | #define FW1_STATE_MISSING 1 | ||
180 | #define FW1_STATE_FAILED 2 | ||
181 | #define FW1_STATE_RELOAD 3 | ||
182 | #define FW1_STATE_OK 4 | ||
183 | |||
184 | /* Known major hardware variants, keyed from device ID */ | ||
185 | #define PVR2_HDW_TYPE_29XXX 0 | ||
186 | #ifdef CONFIG_VIDEO_PVRUSB2_24XXX | ||
187 | #define PVR2_HDW_TYPE_24XXX 1 | ||
188 | #endif | ||
189 | |||
190 | typedef int (*pvr2_i2c_func)(struct pvr2_hdw *,u8,u8 *,u16,u8 *, u16); | ||
191 | #define PVR2_I2C_FUNC_CNT 128 | ||
192 | |||
193 | /* This structure contains all state data directly needed to | ||
194 | manipulate the hardware (as opposed to complying with a kernel | ||
195 | interface) */ | ||
196 | struct pvr2_hdw { | ||
197 | /* Underlying USB device handle */ | ||
198 | struct usb_device *usb_dev; | ||
199 | struct usb_interface *usb_intf; | ||
200 | |||
201 | /* Device type, one of PVR2_HDW_TYPE_xxxxx */ | ||
202 | unsigned int hdw_type; | ||
203 | |||
204 | /* Video spigot */ | ||
205 | struct pvr2_stream *vid_stream; | ||
206 | |||
207 | /* Mutex for all hardware state control */ | ||
208 | struct mutex big_lock_mutex; | ||
209 | int big_lock_held; /* For debugging */ | ||
210 | |||
211 | void (*poll_trigger_func)(void *); | ||
212 | void *poll_trigger_data; | ||
213 | |||
214 | char name[32]; | ||
215 | |||
216 | /* I2C stuff */ | ||
217 | struct i2c_adapter i2c_adap; | ||
218 | struct i2c_algorithm i2c_algo; | ||
219 | pvr2_i2c_func i2c_func[PVR2_I2C_FUNC_CNT]; | ||
220 | int i2c_cx25840_hack_state; | ||
221 | int i2c_linked; | ||
222 | unsigned int i2c_pend_types; /* Which types of update are needed */ | ||
223 | unsigned long i2c_pend_mask; /* Change bits we need to scan */ | ||
224 | unsigned long i2c_stale_mask; /* Pending broadcast change bits */ | ||
225 | unsigned long i2c_active_mask; /* All change bits currently in use */ | ||
226 | struct list_head i2c_clients; | ||
227 | struct mutex i2c_list_lock; | ||
228 | |||
229 | /* Frequency table */ | ||
230 | unsigned int freqTable[FREQTABLE_SIZE]; | ||
231 | unsigned int freqProgSlot; | ||
232 | unsigned int freqSlot; | ||
233 | |||
234 | /* Stuff for handling low level control interaction with device */ | ||
235 | struct mutex ctl_lock_mutex; | ||
236 | int ctl_lock_held; /* For debugging */ | ||
237 | struct urb *ctl_write_urb; | ||
238 | struct urb *ctl_read_urb; | ||
239 | unsigned char *ctl_write_buffer; | ||
240 | unsigned char *ctl_read_buffer; | ||
241 | volatile int ctl_write_pend_flag; | ||
242 | volatile int ctl_read_pend_flag; | ||
243 | volatile int ctl_timeout_flag; | ||
244 | struct completion ctl_done; | ||
245 | unsigned char cmd_buffer[PVR2_CTL_BUFFSIZE]; | ||
246 | int cmd_debug_state; // Low level command debugging info | ||
247 | unsigned char cmd_debug_code; // | ||
248 | unsigned int cmd_debug_write_len; // | ||
249 | unsigned int cmd_debug_read_len; // | ||
250 | |||
251 | int flag_ok; // device in known good state | ||
252 | int flag_disconnected; // flag_ok == 0 due to disconnect | ||
253 | int flag_init_ok; // true if structure is fully initialized | ||
254 | int flag_streaming_enabled; // true if streaming should be on | ||
255 | int fw1_state; // current situation with fw1 | ||
256 | |||
257 | int flag_decoder_is_tuned; | ||
258 | |||
259 | struct pvr2_decoder_ctrl *decoder_ctrl; | ||
260 | |||
261 | // CPU firmware info (used to help find / save firmware data) | ||
262 | char *fw_buffer; | ||
263 | unsigned int fw_size; | ||
264 | |||
265 | // Which subsystem pieces have been enabled / configured | ||
266 | unsigned long subsys_enabled_mask; | ||
267 | |||
268 | // Which subsystems are manipulated to enable streaming | ||
269 | unsigned long subsys_stream_mask; | ||
270 | |||
271 | // True if there is a request to trigger logging of state in each | ||
272 | // module. | ||
273 | int log_requested; | ||
274 | |||
275 | /* Tuner / frequency control stuff */ | ||
276 | unsigned int tuner_type; | ||
277 | int tuner_updated; | ||
278 | unsigned int freqVal; | ||
279 | int freqDirty; | ||
280 | |||
281 | /* Video standard handling */ | ||
282 | v4l2_std_id std_mask_eeprom; // Hardware supported selections | ||
283 | v4l2_std_id std_mask_avail; // Which standards we may select from | ||
284 | v4l2_std_id std_mask_cur; // Currently selected standard(s) | ||
285 | unsigned int std_enum_cnt; // # of enumerated standards | ||
286 | int std_enum_cur; // selected standard enumeration value | ||
287 | int std_dirty; // True if std_mask_cur has changed | ||
288 | struct pvr2_ctl_info std_info_enum; | ||
289 | struct pvr2_ctl_info std_info_avail; | ||
290 | struct pvr2_ctl_info std_info_cur; | ||
291 | struct v4l2_standard *std_defs; | ||
292 | const char **std_enum_names; | ||
293 | |||
294 | // Generated string names, one per actual V4L2 standard | ||
295 | const char *std_mask_ptrs[32]; | ||
296 | char std_mask_names[32][10]; | ||
297 | |||
298 | int unit_number; /* ID for driver instance */ | ||
299 | unsigned long serial_number; /* ID for hardware itself */ | ||
300 | |||
301 | /* Minor number used by v4l logic (yes, this is a hack, as there should | ||
302 | be no v4l junk here). Probably a better way to do this. */ | ||
303 | int v4l_minor_number; | ||
304 | |||
305 | /* Location of eeprom or a negative number if none */ | ||
306 | int eeprom_addr; | ||
307 | |||
308 | enum pvr2_config config; | ||
309 | |||
310 | /* Information about what audio signal we're hearing */ | ||
311 | int flag_stereo; | ||
312 | int flag_bilingual; | ||
313 | struct pvr2_audio_stat *audio_stat; | ||
314 | |||
315 | /* Control state */ | ||
316 | #define VCREATE_DATA(lab) int lab##_val; int lab##_dirty | ||
317 | VCREATE_DATA(brightness); | ||
318 | VCREATE_DATA(contrast); | ||
319 | VCREATE_DATA(saturation); | ||
320 | VCREATE_DATA(hue); | ||
321 | VCREATE_DATA(volume); | ||
322 | VCREATE_DATA(balance); | ||
323 | VCREATE_DATA(bass); | ||
324 | VCREATE_DATA(treble); | ||
325 | VCREATE_DATA(mute); | ||
326 | VCREATE_DATA(srate); | ||
327 | VCREATE_DATA(audiobitrate); | ||
328 | VCREATE_DATA(audiocrc); | ||
329 | VCREATE_DATA(audioemphasis); | ||
330 | VCREATE_DATA(vbr); | ||
331 | VCREATE_DATA(videobitrate); | ||
332 | VCREATE_DATA(videopeak); | ||
333 | VCREATE_DATA(input); | ||
334 | VCREATE_DATA(audiomode); | ||
335 | VCREATE_DATA(res_hor); | ||
336 | VCREATE_DATA(res_ver); | ||
337 | VCREATE_DATA(interlace); | ||
338 | VCREATE_DATA(audiolayer); | ||
339 | #undef VCREATE_DATA | ||
340 | |||
341 | struct pvr2_ctrl *controls; | ||
342 | }; | ||
343 | |||
344 | int pvr2_hdw_commit_ctl_internal(struct pvr2_hdw *hdw); | ||
345 | |||
346 | unsigned int pvr2_hdw_get_signal_status_internal(struct pvr2_hdw *); | ||
347 | |||
348 | void pvr2_hdw_subsys_bit_chg_no_lock(struct pvr2_hdw *hdw, | ||
349 | unsigned long msk,unsigned long val); | ||
350 | void pvr2_hdw_subsys_stream_bit_chg_no_lock(struct pvr2_hdw *hdw, | ||
351 | unsigned long msk, | ||
352 | unsigned long val); | ||
353 | |||
354 | void pvr2_hdw_internal_find_stdenum(struct pvr2_hdw *hdw); | ||
355 | void pvr2_hdw_internal_set_std_avail(struct pvr2_hdw *hdw); | ||
356 | |||
357 | int pvr2_i2c_basic_op(struct pvr2_hdw *,u8 i2c_addr, | ||
358 | u8 *wdata,u16 wlen, | ||
359 | u8 *rdata,u16 rlen); | ||
360 | |||
361 | #endif /* __PVRUSB2_HDW_INTERNAL_H */ | ||
362 | |||
363 | /* | ||
364 | Stuff for Emacs to see, in order to encourage consistent editing style: | ||
365 | *** Local Variables: *** | ||
366 | *** mode: c *** | ||
367 | *** fill-column: 75 *** | ||
368 | *** tab-width: 8 *** | ||
369 | *** c-basic-offset: 8 *** | ||
370 | *** End: *** | ||
371 | */ | ||