4 * Copyright (C) 2000 Ralph Metzler <ralph@convergence.de>
5 * & Marcus Metzler <marcus@convergence.de>
6 * for convergence integrated media GmbH
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public License
10 * as published by the Free Software Foundation; either version 2.1
11 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
20 #define pr_fmt(fmt) "dvbdev: " fmt
22 #include <linux/types.h>
23 #include <linux/errno.h>
24 #include <linux/string.h>
25 #include <linux/module.h>
26 #include <linux/kernel.h>
27 #include <linux/i2c.h>
28 #include <linux/init.h>
29 #include <linux/slab.h>
30 #include <linux/device.h>
32 #include <linux/cdev.h>
33 #include <linux/mutex.h>
34 #include <media/dvbdev.h>
36 /* Due to enum tuner_pad_index */
37 #include <media/tuner.h>
39 static DEFINE_MUTEX(dvbdev_mutex
);
40 static int dvbdev_debug
;
42 module_param(dvbdev_debug
, int, 0644);
43 MODULE_PARM_DESC(dvbdev_debug
, "Turn on/off device debugging (default:off).");
45 #define dprintk(fmt, arg...) do { \
47 printk(KERN_DEBUG pr_fmt("%s: " fmt), \
51 static LIST_HEAD(dvb_adapter_list
);
52 static DEFINE_MUTEX(dvbdev_register_lock
);
54 static const char * const dnames
[] = {
55 [DVB_DEVICE_VIDEO
] = "video",
56 [DVB_DEVICE_AUDIO
] = "audio",
57 [DVB_DEVICE_SEC
] = "sec",
58 [DVB_DEVICE_FRONTEND
] = "frontend",
59 [DVB_DEVICE_DEMUX
] = "demux",
60 [DVB_DEVICE_DVR
] = "dvr",
61 [DVB_DEVICE_CA
] = "ca",
62 [DVB_DEVICE_NET
] = "net",
63 [DVB_DEVICE_OSD
] = "osd"
66 #ifdef CONFIG_DVB_DYNAMIC_MINORS
67 #define MAX_DVB_MINORS 256
68 #define DVB_MAX_IDS MAX_DVB_MINORS
72 static const u8 minor_type
[] = {
73 [DVB_DEVICE_VIDEO
] = 0,
74 [DVB_DEVICE_AUDIO
] = 1,
76 [DVB_DEVICE_FRONTEND
] = 3,
77 [DVB_DEVICE_DEMUX
] = 4,
84 #define nums2minor(num, type, id) \
85 (((num) << 6) | ((id) << 4) | minor_type[type])
87 #define MAX_DVB_MINORS (DVB_MAX_ADAPTERS*64)
90 static struct class *dvb_class
;
92 static struct dvb_device
*dvb_minors
[MAX_DVB_MINORS
];
93 static DECLARE_RWSEM(minor_rwsem
);
95 static int dvb_device_open(struct inode
*inode
, struct file
*file
)
97 struct dvb_device
*dvbdev
;
99 mutex_lock(&dvbdev_mutex
);
100 down_read(&minor_rwsem
);
101 dvbdev
= dvb_minors
[iminor(inode
)];
103 if (dvbdev
&& dvbdev
->fops
) {
105 const struct file_operations
*new_fops
;
107 new_fops
= fops_get(dvbdev
->fops
);
110 file
->private_data
= dvbdev
;
111 replace_fops(file
, new_fops
);
112 if (file
->f_op
->open
)
113 err
= file
->f_op
->open(inode
, file
);
114 up_read(&minor_rwsem
);
115 mutex_unlock(&dvbdev_mutex
);
119 up_read(&minor_rwsem
);
120 mutex_unlock(&dvbdev_mutex
);
125 static const struct file_operations dvb_device_fops
=
127 .owner
= THIS_MODULE
,
128 .open
= dvb_device_open
,
129 .llseek
= noop_llseek
,
132 static struct cdev dvb_device_cdev
;
134 int dvb_generic_open(struct inode
*inode
, struct file
*file
)
136 struct dvb_device
*dvbdev
= file
->private_data
;
144 if ((file
->f_flags
& O_ACCMODE
) == O_RDONLY
) {
145 if (!dvbdev
->readers
)
149 if (!dvbdev
->writers
)
157 EXPORT_SYMBOL(dvb_generic_open
);
160 int dvb_generic_release(struct inode
*inode
, struct file
*file
)
162 struct dvb_device
*dvbdev
= file
->private_data
;
167 if ((file
->f_flags
& O_ACCMODE
) == O_RDONLY
) {
176 EXPORT_SYMBOL(dvb_generic_release
);
179 long dvb_generic_ioctl(struct file
*file
,
180 unsigned int cmd
, unsigned long arg
)
182 struct dvb_device
*dvbdev
= file
->private_data
;
187 if (!dvbdev
->kernel_ioctl
)
190 return dvb_usercopy(file
, cmd
, arg
, dvbdev
->kernel_ioctl
);
192 EXPORT_SYMBOL(dvb_generic_ioctl
);
195 static int dvbdev_get_free_id (struct dvb_adapter
*adap
, int type
)
199 while (id
< DVB_MAX_IDS
) {
200 struct dvb_device
*dev
;
201 list_for_each_entry(dev
, &adap
->device_list
, list_head
)
202 if (dev
->type
== type
&& dev
->id
== id
)
211 static void dvb_media_device_free(struct dvb_device
*dvbdev
)
213 #if defined(CONFIG_MEDIA_CONTROLLER_DVB)
214 if (dvbdev
->entity
) {
215 media_device_unregister_entity(dvbdev
->entity
);
216 kfree(dvbdev
->entity
);
218 dvbdev
->entity
= NULL
;
222 if (dvbdev
->tsout_entity
) {
225 for (i
= 0; i
< dvbdev
->tsout_num_entities
; i
++) {
226 media_device_unregister_entity(&dvbdev
->tsout_entity
[i
]);
227 kfree(dvbdev
->tsout_entity
[i
].name
);
229 kfree(dvbdev
->tsout_entity
);
230 kfree(dvbdev
->tsout_pads
);
231 dvbdev
->tsout_entity
= NULL
;
232 dvbdev
->tsout_pads
= NULL
;
234 dvbdev
->tsout_num_entities
= 0;
237 if (dvbdev
->intf_devnode
) {
238 media_devnode_remove(dvbdev
->intf_devnode
);
239 dvbdev
->intf_devnode
= NULL
;
242 if (dvbdev
->adapter
->conn
) {
243 media_device_unregister_entity(dvbdev
->adapter
->conn
);
244 dvbdev
->adapter
->conn
= NULL
;
245 kfree(dvbdev
->adapter
->conn_pads
);
246 dvbdev
->adapter
->conn_pads
= NULL
;
251 #if defined(CONFIG_MEDIA_CONTROLLER_DVB)
252 static int dvb_create_tsout_entity(struct dvb_device
*dvbdev
,
253 const char *name
, int npads
)
257 dvbdev
->tsout_pads
= kcalloc(npads
, sizeof(*dvbdev
->tsout_pads
),
259 if (!dvbdev
->tsout_pads
)
262 dvbdev
->tsout_entity
= kcalloc(npads
, sizeof(*dvbdev
->tsout_entity
),
264 if (!dvbdev
->tsout_entity
)
267 dvbdev
->tsout_num_entities
= npads
;
269 for (i
= 0; i
< npads
; i
++) {
270 struct media_pad
*pads
= &dvbdev
->tsout_pads
[i
];
271 struct media_entity
*entity
= &dvbdev
->tsout_entity
[i
];
273 entity
->name
= kasprintf(GFP_KERNEL
, "%s #%d", name
, i
);
277 entity
->function
= MEDIA_ENT_F_IO_DTV
;
278 pads
->flags
= MEDIA_PAD_FL_SINK
;
280 ret
= media_entity_pads_init(entity
, 1, pads
);
284 ret
= media_device_register_entity(dvbdev
->adapter
->mdev
,
292 #define DEMUX_TSOUT "demux-tsout"
293 #define DVR_TSOUT "dvr-tsout"
295 static int dvb_create_media_entity(struct dvb_device
*dvbdev
,
296 int type
, int demux_sink_pads
)
301 case DVB_DEVICE_FRONTEND
:
305 ret
= dvb_create_tsout_entity(dvbdev
, DVR_TSOUT
,
308 case DVB_DEVICE_DEMUX
:
309 npads
= 1 + demux_sink_pads
;
310 ret
= dvb_create_tsout_entity(dvbdev
, DEMUX_TSOUT
,
320 * We should be creating entities for the MPE/ULE
321 * decapsulation hardware (or software implementation).
323 * However, the number of for the MPE/ULE decaps may not be
324 * fixed. As we don't have yet dynamic support for PADs at
325 * the Media Controller, let's not create the decap
333 dvbdev
->entity
= kzalloc(sizeof(*dvbdev
->entity
), GFP_KERNEL
);
337 dvbdev
->entity
->name
= dvbdev
->name
;
340 dvbdev
->pads
= kcalloc(npads
, sizeof(*dvbdev
->pads
),
347 case DVB_DEVICE_FRONTEND
:
348 dvbdev
->entity
->function
= MEDIA_ENT_F_DTV_DEMOD
;
349 dvbdev
->pads
[0].flags
= MEDIA_PAD_FL_SINK
;
350 dvbdev
->pads
[1].flags
= MEDIA_PAD_FL_SOURCE
;
352 case DVB_DEVICE_DEMUX
:
353 dvbdev
->entity
->function
= MEDIA_ENT_F_TS_DEMUX
;
354 dvbdev
->pads
[0].flags
= MEDIA_PAD_FL_SINK
;
355 for (i
= 1; i
< npads
; i
++)
356 dvbdev
->pads
[i
].flags
= MEDIA_PAD_FL_SOURCE
;
359 dvbdev
->entity
->function
= MEDIA_ENT_F_DTV_CA
;
360 dvbdev
->pads
[0].flags
= MEDIA_PAD_FL_SINK
;
361 dvbdev
->pads
[1].flags
= MEDIA_PAD_FL_SOURCE
;
364 /* Should never happen, as the first switch prevents it */
365 kfree(dvbdev
->entity
);
367 dvbdev
->entity
= NULL
;
373 ret
= media_entity_pads_init(dvbdev
->entity
, npads
, dvbdev
->pads
);
377 ret
= media_device_register_entity(dvbdev
->adapter
->mdev
,
382 pr_info("%s: media entity '%s' registered.\n",
383 __func__
, dvbdev
->entity
->name
);
389 static int dvb_register_media_device(struct dvb_device
*dvbdev
,
391 unsigned demux_sink_pads
)
393 #if defined(CONFIG_MEDIA_CONTROLLER_DVB)
394 struct media_link
*link
;
398 if (!dvbdev
->adapter
->mdev
)
401 ret
= dvb_create_media_entity(dvbdev
, type
, demux_sink_pads
);
406 case DVB_DEVICE_FRONTEND
:
407 intf_type
= MEDIA_INTF_T_DVB_FE
;
409 case DVB_DEVICE_DEMUX
:
410 intf_type
= MEDIA_INTF_T_DVB_DEMUX
;
413 intf_type
= MEDIA_INTF_T_DVB_DVR
;
416 intf_type
= MEDIA_INTF_T_DVB_CA
;
419 intf_type
= MEDIA_INTF_T_DVB_NET
;
425 dvbdev
->intf_devnode
= media_devnode_create(dvbdev
->adapter
->mdev
,
429 if (!dvbdev
->intf_devnode
)
433 * Create the "obvious" link, e. g. the ones that represent
434 * a direct association between an interface and an entity.
435 * Other links should be created elsewhere, like:
436 * DVB FE intf -> tuner
437 * DVB demux intf -> dvr
443 link
= media_create_intf_link(dvbdev
->entity
,
444 &dvbdev
->intf_devnode
->intf
,
445 MEDIA_LNK_FL_ENABLED
|
446 MEDIA_LNK_FL_IMMUTABLE
);
453 int dvb_register_device(struct dvb_adapter
*adap
, struct dvb_device
**pdvbdev
,
454 const struct dvb_device
*template, void *priv
,
455 enum dvb_device_type type
, int demux_sink_pads
)
457 struct dvb_device
*dvbdev
;
458 struct file_operations
*dvbdevfops
;
459 struct device
*clsdev
;
463 mutex_lock(&dvbdev_register_lock
);
465 if ((id
= dvbdev_get_free_id (adap
, type
)) < 0){
466 mutex_unlock(&dvbdev_register_lock
);
468 pr_err("%s: couldn't find free device id\n", __func__
);
472 *pdvbdev
= dvbdev
= kzalloc(sizeof(*dvbdev
), GFP_KERNEL
);
475 mutex_unlock(&dvbdev_register_lock
);
479 dvbdevfops
= kzalloc(sizeof(struct file_operations
), GFP_KERNEL
);
483 mutex_unlock(&dvbdev_register_lock
);
487 memcpy(dvbdev
, template, sizeof(struct dvb_device
));
490 dvbdev
->adapter
= adap
;
492 dvbdev
->fops
= dvbdevfops
;
493 init_waitqueue_head (&dvbdev
->wait_queue
);
495 memcpy(dvbdevfops
, template->fops
, sizeof(struct file_operations
));
496 dvbdevfops
->owner
= adap
->module
;
498 list_add_tail (&dvbdev
->list_head
, &adap
->device_list
);
500 down_write(&minor_rwsem
);
501 #ifdef CONFIG_DVB_DYNAMIC_MINORS
502 for (minor
= 0; minor
< MAX_DVB_MINORS
; minor
++)
503 if (dvb_minors
[minor
] == NULL
)
506 if (minor
== MAX_DVB_MINORS
) {
509 up_write(&minor_rwsem
);
510 mutex_unlock(&dvbdev_register_lock
);
514 minor
= nums2minor(adap
->num
, type
, id
);
517 dvbdev
->minor
= minor
;
518 dvb_minors
[minor
] = dvbdev
;
519 up_write(&minor_rwsem
);
521 ret
= dvb_register_media_device(dvbdev
, type
, minor
, demux_sink_pads
);
523 pr_err("%s: dvb_register_media_device failed to create the mediagraph\n",
526 dvb_media_device_free(dvbdev
);
529 up_write(&minor_rwsem
);
530 mutex_unlock(&dvbdev_register_lock
);
534 mutex_unlock(&dvbdev_register_lock
);
536 clsdev
= device_create(dvb_class
, adap
->device
,
537 MKDEV(DVB_MAJOR
, minor
),
538 dvbdev
, "dvb%d.%s%d", adap
->num
, dnames
[type
], id
);
539 if (IS_ERR(clsdev
)) {
540 pr_err("%s: failed to create device dvb%d.%s%d (%ld)\n",
541 __func__
, adap
->num
, dnames
[type
], id
, PTR_ERR(clsdev
));
542 return PTR_ERR(clsdev
);
544 dprintk("DVB: register adapter%d/%s%d @ minor: %i (0x%02x)\n",
545 adap
->num
, dnames
[type
], id
, minor
, minor
);
549 EXPORT_SYMBOL(dvb_register_device
);
552 void dvb_remove_device(struct dvb_device
*dvbdev
)
557 down_write(&minor_rwsem
);
558 dvb_minors
[dvbdev
->minor
] = NULL
;
559 up_write(&minor_rwsem
);
561 dvb_media_device_free(dvbdev
);
563 device_destroy(dvb_class
, MKDEV(DVB_MAJOR
, dvbdev
->minor
));
565 list_del (&dvbdev
->list_head
);
567 EXPORT_SYMBOL(dvb_remove_device
);
570 void dvb_free_device(struct dvb_device
*dvbdev
)
575 kfree (dvbdev
->fops
);
578 EXPORT_SYMBOL(dvb_free_device
);
581 void dvb_unregister_device(struct dvb_device
*dvbdev
)
583 dvb_remove_device(dvbdev
);
584 dvb_free_device(dvbdev
);
586 EXPORT_SYMBOL(dvb_unregister_device
);
589 #ifdef CONFIG_MEDIA_CONTROLLER_DVB
591 static int dvb_create_io_intf_links(struct dvb_adapter
*adap
,
592 struct media_interface
*intf
,
595 struct media_device
*mdev
= adap
->mdev
;
596 struct media_entity
*entity
;
597 struct media_link
*link
;
599 media_device_for_each_entity(entity
, mdev
) {
600 if (entity
->function
== MEDIA_ENT_F_IO_DTV
) {
601 if (strncmp(entity
->name
, name
, strlen(name
)))
603 link
= media_create_intf_link(entity
, intf
,
604 MEDIA_LNK_FL_ENABLED
|
605 MEDIA_LNK_FL_IMMUTABLE
);
613 int dvb_create_media_graph(struct dvb_adapter
*adap
,
614 bool create_rf_connector
)
616 struct media_device
*mdev
= adap
->mdev
;
617 struct media_entity
*entity
, *tuner
= NULL
, *demod
= NULL
, *conn
;
618 struct media_entity
*demux
= NULL
, *ca
= NULL
;
619 struct media_link
*link
;
620 struct media_interface
*intf
;
621 unsigned demux_pad
= 0;
622 unsigned dvr_pad
= 0;
623 unsigned ntuner
= 0, ndemod
= 0;
625 static const char *connector_name
= "Television";
630 media_device_for_each_entity(entity
, mdev
) {
631 switch (entity
->function
) {
632 case MEDIA_ENT_F_TUNER
:
636 case MEDIA_ENT_F_DTV_DEMOD
:
640 case MEDIA_ENT_F_TS_DEMUX
:
643 case MEDIA_ENT_F_DTV_CA
:
650 * Prepare to signalize to media_create_pad_links() that multiple
651 * entities of the same type exists and a 1:n or n:1 links need to be
653 * NOTE: if both tuner and demod have multiple instances, it is up
654 * to the caller driver to create such links.
661 if (create_rf_connector
) {
662 conn
= kzalloc(sizeof(*conn
), GFP_KERNEL
);
667 adap
->conn_pads
= kzalloc(sizeof(*adap
->conn_pads
), GFP_KERNEL
);
668 if (!adap
->conn_pads
)
671 conn
->flags
= MEDIA_ENT_FL_CONNECTOR
;
672 conn
->function
= MEDIA_ENT_F_CONN_RF
;
673 conn
->name
= connector_name
;
674 adap
->conn_pads
->flags
= MEDIA_PAD_FL_SOURCE
;
676 ret
= media_entity_pads_init(conn
, 1, adap
->conn_pads
);
680 ret
= media_device_register_entity(mdev
, conn
);
685 ret
= media_create_pad_links(mdev
,
688 MEDIA_ENT_F_DTV_DEMOD
,
690 MEDIA_LNK_FL_ENABLED
,
693 ret
= media_create_pad_links(mdev
,
697 tuner
, TUNER_PAD_RF_INPUT
,
698 MEDIA_LNK_FL_ENABLED
,
704 if (ntuner
&& ndemod
) {
705 ret
= media_create_pad_links(mdev
,
707 tuner
, TUNER_PAD_OUTPUT
,
708 MEDIA_ENT_F_DTV_DEMOD
,
709 demod
, 0, MEDIA_LNK_FL_ENABLED
,
715 if (ndemod
&& demux
) {
716 ret
= media_create_pad_links(mdev
,
717 MEDIA_ENT_F_DTV_DEMOD
,
719 MEDIA_ENT_F_TS_DEMUX
,
720 demux
, 0, MEDIA_LNK_FL_ENABLED
,
726 ret
= media_create_pad_link(demux
, 1, ca
,
727 0, MEDIA_LNK_FL_ENABLED
);
732 /* Create demux links for each ringbuffer/pad */
734 media_device_for_each_entity(entity
, mdev
) {
735 if (entity
->function
== MEDIA_ENT_F_IO_DTV
) {
736 if (!strncmp(entity
->name
, DVR_TSOUT
,
737 strlen(DVR_TSOUT
))) {
738 ret
= media_create_pad_link(demux
,
744 if (!strncmp(entity
->name
, DEMUX_TSOUT
,
745 strlen(DEMUX_TSOUT
))) {
746 ret
= media_create_pad_link(demux
,
756 /* Create interface links for FE->tuner, DVR->demux and CA->ca */
757 media_device_for_each_intf(intf
, mdev
) {
758 if (intf
->type
== MEDIA_INTF_T_DVB_CA
&& ca
) {
759 link
= media_create_intf_link(ca
, intf
,
760 MEDIA_LNK_FL_ENABLED
|
761 MEDIA_LNK_FL_IMMUTABLE
);
766 if (intf
->type
== MEDIA_INTF_T_DVB_FE
&& tuner
) {
767 link
= media_create_intf_link(tuner
, intf
,
768 MEDIA_LNK_FL_ENABLED
|
769 MEDIA_LNK_FL_IMMUTABLE
);
775 * Indirect link - let's not create yet, as we don't know how
776 * to handle indirect links, nor if this will
777 * actually be needed.
779 if (intf
->type
== MEDIA_INTF_T_DVB_DVR
&& demux
) {
780 link
= media_create_intf_link(demux
, intf
,
781 MEDIA_LNK_FL_ENABLED
|
782 MEDIA_LNK_FL_IMMUTABLE
);
787 if (intf
->type
== MEDIA_INTF_T_DVB_DVR
) {
788 ret
= dvb_create_io_intf_links(adap
, intf
, DVR_TSOUT
);
792 if (intf
->type
== MEDIA_INTF_T_DVB_DEMUX
) {
793 ret
= dvb_create_io_intf_links(adap
, intf
, DEMUX_TSOUT
);
800 EXPORT_SYMBOL_GPL(dvb_create_media_graph
);
803 static int dvbdev_check_free_adapter_num(int num
)
805 struct list_head
*entry
;
806 list_for_each(entry
, &dvb_adapter_list
) {
807 struct dvb_adapter
*adap
;
808 adap
= list_entry(entry
, struct dvb_adapter
, list_head
);
809 if (adap
->num
== num
)
815 static int dvbdev_get_free_adapter_num (void)
819 while (num
< DVB_MAX_ADAPTERS
) {
820 if (dvbdev_check_free_adapter_num(num
))
829 int dvb_register_adapter(struct dvb_adapter
*adap
, const char *name
,
830 struct module
*module
, struct device
*device
,
835 mutex_lock(&dvbdev_register_lock
);
837 for (i
= 0; i
< DVB_MAX_ADAPTERS
; ++i
) {
838 num
= adapter_nums
[i
];
839 if (num
>= 0 && num
< DVB_MAX_ADAPTERS
) {
840 /* use the one the driver asked for */
841 if (dvbdev_check_free_adapter_num(num
))
844 num
= dvbdev_get_free_adapter_num();
851 mutex_unlock(&dvbdev_register_lock
);
855 memset (adap
, 0, sizeof(struct dvb_adapter
));
856 INIT_LIST_HEAD (&adap
->device_list
);
858 pr_info("DVB: registering new adapter (%s)\n", name
);
862 adap
->module
= module
;
863 adap
->device
= device
;
864 adap
->mfe_shared
= 0;
865 adap
->mfe_dvbdev
= NULL
;
866 mutex_init (&adap
->mfe_lock
);
868 #ifdef CONFIG_MEDIA_CONTROLLER_DVB
869 mutex_init(&adap
->mdev_lock
);
872 list_add_tail (&adap
->list_head
, &dvb_adapter_list
);
874 mutex_unlock(&dvbdev_register_lock
);
878 EXPORT_SYMBOL(dvb_register_adapter
);
881 int dvb_unregister_adapter(struct dvb_adapter
*adap
)
883 mutex_lock(&dvbdev_register_lock
);
884 list_del (&adap
->list_head
);
885 mutex_unlock(&dvbdev_register_lock
);
888 EXPORT_SYMBOL(dvb_unregister_adapter
);
890 /* if the miracle happens and "generic_usercopy()" is included into
891 the kernel, then this can vanish. please don't make the mistake and
892 define this as video_usercopy(). this will introduce a dependecy
893 to the v4l "videodev.o" module, which is unnecessary for some
894 cards (ie. the budget dvb-cards don't need the v4l module...) */
895 int dvb_usercopy(struct file
*file
,
896 unsigned int cmd
, unsigned long arg
,
897 int (*func
)(struct file
*file
,
898 unsigned int cmd
, void *arg
))
905 /* Copy arguments into temp kernel buffer */
906 switch (_IOC_DIR(cmd
)) {
909 * For this command, the pointer is actually an integer
914 case _IOC_READ
: /* some v4l ioctls are marked wrong ... */
916 case (_IOC_WRITE
| _IOC_READ
):
917 if (_IOC_SIZE(cmd
) <= sizeof(sbuf
)) {
920 /* too big to allocate from stack */
921 mbuf
= kmalloc(_IOC_SIZE(cmd
), GFP_KERNEL
);
928 if (copy_from_user(parg
, (void __user
*)arg
, _IOC_SIZE(cmd
)))
934 if ((err
= func(file
, cmd
, parg
)) == -ENOIOCTLCMD
)
940 /* Copy results into user buffer */
941 switch (_IOC_DIR(cmd
))
944 case (_IOC_WRITE
| _IOC_READ
):
945 if (copy_to_user((void __user
*)arg
, parg
, _IOC_SIZE(cmd
)))
955 #if IS_ENABLED(CONFIG_I2C)
956 struct i2c_client
*dvb_module_probe(const char *module_name
,
958 struct i2c_adapter
*adap
,
962 struct i2c_client
*client
;
963 struct i2c_board_info
*board_info
;
965 board_info
= kzalloc(sizeof(*board_info
), GFP_KERNEL
);
970 strlcpy(board_info
->type
, name
, I2C_NAME_SIZE
);
972 strlcpy(board_info
->type
, module_name
, I2C_NAME_SIZE
);
974 board_info
->addr
= addr
;
975 board_info
->platform_data
= platform_data
;
976 request_module(module_name
);
977 client
= i2c_new_device(adap
, board_info
);
978 if (client
== NULL
|| client
->dev
.driver
== NULL
) {
983 if (!try_module_get(client
->dev
.driver
->owner
)) {
984 i2c_unregister_device(client
);
991 EXPORT_SYMBOL_GPL(dvb_module_probe
);
993 void dvb_module_release(struct i2c_client
*client
)
998 module_put(client
->dev
.driver
->owner
);
999 i2c_unregister_device(client
);
1001 EXPORT_SYMBOL_GPL(dvb_module_release
);
1004 static int dvb_uevent(struct device
*dev
, struct kobj_uevent_env
*env
)
1006 struct dvb_device
*dvbdev
= dev_get_drvdata(dev
);
1008 add_uevent_var(env
, "DVB_ADAPTER_NUM=%d", dvbdev
->adapter
->num
);
1009 add_uevent_var(env
, "DVB_DEVICE_TYPE=%s", dnames
[dvbdev
->type
]);
1010 add_uevent_var(env
, "DVB_DEVICE_NUM=%d", dvbdev
->id
);
1014 static char *dvb_devnode(struct device
*dev
, umode_t
*mode
)
1016 struct dvb_device
*dvbdev
= dev_get_drvdata(dev
);
1018 return kasprintf(GFP_KERNEL
, "dvb/adapter%d/%s%d",
1019 dvbdev
->adapter
->num
, dnames
[dvbdev
->type
], dvbdev
->id
);
1023 static int __init
init_dvbdev(void)
1026 dev_t dev
= MKDEV(DVB_MAJOR
, 0);
1028 if ((retval
= register_chrdev_region(dev
, MAX_DVB_MINORS
, "DVB")) != 0) {
1029 pr_err("dvb-core: unable to get major %d\n", DVB_MAJOR
);
1033 cdev_init(&dvb_device_cdev
, &dvb_device_fops
);
1034 if ((retval
= cdev_add(&dvb_device_cdev
, dev
, MAX_DVB_MINORS
)) != 0) {
1035 pr_err("dvb-core: unable register character device\n");
1039 dvb_class
= class_create(THIS_MODULE
, "dvb");
1040 if (IS_ERR(dvb_class
)) {
1041 retval
= PTR_ERR(dvb_class
);
1044 dvb_class
->dev_uevent
= dvb_uevent
;
1045 dvb_class
->devnode
= dvb_devnode
;
1049 cdev_del(&dvb_device_cdev
);
1050 unregister_chrdev_region(dev
, MAX_DVB_MINORS
);
1055 static void __exit
exit_dvbdev(void)
1057 class_destroy(dvb_class
);
1058 cdev_del(&dvb_device_cdev
);
1059 unregister_chrdev_region(MKDEV(DVB_MAJOR
, 0), MAX_DVB_MINORS
);
1062 subsys_initcall(init_dvbdev
);
1063 module_exit(exit_dvbdev
);
1065 MODULE_DESCRIPTION("DVB Core Driver");
1066 MODULE_AUTHOR("Marcus Metzler, Ralph Metzler, Holger Waechtler");
1067 MODULE_LICENSE("GPL");