Hans Verkuil | 27a5e6d | 2008-07-20 08:43:17 -0300 | [diff] [blame] | 1 | /* |
| 2 | * Video capture interface for Linux version 2 |
| 3 | * |
| 4 | * A generic video device interface for the LINUX operating system |
| 5 | * using a set of device structures/vectors for low level operations. |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License |
| 9 | * as published by the Free Software Foundation; either version |
| 10 | * 2 of the License, or (at your option) any later version. |
| 11 | * |
| 12 | * Authors: Alan Cox, <alan@redhat.com> (version 1) |
| 13 | * Mauro Carvalho Chehab <mchehab@infradead.org> (version 2) |
| 14 | * |
| 15 | * Fixes: 20000516 Claudio Matsuoka <claudio@conectiva.com> |
| 16 | * - Added procfs support |
| 17 | */ |
| 18 | |
| 19 | #include <linux/module.h> |
| 20 | #include <linux/types.h> |
| 21 | #include <linux/kernel.h> |
| 22 | #include <linux/mm.h> |
| 23 | #include <linux/string.h> |
| 24 | #include <linux/errno.h> |
| 25 | #include <linux/init.h> |
| 26 | #include <linux/kmod.h> |
| 27 | #include <linux/slab.h> |
| 28 | #include <linux/smp_lock.h> |
| 29 | #include <asm/uaccess.h> |
| 30 | #include <asm/system.h> |
| 31 | |
| 32 | #include <media/v4l2-common.h> |
| 33 | |
| 34 | #define VIDEO_NUM_DEVICES 256 |
| 35 | #define VIDEO_NAME "video4linux" |
| 36 | |
| 37 | /* |
| 38 | * sysfs stuff |
| 39 | */ |
| 40 | |
| 41 | static ssize_t show_index(struct device *cd, |
| 42 | struct device_attribute *attr, char *buf) |
| 43 | { |
Hans Verkuil | 22a04f1 | 2008-07-20 06:35:02 -0300 | [diff] [blame] | 44 | struct video_device *vfd = container_of(cd, struct video_device, dev); |
Hans Verkuil | bfa8a27 | 2008-08-23 07:48:38 -0300 | [diff] [blame] | 45 | |
Hans Verkuil | 27a5e6d | 2008-07-20 08:43:17 -0300 | [diff] [blame] | 46 | return sprintf(buf, "%i\n", vfd->index); |
| 47 | } |
| 48 | |
| 49 | static ssize_t show_name(struct device *cd, |
| 50 | struct device_attribute *attr, char *buf) |
| 51 | { |
Hans Verkuil | 22a04f1 | 2008-07-20 06:35:02 -0300 | [diff] [blame] | 52 | struct video_device *vfd = container_of(cd, struct video_device, dev); |
Hans Verkuil | bfa8a27 | 2008-08-23 07:48:38 -0300 | [diff] [blame] | 53 | |
Hans Verkuil | 27a5e6d | 2008-07-20 08:43:17 -0300 | [diff] [blame] | 54 | return sprintf(buf, "%.*s\n", (int)sizeof(vfd->name), vfd->name); |
| 55 | } |
| 56 | |
| 57 | static struct device_attribute video_device_attrs[] = { |
| 58 | __ATTR(name, S_IRUGO, show_name, NULL), |
| 59 | __ATTR(index, S_IRUGO, show_index, NULL), |
| 60 | __ATTR_NULL |
| 61 | }; |
| 62 | |
Hans Verkuil | 7f8ecfa | 2008-08-29 17:31:35 -0300 | [diff] [blame] | 63 | /* |
| 64 | * Active devices |
| 65 | */ |
| 66 | static struct video_device *video_device[VIDEO_NUM_DEVICES]; |
| 67 | static DEFINE_MUTEX(videodev_lock); |
Hans Verkuil | dd89601 | 2008-10-04 08:36:54 -0300 | [diff] [blame] | 68 | static DECLARE_BITMAP(video_nums[VFL_TYPE_MAX], VIDEO_NUM_DEVICES); |
Hans Verkuil | 7f8ecfa | 2008-08-29 17:31:35 -0300 | [diff] [blame] | 69 | |
Hans Verkuil | 27a5e6d | 2008-07-20 08:43:17 -0300 | [diff] [blame] | 70 | struct video_device *video_device_alloc(void) |
| 71 | { |
Hans Verkuil | bfa8a27 | 2008-08-23 07:48:38 -0300 | [diff] [blame] | 72 | return kzalloc(sizeof(struct video_device), GFP_KERNEL); |
Hans Verkuil | 27a5e6d | 2008-07-20 08:43:17 -0300 | [diff] [blame] | 73 | } |
| 74 | EXPORT_SYMBOL(video_device_alloc); |
| 75 | |
| 76 | void video_device_release(struct video_device *vfd) |
| 77 | { |
| 78 | kfree(vfd); |
| 79 | } |
| 80 | EXPORT_SYMBOL(video_device_release); |
| 81 | |
Hans Verkuil | f9e86b5 | 2008-08-23 05:47:41 -0300 | [diff] [blame] | 82 | void video_device_release_empty(struct video_device *vfd) |
| 83 | { |
| 84 | /* Do nothing */ |
| 85 | /* Only valid when the video_device struct is a static. */ |
| 86 | } |
| 87 | EXPORT_SYMBOL(video_device_release_empty); |
| 88 | |
Hans Verkuil | 7f8ecfa | 2008-08-29 17:31:35 -0300 | [diff] [blame] | 89 | /* Called when the last user of the character device is gone. */ |
| 90 | static void v4l2_chardev_release(struct kobject *kobj) |
| 91 | { |
| 92 | struct video_device *vfd = container_of(kobj, struct video_device, cdev.kobj); |
| 93 | |
| 94 | mutex_lock(&videodev_lock); |
Hans Verkuil | 6ea9a18 | 2008-08-30 09:40:47 -0300 | [diff] [blame] | 95 | if (video_device[vfd->minor] != vfd) { |
| 96 | mutex_unlock(&videodev_lock); |
| 97 | BUG(); |
| 98 | return; |
| 99 | } |
Hans Verkuil | 7f8ecfa | 2008-08-29 17:31:35 -0300 | [diff] [blame] | 100 | |
| 101 | /* Free up this device for reuse */ |
| 102 | video_device[vfd->minor] = NULL; |
Hans Verkuil | dd89601 | 2008-10-04 08:36:54 -0300 | [diff] [blame] | 103 | clear_bit(vfd->num, video_nums[vfd->vfl_type]); |
Hans Verkuil | 7f8ecfa | 2008-08-29 17:31:35 -0300 | [diff] [blame] | 104 | mutex_unlock(&videodev_lock); |
| 105 | |
| 106 | /* Release the character device */ |
| 107 | vfd->cdev_release(kobj); |
| 108 | /* Release video_device and perform other |
| 109 | cleanups as needed. */ |
| 110 | if (vfd->release) |
| 111 | vfd->release(vfd); |
| 112 | } |
| 113 | |
| 114 | /* The new kobj_type for the character device */ |
| 115 | static struct kobj_type v4l2_ktype_cdev_default = { |
| 116 | .release = v4l2_chardev_release, |
| 117 | }; |
| 118 | |
Hans Verkuil | 27a5e6d | 2008-07-20 08:43:17 -0300 | [diff] [blame] | 119 | static void video_release(struct device *cd) |
| 120 | { |
Hans Verkuil | 22a04f1 | 2008-07-20 06:35:02 -0300 | [diff] [blame] | 121 | struct video_device *vfd = container_of(cd, struct video_device, dev); |
Hans Verkuil | 27a5e6d | 2008-07-20 08:43:17 -0300 | [diff] [blame] | 122 | |
Hans Verkuil | 7f8ecfa | 2008-08-29 17:31:35 -0300 | [diff] [blame] | 123 | /* It's now safe to delete the char device. |
| 124 | This will either trigger the v4l2_chardev_release immediately (if |
| 125 | the refcount goes to 0) or later when the last user of the |
| 126 | character device closes it. */ |
| 127 | cdev_del(&vfd->cdev); |
Hans Verkuil | 27a5e6d | 2008-07-20 08:43:17 -0300 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | static struct class video_class = { |
| 131 | .name = VIDEO_NAME, |
| 132 | .dev_attrs = video_device_attrs, |
| 133 | .dev_release = video_release, |
| 134 | }; |
| 135 | |
Hans Verkuil | 27a5e6d | 2008-07-20 08:43:17 -0300 | [diff] [blame] | 136 | struct video_device *video_devdata(struct file *file) |
| 137 | { |
| 138 | return video_device[iminor(file->f_path.dentry->d_inode)]; |
| 139 | } |
| 140 | EXPORT_SYMBOL(video_devdata); |
| 141 | |
Hans Verkuil | 27a5e6d | 2008-07-20 08:43:17 -0300 | [diff] [blame] | 142 | /** |
| 143 | * get_index - assign stream number based on parent device |
| 144 | * @vdev: video_device to assign index number to, vdev->dev should be assigned |
| 145 | * @num: -1 if auto assign, requested number otherwise |
| 146 | * |
| 147 | * |
| 148 | * returns -ENFILE if num is already in use, a free index number if |
| 149 | * successful. |
| 150 | */ |
| 151 | static int get_index(struct video_device *vdev, int num) |
| 152 | { |
| 153 | u32 used = 0; |
| 154 | const int max_index = sizeof(used) * 8 - 1; |
| 155 | int i; |
| 156 | |
| 157 | /* Currently a single v4l driver instance cannot create more than |
| 158 | 32 devices. |
| 159 | Increase to u64 or an array of u32 if more are needed. */ |
| 160 | if (num > max_index) { |
| 161 | printk(KERN_ERR "videodev: %s num is too large\n", __func__); |
| 162 | return -EINVAL; |
| 163 | } |
| 164 | |
| 165 | for (i = 0; i < VIDEO_NUM_DEVICES; i++) { |
| 166 | if (video_device[i] != NULL && |
| 167 | video_device[i] != vdev && |
Hans Verkuil | 5e85e73 | 2008-07-20 06:31:39 -0300 | [diff] [blame] | 168 | video_device[i]->parent == vdev->parent) { |
Hans Verkuil | 27a5e6d | 2008-07-20 08:43:17 -0300 | [diff] [blame] | 169 | used |= 1 << video_device[i]->index; |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | if (num >= 0) { |
| 174 | if (used & (1 << num)) |
| 175 | return -ENFILE; |
| 176 | return num; |
| 177 | } |
| 178 | |
| 179 | i = ffz(used); |
| 180 | return i > max_index ? -ENFILE : i; |
| 181 | } |
| 182 | |
| 183 | static const struct file_operations video_fops; |
| 184 | |
| 185 | int video_register_device(struct video_device *vfd, int type, int nr) |
| 186 | { |
| 187 | return video_register_device_index(vfd, type, nr, -1); |
| 188 | } |
| 189 | EXPORT_SYMBOL(video_register_device); |
| 190 | |
| 191 | /** |
Randy Dunlap | edc9189 | 2008-07-28 15:39:38 -0300 | [diff] [blame] | 192 | * video_register_device_index - register video4linux devices |
Hans Verkuil | 27a5e6d | 2008-07-20 08:43:17 -0300 | [diff] [blame] | 193 | * @vfd: video device structure we want to register |
| 194 | * @type: type of device to register |
| 195 | * @nr: which device number (0 == /dev/video0, 1 == /dev/video1, ... |
| 196 | * -1 == first free) |
Randy Dunlap | edc9189 | 2008-07-28 15:39:38 -0300 | [diff] [blame] | 197 | * @index: stream number based on parent device; |
| 198 | * -1 if auto assign, requested number otherwise |
Hans Verkuil | 27a5e6d | 2008-07-20 08:43:17 -0300 | [diff] [blame] | 199 | * |
| 200 | * The registration code assigns minor numbers based on the type |
| 201 | * requested. -ENFILE is returned in all the device slots for this |
| 202 | * category are full. If not then the minor field is set and the |
| 203 | * driver initialize function is called (if non %NULL). |
| 204 | * |
| 205 | * Zero is returned on success. |
| 206 | * |
| 207 | * Valid types are |
| 208 | * |
| 209 | * %VFL_TYPE_GRABBER - A frame grabber |
| 210 | * |
| 211 | * %VFL_TYPE_VTX - A teletext device |
| 212 | * |
| 213 | * %VFL_TYPE_VBI - Vertical blank data (undecoded) |
| 214 | * |
| 215 | * %VFL_TYPE_RADIO - A radio card |
| 216 | */ |
| 217 | |
| 218 | int video_register_device_index(struct video_device *vfd, int type, int nr, |
| 219 | int index) |
| 220 | { |
| 221 | int i = 0; |
Hans Verkuil | 27a5e6d | 2008-07-20 08:43:17 -0300 | [diff] [blame] | 222 | int ret; |
Hans Verkuil | dd89601 | 2008-10-04 08:36:54 -0300 | [diff] [blame] | 223 | int minor_offset = 0; |
| 224 | int minor_cnt = VIDEO_NUM_DEVICES; |
| 225 | const char *name_base; |
Hans Verkuil | 9d95af9 | 2008-08-24 11:18:47 -0300 | [diff] [blame] | 226 | void *priv = video_get_drvdata(vfd); |
Hans Verkuil | 27a5e6d | 2008-07-20 08:43:17 -0300 | [diff] [blame] | 227 | |
Hans Verkuil | d6e7497 | 2008-08-23 06:27:59 -0300 | [diff] [blame] | 228 | /* the release callback MUST be present */ |
| 229 | BUG_ON(!vfd->release); |
Henrik Kretzschmar | f3b9f50 | 2008-09-03 17:11:53 -0300 | [diff] [blame] | 230 | |
Henrik Kretzschmar | ee7aa9f | 2008-08-22 16:41:03 -0300 | [diff] [blame] | 231 | if (vfd == NULL) |
| 232 | return -EINVAL; |
| 233 | |
Hans Verkuil | 27a5e6d | 2008-07-20 08:43:17 -0300 | [diff] [blame] | 234 | switch (type) { |
| 235 | case VFL_TYPE_GRABBER: |
Hans Verkuil | 27a5e6d | 2008-07-20 08:43:17 -0300 | [diff] [blame] | 236 | name_base = "video"; |
| 237 | break; |
| 238 | case VFL_TYPE_VTX: |
Hans Verkuil | 27a5e6d | 2008-07-20 08:43:17 -0300 | [diff] [blame] | 239 | name_base = "vtx"; |
| 240 | break; |
| 241 | case VFL_TYPE_VBI: |
Hans Verkuil | 27a5e6d | 2008-07-20 08:43:17 -0300 | [diff] [blame] | 242 | name_base = "vbi"; |
| 243 | break; |
| 244 | case VFL_TYPE_RADIO: |
Hans Verkuil | 27a5e6d | 2008-07-20 08:43:17 -0300 | [diff] [blame] | 245 | name_base = "radio"; |
| 246 | break; |
| 247 | default: |
| 248 | printk(KERN_ERR "%s called with unknown type: %d\n", |
| 249 | __func__, type); |
Henrik Kretzschmar | 46f2c21 | 2008-09-03 16:47:39 -0300 | [diff] [blame] | 250 | return -EINVAL; |
Hans Verkuil | 27a5e6d | 2008-07-20 08:43:17 -0300 | [diff] [blame] | 251 | } |
| 252 | |
Hans Verkuil | dd89601 | 2008-10-04 08:36:54 -0300 | [diff] [blame] | 253 | vfd->vfl_type = type; |
| 254 | |
| 255 | #ifdef CONFIG_VIDEO_FIXED_MINOR_RANGES |
| 256 | /* Keep the ranges for the first four types for historical |
| 257 | * reasons. |
| 258 | * Newer devices (not yet in place) should use the range |
| 259 | * of 128-191 and just pick the first free minor there |
| 260 | * (new style). */ |
| 261 | switch (type) { |
| 262 | case VFL_TYPE_GRABBER: |
| 263 | minor_offset = 0; |
| 264 | minor_cnt = 64; |
| 265 | break; |
| 266 | case VFL_TYPE_RADIO: |
| 267 | minor_offset = 64; |
| 268 | minor_cnt = 64; |
| 269 | break; |
| 270 | case VFL_TYPE_VTX: |
| 271 | minor_offset = 192; |
| 272 | minor_cnt = 32; |
| 273 | break; |
| 274 | case VFL_TYPE_VBI: |
| 275 | minor_offset = 224; |
| 276 | minor_cnt = 32; |
| 277 | break; |
| 278 | default: |
| 279 | minor_offset = 128; |
| 280 | minor_cnt = 64; |
| 281 | break; |
| 282 | } |
| 283 | #endif |
| 284 | |
Hans Verkuil | 7f8ecfa | 2008-08-29 17:31:35 -0300 | [diff] [blame] | 285 | /* Initialize the character device */ |
| 286 | cdev_init(&vfd->cdev, vfd->fops); |
| 287 | vfd->cdev.owner = vfd->fops->owner; |
Hans Verkuil | 27a5e6d | 2008-07-20 08:43:17 -0300 | [diff] [blame] | 288 | /* pick a minor number */ |
| 289 | mutex_lock(&videodev_lock); |
Hans Verkuil | dd89601 | 2008-10-04 08:36:54 -0300 | [diff] [blame] | 290 | nr = find_next_zero_bit(video_nums[type], minor_cnt, nr == -1 ? 0 : nr); |
| 291 | if (nr == minor_cnt) |
| 292 | nr = find_first_zero_bit(video_nums[type], minor_cnt); |
| 293 | if (nr == minor_cnt) { |
| 294 | printk(KERN_ERR "could not get a free kernel number\n"); |
| 295 | mutex_unlock(&videodev_lock); |
| 296 | return -ENFILE; |
Hans Verkuil | 27a5e6d | 2008-07-20 08:43:17 -0300 | [diff] [blame] | 297 | } |
Hans Verkuil | dd89601 | 2008-10-04 08:36:54 -0300 | [diff] [blame] | 298 | #ifdef CONFIG_VIDEO_FIXED_MINOR_RANGES |
| 299 | /* 1-on-1 mapping of kernel number to minor number */ |
| 300 | i = nr; |
| 301 | #else |
| 302 | /* The kernel number and minor numbers are independent */ |
| 303 | for (i = 0; i < VIDEO_NUM_DEVICES; i++) |
| 304 | if (video_device[i] == NULL) |
| 305 | break; |
| 306 | if (i == VIDEO_NUM_DEVICES) { |
| 307 | mutex_unlock(&videodev_lock); |
| 308 | printk(KERN_ERR "could not get a free minor\n"); |
| 309 | return -ENFILE; |
| 310 | } |
| 311 | #endif |
| 312 | vfd->minor = i + minor_offset; |
| 313 | vfd->num = nr; |
| 314 | set_bit(nr, video_nums[type]); |
| 315 | BUG_ON(video_device[vfd->minor]); |
| 316 | video_device[vfd->minor] = vfd; |
Hans Verkuil | 27a5e6d | 2008-07-20 08:43:17 -0300 | [diff] [blame] | 317 | |
| 318 | ret = get_index(vfd, index); |
| 319 | vfd->index = ret; |
| 320 | |
| 321 | mutex_unlock(&videodev_lock); |
| 322 | |
| 323 | if (ret < 0) { |
| 324 | printk(KERN_ERR "%s: get_index failed\n", __func__); |
| 325 | goto fail_minor; |
| 326 | } |
| 327 | |
Hans Verkuil | 7f8ecfa | 2008-08-29 17:31:35 -0300 | [diff] [blame] | 328 | ret = cdev_add(&vfd->cdev, MKDEV(VIDEO_MAJOR, vfd->minor), 1); |
| 329 | if (ret < 0) { |
| 330 | printk(KERN_ERR "%s: cdev_add failed\n", __func__); |
| 331 | goto fail_minor; |
| 332 | } |
Hans Verkuil | 27a5e6d | 2008-07-20 08:43:17 -0300 | [diff] [blame] | 333 | /* sysfs class */ |
Hans Verkuil | bfa8a27 | 2008-08-23 07:48:38 -0300 | [diff] [blame] | 334 | memset(&vfd->dev, 0, sizeof(vfd->dev)); |
Hans Verkuil | 9d95af9 | 2008-08-24 11:18:47 -0300 | [diff] [blame] | 335 | /* The memset above cleared the device's drvdata, so |
| 336 | put back the copy we made earlier. */ |
| 337 | video_set_drvdata(vfd, priv); |
Hans Verkuil | 22a04f1 | 2008-07-20 06:35:02 -0300 | [diff] [blame] | 338 | vfd->dev.class = &video_class; |
| 339 | vfd->dev.devt = MKDEV(VIDEO_MAJOR, vfd->minor); |
Hans Verkuil | 5e85e73 | 2008-07-20 06:31:39 -0300 | [diff] [blame] | 340 | if (vfd->parent) |
Hans Verkuil | 22a04f1 | 2008-07-20 06:35:02 -0300 | [diff] [blame] | 341 | vfd->dev.parent = vfd->parent; |
Hans Verkuil | dd89601 | 2008-10-04 08:36:54 -0300 | [diff] [blame] | 342 | sprintf(vfd->dev.bus_id, "%s%d", name_base, nr); |
Hans Verkuil | 22a04f1 | 2008-07-20 06:35:02 -0300 | [diff] [blame] | 343 | ret = device_register(&vfd->dev); |
Hans Verkuil | 27a5e6d | 2008-07-20 08:43:17 -0300 | [diff] [blame] | 344 | if (ret < 0) { |
| 345 | printk(KERN_ERR "%s: device_register failed\n", __func__); |
Hans Verkuil | 7f8ecfa | 2008-08-29 17:31:35 -0300 | [diff] [blame] | 346 | goto del_cdev; |
Hans Verkuil | 27a5e6d | 2008-07-20 08:43:17 -0300 | [diff] [blame] | 347 | } |
Hans Verkuil | 7f8ecfa | 2008-08-29 17:31:35 -0300 | [diff] [blame] | 348 | /* Remember the cdev's release function */ |
| 349 | vfd->cdev_release = vfd->cdev.kobj.ktype->release; |
| 350 | /* Install our own */ |
| 351 | vfd->cdev.kobj.ktype = &v4l2_ktype_cdev_default; |
Hans Verkuil | 27a5e6d | 2008-07-20 08:43:17 -0300 | [diff] [blame] | 352 | return 0; |
| 353 | |
Hans Verkuil | 7f8ecfa | 2008-08-29 17:31:35 -0300 | [diff] [blame] | 354 | del_cdev: |
| 355 | cdev_del(&vfd->cdev); |
| 356 | |
Hans Verkuil | 27a5e6d | 2008-07-20 08:43:17 -0300 | [diff] [blame] | 357 | fail_minor: |
| 358 | mutex_lock(&videodev_lock); |
| 359 | video_device[vfd->minor] = NULL; |
Hans Verkuil | dd89601 | 2008-10-04 08:36:54 -0300 | [diff] [blame] | 360 | clear_bit(vfd->num, video_nums[type]); |
Hans Verkuil | 27a5e6d | 2008-07-20 08:43:17 -0300 | [diff] [blame] | 361 | mutex_unlock(&videodev_lock); |
Hans Verkuil | bfa8a27 | 2008-08-23 07:48:38 -0300 | [diff] [blame] | 362 | vfd->minor = -1; |
Hans Verkuil | 27a5e6d | 2008-07-20 08:43:17 -0300 | [diff] [blame] | 363 | return ret; |
| 364 | } |
| 365 | EXPORT_SYMBOL(video_register_device_index); |
| 366 | |
| 367 | /** |
| 368 | * video_unregister_device - unregister a video4linux device |
| 369 | * @vfd: the device to unregister |
| 370 | * |
| 371 | * This unregisters the passed device and deassigns the minor |
| 372 | * number. Future open calls will be met with errors. |
| 373 | */ |
| 374 | |
| 375 | void video_unregister_device(struct video_device *vfd) |
| 376 | { |
Hans Verkuil | 22a04f1 | 2008-07-20 06:35:02 -0300 | [diff] [blame] | 377 | device_unregister(&vfd->dev); |
Hans Verkuil | 27a5e6d | 2008-07-20 08:43:17 -0300 | [diff] [blame] | 378 | } |
| 379 | EXPORT_SYMBOL(video_unregister_device); |
| 380 | |
| 381 | /* |
Hans Verkuil | 27a5e6d | 2008-07-20 08:43:17 -0300 | [diff] [blame] | 382 | * Initialise video for linux |
| 383 | */ |
Hans Verkuil | 27a5e6d | 2008-07-20 08:43:17 -0300 | [diff] [blame] | 384 | static int __init videodev_init(void) |
| 385 | { |
Hans Verkuil | 7f8ecfa | 2008-08-29 17:31:35 -0300 | [diff] [blame] | 386 | dev_t dev = MKDEV(VIDEO_MAJOR, 0); |
Hans Verkuil | 27a5e6d | 2008-07-20 08:43:17 -0300 | [diff] [blame] | 387 | int ret; |
| 388 | |
| 389 | printk(KERN_INFO "Linux video capture interface: v2.00\n"); |
Hans Verkuil | 7f8ecfa | 2008-08-29 17:31:35 -0300 | [diff] [blame] | 390 | ret = register_chrdev_region(dev, VIDEO_NUM_DEVICES, VIDEO_NAME); |
| 391 | if (ret < 0) { |
| 392 | printk(KERN_WARNING "videodev: unable to get major %d\n", |
| 393 | VIDEO_MAJOR); |
| 394 | return ret; |
Hans Verkuil | 27a5e6d | 2008-07-20 08:43:17 -0300 | [diff] [blame] | 395 | } |
| 396 | |
| 397 | ret = class_register(&video_class); |
| 398 | if (ret < 0) { |
Hans Verkuil | 7f8ecfa | 2008-08-29 17:31:35 -0300 | [diff] [blame] | 399 | unregister_chrdev_region(dev, VIDEO_NUM_DEVICES); |
Hans Verkuil | 27a5e6d | 2008-07-20 08:43:17 -0300 | [diff] [blame] | 400 | printk(KERN_WARNING "video_dev: class_register failed\n"); |
| 401 | return -EIO; |
| 402 | } |
| 403 | |
| 404 | return 0; |
| 405 | } |
| 406 | |
| 407 | static void __exit videodev_exit(void) |
| 408 | { |
Hans Verkuil | 7f8ecfa | 2008-08-29 17:31:35 -0300 | [diff] [blame] | 409 | dev_t dev = MKDEV(VIDEO_MAJOR, 0); |
| 410 | |
Hans Verkuil | 27a5e6d | 2008-07-20 08:43:17 -0300 | [diff] [blame] | 411 | class_unregister(&video_class); |
Hans Verkuil | 7f8ecfa | 2008-08-29 17:31:35 -0300 | [diff] [blame] | 412 | unregister_chrdev_region(dev, VIDEO_NUM_DEVICES); |
Hans Verkuil | 27a5e6d | 2008-07-20 08:43:17 -0300 | [diff] [blame] | 413 | } |
| 414 | |
| 415 | module_init(videodev_init) |
| 416 | module_exit(videodev_exit) |
| 417 | |
| 418 | MODULE_AUTHOR("Alan Cox, Mauro Carvalho Chehab <mchehab@infradead.org>"); |
| 419 | MODULE_DESCRIPTION("Device registrar for Video4Linux drivers v2"); |
| 420 | MODULE_LICENSE("GPL"); |
| 421 | |
| 422 | |
| 423 | /* |
| 424 | * Local variables: |
| 425 | * c-basic-offset: 8 |
| 426 | * End: |
| 427 | */ |