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/init.h>
28 #include <linux/slab.h>
29 #include <linux/device.h>
31 #include <linux/cdev.h>
32 #include <linux/mutex.h>
33 #include <media/dvbdev.h>
35 /* Due to enum tuner_pad_index */
36 #include <media/tuner.h>
38 static DEFINE_MUTEX(dvbdev_mutex
);
39 static int dvbdev_debug
;
41 module_param(dvbdev_debug
, int, 0644);
42 MODULE_PARM_DESC(dvbdev_debug
, "Turn on/off device debugging (default:off).");
44 #define dprintk(fmt, arg...) do { \
46 printk(KERN_DEBUG pr_fmt("%s: " fmt), \
50 static LIST_HEAD(dvb_adapter_list
);
51 static DEFINE_MUTEX(dvbdev_register_lock
);
53 static const char * const dnames
[] = {
54 [DVB_DEVICE_VIDEO
] = "video",
55 [DVB_DEVICE_AUDIO
] = "audio",
56 [DVB_DEVICE_SEC
] = "sec",
57 [DVB_DEVICE_FRONTEND
] = "frontend",
58 [DVB_DEVICE_DEMUX
] = "demux",
59 [DVB_DEVICE_DVR
] = "dvr",
60 [DVB_DEVICE_CA
] = "ca",
61 [DVB_DEVICE_NET
] = "net",
62 [DVB_DEVICE_OSD
] = "osd"
65 #ifdef CONFIG_DVB_DYNAMIC_MINORS
66 #define MAX_DVB_MINORS 256
67 #define DVB_MAX_IDS MAX_DVB_MINORS
71 static const u8 minor_type
[] = {
72 [DVB_DEVICE_VIDEO
] = 0,
73 [DVB_DEVICE_AUDIO
] = 1,
75 [DVB_DEVICE_FRONTEND
] = 3,
76 [DVB_DEVICE_DEMUX
] = 4,
83 #define nums2minor(num, type, id) \
84 (((num) << 6) | ((id) << 4) | minor_type[type])
86 #define MAX_DVB_MINORS (DVB_MAX_ADAPTERS*64)
89 static struct class *dvb_class
;
91 static struct dvb_device
*dvb_minors
[MAX_DVB_MINORS
];
92 static DECLARE_RWSEM(minor_rwsem
);
94 static int dvb_device_open(struct inode
*inode
, struct file
*file
)
96 struct dvb_device
*dvbdev
;
98 mutex_lock(&dvbdev_mutex
);
99 down_read(&minor_rwsem
);
100 dvbdev
= dvb_minors
[iminor(inode
)];
102 if (dvbdev
&& dvbdev
->fops
) {
104 const struct file_operations
*new_fops
;
106 new_fops
= fops_get(dvbdev
->fops
);
109 file
->private_data
= dvbdev
;
110 replace_fops(file
, new_fops
);
111 if (file
->f_op
->open
)
112 err
= file
->f_op
->open(inode
, file
);
113 up_read(&minor_rwsem
);
114 mutex_unlock(&dvbdev_mutex
);
118 up_read(&minor_rwsem
);
119 mutex_unlock(&dvbdev_mutex
);
124 static const struct file_operations dvb_device_fops
=
126 .owner
= THIS_MODULE
,
127 .open
= dvb_device_open
,
128 .llseek
= noop_llseek
,
131 static struct cdev dvb_device_cdev
;
133 int dvb_generic_open(struct inode
*inode
, struct file
*file
)
135 struct dvb_device
*dvbdev
= file
->private_data
;
143 if ((file
->f_flags
& O_ACCMODE
) == O_RDONLY
) {
144 if (!dvbdev
->readers
)
148 if (!dvbdev
->writers
)
156 EXPORT_SYMBOL(dvb_generic_open
);
159 int dvb_generic_release(struct inode
*inode
, struct file
*file
)
161 struct dvb_device
*dvbdev
= file
->private_data
;
166 if ((file
->f_flags
& O_ACCMODE
) == O_RDONLY
) {
175 EXPORT_SYMBOL(dvb_generic_release
);
178 long dvb_generic_ioctl(struct file
*file
,
179 unsigned int cmd
, unsigned long arg
)
181 struct dvb_device
*dvbdev
= file
->private_data
;
186 if (!dvbdev
->kernel_ioctl
)
189 return dvb_usercopy(file
, cmd
, arg
, dvbdev
->kernel_ioctl
);
191 EXPORT_SYMBOL(dvb_generic_ioctl
);
194 static int dvbdev_get_free_id (struct dvb_adapter
*adap
, int type
)
198 while (id
< DVB_MAX_IDS
) {
199 struct dvb_device
*dev
;
200 list_for_each_entry(dev
, &adap
->device_list
, list_head
)
201 if (dev
->type
== type
&& dev
->id
== id
)
210 static void dvb_media_device_free(struct dvb_device
*dvbdev
)
212 #if defined(CONFIG_MEDIA_CONTROLLER_DVB)
213 if (dvbdev
->entity
) {
214 media_device_unregister_entity(dvbdev
->entity
);
215 kfree(dvbdev
->entity
);
217 dvbdev
->entity
= NULL
;
221 if (dvbdev
->tsout_entity
) {
224 for (i
= 0; i
< dvbdev
->tsout_num_entities
; i
++) {
225 media_device_unregister_entity(&dvbdev
->tsout_entity
[i
]);
226 kfree(dvbdev
->tsout_entity
[i
].name
);
228 kfree(dvbdev
->tsout_entity
);
229 kfree(dvbdev
->tsout_pads
);
230 dvbdev
->tsout_entity
= NULL
;
231 dvbdev
->tsout_pads
= NULL
;
233 dvbdev
->tsout_num_entities
= 0;
236 if (dvbdev
->intf_devnode
) {
237 media_devnode_remove(dvbdev
->intf_devnode
);
238 dvbdev
->intf_devnode
= NULL
;
241 if (dvbdev
->adapter
->conn
) {
242 media_device_unregister_entity(dvbdev
->adapter
->conn
);
243 dvbdev
->adapter
->conn
= NULL
;
244 kfree(dvbdev
->adapter
->conn_pads
);
245 dvbdev
->adapter
->conn_pads
= NULL
;
250 #if defined(CONFIG_MEDIA_CONTROLLER_DVB)
251 static int dvb_create_tsout_entity(struct dvb_device
*dvbdev
,
252 const char *name
, int npads
)
256 dvbdev
->tsout_pads
= kcalloc(npads
, sizeof(*dvbdev
->tsout_pads
),
258 if (!dvbdev
->tsout_pads
)
261 dvbdev
->tsout_entity
= kcalloc(npads
, sizeof(*dvbdev
->tsout_entity
),
263 if (!dvbdev
->tsout_entity
)
266 dvbdev
->tsout_num_entities
= npads
;
268 for (i
= 0; i
< npads
; i
++) {
269 struct media_pad
*pads
= &dvbdev
->tsout_pads
[i
];
270 struct media_entity
*entity
= &dvbdev
->tsout_entity
[i
];
272 entity
->name
= kasprintf(GFP_KERNEL
, "%s #%d", name
, i
);
276 entity
->function
= MEDIA_ENT_F_IO_DTV
;
277 pads
->flags
= MEDIA_PAD_FL_SINK
;
279 ret
= media_entity_pads_init(entity
, 1, pads
);
283 ret
= media_device_register_entity(dvbdev
->adapter
->mdev
,
291 #define DEMUX_TSOUT "demux-tsout"
292 #define DVR_TSOUT "dvr-tsout"
294 static int dvb_create_media_entity(struct dvb_device
*dvbdev
,
295 int type
, int demux_sink_pads
)
300 case DVB_DEVICE_FRONTEND
:
304 ret
= dvb_create_tsout_entity(dvbdev
, DVR_TSOUT
,
307 case DVB_DEVICE_DEMUX
:
308 npads
= 1 + demux_sink_pads
;
309 ret
= dvb_create_tsout_entity(dvbdev
, DEMUX_TSOUT
,
319 * We should be creating entities for the MPE/ULE
320 * decapsulation hardware (or software implementation).
322 * However, the number of for the MPE/ULE decaps may not be
323 * fixed. As we don't have yet dynamic support for PADs at
324 * the Media Controller, let's not create the decap
332 dvbdev
->entity
= kzalloc(sizeof(*dvbdev
->entity
), GFP_KERNEL
);
336 dvbdev
->entity
->name
= dvbdev
->name
;
339 dvbdev
->pads
= kcalloc(npads
, sizeof(*dvbdev
->pads
),
346 case DVB_DEVICE_FRONTEND
:
347 dvbdev
->entity
->function
= MEDIA_ENT_F_DTV_DEMOD
;
348 dvbdev
->pads
[0].flags
= MEDIA_PAD_FL_SINK
;
349 dvbdev
->pads
[1].flags
= MEDIA_PAD_FL_SOURCE
;
351 case DVB_DEVICE_DEMUX
:
352 dvbdev
->entity
->function
= MEDIA_ENT_F_TS_DEMUX
;
353 dvbdev
->pads
[0].flags
= MEDIA_PAD_FL_SINK
;
354 for (i
= 1; i
< npads
; i
++)
355 dvbdev
->pads
[i
].flags
= MEDIA_PAD_FL_SOURCE
;
358 dvbdev
->entity
->function
= MEDIA_ENT_F_DTV_CA
;
359 dvbdev
->pads
[0].flags
= MEDIA_PAD_FL_SINK
;
360 dvbdev
->pads
[1].flags
= MEDIA_PAD_FL_SOURCE
;
363 /* Should never happen, as the first switch prevents it */
364 kfree(dvbdev
->entity
);
366 dvbdev
->entity
= NULL
;
372 ret
= media_entity_pads_init(dvbdev
->entity
, npads
, dvbdev
->pads
);
376 ret
= media_device_register_entity(dvbdev
->adapter
->mdev
,
381 pr_info("%s: media entity '%s' registered.\n",
382 __func__
, dvbdev
->entity
->name
);
388 static int dvb_register_media_device(struct dvb_device
*dvbdev
,
390 unsigned demux_sink_pads
)
392 #if defined(CONFIG_MEDIA_CONTROLLER_DVB)
393 struct media_link
*link
;
397 if (!dvbdev
->adapter
->mdev
)
400 ret
= dvb_create_media_entity(dvbdev
, type
, demux_sink_pads
);
405 case DVB_DEVICE_FRONTEND
:
406 intf_type
= MEDIA_INTF_T_DVB_FE
;
408 case DVB_DEVICE_DEMUX
:
409 intf_type
= MEDIA_INTF_T_DVB_DEMUX
;
412 intf_type
= MEDIA_INTF_T_DVB_DVR
;
415 intf_type
= MEDIA_INTF_T_DVB_CA
;
418 intf_type
= MEDIA_INTF_T_DVB_NET
;
424 dvbdev
->intf_devnode
= media_devnode_create(dvbdev
->adapter
->mdev
,
428 if (!dvbdev
->intf_devnode
)
432 * Create the "obvious" link, e. g. the ones that represent
433 * a direct association between an interface and an entity.
434 * Other links should be created elsewhere, like:
435 * DVB FE intf -> tuner
436 * DVB demux intf -> dvr
442 link
= media_create_intf_link(dvbdev
->entity
, &dvbdev
->intf_devnode
->intf
,
443 MEDIA_LNK_FL_ENABLED
);
450 int dvb_register_device(struct dvb_adapter
*adap
, struct dvb_device
**pdvbdev
,
451 const struct dvb_device
*template, void *priv
,
452 enum dvb_device_type type
, int demux_sink_pads
)
454 struct dvb_device
*dvbdev
;
455 struct file_operations
*dvbdevfops
;
456 struct device
*clsdev
;
460 mutex_lock(&dvbdev_register_lock
);
462 if ((id
= dvbdev_get_free_id (adap
, type
)) < 0){
463 mutex_unlock(&dvbdev_register_lock
);
465 pr_err("%s: couldn't find free device id\n", __func__
);
469 *pdvbdev
= dvbdev
= kzalloc(sizeof(*dvbdev
), GFP_KERNEL
);
472 mutex_unlock(&dvbdev_register_lock
);
476 dvbdevfops
= kzalloc(sizeof(struct file_operations
), GFP_KERNEL
);
480 mutex_unlock(&dvbdev_register_lock
);
484 memcpy(dvbdev
, template, sizeof(struct dvb_device
));
487 dvbdev
->adapter
= adap
;
489 dvbdev
->fops
= dvbdevfops
;
490 init_waitqueue_head (&dvbdev
->wait_queue
);
492 memcpy(dvbdevfops
, template->fops
, sizeof(struct file_operations
));
493 dvbdevfops
->owner
= adap
->module
;
495 list_add_tail (&dvbdev
->list_head
, &adap
->device_list
);
497 down_write(&minor_rwsem
);
498 #ifdef CONFIG_DVB_DYNAMIC_MINORS
499 for (minor
= 0; minor
< MAX_DVB_MINORS
; minor
++)
500 if (dvb_minors
[minor
] == NULL
)
503 if (minor
== MAX_DVB_MINORS
) {
506 up_write(&minor_rwsem
);
507 mutex_unlock(&dvbdev_register_lock
);
511 minor
= nums2minor(adap
->num
, type
, id
);
514 dvbdev
->minor
= minor
;
515 dvb_minors
[minor
] = dvbdev
;
516 up_write(&minor_rwsem
);
518 ret
= dvb_register_media_device(dvbdev
, type
, minor
, demux_sink_pads
);
520 pr_err("%s: dvb_register_media_device failed to create the mediagraph\n",
523 dvb_media_device_free(dvbdev
);
526 up_write(&minor_rwsem
);
527 mutex_unlock(&dvbdev_register_lock
);
531 mutex_unlock(&dvbdev_register_lock
);
533 clsdev
= device_create(dvb_class
, adap
->device
,
534 MKDEV(DVB_MAJOR
, minor
),
535 dvbdev
, "dvb%d.%s%d", adap
->num
, dnames
[type
], id
);
536 if (IS_ERR(clsdev
)) {
537 pr_err("%s: failed to create device dvb%d.%s%d (%ld)\n",
538 __func__
, adap
->num
, dnames
[type
], id
, PTR_ERR(clsdev
));
539 return PTR_ERR(clsdev
);
541 dprintk("DVB: register adapter%d/%s%d @ minor: %i (0x%02x)\n",
542 adap
->num
, dnames
[type
], id
, minor
, minor
);
546 EXPORT_SYMBOL(dvb_register_device
);
549 void dvb_remove_device(struct dvb_device
*dvbdev
)
554 down_write(&minor_rwsem
);
555 dvb_minors
[dvbdev
->minor
] = NULL
;
556 up_write(&minor_rwsem
);
558 dvb_media_device_free(dvbdev
);
560 device_destroy(dvb_class
, MKDEV(DVB_MAJOR
, dvbdev
->minor
));
562 list_del (&dvbdev
->list_head
);
564 EXPORT_SYMBOL(dvb_remove_device
);
567 void dvb_free_device(struct dvb_device
*dvbdev
)
572 kfree (dvbdev
->fops
);
575 EXPORT_SYMBOL(dvb_free_device
);
578 void dvb_unregister_device(struct dvb_device
*dvbdev
)
580 dvb_remove_device(dvbdev
);
581 dvb_free_device(dvbdev
);
583 EXPORT_SYMBOL(dvb_unregister_device
);
586 #ifdef CONFIG_MEDIA_CONTROLLER_DVB
588 static int dvb_create_io_intf_links(struct dvb_adapter
*adap
,
589 struct media_interface
*intf
,
592 struct media_device
*mdev
= adap
->mdev
;
593 struct media_entity
*entity
;
594 struct media_link
*link
;
596 media_device_for_each_entity(entity
, mdev
) {
597 if (entity
->function
== MEDIA_ENT_F_IO_DTV
) {
598 if (strncmp(entity
->name
, name
, strlen(name
)))
600 link
= media_create_intf_link(entity
, intf
,
601 MEDIA_LNK_FL_ENABLED
);
609 int dvb_create_media_graph(struct dvb_adapter
*adap
,
610 bool create_rf_connector
)
612 struct media_device
*mdev
= adap
->mdev
;
613 struct media_entity
*entity
, *tuner
= NULL
, *demod
= NULL
, *conn
;
614 struct media_entity
*demux
= NULL
, *ca
= NULL
;
615 struct media_link
*link
;
616 struct media_interface
*intf
;
617 unsigned demux_pad
= 0;
618 unsigned dvr_pad
= 0;
619 unsigned ntuner
= 0, ndemod
= 0;
621 static const char *connector_name
= "Television";
626 media_device_for_each_entity(entity
, mdev
) {
627 switch (entity
->function
) {
628 case MEDIA_ENT_F_TUNER
:
632 case MEDIA_ENT_F_DTV_DEMOD
:
636 case MEDIA_ENT_F_TS_DEMUX
:
639 case MEDIA_ENT_F_DTV_CA
:
646 * Prepare to signalize to media_create_pad_links() that multiple
647 * entities of the same type exists and a 1:n or n:1 links need to be
649 * NOTE: if both tuner and demod have multiple instances, it is up
650 * to the caller driver to create such links.
657 if (create_rf_connector
) {
658 conn
= kzalloc(sizeof(*conn
), GFP_KERNEL
);
663 adap
->conn_pads
= kzalloc(sizeof(*adap
->conn_pads
), GFP_KERNEL
);
664 if (!adap
->conn_pads
)
667 conn
->flags
= MEDIA_ENT_FL_CONNECTOR
;
668 conn
->function
= MEDIA_ENT_F_CONN_RF
;
669 conn
->name
= connector_name
;
670 adap
->conn_pads
->flags
= MEDIA_PAD_FL_SOURCE
;
672 ret
= media_entity_pads_init(conn
, 1, adap
->conn_pads
);
676 ret
= media_device_register_entity(mdev
, conn
);
681 ret
= media_create_pad_links(mdev
,
684 MEDIA_ENT_F_DTV_DEMOD
,
686 MEDIA_LNK_FL_ENABLED
,
689 ret
= media_create_pad_links(mdev
,
693 tuner
, TUNER_PAD_RF_INPUT
,
694 MEDIA_LNK_FL_ENABLED
,
700 if (ntuner
&& ndemod
) {
701 ret
= media_create_pad_links(mdev
,
703 tuner
, TUNER_PAD_OUTPUT
,
704 MEDIA_ENT_F_DTV_DEMOD
,
705 demod
, 0, MEDIA_LNK_FL_ENABLED
,
711 if (ndemod
&& demux
) {
712 ret
= media_create_pad_links(mdev
,
713 MEDIA_ENT_F_DTV_DEMOD
,
715 MEDIA_ENT_F_TS_DEMUX
,
716 demux
, 0, MEDIA_LNK_FL_ENABLED
,
722 ret
= media_create_pad_link(demux
, 1, ca
,
723 0, MEDIA_LNK_FL_ENABLED
);
728 /* Create demux links for each ringbuffer/pad */
730 media_device_for_each_entity(entity
, mdev
) {
731 if (entity
->function
== MEDIA_ENT_F_IO_DTV
) {
732 if (!strncmp(entity
->name
, DVR_TSOUT
,
733 strlen(DVR_TSOUT
))) {
734 ret
= media_create_pad_link(demux
,
740 if (!strncmp(entity
->name
, DEMUX_TSOUT
,
741 strlen(DEMUX_TSOUT
))) {
742 ret
= media_create_pad_link(demux
,
752 /* Create interface links for FE->tuner, DVR->demux and CA->ca */
753 media_device_for_each_intf(intf
, mdev
) {
754 if (intf
->type
== MEDIA_INTF_T_DVB_CA
&& ca
) {
755 link
= media_create_intf_link(ca
, intf
,
756 MEDIA_LNK_FL_ENABLED
);
761 if (intf
->type
== MEDIA_INTF_T_DVB_FE
&& tuner
) {
762 link
= media_create_intf_link(tuner
, intf
,
763 MEDIA_LNK_FL_ENABLED
);
769 * Indirect link - let's not create yet, as we don't know how
770 * to handle indirect links, nor if this will
771 * actually be needed.
773 if (intf
->type
== MEDIA_INTF_T_DVB_DVR
&& demux
) {
774 link
= media_create_intf_link(demux
, intf
,
775 MEDIA_LNK_FL_ENABLED
);
780 if (intf
->type
== MEDIA_INTF_T_DVB_DVR
) {
781 ret
= dvb_create_io_intf_links(adap
, intf
, DVR_TSOUT
);
785 if (intf
->type
== MEDIA_INTF_T_DVB_DEMUX
) {
786 ret
= dvb_create_io_intf_links(adap
, intf
, DEMUX_TSOUT
);
793 EXPORT_SYMBOL_GPL(dvb_create_media_graph
);
796 static int dvbdev_check_free_adapter_num(int num
)
798 struct list_head
*entry
;
799 list_for_each(entry
, &dvb_adapter_list
) {
800 struct dvb_adapter
*adap
;
801 adap
= list_entry(entry
, struct dvb_adapter
, list_head
);
802 if (adap
->num
== num
)
808 static int dvbdev_get_free_adapter_num (void)
812 while (num
< DVB_MAX_ADAPTERS
) {
813 if (dvbdev_check_free_adapter_num(num
))
822 int dvb_register_adapter(struct dvb_adapter
*adap
, const char *name
,
823 struct module
*module
, struct device
*device
,
828 mutex_lock(&dvbdev_register_lock
);
830 for (i
= 0; i
< DVB_MAX_ADAPTERS
; ++i
) {
831 num
= adapter_nums
[i
];
832 if (num
>= 0 && num
< DVB_MAX_ADAPTERS
) {
833 /* use the one the driver asked for */
834 if (dvbdev_check_free_adapter_num(num
))
837 num
= dvbdev_get_free_adapter_num();
844 mutex_unlock(&dvbdev_register_lock
);
848 memset (adap
, 0, sizeof(struct dvb_adapter
));
849 INIT_LIST_HEAD (&adap
->device_list
);
851 pr_info("DVB: registering new adapter (%s)\n", name
);
855 adap
->module
= module
;
856 adap
->device
= device
;
857 adap
->mfe_shared
= 0;
858 adap
->mfe_dvbdev
= NULL
;
859 mutex_init (&adap
->mfe_lock
);
861 list_add_tail (&adap
->list_head
, &dvb_adapter_list
);
863 mutex_unlock(&dvbdev_register_lock
);
867 EXPORT_SYMBOL(dvb_register_adapter
);
870 int dvb_unregister_adapter(struct dvb_adapter
*adap
)
872 mutex_lock(&dvbdev_register_lock
);
873 list_del (&adap
->list_head
);
874 mutex_unlock(&dvbdev_register_lock
);
877 EXPORT_SYMBOL(dvb_unregister_adapter
);
879 /* if the miracle happens and "generic_usercopy()" is included into
880 the kernel, then this can vanish. please don't make the mistake and
881 define this as video_usercopy(). this will introduce a dependecy
882 to the v4l "videodev.o" module, which is unnecessary for some
883 cards (ie. the budget dvb-cards don't need the v4l module...) */
884 int dvb_usercopy(struct file
*file
,
885 unsigned int cmd
, unsigned long arg
,
886 int (*func
)(struct file
*file
,
887 unsigned int cmd
, void *arg
))
894 /* Copy arguments into temp kernel buffer */
895 switch (_IOC_DIR(cmd
)) {
898 * For this command, the pointer is actually an integer
903 case _IOC_READ
: /* some v4l ioctls are marked wrong ... */
905 case (_IOC_WRITE
| _IOC_READ
):
906 if (_IOC_SIZE(cmd
) <= sizeof(sbuf
)) {
909 /* too big to allocate from stack */
910 mbuf
= kmalloc(_IOC_SIZE(cmd
), GFP_KERNEL
);
917 if (copy_from_user(parg
, (void __user
*)arg
, _IOC_SIZE(cmd
)))
923 if ((err
= func(file
, cmd
, parg
)) == -ENOIOCTLCMD
)
929 /* Copy results into user buffer */
930 switch (_IOC_DIR(cmd
))
933 case (_IOC_WRITE
| _IOC_READ
):
934 if (copy_to_user((void __user
*)arg
, parg
, _IOC_SIZE(cmd
)))
944 static int dvb_uevent(struct device
*dev
, struct kobj_uevent_env
*env
)
946 struct dvb_device
*dvbdev
= dev_get_drvdata(dev
);
948 add_uevent_var(env
, "DVB_ADAPTER_NUM=%d", dvbdev
->adapter
->num
);
949 add_uevent_var(env
, "DVB_DEVICE_TYPE=%s", dnames
[dvbdev
->type
]);
950 add_uevent_var(env
, "DVB_DEVICE_NUM=%d", dvbdev
->id
);
954 static char *dvb_devnode(struct device
*dev
, umode_t
*mode
)
956 struct dvb_device
*dvbdev
= dev_get_drvdata(dev
);
958 return kasprintf(GFP_KERNEL
, "dvb/adapter%d/%s%d",
959 dvbdev
->adapter
->num
, dnames
[dvbdev
->type
], dvbdev
->id
);
963 static int __init
init_dvbdev(void)
966 dev_t dev
= MKDEV(DVB_MAJOR
, 0);
968 if ((retval
= register_chrdev_region(dev
, MAX_DVB_MINORS
, "DVB")) != 0) {
969 pr_err("dvb-core: unable to get major %d\n", DVB_MAJOR
);
973 cdev_init(&dvb_device_cdev
, &dvb_device_fops
);
974 if ((retval
= cdev_add(&dvb_device_cdev
, dev
, MAX_DVB_MINORS
)) != 0) {
975 pr_err("dvb-core: unable register character device\n");
979 dvb_class
= class_create(THIS_MODULE
, "dvb");
980 if (IS_ERR(dvb_class
)) {
981 retval
= PTR_ERR(dvb_class
);
984 dvb_class
->dev_uevent
= dvb_uevent
;
985 dvb_class
->devnode
= dvb_devnode
;
989 cdev_del(&dvb_device_cdev
);
990 unregister_chrdev_region(dev
, MAX_DVB_MINORS
);
995 static void __exit
exit_dvbdev(void)
997 class_destroy(dvb_class
);
998 cdev_del(&dvb_device_cdev
);
999 unregister_chrdev_region(MKDEV(DVB_MAJOR
, 0), MAX_DVB_MINORS
);
1002 subsys_initcall(init_dvbdev
);
1003 module_exit(exit_dvbdev
);
1005 MODULE_DESCRIPTION("DVB Core Driver");
1006 MODULE_AUTHOR("Marcus Metzler, Ralph Metzler, Holger Waechtler");
1007 MODULE_LICENSE("GPL");