]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - drivers/media/video/pvrusb2/pvrusb2-hdw.h
V4L/DVB (7296): pvrusb2: Define device attributes for all input modes
[mirror_ubuntu-artful-kernel.git] / drivers / media / video / pvrusb2 / pvrusb2-hdw.h
CommitLineData
d855497e
MI
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
d855497e
MI
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
d855497e
MI
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
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
681c7399
MI
93/* Translate a master state enum to a string label */
94const char *pvr2_hdw_get_state_name(unsigned int);
95
d855497e
MI
96struct pvr2_hdw;
97
98/* Create and return a structure for interacting with the underlying
99 hardware */
100struct pvr2_hdw *pvr2_hdw_create(struct usb_interface *intf,
101 const struct usb_device_id *devid);
102
d855497e
MI
103/* Destroy hardware interaction structure */
104void pvr2_hdw_destroy(struct pvr2_hdw *);
105
681c7399
MI
106/* Register a function to be called whenever the master state changes. */
107void pvr2_hdw_set_state_callback(struct pvr2_hdw *,
108 void (*callback_func)(void *),
109 void *callback_data);
d855497e
MI
110
111/* Return true if in the ready (normal) state */
112int pvr2_hdw_dev_ok(struct pvr2_hdw *);
113
114/* Return small integer number [1..N] for logical instance number of this
115 device. This is useful for indexing array-valued module parameters. */
116int pvr2_hdw_get_unit_number(struct pvr2_hdw *);
117
118/* Get pointer to underlying USB device */
119struct usb_device *pvr2_hdw_get_dev(struct pvr2_hdw *);
120
121/* Retrieve serial number of device */
122unsigned long pvr2_hdw_get_sn(struct pvr2_hdw *);
123
31a18547
MI
124/* Retrieve bus location info of device */
125const char *pvr2_hdw_get_bus_info(struct pvr2_hdw *);
126
d855497e
MI
127/* Called when hardware has been unplugged */
128void pvr2_hdw_disconnect(struct pvr2_hdw *);
129
130/* Get the number of defined controls */
131unsigned int pvr2_hdw_get_ctrl_count(struct pvr2_hdw *);
132
133/* Retrieve a control handle given its index (0..count-1) */
134struct 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) */
137struct 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) */
140struct pvr2_ctrl *pvr2_hdw_get_ctrl_v4l(struct pvr2_hdw *,unsigned int ctl_id);
141
a761f431
MI
142/* Retrieve a control handle given its immediate predecessor V4L ID (if any) */
143struct pvr2_ctrl *pvr2_hdw_get_ctrl_nextv4l(struct pvr2_hdw *,
144 unsigned int ctl_id);
145
d855497e
MI
146/* Commit all control changes made up to this point */
147int pvr2_hdw_commit_ctl(struct pvr2_hdw *);
148
149/* Return name for this driver instance */
150const char *pvr2_hdw_get_driver_name(struct pvr2_hdw *);
151
18103c57
MI
152/* Mark tuner status stale so that it will be re-fetched */
153void pvr2_hdw_execute_tuner_poll(struct pvr2_hdw *);
154
155/* Return information about the tuner */
156int pvr2_hdw_get_tuner_status(struct pvr2_hdw *,struct v4l2_tuner *);
d855497e
MI
157
158/* Query device and see if it thinks it is on a high-speed USB link */
159int pvr2_hdw_is_hsm(struct pvr2_hdw *);
160
78a47101
MI
161/* Return a string token representative of the hardware type */
162const char *pvr2_hdw_get_type(struct pvr2_hdw *);
163
164/* Return a single line description of the hardware type */
165const char *pvr2_hdw_get_desc(struct pvr2_hdw *);
166
d855497e
MI
167/* Turn streaming on/off */
168int pvr2_hdw_set_streaming(struct pvr2_hdw *,int);
169
170/* Find out if streaming is on */
171int pvr2_hdw_get_streaming(struct pvr2_hdw *);
172
681c7399
MI
173/* Retrieve driver overall state */
174int pvr2_hdw_get_state(struct pvr2_hdw *);
175
d855497e
MI
176/* Configure the type of stream to generate */
177int pvr2_hdw_set_stream_type(struct pvr2_hdw *, enum pvr2_config);
178
179/* Get handle to video output stream */
180struct pvr2_stream *pvr2_hdw_get_video_stream(struct pvr2_hdw *);
181
182/* Emit a video standard struct */
183int pvr2_hdw_get_stdenum_value(struct pvr2_hdw *hdw,struct v4l2_standard *std,
184 unsigned int idx);
185
4db666cc
MI
186/* Enable / disable retrieval of CPU firmware or prom contents. This must
187 be enabled before pvr2_hdw_cpufw_get() will function. Note that doing
188 this may prevent the device from running (and leaving this mode may
189 imply a device reset). */
190void pvr2_hdw_cpufw_set_enabled(struct pvr2_hdw *,
191 int prom_flag,
192 int enable_flag);
d855497e
MI
193
194/* Return true if we're in a mode for retrieval CPU firmware */
195int pvr2_hdw_cpufw_get_enabled(struct pvr2_hdw *);
196
197/* Retrieve a piece of the CPU's firmware at the given offset. Return
198 value is the number of bytes retrieved or zero if we're past the end or
199 an error otherwise (e.g. if firmware retrieval is not enabled). */
200int pvr2_hdw_cpufw_get(struct pvr2_hdw *,unsigned int offs,
201 char *buf,unsigned int cnt);
202
2fdf3d9c 203/* Retrieve a previously stored v4l minor device number */
8079384e 204int pvr2_hdw_v4l_get_minor_number(struct pvr2_hdw *,enum pvr2_v4l_type index);
d855497e 205
2fdf3d9c 206/* Store a v4l minor device number */
fd5a75fe 207void pvr2_hdw_v4l_store_minor_number(struct pvr2_hdw *,
8079384e 208 enum pvr2_v4l_type index,int);
d855497e 209
32ffa9ae 210/* Direct read/write access to chip's registers:
f3d092b8
HV
211 match_type - how to interpret match_chip (e.g. driver ID, i2c address)
212 match_chip - chip match value (e.g. I2C_DRIVERD_xxxx)
32ffa9ae
MI
213 reg_id - register number to access
214 setFl - true to set the register, false to read it
215 val_ptr - storage location for source / result. */
216int pvr2_hdw_register_access(struct pvr2_hdw *,
f3d092b8
HV
217 u32 match_type, u32 match_chip,u64 reg_id,
218 int setFl,u64 *val_ptr);
d855497e
MI
219
220/* The following entry points are all lower level things you normally don't
221 want to worry about. */
222
d855497e
MI
223/* Issue a command and get a response from the device. LOTS of higher
224 level stuff is built on this. */
225int pvr2_send_request(struct pvr2_hdw *,
226 void *write_ptr,unsigned int write_len,
227 void *read_ptr,unsigned int read_len);
228
d855497e
MI
229/* Slightly higher level device communication functions. */
230int pvr2_write_register(struct pvr2_hdw *, u16, u32);
d855497e
MI
231
232/* Call if for any reason we can't talk to the hardware anymore - this will
233 cause the driver to stop flailing on the device. */
234void pvr2_hdw_render_useless(struct pvr2_hdw *);
d855497e
MI
235
236/* Set / clear 8051's reset bit */
237void pvr2_hdw_cpureset_assert(struct pvr2_hdw *,int);
238
239/* Execute a USB-commanded device reset */
240void pvr2_hdw_device_reset(struct pvr2_hdw *);
241
681c7399
MI
242/* Reset worker's error trapping circuit breaker */
243int pvr2_hdw_untrip(struct pvr2_hdw *);
244
d855497e
MI
245/* Execute hard reset command (after this point it's likely that the
246 encoder will have to be reconfigured). This also clears the "useless"
247 state. */
248int pvr2_hdw_cmd_deep_reset(struct pvr2_hdw *);
249
250/* Execute simple reset command */
251int pvr2_hdw_cmd_powerup(struct pvr2_hdw *);
252
253/* Order decoder to reset */
254int pvr2_hdw_cmd_decoder_reset(struct pvr2_hdw *);
255
d855497e
MI
256/* Direct manipulation of GPIO bits */
257int pvr2_hdw_gpio_get_dir(struct pvr2_hdw *hdw,u32 *);
258int pvr2_hdw_gpio_get_out(struct pvr2_hdw *hdw,u32 *);
259int pvr2_hdw_gpio_get_in(struct pvr2_hdw *hdw,u32 *);
260int pvr2_hdw_gpio_chg_dir(struct pvr2_hdw *hdw,u32 msk,u32 val);
261int pvr2_hdw_gpio_chg_out(struct pvr2_hdw *hdw,u32 msk,u32 val);
262
263/* This data structure is specifically for the next function... */
264struct pvr2_hdw_debug_info {
265 int big_lock_held;
266 int ctl_lock_held;
d855497e
MI
267 int flag_disconnected;
268 int flag_init_ok;
681c7399
MI
269 int flag_ok;
270 int fw1_state;
271 int flag_decoder_missed;
272 int flag_tripped;
273 int state_encoder_ok;
274 int state_encoder_run;
275 int state_decoder_run;
276 int state_usbstream_run;
277 int state_decoder_quiescent;
278 int state_pipeline_config;
279 int state_pipeline_req;
280 int state_pipeline_pause;
281 int state_pipeline_idle;
d855497e
MI
282 int cmd_debug_state;
283 int cmd_debug_write_len;
284 int cmd_debug_read_len;
285 int cmd_debug_write_pend;
286 int cmd_debug_read_pend;
287 int cmd_debug_timeout;
288 int cmd_debug_rstatus;
289 int cmd_debug_wstatus;
290 unsigned char cmd_code;
291};
292
293/* Non-intrusively retrieve internal state info - this is useful for
294 diagnosing lockups. Note that this operation is completed without any
295 kind of locking and so it is not atomic and may yield inconsistent
296 results. This is *purely* a debugging aid. */
681c7399
MI
297void pvr2_hdw_get_debug_info_unlocked(const struct pvr2_hdw *hdw,
298 struct pvr2_hdw_debug_info *);
299
300/* Intrusively retrieve internal state info - this is useful for
301 diagnosing overall driver state. This operation synchronizes against
302 the overall driver mutex - so if there are locking problems this will
303 likely hang! This is *purely* a debugging aid. */
304void pvr2_hdw_get_debug_info_locked(struct pvr2_hdw *hdw,
305 struct pvr2_hdw_debug_info *);
306
307/* Report out several lines of text that describes driver internal state.
308 Results are written into the passed-in buffer. */
309unsigned int pvr2_hdw_state_report(struct pvr2_hdw *hdw,
310 char *buf_ptr,unsigned int buf_size);
d855497e
MI
311
312/* Cause modules to log their state once */
313void pvr2_hdw_trigger_module_log(struct pvr2_hdw *hdw);
314
315/* Cause encoder firmware to be uploaded into the device. This is normally
316 done autonomously, but the interface is exported here because it is also
317 a debugging aid. */
318int pvr2_upload_firmware2(struct pvr2_hdw *hdw);
319
d855497e
MI
320#endif /* __PVRUSB2_HDW_H */
321
322/*
323 Stuff for Emacs to see, in order to encourage consistent editing style:
324 *** Local Variables: ***
325 *** mode: c ***
326 *** fill-column: 75 ***
327 *** tab-width: 8 ***
328 *** c-basic-offset: 8 ***
329 *** End: ***
330 */