Merge remote-tracking branch 'lightnvm/for-next'
[deliverable/linux.git] / drivers / media / usb / pvrusb2 / pvrusb2-hdw-internal.h
CommitLineData
d855497e
MI
1/*
2 *
d855497e
MI
3 *
4 * Copyright (C) 2005 Mike Isely <isely@pobox.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 */
20#ifndef __PVRUSB2_HDW_INTERNAL_H
21#define __PVRUSB2_HDW_INTERNAL_H
22
23/*
24
25 This header sets up all the internal structures and definitions needed to
26 track and coordinate the driver's interaction with the hardware. ONLY
27 source files which actually implement part of that whole circus should be
28 including this header. Higher levels, like the external layers to the
29 various public APIs (V4L, sysfs, etc) should NOT ever include this
30 private, internal header. This means that pvrusb2-hdw, pvrusb2-encoder,
31 etc will include this, but pvrusb2-v4l should not.
32
33*/
34
d855497e
MI
35#include <linux/videodev2.h>
36#include <linux/i2c.h>
681c7399 37#include <linux/workqueue.h>
d855497e
MI
38#include <linux/mutex.h>
39#include "pvrusb2-hdw.h"
40#include "pvrusb2-io.h"
b72b7bf5 41#include <media/v4l2-device.h>
d647f0b7 42#include <media/drv-intf/cx2341x.h>
b5dcee22 43#include <media/i2c/ir-kbd-i2c.h>
989eb154 44#include "pvrusb2-devattr.h"
d855497e 45
d855497e
MI
46/* Legal values for PVR2_CID_HSM */
47#define PVR2_CVAL_HSM_FAIL 0
48#define PVR2_CVAL_HSM_FULL 1
49#define PVR2_CVAL_HSM_HIGH 2
50
51#define PVR2_VID_ENDPOINT 0x84
52#define PVR2_UNK_ENDPOINT 0x86 /* maybe raw yuv ? */
53#define PVR2_VBI_ENDPOINT 0x88
54
55#define PVR2_CTL_BUFFSIZE 64
56
57#define FREQTABLE_SIZE 500
58
59#define LOCK_TAKE(x) do { mutex_lock(&x##_mutex); x##_held = !0; } while (0)
60#define LOCK_GIVE(x) do { x##_held = 0; mutex_unlock(&x##_mutex); } while (0)
61
d855497e
MI
62typedef int (*pvr2_ctlf_is_dirty)(struct pvr2_ctrl *);
63typedef void (*pvr2_ctlf_clear_dirty)(struct pvr2_ctrl *);
5549f54f 64typedef int (*pvr2_ctlf_check_value)(struct pvr2_ctrl *,int);
d855497e
MI
65typedef int (*pvr2_ctlf_get_value)(struct pvr2_ctrl *,int *);
66typedef int (*pvr2_ctlf_set_value)(struct pvr2_ctrl *,int msk,int val);
67typedef int (*pvr2_ctlf_val_to_sym)(struct pvr2_ctrl *,int msk,int val,
68 char *,unsigned int,unsigned int *);
69typedef int (*pvr2_ctlf_sym_to_val)(struct pvr2_ctrl *,
70 const char *,unsigned int,
71 int *mskp,int *valp);
a761f431 72typedef unsigned int (*pvr2_ctlf_get_v4lflags)(struct pvr2_ctrl *);
d855497e
MI
73
74/* This structure describes a specific control. A table of these is set up
75 in pvrusb2-hdw.c. */
76struct pvr2_ctl_info {
77 /* Control's name suitable for use as an identifier */
78 const char *name;
79
80 /* Short description of control */
81 const char *desc;
82
83 /* Control's implementation */
84 pvr2_ctlf_get_value get_value; /* Get its value */
26dd1c57 85 pvr2_ctlf_get_value get_def_value; /* Get its default 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 */
513521ea 119 const char * const *value_names; /* symbol names */
d855497e
MI
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
131struct pvr2_ctld_info {
132 struct pvr2_ctl_info info;
133 char desc[PVR2_CTLD_INFO_DESC_SIZE];
134};
135
d855497e
MI
136struct pvr2_ctrl {
137 const struct pvr2_ctl_info *info;
138 struct pvr2_hdw *hdw;
139};
140
141
d855497e
MI
142
143/* Disposition of firmware1 loading situation */
144#define FW1_STATE_UNKNOWN 0
145#define FW1_STATE_MISSING 1
146#define FW1_STATE_FAILED 2
147#define FW1_STATE_RELOAD 3
148#define FW1_STATE_OK 4
149
62433e31
MI
150/* What state the device is in if it is a hybrid */
151#define PVR2_PATHWAY_UNKNOWN 0
152#define PVR2_PATHWAY_ANALOG 1
153#define PVR2_PATHWAY_DIGITAL 2
154
d855497e
MI
155typedef int (*pvr2_i2c_func)(struct pvr2_hdw *,u8,u8 *,u16,u8 *, u16);
156#define PVR2_I2C_FUNC_CNT 128
157
158/* This structure contains all state data directly needed to
159 manipulate the hardware (as opposed to complying with a kernel
160 interface) */
161struct pvr2_hdw {
162 /* Underlying USB device handle */
163 struct usb_device *usb_dev;
164 struct usb_interface *usb_intf;
165
b72b7bf5
MI
166 /* Our handle into the v4l2 sub-device architecture */
167 struct v4l2_device v4l2_dev;
f66fbd71
MI
168 /* Device description, anything that must adjust behavior based on
169 device specific info will use information held here. */
989eb154 170 const struct pvr2_device_desc *hdw_desc;
d855497e 171
681c7399 172 /* Kernel worker thread handling */
681c7399 173 struct work_struct workpoll; /* Update driver state */
681c7399 174
d855497e
MI
175 /* Video spigot */
176 struct pvr2_stream *vid_stream;
177
178 /* Mutex for all hardware state control */
179 struct mutex big_lock_mutex;
180 int big_lock_held; /* For debugging */
181
13a88797
MI
182 /* This is a simple string which identifies the instance of this
183 driver. It is unique within the set of existing devices, but
184 there is no attempt to keep the name consistent with the same
185 physical device each time. */
d855497e
MI
186 char name[32];
187
13a88797
MI
188 /* This is a simple string which identifies the physical device
189 instance itself - if possible. (If not possible, then it is
190 based on the specific driver instance, similar to name above.)
191 The idea here is that userspace might hopefully be able to use
192 this recognize specific tuners. It will encode a serial number,
193 if available. */
194 char identifier[32];
195
d855497e
MI
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;
d855497e 202
27eab384
MI
203 /* IR related */
204 unsigned int ir_scheme_active; /* IR scheme as seen from the outside */
4999e27a 205 struct IR_i2c_init_data ir_init_data; /* params passed to IR modules */
27eab384 206
d855497e
MI
207 /* Frequency table */
208 unsigned int freqTable[FREQTABLE_SIZE];
209 unsigned int freqProgSlot;
d855497e
MI
210
211 /* Stuff for handling low level control interaction with device */
212 struct mutex ctl_lock_mutex;
213 int ctl_lock_held; /* For debugging */
214 struct urb *ctl_write_urb;
215 struct urb *ctl_read_urb;
216 unsigned char *ctl_write_buffer;
217 unsigned char *ctl_read_buffer;
26e33048
MI
218 int ctl_write_pend_flag;
219 int ctl_read_pend_flag;
220 int ctl_timeout_flag;
d855497e
MI
221 struct completion ctl_done;
222 unsigned char cmd_buffer[PVR2_CTL_BUFFSIZE];
223 int cmd_debug_state; // Low level command debugging info
224 unsigned char cmd_debug_code; //
225 unsigned int cmd_debug_write_len; //
226 unsigned int cmd_debug_read_len; //
227
681c7399
MI
228 /* Bits of state that describe what is going on with various parts
229 of the driver. */
62433e31 230 int state_pathway_ok; /* Pathway config is ok */
e802c14b
MI
231 int state_encoder_ok; /* Encoder is operational */
232 int state_encoder_run; /* Encoder is running */
233 int state_encoder_config; /* Encoder is configured */
234 int state_encoder_waitok; /* Encoder pre-wait done */
d913d630 235 int state_encoder_runok; /* Encoder has run for >= .25 sec */
e802c14b 236 int state_decoder_run; /* Decoder is running */
6e931375 237 int state_decoder_ready; /* Decoder is stabilized & streamable */
e802c14b 238 int state_usbstream_run; /* FX2 is streaming */
6e931375 239 int state_decoder_quiescent; /* Decoder idle for minimal interval */
e802c14b 240 int state_pipeline_config; /* Pipeline is configured */
7f421fe4
MI
241 int state_pipeline_req; /* Somebody wants to stream */
242 int state_pipeline_pause; /* Pipeline must be paused */
243 int state_pipeline_idle; /* Pipeline not running */
681c7399
MI
244
245 /* This is the master state of the driver. It is the combined
246 result of other bits of state. Examining this will indicate the
247 overall state of the driver. Values here are one of
248 PVR2_STATE_xxxx */
249 unsigned int master_state;
250
40381cb0
MI
251 /* True if device led is currently on */
252 int led_on;
253
681c7399
MI
254 /* True if states must be re-evaluated */
255 int state_stale;
256
257 void (*state_func)(void *);
258 void *state_data;
259
6e931375
MI
260 /* Timer for measuring required decoder settling time before we're
261 allowed to fire it up again. */
681c7399
MI
262 struct timer_list quiescent_timer;
263
6e931375
MI
264 /* Timer for measuring decoder stabilization time, which is the
265 amount of time we need to let the decoder run before we can
266 trust its output (otherwise the encoder might see garbage and
267 then fail to start correctly). */
268 struct timer_list decoder_stabilization_timer;
269
681c7399
MI
270 /* Timer for measuring encoder pre-wait time */
271 struct timer_list encoder_wait_timer;
272
d913d630
MI
273 /* Timer for measuring encoder minimum run time */
274 struct timer_list encoder_run_timer;
275
681c7399
MI
276 /* Place to block while waiting for state changes */
277 wait_queue_head_t state_wait_data;
278
279
27764726 280 int force_dirty; /* consider all controls dirty if true */
9a607f01 281 int flag_ok; /* device in known good state */
27108147 282 int flag_modulefail; /* true if at least one module failed to load */
9a607f01
MI
283 int flag_disconnected; /* flag_ok == 0 due to disconnect */
284 int flag_init_ok; /* true if structure is fully initialized */
9a607f01 285 int fw1_state; /* current situation with fw1 */
62433e31 286 int pathway_state; /* one of PVR2_PATHWAY_xxx */
681c7399
MI
287 int flag_decoder_missed;/* We've noticed missing decoder */
288 int flag_tripped; /* Indicates overall failure to start */
d855497e 289
00e5f736 290 unsigned int decoder_client_id;
d855497e
MI
291
292 // CPU firmware info (used to help find / save firmware data)
293 char *fw_buffer;
294 unsigned int fw_size;
4db666cc 295 int fw_cpu_flag; /* True if we are dealing with the CPU */
d855497e 296
d855497e
MI
297 /* Tuner / frequency control stuff */
298 unsigned int tuner_type;
299 int tuner_updated;
1bde0289
MI
300 unsigned int freqValTelevision; /* Current freq for tv mode */
301 unsigned int freqValRadio; /* Current freq for radio mode */
302 unsigned int freqSlotTelevision; /* Current slot for tv mode */
303 unsigned int freqSlotRadio; /* Current slot for radio mode */
304 unsigned int freqSelector; /* 0=radio 1=television */
d855497e
MI
305 int freqDirty;
306
18103c57
MI
307 /* Current tuner info - this information is polled from the I2C bus */
308 struct v4l2_tuner tuner_signal_info;
309 int tuner_signal_stale;
310
432907f7
MI
311 /* Cropping capability info */
312 struct v4l2_cropcap cropcap_info;
313 int cropcap_stale;
314
d855497e
MI
315 /* Video standard handling */
316 v4l2_std_id std_mask_eeprom; // Hardware supported selections
317 v4l2_std_id std_mask_avail; // Which standards we may select from
318 v4l2_std_id std_mask_cur; // Currently selected standard(s)
d855497e
MI
319 int std_enum_cur; // selected standard enumeration value
320 int std_dirty; // True if std_mask_cur has changed
321 struct pvr2_ctl_info std_info_enum;
322 struct pvr2_ctl_info std_info_avail;
323 struct pvr2_ctl_info std_info_cur;
ac04d00e 324 struct pvr2_ctl_info std_info_detect;
d855497e
MI
325
326 // Generated string names, one per actual V4L2 standard
327 const char *std_mask_ptrs[32];
99ba1514 328 char std_mask_names[32][16];
d855497e
MI
329
330 int unit_number; /* ID for driver instance */
331 unsigned long serial_number; /* ID for hardware itself */
332
31a18547
MI
333 char bus_info[32]; /* Bus location info */
334
2fdf3d9c
PK
335 /* Minor numbers used by v4l logic (yes, this is a hack, as there
336 should be no v4l junk here). Probably a better way to do this. */
8079384e
MI
337 int v4l_minor_number_video;
338 int v4l_minor_number_vbi;
fd5a75fe 339 int v4l_minor_number_radio;
d855497e 340
1cb03b76 341 /* Bit mask of PVR2_CVAL_INPUT choices which are valid for the hardware */
7fb20fa3 342 unsigned int input_avail_mask;
af901ca1 343 /* Bit mask of PVR2_CVAL_INPUT choices which are currently allowed */
1cb03b76 344 unsigned int input_allowed_mask;
7fb20fa3 345
d855497e
MI
346 /* Location of eeprom or a negative number if none */
347 int eeprom_addr;
348
681c7399
MI
349 enum pvr2_config active_stream_type;
350 enum pvr2_config desired_stream_type;
d855497e 351
b30d2441
MI
352 /* Control state needed for cx2341x module */
353 struct cx2341x_mpeg_params enc_cur_state;
354 struct cx2341x_mpeg_params enc_ctl_state;
355 /* True if an encoder attribute has changed */
356 int enc_stale;
681c7399
MI
357 /* True if an unsafe encoder attribute has changed */
358 int enc_unsafe_stale;
b30d2441
MI
359 /* True if enc_cur_state is valid */
360 int enc_cur_valid;
c05c0462 361
d855497e
MI
362 /* Control state */
363#define VCREATE_DATA(lab) int lab##_val; int lab##_dirty
364 VCREATE_DATA(brightness);
365 VCREATE_DATA(contrast);
366 VCREATE_DATA(saturation);
367 VCREATE_DATA(hue);
368 VCREATE_DATA(volume);
369 VCREATE_DATA(balance);
370 VCREATE_DATA(bass);
371 VCREATE_DATA(treble);
372 VCREATE_DATA(mute);
e784bfb9 373 VCREATE_DATA(cropl);
374 VCREATE_DATA(cropt);
375 VCREATE_DATA(cropw);
376 VCREATE_DATA(croph);
c05c0462
MI
377 VCREATE_DATA(input);
378 VCREATE_DATA(audiomode);
379 VCREATE_DATA(res_hor);
380 VCREATE_DATA(res_ver);
d855497e 381 VCREATE_DATA(srate);
d855497e
MI
382#undef VCREATE_DATA
383
b30d2441 384 struct pvr2_ctld_info *mpeg_ctrl_info;
c05c0462 385
d855497e 386 struct pvr2_ctrl *controls;
c05c0462 387 unsigned int control_cnt;
d855497e
MI
388};
389
1bde0289
MI
390/* This function gets the current frequency */
391unsigned long pvr2_hdw_get_cur_freq(struct pvr2_hdw *);
392
a51f5000
MI
393void pvr2_hdw_status_poll(struct pvr2_hdw *);
394
d855497e 395#endif /* __PVRUSB2_HDW_INTERNAL_H */
This page took 0.927924 seconds and 5 git commands to generate.