blob: e2f9d5e4cb653c191f1a07ed94bf14a5799d3a4f [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
43#define PVR2_CVAL_INPUT_SVIDEO 1
44#define PVR2_CVAL_INPUT_COMPOSITE 2
45#define PVR2_CVAL_INPUT_RADIO 3
46
Mike Iselyd8554972006-06-26 20:58:46 -030047/* Subsystem definitions - these are various pieces that can be
48 independently stopped / started. Usually you don't want to mess with
49 this directly (let the driver handle things itself), but it is useful
50 for debugging. */
51#define PVR2_SUBSYS_B_ENC_FIRMWARE 0
52#define PVR2_SUBSYS_B_ENC_CFG 1
53#define PVR2_SUBSYS_B_DIGITIZER_RUN 2
54#define PVR2_SUBSYS_B_USBSTREAM_RUN 3
55#define PVR2_SUBSYS_B_ENC_RUN 4
56
57#define PVR2_SUBSYS_CFG_ALL ( \
58 (1 << PVR2_SUBSYS_B_ENC_FIRMWARE) | \
59 (1 << PVR2_SUBSYS_B_ENC_CFG) )
60#define PVR2_SUBSYS_RUN_ALL ( \
61 (1 << PVR2_SUBSYS_B_DIGITIZER_RUN) | \
62 (1 << PVR2_SUBSYS_B_USBSTREAM_RUN) | \
63 (1 << PVR2_SUBSYS_B_ENC_RUN) )
64#define PVR2_SUBSYS_ALL ( \
65 PVR2_SUBSYS_CFG_ALL | \
66 PVR2_SUBSYS_RUN_ALL )
67
68enum pvr2_config {
Mike Isely16eb40d2006-12-30 18:27:32 -030069 pvr2_config_empty, /* No configuration */
70 pvr2_config_mpeg, /* Encoded / compressed video */
71 pvr2_config_vbi, /* Standard vbi info */
72 pvr2_config_pcm, /* Audio raw pcm stream */
73 pvr2_config_rawvideo, /* Video raw frames */
Mike Iselyd8554972006-06-26 20:58:46 -030074};
75
Mike Isely80793842006-12-27 23:12:28 -030076enum pvr2_v4l_type {
77 pvr2_v4l_type_video,
78 pvr2_v4l_type_vbi,
79 pvr2_v4l_type_radio,
80};
81
Mike Iselyd8554972006-06-26 20:58:46 -030082const char *pvr2_config_get_name(enum pvr2_config);
83
84struct pvr2_hdw;
85
86/* Create and return a structure for interacting with the underlying
87 hardware */
88struct pvr2_hdw *pvr2_hdw_create(struct usb_interface *intf,
89 const struct usb_device_id *devid);
90
91/* Poll for background activity (if any) */
92void pvr2_hdw_poll(struct pvr2_hdw *);
93
94/* Trigger a poll to take place later at a convenient time */
Mike Iselyd8554972006-06-26 20:58:46 -030095void pvr2_hdw_poll_trigger_unlocked(struct pvr2_hdw *);
96
97/* Register a callback used to trigger a future poll */
98void pvr2_hdw_setup_poll_trigger(struct pvr2_hdw *,
99 void (*func)(void *),
100 void *data);
101
Mike Iselyd8554972006-06-26 20:58:46 -0300102/* Destroy hardware interaction structure */
103void pvr2_hdw_destroy(struct pvr2_hdw *);
104
105/* Set up the structure and attempt to put the device into a usable state.
106 This can be a time-consuming operation, which is why it is not done
107 internally as part of the create() step. Return value is exactly the
108 same as pvr2_hdw_init_ok(). */
109int pvr2_hdw_setup(struct pvr2_hdw *);
110
111/* Initialization succeeded */
112int pvr2_hdw_init_ok(struct pvr2_hdw *);
113
114/* Return true if in the ready (normal) state */
115int pvr2_hdw_dev_ok(struct pvr2_hdw *);
116
117/* Return small integer number [1..N] for logical instance number of this
118 device. This is useful for indexing array-valued module parameters. */
119int pvr2_hdw_get_unit_number(struct pvr2_hdw *);
120
121/* Get pointer to underlying USB device */
122struct usb_device *pvr2_hdw_get_dev(struct pvr2_hdw *);
123
124/* Retrieve serial number of device */
125unsigned long pvr2_hdw_get_sn(struct pvr2_hdw *);
126
Mike Isely31a18542007-04-08 01:11:47 -0300127/* Retrieve bus location info of device */
128const char *pvr2_hdw_get_bus_info(struct pvr2_hdw *);
129
Mike Iselyd8554972006-06-26 20:58:46 -0300130/* Called when hardware has been unplugged */
131void pvr2_hdw_disconnect(struct pvr2_hdw *);
132
133/* Get the number of defined controls */
134unsigned int pvr2_hdw_get_ctrl_count(struct pvr2_hdw *);
135
136/* Retrieve a control handle given its index (0..count-1) */
137struct pvr2_ctrl *pvr2_hdw_get_ctrl_by_index(struct pvr2_hdw *,unsigned int);
138
139/* Retrieve a control handle given its internal ID (if any) */
140struct pvr2_ctrl *pvr2_hdw_get_ctrl_by_id(struct pvr2_hdw *,unsigned int);
141
142/* Retrieve a control handle given its V4L ID (if any) */
143struct pvr2_ctrl *pvr2_hdw_get_ctrl_v4l(struct pvr2_hdw *,unsigned int ctl_id);
144
Mike Iselya761f432006-06-25 20:04:44 -0300145/* Retrieve a control handle given its immediate predecessor V4L ID (if any) */
146struct pvr2_ctrl *pvr2_hdw_get_ctrl_nextv4l(struct pvr2_hdw *,
147 unsigned int ctl_id);
148
Mike Iselyd8554972006-06-26 20:58:46 -0300149/* Commit all control changes made up to this point */
150int pvr2_hdw_commit_ctl(struct pvr2_hdw *);
151
152/* Return name for this driver instance */
153const char *pvr2_hdw_get_driver_name(struct pvr2_hdw *);
154
Mike Isely18103c572007-01-20 00:09:47 -0300155/* Mark tuner status stale so that it will be re-fetched */
156void pvr2_hdw_execute_tuner_poll(struct pvr2_hdw *);
157
158/* Return information about the tuner */
159int pvr2_hdw_get_tuner_status(struct pvr2_hdw *,struct v4l2_tuner *);
Mike Iselyd8554972006-06-26 20:58:46 -0300160
161/* Query device and see if it thinks it is on a high-speed USB link */
162int pvr2_hdw_is_hsm(struct pvr2_hdw *);
163
164/* Turn streaming on/off */
165int pvr2_hdw_set_streaming(struct pvr2_hdw *,int);
166
167/* Find out if streaming is on */
168int pvr2_hdw_get_streaming(struct pvr2_hdw *);
169
170/* Configure the type of stream to generate */
171int pvr2_hdw_set_stream_type(struct pvr2_hdw *, enum pvr2_config);
172
173/* Get handle to video output stream */
174struct pvr2_stream *pvr2_hdw_get_video_stream(struct pvr2_hdw *);
175
176/* Emit a video standard struct */
177int pvr2_hdw_get_stdenum_value(struct pvr2_hdw *hdw,struct v4l2_standard *std,
178 unsigned int idx);
179
180/* Enable / disable various pieces of hardware. Items to change are
181 identified by bit positions within msk, and new state for each item is
182 identified by corresponding bit positions within val. */
183void pvr2_hdw_subsys_bit_chg(struct pvr2_hdw *hdw,
184 unsigned long msk,unsigned long val);
185
Mike Iselyd8554972006-06-26 20:58:46 -0300186/* Retrieve mask indicating which pieces of hardware are currently enabled
187 / configured. */
188unsigned long pvr2_hdw_subsys_get(struct pvr2_hdw *);
189
190/* Adjust mask of what get shut down when streaming is stopped. This is a
191 debugging aid. */
192void pvr2_hdw_subsys_stream_bit_chg(struct pvr2_hdw *hdw,
193 unsigned long msk,unsigned long val);
194
195/* Retrieve mask indicating which pieces of hardware are disabled when
196 streaming is turned off. */
197unsigned long pvr2_hdw_subsys_stream_get(struct pvr2_hdw *);
198
199
Mike Isely4db666c2007-09-08 22:16:27 -0300200/* Enable / disable retrieval of CPU firmware or prom contents. This must
201 be enabled before pvr2_hdw_cpufw_get() will function. Note that doing
202 this may prevent the device from running (and leaving this mode may
203 imply a device reset). */
204void pvr2_hdw_cpufw_set_enabled(struct pvr2_hdw *,
205 int prom_flag,
206 int enable_flag);
Mike Iselyd8554972006-06-26 20:58:46 -0300207
208/* Return true if we're in a mode for retrieval CPU firmware */
209int pvr2_hdw_cpufw_get_enabled(struct pvr2_hdw *);
210
211/* Retrieve a piece of the CPU's firmware at the given offset. Return
212 value is the number of bytes retrieved or zero if we're past the end or
213 an error otherwise (e.g. if firmware retrieval is not enabled). */
214int pvr2_hdw_cpufw_get(struct pvr2_hdw *,unsigned int offs,
215 char *buf,unsigned int cnt);
216
Pantelis Koukousoulas2fdf3d92006-12-27 23:07:58 -0300217/* Retrieve a previously stored v4l minor device number */
Mike Isely80793842006-12-27 23:12:28 -0300218int pvr2_hdw_v4l_get_minor_number(struct pvr2_hdw *,enum pvr2_v4l_type index);
Mike Iselyd8554972006-06-26 20:58:46 -0300219
Pantelis Koukousoulas2fdf3d92006-12-27 23:07:58 -0300220/* Store a v4l minor device number */
Mike Iselyfd5a75f2006-12-27 23:11:22 -0300221void pvr2_hdw_v4l_store_minor_number(struct pvr2_hdw *,
Mike Isely80793842006-12-27 23:12:28 -0300222 enum pvr2_v4l_type index,int);
Mike Iselyd8554972006-06-26 20:58:46 -0300223
Mike Isely32ffa9a2006-09-23 22:26:52 -0300224/* Direct read/write access to chip's registers:
Hans Verkuilf3d092b2007-02-23 20:55:14 -0300225 match_type - how to interpret match_chip (e.g. driver ID, i2c address)
226 match_chip - chip match value (e.g. I2C_DRIVERD_xxxx)
Mike Isely32ffa9a2006-09-23 22:26:52 -0300227 reg_id - register number to access
228 setFl - true to set the register, false to read it
229 val_ptr - storage location for source / result. */
230int pvr2_hdw_register_access(struct pvr2_hdw *,
Hans Verkuilf3d092b2007-02-23 20:55:14 -0300231 u32 match_type, u32 match_chip,u64 reg_id,
232 int setFl,u64 *val_ptr);
Mike Iselyd8554972006-06-26 20:58:46 -0300233
234/* The following entry points are all lower level things you normally don't
235 want to worry about. */
236
Mike Iselyd8554972006-06-26 20:58:46 -0300237/* Issue a command and get a response from the device. LOTS of higher
238 level stuff is built on this. */
239int pvr2_send_request(struct pvr2_hdw *,
240 void *write_ptr,unsigned int write_len,
241 void *read_ptr,unsigned int read_len);
242
Mike Iselyd8554972006-06-26 20:58:46 -0300243/* Slightly higher level device communication functions. */
244int pvr2_write_register(struct pvr2_hdw *, u16, u32);
Mike Iselyd8554972006-06-26 20:58:46 -0300245
246/* Call if for any reason we can't talk to the hardware anymore - this will
247 cause the driver to stop flailing on the device. */
248void pvr2_hdw_render_useless(struct pvr2_hdw *);
Mike Iselyd8554972006-06-26 20:58:46 -0300249
250/* Set / clear 8051's reset bit */
251void pvr2_hdw_cpureset_assert(struct pvr2_hdw *,int);
252
253/* Execute a USB-commanded device reset */
254void pvr2_hdw_device_reset(struct pvr2_hdw *);
255
256/* Execute hard reset command (after this point it's likely that the
257 encoder will have to be reconfigured). This also clears the "useless"
258 state. */
259int pvr2_hdw_cmd_deep_reset(struct pvr2_hdw *);
260
261/* Execute simple reset command */
262int pvr2_hdw_cmd_powerup(struct pvr2_hdw *);
263
264/* Order decoder to reset */
265int pvr2_hdw_cmd_decoder_reset(struct pvr2_hdw *);
266
Mike Iselyd8554972006-06-26 20:58:46 -0300267/* Direct manipulation of GPIO bits */
268int pvr2_hdw_gpio_get_dir(struct pvr2_hdw *hdw,u32 *);
269int pvr2_hdw_gpio_get_out(struct pvr2_hdw *hdw,u32 *);
270int pvr2_hdw_gpio_get_in(struct pvr2_hdw *hdw,u32 *);
271int pvr2_hdw_gpio_chg_dir(struct pvr2_hdw *hdw,u32 msk,u32 val);
272int pvr2_hdw_gpio_chg_out(struct pvr2_hdw *hdw,u32 msk,u32 val);
273
274/* This data structure is specifically for the next function... */
275struct pvr2_hdw_debug_info {
276 int big_lock_held;
277 int ctl_lock_held;
278 int flag_ok;
279 int flag_disconnected;
280 int flag_init_ok;
281 int flag_streaming_enabled;
282 unsigned long subsys_flags;
283 int cmd_debug_state;
284 int cmd_debug_write_len;
285 int cmd_debug_read_len;
286 int cmd_debug_write_pend;
287 int cmd_debug_read_pend;
288 int cmd_debug_timeout;
289 int cmd_debug_rstatus;
290 int cmd_debug_wstatus;
291 unsigned char cmd_code;
292};
293
294/* Non-intrusively retrieve internal state info - this is useful for
295 diagnosing lockups. Note that this operation is completed without any
296 kind of locking and so it is not atomic and may yield inconsistent
297 results. This is *purely* a debugging aid. */
298void pvr2_hdw_get_debug_info(const struct pvr2_hdw *hdw,
299 struct pvr2_hdw_debug_info *);
300
301/* Cause modules to log their state once */
302void pvr2_hdw_trigger_module_log(struct pvr2_hdw *hdw);
303
304/* Cause encoder firmware to be uploaded into the device. This is normally
305 done autonomously, but the interface is exported here because it is also
306 a debugging aid. */
307int pvr2_upload_firmware2(struct pvr2_hdw *hdw);
308
309/* List of device types that we can match */
310extern struct usb_device_id pvr2_device_table[];
311
312#endif /* __PVRUSB2_HDW_H */
313
314/*
315 Stuff for Emacs to see, in order to encourage consistent editing style:
316 *** Local Variables: ***
317 *** mode: c ***
318 *** fill-column: 75 ***
319 *** tab-width: 8 ***
320 *** c-basic-offset: 8 ***
321 *** End: ***
322 */