]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blob - drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
Merge branch 'devel' of master.kernel.org:/home/rmk/linux-2.6-serial
[mirror_ubuntu-hirsute-kernel.git] / drivers / media / video / pvrusb2 / pvrusb2-hdw-internal.h
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/videodev2.h>
37 #include <linux/i2c.h>
38 #include <linux/mutex.h>
39 #include "pvrusb2-hdw.h"
40 #include "pvrusb2-io.h"
41 #include <media/cx2341x.h>
42
43 /* Legal values for PVR2_CID_HSM */
44 #define PVR2_CVAL_HSM_FAIL 0
45 #define PVR2_CVAL_HSM_FULL 1
46 #define PVR2_CVAL_HSM_HIGH 2
47
48 #define PVR2_VID_ENDPOINT 0x84
49 #define PVR2_UNK_ENDPOINT 0x86 /* maybe raw yuv ? */
50 #define PVR2_VBI_ENDPOINT 0x88
51
52 #define PVR2_CTL_BUFFSIZE 64
53
54 #define FREQTABLE_SIZE 500
55
56 #define LOCK_TAKE(x) do { mutex_lock(&x##_mutex); x##_held = !0; } while (0)
57 #define LOCK_GIVE(x) do { x##_held = 0; mutex_unlock(&x##_mutex); } while (0)
58
59 struct pvr2_decoder;
60
61 typedef int (*pvr2_ctlf_is_dirty)(struct pvr2_ctrl *);
62 typedef void (*pvr2_ctlf_clear_dirty)(struct pvr2_ctrl *);
63 typedef int (*pvr2_ctlf_get_value)(struct pvr2_ctrl *,int *);
64 typedef int (*pvr2_ctlf_set_value)(struct pvr2_ctrl *,int msk,int val);
65 typedef int (*pvr2_ctlf_val_to_sym)(struct pvr2_ctrl *,int msk,int val,
66 char *,unsigned int,unsigned int *);
67 typedef int (*pvr2_ctlf_sym_to_val)(struct pvr2_ctrl *,
68 const char *,unsigned int,
69 int *mskp,int *valp);
70 typedef unsigned int (*pvr2_ctlf_get_v4lflags)(struct pvr2_ctrl *);
71
72 /* This structure describes a specific control. A table of these is set up
73 in pvrusb2-hdw.c. */
74 struct pvr2_ctl_info {
75 /* Control's name suitable for use as an identifier */
76 const char *name;
77
78 /* Short description of control */
79 const char *desc;
80
81 /* Control's implementation */
82 pvr2_ctlf_get_value get_value; /* Get its value */
83 pvr2_ctlf_get_value get_min_value; /* Get minimum allowed value */
84 pvr2_ctlf_get_value get_max_value; /* Get maximum allowed value */
85 pvr2_ctlf_set_value set_value; /* Set its value */
86 pvr2_ctlf_val_to_sym val_to_sym; /* Custom convert value->symbol */
87 pvr2_ctlf_sym_to_val sym_to_val; /* Custom convert symbol->value */
88 pvr2_ctlf_is_dirty is_dirty; /* Return true if dirty */
89 pvr2_ctlf_clear_dirty clear_dirty; /* Clear dirty state */
90 pvr2_ctlf_get_v4lflags get_v4lflags;/* Retrieve v4l flags */
91
92 /* Control's type (int, enum, bitmask) */
93 enum pvr2_ctl_type type;
94
95 /* Associated V4L control ID, if any */
96 int v4l_id;
97
98 /* Associated driver internal ID, if any */
99 int internal_id;
100
101 /* Don't implicitly initialize this control's value */
102 int skip_init;
103
104 /* Starting value for this control */
105 int default_value;
106
107 /* Type-specific control information */
108 union {
109 struct { /* Integer control */
110 long min_value; /* lower limit */
111 long max_value; /* upper limit */
112 } type_int;
113 struct { /* enumerated control */
114 unsigned int count; /* enum value count */
115 const char **value_names; /* symbol names */
116 } type_enum;
117 struct { /* bitmask control */
118 unsigned int valid_bits; /* bits in use */
119 const char **bit_names; /* symbol name/bit */
120 } type_bitmask;
121 } def;
122 };
123
124
125 /* Same as pvr2_ctl_info, but includes storage for the control description */
126 #define PVR2_CTLD_INFO_DESC_SIZE 32
127 struct pvr2_ctld_info {
128 struct pvr2_ctl_info info;
129 char desc[PVR2_CTLD_INFO_DESC_SIZE];
130 };
131
132 struct pvr2_ctrl {
133 const struct pvr2_ctl_info *info;
134 struct pvr2_hdw *hdw;
135 };
136
137
138 struct pvr2_audio_stat {
139 void *ctxt;
140 void (*detach)(void *);
141 int (*status)(void *);
142 };
143
144 struct pvr2_decoder_ctrl {
145 void *ctxt;
146 void (*detach)(void *);
147 void (*enable)(void *,int);
148 int (*tuned)(void *);
149 void (*force_reset)(void *);
150 };
151
152 #define PVR2_I2C_PEND_DETECT 0x01 /* Need to detect a client type */
153 #define PVR2_I2C_PEND_CLIENT 0x02 /* Client needs a specific update */
154 #define PVR2_I2C_PEND_REFRESH 0x04 /* Client has specific pending bits */
155 #define PVR2_I2C_PEND_STALE 0x08 /* Broadcast pending bits */
156
157 #define PVR2_I2C_PEND_ALL (PVR2_I2C_PEND_DETECT |\
158 PVR2_I2C_PEND_CLIENT |\
159 PVR2_I2C_PEND_REFRESH |\
160 PVR2_I2C_PEND_STALE)
161
162 /* Disposition of firmware1 loading situation */
163 #define FW1_STATE_UNKNOWN 0
164 #define FW1_STATE_MISSING 1
165 #define FW1_STATE_FAILED 2
166 #define FW1_STATE_RELOAD 3
167 #define FW1_STATE_OK 4
168
169 /* Known major hardware variants, keyed from device ID */
170 #define PVR2_HDW_TYPE_29XXX 0
171 #define PVR2_HDW_TYPE_24XXX 1
172
173 typedef int (*pvr2_i2c_func)(struct pvr2_hdw *,u8,u8 *,u16,u8 *, u16);
174 #define PVR2_I2C_FUNC_CNT 128
175
176 /* This structure contains all state data directly needed to
177 manipulate the hardware (as opposed to complying with a kernel
178 interface) */
179 struct pvr2_hdw {
180 /* Underlying USB device handle */
181 struct usb_device *usb_dev;
182 struct usb_interface *usb_intf;
183
184 /* Device type, one of PVR2_HDW_TYPE_xxxxx */
185 unsigned int hdw_type;
186
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
194 void (*poll_trigger_func)(void *);
195 void *poll_trigger_data;
196
197 char name[32];
198
199 /* I2C stuff */
200 struct i2c_adapter i2c_adap;
201 struct i2c_algorithm i2c_algo;
202 pvr2_i2c_func i2c_func[PVR2_I2C_FUNC_CNT];
203 int i2c_cx25840_hack_state;
204 int i2c_linked;
205 unsigned int i2c_pend_types; /* Which types of update are needed */
206 unsigned long i2c_pend_mask; /* Change bits we need to scan */
207 unsigned long i2c_stale_mask; /* Pending broadcast change bits */
208 unsigned long i2c_active_mask; /* All change bits currently in use */
209 struct list_head i2c_clients;
210 struct mutex i2c_list_lock;
211
212 /* Frequency table */
213 unsigned int freqTable[FREQTABLE_SIZE];
214 unsigned int freqProgSlot;
215 unsigned int freqSlot;
216
217 /* Stuff for handling low level control interaction with device */
218 struct mutex ctl_lock_mutex;
219 int ctl_lock_held; /* For debugging */
220 struct urb *ctl_write_urb;
221 struct urb *ctl_read_urb;
222 unsigned char *ctl_write_buffer;
223 unsigned char *ctl_read_buffer;
224 volatile int ctl_write_pend_flag;
225 volatile int ctl_read_pend_flag;
226 volatile int ctl_timeout_flag;
227 struct completion ctl_done;
228 unsigned char cmd_buffer[PVR2_CTL_BUFFSIZE];
229 int cmd_debug_state; // Low level command debugging info
230 unsigned char cmd_debug_code; //
231 unsigned int cmd_debug_write_len; //
232 unsigned int cmd_debug_read_len; //
233
234 int flag_ok; // device in known good state
235 int flag_disconnected; // flag_ok == 0 due to disconnect
236 int flag_init_ok; // true if structure is fully initialized
237 int flag_streaming_enabled; // true if streaming should be on
238 int fw1_state; // current situation with fw1
239
240 int flag_decoder_is_tuned;
241
242 struct pvr2_decoder_ctrl *decoder_ctrl;
243
244 // CPU firmware info (used to help find / save firmware data)
245 char *fw_buffer;
246 unsigned int fw_size;
247
248 // Which subsystem pieces have been enabled / configured
249 unsigned long subsys_enabled_mask;
250
251 // Which subsystems are manipulated to enable streaming
252 unsigned long subsys_stream_mask;
253
254 // True if there is a request to trigger logging of state in each
255 // module.
256 int log_requested;
257
258 /* Tuner / frequency control stuff */
259 unsigned int tuner_type;
260 int tuner_updated;
261 unsigned int freqVal;
262 int freqDirty;
263
264 /* Video standard handling */
265 v4l2_std_id std_mask_eeprom; // Hardware supported selections
266 v4l2_std_id std_mask_avail; // Which standards we may select from
267 v4l2_std_id std_mask_cur; // Currently selected standard(s)
268 unsigned int std_enum_cnt; // # of enumerated standards
269 int std_enum_cur; // selected standard enumeration value
270 int std_dirty; // True if std_mask_cur has changed
271 struct pvr2_ctl_info std_info_enum;
272 struct pvr2_ctl_info std_info_avail;
273 struct pvr2_ctl_info std_info_cur;
274 struct v4l2_standard *std_defs;
275 const char **std_enum_names;
276
277 // Generated string names, one per actual V4L2 standard
278 const char *std_mask_ptrs[32];
279 char std_mask_names[32][10];
280
281 int unit_number; /* ID for driver instance */
282 unsigned long serial_number; /* ID for hardware itself */
283
284 /* Minor number used by v4l logic (yes, this is a hack, as there should
285 be no v4l junk here). Probably a better way to do this. */
286 int v4l_minor_number;
287
288 /* Location of eeprom or a negative number if none */
289 int eeprom_addr;
290
291 enum pvr2_config config;
292
293 /* Information about what audio signal we're hearing */
294 int flag_stereo;
295 int flag_bilingual;
296 struct pvr2_audio_stat *audio_stat;
297
298 /* Control state needed for cx2341x module */
299 struct cx2341x_mpeg_params enc_cur_state;
300 struct cx2341x_mpeg_params enc_ctl_state;
301 /* True if an encoder attribute has changed */
302 int enc_stale;
303 /* True if enc_cur_state is valid */
304 int enc_cur_valid;
305
306 /* Control state */
307 #define VCREATE_DATA(lab) int lab##_val; int lab##_dirty
308 VCREATE_DATA(brightness);
309 VCREATE_DATA(contrast);
310 VCREATE_DATA(saturation);
311 VCREATE_DATA(hue);
312 VCREATE_DATA(volume);
313 VCREATE_DATA(balance);
314 VCREATE_DATA(bass);
315 VCREATE_DATA(treble);
316 VCREATE_DATA(mute);
317 VCREATE_DATA(input);
318 VCREATE_DATA(audiomode);
319 VCREATE_DATA(res_hor);
320 VCREATE_DATA(res_ver);
321 VCREATE_DATA(srate);
322 #undef VCREATE_DATA
323
324 struct pvr2_ctld_info *mpeg_ctrl_info;
325
326 struct pvr2_ctrl *controls;
327 unsigned int control_cnt;
328 };
329
330 #endif /* __PVRUSB2_HDW_INTERNAL_H */
331
332 /*
333 Stuff for Emacs to see, in order to encourage consistent editing style:
334 *** Local Variables: ***
335 *** mode: c ***
336 *** fill-column: 75 ***
337 *** tab-width: 8 ***
338 *** c-basic-offset: 8 ***
339 *** End: ***
340 */