4 * Copyright (C) 2005 Mike Isely <isely@pobox.com>
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
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.
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
20 #ifndef __PVRUSB2_HDW_INTERNAL_H
21 #define __PVRUSB2_HDW_INTERNAL_H
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.
35 #include <linux/videodev2.h>
36 #include <linux/i2c.h>
37 #include <linux/workqueue.h>
38 #include <linux/mutex.h>
39 #include "pvrusb2-hdw.h"
40 #include "pvrusb2-io.h"
41 #include <media/v4l2-device.h>
42 #include <media/cx2341x.h>
43 #include "pvrusb2-devattr.h"
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
50 #define PVR2_VID_ENDPOINT 0x84
51 #define PVR2_UNK_ENDPOINT 0x86 /* maybe raw yuv ? */
52 #define PVR2_VBI_ENDPOINT 0x88
54 #define PVR2_CTL_BUFFSIZE 64
56 #define FREQTABLE_SIZE 500
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)
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_check_value
)(struct pvr2_ctrl
*,int);
64 typedef int (*pvr2_ctlf_get_value
)(struct pvr2_ctrl
*,int *);
65 typedef int (*pvr2_ctlf_set_value
)(struct pvr2_ctrl
*,int msk
,int val
);
66 typedef int (*pvr2_ctlf_val_to_sym
)(struct pvr2_ctrl
*,int msk
,int val
,
67 char *,unsigned int,unsigned int *);
68 typedef int (*pvr2_ctlf_sym_to_val
)(struct pvr2_ctrl
*,
69 const char *,unsigned int,
71 typedef unsigned int (*pvr2_ctlf_get_v4lflags
)(struct pvr2_ctrl
*);
73 /* This structure describes a specific control. A table of these is set up
75 struct pvr2_ctl_info
{
76 /* Control's name suitable for use as an identifier */
79 /* Short description of control */
82 /* Control's implementation */
83 pvr2_ctlf_get_value get_value
; /* Get its value */
84 pvr2_ctlf_get_value get_def_value
; /* Get its default value */
85 pvr2_ctlf_get_value get_min_value
; /* Get minimum allowed value */
86 pvr2_ctlf_get_value get_max_value
; /* Get maximum allowed value */
87 pvr2_ctlf_set_value set_value
; /* Set its value */
88 pvr2_ctlf_check_value check_value
; /* Check that value is valid */
89 pvr2_ctlf_val_to_sym val_to_sym
; /* Custom convert value->symbol */
90 pvr2_ctlf_sym_to_val sym_to_val
; /* Custom convert symbol->value */
91 pvr2_ctlf_is_dirty is_dirty
; /* Return true if dirty */
92 pvr2_ctlf_clear_dirty clear_dirty
; /* Clear dirty state */
93 pvr2_ctlf_get_v4lflags get_v4lflags
;/* Retrieve v4l flags */
95 /* Control's type (int, enum, bitmask) */
96 enum pvr2_ctl_type type
;
98 /* Associated V4L control ID, if any */
101 /* Associated driver internal ID, if any */
104 /* Don't implicitly initialize this control's value */
107 /* Starting value for this control */
110 /* Type-specific control information */
112 struct { /* Integer control */
113 long min_value
; /* lower limit */
114 long max_value
; /* upper limit */
116 struct { /* enumerated control */
117 unsigned int count
; /* enum value count */
118 const char **value_names
; /* symbol names */
120 struct { /* bitmask control */
121 unsigned int valid_bits
; /* bits in use */
122 const char **bit_names
; /* symbol name/bit */
128 /* Same as pvr2_ctl_info, but includes storage for the control description */
129 #define PVR2_CTLD_INFO_DESC_SIZE 32
130 struct pvr2_ctld_info
{
131 struct pvr2_ctl_info info
;
132 char desc
[PVR2_CTLD_INFO_DESC_SIZE
];
136 const struct pvr2_ctl_info
*info
;
137 struct pvr2_hdw
*hdw
;
141 struct pvr2_decoder_ctrl
{
143 void (*detach
)(void *);
144 void (*enable
)(void *,int);
145 void (*force_reset
)(void *);
148 #define PVR2_I2C_PEND_DETECT 0x01 /* Need to detect a client type */
149 #define PVR2_I2C_PEND_CLIENT 0x02 /* Client needs a specific update */
150 #define PVR2_I2C_PEND_REFRESH 0x04 /* Client has specific pending bits */
151 #define PVR2_I2C_PEND_STALE 0x08 /* Broadcast pending bits */
153 #define PVR2_I2C_PEND_ALL (PVR2_I2C_PEND_DETECT |\
154 PVR2_I2C_PEND_CLIENT |\
155 PVR2_I2C_PEND_REFRESH |\
158 /* Disposition of firmware1 loading situation */
159 #define FW1_STATE_UNKNOWN 0
160 #define FW1_STATE_MISSING 1
161 #define FW1_STATE_FAILED 2
162 #define FW1_STATE_RELOAD 3
163 #define FW1_STATE_OK 4
165 /* What state the device is in if it is a hybrid */
166 #define PVR2_PATHWAY_UNKNOWN 0
167 #define PVR2_PATHWAY_ANALOG 1
168 #define PVR2_PATHWAY_DIGITAL 2
170 typedef int (*pvr2_i2c_func
)(struct pvr2_hdw
*,u8
,u8
*,u16
,u8
*, u16
);
171 #define PVR2_I2C_FUNC_CNT 128
173 /* This structure contains all state data directly needed to
174 manipulate the hardware (as opposed to complying with a kernel
177 /* Underlying USB device handle */
178 struct usb_device
*usb_dev
;
179 struct usb_interface
*usb_intf
;
181 /* Our handle into the v4l2 sub-device architecture */
182 struct v4l2_device v4l2_dev
;
183 /* Device description, anything that must adjust behavior based on
184 device specific info will use information held here. */
185 const struct pvr2_device_desc
*hdw_desc
;
187 /* Kernel worker thread handling */
188 struct workqueue_struct
*workqueue
;
189 struct work_struct workpoll
; /* Update driver state */
190 struct work_struct worki2csync
; /* Update i2c clients */
193 struct pvr2_stream
*vid_stream
;
195 /* Mutex for all hardware state control */
196 struct mutex big_lock_mutex
;
197 int big_lock_held
; /* For debugging */
199 /* This is a simple string which identifies the instance of this
200 driver. It is unique within the set of existing devices, but
201 there is no attempt to keep the name consistent with the same
202 physical device each time. */
205 /* This is a simple string which identifies the physical device
206 instance itself - if possible. (If not possible, then it is
207 based on the specific driver instance, similar to name above.)
208 The idea here is that userspace might hopefully be able to use
209 this recognize specific tuners. It will encode a serial number,
214 struct i2c_adapter i2c_adap
;
215 struct i2c_algorithm i2c_algo
;
216 pvr2_i2c_func i2c_func
[PVR2_I2C_FUNC_CNT
];
217 int i2c_cx25840_hack_state
;
219 unsigned int i2c_pend_types
; /* Which types of update are needed */
220 unsigned long i2c_pend_mask
; /* Change bits we need to scan */
221 unsigned long i2c_stale_mask
; /* Pending broadcast change bits */
222 unsigned long i2c_active_mask
; /* All change bits currently in use */
223 struct list_head i2c_clients
;
224 struct mutex i2c_list_lock
;
226 /* Frequency table */
227 unsigned int freqTable
[FREQTABLE_SIZE
];
228 unsigned int freqProgSlot
;
230 /* Stuff for handling low level control interaction with device */
231 struct mutex ctl_lock_mutex
;
232 int ctl_lock_held
; /* For debugging */
233 struct urb
*ctl_write_urb
;
234 struct urb
*ctl_read_urb
;
235 unsigned char *ctl_write_buffer
;
236 unsigned char *ctl_read_buffer
;
237 int ctl_write_pend_flag
;
238 int ctl_read_pend_flag
;
239 int ctl_timeout_flag
;
240 struct completion ctl_done
;
241 unsigned char cmd_buffer
[PVR2_CTL_BUFFSIZE
];
242 int cmd_debug_state
; // Low level command debugging info
243 unsigned char cmd_debug_code
; //
244 unsigned int cmd_debug_write_len
; //
245 unsigned int cmd_debug_read_len
; //
247 /* Bits of state that describe what is going on with various parts
249 int state_pathway_ok
; /* Pathway config is ok */
250 int state_encoder_ok
; /* Encoder is operational */
251 int state_encoder_run
; /* Encoder is running */
252 int state_encoder_config
; /* Encoder is configured */
253 int state_encoder_waitok
; /* Encoder pre-wait done */
254 int state_encoder_runok
; /* Encoder has run for >= .25 sec */
255 int state_decoder_run
; /* Decoder is running */
256 int state_usbstream_run
; /* FX2 is streaming */
257 int state_decoder_quiescent
; /* Decoder idle for > 50msec */
258 int state_pipeline_config
; /* Pipeline is configured */
259 int state_pipeline_req
; /* Somebody wants to stream */
260 int state_pipeline_pause
; /* Pipeline must be paused */
261 int state_pipeline_idle
; /* Pipeline not running */
263 /* This is the master state of the driver. It is the combined
264 result of other bits of state. Examining this will indicate the
265 overall state of the driver. Values here are one of
267 unsigned int master_state
;
269 /* True if device led is currently on */
272 /* True if states must be re-evaluated */
275 void (*state_func
)(void *);
278 /* Timer for measuring decoder settling time */
279 struct timer_list quiescent_timer
;
281 /* Timer for measuring encoder pre-wait time */
282 struct timer_list encoder_wait_timer
;
284 /* Timer for measuring encoder minimum run time */
285 struct timer_list encoder_run_timer
;
287 /* Place to block while waiting for state changes */
288 wait_queue_head_t state_wait_data
;
291 int force_dirty
; /* consider all controls dirty if true */
292 int flag_ok
; /* device in known good state */
293 int flag_disconnected
; /* flag_ok == 0 due to disconnect */
294 int flag_init_ok
; /* true if structure is fully initialized */
295 int fw1_state
; /* current situation with fw1 */
296 int pathway_state
; /* one of PVR2_PATHWAY_xxx */
297 int flag_decoder_missed
;/* We've noticed missing decoder */
298 int flag_tripped
; /* Indicates overall failure to start */
300 struct pvr2_decoder_ctrl
*decoder_ctrl
;
301 unsigned int decoder_client_id
;
303 // CPU firmware info (used to help find / save firmware data)
305 unsigned int fw_size
;
306 int fw_cpu_flag
; /* True if we are dealing with the CPU */
308 // True if there is a request to trigger logging of state in each
312 /* Tuner / frequency control stuff */
313 unsigned int tuner_type
;
315 unsigned int freqValTelevision
; /* Current freq for tv mode */
316 unsigned int freqValRadio
; /* Current freq for radio mode */
317 unsigned int freqSlotTelevision
; /* Current slot for tv mode */
318 unsigned int freqSlotRadio
; /* Current slot for radio mode */
319 unsigned int freqSelector
; /* 0=radio 1=television */
322 /* Current tuner info - this information is polled from the I2C bus */
323 struct v4l2_tuner tuner_signal_info
;
324 int tuner_signal_stale
;
326 /* Cropping capability info */
327 struct v4l2_cropcap cropcap_info
;
330 /* Video standard handling */
331 v4l2_std_id std_mask_eeprom
; // Hardware supported selections
332 v4l2_std_id std_mask_avail
; // Which standards we may select from
333 v4l2_std_id std_mask_cur
; // Currently selected standard(s)
334 unsigned int std_enum_cnt
; // # of enumerated standards
335 int std_enum_cur
; // selected standard enumeration value
336 int std_dirty
; // True if std_mask_cur has changed
337 struct pvr2_ctl_info std_info_enum
;
338 struct pvr2_ctl_info std_info_avail
;
339 struct pvr2_ctl_info std_info_cur
;
340 struct v4l2_standard
*std_defs
;
341 const char **std_enum_names
;
343 // Generated string names, one per actual V4L2 standard
344 const char *std_mask_ptrs
[32];
345 char std_mask_names
[32][10];
347 int unit_number
; /* ID for driver instance */
348 unsigned long serial_number
; /* ID for hardware itself */
350 char bus_info
[32]; /* Bus location info */
352 /* Minor numbers used by v4l logic (yes, this is a hack, as there
353 should be no v4l junk here). Probably a better way to do this. */
354 int v4l_minor_number_video
;
355 int v4l_minor_number_vbi
;
356 int v4l_minor_number_radio
;
358 /* Bit mask of PVR2_CVAL_INPUT choices which are valid for the hardware */
359 unsigned int input_avail_mask
;
360 /* Bit mask of PVR2_CVAL_INPUT choices which are currenly allowed */
361 unsigned int input_allowed_mask
;
363 /* Location of eeprom or a negative number if none */
366 enum pvr2_config active_stream_type
;
367 enum pvr2_config desired_stream_type
;
369 /* Control state needed for cx2341x module */
370 struct cx2341x_mpeg_params enc_cur_state
;
371 struct cx2341x_mpeg_params enc_ctl_state
;
372 /* True if an encoder attribute has changed */
374 /* True if an unsafe encoder attribute has changed */
375 int enc_unsafe_stale
;
376 /* True if enc_cur_state is valid */
380 #define VCREATE_DATA(lab) int lab##_val; int lab##_dirty
381 VCREATE_DATA(brightness
);
382 VCREATE_DATA(contrast
);
383 VCREATE_DATA(saturation
);
385 VCREATE_DATA(volume
);
386 VCREATE_DATA(balance
);
388 VCREATE_DATA(treble
);
395 VCREATE_DATA(audiomode
);
396 VCREATE_DATA(res_hor
);
397 VCREATE_DATA(res_ver
);
401 struct pvr2_ctld_info
*mpeg_ctrl_info
;
403 struct pvr2_ctrl
*controls
;
404 unsigned int control_cnt
;
407 /* This function gets the current frequency */
408 unsigned long pvr2_hdw_get_cur_freq(struct pvr2_hdw
*);
409 void pvr2_hdw_set_decoder(struct pvr2_hdw
*,struct pvr2_decoder_ctrl
*);
411 void pvr2_hdw_status_poll(struct pvr2_hdw
*);
413 #endif /* __PVRUSB2_HDW_INTERNAL_H */
416 Stuff for Emacs to see, in order to encourage consistent editing style:
417 *** Local Variables: ***
419 *** fill-column: 75 ***
421 *** c-basic-offset: 8 ***