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