1 // SPDX-License-Identifier: LGPL-2.1-or-later
5 * Copyright (C) 2000 Ralph Metzler <ralph@convergence.de>
6 * & Marcus Metzler <marcus@convergence.de>
7 * for convergence integrated media GmbH
10 #define pr_fmt(fmt) "dvbdev: " fmt
12 #include <linux/types.h>
13 #include <linux/errno.h>
14 #include <linux/string.h>
15 #include <linux/module.h>
16 #include <linux/kernel.h>
17 #include <linux/i2c.h>
18 #include <linux/init.h>
19 #include <linux/slab.h>
20 #include <linux/device.h>
22 #include <linux/cdev.h>
23 #include <linux/mutex.h>
24 #include <media/dvbdev.h>
26 /* Due to enum tuner_pad_index */
27 #include <media/tuner.h>
29 static DEFINE_MUTEX(dvbdev_mutex
);
30 static LIST_HEAD(dvbdevfops_list
);
31 static int dvbdev_debug
;
33 module_param(dvbdev_debug
, int, 0644);
34 MODULE_PARM_DESC(dvbdev_debug
, "Turn on/off device debugging (default:off).");
36 #define dprintk(fmt, arg...) do { \
38 printk(KERN_DEBUG pr_fmt("%s: " fmt), \
42 static LIST_HEAD(dvb_adapter_list
);
43 static DEFINE_MUTEX(dvbdev_register_lock
);
45 static const char * const dnames
[] = {
46 [DVB_DEVICE_VIDEO
] = "video",
47 [DVB_DEVICE_AUDIO
] = "audio",
48 [DVB_DEVICE_SEC
] = "sec",
49 [DVB_DEVICE_FRONTEND
] = "frontend",
50 [DVB_DEVICE_DEMUX
] = "demux",
51 [DVB_DEVICE_DVR
] = "dvr",
52 [DVB_DEVICE_CA
] = "ca",
53 [DVB_DEVICE_NET
] = "net",
54 [DVB_DEVICE_OSD
] = "osd"
57 #ifdef CONFIG_DVB_DYNAMIC_MINORS
58 #define MAX_DVB_MINORS 256
59 #define DVB_MAX_IDS MAX_DVB_MINORS
63 static const u8 minor_type
[] = {
64 [DVB_DEVICE_VIDEO
] = 0,
65 [DVB_DEVICE_AUDIO
] = 1,
67 [DVB_DEVICE_FRONTEND
] = 3,
68 [DVB_DEVICE_DEMUX
] = 4,
75 #define nums2minor(num, type, id) \
76 (((num) << 6) | ((id) << 4) | minor_type[type])
78 #define MAX_DVB_MINORS (DVB_MAX_ADAPTERS * 64)
81 static struct class *dvb_class
;
83 static struct dvb_device
*dvb_minors
[MAX_DVB_MINORS
];
84 static DECLARE_RWSEM(minor_rwsem
);
86 static int dvb_device_open(struct inode
*inode
, struct file
*file
)
88 struct dvb_device
*dvbdev
;
89 unsigned int minor
= iminor(inode
);
91 if (minor
>= MAX_DVB_MINORS
)
94 mutex_lock(&dvbdev_mutex
);
95 down_read(&minor_rwsem
);
97 dvbdev
= dvb_minors
[minor
];
99 if (dvbdev
&& dvbdev
->fops
) {
101 const struct file_operations
*new_fops
;
103 new_fops
= fops_get(dvbdev
->fops
);
106 file
->private_data
= dvb_device_get(dvbdev
);
107 replace_fops(file
, new_fops
);
108 if (file
->f_op
->open
)
109 err
= file
->f_op
->open(inode
, file
);
110 up_read(&minor_rwsem
);
111 mutex_unlock(&dvbdev_mutex
);
113 dvb_device_put(dvbdev
);
117 up_read(&minor_rwsem
);
118 mutex_unlock(&dvbdev_mutex
);
122 static const struct file_operations dvb_device_fops
= {
123 .owner
= THIS_MODULE
,
124 .open
= dvb_device_open
,
125 .llseek
= noop_llseek
,
128 static struct cdev dvb_device_cdev
;
130 int dvb_generic_open(struct inode
*inode
, struct file
*file
)
132 struct dvb_device
*dvbdev
= file
->private_data
;
140 if ((file
->f_flags
& O_ACCMODE
) == O_RDONLY
) {
141 if (!dvbdev
->readers
)
145 if (!dvbdev
->writers
)
153 EXPORT_SYMBOL(dvb_generic_open
);
155 int dvb_generic_release(struct inode
*inode
, struct file
*file
)
157 struct dvb_device
*dvbdev
= file
->private_data
;
162 if ((file
->f_flags
& O_ACCMODE
) == O_RDONLY
)
169 dvb_device_put(dvbdev
);
173 EXPORT_SYMBOL(dvb_generic_release
);
175 long dvb_generic_ioctl(struct file
*file
,
176 unsigned int cmd
, unsigned long arg
)
178 struct dvb_device
*dvbdev
= file
->private_data
;
183 if (!dvbdev
->kernel_ioctl
)
186 return dvb_usercopy(file
, cmd
, arg
, dvbdev
->kernel_ioctl
);
188 EXPORT_SYMBOL(dvb_generic_ioctl
);
190 static int dvbdev_get_free_id(struct dvb_adapter
*adap
, int type
)
194 while (id
< DVB_MAX_IDS
) {
195 struct dvb_device
*dev
;
197 list_for_each_entry(dev
, &adap
->device_list
, list_head
)
198 if (dev
->type
== type
&& dev
->id
== id
)
207 static void dvb_media_device_free(struct dvb_device
*dvbdev
)
209 #if defined(CONFIG_MEDIA_CONTROLLER_DVB)
210 if (dvbdev
->entity
) {
211 media_device_unregister_entity(dvbdev
->entity
);
212 kfree(dvbdev
->entity
);
214 dvbdev
->entity
= NULL
;
218 if (dvbdev
->tsout_entity
) {
221 for (i
= 0; i
< dvbdev
->tsout_num_entities
; i
++) {
222 media_device_unregister_entity(&dvbdev
->tsout_entity
[i
]);
223 kfree(dvbdev
->tsout_entity
[i
].name
);
225 kfree(dvbdev
->tsout_entity
);
226 kfree(dvbdev
->tsout_pads
);
227 dvbdev
->tsout_entity
= NULL
;
228 dvbdev
->tsout_pads
= NULL
;
230 dvbdev
->tsout_num_entities
= 0;
233 if (dvbdev
->intf_devnode
) {
234 media_devnode_remove(dvbdev
->intf_devnode
);
235 dvbdev
->intf_devnode
= NULL
;
238 if (dvbdev
->adapter
->conn
) {
239 media_device_unregister_entity(dvbdev
->adapter
->conn
);
240 kfree(dvbdev
->adapter
->conn
);
241 dvbdev
->adapter
->conn
= NULL
;
242 kfree(dvbdev
->adapter
->conn_pads
);
243 dvbdev
->adapter
->conn_pads
= NULL
;
248 #if defined(CONFIG_MEDIA_CONTROLLER_DVB)
249 static int dvb_create_tsout_entity(struct dvb_device
*dvbdev
,
250 const char *name
, int npads
)
254 dvbdev
->tsout_pads
= kcalloc(npads
, sizeof(*dvbdev
->tsout_pads
),
256 if (!dvbdev
->tsout_pads
)
259 dvbdev
->tsout_entity
= kcalloc(npads
, sizeof(*dvbdev
->tsout_entity
),
261 if (!dvbdev
->tsout_entity
)
264 dvbdev
->tsout_num_entities
= npads
;
266 for (i
= 0; i
< npads
; i
++) {
267 struct media_pad
*pads
= &dvbdev
->tsout_pads
[i
];
268 struct media_entity
*entity
= &dvbdev
->tsout_entity
[i
];
271 entity
->name
= kasprintf(GFP_KERNEL
, "%s #%d", name
, i
);
275 entity
->function
= MEDIA_ENT_F_IO_DTV
;
276 pads
->flags
= MEDIA_PAD_FL_SINK
;
278 ret
= media_entity_pads_init(entity
, 1, pads
);
282 ret
= media_device_register_entity(dvbdev
->adapter
->mdev
,
290 #define DEMUX_TSOUT "demux-tsout"
291 #define DVR_TSOUT "dvr-tsout"
293 static int dvb_create_media_entity(struct dvb_device
*dvbdev
,
294 int type
, int demux_sink_pads
)
299 case DVB_DEVICE_FRONTEND
:
303 ret
= dvb_create_tsout_entity(dvbdev
, DVR_TSOUT
,
306 case DVB_DEVICE_DEMUX
:
307 npads
= 1 + demux_sink_pads
;
308 ret
= dvb_create_tsout_entity(dvbdev
, DEMUX_TSOUT
,
318 * We should be creating entities for the MPE/ULE
319 * decapsulation hardware (or software implementation).
321 * However, the number of for the MPE/ULE decaps may not be
322 * fixed. As we don't have yet dynamic support for PADs at
323 * the Media Controller, let's not create the decap
331 dvbdev
->entity
= kzalloc(sizeof(*dvbdev
->entity
), GFP_KERNEL
);
335 dvbdev
->entity
->name
= dvbdev
->name
;
338 dvbdev
->pads
= kcalloc(npads
, sizeof(*dvbdev
->pads
),
341 kfree(dvbdev
->entity
);
342 dvbdev
->entity
= NULL
;
348 case DVB_DEVICE_FRONTEND
:
349 dvbdev
->entity
->function
= MEDIA_ENT_F_DTV_DEMOD
;
350 dvbdev
->pads
[0].flags
= MEDIA_PAD_FL_SINK
;
351 dvbdev
->pads
[1].flags
= MEDIA_PAD_FL_SOURCE
;
353 case DVB_DEVICE_DEMUX
:
354 dvbdev
->entity
->function
= MEDIA_ENT_F_TS_DEMUX
;
355 dvbdev
->pads
[0].flags
= MEDIA_PAD_FL_SINK
;
356 for (i
= 1; i
< npads
; i
++)
357 dvbdev
->pads
[i
].flags
= MEDIA_PAD_FL_SOURCE
;
360 dvbdev
->entity
->function
= MEDIA_ENT_F_DTV_CA
;
361 dvbdev
->pads
[0].flags
= MEDIA_PAD_FL_SINK
;
362 dvbdev
->pads
[1].flags
= MEDIA_PAD_FL_SOURCE
;
365 /* Should never happen, as the first switch prevents it */
366 kfree(dvbdev
->entity
);
368 dvbdev
->entity
= NULL
;
374 ret
= media_entity_pads_init(dvbdev
->entity
, npads
, dvbdev
->pads
);
378 ret
= media_device_register_entity(dvbdev
->adapter
->mdev
,
383 pr_info("%s: media entity '%s' registered.\n",
384 __func__
, dvbdev
->entity
->name
);
390 static int dvb_register_media_device(struct dvb_device
*dvbdev
,
392 unsigned int demux_sink_pads
)
394 #if defined(CONFIG_MEDIA_CONTROLLER_DVB)
395 struct media_link
*link
;
399 if (!dvbdev
->adapter
->mdev
)
402 ret
= dvb_create_media_entity(dvbdev
, type
, demux_sink_pads
);
407 case DVB_DEVICE_FRONTEND
:
408 intf_type
= MEDIA_INTF_T_DVB_FE
;
410 case DVB_DEVICE_DEMUX
:
411 intf_type
= MEDIA_INTF_T_DVB_DEMUX
;
414 intf_type
= MEDIA_INTF_T_DVB_DVR
;
417 intf_type
= MEDIA_INTF_T_DVB_CA
;
420 intf_type
= MEDIA_INTF_T_DVB_NET
;
426 dvbdev
->intf_devnode
= media_devnode_create(dvbdev
->adapter
->mdev
,
430 if (!dvbdev
->intf_devnode
)
434 * Create the "obvious" link, e. g. the ones that represent
435 * a direct association between an interface and an entity.
436 * Other links should be created elsewhere, like:
437 * DVB FE intf -> tuner
438 * DVB demux intf -> dvr
444 link
= media_create_intf_link(dvbdev
->entity
,
445 &dvbdev
->intf_devnode
->intf
,
446 MEDIA_LNK_FL_ENABLED
|
447 MEDIA_LNK_FL_IMMUTABLE
);
454 int dvb_register_device(struct dvb_adapter
*adap
, struct dvb_device
**pdvbdev
,
455 const struct dvb_device
*template, void *priv
,
456 enum dvb_device_type type
, int demux_sink_pads
)
458 struct dvb_device
*dvbdev
;
459 struct file_operations
*dvbdevfops
= NULL
;
460 struct dvbdevfops_node
*node
= NULL
, *new_node
= NULL
;
461 struct device
*clsdev
;
465 mutex_lock(&dvbdev_register_lock
);
467 id
= dvbdev_get_free_id(adap
, type
);
469 mutex_unlock(&dvbdev_register_lock
);
471 pr_err("%s: couldn't find free device id\n", __func__
);
475 *pdvbdev
= dvbdev
= kzalloc(sizeof(*dvbdev
), GFP_KERNEL
);
477 mutex_unlock(&dvbdev_register_lock
);
482 * When a device of the same type is probe()d more than once,
483 * the first allocated fops are used. This prevents memory leaks
484 * that can occur when the same device is probe()d repeatedly.
486 list_for_each_entry(node
, &dvbdevfops_list
, list_head
) {
487 if (node
->fops
->owner
== adap
->module
&&
488 node
->type
== type
&& node
->template == template) {
489 dvbdevfops
= node
->fops
;
495 dvbdevfops
= kmemdup(template->fops
, sizeof(*dvbdevfops
), GFP_KERNEL
);
499 mutex_unlock(&dvbdev_register_lock
);
503 new_node
= kzalloc(sizeof(*new_node
), GFP_KERNEL
);
508 mutex_unlock(&dvbdev_register_lock
);
512 new_node
->fops
= dvbdevfops
;
513 new_node
->type
= type
;
514 new_node
->template = template;
515 list_add_tail(&new_node
->list_head
, &dvbdevfops_list
);
518 memcpy(dvbdev
, template, sizeof(struct dvb_device
));
519 kref_init(&dvbdev
->ref
);
522 dvbdev
->adapter
= adap
;
524 dvbdev
->fops
= dvbdevfops
;
525 init_waitqueue_head(&dvbdev
->wait_queue
);
526 dvbdevfops
->owner
= adap
->module
;
527 list_add_tail(&dvbdev
->list_head
, &adap
->device_list
);
528 down_write(&minor_rwsem
);
529 #ifdef CONFIG_DVB_DYNAMIC_MINORS
530 for (minor
= 0; minor
< MAX_DVB_MINORS
; minor
++)
531 if (!dvb_minors
[minor
])
534 minor
= nums2minor(adap
->num
, type
, id
);
536 if (minor
>= MAX_DVB_MINORS
) {
538 list_del(&new_node
->list_head
);
542 list_del(&dvbdev
->list_head
);
545 up_write(&minor_rwsem
);
546 mutex_unlock(&dvbdev_register_lock
);
550 dvbdev
->minor
= minor
;
551 dvb_minors
[minor
] = dvb_device_get(dvbdev
);
552 up_write(&minor_rwsem
);
553 ret
= dvb_register_media_device(dvbdev
, type
, minor
, demux_sink_pads
);
555 pr_err("%s: dvb_register_media_device failed to create the mediagraph\n",
558 list_del(&new_node
->list_head
);
562 dvb_media_device_free(dvbdev
);
563 list_del(&dvbdev
->list_head
);
566 mutex_unlock(&dvbdev_register_lock
);
570 clsdev
= device_create(dvb_class
, adap
->device
,
571 MKDEV(DVB_MAJOR
, minor
),
572 dvbdev
, "dvb%d.%s%d", adap
->num
, dnames
[type
], id
);
573 if (IS_ERR(clsdev
)) {
574 pr_err("%s: failed to create device dvb%d.%s%d (%ld)\n",
575 __func__
, adap
->num
, dnames
[type
], id
, PTR_ERR(clsdev
));
577 list_del(&new_node
->list_head
);
581 dvb_media_device_free(dvbdev
);
582 list_del(&dvbdev
->list_head
);
585 mutex_unlock(&dvbdev_register_lock
);
586 return PTR_ERR(clsdev
);
589 dprintk("DVB: register adapter%d/%s%d @ minor: %i (0x%02x)\n",
590 adap
->num
, dnames
[type
], id
, minor
, minor
);
592 mutex_unlock(&dvbdev_register_lock
);
595 EXPORT_SYMBOL(dvb_register_device
);
597 void dvb_remove_device(struct dvb_device
*dvbdev
)
602 down_write(&minor_rwsem
);
603 dvb_minors
[dvbdev
->minor
] = NULL
;
604 dvb_device_put(dvbdev
);
605 up_write(&minor_rwsem
);
607 dvb_media_device_free(dvbdev
);
609 device_destroy(dvb_class
, MKDEV(DVB_MAJOR
, dvbdev
->minor
));
611 list_del(&dvbdev
->list_head
);
613 EXPORT_SYMBOL(dvb_remove_device
);
615 static void dvb_free_device(struct kref
*ref
)
617 struct dvb_device
*dvbdev
= container_of(ref
, struct dvb_device
, ref
);
622 struct dvb_device
*dvb_device_get(struct dvb_device
*dvbdev
)
624 kref_get(&dvbdev
->ref
);
627 EXPORT_SYMBOL(dvb_device_get
);
629 void dvb_device_put(struct dvb_device
*dvbdev
)
632 kref_put(&dvbdev
->ref
, dvb_free_device
);
635 void dvb_unregister_device(struct dvb_device
*dvbdev
)
637 dvb_remove_device(dvbdev
);
638 dvb_device_put(dvbdev
);
640 EXPORT_SYMBOL(dvb_unregister_device
);
642 #ifdef CONFIG_MEDIA_CONTROLLER_DVB
644 static int dvb_create_io_intf_links(struct dvb_adapter
*adap
,
645 struct media_interface
*intf
,
648 struct media_device
*mdev
= adap
->mdev
;
649 struct media_entity
*entity
;
650 struct media_link
*link
;
652 media_device_for_each_entity(entity
, mdev
) {
653 if (entity
->function
== MEDIA_ENT_F_IO_DTV
) {
654 if (strncmp(entity
->name
, name
, strlen(name
)))
656 link
= media_create_intf_link(entity
, intf
,
657 MEDIA_LNK_FL_ENABLED
|
658 MEDIA_LNK_FL_IMMUTABLE
);
666 int dvb_create_media_graph(struct dvb_adapter
*adap
,
667 bool create_rf_connector
)
669 struct media_device
*mdev
= adap
->mdev
;
670 struct media_entity
*entity
, *tuner
= NULL
, *demod
= NULL
, *conn
;
671 struct media_entity
*demux
= NULL
, *ca
= NULL
;
672 struct media_link
*link
;
673 struct media_interface
*intf
;
674 unsigned int demux_pad
= 0;
675 unsigned int dvr_pad
= 0;
676 unsigned int ntuner
= 0, ndemod
= 0;
677 int ret
, pad_source
, pad_sink
;
678 static const char *connector_name
= "Television";
683 media_device_for_each_entity(entity
, mdev
) {
684 switch (entity
->function
) {
685 case MEDIA_ENT_F_TUNER
:
689 case MEDIA_ENT_F_DTV_DEMOD
:
693 case MEDIA_ENT_F_TS_DEMUX
:
696 case MEDIA_ENT_F_DTV_CA
:
703 * Prepare to signalize to media_create_pad_links() that multiple
704 * entities of the same type exists and a 1:n or n:1 links need to be
706 * NOTE: if both tuner and demod have multiple instances, it is up
707 * to the caller driver to create such links.
714 if (create_rf_connector
) {
715 conn
= kzalloc(sizeof(*conn
), GFP_KERNEL
);
720 adap
->conn_pads
= kzalloc(sizeof(*adap
->conn_pads
), GFP_KERNEL
);
721 if (!adap
->conn_pads
)
724 conn
->flags
= MEDIA_ENT_FL_CONNECTOR
;
725 conn
->function
= MEDIA_ENT_F_CONN_RF
;
726 conn
->name
= connector_name
;
727 adap
->conn_pads
->flags
= MEDIA_PAD_FL_SOURCE
;
729 ret
= media_entity_pads_init(conn
, 1, adap
->conn_pads
);
733 ret
= media_device_register_entity(mdev
, conn
);
738 ret
= media_create_pad_links(mdev
,
741 MEDIA_ENT_F_DTV_DEMOD
,
743 MEDIA_LNK_FL_ENABLED
,
746 pad_sink
= media_get_pad_index(tuner
, MEDIA_PAD_FL_SINK
,
750 ret
= media_create_pad_links(mdev
,
755 MEDIA_LNK_FL_ENABLED
,
762 if (ntuner
&& ndemod
) {
763 /* NOTE: first found tuner source pad presumed correct */
764 pad_source
= media_get_pad_index(tuner
, MEDIA_PAD_FL_SOURCE
,
768 ret
= media_create_pad_links(mdev
,
771 MEDIA_ENT_F_DTV_DEMOD
,
772 demod
, 0, MEDIA_LNK_FL_ENABLED
,
778 if (ndemod
&& demux
) {
779 ret
= media_create_pad_links(mdev
,
780 MEDIA_ENT_F_DTV_DEMOD
,
782 MEDIA_ENT_F_TS_DEMUX
,
783 demux
, 0, MEDIA_LNK_FL_ENABLED
,
789 ret
= media_create_pad_link(demux
, 1, ca
,
790 0, MEDIA_LNK_FL_ENABLED
);
795 /* Create demux links for each ringbuffer/pad */
797 media_device_for_each_entity(entity
, mdev
) {
798 if (entity
->function
== MEDIA_ENT_F_IO_DTV
) {
799 if (!strncmp(entity
->name
, DVR_TSOUT
,
800 strlen(DVR_TSOUT
))) {
801 ret
= media_create_pad_link(demux
,
807 if (!strncmp(entity
->name
, DEMUX_TSOUT
,
808 strlen(DEMUX_TSOUT
))) {
809 ret
= media_create_pad_link(demux
,
819 /* Create interface links for FE->tuner, DVR->demux and CA->ca */
820 media_device_for_each_intf(intf
, mdev
) {
821 if (intf
->type
== MEDIA_INTF_T_DVB_CA
&& ca
) {
822 link
= media_create_intf_link(ca
, intf
,
823 MEDIA_LNK_FL_ENABLED
|
824 MEDIA_LNK_FL_IMMUTABLE
);
829 if (intf
->type
== MEDIA_INTF_T_DVB_FE
&& tuner
) {
830 link
= media_create_intf_link(tuner
, intf
,
831 MEDIA_LNK_FL_ENABLED
|
832 MEDIA_LNK_FL_IMMUTABLE
);
838 * Indirect link - let's not create yet, as we don't know how
839 * to handle indirect links, nor if this will
840 * actually be needed.
842 if (intf
->type
== MEDIA_INTF_T_DVB_DVR
&& demux
) {
843 link
= media_create_intf_link(demux
, intf
,
844 MEDIA_LNK_FL_ENABLED
|
845 MEDIA_LNK_FL_IMMUTABLE
);
850 if (intf
->type
== MEDIA_INTF_T_DVB_DVR
) {
851 ret
= dvb_create_io_intf_links(adap
, intf
, DVR_TSOUT
);
855 if (intf
->type
== MEDIA_INTF_T_DVB_DEMUX
) {
856 ret
= dvb_create_io_intf_links(adap
, intf
, DEMUX_TSOUT
);
863 EXPORT_SYMBOL_GPL(dvb_create_media_graph
);
866 static int dvbdev_check_free_adapter_num(int num
)
868 struct list_head
*entry
;
870 list_for_each(entry
, &dvb_adapter_list
) {
871 struct dvb_adapter
*adap
;
873 adap
= list_entry(entry
, struct dvb_adapter
, list_head
);
874 if (adap
->num
== num
)
880 static int dvbdev_get_free_adapter_num(void)
884 while (num
< DVB_MAX_ADAPTERS
) {
885 if (dvbdev_check_free_adapter_num(num
))
893 int dvb_register_adapter(struct dvb_adapter
*adap
, const char *name
,
894 struct module
*module
, struct device
*device
,
899 mutex_lock(&dvbdev_register_lock
);
901 for (i
= 0; i
< DVB_MAX_ADAPTERS
; ++i
) {
902 num
= adapter_nums
[i
];
903 if (num
>= 0 && num
< DVB_MAX_ADAPTERS
) {
904 /* use the one the driver asked for */
905 if (dvbdev_check_free_adapter_num(num
))
908 num
= dvbdev_get_free_adapter_num();
915 mutex_unlock(&dvbdev_register_lock
);
919 memset(adap
, 0, sizeof(struct dvb_adapter
));
920 INIT_LIST_HEAD(&adap
->device_list
);
922 pr_info("DVB: registering new adapter (%s)\n", name
);
926 adap
->module
= module
;
927 adap
->device
= device
;
928 adap
->mfe_shared
= 0;
929 adap
->mfe_dvbdev
= NULL
;
930 mutex_init(&adap
->mfe_lock
);
932 #ifdef CONFIG_MEDIA_CONTROLLER_DVB
933 mutex_init(&adap
->mdev_lock
);
936 list_add_tail(&adap
->list_head
, &dvb_adapter_list
);
938 mutex_unlock(&dvbdev_register_lock
);
942 EXPORT_SYMBOL(dvb_register_adapter
);
944 int dvb_unregister_adapter(struct dvb_adapter
*adap
)
946 mutex_lock(&dvbdev_register_lock
);
947 list_del(&adap
->list_head
);
948 mutex_unlock(&dvbdev_register_lock
);
951 EXPORT_SYMBOL(dvb_unregister_adapter
);
954 * if the miracle happens and "generic_usercopy()" is included into
955 * the kernel, then this can vanish. please don't make the mistake and
956 * define this as video_usercopy(). this will introduce a dependency
957 * to the v4l "videodev.o" module, which is unnecessary for some
958 * cards (ie. the budget dvb-cards don't need the v4l module...)
960 int dvb_usercopy(struct file
*file
,
961 unsigned int cmd
, unsigned long arg
,
962 int (*func
)(struct file
*file
,
963 unsigned int cmd
, void *arg
))
970 /* Copy arguments into temp kernel buffer */
971 switch (_IOC_DIR(cmd
)) {
974 * For this command, the pointer is actually an integer
979 case _IOC_READ
: /* some v4l ioctls are marked wrong ... */
981 case (_IOC_WRITE
| _IOC_READ
):
982 if (_IOC_SIZE(cmd
) <= sizeof(sbuf
)) {
985 /* too big to allocate from stack */
986 mbuf
= kmalloc(_IOC_SIZE(cmd
), GFP_KERNEL
);
993 if (copy_from_user(parg
, (void __user
*)arg
, _IOC_SIZE(cmd
)))
999 err
= func(file
, cmd
, parg
);
1000 if (err
== -ENOIOCTLCMD
)
1006 /* Copy results into user buffer */
1007 switch (_IOC_DIR(cmd
)) {
1009 case (_IOC_WRITE
| _IOC_READ
):
1010 if (copy_to_user((void __user
*)arg
, parg
, _IOC_SIZE(cmd
)))
1020 #if IS_ENABLED(CONFIG_I2C)
1021 struct i2c_client
*dvb_module_probe(const char *module_name
,
1023 struct i2c_adapter
*adap
,
1025 void *platform_data
)
1027 struct i2c_client
*client
;
1028 struct i2c_board_info
*board_info
;
1030 board_info
= kzalloc(sizeof(*board_info
), GFP_KERNEL
);
1035 strscpy(board_info
->type
, name
, I2C_NAME_SIZE
);
1037 strscpy(board_info
->type
, module_name
, I2C_NAME_SIZE
);
1039 board_info
->addr
= addr
;
1040 board_info
->platform_data
= platform_data
;
1041 request_module(module_name
);
1042 client
= i2c_new_client_device(adap
, board_info
);
1043 if (!i2c_client_has_driver(client
)) {
1048 if (!try_module_get(client
->dev
.driver
->owner
)) {
1049 i2c_unregister_device(client
);
1056 EXPORT_SYMBOL_GPL(dvb_module_probe
);
1058 void dvb_module_release(struct i2c_client
*client
)
1063 module_put(client
->dev
.driver
->owner
);
1064 i2c_unregister_device(client
);
1066 EXPORT_SYMBOL_GPL(dvb_module_release
);
1069 static int dvb_uevent(const struct device
*dev
, struct kobj_uevent_env
*env
)
1071 const struct dvb_device
*dvbdev
= dev_get_drvdata(dev
);
1073 add_uevent_var(env
, "DVB_ADAPTER_NUM=%d", dvbdev
->adapter
->num
);
1074 add_uevent_var(env
, "DVB_DEVICE_TYPE=%s", dnames
[dvbdev
->type
]);
1075 add_uevent_var(env
, "DVB_DEVICE_NUM=%d", dvbdev
->id
);
1079 static char *dvb_devnode(const struct device
*dev
, umode_t
*mode
)
1081 const struct dvb_device
*dvbdev
= dev_get_drvdata(dev
);
1083 return kasprintf(GFP_KERNEL
, "dvb/adapter%d/%s%d",
1084 dvbdev
->adapter
->num
, dnames
[dvbdev
->type
], dvbdev
->id
);
1087 static int __init
init_dvbdev(void)
1090 dev_t dev
= MKDEV(DVB_MAJOR
, 0);
1092 retval
= register_chrdev_region(dev
, MAX_DVB_MINORS
, "DVB");
1094 pr_err("dvb-core: unable to get major %d\n", DVB_MAJOR
);
1098 cdev_init(&dvb_device_cdev
, &dvb_device_fops
);
1099 retval
= cdev_add(&dvb_device_cdev
, dev
, MAX_DVB_MINORS
);
1101 pr_err("dvb-core: unable register character device\n");
1105 dvb_class
= class_create("dvb");
1106 if (IS_ERR(dvb_class
)) {
1107 retval
= PTR_ERR(dvb_class
);
1110 dvb_class
->dev_uevent
= dvb_uevent
;
1111 dvb_class
->devnode
= dvb_devnode
;
1115 cdev_del(&dvb_device_cdev
);
1116 unregister_chrdev_region(dev
, MAX_DVB_MINORS
);
1120 static void __exit
exit_dvbdev(void)
1122 struct dvbdevfops_node
*node
, *next
;
1124 class_destroy(dvb_class
);
1125 cdev_del(&dvb_device_cdev
);
1126 unregister_chrdev_region(MKDEV(DVB_MAJOR
, 0), MAX_DVB_MINORS
);
1128 list_for_each_entry_safe(node
, next
, &dvbdevfops_list
, list_head
) {
1129 list_del(&node
->list_head
);
1135 subsys_initcall(init_dvbdev
);
1136 module_exit(exit_dvbdev
);
1138 MODULE_DESCRIPTION("DVB Core Driver");
1139 MODULE_AUTHOR("Marcus Metzler, Ralph Metzler, Holger Waechtler");
1140 MODULE_LICENSE("GPL");