]> git.proxmox.com Git - mirror_ubuntu-kernels.git/blame - drivers/media/usb/dvb-usb-v2/dvb_usb.h
Merge branches 'for-5.1/upstream-fixes', 'for-5.2/core', 'for-5.2/ish', 'for-5.2...
[mirror_ubuntu-kernels.git] / drivers / media / usb / dvb-usb-v2 / dvb_usb.h
CommitLineData
12042b05
AP
1/*
2 * DVB USB framework
3 *
99e44da7 4 * Copyright (C) 2004-6 Patrick Boettcher <patrick.boettcher@posteo.de>
12042b05 5 * Copyright (C) 2012 Antti Palosaari <crope@iki.fi>
c79b339f 6 *
12042b05
AP
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
c79b339f 11 *
12042b05
AP
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
c79b339f 20 */
12042b05 21
c79b339f
AP
22#ifndef DVB_USB_H
23#define DVB_USB_H
24
831511bd 25#include <linux/usb/input.h>
c79b339f 26#include <linux/firmware.h>
c79b339f 27#include <media/rc-core.h>
6f6c77d8 28#include <media/media-device.h>
c79b339f 29
fada1935
MCC
30#include <media/dvb_frontend.h>
31#include <media/dvb_demux.h>
32#include <media/dvb_net.h>
33#include <media/dmxdev.h>
34#include <media/dvb-usb-ids.h>
c79b339f 35
f93c8028
AP
36/*
37 * device file: /dev/dvb/adapter[0-1]/frontend[0-2]
38 *
39 * |-- device
40 * | |-- adapter0
41 * | | |-- frontend0
42 * | | |-- frontend1
43 * | | `-- frontend2
44 * | `-- adapter1
45 * | |-- frontend0
46 * | |-- frontend1
47 * | `-- frontend2
48 *
49 *
50 * Commonly used variable names:
51 * d = pointer to device (struct dvb_usb_device *)
52 * adap = pointer to adapter (struct dvb_usb_adapter *)
53 * fe = pointer to frontend (struct dvb_frontend *)
54 *
55 * Use macros defined in that file to resolve needed pointers.
56 */
57
f89f9ff8 58/* helper macros for every DVB USB driver use */
ec0dd2f2
AP
59#define adap_to_d(adap) (container_of(adap, struct dvb_usb_device, \
60 adapter[adap->id]))
f89f9ff8
AP
61#define adap_to_priv(adap) (adap_to_d(adap)->priv)
62#define fe_to_adap(fe) ((struct dvb_usb_adapter *) ((fe)->dvb->priv))
63#define fe_to_d(fe) (adap_to_d(fe_to_adap(fe)))
64#define fe_to_priv(fe) (fe_to_d(fe)->priv)
65#define d_to_priv(d) (d->priv)
66
4ab79283
AP
67#define dvb_usb_dbg_usb_control_msg(udev, r, t, v, i, b, l) { \
68 char *direction; \
69 if (t == (USB_TYPE_VENDOR | USB_DIR_OUT)) \
70 direction = ">>>"; \
71 else \
72 direction = "<<<"; \
73 dev_dbg(&udev->dev, "%s: %02x %02x %02x %02x %02x %02x %02x %02x " \
74 "%s %*ph\n", __func__, t, r, v & 0xff, v >> 8, \
75 i & 0xff, i >> 8, l & 0xff, l >> 8, direction, l, b); \
76}
77
12077a3a
AP
78#define DVB_USB_STREAM_BULK(endpoint_, count_, size_) { \
79 .type = USB_BULK, \
80 .count = count_, \
81 .endpoint = endpoint_, \
82 .u = { \
83 .bulk = { \
84 .buffersize = size_, \
85 } \
86 } \
87}
88
89#define DVB_USB_STREAM_ISOC(endpoint_, count_, frames_, size_, interval_) { \
90 .type = USB_ISOC, \
91 .count = count_, \
92 .endpoint = endpoint_, \
93 .u = { \
94 .isoc = { \
95 .framesperurb = frames_, \
96 .framesize = size_,\
97 .interval = interval_, \
98 } \
99 } \
100}
c79b339f 101
0359b5fa
AP
102#define DVB_USB_DEVICE(vend, prod, props_, name_, rc) \
103 .match_flags = USB_DEVICE_ID_MATCH_DEVICE, \
104 .idVendor = (vend), \
105 .idProduct = (prod), \
acaec14f 106 .driver_info = (kernel_ulong_t) &((const struct dvb_usb_driver_info) { \
0359b5fa
AP
107 .props = (props_), \
108 .name = (name_), \
109 .rc_map = (rc), \
110 })
111
831511bd
AP
112struct dvb_usb_device;
113struct dvb_usb_adapter;
114
f93c8028
AP
115/**
116 * structure for carrying all needed data from the device driver to the general
117 * dvb usb routines
118 * @name: device name
119 * @rc_map: name of rc codes table
120 * @props: structure containing all device properties
121 */
12077a3a
AP
122struct dvb_usb_driver_info {
123 const char *name;
124 const char *rc_map;
125 const struct dvb_usb_device_properties *props;
126};
127
831511bd 128/**
f93c8028
AP
129 * structure for remote controller configuration
130 * @map_name: name of rc codes table
831511bd 131 * @allowed_protos: protocol(s) supported by the driver
831511bd 132 * @change_protocol: callback to change protocol
f93c8028
AP
133 * @query: called to query an event from the device
134 * @interval: time in ms between two queries
135 * @driver_type: used to point if a device supports raw mode
136 * @bulk_mode: device supports bulk mode for rc (disable polling mode)
831511bd
AP
137 */
138struct dvb_usb_rc {
de73beee 139 const char *map_name;
831511bd 140 u64 allowed_protos;
6d741bfe 141 int (*change_protocol)(struct rc_dev *dev, u64 *rc_proto);
831511bd
AP
142 int (*query) (struct dvb_usb_device *d);
143 unsigned int interval;
1e41413f 144 enum rc_driver_type driver_type;
831511bd
AP
145 bool bulk_mode;
146};
c79b339f
AP
147
148/**
3e4d8f48 149 * usb streaming configuration for adapter
f93c8028
AP
150 * @type: urb type
151 * @count: count of used urbs
152 * @endpoint: stream usb endpoint number
c79b339f
AP
153 */
154struct usb_data_stream_properties {
155#define USB_BULK 1
156#define USB_ISOC 2
831511bd
AP
157 u8 type;
158 u8 count;
159 u8 endpoint;
c79b339f
AP
160
161 union {
162 struct {
831511bd 163 unsigned int buffersize; /* per URB */
c79b339f
AP
164 } bulk;
165 struct {
166 int framesperurb;
167 int framesize;
168 int interval;
169 } isoc;
170 } u;
171};
172
173/**
f93c8028
AP
174 * properties of dvb usb device adapter
175 * @caps: adapter capabilities
176 * @pid_filter_count: pid count of adapter pid-filter
177 * @pid_filter_ctrl: called to enable/disable pid-filter
178 * @pid_filter: called to set/unset pid for filtering
179 * @stream: adapter usb stream configuration
c79b339f 180 */
c79b339f
AP
181#define MAX_NO_OF_FE_PER_ADAP 3
182struct dvb_usb_adapter_properties {
e46c5b66
AP
183#define DVB_USB_ADAP_HAS_PID_FILTER 0x01
184#define DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF 0x02
185#define DVB_USB_ADAP_NEED_PID_FILTERING 0x04
831511bd 186 u8 caps;
c79b339f 187
831511bd 188 u8 pid_filter_count;
e46c5b66
AP
189 int (*pid_filter_ctrl) (struct dvb_usb_adapter *, int);
190 int (*pid_filter) (struct dvb_usb_adapter *, int, u16, int);
191
3024985d 192 struct usb_data_stream_properties stream;
c79b339f
AP
193};
194
c79b339f
AP
195/**
196 * struct dvb_usb_device_properties - properties of a dvb-usb-device
f93c8028 197 * @driver_name: name of the owning driver module
654e62dc 198 * @owner: owner of the dvb_adapter
f93c8028
AP
199 * @adapter_nr: values from the DVB_DEFINE_MOD_OPT_ADAPTER_NR() macro
200 * @bInterfaceNumber: usb interface number driver binds
201 * @size_of_priv: bytes allocated for the driver private data
202 * @generic_bulk_ctrl_endpoint: bulk control endpoint number for sent
203 * @generic_bulk_ctrl_endpoint_response: bulk control endpoint number for
204 * receive
205 * @generic_bulk_ctrl_delay: delay between bulk control sent and receive message
19324414
AP
206 * @probe: like probe on driver model
207 * @disconnect: like disconnect on driver model
f93c8028
AP
208 * @identify_state: called to determine the firmware state (cold or warm) and
209 * return possible firmware file name to be loaded
210 * @firmware: name of the firmware file to be loaded
211 * @download_firmware: called to download the firmware
212 * @i2c_algo: i2c_algorithm if the device has i2c-adapter
213 * @num_adapters: dvb usb device adapter count
214 * @get_adapter_count: called to resolve adapter count
215 * @adapter: array of all adapter properties of device
216 * @power_ctrl: called to enable/disable power of the device
217 * @read_config: called to resolve device configuration
218 * @read_mac_address: called to resolve adapter mac-address
219 * @frontend_attach: called to attach the possible frontends
ca42129f 220 * @frontend_detach: called to detach the possible frontends
f93c8028
AP
221 * @tuner_attach: called to attach the possible tuners
222 * @frontend_ctrl: called to power on/off active frontend
223 * @streaming_ctrl: called to start/stop the usb streaming of adapter
dc786937 224 * @init: called after adapters are created in order to finalize device
f93c8028
AP
225 * configuration
226 * @exit: called when driver is unloaded
227 * @get_rc_config: called to resolve used remote controller configuration
228 * @get_stream_config: called to resolve input and output stream configuration
229 * of the adapter just before streaming is started. input stream is transport
230 * stream from the demodulator and output stream is usb stream to host.
c79b339f
AP
231 */
232#define MAX_NO_OF_ADAPTER_PER_DEVICE 2
233struct dvb_usb_device_properties {
05752890 234 const char *driver_name;
654e62dc 235 struct module *owner;
55b1f704 236 short *adapter_nr;
831511bd 237
36764037 238 u8 bInterfaceNumber;
831511bd
AP
239 unsigned int size_of_priv;
240 u8 generic_bulk_ctrl_endpoint;
241 u8 generic_bulk_ctrl_endpoint_response;
1162c7b3 242 unsigned int generic_bulk_ctrl_delay;
005bc3fc 243
19324414
AP
244 int (*probe)(struct dvb_usb_device *);
245 void (*disconnect)(struct dvb_usb_device *);
a0921af7
AP
246#define WARM 0
247#define COLD 1
248 int (*identify_state) (struct dvb_usb_device *, const char **);
005bc3fc 249 const char *firmware;
a0921af7 250#define RECONNECTS_USB 1
4e60d951
AP
251 int (*download_firmware) (struct dvb_usb_device *,
252 const struct firmware *);
c79b339f 253
831511bd 254 struct i2c_algorithm *i2c_algo;
c79b339f 255
831511bd 256 unsigned int num_adapters;
831511bd 257 int (*get_adapter_count) (struct dvb_usb_device *);
f93c8028 258 struct dvb_usb_adapter_properties adapter[MAX_NO_OF_ADAPTER_PER_DEVICE];
831511bd 259 int (*power_ctrl) (struct dvb_usb_device *, int);
43402bbd 260 int (*read_config) (struct dvb_usb_device *d);
ddee5694 261 int (*read_mac_address) (struct dvb_usb_adapter *, u8 []);
2d2b37c7 262 int (*frontend_attach) (struct dvb_usb_adapter *);
ca42129f 263 int (*frontend_detach)(struct dvb_usb_adapter *);
2d2b37c7 264 int (*tuner_attach) (struct dvb_usb_adapter *);
1066d77f 265 int (*tuner_detach)(struct dvb_usb_adapter *);
2d2b37c7 266 int (*frontend_ctrl) (struct dvb_frontend *, int);
a13a6e1f 267 int (*streaming_ctrl) (struct dvb_frontend *, int);
dc786937 268 int (*init) (struct dvb_usb_device *);
831511bd 269 void (*exit) (struct dvb_usb_device *);
05752890 270 int (*get_rc_config) (struct dvb_usb_device *, struct dvb_usb_rc *);
b905a2a1
AP
271#define DVB_USB_FE_TS_TYPE_188 0
272#define DVB_USB_FE_TS_TYPE_204 1
273#define DVB_USB_FE_TS_TYPE_RAW 2
274 int (*get_stream_config) (struct dvb_frontend *, u8 *,
39831f09 275 struct usb_data_stream_properties *);
c79b339f
AP
276};
277
278/**
f93c8028
AP
279 * generic object of an usb stream
280 * @buf_num: number of buffer allocated
281 * @buf_size: size of each buffer in buf_list
282 * @buf_list: array containing all allocate buffers for streaming
283 * @dma_addr: list of dma_addr_t for each buffer in buf_list
c79b339f 284 *
f93c8028
AP
285 * @urbs_initialized: number of URBs initialized
286 * @urbs_submitted: number of URBs submitted
c79b339f
AP
287 */
288#define MAX_NO_URBS_FOR_DATA_STREAM 10
289struct usb_data_stream {
831511bd
AP
290 struct usb_device *udev;
291 struct usb_data_stream_properties props;
c79b339f
AP
292
293#define USB_STATE_INIT 0x00
294#define USB_STATE_URB_BUF 0x01
831511bd 295 u8 state;
c79b339f
AP
296
297 void (*complete) (struct usb_data_stream *, u8 *, size_t);
298
299 struct urb *urb_list[MAX_NO_URBS_FOR_DATA_STREAM];
300 int buf_num;
301 unsigned long buf_size;
302 u8 *buf_list[MAX_NO_URBS_FOR_DATA_STREAM];
303 dma_addr_t dma_addr[MAX_NO_URBS_FOR_DATA_STREAM];
304
305 int urbs_initialized;
306 int urbs_submitted;
307
308 void *user_priv;
309};
310
311/**
f93c8028
AP
312 * dvb adapter object on dvb usb device
313 * @props: pointer to adapter properties
314 * @stream: adapter the usb data stream
315 * @id: index of this adapter (starting with 0)
316 * @ts_type: transport stream, input stream, type
06bae122 317 * @suspend_resume_active: set when there is ongoing suspend / resume
f93c8028
AP
318 * @pid_filtering: is hardware pid_filtering used or not
319 * @feed_count: current feed count
320 * @max_feed_count: maimum feed count device can handle
321 * @dvb_adap: adapter dvb_adapter
322 * @dmxdev: adapter dmxdev
323 * @demux: adapter software demuxer
324 * @dvb_net: adapter dvb_net interfaces
325 * @sync_mutex: mutex used to sync control and streaming of the adapter
326 * @fe: adapter frontends
327 * @fe_init: rerouted frontend-init function
328 * @fe_sleep: rerouted frontend-sleep function
c79b339f 329 */
c79b339f 330struct dvb_usb_adapter {
f093c388 331 const struct dvb_usb_adapter_properties *props;
e46c5b66 332 struct usb_data_stream stream;
831511bd 333 u8 id;
b905a2a1 334 u8 ts_type;
06bae122 335 bool suspend_resume_active;
831511bd
AP
336 bool pid_filtering;
337 u8 feed_count;
338 u8 max_feed_count;
339 s8 active_fe;
bdecbe43
AP
340#define ADAP_INIT 0
341#define ADAP_SLEEP 1
342#define ADAP_STREAMING 2
343 unsigned long state_bits;
191f79a4 344
c79b339f
AP
345 /* dvb */
346 struct dvb_adapter dvb_adap;
347 struct dmxdev dmxdev;
348 struct dvb_demux demux;
349 struct dvb_net dvb_net;
350
20bb9cc4
AP
351 struct dvb_frontend *fe[MAX_NO_OF_FE_PER_ADAP];
352 int (*fe_init[MAX_NO_OF_FE_PER_ADAP]) (struct dvb_frontend *);
353 int (*fe_sleep[MAX_NO_OF_FE_PER_ADAP]) (struct dvb_frontend *);
c79b339f
AP
354};
355
356/**
f93c8028
AP
357 * dvb usb device object
358 * @props: device properties
359 * @name: device name
360 * @rc_map: name of rc codes table
ac1c86c8 361 * @rc_polling_active: set when RC polling is active
ac5361a8 362 * @intf: pointer to the device's struct usb_interface
f93c8028 363 * @udev: pointer to the device's struct usb_device
f93c8028 364 * @rc: remote controller configuration
f93c8028
AP
365 * @powered: indicated whether the device is power or not
366 * @usb_mutex: mutex for usb control messages
367 * @i2c_mutex: mutex for i2c-transfers
368 * @i2c_adap: device's i2c-adapter
f93c8028 369 * @rc_dev: rc device for the remote control
f93c8028
AP
370 * @rc_query_work: work for polling remote
371 * @priv: private data of the actual driver (allocate by dvb usb, size defined
c79b339f
AP
372 * in size_of_priv of dvb_usb_properties).
373 */
374struct dvb_usb_device {
f093c388 375 const struct dvb_usb_device_properties *props;
7dfd1242 376 const char *name;
64921670 377 const char *rc_map;
ac1c86c8 378 bool rc_polling_active;
ac5361a8 379 struct usb_interface *intf;
c79b339f 380 struct usb_device *udev;
831511bd 381 struct dvb_usb_rc rc;
c79b339f
AP
382 int powered;
383
384 /* locking */
385 struct mutex usb_mutex;
386
387 /* i2c */
388 struct mutex i2c_mutex;
389 struct i2c_adapter i2c_adap;
390
c79b339f
AP
391 struct dvb_usb_adapter adapter[MAX_NO_OF_ADAPTER_PER_DEVICE];
392
393 /* remote control */
394 struct rc_dev *rc_dev;
c79b339f
AP
395 char rc_phys[64];
396 struct delayed_work rc_query_work;
c79b339f 397
c79b339f
AP
398 void *priv;
399};
400
6b8c8c40 401extern int dvb_usbv2_probe(struct usb_interface *,
55b1f704 402 const struct usb_device_id *);
6b8c8c40 403extern void dvb_usbv2_disconnect(struct usb_interface *);
ef81e9eb
AP
404extern int dvb_usbv2_suspend(struct usb_interface *, pm_message_t);
405extern int dvb_usbv2_resume(struct usb_interface *);
15d08836 406extern int dvb_usbv2_reset_resume(struct usb_interface *);
c79b339f
AP
407
408/* the generic read/write method for device control */
1162c7b3 409extern int dvb_usbv2_generic_rw(struct dvb_usb_device *, u8 *, u16, u8 *, u16);
c79b339f 410extern int dvb_usbv2_generic_write(struct dvb_usb_device *, u8 *, u16);
acb0549a
AP
411/* caller must hold lock when locked versions are called */
412extern int dvb_usbv2_generic_rw_locked(struct dvb_usb_device *,
413 u8 *, u16, u8 *, u16);
414extern int dvb_usbv2_generic_write_locked(struct dvb_usb_device *, u8 *, u16);
c79b339f 415
c79b339f 416#endif