1 /* SPDX-License-Identifier: GPL-2.0-or-later */
5 * Copyright (C) 2004-6 Patrick Boettcher <patrick.boettcher@posteo.de>
6 * Copyright (C) 2012 Antti Palosaari <crope@iki.fi>
12 #include <linux/usb/input.h>
13 #include <linux/firmware.h>
14 #include <media/rc-core.h>
15 #include <media/media-device.h>
17 #include <media/dvb_frontend.h>
18 #include <media/dvb_demux.h>
19 #include <media/dvb_net.h>
20 #include <media/dmxdev.h>
21 #include <media/dvb-usb-ids.h>
24 * device file: /dev/dvb/adapter[0-1]/frontend[0-2]
37 * Commonly used variable names:
38 * d = pointer to device (struct dvb_usb_device *)
39 * adap = pointer to adapter (struct dvb_usb_adapter *)
40 * fe = pointer to frontend (struct dvb_frontend *)
42 * Use macros defined in that file to resolve needed pointers.
45 /* helper macros for every DVB USB driver use */
46 #define adap_to_d(adap) (container_of(adap, struct dvb_usb_device, \
48 #define adap_to_priv(adap) (adap_to_d(adap)->priv)
49 #define fe_to_adap(fe) ((struct dvb_usb_adapter *) ((fe)->dvb->priv))
50 #define fe_to_d(fe) (adap_to_d(fe_to_adap(fe)))
51 #define fe_to_priv(fe) (fe_to_d(fe)->priv)
52 #define d_to_priv(d) (d->priv)
54 #define dvb_usb_dbg_usb_control_msg(udev, r, t, v, i, b, l) { \
56 if (t == (USB_TYPE_VENDOR | USB_DIR_OUT)) \
60 dev_dbg(&udev->dev, "%s: %02x %02x %02x %02x %02x %02x %02x %02x " \
61 "%s %*ph\n", __func__, t, r, v & 0xff, v >> 8, \
62 i & 0xff, i >> 8, l & 0xff, l >> 8, direction, l, b); \
65 #define DVB_USB_STREAM_BULK(endpoint_, count_, size_) { \
68 .endpoint = endpoint_, \
71 .buffersize = size_, \
76 #define DVB_USB_STREAM_ISOC(endpoint_, count_, frames_, size_, interval_) { \
79 .endpoint = endpoint_, \
82 .framesperurb = frames_, \
84 .interval = interval_, \
89 #define DVB_USB_DEVICE(vend, prod, props_, name_, rc) \
90 .match_flags = USB_DEVICE_ID_MATCH_DEVICE, \
92 .idProduct = (prod), \
93 .driver_info = (kernel_ulong_t) &((const struct dvb_usb_driver_info) { \
99 struct dvb_usb_device
;
100 struct dvb_usb_adapter
;
103 * structure for carrying all needed data from the device driver to the general
106 * @rc_map: name of rc codes table
107 * @props: structure containing all device properties
109 struct dvb_usb_driver_info
{
112 const struct dvb_usb_device_properties
*props
;
116 * structure for remote controller configuration
117 * @map_name: name of rc codes table
118 * @allowed_protos: protocol(s) supported by the driver
119 * @change_protocol: callback to change protocol
120 * @query: called to query an event from the device
121 * @interval: time in ms between two queries
122 * @driver_type: used to point if a device supports raw mode
123 * @bulk_mode: device supports bulk mode for rc (disable polling mode)
124 * @timeout: set to length of last space before raw IR goes idle
127 const char *map_name
;
129 int (*change_protocol
)(struct rc_dev
*dev
, u64
*rc_proto
);
130 int (*query
) (struct dvb_usb_device
*d
);
131 unsigned int interval
;
132 enum rc_driver_type driver_type
;
138 * usb streaming configuration for adapter
140 * @count: count of used urbs
141 * @endpoint: stream usb endpoint number
143 struct usb_data_stream_properties
{
152 unsigned int buffersize
; /* per URB */
163 * properties of dvb usb device adapter
164 * @caps: adapter capabilities
165 * @pid_filter_count: pid count of adapter pid-filter
166 * @pid_filter_ctrl: called to enable/disable pid-filter
167 * @pid_filter: called to set/unset pid for filtering
168 * @stream: adapter usb stream configuration
170 #define MAX_NO_OF_FE_PER_ADAP 3
171 struct dvb_usb_adapter_properties
{
172 #define DVB_USB_ADAP_HAS_PID_FILTER 0x01
173 #define DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF 0x02
174 #define DVB_USB_ADAP_NEED_PID_FILTERING 0x04
178 int (*pid_filter_ctrl
) (struct dvb_usb_adapter
*, int);
179 int (*pid_filter
) (struct dvb_usb_adapter
*, int, u16
, int);
181 struct usb_data_stream_properties stream
;
185 * struct dvb_usb_device_properties - properties of a dvb-usb-device
186 * @driver_name: name of the owning driver module
187 * @owner: owner of the dvb_adapter
188 * @adapter_nr: values from the DVB_DEFINE_MOD_OPT_ADAPTER_NR() macro
189 * @bInterfaceNumber: usb interface number driver binds
190 * @size_of_priv: bytes allocated for the driver private data
191 * @generic_bulk_ctrl_endpoint: bulk control endpoint number for sent
192 * @generic_bulk_ctrl_endpoint_response: bulk control endpoint number for
194 * @generic_bulk_ctrl_delay: delay between bulk control sent and receive message
195 * @probe: like probe on driver model
196 * @disconnect: like disconnect on driver model
197 * @identify_state: called to determine the firmware state (cold or warm) and
198 * return possible firmware file name to be loaded
199 * @firmware: name of the firmware file to be loaded
200 * @download_firmware: called to download the firmware
201 * @i2c_algo: i2c_algorithm if the device has i2c-adapter
202 * @num_adapters: dvb usb device adapter count
203 * @get_adapter_count: called to resolve adapter count
204 * @adapter: array of all adapter properties of device
205 * @power_ctrl: called to enable/disable power of the device
206 * @read_config: called to resolve device configuration
207 * @read_mac_address: called to resolve adapter mac-address
208 * @frontend_attach: called to attach the possible frontends
209 * @frontend_detach: called to detach the possible frontends
210 * @tuner_attach: called to attach the possible tuners
211 * @frontend_ctrl: called to power on/off active frontend
212 * @streaming_ctrl: called to start/stop the usb streaming of adapter
213 * @init: called after adapters are created in order to finalize device
215 * @exit: called when driver is unloaded
216 * @get_rc_config: called to resolve used remote controller configuration
217 * @get_stream_config: called to resolve input and output stream configuration
218 * of the adapter just before streaming is started. input stream is transport
219 * stream from the demodulator and output stream is usb stream to host.
221 #define MAX_NO_OF_ADAPTER_PER_DEVICE 2
222 struct dvb_usb_device_properties
{
223 const char *driver_name
;
224 struct module
*owner
;
228 unsigned int size_of_priv
;
229 u8 generic_bulk_ctrl_endpoint
;
230 u8 generic_bulk_ctrl_endpoint_response
;
231 unsigned int generic_bulk_ctrl_delay
;
233 int (*probe
)(struct dvb_usb_device
*);
234 void (*disconnect
)(struct dvb_usb_device
*);
237 int (*identify_state
) (struct dvb_usb_device
*, const char **);
238 const char *firmware
;
239 #define RECONNECTS_USB 1
240 int (*download_firmware
) (struct dvb_usb_device
*,
241 const struct firmware
*);
243 struct i2c_algorithm
*i2c_algo
;
245 unsigned int num_adapters
;
246 int (*get_adapter_count
) (struct dvb_usb_device
*);
247 struct dvb_usb_adapter_properties adapter
[MAX_NO_OF_ADAPTER_PER_DEVICE
];
248 int (*power_ctrl
) (struct dvb_usb_device
*, int);
249 int (*read_config
) (struct dvb_usb_device
*d
);
250 int (*read_mac_address
) (struct dvb_usb_adapter
*, u8
[]);
251 int (*frontend_attach
) (struct dvb_usb_adapter
*);
252 int (*frontend_detach
)(struct dvb_usb_adapter
*);
253 int (*tuner_attach
) (struct dvb_usb_adapter
*);
254 int (*tuner_detach
)(struct dvb_usb_adapter
*);
255 int (*frontend_ctrl
) (struct dvb_frontend
*, int);
256 int (*streaming_ctrl
) (struct dvb_frontend
*, int);
257 int (*init
) (struct dvb_usb_device
*);
258 void (*exit
) (struct dvb_usb_device
*);
259 int (*get_rc_config
) (struct dvb_usb_device
*, struct dvb_usb_rc
*);
260 #define DVB_USB_FE_TS_TYPE_188 0
261 #define DVB_USB_FE_TS_TYPE_204 1
262 #define DVB_USB_FE_TS_TYPE_RAW 2
263 int (*get_stream_config
) (struct dvb_frontend
*, u8
*,
264 struct usb_data_stream_properties
*);
268 * generic object of an usb stream
269 * @buf_num: number of buffer allocated
270 * @buf_size: size of each buffer in buf_list
271 * @buf_list: array containing all allocate buffers for streaming
272 * @dma_addr: list of dma_addr_t for each buffer in buf_list
274 * @urbs_initialized: number of URBs initialized
275 * @urbs_submitted: number of URBs submitted
277 #define MAX_NO_URBS_FOR_DATA_STREAM 10
278 struct usb_data_stream
{
279 struct usb_device
*udev
;
280 struct usb_data_stream_properties props
;
282 #define USB_STATE_INIT 0x00
283 #define USB_STATE_URB_BUF 0x01
286 void (*complete
) (struct usb_data_stream
*, u8
*, size_t);
288 struct urb
*urb_list
[MAX_NO_URBS_FOR_DATA_STREAM
];
290 unsigned long buf_size
;
291 u8
*buf_list
[MAX_NO_URBS_FOR_DATA_STREAM
];
292 dma_addr_t dma_addr
[MAX_NO_URBS_FOR_DATA_STREAM
];
294 int urbs_initialized
;
301 * dvb adapter object on dvb usb device
302 * @props: pointer to adapter properties
303 * @stream: adapter the usb data stream
304 * @id: index of this adapter (starting with 0)
305 * @ts_type: transport stream, input stream, type
306 * @suspend_resume_active: set when there is ongoing suspend / resume
307 * @pid_filtering: is hardware pid_filtering used or not
308 * @feed_count: current feed count
309 * @max_feed_count: maimum feed count device can handle
310 * @dvb_adap: adapter dvb_adapter
311 * @dmxdev: adapter dmxdev
312 * @demux: adapter software demuxer
313 * @dvb_net: adapter dvb_net interfaces
314 * @sync_mutex: mutex used to sync control and streaming of the adapter
315 * @fe: adapter frontends
316 * @fe_init: rerouted frontend-init function
317 * @fe_sleep: rerouted frontend-sleep function
319 struct dvb_usb_adapter
{
320 const struct dvb_usb_adapter_properties
*props
;
321 struct usb_data_stream stream
;
324 bool suspend_resume_active
;
331 #define ADAP_STREAMING 2
332 unsigned long state_bits
;
335 struct dvb_adapter dvb_adap
;
336 struct dmxdev dmxdev
;
337 struct dvb_demux demux
;
338 struct dvb_net dvb_net
;
340 struct dvb_frontend
*fe
[MAX_NO_OF_FE_PER_ADAP
];
341 int (*fe_init
[MAX_NO_OF_FE_PER_ADAP
]) (struct dvb_frontend
*);
342 int (*fe_sleep
[MAX_NO_OF_FE_PER_ADAP
]) (struct dvb_frontend
*);
346 * dvb usb device object
347 * @props: device properties
349 * @rc_map: name of rc codes table
350 * @rc_polling_active: set when RC polling is active
351 * @intf: pointer to the device's struct usb_interface
352 * @udev: pointer to the device's struct usb_device
353 * @rc: remote controller configuration
354 * @powered: indicated whether the device is power or not
355 * @usb_mutex: mutex for usb control messages
356 * @i2c_mutex: mutex for i2c-transfers
357 * @i2c_adap: device's i2c-adapter
358 * @rc_dev: rc device for the remote control
359 * @rc_query_work: work for polling remote
360 * @priv: private data of the actual driver (allocate by dvb usb, size defined
361 * in size_of_priv of dvb_usb_properties).
363 struct dvb_usb_device
{
364 const struct dvb_usb_device_properties
*props
;
367 bool rc_polling_active
;
368 struct usb_interface
*intf
;
369 struct usb_device
*udev
;
370 struct dvb_usb_rc rc
;
374 struct mutex usb_mutex
;
377 struct mutex i2c_mutex
;
378 struct i2c_adapter i2c_adap
;
380 struct dvb_usb_adapter adapter
[MAX_NO_OF_ADAPTER_PER_DEVICE
];
383 struct rc_dev
*rc_dev
;
385 struct delayed_work rc_query_work
;
390 extern int dvb_usbv2_probe(struct usb_interface
*,
391 const struct usb_device_id
*);
392 extern void dvb_usbv2_disconnect(struct usb_interface
*);
393 extern int dvb_usbv2_suspend(struct usb_interface
*, pm_message_t
);
394 extern int dvb_usbv2_resume(struct usb_interface
*);
395 extern int dvb_usbv2_reset_resume(struct usb_interface
*);
397 /* the generic read/write method for device control */
398 extern int dvb_usbv2_generic_rw(struct dvb_usb_device
*, u8
*, u16
, u8
*, u16
);
399 extern int dvb_usbv2_generic_write(struct dvb_usb_device
*, u8
*, u16
);
400 /* caller must hold lock when locked versions are called */
401 extern int dvb_usbv2_generic_rw_locked(struct dvb_usb_device
*,
402 u8
*, u16
, u8
*, u16
);
403 extern int dvb_usbv2_generic_write_locked(struct dvb_usb_device
*, u8
*, u16
);