18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/* dvb-usb.h is part of the DVB USB library.
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * Copyright (C) 2004-6 Patrick Boettcher (patrick.boettcher@posteo.de)
58c2ecf20Sopenharmony_ci * see dvb-usb-init.c for copyright information.
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * the headerfile, all dvb-usb-drivers have to include.
88c2ecf20Sopenharmony_ci *
98c2ecf20Sopenharmony_ci * TODO: clean-up the structures for unused fields and update the comments
108c2ecf20Sopenharmony_ci */
118c2ecf20Sopenharmony_ci#ifndef __DVB_USB_H__
128c2ecf20Sopenharmony_ci#define __DVB_USB_H__
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci#include <linux/input.h>
158c2ecf20Sopenharmony_ci#include <linux/usb.h>
168c2ecf20Sopenharmony_ci#include <linux/firmware.h>
178c2ecf20Sopenharmony_ci#include <linux/mutex.h>
188c2ecf20Sopenharmony_ci#include <media/rc-core.h>
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci#include <media/dvb_frontend.h>
218c2ecf20Sopenharmony_ci#include <media/dvb_demux.h>
228c2ecf20Sopenharmony_ci#include <media/dvb_net.h>
238c2ecf20Sopenharmony_ci#include <media/dmxdev.h>
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci#include "dvb-pll.h"
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci#include <media/dvb-usb-ids.h>
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ci/* debug */
308c2ecf20Sopenharmony_ci#ifdef CONFIG_DVB_USB_DEBUG
318c2ecf20Sopenharmony_ci#define dprintk(var,level,args...) \
328c2ecf20Sopenharmony_ci	    do { if ((var & level)) { printk(args); } } while (0)
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci#define debug_dump(b,l,func) {\
358c2ecf20Sopenharmony_ci	int loop_; \
368c2ecf20Sopenharmony_ci	for (loop_ = 0; loop_ < l; loop_++) func("%02x ", b[loop_]); \
378c2ecf20Sopenharmony_ci	func("\n");\
388c2ecf20Sopenharmony_ci}
398c2ecf20Sopenharmony_ci#define DVB_USB_DEBUG_STATUS
408c2ecf20Sopenharmony_ci#else
418c2ecf20Sopenharmony_ci#define dprintk(args...)
428c2ecf20Sopenharmony_ci#define debug_dump(b,l,func)
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ci#define DVB_USB_DEBUG_STATUS " (debugging is not enabled)"
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_ci#endif
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ci/* generic log methods - taken from usb.h */
498c2ecf20Sopenharmony_ci#ifndef DVB_USB_LOG_PREFIX
508c2ecf20Sopenharmony_ci #define DVB_USB_LOG_PREFIX "dvb-usb (please define a log prefix)"
518c2ecf20Sopenharmony_ci#endif
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_ci#undef err
548c2ecf20Sopenharmony_ci#define err(format, arg...)  printk(KERN_ERR     DVB_USB_LOG_PREFIX ": " format "\n" , ## arg)
558c2ecf20Sopenharmony_ci#undef info
568c2ecf20Sopenharmony_ci#define info(format, arg...) printk(KERN_INFO    DVB_USB_LOG_PREFIX ": " format "\n" , ## arg)
578c2ecf20Sopenharmony_ci#undef warn
588c2ecf20Sopenharmony_ci#define warn(format, arg...) printk(KERN_WARNING DVB_USB_LOG_PREFIX ": " format "\n" , ## arg)
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ci/**
618c2ecf20Sopenharmony_ci * struct dvb_usb_device_description - name and its according USB IDs
628c2ecf20Sopenharmony_ci * @name: real name of the box, regardless which DVB USB device class is in use
638c2ecf20Sopenharmony_ci * @cold_ids: array of struct usb_device_id which describe the device in
648c2ecf20Sopenharmony_ci *  pre-firmware state
658c2ecf20Sopenharmony_ci * @warm_ids: array of struct usb_device_id which describe the device in
668c2ecf20Sopenharmony_ci *  post-firmware state
678c2ecf20Sopenharmony_ci *
688c2ecf20Sopenharmony_ci * Each DVB USB device class can have one or more actual devices, this struct
698c2ecf20Sopenharmony_ci * assigns a name to it.
708c2ecf20Sopenharmony_ci */
718c2ecf20Sopenharmony_cistruct dvb_usb_device_description {
728c2ecf20Sopenharmony_ci	const char *name;
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ci#define DVB_USB_ID_MAX_NUM 15
758c2ecf20Sopenharmony_ci	struct usb_device_id *cold_ids[DVB_USB_ID_MAX_NUM];
768c2ecf20Sopenharmony_ci	struct usb_device_id *warm_ids[DVB_USB_ID_MAX_NUM];
778c2ecf20Sopenharmony_ci};
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_cistatic inline u8 rc5_custom(struct rc_map_table *key)
808c2ecf20Sopenharmony_ci{
818c2ecf20Sopenharmony_ci	return (key->scancode >> 8) & 0xff;
828c2ecf20Sopenharmony_ci}
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_cistatic inline u8 rc5_data(struct rc_map_table *key)
858c2ecf20Sopenharmony_ci{
868c2ecf20Sopenharmony_ci	return key->scancode & 0xff;
878c2ecf20Sopenharmony_ci}
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_cistatic inline u16 rc5_scan(struct rc_map_table *key)
908c2ecf20Sopenharmony_ci{
918c2ecf20Sopenharmony_ci	return key->scancode & 0xffff;
928c2ecf20Sopenharmony_ci}
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_cistruct dvb_usb_device;
958c2ecf20Sopenharmony_cistruct dvb_usb_adapter;
968c2ecf20Sopenharmony_cistruct usb_data_stream;
978c2ecf20Sopenharmony_ci
988c2ecf20Sopenharmony_ci/**
998c2ecf20Sopenharmony_ci * Properties of USB streaming - TODO this structure should be somewhere else
1008c2ecf20Sopenharmony_ci * describes the kind of USB transfer used for data-streaming.
1018c2ecf20Sopenharmony_ci *  (BULK or ISOC)
1028c2ecf20Sopenharmony_ci */
1038c2ecf20Sopenharmony_cistruct usb_data_stream_properties {
1048c2ecf20Sopenharmony_ci#define USB_BULK  1
1058c2ecf20Sopenharmony_ci#define USB_ISOC  2
1068c2ecf20Sopenharmony_ci	int type;
1078c2ecf20Sopenharmony_ci	int count;
1088c2ecf20Sopenharmony_ci	int endpoint;
1098c2ecf20Sopenharmony_ci
1108c2ecf20Sopenharmony_ci	union {
1118c2ecf20Sopenharmony_ci		struct {
1128c2ecf20Sopenharmony_ci			int buffersize; /* per URB */
1138c2ecf20Sopenharmony_ci		} bulk;
1148c2ecf20Sopenharmony_ci		struct {
1158c2ecf20Sopenharmony_ci			int framesperurb;
1168c2ecf20Sopenharmony_ci			int framesize;
1178c2ecf20Sopenharmony_ci			int interval;
1188c2ecf20Sopenharmony_ci		} isoc;
1198c2ecf20Sopenharmony_ci	} u;
1208c2ecf20Sopenharmony_ci};
1218c2ecf20Sopenharmony_ci
1228c2ecf20Sopenharmony_ci/**
1238c2ecf20Sopenharmony_ci * struct dvb_usb_adapter_properties - properties of a dvb-usb-adapter.
1248c2ecf20Sopenharmony_ci *    A DVB-USB-Adapter is basically a dvb_adapter which is present on a USB-device.
1258c2ecf20Sopenharmony_ci * @caps: capabilities of the DVB USB device.
1268c2ecf20Sopenharmony_ci * @pid_filter_count: number of PID filter position in the optional hardware
1278c2ecf20Sopenharmony_ci *  PID-filter.
1288c2ecf20Sopenharmony_ci * @num_frontends: number of frontends of the DVB USB adapter.
1298c2ecf20Sopenharmony_ci * @frontend_ctrl: called to power on/off active frontend.
1308c2ecf20Sopenharmony_ci * @streaming_ctrl: called to start and stop the MPEG2-TS streaming of the
1318c2ecf20Sopenharmony_ci *  device (not URB submitting/killing).
1328c2ecf20Sopenharmony_ci *  This callback will be called without data URBs being active - data URBs
1338c2ecf20Sopenharmony_ci *  will be submitted only after streaming_ctrl(1) returns successfully and
1348c2ecf20Sopenharmony_ci *  they will be killed before streaming_ctrl(0) gets called.
1358c2ecf20Sopenharmony_ci * @pid_filter_ctrl: called to en/disable the PID filter, if any.
1368c2ecf20Sopenharmony_ci * @pid_filter: called to set/unset a PID for filtering.
1378c2ecf20Sopenharmony_ci * @frontend_attach: called to attach the possible frontends (fill fe-field
1388c2ecf20Sopenharmony_ci *  of struct dvb_usb_device).
1398c2ecf20Sopenharmony_ci * @tuner_attach: called to attach the correct tuner and to fill pll_addr,
1408c2ecf20Sopenharmony_ci *  pll_desc and pll_init_buf of struct dvb_usb_device).
1418c2ecf20Sopenharmony_ci * @stream: configuration of the USB streaming
1428c2ecf20Sopenharmony_ci */
1438c2ecf20Sopenharmony_cistruct dvb_usb_adapter_fe_properties {
1448c2ecf20Sopenharmony_ci#define DVB_USB_ADAP_HAS_PID_FILTER               0x01
1458c2ecf20Sopenharmony_ci#define DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF 0x02
1468c2ecf20Sopenharmony_ci#define DVB_USB_ADAP_NEED_PID_FILTERING           0x04
1478c2ecf20Sopenharmony_ci#define DVB_USB_ADAP_RECEIVES_204_BYTE_TS         0x08
1488c2ecf20Sopenharmony_ci#define DVB_USB_ADAP_RECEIVES_RAW_PAYLOAD         0x10
1498c2ecf20Sopenharmony_ci	int caps;
1508c2ecf20Sopenharmony_ci	int pid_filter_count;
1518c2ecf20Sopenharmony_ci
1528c2ecf20Sopenharmony_ci	int (*streaming_ctrl)  (struct dvb_usb_adapter *, int);
1538c2ecf20Sopenharmony_ci	int (*pid_filter_ctrl) (struct dvb_usb_adapter *, int);
1548c2ecf20Sopenharmony_ci	int (*pid_filter)      (struct dvb_usb_adapter *, int, u16, int);
1558c2ecf20Sopenharmony_ci
1568c2ecf20Sopenharmony_ci	int (*frontend_attach) (struct dvb_usb_adapter *);
1578c2ecf20Sopenharmony_ci	int (*tuner_attach)    (struct dvb_usb_adapter *);
1588c2ecf20Sopenharmony_ci
1598c2ecf20Sopenharmony_ci	struct usb_data_stream_properties stream;
1608c2ecf20Sopenharmony_ci
1618c2ecf20Sopenharmony_ci	int size_of_priv;
1628c2ecf20Sopenharmony_ci};
1638c2ecf20Sopenharmony_ci
1648c2ecf20Sopenharmony_ci#define MAX_NO_OF_FE_PER_ADAP 3
1658c2ecf20Sopenharmony_cistruct dvb_usb_adapter_properties {
1668c2ecf20Sopenharmony_ci	int size_of_priv;
1678c2ecf20Sopenharmony_ci
1688c2ecf20Sopenharmony_ci	int (*frontend_ctrl)   (struct dvb_frontend *, int);
1698c2ecf20Sopenharmony_ci
1708c2ecf20Sopenharmony_ci	int num_frontends;
1718c2ecf20Sopenharmony_ci	struct dvb_usb_adapter_fe_properties fe[MAX_NO_OF_FE_PER_ADAP];
1728c2ecf20Sopenharmony_ci};
1738c2ecf20Sopenharmony_ci
1748c2ecf20Sopenharmony_ci/**
1758c2ecf20Sopenharmony_ci * struct dvb_rc_legacy - old properties of remote controller
1768c2ecf20Sopenharmony_ci * @rc_map_table: a hard-wired array of struct rc_map_table (NULL to disable
1778c2ecf20Sopenharmony_ci *  remote control handling).
1788c2ecf20Sopenharmony_ci * @rc_map_size: number of items in @rc_map_table.
1798c2ecf20Sopenharmony_ci * @rc_query: called to query an event event.
1808c2ecf20Sopenharmony_ci * @rc_interval: time in ms between two queries.
1818c2ecf20Sopenharmony_ci */
1828c2ecf20Sopenharmony_cistruct dvb_rc_legacy {
1838c2ecf20Sopenharmony_ci/* remote control properties */
1848c2ecf20Sopenharmony_ci#define REMOTE_NO_KEY_PRESSED      0x00
1858c2ecf20Sopenharmony_ci#define REMOTE_KEY_PRESSED         0x01
1868c2ecf20Sopenharmony_ci#define REMOTE_KEY_REPEAT          0x02
1878c2ecf20Sopenharmony_ci	struct rc_map_table  *rc_map_table;
1888c2ecf20Sopenharmony_ci	int rc_map_size;
1898c2ecf20Sopenharmony_ci	int (*rc_query) (struct dvb_usb_device *, u32 *, int *);
1908c2ecf20Sopenharmony_ci	int rc_interval;
1918c2ecf20Sopenharmony_ci};
1928c2ecf20Sopenharmony_ci
1938c2ecf20Sopenharmony_ci/**
1948c2ecf20Sopenharmony_ci * struct dvb_rc properties of remote controller, using rc-core
1958c2ecf20Sopenharmony_ci * @rc_codes: name of rc codes table
1968c2ecf20Sopenharmony_ci * @protocol: type of protocol(s) currently used by the driver
1978c2ecf20Sopenharmony_ci * @allowed_protos: protocol(s) supported by the driver
1988c2ecf20Sopenharmony_ci * @driver_type: Used to point if a device supports raw mode
1998c2ecf20Sopenharmony_ci * @change_protocol: callback to change protocol
2008c2ecf20Sopenharmony_ci * @rc_query: called to query an event event.
2018c2ecf20Sopenharmony_ci * @rc_interval: time in ms between two queries.
2028c2ecf20Sopenharmony_ci * @bulk_mode: device supports bulk mode for RC (disable polling mode)
2038c2ecf20Sopenharmony_ci */
2048c2ecf20Sopenharmony_cistruct dvb_rc {
2058c2ecf20Sopenharmony_ci	char *rc_codes;
2068c2ecf20Sopenharmony_ci	u64 protocol;
2078c2ecf20Sopenharmony_ci	u64 allowed_protos;
2088c2ecf20Sopenharmony_ci	enum rc_driver_type driver_type;
2098c2ecf20Sopenharmony_ci	int (*change_protocol)(struct rc_dev *dev, u64 *rc_proto);
2108c2ecf20Sopenharmony_ci	char *module_name;
2118c2ecf20Sopenharmony_ci	int (*rc_query) (struct dvb_usb_device *d);
2128c2ecf20Sopenharmony_ci	int rc_interval;
2138c2ecf20Sopenharmony_ci	bool bulk_mode;				/* uses bulk mode */
2148c2ecf20Sopenharmony_ci	u32 scancode_mask;
2158c2ecf20Sopenharmony_ci};
2168c2ecf20Sopenharmony_ci
2178c2ecf20Sopenharmony_ci/**
2188c2ecf20Sopenharmony_ci * enum dvb_usb_mode - Specifies if it is using a legacy driver or a new one
2198c2ecf20Sopenharmony_ci *		       based on rc-core
2208c2ecf20Sopenharmony_ci * This is initialized/used only inside dvb-usb-remote.c.
2218c2ecf20Sopenharmony_ci * It shouldn't be set by the drivers.
2228c2ecf20Sopenharmony_ci */
2238c2ecf20Sopenharmony_cienum dvb_usb_mode {
2248c2ecf20Sopenharmony_ci	DVB_RC_LEGACY,
2258c2ecf20Sopenharmony_ci	DVB_RC_CORE,
2268c2ecf20Sopenharmony_ci};
2278c2ecf20Sopenharmony_ci
2288c2ecf20Sopenharmony_ci/**
2298c2ecf20Sopenharmony_ci * struct dvb_usb_device_properties - properties of a dvb-usb-device
2308c2ecf20Sopenharmony_ci * @usb_ctrl: which USB device-side controller is in use. Needed for firmware
2318c2ecf20Sopenharmony_ci *  download.
2328c2ecf20Sopenharmony_ci * @firmware: name of the firmware file.
2338c2ecf20Sopenharmony_ci * @download_firmware: called to download the firmware when the usb_ctrl is
2348c2ecf20Sopenharmony_ci *  DEVICE_SPECIFIC.
2358c2ecf20Sopenharmony_ci * @no_reconnect: device doesn't do a reconnect after downloading the firmware,
2368c2ecf20Sopenharmony_ci *  so do the warm initialization right after it
2378c2ecf20Sopenharmony_ci *
2388c2ecf20Sopenharmony_ci * @size_of_priv: how many bytes shall be allocated for the private field
2398c2ecf20Sopenharmony_ci *  of struct dvb_usb_device.
2408c2ecf20Sopenharmony_ci * @priv_init: optional callback to initialize the variable that private field
2418c2ecf20Sopenharmony_ci * of struct dvb_usb_device has pointer to just after it had been allocated and
2428c2ecf20Sopenharmony_ci * zeroed.
2438c2ecf20Sopenharmony_ci * @priv_destroy: just like priv_init, only called before deallocating
2448c2ecf20Sopenharmony_ci * the memory pointed by private field of struct dvb_usb_device.
2458c2ecf20Sopenharmony_ci *
2468c2ecf20Sopenharmony_ci * @power_ctrl: called to enable/disable power of the device.
2478c2ecf20Sopenharmony_ci * @read_mac_address: called to read the MAC address of the device.
2488c2ecf20Sopenharmony_ci * @identify_state: called to determine the state (cold or warm), when it
2498c2ecf20Sopenharmony_ci *  is not distinguishable by the USB IDs.
2508c2ecf20Sopenharmony_ci *
2518c2ecf20Sopenharmony_ci * @rc: remote controller properties
2528c2ecf20Sopenharmony_ci *
2538c2ecf20Sopenharmony_ci * @i2c_algo: i2c_algorithm if the device has I2CoverUSB.
2548c2ecf20Sopenharmony_ci *
2558c2ecf20Sopenharmony_ci * @generic_bulk_ctrl_endpoint: most of the DVB USB devices have a generic
2568c2ecf20Sopenharmony_ci *  endpoint which received control messages with bulk transfers. When this
2578c2ecf20Sopenharmony_ci *  is non-zero, one can use dvb_usb_generic_rw and dvb_usb_generic_write-
2588c2ecf20Sopenharmony_ci *  helper functions.
2598c2ecf20Sopenharmony_ci *
2608c2ecf20Sopenharmony_ci * @generic_bulk_ctrl_endpoint_response: some DVB USB devices use a separate
2618c2ecf20Sopenharmony_ci *  endpoint for responses to control messages sent with bulk transfers via
2628c2ecf20Sopenharmony_ci *  the generic_bulk_ctrl_endpoint. When this is non-zero, this will be used
2638c2ecf20Sopenharmony_ci *  instead of the generic_bulk_ctrl_endpoint when reading usb responses in
2648c2ecf20Sopenharmony_ci *  the dvb_usb_generic_rw helper function.
2658c2ecf20Sopenharmony_ci *
2668c2ecf20Sopenharmony_ci * @num_device_descs: number of struct dvb_usb_device_description in @devices
2678c2ecf20Sopenharmony_ci * @devices: array of struct dvb_usb_device_description compatibles with these
2688c2ecf20Sopenharmony_ci *  properties.
2698c2ecf20Sopenharmony_ci */
2708c2ecf20Sopenharmony_ci#define MAX_NO_OF_ADAPTER_PER_DEVICE 2
2718c2ecf20Sopenharmony_cistruct dvb_usb_device_properties {
2728c2ecf20Sopenharmony_ci
2738c2ecf20Sopenharmony_ci#define DVB_USB_IS_AN_I2C_ADAPTER            0x01
2748c2ecf20Sopenharmony_ci	int caps;
2758c2ecf20Sopenharmony_ci
2768c2ecf20Sopenharmony_ci#define DEVICE_SPECIFIC 0
2778c2ecf20Sopenharmony_ci#define CYPRESS_AN2135  1
2788c2ecf20Sopenharmony_ci#define CYPRESS_AN2235  2
2798c2ecf20Sopenharmony_ci#define CYPRESS_FX2     3
2808c2ecf20Sopenharmony_ci	int        usb_ctrl;
2818c2ecf20Sopenharmony_ci	int        (*download_firmware) (struct usb_device *, const struct firmware *);
2828c2ecf20Sopenharmony_ci	const char *firmware;
2838c2ecf20Sopenharmony_ci	int        no_reconnect;
2848c2ecf20Sopenharmony_ci
2858c2ecf20Sopenharmony_ci	int size_of_priv;
2868c2ecf20Sopenharmony_ci	int (*priv_init)(struct dvb_usb_device *);
2878c2ecf20Sopenharmony_ci	void (*priv_destroy)(struct dvb_usb_device *);
2888c2ecf20Sopenharmony_ci
2898c2ecf20Sopenharmony_ci	int num_adapters;
2908c2ecf20Sopenharmony_ci	struct dvb_usb_adapter_properties adapter[MAX_NO_OF_ADAPTER_PER_DEVICE];
2918c2ecf20Sopenharmony_ci
2928c2ecf20Sopenharmony_ci	int (*power_ctrl)       (struct dvb_usb_device *, int);
2938c2ecf20Sopenharmony_ci	int (*read_mac_address) (struct dvb_usb_device *, u8 []);
2948c2ecf20Sopenharmony_ci	int (*identify_state)(struct usb_device *udev,
2958c2ecf20Sopenharmony_ci			      const struct dvb_usb_device_properties *props,
2968c2ecf20Sopenharmony_ci			      const struct dvb_usb_device_description **desc,
2978c2ecf20Sopenharmony_ci			      int *cold);
2988c2ecf20Sopenharmony_ci
2998c2ecf20Sopenharmony_ci	struct {
3008c2ecf20Sopenharmony_ci		enum dvb_usb_mode mode;	/* Drivers shouldn't touch on it */
3018c2ecf20Sopenharmony_ci		struct dvb_rc_legacy legacy;
3028c2ecf20Sopenharmony_ci		struct dvb_rc core;
3038c2ecf20Sopenharmony_ci	} rc;
3048c2ecf20Sopenharmony_ci
3058c2ecf20Sopenharmony_ci	struct i2c_algorithm *i2c_algo;
3068c2ecf20Sopenharmony_ci
3078c2ecf20Sopenharmony_ci	int generic_bulk_ctrl_endpoint;
3088c2ecf20Sopenharmony_ci	int generic_bulk_ctrl_endpoint_response;
3098c2ecf20Sopenharmony_ci
3108c2ecf20Sopenharmony_ci	int num_device_descs;
3118c2ecf20Sopenharmony_ci	struct dvb_usb_device_description devices[12];
3128c2ecf20Sopenharmony_ci};
3138c2ecf20Sopenharmony_ci
3148c2ecf20Sopenharmony_ci/**
3158c2ecf20Sopenharmony_ci * struct usb_data_stream - generic object of an USB stream
3168c2ecf20Sopenharmony_ci * @buf_num: number of buffer allocated.
3178c2ecf20Sopenharmony_ci * @buf_size: size of each buffer in buf_list.
3188c2ecf20Sopenharmony_ci * @buf_list: array containing all allocate buffers for streaming.
3198c2ecf20Sopenharmony_ci * @dma_addr: list of dma_addr_t for each buffer in buf_list.
3208c2ecf20Sopenharmony_ci *
3218c2ecf20Sopenharmony_ci * @urbs_initialized: number of URBs initialized.
3228c2ecf20Sopenharmony_ci * @urbs_submitted: number of URBs submitted.
3238c2ecf20Sopenharmony_ci */
3248c2ecf20Sopenharmony_ci#define MAX_NO_URBS_FOR_DATA_STREAM 10
3258c2ecf20Sopenharmony_cistruct usb_data_stream {
3268c2ecf20Sopenharmony_ci	struct usb_device                 *udev;
3278c2ecf20Sopenharmony_ci	struct usb_data_stream_properties  props;
3288c2ecf20Sopenharmony_ci
3298c2ecf20Sopenharmony_ci#define USB_STATE_INIT    0x00
3308c2ecf20Sopenharmony_ci#define USB_STATE_URB_BUF 0x01
3318c2ecf20Sopenharmony_ci	int state;
3328c2ecf20Sopenharmony_ci
3338c2ecf20Sopenharmony_ci	void (*complete) (struct usb_data_stream *, u8 *, size_t);
3348c2ecf20Sopenharmony_ci
3358c2ecf20Sopenharmony_ci	struct urb    *urb_list[MAX_NO_URBS_FOR_DATA_STREAM];
3368c2ecf20Sopenharmony_ci	int            buf_num;
3378c2ecf20Sopenharmony_ci	unsigned long  buf_size;
3388c2ecf20Sopenharmony_ci	u8            *buf_list[MAX_NO_URBS_FOR_DATA_STREAM];
3398c2ecf20Sopenharmony_ci	dma_addr_t     dma_addr[MAX_NO_URBS_FOR_DATA_STREAM];
3408c2ecf20Sopenharmony_ci
3418c2ecf20Sopenharmony_ci	int urbs_initialized;
3428c2ecf20Sopenharmony_ci	int urbs_submitted;
3438c2ecf20Sopenharmony_ci
3448c2ecf20Sopenharmony_ci	void *user_priv;
3458c2ecf20Sopenharmony_ci};
3468c2ecf20Sopenharmony_ci
3478c2ecf20Sopenharmony_ci/**
3488c2ecf20Sopenharmony_ci * struct dvb_usb_adapter - a DVB adapter on a USB device
3498c2ecf20Sopenharmony_ci * @id: index of this adapter (starting with 0).
3508c2ecf20Sopenharmony_ci *
3518c2ecf20Sopenharmony_ci * @feedcount: number of requested feeds (used for streaming-activation)
3528c2ecf20Sopenharmony_ci * @pid_filtering: is hardware pid_filtering used or not.
3538c2ecf20Sopenharmony_ci *
3548c2ecf20Sopenharmony_ci * @pll_addr: I2C address of the tuner for programming
3558c2ecf20Sopenharmony_ci * @pll_init: array containing the initialization buffer
3568c2ecf20Sopenharmony_ci * @pll_desc: pointer to the appropriate struct dvb_pll_desc
3578c2ecf20Sopenharmony_ci * @tuner_pass_ctrl: called to (de)activate tuner passthru of the demod or the board
3588c2ecf20Sopenharmony_ci *
3598c2ecf20Sopenharmony_ci * @dvb_adap: device's dvb_adapter.
3608c2ecf20Sopenharmony_ci * @dmxdev: device's dmxdev.
3618c2ecf20Sopenharmony_ci * @demux: device's software demuxer.
3628c2ecf20Sopenharmony_ci * @dvb_net: device's dvb_net interfaces.
3638c2ecf20Sopenharmony_ci * @dvb_frontend: device's frontend.
3648c2ecf20Sopenharmony_ci * @max_feed_count: how many feeds can be handled simultaneously by this
3658c2ecf20Sopenharmony_ci *  device
3668c2ecf20Sopenharmony_ci *
3678c2ecf20Sopenharmony_ci * @fe_init:  rerouted frontend-init (wakeup) function.
3688c2ecf20Sopenharmony_ci * @fe_sleep: rerouted frontend-sleep function.
3698c2ecf20Sopenharmony_ci *
3708c2ecf20Sopenharmony_ci * @stream: the usb data stream.
3718c2ecf20Sopenharmony_ci */
3728c2ecf20Sopenharmony_cistruct dvb_usb_fe_adapter {
3738c2ecf20Sopenharmony_ci	struct dvb_frontend *fe;
3748c2ecf20Sopenharmony_ci
3758c2ecf20Sopenharmony_ci	int (*fe_init)  (struct dvb_frontend *);
3768c2ecf20Sopenharmony_ci	int (*fe_sleep) (struct dvb_frontend *);
3778c2ecf20Sopenharmony_ci
3788c2ecf20Sopenharmony_ci	struct usb_data_stream stream;
3798c2ecf20Sopenharmony_ci
3808c2ecf20Sopenharmony_ci	int pid_filtering;
3818c2ecf20Sopenharmony_ci	int max_feed_count;
3828c2ecf20Sopenharmony_ci
3838c2ecf20Sopenharmony_ci	void *priv;
3848c2ecf20Sopenharmony_ci};
3858c2ecf20Sopenharmony_ci
3868c2ecf20Sopenharmony_cistruct dvb_usb_adapter {
3878c2ecf20Sopenharmony_ci	struct dvb_usb_device *dev;
3888c2ecf20Sopenharmony_ci	struct dvb_usb_adapter_properties props;
3898c2ecf20Sopenharmony_ci
3908c2ecf20Sopenharmony_ci#define DVB_USB_ADAP_STATE_INIT 0x000
3918c2ecf20Sopenharmony_ci#define DVB_USB_ADAP_STATE_DVB  0x001
3928c2ecf20Sopenharmony_ci	int state;
3938c2ecf20Sopenharmony_ci
3948c2ecf20Sopenharmony_ci	u8  id;
3958c2ecf20Sopenharmony_ci
3968c2ecf20Sopenharmony_ci	int feedcount;
3978c2ecf20Sopenharmony_ci
3988c2ecf20Sopenharmony_ci	/* dvb */
3998c2ecf20Sopenharmony_ci	struct dvb_adapter   dvb_adap;
4008c2ecf20Sopenharmony_ci	struct dmxdev        dmxdev;
4018c2ecf20Sopenharmony_ci	struct dvb_demux     demux;
4028c2ecf20Sopenharmony_ci	struct dvb_net       dvb_net;
4038c2ecf20Sopenharmony_ci
4048c2ecf20Sopenharmony_ci	struct dvb_usb_fe_adapter fe_adap[MAX_NO_OF_FE_PER_ADAP];
4058c2ecf20Sopenharmony_ci	int active_fe;
4068c2ecf20Sopenharmony_ci	int num_frontends_initialized;
4078c2ecf20Sopenharmony_ci
4088c2ecf20Sopenharmony_ci	void *priv;
4098c2ecf20Sopenharmony_ci};
4108c2ecf20Sopenharmony_ci
4118c2ecf20Sopenharmony_ci/**
4128c2ecf20Sopenharmony_ci * struct dvb_usb_device - object of a DVB USB device
4138c2ecf20Sopenharmony_ci * @props: copy of the struct dvb_usb_properties this device belongs to.
4148c2ecf20Sopenharmony_ci * @desc: pointer to the device's struct dvb_usb_device_description.
4158c2ecf20Sopenharmony_ci * @state: initialization and runtime state of the device.
4168c2ecf20Sopenharmony_ci *
4178c2ecf20Sopenharmony_ci * @powered: indicated whether the device is power or not.
4188c2ecf20Sopenharmony_ci *  Powered is in/decremented for each call to modify the state.
4198c2ecf20Sopenharmony_ci * @udev: pointer to the device's struct usb_device.
4208c2ecf20Sopenharmony_ci *
4218c2ecf20Sopenharmony_ci * @data_mutex: mutex to protect the data structure used to store URB data
4228c2ecf20Sopenharmony_ci * @usb_mutex: mutex of USB control messages (reading needs two messages).
4238c2ecf20Sopenharmony_ci *	Please notice that this mutex is used internally at the generic
4248c2ecf20Sopenharmony_ci *	URB control functions. So, drivers using dvb_usb_generic_rw() and
4258c2ecf20Sopenharmony_ci *	derivated functions should not lock it internally.
4268c2ecf20Sopenharmony_ci * @i2c_mutex: mutex for i2c-transfers
4278c2ecf20Sopenharmony_ci *
4288c2ecf20Sopenharmony_ci * @i2c_adap: device's i2c_adapter if it uses I2CoverUSB
4298c2ecf20Sopenharmony_ci *
4308c2ecf20Sopenharmony_ci * @rc_dev: rc device for the remote control (rc-core mode)
4318c2ecf20Sopenharmony_ci * @input_dev: input device for the remote control (legacy mode)
4328c2ecf20Sopenharmony_ci * @rc_query_work: struct work_struct frequent rc queries
4338c2ecf20Sopenharmony_ci * @last_event: last triggered event
4348c2ecf20Sopenharmony_ci * @last_state: last state (no, pressed, repeat)
4358c2ecf20Sopenharmony_ci * @owner: owner of the dvb_adapter
4368c2ecf20Sopenharmony_ci * @priv: private data of the actual driver (allocate by dvb-usb, size defined
4378c2ecf20Sopenharmony_ci *  in size_of_priv of dvb_usb_properties).
4388c2ecf20Sopenharmony_ci */
4398c2ecf20Sopenharmony_cistruct dvb_usb_device {
4408c2ecf20Sopenharmony_ci	struct dvb_usb_device_properties props;
4418c2ecf20Sopenharmony_ci	const struct dvb_usb_device_description *desc;
4428c2ecf20Sopenharmony_ci
4438c2ecf20Sopenharmony_ci	struct usb_device *udev;
4448c2ecf20Sopenharmony_ci
4458c2ecf20Sopenharmony_ci#define DVB_USB_STATE_INIT        0x000
4468c2ecf20Sopenharmony_ci#define DVB_USB_STATE_I2C         0x001
4478c2ecf20Sopenharmony_ci#define DVB_USB_STATE_DVB         0x002
4488c2ecf20Sopenharmony_ci#define DVB_USB_STATE_REMOTE      0x004
4498c2ecf20Sopenharmony_ci	int state;
4508c2ecf20Sopenharmony_ci
4518c2ecf20Sopenharmony_ci	int powered;
4528c2ecf20Sopenharmony_ci
4538c2ecf20Sopenharmony_ci	/* locking */
4548c2ecf20Sopenharmony_ci	struct mutex data_mutex;
4558c2ecf20Sopenharmony_ci	struct mutex usb_mutex;
4568c2ecf20Sopenharmony_ci
4578c2ecf20Sopenharmony_ci	/* i2c */
4588c2ecf20Sopenharmony_ci	struct mutex i2c_mutex;
4598c2ecf20Sopenharmony_ci	struct i2c_adapter i2c_adap;
4608c2ecf20Sopenharmony_ci
4618c2ecf20Sopenharmony_ci	int                    num_adapters_initialized;
4628c2ecf20Sopenharmony_ci	struct dvb_usb_adapter adapter[MAX_NO_OF_ADAPTER_PER_DEVICE];
4638c2ecf20Sopenharmony_ci
4648c2ecf20Sopenharmony_ci	/* remote control */
4658c2ecf20Sopenharmony_ci	struct rc_dev *rc_dev;
4668c2ecf20Sopenharmony_ci	struct input_dev *input_dev;
4678c2ecf20Sopenharmony_ci	char rc_phys[64];
4688c2ecf20Sopenharmony_ci	struct delayed_work rc_query_work;
4698c2ecf20Sopenharmony_ci	u32 last_event;
4708c2ecf20Sopenharmony_ci	int last_state;
4718c2ecf20Sopenharmony_ci
4728c2ecf20Sopenharmony_ci	struct module *owner;
4738c2ecf20Sopenharmony_ci
4748c2ecf20Sopenharmony_ci	void *priv;
4758c2ecf20Sopenharmony_ci};
4768c2ecf20Sopenharmony_ci
4778c2ecf20Sopenharmony_ciextern int dvb_usb_device_init(struct usb_interface *,
4788c2ecf20Sopenharmony_ci			       const struct dvb_usb_device_properties *,
4798c2ecf20Sopenharmony_ci			       struct module *, struct dvb_usb_device **,
4808c2ecf20Sopenharmony_ci			       short *adapter_nums);
4818c2ecf20Sopenharmony_ciextern void dvb_usb_device_exit(struct usb_interface *);
4828c2ecf20Sopenharmony_ci
4838c2ecf20Sopenharmony_ci/* the generic read/write method for device control */
4848c2ecf20Sopenharmony_ciextern int __must_check
4858c2ecf20Sopenharmony_cidvb_usb_generic_rw(struct dvb_usb_device *, u8 *, u16, u8 *, u16, int);
4868c2ecf20Sopenharmony_ciextern int __must_check
4878c2ecf20Sopenharmony_cidvb_usb_generic_write(struct dvb_usb_device *, u8 *, u16);
4888c2ecf20Sopenharmony_ci
4898c2ecf20Sopenharmony_ci/* commonly used remote control parsing */
4908c2ecf20Sopenharmony_ciextern int dvb_usb_nec_rc_key_to_event(struct dvb_usb_device *, u8[5], u32 *, int *);
4918c2ecf20Sopenharmony_ci
4928c2ecf20Sopenharmony_ci/* commonly used firmware download types and function */
4938c2ecf20Sopenharmony_cistruct hexline {
4948c2ecf20Sopenharmony_ci	u8 len;
4958c2ecf20Sopenharmony_ci	u32 addr;
4968c2ecf20Sopenharmony_ci	u8 type;
4978c2ecf20Sopenharmony_ci	u8 data[255];
4988c2ecf20Sopenharmony_ci	u8 chk;
4998c2ecf20Sopenharmony_ci};
5008c2ecf20Sopenharmony_ciextern int usb_cypress_load_firmware(struct usb_device *udev, const struct firmware *fw, int type);
5018c2ecf20Sopenharmony_ciextern int dvb_usb_get_hexline(const struct firmware *fw, struct hexline *hx, int *pos);
5028c2ecf20Sopenharmony_ci
5038c2ecf20Sopenharmony_ci
5048c2ecf20Sopenharmony_ci#endif
505