V4L/DVB (7319): pvrusb2: Close potential race condition during initialization
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / media / video / pvrusb2 / pvrusb2-hdw.h
blob597ee50331492b689bf3abb14b144f4857bc43e8
1 /*
3 * $Id$
5 * Copyright (C) 2005 Mike Isely <isely@pobox.com>
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
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.
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
21 #ifndef __PVRUSB2_HDW_H
22 #define __PVRUSB2_HDW_H
24 #include <linux/usb.h>
25 #include <linux/videodev2.h>
26 #include "pvrusb2-io.h"
27 #include "pvrusb2-ctrl.h"
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
41 /* Legal values for the INPUT state variable */
42 #define PVR2_CVAL_INPUT_TV 0
43 #define PVR2_CVAL_INPUT_DTV 1
44 #define PVR2_CVAL_INPUT_COMPOSITE 2
45 #define PVR2_CVAL_INPUT_SVIDEO 3
46 #define PVR2_CVAL_INPUT_RADIO 4
48 enum pvr2_config {
49 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 */
56 enum pvr2_v4l_type {
57 pvr2_v4l_type_video,
58 pvr2_v4l_type_vbi,
59 pvr2_v4l_type_radio,
62 /* Major states that we can be in:
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.
69 * COLD - Device is in an unusuable state, needs microcontroller firmware.
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).
75 * ERROR - A problem prevents capture operation (e.g. encoder firmware
76 * missing).
78 * READY - Device is operational, but not streaming.
80 * RUN - Device is streaming.
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
91 /* Translate configuration enum to a string label */
92 const char *pvr2_config_get_name(enum pvr2_config);
94 /* Translate a master state enum to a string label */
95 const char *pvr2_hdw_get_state_name(unsigned int);
97 struct pvr2_hdw;
99 /* Create and return a structure for interacting with the underlying
100 hardware */
101 struct pvr2_hdw *pvr2_hdw_create(struct usb_interface *intf,
102 const struct usb_device_id *devid);
104 /* Perform second stage initialization, passing in a notification callback
105 for when the master state changes. */
106 void pvr2_hdw_initialize(struct pvr2_hdw *,
107 void (*callback_func)(void *),
108 void *callback_data);
110 /* Destroy hardware interaction structure */
111 void pvr2_hdw_destroy(struct pvr2_hdw *);
113 /* Return true if in the ready (normal) state */
114 int pvr2_hdw_dev_ok(struct pvr2_hdw *);
116 /* Return small integer number [1..N] for logical instance number of this
117 device. This is useful for indexing array-valued module parameters. */
118 int pvr2_hdw_get_unit_number(struct pvr2_hdw *);
120 /* Get pointer to underlying USB device */
121 struct usb_device *pvr2_hdw_get_dev(struct pvr2_hdw *);
123 /* Retrieve serial number of device */
124 unsigned long pvr2_hdw_get_sn(struct pvr2_hdw *);
126 /* Retrieve bus location info of device */
127 const char *pvr2_hdw_get_bus_info(struct pvr2_hdw *);
129 /* Called when hardware has been unplugged */
130 void pvr2_hdw_disconnect(struct pvr2_hdw *);
132 /* Get the number of defined controls */
133 unsigned int pvr2_hdw_get_ctrl_count(struct pvr2_hdw *);
135 /* Retrieve a control handle given its index (0..count-1) */
136 struct pvr2_ctrl *pvr2_hdw_get_ctrl_by_index(struct pvr2_hdw *,unsigned int);
138 /* Retrieve a control handle given its internal ID (if any) */
139 struct pvr2_ctrl *pvr2_hdw_get_ctrl_by_id(struct pvr2_hdw *,unsigned int);
141 /* Retrieve a control handle given its V4L ID (if any) */
142 struct pvr2_ctrl *pvr2_hdw_get_ctrl_v4l(struct pvr2_hdw *,unsigned int ctl_id);
144 /* Retrieve a control handle given its immediate predecessor V4L ID (if any) */
145 struct pvr2_ctrl *pvr2_hdw_get_ctrl_nextv4l(struct pvr2_hdw *,
146 unsigned int ctl_id);
148 /* Commit all control changes made up to this point */
149 int pvr2_hdw_commit_ctl(struct pvr2_hdw *);
151 /* Return a bit mask of valid input selections for this device. Mask bits
152 * will be according to PVR_CVAL_INPUT_xxxx definitions. */
153 unsigned int pvr2_hdw_get_input_available(struct pvr2_hdw *);
155 /* Return name for this driver instance */
156 const char *pvr2_hdw_get_driver_name(struct pvr2_hdw *);
158 /* Mark tuner status stale so that it will be re-fetched */
159 void pvr2_hdw_execute_tuner_poll(struct pvr2_hdw *);
161 /* Return information about the tuner */
162 int pvr2_hdw_get_tuner_status(struct pvr2_hdw *,struct v4l2_tuner *);
164 /* Query device and see if it thinks it is on a high-speed USB link */
165 int pvr2_hdw_is_hsm(struct pvr2_hdw *);
167 /* Return a string token representative of the hardware type */
168 const char *pvr2_hdw_get_type(struct pvr2_hdw *);
170 /* Return a single line description of the hardware type */
171 const char *pvr2_hdw_get_desc(struct pvr2_hdw *);
173 /* Turn streaming on/off */
174 int pvr2_hdw_set_streaming(struct pvr2_hdw *,int);
176 /* Find out if streaming is on */
177 int pvr2_hdw_get_streaming(struct pvr2_hdw *);
179 /* Retrieve driver overall state */
180 int pvr2_hdw_get_state(struct pvr2_hdw *);
182 /* Configure the type of stream to generate */
183 int pvr2_hdw_set_stream_type(struct pvr2_hdw *, enum pvr2_config);
185 /* Get handle to video output stream */
186 struct pvr2_stream *pvr2_hdw_get_video_stream(struct pvr2_hdw *);
188 /* Emit a video standard struct */
189 int pvr2_hdw_get_stdenum_value(struct pvr2_hdw *hdw,struct v4l2_standard *std,
190 unsigned int idx);
192 /* Enable / disable retrieval of CPU firmware or prom contents. This must
193 be enabled before pvr2_hdw_cpufw_get() will function. Note that doing
194 this may prevent the device from running (and leaving this mode may
195 imply a device reset). */
196 void pvr2_hdw_cpufw_set_enabled(struct pvr2_hdw *,
197 int prom_flag,
198 int enable_flag);
200 /* Return true if we're in a mode for retrieval CPU firmware */
201 int pvr2_hdw_cpufw_get_enabled(struct pvr2_hdw *);
203 /* Retrieve a piece of the CPU's firmware at the given offset. Return
204 value is the number of bytes retrieved or zero if we're past the end or
205 an error otherwise (e.g. if firmware retrieval is not enabled). */
206 int pvr2_hdw_cpufw_get(struct pvr2_hdw *,unsigned int offs,
207 char *buf,unsigned int cnt);
209 /* Retrieve a previously stored v4l minor device number */
210 int pvr2_hdw_v4l_get_minor_number(struct pvr2_hdw *,enum pvr2_v4l_type index);
212 /* Store a v4l minor device number */
213 void pvr2_hdw_v4l_store_minor_number(struct pvr2_hdw *,
214 enum pvr2_v4l_type index,int);
216 /* Direct read/write access to chip's registers:
217 match_type - how to interpret match_chip (e.g. driver ID, i2c address)
218 match_chip - chip match value (e.g. I2C_DRIVERD_xxxx)
219 reg_id - register number to access
220 setFl - true to set the register, false to read it
221 val_ptr - storage location for source / result. */
222 int pvr2_hdw_register_access(struct pvr2_hdw *,
223 u32 match_type, u32 match_chip,u64 reg_id,
224 int setFl,u64 *val_ptr);
226 /* The following entry points are all lower level things you normally don't
227 want to worry about. */
229 /* Issue a command and get a response from the device. LOTS of higher
230 level stuff is built on this. */
231 int pvr2_send_request(struct pvr2_hdw *,
232 void *write_ptr,unsigned int write_len,
233 void *read_ptr,unsigned int read_len);
235 /* Slightly higher level device communication functions. */
236 int pvr2_write_register(struct pvr2_hdw *, u16, u32);
238 /* Call if for any reason we can't talk to the hardware anymore - this will
239 cause the driver to stop flailing on the device. */
240 void pvr2_hdw_render_useless(struct pvr2_hdw *);
242 /* Set / clear 8051's reset bit */
243 void pvr2_hdw_cpureset_assert(struct pvr2_hdw *,int);
245 /* Execute a USB-commanded device reset */
246 void pvr2_hdw_device_reset(struct pvr2_hdw *);
248 /* Reset worker's error trapping circuit breaker */
249 int pvr2_hdw_untrip(struct pvr2_hdw *);
251 /* Execute hard reset command (after this point it's likely that the
252 encoder will have to be reconfigured). This also clears the "useless"
253 state. */
254 int pvr2_hdw_cmd_deep_reset(struct pvr2_hdw *);
256 /* Execute simple reset command */
257 int pvr2_hdw_cmd_powerup(struct pvr2_hdw *);
259 /* suspend */
260 int pvr2_hdw_cmd_powerdown(struct pvr2_hdw *);
262 /* Order decoder to reset */
263 int pvr2_hdw_cmd_decoder_reset(struct pvr2_hdw *);
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);
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_disconnected;
277 int flag_init_ok;
278 int flag_ok;
279 int fw1_state;
280 int flag_decoder_missed;
281 int flag_tripped;
282 int state_encoder_ok;
283 int state_encoder_run;
284 int state_decoder_run;
285 int state_usbstream_run;
286 int state_decoder_quiescent;
287 int state_pipeline_config;
288 int state_pipeline_req;
289 int state_pipeline_pause;
290 int state_pipeline_idle;
291 int cmd_debug_state;
292 int cmd_debug_write_len;
293 int cmd_debug_read_len;
294 int cmd_debug_write_pend;
295 int cmd_debug_read_pend;
296 int cmd_debug_timeout;
297 int cmd_debug_rstatus;
298 int cmd_debug_wstatus;
299 unsigned char cmd_code;
302 /* Non-intrusively retrieve internal state info - this is useful for
303 diagnosing lockups. Note that this operation is completed without any
304 kind of locking and so it is not atomic and may yield inconsistent
305 results. This is *purely* a debugging aid. */
306 void pvr2_hdw_get_debug_info_unlocked(const struct pvr2_hdw *hdw,
307 struct pvr2_hdw_debug_info *);
309 /* Intrusively retrieve internal state info - this is useful for
310 diagnosing overall driver state. This operation synchronizes against
311 the overall driver mutex - so if there are locking problems this will
312 likely hang! This is *purely* a debugging aid. */
313 void pvr2_hdw_get_debug_info_locked(struct pvr2_hdw *hdw,
314 struct pvr2_hdw_debug_info *);
316 /* Report out several lines of text that describes driver internal state.
317 Results are written into the passed-in buffer. */
318 unsigned int pvr2_hdw_state_report(struct pvr2_hdw *hdw,
319 char *buf_ptr,unsigned int buf_size);
321 /* Cause modules to log their state once */
322 void pvr2_hdw_trigger_module_log(struct pvr2_hdw *hdw);
324 /* Cause encoder firmware to be uploaded into the device. This is normally
325 done autonomously, but the interface is exported here because it is also
326 a debugging aid. */
327 int pvr2_upload_firmware2(struct pvr2_hdw *hdw);
329 #endif /* __PVRUSB2_HDW_H */
332 Stuff for Emacs to see, in order to encourage consistent editing style:
333 *** Local Variables: ***
334 *** mode: c ***
335 *** fill-column: 75 ***
336 *** tab-width: 8 ***
337 *** c-basic-offset: 8 ***
338 *** End: ***