Commit | Line | Data |
---|---|---|
d855497e MI |
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 | ||
d855497e MI |
36 | #include <linux/videodev2.h> |
37 | #include <linux/i2c.h> | |
681c7399 | 38 | #include <linux/workqueue.h> |
d855497e MI |
39 | #include <linux/mutex.h> |
40 | #include "pvrusb2-hdw.h" | |
41 | #include "pvrusb2-io.h" | |
c05c0462 | 42 | #include <media/cx2341x.h> |
989eb154 | 43 | #include "pvrusb2-devattr.h" |
d855497e | 44 | |
d855497e MI |
45 | /* Legal values for PVR2_CID_HSM */ |
46 | #define PVR2_CVAL_HSM_FAIL 0 | |
47 | #define PVR2_CVAL_HSM_FULL 1 | |
48 | #define PVR2_CVAL_HSM_HIGH 2 | |
49 | ||
50 | #define PVR2_VID_ENDPOINT 0x84 | |
51 | #define PVR2_UNK_ENDPOINT 0x86 /* maybe raw yuv ? */ | |
52 | #define PVR2_VBI_ENDPOINT 0x88 | |
53 | ||
54 | #define PVR2_CTL_BUFFSIZE 64 | |
55 | ||
56 | #define FREQTABLE_SIZE 500 | |
57 | ||
58 | #define LOCK_TAKE(x) do { mutex_lock(&x##_mutex); x##_held = !0; } while (0) | |
59 | #define LOCK_GIVE(x) do { x##_held = 0; mutex_unlock(&x##_mutex); } while (0) | |
60 | ||
61 | struct pvr2_decoder; | |
62 | ||
63 | typedef int (*pvr2_ctlf_is_dirty)(struct pvr2_ctrl *); | |
64 | typedef void (*pvr2_ctlf_clear_dirty)(struct pvr2_ctrl *); | |
5549f54f | 65 | typedef int (*pvr2_ctlf_check_value)(struct pvr2_ctrl *,int); |
d855497e MI |
66 | typedef int (*pvr2_ctlf_get_value)(struct pvr2_ctrl *,int *); |
67 | typedef int (*pvr2_ctlf_set_value)(struct pvr2_ctrl *,int msk,int val); | |
68 | typedef int (*pvr2_ctlf_val_to_sym)(struct pvr2_ctrl *,int msk,int val, | |
69 | char *,unsigned int,unsigned int *); | |
70 | typedef int (*pvr2_ctlf_sym_to_val)(struct pvr2_ctrl *, | |
71 | const char *,unsigned int, | |
72 | int *mskp,int *valp); | |
a761f431 | 73 | typedef unsigned int (*pvr2_ctlf_get_v4lflags)(struct pvr2_ctrl *); |
d855497e MI |
74 | |
75 | /* This structure describes a specific control. A table of these is set up | |
76 | in pvrusb2-hdw.c. */ | |
77 | struct pvr2_ctl_info { | |
78 | /* Control's name suitable for use as an identifier */ | |
79 | const char *name; | |
80 | ||
81 | /* Short description of control */ | |
82 | const char *desc; | |
83 | ||
84 | /* Control's implementation */ | |
85 | pvr2_ctlf_get_value get_value; /* Get its value */ | |
89ebd63f MI |
86 | pvr2_ctlf_get_value get_min_value; /* Get minimum allowed value */ |
87 | pvr2_ctlf_get_value get_max_value; /* Get maximum allowed value */ | |
d855497e | 88 | pvr2_ctlf_set_value set_value; /* Set its value */ |
5549f54f | 89 | pvr2_ctlf_check_value check_value; /* Check that value is valid */ |
d855497e MI |
90 | pvr2_ctlf_val_to_sym val_to_sym; /* Custom convert value->symbol */ |
91 | pvr2_ctlf_sym_to_val sym_to_val; /* Custom convert symbol->value */ | |
92 | pvr2_ctlf_is_dirty is_dirty; /* Return true if dirty */ | |
93 | pvr2_ctlf_clear_dirty clear_dirty; /* Clear dirty state */ | |
a761f431 | 94 | pvr2_ctlf_get_v4lflags get_v4lflags;/* Retrieve v4l flags */ |
d855497e MI |
95 | |
96 | /* Control's type (int, enum, bitmask) */ | |
97 | enum pvr2_ctl_type type; | |
98 | ||
99 | /* Associated V4L control ID, if any */ | |
100 | int v4l_id; | |
101 | ||
102 | /* Associated driver internal ID, if any */ | |
103 | int internal_id; | |
104 | ||
105 | /* Don't implicitly initialize this control's value */ | |
106 | int skip_init; | |
107 | ||
108 | /* Starting value for this control */ | |
109 | int default_value; | |
110 | ||
111 | /* Type-specific control information */ | |
112 | union { | |
113 | struct { /* Integer control */ | |
114 | long min_value; /* lower limit */ | |
115 | long max_value; /* upper limit */ | |
116 | } type_int; | |
117 | struct { /* enumerated control */ | |
118 | unsigned int count; /* enum value count */ | |
119 | const char **value_names; /* symbol names */ | |
120 | } type_enum; | |
121 | struct { /* bitmask control */ | |
122 | unsigned int valid_bits; /* bits in use */ | |
123 | const char **bit_names; /* symbol name/bit */ | |
124 | } type_bitmask; | |
125 | } def; | |
126 | }; | |
127 | ||
128 | ||
c05c0462 MI |
129 | /* Same as pvr2_ctl_info, but includes storage for the control description */ |
130 | #define PVR2_CTLD_INFO_DESC_SIZE 32 | |
131 | struct pvr2_ctld_info { | |
132 | struct pvr2_ctl_info info; | |
133 | char desc[PVR2_CTLD_INFO_DESC_SIZE]; | |
134 | }; | |
135 | ||
d855497e MI |
136 | struct pvr2_ctrl { |
137 | const struct pvr2_ctl_info *info; | |
138 | struct pvr2_hdw *hdw; | |
139 | }; | |
140 | ||
141 | ||
d855497e MI |
142 | struct pvr2_decoder_ctrl { |
143 | void *ctxt; | |
144 | void (*detach)(void *); | |
145 | void (*enable)(void *,int); | |
d855497e MI |
146 | void (*force_reset)(void *); |
147 | }; | |
148 | ||
149 | #define PVR2_I2C_PEND_DETECT 0x01 /* Need to detect a client type */ | |
150 | #define PVR2_I2C_PEND_CLIENT 0x02 /* Client needs a specific update */ | |
151 | #define PVR2_I2C_PEND_REFRESH 0x04 /* Client has specific pending bits */ | |
152 | #define PVR2_I2C_PEND_STALE 0x08 /* Broadcast pending bits */ | |
153 | ||
154 | #define PVR2_I2C_PEND_ALL (PVR2_I2C_PEND_DETECT |\ | |
155 | PVR2_I2C_PEND_CLIENT |\ | |
156 | PVR2_I2C_PEND_REFRESH |\ | |
157 | PVR2_I2C_PEND_STALE) | |
158 | ||
159 | /* Disposition of firmware1 loading situation */ | |
160 | #define FW1_STATE_UNKNOWN 0 | |
161 | #define FW1_STATE_MISSING 1 | |
162 | #define FW1_STATE_FAILED 2 | |
163 | #define FW1_STATE_RELOAD 3 | |
164 | #define FW1_STATE_OK 4 | |
165 | ||
d855497e MI |
166 | typedef int (*pvr2_i2c_func)(struct pvr2_hdw *,u8,u8 *,u16,u8 *, u16); |
167 | #define PVR2_I2C_FUNC_CNT 128 | |
168 | ||
169 | /* This structure contains all state data directly needed to | |
170 | manipulate the hardware (as opposed to complying with a kernel | |
171 | interface) */ | |
172 | struct pvr2_hdw { | |
173 | /* Underlying USB device handle */ | |
174 | struct usb_device *usb_dev; | |
175 | struct usb_interface *usb_intf; | |
176 | ||
f66fbd71 MI |
177 | /* Device description, anything that must adjust behavior based on |
178 | device specific info will use information held here. */ | |
989eb154 | 179 | const struct pvr2_device_desc *hdw_desc; |
d855497e | 180 | |
681c7399 MI |
181 | /* Kernel worker thread handling */ |
182 | struct workqueue_struct *workqueue; | |
183 | struct work_struct workpoll; /* Update driver state */ | |
184 | struct work_struct worki2csync; /* Update i2c clients */ | |
185 | struct work_struct workinit; /* Driver initialization sequence */ | |
186 | ||
d855497e MI |
187 | /* Video spigot */ |
188 | struct pvr2_stream *vid_stream; | |
189 | ||
190 | /* Mutex for all hardware state control */ | |
191 | struct mutex big_lock_mutex; | |
192 | int big_lock_held; /* For debugging */ | |
193 | ||
d855497e MI |
194 | char name[32]; |
195 | ||
196 | /* I2C stuff */ | |
197 | struct i2c_adapter i2c_adap; | |
198 | struct i2c_algorithm i2c_algo; | |
199 | pvr2_i2c_func i2c_func[PVR2_I2C_FUNC_CNT]; | |
200 | int i2c_cx25840_hack_state; | |
201 | int i2c_linked; | |
202 | unsigned int i2c_pend_types; /* Which types of update are needed */ | |
203 | unsigned long i2c_pend_mask; /* Change bits we need to scan */ | |
204 | unsigned long i2c_stale_mask; /* Pending broadcast change bits */ | |
205 | unsigned long i2c_active_mask; /* All change bits currently in use */ | |
206 | struct list_head i2c_clients; | |
207 | struct mutex i2c_list_lock; | |
208 | ||
209 | /* Frequency table */ | |
210 | unsigned int freqTable[FREQTABLE_SIZE]; | |
211 | unsigned int freqProgSlot; | |
d855497e MI |
212 | |
213 | /* Stuff for handling low level control interaction with device */ | |
214 | struct mutex ctl_lock_mutex; | |
215 | int ctl_lock_held; /* For debugging */ | |
216 | struct urb *ctl_write_urb; | |
217 | struct urb *ctl_read_urb; | |
218 | unsigned char *ctl_write_buffer; | |
219 | unsigned char *ctl_read_buffer; | |
26e33048 MI |
220 | int ctl_write_pend_flag; |
221 | int ctl_read_pend_flag; | |
222 | int ctl_timeout_flag; | |
d855497e MI |
223 | struct completion ctl_done; |
224 | unsigned char cmd_buffer[PVR2_CTL_BUFFSIZE]; | |
225 | int cmd_debug_state; // Low level command debugging info | |
226 | unsigned char cmd_debug_code; // | |
227 | unsigned int cmd_debug_write_len; // | |
228 | unsigned int cmd_debug_read_len; // | |
229 | ||
681c7399 MI |
230 | /* Bits of state that describe what is going on with various parts |
231 | of the driver. */ | |
e802c14b MI |
232 | int state_encoder_ok; /* Encoder is operational */ |
233 | int state_encoder_run; /* Encoder is running */ | |
234 | int state_encoder_config; /* Encoder is configured */ | |
235 | int state_encoder_waitok; /* Encoder pre-wait done */ | |
236 | int state_decoder_run; /* Decoder is running */ | |
237 | int state_usbstream_run; /* FX2 is streaming */ | |
238 | int state_decoder_quiescent; /* Decoder idle for > 50msec */ | |
239 | int state_pipeline_config; /* Pipeline is configured */ | |
7f421fe4 MI |
240 | int state_pipeline_req; /* Somebody wants to stream */ |
241 | int state_pipeline_pause; /* Pipeline must be paused */ | |
242 | int state_pipeline_idle; /* Pipeline not running */ | |
681c7399 MI |
243 | |
244 | /* This is the master state of the driver. It is the combined | |
245 | result of other bits of state. Examining this will indicate the | |
246 | overall state of the driver. Values here are one of | |
247 | PVR2_STATE_xxxx */ | |
248 | unsigned int master_state; | |
249 | ||
250 | /* True if states must be re-evaluated */ | |
251 | int state_stale; | |
252 | ||
253 | void (*state_func)(void *); | |
254 | void *state_data; | |
255 | ||
256 | /* Timer for measuring decoder settling time */ | |
257 | struct timer_list quiescent_timer; | |
258 | ||
259 | /* Timer for measuring encoder pre-wait time */ | |
260 | struct timer_list encoder_wait_timer; | |
261 | ||
262 | /* Place to block while waiting for state changes */ | |
263 | wait_queue_head_t state_wait_data; | |
264 | ||
265 | ||
9a607f01 MI |
266 | int flag_ok; /* device in known good state */ |
267 | int flag_disconnected; /* flag_ok == 0 due to disconnect */ | |
268 | int flag_init_ok; /* true if structure is fully initialized */ | |
9a607f01 | 269 | int fw1_state; /* current situation with fw1 */ |
681c7399 MI |
270 | int flag_decoder_missed;/* We've noticed missing decoder */ |
271 | int flag_tripped; /* Indicates overall failure to start */ | |
d855497e MI |
272 | |
273 | struct pvr2_decoder_ctrl *decoder_ctrl; | |
274 | ||
275 | // CPU firmware info (used to help find / save firmware data) | |
276 | char *fw_buffer; | |
277 | unsigned int fw_size; | |
4db666cc | 278 | int fw_cpu_flag; /* True if we are dealing with the CPU */ |
d855497e | 279 | |
d855497e MI |
280 | // True if there is a request to trigger logging of state in each |
281 | // module. | |
282 | int log_requested; | |
283 | ||
284 | /* Tuner / frequency control stuff */ | |
285 | unsigned int tuner_type; | |
286 | int tuner_updated; | |
1bde0289 MI |
287 | unsigned int freqValTelevision; /* Current freq for tv mode */ |
288 | unsigned int freqValRadio; /* Current freq for radio mode */ | |
289 | unsigned int freqSlotTelevision; /* Current slot for tv mode */ | |
290 | unsigned int freqSlotRadio; /* Current slot for radio mode */ | |
291 | unsigned int freqSelector; /* 0=radio 1=television */ | |
d855497e MI |
292 | int freqDirty; |
293 | ||
18103c57 MI |
294 | /* Current tuner info - this information is polled from the I2C bus */ |
295 | struct v4l2_tuner tuner_signal_info; | |
296 | int tuner_signal_stale; | |
297 | ||
d855497e MI |
298 | /* Video standard handling */ |
299 | v4l2_std_id std_mask_eeprom; // Hardware supported selections | |
300 | v4l2_std_id std_mask_avail; // Which standards we may select from | |
301 | v4l2_std_id std_mask_cur; // Currently selected standard(s) | |
302 | unsigned int std_enum_cnt; // # of enumerated standards | |
303 | int std_enum_cur; // selected standard enumeration value | |
304 | int std_dirty; // True if std_mask_cur has changed | |
305 | struct pvr2_ctl_info std_info_enum; | |
306 | struct pvr2_ctl_info std_info_avail; | |
307 | struct pvr2_ctl_info std_info_cur; | |
308 | struct v4l2_standard *std_defs; | |
309 | const char **std_enum_names; | |
310 | ||
311 | // Generated string names, one per actual V4L2 standard | |
312 | const char *std_mask_ptrs[32]; | |
313 | char std_mask_names[32][10]; | |
314 | ||
315 | int unit_number; /* ID for driver instance */ | |
316 | unsigned long serial_number; /* ID for hardware itself */ | |
317 | ||
31a18547 MI |
318 | char bus_info[32]; /* Bus location info */ |
319 | ||
2fdf3d9c PK |
320 | /* Minor numbers used by v4l logic (yes, this is a hack, as there |
321 | should be no v4l junk here). Probably a better way to do this. */ | |
8079384e MI |
322 | int v4l_minor_number_video; |
323 | int v4l_minor_number_vbi; | |
fd5a75fe | 324 | int v4l_minor_number_radio; |
d855497e | 325 | |
7fb20fa3 MI |
326 | /* Bit mask of PVR2_CVAL_INPUT choices which are valid */ |
327 | unsigned int input_avail_mask; | |
328 | ||
d855497e MI |
329 | /* Location of eeprom or a negative number if none */ |
330 | int eeprom_addr; | |
331 | ||
681c7399 MI |
332 | enum pvr2_config active_stream_type; |
333 | enum pvr2_config desired_stream_type; | |
d855497e | 334 | |
b30d2441 MI |
335 | /* Control state needed for cx2341x module */ |
336 | struct cx2341x_mpeg_params enc_cur_state; | |
337 | struct cx2341x_mpeg_params enc_ctl_state; | |
338 | /* True if an encoder attribute has changed */ | |
339 | int enc_stale; | |
681c7399 MI |
340 | /* True if an unsafe encoder attribute has changed */ |
341 | int enc_unsafe_stale; | |
b30d2441 MI |
342 | /* True if enc_cur_state is valid */ |
343 | int enc_cur_valid; | |
c05c0462 | 344 | |
d855497e MI |
345 | /* Control state */ |
346 | #define VCREATE_DATA(lab) int lab##_val; int lab##_dirty | |
347 | VCREATE_DATA(brightness); | |
348 | VCREATE_DATA(contrast); | |
349 | VCREATE_DATA(saturation); | |
350 | VCREATE_DATA(hue); | |
351 | VCREATE_DATA(volume); | |
352 | VCREATE_DATA(balance); | |
353 | VCREATE_DATA(bass); | |
354 | VCREATE_DATA(treble); | |
355 | VCREATE_DATA(mute); | |
c05c0462 MI |
356 | VCREATE_DATA(input); |
357 | VCREATE_DATA(audiomode); | |
358 | VCREATE_DATA(res_hor); | |
359 | VCREATE_DATA(res_ver); | |
d855497e | 360 | VCREATE_DATA(srate); |
d855497e MI |
361 | #undef VCREATE_DATA |
362 | ||
b30d2441 | 363 | struct pvr2_ctld_info *mpeg_ctrl_info; |
c05c0462 | 364 | |
d855497e | 365 | struct pvr2_ctrl *controls; |
c05c0462 | 366 | unsigned int control_cnt; |
d855497e MI |
367 | }; |
368 | ||
1bde0289 MI |
369 | /* This function gets the current frequency */ |
370 | unsigned long pvr2_hdw_get_cur_freq(struct pvr2_hdw *); | |
681c7399 | 371 | void pvr2_hdw_set_decoder(struct pvr2_hdw *,struct pvr2_decoder_ctrl *); |
1bde0289 | 372 | |
d855497e MI |
373 | #endif /* __PVRUSB2_HDW_INTERNAL_H */ |
374 | ||
375 | /* | |
376 | Stuff for Emacs to see, in order to encourage consistent editing style: | |
377 | *** Local Variables: *** | |
378 | *** mode: c *** | |
379 | *** fill-column: 75 *** | |
380 | *** tab-width: 8 *** | |
381 | *** c-basic-offset: 8 *** | |
382 | *** End: *** | |
383 | */ |