Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 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 | |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 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 |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 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 | |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 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 { |
Mike Isely | 16eb40d | 2006-12-30 18:27:32 -0300 | [diff] [blame] | 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 */ |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 74 | }; |
| 75 | |
Mike Isely | 8079384 | 2006-12-27 23:12:28 -0300 | [diff] [blame] | 76 | enum pvr2_v4l_type { |
| 77 | pvr2_v4l_type_video, |
| 78 | pvr2_v4l_type_vbi, |
| 79 | pvr2_v4l_type_radio, |
| 80 | }; |
| 81 | |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 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 */ |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 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 | |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 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 | /* Called when hardware has been unplugged */ |
| 128 | void pvr2_hdw_disconnect(struct pvr2_hdw *); |
| 129 | |
| 130 | /* Get the number of defined controls */ |
| 131 | unsigned int pvr2_hdw_get_ctrl_count(struct pvr2_hdw *); |
| 132 | |
| 133 | /* Retrieve a control handle given its index (0..count-1) */ |
| 134 | struct pvr2_ctrl *pvr2_hdw_get_ctrl_by_index(struct pvr2_hdw *,unsigned int); |
| 135 | |
| 136 | /* Retrieve a control handle given its internal ID (if any) */ |
| 137 | struct pvr2_ctrl *pvr2_hdw_get_ctrl_by_id(struct pvr2_hdw *,unsigned int); |
| 138 | |
| 139 | /* Retrieve a control handle given its V4L ID (if any) */ |
| 140 | struct pvr2_ctrl *pvr2_hdw_get_ctrl_v4l(struct pvr2_hdw *,unsigned int ctl_id); |
| 141 | |
Mike Isely | a761f43 | 2006-06-25 20:04:44 -0300 | [diff] [blame] | 142 | /* Retrieve a control handle given its immediate predecessor V4L ID (if any) */ |
| 143 | struct pvr2_ctrl *pvr2_hdw_get_ctrl_nextv4l(struct pvr2_hdw *, |
| 144 | unsigned int ctl_id); |
| 145 | |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 146 | /* Commit all control changes made up to this point */ |
| 147 | int pvr2_hdw_commit_ctl(struct pvr2_hdw *); |
| 148 | |
| 149 | /* Return name for this driver instance */ |
| 150 | const char *pvr2_hdw_get_driver_name(struct pvr2_hdw *); |
| 151 | |
Mike Isely | 18103c57 | 2007-01-20 00:09:47 -0300 | [diff] [blame] | 152 | /* Mark tuner status stale so that it will be re-fetched */ |
| 153 | void pvr2_hdw_execute_tuner_poll(struct pvr2_hdw *); |
| 154 | |
| 155 | /* Return information about the tuner */ |
| 156 | int pvr2_hdw_get_tuner_status(struct pvr2_hdw *,struct v4l2_tuner *); |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 157 | |
| 158 | /* Query device and see if it thinks it is on a high-speed USB link */ |
| 159 | int pvr2_hdw_is_hsm(struct pvr2_hdw *); |
| 160 | |
| 161 | /* Turn streaming on/off */ |
| 162 | int pvr2_hdw_set_streaming(struct pvr2_hdw *,int); |
| 163 | |
| 164 | /* Find out if streaming is on */ |
| 165 | int pvr2_hdw_get_streaming(struct pvr2_hdw *); |
| 166 | |
| 167 | /* Configure the type of stream to generate */ |
| 168 | int pvr2_hdw_set_stream_type(struct pvr2_hdw *, enum pvr2_config); |
| 169 | |
| 170 | /* Get handle to video output stream */ |
| 171 | struct pvr2_stream *pvr2_hdw_get_video_stream(struct pvr2_hdw *); |
| 172 | |
| 173 | /* Emit a video standard struct */ |
| 174 | int pvr2_hdw_get_stdenum_value(struct pvr2_hdw *hdw,struct v4l2_standard *std, |
| 175 | unsigned int idx); |
| 176 | |
| 177 | /* Enable / disable various pieces of hardware. Items to change are |
| 178 | identified by bit positions within msk, and new state for each item is |
| 179 | identified by corresponding bit positions within val. */ |
| 180 | void pvr2_hdw_subsys_bit_chg(struct pvr2_hdw *hdw, |
| 181 | unsigned long msk,unsigned long val); |
| 182 | |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 183 | /* Retrieve mask indicating which pieces of hardware are currently enabled |
| 184 | / configured. */ |
| 185 | unsigned long pvr2_hdw_subsys_get(struct pvr2_hdw *); |
| 186 | |
| 187 | /* Adjust mask of what get shut down when streaming is stopped. This is a |
| 188 | debugging aid. */ |
| 189 | void pvr2_hdw_subsys_stream_bit_chg(struct pvr2_hdw *hdw, |
| 190 | unsigned long msk,unsigned long val); |
| 191 | |
| 192 | /* Retrieve mask indicating which pieces of hardware are disabled when |
| 193 | streaming is turned off. */ |
| 194 | unsigned long pvr2_hdw_subsys_stream_get(struct pvr2_hdw *); |
| 195 | |
| 196 | |
| 197 | /* Enable / disable retrieval of CPU firmware. This must be enabled before |
| 198 | pvr2_hdw_cpufw_get() will function. Note that doing this may prevent |
| 199 | the device from running (and leaving this mode may imply a device |
| 200 | reset). */ |
| 201 | void pvr2_hdw_cpufw_set_enabled(struct pvr2_hdw *, int enable_flag); |
| 202 | |
| 203 | /* Return true if we're in a mode for retrieval CPU firmware */ |
| 204 | int pvr2_hdw_cpufw_get_enabled(struct pvr2_hdw *); |
| 205 | |
| 206 | /* Retrieve a piece of the CPU's firmware at the given offset. Return |
| 207 | value is the number of bytes retrieved or zero if we're past the end or |
| 208 | an error otherwise (e.g. if firmware retrieval is not enabled). */ |
| 209 | int pvr2_hdw_cpufw_get(struct pvr2_hdw *,unsigned int offs, |
| 210 | char *buf,unsigned int cnt); |
| 211 | |
Pantelis Koukousoulas | 2fdf3d9 | 2006-12-27 23:07:58 -0300 | [diff] [blame] | 212 | /* Retrieve a previously stored v4l minor device number */ |
Mike Isely | 8079384 | 2006-12-27 23:12:28 -0300 | [diff] [blame] | 213 | int pvr2_hdw_v4l_get_minor_number(struct pvr2_hdw *,enum pvr2_v4l_type index); |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 214 | |
Pantelis Koukousoulas | 2fdf3d9 | 2006-12-27 23:07:58 -0300 | [diff] [blame] | 215 | /* Store a v4l minor device number */ |
Mike Isely | fd5a75f | 2006-12-27 23:11:22 -0300 | [diff] [blame] | 216 | void pvr2_hdw_v4l_store_minor_number(struct pvr2_hdw *, |
Mike Isely | 8079384 | 2006-12-27 23:12:28 -0300 | [diff] [blame] | 217 | enum pvr2_v4l_type index,int); |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 218 | |
Mike Isely | 32ffa9a | 2006-09-23 22:26:52 -0300 | [diff] [blame] | 219 | /* Direct read/write access to chip's registers: |
Hans Verkuil | f3d092b | 2007-02-23 20:55:14 -0300 | [diff] [blame] | 220 | match_type - how to interpret match_chip (e.g. driver ID, i2c address) |
| 221 | match_chip - chip match value (e.g. I2C_DRIVERD_xxxx) |
Mike Isely | 32ffa9a | 2006-09-23 22:26:52 -0300 | [diff] [blame] | 222 | reg_id - register number to access |
| 223 | setFl - true to set the register, false to read it |
| 224 | val_ptr - storage location for source / result. */ |
| 225 | int pvr2_hdw_register_access(struct pvr2_hdw *, |
Hans Verkuil | f3d092b | 2007-02-23 20:55:14 -0300 | [diff] [blame] | 226 | u32 match_type, u32 match_chip,u64 reg_id, |
| 227 | int setFl,u64 *val_ptr); |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 228 | |
| 229 | /* The following entry points are all lower level things you normally don't |
| 230 | want to worry about. */ |
| 231 | |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 232 | /* Issue a command and get a response from the device. LOTS of higher |
| 233 | level stuff is built on this. */ |
| 234 | int pvr2_send_request(struct pvr2_hdw *, |
| 235 | void *write_ptr,unsigned int write_len, |
| 236 | void *read_ptr,unsigned int read_len); |
| 237 | |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 238 | /* Slightly higher level device communication functions. */ |
| 239 | int pvr2_write_register(struct pvr2_hdw *, u16, u32); |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 240 | |
| 241 | /* Call if for any reason we can't talk to the hardware anymore - this will |
| 242 | cause the driver to stop flailing on the device. */ |
| 243 | void pvr2_hdw_render_useless(struct pvr2_hdw *); |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 244 | |
| 245 | /* Set / clear 8051's reset bit */ |
| 246 | void pvr2_hdw_cpureset_assert(struct pvr2_hdw *,int); |
| 247 | |
| 248 | /* Execute a USB-commanded device reset */ |
| 249 | void pvr2_hdw_device_reset(struct pvr2_hdw *); |
| 250 | |
| 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 *); |
| 255 | |
| 256 | /* Execute simple reset command */ |
| 257 | int pvr2_hdw_cmd_powerup(struct pvr2_hdw *); |
| 258 | |
| 259 | /* Order decoder to reset */ |
| 260 | int pvr2_hdw_cmd_decoder_reset(struct pvr2_hdw *); |
| 261 | |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 262 | /* Direct manipulation of GPIO bits */ |
| 263 | int pvr2_hdw_gpio_get_dir(struct pvr2_hdw *hdw,u32 *); |
| 264 | int pvr2_hdw_gpio_get_out(struct pvr2_hdw *hdw,u32 *); |
| 265 | int pvr2_hdw_gpio_get_in(struct pvr2_hdw *hdw,u32 *); |
| 266 | int pvr2_hdw_gpio_chg_dir(struct pvr2_hdw *hdw,u32 msk,u32 val); |
| 267 | int pvr2_hdw_gpio_chg_out(struct pvr2_hdw *hdw,u32 msk,u32 val); |
| 268 | |
| 269 | /* This data structure is specifically for the next function... */ |
| 270 | struct pvr2_hdw_debug_info { |
| 271 | int big_lock_held; |
| 272 | int ctl_lock_held; |
| 273 | int flag_ok; |
| 274 | int flag_disconnected; |
| 275 | int flag_init_ok; |
| 276 | int flag_streaming_enabled; |
| 277 | unsigned long subsys_flags; |
| 278 | int cmd_debug_state; |
| 279 | int cmd_debug_write_len; |
| 280 | int cmd_debug_read_len; |
| 281 | int cmd_debug_write_pend; |
| 282 | int cmd_debug_read_pend; |
| 283 | int cmd_debug_timeout; |
| 284 | int cmd_debug_rstatus; |
| 285 | int cmd_debug_wstatus; |
| 286 | unsigned char cmd_code; |
| 287 | }; |
| 288 | |
| 289 | /* Non-intrusively retrieve internal state info - this is useful for |
| 290 | diagnosing lockups. Note that this operation is completed without any |
| 291 | kind of locking and so it is not atomic and may yield inconsistent |
| 292 | results. This is *purely* a debugging aid. */ |
| 293 | void pvr2_hdw_get_debug_info(const struct pvr2_hdw *hdw, |
| 294 | struct pvr2_hdw_debug_info *); |
| 295 | |
| 296 | /* Cause modules to log their state once */ |
| 297 | void pvr2_hdw_trigger_module_log(struct pvr2_hdw *hdw); |
| 298 | |
| 299 | /* Cause encoder firmware to be uploaded into the device. This is normally |
| 300 | done autonomously, but the interface is exported here because it is also |
| 301 | a debugging aid. */ |
| 302 | int pvr2_upload_firmware2(struct pvr2_hdw *hdw); |
| 303 | |
| 304 | /* List of device types that we can match */ |
| 305 | extern struct usb_device_id pvr2_device_table[]; |
| 306 | |
| 307 | #endif /* __PVRUSB2_HDW_H */ |
| 308 | |
| 309 | /* |
| 310 | Stuff for Emacs to see, in order to encourage consistent editing style: |
| 311 | *** Local Variables: *** |
| 312 | *** mode: c *** |
| 313 | *** fill-column: 75 *** |
| 314 | *** tab-width: 8 *** |
| 315 | *** c-basic-offset: 8 *** |
| 316 | *** End: *** |
| 317 | */ |