Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /* dvb-usb.h is part of the DVB USB library.
0003  *
0004  * Copyright (C) 2004-6 Patrick Boettcher (patrick.boettcher@posteo.de)
0005  * see dvb-usb-init.c for copyright information.
0006  *
0007  * the headerfile, all dvb-usb-drivers have to include.
0008  *
0009  * TODO: clean-up the structures for unused fields and update the comments
0010  */
0011 #ifndef __DVB_USB_H__
0012 #define __DVB_USB_H__
0013 
0014 #include <linux/input.h>
0015 #include <linux/usb.h>
0016 #include <linux/firmware.h>
0017 #include <linux/mutex.h>
0018 #include <media/rc-core.h>
0019 
0020 #include <media/dvb_frontend.h>
0021 #include <media/dvb_demux.h>
0022 #include <media/dvb_net.h>
0023 #include <media/dmxdev.h>
0024 
0025 #include "dvb-pll.h"
0026 
0027 #include <media/dvb-usb-ids.h>
0028 
0029 /* debug */
0030 #ifdef CONFIG_DVB_USB_DEBUG
0031 #define dprintk(var, level, args...) \
0032         do { if (((var) & (level))) { printk(args); } } while (0)
0033 
0034 #define debug_dump(b, l, func) {\
0035     int loop_; \
0036     for (loop_ = 0; loop_ < (l); loop_++) \
0037         func("%02x ", b[loop_]); \
0038     func("\n");\
0039 }
0040 #define DVB_USB_DEBUG_STATUS
0041 #else
0042 #define dprintk(var, level, args...) no_printk(args)
0043 #define debug_dump(b, l, func) do { } while (0)
0044 
0045 #define DVB_USB_DEBUG_STATUS " (debugging is not enabled)"
0046 
0047 #endif
0048 
0049 /* generic log methods - taken from usb.h */
0050 #ifndef DVB_USB_LOG_PREFIX
0051  #define DVB_USB_LOG_PREFIX "dvb-usb (please define a log prefix)"
0052 #endif
0053 
0054 #undef err
0055 #define err(format, arg...)  printk(KERN_ERR     DVB_USB_LOG_PREFIX ": " format "\n" , ## arg)
0056 #undef info
0057 #define info(format, arg...) printk(KERN_INFO    DVB_USB_LOG_PREFIX ": " format "\n" , ## arg)
0058 #undef warn
0059 #define warn(format, arg...) printk(KERN_WARNING DVB_USB_LOG_PREFIX ": " format "\n" , ## arg)
0060 
0061 /**
0062  * struct dvb_usb_device_description - name and its according USB IDs
0063  * @name: real name of the box, regardless which DVB USB device class is in use
0064  * @cold_ids: array of struct usb_device_id which describe the device in
0065  *  pre-firmware state
0066  * @warm_ids: array of struct usb_device_id which describe the device in
0067  *  post-firmware state
0068  *
0069  * Each DVB USB device class can have one or more actual devices, this struct
0070  * assigns a name to it.
0071  */
0072 struct dvb_usb_device_description {
0073     const char *name;
0074 
0075 #define DVB_USB_ID_MAX_NUM 15
0076     struct usb_device_id *cold_ids[DVB_USB_ID_MAX_NUM];
0077     struct usb_device_id *warm_ids[DVB_USB_ID_MAX_NUM];
0078 };
0079 
0080 static inline u8 rc5_custom(struct rc_map_table *key)
0081 {
0082     return (key->scancode >> 8) & 0xff;
0083 }
0084 
0085 static inline u8 rc5_data(struct rc_map_table *key)
0086 {
0087     return key->scancode & 0xff;
0088 }
0089 
0090 static inline u16 rc5_scan(struct rc_map_table *key)
0091 {
0092     return key->scancode & 0xffff;
0093 }
0094 
0095 struct dvb_usb_device;
0096 struct dvb_usb_adapter;
0097 struct usb_data_stream;
0098 
0099 /*
0100  * Properties of USB streaming - TODO this structure should be somewhere else
0101  * describes the kind of USB transfer used for data-streaming.
0102  *  (BULK or ISOC)
0103  */
0104 struct usb_data_stream_properties {
0105 #define USB_BULK  1
0106 #define USB_ISOC  2
0107     int type;
0108     int count;
0109     int endpoint;
0110 
0111     union {
0112         struct {
0113             int buffersize; /* per URB */
0114         } bulk;
0115         struct {
0116             int framesperurb;
0117             int framesize;
0118             int interval;
0119         } isoc;
0120     } u;
0121 };
0122 
0123 /**
0124  * struct dvb_usb_adapter_fe_properties - properties of a dvb-usb-adapter.
0125  *    A DVB-USB-Adapter is basically a dvb_adapter which is present on a USB-device.
0126  * @caps: capabilities of the DVB USB device.
0127  * @pid_filter_count: number of PID filter position in the optional hardware
0128  *  PID-filter.
0129  * @num_frontends: number of frontends of the DVB USB adapter.
0130  * @frontend_ctrl: called to power on/off active frontend.
0131  * @streaming_ctrl: called to start and stop the MPEG2-TS streaming of the
0132  *  device (not URB submitting/killing).
0133  *  This callback will be called without data URBs being active - data URBs
0134  *  will be submitted only after streaming_ctrl(1) returns successfully and
0135  *  they will be killed before streaming_ctrl(0) gets called.
0136  * @pid_filter_ctrl: called to en/disable the PID filter, if any.
0137  * @pid_filter: called to set/unset a PID for filtering.
0138  * @frontend_attach: called to attach the possible frontends (fill fe-field
0139  *  of struct dvb_usb_device).
0140  * @tuner_attach: called to attach the correct tuner and to fill pll_addr,
0141  *  pll_desc and pll_init_buf of struct dvb_usb_device).
0142  * @stream: configuration of the USB streaming
0143  * @size_of_priv: size of the priv memory in struct dvb_usb_adapter
0144  */
0145 struct dvb_usb_adapter_fe_properties {
0146 #define DVB_USB_ADAP_HAS_PID_FILTER               0x01
0147 #define DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF 0x02
0148 #define DVB_USB_ADAP_NEED_PID_FILTERING           0x04
0149 #define DVB_USB_ADAP_RECEIVES_204_BYTE_TS         0x08
0150 #define DVB_USB_ADAP_RECEIVES_RAW_PAYLOAD         0x10
0151     int caps;
0152     int pid_filter_count;
0153 
0154     int (*streaming_ctrl)  (struct dvb_usb_adapter *, int);
0155     int (*pid_filter_ctrl) (struct dvb_usb_adapter *, int);
0156     int (*pid_filter)      (struct dvb_usb_adapter *, int, u16, int);
0157 
0158     int (*frontend_attach) (struct dvb_usb_adapter *);
0159     int (*tuner_attach)    (struct dvb_usb_adapter *);
0160 
0161     struct usb_data_stream_properties stream;
0162 
0163     int size_of_priv;
0164 };
0165 
0166 #define MAX_NO_OF_FE_PER_ADAP 3
0167 struct dvb_usb_adapter_properties {
0168     int size_of_priv;
0169 
0170     int (*frontend_ctrl)   (struct dvb_frontend *, int);
0171 
0172     int num_frontends;
0173     struct dvb_usb_adapter_fe_properties fe[MAX_NO_OF_FE_PER_ADAP];
0174 };
0175 
0176 /**
0177  * struct dvb_rc_legacy - old properties of remote controller
0178  * @rc_map_table: a hard-wired array of struct rc_map_table (NULL to disable
0179  *  remote control handling).
0180  * @rc_map_size: number of items in @rc_map_table.
0181  * @rc_query: called to query an event event.
0182  * @rc_interval: time in ms between two queries.
0183  */
0184 struct dvb_rc_legacy {
0185 /* remote control properties */
0186 #define REMOTE_NO_KEY_PRESSED      0x00
0187 #define REMOTE_KEY_PRESSED         0x01
0188 #define REMOTE_KEY_REPEAT          0x02
0189     struct rc_map_table  *rc_map_table;
0190     int rc_map_size;
0191     int (*rc_query) (struct dvb_usb_device *, u32 *, int *);
0192     int rc_interval;
0193 };
0194 
0195 /**
0196  * struct dvb_rc - properties of remote controller, using rc-core
0197  * @rc_codes: name of rc codes table
0198  * @protocol: type of protocol(s) currently used by the driver
0199  * @allowed_protos: protocol(s) supported by the driver
0200  * @driver_type: Used to point if a device supports raw mode
0201  * @change_protocol: callback to change protocol
0202  * @module_name: module name
0203  * @rc_query: called to query an event event.
0204  * @rc_interval: time in ms between two queries.
0205  * @bulk_mode: device supports bulk mode for RC (disable polling mode)
0206  * @scancode_mask: scancode mask
0207  */
0208 struct dvb_rc {
0209     char *rc_codes;
0210     u64 protocol;
0211     u64 allowed_protos;
0212     enum rc_driver_type driver_type;
0213     int (*change_protocol)(struct rc_dev *dev, u64 *rc_proto);
0214     char *module_name;
0215     int (*rc_query) (struct dvb_usb_device *d);
0216     int rc_interval;
0217     bool bulk_mode;             /* uses bulk mode */
0218     u32 scancode_mask;
0219 };
0220 
0221 /**
0222  * enum dvb_usb_mode - Specifies if it is using a legacy driver or a new one
0223  *             based on rc-core
0224  * This is initialized/used only inside dvb-usb-remote.c.
0225  * It shouldn't be set by the drivers.
0226  *
0227  * @DVB_RC_LEGACY: legacy driver
0228  * @DVB_RC_CORE: rc-core driver
0229  */
0230 enum dvb_usb_mode {
0231     DVB_RC_LEGACY,
0232     DVB_RC_CORE,
0233 };
0234 
0235 /**
0236  * struct dvb_usb_device_properties - properties of a dvb-usb-device
0237  * @caps: capabilities
0238  * @usb_ctrl: which USB device-side controller is in use. Needed for firmware
0239  *  download.
0240  * @firmware: name of the firmware file.
0241  * @download_firmware: called to download the firmware when the usb_ctrl is
0242  *  DEVICE_SPECIFIC.
0243  * @no_reconnect: device doesn't do a reconnect after downloading the firmware,
0244  *  so do the warm initialization right after it
0245  *
0246  * @size_of_priv: how many bytes shall be allocated for the private field
0247  *  of struct dvb_usb_device.
0248  * @priv_init: optional callback to initialize the variable that private field
0249  * of struct dvb_usb_device has pointer to just after it had been allocated and
0250  * zeroed.
0251  * @priv_destroy: just like priv_init, only called before deallocating
0252  * the memory pointed by private field of struct dvb_usb_device.
0253  *
0254  * @num_adapters: the number of adapters in @adapters
0255  * @adapter: the adapters
0256  * @power_ctrl: called to enable/disable power of the device.
0257  * @read_mac_address: called to read the MAC address of the device.
0258  * @identify_state: called to determine the state (cold or warm), when it
0259  *  is not distinguishable by the USB IDs.
0260  *
0261  * @rc: remote controller properties
0262  *
0263  * @i2c_algo: i2c_algorithm if the device has I2CoverUSB.
0264  *
0265  * @generic_bulk_ctrl_endpoint: most of the DVB USB devices have a generic
0266  *  endpoint which received control messages with bulk transfers. When this
0267  *  is non-zero, one can use dvb_usb_generic_rw and dvb_usb_generic_write-
0268  *  helper functions.
0269  *
0270  * @generic_bulk_ctrl_endpoint_response: some DVB USB devices use a separate
0271  *  endpoint for responses to control messages sent with bulk transfers via
0272  *  the generic_bulk_ctrl_endpoint. When this is non-zero, this will be used
0273  *  instead of the generic_bulk_ctrl_endpoint when reading usb responses in
0274  *  the dvb_usb_generic_rw helper function.
0275  *
0276  * @num_device_descs: number of struct dvb_usb_device_description in @devices
0277  * @devices: array of struct dvb_usb_device_description compatibles with these
0278  *  properties.
0279  */
0280 struct dvb_usb_device_properties {
0281 #define MAX_NO_OF_ADAPTER_PER_DEVICE 2
0282 #define DVB_USB_IS_AN_I2C_ADAPTER            0x01
0283     int caps;
0284 
0285 #define DEVICE_SPECIFIC 0
0286 #define CYPRESS_AN2135  1
0287 #define CYPRESS_AN2235  2
0288 #define CYPRESS_FX2     3
0289     int        usb_ctrl;
0290     int        (*download_firmware) (struct usb_device *, const struct firmware *);
0291     const char *firmware;
0292     int        no_reconnect;
0293 
0294     int size_of_priv;
0295     int (*priv_init)(struct dvb_usb_device *);
0296     void (*priv_destroy)(struct dvb_usb_device *);
0297 
0298     int num_adapters;
0299     struct dvb_usb_adapter_properties adapter[MAX_NO_OF_ADAPTER_PER_DEVICE];
0300 
0301     int (*power_ctrl)       (struct dvb_usb_device *, int);
0302     int (*read_mac_address) (struct dvb_usb_device *, u8 []);
0303     int (*identify_state)(struct usb_device *udev,
0304                   const struct dvb_usb_device_properties *props,
0305                   const struct dvb_usb_device_description **desc,
0306                   int *cold);
0307 
0308     struct {
0309         enum dvb_usb_mode mode; /* Drivers shouldn't touch on it */
0310         struct dvb_rc_legacy legacy;
0311         struct dvb_rc core;
0312     } rc;
0313 
0314     struct i2c_algorithm *i2c_algo;
0315 
0316     int generic_bulk_ctrl_endpoint;
0317     int generic_bulk_ctrl_endpoint_response;
0318 
0319     int num_device_descs;
0320     struct dvb_usb_device_description devices[12];
0321 };
0322 
0323 /**
0324  * struct usb_data_stream - generic object of an USB stream
0325  * @udev: the USB device
0326  * @props: data stream properties
0327  * @state: state of the stream
0328  * @complete: complete callback
0329  * @urb_list: list of URBs
0330  * @buf_num: number of buffer allocated.
0331  * @buf_size: size of each buffer in buf_list.
0332  * @buf_list: array containing all allocate buffers for streaming.
0333  * @dma_addr: list of dma_addr_t for each buffer in buf_list.
0334  *
0335  * @urbs_initialized: number of URBs initialized.
0336  * @urbs_submitted: number of URBs submitted.
0337  * @user_priv: for private use.
0338  */
0339 struct usb_data_stream {
0340 #define MAX_NO_URBS_FOR_DATA_STREAM 10
0341     struct usb_device                 *udev;
0342     struct usb_data_stream_properties  props;
0343 
0344 #define USB_STATE_INIT    0x00
0345 #define USB_STATE_URB_BUF 0x01
0346     int state;
0347 
0348     void (*complete) (struct usb_data_stream *, u8 *, size_t);
0349 
0350     struct urb    *urb_list[MAX_NO_URBS_FOR_DATA_STREAM];
0351     int            buf_num;
0352     unsigned long  buf_size;
0353     u8            *buf_list[MAX_NO_URBS_FOR_DATA_STREAM];
0354     dma_addr_t     dma_addr[MAX_NO_URBS_FOR_DATA_STREAM];
0355 
0356     int urbs_initialized;
0357     int urbs_submitted;
0358 
0359     void *user_priv;
0360 };
0361 
0362 /**
0363  * struct dvb_usb_fe_adapter - a DVB adapter on a USB device
0364  * @fe: frontend
0365  * @fe_init:  rerouted frontend-init (wakeup) function.
0366  * @fe_sleep: rerouted frontend-sleep function.
0367  * @stream: the usb data stream.
0368  * @pid_filtering: is hardware pid_filtering used or not.
0369  * @max_feed_count: how many feeds can be handled simultaneously by this
0370  *  device
0371  * @priv: private pointer
0372  */
0373 struct dvb_usb_fe_adapter {
0374     struct dvb_frontend *fe;
0375 
0376     int (*fe_init)  (struct dvb_frontend *);
0377     int (*fe_sleep) (struct dvb_frontend *);
0378 
0379     struct usb_data_stream stream;
0380 
0381     int pid_filtering;
0382     int max_feed_count;
0383 
0384     void *priv;
0385 };
0386 
0387 /**
0388  * struct dvb_usb_adapter - a DVB adapter on a USB device
0389  * @dev: DVB USB device pointer
0390  * @props: properties
0391  * @state: status
0392  * @id: index of this adapter (starting with 0).
0393  *
0394  * @feedcount: number of requested feeds (used for streaming-activation)
0395  *
0396  * @dvb_adap: device's dvb_adapter.
0397  * @dmxdev: device's dmxdev.
0398  * @demux: device's software demuxer.
0399  * @dvb_net: device's dvb_net interfaces.
0400  *
0401  * @fe_adap: frontend adapters
0402  * @active_fe: active frontend
0403  * @num_frontends_initialized: number of initialized frontends
0404  * @priv: private pointer
0405  */
0406 struct dvb_usb_adapter {
0407     struct dvb_usb_device *dev;
0408     struct dvb_usb_adapter_properties props;
0409 
0410 #define DVB_USB_ADAP_STATE_INIT 0x000
0411 #define DVB_USB_ADAP_STATE_DVB  0x001
0412     int state;
0413 
0414     u8  id;
0415 
0416     int feedcount;
0417 
0418     /* dvb */
0419     struct dvb_adapter   dvb_adap;
0420     struct dmxdev        dmxdev;
0421     struct dvb_demux     demux;
0422     struct dvb_net       dvb_net;
0423 
0424     struct dvb_usb_fe_adapter fe_adap[MAX_NO_OF_FE_PER_ADAP];
0425     int active_fe;
0426     int num_frontends_initialized;
0427 
0428     void *priv;
0429 };
0430 
0431 /**
0432  * struct dvb_usb_device - object of a DVB USB device
0433  * @props: copy of the struct dvb_usb_properties this device belongs to.
0434  * @desc: pointer to the device's struct dvb_usb_device_description.
0435  * @state: initialization and runtime state of the device.
0436  *
0437  * @powered: indicated whether the device is power or not.
0438  *  Powered is in/decremented for each call to modify the state.
0439  * @udev: pointer to the device's struct usb_device.
0440  *
0441  * @data_mutex: mutex to protect the data structure used to store URB data
0442  * @usb_mutex: mutex of USB control messages (reading needs two messages).
0443  *  Please notice that this mutex is used internally at the generic
0444  *  URB control functions. So, drivers using dvb_usb_generic_rw() and
0445  *  derivated functions should not lock it internally.
0446  * @i2c_mutex: mutex for i2c-transfers
0447  *
0448  * @i2c_adap: device's i2c_adapter if it uses I2CoverUSB
0449  *
0450  * @num_adapters_initialized: number of initialized adapters
0451  * @adapter: adapters
0452  *
0453  * @rc_dev: rc device for the remote control (rc-core mode)
0454  * @input_dev: input device for the remote control (legacy mode)
0455  * @rc_phys: rc device path
0456  * @rc_query_work: struct work_struct frequent rc queries
0457  * @last_event: last triggered event
0458  * @last_state: last state (no, pressed, repeat)
0459  * @owner: owner of the dvb_adapter
0460  * @priv: private data of the actual driver (allocate by dvb-usb, size defined
0461  *  in size_of_priv of dvb_usb_properties).
0462  */
0463 struct dvb_usb_device {
0464     struct dvb_usb_device_properties props;
0465     const struct dvb_usb_device_description *desc;
0466 
0467     struct usb_device *udev;
0468 
0469 #define DVB_USB_STATE_INIT        0x000
0470 #define DVB_USB_STATE_I2C         0x001
0471 #define DVB_USB_STATE_DVB         0x002
0472 #define DVB_USB_STATE_REMOTE      0x004
0473     int state;
0474 
0475     int powered;
0476 
0477     /* locking */
0478     struct mutex data_mutex;
0479     struct mutex usb_mutex;
0480 
0481     /* i2c */
0482     struct mutex i2c_mutex;
0483     struct i2c_adapter i2c_adap;
0484 
0485     int                    num_adapters_initialized;
0486     struct dvb_usb_adapter adapter[MAX_NO_OF_ADAPTER_PER_DEVICE];
0487 
0488     /* remote control */
0489     struct rc_dev *rc_dev;
0490     struct input_dev *input_dev;
0491     char rc_phys[64];
0492     struct delayed_work rc_query_work;
0493     u32 last_event;
0494     int last_state;
0495 
0496     struct module *owner;
0497 
0498     void *priv;
0499 };
0500 
0501 extern int dvb_usb_device_init(struct usb_interface *,
0502                    const struct dvb_usb_device_properties *,
0503                    struct module *, struct dvb_usb_device **,
0504                    short *adapter_nums);
0505 extern void dvb_usb_device_exit(struct usb_interface *);
0506 
0507 /* the generic read/write method for device control */
0508 extern int __must_check
0509 dvb_usb_generic_rw(struct dvb_usb_device *, u8 *, u16, u8 *, u16, int);
0510 extern int __must_check
0511 dvb_usb_generic_write(struct dvb_usb_device *, u8 *, u16);
0512 
0513 /* commonly used remote control parsing */
0514 int dvb_usb_nec_rc_key_to_event(struct dvb_usb_device *d, u8 keybuf[5],
0515                 u32 *event, int *state);
0516 
0517 /* commonly used firmware download types and function */
0518 struct hexline {
0519     u8 len;
0520     u32 addr;
0521     u8 type;
0522     u8 data[255];
0523     u8 chk;
0524 };
0525 extern int usb_cypress_load_firmware(struct usb_device *udev, const struct firmware *fw, int type);
0526 extern int dvb_usb_get_hexline(const struct firmware *fw, struct hexline *hx, int *pos);
0527 
0528 
0529 #endif