]> pilppa.org Git - linux-2.6-omap-h63xx.git/blob - drivers/media/video/pvrusb2/pvrusb2-hdw.h
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input
[linux-2.6-omap-h63xx.git] / drivers / media / video / pvrusb2 / pvrusb2-hdw.h
1 /*
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
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
40
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
47 /* 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
68 enum pvr2_config {
69         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 */
74 };
75
76 enum pvr2_v4l_type {
77         pvr2_v4l_type_video,
78         pvr2_v4l_type_vbi,
79         pvr2_v4l_type_radio,
80 };
81
82 const char *pvr2_config_get_name(enum pvr2_config);
83
84 struct pvr2_hdw;
85
86 /* Create and return a structure for interacting with the underlying
87    hardware */
88 struct pvr2_hdw *pvr2_hdw_create(struct usb_interface *intf,
89                                  const struct usb_device_id *devid);
90
91 /* Poll for background activity (if any) */
92 void pvr2_hdw_poll(struct pvr2_hdw *);
93
94 /* Trigger a poll to take place later at a convenient time */
95 void pvr2_hdw_poll_trigger_unlocked(struct pvr2_hdw *);
96
97 /* Register a callback used to trigger a future poll */
98 void pvr2_hdw_setup_poll_trigger(struct pvr2_hdw *,
99                                  void (*func)(void *),
100                                  void *data);
101
102 /* Destroy hardware interaction structure */
103 void 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(). */
109 int pvr2_hdw_setup(struct pvr2_hdw *);
110
111 /* Initialization succeeded */
112 int pvr2_hdw_init_ok(struct pvr2_hdw *);
113
114 /* Return true if in the ready (normal) state */
115 int 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. */
119 int pvr2_hdw_get_unit_number(struct pvr2_hdw *);
120
121 /* Get pointer to underlying USB device */
122 struct usb_device *pvr2_hdw_get_dev(struct pvr2_hdw *);
123
124 /* Retrieve serial number of device */
125 unsigned long pvr2_hdw_get_sn(struct pvr2_hdw *);
126
127 /* Retrieve bus location info of device */
128 const char *pvr2_hdw_get_bus_info(struct pvr2_hdw *);
129
130 /* Called when hardware has been unplugged */
131 void pvr2_hdw_disconnect(struct pvr2_hdw *);
132
133 /* Get the number of defined controls */
134 unsigned int pvr2_hdw_get_ctrl_count(struct pvr2_hdw *);
135
136 /* Retrieve a control handle given its index (0..count-1) */
137 struct 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) */
140 struct 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) */
143 struct pvr2_ctrl *pvr2_hdw_get_ctrl_v4l(struct pvr2_hdw *,unsigned int ctl_id);
144
145 /* Retrieve a control handle given its immediate predecessor V4L ID (if any) */
146 struct pvr2_ctrl *pvr2_hdw_get_ctrl_nextv4l(struct pvr2_hdw *,
147                                             unsigned int ctl_id);
148
149 /* Commit all control changes made up to this point */
150 int pvr2_hdw_commit_ctl(struct pvr2_hdw *);
151
152 /* Return name for this driver instance */
153 const char *pvr2_hdw_get_driver_name(struct pvr2_hdw *);
154
155 /* Mark tuner status stale so that it will be re-fetched */
156 void pvr2_hdw_execute_tuner_poll(struct pvr2_hdw *);
157
158 /* Return information about the tuner */
159 int pvr2_hdw_get_tuner_status(struct pvr2_hdw *,struct v4l2_tuner *);
160
161 /* Query device and see if it thinks it is on a high-speed USB link */
162 int pvr2_hdw_is_hsm(struct pvr2_hdw *);
163
164 /* Turn streaming on/off */
165 int pvr2_hdw_set_streaming(struct pvr2_hdw *,int);
166
167 /* Find out if streaming is on */
168 int pvr2_hdw_get_streaming(struct pvr2_hdw *);
169
170 /* Configure the type of stream to generate */
171 int pvr2_hdw_set_stream_type(struct pvr2_hdw *, enum pvr2_config);
172
173 /* Get handle to video output stream */
174 struct pvr2_stream *pvr2_hdw_get_video_stream(struct pvr2_hdw *);
175
176 /* Emit a video standard struct */
177 int 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. */
183 void pvr2_hdw_subsys_bit_chg(struct pvr2_hdw *hdw,
184                              unsigned long msk,unsigned long val);
185
186 /* Retrieve mask indicating which pieces of hardware are currently enabled
187    / configured. */
188 unsigned 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. */
192 void 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. */
197 unsigned long pvr2_hdw_subsys_stream_get(struct pvr2_hdw *);
198
199
200 /* Enable / disable retrieval of CPU firmware.  This must be enabled before
201    pvr2_hdw_cpufw_get() will function.  Note that doing this may prevent
202    the device from running (and leaving this mode may imply a device
203    reset). */
204 void pvr2_hdw_cpufw_set_enabled(struct pvr2_hdw *, int enable_flag);
205
206 /* Return true if we're in a mode for retrieval CPU firmware */
207 int pvr2_hdw_cpufw_get_enabled(struct pvr2_hdw *);
208
209 /* Retrieve a piece of the CPU's firmware at the given offset.  Return
210    value is the number of bytes retrieved or zero if we're past the end or
211    an error otherwise (e.g. if firmware retrieval is not enabled). */
212 int pvr2_hdw_cpufw_get(struct pvr2_hdw *,unsigned int offs,
213                        char *buf,unsigned int cnt);
214
215 /* Retrieve a previously stored v4l minor device number */
216 int pvr2_hdw_v4l_get_minor_number(struct pvr2_hdw *,enum pvr2_v4l_type index);
217
218 /* Store a v4l minor device number */
219 void pvr2_hdw_v4l_store_minor_number(struct pvr2_hdw *,
220                                      enum pvr2_v4l_type index,int);
221
222 /* Direct read/write access to chip's registers:
223    match_type - how to interpret match_chip (e.g. driver ID, i2c address)
224    match_chip - chip match value (e.g. I2C_DRIVERD_xxxx)
225    reg_id  - register number to access
226    setFl   - true to set the register, false to read it
227    val_ptr - storage location for source / result. */
228 int pvr2_hdw_register_access(struct pvr2_hdw *,
229                              u32 match_type, u32 match_chip,u64 reg_id,
230                              int setFl,u64 *val_ptr);
231
232 /* The following entry points are all lower level things you normally don't
233    want to worry about. */
234
235 /* Issue a command and get a response from the device.  LOTS of higher
236    level stuff is built on this. */
237 int pvr2_send_request(struct pvr2_hdw *,
238                       void *write_ptr,unsigned int write_len,
239                       void *read_ptr,unsigned int read_len);
240
241 /* Slightly higher level device communication functions. */
242 int pvr2_write_register(struct pvr2_hdw *, u16, u32);
243
244 /* Call if for any reason we can't talk to the hardware anymore - this will
245    cause the driver to stop flailing on the device. */
246 void pvr2_hdw_render_useless(struct pvr2_hdw *);
247
248 /* Set / clear 8051's reset bit */
249 void pvr2_hdw_cpureset_assert(struct pvr2_hdw *,int);
250
251 /* Execute a USB-commanded device reset */
252 void pvr2_hdw_device_reset(struct pvr2_hdw *);
253
254 /* Execute hard reset command (after this point it's likely that the
255    encoder will have to be reconfigured).  This also clears the "useless"
256    state. */
257 int pvr2_hdw_cmd_deep_reset(struct pvr2_hdw *);
258
259 /* Execute simple reset command */
260 int pvr2_hdw_cmd_powerup(struct pvr2_hdw *);
261
262 /* Order decoder to reset */
263 int pvr2_hdw_cmd_decoder_reset(struct pvr2_hdw *);
264
265 /* Direct manipulation of GPIO bits */
266 int pvr2_hdw_gpio_get_dir(struct pvr2_hdw *hdw,u32 *);
267 int pvr2_hdw_gpio_get_out(struct pvr2_hdw *hdw,u32 *);
268 int pvr2_hdw_gpio_get_in(struct pvr2_hdw *hdw,u32 *);
269 int pvr2_hdw_gpio_chg_dir(struct pvr2_hdw *hdw,u32 msk,u32 val);
270 int pvr2_hdw_gpio_chg_out(struct pvr2_hdw *hdw,u32 msk,u32 val);
271
272 /* This data structure is specifically for the next function... */
273 struct pvr2_hdw_debug_info {
274         int big_lock_held;
275         int ctl_lock_held;
276         int flag_ok;
277         int flag_disconnected;
278         int flag_init_ok;
279         int flag_streaming_enabled;
280         unsigned long subsys_flags;
281         int cmd_debug_state;
282         int cmd_debug_write_len;
283         int cmd_debug_read_len;
284         int cmd_debug_write_pend;
285         int cmd_debug_read_pend;
286         int cmd_debug_timeout;
287         int cmd_debug_rstatus;
288         int cmd_debug_wstatus;
289         unsigned char cmd_code;
290 };
291
292 /* Non-intrusively retrieve internal state info - this is useful for
293    diagnosing lockups.  Note that this operation is completed without any
294    kind of locking and so it is not atomic and may yield inconsistent
295    results.  This is *purely* a debugging aid. */
296 void pvr2_hdw_get_debug_info(const struct pvr2_hdw *hdw,
297                              struct pvr2_hdw_debug_info *);
298
299 /* Cause modules to log their state once */
300 void pvr2_hdw_trigger_module_log(struct pvr2_hdw *hdw);
301
302 /* Cause encoder firmware to be uploaded into the device.  This is normally
303    done autonomously, but the interface is exported here because it is also
304    a debugging aid. */
305 int pvr2_upload_firmware2(struct pvr2_hdw *hdw);
306
307 /* List of device types that we can match */
308 extern struct usb_device_id pvr2_device_table[];
309
310 #endif /* __PVRUSB2_HDW_H */
311
312 /*
313   Stuff for Emacs to see, in order to encourage consistent editing style:
314   *** Local Variables: ***
315   *** mode: c ***
316   *** fill-column: 75 ***
317   *** tab-width: 8 ***
318   *** c-basic-offset: 8 ***
319   *** End: ***
320   */