V4L/DVB (5175): Pvrusb2: VIDIOC_DBG_[S|G]_REGISTER fixups
[safe/jmp/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 /* Called when hardware has been unplugged */
128 void pvr2_hdw_disconnect(struct pvr2_hdw *);
129
130 /* Get the number of defined controls */
131 unsigned int pvr2_hdw_get_ctrl_count(struct pvr2_hdw *);
132
133 /* Retrieve a control handle given its index (0..count-1) */
134 struct pvr2_ctrl *pvr2_hdw_get_ctrl_by_index(struct pvr2_hdw *,unsigned int);
135
136 /* Retrieve a control handle given its internal ID (if any) */
137 struct pvr2_ctrl *pvr2_hdw_get_ctrl_by_id(struct pvr2_hdw *,unsigned int);
138
139 /* Retrieve a control handle given its V4L ID (if any) */
140 struct pvr2_ctrl *pvr2_hdw_get_ctrl_v4l(struct pvr2_hdw *,unsigned int ctl_id);
141
142 /* Retrieve a control handle given its immediate predecessor V4L ID (if any) */
143 struct pvr2_ctrl *pvr2_hdw_get_ctrl_nextv4l(struct pvr2_hdw *,
144                                             unsigned int ctl_id);
145
146 /* Commit all control changes made up to this point */
147 int pvr2_hdw_commit_ctl(struct pvr2_hdw *);
148
149 /* Return name for this driver instance */
150 const char *pvr2_hdw_get_driver_name(struct pvr2_hdw *);
151
152 /* Mark tuner status stale so that it will be re-fetched */
153 void pvr2_hdw_execute_tuner_poll(struct pvr2_hdw *);
154
155 /* Return information about the tuner */
156 int pvr2_hdw_get_tuner_status(struct pvr2_hdw *,struct v4l2_tuner *);
157
158 /* Query device and see if it thinks it is on a high-speed USB link */
159 int pvr2_hdw_is_hsm(struct pvr2_hdw *);
160
161 /* Turn streaming on/off */
162 int pvr2_hdw_set_streaming(struct pvr2_hdw *,int);
163
164 /* Find out if streaming is on */
165 int pvr2_hdw_get_streaming(struct pvr2_hdw *);
166
167 /* Configure the type of stream to generate */
168 int pvr2_hdw_set_stream_type(struct pvr2_hdw *, enum pvr2_config);
169
170 /* Get handle to video output stream */
171 struct pvr2_stream *pvr2_hdw_get_video_stream(struct pvr2_hdw *);
172
173 /* Emit a video standard struct */
174 int pvr2_hdw_get_stdenum_value(struct pvr2_hdw *hdw,struct v4l2_standard *std,
175                                unsigned int idx);
176
177 /* Enable / disable various pieces of hardware.  Items to change are
178    identified by bit positions within msk, and new state for each item is
179    identified by corresponding bit positions within val. */
180 void pvr2_hdw_subsys_bit_chg(struct pvr2_hdw *hdw,
181                              unsigned long msk,unsigned long val);
182
183 /* Retrieve mask indicating which pieces of hardware are currently enabled
184    / configured. */
185 unsigned long pvr2_hdw_subsys_get(struct pvr2_hdw *);
186
187 /* Adjust mask of what get shut down when streaming is stopped.  This is a
188    debugging aid. */
189 void pvr2_hdw_subsys_stream_bit_chg(struct pvr2_hdw *hdw,
190                                     unsigned long msk,unsigned long val);
191
192 /* Retrieve mask indicating which pieces of hardware are disabled when
193    streaming is turned off. */
194 unsigned long pvr2_hdw_subsys_stream_get(struct pvr2_hdw *);
195
196
197 /* Enable / disable retrieval of CPU firmware.  This must be enabled before
198    pvr2_hdw_cpufw_get() will function.  Note that doing this may prevent
199    the device from running (and leaving this mode may imply a device
200    reset). */
201 void pvr2_hdw_cpufw_set_enabled(struct pvr2_hdw *, int enable_flag);
202
203 /* Return true if we're in a mode for retrieval CPU firmware */
204 int pvr2_hdw_cpufw_get_enabled(struct pvr2_hdw *);
205
206 /* Retrieve a piece of the CPU's firmware at the given offset.  Return
207    value is the number of bytes retrieved or zero if we're past the end or
208    an error otherwise (e.g. if firmware retrieval is not enabled). */
209 int pvr2_hdw_cpufw_get(struct pvr2_hdw *,unsigned int offs,
210                        char *buf,unsigned int cnt);
211
212 /* Retrieve a previously stored v4l minor device number */
213 int pvr2_hdw_v4l_get_minor_number(struct pvr2_hdw *,enum pvr2_v4l_type index);
214
215 /* Store a v4l minor device number */
216 void pvr2_hdw_v4l_store_minor_number(struct pvr2_hdw *,
217                                      enum pvr2_v4l_type index,int);
218
219 /* Direct read/write access to chip's registers:
220    chip_id - unique id of chip (e.g. I2C_DRIVERD_xxxx)
221    reg_id  - register number to access
222    setFl   - true to set the register, false to read it
223    val_ptr - storage location for source / result. */
224 int pvr2_hdw_register_access(struct pvr2_hdw *,
225                              u32 chip_id,u64 reg_id,
226                              int setFl,u32 *val_ptr);
227
228 /* The following entry points are all lower level things you normally don't
229    want to worry about. */
230
231 /* Issue a command and get a response from the device.  LOTS of higher
232    level stuff is built on this. */
233 int pvr2_send_request(struct pvr2_hdw *,
234                       void *write_ptr,unsigned int write_len,
235                       void *read_ptr,unsigned int read_len);
236
237 /* Slightly higher level device communication functions. */
238 int pvr2_write_register(struct pvr2_hdw *, u16, u32);
239
240 /* Call if for any reason we can't talk to the hardware anymore - this will
241    cause the driver to stop flailing on the device. */
242 void pvr2_hdw_render_useless(struct pvr2_hdw *);
243
244 /* Set / clear 8051's reset bit */
245 void pvr2_hdw_cpureset_assert(struct pvr2_hdw *,int);
246
247 /* Execute a USB-commanded device reset */
248 void pvr2_hdw_device_reset(struct pvr2_hdw *);
249
250 /* Execute hard reset command (after this point it's likely that the
251    encoder will have to be reconfigured).  This also clears the "useless"
252    state. */
253 int pvr2_hdw_cmd_deep_reset(struct pvr2_hdw *);
254
255 /* Execute simple reset command */
256 int pvr2_hdw_cmd_powerup(struct pvr2_hdw *);
257
258 /* Order decoder to reset */
259 int pvr2_hdw_cmd_decoder_reset(struct pvr2_hdw *);
260
261 /* Direct manipulation of GPIO bits */
262 int pvr2_hdw_gpio_get_dir(struct pvr2_hdw *hdw,u32 *);
263 int pvr2_hdw_gpio_get_out(struct pvr2_hdw *hdw,u32 *);
264 int pvr2_hdw_gpio_get_in(struct pvr2_hdw *hdw,u32 *);
265 int pvr2_hdw_gpio_chg_dir(struct pvr2_hdw *hdw,u32 msk,u32 val);
266 int pvr2_hdw_gpio_chg_out(struct pvr2_hdw *hdw,u32 msk,u32 val);
267
268 /* This data structure is specifically for the next function... */
269 struct pvr2_hdw_debug_info {
270         int big_lock_held;
271         int ctl_lock_held;
272         int flag_ok;
273         int flag_disconnected;
274         int flag_init_ok;
275         int flag_streaming_enabled;
276         unsigned long subsys_flags;
277         int cmd_debug_state;
278         int cmd_debug_write_len;
279         int cmd_debug_read_len;
280         int cmd_debug_write_pend;
281         int cmd_debug_read_pend;
282         int cmd_debug_timeout;
283         int cmd_debug_rstatus;
284         int cmd_debug_wstatus;
285         unsigned char cmd_code;
286 };
287
288 /* Non-intrusively retrieve internal state info - this is useful for
289    diagnosing lockups.  Note that this operation is completed without any
290    kind of locking and so it is not atomic and may yield inconsistent
291    results.  This is *purely* a debugging aid. */
292 void pvr2_hdw_get_debug_info(const struct pvr2_hdw *hdw,
293                              struct pvr2_hdw_debug_info *);
294
295 /* Cause modules to log their state once */
296 void pvr2_hdw_trigger_module_log(struct pvr2_hdw *hdw);
297
298 /* Cause encoder firmware to be uploaded into the device.  This is normally
299    done autonomously, but the interface is exported here because it is also
300    a debugging aid. */
301 int pvr2_upload_firmware2(struct pvr2_hdw *hdw);
302
303 /* List of device types that we can match */
304 extern struct usb_device_id pvr2_device_table[];
305
306 #endif /* __PVRUSB2_HDW_H */
307
308 /*
309   Stuff for Emacs to see, in order to encourage consistent editing style:
310   *** Local Variables: ***
311   *** mode: c ***
312   *** fill-column: 75 ***
313   *** tab-width: 8 ***
314   *** c-basic-offset: 8 ***
315   *** End: ***
316   */