diff options
author | Hans Verkuil <hans.verkuil@cisco.com> | 2015-03-09 12:34:00 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@osg.samsung.com> | 2015-04-08 05:43:16 -0400 |
commit | 34080bc25fa04e07691e853cd516c431b67be5f4 (patch) | |
tree | 78116e7d353c87097cd63ec9bcd4259120588bc3 | |
parent | 55cda4ab5386418b31e626e91bbf4eedf209b9bb (diff) |
[media] cx88: embed video_device
Embed the video_device struct to simplify the error handling and in
order to (eventually) get rid of video_device_alloc/release.
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
-rw-r--r-- | drivers/media/pci/cx88/cx88-blackbird.c | 22 | ||||
-rw-r--r-- | drivers/media/pci/cx88/cx88-core.c | 18 | ||||
-rw-r--r-- | drivers/media/pci/cx88/cx88-video.c | 61 | ||||
-rw-r--r-- | drivers/media/pci/cx88/cx88.h | 17 |
4 files changed, 46 insertions, 72 deletions
diff --git a/drivers/media/pci/cx88/cx88-blackbird.c b/drivers/media/pci/cx88/cx88-blackbird.c index b6be46e94289..24216efa56e7 100644 --- a/drivers/media/pci/cx88/cx88-blackbird.c +++ b/drivers/media/pci/cx88/cx88-blackbird.c | |||
@@ -1102,32 +1102,26 @@ static int cx8802_blackbird_advise_release(struct cx8802_driver *drv) | |||
1102 | 1102 | ||
1103 | static void blackbird_unregister_video(struct cx8802_dev *dev) | 1103 | static void blackbird_unregister_video(struct cx8802_dev *dev) |
1104 | { | 1104 | { |
1105 | if (dev->mpeg_dev) { | 1105 | video_unregister_device(&dev->mpeg_dev); |
1106 | if (video_is_registered(dev->mpeg_dev)) | ||
1107 | video_unregister_device(dev->mpeg_dev); | ||
1108 | else | ||
1109 | video_device_release(dev->mpeg_dev); | ||
1110 | dev->mpeg_dev = NULL; | ||
1111 | } | ||
1112 | } | 1106 | } |
1113 | 1107 | ||
1114 | static int blackbird_register_video(struct cx8802_dev *dev) | 1108 | static int blackbird_register_video(struct cx8802_dev *dev) |
1115 | { | 1109 | { |
1116 | int err; | 1110 | int err; |
1117 | 1111 | ||
1118 | dev->mpeg_dev = cx88_vdev_init(dev->core, dev->pci, | 1112 | cx88_vdev_init(dev->core, dev->pci, &dev->mpeg_dev, |
1119 | &cx8802_mpeg_template, "mpeg"); | 1113 | &cx8802_mpeg_template, "mpeg"); |
1120 | dev->mpeg_dev->ctrl_handler = &dev->cxhdl.hdl; | 1114 | dev->mpeg_dev.ctrl_handler = &dev->cxhdl.hdl; |
1121 | video_set_drvdata(dev->mpeg_dev, dev); | 1115 | video_set_drvdata(&dev->mpeg_dev, dev); |
1122 | dev->mpeg_dev->queue = &dev->vb2_mpegq; | 1116 | dev->mpeg_dev.queue = &dev->vb2_mpegq; |
1123 | err = video_register_device(dev->mpeg_dev, VFL_TYPE_GRABBER, -1); | 1117 | err = video_register_device(&dev->mpeg_dev, VFL_TYPE_GRABBER, -1); |
1124 | if (err < 0) { | 1118 | if (err < 0) { |
1125 | printk(KERN_INFO "%s/2: can't register mpeg device\n", | 1119 | printk(KERN_INFO "%s/2: can't register mpeg device\n", |
1126 | dev->core->name); | 1120 | dev->core->name); |
1127 | return err; | 1121 | return err; |
1128 | } | 1122 | } |
1129 | printk(KERN_INFO "%s/2: registered device %s [mpeg]\n", | 1123 | printk(KERN_INFO "%s/2: registered device %s [mpeg]\n", |
1130 | dev->core->name, video_device_node_name(dev->mpeg_dev)); | 1124 | dev->core->name, video_device_node_name(&dev->mpeg_dev)); |
1131 | return 0; | 1125 | return 0; |
1132 | } | 1126 | } |
1133 | 1127 | ||
diff --git a/drivers/media/pci/cx88/cx88-core.c b/drivers/media/pci/cx88/cx88-core.c index c38d5a12e277..3501be9f19d8 100644 --- a/drivers/media/pci/cx88/cx88-core.c +++ b/drivers/media/pci/cx88/cx88-core.c | |||
@@ -985,17 +985,14 @@ int cx88_set_tvnorm(struct cx88_core *core, v4l2_std_id norm) | |||
985 | 985 | ||
986 | /* ------------------------------------------------------------------ */ | 986 | /* ------------------------------------------------------------------ */ |
987 | 987 | ||
988 | struct video_device *cx88_vdev_init(struct cx88_core *core, | 988 | void cx88_vdev_init(struct cx88_core *core, |
989 | struct pci_dev *pci, | 989 | struct pci_dev *pci, |
990 | const struct video_device *template_, | 990 | struct video_device *vfd, |
991 | const char *type) | 991 | const struct video_device *template_, |
992 | const char *type) | ||
992 | { | 993 | { |
993 | struct video_device *vfd; | ||
994 | |||
995 | vfd = video_device_alloc(); | ||
996 | if (NULL == vfd) | ||
997 | return NULL; | ||
998 | *vfd = *template_; | 994 | *vfd = *template_; |
995 | |||
999 | /* | 996 | /* |
1000 | * The dev pointer of v4l2_device is NULL, instead we set the | 997 | * The dev pointer of v4l2_device is NULL, instead we set the |
1001 | * video_device dev_parent pointer to the correct PCI bus device. | 998 | * video_device dev_parent pointer to the correct PCI bus device. |
@@ -1004,11 +1001,10 @@ struct video_device *cx88_vdev_init(struct cx88_core *core, | |||
1004 | */ | 1001 | */ |
1005 | vfd->v4l2_dev = &core->v4l2_dev; | 1002 | vfd->v4l2_dev = &core->v4l2_dev; |
1006 | vfd->dev_parent = &pci->dev; | 1003 | vfd->dev_parent = &pci->dev; |
1007 | vfd->release = video_device_release; | 1004 | vfd->release = video_device_release_empty; |
1008 | vfd->lock = &core->lock; | 1005 | vfd->lock = &core->lock; |
1009 | snprintf(vfd->name, sizeof(vfd->name), "%s %s (%s)", | 1006 | snprintf(vfd->name, sizeof(vfd->name), "%s %s (%s)", |
1010 | core->name, type, core->board.name); | 1007 | core->name, type, core->board.name); |
1011 | return vfd; | ||
1012 | } | 1008 | } |
1013 | 1009 | ||
1014 | struct cx88_core* cx88_core_get(struct pci_dev *pci) | 1010 | struct cx88_core* cx88_core_get(struct pci_dev *pci) |
diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c index 860c98fc72c7..c9decd80bf61 100644 --- a/drivers/media/pci/cx88/cx88-video.c +++ b/drivers/media/pci/cx88/cx88-video.c | |||
@@ -1274,27 +1274,9 @@ static const struct v4l2_ctrl_ops cx8800_ctrl_aud_ops = { | |||
1274 | 1274 | ||
1275 | static void cx8800_unregister_video(struct cx8800_dev *dev) | 1275 | static void cx8800_unregister_video(struct cx8800_dev *dev) |
1276 | { | 1276 | { |
1277 | if (dev->radio_dev) { | 1277 | video_unregister_device(&dev->radio_dev); |
1278 | if (video_is_registered(dev->radio_dev)) | 1278 | video_unregister_device(&dev->vbi_dev); |
1279 | video_unregister_device(dev->radio_dev); | 1279 | video_unregister_device(&dev->video_dev); |
1280 | else | ||
1281 | video_device_release(dev->radio_dev); | ||
1282 | dev->radio_dev = NULL; | ||
1283 | } | ||
1284 | if (dev->vbi_dev) { | ||
1285 | if (video_is_registered(dev->vbi_dev)) | ||
1286 | video_unregister_device(dev->vbi_dev); | ||
1287 | else | ||
1288 | video_device_release(dev->vbi_dev); | ||
1289 | dev->vbi_dev = NULL; | ||
1290 | } | ||
1291 | if (dev->video_dev) { | ||
1292 | if (video_is_registered(dev->video_dev)) | ||
1293 | video_unregister_device(dev->video_dev); | ||
1294 | else | ||
1295 | video_device_release(dev->video_dev); | ||
1296 | dev->video_dev = NULL; | ||
1297 | } | ||
1298 | } | 1280 | } |
1299 | 1281 | ||
1300 | static int cx8800_initdev(struct pci_dev *pci_dev, | 1282 | static int cx8800_initdev(struct pci_dev *pci_dev, |
@@ -1485,12 +1467,12 @@ static int cx8800_initdev(struct pci_dev *pci_dev, | |||
1485 | goto fail_unreg; | 1467 | goto fail_unreg; |
1486 | 1468 | ||
1487 | /* register v4l devices */ | 1469 | /* register v4l devices */ |
1488 | dev->video_dev = cx88_vdev_init(core,dev->pci, | 1470 | cx88_vdev_init(core, dev->pci, &dev->video_dev, |
1489 | &cx8800_video_template,"video"); | 1471 | &cx8800_video_template, "video"); |
1490 | video_set_drvdata(dev->video_dev, dev); | 1472 | video_set_drvdata(&dev->video_dev, dev); |
1491 | dev->video_dev->ctrl_handler = &core->video_hdl; | 1473 | dev->video_dev.ctrl_handler = &core->video_hdl; |
1492 | dev->video_dev->queue = &dev->vb2_vidq; | 1474 | dev->video_dev.queue = &dev->vb2_vidq; |
1493 | err = video_register_device(dev->video_dev,VFL_TYPE_GRABBER, | 1475 | err = video_register_device(&dev->video_dev, VFL_TYPE_GRABBER, |
1494 | video_nr[core->nr]); | 1476 | video_nr[core->nr]); |
1495 | if (err < 0) { | 1477 | if (err < 0) { |
1496 | printk(KERN_ERR "%s/0: can't register video device\n", | 1478 | printk(KERN_ERR "%s/0: can't register video device\n", |
@@ -1498,12 +1480,13 @@ static int cx8800_initdev(struct pci_dev *pci_dev, | |||
1498 | goto fail_unreg; | 1480 | goto fail_unreg; |
1499 | } | 1481 | } |
1500 | printk(KERN_INFO "%s/0: registered device %s [v4l2]\n", | 1482 | printk(KERN_INFO "%s/0: registered device %s [v4l2]\n", |
1501 | core->name, video_device_node_name(dev->video_dev)); | 1483 | core->name, video_device_node_name(&dev->video_dev)); |
1502 | 1484 | ||
1503 | dev->vbi_dev = cx88_vdev_init(core,dev->pci,&cx8800_vbi_template,"vbi"); | 1485 | cx88_vdev_init(core, dev->pci, &dev->vbi_dev, |
1504 | video_set_drvdata(dev->vbi_dev, dev); | 1486 | &cx8800_vbi_template, "vbi"); |
1505 | dev->vbi_dev->queue = &dev->vb2_vbiq; | 1487 | video_set_drvdata(&dev->vbi_dev, dev); |
1506 | err = video_register_device(dev->vbi_dev,VFL_TYPE_VBI, | 1488 | dev->vbi_dev.queue = &dev->vb2_vbiq; |
1489 | err = video_register_device(&dev->vbi_dev, VFL_TYPE_VBI, | ||
1507 | vbi_nr[core->nr]); | 1490 | vbi_nr[core->nr]); |
1508 | if (err < 0) { | 1491 | if (err < 0) { |
1509 | printk(KERN_ERR "%s/0: can't register vbi device\n", | 1492 | printk(KERN_ERR "%s/0: can't register vbi device\n", |
@@ -1511,14 +1494,14 @@ static int cx8800_initdev(struct pci_dev *pci_dev, | |||
1511 | goto fail_unreg; | 1494 | goto fail_unreg; |
1512 | } | 1495 | } |
1513 | printk(KERN_INFO "%s/0: registered device %s\n", | 1496 | printk(KERN_INFO "%s/0: registered device %s\n", |
1514 | core->name, video_device_node_name(dev->vbi_dev)); | 1497 | core->name, video_device_node_name(&dev->vbi_dev)); |
1515 | 1498 | ||
1516 | if (core->board.radio.type == CX88_RADIO) { | 1499 | if (core->board.radio.type == CX88_RADIO) { |
1517 | dev->radio_dev = cx88_vdev_init(core,dev->pci, | 1500 | cx88_vdev_init(core, dev->pci, &dev->radio_dev, |
1518 | &cx8800_radio_template,"radio"); | 1501 | &cx8800_radio_template, "radio"); |
1519 | video_set_drvdata(dev->radio_dev, dev); | 1502 | video_set_drvdata(&dev->radio_dev, dev); |
1520 | dev->radio_dev->ctrl_handler = &core->audio_hdl; | 1503 | dev->radio_dev.ctrl_handler = &core->audio_hdl; |
1521 | err = video_register_device(dev->radio_dev,VFL_TYPE_RADIO, | 1504 | err = video_register_device(&dev->radio_dev, VFL_TYPE_RADIO, |
1522 | radio_nr[core->nr]); | 1505 | radio_nr[core->nr]); |
1523 | if (err < 0) { | 1506 | if (err < 0) { |
1524 | printk(KERN_ERR "%s/0: can't register radio device\n", | 1507 | printk(KERN_ERR "%s/0: can't register radio device\n", |
@@ -1526,7 +1509,7 @@ static int cx8800_initdev(struct pci_dev *pci_dev, | |||
1526 | goto fail_unreg; | 1509 | goto fail_unreg; |
1527 | } | 1510 | } |
1528 | printk(KERN_INFO "%s/0: registered device %s\n", | 1511 | printk(KERN_INFO "%s/0: registered device %s\n", |
1529 | core->name, video_device_node_name(dev->radio_dev)); | 1512 | core->name, video_device_node_name(&dev->radio_dev)); |
1530 | } | 1513 | } |
1531 | 1514 | ||
1532 | /* start tvaudio thread */ | 1515 | /* start tvaudio thread */ |
diff --git a/drivers/media/pci/cx88/cx88.h b/drivers/media/pci/cx88/cx88.h index 7748ca9abb09..b9fe1ac24803 100644 --- a/drivers/media/pci/cx88/cx88.h +++ b/drivers/media/pci/cx88/cx88.h | |||
@@ -478,9 +478,9 @@ struct cx8800_dev { | |||
478 | 478 | ||
479 | /* various device info */ | 479 | /* various device info */ |
480 | unsigned int resources; | 480 | unsigned int resources; |
481 | struct video_device *video_dev; | 481 | struct video_device video_dev; |
482 | struct video_device *vbi_dev; | 482 | struct video_device vbi_dev; |
483 | struct video_device *radio_dev; | 483 | struct video_device radio_dev; |
484 | 484 | ||
485 | /* pci i/o */ | 485 | /* pci i/o */ |
486 | struct pci_dev *pci; | 486 | struct pci_dev *pci; |
@@ -563,7 +563,7 @@ struct cx8802_dev { | |||
563 | /* for blackbird only */ | 563 | /* for blackbird only */ |
564 | struct list_head devlist; | 564 | struct list_head devlist; |
565 | #if IS_ENABLED(CONFIG_VIDEO_CX88_BLACKBIRD) | 565 | #if IS_ENABLED(CONFIG_VIDEO_CX88_BLACKBIRD) |
566 | struct video_device *mpeg_dev; | 566 | struct video_device mpeg_dev; |
567 | u32 mailbox; | 567 | u32 mailbox; |
568 | 568 | ||
569 | /* mpeg params */ | 569 | /* mpeg params */ |
@@ -647,10 +647,11 @@ extern int cx88_set_scale(struct cx88_core *core, unsigned int width, | |||
647 | unsigned int height, enum v4l2_field field); | 647 | unsigned int height, enum v4l2_field field); |
648 | extern int cx88_set_tvnorm(struct cx88_core *core, v4l2_std_id norm); | 648 | extern int cx88_set_tvnorm(struct cx88_core *core, v4l2_std_id norm); |
649 | 649 | ||
650 | extern struct video_device *cx88_vdev_init(struct cx88_core *core, | 650 | extern void cx88_vdev_init(struct cx88_core *core, |
651 | struct pci_dev *pci, | 651 | struct pci_dev *pci, |
652 | const struct video_device *template_, | 652 | struct video_device *vfd, |
653 | const char *type); | 653 | const struct video_device *template_, |
654 | const char *type); | ||
654 | extern struct cx88_core *cx88_core_get(struct pci_dev *pci); | 655 | extern struct cx88_core *cx88_core_get(struct pci_dev *pci); |
655 | extern void cx88_core_put(struct cx88_core *core, | 656 | extern void cx88_core_put(struct cx88_core *core, |
656 | struct pci_dev *pci); | 657 | struct pci_dev *pci); |