Lines Matching refs:dvbdev
3 * dvbdev.c
10 #define pr_fmt(fmt) "dvbdev: " fmt
24 #include <media/dvbdev.h>
88 struct dvb_device *dvbdev;
97 dvbdev = dvb_minors[minor];
99 if (dvbdev && dvbdev->fops) {
103 new_fops = fops_get(dvbdev->fops);
106 file->private_data = dvb_device_get(dvbdev);
113 dvb_device_put(dvbdev);
132 struct dvb_device *dvbdev = file->private_data;
134 if (!dvbdev)
137 if (!dvbdev->users)
141 if (!dvbdev->readers)
143 dvbdev->readers--;
145 if (!dvbdev->writers)
147 dvbdev->writers--;
150 dvbdev->users--;
157 struct dvb_device *dvbdev = file->private_data;
159 if (!dvbdev)
163 dvbdev->readers++;
165 dvbdev->writers++;
167 dvbdev->users++;
169 dvb_device_put(dvbdev);
178 struct dvb_device *dvbdev = file->private_data;
180 if (!dvbdev)
183 if (!dvbdev->kernel_ioctl)
186 return dvb_usercopy(file, cmd, arg, dvbdev->kernel_ioctl);
207 static void dvb_media_device_free(struct dvb_device *dvbdev)
210 if (dvbdev->entity) {
211 media_device_unregister_entity(dvbdev->entity);
212 kfree(dvbdev->entity);
213 kfree(dvbdev->pads);
214 dvbdev->entity = NULL;
215 dvbdev->pads = 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;
249 static int dvb_create_tsout_entity(struct dvb_device *dvbdev,
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;
267 struct media_pad *pads = &dvbdev->tsout_pads[i];
268 struct media_entity *entity = &dvbdev->tsout_entity[i];
282 ret = media_device_register_entity(dvbdev->adapter->mdev,
293 static int dvb_create_media_entity(struct dvb_device *dvbdev,
303 ret = dvb_create_tsout_entity(dvbdev, DVR_TSOUT,
308 ret = dvb_create_tsout_entity(dvbdev, DEMUX_TSOUT,
331 dvbdev->entity = kzalloc(sizeof(*dvbdev->entity), GFP_KERNEL);
332 if (!dvbdev->entity)
335 dvbdev->entity->name = dvbdev->name;
338 dvbdev->pads = kcalloc(npads, sizeof(*dvbdev->pads),
340 if (!dvbdev->pads) {
341 kfree(dvbdev->entity);
342 dvbdev->entity = NULL;
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;
354 dvbdev->entity->function = MEDIA_ENT_F_TS_DEMUX;
355 dvbdev->pads[0].flags = MEDIA_PAD_FL_SINK;
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;
366 kfree(dvbdev->entity);
367 kfree(dvbdev->pads);
368 dvbdev->entity = NULL;
369 dvbdev->pads = NULL;
374 ret = media_entity_pads_init(dvbdev->entity, npads, dvbdev->pads);
378 ret = media_device_register_entity(dvbdev->adapter->mdev,
379 dvbdev->entity);
384 __func__, dvbdev->entity->name);
390 static int dvb_register_media_device(struct dvb_device *dvbdev,
399 if (!dvbdev->adapter->mdev)
402 ret = dvb_create_media_entity(dvbdev, type, demux_sink_pads);
426 dvbdev->intf_devnode = media_devnode_create(dvbdev->adapter->mdev,
430 if (!dvbdev->intf_devnode)
441 if (!dvbdev->entity)
444 link = media_create_intf_link(dvbdev->entity,
445 &dvbdev->intf_devnode->intf,
458 struct dvb_device *dvbdev;
475 *pdvbdev = dvbdev = kzalloc(sizeof(*dvbdev), GFP_KERNEL);
476 if (!dvbdev) {
497 kfree(dvbdev);
506 kfree(dvbdev);
518 memcpy(dvbdev, template, sizeof(struct dvb_device));
519 kref_init(&dvbdev->ref);
520 dvbdev->type = type;
521 dvbdev->id = id;
522 dvbdev->adapter = adap;
523 dvbdev->priv = priv;
524 dvbdev->fops = dvbdevfops;
525 init_waitqueue_head(&dvbdev->wait_queue);
527 list_add_tail(&dvbdev->list_head, &adap->device_list);
542 list_del(&dvbdev->list_head);
543 kfree(dvbdev);
550 dvbdev->minor = minor;
551 dvb_minors[minor] = dvb_device_get(dvbdev);
553 ret = dvb_register_media_device(dvbdev, type, minor, demux_sink_pads);
562 dvb_media_device_free(dvbdev);
563 list_del(&dvbdev->list_head);
564 kfree(dvbdev);
572 dvbdev, "dvb%d.%s%d", adap->num, dnames[type], id);
581 dvb_media_device_free(dvbdev);
582 list_del(&dvbdev->list_head);
583 kfree(dvbdev);
597 void dvb_remove_device(struct dvb_device *dvbdev)
599 if (!dvbdev)
603 dvb_minors[dvbdev->minor] = NULL;
604 dvb_device_put(dvbdev);
607 dvb_media_device_free(dvbdev);
609 device_destroy(dvb_class, MKDEV(DVB_MAJOR, dvbdev->minor));
611 list_del(&dvbdev->list_head);
617 struct dvb_device *dvbdev = container_of(ref, struct dvb_device, ref);
619 kfree(dvbdev);
622 struct dvb_device *dvb_device_get(struct dvb_device *dvbdev)
624 kref_get(&dvbdev->ref);
625 return dvbdev;
629 void dvb_device_put(struct dvb_device *dvbdev)
631 if (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);
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);
1081 const struct dvb_device *dvbdev = dev_get_drvdata(dev);
1084 dvbdev->adapter->num, dnames[dvbdev->type], dvbdev->id);