4 * Copyright (C) 2000 Ralph Metzler & Marcus Metzler
5 * for convergence integrated media GmbH
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Lesser Public License
9 * as published by the Free Software Foundation; either version 2.1
10 * of the License, or (at your option) any later version.
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.
22 #include <linux/types.h>
23 #include <linux/poll.h>
25 #include <linux/list.h>
26 #include <media/media-device.h>
30 #if defined(CONFIG_DVB_MAX_ADAPTERS) && CONFIG_DVB_MAX_ADAPTERS > 0
31 #define DVB_MAX_ADAPTERS CONFIG_DVB_MAX_ADAPTERS
33 #define DVB_MAX_ADAPTERS 16
36 #define DVB_UNSET (-1)
38 #define DVB_DEVICE_VIDEO 0
39 #define DVB_DEVICE_AUDIO 1
40 #define DVB_DEVICE_SEC 2
41 #define DVB_DEVICE_FRONTEND 3
42 #define DVB_DEVICE_DEMUX 4
43 #define DVB_DEVICE_DVR 5
44 #define DVB_DEVICE_CA 6
45 #define DVB_DEVICE_NET 7
46 #define DVB_DEVICE_OSD 8
48 #define DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr) \
49 static short adapter_nr[] = \
50 {[0 ... (DVB_MAX_ADAPTERS - 1)] = DVB_UNSET }; \
51 module_param_array(adapter_nr, short, NULL, 0444); \
52 MODULE_PARM_DESC(adapter_nr, "DVB adapter numbers")
57 * struct dvb_adapter - represents a Digital TV adapter using Linux DVB API
59 * @num: Number of the adapter
60 * @list_head: List with the DVB adapters
61 * @device_list: List with the DVB devices
62 * @name: Name of the adapter
63 * @proposed_mac: proposed MAC address for the adapter
65 * @device: pointer to struct device
66 * @module: pointer to struct module
67 * @mfe_shared: mfe shared: indicates mutually exclusive frontends
68 * Thie usage of this flag is currently deprecated
69 * @mfe_dvbdev: Frontend device in use, in the case of MFE
70 * @mfe_lock: Lock to prevent using the other frontends when MFE is
72 * @mdev: pointer to struct media_device, used when the media
74 * @conn: RF connector. Used only if the device has no separate
76 * @conn_pads: pointer to struct media_pad associated with @conn;
80 struct list_head list_head;
81 struct list_head device_list;
86 struct device *device;
88 struct module *module;
90 int mfe_shared; /* indicates mutually exclusive frontends */
91 struct dvb_device *mfe_dvbdev; /* frontend device in use */
92 struct mutex mfe_lock; /* access lock for thread creation */
94 #if defined(CONFIG_MEDIA_CONTROLLER_DVB)
95 struct media_device *mdev;
96 struct media_entity *conn;
97 struct media_pad *conn_pads;
102 * struct dvb_device - represents a DVB device node
104 * @list_head: List head with all DVB devices
105 * @fops: pointer to struct file_operations
106 * @adapter: pointer to the adapter that holds this device node
107 * @type: type of the device: DVB_DEVICE_SEC, DVB_DEVICE_FRONTEND,
108 * DVB_DEVICE_DEMUX, DVB_DEVICE_DVR, DVB_DEVICE_CA, DVB_DEVICE_NET
109 * @minor: devnode minor number. Major number is always DVB_MAJOR.
110 * @id: device ID number, inside the adapter
111 * @readers: Initialized by the caller. Each call to open() in Read Only mode
112 * decreases this counter by one.
113 * @writers: Initialized by the caller. Each call to open() in Read/Write
114 * mode decreases this counter by one.
115 * @users: Initialized by the caller. Each call to open() in any mode
116 * decreases this counter by one.
117 * @wait_queue: wait queue, used to wait for certain events inside one of
118 * the DVB API callers
119 * @kernel_ioctl: callback function used to handle ioctl calls from userspace.
120 * @name: Name to be used for the device at the Media Controller
121 * @entity: pointer to struct media_entity associated with the device node
122 * @pads: pointer to struct media_pad associated with @entity;
123 * @priv: private data
124 * @intf_devnode: Pointer to media_intf_devnode. Used by the dvbdev core to
125 * store the MC device node interface
126 * @tsout_num_entities: Number of Transport Stream output entities
127 * @tsout_entity: array with MC entities associated to each TS output node
128 * @tsout_pads: array with the source pads for each @tsout_entity
130 * This structure is used by the DVB core (frontend, CA, net, demux) in
131 * order to create the device nodes. Usually, driver should not initialize
132 * this struct diretly.
135 struct list_head list_head;
137 const struct file_operations *fops;
138 struct dvb_adapter *adapter;
143 /* in theory, 'users' can vanish now,
144 but I don't want to change too much now... */
149 wait_queue_head_t wait_queue;
150 /* don't really need those !? -- FIXME: use video_usercopy */
151 int (*kernel_ioctl)(struct file *file, unsigned int cmd, void *arg);
153 /* Needed for media controller register/unregister */
154 #if defined(CONFIG_MEDIA_CONTROLLER_DVB)
157 /* Allocated and filled inside dvbdev.c */
158 struct media_intf_devnode *intf_devnode;
160 unsigned tsout_num_entities;
161 struct media_entity *entity, *tsout_entity;
162 struct media_pad *pads, *tsout_pads;
169 * dvb_device_get - Increase dvb_device reference
171 * @dvbdev: pointer to struct dvb_device
173 struct dvb_device *dvb_device_get(struct dvb_device *dvbdev);
176 * dvb_device_get - Decrease dvb_device reference
178 * @dvbdev: pointer to struct dvb_device
180 void dvb_device_put(struct dvb_device *dvbdev);
183 * dvb_register_adapter - Registers a new DVB adapter
185 * @adap: pointer to struct dvb_adapter
186 * @name: Adapter's name
187 * @module: initialized with THIS_MODULE at the caller
188 * @device: pointer to struct device that corresponds to the device driver
189 * @adapter_nums: Array with a list of the numbers for @dvb_register_adapter;
190 * to select among them. Typically, initialized with:
191 * DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nums)
193 int dvb_register_adapter(struct dvb_adapter *adap, const char *name,
194 struct module *module, struct device *device,
195 short *adapter_nums);
198 * dvb_unregister_adapter - Unregisters a DVB adapter
200 * @adap: pointer to struct dvb_adapter
202 int dvb_unregister_adapter(struct dvb_adapter *adap);
205 * dvb_register_device - Registers a new DVB device
207 * @adap: pointer to struct dvb_adapter
208 * @pdvbdev: pointer to the place where the new struct dvb_device will be
210 * @template: Template used to create &pdvbdev;
211 * @priv: private data
212 * @type: type of the device: %DVB_DEVICE_SEC, %DVB_DEVICE_FRONTEND,
213 * %DVB_DEVICE_DEMUX, %DVB_DEVICE_DVR, %DVB_DEVICE_CA,
215 * @demux_sink_pads: Number of demux outputs, to be used to create the TS
216 * outputs via the Media Controller.
218 int dvb_register_device(struct dvb_adapter *adap,
219 struct dvb_device **pdvbdev,
220 const struct dvb_device *template,
223 int demux_sink_pads);
226 * dvb_remove_device - Remove a registered DVB device
228 * This does not free memory. dvb_free_device() will do that when
229 * reference counter is empty
231 * @dvbdev: pointer to struct dvb_device
233 void dvb_remove_device(struct dvb_device *dvbdev);
237 * dvb_unregister_device - Unregisters a DVB device
239 * @dvbdev: pointer to struct dvb_device
241 void dvb_unregister_device(struct dvb_device *dvbdev);
243 #ifdef CONFIG_MEDIA_CONTROLLER_DVB
245 * dvb_create_media_graph - Creates media graph for the Digital TV part of the
248 * @adap: pointer to struct dvb_adapter
249 * @create_rf_connector: if true, it creates the RF connector too
251 * This function checks all DVB-related functions at the media controller
252 * entities and creates the needed links for the media graph. It is
253 * capable of working with multiple tuners or multiple frontends, but it
254 * won't create links if the device has multiple tuners and multiple frontends
255 * or if the device has multiple muxes. In such case, the caller driver should
256 * manually create the remaining links.
258 __must_check int dvb_create_media_graph(struct dvb_adapter *adap,
259 bool create_rf_connector);
261 static inline void dvb_register_media_controller(struct dvb_adapter *adap,
262 struct media_device *mdev)
267 static inline struct media_device
268 *dvb_get_media_controller(struct dvb_adapter *adap)
274 int dvb_create_media_graph(struct dvb_adapter *adap,
275 bool create_rf_connector)
279 #define dvb_register_media_controller(a, b) {}
280 #define dvb_get_media_controller(a) NULL
283 int dvb_generic_open (struct inode *inode, struct file *file);
284 int dvb_generic_release (struct inode *inode, struct file *file);
285 long dvb_generic_ioctl (struct file *file,
286 unsigned int cmd, unsigned long arg);
288 /* we don't mess with video_usercopy() any more,
289 we simply define out own dvb_usercopy(), which will hopefully become
290 generic_usercopy() someday... */
292 int dvb_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
293 int (*func)(struct file *file, unsigned int cmd, void *arg));
295 /** generic DVB attach function. */
296 #ifdef CONFIG_MEDIA_ATTACH
297 #define dvb_attach(FUNCTION, ARGS...) ({ \
299 typeof(&FUNCTION) __a = symbol_request(FUNCTION); \
301 __r = (void *) __a(ARGS); \
303 symbol_put(FUNCTION); \
305 printk(KERN_ERR "DVB: Unable to find symbol "#FUNCTION"()\n"); \
310 #define dvb_detach(FUNC) symbol_put_addr(FUNC)
313 #define dvb_attach(FUNCTION, ARGS...) ({ \
317 #define dvb_detach(FUNC) {}
321 #endif /* #ifndef _DVBDEV_H_ */