blob: 45ddb81475b7eb3f592fa8190c7b154736677b1f [file] [log] [blame]
Mike Iselyd8554972006-06-26 20:58:46 -03001/*
2 *
Mike Iselyd8554972006-06-26 20:58:46 -03003 *
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
Mike Iselyd8554972006-06-26 20:58:46 -030028
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
vdb128@picaros.orge784bfb2008-08-30 18:26:39 -030039#define PVR2_CID_CROPL 9
40#define PVR2_CID_CROPT 10
41#define PVR2_CID_CROPW 11
42#define PVR2_CID_CROPH 12
Mike Isely432907f2008-08-31 21:02:20 -030043#define PVR2_CID_CROPCAPPAN 13
44#define PVR2_CID_CROPCAPPAD 14
45#define PVR2_CID_CROPCAPBL 15
46#define PVR2_CID_CROPCAPBT 16
47#define PVR2_CID_CROPCAPBW 17
48#define PVR2_CID_CROPCAPBH 18
Mike Iselyac04d002012-02-20 02:28:56 -030049#define PVR2_CID_STDDETECT 19
Mike Iselyd8554972006-06-26 20:58:46 -030050
51/* Legal values for the INPUT state variable */
52#define PVR2_CVAL_INPUT_TV 0
Mike Isely29bf5b12008-04-22 14:45:37 -030053#define PVR2_CVAL_INPUT_DTV 1
Mike Iselydbc40a02008-04-22 14:45:39 -030054#define PVR2_CVAL_INPUT_COMPOSITE 2
55#define PVR2_CVAL_INPUT_SVIDEO 3
Mike Isely29bf5b12008-04-22 14:45:37 -030056#define PVR2_CVAL_INPUT_RADIO 4
Mike Iselyd8554972006-06-26 20:58:46 -030057
Mike Iselyd8554972006-06-26 20:58:46 -030058enum pvr2_config {
Mike Isely16eb40d2006-12-30 18:27:32 -030059 pvr2_config_empty, /* No configuration */
60 pvr2_config_mpeg, /* Encoded / compressed video */
61 pvr2_config_vbi, /* Standard vbi info */
62 pvr2_config_pcm, /* Audio raw pcm stream */
63 pvr2_config_rawvideo, /* Video raw frames */
Mike Iselyd8554972006-06-26 20:58:46 -030064};
65
Mike Isely80793842006-12-27 23:12:28 -030066enum pvr2_v4l_type {
67 pvr2_v4l_type_video,
68 pvr2_v4l_type_vbi,
69 pvr2_v4l_type_radio,
70};
71
Mike Isely681c7392007-11-26 01:48:52 -030072/* Major states that we can be in:
73 *
74 * DEAD - Device is in an unusable state and cannot be recovered. This
75 * can happen if we completely lose the ability to communicate with it
76 * (but it might still on the bus). In this state there's nothing we can
77 * do; it must be replugged in order to recover.
78 *
Lucas De Marchi25985ed2011-03-30 22:57:33 -030079 * COLD - Device is in an unusable state, needs microcontroller firmware.
Mike Isely681c7392007-11-26 01:48:52 -030080 *
81 * WARM - We can communicate with the device and the proper
82 * microcontroller firmware is running, but other device initialization is
83 * still needed (e.g. encoder firmware).
84 *
85 * ERROR - A problem prevents capture operation (e.g. encoder firmware
86 * missing).
87 *
88 * READY - Device is operational, but not streaming.
89 *
90 * RUN - Device is streaming.
91 *
92 */
93#define PVR2_STATE_NONE 0
94#define PVR2_STATE_DEAD 1
95#define PVR2_STATE_COLD 2
96#define PVR2_STATE_WARM 3
97#define PVR2_STATE_ERROR 4
98#define PVR2_STATE_READY 5
99#define PVR2_STATE_RUN 6
100
101/* Translate configuration enum to a string label */
Mike Iselyd8554972006-06-26 20:58:46 -0300102const char *pvr2_config_get_name(enum pvr2_config);
103
104struct pvr2_hdw;
105
106/* Create and return a structure for interacting with the underlying
107 hardware */
108struct pvr2_hdw *pvr2_hdw_create(struct usb_interface *intf,
109 const struct usb_device_id *devid);
110
Mike Iselyc4a8828d2008-04-22 14:45:44 -0300111/* Perform second stage initialization, passing in a notification callback
112 for when the master state changes. */
Mike Isely794b1602008-04-22 14:45:45 -0300113int pvr2_hdw_initialize(struct pvr2_hdw *,
114 void (*callback_func)(void *),
115 void *callback_data);
Mike Iselyc4a8828d2008-04-22 14:45:44 -0300116
Mike Iselyd8554972006-06-26 20:58:46 -0300117/* Destroy hardware interaction structure */
118void pvr2_hdw_destroy(struct pvr2_hdw *);
119
Mike Iselyd8554972006-06-26 20:58:46 -0300120/* Return true if in the ready (normal) state */
121int pvr2_hdw_dev_ok(struct pvr2_hdw *);
122
123/* Return small integer number [1..N] for logical instance number of this
124 device. This is useful for indexing array-valued module parameters. */
125int pvr2_hdw_get_unit_number(struct pvr2_hdw *);
126
127/* Get pointer to underlying USB device */
128struct usb_device *pvr2_hdw_get_dev(struct pvr2_hdw *);
129
130/* Retrieve serial number of device */
131unsigned long pvr2_hdw_get_sn(struct pvr2_hdw *);
132
Mike Isely31a18542007-04-08 01:11:47 -0300133/* Retrieve bus location info of device */
134const char *pvr2_hdw_get_bus_info(struct pvr2_hdw *);
135
Mike Isely13a88792009-01-14 04:22:56 -0300136/* Retrieve per-instance string identifier for this specific device */
137const char *pvr2_hdw_get_device_identifier(struct pvr2_hdw *);
138
Mike Iselyd8554972006-06-26 20:58:46 -0300139/* Called when hardware has been unplugged */
140void pvr2_hdw_disconnect(struct pvr2_hdw *);
141
142/* Get the number of defined controls */
143unsigned int pvr2_hdw_get_ctrl_count(struct pvr2_hdw *);
144
145/* Retrieve a control handle given its index (0..count-1) */
146struct pvr2_ctrl *pvr2_hdw_get_ctrl_by_index(struct pvr2_hdw *,unsigned int);
147
148/* Retrieve a control handle given its internal ID (if any) */
149struct pvr2_ctrl *pvr2_hdw_get_ctrl_by_id(struct pvr2_hdw *,unsigned int);
150
151/* Retrieve a control handle given its V4L ID (if any) */
152struct pvr2_ctrl *pvr2_hdw_get_ctrl_v4l(struct pvr2_hdw *,unsigned int ctl_id);
153
Mike Iselya761f432006-06-25 20:04:44 -0300154/* Retrieve a control handle given its immediate predecessor V4L ID (if any) */
155struct pvr2_ctrl *pvr2_hdw_get_ctrl_nextv4l(struct pvr2_hdw *,
156 unsigned int ctl_id);
157
Mike Iselyd8554972006-06-26 20:58:46 -0300158/* Commit all control changes made up to this point */
159int pvr2_hdw_commit_ctl(struct pvr2_hdw *);
160
Mike Isely7fb20fa2008-04-22 14:45:37 -0300161/* Return a bit mask of valid input selections for this device. Mask bits
162 * will be according to PVR_CVAL_INPUT_xxxx definitions. */
163unsigned int pvr2_hdw_get_input_available(struct pvr2_hdw *);
164
Mike Isely1cb03b72008-04-21 03:47:43 -0300165/* Return a bit mask of allowed input selections for this device. Mask bits
166 * will be according to PVR_CVAL_INPUT_xxxx definitions. */
167unsigned int pvr2_hdw_get_input_allowed(struct pvr2_hdw *);
168
169/* Change the set of allowed input selections for this device. Both
170 change_mask and change_valu are mask bits according to
171 PVR_CVAL_INPUT_xxxx definitions. The change_mask parameter indicate
172 which settings are being changed and the change_val parameter indicates
173 whether corresponding settings are being set or cleared. */
174int pvr2_hdw_set_input_allowed(struct pvr2_hdw *,
175 unsigned int change_mask,
176 unsigned int change_val);
177
Mike Iselyd8554972006-06-26 20:58:46 -0300178/* Return name for this driver instance */
179const char *pvr2_hdw_get_driver_name(struct pvr2_hdw *);
180
Mike Isely18103c572007-01-20 00:09:47 -0300181/* Mark tuner status stale so that it will be re-fetched */
182void pvr2_hdw_execute_tuner_poll(struct pvr2_hdw *);
183
184/* Return information about the tuner */
185int pvr2_hdw_get_tuner_status(struct pvr2_hdw *,struct v4l2_tuner *);
Mike Iselyd8554972006-06-26 20:58:46 -0300186
Mike Isely432907f2008-08-31 21:02:20 -0300187/* Return information about cropping capabilities */
188int pvr2_hdw_get_cropcap(struct pvr2_hdw *, struct v4l2_cropcap *);
189
Mike Iselyd8554972006-06-26 20:58:46 -0300190/* Query device and see if it thinks it is on a high-speed USB link */
191int pvr2_hdw_is_hsm(struct pvr2_hdw *);
192
Mike Isely78a47102007-11-26 01:58:20 -0300193/* Return a string token representative of the hardware type */
194const char *pvr2_hdw_get_type(struct pvr2_hdw *);
195
196/* Return a single line description of the hardware type */
197const char *pvr2_hdw_get_desc(struct pvr2_hdw *);
198
Mike Iselyd8554972006-06-26 20:58:46 -0300199/* Turn streaming on/off */
200int pvr2_hdw_set_streaming(struct pvr2_hdw *,int);
201
202/* Find out if streaming is on */
203int pvr2_hdw_get_streaming(struct pvr2_hdw *);
204
Mike Isely681c7392007-11-26 01:48:52 -0300205/* Retrieve driver overall state */
206int pvr2_hdw_get_state(struct pvr2_hdw *);
207
Mike Iselyd8554972006-06-26 20:58:46 -0300208/* Configure the type of stream to generate */
209int pvr2_hdw_set_stream_type(struct pvr2_hdw *, enum pvr2_config);
210
211/* Get handle to video output stream */
212struct pvr2_stream *pvr2_hdw_get_video_stream(struct pvr2_hdw *);
213
214/* Emit a video standard struct */
215int pvr2_hdw_get_stdenum_value(struct pvr2_hdw *hdw,struct v4l2_standard *std,
216 unsigned int idx);
217
Mike Isely4db666c2007-09-08 22:16:27 -0300218/* Enable / disable retrieval of CPU firmware or prom contents. This must
219 be enabled before pvr2_hdw_cpufw_get() will function. Note that doing
220 this may prevent the device from running (and leaving this mode may
221 imply a device reset). */
222void pvr2_hdw_cpufw_set_enabled(struct pvr2_hdw *,
Mike Isely568efaa2009-11-25 02:52:06 -0300223 int mode, /* 0=8KB FX2, 1=16KB FX2, 2=PROM */
Mike Isely4db666c2007-09-08 22:16:27 -0300224 int enable_flag);
Mike Iselyd8554972006-06-26 20:58:46 -0300225
226/* Return true if we're in a mode for retrieval CPU firmware */
227int pvr2_hdw_cpufw_get_enabled(struct pvr2_hdw *);
228
229/* Retrieve a piece of the CPU's firmware at the given offset. Return
230 value is the number of bytes retrieved or zero if we're past the end or
231 an error otherwise (e.g. if firmware retrieval is not enabled). */
232int pvr2_hdw_cpufw_get(struct pvr2_hdw *,unsigned int offs,
233 char *buf,unsigned int cnt);
234
Pantelis Koukousoulas2fdf3d92006-12-27 23:07:58 -0300235/* Retrieve a previously stored v4l minor device number */
Mike Isely80793842006-12-27 23:12:28 -0300236int pvr2_hdw_v4l_get_minor_number(struct pvr2_hdw *,enum pvr2_v4l_type index);
Mike Iselyd8554972006-06-26 20:58:46 -0300237
Pantelis Koukousoulas2fdf3d92006-12-27 23:07:58 -0300238/* Store a v4l minor device number */
Mike Iselyfd5a75f2006-12-27 23:11:22 -0300239void pvr2_hdw_v4l_store_minor_number(struct pvr2_hdw *,
Mike Isely80793842006-12-27 23:12:28 -0300240 enum pvr2_v4l_type index,int);
Mike Iselyd8554972006-06-26 20:58:46 -0300241
Mike Isely32ffa9a2006-09-23 22:26:52 -0300242/* Direct read/write access to chip's registers:
Mike Iselybe4f4ae2009-01-14 04:40:57 -0300243 match - specify criteria to identify target chip (this is a v4l dbg struct)
Mike Isely32ffa9a2006-09-23 22:26:52 -0300244 reg_id - register number to access
245 setFl - true to set the register, false to read it
246 val_ptr - storage location for source / result. */
247int pvr2_hdw_register_access(struct pvr2_hdw *,
Hans Verkuilaecde8b2008-12-30 07:14:19 -0300248 struct v4l2_dbg_match *match, u64 reg_id,
249 int setFl, u64 *val_ptr);
Mike Iselyd8554972006-06-26 20:58:46 -0300250
251/* The following entry points are all lower level things you normally don't
252 want to worry about. */
253
Mike Iselyd8554972006-06-26 20:58:46 -0300254/* Issue a command and get a response from the device. LOTS of higher
255 level stuff is built on this. */
256int pvr2_send_request(struct pvr2_hdw *,
257 void *write_ptr,unsigned int write_len,
258 void *read_ptr,unsigned int read_len);
259
Mike Iselyd8554972006-06-26 20:58:46 -0300260/* Slightly higher level device communication functions. */
261int pvr2_write_register(struct pvr2_hdw *, u16, u32);
Mike Iselyd8554972006-06-26 20:58:46 -0300262
263/* Call if for any reason we can't talk to the hardware anymore - this will
264 cause the driver to stop flailing on the device. */
265void pvr2_hdw_render_useless(struct pvr2_hdw *);
Mike Iselyd8554972006-06-26 20:58:46 -0300266
267/* Set / clear 8051's reset bit */
268void pvr2_hdw_cpureset_assert(struct pvr2_hdw *,int);
269
270/* Execute a USB-commanded device reset */
271void pvr2_hdw_device_reset(struct pvr2_hdw *);
272
Mike Isely681c7392007-11-26 01:48:52 -0300273/* Reset worker's error trapping circuit breaker */
274int pvr2_hdw_untrip(struct pvr2_hdw *);
275
Mike Iselyd8554972006-06-26 20:58:46 -0300276/* Execute hard reset command (after this point it's likely that the
277 encoder will have to be reconfigured). This also clears the "useless"
278 state. */
279int pvr2_hdw_cmd_deep_reset(struct pvr2_hdw *);
280
281/* Execute simple reset command */
282int pvr2_hdw_cmd_powerup(struct pvr2_hdw *);
283
Michael Krufkye1edb192008-04-22 14:45:39 -0300284/* suspend */
285int pvr2_hdw_cmd_powerdown(struct pvr2_hdw *);
286
Mike Iselyd8554972006-06-26 20:58:46 -0300287/* Order decoder to reset */
288int pvr2_hdw_cmd_decoder_reset(struct pvr2_hdw *);
289
Mike Iselyd8554972006-06-26 20:58:46 -0300290/* Direct manipulation of GPIO bits */
291int pvr2_hdw_gpio_get_dir(struct pvr2_hdw *hdw,u32 *);
292int pvr2_hdw_gpio_get_out(struct pvr2_hdw *hdw,u32 *);
293int pvr2_hdw_gpio_get_in(struct pvr2_hdw *hdw,u32 *);
294int pvr2_hdw_gpio_chg_dir(struct pvr2_hdw *hdw,u32 msk,u32 val);
295int pvr2_hdw_gpio_chg_out(struct pvr2_hdw *hdw,u32 msk,u32 val);
296
297/* This data structure is specifically for the next function... */
298struct pvr2_hdw_debug_info {
299 int big_lock_held;
300 int ctl_lock_held;
Mike Iselyd8554972006-06-26 20:58:46 -0300301 int flag_disconnected;
302 int flag_init_ok;
Mike Isely681c7392007-11-26 01:48:52 -0300303 int flag_ok;
304 int fw1_state;
305 int flag_decoder_missed;
306 int flag_tripped;
307 int state_encoder_ok;
308 int state_encoder_run;
309 int state_decoder_run;
Mike Isely6e931372010-02-06 02:10:38 -0300310 int state_decoder_ready;
Mike Isely681c7392007-11-26 01:48:52 -0300311 int state_usbstream_run;
312 int state_decoder_quiescent;
313 int state_pipeline_config;
314 int state_pipeline_req;
315 int state_pipeline_pause;
316 int state_pipeline_idle;
Mike Iselyd8554972006-06-26 20:58:46 -0300317 int cmd_debug_state;
318 int cmd_debug_write_len;
319 int cmd_debug_read_len;
320 int cmd_debug_write_pend;
321 int cmd_debug_read_pend;
322 int cmd_debug_timeout;
323 int cmd_debug_rstatus;
324 int cmd_debug_wstatus;
325 unsigned char cmd_code;
326};
327
328/* Non-intrusively retrieve internal state info - this is useful for
329 diagnosing lockups. Note that this operation is completed without any
330 kind of locking and so it is not atomic and may yield inconsistent
331 results. This is *purely* a debugging aid. */
Mike Isely681c7392007-11-26 01:48:52 -0300332void pvr2_hdw_get_debug_info_unlocked(const struct pvr2_hdw *hdw,
333 struct pvr2_hdw_debug_info *);
334
335/* Intrusively retrieve internal state info - this is useful for
336 diagnosing overall driver state. This operation synchronizes against
337 the overall driver mutex - so if there are locking problems this will
338 likely hang! This is *purely* a debugging aid. */
339void pvr2_hdw_get_debug_info_locked(struct pvr2_hdw *hdw,
340 struct pvr2_hdw_debug_info *);
341
342/* Report out several lines of text that describes driver internal state.
343 Results are written into the passed-in buffer. */
344unsigned int pvr2_hdw_state_report(struct pvr2_hdw *hdw,
345 char *buf_ptr,unsigned int buf_size);
Mike Iselyd8554972006-06-26 20:58:46 -0300346
347/* Cause modules to log their state once */
348void pvr2_hdw_trigger_module_log(struct pvr2_hdw *hdw);
349
350/* Cause encoder firmware to be uploaded into the device. This is normally
351 done autonomously, but the interface is exported here because it is also
352 a debugging aid. */
353int pvr2_upload_firmware2(struct pvr2_hdw *hdw);
354
Mike Iselyd8554972006-06-26 20:58:46 -0300355#endif /* __PVRUSB2_HDW_H */
356
357/*
358 Stuff for Emacs to see, in order to encourage consistent editing style:
359 *** Local Variables: ***
360 *** mode: c ***
361 *** fill-column: 75 ***
362 *** tab-width: 8 ***
363 *** c-basic-offset: 8 ***
364 *** End: ***
365 */