blob: 1069a776bbdb894565ca895ffe807d5914bd5976 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 Chehaba0246e02015-01-02 12:19:51 -030030#include <media/media-device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
32#define DVB_MAJOR 212
33
Janne Grunau4457ef12009-09-01 19:15:39 -030034#if defined(CONFIG_DVB_MAX_ADAPTERS) && CONFIG_DVB_MAX_ADAPTERS > 0
Mauro Carvalho Chehabd4c02ef2009-09-19 09:45:22 -030035 #define DVB_MAX_ADAPTERS CONFIG_DVB_MAX_ADAPTERS
Janne Grunau4457ef12009-09-01 19:15:39 -030036#else
Mauro Carvalho Chehabd4c02ef2009-09-19 09:45:22 -030037 #define DVB_MAX_ADAPTERS 8
Janne Grunau4457ef12009-09-01 19:15:39 -030038#endif
Janne Grunau78e92002008-04-09 19:13:13 -030039
40#define DVB_UNSET (-1)
41
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#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 Grunau78e92002008-04-09 19:13:13 -030052#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 Torvalds1da177e2005-04-16 15:20:36 -070057
Michael Krufky9133aee2009-05-23 18:00:59 -030058struct dvb_frontend;
59
Mauro Carvalho Chehabd071c8332015-08-22 19:39:38 -030060/**
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.
78 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070079struct dvb_adapter {
80 int num;
81 struct list_head list_head;
82 struct list_head device_list;
83 const char *name;
84 u8 proposed_mac [6];
85 void* priv;
86
Andrew de Quinceyd09dbf92006-04-10 09:27:37 -030087 struct device *device;
88
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 struct module *module;
Darron Broad59b18422008-10-11 11:44:05 -030090
91 int mfe_shared; /* indicates mutually exclusive frontends */
92 struct dvb_device *mfe_dvbdev; /* frontend device in use */
93 struct mutex mfe_lock; /* access lock for thread creation */
Mauro Carvalho Chehaba0246e02015-01-02 12:19:51 -030094
95#if defined(CONFIG_MEDIA_CONTROLLER_DVB)
96 struct media_device *mdev;
97#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070098};
99
Mauro Carvalho Chehabd071c8332015-08-22 19:39:38 -0300100/**
101 * struct dvb_device - represents a DVB device node
102 *
103 * @list_head: List head with all DVB devices
104 * @fops: pointer to struct file_operations
105 * @adapter: pointer to the adapter that holds this device node
106 * @type: type of the device: DVB_DEVICE_SEC, DVB_DEVICE_FRONTEND,
107 * DVB_DEVICE_DEMUX, DVB_DEVICE_DVR, DVB_DEVICE_CA, DVB_DEVICE_NET
108 * @minor: devnode minor number. Major number is always DVB_MAJOR.
109 * @id: device ID number, inside the adapter
110 * @readers: Initialized by the caller. Each call to open() in Read Only mode
111 * decreases this counter by one.
112 * @writers: Initialized by the caller. Each call to open() in Read/Write
113 * mode decreases this counter by one.
114 * @users: Initialized by the caller. Each call to open() in any mode
115 * decreases this counter by one.
116 * @wait_queue: wait queue, used to wait for certain events inside one of
117 * the DVB API callers
118 * @kernel_ioctl: callback function used to handle ioctl calls from userspace.
119 * @name: Name to be used for the device at the Media Controller
120 * @entity: pointer to struct media_entity associated with the device node
121 * @pads: pointer to struct media_pad associated with @entity;
122 * @priv: private data
123 *
124 * This structure is used by the DVB core (frontend, CA, net, demux) in
125 * order to create the device nodes. Usually, driver should not initialize
126 * this struct diretly.
127 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128struct dvb_device {
129 struct list_head list_head;
Jan Engelhardt784e29d2009-01-11 06:12:43 -0300130 const struct file_operations *fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 struct dvb_adapter *adapter;
132 int type;
Andreas Oberritter5dd3f302008-10-23 12:11:19 -0300133 int minor;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 u32 id;
135
136 /* in theory, 'users' can vanish now,
137 but I don't want to change too much now... */
138 int readers;
139 int writers;
140 int users;
141
Markus Rechbergerca5be9c2007-04-14 10:18:58 -0300142 wait_queue_head_t wait_queue;
Mauro Carvalho Chehabafd1a0c2005-12-12 00:37:27 -0800143 /* don't really need those !? -- FIXME: use video_usercopy */
Arnd Bergmann16ef8de2010-04-27 00:24:00 +0200144 int (*kernel_ioctl)(struct file *file, unsigned int cmd, void *arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145
Mauro Carvalho Chehaba0246e02015-01-02 12:19:51 -0300146 /* Needed for media controller register/unregister */
147#if defined(CONFIG_MEDIA_CONTROLLER_DVB)
148 const char *name;
149
Mauro Carvalho Chehab172e9d32015-01-03 01:59:53 -0300150 /* Allocated and filled inside dvbdev.c */
Mauro Carvalho Chehaba0246e02015-01-02 12:19:51 -0300151 struct media_entity *entity;
Mauro Carvalho Chehab172e9d32015-01-03 01:59:53 -0300152 struct media_pad *pads;
Mauro Carvalho Chehaba0246e02015-01-02 12:19:51 -0300153#endif
154
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 void *priv;
156};
157
Mauro Carvalho Chehabd071c8332015-08-22 19:39:38 -0300158/**
159 * dvb_register_adapter - Registers a new DVB adapter
160 *
161 * @adap: pointer to struct dvb_adapter
162 * @name: Adapter's name
163 * @module: initialized with THIS_MODULE at the caller
164 * @device: pointer to struct device that corresponds to the device driver
165 * @adapter_nums: Array with a list of the numbers for @dvb_register_adapter;
166 * to select among them. Typically, initialized with:
167 * DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nums)
168 */
169int dvb_register_adapter(struct dvb_adapter *adap, const char *name,
170 struct module *module, struct device *device,
171 short *adapter_nums);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172
Mauro Carvalho Chehabd071c8332015-08-22 19:39:38 -0300173/**
174 * dvb_unregister_adapter - Unregisters a DVB adapter
175 *
176 * @adap: pointer to struct dvb_adapter
177 */
178int dvb_unregister_adapter(struct dvb_adapter *adap);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179
Mauro Carvalho Chehabd071c8332015-08-22 19:39:38 -0300180/**
181 * dvb_register_device - Registers a new DVB device
182 *
183 * @adap: pointer to struct dvb_adapter
184 * @pdvbdev: pointer to the place where the new struct dvb_device will be
185 * stored
186 * @template: Template used to create &pdvbdev;
Mauro Carvalho Chehabd071c8332015-08-22 19:39:38 -0300187 * @priv: private data
188 * @type: type of the device: DVB_DEVICE_SEC, DVB_DEVICE_FRONTEND,
189 * DVB_DEVICE_DEMUX, DVB_DEVICE_DVR, DVB_DEVICE_CA, DVB_DEVICE_NET
190 */
191int dvb_register_device(struct dvb_adapter *adap,
192 struct dvb_device **pdvbdev,
193 const struct dvb_device *template,
194 void *priv,
195 int type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196
Mauro Carvalho Chehabd071c8332015-08-22 19:39:38 -0300197/**
198 * dvb_unregister_device - Unregisters a DVB device
199 *
200 * @dvbdev: pointer to struct dvb_device
201 */
202void dvb_unregister_device(struct dvb_device *dvbdev);
Mauro Carvalho Chehab480884b2015-03-02 10:49:04 -0300203
204#ifdef CONFIG_MEDIA_CONTROLLER_DVB
205void dvb_create_media_graph(struct dvb_adapter *adap);
Mauro Carvalho Chehab89a2c1d2015-03-02 11:26:14 -0300206static inline void dvb_register_media_controller(struct dvb_adapter *adap,
207 struct media_device *mdev)
208{
209 adap->mdev = mdev;
210}
211
Mauro Carvalho Chehab480884b2015-03-02 10:49:04 -0300212#else
213static inline void dvb_create_media_graph(struct dvb_adapter *adap) {}
Mauro Carvalho Chehab89a2c1d2015-03-02 11:26:14 -0300214#define dvb_register_media_controller(a, b) {}
Mauro Carvalho Chehab480884b2015-03-02 10:49:04 -0300215#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216
Mauro Carvalho Chehabd071c8332015-08-22 19:39:38 -0300217int dvb_generic_open (struct inode *inode, struct file *file);
218int dvb_generic_release (struct inode *inode, struct file *file);
219long dvb_generic_ioctl (struct file *file,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 unsigned int cmd, unsigned long arg);
221
222/* we don't mess with video_usercopy() any more,
223we simply define out own dvb_usercopy(), which will hopefully become
224generic_usercopy() someday... */
225
Mauro Carvalho Chehabd071c8332015-08-22 19:39:38 -0300226int dvb_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
227 int (*func)(struct file *file, unsigned int cmd, void *arg));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228
Andrew de Quinceyd9955062006-08-08 09:10:08 -0300229/** generic DVB attach function. */
Mauro Carvalho Chehab149ef722008-04-29 21:38:46 -0300230#ifdef CONFIG_MEDIA_ATTACH
Andrew de Quinceyd9955062006-08-08 09:10:08 -0300231#define dvb_attach(FUNCTION, ARGS...) ({ \
232 void *__r = NULL; \
233 typeof(&FUNCTION) __a = symbol_request(FUNCTION); \
234 if (__a) { \
235 __r = (void *) __a(ARGS); \
236 if (__r == NULL) \
237 symbol_put(FUNCTION); \
238 } else { \
239 printk(KERN_ERR "DVB: Unable to find symbol "#FUNCTION"()\n"); \
240 } \
241 __r; \
242})
243
Mauro Carvalho Chehab4647f482014-05-29 09:20:13 -0300244#define dvb_detach(FUNC) symbol_put_addr(FUNC)
245
Andrew de Quinceyd9955062006-08-08 09:10:08 -0300246#else
247#define dvb_attach(FUNCTION, ARGS...) ({ \
248 FUNCTION(ARGS); \
249})
250
Mauro Carvalho Chehab4647f482014-05-29 09:20:13 -0300251#define dvb_detach(FUNC) {}
252
Andrew de Quinceyd9955062006-08-08 09:10:08 -0300253#endif
254
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255#endif /* #ifndef _DVBDEV_H_ */