]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - drivers/media/usb/pvrusb2/pvrusb2-hdw.h
Merge branches 'for-4.11/upstream-fixes', 'for-4.12/accutouch', 'for-4.12/cp2112...
[mirror_ubuntu-artful-kernel.git] / drivers / media / usb / 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 *
d855497e
MI
15 */
16#ifndef __PVRUSB2_HDW_H
17#define __PVRUSB2_HDW_H
18
19#include <linux/usb.h>
20#include <linux/videodev2.h>
a28fbd04 21#include <media/v4l2-dev.h>
d855497e
MI
22#include "pvrusb2-io.h"
23#include "pvrusb2-ctrl.h"
24
d855497e
MI
25
26/* Private internal control ids, look these up with
27 pvr2_hdw_get_ctrl_by_id() - these are NOT visible in V4L */
d855497e
MI
28#define PVR2_CID_STDCUR 2
29#define PVR2_CID_STDAVAIL 3
30#define PVR2_CID_INPUT 4
31#define PVR2_CID_AUDIOMODE 5
32#define PVR2_CID_FREQUENCY 6
33#define PVR2_CID_HRES 7
34#define PVR2_CID_VRES 8
e784bfb9 35#define PVR2_CID_CROPL 9
36#define PVR2_CID_CROPT 10
37#define PVR2_CID_CROPW 11
38#define PVR2_CID_CROPH 12
432907f7
MI
39#define PVR2_CID_CROPCAPPAN 13
40#define PVR2_CID_CROPCAPPAD 14
41#define PVR2_CID_CROPCAPBL 15
42#define PVR2_CID_CROPCAPBT 16
43#define PVR2_CID_CROPCAPBW 17
44#define PVR2_CID_CROPCAPBH 18
ac04d00e 45#define PVR2_CID_STDDETECT 19
d855497e
MI
46
47/* Legal values for the INPUT state variable */
48#define PVR2_CVAL_INPUT_TV 0
29bf5b1d 49#define PVR2_CVAL_INPUT_DTV 1
dbc40a0e
MI
50#define PVR2_CVAL_INPUT_COMPOSITE 2
51#define PVR2_CVAL_INPUT_SVIDEO 3
29bf5b1d 52#define PVR2_CVAL_INPUT_RADIO 4
d855497e 53
d855497e 54enum pvr2_config {
16eb40d3
MI
55 pvr2_config_empty, /* No configuration */
56 pvr2_config_mpeg, /* Encoded / compressed video */
57 pvr2_config_vbi, /* Standard vbi info */
58 pvr2_config_pcm, /* Audio raw pcm stream */
59 pvr2_config_rawvideo, /* Video raw frames */
d855497e
MI
60};
61
8079384e
MI
62enum pvr2_v4l_type {
63 pvr2_v4l_type_video,
64 pvr2_v4l_type_vbi,
65 pvr2_v4l_type_radio,
66};
67
681c7399
MI
68/* Major states that we can be in:
69 *
70 * DEAD - Device is in an unusable state and cannot be recovered. This
71 * can happen if we completely lose the ability to communicate with it
72 * (but it might still on the bus). In this state there's nothing we can
73 * do; it must be replugged in order to recover.
74 *
25985edc 75 * COLD - Device is in an unusable state, needs microcontroller firmware.
681c7399
MI
76 *
77 * WARM - We can communicate with the device and the proper
78 * microcontroller firmware is running, but other device initialization is
79 * still needed (e.g. encoder firmware).
80 *
81 * ERROR - A problem prevents capture operation (e.g. encoder firmware
82 * missing).
83 *
84 * READY - Device is operational, but not streaming.
85 *
86 * RUN - Device is streaming.
87 *
88 */
89#define PVR2_STATE_NONE 0
90#define PVR2_STATE_DEAD 1
91#define PVR2_STATE_COLD 2
92#define PVR2_STATE_WARM 3
93#define PVR2_STATE_ERROR 4
94#define PVR2_STATE_READY 5
95#define PVR2_STATE_RUN 6
96
97/* Translate configuration enum to a string label */
d855497e
MI
98const char *pvr2_config_get_name(enum pvr2_config);
99
100struct pvr2_hdw;
101
102/* Create and return a structure for interacting with the underlying
103 hardware */
104struct pvr2_hdw *pvr2_hdw_create(struct usb_interface *intf,
105 const struct usb_device_id *devid);
106
c4a8828d
MI
107/* Perform second stage initialization, passing in a notification callback
108 for when the master state changes. */
794b1607
MI
109int pvr2_hdw_initialize(struct pvr2_hdw *,
110 void (*callback_func)(void *),
111 void *callback_data);
c4a8828d 112
d855497e
MI
113/* Destroy hardware interaction structure */
114void pvr2_hdw_destroy(struct pvr2_hdw *);
115
d855497e
MI
116/* Return true if in the ready (normal) state */
117int pvr2_hdw_dev_ok(struct pvr2_hdw *);
118
119/* Return small integer number [1..N] for logical instance number of this
120 device. This is useful for indexing array-valued module parameters. */
121int pvr2_hdw_get_unit_number(struct pvr2_hdw *);
122
123/* Get pointer to underlying USB device */
124struct usb_device *pvr2_hdw_get_dev(struct pvr2_hdw *);
125
126/* Retrieve serial number of device */
127unsigned long pvr2_hdw_get_sn(struct pvr2_hdw *);
128
31a18547
MI
129/* Retrieve bus location info of device */
130const char *pvr2_hdw_get_bus_info(struct pvr2_hdw *);
131
13a88797
MI
132/* Retrieve per-instance string identifier for this specific device */
133const char *pvr2_hdw_get_device_identifier(struct pvr2_hdw *);
134
d855497e
MI
135/* Called when hardware has been unplugged */
136void pvr2_hdw_disconnect(struct pvr2_hdw *);
137
a28fbd04
HV
138/* Sets v4l2_dev of a video_device struct */
139void pvr2_hdw_set_v4l2_dev(struct pvr2_hdw *, struct video_device *);
140
d855497e
MI
141/* Get the number of defined controls */
142unsigned int pvr2_hdw_get_ctrl_count(struct pvr2_hdw *);
143
144/* Retrieve a control handle given its index (0..count-1) */
145struct pvr2_ctrl *pvr2_hdw_get_ctrl_by_index(struct pvr2_hdw *,unsigned int);
146
147/* Retrieve a control handle given its internal ID (if any) */
148struct pvr2_ctrl *pvr2_hdw_get_ctrl_by_id(struct pvr2_hdw *,unsigned int);
149
150/* Retrieve a control handle given its V4L ID (if any) */
151struct pvr2_ctrl *pvr2_hdw_get_ctrl_v4l(struct pvr2_hdw *,unsigned int ctl_id);
152
a761f431
MI
153/* Retrieve a control handle given its immediate predecessor V4L ID (if any) */
154struct pvr2_ctrl *pvr2_hdw_get_ctrl_nextv4l(struct pvr2_hdw *,
155 unsigned int ctl_id);
156
d855497e
MI
157/* Commit all control changes made up to this point */
158int pvr2_hdw_commit_ctl(struct pvr2_hdw *);
159
7fb20fa3
MI
160/* Return a bit mask of valid input selections for this device. Mask bits
161 * will be according to PVR_CVAL_INPUT_xxxx definitions. */
162unsigned int pvr2_hdw_get_input_available(struct pvr2_hdw *);
163
1cb03b76
MI
164/* Return a bit mask of allowed input selections for this device. Mask bits
165 * will be according to PVR_CVAL_INPUT_xxxx definitions. */
166unsigned int pvr2_hdw_get_input_allowed(struct pvr2_hdw *);
167
168/* Change the set of allowed input selections for this device. Both
169 change_mask and change_valu are mask bits according to
170 PVR_CVAL_INPUT_xxxx definitions. The change_mask parameter indicate
171 which settings are being changed and the change_val parameter indicates
172 whether corresponding settings are being set or cleared. */
173int pvr2_hdw_set_input_allowed(struct pvr2_hdw *,
174 unsigned int change_mask,
175 unsigned int change_val);
176
d855497e
MI
177/* Return name for this driver instance */
178const char *pvr2_hdw_get_driver_name(struct pvr2_hdw *);
179
18103c57
MI
180/* Mark tuner status stale so that it will be re-fetched */
181void pvr2_hdw_execute_tuner_poll(struct pvr2_hdw *);
182
183/* Return information about the tuner */
184int pvr2_hdw_get_tuner_status(struct pvr2_hdw *,struct v4l2_tuner *);
d855497e 185
432907f7
MI
186/* Return information about cropping capabilities */
187int pvr2_hdw_get_cropcap(struct pvr2_hdw *, struct v4l2_cropcap *);
188
d855497e
MI
189/* Query device and see if it thinks it is on a high-speed USB link */
190int pvr2_hdw_is_hsm(struct pvr2_hdw *);
191
78a47101
MI
192/* Return a string token representative of the hardware type */
193const char *pvr2_hdw_get_type(struct pvr2_hdw *);
194
195/* Return a single line description of the hardware type */
196const char *pvr2_hdw_get_desc(struct pvr2_hdw *);
197
d855497e
MI
198/* Turn streaming on/off */
199int pvr2_hdw_set_streaming(struct pvr2_hdw *,int);
200
201/* Find out if streaming is on */
202int pvr2_hdw_get_streaming(struct pvr2_hdw *);
203
681c7399
MI
204/* Retrieve driver overall state */
205int pvr2_hdw_get_state(struct pvr2_hdw *);
206
d855497e
MI
207/* Configure the type of stream to generate */
208int pvr2_hdw_set_stream_type(struct pvr2_hdw *, enum pvr2_config);
209
210/* Get handle to video output stream */
211struct pvr2_stream *pvr2_hdw_get_video_stream(struct pvr2_hdw *);
212
4db666cc
MI
213/* Enable / disable retrieval of CPU firmware or prom contents. This must
214 be enabled before pvr2_hdw_cpufw_get() will function. Note that doing
215 this may prevent the device from running (and leaving this mode may
216 imply a device reset). */
217void pvr2_hdw_cpufw_set_enabled(struct pvr2_hdw *,
568efaa2 218 int mode, /* 0=8KB FX2, 1=16KB FX2, 2=PROM */
4db666cc 219 int enable_flag);
d855497e
MI
220
221/* Return true if we're in a mode for retrieval CPU firmware */
222int pvr2_hdw_cpufw_get_enabled(struct pvr2_hdw *);
223
224/* Retrieve a piece of the CPU's firmware at the given offset. Return
225 value is the number of bytes retrieved or zero if we're past the end or
226 an error otherwise (e.g. if firmware retrieval is not enabled). */
227int pvr2_hdw_cpufw_get(struct pvr2_hdw *,unsigned int offs,
228 char *buf,unsigned int cnt);
229
2fdf3d9c 230/* Retrieve a previously stored v4l minor device number */
8079384e 231int pvr2_hdw_v4l_get_minor_number(struct pvr2_hdw *,enum pvr2_v4l_type index);
d855497e 232
2fdf3d9c 233/* Store a v4l minor device number */
fd5a75fe 234void pvr2_hdw_v4l_store_minor_number(struct pvr2_hdw *,
8079384e 235 enum pvr2_v4l_type index,int);
d855497e 236
d855497e
MI
237/* The following entry points are all lower level things you normally don't
238 want to worry about. */
239
d855497e
MI
240/* Issue a command and get a response from the device. LOTS of higher
241 level stuff is built on this. */
242int pvr2_send_request(struct pvr2_hdw *,
243 void *write_ptr,unsigned int write_len,
244 void *read_ptr,unsigned int read_len);
245
d855497e
MI
246/* Slightly higher level device communication functions. */
247int pvr2_write_register(struct pvr2_hdw *, u16, u32);
d855497e
MI
248
249/* Call if for any reason we can't talk to the hardware anymore - this will
250 cause the driver to stop flailing on the device. */
251void pvr2_hdw_render_useless(struct pvr2_hdw *);
d855497e
MI
252
253/* Set / clear 8051's reset bit */
254void pvr2_hdw_cpureset_assert(struct pvr2_hdw *,int);
255
256/* Execute a USB-commanded device reset */
257void pvr2_hdw_device_reset(struct pvr2_hdw *);
258
681c7399
MI
259/* Reset worker's error trapping circuit breaker */
260int pvr2_hdw_untrip(struct pvr2_hdw *);
261
d855497e
MI
262/* Execute hard reset command (after this point it's likely that the
263 encoder will have to be reconfigured). This also clears the "useless"
264 state. */
265int pvr2_hdw_cmd_deep_reset(struct pvr2_hdw *);
266
267/* Execute simple reset command */
268int pvr2_hdw_cmd_powerup(struct pvr2_hdw *);
269
270/* Order decoder to reset */
271int pvr2_hdw_cmd_decoder_reset(struct pvr2_hdw *);
272
d855497e
MI
273/* Direct manipulation of GPIO bits */
274int pvr2_hdw_gpio_get_dir(struct pvr2_hdw *hdw,u32 *);
275int pvr2_hdw_gpio_get_out(struct pvr2_hdw *hdw,u32 *);
276int pvr2_hdw_gpio_get_in(struct pvr2_hdw *hdw,u32 *);
277int pvr2_hdw_gpio_chg_dir(struct pvr2_hdw *hdw,u32 msk,u32 val);
278int pvr2_hdw_gpio_chg_out(struct pvr2_hdw *hdw,u32 msk,u32 val);
279
280/* This data structure is specifically for the next function... */
281struct pvr2_hdw_debug_info {
282 int big_lock_held;
283 int ctl_lock_held;
d855497e
MI
284 int flag_disconnected;
285 int flag_init_ok;
681c7399
MI
286 int flag_ok;
287 int fw1_state;
288 int flag_decoder_missed;
289 int flag_tripped;
290 int state_encoder_ok;
291 int state_encoder_run;
292 int state_decoder_run;
6e931375 293 int state_decoder_ready;
681c7399
MI
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 338#endif /* __PVRUSB2_HDW_H */