Merge branch 'upstream' of git://ftp.linux-mips.org/pub/scm/upstream-linus
[linux-2.6] / drivers / media / video / pvrusb2 / pvrusb2-hdw.h
1 /*
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_H
22 #define __PVRUSB2_HDW_H
23
24 #include <linux/usb.h>
25 #include <linux/videodev2.h>
26 #include "pvrusb2-io.h"
27 #include "pvrusb2-ctrl.h"
28
29
30 /* Private internal control ids, look these up with
31    pvr2_hdw_get_ctrl_by_id() - these are NOT visible in V4L */
32 #define PVR2_CID_STDENUM 1
33 #define PVR2_CID_STDCUR 2
34 #define PVR2_CID_STDAVAIL 3
35 #define PVR2_CID_INPUT 4
36 #define PVR2_CID_AUDIOMODE 5
37 #define PVR2_CID_FREQUENCY 6
38 #define PVR2_CID_HRES 7
39 #define PVR2_CID_VRES 8
40
41 /* Legal values for the INPUT state variable */
42 #define PVR2_CVAL_INPUT_TV 0
43 #define PVR2_CVAL_INPUT_SVIDEO 1
44 #define PVR2_CVAL_INPUT_COMPOSITE 2
45 #define PVR2_CVAL_INPUT_RADIO 3
46
47 /* Subsystem definitions - these are various pieces that can be
48    independently stopped / started.  Usually you don't want to mess with
49    this directly (let the driver handle things itself), but it is useful
50    for debugging. */
51 #define PVR2_SUBSYS_B_ENC_FIRMWARE        0
52 #define PVR2_SUBSYS_B_ENC_CFG             1
53 #define PVR2_SUBSYS_B_DIGITIZER_RUN       2
54 #define PVR2_SUBSYS_B_USBSTREAM_RUN       3
55 #define PVR2_SUBSYS_B_ENC_RUN             4
56
57 #define PVR2_SUBSYS_CFG_ALL ( \
58         (1 << PVR2_SUBSYS_B_ENC_FIRMWARE) | \
59         (1 << PVR2_SUBSYS_B_ENC_CFG) )
60 #define PVR2_SUBSYS_RUN_ALL ( \
61         (1 << PVR2_SUBSYS_B_DIGITIZER_RUN) | \
62         (1 << PVR2_SUBSYS_B_USBSTREAM_RUN) | \
63         (1 << PVR2_SUBSYS_B_ENC_RUN) )
64 #define PVR2_SUBSYS_ALL ( \
65         PVR2_SUBSYS_CFG_ALL | \
66         PVR2_SUBSYS_RUN_ALL )
67
68 enum pvr2_config {
69         pvr2_config_empty,    /* No configuration */
70         pvr2_config_mpeg,     /* Encoded / compressed video */
71         pvr2_config_vbi,      /* Standard vbi info */
72         pvr2_config_pcm,      /* Audio raw pcm stream */
73         pvr2_config_rawvideo, /* Video raw frames */
74 };
75
76 enum pvr2_v4l_type {
77         pvr2_v4l_type_video,
78         pvr2_v4l_type_vbi,
79         pvr2_v4l_type_radio,
80 };
81
82 const char *pvr2_config_get_name(enum pvr2_config);
83
84 struct pvr2_hdw;
85
86 /* Create and return a structure for interacting with the underlying
87    hardware */
88 struct pvr2_hdw *pvr2_hdw_create(struct usb_interface *intf,
89                                  const struct usb_device_id *devid);
90
91 /* Poll for background activity (if any) */
92 void pvr2_hdw_poll(struct pvr2_hdw *);
93
94 /* Trigger a poll to take place later at a convenient time */
95 void pvr2_hdw_poll_trigger_unlocked(struct pvr2_hdw *);
96
97 /* Register a callback used to trigger a future poll */
98 void pvr2_hdw_setup_poll_trigger(struct pvr2_hdw *,
99                                  void (*func)(void *),
100                                  void *data);
101
102 /* Destroy hardware interaction structure */
103 void pvr2_hdw_destroy(struct pvr2_hdw *);
104
105 /* Set up the structure and attempt to put the device into a usable state.
106    This can be a time-consuming operation, which is why it is not done
107    internally as part of the create() step.  Return value is exactly the
108    same as pvr2_hdw_init_ok(). */
109 int pvr2_hdw_setup(struct pvr2_hdw *);
110
111 /* Initialization succeeded */
112 int pvr2_hdw_init_ok(struct pvr2_hdw *);
113
114 /* Return true if in the ready (normal) state */
115 int pvr2_hdw_dev_ok(struct pvr2_hdw *);
116
117 /* Return small integer number [1..N] for logical instance number of this
118    device.  This is useful for indexing array-valued module parameters. */
119 int pvr2_hdw_get_unit_number(struct pvr2_hdw *);
120
121 /* Get pointer to underlying USB device */
122 struct usb_device *pvr2_hdw_get_dev(struct pvr2_hdw *);
123
124 /* Retrieve serial number of device */
125 unsigned long pvr2_hdw_get_sn(struct pvr2_hdw *);
126
127 /* Retrieve bus location info of device */
128 const char *pvr2_hdw_get_bus_info(struct pvr2_hdw *);
129
130 /* Called when hardware has been unplugged */
131 void pvr2_hdw_disconnect(struct pvr2_hdw *);
132
133 /* Get the number of defined controls */
134 unsigned int pvr2_hdw_get_ctrl_count(struct pvr2_hdw *);
135
136 /* Retrieve a control handle given its index (0..count-1) */
137 struct pvr2_ctrl *pvr2_hdw_get_ctrl_by_index(struct pvr2_hdw *,unsigned int);
138
139 /* Retrieve a control handle given its internal ID (if any) */
140 struct pvr2_ctrl *pvr2_hdw_get_ctrl_by_id(struct pvr2_hdw *,unsigned int);
141
142 /* Retrieve a control handle given its V4L ID (if any) */
143 struct pvr2_ctrl *pvr2_hdw_get_ctrl_v4l(struct pvr2_hdw *,unsigned int ctl_id);
144
145 /* Retrieve a control handle given its immediate predecessor V4L ID (if any) */
146 struct pvr2_ctrl *pvr2_hdw_get_ctrl_nextv4l(struct pvr2_hdw *,
147                                             unsigned int ctl_id);
148
149 /* Commit all control changes made up to this point */
150 int pvr2_hdw_commit_ctl(struct pvr2_hdw *);
151
152 /* Return name for this driver instance */
153 const char *pvr2_hdw_get_driver_name(struct pvr2_hdw *);
154
155 /* Mark tuner status stale so that it will be re-fetched */
156 void pvr2_hdw_execute_tuner_poll(struct pvr2_hdw *);
157
158 /* Return information about the tuner */
159 int pvr2_hdw_get_tuner_status(struct pvr2_hdw *,struct v4l2_tuner *);
160
161 /* Query device and see if it thinks it is on a high-speed USB link */
162 int pvr2_hdw_is_hsm(struct pvr2_hdw *);
163
164 /* Turn streaming on/off */
165 int pvr2_hdw_set_streaming(struct pvr2_hdw *,int);
166
167 /* Find out if streaming is on */
168 int pvr2_hdw_get_streaming(struct pvr2_hdw *);
169
170 /* Configure the type of stream to generate */
171 int pvr2_hdw_set_stream_type(struct pvr2_hdw *, enum pvr2_config);
172
173 /* Get handle to video output stream */
174 struct pvr2_stream *pvr2_hdw_get_video_stream(struct pvr2_hdw *);
175
176 /* Emit a video standard struct */
177 int pvr2_hdw_get_stdenum_value(struct pvr2_hdw *hdw,struct v4l2_standard *std,
178                                unsigned int idx);
179
180 /* Enable / disable various pieces of hardware.  Items to change are
181    identified by bit positions within msk, and new state for each item is
182    identified by corresponding bit positions within val. */
183 void pvr2_hdw_subsys_bit_chg(struct pvr2_hdw *hdw,
184                              unsigned long msk,unsigned long val);
185
186 /* Retrieve mask indicating which pieces of hardware are currently enabled
187    / configured. */
188 unsigned long pvr2_hdw_subsys_get(struct pvr2_hdw *);
189
190 /* Adjust mask of what get shut down when streaming is stopped.  This is a
191    debugging aid. */
192 void pvr2_hdw_subsys_stream_bit_chg(struct pvr2_hdw *hdw,
193                                     unsigned long msk,unsigned long val);
194
195 /* Retrieve mask indicating which pieces of hardware are disabled when
196    streaming is turned off. */
197 unsigned long pvr2_hdw_subsys_stream_get(struct pvr2_hdw *);
198
199
200 /* Enable / disable retrieval of CPU firmware or prom contents.  This must
201    be enabled before pvr2_hdw_cpufw_get() will function.  Note that doing
202    this may prevent the device from running (and leaving this mode may
203    imply a device reset). */
204 void pvr2_hdw_cpufw_set_enabled(struct pvr2_hdw *,
205                                 int prom_flag,
206                                 int enable_flag);
207
208 /* Return true if we're in a mode for retrieval CPU firmware */
209 int pvr2_hdw_cpufw_get_enabled(struct pvr2_hdw *);
210
211 /* Retrieve a piece of the CPU's firmware at the given offset.  Return
212    value is the number of bytes retrieved or zero if we're past the end or
213    an error otherwise (e.g. if firmware retrieval is not enabled). */
214 int pvr2_hdw_cpufw_get(struct pvr2_hdw *,unsigned int offs,
215                        char *buf,unsigned int cnt);
216
217 /* Retrieve a previously stored v4l minor device number */
218 int pvr2_hdw_v4l_get_minor_number(struct pvr2_hdw *,enum pvr2_v4l_type index);
219
220 /* Store a v4l minor device number */
221 void pvr2_hdw_v4l_store_minor_number(struct pvr2_hdw *,
222                                      enum pvr2_v4l_type index,int);
223
224 /* Direct read/write access to chip's registers:
225    match_type - how to interpret match_chip (e.g. driver ID, i2c address)
226    match_chip - chip match value (e.g. I2C_DRIVERD_xxxx)
227    reg_id  - register number to access
228    setFl   - true to set the register, false to read it
229    val_ptr - storage location for source / result. */
230 int pvr2_hdw_register_access(struct pvr2_hdw *,
231                              u32 match_type, u32 match_chip,u64 reg_id,
232                              int setFl,u64 *val_ptr);
233
234 /* The following entry points are all lower level things you normally don't
235    want to worry about. */
236
237 /* Issue a command and get a response from the device.  LOTS of higher
238    level stuff is built on this. */
239 int pvr2_send_request(struct pvr2_hdw *,
240                       void *write_ptr,unsigned int write_len,
241                       void *read_ptr,unsigned int read_len);
242
243 /* Slightly higher level device communication functions. */
244 int pvr2_write_register(struct pvr2_hdw *, u16, u32);
245
246 /* Call if for any reason we can't talk to the hardware anymore - this will
247    cause the driver to stop flailing on the device. */
248 void pvr2_hdw_render_useless(struct pvr2_hdw *);
249
250 /* Set / clear 8051's reset bit */
251 void pvr2_hdw_cpureset_assert(struct pvr2_hdw *,int);
252
253 /* Execute a USB-commanded device reset */
254 void pvr2_hdw_device_reset(struct pvr2_hdw *);
255
256 /* Execute hard reset command (after this point it's likely that the
257    encoder will have to be reconfigured).  This also clears the "useless"
258    state. */
259 int pvr2_hdw_cmd_deep_reset(struct pvr2_hdw *);
260
261 /* Execute simple reset command */
262 int pvr2_hdw_cmd_powerup(struct pvr2_hdw *);
263
264 /* Order decoder to reset */
265 int pvr2_hdw_cmd_decoder_reset(struct pvr2_hdw *);
266
267 /* Direct manipulation of GPIO bits */
268 int pvr2_hdw_gpio_get_dir(struct pvr2_hdw *hdw,u32 *);
269 int pvr2_hdw_gpio_get_out(struct pvr2_hdw *hdw,u32 *);
270 int pvr2_hdw_gpio_get_in(struct pvr2_hdw *hdw,u32 *);
271 int pvr2_hdw_gpio_chg_dir(struct pvr2_hdw *hdw,u32 msk,u32 val);
272 int pvr2_hdw_gpio_chg_out(struct pvr2_hdw *hdw,u32 msk,u32 val);
273
274 /* This data structure is specifically for the next function... */
275 struct pvr2_hdw_debug_info {
276         int big_lock_held;
277         int ctl_lock_held;
278         int flag_ok;
279         int flag_disconnected;
280         int flag_init_ok;
281         int flag_streaming_enabled;
282         unsigned long subsys_flags;
283         int cmd_debug_state;
284         int cmd_debug_write_len;
285         int cmd_debug_read_len;
286         int cmd_debug_write_pend;
287         int cmd_debug_read_pend;
288         int cmd_debug_timeout;
289         int cmd_debug_rstatus;
290         int cmd_debug_wstatus;
291         unsigned char cmd_code;
292 };
293
294 /* Non-intrusively retrieve internal state info - this is useful for
295    diagnosing lockups.  Note that this operation is completed without any
296    kind of locking and so it is not atomic and may yield inconsistent
297    results.  This is *purely* a debugging aid. */
298 void pvr2_hdw_get_debug_info(const struct pvr2_hdw *hdw,
299                              struct pvr2_hdw_debug_info *);
300
301 /* Cause modules to log their state once */
302 void pvr2_hdw_trigger_module_log(struct pvr2_hdw *hdw);
303
304 /* Cause encoder firmware to be uploaded into the device.  This is normally
305    done autonomously, but the interface is exported here because it is also
306    a debugging aid. */
307 int pvr2_upload_firmware2(struct pvr2_hdw *hdw);
308
309 /* List of device types that we can match */
310 extern struct usb_device_id pvr2_device_table[];
311
312 #endif /* __PVRUSB2_HDW_H */
313
314 /*
315   Stuff for Emacs to see, in order to encourage consistent editing style:
316   *** Local Variables: ***
317   *** mode: c ***
318   *** fill-column: 75 ***
319   *** tab-width: 8 ***
320   *** c-basic-offset: 8 ***
321   *** End: ***
322   */