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, &dvbdev->intf_devnode->intf,
444 MEDIA_LNK_FL_ENABLED);
451 int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
452 const struct dvb_device *template, void *priv,
453 enum dvb_device_type type, int demux_sink_pads)
455 struct dvb_device *dvbdev;
456 struct file_operations *dvbdevfops;
457 struct device *clsdev;
461 mutex_lock(&dvbdev_register_lock);
463 if ((id = dvbdev_get_free_id (adap, type)) < 0){
464 mutex_unlock(&dvbdev_register_lock);
466 pr_err("%s: couldn't find free device id\n", __func__);
470 *pdvbdev = dvbdev = kzalloc(sizeof(*dvbdev), GFP_KERNEL);
473 mutex_unlock(&dvbdev_register_lock);
477 dvbdevfops = kzalloc(sizeof(struct file_operations), GFP_KERNEL);
481 mutex_unlock(&dvbdev_register_lock);
485 memcpy(dvbdev, template, sizeof(struct dvb_device));
488 dvbdev->adapter = adap;
490 dvbdev->fops = dvbdevfops;
491 init_waitqueue_head (&dvbdev->wait_queue);
493 memcpy(dvbdevfops, template->fops, sizeof(struct file_operations));
494 dvbdevfops->owner = adap->module;
496 list_add_tail (&dvbdev->list_head, &adap->device_list);
498 down_write(&minor_rwsem);
499 #ifdef CONFIG_DVB_DYNAMIC_MINORS
500 for (minor = 0; minor < MAX_DVB_MINORS; minor++)
501 if (dvb_minors[minor] == NULL)
504 if (minor == MAX_DVB_MINORS) {
507 up_write(&minor_rwsem);
508 mutex_unlock(&dvbdev_register_lock);
512 minor = nums2minor(adap->num, type, id);
515 dvbdev->minor = minor;
516 dvb_minors[minor] = dvbdev;
517 up_write(&minor_rwsem);
519 ret = dvb_register_media_device(dvbdev, type, minor, demux_sink_pads);
521 pr_err("%s: dvb_register_media_device failed to create the mediagraph\n",
524 dvb_media_device_free(dvbdev);
527 up_write(&minor_rwsem);
528 mutex_unlock(&dvbdev_register_lock);
532 mutex_unlock(&dvbdev_register_lock);
534 clsdev = device_create(dvb_class, adap->device,
535 MKDEV(DVB_MAJOR, minor),
536 dvbdev, "dvb%d.%s%d", adap->num, dnames[type], id);
537 if (IS_ERR(clsdev)) {
538 pr_err("%s: failed to create device dvb%d.%s%d (%ld)\n",
539 __func__, adap->num, dnames[type], id, PTR_ERR(clsdev));
540 return PTR_ERR(clsdev);
542 dprintk("DVB: register adapter%d/%s%d @ minor: %i (0x%02x)\n",
543 adap->num, dnames[type], id, minor, minor);
547 EXPORT_SYMBOL(dvb_register_device);
550 void dvb_remove_device(struct dvb_device *dvbdev)
555 down_write(&minor_rwsem);
556 dvb_minors[dvbdev->minor] = NULL;
557 up_write(&minor_rwsem);
559 dvb_media_device_free(dvbdev);
561 device_destroy(dvb_class, MKDEV(DVB_MAJOR, dvbdev->minor));
563 list_del (&dvbdev->list_head);
565 EXPORT_SYMBOL(dvb_remove_device);
568 void dvb_free_device(struct dvb_device *dvbdev)
573 kfree (dvbdev->fops);
576 EXPORT_SYMBOL(dvb_free_device);
579 void dvb_unregister_device(struct dvb_device *dvbdev)
581 dvb_remove_device(dvbdev);
582 dvb_free_device(dvbdev);
584 EXPORT_SYMBOL(dvb_unregister_device);
587 #ifdef CONFIG_MEDIA_CONTROLLER_DVB
589 static int dvb_create_io_intf_links(struct dvb_adapter *adap,
590 struct media_interface *intf,
593 struct media_device *mdev = adap->mdev;
594 struct media_entity *entity;
595 struct media_link *link;
597 media_device_for_each_entity(entity, mdev) {
598 if (entity->function == MEDIA_ENT_F_IO_DTV) {
599 if (strncmp(entity->name, name, strlen(name)))
601 link = media_create_intf_link(entity, intf,
602 MEDIA_LNK_FL_ENABLED);
610 int dvb_create_media_graph(struct dvb_adapter *adap,
611 bool create_rf_connector)
613 struct media_device *mdev = adap->mdev;
614 struct media_entity *entity, *tuner = NULL, *demod = NULL, *conn;
615 struct media_entity *demux = NULL, *ca = NULL;
616 struct media_link *link;
617 struct media_interface *intf;
618 unsigned demux_pad = 0;
619 unsigned dvr_pad = 0;
620 unsigned ntuner = 0, ndemod = 0;
622 static const char *connector_name = "Television";
627 media_device_for_each_entity(entity, mdev) {
628 switch (entity->function) {
629 case MEDIA_ENT_F_TUNER:
633 case MEDIA_ENT_F_DTV_DEMOD:
637 case MEDIA_ENT_F_TS_DEMUX:
640 case MEDIA_ENT_F_DTV_CA:
647 * Prepare to signalize to media_create_pad_links() that multiple
648 * entities of the same type exists and a 1:n or n:1 links need to be
650 * NOTE: if both tuner and demod have multiple instances, it is up
651 * to the caller driver to create such links.
658 if (create_rf_connector) {
659 conn = kzalloc(sizeof(*conn), GFP_KERNEL);
664 adap->conn_pads = kzalloc(sizeof(*adap->conn_pads), GFP_KERNEL);
665 if (!adap->conn_pads)
668 conn->flags = MEDIA_ENT_FL_CONNECTOR;
669 conn->function = MEDIA_ENT_F_CONN_RF;
670 conn->name = connector_name;
671 adap->conn_pads->flags = MEDIA_PAD_FL_SOURCE;
673 ret = media_entity_pads_init(conn, 1, adap->conn_pads);
677 ret = media_device_register_entity(mdev, conn);
682 ret = media_create_pad_links(mdev,
685 MEDIA_ENT_F_DTV_DEMOD,
687 MEDIA_LNK_FL_ENABLED,
690 ret = media_create_pad_links(mdev,
694 tuner, TUNER_PAD_RF_INPUT,
695 MEDIA_LNK_FL_ENABLED,
701 if (ntuner && ndemod) {
702 ret = media_create_pad_links(mdev,
704 tuner, TUNER_PAD_OUTPUT,
705 MEDIA_ENT_F_DTV_DEMOD,
706 demod, 0, MEDIA_LNK_FL_ENABLED,
712 if (ndemod && demux) {
713 ret = media_create_pad_links(mdev,
714 MEDIA_ENT_F_DTV_DEMOD,
716 MEDIA_ENT_F_TS_DEMUX,
717 demux, 0, MEDIA_LNK_FL_ENABLED,
723 ret = media_create_pad_link(demux, 1, ca,
724 0, MEDIA_LNK_FL_ENABLED);
729 /* Create demux links for each ringbuffer/pad */
731 media_device_for_each_entity(entity, mdev) {
732 if (entity->function == MEDIA_ENT_F_IO_DTV) {
733 if (!strncmp(entity->name, DVR_TSOUT,
734 strlen(DVR_TSOUT))) {
735 ret = media_create_pad_link(demux,
741 if (!strncmp(entity->name, DEMUX_TSOUT,
742 strlen(DEMUX_TSOUT))) {
743 ret = media_create_pad_link(demux,
753 /* Create interface links for FE->tuner, DVR->demux and CA->ca */
754 media_device_for_each_intf(intf, mdev) {
755 if (intf->type == MEDIA_INTF_T_DVB_CA && ca) {
756 link = media_create_intf_link(ca, intf,
757 MEDIA_LNK_FL_ENABLED);
762 if (intf->type == MEDIA_INTF_T_DVB_FE && tuner) {
763 link = media_create_intf_link(tuner, intf,
764 MEDIA_LNK_FL_ENABLED);
770 * Indirect link - let's not create yet, as we don't know how
771 * to handle indirect links, nor if this will
772 * actually be needed.
774 if (intf->type == MEDIA_INTF_T_DVB_DVR && demux) {
775 link = media_create_intf_link(demux, intf,
776 MEDIA_LNK_FL_ENABLED);
781 if (intf->type == MEDIA_INTF_T_DVB_DVR) {
782 ret = dvb_create_io_intf_links(adap, intf, DVR_TSOUT);
786 if (intf->type == MEDIA_INTF_T_DVB_DEMUX) {
787 ret = dvb_create_io_intf_links(adap, intf, DEMUX_TSOUT);
794 EXPORT_SYMBOL_GPL(dvb_create_media_graph);
797 static int dvbdev_check_free_adapter_num(int num)
799 struct list_head *entry;
800 list_for_each(entry, &dvb_adapter_list) {
801 struct dvb_adapter *adap;
802 adap = list_entry(entry, struct dvb_adapter, list_head);
803 if (adap->num == num)
809 static int dvbdev_get_free_adapter_num (void)
813 while (num < DVB_MAX_ADAPTERS) {
814 if (dvbdev_check_free_adapter_num(num))
823 int dvb_register_adapter(struct dvb_adapter *adap, const char *name,
824 struct module *module, struct device *device,
829 mutex_lock(&dvbdev_register_lock);
831 for (i = 0; i < DVB_MAX_ADAPTERS; ++i) {
832 num = adapter_nums[i];
833 if (num >= 0 && num < DVB_MAX_ADAPTERS) {
834 /* use the one the driver asked for */
835 if (dvbdev_check_free_adapter_num(num))
838 num = dvbdev_get_free_adapter_num();
845 mutex_unlock(&dvbdev_register_lock);
849 memset (adap, 0, sizeof(struct dvb_adapter));
850 INIT_LIST_HEAD (&adap->device_list);
852 pr_info("DVB: registering new adapter (%s)\n", name);
856 adap->module = module;
857 adap->device = device;
858 adap->mfe_shared = 0;
859 adap->mfe_dvbdev = NULL;
860 mutex_init (&adap->mfe_lock);
862 #ifdef CONFIG_MEDIA_CONTROLLER_DVB
863 mutex_init(&adap->mdev_lock);
866 list_add_tail (&adap->list_head, &dvb_adapter_list);
868 mutex_unlock(&dvbdev_register_lock);
872 EXPORT_SYMBOL(dvb_register_adapter);
875 int dvb_unregister_adapter(struct dvb_adapter *adap)
877 mutex_lock(&dvbdev_register_lock);
878 list_del (&adap->list_head);
879 mutex_unlock(&dvbdev_register_lock);
882 EXPORT_SYMBOL(dvb_unregister_adapter);
884 /* if the miracle happens and "generic_usercopy()" is included into
885 the kernel, then this can vanish. please don't make the mistake and
886 define this as video_usercopy(). this will introduce a dependecy
887 to the v4l "videodev.o" module, which is unnecessary for some
888 cards (ie. the budget dvb-cards don't need the v4l module...) */
889 int dvb_usercopy(struct file *file,
890 unsigned int cmd, unsigned long arg,
891 int (*func)(struct file *file,
892 unsigned int cmd, void *arg))
899 /* Copy arguments into temp kernel buffer */
900 switch (_IOC_DIR(cmd)) {
903 * For this command, the pointer is actually an integer
908 case _IOC_READ: /* some v4l ioctls are marked wrong ... */
910 case (_IOC_WRITE | _IOC_READ):
911 if (_IOC_SIZE(cmd) <= sizeof(sbuf)) {
914 /* too big to allocate from stack */
915 mbuf = kmalloc(_IOC_SIZE(cmd), GFP_KERNEL);
922 if (copy_from_user(parg, (void __user *)arg, _IOC_SIZE(cmd)))
928 if ((err = func(file, cmd, parg)) == -ENOIOCTLCMD)
934 /* Copy results into user buffer */
935 switch (_IOC_DIR(cmd))
938 case (_IOC_WRITE | _IOC_READ):
939 if (copy_to_user((void __user *)arg, parg, _IOC_SIZE(cmd)))
949 #if IS_ENABLED(CONFIG_I2C)
950 struct i2c_client *dvb_module_probe(const char *module_name,
952 struct i2c_adapter *adap,
956 struct i2c_client *client;
957 struct i2c_board_info *board_info;
959 board_info = kzalloc(sizeof(*board_info), GFP_KERNEL);
964 strlcpy(board_info->type, name, I2C_NAME_SIZE);
966 strlcpy(board_info->type, module_name, I2C_NAME_SIZE);
968 board_info->addr = addr;
969 board_info->platform_data = platform_data;
970 request_module(module_name);
971 client = i2c_new_device(adap, board_info);
972 if (client == NULL || client->dev.driver == NULL) {
977 if (!try_module_get(client->dev.driver->owner)) {
978 i2c_unregister_device(client);
985 EXPORT_SYMBOL_GPL(dvb_module_probe);
987 void dvb_module_release(struct i2c_client *client)
992 module_put(client->dev.driver->owner);
993 i2c_unregister_device(client);
995 EXPORT_SYMBOL_GPL(dvb_module_release);
998 static int dvb_uevent(struct device *dev, struct kobj_uevent_env *env)
1000 struct dvb_device *dvbdev = dev_get_drvdata(dev);
1002 add_uevent_var(env, "DVB_ADAPTER_NUM=%d", dvbdev->adapter->num);
1003 add_uevent_var(env, "DVB_DEVICE_TYPE=%s", dnames[dvbdev->type]);
1004 add_uevent_var(env, "DVB_DEVICE_NUM=%d", dvbdev->id);
1008 static char *dvb_devnode(struct device *dev, umode_t *mode)
1010 struct dvb_device *dvbdev = dev_get_drvdata(dev);
1012 return kasprintf(GFP_KERNEL, "dvb/adapter%d/%s%d",
1013 dvbdev->adapter->num, dnames[dvbdev->type], dvbdev->id);
1017 static int __init init_dvbdev(void)
1020 dev_t dev = MKDEV(DVB_MAJOR, 0);
1022 if ((retval = register_chrdev_region(dev, MAX_DVB_MINORS, "DVB")) != 0) {
1023 pr_err("dvb-core: unable to get major %d\n", DVB_MAJOR);
1027 cdev_init(&dvb_device_cdev, &dvb_device_fops);
1028 if ((retval = cdev_add(&dvb_device_cdev, dev, MAX_DVB_MINORS)) != 0) {
1029 pr_err("dvb-core: unable register character device\n");
1033 dvb_class = class_create(THIS_MODULE, "dvb");
1034 if (IS_ERR(dvb_class)) {
1035 retval = PTR_ERR(dvb_class);
1038 dvb_class->dev_uevent = dvb_uevent;
1039 dvb_class->devnode = dvb_devnode;
1043 cdev_del(&dvb_device_cdev);
1044 unregister_chrdev_region(dev, MAX_DVB_MINORS);
1049 static void __exit exit_dvbdev(void)
1051 class_destroy(dvb_class);
1052 cdev_del(&dvb_device_cdev);
1053 unregister_chrdev_region(MKDEV(DVB_MAJOR, 0), MAX_DVB_MINORS);
1056 subsys_initcall(init_dvbdev);
1057 module_exit(exit_dvbdev);
1059 MODULE_DESCRIPTION("DVB Core Driver");
1060 MODULE_AUTHOR("Marcus Metzler, Ralph Metzler, Holger Waechtler");
1061 MODULE_LICENSE("GPL");