1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun * dvbdev.h
3*4882a593Smuzhiyun *
4*4882a593Smuzhiyun * Copyright (C) 2000 Ralph Metzler & Marcus Metzler
5*4882a593Smuzhiyun * for convergence integrated media GmbH
6*4882a593Smuzhiyun *
7*4882a593Smuzhiyun * This program is free software; you can redistribute it and/or
8*4882a593Smuzhiyun * modify it under the terms of the GNU General Lesser Public License
9*4882a593Smuzhiyun * as published by the Free Software Foundation; either version 2.1
10*4882a593Smuzhiyun * of the License, or (at your option) any later version.
11*4882a593Smuzhiyun *
12*4882a593Smuzhiyun * This program is distributed in the hope that it will be useful,
13*4882a593Smuzhiyun * but WITHOUT ANY WARRANTY; without even the implied warranty of
14*4882a593Smuzhiyun * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15*4882a593Smuzhiyun * GNU General Public License for more details.
16*4882a593Smuzhiyun *
17*4882a593Smuzhiyun */
18*4882a593Smuzhiyun
19*4882a593Smuzhiyun #ifndef _DVBDEV_H_
20*4882a593Smuzhiyun #define _DVBDEV_H_
21*4882a593Smuzhiyun
22*4882a593Smuzhiyun #include <linux/types.h>
23*4882a593Smuzhiyun #include <linux/poll.h>
24*4882a593Smuzhiyun #include <linux/fs.h>
25*4882a593Smuzhiyun #include <linux/list.h>
26*4882a593Smuzhiyun #include <media/media-device.h>
27*4882a593Smuzhiyun
28*4882a593Smuzhiyun #define DVB_MAJOR 212
29*4882a593Smuzhiyun
30*4882a593Smuzhiyun #if defined(CONFIG_DVB_MAX_ADAPTERS) && CONFIG_DVB_MAX_ADAPTERS > 0
31*4882a593Smuzhiyun #define DVB_MAX_ADAPTERS CONFIG_DVB_MAX_ADAPTERS
32*4882a593Smuzhiyun #else
33*4882a593Smuzhiyun #define DVB_MAX_ADAPTERS 16
34*4882a593Smuzhiyun #endif
35*4882a593Smuzhiyun
36*4882a593Smuzhiyun #define DVB_UNSET (-1)
37*4882a593Smuzhiyun
38*4882a593Smuzhiyun /* List of DVB device types */
39*4882a593Smuzhiyun
40*4882a593Smuzhiyun /**
41*4882a593Smuzhiyun * enum dvb_device_type - type of the Digital TV device
42*4882a593Smuzhiyun *
43*4882a593Smuzhiyun * @DVB_DEVICE_SEC: Digital TV standalone Common Interface (CI)
44*4882a593Smuzhiyun * @DVB_DEVICE_FRONTEND: Digital TV frontend.
45*4882a593Smuzhiyun * @DVB_DEVICE_DEMUX: Digital TV demux.
46*4882a593Smuzhiyun * @DVB_DEVICE_DVR: Digital TV digital video record (DVR).
47*4882a593Smuzhiyun * @DVB_DEVICE_CA: Digital TV Conditional Access (CA).
48*4882a593Smuzhiyun * @DVB_DEVICE_NET: Digital TV network.
49*4882a593Smuzhiyun *
50*4882a593Smuzhiyun * @DVB_DEVICE_VIDEO: Digital TV video decoder.
51*4882a593Smuzhiyun * Deprecated. Used only on av7110-av.
52*4882a593Smuzhiyun * @DVB_DEVICE_AUDIO: Digital TV audio decoder.
53*4882a593Smuzhiyun * Deprecated. Used only on av7110-av.
54*4882a593Smuzhiyun * @DVB_DEVICE_OSD: Digital TV On Screen Display (OSD).
55*4882a593Smuzhiyun * Deprecated. Used only on av7110.
56*4882a593Smuzhiyun */
57*4882a593Smuzhiyun enum dvb_device_type {
58*4882a593Smuzhiyun DVB_DEVICE_SEC,
59*4882a593Smuzhiyun DVB_DEVICE_FRONTEND,
60*4882a593Smuzhiyun DVB_DEVICE_DEMUX,
61*4882a593Smuzhiyun DVB_DEVICE_DVR,
62*4882a593Smuzhiyun DVB_DEVICE_CA,
63*4882a593Smuzhiyun DVB_DEVICE_NET,
64*4882a593Smuzhiyun
65*4882a593Smuzhiyun DVB_DEVICE_VIDEO,
66*4882a593Smuzhiyun DVB_DEVICE_AUDIO,
67*4882a593Smuzhiyun DVB_DEVICE_OSD,
68*4882a593Smuzhiyun };
69*4882a593Smuzhiyun
70*4882a593Smuzhiyun #define DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr) \
71*4882a593Smuzhiyun static short adapter_nr[] = \
72*4882a593Smuzhiyun {[0 ... (DVB_MAX_ADAPTERS - 1)] = DVB_UNSET }; \
73*4882a593Smuzhiyun module_param_array(adapter_nr, short, NULL, 0444); \
74*4882a593Smuzhiyun MODULE_PARM_DESC(adapter_nr, "DVB adapter numbers")
75*4882a593Smuzhiyun
76*4882a593Smuzhiyun struct dvb_frontend;
77*4882a593Smuzhiyun
78*4882a593Smuzhiyun /**
79*4882a593Smuzhiyun * struct dvb_adapter - represents a Digital TV adapter using Linux DVB API
80*4882a593Smuzhiyun *
81*4882a593Smuzhiyun * @num: Number of the adapter
82*4882a593Smuzhiyun * @list_head: List with the DVB adapters
83*4882a593Smuzhiyun * @device_list: List with the DVB devices
84*4882a593Smuzhiyun * @name: Name of the adapter
85*4882a593Smuzhiyun * @proposed_mac: proposed MAC address for the adapter
86*4882a593Smuzhiyun * @priv: private data
87*4882a593Smuzhiyun * @device: pointer to struct device
88*4882a593Smuzhiyun * @module: pointer to struct module
89*4882a593Smuzhiyun * @mfe_shared: indicates mutually exclusive frontends.
90*4882a593Smuzhiyun * Use of this flag is currently deprecated.
91*4882a593Smuzhiyun * @mfe_dvbdev: Frontend device in use, in the case of MFE
92*4882a593Smuzhiyun * @mfe_lock: Lock to prevent using the other frontends when MFE is
93*4882a593Smuzhiyun * used.
94*4882a593Smuzhiyun * @mdev_lock: Protect access to the mdev pointer.
95*4882a593Smuzhiyun * @mdev: pointer to struct media_device, used when the media
96*4882a593Smuzhiyun * controller is used.
97*4882a593Smuzhiyun * @conn: RF connector. Used only if the device has no separate
98*4882a593Smuzhiyun * tuner.
99*4882a593Smuzhiyun * @conn_pads: pointer to struct media_pad associated with @conn;
100*4882a593Smuzhiyun */
101*4882a593Smuzhiyun struct dvb_adapter {
102*4882a593Smuzhiyun int num;
103*4882a593Smuzhiyun struct list_head list_head;
104*4882a593Smuzhiyun struct list_head device_list;
105*4882a593Smuzhiyun const char *name;
106*4882a593Smuzhiyun u8 proposed_mac [6];
107*4882a593Smuzhiyun void* priv;
108*4882a593Smuzhiyun
109*4882a593Smuzhiyun struct device *device;
110*4882a593Smuzhiyun
111*4882a593Smuzhiyun struct module *module;
112*4882a593Smuzhiyun
113*4882a593Smuzhiyun int mfe_shared; /* indicates mutually exclusive frontends */
114*4882a593Smuzhiyun struct dvb_device *mfe_dvbdev; /* frontend device in use */
115*4882a593Smuzhiyun struct mutex mfe_lock; /* access lock for thread creation */
116*4882a593Smuzhiyun
117*4882a593Smuzhiyun #if defined(CONFIG_MEDIA_CONTROLLER_DVB)
118*4882a593Smuzhiyun struct mutex mdev_lock;
119*4882a593Smuzhiyun struct media_device *mdev;
120*4882a593Smuzhiyun struct media_entity *conn;
121*4882a593Smuzhiyun struct media_pad *conn_pads;
122*4882a593Smuzhiyun #endif
123*4882a593Smuzhiyun };
124*4882a593Smuzhiyun
125*4882a593Smuzhiyun /**
126*4882a593Smuzhiyun * struct dvb_device - represents a DVB device node
127*4882a593Smuzhiyun *
128*4882a593Smuzhiyun * @list_head: List head with all DVB devices
129*4882a593Smuzhiyun * @fops: pointer to struct file_operations
130*4882a593Smuzhiyun * @adapter: pointer to the adapter that holds this device node
131*4882a593Smuzhiyun * @type: type of the device, as defined by &enum dvb_device_type.
132*4882a593Smuzhiyun * @minor: devnode minor number. Major number is always DVB_MAJOR.
133*4882a593Smuzhiyun * @id: device ID number, inside the adapter
134*4882a593Smuzhiyun * @readers: Initialized by the caller. Each call to open() in Read Only mode
135*4882a593Smuzhiyun * decreases this counter by one.
136*4882a593Smuzhiyun * @writers: Initialized by the caller. Each call to open() in Read/Write
137*4882a593Smuzhiyun * mode decreases this counter by one.
138*4882a593Smuzhiyun * @users: Initialized by the caller. Each call to open() in any mode
139*4882a593Smuzhiyun * decreases this counter by one.
140*4882a593Smuzhiyun * @wait_queue: wait queue, used to wait for certain events inside one of
141*4882a593Smuzhiyun * the DVB API callers
142*4882a593Smuzhiyun * @kernel_ioctl: callback function used to handle ioctl calls from userspace.
143*4882a593Smuzhiyun * @name: Name to be used for the device at the Media Controller
144*4882a593Smuzhiyun * @entity: pointer to struct media_entity associated with the device node
145*4882a593Smuzhiyun * @pads: pointer to struct media_pad associated with @entity;
146*4882a593Smuzhiyun * @priv: private data
147*4882a593Smuzhiyun * @intf_devnode: Pointer to media_intf_devnode. Used by the dvbdev core to
148*4882a593Smuzhiyun * store the MC device node interface
149*4882a593Smuzhiyun * @tsout_num_entities: Number of Transport Stream output entities
150*4882a593Smuzhiyun * @tsout_entity: array with MC entities associated to each TS output node
151*4882a593Smuzhiyun * @tsout_pads: array with the source pads for each @tsout_entity
152*4882a593Smuzhiyun *
153*4882a593Smuzhiyun * This structure is used by the DVB core (frontend, CA, net, demux) in
154*4882a593Smuzhiyun * order to create the device nodes. Usually, driver should not initialize
155*4882a593Smuzhiyun * this struct diretly.
156*4882a593Smuzhiyun */
157*4882a593Smuzhiyun struct dvb_device {
158*4882a593Smuzhiyun struct list_head list_head;
159*4882a593Smuzhiyun const struct file_operations *fops;
160*4882a593Smuzhiyun struct dvb_adapter *adapter;
161*4882a593Smuzhiyun enum dvb_device_type type;
162*4882a593Smuzhiyun int minor;
163*4882a593Smuzhiyun u32 id;
164*4882a593Smuzhiyun
165*4882a593Smuzhiyun /* in theory, 'users' can vanish now,
166*4882a593Smuzhiyun but I don't want to change too much now... */
167*4882a593Smuzhiyun int readers;
168*4882a593Smuzhiyun int writers;
169*4882a593Smuzhiyun int users;
170*4882a593Smuzhiyun
171*4882a593Smuzhiyun wait_queue_head_t wait_queue;
172*4882a593Smuzhiyun /* don't really need those !? -- FIXME: use video_usercopy */
173*4882a593Smuzhiyun int (*kernel_ioctl)(struct file *file, unsigned int cmd, void *arg);
174*4882a593Smuzhiyun
175*4882a593Smuzhiyun /* Needed for media controller register/unregister */
176*4882a593Smuzhiyun #if defined(CONFIG_MEDIA_CONTROLLER_DVB)
177*4882a593Smuzhiyun const char *name;
178*4882a593Smuzhiyun
179*4882a593Smuzhiyun /* Allocated and filled inside dvbdev.c */
180*4882a593Smuzhiyun struct media_intf_devnode *intf_devnode;
181*4882a593Smuzhiyun
182*4882a593Smuzhiyun unsigned tsout_num_entities;
183*4882a593Smuzhiyun struct media_entity *entity, *tsout_entity;
184*4882a593Smuzhiyun struct media_pad *pads, *tsout_pads;
185*4882a593Smuzhiyun #endif
186*4882a593Smuzhiyun
187*4882a593Smuzhiyun void *priv;
188*4882a593Smuzhiyun };
189*4882a593Smuzhiyun
190*4882a593Smuzhiyun /**
191*4882a593Smuzhiyun * dvb_register_adapter - Registers a new DVB adapter
192*4882a593Smuzhiyun *
193*4882a593Smuzhiyun * @adap: pointer to struct dvb_adapter
194*4882a593Smuzhiyun * @name: Adapter's name
195*4882a593Smuzhiyun * @module: initialized with THIS_MODULE at the caller
196*4882a593Smuzhiyun * @device: pointer to struct device that corresponds to the device driver
197*4882a593Smuzhiyun * @adapter_nums: Array with a list of the numbers for @dvb_register_adapter;
198*4882a593Smuzhiyun * to select among them. Typically, initialized with:
199*4882a593Smuzhiyun * DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nums)
200*4882a593Smuzhiyun */
201*4882a593Smuzhiyun int dvb_register_adapter(struct dvb_adapter *adap, const char *name,
202*4882a593Smuzhiyun struct module *module, struct device *device,
203*4882a593Smuzhiyun short *adapter_nums);
204*4882a593Smuzhiyun
205*4882a593Smuzhiyun /**
206*4882a593Smuzhiyun * dvb_unregister_adapter - Unregisters a DVB adapter
207*4882a593Smuzhiyun *
208*4882a593Smuzhiyun * @adap: pointer to struct dvb_adapter
209*4882a593Smuzhiyun */
210*4882a593Smuzhiyun int dvb_unregister_adapter(struct dvb_adapter *adap);
211*4882a593Smuzhiyun
212*4882a593Smuzhiyun /**
213*4882a593Smuzhiyun * dvb_register_device - Registers a new DVB device
214*4882a593Smuzhiyun *
215*4882a593Smuzhiyun * @adap: pointer to struct dvb_adapter
216*4882a593Smuzhiyun * @pdvbdev: pointer to the place where the new struct dvb_device will be
217*4882a593Smuzhiyun * stored
218*4882a593Smuzhiyun * @template: Template used to create &pdvbdev;
219*4882a593Smuzhiyun * @priv: private data
220*4882a593Smuzhiyun * @type: type of the device, as defined by &enum dvb_device_type.
221*4882a593Smuzhiyun * @demux_sink_pads: Number of demux outputs, to be used to create the TS
222*4882a593Smuzhiyun * outputs via the Media Controller.
223*4882a593Smuzhiyun */
224*4882a593Smuzhiyun int dvb_register_device(struct dvb_adapter *adap,
225*4882a593Smuzhiyun struct dvb_device **pdvbdev,
226*4882a593Smuzhiyun const struct dvb_device *template,
227*4882a593Smuzhiyun void *priv,
228*4882a593Smuzhiyun enum dvb_device_type type,
229*4882a593Smuzhiyun int demux_sink_pads);
230*4882a593Smuzhiyun
231*4882a593Smuzhiyun /**
232*4882a593Smuzhiyun * dvb_remove_device - Remove a registered DVB device
233*4882a593Smuzhiyun *
234*4882a593Smuzhiyun * This does not free memory. To do that, call dvb_free_device().
235*4882a593Smuzhiyun *
236*4882a593Smuzhiyun * @dvbdev: pointer to struct dvb_device
237*4882a593Smuzhiyun */
238*4882a593Smuzhiyun void dvb_remove_device(struct dvb_device *dvbdev);
239*4882a593Smuzhiyun
240*4882a593Smuzhiyun /**
241*4882a593Smuzhiyun * dvb_free_device - Free memory occupied by a DVB device.
242*4882a593Smuzhiyun *
243*4882a593Smuzhiyun * Call dvb_unregister_device() before calling this function.
244*4882a593Smuzhiyun *
245*4882a593Smuzhiyun * @dvbdev: pointer to struct dvb_device
246*4882a593Smuzhiyun */
247*4882a593Smuzhiyun void dvb_free_device(struct dvb_device *dvbdev);
248*4882a593Smuzhiyun
249*4882a593Smuzhiyun /**
250*4882a593Smuzhiyun * dvb_unregister_device - Unregisters a DVB device
251*4882a593Smuzhiyun *
252*4882a593Smuzhiyun * This is a combination of dvb_remove_device() and dvb_free_device().
253*4882a593Smuzhiyun * Using this function is usually a mistake, and is often an indicator
254*4882a593Smuzhiyun * for a use-after-free bug (when a userspace process keeps a file
255*4882a593Smuzhiyun * handle to a detached device).
256*4882a593Smuzhiyun *
257*4882a593Smuzhiyun * @dvbdev: pointer to struct dvb_device
258*4882a593Smuzhiyun */
259*4882a593Smuzhiyun void dvb_unregister_device(struct dvb_device *dvbdev);
260*4882a593Smuzhiyun
261*4882a593Smuzhiyun #ifdef CONFIG_MEDIA_CONTROLLER_DVB
262*4882a593Smuzhiyun /**
263*4882a593Smuzhiyun * dvb_create_media_graph - Creates media graph for the Digital TV part of the
264*4882a593Smuzhiyun * device.
265*4882a593Smuzhiyun *
266*4882a593Smuzhiyun * @adap: pointer to &struct dvb_adapter
267*4882a593Smuzhiyun * @create_rf_connector: if true, it creates the RF connector too
268*4882a593Smuzhiyun *
269*4882a593Smuzhiyun * This function checks all DVB-related functions at the media controller
270*4882a593Smuzhiyun * entities and creates the needed links for the media graph. It is
271*4882a593Smuzhiyun * capable of working with multiple tuners or multiple frontends, but it
272*4882a593Smuzhiyun * won't create links if the device has multiple tuners and multiple frontends
273*4882a593Smuzhiyun * or if the device has multiple muxes. In such case, the caller driver should
274*4882a593Smuzhiyun * manually create the remaining links.
275*4882a593Smuzhiyun */
276*4882a593Smuzhiyun __must_check int dvb_create_media_graph(struct dvb_adapter *adap,
277*4882a593Smuzhiyun bool create_rf_connector);
278*4882a593Smuzhiyun
279*4882a593Smuzhiyun /**
280*4882a593Smuzhiyun * dvb_register_media_controller - registers a media controller at DVB adapter
281*4882a593Smuzhiyun *
282*4882a593Smuzhiyun * @adap: pointer to &struct dvb_adapter
283*4882a593Smuzhiyun * @mdev: pointer to &struct media_device
284*4882a593Smuzhiyun */
dvb_register_media_controller(struct dvb_adapter * adap,struct media_device * mdev)285*4882a593Smuzhiyun static inline void dvb_register_media_controller(struct dvb_adapter *adap,
286*4882a593Smuzhiyun struct media_device *mdev)
287*4882a593Smuzhiyun {
288*4882a593Smuzhiyun adap->mdev = mdev;
289*4882a593Smuzhiyun }
290*4882a593Smuzhiyun
291*4882a593Smuzhiyun /**
292*4882a593Smuzhiyun * dvb_get_media_controller - gets the associated media controller
293*4882a593Smuzhiyun *
294*4882a593Smuzhiyun * @adap: pointer to &struct dvb_adapter
295*4882a593Smuzhiyun */
296*4882a593Smuzhiyun static inline struct media_device *
dvb_get_media_controller(struct dvb_adapter * adap)297*4882a593Smuzhiyun dvb_get_media_controller(struct dvb_adapter *adap)
298*4882a593Smuzhiyun {
299*4882a593Smuzhiyun return adap->mdev;
300*4882a593Smuzhiyun }
301*4882a593Smuzhiyun #else
302*4882a593Smuzhiyun static inline
dvb_create_media_graph(struct dvb_adapter * adap,bool create_rf_connector)303*4882a593Smuzhiyun int dvb_create_media_graph(struct dvb_adapter *adap,
304*4882a593Smuzhiyun bool create_rf_connector)
305*4882a593Smuzhiyun {
306*4882a593Smuzhiyun return 0;
307*4882a593Smuzhiyun };
308*4882a593Smuzhiyun #define dvb_register_media_controller(a, b) {}
309*4882a593Smuzhiyun #define dvb_get_media_controller(a) NULL
310*4882a593Smuzhiyun #endif
311*4882a593Smuzhiyun
312*4882a593Smuzhiyun /**
313*4882a593Smuzhiyun * dvb_generic_open - Digital TV open function, used by DVB devices
314*4882a593Smuzhiyun *
315*4882a593Smuzhiyun * @inode: pointer to &struct inode.
316*4882a593Smuzhiyun * @file: pointer to &struct file.
317*4882a593Smuzhiyun *
318*4882a593Smuzhiyun * Checks if a DVB devnode is still valid, and if the permissions are
319*4882a593Smuzhiyun * OK and increment negative use count.
320*4882a593Smuzhiyun */
321*4882a593Smuzhiyun int dvb_generic_open(struct inode *inode, struct file *file);
322*4882a593Smuzhiyun
323*4882a593Smuzhiyun /**
324*4882a593Smuzhiyun * dvb_generic_close - Digital TV close function, used by DVB devices
325*4882a593Smuzhiyun *
326*4882a593Smuzhiyun * @inode: pointer to &struct inode.
327*4882a593Smuzhiyun * @file: pointer to &struct file.
328*4882a593Smuzhiyun *
329*4882a593Smuzhiyun * Checks if a DVB devnode is still valid, and if the permissions are
330*4882a593Smuzhiyun * OK and decrement negative use count.
331*4882a593Smuzhiyun */
332*4882a593Smuzhiyun int dvb_generic_release(struct inode *inode, struct file *file);
333*4882a593Smuzhiyun
334*4882a593Smuzhiyun /**
335*4882a593Smuzhiyun * dvb_generic_ioctl - Digital TV close function, used by DVB devices
336*4882a593Smuzhiyun *
337*4882a593Smuzhiyun * @file: pointer to &struct file.
338*4882a593Smuzhiyun * @cmd: Ioctl name.
339*4882a593Smuzhiyun * @arg: Ioctl argument.
340*4882a593Smuzhiyun *
341*4882a593Smuzhiyun * Checks if a DVB devnode and struct dvbdev.kernel_ioctl is still valid.
342*4882a593Smuzhiyun * If so, calls dvb_usercopy().
343*4882a593Smuzhiyun */
344*4882a593Smuzhiyun long dvb_generic_ioctl(struct file *file,
345*4882a593Smuzhiyun unsigned int cmd, unsigned long arg);
346*4882a593Smuzhiyun
347*4882a593Smuzhiyun /**
348*4882a593Smuzhiyun * dvb_usercopy - copies data from/to userspace memory when an ioctl is
349*4882a593Smuzhiyun * issued.
350*4882a593Smuzhiyun *
351*4882a593Smuzhiyun * @file: Pointer to struct &file.
352*4882a593Smuzhiyun * @cmd: Ioctl name.
353*4882a593Smuzhiyun * @arg: Ioctl argument.
354*4882a593Smuzhiyun * @func: function that will actually handle the ioctl
355*4882a593Smuzhiyun *
356*4882a593Smuzhiyun * Ancillary function that uses ioctl direction and size to copy from
357*4882a593Smuzhiyun * userspace. Then, it calls @func, and, if needed, data is copied back
358*4882a593Smuzhiyun * to userspace.
359*4882a593Smuzhiyun */
360*4882a593Smuzhiyun int dvb_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
361*4882a593Smuzhiyun int (*func)(struct file *file, unsigned int cmd, void *arg));
362*4882a593Smuzhiyun
363*4882a593Smuzhiyun #if IS_ENABLED(CONFIG_I2C)
364*4882a593Smuzhiyun
365*4882a593Smuzhiyun struct i2c_adapter;
366*4882a593Smuzhiyun struct i2c_client;
367*4882a593Smuzhiyun /**
368*4882a593Smuzhiyun * dvb_module_probe - helper routine to probe an I2C module
369*4882a593Smuzhiyun *
370*4882a593Smuzhiyun * @module_name:
371*4882a593Smuzhiyun * Name of the I2C module to be probed
372*4882a593Smuzhiyun * @name:
373*4882a593Smuzhiyun * Optional name for the I2C module. Used for debug purposes.
374*4882a593Smuzhiyun * If %NULL, defaults to @module_name.
375*4882a593Smuzhiyun * @adap:
376*4882a593Smuzhiyun * pointer to &struct i2c_adapter that describes the I2C adapter where
377*4882a593Smuzhiyun * the module will be bound.
378*4882a593Smuzhiyun * @addr:
379*4882a593Smuzhiyun * I2C address of the adapter, in 7-bit notation.
380*4882a593Smuzhiyun * @platform_data:
381*4882a593Smuzhiyun * Platform data to be passed to the I2C module probed.
382*4882a593Smuzhiyun *
383*4882a593Smuzhiyun * This function binds an I2C device into the DVB core. Should be used by
384*4882a593Smuzhiyun * all drivers that use I2C bus to control the hardware. A module bound
385*4882a593Smuzhiyun * with dvb_module_probe() should use dvb_module_release() to unbind.
386*4882a593Smuzhiyun *
387*4882a593Smuzhiyun * Return:
388*4882a593Smuzhiyun * On success, return an &struct i2c_client, pointing to the bound
389*4882a593Smuzhiyun * I2C device. %NULL otherwise.
390*4882a593Smuzhiyun *
391*4882a593Smuzhiyun * .. note::
392*4882a593Smuzhiyun *
393*4882a593Smuzhiyun * In the past, DVB modules (mainly, frontends) were bound via dvb_attach()
394*4882a593Smuzhiyun * macro, with does an ugly hack, using I2C low level functions. Such
395*4882a593Smuzhiyun * usage is deprecated and will be removed soon. Instead, use this routine.
396*4882a593Smuzhiyun */
397*4882a593Smuzhiyun struct i2c_client *dvb_module_probe(const char *module_name,
398*4882a593Smuzhiyun const char *name,
399*4882a593Smuzhiyun struct i2c_adapter *adap,
400*4882a593Smuzhiyun unsigned char addr,
401*4882a593Smuzhiyun void *platform_data);
402*4882a593Smuzhiyun
403*4882a593Smuzhiyun /**
404*4882a593Smuzhiyun * dvb_module_release - releases an I2C device allocated with
405*4882a593Smuzhiyun * dvb_module_probe().
406*4882a593Smuzhiyun *
407*4882a593Smuzhiyun * @client: pointer to &struct i2c_client with the I2C client to be released.
408*4882a593Smuzhiyun * can be %NULL.
409*4882a593Smuzhiyun *
410*4882a593Smuzhiyun * This function should be used to free all resources reserved by
411*4882a593Smuzhiyun * dvb_module_probe() and unbinding the I2C hardware.
412*4882a593Smuzhiyun */
413*4882a593Smuzhiyun void dvb_module_release(struct i2c_client *client);
414*4882a593Smuzhiyun
415*4882a593Smuzhiyun #endif /* CONFIG_I2C */
416*4882a593Smuzhiyun
417*4882a593Smuzhiyun /* Legacy generic DVB attach function. */
418*4882a593Smuzhiyun #ifdef CONFIG_MEDIA_ATTACH
419*4882a593Smuzhiyun
420*4882a593Smuzhiyun /**
421*4882a593Smuzhiyun * dvb_attach - attaches a DVB frontend into the DVB core.
422*4882a593Smuzhiyun *
423*4882a593Smuzhiyun * @FUNCTION: function on a frontend module to be called.
424*4882a593Smuzhiyun * @ARGS...: @FUNCTION arguments.
425*4882a593Smuzhiyun *
426*4882a593Smuzhiyun * This ancillary function loads a frontend module in runtime and runs
427*4882a593Smuzhiyun * the @FUNCTION function there, with @ARGS.
428*4882a593Smuzhiyun * As it increments symbol usage cont, at unregister, dvb_detach()
429*4882a593Smuzhiyun * should be called.
430*4882a593Smuzhiyun *
431*4882a593Smuzhiyun * .. note::
432*4882a593Smuzhiyun *
433*4882a593Smuzhiyun * In the past, DVB modules (mainly, frontends) were bound via dvb_attach()
434*4882a593Smuzhiyun * macro, with does an ugly hack, using I2C low level functions. Such
435*4882a593Smuzhiyun * usage is deprecated and will be removed soon. Instead, you should use
436*4882a593Smuzhiyun * dvb_module_probe().
437*4882a593Smuzhiyun */
438*4882a593Smuzhiyun #define dvb_attach(FUNCTION, ARGS...) ({ \
439*4882a593Smuzhiyun void *__r = NULL; \
440*4882a593Smuzhiyun typeof(&FUNCTION) __a = symbol_request(FUNCTION); \
441*4882a593Smuzhiyun if (__a) { \
442*4882a593Smuzhiyun __r = (void *) __a(ARGS); \
443*4882a593Smuzhiyun if (__r == NULL) \
444*4882a593Smuzhiyun symbol_put(FUNCTION); \
445*4882a593Smuzhiyun } else { \
446*4882a593Smuzhiyun printk(KERN_ERR "DVB: Unable to find symbol "#FUNCTION"()\n"); \
447*4882a593Smuzhiyun } \
448*4882a593Smuzhiyun __r; \
449*4882a593Smuzhiyun })
450*4882a593Smuzhiyun
451*4882a593Smuzhiyun /**
452*4882a593Smuzhiyun * dvb_detach - detaches a DVB frontend loaded via dvb_attach()
453*4882a593Smuzhiyun *
454*4882a593Smuzhiyun * @FUNC: attach function
455*4882a593Smuzhiyun *
456*4882a593Smuzhiyun * Decrements usage count for a function previously called via dvb_attach().
457*4882a593Smuzhiyun */
458*4882a593Smuzhiyun
459*4882a593Smuzhiyun #define dvb_detach(FUNC) symbol_put_addr(FUNC)
460*4882a593Smuzhiyun
461*4882a593Smuzhiyun #else
462*4882a593Smuzhiyun #define dvb_attach(FUNCTION, ARGS...) ({ \
463*4882a593Smuzhiyun FUNCTION(ARGS); \
464*4882a593Smuzhiyun })
465*4882a593Smuzhiyun
466*4882a593Smuzhiyun #define dvb_detach(FUNC) {}
467*4882a593Smuzhiyun
468*4882a593Smuzhiyun #endif /* CONFIG_MEDIA_ATTACH */
469*4882a593Smuzhiyun
470*4882a593Smuzhiyun #endif /* #ifndef _DVBDEV_H_ */
471