]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - drivers/media/video/pvrusb2/pvrusb2-hdw.h
V4L/DVB (8895): pvrusb2: Fail gracefully if an alien USB ID is used
[mirror_ubuntu-artful-kernel.git] / drivers / media / video / pvrusb2 / pvrusb2-hdw.h
CommitLineData
d855497e
MI
1/*
2 *
d855497e
MI
3 *
4 * Copyright (C) 2005 Mike Isely <isely@pobox.com>
5 *
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
9 *
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.
14 *
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
18 *
19 */
20#ifndef __PVRUSB2_HDW_H
21#define __PVRUSB2_HDW_H
22
23#include <linux/usb.h>
24#include <linux/videodev2.h>
25#include "pvrusb2-io.h"
26#include "pvrusb2-ctrl.h"
27
d855497e
MI
28
29/* Private internal control ids, look these up with
30 pvr2_hdw_get_ctrl_by_id() - these are NOT visible in V4L */
31#define PVR2_CID_STDENUM 1
32#define PVR2_CID_STDCUR 2
33#define PVR2_CID_STDAVAIL 3
34#define PVR2_CID_INPUT 4
35#define PVR2_CID_AUDIOMODE 5
36#define PVR2_CID_FREQUENCY 6
37#define PVR2_CID_HRES 7
38#define PVR2_CID_VRES 8
d855497e
MI
39
40/* Legal values for the INPUT state variable */
41#define PVR2_CVAL_INPUT_TV 0
29bf5b1d 42#define PVR2_CVAL_INPUT_DTV 1
dbc40a0e
MI
43#define PVR2_CVAL_INPUT_COMPOSITE 2
44#define PVR2_CVAL_INPUT_SVIDEO 3
29bf5b1d 45#define PVR2_CVAL_INPUT_RADIO 4
d855497e 46
d855497e 47enum pvr2_config {
16eb40d3
MI
48 pvr2_config_empty, /* No configuration */
49 pvr2_config_mpeg, /* Encoded / compressed video */
50 pvr2_config_vbi, /* Standard vbi info */
51 pvr2_config_pcm, /* Audio raw pcm stream */
52 pvr2_config_rawvideo, /* Video raw frames */
d855497e
MI
53};
54
8079384e
MI
55enum pvr2_v4l_type {
56 pvr2_v4l_type_video,
57 pvr2_v4l_type_vbi,
58 pvr2_v4l_type_radio,
59};
60
681c7399
MI
61/* Major states that we can be in:
62 *
63 * DEAD - Device is in an unusable state and cannot be recovered. This
64 * can happen if we completely lose the ability to communicate with it
65 * (but it might still on the bus). In this state there's nothing we can
66 * do; it must be replugged in order to recover.
67 *
68 * COLD - Device is in an unusuable state, needs microcontroller firmware.
69 *
70 * WARM - We can communicate with the device and the proper
71 * microcontroller firmware is running, but other device initialization is
72 * still needed (e.g. encoder firmware).
73 *
74 * ERROR - A problem prevents capture operation (e.g. encoder firmware
75 * missing).
76 *
77 * READY - Device is operational, but not streaming.
78 *
79 * RUN - Device is streaming.
80 *
81 */
82#define PVR2_STATE_NONE 0
83#define PVR2_STATE_DEAD 1
84#define PVR2_STATE_COLD 2
85#define PVR2_STATE_WARM 3
86#define PVR2_STATE_ERROR 4
87#define PVR2_STATE_READY 5
88#define PVR2_STATE_RUN 6
89
90/* Translate configuration enum to a string label */
d855497e
MI
91const char *pvr2_config_get_name(enum pvr2_config);
92
93struct pvr2_hdw;
94
95/* Create and return a structure for interacting with the underlying
96 hardware */
97struct pvr2_hdw *pvr2_hdw_create(struct usb_interface *intf,
98 const struct usb_device_id *devid);
99
c4a8828d
MI
100/* Perform second stage initialization, passing in a notification callback
101 for when the master state changes. */
794b1607
MI
102int pvr2_hdw_initialize(struct pvr2_hdw *,
103 void (*callback_func)(void *),
104 void *callback_data);
c4a8828d 105
d855497e
MI
106/* Destroy hardware interaction structure */
107void pvr2_hdw_destroy(struct pvr2_hdw *);
108
d855497e
MI
109/* Return true if in the ready (normal) state */
110int pvr2_hdw_dev_ok(struct pvr2_hdw *);
111
112/* Return small integer number [1..N] for logical instance number of this
113 device. This is useful for indexing array-valued module parameters. */
114int pvr2_hdw_get_unit_number(struct pvr2_hdw *);
115
116/* Get pointer to underlying USB device */
117struct usb_device *pvr2_hdw_get_dev(struct pvr2_hdw *);
118
119/* Retrieve serial number of device */
120unsigned long pvr2_hdw_get_sn(struct pvr2_hdw *);
121
31a18547
MI
122/* Retrieve bus location info of device */
123const char *pvr2_hdw_get_bus_info(struct pvr2_hdw *);
124
d855497e
MI
125/* Called when hardware has been unplugged */
126void pvr2_hdw_disconnect(struct pvr2_hdw *);
127
128/* Get the number of defined controls */
129unsigned int pvr2_hdw_get_ctrl_count(struct pvr2_hdw *);
130
131/* Retrieve a control handle given its index (0..count-1) */
132struct pvr2_ctrl *pvr2_hdw_get_ctrl_by_index(struct pvr2_hdw *,unsigned int);
133
134/* Retrieve a control handle given its internal ID (if any) */
135struct pvr2_ctrl *pvr2_hdw_get_ctrl_by_id(struct pvr2_hdw *,unsigned int);
136
137/* Retrieve a control handle given its V4L ID (if any) */
138struct pvr2_ctrl *pvr2_hdw_get_ctrl_v4l(struct pvr2_hdw *,unsigned int ctl_id);
139
a761f431
MI
140/* Retrieve a control handle given its immediate predecessor V4L ID (if any) */
141struct pvr2_ctrl *pvr2_hdw_get_ctrl_nextv4l(struct pvr2_hdw *,
142 unsigned int ctl_id);
143
d855497e
MI
144/* Commit all control changes made up to this point */
145int pvr2_hdw_commit_ctl(struct pvr2_hdw *);
146
7fb20fa3
MI
147/* Return a bit mask of valid input selections for this device. Mask bits
148 * will be according to PVR_CVAL_INPUT_xxxx definitions. */
149unsigned int pvr2_hdw_get_input_available(struct pvr2_hdw *);
150
1cb03b76
MI
151/* Return a bit mask of allowed input selections for this device. Mask bits
152 * will be according to PVR_CVAL_INPUT_xxxx definitions. */
153unsigned int pvr2_hdw_get_input_allowed(struct pvr2_hdw *);
154
155/* Change the set of allowed input selections for this device. Both
156 change_mask and change_valu are mask bits according to
157 PVR_CVAL_INPUT_xxxx definitions. The change_mask parameter indicate
158 which settings are being changed and the change_val parameter indicates
159 whether corresponding settings are being set or cleared. */
160int pvr2_hdw_set_input_allowed(struct pvr2_hdw *,
161 unsigned int change_mask,
162 unsigned int change_val);
163
d855497e
MI
164/* Return name for this driver instance */
165const char *pvr2_hdw_get_driver_name(struct pvr2_hdw *);
166
18103c57
MI
167/* Mark tuner status stale so that it will be re-fetched */
168void pvr2_hdw_execute_tuner_poll(struct pvr2_hdw *);
169
170/* Return information about the tuner */
171int pvr2_hdw_get_tuner_status(struct pvr2_hdw *,struct v4l2_tuner *);
d855497e
MI
172
173/* Query device and see if it thinks it is on a high-speed USB link */
174int pvr2_hdw_is_hsm(struct pvr2_hdw *);
175
78a47101
MI
176/* Return a string token representative of the hardware type */
177const char *pvr2_hdw_get_type(struct pvr2_hdw *);
178
179/* Return a single line description of the hardware type */
180const char *pvr2_hdw_get_desc(struct pvr2_hdw *);
181
d855497e
MI
182/* Turn streaming on/off */
183int pvr2_hdw_set_streaming(struct pvr2_hdw *,int);
184
185/* Find out if streaming is on */
186int pvr2_hdw_get_streaming(struct pvr2_hdw *);
187
681c7399
MI
188/* Retrieve driver overall state */
189int pvr2_hdw_get_state(struct pvr2_hdw *);
190
d855497e
MI
191/* Configure the type of stream to generate */
192int pvr2_hdw_set_stream_type(struct pvr2_hdw *, enum pvr2_config);
193
194/* Get handle to video output stream */
195struct pvr2_stream *pvr2_hdw_get_video_stream(struct pvr2_hdw *);
196
197/* Emit a video standard struct */
198int pvr2_hdw_get_stdenum_value(struct pvr2_hdw *hdw,struct v4l2_standard *std,
199 unsigned int idx);
200
4db666cc
MI
201/* Enable / disable retrieval of CPU firmware or prom contents. This must
202 be enabled before pvr2_hdw_cpufw_get() will function. Note that doing
203 this may prevent the device from running (and leaving this mode may
204 imply a device reset). */
205void pvr2_hdw_cpufw_set_enabled(struct pvr2_hdw *,
206 int prom_flag,
207 int enable_flag);
d855497e
MI
208
209/* Return true if we're in a mode for retrieval CPU firmware */
210int pvr2_hdw_cpufw_get_enabled(struct pvr2_hdw *);
211
212/* Retrieve a piece of the CPU's firmware at the given offset. Return
213 value is the number of bytes retrieved or zero if we're past the end or
214 an error otherwise (e.g. if firmware retrieval is not enabled). */
215int pvr2_hdw_cpufw_get(struct pvr2_hdw *,unsigned int offs,
216 char *buf,unsigned int cnt);
217
2fdf3d9c 218/* Retrieve a previously stored v4l minor device number */
8079384e 219int pvr2_hdw_v4l_get_minor_number(struct pvr2_hdw *,enum pvr2_v4l_type index);
d855497e 220
2fdf3d9c 221/* Store a v4l minor device number */
fd5a75fe 222void pvr2_hdw_v4l_store_minor_number(struct pvr2_hdw *,
8079384e 223 enum pvr2_v4l_type index,int);
d855497e 224
32ffa9ae 225/* Direct read/write access to chip's registers:
f3d092b8
HV
226 match_type - how to interpret match_chip (e.g. driver ID, i2c address)
227 match_chip - chip match value (e.g. I2C_DRIVERD_xxxx)
32ffa9ae
MI
228 reg_id - register number to access
229 setFl - true to set the register, false to read it
230 val_ptr - storage location for source / result. */
231int pvr2_hdw_register_access(struct pvr2_hdw *,
f3d092b8
HV
232 u32 match_type, u32 match_chip,u64 reg_id,
233 int setFl,u64 *val_ptr);
d855497e
MI
234
235/* The following entry points are all lower level things you normally don't
236 want to worry about. */
237
d855497e
MI
238/* Issue a command and get a response from the device. LOTS of higher
239 level stuff is built on this. */
240int pvr2_send_request(struct pvr2_hdw *,
241 void *write_ptr,unsigned int write_len,
242 void *read_ptr,unsigned int read_len);
243
d855497e
MI
244/* Slightly higher level device communication functions. */
245int pvr2_write_register(struct pvr2_hdw *, u16, u32);
d855497e
MI
246
247/* Call if for any reason we can't talk to the hardware anymore - this will
248 cause the driver to stop flailing on the device. */
249void pvr2_hdw_render_useless(struct pvr2_hdw *);
d855497e
MI
250
251/* Set / clear 8051's reset bit */
252void pvr2_hdw_cpureset_assert(struct pvr2_hdw *,int);
253
254/* Execute a USB-commanded device reset */
255void pvr2_hdw_device_reset(struct pvr2_hdw *);
256
681c7399
MI
257/* Reset worker's error trapping circuit breaker */
258int pvr2_hdw_untrip(struct pvr2_hdw *);
259
d855497e
MI
260/* Execute hard reset command (after this point it's likely that the
261 encoder will have to be reconfigured). This also clears the "useless"
262 state. */
263int pvr2_hdw_cmd_deep_reset(struct pvr2_hdw *);
264
265/* Execute simple reset command */
266int pvr2_hdw_cmd_powerup(struct pvr2_hdw *);
267
e1edb19a
MK
268/* suspend */
269int pvr2_hdw_cmd_powerdown(struct pvr2_hdw *);
270
d855497e
MI
271/* Order decoder to reset */
272int pvr2_hdw_cmd_decoder_reset(struct pvr2_hdw *);
273
d855497e
MI
274/* Direct manipulation of GPIO bits */
275int pvr2_hdw_gpio_get_dir(struct pvr2_hdw *hdw,u32 *);
276int pvr2_hdw_gpio_get_out(struct pvr2_hdw *hdw,u32 *);
277int pvr2_hdw_gpio_get_in(struct pvr2_hdw *hdw,u32 *);
278int pvr2_hdw_gpio_chg_dir(struct pvr2_hdw *hdw,u32 msk,u32 val);
279int pvr2_hdw_gpio_chg_out(struct pvr2_hdw *hdw,u32 msk,u32 val);
280
281/* This data structure is specifically for the next function... */
282struct pvr2_hdw_debug_info {
283 int big_lock_held;
284 int ctl_lock_held;
d855497e
MI
285 int flag_disconnected;
286 int flag_init_ok;
681c7399
MI
287 int flag_ok;
288 int fw1_state;
289 int flag_decoder_missed;
290 int flag_tripped;
291 int state_encoder_ok;
292 int state_encoder_run;
293 int state_decoder_run;
294 int state_usbstream_run;
295 int state_decoder_quiescent;
296 int state_pipeline_config;
297 int state_pipeline_req;
298 int state_pipeline_pause;
299 int state_pipeline_idle;
d855497e
MI
300 int cmd_debug_state;
301 int cmd_debug_write_len;
302 int cmd_debug_read_len;
303 int cmd_debug_write_pend;
304 int cmd_debug_read_pend;
305 int cmd_debug_timeout;
306 int cmd_debug_rstatus;
307 int cmd_debug_wstatus;
308 unsigned char cmd_code;
309};
310
311/* Non-intrusively retrieve internal state info - this is useful for
312 diagnosing lockups. Note that this operation is completed without any
313 kind of locking and so it is not atomic and may yield inconsistent
314 results. This is *purely* a debugging aid. */
681c7399
MI
315void pvr2_hdw_get_debug_info_unlocked(const struct pvr2_hdw *hdw,
316 struct pvr2_hdw_debug_info *);
317
318/* Intrusively retrieve internal state info - this is useful for
319 diagnosing overall driver state. This operation synchronizes against
320 the overall driver mutex - so if there are locking problems this will
321 likely hang! This is *purely* a debugging aid. */
322void pvr2_hdw_get_debug_info_locked(struct pvr2_hdw *hdw,
323 struct pvr2_hdw_debug_info *);
324
325/* Report out several lines of text that describes driver internal state.
326 Results are written into the passed-in buffer. */
327unsigned int pvr2_hdw_state_report(struct pvr2_hdw *hdw,
328 char *buf_ptr,unsigned int buf_size);
d855497e
MI
329
330/* Cause modules to log their state once */
331void pvr2_hdw_trigger_module_log(struct pvr2_hdw *hdw);
332
333/* Cause encoder firmware to be uploaded into the device. This is normally
334 done autonomously, but the interface is exported here because it is also
335 a debugging aid. */
336int pvr2_upload_firmware2(struct pvr2_hdw *hdw);
337
d855497e
MI
338#endif /* __PVRUSB2_HDW_H */
339
340/*
341 Stuff for Emacs to see, in order to encourage consistent editing style:
342 *** Local Variables: ***
343 *** mode: c ***
344 *** fill-column: 75 ***
345 *** tab-width: 8 ***
346 *** c-basic-offset: 8 ***
347 *** End: ***
348 */