Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * dvbdev.c |
| 3 | * |
| 4 | * Copyright (C) 2000 Ralph Metzler <ralph@convergence.de> |
| 5 | * & Marcus Metzler <marcus@convergence.de> |
| 6 | * for convergence integrated media GmbH |
| 7 | * |
| 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. |
| 12 | * |
| 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. |
| 17 | * |
| 18 | * You should have received a copy of the GNU Lesser General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 21 | * |
| 22 | */ |
| 23 | |
| 24 | #include <linux/types.h> |
| 25 | #include <linux/errno.h> |
| 26 | #include <linux/string.h> |
| 27 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | #include <linux/kernel.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #include <linux/init.h> |
| 30 | #include <linux/slab.h> |
| 31 | #include <linux/device.h> |
| 32 | #include <linux/fs.h> |
| 33 | #include <linux/cdev.h> |
Ingo Molnar | 1e4baed | 2006-01-15 07:52:23 -0200 | [diff] [blame] | 34 | #include <linux/mutex.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | #include "dvbdev.h" |
| 36 | |
Mauro Carvalho Chehab | 188d2d5 | 2015-08-31 13:23:03 -0300 | [diff] [blame] | 37 | /* Due to enum tuner_pad_index */ |
| 38 | #include <media/tuner.h> |
| 39 | |
Arnd Bergmann | 72024f1 | 2010-09-11 19:56:45 +0200 | [diff] [blame] | 40 | static DEFINE_MUTEX(dvbdev_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | static int dvbdev_debug; |
| 42 | |
| 43 | module_param(dvbdev_debug, int, 0644); |
| 44 | MODULE_PARM_DESC(dvbdev_debug, "Turn on/off device debugging (default:off)."); |
| 45 | |
| 46 | #define dprintk if (dvbdev_debug) printk |
| 47 | |
| 48 | static LIST_HEAD(dvb_adapter_list); |
Ingo Molnar | 1e4baed | 2006-01-15 07:52:23 -0200 | [diff] [blame] | 49 | static DEFINE_MUTEX(dvbdev_register_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | |
| 51 | static const char * const dnames[] = { |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 52 | "video", "audio", "sec", "frontend", "demux", "dvr", "ca", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | "net", "osd" |
| 54 | }; |
| 55 | |
Andreas Oberritter | 5dd3f30 | 2008-10-23 12:11:19 -0300 | [diff] [blame] | 56 | #ifdef CONFIG_DVB_DYNAMIC_MINORS |
| 57 | #define MAX_DVB_MINORS 256 |
| 58 | #define DVB_MAX_IDS MAX_DVB_MINORS |
| 59 | #else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | #define DVB_MAX_IDS 4 |
| 61 | #define nums2minor(num,type,id) ((num << 6) | (id << 4) | type) |
| 62 | #define MAX_DVB_MINORS (DVB_MAX_ADAPTERS*64) |
Andreas Oberritter | 5dd3f30 | 2008-10-23 12:11:19 -0300 | [diff] [blame] | 63 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | |
gregkh@suse.de | 56b2293 | 2005-03-23 10:01:41 -0800 | [diff] [blame] | 65 | static struct class *dvb_class; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | |
Andreas Oberritter | 5dd3f30 | 2008-10-23 12:11:19 -0300 | [diff] [blame] | 67 | static struct dvb_device *dvb_minors[MAX_DVB_MINORS]; |
| 68 | static DECLARE_RWSEM(minor_rwsem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | |
| 70 | static int dvb_device_open(struct inode *inode, struct file *file) |
| 71 | { |
| 72 | struct dvb_device *dvbdev; |
| 73 | |
Arnd Bergmann | 72024f1 | 2010-09-11 19:56:45 +0200 | [diff] [blame] | 74 | mutex_lock(&dvbdev_mutex); |
Andreas Oberritter | 5dd3f30 | 2008-10-23 12:11:19 -0300 | [diff] [blame] | 75 | down_read(&minor_rwsem); |
| 76 | dvbdev = dvb_minors[iminor(inode)]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | |
| 78 | if (dvbdev && dvbdev->fops) { |
| 79 | int err = 0; |
Al Viro | e84f9e5 | 2013-09-22 14:17:15 -0400 | [diff] [blame] | 80 | const struct file_operations *new_fops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | |
Al Viro | e84f9e5 | 2013-09-22 14:17:15 -0400 | [diff] [blame] | 82 | new_fops = fops_get(dvbdev->fops); |
| 83 | if (!new_fops) |
Laurent Pinchart | f41ced8 | 2009-01-06 14:40:40 -0800 | [diff] [blame] | 84 | goto fail; |
Al Viro | e84f9e5 | 2013-09-22 14:17:15 -0400 | [diff] [blame] | 85 | file->private_data = dvbdev; |
| 86 | replace_fops(file, new_fops); |
| 87 | if (file->f_op->open) |
Michael Krufky | 50c25ff | 2006-01-09 15:25:34 -0200 | [diff] [blame] | 88 | err = file->f_op->open(inode,file); |
Andreas Oberritter | 5dd3f30 | 2008-10-23 12:11:19 -0300 | [diff] [blame] | 89 | up_read(&minor_rwsem); |
Arnd Bergmann | 72024f1 | 2010-09-11 19:56:45 +0200 | [diff] [blame] | 90 | mutex_unlock(&dvbdev_mutex); |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 91 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | } |
Laurent Pinchart | f41ced8 | 2009-01-06 14:40:40 -0800 | [diff] [blame] | 93 | fail: |
Andreas Oberritter | 5dd3f30 | 2008-10-23 12:11:19 -0300 | [diff] [blame] | 94 | up_read(&minor_rwsem); |
Arnd Bergmann | 72024f1 | 2010-09-11 19:56:45 +0200 | [diff] [blame] | 95 | mutex_unlock(&dvbdev_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | return -ENODEV; |
| 97 | } |
| 98 | |
| 99 | |
Jan Engelhardt | 27a643b | 2008-04-22 14:42:01 -0300 | [diff] [blame] | 100 | static const struct file_operations dvb_device_fops = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | { |
| 102 | .owner = THIS_MODULE, |
| 103 | .open = dvb_device_open, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 104 | .llseek = noop_llseek, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | }; |
| 106 | |
Greg Kroah-Hartman | 7e7654a | 2007-09-12 15:06:57 -0700 | [diff] [blame] | 107 | static struct cdev dvb_device_cdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | |
| 109 | int dvb_generic_open(struct inode *inode, struct file *file) |
| 110 | { |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 111 | struct dvb_device *dvbdev = file->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 113 | if (!dvbdev) |
| 114 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | |
| 116 | if (!dvbdev->users) |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 117 | return -EBUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | |
| 119 | if ((file->f_flags & O_ACCMODE) == O_RDONLY) { |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 120 | if (!dvbdev->readers) |
| 121 | return -EBUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | dvbdev->readers--; |
| 123 | } else { |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 124 | if (!dvbdev->writers) |
| 125 | return -EBUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | dvbdev->writers--; |
| 127 | } |
| 128 | |
| 129 | dvbdev->users--; |
| 130 | return 0; |
| 131 | } |
| 132 | EXPORT_SYMBOL(dvb_generic_open); |
| 133 | |
| 134 | |
| 135 | int dvb_generic_release(struct inode *inode, struct file *file) |
| 136 | { |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 137 | struct dvb_device *dvbdev = file->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | |
| 139 | if (!dvbdev) |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 140 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | |
| 142 | if ((file->f_flags & O_ACCMODE) == O_RDONLY) { |
| 143 | dvbdev->readers++; |
| 144 | } else { |
| 145 | dvbdev->writers++; |
| 146 | } |
| 147 | |
| 148 | dvbdev->users++; |
| 149 | return 0; |
| 150 | } |
| 151 | EXPORT_SYMBOL(dvb_generic_release); |
| 152 | |
| 153 | |
Arnd Bergmann | 16ef8de | 2010-04-27 00:24:00 +0200 | [diff] [blame] | 154 | long dvb_generic_ioctl(struct file *file, |
| 155 | unsigned int cmd, unsigned long arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | { |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 157 | struct dvb_device *dvbdev = file->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 159 | if (!dvbdev) |
| 160 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | |
| 162 | if (!dvbdev->kernel_ioctl) |
| 163 | return -EINVAL; |
| 164 | |
Arnd Bergmann | 72024f1 | 2010-09-11 19:56:45 +0200 | [diff] [blame] | 165 | return dvb_usercopy(file, cmd, arg, dvbdev->kernel_ioctl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | } |
| 167 | EXPORT_SYMBOL(dvb_generic_ioctl); |
| 168 | |
| 169 | |
| 170 | static int dvbdev_get_free_id (struct dvb_adapter *adap, int type) |
| 171 | { |
| 172 | u32 id = 0; |
| 173 | |
| 174 | while (id < DVB_MAX_IDS) { |
Trent Piepho | 7948261 | 2007-10-10 05:37:39 -0300 | [diff] [blame] | 175 | struct dvb_device *dev; |
| 176 | list_for_each_entry(dev, &adap->device_list, list_head) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | if (dev->type == type && dev->id == id) |
| 178 | goto skip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | return id; |
| 180 | skip: |
| 181 | id++; |
| 182 | } |
| 183 | return -ENFILE; |
| 184 | } |
| 185 | |
Mauro Carvalho Chehab | f50d516 | 2015-09-04 15:10:29 -0300 | [diff] [blame] | 186 | static void dvb_media_device_free(struct dvb_device *dvbdev) |
| 187 | { |
| 188 | #if defined(CONFIG_MEDIA_CONTROLLER_DVB) |
| 189 | if (dvbdev->entity) { |
| 190 | media_device_unregister_entity(dvbdev->entity); |
| 191 | kfree(dvbdev->entity); |
| 192 | kfree(dvbdev->pads); |
| 193 | dvbdev->entity = NULL; |
| 194 | dvbdev->pads = NULL; |
| 195 | } |
| 196 | |
| 197 | if (dvbdev->tsout_entity) { |
| 198 | int i; |
| 199 | |
| 200 | for (i = 0; i < dvbdev->tsout_num_entities; i++) { |
| 201 | media_device_unregister_entity(&dvbdev->tsout_entity[i]); |
| 202 | kfree(dvbdev->tsout_entity[i].name); |
| 203 | } |
| 204 | kfree(dvbdev->tsout_entity); |
| 205 | kfree(dvbdev->tsout_pads); |
| 206 | dvbdev->tsout_entity = NULL; |
| 207 | dvbdev->tsout_pads = NULL; |
| 208 | |
| 209 | dvbdev->tsout_num_entities = 0; |
| 210 | } |
| 211 | |
| 212 | if (dvbdev->intf_devnode) { |
| 213 | media_devnode_remove(dvbdev->intf_devnode); |
| 214 | dvbdev->intf_devnode = NULL; |
| 215 | } |
Mauro Carvalho Chehab | 0230d60 | 2015-12-29 11:52:23 -0200 | [diff] [blame] | 216 | |
| 217 | if (dvbdev->adapter->conn) { |
| 218 | media_device_unregister_entity(dvbdev->adapter->conn); |
| 219 | dvbdev->adapter->conn = NULL; |
| 220 | kfree(dvbdev->adapter->conn_pads); |
| 221 | dvbdev->adapter->conn_pads = NULL; |
| 222 | } |
Mauro Carvalho Chehab | f50d516 | 2015-09-04 15:10:29 -0300 | [diff] [blame] | 223 | #endif |
| 224 | } |
| 225 | |
Mauro Carvalho Chehab | 0820eb5 | 2015-12-28 10:30:06 -0200 | [diff] [blame] | 226 | #if defined(CONFIG_MEDIA_CONTROLLER_DVB) |
Mauro Carvalho Chehab | f50d516 | 2015-09-04 15:10:29 -0300 | [diff] [blame] | 227 | static int dvb_create_tsout_entity(struct dvb_device *dvbdev, |
Mauro Carvalho Chehab | df2f94e | 2015-08-21 16:18:18 -0300 | [diff] [blame] | 228 | const char *name, int npads) |
Mauro Carvalho Chehab | a0246e0 | 2015-01-02 12:19:51 -0300 | [diff] [blame] | 229 | { |
Mauro Carvalho Chehab | df2f94e | 2015-08-21 16:18:18 -0300 | [diff] [blame] | 230 | int i, ret = 0; |
| 231 | |
| 232 | dvbdev->tsout_pads = kcalloc(npads, sizeof(*dvbdev->tsout_pads), |
| 233 | GFP_KERNEL); |
| 234 | if (!dvbdev->tsout_pads) |
Mauro Carvalho Chehab | f50d516 | 2015-09-04 15:10:29 -0300 | [diff] [blame] | 235 | return -ENOMEM; |
| 236 | |
Mauro Carvalho Chehab | df2f94e | 2015-08-21 16:18:18 -0300 | [diff] [blame] | 237 | dvbdev->tsout_entity = kcalloc(npads, sizeof(*dvbdev->tsout_entity), |
| 238 | GFP_KERNEL); |
Mauro Carvalho Chehab | f50d516 | 2015-09-04 15:10:29 -0300 | [diff] [blame] | 239 | if (!dvbdev->tsout_entity) |
| 240 | return -ENOMEM; |
| 241 | |
| 242 | dvbdev->tsout_num_entities = npads; |
| 243 | |
Mauro Carvalho Chehab | df2f94e | 2015-08-21 16:18:18 -0300 | [diff] [blame] | 244 | for (i = 0; i < npads; i++) { |
| 245 | struct media_pad *pads = &dvbdev->tsout_pads[i]; |
| 246 | struct media_entity *entity = &dvbdev->tsout_entity[i]; |
| 247 | |
| 248 | entity->name = kasprintf(GFP_KERNEL, "%s #%d", name, i); |
Mauro Carvalho Chehab | f50d516 | 2015-09-04 15:10:29 -0300 | [diff] [blame] | 249 | if (!entity->name) |
| 250 | return -ENOMEM; |
Mauro Carvalho Chehab | df2f94e | 2015-08-21 16:18:18 -0300 | [diff] [blame] | 251 | |
Mauro Carvalho Chehab | 4ca72ef | 2015-12-10 17:25:41 -0200 | [diff] [blame] | 252 | entity->function = MEDIA_ENT_F_IO_DTV; |
Mauro Carvalho Chehab | df2f94e | 2015-08-21 16:18:18 -0300 | [diff] [blame] | 253 | pads->flags = MEDIA_PAD_FL_SINK; |
| 254 | |
Mauro Carvalho Chehab | ab22e77 | 2015-12-11 07:44:40 -0200 | [diff] [blame] | 255 | ret = media_entity_pads_init(entity, 1, pads); |
Mauro Carvalho Chehab | df2f94e | 2015-08-21 16:18:18 -0300 | [diff] [blame] | 256 | if (ret < 0) |
Mauro Carvalho Chehab | f50d516 | 2015-09-04 15:10:29 -0300 | [diff] [blame] | 257 | return ret; |
Mauro Carvalho Chehab | df2f94e | 2015-08-21 16:18:18 -0300 | [diff] [blame] | 258 | |
| 259 | ret = media_device_register_entity(dvbdev->adapter->mdev, |
| 260 | entity); |
| 261 | if (ret < 0) |
Mauro Carvalho Chehab | f50d516 | 2015-09-04 15:10:29 -0300 | [diff] [blame] | 262 | return ret; |
Mauro Carvalho Chehab | df2f94e | 2015-08-21 16:18:18 -0300 | [diff] [blame] | 263 | } |
Mauro Carvalho Chehab | f50d516 | 2015-09-04 15:10:29 -0300 | [diff] [blame] | 264 | return 0; |
Mauro Carvalho Chehab | df2f94e | 2015-08-21 16:18:18 -0300 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | #define DEMUX_TSOUT "demux-tsout" |
| 268 | #define DVR_TSOUT "dvr-tsout" |
| 269 | |
Mauro Carvalho Chehab | f50d516 | 2015-09-04 15:10:29 -0300 | [diff] [blame] | 270 | static int dvb_create_media_entity(struct dvb_device *dvbdev, |
| 271 | int type, int demux_sink_pads) |
Mauro Carvalho Chehab | df2f94e | 2015-08-21 16:18:18 -0300 | [diff] [blame] | 272 | { |
Mauro Carvalho Chehab | f50d516 | 2015-09-04 15:10:29 -0300 | [diff] [blame] | 273 | int i, ret, npads; |
Mauro Carvalho Chehab | a0246e0 | 2015-01-02 12:19:51 -0300 | [diff] [blame] | 274 | |
Mauro Carvalho Chehab | 8211b18 | 2015-08-21 08:20:22 -0300 | [diff] [blame] | 275 | switch (type) { |
| 276 | case DVB_DEVICE_FRONTEND: |
| 277 | npads = 2; |
| 278 | break; |
Mauro Carvalho Chehab | df2f94e | 2015-08-21 16:18:18 -0300 | [diff] [blame] | 279 | case DVB_DEVICE_DVR: |
Mauro Carvalho Chehab | f50d516 | 2015-09-04 15:10:29 -0300 | [diff] [blame] | 280 | ret = dvb_create_tsout_entity(dvbdev, DVR_TSOUT, |
| 281 | demux_sink_pads); |
| 282 | return ret; |
Mauro Carvalho Chehab | 8211b18 | 2015-08-21 08:20:22 -0300 | [diff] [blame] | 283 | case DVB_DEVICE_DEMUX: |
Mauro Carvalho Chehab | df2f94e | 2015-08-21 16:18:18 -0300 | [diff] [blame] | 284 | npads = 1 + demux_sink_pads; |
Mauro Carvalho Chehab | f50d516 | 2015-09-04 15:10:29 -0300 | [diff] [blame] | 285 | ret = dvb_create_tsout_entity(dvbdev, DEMUX_TSOUT, |
| 286 | demux_sink_pads); |
| 287 | if (ret < 0) |
| 288 | return ret; |
Mauro Carvalho Chehab | 8211b18 | 2015-08-21 08:20:22 -0300 | [diff] [blame] | 289 | break; |
| 290 | case DVB_DEVICE_CA: |
| 291 | npads = 2; |
| 292 | break; |
| 293 | case DVB_DEVICE_NET: |
| 294 | /* |
| 295 | * We should be creating entities for the MPE/ULE |
| 296 | * decapsulation hardware (or software implementation). |
| 297 | * |
| 298 | * However, the number of for the MPE/ULE decaps may not be |
| 299 | * fixed. As we don't have yet dynamic support for PADs at |
| 300 | * the Media Controller, let's not create the decap |
| 301 | * entities yet. |
| 302 | */ |
Mauro Carvalho Chehab | f50d516 | 2015-09-04 15:10:29 -0300 | [diff] [blame] | 303 | return 0; |
Mauro Carvalho Chehab | 8211b18 | 2015-08-21 08:20:22 -0300 | [diff] [blame] | 304 | default: |
Mauro Carvalho Chehab | f50d516 | 2015-09-04 15:10:29 -0300 | [diff] [blame] | 305 | return 0; |
Mauro Carvalho Chehab | 8211b18 | 2015-08-21 08:20:22 -0300 | [diff] [blame] | 306 | } |
Mauro Carvalho Chehab | a0246e0 | 2015-01-02 12:19:51 -0300 | [diff] [blame] | 307 | |
| 308 | dvbdev->entity = kzalloc(sizeof(*dvbdev->entity), GFP_KERNEL); |
| 309 | if (!dvbdev->entity) |
Mauro Carvalho Chehab | f50d516 | 2015-09-04 15:10:29 -0300 | [diff] [blame] | 310 | return -ENOMEM; |
Mauro Carvalho Chehab | a0246e0 | 2015-01-02 12:19:51 -0300 | [diff] [blame] | 311 | |
Mauro Carvalho Chehab | a0246e0 | 2015-01-02 12:19:51 -0300 | [diff] [blame] | 312 | dvbdev->entity->name = dvbdev->name; |
Mauro Carvalho Chehab | 172e9d3 | 2015-01-03 01:59:53 -0300 | [diff] [blame] | 313 | |
Mauro Carvalho Chehab | 172e9d3 | 2015-01-03 01:59:53 -0300 | [diff] [blame] | 314 | if (npads) { |
| 315 | dvbdev->pads = kcalloc(npads, sizeof(*dvbdev->pads), |
| 316 | GFP_KERNEL); |
Mauro Carvalho Chehab | f50d516 | 2015-09-04 15:10:29 -0300 | [diff] [blame] | 317 | if (!dvbdev->pads) |
| 318 | return -ENOMEM; |
Mauro Carvalho Chehab | 172e9d3 | 2015-01-03 01:59:53 -0300 | [diff] [blame] | 319 | } |
| 320 | |
Mauro Carvalho Chehab | a0246e0 | 2015-01-02 12:19:51 -0300 | [diff] [blame] | 321 | switch (type) { |
| 322 | case DVB_DEVICE_FRONTEND: |
Mauro Carvalho Chehab | 4ca72ef | 2015-12-10 17:25:41 -0200 | [diff] [blame] | 323 | dvbdev->entity->function = MEDIA_ENT_F_DTV_DEMOD; |
Mauro Carvalho Chehab | 3bde1b7 | 2015-01-03 16:35:53 -0300 | [diff] [blame] | 324 | dvbdev->pads[0].flags = MEDIA_PAD_FL_SINK; |
| 325 | dvbdev->pads[1].flags = MEDIA_PAD_FL_SOURCE; |
Mauro Carvalho Chehab | a0246e0 | 2015-01-02 12:19:51 -0300 | [diff] [blame] | 326 | break; |
| 327 | case DVB_DEVICE_DEMUX: |
Mauro Carvalho Chehab | 4ca72ef | 2015-12-10 17:25:41 -0200 | [diff] [blame] | 328 | dvbdev->entity->function = MEDIA_ENT_F_TS_DEMUX; |
Mauro Carvalho Chehab | 3bde1b7 | 2015-01-03 16:35:53 -0300 | [diff] [blame] | 329 | dvbdev->pads[0].flags = MEDIA_PAD_FL_SINK; |
Mauro Carvalho Chehab | df2f94e | 2015-08-21 16:18:18 -0300 | [diff] [blame] | 330 | for (i = 1; i < npads; i++) |
| 331 | dvbdev->pads[i].flags = MEDIA_PAD_FL_SOURCE; |
Mauro Carvalho Chehab | a0246e0 | 2015-01-02 12:19:51 -0300 | [diff] [blame] | 332 | break; |
Mauro Carvalho Chehab | a0246e0 | 2015-01-02 12:19:51 -0300 | [diff] [blame] | 333 | case DVB_DEVICE_CA: |
Mauro Carvalho Chehab | 4ca72ef | 2015-12-10 17:25:41 -0200 | [diff] [blame] | 334 | dvbdev->entity->function = MEDIA_ENT_F_DTV_CA; |
Mauro Carvalho Chehab | 3bde1b7 | 2015-01-03 16:35:53 -0300 | [diff] [blame] | 335 | dvbdev->pads[0].flags = MEDIA_PAD_FL_SINK; |
| 336 | dvbdev->pads[1].flags = MEDIA_PAD_FL_SOURCE; |
Mauro Carvalho Chehab | a0246e0 | 2015-01-02 12:19:51 -0300 | [diff] [blame] | 337 | break; |
Mauro Carvalho Chehab | a0246e0 | 2015-01-02 12:19:51 -0300 | [diff] [blame] | 338 | default: |
Mauro Carvalho Chehab | f50d516 | 2015-09-04 15:10:29 -0300 | [diff] [blame] | 339 | /* Should never happen, as the first switch prevents it */ |
Mauro Carvalho Chehab | a0246e0 | 2015-01-02 12:19:51 -0300 | [diff] [blame] | 340 | kfree(dvbdev->entity); |
Mauro Carvalho Chehab | 172e9d3 | 2015-01-03 01:59:53 -0300 | [diff] [blame] | 341 | kfree(dvbdev->pads); |
Mauro Carvalho Chehab | a0246e0 | 2015-01-02 12:19:51 -0300 | [diff] [blame] | 342 | dvbdev->entity = NULL; |
Mauro Carvalho Chehab | f50d516 | 2015-09-04 15:10:29 -0300 | [diff] [blame] | 343 | dvbdev->pads = NULL; |
| 344 | return 0; |
Mauro Carvalho Chehab | a0246e0 | 2015-01-02 12:19:51 -0300 | [diff] [blame] | 345 | } |
| 346 | |
Mauro Carvalho Chehab | f50d516 | 2015-09-04 15:10:29 -0300 | [diff] [blame] | 347 | if (npads) { |
Mauro Carvalho Chehab | ab22e77 | 2015-12-11 07:44:40 -0200 | [diff] [blame] | 348 | ret = media_entity_pads_init(dvbdev->entity, npads, dvbdev->pads); |
Mauro Carvalho Chehab | f50d516 | 2015-09-04 15:10:29 -0300 | [diff] [blame] | 349 | if (ret) |
| 350 | return ret; |
| 351 | } |
| 352 | ret = media_device_register_entity(dvbdev->adapter->mdev, |
| 353 | dvbdev->entity); |
| 354 | if (ret) |
Xiubo Li | eac287a | 2016-01-15 03:15:00 -0200 | [diff] [blame] | 355 | return ret; |
Mauro Carvalho Chehab | f50d516 | 2015-09-04 15:10:29 -0300 | [diff] [blame] | 356 | |
Mauro Carvalho Chehab | 8211b18 | 2015-08-21 08:20:22 -0300 | [diff] [blame] | 357 | printk(KERN_DEBUG "%s: media entity '%s' registered.\n", |
Mauro Carvalho Chehab | a0246e0 | 2015-01-02 12:19:51 -0300 | [diff] [blame] | 358 | __func__, dvbdev->entity->name); |
Mauro Carvalho Chehab | f50d516 | 2015-09-04 15:10:29 -0300 | [diff] [blame] | 359 | |
Mauro Carvalho Chehab | f50d516 | 2015-09-04 15:10:29 -0300 | [diff] [blame] | 360 | return 0; |
Mauro Carvalho Chehab | a0246e0 | 2015-01-02 12:19:51 -0300 | [diff] [blame] | 361 | } |
Mauro Carvalho Chehab | 0820eb5 | 2015-12-28 10:30:06 -0200 | [diff] [blame] | 362 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | |
Mauro Carvalho Chehab | f50d516 | 2015-09-04 15:10:29 -0300 | [diff] [blame] | 364 | static int dvb_register_media_device(struct dvb_device *dvbdev, |
| 365 | int type, int minor, |
| 366 | unsigned demux_sink_pads) |
Mauro Carvalho Chehab | 8211b18 | 2015-08-21 08:20:22 -0300 | [diff] [blame] | 367 | { |
| 368 | #if defined(CONFIG_MEDIA_CONTROLLER_DVB) |
Mauro Carvalho Chehab | f50d516 | 2015-09-04 15:10:29 -0300 | [diff] [blame] | 369 | struct media_link *link; |
Mauro Carvalho Chehab | 8211b18 | 2015-08-21 08:20:22 -0300 | [diff] [blame] | 370 | u32 intf_type; |
Mauro Carvalho Chehab | f50d516 | 2015-09-04 15:10:29 -0300 | [diff] [blame] | 371 | int ret; |
Mauro Carvalho Chehab | 8211b18 | 2015-08-21 08:20:22 -0300 | [diff] [blame] | 372 | |
| 373 | if (!dvbdev->adapter->mdev) |
Mauro Carvalho Chehab | f50d516 | 2015-09-04 15:10:29 -0300 | [diff] [blame] | 374 | return 0; |
Mauro Carvalho Chehab | 8211b18 | 2015-08-21 08:20:22 -0300 | [diff] [blame] | 375 | |
Mauro Carvalho Chehab | f50d516 | 2015-09-04 15:10:29 -0300 | [diff] [blame] | 376 | ret = dvb_create_media_entity(dvbdev, type, demux_sink_pads); |
| 377 | if (ret) |
| 378 | return ret; |
Mauro Carvalho Chehab | 8211b18 | 2015-08-21 08:20:22 -0300 | [diff] [blame] | 379 | |
| 380 | switch (type) { |
| 381 | case DVB_DEVICE_FRONTEND: |
| 382 | intf_type = MEDIA_INTF_T_DVB_FE; |
| 383 | break; |
| 384 | case DVB_DEVICE_DEMUX: |
| 385 | intf_type = MEDIA_INTF_T_DVB_DEMUX; |
| 386 | break; |
| 387 | case DVB_DEVICE_DVR: |
| 388 | intf_type = MEDIA_INTF_T_DVB_DVR; |
| 389 | break; |
| 390 | case DVB_DEVICE_CA: |
| 391 | intf_type = MEDIA_INTF_T_DVB_CA; |
| 392 | break; |
| 393 | case DVB_DEVICE_NET: |
| 394 | intf_type = MEDIA_INTF_T_DVB_NET; |
| 395 | break; |
| 396 | default: |
Mauro Carvalho Chehab | f50d516 | 2015-09-04 15:10:29 -0300 | [diff] [blame] | 397 | return 0; |
Mauro Carvalho Chehab | 8211b18 | 2015-08-21 08:20:22 -0300 | [diff] [blame] | 398 | } |
| 399 | |
| 400 | dvbdev->intf_devnode = media_devnode_create(dvbdev->adapter->mdev, |
Mauro Carvalho Chehab | f50d516 | 2015-09-04 15:10:29 -0300 | [diff] [blame] | 401 | intf_type, 0, |
Mauro Carvalho Chehab | 0b3b72df9 | 2015-09-09 08:19:25 -0300 | [diff] [blame] | 402 | DVB_MAJOR, minor); |
Mauro Carvalho Chehab | f50d516 | 2015-09-04 15:10:29 -0300 | [diff] [blame] | 403 | |
| 404 | if (!dvbdev->intf_devnode) |
| 405 | return -ENOMEM; |
Mauro Carvalho Chehab | 8211b18 | 2015-08-21 08:20:22 -0300 | [diff] [blame] | 406 | |
| 407 | /* |
| 408 | * Create the "obvious" link, e. g. the ones that represent |
| 409 | * a direct association between an interface and an entity. |
| 410 | * Other links should be created elsewhere, like: |
| 411 | * DVB FE intf -> tuner |
| 412 | * DVB demux intf -> dvr |
| 413 | */ |
| 414 | |
Mauro Carvalho Chehab | f50d516 | 2015-09-04 15:10:29 -0300 | [diff] [blame] | 415 | if (!dvbdev->entity) |
| 416 | return 0; |
Mauro Carvalho Chehab | 8211b18 | 2015-08-21 08:20:22 -0300 | [diff] [blame] | 417 | |
Mauro Carvalho Chehab | f50d516 | 2015-09-04 15:10:29 -0300 | [diff] [blame] | 418 | link = media_create_intf_link(dvbdev->entity, &dvbdev->intf_devnode->intf, |
| 419 | MEDIA_LNK_FL_ENABLED); |
| 420 | if (!link) |
| 421 | return -ENOMEM; |
Mauro Carvalho Chehab | 8211b18 | 2015-08-21 08:20:22 -0300 | [diff] [blame] | 422 | #endif |
Mauro Carvalho Chehab | f50d516 | 2015-09-04 15:10:29 -0300 | [diff] [blame] | 423 | return 0; |
Mauro Carvalho Chehab | 8211b18 | 2015-08-21 08:20:22 -0300 | [diff] [blame] | 424 | } |
| 425 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev, |
Mauro Carvalho Chehab | df2f94e | 2015-08-21 16:18:18 -0300 | [diff] [blame] | 427 | const struct dvb_device *template, void *priv, int type, |
| 428 | int demux_sink_pads) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | { |
| 430 | struct dvb_device *dvbdev; |
Marcel Siegert | b619010 | 2007-02-13 09:46:55 -0300 | [diff] [blame] | 431 | struct file_operations *dvbdevfops; |
Kay Sievers | 5f55338 | 2007-08-15 14:00:09 -0300 | [diff] [blame] | 432 | struct device *clsdev; |
Andreas Oberritter | 5dd3f30 | 2008-10-23 12:11:19 -0300 | [diff] [blame] | 433 | int minor; |
Mauro Carvalho Chehab | f50d516 | 2015-09-04 15:10:29 -0300 | [diff] [blame] | 434 | int id, ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | |
Simon Arlott | c278850 | 2007-03-10 06:21:25 -0300 | [diff] [blame] | 436 | mutex_lock(&dvbdev_register_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | |
Marcel Siegert | b619010 | 2007-02-13 09:46:55 -0300 | [diff] [blame] | 438 | if ((id = dvbdev_get_free_id (adap, type)) < 0){ |
Ingo Molnar | 1e4baed | 2006-01-15 07:52:23 -0200 | [diff] [blame] | 439 | mutex_unlock(&dvbdev_register_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | *pdvbdev = NULL; |
Harvey Harrison | 46b4f7c | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 441 | printk(KERN_ERR "%s: couldn't find free device id\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | return -ENFILE; |
| 443 | } |
| 444 | |
Mauro Carvalho Chehab | f50d516 | 2015-09-04 15:10:29 -0300 | [diff] [blame] | 445 | *pdvbdev = dvbdev = kzalloc(sizeof(*dvbdev), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | |
Marcel Siegert | b619010 | 2007-02-13 09:46:55 -0300 | [diff] [blame] | 447 | if (!dvbdev){ |
| 448 | mutex_unlock(&dvbdev_register_lock); |
| 449 | return -ENOMEM; |
| 450 | } |
| 451 | |
| 452 | dvbdevfops = kzalloc(sizeof(struct file_operations), GFP_KERNEL); |
| 453 | |
| 454 | if (!dvbdevfops){ |
| 455 | kfree (dvbdev); |
Ingo Molnar | 1e4baed | 2006-01-15 07:52:23 -0200 | [diff] [blame] | 456 | mutex_unlock(&dvbdev_register_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | return -ENOMEM; |
| 458 | } |
| 459 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | memcpy(dvbdev, template, sizeof(struct dvb_device)); |
| 461 | dvbdev->type = type; |
| 462 | dvbdev->id = id; |
| 463 | dvbdev->adapter = adap; |
| 464 | dvbdev->priv = priv; |
Marcel Siegert | b619010 | 2007-02-13 09:46:55 -0300 | [diff] [blame] | 465 | dvbdev->fops = dvbdevfops; |
Markus Rechberger | ca5be9c | 2007-04-14 10:18:58 -0300 | [diff] [blame] | 466 | init_waitqueue_head (&dvbdev->wait_queue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | |
Jan Engelhardt | 784e29d | 2009-01-11 06:12:43 -0300 | [diff] [blame] | 468 | memcpy(dvbdevfops, template->fops, sizeof(struct file_operations)); |
| 469 | dvbdevfops->owner = adap->module; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | |
| 471 | list_add_tail (&dvbdev->list_head, &adap->device_list); |
| 472 | |
Andreas Oberritter | 5dd3f30 | 2008-10-23 12:11:19 -0300 | [diff] [blame] | 473 | down_write(&minor_rwsem); |
| 474 | #ifdef CONFIG_DVB_DYNAMIC_MINORS |
| 475 | for (minor = 0; minor < MAX_DVB_MINORS; minor++) |
| 476 | if (dvb_minors[minor] == NULL) |
| 477 | break; |
| 478 | |
| 479 | if (minor == MAX_DVB_MINORS) { |
| 480 | kfree(dvbdevfops); |
| 481 | kfree(dvbdev); |
Santosh Nayak | 82163ed | 2012-06-23 07:59:54 -0300 | [diff] [blame] | 482 | up_write(&minor_rwsem); |
Andreas Oberritter | 5dd3f30 | 2008-10-23 12:11:19 -0300 | [diff] [blame] | 483 | mutex_unlock(&dvbdev_register_lock); |
| 484 | return -EINVAL; |
| 485 | } |
| 486 | #else |
| 487 | minor = nums2minor(adap->num, type, id); |
| 488 | #endif |
| 489 | |
| 490 | dvbdev->minor = minor; |
| 491 | dvb_minors[minor] = dvbdev; |
| 492 | up_write(&minor_rwsem); |
| 493 | |
Mauro Carvalho Chehab | f50d516 | 2015-09-04 15:10:29 -0300 | [diff] [blame] | 494 | ret = dvb_register_media_device(dvbdev, type, minor, demux_sink_pads); |
| 495 | if (ret) { |
| 496 | printk(KERN_ERR |
| 497 | "%s: dvb_register_media_device failed to create the mediagraph\n", |
| 498 | __func__); |
| 499 | |
| 500 | dvb_media_device_free(dvbdev); |
| 501 | kfree(dvbdevfops); |
| 502 | kfree(dvbdev); |
| 503 | up_write(&minor_rwsem); |
| 504 | mutex_unlock(&dvbdev_register_lock); |
| 505 | return ret; |
| 506 | } |
| 507 | |
Andrew de Quincey | f47f476 | 2006-04-04 09:41:47 -0300 | [diff] [blame] | 508 | mutex_unlock(&dvbdev_register_lock); |
| 509 | |
Greg Kroah-Hartman | a9b1261 | 2008-07-21 20:03:34 -0700 | [diff] [blame] | 510 | clsdev = device_create(dvb_class, adap->device, |
Hans Verkuil | b749678 | 2008-11-03 05:38:43 -0300 | [diff] [blame] | 511 | MKDEV(DVB_MAJOR, minor), |
Kay Sievers | a5f4c0c | 2008-10-27 22:27:37 -0300 | [diff] [blame] | 512 | dvbdev, "dvb%d.%s%d", adap->num, dnames[type], id); |
Simon Arlott | 4abdcf9 | 2007-05-06 20:56:14 -0300 | [diff] [blame] | 513 | if (IS_ERR(clsdev)) { |
| 514 | printk(KERN_ERR "%s: failed to create device dvb%d.%s%d (%ld)\n", |
Harvey Harrison | 46b4f7c | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 515 | __func__, adap->num, dnames[type], id, PTR_ERR(clsdev)); |
Simon Arlott | 4abdcf9 | 2007-05-06 20:56:14 -0300 | [diff] [blame] | 516 | return PTR_ERR(clsdev); |
| 517 | } |
Simon Arlott | 900858e | 2007-05-06 21:06:32 -0300 | [diff] [blame] | 518 | dprintk(KERN_DEBUG "DVB: register adapter%d/%s%d @ minor: %i (0x%02x)\n", |
Andreas Oberritter | 5dd3f30 | 2008-10-23 12:11:19 -0300 | [diff] [blame] | 519 | adap->num, dnames[type], id, minor, minor); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | |
| 521 | return 0; |
| 522 | } |
| 523 | EXPORT_SYMBOL(dvb_register_device); |
| 524 | |
| 525 | |
| 526 | void dvb_unregister_device(struct dvb_device *dvbdev) |
| 527 | { |
| 528 | if (!dvbdev) |
| 529 | return; |
| 530 | |
Andreas Oberritter | 5dd3f30 | 2008-10-23 12:11:19 -0300 | [diff] [blame] | 531 | down_write(&minor_rwsem); |
| 532 | dvb_minors[dvbdev->minor] = NULL; |
| 533 | up_write(&minor_rwsem); |
| 534 | |
Mauro Carvalho Chehab | f50d516 | 2015-09-04 15:10:29 -0300 | [diff] [blame] | 535 | dvb_media_device_free(dvbdev); |
| 536 | |
Andreas Oberritter | 5dd3f30 | 2008-10-23 12:11:19 -0300 | [diff] [blame] | 537 | device_destroy(dvb_class, MKDEV(DVB_MAJOR, dvbdev->minor)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | |
| 539 | list_del (&dvbdev->list_head); |
Marcel Siegert | b619010 | 2007-02-13 09:46:55 -0300 | [diff] [blame] | 540 | kfree (dvbdev->fops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 541 | kfree (dvbdev); |
| 542 | } |
| 543 | EXPORT_SYMBOL(dvb_unregister_device); |
| 544 | |
Mauro Carvalho Chehab | 4155109 | 2015-01-03 16:52:34 -0300 | [diff] [blame] | 545 | |
Mauro Carvalho Chehab | 4155109 | 2015-01-03 16:52:34 -0300 | [diff] [blame] | 546 | #ifdef CONFIG_MEDIA_CONTROLLER_DVB |
Mauro Carvalho Chehab | 17813e2 | 2015-09-06 13:28:48 -0300 | [diff] [blame] | 547 | |
| 548 | static int dvb_create_io_intf_links(struct dvb_adapter *adap, |
| 549 | struct media_interface *intf, |
| 550 | char *name) |
| 551 | { |
| 552 | struct media_device *mdev = adap->mdev; |
| 553 | struct media_entity *entity; |
| 554 | struct media_link *link; |
| 555 | |
| 556 | media_device_for_each_entity(entity, mdev) { |
| 557 | if (entity->function == MEDIA_ENT_F_IO_DTV) { |
| 558 | if (strncmp(entity->name, name, strlen(name))) |
| 559 | continue; |
| 560 | link = media_create_intf_link(entity, intf, |
| 561 | MEDIA_LNK_FL_ENABLED); |
| 562 | if (!link) |
| 563 | return -ENOMEM; |
| 564 | } |
| 565 | } |
| 566 | return 0; |
| 567 | } |
| 568 | |
Mauro Carvalho Chehab | 0230d60 | 2015-12-29 11:52:23 -0200 | [diff] [blame] | 569 | int dvb_create_media_graph(struct dvb_adapter *adap, |
| 570 | bool create_rf_connector) |
Mauro Carvalho Chehab | 480884b | 2015-03-02 10:49:04 -0300 | [diff] [blame] | 571 | { |
| 572 | struct media_device *mdev = adap->mdev; |
Mauro Carvalho Chehab | 0230d60 | 2015-12-29 11:52:23 -0200 | [diff] [blame] | 573 | struct media_entity *entity, *tuner = NULL, *demod = NULL, *conn; |
Mauro Carvalho Chehab | df2f94e | 2015-08-21 16:18:18 -0300 | [diff] [blame] | 574 | struct media_entity *demux = NULL, *ca = NULL; |
Mauro Carvalho Chehab | f50d516 | 2015-09-04 15:10:29 -0300 | [diff] [blame] | 575 | struct media_link *link; |
Mauro Carvalho Chehab | 8ddb90d | 2015-08-21 09:32:38 -0300 | [diff] [blame] | 576 | struct media_interface *intf; |
Mauro Carvalho Chehab | df2f94e | 2015-08-21 16:18:18 -0300 | [diff] [blame] | 577 | unsigned demux_pad = 0; |
| 578 | unsigned dvr_pad = 0; |
Mauro Carvalho Chehab | a0cce2a | 2015-12-30 10:11:53 -0200 | [diff] [blame] | 579 | unsigned ntuner = 0, ndemod = 0; |
Mauro Carvalho Chehab | f50d516 | 2015-09-04 15:10:29 -0300 | [diff] [blame] | 580 | int ret; |
Mauro Carvalho Chehab | 0230d60 | 2015-12-29 11:52:23 -0200 | [diff] [blame] | 581 | static const char *connector_name = "Television"; |
Mauro Carvalho Chehab | 4155109 | 2015-01-03 16:52:34 -0300 | [diff] [blame] | 582 | |
| 583 | if (!mdev) |
Mauro Carvalho Chehab | f50d516 | 2015-09-04 15:10:29 -0300 | [diff] [blame] | 584 | return 0; |
Mauro Carvalho Chehab | 4155109 | 2015-01-03 16:52:34 -0300 | [diff] [blame] | 585 | |
| 586 | media_device_for_each_entity(entity, mdev) { |
Mauro Carvalho Chehab | 0e576b7 | 2015-09-06 09:33:39 -0300 | [diff] [blame] | 587 | switch (entity->function) { |
Mauro Carvalho Chehab | 4ca72ef | 2015-12-10 17:25:41 -0200 | [diff] [blame] | 588 | case MEDIA_ENT_F_TUNER: |
Mauro Carvalho Chehab | 4155109 | 2015-01-03 16:52:34 -0300 | [diff] [blame] | 589 | tuner = entity; |
Mauro Carvalho Chehab | a0cce2a | 2015-12-30 10:11:53 -0200 | [diff] [blame] | 590 | ntuner++; |
Mauro Carvalho Chehab | 4155109 | 2015-01-03 16:52:34 -0300 | [diff] [blame] | 591 | break; |
Mauro Carvalho Chehab | 4ca72ef | 2015-12-10 17:25:41 -0200 | [diff] [blame] | 592 | case MEDIA_ENT_F_DTV_DEMOD: |
Mauro Carvalho Chehab | 32fdc0e | 2015-08-21 11:40:34 -0300 | [diff] [blame] | 593 | demod = entity; |
Mauro Carvalho Chehab | a0cce2a | 2015-12-30 10:11:53 -0200 | [diff] [blame] | 594 | ndemod++; |
Mauro Carvalho Chehab | 4155109 | 2015-01-03 16:52:34 -0300 | [diff] [blame] | 595 | break; |
Mauro Carvalho Chehab | 4ca72ef | 2015-12-10 17:25:41 -0200 | [diff] [blame] | 596 | case MEDIA_ENT_F_TS_DEMUX: |
Mauro Carvalho Chehab | 4155109 | 2015-01-03 16:52:34 -0300 | [diff] [blame] | 597 | demux = entity; |
| 598 | break; |
Mauro Carvalho Chehab | 4ca72ef | 2015-12-10 17:25:41 -0200 | [diff] [blame] | 599 | case MEDIA_ENT_F_DTV_CA: |
Mauro Carvalho Chehab | 4155109 | 2015-01-03 16:52:34 -0300 | [diff] [blame] | 600 | ca = entity; |
| 601 | break; |
| 602 | } |
| 603 | } |
| 604 | |
Mauro Carvalho Chehab | a0cce2a | 2015-12-30 10:11:53 -0200 | [diff] [blame] | 605 | /* |
| 606 | * Prepare to signalize to media_create_pad_links() that multiple |
| 607 | * entities of the same type exists and a 1:n or n:1 links need to be |
| 608 | * created. |
| 609 | * NOTE: if both tuner and demod have multiple instances, it is up |
| 610 | * to the caller driver to create such links. |
| 611 | */ |
| 612 | if (ntuner > 1) |
| 613 | tuner = NULL; |
| 614 | if (ndemod > 1) |
| 615 | demod = NULL; |
| 616 | |
Mauro Carvalho Chehab | 0230d60 | 2015-12-29 11:52:23 -0200 | [diff] [blame] | 617 | if (create_rf_connector) { |
| 618 | conn = kzalloc(sizeof(*conn), GFP_KERNEL); |
| 619 | if (!conn) |
| 620 | return -ENOMEM; |
| 621 | adap->conn = conn; |
| 622 | |
Xiubo Li | 5c3fbc5 | 2016-01-15 03:14:58 -0200 | [diff] [blame^] | 623 | adap->conn_pads = kzalloc(sizeof(*adap->conn_pads), GFP_KERNEL); |
Mauro Carvalho Chehab | 0230d60 | 2015-12-29 11:52:23 -0200 | [diff] [blame] | 624 | if (!adap->conn_pads) |
| 625 | return -ENOMEM; |
| 626 | |
| 627 | conn->flags = MEDIA_ENT_FL_CONNECTOR; |
| 628 | conn->function = MEDIA_ENT_F_CONN_RF; |
| 629 | conn->name = connector_name; |
| 630 | adap->conn_pads->flags = MEDIA_PAD_FL_SOURCE; |
| 631 | |
| 632 | ret = media_entity_pads_init(conn, 1, adap->conn_pads); |
| 633 | if (ret) |
| 634 | return ret; |
| 635 | |
| 636 | ret = media_device_register_entity(mdev, conn); |
| 637 | if (ret) |
| 638 | return ret; |
| 639 | |
Mauro Carvalho Chehab | a0cce2a | 2015-12-30 10:11:53 -0200 | [diff] [blame] | 640 | if (!ntuner) |
| 641 | ret = media_create_pad_links(mdev, |
| 642 | MEDIA_ENT_F_CONN_RF, |
| 643 | conn, 0, |
| 644 | MEDIA_ENT_F_DTV_DEMOD, |
| 645 | demod, 0, |
| 646 | MEDIA_LNK_FL_ENABLED, |
| 647 | false); |
Mauro Carvalho Chehab | 0230d60 | 2015-12-29 11:52:23 -0200 | [diff] [blame] | 648 | else |
Mauro Carvalho Chehab | a0cce2a | 2015-12-30 10:11:53 -0200 | [diff] [blame] | 649 | ret = media_create_pad_links(mdev, |
| 650 | MEDIA_ENT_F_CONN_RF, |
| 651 | conn, 0, |
| 652 | MEDIA_ENT_F_TUNER, |
| 653 | tuner, TUNER_PAD_RF_INPUT, |
| 654 | MEDIA_LNK_FL_ENABLED, |
| 655 | false); |
Mauro Carvalho Chehab | 0230d60 | 2015-12-29 11:52:23 -0200 | [diff] [blame] | 656 | if (ret) |
| 657 | return ret; |
| 658 | } |
| 659 | |
Mauro Carvalho Chehab | a0cce2a | 2015-12-30 10:11:53 -0200 | [diff] [blame] | 660 | if (ntuner && ndemod) { |
| 661 | ret = media_create_pad_links(mdev, |
| 662 | MEDIA_ENT_F_TUNER, |
Mauro Carvalho Chehab | 163c9bc | 2016-01-27 08:39:33 -0200 | [diff] [blame] | 663 | tuner, TUNER_PAD_OUTPUT, |
Mauro Carvalho Chehab | a0cce2a | 2015-12-30 10:11:53 -0200 | [diff] [blame] | 664 | MEDIA_ENT_F_DTV_DEMOD, |
| 665 | demod, 0, MEDIA_LNK_FL_ENABLED, |
| 666 | false); |
Mauro Carvalho Chehab | f50d516 | 2015-09-04 15:10:29 -0300 | [diff] [blame] | 667 | if (ret) |
| 668 | return ret; |
| 669 | } |
Mauro Carvalho Chehab | 4155109 | 2015-01-03 16:52:34 -0300 | [diff] [blame] | 670 | |
Mauro Carvalho Chehab | a0cce2a | 2015-12-30 10:11:53 -0200 | [diff] [blame] | 671 | if (ndemod && demux) { |
| 672 | ret = media_create_pad_links(mdev, |
| 673 | MEDIA_ENT_F_DTV_DEMOD, |
| 674 | demod, 1, |
| 675 | MEDIA_ENT_F_TS_DEMUX, |
| 676 | demux, 0, MEDIA_LNK_FL_ENABLED, |
| 677 | false); |
Mauro Carvalho Chehab | f50d516 | 2015-09-04 15:10:29 -0300 | [diff] [blame] | 678 | if (ret) |
| 679 | return -ENOMEM; |
| 680 | } |
| 681 | if (demux && ca) { |
| 682 | ret = media_create_pad_link(demux, 1, ca, |
| 683 | 0, MEDIA_LNK_FL_ENABLED); |
| 684 | if (!ret) |
| 685 | return -ENOMEM; |
| 686 | } |
Mauro Carvalho Chehab | 8ddb90d | 2015-08-21 09:32:38 -0300 | [diff] [blame] | 687 | |
Mauro Carvalho Chehab | df2f94e | 2015-08-21 16:18:18 -0300 | [diff] [blame] | 688 | /* Create demux links for each ringbuffer/pad */ |
| 689 | if (demux) { |
| 690 | media_device_for_each_entity(entity, mdev) { |
Mauro Carvalho Chehab | 4ca72ef | 2015-12-10 17:25:41 -0200 | [diff] [blame] | 691 | if (entity->function == MEDIA_ENT_F_IO_DTV) { |
Mauro Carvalho Chehab | df2f94e | 2015-08-21 16:18:18 -0300 | [diff] [blame] | 692 | if (!strncmp(entity->name, DVR_TSOUT, |
Mauro Carvalho Chehab | f50d516 | 2015-09-04 15:10:29 -0300 | [diff] [blame] | 693 | strlen(DVR_TSOUT))) { |
| 694 | ret = media_create_pad_link(demux, |
| 695 | ++dvr_pad, |
| 696 | entity, 0, 0); |
| 697 | if (ret) |
| 698 | return ret; |
| 699 | } |
Mauro Carvalho Chehab | df2f94e | 2015-08-21 16:18:18 -0300 | [diff] [blame] | 700 | if (!strncmp(entity->name, DEMUX_TSOUT, |
Mauro Carvalho Chehab | f50d516 | 2015-09-04 15:10:29 -0300 | [diff] [blame] | 701 | strlen(DEMUX_TSOUT))) { |
| 702 | ret = media_create_pad_link(demux, |
Mauro Carvalho Chehab | df2f94e | 2015-08-21 16:18:18 -0300 | [diff] [blame] | 703 | ++demux_pad, |
Mauro Carvalho Chehab | f50d516 | 2015-09-04 15:10:29 -0300 | [diff] [blame] | 704 | entity, 0, 0); |
| 705 | if (ret) |
| 706 | return ret; |
| 707 | } |
Mauro Carvalho Chehab | df2f94e | 2015-08-21 16:18:18 -0300 | [diff] [blame] | 708 | } |
| 709 | } |
| 710 | } |
| 711 | |
Mauro Carvalho Chehab | 8ed0714 | 2015-09-06 13:38:23 -0300 | [diff] [blame] | 712 | /* Create interface links for FE->tuner, DVR->demux and CA->ca */ |
Mauro Carvalho Chehab | cf975a4 | 2015-08-23 07:51:22 -0300 | [diff] [blame] | 713 | media_device_for_each_intf(intf, mdev) { |
Mauro Carvalho Chehab | f50d516 | 2015-09-04 15:10:29 -0300 | [diff] [blame] | 714 | if (intf->type == MEDIA_INTF_T_DVB_CA && ca) { |
| 715 | link = media_create_intf_link(ca, intf, |
| 716 | MEDIA_LNK_FL_ENABLED); |
| 717 | if (!link) |
| 718 | return -ENOMEM; |
| 719 | } |
Mauro Carvalho Chehab | cf975a4 | 2015-08-23 07:51:22 -0300 | [diff] [blame] | 720 | |
Mauro Carvalho Chehab | f50d516 | 2015-09-04 15:10:29 -0300 | [diff] [blame] | 721 | if (intf->type == MEDIA_INTF_T_DVB_FE && tuner) { |
| 722 | link = media_create_intf_link(tuner, intf, |
| 723 | MEDIA_LNK_FL_ENABLED); |
| 724 | if (!link) |
| 725 | return -ENOMEM; |
| 726 | } |
Mauro Carvalho Chehab | 8ed0714 | 2015-09-06 13:38:23 -0300 | [diff] [blame] | 727 | #if 0 |
| 728 | /* |
| 729 | * Indirect link - let's not create yet, as we don't know how |
| 730 | * to handle indirect links, nor if this will |
| 731 | * actually be needed. |
| 732 | */ |
Mauro Carvalho Chehab | f50d516 | 2015-09-04 15:10:29 -0300 | [diff] [blame] | 733 | if (intf->type == MEDIA_INTF_T_DVB_DVR && demux) { |
| 734 | link = media_create_intf_link(demux, intf, |
| 735 | MEDIA_LNK_FL_ENABLED); |
| 736 | if (!link) |
| 737 | return -ENOMEM; |
| 738 | } |
Mauro Carvalho Chehab | 8ed0714 | 2015-09-06 13:38:23 -0300 | [diff] [blame] | 739 | #endif |
Mauro Carvalho Chehab | 17813e2 | 2015-09-06 13:28:48 -0300 | [diff] [blame] | 740 | if (intf->type == MEDIA_INTF_T_DVB_DVR) { |
| 741 | ret = dvb_create_io_intf_links(adap, intf, DVR_TSOUT); |
| 742 | if (ret) |
| 743 | return ret; |
| 744 | } |
| 745 | if (intf->type == MEDIA_INTF_T_DVB_DEMUX) { |
| 746 | ret = dvb_create_io_intf_links(adap, intf, DEMUX_TSOUT); |
| 747 | if (ret) |
| 748 | return ret; |
Mauro Carvalho Chehab | df2f94e | 2015-08-21 16:18:18 -0300 | [diff] [blame] | 749 | } |
Mauro Carvalho Chehab | 8ddb90d | 2015-08-21 09:32:38 -0300 | [diff] [blame] | 750 | } |
Mauro Carvalho Chehab | f50d516 | 2015-09-04 15:10:29 -0300 | [diff] [blame] | 751 | return 0; |
Mauro Carvalho Chehab | 4155109 | 2015-01-03 16:52:34 -0300 | [diff] [blame] | 752 | } |
| 753 | EXPORT_SYMBOL_GPL(dvb_create_media_graph); |
Mauro Carvalho Chehab | 480884b | 2015-03-02 10:49:04 -0300 | [diff] [blame] | 754 | #endif |
Mauro Carvalho Chehab | 4155109 | 2015-01-03 16:52:34 -0300 | [diff] [blame] | 755 | |
Janne Grunau | 78e9200 | 2008-04-09 19:13:13 -0300 | [diff] [blame] | 756 | static int dvbdev_check_free_adapter_num(int num) |
| 757 | { |
| 758 | struct list_head *entry; |
| 759 | list_for_each(entry, &dvb_adapter_list) { |
| 760 | struct dvb_adapter *adap; |
| 761 | adap = list_entry(entry, struct dvb_adapter, list_head); |
| 762 | if (adap->num == num) |
| 763 | return 0; |
| 764 | } |
| 765 | return 1; |
| 766 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 767 | |
| 768 | static int dvbdev_get_free_adapter_num (void) |
| 769 | { |
| 770 | int num = 0; |
| 771 | |
| 772 | while (num < DVB_MAX_ADAPTERS) { |
Janne Grunau | 78e9200 | 2008-04-09 19:13:13 -0300 | [diff] [blame] | 773 | if (dvbdev_check_free_adapter_num(num)) |
| 774 | return num; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 775 | num++; |
| 776 | } |
| 777 | |
| 778 | return -ENFILE; |
| 779 | } |
| 780 | |
| 781 | |
Janne Grunau | 78e9200 | 2008-04-09 19:13:13 -0300 | [diff] [blame] | 782 | int dvb_register_adapter(struct dvb_adapter *adap, const char *name, |
| 783 | struct module *module, struct device *device, |
| 784 | short *adapter_nums) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 785 | { |
Janne Grunau | 78e9200 | 2008-04-09 19:13:13 -0300 | [diff] [blame] | 786 | int i, num; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 787 | |
Simon Arlott | c278850 | 2007-03-10 06:21:25 -0300 | [diff] [blame] | 788 | mutex_lock(&dvbdev_register_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 789 | |
Janne Grunau | 78e9200 | 2008-04-09 19:13:13 -0300 | [diff] [blame] | 790 | for (i = 0; i < DVB_MAX_ADAPTERS; ++i) { |
| 791 | num = adapter_nums[i]; |
| 792 | if (num >= 0 && num < DVB_MAX_ADAPTERS) { |
| 793 | /* use the one the driver asked for */ |
| 794 | if (dvbdev_check_free_adapter_num(num)) |
| 795 | break; |
| 796 | } else { |
| 797 | num = dvbdev_get_free_adapter_num(); |
| 798 | break; |
| 799 | } |
| 800 | num = -1; |
| 801 | } |
| 802 | |
| 803 | if (num < 0) { |
Ingo Molnar | 1e4baed | 2006-01-15 07:52:23 -0200 | [diff] [blame] | 804 | mutex_unlock(&dvbdev_register_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 805 | return -ENFILE; |
| 806 | } |
| 807 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 808 | memset (adap, 0, sizeof(struct dvb_adapter)); |
| 809 | INIT_LIST_HEAD (&adap->device_list); |
| 810 | |
Simon Arlott | 900858e | 2007-05-06 21:06:32 -0300 | [diff] [blame] | 811 | printk(KERN_INFO "DVB: registering new adapter (%s)\n", name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 812 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 813 | adap->num = num; |
| 814 | adap->name = name; |
| 815 | adap->module = module; |
Andrew de Quincey | d09dbf9 | 2006-04-10 09:27:37 -0300 | [diff] [blame] | 816 | adap->device = device; |
Darron Broad | 59b1842 | 2008-10-11 11:44:05 -0300 | [diff] [blame] | 817 | adap->mfe_shared = 0; |
| 818 | adap->mfe_dvbdev = NULL; |
| 819 | mutex_init (&adap->mfe_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 820 | |
| 821 | list_add_tail (&adap->list_head, &dvb_adapter_list); |
| 822 | |
Ingo Molnar | 1e4baed | 2006-01-15 07:52:23 -0200 | [diff] [blame] | 823 | mutex_unlock(&dvbdev_register_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 824 | |
| 825 | return num; |
| 826 | } |
| 827 | EXPORT_SYMBOL(dvb_register_adapter); |
| 828 | |
| 829 | |
| 830 | int dvb_unregister_adapter(struct dvb_adapter *adap) |
| 831 | { |
Simon Arlott | c278850 | 2007-03-10 06:21:25 -0300 | [diff] [blame] | 832 | mutex_lock(&dvbdev_register_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 833 | list_del (&adap->list_head); |
Ingo Molnar | 1e4baed | 2006-01-15 07:52:23 -0200 | [diff] [blame] | 834 | mutex_unlock(&dvbdev_register_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 835 | return 0; |
| 836 | } |
| 837 | EXPORT_SYMBOL(dvb_unregister_adapter); |
| 838 | |
| 839 | /* if the miracle happens and "generic_usercopy()" is included into |
| 840 | the kernel, then this can vanish. please don't make the mistake and |
| 841 | define this as video_usercopy(). this will introduce a dependecy |
| 842 | to the v4l "videodev.o" module, which is unnecessary for some |
| 843 | cards (ie. the budget dvb-cards don't need the v4l module...) */ |
Arnd Bergmann | 16ef8de | 2010-04-27 00:24:00 +0200 | [diff] [blame] | 844 | int dvb_usercopy(struct file *file, |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 845 | unsigned int cmd, unsigned long arg, |
Arnd Bergmann | 16ef8de | 2010-04-27 00:24:00 +0200 | [diff] [blame] | 846 | int (*func)(struct file *file, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 847 | unsigned int cmd, void *arg)) |
| 848 | { |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 849 | char sbuf[128]; |
| 850 | void *mbuf = NULL; |
| 851 | void *parg = NULL; |
| 852 | int err = -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 853 | |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 854 | /* Copy arguments into temp kernel buffer */ |
| 855 | switch (_IOC_DIR(cmd)) { |
| 856 | case _IOC_NONE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 857 | /* |
| 858 | * For this command, the pointer is actually an integer |
| 859 | * argument. |
| 860 | */ |
| 861 | parg = (void *) arg; |
| 862 | break; |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 863 | case _IOC_READ: /* some v4l ioctls are marked wrong ... */ |
| 864 | case _IOC_WRITE: |
| 865 | case (_IOC_WRITE | _IOC_READ): |
| 866 | if (_IOC_SIZE(cmd) <= sizeof(sbuf)) { |
Michael Krufky | 50c25ff | 2006-01-09 15:25:34 -0200 | [diff] [blame] | 867 | parg = sbuf; |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 868 | } else { |
Michael Krufky | 50c25ff | 2006-01-09 15:25:34 -0200 | [diff] [blame] | 869 | /* too big to allocate from stack */ |
| 870 | mbuf = kmalloc(_IOC_SIZE(cmd),GFP_KERNEL); |
| 871 | if (NULL == mbuf) |
| 872 | return -ENOMEM; |
| 873 | parg = mbuf; |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 874 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 875 | |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 876 | err = -EFAULT; |
| 877 | if (copy_from_user(parg, (void __user *)arg, _IOC_SIZE(cmd))) |
Michael Krufky | 50c25ff | 2006-01-09 15:25:34 -0200 | [diff] [blame] | 878 | goto out; |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 879 | break; |
| 880 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 881 | |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 882 | /* call driver */ |
Arnd Bergmann | 16ef8de | 2010-04-27 00:24:00 +0200 | [diff] [blame] | 883 | if ((err = func(file, cmd, parg)) == -ENOIOCTLCMD) |
Wanlong Gao | d9751fd | 2012-08-27 03:23:14 -0300 | [diff] [blame] | 884 | err = -ENOTTY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 885 | |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 886 | if (err < 0) |
| 887 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 888 | |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 889 | /* Copy results into user buffer */ |
| 890 | switch (_IOC_DIR(cmd)) |
| 891 | { |
| 892 | case _IOC_READ: |
| 893 | case (_IOC_WRITE | _IOC_READ): |
| 894 | if (copy_to_user((void __user *)arg, parg, _IOC_SIZE(cmd))) |
Michael Krufky | 50c25ff | 2006-01-09 15:25:34 -0200 | [diff] [blame] | 895 | err = -EFAULT; |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 896 | break; |
| 897 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 898 | |
| 899 | out: |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 900 | kfree(mbuf); |
| 901 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 902 | } |
| 903 | |
Kay Sievers | a5f4c0c | 2008-10-27 22:27:37 -0300 | [diff] [blame] | 904 | static int dvb_uevent(struct device *dev, struct kobj_uevent_env *env) |
| 905 | { |
| 906 | struct dvb_device *dvbdev = dev_get_drvdata(dev); |
| 907 | |
Kay Sievers | a5f4c0c | 2008-10-27 22:27:37 -0300 | [diff] [blame] | 908 | add_uevent_var(env, "DVB_ADAPTER_NUM=%d", dvbdev->adapter->num); |
Kay Sievers | 763d19b | 2008-12-31 23:35:24 -0300 | [diff] [blame] | 909 | add_uevent_var(env, "DVB_DEVICE_TYPE=%s", dnames[dvbdev->type]); |
| 910 | add_uevent_var(env, "DVB_DEVICE_NUM=%d", dvbdev->id); |
Kay Sievers | a5f4c0c | 2008-10-27 22:27:37 -0300 | [diff] [blame] | 911 | return 0; |
| 912 | } |
| 913 | |
Al Viro | 2c9ede5 | 2011-07-23 20:24:48 -0400 | [diff] [blame] | 914 | static char *dvb_devnode(struct device *dev, umode_t *mode) |
Kay Sievers | 8a8bdcc | 2009-04-30 15:23:42 +0200 | [diff] [blame] | 915 | { |
| 916 | struct dvb_device *dvbdev = dev_get_drvdata(dev); |
| 917 | |
| 918 | return kasprintf(GFP_KERNEL, "dvb/adapter%d/%s%d", |
| 919 | dvbdev->adapter->num, dnames[dvbdev->type], dvbdev->id); |
| 920 | } |
| 921 | |
| 922 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 923 | static int __init init_dvbdev(void) |
| 924 | { |
| 925 | int retval; |
| 926 | dev_t dev = MKDEV(DVB_MAJOR, 0); |
| 927 | |
| 928 | if ((retval = register_chrdev_region(dev, MAX_DVB_MINORS, "DVB")) != 0) { |
Simon Arlott | 900858e | 2007-05-06 21:06:32 -0300 | [diff] [blame] | 929 | printk(KERN_ERR "dvb-core: unable to get major %d\n", DVB_MAJOR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 930 | return retval; |
| 931 | } |
| 932 | |
| 933 | cdev_init(&dvb_device_cdev, &dvb_device_fops); |
| 934 | if ((retval = cdev_add(&dvb_device_cdev, dev, MAX_DVB_MINORS)) != 0) { |
Simon Arlott | 900858e | 2007-05-06 21:06:32 -0300 | [diff] [blame] | 935 | printk(KERN_ERR "dvb-core: unable register character device\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 936 | goto error; |
| 937 | } |
| 938 | |
gregkh@suse.de | 56b2293 | 2005-03-23 10:01:41 -0800 | [diff] [blame] | 939 | dvb_class = class_create(THIS_MODULE, "dvb"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 940 | if (IS_ERR(dvb_class)) { |
| 941 | retval = PTR_ERR(dvb_class); |
| 942 | goto error; |
| 943 | } |
Kay Sievers | a5f4c0c | 2008-10-27 22:27:37 -0300 | [diff] [blame] | 944 | dvb_class->dev_uevent = dvb_uevent; |
Kay Sievers | e454cea | 2009-09-18 23:01:12 +0200 | [diff] [blame] | 945 | dvb_class->devnode = dvb_devnode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 946 | return 0; |
| 947 | |
| 948 | error: |
| 949 | cdev_del(&dvb_device_cdev); |
| 950 | unregister_chrdev_region(dev, MAX_DVB_MINORS); |
| 951 | return retval; |
| 952 | } |
| 953 | |
| 954 | |
| 955 | static void __exit exit_dvbdev(void) |
| 956 | { |
gregkh@suse.de | 56b2293 | 2005-03-23 10:01:41 -0800 | [diff] [blame] | 957 | class_destroy(dvb_class); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 958 | cdev_del(&dvb_device_cdev); |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 959 | unregister_chrdev_region(MKDEV(DVB_MAJOR, 0), MAX_DVB_MINORS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 960 | } |
| 961 | |
Simon Arlott | 4abdcf9 | 2007-05-06 20:56:14 -0300 | [diff] [blame] | 962 | subsys_initcall(init_dvbdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 963 | module_exit(exit_dvbdev); |
| 964 | |
| 965 | MODULE_DESCRIPTION("DVB Core Driver"); |
| 966 | MODULE_AUTHOR("Marcus Metzler, Ralph Metzler, Holger Waechtler"); |
| 967 | MODULE_LICENSE("GPL"); |