2023-05-05 13:08:01 +02:00
|
|
|
// SPDX-License-Identifier: LGPL-2.1-or-later
|
2015-08-05 17:22:42 +02:00
|
|
|
/*
|
|
|
|
* dvbdev.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 2000 Ralph Metzler <ralph@convergence.de>
|
|
|
|
* & Marcus Metzler <marcus@convergence.de>
|
|
|
|
* for convergence integrated media GmbH
|
|
|
|
*/
|
|
|
|
|
2017-09-26 21:18:04 +02:00
|
|
|
#define pr_fmt(fmt) "dvbdev: " fmt
|
|
|
|
|
2015-08-05 17:22:42 +02:00
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/kernel.h>
|
2020-08-29 15:32:42 +02:00
|
|
|
#include <linux/i2c.h>
|
2015-08-05 17:22:42 +02:00
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/device.h>
|
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/cdev.h>
|
|
|
|
#include <linux/mutex.h>
|
|
|
|
#include <linux/version.h>
|
2020-08-29 15:32:42 +02:00
|
|
|
#include <media/dvbdev.h>
|
2015-08-05 17:22:42 +02:00
|
|
|
|
2017-09-26 21:18:04 +02:00
|
|
|
#if (LINUX_VERSION_CODE > KERNEL_VERSION(4,0,0))
|
|
|
|
/* Due to enum tuner_pad_index */
|
|
|
|
#include <media/tuner.h>
|
|
|
|
#endif
|
|
|
|
|
2015-08-05 17:22:42 +02:00
|
|
|
static DEFINE_MUTEX(dvbdev_mutex);
|
2023-09-12 15:06:23 +02:00
|
|
|
static LIST_HEAD(dvbdevfops_list);
|
2015-08-05 17:22:42 +02:00
|
|
|
static int dvbdev_debug;
|
|
|
|
|
|
|
|
module_param(dvbdev_debug, int, 0644);
|
|
|
|
MODULE_PARM_DESC(dvbdev_debug, "Turn on/off device debugging (default:off).");
|
|
|
|
|
2017-09-26 21:18:04 +02:00
|
|
|
#define dprintk(fmt, arg...) do { \
|
|
|
|
if (dvbdev_debug) \
|
|
|
|
printk(KERN_DEBUG pr_fmt("%s: " fmt), \
|
|
|
|
__func__, ##arg); \
|
|
|
|
} while (0)
|
2015-08-05 17:22:42 +02:00
|
|
|
|
|
|
|
static LIST_HEAD(dvb_adapter_list);
|
|
|
|
static DEFINE_MUTEX(dvbdev_register_lock);
|
|
|
|
|
|
|
|
static const char * const dnames[] = {
|
2020-08-29 15:32:42 +02:00
|
|
|
[DVB_DEVICE_VIDEO] = "video",
|
|
|
|
[DVB_DEVICE_AUDIO] = "audio",
|
|
|
|
[DVB_DEVICE_SEC] = "sec",
|
|
|
|
[DVB_DEVICE_FRONTEND] = "frontend",
|
|
|
|
[DVB_DEVICE_DEMUX] = "demux",
|
|
|
|
[DVB_DEVICE_DVR] = "dvr",
|
|
|
|
[DVB_DEVICE_CA] = "ca",
|
|
|
|
[DVB_DEVICE_NET] = "net",
|
|
|
|
[DVB_DEVICE_OSD] = "osd",
|
|
|
|
[DVB_DEVICE_CI] = "ci",
|
|
|
|
[DVB_DEVICE_MOD] = "mod",
|
|
|
|
[DVB_DEVICE_NS] = "ns",
|
|
|
|
[DVB_DEVICE_NSD] = "nsd",
|
2015-08-05 17:22:42 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#ifdef CONFIG_DVB_DYNAMIC_MINORS
|
2018-07-18 09:45:07 +02:00
|
|
|
#define MAX_DVB_MINORS 512
|
2015-08-05 17:22:42 +02:00
|
|
|
#define DVB_MAX_IDS MAX_DVB_MINORS
|
|
|
|
#else
|
|
|
|
#define DVB_MAX_IDS 4
|
2020-08-29 15:32:42 +02:00
|
|
|
|
|
|
|
static const u8 minor_type[] = {
|
|
|
|
[DVB_DEVICE_VIDEO] = 0,
|
|
|
|
[DVB_DEVICE_AUDIO] = 1,
|
2022-01-14 20:13:34 +01:00
|
|
|
[DVB_DEVICE_SEC] = 2,
|
2020-08-29 15:32:42 +02:00
|
|
|
[DVB_DEVICE_FRONTEND] = 3,
|
|
|
|
[DVB_DEVICE_DEMUX] = 4,
|
|
|
|
[DVB_DEVICE_DVR] = 5,
|
|
|
|
[DVB_DEVICE_CA] = 6,
|
|
|
|
[DVB_DEVICE_NET] = 7,
|
|
|
|
[DVB_DEVICE_OSD] = 8,
|
2022-01-14 20:13:34 +01:00
|
|
|
[DVB_DEVICE_CI] = 9,
|
|
|
|
[DVB_DEVICE_MOD] = 10,
|
|
|
|
[DVB_DEVICE_NS] = 11,
|
|
|
|
[DVB_DEVICE_NSD] = 12,
|
2020-08-29 15:32:42 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#define nums2minor(num, type, id) \
|
2023-09-12 15:06:23 +02:00
|
|
|
(((num) << 6) | ((id) << 4) | minor_type[type])
|
2020-08-29 15:32:42 +02:00
|
|
|
|
2023-09-12 15:06:23 +02:00
|
|
|
#define MAX_DVB_MINORS (DVB_MAX_ADAPTERS * 64)
|
2015-08-05 17:22:42 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
static struct class *dvb_class;
|
|
|
|
|
|
|
|
static struct dvb_device *dvb_minors[MAX_DVB_MINORS];
|
|
|
|
static DECLARE_RWSEM(minor_rwsem);
|
|
|
|
|
|
|
|
static int dvb_device_open(struct inode *inode, struct file *file)
|
|
|
|
{
|
|
|
|
struct dvb_device *dvbdev;
|
|
|
|
|
|
|
|
mutex_lock(&dvbdev_mutex);
|
|
|
|
down_read(&minor_rwsem);
|
|
|
|
dvbdev = dvb_minors[iminor(inode)];
|
|
|
|
|
|
|
|
if (dvbdev && dvbdev->fops) {
|
|
|
|
int err = 0;
|
2017-09-26 21:18:04 +02:00
|
|
|
const struct file_operations *new_fops;
|
2015-08-05 17:22:42 +02:00
|
|
|
|
2017-09-26 21:18:04 +02:00
|
|
|
new_fops = fops_get(dvbdev->fops);
|
|
|
|
if (!new_fops)
|
2015-08-05 17:22:42 +02:00
|
|
|
goto fail;
|
2023-05-05 13:08:01 +02:00
|
|
|
file->private_data = dvb_device_get(dvbdev);
|
2017-09-26 21:18:04 +02:00
|
|
|
replace_fops(file, new_fops);
|
|
|
|
if (file->f_op->open)
|
|
|
|
err = file->f_op->open(inode, file);
|
2015-08-05 17:22:42 +02:00
|
|
|
up_read(&minor_rwsem);
|
|
|
|
mutex_unlock(&dvbdev_mutex);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
fail:
|
|
|
|
up_read(&minor_rwsem);
|
|
|
|
mutex_unlock(&dvbdev_mutex);
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
2023-09-12 15:06:23 +02:00
|
|
|
static const struct file_operations dvb_device_fops = {
|
2015-08-05 17:22:42 +02:00
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.open = dvb_device_open,
|
|
|
|
.llseek = noop_llseek,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct cdev dvb_device_cdev;
|
|
|
|
|
|
|
|
int dvb_generic_open(struct inode *inode, struct file *file)
|
|
|
|
{
|
|
|
|
struct dvb_device *dvbdev = file->private_data;
|
|
|
|
|
|
|
|
if (!dvbdev)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
if (!dvbdev->users)
|
|
|
|
return -EBUSY;
|
|
|
|
|
|
|
|
if ((file->f_flags & O_ACCMODE) == O_RDONLY) {
|
|
|
|
if (!dvbdev->readers)
|
|
|
|
return -EBUSY;
|
|
|
|
dvbdev->readers--;
|
|
|
|
} else {
|
|
|
|
if (!dvbdev->writers)
|
|
|
|
return -EBUSY;
|
|
|
|
dvbdev->writers--;
|
|
|
|
}
|
|
|
|
|
|
|
|
dvbdev->users--;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(dvb_generic_open);
|
|
|
|
|
|
|
|
int dvb_generic_release(struct inode *inode, struct file *file)
|
|
|
|
{
|
|
|
|
struct dvb_device *dvbdev = file->private_data;
|
|
|
|
|
|
|
|
if (!dvbdev)
|
|
|
|
return -ENODEV;
|
|
|
|
|
2023-09-12 15:06:23 +02:00
|
|
|
if ((file->f_flags & O_ACCMODE) == O_RDONLY)
|
2015-08-05 17:22:42 +02:00
|
|
|
dvbdev->readers++;
|
2023-09-12 15:06:23 +02:00
|
|
|
else
|
2015-08-05 17:22:42 +02:00
|
|
|
dvbdev->writers++;
|
|
|
|
|
|
|
|
dvbdev->users++;
|
2023-05-05 13:08:01 +02:00
|
|
|
|
|
|
|
dvb_device_put(dvbdev);
|
|
|
|
|
2015-08-05 17:22:42 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(dvb_generic_release);
|
|
|
|
|
|
|
|
long dvb_generic_ioctl(struct file *file,
|
|
|
|
unsigned int cmd, unsigned long arg)
|
|
|
|
{
|
|
|
|
struct dvb_device *dvbdev = file->private_data;
|
|
|
|
|
|
|
|
if (!dvbdev)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
if (!dvbdev->kernel_ioctl)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
return dvb_usercopy(file, cmd, arg, dvbdev->kernel_ioctl);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(dvb_generic_ioctl);
|
|
|
|
|
2023-09-12 15:06:23 +02:00
|
|
|
static int dvbdev_get_free_id(struct dvb_adapter *adap, int type)
|
2015-08-05 17:22:42 +02:00
|
|
|
{
|
|
|
|
u32 id = 0;
|
|
|
|
|
|
|
|
while (id < DVB_MAX_IDS) {
|
|
|
|
struct dvb_device *dev;
|
2023-09-12 15:06:23 +02:00
|
|
|
|
2015-08-05 17:22:42 +02:00
|
|
|
list_for_each_entry(dev, &adap->device_list, list_head)
|
|
|
|
if (dev->type == type && dev->id == id)
|
|
|
|
goto skip;
|
|
|
|
return id;
|
|
|
|
skip:
|
|
|
|
id++;
|
|
|
|
}
|
|
|
|
return -ENFILE;
|
|
|
|
}
|
|
|
|
|
2017-09-26 21:18:04 +02:00
|
|
|
static void dvb_media_device_free(struct dvb_device *dvbdev)
|
|
|
|
{
|
|
|
|
#if defined(CONFIG_MEDIA_CONTROLLER_DVB)
|
|
|
|
if (dvbdev->entity) {
|
|
|
|
media_device_unregister_entity(dvbdev->entity);
|
|
|
|
kfree(dvbdev->entity);
|
|
|
|
kfree(dvbdev->pads);
|
|
|
|
dvbdev->entity = NULL;
|
|
|
|
dvbdev->pads = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dvbdev->tsout_entity) {
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < dvbdev->tsout_num_entities; i++) {
|
|
|
|
media_device_unregister_entity(&dvbdev->tsout_entity[i]);
|
|
|
|
kfree(dvbdev->tsout_entity[i].name);
|
|
|
|
}
|
|
|
|
kfree(dvbdev->tsout_entity);
|
|
|
|
kfree(dvbdev->tsout_pads);
|
|
|
|
dvbdev->tsout_entity = NULL;
|
|
|
|
dvbdev->tsout_pads = NULL;
|
|
|
|
|
|
|
|
dvbdev->tsout_num_entities = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dvbdev->intf_devnode) {
|
|
|
|
media_devnode_remove(dvbdev->intf_devnode);
|
|
|
|
dvbdev->intf_devnode = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dvbdev->adapter->conn) {
|
|
|
|
media_device_unregister_entity(dvbdev->adapter->conn);
|
2022-01-14 20:13:34 +01:00
|
|
|
kfree(dvbdev->adapter->conn);
|
2017-09-26 21:18:04 +02:00
|
|
|
dvbdev->adapter->conn = NULL;
|
|
|
|
kfree(dvbdev->adapter->conn_pads);
|
|
|
|
dvbdev->adapter->conn_pads = NULL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(CONFIG_MEDIA_CONTROLLER_DVB)
|
|
|
|
static int dvb_create_tsout_entity(struct dvb_device *dvbdev,
|
2023-09-12 15:06:23 +02:00
|
|
|
const char *name, int npads)
|
2017-09-26 21:18:04 +02:00
|
|
|
{
|
2023-05-05 13:08:01 +02:00
|
|
|
int i;
|
2017-09-26 21:18:04 +02:00
|
|
|
|
|
|
|
dvbdev->tsout_pads = kcalloc(npads, sizeof(*dvbdev->tsout_pads),
|
|
|
|
GFP_KERNEL);
|
|
|
|
if (!dvbdev->tsout_pads)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
dvbdev->tsout_entity = kcalloc(npads, sizeof(*dvbdev->tsout_entity),
|
|
|
|
GFP_KERNEL);
|
|
|
|
if (!dvbdev->tsout_entity)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
dvbdev->tsout_num_entities = npads;
|
|
|
|
|
|
|
|
for (i = 0; i < npads; i++) {
|
|
|
|
struct media_pad *pads = &dvbdev->tsout_pads[i];
|
|
|
|
struct media_entity *entity = &dvbdev->tsout_entity[i];
|
2023-05-05 13:08:01 +02:00
|
|
|
int ret;
|
2017-09-26 21:18:04 +02:00
|
|
|
|
|
|
|
entity->name = kasprintf(GFP_KERNEL, "%s #%d", name, i);
|
|
|
|
if (!entity->name)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
entity->function = MEDIA_ENT_F_IO_DTV;
|
|
|
|
pads->flags = MEDIA_PAD_FL_SINK;
|
|
|
|
|
|
|
|
ret = media_entity_pads_init(entity, 1, pads);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret = media_device_register_entity(dvbdev->adapter->mdev,
|
|
|
|
entity);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define DEMUX_TSOUT "demux-tsout"
|
|
|
|
#define DVR_TSOUT "dvr-tsout"
|
|
|
|
|
|
|
|
static int dvb_create_media_entity(struct dvb_device *dvbdev,
|
|
|
|
int type, int demux_sink_pads)
|
|
|
|
{
|
|
|
|
int i, ret, npads;
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case DVB_DEVICE_FRONTEND:
|
|
|
|
npads = 2;
|
|
|
|
break;
|
|
|
|
case DVB_DEVICE_DVR:
|
|
|
|
ret = dvb_create_tsout_entity(dvbdev, DVR_TSOUT,
|
|
|
|
demux_sink_pads);
|
|
|
|
return ret;
|
|
|
|
case DVB_DEVICE_DEMUX:
|
|
|
|
npads = 1 + demux_sink_pads;
|
|
|
|
ret = dvb_create_tsout_entity(dvbdev, DEMUX_TSOUT,
|
|
|
|
demux_sink_pads);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
break;
|
|
|
|
case DVB_DEVICE_CA:
|
|
|
|
npads = 2;
|
|
|
|
break;
|
|
|
|
case DVB_DEVICE_NET:
|
|
|
|
/*
|
|
|
|
* We should be creating entities for the MPE/ULE
|
|
|
|
* decapsulation hardware (or software implementation).
|
|
|
|
*
|
|
|
|
* However, the number of for the MPE/ULE decaps may not be
|
|
|
|
* fixed. As we don't have yet dynamic support for PADs at
|
|
|
|
* the Media Controller, let's not create the decap
|
|
|
|
* entities yet.
|
|
|
|
*/
|
|
|
|
return 0;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
dvbdev->entity = kzalloc(sizeof(*dvbdev->entity), GFP_KERNEL);
|
|
|
|
if (!dvbdev->entity)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
dvbdev->entity->name = dvbdev->name;
|
|
|
|
|
|
|
|
if (npads) {
|
|
|
|
dvbdev->pads = kcalloc(npads, sizeof(*dvbdev->pads),
|
|
|
|
GFP_KERNEL);
|
2022-01-14 20:13:34 +01:00
|
|
|
if (!dvbdev->pads) {
|
2020-08-29 15:32:42 +02:00
|
|
|
kfree(dvbdev->entity);
|
2023-05-05 13:08:01 +02:00
|
|
|
dvbdev->entity = NULL;
|
2017-09-26 21:18:04 +02:00
|
|
|
return -ENOMEM;
|
2020-08-29 15:32:42 +02:00
|
|
|
}
|
2017-09-26 21:18:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case DVB_DEVICE_FRONTEND:
|
|
|
|
dvbdev->entity->function = MEDIA_ENT_F_DTV_DEMOD;
|
|
|
|
dvbdev->pads[0].flags = MEDIA_PAD_FL_SINK;
|
|
|
|
dvbdev->pads[1].flags = MEDIA_PAD_FL_SOURCE;
|
|
|
|
break;
|
|
|
|
case DVB_DEVICE_DEMUX:
|
|
|
|
dvbdev->entity->function = MEDIA_ENT_F_TS_DEMUX;
|
|
|
|
dvbdev->pads[0].flags = MEDIA_PAD_FL_SINK;
|
|
|
|
for (i = 1; i < npads; i++)
|
|
|
|
dvbdev->pads[i].flags = MEDIA_PAD_FL_SOURCE;
|
|
|
|
break;
|
|
|
|
case DVB_DEVICE_CA:
|
|
|
|
dvbdev->entity->function = MEDIA_ENT_F_DTV_CA;
|
|
|
|
dvbdev->pads[0].flags = MEDIA_PAD_FL_SINK;
|
|
|
|
dvbdev->pads[1].flags = MEDIA_PAD_FL_SOURCE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* Should never happen, as the first switch prevents it */
|
|
|
|
kfree(dvbdev->entity);
|
|
|
|
kfree(dvbdev->pads);
|
|
|
|
dvbdev->entity = NULL;
|
|
|
|
dvbdev->pads = NULL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (npads) {
|
|
|
|
ret = media_entity_pads_init(dvbdev->entity, npads, dvbdev->pads);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
ret = media_device_register_entity(dvbdev->adapter->mdev,
|
|
|
|
dvbdev->entity);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
pr_info("%s: media entity '%s' registered.\n",
|
|
|
|
__func__, dvbdev->entity->name);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static int dvb_register_media_device(struct dvb_device *dvbdev,
|
|
|
|
int type, int minor,
|
2023-09-12 15:06:23 +02:00
|
|
|
unsigned int demux_sink_pads)
|
2017-09-26 21:18:04 +02:00
|
|
|
{
|
|
|
|
#if defined(CONFIG_MEDIA_CONTROLLER_DVB)
|
|
|
|
struct media_link *link;
|
|
|
|
u32 intf_type;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!dvbdev->adapter->mdev)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
ret = dvb_create_media_entity(dvbdev, type, demux_sink_pads);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case DVB_DEVICE_FRONTEND:
|
|
|
|
intf_type = MEDIA_INTF_T_DVB_FE;
|
|
|
|
break;
|
|
|
|
case DVB_DEVICE_DEMUX:
|
|
|
|
intf_type = MEDIA_INTF_T_DVB_DEMUX;
|
|
|
|
break;
|
|
|
|
case DVB_DEVICE_DVR:
|
|
|
|
intf_type = MEDIA_INTF_T_DVB_DVR;
|
|
|
|
break;
|
|
|
|
case DVB_DEVICE_CA:
|
|
|
|
intf_type = MEDIA_INTF_T_DVB_CA;
|
|
|
|
break;
|
|
|
|
case DVB_DEVICE_NET:
|
|
|
|
intf_type = MEDIA_INTF_T_DVB_NET;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
dvbdev->intf_devnode = media_devnode_create(dvbdev->adapter->mdev,
|
|
|
|
intf_type, 0,
|
|
|
|
DVB_MAJOR, minor);
|
|
|
|
|
|
|
|
if (!dvbdev->intf_devnode)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create the "obvious" link, e. g. the ones that represent
|
|
|
|
* a direct association between an interface and an entity.
|
|
|
|
* Other links should be created elsewhere, like:
|
|
|
|
* DVB FE intf -> tuner
|
|
|
|
* DVB demux intf -> dvr
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (!dvbdev->entity)
|
|
|
|
return 0;
|
|
|
|
|
2020-08-29 15:32:42 +02:00
|
|
|
link = media_create_intf_link(dvbdev->entity,
|
|
|
|
&dvbdev->intf_devnode->intf,
|
|
|
|
MEDIA_LNK_FL_ENABLED |
|
|
|
|
MEDIA_LNK_FL_IMMUTABLE);
|
2017-09-26 21:18:04 +02:00
|
|
|
if (!link)
|
|
|
|
return -ENOMEM;
|
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
2015-08-05 17:22:42 +02:00
|
|
|
|
|
|
|
int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
|
2020-08-29 15:32:42 +02:00
|
|
|
const struct dvb_device *template, void *priv,
|
|
|
|
enum dvb_device_type type, int demux_sink_pads)
|
2015-08-05 17:22:42 +02:00
|
|
|
{
|
|
|
|
struct dvb_device *dvbdev;
|
2023-09-12 15:06:23 +02:00
|
|
|
struct file_operations *dvbdevfops = NULL;
|
|
|
|
struct dvbdevfops_node *node = NULL, *new_node = NULL;
|
2015-08-05 17:22:42 +02:00
|
|
|
struct device *clsdev;
|
|
|
|
int minor;
|
2017-09-26 21:18:04 +02:00
|
|
|
int id, ret;
|
2015-08-05 17:22:42 +02:00
|
|
|
|
|
|
|
mutex_lock(&dvbdev_register_lock);
|
|
|
|
|
2023-09-12 15:06:23 +02:00
|
|
|
id = dvbdev_get_free_id(adap, type);
|
|
|
|
if (id < 0) {
|
2015-08-05 17:22:42 +02:00
|
|
|
mutex_unlock(&dvbdev_register_lock);
|
|
|
|
*pdvbdev = NULL;
|
2017-09-26 21:18:04 +02:00
|
|
|
pr_err("%s: couldn't find free device id\n", __func__);
|
2015-08-05 17:22:42 +02:00
|
|
|
return -ENFILE;
|
|
|
|
}
|
|
|
|
|
2017-09-26 21:18:04 +02:00
|
|
|
*pdvbdev = dvbdev = kzalloc(sizeof(*dvbdev), GFP_KERNEL);
|
2023-09-12 15:06:23 +02:00
|
|
|
if (!dvbdev) {
|
2015-08-05 17:22:42 +02:00
|
|
|
mutex_unlock(&dvbdev_register_lock);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2023-09-12 15:06:23 +02:00
|
|
|
/*
|
|
|
|
* When a device of the same type is probe()d more than once,
|
|
|
|
* the first allocated fops are used. This prevents memory leaks
|
|
|
|
* that can occur when the same device is probe()d repeatedly.
|
|
|
|
*/
|
|
|
|
list_for_each_entry(node, &dvbdevfops_list, list_head) {
|
|
|
|
if (node->fops->owner == adap->module &&
|
|
|
|
node->type == type && node->template == template) {
|
|
|
|
dvbdevfops = node->fops;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!dvbdevfops) {
|
|
|
|
dvbdevfops = kmemdup(template->fops, sizeof(*dvbdevfops), GFP_KERNEL);
|
|
|
|
if (!dvbdevfops) {
|
|
|
|
kfree(dvbdev);
|
|
|
|
mutex_unlock(&dvbdev_register_lock);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2015-08-05 17:22:42 +02:00
|
|
|
|
2023-09-12 15:06:23 +02:00
|
|
|
new_node = kzalloc(sizeof(*new_node), GFP_KERNEL);
|
|
|
|
if (!new_node) {
|
|
|
|
kfree(dvbdevfops);
|
|
|
|
kfree(dvbdev);
|
|
|
|
mutex_unlock(&dvbdev_register_lock);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
new_node->fops = dvbdevfops;
|
|
|
|
new_node->type = type;
|
|
|
|
new_node->template = template;
|
|
|
|
list_add_tail(&new_node->list_head, &dvbdevfops_list);
|
2015-08-05 17:22:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(dvbdev, template, sizeof(struct dvb_device));
|
2023-05-05 13:08:01 +02:00
|
|
|
kref_init(&dvbdev->ref);
|
2015-08-05 17:22:42 +02:00
|
|
|
dvbdev->type = type;
|
|
|
|
dvbdev->id = id;
|
|
|
|
dvbdev->adapter = adap;
|
|
|
|
dvbdev->priv = priv;
|
|
|
|
dvbdev->fops = dvbdevfops;
|
2023-09-12 15:06:23 +02:00
|
|
|
init_waitqueue_head(&dvbdev->wait_queue);
|
2015-08-05 17:22:42 +02:00
|
|
|
dvbdevfops->owner = adap->module;
|
2023-09-12 15:06:23 +02:00
|
|
|
list_add_tail(&dvbdev->list_head, &adap->device_list);
|
2015-08-05 17:22:42 +02:00
|
|
|
down_write(&minor_rwsem);
|
|
|
|
#ifdef CONFIG_DVB_DYNAMIC_MINORS
|
|
|
|
for (minor = 0; minor < MAX_DVB_MINORS; minor++)
|
2023-09-12 15:06:23 +02:00
|
|
|
if (!dvb_minors[minor])
|
2015-08-05 17:22:42 +02:00
|
|
|
break;
|
|
|
|
if (minor == MAX_DVB_MINORS) {
|
2023-09-12 15:06:23 +02:00
|
|
|
if (new_node) {
|
|
|
|
list_del(&new_node->list_head);
|
|
|
|
kfree(dvbdevfops);
|
|
|
|
kfree(new_node);
|
|
|
|
}
|
|
|
|
list_del(&dvbdev->list_head);
|
2015-08-05 17:22:42 +02:00
|
|
|
kfree(dvbdev);
|
|
|
|
up_write(&minor_rwsem);
|
|
|
|
mutex_unlock(&dvbdev_register_lock);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
minor = nums2minor(adap->num, type, id);
|
|
|
|
#endif
|
|
|
|
dvbdev->minor = minor;
|
2023-05-05 13:08:01 +02:00
|
|
|
dvb_minors[minor] = dvb_device_get(dvbdev);
|
2015-08-05 17:22:42 +02:00
|
|
|
up_write(&minor_rwsem);
|
2017-09-26 21:18:04 +02:00
|
|
|
ret = dvb_register_media_device(dvbdev, type, minor, demux_sink_pads);
|
|
|
|
if (ret) {
|
|
|
|
pr_err("%s: dvb_register_media_device failed to create the mediagraph\n",
|
2023-09-12 15:06:23 +02:00
|
|
|
__func__);
|
|
|
|
if (new_node) {
|
|
|
|
list_del(&new_node->list_head);
|
|
|
|
kfree(dvbdevfops);
|
|
|
|
kfree(new_node);
|
|
|
|
}
|
2017-09-26 21:18:04 +02:00
|
|
|
dvb_media_device_free(dvbdev);
|
2023-09-12 15:06:23 +02:00
|
|
|
list_del(&dvbdev->list_head);
|
2017-09-26 21:18:04 +02:00
|
|
|
kfree(dvbdev);
|
|
|
|
mutex_unlock(&dvbdev_register_lock);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-08-05 17:22:42 +02:00
|
|
|
clsdev = device_create(dvb_class, adap->device,
|
|
|
|
MKDEV(DVB_MAJOR, minor),
|
|
|
|
dvbdev, "dvb%d.%s%d", adap->num, dnames[type], id);
|
|
|
|
if (IS_ERR(clsdev)) {
|
2017-09-26 21:18:04 +02:00
|
|
|
pr_err("%s: failed to create device dvb%d.%s%d (%ld)\n",
|
2015-08-05 17:22:42 +02:00
|
|
|
__func__, adap->num, dnames[type], id, PTR_ERR(clsdev));
|
2023-09-12 15:06:23 +02:00
|
|
|
if (new_node) {
|
|
|
|
list_del(&new_node->list_head);
|
|
|
|
kfree(dvbdevfops);
|
|
|
|
kfree(new_node);
|
|
|
|
}
|
2022-01-14 20:13:34 +01:00
|
|
|
dvb_media_device_free(dvbdev);
|
2023-09-12 15:06:23 +02:00
|
|
|
list_del(&dvbdev->list_head);
|
2022-01-14 20:13:34 +01:00
|
|
|
kfree(dvbdev);
|
2023-09-12 15:06:23 +02:00
|
|
|
mutex_unlock(&dvbdev_register_lock);
|
2015-08-05 17:22:42 +02:00
|
|
|
return PTR_ERR(clsdev);
|
|
|
|
}
|
2023-09-12 15:06:23 +02:00
|
|
|
|
2017-09-26 21:18:04 +02:00
|
|
|
dprintk("DVB: register adapter%d/%s%d @ minor: %i (0x%02x)\n",
|
2015-08-05 17:22:42 +02:00
|
|
|
adap->num, dnames[type], id, minor, minor);
|
|
|
|
|
2023-09-12 15:06:23 +02:00
|
|
|
mutex_unlock(&dvbdev_register_lock);
|
2015-08-05 17:22:42 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(dvb_register_device);
|
|
|
|
|
2017-09-26 21:18:04 +02:00
|
|
|
void dvb_remove_device(struct dvb_device *dvbdev)
|
2015-08-05 17:22:42 +02:00
|
|
|
{
|
|
|
|
if (!dvbdev)
|
|
|
|
return;
|
|
|
|
|
|
|
|
down_write(&minor_rwsem);
|
|
|
|
dvb_minors[dvbdev->minor] = NULL;
|
2023-05-05 13:08:01 +02:00
|
|
|
dvb_device_put(dvbdev);
|
2015-08-05 17:22:42 +02:00
|
|
|
up_write(&minor_rwsem);
|
|
|
|
|
2017-09-26 21:18:04 +02:00
|
|
|
dvb_media_device_free(dvbdev);
|
|
|
|
|
2015-08-05 17:22:42 +02:00
|
|
|
device_destroy(dvb_class, MKDEV(DVB_MAJOR, dvbdev->minor));
|
|
|
|
|
2023-09-12 15:06:23 +02:00
|
|
|
list_del(&dvbdev->list_head);
|
2017-09-26 21:18:04 +02:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(dvb_remove_device);
|
|
|
|
|
2023-05-05 13:08:01 +02:00
|
|
|
static void dvb_free_device(struct kref *ref)
|
2017-09-26 21:18:04 +02:00
|
|
|
{
|
2023-05-05 13:08:01 +02:00
|
|
|
struct dvb_device *dvbdev = container_of(ref, struct dvb_device, ref);
|
2017-09-26 21:18:04 +02:00
|
|
|
|
2023-09-12 15:06:23 +02:00
|
|
|
kfree(dvbdev);
|
2015-08-05 17:22:42 +02:00
|
|
|
}
|
2023-05-05 13:08:01 +02:00
|
|
|
|
|
|
|
struct dvb_device *dvb_device_get(struct dvb_device *dvbdev)
|
|
|
|
{
|
|
|
|
kref_get(&dvbdev->ref);
|
|
|
|
return dvbdev;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(dvb_device_get);
|
|
|
|
|
|
|
|
void dvb_device_put(struct dvb_device *dvbdev)
|
|
|
|
{
|
|
|
|
if (dvbdev)
|
|
|
|
kref_put(&dvbdev->ref, dvb_free_device);
|
|
|
|
}
|
2017-09-26 21:18:04 +02:00
|
|
|
|
|
|
|
void dvb_unregister_device(struct dvb_device *dvbdev)
|
|
|
|
{
|
|
|
|
dvb_remove_device(dvbdev);
|
2023-05-05 13:08:01 +02:00
|
|
|
dvb_device_put(dvbdev);
|
2017-09-26 21:18:04 +02:00
|
|
|
}
|
2015-08-05 17:22:42 +02:00
|
|
|
EXPORT_SYMBOL(dvb_unregister_device);
|
|
|
|
|
2017-09-26 21:18:04 +02:00
|
|
|
#ifdef CONFIG_MEDIA_CONTROLLER_DVB
|
|
|
|
|
|
|
|
static int dvb_create_io_intf_links(struct dvb_adapter *adap,
|
|
|
|
struct media_interface *intf,
|
|
|
|
char *name)
|
|
|
|
{
|
|
|
|
struct media_device *mdev = adap->mdev;
|
|
|
|
struct media_entity *entity;
|
|
|
|
struct media_link *link;
|
|
|
|
|
|
|
|
media_device_for_each_entity(entity, mdev) {
|
|
|
|
if (entity->function == MEDIA_ENT_F_IO_DTV) {
|
|
|
|
if (strncmp(entity->name, name, strlen(name)))
|
|
|
|
continue;
|
|
|
|
link = media_create_intf_link(entity, intf,
|
2020-08-29 15:32:42 +02:00
|
|
|
MEDIA_LNK_FL_ENABLED |
|
|
|
|
MEDIA_LNK_FL_IMMUTABLE);
|
2017-09-26 21:18:04 +02:00
|
|
|
if (!link)
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int dvb_create_media_graph(struct dvb_adapter *adap,
|
|
|
|
bool create_rf_connector)
|
|
|
|
{
|
|
|
|
struct media_device *mdev = adap->mdev;
|
|
|
|
struct media_entity *entity, *tuner = NULL, *demod = NULL, *conn;
|
|
|
|
struct media_entity *demux = NULL, *ca = NULL;
|
|
|
|
struct media_link *link;
|
|
|
|
struct media_interface *intf;
|
2023-09-12 15:06:23 +02:00
|
|
|
unsigned int demux_pad = 0;
|
|
|
|
unsigned int dvr_pad = 0;
|
|
|
|
unsigned int ntuner = 0, ndemod = 0;
|
2020-08-29 15:32:42 +02:00
|
|
|
int ret, pad_source, pad_sink;
|
2017-09-26 21:18:04 +02:00
|
|
|
static const char *connector_name = "Television";
|
|
|
|
|
|
|
|
if (!mdev)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
media_device_for_each_entity(entity, mdev) {
|
|
|
|
switch (entity->function) {
|
|
|
|
case MEDIA_ENT_F_TUNER:
|
|
|
|
tuner = entity;
|
|
|
|
ntuner++;
|
|
|
|
break;
|
|
|
|
case MEDIA_ENT_F_DTV_DEMOD:
|
|
|
|
demod = entity;
|
|
|
|
ndemod++;
|
|
|
|
break;
|
|
|
|
case MEDIA_ENT_F_TS_DEMUX:
|
|
|
|
demux = entity;
|
|
|
|
break;
|
|
|
|
case MEDIA_ENT_F_DTV_CA:
|
|
|
|
ca = entity;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Prepare to signalize to media_create_pad_links() that multiple
|
|
|
|
* entities of the same type exists and a 1:n or n:1 links need to be
|
|
|
|
* created.
|
|
|
|
* NOTE: if both tuner and demod have multiple instances, it is up
|
|
|
|
* to the caller driver to create such links.
|
|
|
|
*/
|
|
|
|
if (ntuner > 1)
|
|
|
|
tuner = NULL;
|
|
|
|
if (ndemod > 1)
|
|
|
|
demod = NULL;
|
|
|
|
|
|
|
|
if (create_rf_connector) {
|
|
|
|
conn = kzalloc(sizeof(*conn), GFP_KERNEL);
|
|
|
|
if (!conn)
|
|
|
|
return -ENOMEM;
|
|
|
|
adap->conn = conn;
|
|
|
|
|
|
|
|
adap->conn_pads = kzalloc(sizeof(*adap->conn_pads), GFP_KERNEL);
|
|
|
|
if (!adap->conn_pads)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
conn->flags = MEDIA_ENT_FL_CONNECTOR;
|
|
|
|
conn->function = MEDIA_ENT_F_CONN_RF;
|
|
|
|
conn->name = connector_name;
|
|
|
|
adap->conn_pads->flags = MEDIA_PAD_FL_SOURCE;
|
|
|
|
|
|
|
|
ret = media_entity_pads_init(conn, 1, adap->conn_pads);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret = media_device_register_entity(mdev, conn);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2022-01-14 20:13:34 +01:00
|
|
|
|
2019-07-24 07:03:02 +02:00
|
|
|
if (!ntuner) {
|
2017-09-26 21:18:04 +02:00
|
|
|
ret = media_create_pad_links(mdev,
|
|
|
|
MEDIA_ENT_F_CONN_RF,
|
|
|
|
conn, 0,
|
|
|
|
MEDIA_ENT_F_DTV_DEMOD,
|
|
|
|
demod, 0,
|
|
|
|
MEDIA_LNK_FL_ENABLED,
|
|
|
|
false);
|
2019-07-24 07:03:02 +02:00
|
|
|
} else {
|
2020-08-29 15:32:42 +02:00
|
|
|
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,2,0))
|
2023-09-12 15:06:23 +02:00
|
|
|
pad_sink = media_get_pad_index(tuner, MEDIA_PAD_FL_SINK,
|
2020-08-29 15:32:42 +02:00
|
|
|
PAD_SIGNAL_ANALOG);
|
|
|
|
if (pad_sink < 0)
|
|
|
|
return -EINVAL;
|
2017-09-26 21:18:04 +02:00
|
|
|
ret = media_create_pad_links(mdev,
|
|
|
|
MEDIA_ENT_F_CONN_RF,
|
|
|
|
conn, 0,
|
|
|
|
MEDIA_ENT_F_TUNER,
|
2020-08-29 15:32:42 +02:00
|
|
|
tuner, pad_sink,
|
2017-09-26 21:18:04 +02:00
|
|
|
MEDIA_LNK_FL_ENABLED,
|
|
|
|
false);
|
2020-08-29 15:32:42 +02:00
|
|
|
#else
|
|
|
|
pad_sink = TUNER_PAD_RF_INPUT;
|
|
|
|
#endif
|
2019-07-24 07:03:02 +02:00
|
|
|
}
|
2017-09-26 21:18:04 +02:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ntuner && ndemod) {
|
2019-07-24 07:03:02 +02:00
|
|
|
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,2,0))
|
2020-08-29 15:32:42 +02:00
|
|
|
/* NOTE: first found tuner source pad presumed correct */
|
2023-09-12 15:06:23 +02:00
|
|
|
pad_source = media_get_pad_index(tuner, MEDIA_PAD_FL_SOURCE,
|
2020-08-29 15:32:42 +02:00
|
|
|
PAD_SIGNAL_ANALOG);
|
|
|
|
if (pad_source < 0)
|
|
|
|
return -EINVAL;
|
2019-07-24 07:03:02 +02:00
|
|
|
#else
|
2020-08-29 15:32:42 +02:00
|
|
|
pad_source = TUNER_PAD_OUTPUT;
|
2019-07-24 07:03:02 +02:00
|
|
|
#endif
|
|
|
|
|
2017-09-26 21:18:04 +02:00
|
|
|
ret = media_create_pad_links(mdev,
|
|
|
|
MEDIA_ENT_F_TUNER,
|
2020-08-29 15:32:42 +02:00
|
|
|
tuner, pad_source,
|
2017-09-26 21:18:04 +02:00
|
|
|
MEDIA_ENT_F_DTV_DEMOD,
|
|
|
|
demod, 0, MEDIA_LNK_FL_ENABLED,
|
|
|
|
false);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ndemod && demux) {
|
|
|
|
ret = media_create_pad_links(mdev,
|
|
|
|
MEDIA_ENT_F_DTV_DEMOD,
|
|
|
|
demod, 1,
|
|
|
|
MEDIA_ENT_F_TS_DEMUX,
|
|
|
|
demux, 0, MEDIA_LNK_FL_ENABLED,
|
|
|
|
false);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
if (demux && ca) {
|
|
|
|
ret = media_create_pad_link(demux, 1, ca,
|
|
|
|
0, MEDIA_LNK_FL_ENABLED);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Create demux links for each ringbuffer/pad */
|
|
|
|
if (demux) {
|
|
|
|
media_device_for_each_entity(entity, mdev) {
|
|
|
|
if (entity->function == MEDIA_ENT_F_IO_DTV) {
|
|
|
|
if (!strncmp(entity->name, DVR_TSOUT,
|
2023-09-12 15:06:23 +02:00
|
|
|
strlen(DVR_TSOUT))) {
|
2017-09-26 21:18:04 +02:00
|
|
|
ret = media_create_pad_link(demux,
|
2023-09-12 15:06:23 +02:00
|
|
|
++dvr_pad,
|
|
|
|
entity, 0, 0);
|
2017-09-26 21:18:04 +02:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
if (!strncmp(entity->name, DEMUX_TSOUT,
|
2023-09-12 15:06:23 +02:00
|
|
|
strlen(DEMUX_TSOUT))) {
|
2017-09-26 21:18:04 +02:00
|
|
|
ret = media_create_pad_link(demux,
|
2023-09-12 15:06:23 +02:00
|
|
|
++demux_pad,
|
|
|
|
entity, 0, 0);
|
2017-09-26 21:18:04 +02:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Create interface links for FE->tuner, DVR->demux and CA->ca */
|
|
|
|
media_device_for_each_intf(intf, mdev) {
|
|
|
|
if (intf->type == MEDIA_INTF_T_DVB_CA && ca) {
|
|
|
|
link = media_create_intf_link(ca, intf,
|
2020-08-29 15:32:42 +02:00
|
|
|
MEDIA_LNK_FL_ENABLED |
|
|
|
|
MEDIA_LNK_FL_IMMUTABLE);
|
2017-09-26 21:18:04 +02:00
|
|
|
if (!link)
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (intf->type == MEDIA_INTF_T_DVB_FE && tuner) {
|
|
|
|
link = media_create_intf_link(tuner, intf,
|
2020-08-29 15:32:42 +02:00
|
|
|
MEDIA_LNK_FL_ENABLED |
|
|
|
|
MEDIA_LNK_FL_IMMUTABLE);
|
2017-09-26 21:18:04 +02:00
|
|
|
if (!link)
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
#if 0
|
|
|
|
/*
|
|
|
|
* Indirect link - let's not create yet, as we don't know how
|
|
|
|
* to handle indirect links, nor if this will
|
|
|
|
* actually be needed.
|
|
|
|
*/
|
|
|
|
if (intf->type == MEDIA_INTF_T_DVB_DVR && demux) {
|
|
|
|
link = media_create_intf_link(demux, intf,
|
2020-08-29 15:32:42 +02:00
|
|
|
MEDIA_LNK_FL_ENABLED |
|
|
|
|
MEDIA_LNK_FL_IMMUTABLE);
|
2017-09-26 21:18:04 +02:00
|
|
|
if (!link)
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (intf->type == MEDIA_INTF_T_DVB_DVR) {
|
|
|
|
ret = dvb_create_io_intf_links(adap, intf, DVR_TSOUT);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
if (intf->type == MEDIA_INTF_T_DVB_DEMUX) {
|
|
|
|
ret = dvb_create_io_intf_links(adap, intf, DEMUX_TSOUT);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(dvb_create_media_graph);
|
|
|
|
#endif
|
|
|
|
|
2015-08-05 17:22:42 +02:00
|
|
|
static int dvbdev_check_free_adapter_num(int num)
|
|
|
|
{
|
|
|
|
struct list_head *entry;
|
2023-09-12 15:06:23 +02:00
|
|
|
|
2015-08-05 17:22:42 +02:00
|
|
|
list_for_each(entry, &dvb_adapter_list) {
|
|
|
|
struct dvb_adapter *adap;
|
2023-09-12 15:06:23 +02:00
|
|
|
|
2015-08-05 17:22:42 +02:00
|
|
|
adap = list_entry(entry, struct dvb_adapter, list_head);
|
|
|
|
if (adap->num == num)
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2023-09-12 15:06:23 +02:00
|
|
|
static int dvbdev_get_free_adapter_num(void)
|
2015-08-05 17:22:42 +02:00
|
|
|
{
|
|
|
|
int num = 0;
|
|
|
|
|
|
|
|
while (num < DVB_MAX_ADAPTERS) {
|
|
|
|
if (dvbdev_check_free_adapter_num(num))
|
|
|
|
return num;
|
|
|
|
num++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -ENFILE;
|
|
|
|
}
|
|
|
|
|
|
|
|
int dvb_register_adapter(struct dvb_adapter *adap, const char *name,
|
|
|
|
struct module *module, struct device *device,
|
|
|
|
short *adapter_nums)
|
|
|
|
{
|
|
|
|
int i, num;
|
|
|
|
|
|
|
|
mutex_lock(&dvbdev_register_lock);
|
|
|
|
|
|
|
|
for (i = 0; i < DVB_MAX_ADAPTERS; ++i) {
|
|
|
|
num = adapter_nums[i];
|
|
|
|
if (num >= 0 && num < DVB_MAX_ADAPTERS) {
|
|
|
|
/* use the one the driver asked for */
|
|
|
|
if (dvbdev_check_free_adapter_num(num))
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
num = dvbdev_get_free_adapter_num();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
num = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (num < 0) {
|
|
|
|
mutex_unlock(&dvbdev_register_lock);
|
|
|
|
return -ENFILE;
|
|
|
|
}
|
|
|
|
|
2023-09-12 15:06:23 +02:00
|
|
|
memset(adap, 0, sizeof(struct dvb_adapter));
|
|
|
|
INIT_LIST_HEAD(&adap->device_list);
|
2015-08-05 17:22:42 +02:00
|
|
|
|
2017-09-26 21:18:04 +02:00
|
|
|
pr_info("DVB: registering new adapter (%s)\n", name);
|
2015-08-05 17:22:42 +02:00
|
|
|
|
|
|
|
adap->num = num;
|
|
|
|
adap->name = name;
|
|
|
|
adap->module = module;
|
|
|
|
adap->device = device;
|
|
|
|
adap->mfe_shared = 0;
|
|
|
|
adap->mfe_dvbdev = NULL;
|
2023-09-12 15:06:23 +02:00
|
|
|
mutex_init(&adap->mfe_lock);
|
2015-08-05 17:22:42 +02:00
|
|
|
|
2020-08-29 15:32:42 +02:00
|
|
|
#ifdef CONFIG_MEDIA_CONTROLLER_DVB
|
|
|
|
mutex_init(&adap->mdev_lock);
|
|
|
|
#endif
|
|
|
|
|
2023-09-12 15:06:23 +02:00
|
|
|
list_add_tail(&adap->list_head, &dvb_adapter_list);
|
2015-08-05 17:22:42 +02:00
|
|
|
|
|
|
|
mutex_unlock(&dvbdev_register_lock);
|
|
|
|
|
|
|
|
return num;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(dvb_register_adapter);
|
|
|
|
|
|
|
|
int dvb_unregister_adapter(struct dvb_adapter *adap)
|
|
|
|
{
|
|
|
|
mutex_lock(&dvbdev_register_lock);
|
2023-09-12 15:06:23 +02:00
|
|
|
list_del(&adap->list_head);
|
2015-08-05 17:22:42 +02:00
|
|
|
mutex_unlock(&dvbdev_register_lock);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(dvb_unregister_adapter);
|
|
|
|
|
2023-09-12 15:06:23 +02:00
|
|
|
/*
|
|
|
|
* if the miracle happens and "generic_usercopy()" is included into
|
|
|
|
* the kernel, then this can vanish. please don't make the mistake and
|
|
|
|
* define this as video_usercopy(). this will introduce a dependency
|
|
|
|
* to the v4l "videodev.o" module, which is unnecessary for some
|
|
|
|
* cards (ie. the budget dvb-cards don't need the v4l module...)
|
|
|
|
*/
|
2015-08-05 17:22:42 +02:00
|
|
|
int dvb_usercopy(struct file *file,
|
2023-09-12 15:06:23 +02:00
|
|
|
unsigned int cmd, unsigned long arg,
|
|
|
|
int (*func)(struct file *file,
|
|
|
|
unsigned int cmd, void *arg))
|
2015-08-05 17:22:42 +02:00
|
|
|
{
|
|
|
|
char sbuf[128];
|
|
|
|
void *mbuf = NULL;
|
|
|
|
void *parg = NULL;
|
|
|
|
int err = -EINVAL;
|
|
|
|
|
|
|
|
/* Copy arguments into temp kernel buffer */
|
|
|
|
switch (_IOC_DIR(cmd)) {
|
|
|
|
case _IOC_NONE:
|
|
|
|
/*
|
|
|
|
* For this command, the pointer is actually an integer
|
|
|
|
* argument.
|
|
|
|
*/
|
2023-09-12 15:06:23 +02:00
|
|
|
parg = (void *)arg;
|
2015-08-05 17:22:42 +02:00
|
|
|
break;
|
|
|
|
case _IOC_READ: /* some v4l ioctls are marked wrong ... */
|
|
|
|
case _IOC_WRITE:
|
|
|
|
case (_IOC_WRITE | _IOC_READ):
|
|
|
|
if (_IOC_SIZE(cmd) <= sizeof(sbuf)) {
|
|
|
|
parg = sbuf;
|
|
|
|
} else {
|
|
|
|
/* too big to allocate from stack */
|
2017-09-26 21:18:04 +02:00
|
|
|
mbuf = kmalloc(_IOC_SIZE(cmd), GFP_KERNEL);
|
2023-09-12 15:06:23 +02:00
|
|
|
if (!mbuf)
|
2015-08-05 17:22:42 +02:00
|
|
|
return -ENOMEM;
|
|
|
|
parg = mbuf;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = -EFAULT;
|
|
|
|
if (copy_from_user(parg, (void __user *)arg, _IOC_SIZE(cmd)))
|
|
|
|
goto out;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* call driver */
|
2023-09-12 15:06:23 +02:00
|
|
|
err = func(file, cmd, parg);
|
|
|
|
if (err == -ENOIOCTLCMD)
|
2015-08-05 17:22:42 +02:00
|
|
|
err = -ENOTTY;
|
|
|
|
|
|
|
|
if (err < 0)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/* Copy results into user buffer */
|
2023-09-12 15:06:23 +02:00
|
|
|
switch (_IOC_DIR(cmd)) {
|
2015-08-05 17:22:42 +02:00
|
|
|
case _IOC_READ:
|
|
|
|
case (_IOC_WRITE | _IOC_READ):
|
|
|
|
if (copy_to_user((void __user *)arg, parg, _IOC_SIZE(cmd)))
|
|
|
|
err = -EFAULT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
kfree(mbuf);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2020-08-29 15:32:42 +02:00
|
|
|
#if IS_ENABLED(CONFIG_I2C)
|
2020-10-16 14:32:47 +02:00
|
|
|
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,5,0))
|
2020-08-29 15:32:42 +02:00
|
|
|
struct i2c_client *dvb_module_probe(const char *module_name,
|
|
|
|
const char *name,
|
|
|
|
struct i2c_adapter *adap,
|
|
|
|
unsigned char addr,
|
|
|
|
void *platform_data)
|
|
|
|
{
|
2022-01-14 20:13:34 +01:00
|
|
|
struct i2c_client *client;
|
2020-08-29 15:32:42 +02:00
|
|
|
struct i2c_board_info *board_info;
|
|
|
|
|
|
|
|
board_info = kzalloc(sizeof(*board_info), GFP_KERNEL);
|
|
|
|
if (!board_info)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (name)
|
|
|
|
strscpy(board_info->type, name, I2C_NAME_SIZE);
|
|
|
|
else
|
|
|
|
strscpy(board_info->type, module_name, I2C_NAME_SIZE);
|
|
|
|
|
|
|
|
board_info->addr = addr;
|
|
|
|
board_info->platform_data = platform_data;
|
|
|
|
request_module(module_name);
|
|
|
|
client = i2c_new_client_device(adap, board_info);
|
|
|
|
if (!i2c_client_has_driver(client)) {
|
|
|
|
kfree(board_info);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!try_module_get(client->dev.driver->owner)) {
|
|
|
|
i2c_unregister_device(client);
|
|
|
|
client = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
kfree(board_info);
|
|
|
|
return client;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(dvb_module_probe);
|
|
|
|
|
|
|
|
void dvb_module_release(struct i2c_client *client)
|
|
|
|
{
|
|
|
|
if (!client)
|
|
|
|
return;
|
|
|
|
|
|
|
|
module_put(client->dev.driver->owner);
|
|
|
|
i2c_unregister_device(client);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(dvb_module_release);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2023-05-05 13:08:01 +02:00
|
|
|
#if (KERNEL_VERSION(6, 2, 0) > LINUX_VERSION_CODE)
|
2015-08-05 17:22:42 +02:00
|
|
|
static int dvb_uevent(struct device *dev, struct kobj_uevent_env *env)
|
2023-05-05 13:08:01 +02:00
|
|
|
#else
|
|
|
|
static int dvb_uevent(const struct device *dev, struct kobj_uevent_env *env)
|
|
|
|
#endif
|
2015-08-05 17:22:42 +02:00
|
|
|
{
|
2023-05-05 13:08:01 +02:00
|
|
|
const struct dvb_device *dvbdev = dev_get_drvdata(dev);
|
2015-08-05 17:22:42 +02:00
|
|
|
|
|
|
|
add_uevent_var(env, "DVB_ADAPTER_NUM=%d", dvbdev->adapter->num);
|
|
|
|
add_uevent_var(env, "DVB_DEVICE_TYPE=%s", dnames[dvbdev->type]);
|
|
|
|
add_uevent_var(env, "DVB_DEVICE_NUM=%d", dvbdev->id);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-05-05 13:08:01 +02:00
|
|
|
#if (KERNEL_VERSION(6, 2, 0) > LINUX_VERSION_CODE)
|
2015-08-05 17:22:42 +02:00
|
|
|
static char *dvb_devnode(struct device *dev, umode_t *mode)
|
2023-05-05 13:08:01 +02:00
|
|
|
#else
|
|
|
|
static char *dvb_devnode(const struct device *dev, umode_t *mode)
|
|
|
|
#endif
|
2015-08-05 17:22:42 +02:00
|
|
|
{
|
2023-05-05 13:08:01 +02:00
|
|
|
const struct dvb_device *dvbdev = dev_get_drvdata(dev);
|
2015-08-05 17:22:42 +02:00
|
|
|
|
|
|
|
return kasprintf(GFP_KERNEL, "dvb/adapter%d/%s%d",
|
|
|
|
dvbdev->adapter->num, dnames[dvbdev->type], dvbdev->id);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int __init init_dvbdev(void)
|
|
|
|
{
|
|
|
|
int retval;
|
|
|
|
dev_t dev = MKDEV(DVB_MAJOR, 0);
|
|
|
|
|
2023-09-12 15:06:23 +02:00
|
|
|
retval = register_chrdev_region(dev, MAX_DVB_MINORS, "DVB");
|
|
|
|
if (retval != 0) {
|
2017-09-26 21:18:04 +02:00
|
|
|
pr_err("dvb-core: unable to get major %d\n", DVB_MAJOR);
|
2015-08-05 17:22:42 +02:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
cdev_init(&dvb_device_cdev, &dvb_device_fops);
|
2023-09-12 15:06:23 +02:00
|
|
|
retval = cdev_add(&dvb_device_cdev, dev, MAX_DVB_MINORS);
|
|
|
|
if (retval != 0) {
|
2017-09-26 21:18:04 +02:00
|
|
|
pr_err("dvb-core: unable register character device\n");
|
2015-08-05 17:22:42 +02:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2023-07-31 22:08:22 +02:00
|
|
|
#if (LINUX_VERSION_CODE < KERNEL_VERSION(6,4,0))
|
2015-08-05 17:22:42 +02:00
|
|
|
dvb_class = class_create(THIS_MODULE, "dvb");
|
2023-07-31 22:08:22 +02:00
|
|
|
#else
|
|
|
|
dvb_class = class_create("dvb");
|
|
|
|
#endif
|
2015-08-05 17:22:42 +02:00
|
|
|
if (IS_ERR(dvb_class)) {
|
|
|
|
retval = PTR_ERR(dvb_class);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
dvb_class->dev_uevent = dvb_uevent;
|
|
|
|
dvb_class->devnode = dvb_devnode;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
error:
|
|
|
|
cdev_del(&dvb_device_cdev);
|
|
|
|
unregister_chrdev_region(dev, MAX_DVB_MINORS);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit exit_dvbdev(void)
|
|
|
|
{
|
2023-09-12 15:06:23 +02:00
|
|
|
struct dvbdevfops_node *node, *next;
|
|
|
|
|
2015-08-05 17:22:42 +02:00
|
|
|
class_destroy(dvb_class);
|
|
|
|
cdev_del(&dvb_device_cdev);
|
|
|
|
unregister_chrdev_region(MKDEV(DVB_MAJOR, 0), MAX_DVB_MINORS);
|
2023-09-12 15:06:23 +02:00
|
|
|
|
|
|
|
list_for_each_entry_safe(node, next, &dvbdevfops_list, list_head) {
|
|
|
|
list_del(&node->list_head);
|
|
|
|
kfree(node->fops);
|
|
|
|
kfree(node);
|
|
|
|
}
|
2015-08-05 17:22:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
subsys_initcall(init_dvbdev);
|
|
|
|
module_exit(exit_dvbdev);
|
|
|
|
|
|
|
|
MODULE_DESCRIPTION("DVB Core Driver");
|
|
|
|
MODULE_AUTHOR("Marcus Metzler, Ralph Metzler, Holger Waechtler");
|
|
|
|
MODULE_LICENSE("GPL");
|