Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 1 | /* dvb-usb.h is part of the DVB USB library. |
| 2 | * |
| 3 | * Copyright (C) 2004-5 Patrick Boettcher (patrick.boettcher@desy.de) |
| 4 | * see dvb-usb-init.c for copyright information. |
| 5 | * |
| 6 | * the headerfile, all dvb-usb-drivers have to include. |
| 7 | */ |
| 8 | #ifndef __DVB_USB_H__ |
| 9 | #define __DVB_USB_H__ |
| 10 | |
| 11 | #include <linux/config.h> |
| 12 | #include <linux/input.h> |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 13 | #include <linux/usb.h> |
Patrick Boettcher | d3707ad | 2006-01-09 15:25:04 -0200 | [diff] [blame] | 14 | #include <linux/firmware.h> |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 15 | |
| 16 | #include "dvb_frontend.h" |
| 17 | #include "dvb_demux.h" |
| 18 | #include "dvb_net.h" |
| 19 | #include "dmxdev.h" |
| 20 | |
| 21 | #include "dvb-pll.h" |
| 22 | |
| 23 | #include "dvb-usb-ids.h" |
| 24 | |
| 25 | /* debug */ |
| 26 | #ifdef CONFIG_DVB_USB_DEBUG |
| 27 | #define dprintk(var,level,args...) \ |
| 28 | do { if ((var & level)) { printk(args); } } while (0) |
| 29 | |
| 30 | #define debug_dump(b,l,func) {\ |
| 31 | int loop_; \ |
| 32 | for (loop_ = 0; loop_ < l; loop_++) func("%02x ", b[loop_]); \ |
| 33 | func("\n");\ |
| 34 | } |
| 35 | #define DVB_USB_DEBUG_STATUS |
| 36 | #else |
| 37 | #define dprintk(args...) |
| 38 | #define debug_dump(b,l,func) |
| 39 | |
| 40 | #define DVB_USB_DEBUG_STATUS " (debugging is not enabled)" |
| 41 | |
| 42 | #endif |
| 43 | |
| 44 | /* generic log methods - taken from usb.h */ |
| 45 | #ifndef DVB_USB_LOG_PREFIX |
| 46 | #define DVB_USB_LOG_PREFIX "dvb-usb (please define a log prefix)" |
| 47 | #endif |
| 48 | |
| 49 | #undef err |
| 50 | #define err(format, arg...) printk(KERN_ERR DVB_USB_LOG_PREFIX ": " format "\n" , ## arg) |
| 51 | #undef info |
| 52 | #define info(format, arg...) printk(KERN_INFO DVB_USB_LOG_PREFIX ": " format "\n" , ## arg) |
| 53 | #undef warn |
| 54 | #define warn(format, arg...) printk(KERN_WARNING DVB_USB_LOG_PREFIX ": " format "\n" , ## arg) |
| 55 | |
| 56 | /** |
| 57 | * struct dvb_usb_device_description - name and its according USB IDs |
| 58 | * @name: real name of the box, regardless which DVB USB device class is in use |
| 59 | * @cold_ids: array of struct usb_device_id which describe the device in |
| 60 | * pre-firmware state |
| 61 | * @warm_ids: array of struct usb_device_id which describe the device in |
| 62 | * post-firmware state |
| 63 | * |
| 64 | * Each DVB USB device class can have one or more actual devices, this struct |
| 65 | * assigns a name to it. |
| 66 | */ |
| 67 | struct dvb_usb_device_description { |
| 68 | const char *name; |
| 69 | |
| 70 | #define DVB_USB_ID_MAX_NUM 15 |
| 71 | struct usb_device_id *cold_ids[DVB_USB_ID_MAX_NUM]; |
| 72 | struct usb_device_id *warm_ids[DVB_USB_ID_MAX_NUM]; |
| 73 | }; |
| 74 | |
| 75 | /** |
| 76 | * struct dvb_usb_rc_key - a remote control key and its input-event |
| 77 | * @custom: the vendor/custom part of the key |
| 78 | * @data: the actual key part |
| 79 | * @event: the input event assigned to key identified by custom and data |
| 80 | */ |
| 81 | struct dvb_usb_rc_key { |
| 82 | u8 custom,data; |
| 83 | u32 event; |
| 84 | }; |
| 85 | |
| 86 | struct dvb_usb_device; |
| 87 | |
| 88 | /** |
| 89 | * struct dvb_usb_properties - properties of a dvb-usb-device |
| 90 | * @caps: capabilites of the DVB USB device. |
| 91 | * @pid_filter_count: number of PID filter position in the optional hardware |
| 92 | * PID-filter. |
| 93 | * |
| 94 | * @usb_ctrl: which USB device-side controller is in use. Needed for firmware |
| 95 | * download. |
| 96 | * @firmware: name of the firmware file. |
Patrick Boettcher | d3707ad | 2006-01-09 15:25:04 -0200 | [diff] [blame] | 97 | * @download_firmware: called to download the firmware when the usb_ctrl is |
| 98 | * DEVICE_SPECIFIC. |
| 99 | * @no_reconnect: device doesn't do a reconnect after downloading the firmware, |
| 100 | so do the warm initialization right after it |
| 101 | |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 102 | * @size_of_priv: how many bytes shall be allocated for the private field |
| 103 | * of struct dvb_usb_device. |
| 104 | * |
| 105 | * @power_ctrl: called to enable/disable power of the device. |
| 106 | * @streaming_crtl: called to start and stop the MPEG2-TS streaming of the |
| 107 | * device (not URB submitting/killing). |
| 108 | * @pid_filter_ctrl: called to en/disable the PID filter, if any. |
| 109 | * @pid_filter: called to set/unset a PID for filtering. |
| 110 | * |
| 111 | * @read_mac_address: called to read the MAC address of the device. |
| 112 | * |
| 113 | * @frontend_attach: called to attach the possible frontends (fill fe-field |
| 114 | * of struct dvb_usb_device). |
| 115 | * @tuner_attach: called to attach the correct tuner and to fill pll_addr, |
| 116 | * pll_desc and pll_init_buf of struct dvb_usb_device). |
| 117 | * @identify_state: called to determine the state (cold or warm), when it |
| 118 | * is not distinguishable by the USB IDs. |
| 119 | * |
| 120 | * @rc_key_map: a hard-wired array of struct dvb_usb_rc_key (NULL to disable |
| 121 | * remote control handling). |
| 122 | * @rc_key_map_size: number of items in @rc_key_map. |
| 123 | * @rc_query: called to query an event event. |
| 124 | * @rc_interval: time in ms between two queries. |
| 125 | * |
| 126 | * @i2c_algo: i2c_algorithm if the device has I2CoverUSB. |
| 127 | * |
| 128 | * @generic_bulk_ctrl_endpoint: most of the DVB USB devices have a generic |
| 129 | * endpoint which received control messages with bulk transfers. When this |
| 130 | * is non-zero, one can use dvb_usb_generic_rw and dvb_usb_generic_write- |
| 131 | * helper functions. |
| 132 | * |
| 133 | * @urb: describes the kind of USB transfer used for MPEG2-TS-streaming. |
Patrick Boettcher | 47dc3d6 | 2005-09-09 13:02:47 -0700 | [diff] [blame] | 134 | * (BULK or ISOC) |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 135 | * |
| 136 | * @num_device_descs: number of struct dvb_usb_device_description in @devices |
| 137 | * @devices: array of struct dvb_usb_device_description compatibles with these |
| 138 | * properties. |
| 139 | */ |
| 140 | struct dvb_usb_properties { |
| 141 | |
| 142 | #define DVB_USB_HAS_PID_FILTER 0x01 |
| 143 | #define DVB_USB_PID_FILTER_CAN_BE_TURNED_OFF 0x02 |
| 144 | #define DVB_USB_NEED_PID_FILTERING 0x04 |
| 145 | #define DVB_USB_IS_AN_I2C_ADAPTER 0x08 |
| 146 | int caps; |
| 147 | int pid_filter_count; |
| 148 | |
Patrick Boettcher | d3707ad | 2006-01-09 15:25:04 -0200 | [diff] [blame] | 149 | #define DEVICE_SPECIFIC 0 |
| 150 | #define CYPRESS_AN2135 1 |
| 151 | #define CYPRESS_AN2235 2 |
| 152 | #define CYPRESS_FX2 3 |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 153 | int usb_ctrl; |
Patrick Boettcher | d3707ad | 2006-01-09 15:25:04 -0200 | [diff] [blame] | 154 | const char firmware[FIRMWARE_NAME_MAX]; |
| 155 | int (*download_firmware) (struct usb_device *, const struct firmware *); |
| 156 | int no_reconnect; |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 157 | |
| 158 | int size_of_priv; |
| 159 | |
| 160 | int (*power_ctrl) (struct dvb_usb_device *, int); |
| 161 | int (*streaming_ctrl) (struct dvb_usb_device *, int); |
| 162 | int (*pid_filter_ctrl) (struct dvb_usb_device *, int); |
| 163 | int (*pid_filter) (struct dvb_usb_device *, int, u16, int); |
| 164 | |
| 165 | int (*read_mac_address) (struct dvb_usb_device *, u8 []); |
| 166 | int (*frontend_attach) (struct dvb_usb_device *); |
| 167 | int (*tuner_attach) (struct dvb_usb_device *); |
| 168 | |
| 169 | int (*identify_state) (struct usb_device *, struct dvb_usb_properties *, |
| 170 | struct dvb_usb_device_description **, int *); |
| 171 | |
| 172 | /* remote control properties */ |
| 173 | #define REMOTE_NO_KEY_PRESSED 0x00 |
| 174 | #define REMOTE_KEY_PRESSED 0x01 |
| 175 | #define REMOTE_KEY_REPEAT 0x02 |
| 176 | struct dvb_usb_rc_key *rc_key_map; |
| 177 | int rc_key_map_size; |
| 178 | int (*rc_query) (struct dvb_usb_device *, u32 *, int *); |
| 179 | int rc_interval; |
| 180 | |
| 181 | struct i2c_algorithm *i2c_algo; |
| 182 | |
| 183 | int generic_bulk_ctrl_endpoint; |
| 184 | |
| 185 | struct { |
| 186 | #define DVB_USB_BULK 1 |
| 187 | #define DVB_USB_ISOC 2 |
| 188 | int type; |
| 189 | int count; |
| 190 | int endpoint; |
| 191 | |
| 192 | union { |
| 193 | struct { |
| 194 | int buffersize; /* per URB */ |
| 195 | } bulk; |
| 196 | struct { |
| 197 | int framesperurb; |
| 198 | int framesize; |
Patrick Boettcher | 7f5fee5 | 2005-07-07 17:58:08 -0700 | [diff] [blame] | 199 | int interval; |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 200 | } isoc; |
| 201 | } u; |
| 202 | } urb; |
| 203 | |
| 204 | int num_device_descs; |
Patrick Boettcher | 2f7f96b | 2005-07-07 17:58:16 -0700 | [diff] [blame] | 205 | struct dvb_usb_device_description devices[9]; |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 206 | }; |
| 207 | |
| 208 | |
| 209 | /** |
| 210 | * struct dvb_usb_device - object of a DVB USB device |
| 211 | * @props: copy of the struct dvb_usb_properties this device belongs to. |
| 212 | * @desc: pointer to the device's struct dvb_usb_device_description. |
| 213 | * @state: initialization and runtime state of the device. |
| 214 | * |
| 215 | * @udev: pointer to the device's struct usb_device. |
| 216 | * @urb_list: array of dynamically allocated struct urb for the MPEG2-TS- |
| 217 | * streaming. |
Patrick Boettcher | 7f5fee5 | 2005-07-07 17:58:08 -0700 | [diff] [blame] | 218 | * |
| 219 | * @buf_num: number of buffer allocated. |
| 220 | * @buf_size: size of each buffer in buf_list. |
| 221 | * @buf_list: array containing all allocate buffers for streaming. |
| 222 | * @dma_addr: list of dma_addr_t for each buffer in buf_list. |
| 223 | * |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 224 | * @urbs_initialized: number of URBs initialized. |
| 225 | * @urbs_submitted: number of URBs submitted. |
Patrick Boettcher | 7f5fee5 | 2005-07-07 17:58:08 -0700 | [diff] [blame] | 226 | * |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 227 | * @feedcount: number of reqested feeds (used for streaming-activation) |
| 228 | * @pid_filtering: is hardware pid_filtering used or not. |
Patrick Boettcher | 7f5fee5 | 2005-07-07 17:58:08 -0700 | [diff] [blame] | 229 | * |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 230 | * @usb_sem: semaphore of USB control messages (reading needs two messages) |
| 231 | * @i2c_sem: semaphore for i2c-transfers |
Patrick Boettcher | 7f5fee5 | 2005-07-07 17:58:08 -0700 | [diff] [blame] | 232 | * |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 233 | * @i2c_adap: device's i2c_adapter if it uses I2CoverUSB |
| 234 | * @pll_addr: I2C address of the tuner for programming |
| 235 | * @pll_init: array containing the initialization buffer |
| 236 | * @pll_desc: pointer to the appropriate struct dvb_pll_desc |
Patrick Boettcher | 7f5fee5 | 2005-07-07 17:58:08 -0700 | [diff] [blame] | 237 | * |
| 238 | * @tuner_pass_ctrl: called to (de)activate tuner passthru of the demod or the board |
| 239 | * |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 240 | * @dvb_adap: device's dvb_adapter. |
| 241 | * @dmxdev: device's dmxdev. |
| 242 | * @demux: device's software demuxer. |
| 243 | * @dvb_net: device's dvb_net interfaces. |
| 244 | * @dvb_frontend: device's frontend. |
| 245 | * @max_feed_count: how many feeds can be handled simultaneously by this |
| 246 | * device |
| 247 | * @fe_sleep: rerouted frontend-sleep function. |
| 248 | * @fe_init: rerouted frontend-init (wakeup) function. |
| 249 | * @rc_input_dev: input device for the remote control. |
| 250 | * @rc_query_work: struct work_struct frequent rc queries |
| 251 | * @last_event: last triggered event |
| 252 | * @last_state: last state (no, pressed, repeat) |
| 253 | * @owner: owner of the dvb_adapter |
| 254 | * @priv: private data of the actual driver (allocate by dvb-usb, size defined |
| 255 | * in size_of_priv of dvb_usb_properties). |
| 256 | */ |
| 257 | struct dvb_usb_device { |
| 258 | struct dvb_usb_properties props; |
| 259 | struct dvb_usb_device_description *desc; |
| 260 | |
| 261 | #define DVB_USB_STATE_INIT 0x000 |
| 262 | #define DVB_USB_STATE_URB_LIST 0x001 |
| 263 | #define DVB_USB_STATE_URB_BUF 0x002 |
| 264 | #define DVB_USB_STATE_DVB 0x004 |
| 265 | #define DVB_USB_STATE_I2C 0x008 |
| 266 | #define DVB_USB_STATE_REMOTE 0x010 |
| 267 | #define DVB_USB_STATE_URB_SUBMIT 0x020 |
| 268 | int state; |
| 269 | |
| 270 | /* usb */ |
| 271 | struct usb_device *udev; |
| 272 | struct urb **urb_list; |
Patrick Boettcher | 7f5fee5 | 2005-07-07 17:58:08 -0700 | [diff] [blame] | 273 | |
| 274 | int buf_num; |
| 275 | unsigned long buf_size; |
| 276 | u8 **buf_list; |
| 277 | dma_addr_t *dma_addr; |
| 278 | |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 279 | int urbs_initialized; |
| 280 | int urbs_submitted; |
| 281 | |
| 282 | int feedcount; |
| 283 | int pid_filtering; |
| 284 | |
| 285 | /* locking */ |
| 286 | struct semaphore usb_sem; |
| 287 | |
| 288 | /* i2c */ |
| 289 | struct semaphore i2c_sem; |
| 290 | struct i2c_adapter i2c_adap; |
| 291 | |
| 292 | /* tuner programming information */ |
| 293 | u8 pll_addr; |
| 294 | u8 pll_init[4]; |
| 295 | struct dvb_pll_desc *pll_desc; |
| 296 | int (*tuner_pass_ctrl)(struct dvb_frontend *, int, u8); |
| 297 | |
| 298 | /* dvb */ |
| 299 | struct dvb_adapter dvb_adap; |
| 300 | struct dmxdev dmxdev; |
| 301 | struct dvb_demux demux; |
| 302 | struct dvb_net dvb_net; |
| 303 | struct dvb_frontend* fe; |
| 304 | int max_feed_count; |
| 305 | |
| 306 | int (*fe_sleep) (struct dvb_frontend *); |
| 307 | int (*fe_init) (struct dvb_frontend *); |
| 308 | |
| 309 | /* remote control */ |
Dmitry Torokhov | b7df391 | 2005-09-15 02:01:53 -0500 | [diff] [blame] | 310 | struct input_dev *rc_input_dev; |
| 311 | char rc_phys[64]; |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 312 | struct work_struct rc_query_work; |
| 313 | u32 last_event; |
| 314 | int last_state; |
| 315 | |
| 316 | struct module *owner; |
| 317 | |
| 318 | void *priv; |
| 319 | }; |
| 320 | |
Patrick Boettcher | 47dc3d6 | 2005-09-09 13:02:47 -0700 | [diff] [blame] | 321 | extern int dvb_usb_device_init(struct usb_interface *, struct dvb_usb_properties *, struct module *, struct dvb_usb_device **); |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 322 | extern void dvb_usb_device_exit(struct usb_interface *); |
| 323 | |
| 324 | /* the generic read/write method for device control */ |
| 325 | extern int dvb_usb_generic_rw(struct dvb_usb_device *, u8 *, u16, u8 *, u16,int); |
| 326 | extern int dvb_usb_generic_write(struct dvb_usb_device *, u8 *, u16); |
| 327 | |
| 328 | /* commonly used remote control parsing */ |
| 329 | extern int dvb_usb_nec_rc_key_to_event(struct dvb_usb_device *, u8[], u32 *, int *); |
| 330 | |
| 331 | /* commonly used pll init and set functions */ |
| 332 | extern int dvb_usb_pll_init_i2c(struct dvb_frontend *); |
| 333 | extern int dvb_usb_pll_set(struct dvb_frontend *, struct dvb_frontend_parameters *, u8[]); |
| 334 | extern int dvb_usb_pll_set_i2c(struct dvb_frontend *, struct dvb_frontend_parameters *); |
| 335 | |
Patrick Boettcher | d3707ad | 2006-01-09 15:25:04 -0200 | [diff] [blame] | 336 | /* commonly used firmware download types and function */ |
| 337 | struct hexline { |
| 338 | u8 len; |
| 339 | u32 addr; |
| 340 | u8 type; |
| 341 | u8 data[255]; |
| 342 | u8 chk; |
| 343 | }; |
| 344 | extern int dvb_usb_get_hexline(const struct firmware *, struct hexline *, int *); |
Patrick Boettcher | f537378 | 2006-01-09 18:21:38 -0200 | [diff] [blame] | 345 | extern int usb_cypress_load_firmware(struct usb_device *udev, const struct firmware *fw, int type); |
Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 346 | |
| 347 | #endif |