]>
Commit | Line | Data |
---|---|---|
d855497e MI |
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 | ||
d855497e MI |
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 | |
d855497e MI |
40 | |
41 | /* Legal values for the INPUT state variable */ | |
42 | #define PVR2_CVAL_INPUT_TV 0 | |
29bf5b1d MI |
43 | #define PVR2_CVAL_INPUT_DTV 1 |
44 | #define PVR2_CVAL_INPUT_SVIDEO 2 | |
45 | #define PVR2_CVAL_INPUT_COMPOSITE 3 | |
46 | #define PVR2_CVAL_INPUT_RADIO 4 | |
d855497e | 47 | |
d855497e | 48 | enum pvr2_config { |
16eb40d3 MI |
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 */ | |
d855497e MI |
54 | }; |
55 | ||
8079384e MI |
56 | enum pvr2_v4l_type { |
57 | pvr2_v4l_type_video, | |
58 | pvr2_v4l_type_vbi, | |
59 | pvr2_v4l_type_radio, | |
60 | }; | |
61 | ||
681c7399 MI |
62 | /* 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 */ | |
d855497e MI |
92 | const char *pvr2_config_get_name(enum pvr2_config); |
93 | ||
681c7399 MI |
94 | /* Translate a master state enum to a string label */ |
95 | const char *pvr2_hdw_get_state_name(unsigned int); | |
96 | ||
d855497e MI |
97 | struct pvr2_hdw; |
98 | ||
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); | |
103 | ||
d855497e MI |
104 | /* Destroy hardware interaction structure */ |
105 | void pvr2_hdw_destroy(struct pvr2_hdw *); | |
106 | ||
681c7399 MI |
107 | /* Register a function to be called whenever the master state changes. */ |
108 | void pvr2_hdw_set_state_callback(struct pvr2_hdw *, | |
109 | void (*callback_func)(void *), | |
110 | void *callback_data); | |
d855497e MI |
111 | |
112 | /* Return true if in the ready (normal) state */ | |
113 | int pvr2_hdw_dev_ok(struct pvr2_hdw *); | |
114 | ||
115 | /* Return small integer number [1..N] for logical instance number of this | |
116 | device. This is useful for indexing array-valued module parameters. */ | |
117 | int pvr2_hdw_get_unit_number(struct pvr2_hdw *); | |
118 | ||
119 | /* Get pointer to underlying USB device */ | |
120 | struct usb_device *pvr2_hdw_get_dev(struct pvr2_hdw *); | |
121 | ||
122 | /* Retrieve serial number of device */ | |
123 | unsigned long pvr2_hdw_get_sn(struct pvr2_hdw *); | |
124 | ||
31a18547 MI |
125 | /* Retrieve bus location info of device */ |
126 | const char *pvr2_hdw_get_bus_info(struct pvr2_hdw *); | |
127 | ||
d855497e MI |
128 | /* Called when hardware has been unplugged */ |
129 | void pvr2_hdw_disconnect(struct pvr2_hdw *); | |
130 | ||
131 | /* Get the number of defined controls */ | |
132 | unsigned int pvr2_hdw_get_ctrl_count(struct pvr2_hdw *); | |
133 | ||
134 | /* Retrieve a control handle given its index (0..count-1) */ | |
135 | struct pvr2_ctrl *pvr2_hdw_get_ctrl_by_index(struct pvr2_hdw *,unsigned int); | |
136 | ||
137 | /* Retrieve a control handle given its internal ID (if any) */ | |
138 | struct pvr2_ctrl *pvr2_hdw_get_ctrl_by_id(struct pvr2_hdw *,unsigned int); | |
139 | ||
140 | /* Retrieve a control handle given its V4L ID (if any) */ | |
141 | struct pvr2_ctrl *pvr2_hdw_get_ctrl_v4l(struct pvr2_hdw *,unsigned int ctl_id); | |
142 | ||
a761f431 MI |
143 | /* Retrieve a control handle given its immediate predecessor V4L ID (if any) */ |
144 | struct pvr2_ctrl *pvr2_hdw_get_ctrl_nextv4l(struct pvr2_hdw *, | |
145 | unsigned int ctl_id); | |
146 | ||
d855497e MI |
147 | /* Commit all control changes made up to this point */ |
148 | int pvr2_hdw_commit_ctl(struct pvr2_hdw *); | |
149 | ||
150 | /* Return name for this driver instance */ | |
151 | const char *pvr2_hdw_get_driver_name(struct pvr2_hdw *); | |
152 | ||
18103c57 MI |
153 | /* Mark tuner status stale so that it will be re-fetched */ |
154 | void pvr2_hdw_execute_tuner_poll(struct pvr2_hdw *); | |
155 | ||
156 | /* Return information about the tuner */ | |
157 | int pvr2_hdw_get_tuner_status(struct pvr2_hdw *,struct v4l2_tuner *); | |
d855497e MI |
158 | |
159 | /* Query device and see if it thinks it is on a high-speed USB link */ | |
160 | int pvr2_hdw_is_hsm(struct pvr2_hdw *); | |
161 | ||
78a47101 MI |
162 | /* Return a string token representative of the hardware type */ |
163 | const char *pvr2_hdw_get_type(struct pvr2_hdw *); | |
164 | ||
165 | /* Return a single line description of the hardware type */ | |
166 | const char *pvr2_hdw_get_desc(struct pvr2_hdw *); | |
167 | ||
d855497e MI |
168 | /* Turn streaming on/off */ |
169 | int pvr2_hdw_set_streaming(struct pvr2_hdw *,int); | |
170 | ||
171 | /* Find out if streaming is on */ | |
172 | int pvr2_hdw_get_streaming(struct pvr2_hdw *); | |
173 | ||
681c7399 MI |
174 | /* Retrieve driver overall state */ |
175 | int pvr2_hdw_get_state(struct pvr2_hdw *); | |
176 | ||
d855497e MI |
177 | /* Configure the type of stream to generate */ |
178 | int pvr2_hdw_set_stream_type(struct pvr2_hdw *, enum pvr2_config); | |
179 | ||
180 | /* Get handle to video output stream */ | |
181 | struct pvr2_stream *pvr2_hdw_get_video_stream(struct pvr2_hdw *); | |
182 | ||
183 | /* Emit a video standard struct */ | |
184 | int pvr2_hdw_get_stdenum_value(struct pvr2_hdw *hdw,struct v4l2_standard *std, | |
185 | unsigned int idx); | |
186 | ||
4db666cc MI |
187 | /* Enable / disable retrieval of CPU firmware or prom contents. This must |
188 | be enabled before pvr2_hdw_cpufw_get() will function. Note that doing | |
189 | this may prevent the device from running (and leaving this mode may | |
190 | imply a device reset). */ | |
191 | void pvr2_hdw_cpufw_set_enabled(struct pvr2_hdw *, | |
192 | int prom_flag, | |
193 | int enable_flag); | |
d855497e MI |
194 | |
195 | /* Return true if we're in a mode for retrieval CPU firmware */ | |
196 | int pvr2_hdw_cpufw_get_enabled(struct pvr2_hdw *); | |
197 | ||
198 | /* Retrieve a piece of the CPU's firmware at the given offset. Return | |
199 | value is the number of bytes retrieved or zero if we're past the end or | |
200 | an error otherwise (e.g. if firmware retrieval is not enabled). */ | |
201 | int pvr2_hdw_cpufw_get(struct pvr2_hdw *,unsigned int offs, | |
202 | char *buf,unsigned int cnt); | |
203 | ||
2fdf3d9c | 204 | /* Retrieve a previously stored v4l minor device number */ |
8079384e | 205 | int pvr2_hdw_v4l_get_minor_number(struct pvr2_hdw *,enum pvr2_v4l_type index); |
d855497e | 206 | |
2fdf3d9c | 207 | /* Store a v4l minor device number */ |
fd5a75fe | 208 | void pvr2_hdw_v4l_store_minor_number(struct pvr2_hdw *, |
8079384e | 209 | enum pvr2_v4l_type index,int); |
d855497e | 210 | |
32ffa9ae | 211 | /* Direct read/write access to chip's registers: |
f3d092b8 HV |
212 | match_type - how to interpret match_chip (e.g. driver ID, i2c address) |
213 | match_chip - chip match value (e.g. I2C_DRIVERD_xxxx) | |
32ffa9ae MI |
214 | reg_id - register number to access |
215 | setFl - true to set the register, false to read it | |
216 | val_ptr - storage location for source / result. */ | |
217 | int pvr2_hdw_register_access(struct pvr2_hdw *, | |
f3d092b8 HV |
218 | u32 match_type, u32 match_chip,u64 reg_id, |
219 | int setFl,u64 *val_ptr); | |
d855497e MI |
220 | |
221 | /* The following entry points are all lower level things you normally don't | |
222 | want to worry about. */ | |
223 | ||
d855497e MI |
224 | /* Issue a command and get a response from the device. LOTS of higher |
225 | level stuff is built on this. */ | |
226 | int pvr2_send_request(struct pvr2_hdw *, | |
227 | void *write_ptr,unsigned int write_len, | |
228 | void *read_ptr,unsigned int read_len); | |
229 | ||
d855497e MI |
230 | /* Slightly higher level device communication functions. */ |
231 | int pvr2_write_register(struct pvr2_hdw *, u16, u32); | |
d855497e MI |
232 | |
233 | /* Call if for any reason we can't talk to the hardware anymore - this will | |
234 | cause the driver to stop flailing on the device. */ | |
235 | void pvr2_hdw_render_useless(struct pvr2_hdw *); | |
d855497e MI |
236 | |
237 | /* Set / clear 8051's reset bit */ | |
238 | void pvr2_hdw_cpureset_assert(struct pvr2_hdw *,int); | |
239 | ||
240 | /* Execute a USB-commanded device reset */ | |
241 | void pvr2_hdw_device_reset(struct pvr2_hdw *); | |
242 | ||
681c7399 MI |
243 | /* Reset worker's error trapping circuit breaker */ |
244 | int pvr2_hdw_untrip(struct pvr2_hdw *); | |
245 | ||
d855497e MI |
246 | /* Execute hard reset command (after this point it's likely that the |
247 | encoder will have to be reconfigured). This also clears the "useless" | |
248 | state. */ | |
249 | int pvr2_hdw_cmd_deep_reset(struct pvr2_hdw *); | |
250 | ||
251 | /* Execute simple reset command */ | |
252 | int pvr2_hdw_cmd_powerup(struct pvr2_hdw *); | |
253 | ||
254 | /* Order decoder to reset */ | |
255 | int pvr2_hdw_cmd_decoder_reset(struct pvr2_hdw *); | |
256 | ||
d855497e MI |
257 | /* Direct manipulation of GPIO bits */ |
258 | int pvr2_hdw_gpio_get_dir(struct pvr2_hdw *hdw,u32 *); | |
259 | int pvr2_hdw_gpio_get_out(struct pvr2_hdw *hdw,u32 *); | |
260 | int pvr2_hdw_gpio_get_in(struct pvr2_hdw *hdw,u32 *); | |
261 | int pvr2_hdw_gpio_chg_dir(struct pvr2_hdw *hdw,u32 msk,u32 val); | |
262 | int pvr2_hdw_gpio_chg_out(struct pvr2_hdw *hdw,u32 msk,u32 val); | |
263 | ||
264 | /* This data structure is specifically for the next function... */ | |
265 | struct pvr2_hdw_debug_info { | |
266 | int big_lock_held; | |
267 | int ctl_lock_held; | |
d855497e MI |
268 | int flag_disconnected; |
269 | int flag_init_ok; | |
681c7399 MI |
270 | int flag_ok; |
271 | int fw1_state; | |
272 | int flag_decoder_missed; | |
273 | int flag_tripped; | |
274 | int state_encoder_ok; | |
275 | int state_encoder_run; | |
276 | int state_decoder_run; | |
277 | int state_usbstream_run; | |
278 | int state_decoder_quiescent; | |
279 | int state_pipeline_config; | |
280 | int state_pipeline_req; | |
281 | int state_pipeline_pause; | |
282 | int state_pipeline_idle; | |
d855497e MI |
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. */ | |
681c7399 MI |
298 | void pvr2_hdw_get_debug_info_unlocked(const struct pvr2_hdw *hdw, |
299 | struct pvr2_hdw_debug_info *); | |
300 | ||
301 | /* Intrusively retrieve internal state info - this is useful for | |
302 | diagnosing overall driver state. This operation synchronizes against | |
303 | the overall driver mutex - so if there are locking problems this will | |
304 | likely hang! This is *purely* a debugging aid. */ | |
305 | void pvr2_hdw_get_debug_info_locked(struct pvr2_hdw *hdw, | |
306 | struct pvr2_hdw_debug_info *); | |
307 | ||
308 | /* Report out several lines of text that describes driver internal state. | |
309 | Results are written into the passed-in buffer. */ | |
310 | unsigned int pvr2_hdw_state_report(struct pvr2_hdw *hdw, | |
311 | char *buf_ptr,unsigned int buf_size); | |
d855497e MI |
312 | |
313 | /* Cause modules to log their state once */ | |
314 | void pvr2_hdw_trigger_module_log(struct pvr2_hdw *hdw); | |
315 | ||
316 | /* Cause encoder firmware to be uploaded into the device. This is normally | |
317 | done autonomously, but the interface is exported here because it is also | |
318 | a debugging aid. */ | |
319 | int pvr2_upload_firmware2(struct pvr2_hdw *hdw); | |
320 | ||
d855497e MI |
321 | #endif /* __PVRUSB2_HDW_H */ |
322 | ||
323 | /* | |
324 | Stuff for Emacs to see, in order to encourage consistent editing style: | |
325 | *** Local Variables: *** | |
326 | *** mode: c *** | |
327 | *** fill-column: 75 *** | |
328 | *** tab-width: 8 *** | |
329 | *** c-basic-offset: 8 *** | |
330 | *** End: *** | |
331 | */ |