5 * Copyright (C) 2005 Mike Isely <isely@pobox.com>
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
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.
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
21 #ifndef __PVRUSB2_HDW_INTERNAL_H
22 #define __PVRUSB2_HDW_INTERNAL_H
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.
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>
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
48 #define PVR2_VID_ENDPOINT 0x84
49 #define PVR2_UNK_ENDPOINT 0x86 /* maybe raw yuv ? */
50 #define PVR2_VBI_ENDPOINT 0x88
52 #define PVR2_CTL_BUFFSIZE 64
54 #define FREQTABLE_SIZE 500
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)
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_min_value; /* Get minimum allowed value */
85 pvr2_ctlf_get_value get_max_value; /* Get maximum allowed value */
86 pvr2_ctlf_set_value set_value; /* Set its value */
87 pvr2_ctlf_check_value check_value; /* Check that value is valid */
88 pvr2_ctlf_val_to_sym val_to_sym; /* Custom convert value->symbol */
89 pvr2_ctlf_sym_to_val sym_to_val; /* Custom convert symbol->value */
90 pvr2_ctlf_is_dirty is_dirty; /* Return true if dirty */
91 pvr2_ctlf_clear_dirty clear_dirty; /* Clear dirty state */
92 pvr2_ctlf_get_v4lflags get_v4lflags;/* Retrieve v4l flags */
94 /* Control's type (int, enum, bitmask) */
95 enum pvr2_ctl_type type;
97 /* Associated V4L control ID, if any */
100 /* Associated driver internal ID, if any */
103 /* Don't implicitly initialize this control's value */
106 /* Starting value for this control */
109 /* Type-specific control information */
111 struct { /* Integer control */
112 long min_value; /* lower limit */
113 long max_value; /* upper limit */
115 struct { /* enumerated control */
116 unsigned int count; /* enum value count */
117 const char **value_names; /* symbol names */
119 struct { /* bitmask control */
120 unsigned int valid_bits; /* bits in use */
121 const char **bit_names; /* symbol name/bit */
127 /* Same as pvr2_ctl_info, but includes storage for the control description */
128 #define PVR2_CTLD_INFO_DESC_SIZE 32
129 struct pvr2_ctld_info {
130 struct pvr2_ctl_info info;
131 char desc[PVR2_CTLD_INFO_DESC_SIZE];
135 const struct pvr2_ctl_info *info;
136 struct pvr2_hdw *hdw;
140 struct pvr2_audio_stat {
142 void (*detach)(void *);
143 int (*status)(void *);
146 struct pvr2_decoder_ctrl {
148 void (*detach)(void *);
149 void (*enable)(void *,int);
150 int (*tuned)(void *);
151 void (*force_reset)(void *);
154 #define PVR2_I2C_PEND_DETECT 0x01 /* Need to detect a client type */
155 #define PVR2_I2C_PEND_CLIENT 0x02 /* Client needs a specific update */
156 #define PVR2_I2C_PEND_REFRESH 0x04 /* Client has specific pending bits */
157 #define PVR2_I2C_PEND_STALE 0x08 /* Broadcast pending bits */
159 #define PVR2_I2C_PEND_ALL (PVR2_I2C_PEND_DETECT |\
160 PVR2_I2C_PEND_CLIENT |\
161 PVR2_I2C_PEND_REFRESH |\
164 /* Disposition of firmware1 loading situation */
165 #define FW1_STATE_UNKNOWN 0
166 #define FW1_STATE_MISSING 1
167 #define FW1_STATE_FAILED 2
168 #define FW1_STATE_RELOAD 3
169 #define FW1_STATE_OK 4
171 /* Known major hardware variants, keyed from device ID */
172 #define PVR2_HDW_TYPE_29XXX 0
173 #define PVR2_HDW_TYPE_24XXX 1
175 typedef int (*pvr2_i2c_func)(struct pvr2_hdw *,u8,u8 *,u16,u8 *, u16);
176 #define PVR2_I2C_FUNC_CNT 128
178 /* This structure contains all state data directly needed to
179 manipulate the hardware (as opposed to complying with a kernel
182 /* Underlying USB device handle */
183 struct usb_device *usb_dev;
184 struct usb_interface *usb_intf;
186 /* Device type, one of PVR2_HDW_TYPE_xxxxx */
187 unsigned int hdw_type;
190 struct pvr2_stream *vid_stream;
192 /* Mutex for all hardware state control */
193 struct mutex big_lock_mutex;
194 int big_lock_held; /* For debugging */
196 void (*poll_trigger_func)(void *);
197 void *poll_trigger_data;
202 struct i2c_adapter i2c_adap;
203 struct i2c_algorithm i2c_algo;
204 pvr2_i2c_func i2c_func[PVR2_I2C_FUNC_CNT];
205 int i2c_cx25840_hack_state;
207 unsigned int i2c_pend_types; /* Which types of update are needed */
208 unsigned long i2c_pend_mask; /* Change bits we need to scan */
209 unsigned long i2c_stale_mask; /* Pending broadcast change bits */
210 unsigned long i2c_active_mask; /* All change bits currently in use */
211 struct list_head i2c_clients;
212 struct mutex i2c_list_lock;
214 /* Frequency table */
215 unsigned int freqTable[FREQTABLE_SIZE];
216 unsigned int freqProgSlot;
218 /* Stuff for handling low level control interaction with device */
219 struct mutex ctl_lock_mutex;
220 int ctl_lock_held; /* For debugging */
221 struct urb *ctl_write_urb;
222 struct urb *ctl_read_urb;
223 unsigned char *ctl_write_buffer;
224 unsigned char *ctl_read_buffer;
225 volatile int ctl_write_pend_flag;
226 volatile int ctl_read_pend_flag;
227 volatile int ctl_timeout_flag;
228 struct completion ctl_done;
229 unsigned char cmd_buffer[PVR2_CTL_BUFFSIZE];
230 int cmd_debug_state; // Low level command debugging info
231 unsigned char cmd_debug_code; //
232 unsigned int cmd_debug_write_len; //
233 unsigned int cmd_debug_read_len; //
235 int flag_ok; // device in known good state
236 int flag_disconnected; // flag_ok == 0 due to disconnect
237 int flag_init_ok; // true if structure is fully initialized
238 int flag_streaming_enabled; // true if streaming should be on
239 int fw1_state; // current situation with fw1
241 int flag_decoder_is_tuned;
243 struct pvr2_decoder_ctrl *decoder_ctrl;
245 // CPU firmware info (used to help find / save firmware data)
247 unsigned int fw_size;
249 // Which subsystem pieces have been enabled / configured
250 unsigned long subsys_enabled_mask;
252 // Which subsystems are manipulated to enable streaming
253 unsigned long subsys_stream_mask;
255 // True if there is a request to trigger logging of state in each
259 /* Tuner / frequency control stuff */
260 unsigned int tuner_type;
262 unsigned int freqValTelevision; /* Current freq for tv mode */
263 unsigned int freqValRadio; /* Current freq for radio mode */
264 unsigned int freqSlotTelevision; /* Current slot for tv mode */
265 unsigned int freqSlotRadio; /* Current slot for radio mode */
266 unsigned int freqSelector; /* 0=radio 1=television */
269 /* Video standard handling */
270 v4l2_std_id std_mask_eeprom; // Hardware supported selections
271 v4l2_std_id std_mask_avail; // Which standards we may select from
272 v4l2_std_id std_mask_cur; // Currently selected standard(s)
273 unsigned int std_enum_cnt; // # of enumerated standards
274 int std_enum_cur; // selected standard enumeration value
275 int std_dirty; // True if std_mask_cur has changed
276 struct pvr2_ctl_info std_info_enum;
277 struct pvr2_ctl_info std_info_avail;
278 struct pvr2_ctl_info std_info_cur;
279 struct v4l2_standard *std_defs;
280 const char **std_enum_names;
282 // Generated string names, one per actual V4L2 standard
283 const char *std_mask_ptrs[32];
284 char std_mask_names[32][10];
286 int unit_number; /* ID for driver instance */
287 unsigned long serial_number; /* ID for hardware itself */
289 /* Minor numbers used by v4l logic (yes, this is a hack, as there
290 should be no v4l junk here). Probably a better way to do this. */
291 int v4l_minor_number_video;
292 int v4l_minor_number_vbi;
293 int v4l_minor_number_radio;
295 /* Location of eeprom or a negative number if none */
298 enum pvr2_config config;
300 /* Information about what audio signal we're hearing */
303 struct pvr2_audio_stat *audio_stat;
305 /* Control state needed for cx2341x module */
306 struct cx2341x_mpeg_params enc_cur_state;
307 struct cx2341x_mpeg_params enc_ctl_state;
308 /* True if an encoder attribute has changed */
310 /* True if enc_cur_state is valid */
314 #define VCREATE_DATA(lab) int lab##_val; int lab##_dirty
315 VCREATE_DATA(brightness);
316 VCREATE_DATA(contrast);
317 VCREATE_DATA(saturation);
319 VCREATE_DATA(volume);
320 VCREATE_DATA(balance);
322 VCREATE_DATA(treble);
325 VCREATE_DATA(audiomode);
326 VCREATE_DATA(res_hor);
327 VCREATE_DATA(res_ver);
329 VCREATE_DATA(automodeswitch);
332 struct pvr2_ctld_info *mpeg_ctrl_info;
334 struct pvr2_ctrl *controls;
335 unsigned int control_cnt;
338 /* This function gets the current frequency */
339 unsigned long pvr2_hdw_get_cur_freq(struct pvr2_hdw *);
341 #endif /* __PVRUSB2_HDW_INTERNAL_H */
344 Stuff for Emacs to see, in order to encourage consistent editing style:
345 *** Local Variables: ***
347 *** fill-column: 75 ***
349 *** c-basic-offset: 8 ***