Path: blob/master/drivers/media/dvb/dvb-usb/dvb-usb.h
15111 views
/* dvb-usb.h is part of the DVB USB library.1*2* Copyright (C) 2004-6 Patrick Boettcher ([email protected])3* see dvb-usb-init.c for copyright information.4*5* the headerfile, all dvb-usb-drivers have to include.6*7* TODO: clean-up the structures for unused fields and update the comments8*/9#ifndef __DVB_USB_H__10#define __DVB_USB_H__1112#include <linux/input.h>13#include <linux/usb.h>14#include <linux/firmware.h>15#include <linux/mutex.h>16#include <media/rc-core.h>1718#include "dvb_frontend.h"19#include "dvb_demux.h"20#include "dvb_net.h"21#include "dmxdev.h"2223#include "dvb-pll.h"2425#include "dvb-usb-ids.h"2627/* debug */28#ifdef CONFIG_DVB_USB_DEBUG29#define dprintk(var,level,args...) \30do { if ((var & level)) { printk(args); } } while (0)3132#define debug_dump(b,l,func) {\33int loop_; \34for (loop_ = 0; loop_ < l; loop_++) func("%02x ", b[loop_]); \35func("\n");\36}37#define DVB_USB_DEBUG_STATUS38#else39#define dprintk(args...)40#define debug_dump(b,l,func)4142#define DVB_USB_DEBUG_STATUS " (debugging is not enabled)"4344#endif4546/* generic log methods - taken from usb.h */47#ifndef DVB_USB_LOG_PREFIX48#define DVB_USB_LOG_PREFIX "dvb-usb (please define a log prefix)"49#endif5051#undef err52#define err(format, arg...) printk(KERN_ERR DVB_USB_LOG_PREFIX ": " format "\n" , ## arg)53#undef info54#define info(format, arg...) printk(KERN_INFO DVB_USB_LOG_PREFIX ": " format "\n" , ## arg)55#undef warn56#define warn(format, arg...) printk(KERN_WARNING DVB_USB_LOG_PREFIX ": " format "\n" , ## arg)5758/**59* struct dvb_usb_device_description - name and its according USB IDs60* @name: real name of the box, regardless which DVB USB device class is in use61* @cold_ids: array of struct usb_device_id which describe the device in62* pre-firmware state63* @warm_ids: array of struct usb_device_id which describe the device in64* post-firmware state65*66* Each DVB USB device class can have one or more actual devices, this struct67* assigns a name to it.68*/69struct dvb_usb_device_description {70const char *name;7172#define DVB_USB_ID_MAX_NUM 1573struct usb_device_id *cold_ids[DVB_USB_ID_MAX_NUM];74struct usb_device_id *warm_ids[DVB_USB_ID_MAX_NUM];75};7677static inline u8 rc5_custom(struct rc_map_table *key)78{79return (key->scancode >> 8) & 0xff;80}8182static inline u8 rc5_data(struct rc_map_table *key)83{84return key->scancode & 0xff;85}8687static inline u8 rc5_scan(struct rc_map_table *key)88{89return key->scancode & 0xffff;90}9192struct dvb_usb_device;93struct dvb_usb_adapter;94struct usb_data_stream;9596/**97* Properties of USB streaming - TODO this structure should be somewhere else98* describes the kind of USB transfer used for data-streaming.99* (BULK or ISOC)100*/101struct usb_data_stream_properties {102#define USB_BULK 1103#define USB_ISOC 2104int type;105int count;106int endpoint;107108union {109struct {110int buffersize; /* per URB */111} bulk;112struct {113int framesperurb;114int framesize;115int interval;116} isoc;117} u;118};119120/**121* struct dvb_usb_adapter_properties - properties of a dvb-usb-adapter.122* A DVB-USB-Adapter is basically a dvb_adapter which is present on a USB-device.123* @caps: capabilities of the DVB USB device.124* @pid_filter_count: number of PID filter position in the optional hardware125* PID-filter.126* @streaming_ctrl: called to start and stop the MPEG2-TS streaming of the127* device (not URB submitting/killing).128* @pid_filter_ctrl: called to en/disable the PID filter, if any.129* @pid_filter: called to set/unset a PID for filtering.130* @frontend_attach: called to attach the possible frontends (fill fe-field131* of struct dvb_usb_device).132* @tuner_attach: called to attach the correct tuner and to fill pll_addr,133* pll_desc and pll_init_buf of struct dvb_usb_device).134* @stream: configuration of the USB streaming135*/136struct dvb_usb_adapter_properties {137#define DVB_USB_ADAP_HAS_PID_FILTER 0x01138#define DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF 0x02139#define DVB_USB_ADAP_NEED_PID_FILTERING 0x04140#define DVB_USB_ADAP_RECEIVES_204_BYTE_TS 0x08141int caps;142int pid_filter_count;143144int (*streaming_ctrl) (struct dvb_usb_adapter *, int);145int (*pid_filter_ctrl) (struct dvb_usb_adapter *, int);146int (*pid_filter) (struct dvb_usb_adapter *, int, u16, int);147148int (*frontend_attach) (struct dvb_usb_adapter *);149int (*tuner_attach) (struct dvb_usb_adapter *);150151struct usb_data_stream_properties stream;152153int size_of_priv;154155int (*fe_ioctl_override) (struct dvb_frontend *,156unsigned int, void *, unsigned int);157};158159/**160* struct dvb_rc_legacy - old properties of remote controller161* @rc_map_table: a hard-wired array of struct rc_map_table (NULL to disable162* remote control handling).163* @rc_map_size: number of items in @rc_map_table.164* @rc_query: called to query an event event.165* @rc_interval: time in ms between two queries.166*/167struct dvb_rc_legacy {168/* remote control properties */169#define REMOTE_NO_KEY_PRESSED 0x00170#define REMOTE_KEY_PRESSED 0x01171#define REMOTE_KEY_REPEAT 0x02172struct rc_map_table *rc_map_table;173int rc_map_size;174int (*rc_query) (struct dvb_usb_device *, u32 *, int *);175int rc_interval;176};177178/**179* struct dvb_rc properties of remote controller, using rc-core180* @rc_codes: name of rc codes table181* @protocol: type of protocol(s) currently used by the driver182* @allowed_protos: protocol(s) supported by the driver183* @driver_type: Used to point if a device supports raw mode184* @change_protocol: callback to change protocol185* @rc_query: called to query an event event.186* @rc_interval: time in ms between two queries.187* @bulk_mode: device supports bulk mode for RC (disable polling mode)188*/189struct dvb_rc {190char *rc_codes;191u64 protocol;192u64 allowed_protos;193enum rc_driver_type driver_type;194int (*change_protocol)(struct rc_dev *dev, u64 rc_type);195char *module_name;196int (*rc_query) (struct dvb_usb_device *d);197int rc_interval;198bool bulk_mode; /* uses bulk mode */199};200201/**202* enum dvb_usb_mode - Specifies if it is using a legacy driver or a new one203* based on rc-core204* This is initialized/used only inside dvb-usb-remote.c.205* It shouldn't be set by the drivers.206*/207enum dvb_usb_mode {208DVB_RC_LEGACY,209DVB_RC_CORE,210};211212/**213* struct dvb_usb_device_properties - properties of a dvb-usb-device214* @usb_ctrl: which USB device-side controller is in use. Needed for firmware215* download.216* @firmware: name of the firmware file.217* @download_firmware: called to download the firmware when the usb_ctrl is218* DEVICE_SPECIFIC.219* @no_reconnect: device doesn't do a reconnect after downloading the firmware,220* so do the warm initialization right after it221*222* @size_of_priv: how many bytes shall be allocated for the private field223* of struct dvb_usb_device.224*225* @power_ctrl: called to enable/disable power of the device.226* @read_mac_address: called to read the MAC address of the device.227* @identify_state: called to determine the state (cold or warm), when it228* is not distinguishable by the USB IDs.229*230* @rc: remote controller properties231*232* @i2c_algo: i2c_algorithm if the device has I2CoverUSB.233*234* @generic_bulk_ctrl_endpoint: most of the DVB USB devices have a generic235* endpoint which received control messages with bulk transfers. When this236* is non-zero, one can use dvb_usb_generic_rw and dvb_usb_generic_write-237* helper functions.238*239* @generic_bulk_ctrl_endpoint_response: some DVB USB devices use a separate240* endpoint for responses to control messages sent with bulk transfers via241* the generic_bulk_ctrl_endpoint. When this is non-zero, this will be used242* instead of the generic_bulk_ctrl_endpoint when reading usb responses in243* the dvb_usb_generic_rw helper function.244*245* @num_device_descs: number of struct dvb_usb_device_description in @devices246* @devices: array of struct dvb_usb_device_description compatibles with these247* properties.248*/249#define MAX_NO_OF_ADAPTER_PER_DEVICE 2250struct dvb_usb_device_properties {251252#define DVB_USB_IS_AN_I2C_ADAPTER 0x01253int caps;254255#define DEVICE_SPECIFIC 0256#define CYPRESS_AN2135 1257#define CYPRESS_AN2235 2258#define CYPRESS_FX2 3259int usb_ctrl;260int (*download_firmware) (struct usb_device *, const struct firmware *);261const char *firmware;262int no_reconnect;263264int size_of_priv;265266int num_adapters;267struct dvb_usb_adapter_properties adapter[MAX_NO_OF_ADAPTER_PER_DEVICE];268269int (*power_ctrl) (struct dvb_usb_device *, int);270int (*read_mac_address) (struct dvb_usb_device *, u8 []);271int (*identify_state) (struct usb_device *, struct dvb_usb_device_properties *,272struct dvb_usb_device_description **, int *);273274struct {275enum dvb_usb_mode mode; /* Drivers shouldn't touch on it */276struct dvb_rc_legacy legacy;277struct dvb_rc core;278} rc;279280struct i2c_algorithm *i2c_algo;281282int generic_bulk_ctrl_endpoint;283int generic_bulk_ctrl_endpoint_response;284285int num_device_descs;286struct dvb_usb_device_description devices[12];287};288289/**290* struct usb_data_stream - generic object of an USB stream291* @buf_num: number of buffer allocated.292* @buf_size: size of each buffer in buf_list.293* @buf_list: array containing all allocate buffers for streaming.294* @dma_addr: list of dma_addr_t for each buffer in buf_list.295*296* @urbs_initialized: number of URBs initialized.297* @urbs_submitted: number of URBs submitted.298*/299#define MAX_NO_URBS_FOR_DATA_STREAM 10300struct usb_data_stream {301struct usb_device *udev;302struct usb_data_stream_properties props;303304#define USB_STATE_INIT 0x00305#define USB_STATE_URB_BUF 0x01306int state;307308void (*complete) (struct usb_data_stream *, u8 *, size_t);309310struct urb *urb_list[MAX_NO_URBS_FOR_DATA_STREAM];311int buf_num;312unsigned long buf_size;313u8 *buf_list[MAX_NO_URBS_FOR_DATA_STREAM];314dma_addr_t dma_addr[MAX_NO_URBS_FOR_DATA_STREAM];315316int urbs_initialized;317int urbs_submitted;318319void *user_priv;320};321322/**323* struct dvb_usb_adapter - a DVB adapter on a USB device324* @id: index of this adapter (starting with 0).325*326* @feedcount: number of reqested feeds (used for streaming-activation)327* @pid_filtering: is hardware pid_filtering used or not.328*329* @pll_addr: I2C address of the tuner for programming330* @pll_init: array containing the initialization buffer331* @pll_desc: pointer to the appropriate struct dvb_pll_desc332* @tuner_pass_ctrl: called to (de)activate tuner passthru of the demod or the board333*334* @dvb_adap: device's dvb_adapter.335* @dmxdev: device's dmxdev.336* @demux: device's software demuxer.337* @dvb_net: device's dvb_net interfaces.338* @dvb_frontend: device's frontend.339* @max_feed_count: how many feeds can be handled simultaneously by this340* device341*342* @fe_init: rerouted frontend-init (wakeup) function.343* @fe_sleep: rerouted frontend-sleep function.344*345* @stream: the usb data stream.346*/347struct dvb_usb_adapter {348struct dvb_usb_device *dev;349struct dvb_usb_adapter_properties props;350351#define DVB_USB_ADAP_STATE_INIT 0x000352#define DVB_USB_ADAP_STATE_DVB 0x001353int state;354355u8 id;356357int feedcount;358int pid_filtering;359360/* dvb */361struct dvb_adapter dvb_adap;362struct dmxdev dmxdev;363struct dvb_demux demux;364struct dvb_net dvb_net;365struct dvb_frontend *fe;366int max_feed_count;367368int (*fe_init) (struct dvb_frontend *);369int (*fe_sleep) (struct dvb_frontend *);370371struct usb_data_stream stream;372373void *priv;374};375376/**377* struct dvb_usb_device - object of a DVB USB device378* @props: copy of the struct dvb_usb_properties this device belongs to.379* @desc: pointer to the device's struct dvb_usb_device_description.380* @state: initialization and runtime state of the device.381*382* @powered: indicated whether the device is power or not.383* Powered is in/decremented for each call to modify the state.384* @udev: pointer to the device's struct usb_device.385*386* @usb_mutex: semaphore of USB control messages (reading needs two messages)387* @i2c_mutex: semaphore for i2c-transfers388*389* @i2c_adap: device's i2c_adapter if it uses I2CoverUSB390*391* @rc_dev: rc device for the remote control (rc-core mode)392* @input_dev: input device for the remote control (legacy mode)393* @rc_query_work: struct work_struct frequent rc queries394* @last_event: last triggered event395* @last_state: last state (no, pressed, repeat)396* @owner: owner of the dvb_adapter397* @priv: private data of the actual driver (allocate by dvb-usb, size defined398* in size_of_priv of dvb_usb_properties).399*/400struct dvb_usb_device {401struct dvb_usb_device_properties props;402struct dvb_usb_device_description *desc;403404struct usb_device *udev;405406#define DVB_USB_STATE_INIT 0x000407#define DVB_USB_STATE_I2C 0x001408#define DVB_USB_STATE_DVB 0x002409#define DVB_USB_STATE_REMOTE 0x004410int state;411412int powered;413414/* locking */415struct mutex usb_mutex;416417/* i2c */418struct mutex i2c_mutex;419struct i2c_adapter i2c_adap;420421int num_adapters_initialized;422struct dvb_usb_adapter adapter[MAX_NO_OF_ADAPTER_PER_DEVICE];423424/* remote control */425struct rc_dev *rc_dev;426struct input_dev *input_dev;427char rc_phys[64];428struct delayed_work rc_query_work;429u32 last_event;430int last_state;431432struct module *owner;433434void *priv;435};436437extern int dvb_usb_device_init(struct usb_interface *,438struct dvb_usb_device_properties *,439struct module *, struct dvb_usb_device **,440short *adapter_nums);441extern void dvb_usb_device_exit(struct usb_interface *);442443/* the generic read/write method for device control */444extern int dvb_usb_generic_rw(struct dvb_usb_device *, u8 *, u16, u8 *, u16,int);445extern int dvb_usb_generic_write(struct dvb_usb_device *, u8 *, u16);446447/* commonly used remote control parsing */448extern int dvb_usb_nec_rc_key_to_event(struct dvb_usb_device *, u8[], u32 *, int *);449450/* commonly used firmware download types and function */451struct hexline {452u8 len;453u32 addr;454u8 type;455u8 data[255];456u8 chk;457};458extern int usb_cypress_load_firmware(struct usb_device *udev, const struct firmware *fw, int type);459extern int dvb_usb_get_hexline(const struct firmware *fw, struct hexline *hx, int *pos);460461462#endif463464465