]>
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 | |
43 | #define PVR2_CVAL_INPUT_SVIDEO 1 | |
44 | #define PVR2_CVAL_INPUT_COMPOSITE 2 | |
45 | #define PVR2_CVAL_INPUT_RADIO 3 | |
46 | ||
47 | /* Values that pvr2_hdw_get_signal_status() returns */ | |
48 | #define PVR2_SIGNAL_OK 0x0001 | |
49 | #define PVR2_SIGNAL_STEREO 0x0002 | |
50 | #define PVR2_SIGNAL_SAP 0x0004 | |
51 | ||
52 | ||
53 | /* Subsystem definitions - these are various pieces that can be | |
54 | independently stopped / started. Usually you don't want to mess with | |
55 | this directly (let the driver handle things itself), but it is useful | |
56 | for debugging. */ | |
57 | #define PVR2_SUBSYS_B_ENC_FIRMWARE 0 | |
58 | #define PVR2_SUBSYS_B_ENC_CFG 1 | |
59 | #define PVR2_SUBSYS_B_DIGITIZER_RUN 2 | |
60 | #define PVR2_SUBSYS_B_USBSTREAM_RUN 3 | |
61 | #define PVR2_SUBSYS_B_ENC_RUN 4 | |
62 | ||
63 | #define PVR2_SUBSYS_CFG_ALL ( \ | |
64 | (1 << PVR2_SUBSYS_B_ENC_FIRMWARE) | \ | |
65 | (1 << PVR2_SUBSYS_B_ENC_CFG) ) | |
66 | #define PVR2_SUBSYS_RUN_ALL ( \ | |
67 | (1 << PVR2_SUBSYS_B_DIGITIZER_RUN) | \ | |
68 | (1 << PVR2_SUBSYS_B_USBSTREAM_RUN) | \ | |
69 | (1 << PVR2_SUBSYS_B_ENC_RUN) ) | |
70 | #define PVR2_SUBSYS_ALL ( \ | |
71 | PVR2_SUBSYS_CFG_ALL | \ | |
72 | PVR2_SUBSYS_RUN_ALL ) | |
73 | ||
74 | enum pvr2_config { | |
16eb40d3 MI |
75 | pvr2_config_empty, /* No configuration */ |
76 | pvr2_config_mpeg, /* Encoded / compressed video */ | |
77 | pvr2_config_vbi, /* Standard vbi info */ | |
78 | pvr2_config_pcm, /* Audio raw pcm stream */ | |
79 | pvr2_config_rawvideo, /* Video raw frames */ | |
d855497e MI |
80 | }; |
81 | ||
8079384e MI |
82 | enum pvr2_v4l_type { |
83 | pvr2_v4l_type_video, | |
84 | pvr2_v4l_type_vbi, | |
85 | pvr2_v4l_type_radio, | |
86 | }; | |
87 | ||
d855497e MI |
88 | const char *pvr2_config_get_name(enum pvr2_config); |
89 | ||
90 | struct pvr2_hdw; | |
91 | ||
92 | /* Create and return a structure for interacting with the underlying | |
93 | hardware */ | |
94 | struct pvr2_hdw *pvr2_hdw_create(struct usb_interface *intf, | |
95 | const struct usb_device_id *devid); | |
96 | ||
97 | /* Poll for background activity (if any) */ | |
98 | void pvr2_hdw_poll(struct pvr2_hdw *); | |
99 | ||
100 | /* Trigger a poll to take place later at a convenient time */ | |
d855497e MI |
101 | void pvr2_hdw_poll_trigger_unlocked(struct pvr2_hdw *); |
102 | ||
103 | /* Register a callback used to trigger a future poll */ | |
104 | void pvr2_hdw_setup_poll_trigger(struct pvr2_hdw *, | |
105 | void (*func)(void *), | |
106 | void *data); | |
107 | ||
d855497e MI |
108 | /* Destroy hardware interaction structure */ |
109 | void pvr2_hdw_destroy(struct pvr2_hdw *); | |
110 | ||
111 | /* Set up the structure and attempt to put the device into a usable state. | |
112 | This can be a time-consuming operation, which is why it is not done | |
113 | internally as part of the create() step. Return value is exactly the | |
114 | same as pvr2_hdw_init_ok(). */ | |
115 | int pvr2_hdw_setup(struct pvr2_hdw *); | |
116 | ||
117 | /* Initialization succeeded */ | |
118 | int pvr2_hdw_init_ok(struct pvr2_hdw *); | |
119 | ||
120 | /* Return true if in the ready (normal) state */ | |
121 | int pvr2_hdw_dev_ok(struct pvr2_hdw *); | |
122 | ||
123 | /* Return small integer number [1..N] for logical instance number of this | |
124 | device. This is useful for indexing array-valued module parameters. */ | |
125 | int pvr2_hdw_get_unit_number(struct pvr2_hdw *); | |
126 | ||
127 | /* Get pointer to underlying USB device */ | |
128 | struct usb_device *pvr2_hdw_get_dev(struct pvr2_hdw *); | |
129 | ||
130 | /* Retrieve serial number of device */ | |
131 | unsigned long pvr2_hdw_get_sn(struct pvr2_hdw *); | |
132 | ||
133 | /* Called when hardware has been unplugged */ | |
134 | void pvr2_hdw_disconnect(struct pvr2_hdw *); | |
135 | ||
136 | /* Get the number of defined controls */ | |
137 | unsigned int pvr2_hdw_get_ctrl_count(struct pvr2_hdw *); | |
138 | ||
139 | /* Retrieve a control handle given its index (0..count-1) */ | |
140 | struct pvr2_ctrl *pvr2_hdw_get_ctrl_by_index(struct pvr2_hdw *,unsigned int); | |
141 | ||
142 | /* Retrieve a control handle given its internal ID (if any) */ | |
143 | struct pvr2_ctrl *pvr2_hdw_get_ctrl_by_id(struct pvr2_hdw *,unsigned int); | |
144 | ||
145 | /* Retrieve a control handle given its V4L ID (if any) */ | |
146 | struct pvr2_ctrl *pvr2_hdw_get_ctrl_v4l(struct pvr2_hdw *,unsigned int ctl_id); | |
147 | ||
a761f431 MI |
148 | /* Retrieve a control handle given its immediate predecessor V4L ID (if any) */ |
149 | struct pvr2_ctrl *pvr2_hdw_get_ctrl_nextv4l(struct pvr2_hdw *, | |
150 | unsigned int ctl_id); | |
151 | ||
d855497e MI |
152 | /* Commit all control changes made up to this point */ |
153 | int pvr2_hdw_commit_ctl(struct pvr2_hdw *); | |
154 | ||
155 | /* Return name for this driver instance */ | |
156 | const char *pvr2_hdw_get_driver_name(struct pvr2_hdw *); | |
157 | ||
158 | /* Return PVR2_SIGNAL_XXXX bit mask indicating signal status */ | |
159 | unsigned int pvr2_hdw_get_signal_status(struct pvr2_hdw *); | |
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 | ||
d855497e MI |
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 | ||
2fdf3d9c | 215 | /* Retrieve a previously stored v4l minor device number */ |
8079384e | 216 | int pvr2_hdw_v4l_get_minor_number(struct pvr2_hdw *,enum pvr2_v4l_type index); |
d855497e | 217 | |
2fdf3d9c | 218 | /* Store a v4l minor device number */ |
fd5a75fe | 219 | void pvr2_hdw_v4l_store_minor_number(struct pvr2_hdw *, |
8079384e | 220 | enum pvr2_v4l_type index,int); |
d855497e | 221 | |
32ffa9ae MI |
222 | /* Direct read/write access to chip's registers: |
223 | chip_id - unique id of chip (e.g. I2C_DRIVERD_xxxx) | |
224 | reg_id - register number to access | |
225 | setFl - true to set the register, false to read it | |
226 | val_ptr - storage location for source / result. */ | |
227 | int pvr2_hdw_register_access(struct pvr2_hdw *, | |
228 | u32 chip_id,unsigned long reg_id, | |
229 | int setFl,u32 *val_ptr); | |
d855497e MI |
230 | |
231 | /* The following entry points are all lower level things you normally don't | |
232 | want to worry about. */ | |
233 | ||
d855497e MI |
234 | /* Issue a command and get a response from the device. LOTS of higher |
235 | level stuff is built on this. */ | |
236 | int pvr2_send_request(struct pvr2_hdw *, | |
237 | void *write_ptr,unsigned int write_len, | |
238 | void *read_ptr,unsigned int read_len); | |
239 | ||
d855497e MI |
240 | /* Slightly higher level device communication functions. */ |
241 | int pvr2_write_register(struct pvr2_hdw *, u16, u32); | |
d855497e MI |
242 | |
243 | /* Call if for any reason we can't talk to the hardware anymore - this will | |
244 | cause the driver to stop flailing on the device. */ | |
245 | void pvr2_hdw_render_useless(struct pvr2_hdw *); | |
d855497e MI |
246 | |
247 | /* Set / clear 8051's reset bit */ | |
248 | void pvr2_hdw_cpureset_assert(struct pvr2_hdw *,int); | |
249 | ||
250 | /* Execute a USB-commanded device reset */ | |
251 | void pvr2_hdw_device_reset(struct pvr2_hdw *); | |
252 | ||
253 | /* Execute hard reset command (after this point it's likely that the | |
254 | encoder will have to be reconfigured). This also clears the "useless" | |
255 | state. */ | |
256 | int pvr2_hdw_cmd_deep_reset(struct pvr2_hdw *); | |
257 | ||
258 | /* Execute simple reset command */ | |
259 | int pvr2_hdw_cmd_powerup(struct pvr2_hdw *); | |
260 | ||
261 | /* Order decoder to reset */ | |
262 | int pvr2_hdw_cmd_decoder_reset(struct pvr2_hdw *); | |
263 | ||
d855497e MI |
264 | /* Direct manipulation of GPIO bits */ |
265 | int pvr2_hdw_gpio_get_dir(struct pvr2_hdw *hdw,u32 *); | |
266 | int pvr2_hdw_gpio_get_out(struct pvr2_hdw *hdw,u32 *); | |
267 | int pvr2_hdw_gpio_get_in(struct pvr2_hdw *hdw,u32 *); | |
268 | int pvr2_hdw_gpio_chg_dir(struct pvr2_hdw *hdw,u32 msk,u32 val); | |
269 | int pvr2_hdw_gpio_chg_out(struct pvr2_hdw *hdw,u32 msk,u32 val); | |
270 | ||
271 | /* This data structure is specifically for the next function... */ | |
272 | struct pvr2_hdw_debug_info { | |
273 | int big_lock_held; | |
274 | int ctl_lock_held; | |
275 | int flag_ok; | |
276 | int flag_disconnected; | |
277 | int flag_init_ok; | |
278 | int flag_streaming_enabled; | |
279 | unsigned long subsys_flags; | |
280 | int cmd_debug_state; | |
281 | int cmd_debug_write_len; | |
282 | int cmd_debug_read_len; | |
283 | int cmd_debug_write_pend; | |
284 | int cmd_debug_read_pend; | |
285 | int cmd_debug_timeout; | |
286 | int cmd_debug_rstatus; | |
287 | int cmd_debug_wstatus; | |
288 | unsigned char cmd_code; | |
289 | }; | |
290 | ||
291 | /* Non-intrusively retrieve internal state info - this is useful for | |
292 | diagnosing lockups. Note that this operation is completed without any | |
293 | kind of locking and so it is not atomic and may yield inconsistent | |
294 | results. This is *purely* a debugging aid. */ | |
295 | void pvr2_hdw_get_debug_info(const struct pvr2_hdw *hdw, | |
296 | struct pvr2_hdw_debug_info *); | |
297 | ||
298 | /* Cause modules to log their state once */ | |
299 | void pvr2_hdw_trigger_module_log(struct pvr2_hdw *hdw); | |
300 | ||
301 | /* Cause encoder firmware to be uploaded into the device. This is normally | |
302 | done autonomously, but the interface is exported here because it is also | |
303 | a debugging aid. */ | |
304 | int pvr2_upload_firmware2(struct pvr2_hdw *hdw); | |
305 | ||
306 | /* List of device types that we can match */ | |
307 | extern struct usb_device_id pvr2_device_table[]; | |
308 | ||
309 | #endif /* __PVRUSB2_HDW_H */ | |
310 | ||
311 | /* | |
312 | Stuff for Emacs to see, in order to encourage consistent editing style: | |
313 | *** Local Variables: *** | |
314 | *** mode: c *** | |
315 | *** fill-column: 75 *** | |
316 | *** tab-width: 8 *** | |
317 | *** c-basic-offset: 8 *** | |
318 | *** End: *** | |
319 | */ |