blob: 779c27ea188e5495c97fb33fae964df0c0042f26 [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
29/* Private V4L2-compatible controls available in this driver, look these up
30 with pvr2_hdw_get_ctrl_v4l(). */
31#define V4L2_CID_PVR_SRATE (V4L2_CID_PRIVATE_BASE)
32#define V4L2_CID_PVR_AUDIOBITRATE (V4L2_CID_PRIVATE_BASE+1)
33#define V4L2_CID_PVR_AUDIOCRC (V4L2_CID_PRIVATE_BASE+2)
34#define V4L2_CID_PVR_AUDIOEMPHASIS (V4L2_CID_PRIVATE_BASE+3)
35#define V4L2_CID_PVR_VBR (V4L2_CID_PRIVATE_BASE+4)
36#define V4L2_CID_PVR_VIDEOBITRATE (V4L2_CID_PRIVATE_BASE+5)
37#define V4L2_CID_PVR_VIDEOPEAK (V4L2_CID_PRIVATE_BASE+6)
38#define V4L2_CID_PVR_VIDEOSTANDARD (V4L2_CID_PRIVATE_BASE+7)
39
40/* Private internal control ids, look these up with
41 pvr2_hdw_get_ctrl_by_id() - these are NOT visible in V4L */
42#define PVR2_CID_STDENUM 1
43#define PVR2_CID_STDCUR 2
44#define PVR2_CID_STDAVAIL 3
45#define PVR2_CID_INPUT 4
46#define PVR2_CID_AUDIOMODE 5
47#define PVR2_CID_FREQUENCY 6
48#define PVR2_CID_HRES 7
49#define PVR2_CID_VRES 8
50#define PVR2_CID_INTERLACE 9
51
52/* Legal values for the INPUT state variable */
53#define PVR2_CVAL_INPUT_TV 0
54#define PVR2_CVAL_INPUT_SVIDEO 1
55#define PVR2_CVAL_INPUT_COMPOSITE 2
56#define PVR2_CVAL_INPUT_RADIO 3
57
58/* Values that pvr2_hdw_get_signal_status() returns */
59#define PVR2_SIGNAL_OK 0x0001
60#define PVR2_SIGNAL_STEREO 0x0002
61#define PVR2_SIGNAL_SAP 0x0004
62
63
64/* Subsystem definitions - these are various pieces that can be
65 independently stopped / started. Usually you don't want to mess with
66 this directly (let the driver handle things itself), but it is useful
67 for debugging. */
68#define PVR2_SUBSYS_B_ENC_FIRMWARE 0
69#define PVR2_SUBSYS_B_ENC_CFG 1
70#define PVR2_SUBSYS_B_DIGITIZER_RUN 2
71#define PVR2_SUBSYS_B_USBSTREAM_RUN 3
72#define PVR2_SUBSYS_B_ENC_RUN 4
73
74#define PVR2_SUBSYS_CFG_ALL ( \
75 (1 << PVR2_SUBSYS_B_ENC_FIRMWARE) | \
76 (1 << PVR2_SUBSYS_B_ENC_CFG) )
77#define PVR2_SUBSYS_RUN_ALL ( \
78 (1 << PVR2_SUBSYS_B_DIGITIZER_RUN) | \
79 (1 << PVR2_SUBSYS_B_USBSTREAM_RUN) | \
80 (1 << PVR2_SUBSYS_B_ENC_RUN) )
81#define PVR2_SUBSYS_ALL ( \
82 PVR2_SUBSYS_CFG_ALL | \
83 PVR2_SUBSYS_RUN_ALL )
84
85enum pvr2_config {
86 pvr2_config_empty,
87 pvr2_config_mpeg,
88 pvr2_config_vbi,
89 pvr2_config_radio,
90};
91
92const 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
101/* Poll for background activity (if any) */
102void pvr2_hdw_poll(struct pvr2_hdw *);
103
104/* Trigger a poll to take place later at a convenient time */
105void pvr2_hdw_poll_trigger(struct pvr2_hdw *);
106void pvr2_hdw_poll_trigger_unlocked(struct pvr2_hdw *);
107
108/* Register a callback used to trigger a future poll */
109void pvr2_hdw_setup_poll_trigger(struct pvr2_hdw *,
110 void (*func)(void *),
111 void *data);
112
113/* Get pointer to structure given unit number */
114struct pvr2_hdw *pvr2_hdw_find(int unit_number);
115
116/* Destroy hardware interaction structure */
117void pvr2_hdw_destroy(struct pvr2_hdw *);
118
119/* Set up the structure and attempt to put the device into a usable state.
120 This can be a time-consuming operation, which is why it is not done
121 internally as part of the create() step. Return value is exactly the
122 same as pvr2_hdw_init_ok(). */
123int pvr2_hdw_setup(struct pvr2_hdw *);
124
125/* Initialization succeeded */
126int pvr2_hdw_init_ok(struct pvr2_hdw *);
127
128/* Return true if in the ready (normal) state */
129int pvr2_hdw_dev_ok(struct pvr2_hdw *);
130
131/* Return small integer number [1..N] for logical instance number of this
132 device. This is useful for indexing array-valued module parameters. */
133int pvr2_hdw_get_unit_number(struct pvr2_hdw *);
134
135/* Get pointer to underlying USB device */
136struct usb_device *pvr2_hdw_get_dev(struct pvr2_hdw *);
137
138/* Retrieve serial number of device */
139unsigned long pvr2_hdw_get_sn(struct pvr2_hdw *);
140
141/* Called when hardware has been unplugged */
142void pvr2_hdw_disconnect(struct pvr2_hdw *);
143
144/* Get the number of defined controls */
145unsigned int pvr2_hdw_get_ctrl_count(struct pvr2_hdw *);
146
147/* Retrieve a control handle given its index (0..count-1) */
148struct pvr2_ctrl *pvr2_hdw_get_ctrl_by_index(struct pvr2_hdw *,unsigned int);
149
150/* Retrieve a control handle given its internal ID (if any) */
151struct pvr2_ctrl *pvr2_hdw_get_ctrl_by_id(struct pvr2_hdw *,unsigned int);
152
153/* Retrieve a control handle given its V4L ID (if any) */
154struct pvr2_ctrl *pvr2_hdw_get_ctrl_v4l(struct pvr2_hdw *,unsigned int ctl_id);
155
Mike Iselya761f432006-06-25 20:04:44 -0300156/* Retrieve a control handle given its immediate predecessor V4L ID (if any) */
157struct pvr2_ctrl *pvr2_hdw_get_ctrl_nextv4l(struct pvr2_hdw *,
158 unsigned int ctl_id);
159
Mike Iselyd8554972006-06-26 20:58:46 -0300160/* Commit all control changes made up to this point */
161int pvr2_hdw_commit_ctl(struct pvr2_hdw *);
162
163/* Return name for this driver instance */
164const char *pvr2_hdw_get_driver_name(struct pvr2_hdw *);
165
166/* Return PVR2_SIGNAL_XXXX bit mask indicating signal status */
167unsigned int pvr2_hdw_get_signal_status(struct pvr2_hdw *);
168
169/* Query device and see if it thinks it is on a high-speed USB link */
170int pvr2_hdw_is_hsm(struct pvr2_hdw *);
171
172/* Turn streaming on/off */
173int pvr2_hdw_set_streaming(struct pvr2_hdw *,int);
174
175/* Find out if streaming is on */
176int pvr2_hdw_get_streaming(struct pvr2_hdw *);
177
178/* Configure the type of stream to generate */
179int pvr2_hdw_set_stream_type(struct pvr2_hdw *, enum pvr2_config);
180
181/* Get handle to video output stream */
182struct pvr2_stream *pvr2_hdw_get_video_stream(struct pvr2_hdw *);
183
184/* Emit a video standard struct */
185int pvr2_hdw_get_stdenum_value(struct pvr2_hdw *hdw,struct v4l2_standard *std,
186 unsigned int idx);
187
188/* Enable / disable various pieces of hardware. Items to change are
189 identified by bit positions within msk, and new state for each item is
190 identified by corresponding bit positions within val. */
191void pvr2_hdw_subsys_bit_chg(struct pvr2_hdw *hdw,
192 unsigned long msk,unsigned long val);
193
194/* Shortcut for pvr2_hdw_subsys_bit_chg(hdw,msk,msk) */
195void pvr2_hdw_subsys_bit_set(struct pvr2_hdw *hdw,unsigned long msk);
196
197/* Shortcut for pvr2_hdw_subsys_bit_chg(hdw,msk,0) */
198void pvr2_hdw_subsys_bit_clr(struct pvr2_hdw *hdw,unsigned long msk);
199
200/* Retrieve mask indicating which pieces of hardware are currently enabled
201 / configured. */
202unsigned long pvr2_hdw_subsys_get(struct pvr2_hdw *);
203
204/* Adjust mask of what get shut down when streaming is stopped. This is a
205 debugging aid. */
206void pvr2_hdw_subsys_stream_bit_chg(struct pvr2_hdw *hdw,
207 unsigned long msk,unsigned long val);
208
209/* Retrieve mask indicating which pieces of hardware are disabled when
210 streaming is turned off. */
211unsigned long pvr2_hdw_subsys_stream_get(struct pvr2_hdw *);
212
213
214/* Enable / disable retrieval of CPU firmware. This must be enabled before
215 pvr2_hdw_cpufw_get() will function. Note that doing this may prevent
216 the device from running (and leaving this mode may imply a device
217 reset). */
218void pvr2_hdw_cpufw_set_enabled(struct pvr2_hdw *, int enable_flag);
219
220/* Return true if we're in a mode for retrieval CPU firmware */
221int pvr2_hdw_cpufw_get_enabled(struct pvr2_hdw *);
222
223/* Retrieve a piece of the CPU's firmware at the given offset. Return
224 value is the number of bytes retrieved or zero if we're past the end or
225 an error otherwise (e.g. if firmware retrieval is not enabled). */
226int pvr2_hdw_cpufw_get(struct pvr2_hdw *,unsigned int offs,
227 char *buf,unsigned int cnt);
228
229/* Retrieve previously stored v4l minor device number */
230int pvr2_hdw_v4l_get_minor_number(struct pvr2_hdw *);
231
232/* Store the v4l minor device number */
233void pvr2_hdw_v4l_store_minor_number(struct pvr2_hdw *,int);
234
235
236/* The following entry points are all lower level things you normally don't
237 want to worry about. */
238
239/* Attempt to recover from a USB foul-up (in practice I find that if you
240 have to do this, then it's already too late). */
241void pvr2_reset_ctl_endpoints(struct pvr2_hdw *hdw);
242
243/* Issue a command and get a response from the device. LOTS of higher
244 level stuff is built on this. */
245int pvr2_send_request(struct pvr2_hdw *,
246 void *write_ptr,unsigned int write_len,
247 void *read_ptr,unsigned int read_len);
248
249/* Issue a command and get a response from the device. This extended
250 version includes a probe flag (which if set means that device errors
251 should not be logged or treated as fatal) and a timeout in jiffies.
252 This can be used to non-lethally probe the health of endpoint 1. */
253int pvr2_send_request_ex(struct pvr2_hdw *,unsigned int timeout,int probe_fl,
254 void *write_ptr,unsigned int write_len,
255 void *read_ptr,unsigned int read_len);
256
257/* Slightly higher level device communication functions. */
258int pvr2_write_register(struct pvr2_hdw *, u16, u32);
259int pvr2_read_register(struct pvr2_hdw *, u16, u32 *);
260int pvr2_write_u16(struct pvr2_hdw *, u16, int);
261int pvr2_write_u8(struct pvr2_hdw *, u8, int);
262
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 *);
266void pvr2_hdw_render_useless_unlocked(struct pvr2_hdw *);
267
268/* Set / clear 8051's reset bit */
269void pvr2_hdw_cpureset_assert(struct pvr2_hdw *,int);
270
271/* Execute a USB-commanded device reset */
272void pvr2_hdw_device_reset(struct pvr2_hdw *);
273
274/* Execute hard reset command (after this point it's likely that the
275 encoder will have to be reconfigured). This also clears the "useless"
276 state. */
277int pvr2_hdw_cmd_deep_reset(struct pvr2_hdw *);
278
279/* Execute simple reset command */
280int pvr2_hdw_cmd_powerup(struct pvr2_hdw *);
281
282/* Order decoder to reset */
283int pvr2_hdw_cmd_decoder_reset(struct pvr2_hdw *);
284
285/* Stop / start video stream transport */
286int pvr2_hdw_cmd_usbstream(struct pvr2_hdw *hdw,int runFl);
287
288/* Find I2C address of eeprom */
289int pvr2_hdw_get_eeprom_addr(struct pvr2_hdw *);
290
291/* Direct manipulation of GPIO bits */
292int pvr2_hdw_gpio_get_dir(struct pvr2_hdw *hdw,u32 *);
293int pvr2_hdw_gpio_get_out(struct pvr2_hdw *hdw,u32 *);
294int pvr2_hdw_gpio_get_in(struct pvr2_hdw *hdw,u32 *);
295int pvr2_hdw_gpio_chg_dir(struct pvr2_hdw *hdw,u32 msk,u32 val);
296int pvr2_hdw_gpio_chg_out(struct pvr2_hdw *hdw,u32 msk,u32 val);
297
298/* This data structure is specifically for the next function... */
299struct pvr2_hdw_debug_info {
300 int big_lock_held;
301 int ctl_lock_held;
302 int flag_ok;
303 int flag_disconnected;
304 int flag_init_ok;
305 int flag_streaming_enabled;
306 unsigned long subsys_flags;
307 int cmd_debug_state;
308 int cmd_debug_write_len;
309 int cmd_debug_read_len;
310 int cmd_debug_write_pend;
311 int cmd_debug_read_pend;
312 int cmd_debug_timeout;
313 int cmd_debug_rstatus;
314 int cmd_debug_wstatus;
315 unsigned char cmd_code;
316};
317
318/* Non-intrusively retrieve internal state info - this is useful for
319 diagnosing lockups. Note that this operation is completed without any
320 kind of locking and so it is not atomic and may yield inconsistent
321 results. This is *purely* a debugging aid. */
322void pvr2_hdw_get_debug_info(const struct pvr2_hdw *hdw,
323 struct pvr2_hdw_debug_info *);
324
325/* Cause modules to log their state once */
326void pvr2_hdw_trigger_module_log(struct pvr2_hdw *hdw);
327
328/* Cause encoder firmware to be uploaded into the device. This is normally
329 done autonomously, but the interface is exported here because it is also
330 a debugging aid. */
331int pvr2_upload_firmware2(struct pvr2_hdw *hdw);
332
333/* List of device types that we can match */
334extern struct usb_device_id pvr2_device_table[];
335
336#endif /* __PVRUSB2_HDW_H */
337
338/*
339 Stuff for Emacs to see, in order to encourage consistent editing style:
340 *** Local Variables: ***
341 *** mode: c ***
342 *** fill-column: 75 ***
343 *** tab-width: 8 ***
344 *** c-basic-offset: 8 ***
345 *** End: ***
346 */