Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * dvbdev.h |
| 3 | * |
| 4 | * Copyright (C) 2000 Ralph Metzler & Marcus Metzler |
| 5 | * for convergence integrated media GmbH |
| 6 | * |
| 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. |
| 11 | * |
| 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 Lesser General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 20 | * |
| 21 | */ |
| 22 | |
| 23 | #ifndef _DVBDEV_H_ |
| 24 | #define _DVBDEV_H_ |
| 25 | |
| 26 | #include <linux/types.h> |
| 27 | #include <linux/poll.h> |
| 28 | #include <linux/fs.h> |
| 29 | #include <linux/list.h> |
Mauro Carvalho Chehab | a0246e0 | 2015-01-02 12:19:51 -0300 | [diff] [blame] | 30 | #include <media/media-device.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | |
| 32 | #define DVB_MAJOR 212 |
| 33 | |
Janne Grunau | 4457ef1 | 2009-09-01 19:15:39 -0300 | [diff] [blame] | 34 | #if defined(CONFIG_DVB_MAX_ADAPTERS) && CONFIG_DVB_MAX_ADAPTERS > 0 |
Mauro Carvalho Chehab | d4c02ef | 2009-09-19 09:45:22 -0300 | [diff] [blame] | 35 | #define DVB_MAX_ADAPTERS CONFIG_DVB_MAX_ADAPTERS |
Janne Grunau | 4457ef1 | 2009-09-01 19:15:39 -0300 | [diff] [blame] | 36 | #else |
Mauro Carvalho Chehab | d4c02ef | 2009-09-19 09:45:22 -0300 | [diff] [blame] | 37 | #define DVB_MAX_ADAPTERS 8 |
Janne Grunau | 4457ef1 | 2009-09-01 19:15:39 -0300 | [diff] [blame] | 38 | #endif |
Janne Grunau | 78e9200 | 2008-04-09 19:13:13 -0300 | [diff] [blame] | 39 | |
| 40 | #define DVB_UNSET (-1) |
| 41 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | #define DVB_DEVICE_VIDEO 0 |
| 43 | #define DVB_DEVICE_AUDIO 1 |
| 44 | #define DVB_DEVICE_SEC 2 |
| 45 | #define DVB_DEVICE_FRONTEND 3 |
| 46 | #define DVB_DEVICE_DEMUX 4 |
| 47 | #define DVB_DEVICE_DVR 5 |
| 48 | #define DVB_DEVICE_CA 6 |
| 49 | #define DVB_DEVICE_NET 7 |
| 50 | #define DVB_DEVICE_OSD 8 |
| 51 | |
Janne Grunau | 78e9200 | 2008-04-09 19:13:13 -0300 | [diff] [blame] | 52 | #define DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr) \ |
| 53 | static short adapter_nr[] = \ |
| 54 | {[0 ... (DVB_MAX_ADAPTERS - 1)] = DVB_UNSET }; \ |
| 55 | module_param_array(adapter_nr, short, NULL, 0444); \ |
| 56 | MODULE_PARM_DESC(adapter_nr, "DVB adapter numbers") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | |
Michael Krufky | 9133aee | 2009-05-23 18:00:59 -0300 | [diff] [blame] | 58 | struct dvb_frontend; |
| 59 | |
Mauro Carvalho Chehab | d071c833 | 2015-08-22 19:39:38 -0300 | [diff] [blame] | 60 | /** |
| 61 | * struct dvb_adapter - represents a Digital TV adapter using Linux DVB API |
| 62 | * |
| 63 | * @num: Number of the adapter |
| 64 | * @list_head: List with the DVB adapters |
| 65 | * @device_list: List with the DVB devices |
| 66 | * @name: Name of the adapter |
| 67 | * @proposed_mac: proposed MAC address for the adapter |
| 68 | * @priv: private data |
| 69 | * @device: pointer to struct device |
| 70 | * @module: pointer to struct module |
| 71 | * @mfe_shared: mfe shared: indicates mutually exclusive frontends |
| 72 | * Thie usage of this flag is currently deprecated |
| 73 | * @mfe_dvbdev: Frontend device in use, in the case of MFE |
| 74 | * @mfe_lock: Lock to prevent using the other frontends when MFE is |
| 75 | * used. |
| 76 | * @mdev: pointer to struct media_device, used when the media |
| 77 | * controller is used. |
Mauro Carvalho Chehab | 0230d60 | 2015-12-29 11:52:23 -0200 | [diff] [blame] | 78 | * @conn: RF connector. Used only if the device has no separate |
| 79 | * tuner. |
| 80 | * @conn_pads: pointer to struct media_pad associated with @conn; |
Mauro Carvalho Chehab | d071c833 | 2015-08-22 19:39:38 -0300 | [diff] [blame] | 81 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | struct dvb_adapter { |
| 83 | int num; |
| 84 | struct list_head list_head; |
| 85 | struct list_head device_list; |
| 86 | const char *name; |
| 87 | u8 proposed_mac [6]; |
| 88 | void* priv; |
| 89 | |
Andrew de Quincey | d09dbf9 | 2006-04-10 09:27:37 -0300 | [diff] [blame] | 90 | struct device *device; |
| 91 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | struct module *module; |
Darron Broad | 59b1842 | 2008-10-11 11:44:05 -0300 | [diff] [blame] | 93 | |
| 94 | int mfe_shared; /* indicates mutually exclusive frontends */ |
| 95 | struct dvb_device *mfe_dvbdev; /* frontend device in use */ |
| 96 | struct mutex mfe_lock; /* access lock for thread creation */ |
Mauro Carvalho Chehab | a0246e0 | 2015-01-02 12:19:51 -0300 | [diff] [blame] | 97 | |
| 98 | #if defined(CONFIG_MEDIA_CONTROLLER_DVB) |
| 99 | struct media_device *mdev; |
Mauro Carvalho Chehab | 0230d60 | 2015-12-29 11:52:23 -0200 | [diff] [blame] | 100 | struct media_entity *conn; |
| 101 | struct media_pad *conn_pads; |
Mauro Carvalho Chehab | a0246e0 | 2015-01-02 12:19:51 -0300 | [diff] [blame] | 102 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | }; |
| 104 | |
Mauro Carvalho Chehab | d071c833 | 2015-08-22 19:39:38 -0300 | [diff] [blame] | 105 | /** |
| 106 | * struct dvb_device - represents a DVB device node |
| 107 | * |
| 108 | * @list_head: List head with all DVB devices |
| 109 | * @fops: pointer to struct file_operations |
| 110 | * @adapter: pointer to the adapter that holds this device node |
| 111 | * @type: type of the device: DVB_DEVICE_SEC, DVB_DEVICE_FRONTEND, |
| 112 | * DVB_DEVICE_DEMUX, DVB_DEVICE_DVR, DVB_DEVICE_CA, DVB_DEVICE_NET |
| 113 | * @minor: devnode minor number. Major number is always DVB_MAJOR. |
| 114 | * @id: device ID number, inside the adapter |
| 115 | * @readers: Initialized by the caller. Each call to open() in Read Only mode |
| 116 | * decreases this counter by one. |
| 117 | * @writers: Initialized by the caller. Each call to open() in Read/Write |
| 118 | * mode decreases this counter by one. |
| 119 | * @users: Initialized by the caller. Each call to open() in any mode |
| 120 | * decreases this counter by one. |
| 121 | * @wait_queue: wait queue, used to wait for certain events inside one of |
| 122 | * the DVB API callers |
| 123 | * @kernel_ioctl: callback function used to handle ioctl calls from userspace. |
| 124 | * @name: Name to be used for the device at the Media Controller |
| 125 | * @entity: pointer to struct media_entity associated with the device node |
| 126 | * @pads: pointer to struct media_pad associated with @entity; |
| 127 | * @priv: private data |
Mauro Carvalho Chehab | fdc40b5 | 2015-12-12 08:25:44 -0200 | [diff] [blame] | 128 | * @intf_devnode: Pointer to media_intf_devnode. Used by the dvbdev core to |
| 129 | * store the MC device node interface |
| 130 | * @tsout_num_entities: Number of Transport Stream output entities |
| 131 | * @tsout_entity: array with MC entities associated to each TS output node |
| 132 | * @tsout_pads: array with the source pads for each @tsout_entity |
Mauro Carvalho Chehab | d071c833 | 2015-08-22 19:39:38 -0300 | [diff] [blame] | 133 | * |
| 134 | * This structure is used by the DVB core (frontend, CA, net, demux) in |
| 135 | * order to create the device nodes. Usually, driver should not initialize |
| 136 | * this struct diretly. |
| 137 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | struct dvb_device { |
| 139 | struct list_head list_head; |
Jan Engelhardt | 784e29d | 2009-01-11 06:12:43 -0300 | [diff] [blame] | 140 | const struct file_operations *fops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | struct dvb_adapter *adapter; |
| 142 | int type; |
Andreas Oberritter | 5dd3f30 | 2008-10-23 12:11:19 -0300 | [diff] [blame] | 143 | int minor; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | u32 id; |
| 145 | |
| 146 | /* in theory, 'users' can vanish now, |
| 147 | but I don't want to change too much now... */ |
| 148 | int readers; |
| 149 | int writers; |
| 150 | int users; |
| 151 | |
Markus Rechberger | ca5be9c | 2007-04-14 10:18:58 -0300 | [diff] [blame] | 152 | wait_queue_head_t wait_queue; |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 153 | /* don't really need those !? -- FIXME: use video_usercopy */ |
Arnd Bergmann | 16ef8de | 2010-04-27 00:24:00 +0200 | [diff] [blame] | 154 | int (*kernel_ioctl)(struct file *file, unsigned int cmd, void *arg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | |
Mauro Carvalho Chehab | a0246e0 | 2015-01-02 12:19:51 -0300 | [diff] [blame] | 156 | /* Needed for media controller register/unregister */ |
| 157 | #if defined(CONFIG_MEDIA_CONTROLLER_DVB) |
| 158 | const char *name; |
| 159 | |
Mauro Carvalho Chehab | 172e9d3 | 2015-01-03 01:59:53 -0300 | [diff] [blame] | 160 | /* Allocated and filled inside dvbdev.c */ |
Mauro Carvalho Chehab | 8211b18 | 2015-08-21 08:20:22 -0300 | [diff] [blame] | 161 | struct media_intf_devnode *intf_devnode; |
Mauro Carvalho Chehab | df2f94e | 2015-08-21 16:18:18 -0300 | [diff] [blame] | 162 | |
| 163 | unsigned tsout_num_entities; |
| 164 | struct media_entity *entity, *tsout_entity; |
| 165 | struct media_pad *pads, *tsout_pads; |
Mauro Carvalho Chehab | a0246e0 | 2015-01-02 12:19:51 -0300 | [diff] [blame] | 166 | #endif |
| 167 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | void *priv; |
| 169 | }; |
| 170 | |
Mauro Carvalho Chehab | d071c833 | 2015-08-22 19:39:38 -0300 | [diff] [blame] | 171 | /** |
| 172 | * dvb_register_adapter - Registers a new DVB adapter |
| 173 | * |
| 174 | * @adap: pointer to struct dvb_adapter |
| 175 | * @name: Adapter's name |
| 176 | * @module: initialized with THIS_MODULE at the caller |
| 177 | * @device: pointer to struct device that corresponds to the device driver |
| 178 | * @adapter_nums: Array with a list of the numbers for @dvb_register_adapter; |
| 179 | * to select among them. Typically, initialized with: |
| 180 | * DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nums) |
| 181 | */ |
| 182 | int dvb_register_adapter(struct dvb_adapter *adap, const char *name, |
| 183 | struct module *module, struct device *device, |
| 184 | short *adapter_nums); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | |
Mauro Carvalho Chehab | d071c833 | 2015-08-22 19:39:38 -0300 | [diff] [blame] | 186 | /** |
| 187 | * dvb_unregister_adapter - Unregisters a DVB adapter |
| 188 | * |
| 189 | * @adap: pointer to struct dvb_adapter |
| 190 | */ |
| 191 | int dvb_unregister_adapter(struct dvb_adapter *adap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | |
Mauro Carvalho Chehab | d071c833 | 2015-08-22 19:39:38 -0300 | [diff] [blame] | 193 | /** |
| 194 | * dvb_register_device - Registers a new DVB device |
| 195 | * |
| 196 | * @adap: pointer to struct dvb_adapter |
| 197 | * @pdvbdev: pointer to the place where the new struct dvb_device will be |
| 198 | * stored |
| 199 | * @template: Template used to create &pdvbdev; |
Mauro Carvalho Chehab | d071c833 | 2015-08-22 19:39:38 -0300 | [diff] [blame] | 200 | * @priv: private data |
Mauro Carvalho Chehab | fdc40b5 | 2015-12-12 08:25:44 -0200 | [diff] [blame] | 201 | * @type: type of the device: %DVB_DEVICE_SEC, %DVB_DEVICE_FRONTEND, |
| 202 | * %DVB_DEVICE_DEMUX, %DVB_DEVICE_DVR, %DVB_DEVICE_CA, |
| 203 | * %DVB_DEVICE_NET |
| 204 | * @demux_sink_pads: Number of demux outputs, to be used to create the TS |
| 205 | * outputs via the Media Controller. |
Mauro Carvalho Chehab | d071c833 | 2015-08-22 19:39:38 -0300 | [diff] [blame] | 206 | */ |
| 207 | int dvb_register_device(struct dvb_adapter *adap, |
| 208 | struct dvb_device **pdvbdev, |
| 209 | const struct dvb_device *template, |
| 210 | void *priv, |
Mauro Carvalho Chehab | df2f94e | 2015-08-21 16:18:18 -0300 | [diff] [blame] | 211 | int type, |
| 212 | int demux_sink_pads); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | |
Mauro Carvalho Chehab | d071c833 | 2015-08-22 19:39:38 -0300 | [diff] [blame] | 214 | /** |
| 215 | * dvb_unregister_device - Unregisters a DVB device |
| 216 | * |
| 217 | * @dvbdev: pointer to struct dvb_device |
| 218 | */ |
| 219 | void dvb_unregister_device(struct dvb_device *dvbdev); |
Mauro Carvalho Chehab | 480884b | 2015-03-02 10:49:04 -0300 | [diff] [blame] | 220 | |
| 221 | #ifdef CONFIG_MEDIA_CONTROLLER_DVB |
Mauro Carvalho Chehab | 0230d60 | 2015-12-29 11:52:23 -0200 | [diff] [blame] | 222 | /** |
| 223 | * dvb_create_media_graph - Creates media graph for the Digital TV part of the |
| 224 | * device. |
| 225 | * |
| 226 | * @adap: pointer to struct dvb_adapter |
| 227 | * @create_rf_connector: if true, it creates the RF connector too |
Mauro Carvalho Chehab | a0cce2a | 2015-12-30 10:11:53 -0200 | [diff] [blame] | 228 | * |
| 229 | * This function checks all DVB-related functions at the media controller |
| 230 | * entities and creates the needed links for the media graph. It is |
| 231 | * capable of working with multiple tuners or multiple frontends, but it |
| 232 | * won't create links if the device has multiple tuners and multiple frontends |
| 233 | * or if the device has multiple muxes. In such case, the caller driver should |
| 234 | * manually create the remaining links. |
Mauro Carvalho Chehab | 0230d60 | 2015-12-29 11:52:23 -0200 | [diff] [blame] | 235 | */ |
| 236 | __must_check int dvb_create_media_graph(struct dvb_adapter *adap, |
| 237 | bool create_rf_connector); |
| 238 | |
Mauro Carvalho Chehab | 89a2c1d | 2015-03-02 11:26:14 -0300 | [diff] [blame] | 239 | static inline void dvb_register_media_controller(struct dvb_adapter *adap, |
| 240 | struct media_device *mdev) |
| 241 | { |
| 242 | adap->mdev = mdev; |
| 243 | } |
| 244 | |
Mauro Carvalho Chehab | ce084d4 | 2015-12-30 11:09:39 -0200 | [diff] [blame] | 245 | static inline struct media_device |
| 246 | *dvb_get_media_controller(struct dvb_adapter *adap) |
| 247 | { |
| 248 | return adap->mdev; |
| 249 | } |
Mauro Carvalho Chehab | 480884b | 2015-03-02 10:49:04 -0300 | [diff] [blame] | 250 | #else |
Mauro Carvalho Chehab | 0230d60 | 2015-12-29 11:52:23 -0200 | [diff] [blame] | 251 | static inline |
| 252 | int dvb_create_media_graph(struct dvb_adapter *adap, |
| 253 | bool create_rf_connector) |
Mauro Carvalho Chehab | f50d516 | 2015-09-04 15:10:29 -0300 | [diff] [blame] | 254 | { |
| 255 | return 0; |
| 256 | }; |
Mauro Carvalho Chehab | 89a2c1d | 2015-03-02 11:26:14 -0300 | [diff] [blame] | 257 | #define dvb_register_media_controller(a, b) {} |
Mauro Carvalho Chehab | ce084d4 | 2015-12-30 11:09:39 -0200 | [diff] [blame] | 258 | #define dvb_get_media_controller(a) NULL |
Mauro Carvalho Chehab | 480884b | 2015-03-02 10:49:04 -0300 | [diff] [blame] | 259 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | |
Mauro Carvalho Chehab | d071c833 | 2015-08-22 19:39:38 -0300 | [diff] [blame] | 261 | int dvb_generic_open (struct inode *inode, struct file *file); |
| 262 | int dvb_generic_release (struct inode *inode, struct file *file); |
| 263 | long dvb_generic_ioctl (struct file *file, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | unsigned int cmd, unsigned long arg); |
| 265 | |
| 266 | /* we don't mess with video_usercopy() any more, |
| 267 | we simply define out own dvb_usercopy(), which will hopefully become |
| 268 | generic_usercopy() someday... */ |
| 269 | |
Mauro Carvalho Chehab | d071c833 | 2015-08-22 19:39:38 -0300 | [diff] [blame] | 270 | int dvb_usercopy(struct file *file, unsigned int cmd, unsigned long arg, |
| 271 | int (*func)(struct file *file, unsigned int cmd, void *arg)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | |
Andrew de Quincey | d995506 | 2006-08-08 09:10:08 -0300 | [diff] [blame] | 273 | /** generic DVB attach function. */ |
Mauro Carvalho Chehab | 149ef72 | 2008-04-29 21:38:46 -0300 | [diff] [blame] | 274 | #ifdef CONFIG_MEDIA_ATTACH |
Andrew de Quincey | d995506 | 2006-08-08 09:10:08 -0300 | [diff] [blame] | 275 | #define dvb_attach(FUNCTION, ARGS...) ({ \ |
| 276 | void *__r = NULL; \ |
| 277 | typeof(&FUNCTION) __a = symbol_request(FUNCTION); \ |
| 278 | if (__a) { \ |
| 279 | __r = (void *) __a(ARGS); \ |
| 280 | if (__r == NULL) \ |
| 281 | symbol_put(FUNCTION); \ |
| 282 | } else { \ |
| 283 | printk(KERN_ERR "DVB: Unable to find symbol "#FUNCTION"()\n"); \ |
| 284 | } \ |
| 285 | __r; \ |
| 286 | }) |
| 287 | |
Mauro Carvalho Chehab | 4647f48 | 2014-05-29 09:20:13 -0300 | [diff] [blame] | 288 | #define dvb_detach(FUNC) symbol_put_addr(FUNC) |
| 289 | |
Andrew de Quincey | d995506 | 2006-08-08 09:10:08 -0300 | [diff] [blame] | 290 | #else |
| 291 | #define dvb_attach(FUNCTION, ARGS...) ({ \ |
| 292 | FUNCTION(ARGS); \ |
| 293 | }) |
| 294 | |
Mauro Carvalho Chehab | 4647f48 | 2014-05-29 09:20:13 -0300 | [diff] [blame] | 295 | #define dvb_detach(FUNC) {} |
| 296 | |
Andrew de Quincey | d995506 | 2006-08-08 09:10:08 -0300 | [diff] [blame] | 297 | #endif |
| 298 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | #endif /* #ifndef _DVBDEV_H_ */ |