License cleanup: add SPDX GPL-2.0 license identifier to files with no license
[linux-2.6-block.git] / drivers / media / usb / dvb-usb / dvb-usb.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
776338e1
JS
2/* dvb-usb.h is part of the DVB USB library.
3 *
99e44da7 4 * Copyright (C) 2004-6 Patrick Boettcher (patrick.boettcher@posteo.de)
776338e1
JS
5 * see dvb-usb-init.c for copyright information.
6 *
7 * the headerfile, all dvb-usb-drivers have to include.
4d43e13f
PB
8 *
9 * TODO: clean-up the structures for unused fields and update the comments
776338e1
JS
10 */
11#ifndef __DVB_USB_H__
12#define __DVB_USB_H__
13
776338e1 14#include <linux/input.h>
776338e1 15#include <linux/usb.h>
d3707add 16#include <linux/firmware.h>
3593cab5 17#include <linux/mutex.h>
6bda9644 18#include <media/rc-core.h>
776338e1
JS
19
20#include "dvb_frontend.h"
21#include "dvb_demux.h"
22#include "dvb_net.h"
23#include "dmxdev.h"
24
25#include "dvb-pll.h"
26
27#include "dvb-usb-ids.h"
28
29/* debug */
30#ifdef CONFIG_DVB_USB_DEBUG
31#define dprintk(var,level,args...) \
32 do { if ((var & level)) { printk(args); } } while (0)
33
34#define debug_dump(b,l,func) {\
35 int loop_; \
36 for (loop_ = 0; loop_ < l; loop_++) func("%02x ", b[loop_]); \
37 func("\n");\
38}
39#define DVB_USB_DEBUG_STATUS
40#else
41#define dprintk(args...)
42#define debug_dump(b,l,func)
43
44#define DVB_USB_DEBUG_STATUS " (debugging is not enabled)"
45
46#endif
47
48/* generic log methods - taken from usb.h */
49#ifndef DVB_USB_LOG_PREFIX
50 #define DVB_USB_LOG_PREFIX "dvb-usb (please define a log prefix)"
51#endif
52
53#undef err
54#define err(format, arg...) printk(KERN_ERR DVB_USB_LOG_PREFIX ": " format "\n" , ## arg)
55#undef info
56#define info(format, arg...) printk(KERN_INFO DVB_USB_LOG_PREFIX ": " format "\n" , ## arg)
57#undef warn
58#define warn(format, arg...) printk(KERN_WARNING DVB_USB_LOG_PREFIX ": " format "\n" , ## arg)
59
60/**
61 * struct dvb_usb_device_description - name and its according USB IDs
62 * @name: real name of the box, regardless which DVB USB device class is in use
63 * @cold_ids: array of struct usb_device_id which describe the device in
64 * pre-firmware state
65 * @warm_ids: array of struct usb_device_id which describe the device in
66 * post-firmware state
67 *
68 * Each DVB USB device class can have one or more actual devices, this struct
69 * assigns a name to it.
70 */
71struct dvb_usb_device_description {
72 const char *name;
73
74#define DVB_USB_ID_MAX_NUM 15
75 struct usb_device_id *cold_ids[DVB_USB_ID_MAX_NUM];
76 struct usb_device_id *warm_ids[DVB_USB_ID_MAX_NUM];
77};
78
2f4f58d6 79static inline u8 rc5_custom(struct rc_map_table *key)
2e365883 80{
34abf219 81 return (key->scancode >> 8) & 0xff;
2e365883
MCC
82}
83
2f4f58d6 84static inline u8 rc5_data(struct rc_map_table *key)
2e365883 85{
34abf219 86 return key->scancode & 0xff;
2e365883
MCC
87}
88
147b68cd 89static inline u16 rc5_scan(struct rc_map_table *key)
2e365883 90{
34abf219 91 return key->scancode & 0xffff;
2e365883
MCC
92}
93
776338e1 94struct dvb_usb_device;
4d43e13f
PB
95struct dvb_usb_adapter;
96struct usb_data_stream;
776338e1
JS
97
98/**
136cafbf
PB
99 * Properties of USB streaming - TODO this structure should be somewhere else
100 * describes the kind of USB transfer used for data-streaming.
4d43e13f
PB
101 * (BULK or ISOC)
102 */
103struct usb_data_stream_properties {
104#define USB_BULK 1
105#define USB_ISOC 2
106 int type;
107 int count;
108 int endpoint;
109
110 union {
111 struct {
112 int buffersize; /* per URB */
113 } bulk;
114 struct {
115 int framesperurb;
116 int framesize;
117 int interval;
118 } isoc;
119 } u;
120};
121
122/**
123 * struct dvb_usb_adapter_properties - properties of a dvb-usb-adapter.
124 * A DVB-USB-Adapter is basically a dvb_adapter which is present on a USB-device.
be787ace 125 * @caps: capabilities of the DVB USB device.
776338e1
JS
126 * @pid_filter_count: number of PID filter position in the optional hardware
127 * PID-filter.
9bd9e3bd
AP
128 * @num_frontends: number of frontends of the DVB USB adapter.
129 * @frontend_ctrl: called to power on/off active frontend.
09129f0d 130 * @streaming_ctrl: called to start and stop the MPEG2-TS streaming of the
4d43e13f
PB
131 * device (not URB submitting/killing).
132 * @pid_filter_ctrl: called to en/disable the PID filter, if any.
133 * @pid_filter: called to set/unset a PID for filtering.
134 * @frontend_attach: called to attach the possible frontends (fill fe-field
135 * of struct dvb_usb_device).
136 * @tuner_attach: called to attach the correct tuner and to fill pll_addr,
137 * pll_desc and pll_init_buf of struct dvb_usb_device).
138 * @stream: configuration of the USB streaming
139 */
77eed219 140struct dvb_usb_adapter_fe_properties {
4d43e13f
PB
141#define DVB_USB_ADAP_HAS_PID_FILTER 0x01
142#define DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF 0x02
143#define DVB_USB_ADAP_NEED_PID_FILTERING 0x04
0540c496 144#define DVB_USB_ADAP_RECEIVES_204_BYTE_TS 0x08
379aa4d0 145#define DVB_USB_ADAP_RECEIVES_RAW_PAYLOAD 0x10
4d43e13f
PB
146 int caps;
147 int pid_filter_count;
148
149 int (*streaming_ctrl) (struct dvb_usb_adapter *, int);
150 int (*pid_filter_ctrl) (struct dvb_usb_adapter *, int);
151 int (*pid_filter) (struct dvb_usb_adapter *, int, u16, int);
152
153 int (*frontend_attach) (struct dvb_usb_adapter *);
154 int (*tuner_attach) (struct dvb_usb_adapter *);
155
156 struct usb_data_stream_properties stream;
157
158 int size_of_priv;
77eed219
MK
159};
160
52660885 161#define MAX_NO_OF_FE_PER_ADAP 3
77eed219
MK
162struct dvb_usb_adapter_properties {
163 int size_of_priv;
94d98314 164
77eed219 165 int (*frontend_ctrl) (struct dvb_frontend *, int);
77eed219
MK
166
167 int num_frontends;
168 struct dvb_usb_adapter_fe_properties fe[MAX_NO_OF_FE_PER_ADAP];
4d43e13f
PB
169};
170
f72a27b8
MCC
171/**
172 * struct dvb_rc_legacy - old properties of remote controller
2f4f58d6 173 * @rc_map_table: a hard-wired array of struct rc_map_table (NULL to disable
f72a27b8 174 * remote control handling).
2f4f58d6 175 * @rc_map_size: number of items in @rc_map_table.
f72a27b8
MCC
176 * @rc_query: called to query an event event.
177 * @rc_interval: time in ms between two queries.
178 */
179struct dvb_rc_legacy {
180/* remote control properties */
181#define REMOTE_NO_KEY_PRESSED 0x00
182#define REMOTE_KEY_PRESSED 0x01
183#define REMOTE_KEY_REPEAT 0x02
2f4f58d6
MCC
184 struct rc_map_table *rc_map_table;
185 int rc_map_size;
f72a27b8
MCC
186 int (*rc_query) (struct dvb_usb_device *, u32 *, int *);
187 int rc_interval;
188};
189
6520342b
MCC
190/**
191 * struct dvb_rc properties of remote controller, using rc-core
192 * @rc_codes: name of rc codes table
0ffd1ab3 193 * @protocol: type of protocol(s) currently used by the driver
d8b4b582 194 * @allowed_protos: protocol(s) supported by the driver
739ff04f 195 * @driver_type: Used to point if a device supports raw mode
d8b4b582 196 * @change_protocol: callback to change protocol
6520342b
MCC
197 * @rc_query: called to query an event event.
198 * @rc_interval: time in ms between two queries.
6520342b
MCC
199 * @bulk_mode: device supports bulk mode for RC (disable polling mode)
200 */
201struct dvb_rc {
202 char *rc_codes;
0ffd1ab3 203 u64 protocol;
d8b4b582 204 u64 allowed_protos;
739ff04f 205 enum rc_driver_type driver_type;
6d741bfe 206 int (*change_protocol)(struct rc_dev *dev, u64 *rc_proto);
6520342b
MCC
207 char *module_name;
208 int (*rc_query) (struct dvb_usb_device *d);
209 int rc_interval;
6520342b
MCC
210 bool bulk_mode; /* uses bulk mode */
211};
212
213/**
214 * enum dvb_usb_mode - Specifies if it is using a legacy driver or a new one
215 * based on rc-core
216 * This is initialized/used only inside dvb-usb-remote.c.
217 * It shouldn't be set by the drivers.
218 */
219enum dvb_usb_mode {
220 DVB_RC_LEGACY,
221 DVB_RC_CORE,
222};
223
4d43e13f
PB
224/**
225 * struct dvb_usb_device_properties - properties of a dvb-usb-device
776338e1
JS
226 * @usb_ctrl: which USB device-side controller is in use. Needed for firmware
227 * download.
228 * @firmware: name of the firmware file.
d3707add
PB
229 * @download_firmware: called to download the firmware when the usb_ctrl is
230 * DEVICE_SPECIFIC.
231 * @no_reconnect: device doesn't do a reconnect after downloading the firmware,
4d43e13f
PB
232 * so do the warm initialization right after it
233 *
776338e1
JS
234 * @size_of_priv: how many bytes shall be allocated for the private field
235 * of struct dvb_usb_device.
236 *
237 * @power_ctrl: called to enable/disable power of the device.
776338e1 238 * @read_mac_address: called to read the MAC address of the device.
776338e1
JS
239 * @identify_state: called to determine the state (cold or warm), when it
240 * is not distinguishable by the USB IDs.
241 *
f72a27b8 242 * @rc: remote controller properties
776338e1
JS
243 *
244 * @i2c_algo: i2c_algorithm if the device has I2CoverUSB.
245 *
246 * @generic_bulk_ctrl_endpoint: most of the DVB USB devices have a generic
247 * endpoint which received control messages with bulk transfers. When this
248 * is non-zero, one can use dvb_usb_generic_rw and dvb_usb_generic_write-
249 * helper functions.
250 *
4605664b
MK
251 * @generic_bulk_ctrl_endpoint_response: some DVB USB devices use a separate
252 * endpoint for responses to control messages sent with bulk transfers via
253 * the generic_bulk_ctrl_endpoint. When this is non-zero, this will be used
254 * instead of the generic_bulk_ctrl_endpoint when reading usb responses in
255 * the dvb_usb_generic_rw helper function.
256 *
776338e1
JS
257 * @num_device_descs: number of struct dvb_usb_device_description in @devices
258 * @devices: array of struct dvb_usb_device_description compatibles with these
259 * properties.
260 */
4d43e13f
PB
261#define MAX_NO_OF_ADAPTER_PER_DEVICE 2
262struct dvb_usb_device_properties {
776338e1 263
4d43e13f 264#define DVB_USB_IS_AN_I2C_ADAPTER 0x01
776338e1 265 int caps;
776338e1 266
d3707add
PB
267#define DEVICE_SPECIFIC 0
268#define CYPRESS_AN2135 1
269#define CYPRESS_AN2235 2
270#define CYPRESS_FX2 3
136cafbf
PB
271 int usb_ctrl;
272 int (*download_firmware) (struct usb_device *, const struct firmware *);
56aec8d8 273 const char *firmware;
136cafbf 274 int no_reconnect;
776338e1
JS
275
276 int size_of_priv;
277
4d43e13f
PB
278 int num_adapters;
279 struct dvb_usb_adapter_properties adapter[MAX_NO_OF_ADAPTER_PER_DEVICE];
776338e1 280
4d43e13f 281 int (*power_ctrl) (struct dvb_usb_device *, int);
776338e1 282 int (*read_mac_address) (struct dvb_usb_device *, u8 []);
4d43e13f 283 int (*identify_state) (struct usb_device *, struct dvb_usb_device_properties *,
776338e1
JS
284 struct dvb_usb_device_description **, int *);
285
6520342b
MCC
286 struct {
287 enum dvb_usb_mode mode; /* Drivers shouldn't touch on it */
f72a27b8 288 struct dvb_rc_legacy legacy;
6520342b 289 struct dvb_rc core;
f72a27b8 290 } rc;
776338e1
JS
291
292 struct i2c_algorithm *i2c_algo;
293
294 int generic_bulk_ctrl_endpoint;
4605664b 295 int generic_bulk_ctrl_endpoint_response;
776338e1 296
776338e1 297 int num_device_descs;
513846ec 298 struct dvb_usb_device_description devices[12];
776338e1
JS
299};
300
776338e1 301/**
4d43e13f 302 * struct usb_data_stream - generic object of an USB stream
7f5fee57
PB
303 * @buf_num: number of buffer allocated.
304 * @buf_size: size of each buffer in buf_list.
305 * @buf_list: array containing all allocate buffers for streaming.
306 * @dma_addr: list of dma_addr_t for each buffer in buf_list.
307 *
776338e1
JS
308 * @urbs_initialized: number of URBs initialized.
309 * @urbs_submitted: number of URBs submitted.
4d43e13f
PB
310 */
311#define MAX_NO_URBS_FOR_DATA_STREAM 10
312struct usb_data_stream {
136cafbf
PB
313 struct usb_device *udev;
314 struct usb_data_stream_properties props;
4d43e13f
PB
315
316#define USB_STATE_INIT 0x00
317#define USB_STATE_URB_BUF 0x01
318 int state;
319
320 void (*complete) (struct usb_data_stream *, u8 *, size_t);
321
136cafbf
PB
322 struct urb *urb_list[MAX_NO_URBS_FOR_DATA_STREAM];
323 int buf_num;
324 unsigned long buf_size;
325 u8 *buf_list[MAX_NO_URBS_FOR_DATA_STREAM];
326 dma_addr_t dma_addr[MAX_NO_URBS_FOR_DATA_STREAM];
4d43e13f
PB
327
328 int urbs_initialized;
329 int urbs_submitted;
330
331 void *user_priv;
332};
333
334/**
335 * struct dvb_usb_adapter - a DVB adapter on a USB device
336 * @id: index of this adapter (starting with 0).
337 *
776338e1
JS
338 * @feedcount: number of reqested feeds (used for streaming-activation)
339 * @pid_filtering: is hardware pid_filtering used or not.
7f5fee57 340 *
776338e1
JS
341 * @pll_addr: I2C address of the tuner for programming
342 * @pll_init: array containing the initialization buffer
343 * @pll_desc: pointer to the appropriate struct dvb_pll_desc
7f5fee57 344 * @tuner_pass_ctrl: called to (de)activate tuner passthru of the demod or the board
136cafbf 345 *
776338e1
JS
346 * @dvb_adap: device's dvb_adapter.
347 * @dmxdev: device's dmxdev.
348 * @demux: device's software demuxer.
349 * @dvb_net: device's dvb_net interfaces.
350 * @dvb_frontend: device's frontend.
351 * @max_feed_count: how many feeds can be handled simultaneously by this
352 * device
136cafbf
PB
353 *
354 * @fe_init: rerouted frontend-init (wakeup) function.
776338e1 355 * @fe_sleep: rerouted frontend-sleep function.
136cafbf 356 *
4d43e13f
PB
357 * @stream: the usb data stream.
358 */
77eed219
MK
359struct dvb_usb_fe_adapter {
360 struct dvb_frontend *fe;
361
362 int (*fe_init) (struct dvb_frontend *);
363 int (*fe_sleep) (struct dvb_frontend *);
364
365 struct usb_data_stream stream;
366
367 int pid_filtering;
368 int max_feed_count;
369
370 void *priv;
371};
372
4d43e13f
PB
373struct dvb_usb_adapter {
374 struct dvb_usb_device *dev;
375 struct dvb_usb_adapter_properties props;
376
377#define DVB_USB_ADAP_STATE_INIT 0x000
378#define DVB_USB_ADAP_STATE_DVB 0x001
379 int state;
380
136cafbf 381 u8 id;
4d43e13f
PB
382
383 int feedcount;
4d43e13f 384
4d43e13f
PB
385 /* dvb */
386 struct dvb_adapter dvb_adap;
387 struct dmxdev dmxdev;
388 struct dvb_demux demux;
389 struct dvb_net dvb_net;
4d43e13f 390
77eed219
MK
391 struct dvb_usb_fe_adapter fe_adap[MAX_NO_OF_FE_PER_ADAP];
392 int active_fe;
393 int num_frontends_initialized;
4d43e13f
PB
394
395 void *priv;
396};
397
398/**
399 * struct dvb_usb_device - object of a DVB USB device
400 * @props: copy of the struct dvb_usb_properties this device belongs to.
401 * @desc: pointer to the device's struct dvb_usb_device_description.
402 * @state: initialization and runtime state of the device.
403 *
a37ddced
PB
404 * @powered: indicated whether the device is power or not.
405 * Powered is in/decremented for each call to modify the state.
4d43e13f
PB
406 * @udev: pointer to the device's struct usb_device.
407 *
7724325a
MCC
408 * @data_mutex: mutex to protect the data structure used to store URB data
409 * @usb_mutex: mutex of USB control messages (reading needs two messages).
410 * Please notice that this mutex is used internally at the generic
411 * URB control functions. So, drivers using dvb_usb_generic_rw() and
412 * derivated functions should not lock it internally.
413 * @i2c_mutex: mutex for i2c-transfers
4d43e13f
PB
414 *
415 * @i2c_adap: device's i2c_adapter if it uses I2CoverUSB
416 *
d8b4b582
DH
417 * @rc_dev: rc device for the remote control (rc-core mode)
418 * @input_dev: input device for the remote control (legacy mode)
776338e1
JS
419 * @rc_query_work: struct work_struct frequent rc queries
420 * @last_event: last triggered event
421 * @last_state: last state (no, pressed, repeat)
422 * @owner: owner of the dvb_adapter
423 * @priv: private data of the actual driver (allocate by dvb-usb, size defined
424 * in size_of_priv of dvb_usb_properties).
425 */
426struct dvb_usb_device {
4d43e13f 427 struct dvb_usb_device_properties props;
776338e1
JS
428 struct dvb_usb_device_description *desc;
429
776338e1 430 struct usb_device *udev;
7f5fee57 431
4d43e13f
PB
432#define DVB_USB_STATE_INIT 0x000
433#define DVB_USB_STATE_I2C 0x001
434#define DVB_USB_STATE_DVB 0x002
435#define DVB_USB_STATE_REMOTE 0x004
436 int state;
776338e1 437
4d43e13f 438 int powered;
776338e1
JS
439
440 /* locking */
7724325a 441 struct mutex data_mutex;
3593cab5 442 struct mutex usb_mutex;
776338e1
JS
443
444 /* i2c */
3593cab5 445 struct mutex i2c_mutex;
776338e1
JS
446 struct i2c_adapter i2c_adap;
447
4d43e13f
PB
448 int num_adapters_initialized;
449 struct dvb_usb_adapter adapter[MAX_NO_OF_ADAPTER_PER_DEVICE];
776338e1
JS
450
451 /* remote control */
d8b4b582
DH
452 struct rc_dev *rc_dev;
453 struct input_dev *input_dev;
b7df3910 454 char rc_phys[64];
c4028958 455 struct delayed_work rc_query_work;
776338e1
JS
456 u32 last_event;
457 int last_state;
458
459 struct module *owner;
460
461 void *priv;
462};
463
78e92006
JG
464extern int dvb_usb_device_init(struct usb_interface *,
465 struct dvb_usb_device_properties *,
466 struct module *, struct dvb_usb_device **,
467 short *adapter_nums);
776338e1
JS
468extern void dvb_usb_device_exit(struct usb_interface *);
469
470/* the generic read/write method for device control */
11a1e0ed
MCC
471extern int __must_check
472dvb_usb_generic_rw(struct dvb_usb_device *, u8 *, u16, u8 *, u16, int);
473extern int __must_check
474dvb_usb_generic_write(struct dvb_usb_device *, u8 *, u16);
776338e1
JS
475
476/* commonly used remote control parsing */
477extern int dvb_usb_nec_rc_key_to_event(struct dvb_usb_device *, u8[], u32 *, int *);
478
d3707add
PB
479/* commonly used firmware download types and function */
480struct hexline {
481 u8 len;
482 u32 addr;
483 u8 type;
484 u8 data[255];
485 u8 chk;
486};
f5373788 487extern int usb_cypress_load_firmware(struct usb_device *udev, const struct firmware *fw, int type);
136cafbf
PB
488extern int dvb_usb_get_hexline(const struct firmware *fw, struct hexline *hx, int *pos);
489
776338e1
JS
490
491#endif