blob: f873994b088ce3287a7a5b1bfdb4763b0f818fb6 [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
Mike Iselyd8554972006-06-26 20:58:46 -030036#include <linux/videodev2.h>
37#include <linux/i2c.h>
38#include <linux/mutex.h>
39#include "pvrusb2-hdw.h"
40#include "pvrusb2-io.h"
Mike Iselyc05c0462006-06-25 20:04:25 -030041#include <media/cx2341x.h>
Mike Iselyd8554972006-06-26 20:58:46 -030042
Mike Iselyd8554972006-06-26 20:58:46 -030043/* 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
59struct pvr2_decoder;
60
61typedef int (*pvr2_ctlf_is_dirty)(struct pvr2_ctrl *);
62typedef void (*pvr2_ctlf_clear_dirty)(struct pvr2_ctrl *);
Mike Isely5549f542006-12-27 23:28:54 -030063typedef int (*pvr2_ctlf_check_value)(struct pvr2_ctrl *,int);
Mike Iselyd8554972006-06-26 20:58:46 -030064typedef int (*pvr2_ctlf_get_value)(struct pvr2_ctrl *,int *);
65typedef int (*pvr2_ctlf_set_value)(struct pvr2_ctrl *,int msk,int val);
66typedef int (*pvr2_ctlf_val_to_sym)(struct pvr2_ctrl *,int msk,int val,
67 char *,unsigned int,unsigned int *);
68typedef int (*pvr2_ctlf_sym_to_val)(struct pvr2_ctrl *,
69 const char *,unsigned int,
70 int *mskp,int *valp);
Mike Iselya761f432006-06-25 20:04:44 -030071typedef unsigned int (*pvr2_ctlf_get_v4lflags)(struct pvr2_ctrl *);
Mike Iselyd8554972006-06-26 20:58:46 -030072
73/* This structure describes a specific control. A table of these is set up
74 in pvrusb2-hdw.c. */
75struct pvr2_ctl_info {
76 /* Control's name suitable for use as an identifier */
77 const char *name;
78
79 /* Short description of control */
80 const char *desc;
81
82 /* Control's implementation */
83 pvr2_ctlf_get_value get_value; /* Get its value */
Mike Isely89ebd632006-08-08 09:10:07 -030084 pvr2_ctlf_get_value get_min_value; /* Get minimum allowed value */
85 pvr2_ctlf_get_value get_max_value; /* Get maximum allowed value */
Mike Iselyd8554972006-06-26 20:58:46 -030086 pvr2_ctlf_set_value set_value; /* Set its value */
Mike Isely5549f542006-12-27 23:28:54 -030087 pvr2_ctlf_check_value check_value; /* Check that value is valid */
Mike Iselyd8554972006-06-26 20:58:46 -030088 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 */
Mike Iselya761f432006-06-25 20:04:44 -030092 pvr2_ctlf_get_v4lflags get_v4lflags;/* Retrieve v4l flags */
Mike Iselyd8554972006-06-26 20:58:46 -030093
94 /* Control's type (int, enum, bitmask) */
95 enum pvr2_ctl_type type;
96
97 /* Associated V4L control ID, if any */
98 int v4l_id;
99
100 /* Associated driver internal ID, if any */
101 int internal_id;
102
103 /* Don't implicitly initialize this control's value */
104 int skip_init;
105
106 /* Starting value for this control */
107 int default_value;
108
109 /* Type-specific control information */
110 union {
111 struct { /* Integer control */
112 long min_value; /* lower limit */
113 long max_value; /* upper limit */
114 } type_int;
115 struct { /* enumerated control */
116 unsigned int count; /* enum value count */
117 const char **value_names; /* symbol names */
118 } type_enum;
119 struct { /* bitmask control */
120 unsigned int valid_bits; /* bits in use */
121 const char **bit_names; /* symbol name/bit */
122 } type_bitmask;
123 } def;
124};
125
126
Mike Iselyc05c0462006-06-25 20:04:25 -0300127/* Same as pvr2_ctl_info, but includes storage for the control description */
128#define PVR2_CTLD_INFO_DESC_SIZE 32
129struct pvr2_ctld_info {
130 struct pvr2_ctl_info info;
131 char desc[PVR2_CTLD_INFO_DESC_SIZE];
132};
133
Mike Iselyd8554972006-06-26 20:58:46 -0300134struct pvr2_ctrl {
135 const struct pvr2_ctl_info *info;
136 struct pvr2_hdw *hdw;
137};
138
139
Mike Iselyd8554972006-06-26 20:58:46 -0300140struct pvr2_decoder_ctrl {
141 void *ctxt;
142 void (*detach)(void *);
143 void (*enable)(void *,int);
Mike Iselyd8554972006-06-26 20:58:46 -0300144 void (*force_reset)(void *);
145};
146
147#define PVR2_I2C_PEND_DETECT 0x01 /* Need to detect a client type */
148#define PVR2_I2C_PEND_CLIENT 0x02 /* Client needs a specific update */
149#define PVR2_I2C_PEND_REFRESH 0x04 /* Client has specific pending bits */
150#define PVR2_I2C_PEND_STALE 0x08 /* Broadcast pending bits */
151
152#define PVR2_I2C_PEND_ALL (PVR2_I2C_PEND_DETECT |\
153 PVR2_I2C_PEND_CLIENT |\
154 PVR2_I2C_PEND_REFRESH |\
155 PVR2_I2C_PEND_STALE)
156
157/* Disposition of firmware1 loading situation */
158#define FW1_STATE_UNKNOWN 0
159#define FW1_STATE_MISSING 1
160#define FW1_STATE_FAILED 2
161#define FW1_STATE_RELOAD 3
162#define FW1_STATE_OK 4
163
164/* Known major hardware variants, keyed from device ID */
165#define PVR2_HDW_TYPE_29XXX 0
Mike Iselyd8554972006-06-26 20:58:46 -0300166#define PVR2_HDW_TYPE_24XXX 1
Mike Iselyd8554972006-06-26 20:58:46 -0300167
168typedef int (*pvr2_i2c_func)(struct pvr2_hdw *,u8,u8 *,u16,u8 *, u16);
169#define PVR2_I2C_FUNC_CNT 128
170
171/* This structure contains all state data directly needed to
172 manipulate the hardware (as opposed to complying with a kernel
173 interface) */
174struct pvr2_hdw {
175 /* Underlying USB device handle */
176 struct usb_device *usb_dev;
177 struct usb_interface *usb_intf;
178
179 /* Device type, one of PVR2_HDW_TYPE_xxxxx */
180 unsigned int hdw_type;
181
182 /* Video spigot */
183 struct pvr2_stream *vid_stream;
184
185 /* Mutex for all hardware state control */
186 struct mutex big_lock_mutex;
187 int big_lock_held; /* For debugging */
188
189 void (*poll_trigger_func)(void *);
190 void *poll_trigger_data;
191
192 char name[32];
193
194 /* I2C stuff */
195 struct i2c_adapter i2c_adap;
196 struct i2c_algorithm i2c_algo;
197 pvr2_i2c_func i2c_func[PVR2_I2C_FUNC_CNT];
198 int i2c_cx25840_hack_state;
199 int i2c_linked;
200 unsigned int i2c_pend_types; /* Which types of update are needed */
201 unsigned long i2c_pend_mask; /* Change bits we need to scan */
202 unsigned long i2c_stale_mask; /* Pending broadcast change bits */
203 unsigned long i2c_active_mask; /* All change bits currently in use */
204 struct list_head i2c_clients;
205 struct mutex i2c_list_lock;
206
207 /* Frequency table */
208 unsigned int freqTable[FREQTABLE_SIZE];
209 unsigned int freqProgSlot;
Mike Iselyd8554972006-06-26 20:58:46 -0300210
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;
218 volatile int ctl_write_pend_flag;
219 volatile int ctl_read_pend_flag;
220 volatile int ctl_timeout_flag;
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
Mike Isely9a607f02007-10-14 18:18:12 -0300228 int flag_ok; /* device in known good state */
229 int flag_disconnected; /* flag_ok == 0 due to disconnect */
230 int flag_init_ok; /* true if structure is fully initialized */
231 int flag_streaming_enabled; /* true if streaming should be on */
232 int fw1_state; /* current situation with fw1 */
233 int flag_encoder_ok; /* True if encoder is healthy */
Mike Iselyd8554972006-06-26 20:58:46 -0300234
235 int flag_decoder_is_tuned;
236
237 struct pvr2_decoder_ctrl *decoder_ctrl;
238
239 // CPU firmware info (used to help find / save firmware data)
240 char *fw_buffer;
241 unsigned int fw_size;
Mike Isely4db666c2007-09-08 22:16:27 -0300242 int fw_cpu_flag; /* True if we are dealing with the CPU */
Mike Iselyd8554972006-06-26 20:58:46 -0300243
244 // Which subsystem pieces have been enabled / configured
245 unsigned long subsys_enabled_mask;
246
247 // Which subsystems are manipulated to enable streaming
248 unsigned long subsys_stream_mask;
249
250 // True if there is a request to trigger logging of state in each
251 // module.
252 int log_requested;
253
254 /* Tuner / frequency control stuff */
255 unsigned int tuner_type;
256 int tuner_updated;
Mike Isely1bde0282006-12-27 23:30:13 -0300257 unsigned int freqValTelevision; /* Current freq for tv mode */
258 unsigned int freqValRadio; /* Current freq for radio mode */
259 unsigned int freqSlotTelevision; /* Current slot for tv mode */
260 unsigned int freqSlotRadio; /* Current slot for radio mode */
261 unsigned int freqSelector; /* 0=radio 1=television */
Mike Iselyd8554972006-06-26 20:58:46 -0300262 int freqDirty;
263
Mike Isely18103c52007-01-20 00:09:47 -0300264 /* Current tuner info - this information is polled from the I2C bus */
265 struct v4l2_tuner tuner_signal_info;
266 int tuner_signal_stale;
267
Mike Iselyd8554972006-06-26 20:58:46 -0300268 /* Video standard handling */
269 v4l2_std_id std_mask_eeprom; // Hardware supported selections
270 v4l2_std_id std_mask_avail; // Which standards we may select from
271 v4l2_std_id std_mask_cur; // Currently selected standard(s)
272 unsigned int std_enum_cnt; // # of enumerated standards
273 int std_enum_cur; // selected standard enumeration value
274 int std_dirty; // True if std_mask_cur has changed
275 struct pvr2_ctl_info std_info_enum;
276 struct pvr2_ctl_info std_info_avail;
277 struct pvr2_ctl_info std_info_cur;
278 struct v4l2_standard *std_defs;
279 const char **std_enum_names;
280
281 // Generated string names, one per actual V4L2 standard
282 const char *std_mask_ptrs[32];
283 char std_mask_names[32][10];
284
285 int unit_number; /* ID for driver instance */
286 unsigned long serial_number; /* ID for hardware itself */
287
Mike Isely31a18542007-04-08 01:11:47 -0300288 char bus_info[32]; /* Bus location info */
289
Pantelis Koukousoulas2fdf3d92006-12-27 23:07:58 -0300290 /* Minor numbers used by v4l logic (yes, this is a hack, as there
291 should be no v4l junk here). Probably a better way to do this. */
Mike Isely80793842006-12-27 23:12:28 -0300292 int v4l_minor_number_video;
293 int v4l_minor_number_vbi;
Mike Iselyfd5a75f2006-12-27 23:11:22 -0300294 int v4l_minor_number_radio;
Mike Iselyd8554972006-06-26 20:58:46 -0300295
296 /* Location of eeprom or a negative number if none */
297 int eeprom_addr;
298
299 enum pvr2_config config;
300
Mike Iselyb30d2442006-06-25 20:05:01 -0300301 /* Control state needed for cx2341x module */
302 struct cx2341x_mpeg_params enc_cur_state;
303 struct cx2341x_mpeg_params enc_ctl_state;
304 /* True if an encoder attribute has changed */
305 int enc_stale;
306 /* True if enc_cur_state is valid */
307 int enc_cur_valid;
Mike Iselyc05c0462006-06-25 20:04:25 -0300308
Mike Iselyd8554972006-06-26 20:58:46 -0300309 /* Control state */
310#define VCREATE_DATA(lab) int lab##_val; int lab##_dirty
311 VCREATE_DATA(brightness);
312 VCREATE_DATA(contrast);
313 VCREATE_DATA(saturation);
314 VCREATE_DATA(hue);
315 VCREATE_DATA(volume);
316 VCREATE_DATA(balance);
317 VCREATE_DATA(bass);
318 VCREATE_DATA(treble);
319 VCREATE_DATA(mute);
Mike Iselyc05c0462006-06-25 20:04:25 -0300320 VCREATE_DATA(input);
321 VCREATE_DATA(audiomode);
322 VCREATE_DATA(res_hor);
323 VCREATE_DATA(res_ver);
Mike Iselyd8554972006-06-26 20:58:46 -0300324 VCREATE_DATA(srate);
Mike Iselyd8554972006-06-26 20:58:46 -0300325#undef VCREATE_DATA
326
Mike Iselyb30d2442006-06-25 20:05:01 -0300327 struct pvr2_ctld_info *mpeg_ctrl_info;
Mike Iselyc05c0462006-06-25 20:04:25 -0300328
Mike Iselyd8554972006-06-26 20:58:46 -0300329 struct pvr2_ctrl *controls;
Mike Iselyc05c0462006-06-25 20:04:25 -0300330 unsigned int control_cnt;
Mike Iselyd8554972006-06-26 20:58:46 -0300331};
332
Mike Isely1bde0282006-12-27 23:30:13 -0300333/* This function gets the current frequency */
334unsigned long pvr2_hdw_get_cur_freq(struct pvr2_hdw *);
335
Mike Iselyd8554972006-06-26 20:58:46 -0300336#endif /* __PVRUSB2_HDW_INTERNAL_H */
337
338/*
339 Stuff for Emacs to see, in order to encourage consistent editing style:
340 *** Local Variables: ***
341 *** mode: c ***
342 *** fill-column: 75 ***
343 *** tab-width: 8 ***
344 *** c-basic-offset: 8 ***
345 *** End: ***
346 */