blob: 20295e0c19954efe6e3784a781aa0c6c445551ac [file] [log] [blame]
Mike Iselyd8554972006-06-26 20:58:46 -03001/*
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
Mike Iselyd8554972006-06-26 20:58:46 -030029
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
Mike Iselyd8554972006-06-26 20:58:46 -030040
41/* Legal values for the INPUT state variable */
42#define PVR2_CVAL_INPUT_TV 0
Mike Isely29bf5b12008-04-22 14:45:37 -030043#define PVR2_CVAL_INPUT_DTV 1
Mike Iselydbc40a02008-04-22 14:45:39 -030044#define PVR2_CVAL_INPUT_COMPOSITE 2
45#define PVR2_CVAL_INPUT_SVIDEO 3
Mike Isely29bf5b12008-04-22 14:45:37 -030046#define PVR2_CVAL_INPUT_RADIO 4
Mike Iselyd8554972006-06-26 20:58:46 -030047
Mike Iselyd8554972006-06-26 20:58:46 -030048enum pvr2_config {
Mike Isely16eb40d2006-12-30 18:27:32 -030049 pvr2_config_empty, /* No configuration */
50 pvr2_config_mpeg, /* Encoded / compressed video */
51 pvr2_config_vbi, /* Standard vbi info */
52 pvr2_config_pcm, /* Audio raw pcm stream */
53 pvr2_config_rawvideo, /* Video raw frames */
Mike Iselyd8554972006-06-26 20:58:46 -030054};
55
Mike Isely80793842006-12-27 23:12:28 -030056enum pvr2_v4l_type {
57 pvr2_v4l_type_video,
58 pvr2_v4l_type_vbi,
59 pvr2_v4l_type_radio,
60};
61
Mike Isely681c7392007-11-26 01:48:52 -030062/* Major states that we can be in:
63 *
64 * DEAD - Device is in an unusable state and cannot be recovered. This
65 * can happen if we completely lose the ability to communicate with it
66 * (but it might still on the bus). In this state there's nothing we can
67 * do; it must be replugged in order to recover.
68 *
69 * COLD - Device is in an unusuable state, needs microcontroller firmware.
70 *
71 * WARM - We can communicate with the device and the proper
72 * microcontroller firmware is running, but other device initialization is
73 * still needed (e.g. encoder firmware).
74 *
75 * ERROR - A problem prevents capture operation (e.g. encoder firmware
76 * missing).
77 *
78 * READY - Device is operational, but not streaming.
79 *
80 * RUN - Device is streaming.
81 *
82 */
83#define PVR2_STATE_NONE 0
84#define PVR2_STATE_DEAD 1
85#define PVR2_STATE_COLD 2
86#define PVR2_STATE_WARM 3
87#define PVR2_STATE_ERROR 4
88#define PVR2_STATE_READY 5
89#define PVR2_STATE_RUN 6
90
91/* Translate configuration enum to a string label */
Mike Iselyd8554972006-06-26 20:58:46 -030092const char *pvr2_config_get_name(enum pvr2_config);
93
94struct pvr2_hdw;
95
96/* Create and return a structure for interacting with the underlying
97 hardware */
98struct pvr2_hdw *pvr2_hdw_create(struct usb_interface *intf,
99 const struct usb_device_id *devid);
100
Mike Iselyc4a8828d2008-04-22 14:45:44 -0300101/* Perform second stage initialization, passing in a notification callback
102 for when the master state changes. */
Mike Isely794b1602008-04-22 14:45:45 -0300103int pvr2_hdw_initialize(struct pvr2_hdw *,
104 void (*callback_func)(void *),
105 void *callback_data);
Mike Iselyc4a8828d2008-04-22 14:45:44 -0300106
Mike Iselyd8554972006-06-26 20:58:46 -0300107/* Destroy hardware interaction structure */
108void pvr2_hdw_destroy(struct pvr2_hdw *);
109
Mike Iselyd8554972006-06-26 20:58:46 -0300110/* Return true if in the ready (normal) state */
111int pvr2_hdw_dev_ok(struct pvr2_hdw *);
112
113/* Return small integer number [1..N] for logical instance number of this
114 device. This is useful for indexing array-valued module parameters. */
115int pvr2_hdw_get_unit_number(struct pvr2_hdw *);
116
117/* Get pointer to underlying USB device */
118struct usb_device *pvr2_hdw_get_dev(struct pvr2_hdw *);
119
120/* Retrieve serial number of device */
121unsigned long pvr2_hdw_get_sn(struct pvr2_hdw *);
122
Mike Isely31a18542007-04-08 01:11:47 -0300123/* Retrieve bus location info of device */
124const char *pvr2_hdw_get_bus_info(struct pvr2_hdw *);
125
Mike Iselyd8554972006-06-26 20:58:46 -0300126/* Called when hardware has been unplugged */
127void pvr2_hdw_disconnect(struct pvr2_hdw *);
128
129/* Get the number of defined controls */
130unsigned int pvr2_hdw_get_ctrl_count(struct pvr2_hdw *);
131
132/* Retrieve a control handle given its index (0..count-1) */
133struct pvr2_ctrl *pvr2_hdw_get_ctrl_by_index(struct pvr2_hdw *,unsigned int);
134
135/* Retrieve a control handle given its internal ID (if any) */
136struct pvr2_ctrl *pvr2_hdw_get_ctrl_by_id(struct pvr2_hdw *,unsigned int);
137
138/* Retrieve a control handle given its V4L ID (if any) */
139struct pvr2_ctrl *pvr2_hdw_get_ctrl_v4l(struct pvr2_hdw *,unsigned int ctl_id);
140
Mike Iselya761f432006-06-25 20:04:44 -0300141/* Retrieve a control handle given its immediate predecessor V4L ID (if any) */
142struct pvr2_ctrl *pvr2_hdw_get_ctrl_nextv4l(struct pvr2_hdw *,
143 unsigned int ctl_id);
144
Mike Iselyd8554972006-06-26 20:58:46 -0300145/* Commit all control changes made up to this point */
146int pvr2_hdw_commit_ctl(struct pvr2_hdw *);
147
Mike Isely7fb20fa2008-04-22 14:45:37 -0300148/* Return a bit mask of valid input selections for this device. Mask bits
149 * will be according to PVR_CVAL_INPUT_xxxx definitions. */
150unsigned int pvr2_hdw_get_input_available(struct pvr2_hdw *);
151
Mike Isely1cb03b72008-04-21 03:47:43 -0300152/* Return a bit mask of allowed input selections for this device. Mask bits
153 * will be according to PVR_CVAL_INPUT_xxxx definitions. */
154unsigned int pvr2_hdw_get_input_allowed(struct pvr2_hdw *);
155
156/* Change the set of allowed input selections for this device. Both
157 change_mask and change_valu are mask bits according to
158 PVR_CVAL_INPUT_xxxx definitions. The change_mask parameter indicate
159 which settings are being changed and the change_val parameter indicates
160 whether corresponding settings are being set or cleared. */
161int pvr2_hdw_set_input_allowed(struct pvr2_hdw *,
162 unsigned int change_mask,
163 unsigned int change_val);
164
Mike Iselyd8554972006-06-26 20:58:46 -0300165/* Return name for this driver instance */
166const char *pvr2_hdw_get_driver_name(struct pvr2_hdw *);
167
Mike Isely18103c572007-01-20 00:09:47 -0300168/* Mark tuner status stale so that it will be re-fetched */
169void pvr2_hdw_execute_tuner_poll(struct pvr2_hdw *);
170
171/* Return information about the tuner */
172int pvr2_hdw_get_tuner_status(struct pvr2_hdw *,struct v4l2_tuner *);
Mike Iselyd8554972006-06-26 20:58:46 -0300173
174/* Query device and see if it thinks it is on a high-speed USB link */
175int pvr2_hdw_is_hsm(struct pvr2_hdw *);
176
Mike Isely78a47102007-11-26 01:58:20 -0300177/* Return a string token representative of the hardware type */
178const char *pvr2_hdw_get_type(struct pvr2_hdw *);
179
180/* Return a single line description of the hardware type */
181const char *pvr2_hdw_get_desc(struct pvr2_hdw *);
182
Mike Iselyd8554972006-06-26 20:58:46 -0300183/* Turn streaming on/off */
184int pvr2_hdw_set_streaming(struct pvr2_hdw *,int);
185
186/* Find out if streaming is on */
187int pvr2_hdw_get_streaming(struct pvr2_hdw *);
188
Mike Isely681c7392007-11-26 01:48:52 -0300189/* Retrieve driver overall state */
190int pvr2_hdw_get_state(struct pvr2_hdw *);
191
Mike Iselyd8554972006-06-26 20:58:46 -0300192/* Configure the type of stream to generate */
193int pvr2_hdw_set_stream_type(struct pvr2_hdw *, enum pvr2_config);
194
195/* Get handle to video output stream */
196struct pvr2_stream *pvr2_hdw_get_video_stream(struct pvr2_hdw *);
197
198/* Emit a video standard struct */
199int pvr2_hdw_get_stdenum_value(struct pvr2_hdw *hdw,struct v4l2_standard *std,
200 unsigned int idx);
201
Mike Isely4db666c2007-09-08 22:16:27 -0300202/* Enable / disable retrieval of CPU firmware or prom contents. This must
203 be enabled before pvr2_hdw_cpufw_get() will function. Note that doing
204 this may prevent the device from running (and leaving this mode may
205 imply a device reset). */
206void pvr2_hdw_cpufw_set_enabled(struct pvr2_hdw *,
207 int prom_flag,
208 int enable_flag);
Mike Iselyd8554972006-06-26 20:58:46 -0300209
210/* Return true if we're in a mode for retrieval CPU firmware */
211int pvr2_hdw_cpufw_get_enabled(struct pvr2_hdw *);
212
213/* Retrieve a piece of the CPU's firmware at the given offset. Return
214 value is the number of bytes retrieved or zero if we're past the end or
215 an error otherwise (e.g. if firmware retrieval is not enabled). */
216int pvr2_hdw_cpufw_get(struct pvr2_hdw *,unsigned int offs,
217 char *buf,unsigned int cnt);
218
Pantelis Koukousoulas2fdf3d92006-12-27 23:07:58 -0300219/* Retrieve a previously stored v4l minor device number */
Mike Isely80793842006-12-27 23:12:28 -0300220int pvr2_hdw_v4l_get_minor_number(struct pvr2_hdw *,enum pvr2_v4l_type index);
Mike Iselyd8554972006-06-26 20:58:46 -0300221
Pantelis Koukousoulas2fdf3d92006-12-27 23:07:58 -0300222/* Store a v4l minor device number */
Mike Iselyfd5a75f2006-12-27 23:11:22 -0300223void pvr2_hdw_v4l_store_minor_number(struct pvr2_hdw *,
Mike Isely80793842006-12-27 23:12:28 -0300224 enum pvr2_v4l_type index,int);
Mike Iselyd8554972006-06-26 20:58:46 -0300225
Mike Isely32ffa9a2006-09-23 22:26:52 -0300226/* Direct read/write access to chip's registers:
Hans Verkuilf3d092b2007-02-23 20:55:14 -0300227 match_type - how to interpret match_chip (e.g. driver ID, i2c address)
228 match_chip - chip match value (e.g. I2C_DRIVERD_xxxx)
Mike Isely32ffa9a2006-09-23 22:26:52 -0300229 reg_id - register number to access
230 setFl - true to set the register, false to read it
231 val_ptr - storage location for source / result. */
232int pvr2_hdw_register_access(struct pvr2_hdw *,
Hans Verkuilf3d092b2007-02-23 20:55:14 -0300233 u32 match_type, u32 match_chip,u64 reg_id,
234 int setFl,u64 *val_ptr);
Mike Iselyd8554972006-06-26 20:58:46 -0300235
236/* The following entry points are all lower level things you normally don't
237 want to worry about. */
238
Mike Iselyd8554972006-06-26 20:58:46 -0300239/* Issue a command and get a response from the device. LOTS of higher
240 level stuff is built on this. */
241int pvr2_send_request(struct pvr2_hdw *,
242 void *write_ptr,unsigned int write_len,
243 void *read_ptr,unsigned int read_len);
244
Mike Iselyd8554972006-06-26 20:58:46 -0300245/* Slightly higher level device communication functions. */
246int pvr2_write_register(struct pvr2_hdw *, u16, u32);
Mike Iselyd8554972006-06-26 20:58:46 -0300247
248/* Call if for any reason we can't talk to the hardware anymore - this will
249 cause the driver to stop flailing on the device. */
250void pvr2_hdw_render_useless(struct pvr2_hdw *);
Mike Iselyd8554972006-06-26 20:58:46 -0300251
252/* Set / clear 8051's reset bit */
253void pvr2_hdw_cpureset_assert(struct pvr2_hdw *,int);
254
255/* Execute a USB-commanded device reset */
256void pvr2_hdw_device_reset(struct pvr2_hdw *);
257
Mike Isely681c7392007-11-26 01:48:52 -0300258/* Reset worker's error trapping circuit breaker */
259int pvr2_hdw_untrip(struct pvr2_hdw *);
260
Mike Iselyd8554972006-06-26 20:58:46 -0300261/* Execute hard reset command (after this point it's likely that the
262 encoder will have to be reconfigured). This also clears the "useless"
263 state. */
264int pvr2_hdw_cmd_deep_reset(struct pvr2_hdw *);
265
266/* Execute simple reset command */
267int pvr2_hdw_cmd_powerup(struct pvr2_hdw *);
268
Michael Krufkye1edb192008-04-22 14:45:39 -0300269/* suspend */
270int pvr2_hdw_cmd_powerdown(struct pvr2_hdw *);
271
Mike Iselyd8554972006-06-26 20:58:46 -0300272/* Order decoder to reset */
273int pvr2_hdw_cmd_decoder_reset(struct pvr2_hdw *);
274
Mike Iselyd8554972006-06-26 20:58:46 -0300275/* Direct manipulation of GPIO bits */
276int pvr2_hdw_gpio_get_dir(struct pvr2_hdw *hdw,u32 *);
277int pvr2_hdw_gpio_get_out(struct pvr2_hdw *hdw,u32 *);
278int pvr2_hdw_gpio_get_in(struct pvr2_hdw *hdw,u32 *);
279int pvr2_hdw_gpio_chg_dir(struct pvr2_hdw *hdw,u32 msk,u32 val);
280int pvr2_hdw_gpio_chg_out(struct pvr2_hdw *hdw,u32 msk,u32 val);
281
282/* This data structure is specifically for the next function... */
283struct pvr2_hdw_debug_info {
284 int big_lock_held;
285 int ctl_lock_held;
Mike Iselyd8554972006-06-26 20:58:46 -0300286 int flag_disconnected;
287 int flag_init_ok;
Mike Isely681c7392007-11-26 01:48:52 -0300288 int flag_ok;
289 int fw1_state;
290 int flag_decoder_missed;
291 int flag_tripped;
292 int state_encoder_ok;
293 int state_encoder_run;
294 int state_decoder_run;
295 int state_usbstream_run;
296 int state_decoder_quiescent;
297 int state_pipeline_config;
298 int state_pipeline_req;
299 int state_pipeline_pause;
300 int state_pipeline_idle;
Mike Iselyd8554972006-06-26 20:58:46 -0300301 int cmd_debug_state;
302 int cmd_debug_write_len;
303 int cmd_debug_read_len;
304 int cmd_debug_write_pend;
305 int cmd_debug_read_pend;
306 int cmd_debug_timeout;
307 int cmd_debug_rstatus;
308 int cmd_debug_wstatus;
309 unsigned char cmd_code;
310};
311
312/* Non-intrusively retrieve internal state info - this is useful for
313 diagnosing lockups. Note that this operation is completed without any
314 kind of locking and so it is not atomic and may yield inconsistent
315 results. This is *purely* a debugging aid. */
Mike Isely681c7392007-11-26 01:48:52 -0300316void pvr2_hdw_get_debug_info_unlocked(const struct pvr2_hdw *hdw,
317 struct pvr2_hdw_debug_info *);
318
319/* Intrusively retrieve internal state info - this is useful for
320 diagnosing overall driver state. This operation synchronizes against
321 the overall driver mutex - so if there are locking problems this will
322 likely hang! This is *purely* a debugging aid. */
323void pvr2_hdw_get_debug_info_locked(struct pvr2_hdw *hdw,
324 struct pvr2_hdw_debug_info *);
325
326/* Report out several lines of text that describes driver internal state.
327 Results are written into the passed-in buffer. */
328unsigned int pvr2_hdw_state_report(struct pvr2_hdw *hdw,
329 char *buf_ptr,unsigned int buf_size);
Mike Iselyd8554972006-06-26 20:58:46 -0300330
331/* Cause modules to log their state once */
332void pvr2_hdw_trigger_module_log(struct pvr2_hdw *hdw);
333
334/* Cause encoder firmware to be uploaded into the device. This is normally
335 done autonomously, but the interface is exported here because it is also
336 a debugging aid. */
337int pvr2_upload_firmware2(struct pvr2_hdw *hdw);
338
Mike Iselyd8554972006-06-26 20:58:46 -0300339#endif /* __PVRUSB2_HDW_H */
340
341/*
342 Stuff for Emacs to see, in order to encourage consistent editing style:
343 *** Local Variables: ***
344 *** mode: c ***
345 *** fill-column: 75 ***
346 *** tab-width: 8 ***
347 *** c-basic-offset: 8 ***
348 *** End: ***
349 */