v4l2-dev.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683
  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@lxorguk.ukuu.org.uk> (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. #include <linux/module.h>
  19. #include <linux/types.h>
  20. #include <linux/kernel.h>
  21. #include <linux/mm.h>
  22. #include <linux/string.h>
  23. #include <linux/errno.h>
  24. #include <linux/init.h>
  25. #include <linux/kmod.h>
  26. #include <linux/slab.h>
  27. #include <asm/uaccess.h>
  28. #include <asm/system.h>
  29. #include <media/v4l2-common.h>
  30. #include <media/v4l2-device.h>
  31. #include <media/v4l2-ioctl.h>
  32. #define VIDEO_NUM_DEVICES 256
  33. #define VIDEO_NAME "video4linux"
  34. /*
  35. * sysfs stuff
  36. */
  37. static ssize_t show_index(struct device *cd,
  38. struct device_attribute *attr, char *buf)
  39. {
  40. struct video_device *vdev = to_video_device(cd);
  41. return sprintf(buf, "%i\n", vdev->index);
  42. }
  43. static ssize_t show_name(struct device *cd,
  44. struct device_attribute *attr, char *buf)
  45. {
  46. struct video_device *vdev = to_video_device(cd);
  47. return sprintf(buf, "%.*s\n", (int)sizeof(vdev->name), vdev->name);
  48. }
  49. static struct device_attribute video_device_attrs[] = {
  50. __ATTR(name, S_IRUGO, show_name, NULL),
  51. __ATTR(index, S_IRUGO, show_index, NULL),
  52. __ATTR_NULL
  53. };
  54. /*
  55. * Active devices
  56. */
  57. static struct video_device *video_device[VIDEO_NUM_DEVICES];
  58. static DEFINE_MUTEX(videodev_lock);
  59. static DECLARE_BITMAP(devnode_nums[VFL_TYPE_MAX], VIDEO_NUM_DEVICES);
  60. /* Device node utility functions */
  61. /* Note: these utility functions all assume that vfl_type is in the range
  62. [0, VFL_TYPE_MAX-1]. */
  63. #ifdef CONFIG_VIDEO_FIXED_MINOR_RANGES
  64. /* Return the bitmap corresponding to vfl_type. */
  65. static inline unsigned long *devnode_bits(int vfl_type)
  66. {
  67. /* Any types not assigned to fixed minor ranges must be mapped to
  68. one single bitmap for the purposes of finding a free node number
  69. since all those unassigned types use the same minor range. */
  70. int idx = (vfl_type > VFL_TYPE_RADIO) ? VFL_TYPE_MAX - 1 : vfl_type;
  71. return devnode_nums[idx];
  72. }
  73. #else
  74. /* Return the bitmap corresponding to vfl_type. */
  75. static inline unsigned long *devnode_bits(int vfl_type)
  76. {
  77. return devnode_nums[vfl_type];
  78. }
  79. #endif
  80. /* Mark device node number vdev->num as used */
  81. static inline void devnode_set(struct video_device *vdev)
  82. {
  83. set_bit(vdev->num, devnode_bits(vdev->vfl_type));
  84. }
  85. /* Mark device node number vdev->num as unused */
  86. static inline void devnode_clear(struct video_device *vdev)
  87. {
  88. clear_bit(vdev->num, devnode_bits(vdev->vfl_type));
  89. }
  90. /* Try to find a free device node number in the range [from, to> */
  91. static inline int devnode_find(struct video_device *vdev, int from, int to)
  92. {
  93. return find_next_zero_bit(devnode_bits(vdev->vfl_type), to, from);
  94. }
  95. struct video_device *video_device_alloc(void)
  96. {
  97. return kzalloc(sizeof(struct video_device), GFP_KERNEL);
  98. }
  99. EXPORT_SYMBOL(video_device_alloc);
  100. void video_device_release(struct video_device *vdev)
  101. {
  102. kfree(vdev);
  103. }
  104. EXPORT_SYMBOL(video_device_release);
  105. void video_device_release_empty(struct video_device *vdev)
  106. {
  107. /* Do nothing */
  108. /* Only valid when the video_device struct is a static. */
  109. }
  110. EXPORT_SYMBOL(video_device_release_empty);
  111. static inline void video_get(struct video_device *vdev)
  112. {
  113. get_device(&vdev->dev);
  114. }
  115. static inline void video_put(struct video_device *vdev)
  116. {
  117. put_device(&vdev->dev);
  118. }
  119. /* Called when the last user of the video device exits. */
  120. static void v4l2_device_release(struct device *cd)
  121. {
  122. struct video_device *vdev = to_video_device(cd);
  123. mutex_lock(&videodev_lock);
  124. if (video_device[vdev->minor] != vdev) {
  125. mutex_unlock(&videodev_lock);
  126. /* should not happen */
  127. WARN_ON(1);
  128. return;
  129. }
  130. /* Free up this device for reuse */
  131. video_device[vdev->minor] = NULL;
  132. /* Delete the cdev on this minor as well */
  133. cdev_del(vdev->cdev);
  134. /* Just in case some driver tries to access this from
  135. the release() callback. */
  136. vdev->cdev = NULL;
  137. /* Mark device node number as free */
  138. devnode_clear(vdev);
  139. mutex_unlock(&videodev_lock);
  140. /* Release video_device and perform other
  141. cleanups as needed. */
  142. vdev->release(vdev);
  143. }
  144. static struct class video_class = {
  145. .name = VIDEO_NAME,
  146. .dev_attrs = video_device_attrs,
  147. };
  148. struct video_device *video_devdata(struct file *file)
  149. {
  150. return video_device[iminor(file->f_path.dentry->d_inode)];
  151. }
  152. EXPORT_SYMBOL(video_devdata);
  153. static ssize_t v4l2_read(struct file *filp, char __user *buf,
  154. size_t sz, loff_t *off)
  155. {
  156. struct video_device *vdev = video_devdata(filp);
  157. int ret = -ENODEV;
  158. if (!vdev->fops->read)
  159. return -EINVAL;
  160. if (vdev->lock && mutex_lock_interruptible(vdev->lock))
  161. return -ERESTARTSYS;
  162. if (video_is_registered(vdev))
  163. ret = vdev->fops->read(filp, buf, sz, off);
  164. if (vdev->lock)
  165. mutex_unlock(vdev->lock);
  166. return ret;
  167. }
  168. static ssize_t v4l2_write(struct file *filp, const char __user *buf,
  169. size_t sz, loff_t *off)
  170. {
  171. struct video_device *vdev = video_devdata(filp);
  172. int ret = -ENODEV;
  173. if (!vdev->fops->write)
  174. return -EINVAL;
  175. if (vdev->lock && mutex_lock_interruptible(vdev->lock))
  176. return -ERESTARTSYS;
  177. if (video_is_registered(vdev))
  178. ret = vdev->fops->write(filp, buf, sz, off);
  179. if (vdev->lock)
  180. mutex_unlock(vdev->lock);
  181. return ret;
  182. }
  183. static unsigned int v4l2_poll(struct file *filp, struct poll_table_struct *poll)
  184. {
  185. struct video_device *vdev = video_devdata(filp);
  186. int ret = POLLERR | POLLHUP;
  187. if (!vdev->fops->poll)
  188. return DEFAULT_POLLMASK;
  189. if (vdev->lock)
  190. mutex_lock(vdev->lock);
  191. if (video_is_registered(vdev))
  192. ret = vdev->fops->poll(filp, poll);
  193. if (vdev->lock)
  194. mutex_unlock(vdev->lock);
  195. return ret;
  196. }
  197. static long v4l2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
  198. {
  199. struct video_device *vdev = video_devdata(filp);
  200. int ret = -ENODEV;
  201. if (vdev->fops->unlocked_ioctl) {
  202. if (vdev->lock && mutex_lock_interruptible(vdev->lock))
  203. return -ERESTARTSYS;
  204. if (video_is_registered(vdev))
  205. ret = vdev->fops->unlocked_ioctl(filp, cmd, arg);
  206. if (vdev->lock)
  207. mutex_unlock(vdev->lock);
  208. } else if (vdev->fops->ioctl) {
  209. /* This code path is a replacement for the BKL. It is a major
  210. * hack but it will have to do for those drivers that are not
  211. * yet converted to use unlocked_ioctl.
  212. *
  213. * There are two options: if the driver implements struct
  214. * v4l2_device, then the lock defined there is used to
  215. * serialize the ioctls. Otherwise the v4l2 core lock defined
  216. * below is used. This lock is really bad since it serializes
  217. * completely independent devices.
  218. *
  219. * Both variants suffer from the same problem: if the driver
  220. * sleeps, then it blocks all ioctls since the lock is still
  221. * held. This is very common for VIDIOC_DQBUF since that
  222. * normally waits for a frame to arrive. As a result any other
  223. * ioctl calls will proceed very, very slowly since each call
  224. * will have to wait for the VIDIOC_QBUF to finish. Things that
  225. * should take 0.01s may now take 10-20 seconds.
  226. *
  227. * The workaround is to *not* take the lock for VIDIOC_DQBUF.
  228. * This actually works OK for videobuf-based drivers, since
  229. * videobuf will take its own internal lock.
  230. */
  231. static DEFINE_MUTEX(v4l2_ioctl_mutex);
  232. struct mutex *m = vdev->v4l2_dev ?
  233. &vdev->v4l2_dev->ioctl_lock : &v4l2_ioctl_mutex;
  234. if (cmd != VIDIOC_DQBUF && mutex_lock_interruptible(m))
  235. return -ERESTARTSYS;
  236. if (video_is_registered(vdev))
  237. ret = vdev->fops->ioctl(filp, cmd, arg);
  238. if (cmd != VIDIOC_DQBUF)
  239. mutex_unlock(m);
  240. } else
  241. ret = -ENOTTY;
  242. return ret;
  243. }
  244. static int v4l2_mmap(struct file *filp, struct vm_area_struct *vm)
  245. {
  246. struct video_device *vdev = video_devdata(filp);
  247. int ret = -ENODEV;
  248. if (!vdev->fops->mmap)
  249. return ret;
  250. if (vdev->lock && mutex_lock_interruptible(vdev->lock))
  251. return -ERESTARTSYS;
  252. if (video_is_registered(vdev))
  253. ret = vdev->fops->mmap(filp, vm);
  254. if (vdev->lock)
  255. mutex_unlock(vdev->lock);
  256. return ret;
  257. }
  258. /* Override for the open function */
  259. static int v4l2_open(struct inode *inode, struct file *filp)
  260. {
  261. struct video_device *vdev;
  262. int ret = 0;
  263. /* Check if the video device is available */
  264. mutex_lock(&videodev_lock);
  265. vdev = video_devdata(filp);
  266. /* return ENODEV if the video device has already been removed. */
  267. if (vdev == NULL || !video_is_registered(vdev)) {
  268. mutex_unlock(&videodev_lock);
  269. return -ENODEV;
  270. }
  271. /* and increase the device refcount */
  272. video_get(vdev);
  273. mutex_unlock(&videodev_lock);
  274. if (vdev->fops->open) {
  275. if (vdev->lock && mutex_lock_interruptible(vdev->lock)) {
  276. ret = -ERESTARTSYS;
  277. goto err;
  278. }
  279. if (video_is_registered(vdev))
  280. ret = vdev->fops->open(filp);
  281. else
  282. ret = -ENODEV;
  283. if (vdev->lock)
  284. mutex_unlock(vdev->lock);
  285. }
  286. err:
  287. /* decrease the refcount in case of an error */
  288. if (ret)
  289. video_put(vdev);
  290. return ret;
  291. }
  292. /* Override for the release function */
  293. static int v4l2_release(struct inode *inode, struct file *filp)
  294. {
  295. struct video_device *vdev = video_devdata(filp);
  296. int ret = 0;
  297. if (vdev->fops->release) {
  298. if (vdev->lock)
  299. mutex_lock(vdev->lock);
  300. vdev->fops->release(filp);
  301. if (vdev->lock)
  302. mutex_unlock(vdev->lock);
  303. }
  304. /* decrease the refcount unconditionally since the release()
  305. return value is ignored. */
  306. video_put(vdev);
  307. return ret;
  308. }
  309. static const struct file_operations v4l2_fops = {
  310. .owner = THIS_MODULE,
  311. .read = v4l2_read,
  312. .write = v4l2_write,
  313. .open = v4l2_open,
  314. .mmap = v4l2_mmap,
  315. .unlocked_ioctl = v4l2_ioctl,
  316. #ifdef CONFIG_COMPAT
  317. .compat_ioctl = v4l2_compat_ioctl32,
  318. #endif
  319. .release = v4l2_release,
  320. .poll = v4l2_poll,
  321. .llseek = no_llseek,
  322. };
  323. /**
  324. * get_index - assign stream index number based on parent device
  325. * @vdev: video_device to assign index number to, vdev->parent should be assigned
  326. *
  327. * Note that when this is called the new device has not yet been registered
  328. * in the video_device array, but it was able to obtain a minor number.
  329. *
  330. * This means that we can always obtain a free stream index number since
  331. * the worst case scenario is that there are VIDEO_NUM_DEVICES - 1 slots in
  332. * use of the video_device array.
  333. *
  334. * Returns a free index number.
  335. */
  336. static int get_index(struct video_device *vdev)
  337. {
  338. /* This can be static since this function is called with the global
  339. videodev_lock held. */
  340. static DECLARE_BITMAP(used, VIDEO_NUM_DEVICES);
  341. int i;
  342. /* Some drivers do not set the parent. In that case always return 0. */
  343. if (vdev->parent == NULL)
  344. return 0;
  345. bitmap_zero(used, VIDEO_NUM_DEVICES);
  346. for (i = 0; i < VIDEO_NUM_DEVICES; i++) {
  347. if (video_device[i] != NULL &&
  348. video_device[i]->parent == vdev->parent) {
  349. set_bit(video_device[i]->index, used);
  350. }
  351. }
  352. return find_first_zero_bit(used, VIDEO_NUM_DEVICES);
  353. }
  354. /**
  355. * video_register_device - register video4linux devices
  356. * @vdev: video device structure we want to register
  357. * @type: type of device to register
  358. * @nr: which device node number (0 == /dev/video0, 1 == /dev/video1, ...
  359. * -1 == first free)
  360. * @warn_if_nr_in_use: warn if the desired device node number
  361. * was already in use and another number was chosen instead.
  362. *
  363. * The registration code assigns minor numbers and device node numbers
  364. * based on the requested type and registers the new device node with
  365. * the kernel.
  366. *
  367. * This function assumes that struct video_device was zeroed when it
  368. * was allocated and does not contain any stale date.
  369. *
  370. * An error is returned if no free minor or device node number could be
  371. * found, or if the registration of the device node failed.
  372. *
  373. * Zero is returned on success.
  374. *
  375. * Valid types are
  376. *
  377. * %VFL_TYPE_GRABBER - A frame grabber
  378. *
  379. * %VFL_TYPE_VBI - Vertical blank data (undecoded)
  380. *
  381. * %VFL_TYPE_RADIO - A radio card
  382. */
  383. static int __video_register_device(struct video_device *vdev, int type, int nr,
  384. int warn_if_nr_in_use)
  385. {
  386. int i = 0;
  387. int ret;
  388. int minor_offset = 0;
  389. int minor_cnt = VIDEO_NUM_DEVICES;
  390. const char *name_base;
  391. /* A minor value of -1 marks this video device as never
  392. having been registered */
  393. vdev->minor = -1;
  394. /* the release callback MUST be present */
  395. WARN_ON(!vdev->release);
  396. if (!vdev->release)
  397. return -EINVAL;
  398. /* v4l2_fh support */
  399. spin_lock_init(&vdev->fh_lock);
  400. INIT_LIST_HEAD(&vdev->fh_list);
  401. /* Part 1: check device type */
  402. switch (type) {
  403. case VFL_TYPE_GRABBER:
  404. name_base = "video";
  405. break;
  406. case VFL_TYPE_VBI:
  407. name_base = "vbi";
  408. break;
  409. case VFL_TYPE_RADIO:
  410. name_base = "radio";
  411. break;
  412. default:
  413. printk(KERN_ERR "%s called with unknown type: %d\n",
  414. __func__, type);
  415. return -EINVAL;
  416. }
  417. vdev->vfl_type = type;
  418. vdev->cdev = NULL;
  419. if (vdev->v4l2_dev) {
  420. if (vdev->v4l2_dev->dev)
  421. vdev->parent = vdev->v4l2_dev->dev;
  422. if (vdev->ctrl_handler == NULL)
  423. vdev->ctrl_handler = vdev->v4l2_dev->ctrl_handler;
  424. }
  425. /* Part 2: find a free minor, device node number and device index. */
  426. #ifdef CONFIG_VIDEO_FIXED_MINOR_RANGES
  427. /* Keep the ranges for the first four types for historical
  428. * reasons.
  429. * Newer devices (not yet in place) should use the range
  430. * of 128-191 and just pick the first free minor there
  431. * (new style). */
  432. switch (type) {
  433. case VFL_TYPE_GRABBER:
  434. minor_offset = 0;
  435. minor_cnt = 64;
  436. break;
  437. case VFL_TYPE_RADIO:
  438. minor_offset = 64;
  439. minor_cnt = 64;
  440. break;
  441. case VFL_TYPE_VBI:
  442. minor_offset = 224;
  443. minor_cnt = 32;
  444. break;
  445. default:
  446. minor_offset = 128;
  447. minor_cnt = 64;
  448. break;
  449. }
  450. #endif
  451. /* Pick a device node number */
  452. mutex_lock(&videodev_lock);
  453. nr = devnode_find(vdev, nr == -1 ? 0 : nr, minor_cnt);
  454. if (nr == minor_cnt)
  455. nr = devnode_find(vdev, 0, minor_cnt);
  456. if (nr == minor_cnt) {
  457. printk(KERN_ERR "could not get a free device node number\n");
  458. mutex_unlock(&videodev_lock);
  459. return -ENFILE;
  460. }
  461. #ifdef CONFIG_VIDEO_FIXED_MINOR_RANGES
  462. /* 1-on-1 mapping of device node number to minor number */
  463. i = nr;
  464. #else
  465. /* The device node number and minor numbers are independent, so
  466. we just find the first free minor number. */
  467. for (i = 0; i < VIDEO_NUM_DEVICES; i++)
  468. if (video_device[i] == NULL)
  469. break;
  470. if (i == VIDEO_NUM_DEVICES) {
  471. mutex_unlock(&videodev_lock);
  472. printk(KERN_ERR "could not get a free minor\n");
  473. return -ENFILE;
  474. }
  475. #endif
  476. vdev->minor = i + minor_offset;
  477. vdev->num = nr;
  478. devnode_set(vdev);
  479. /* Should not happen since we thought this minor was free */
  480. WARN_ON(video_device[vdev->minor] != NULL);
  481. vdev->index = get_index(vdev);
  482. mutex_unlock(&videodev_lock);
  483. /* Part 3: Initialize the character device */
  484. vdev->cdev = cdev_alloc();
  485. if (vdev->cdev == NULL) {
  486. ret = -ENOMEM;
  487. goto cleanup;
  488. }
  489. vdev->cdev->ops = &v4l2_fops;
  490. vdev->cdev->owner = vdev->fops->owner;
  491. ret = cdev_add(vdev->cdev, MKDEV(VIDEO_MAJOR, vdev->minor), 1);
  492. if (ret < 0) {
  493. printk(KERN_ERR "%s: cdev_add failed\n", __func__);
  494. kfree(vdev->cdev);
  495. vdev->cdev = NULL;
  496. goto cleanup;
  497. }
  498. /* Part 4: register the device with sysfs */
  499. vdev->dev.class = &video_class;
  500. vdev->dev.devt = MKDEV(VIDEO_MAJOR, vdev->minor);
  501. if (vdev->parent)
  502. vdev->dev.parent = vdev->parent;
  503. dev_set_name(&vdev->dev, "%s%d", name_base, vdev->num);
  504. ret = device_register(&vdev->dev);
  505. if (ret < 0) {
  506. printk(KERN_ERR "%s: device_register failed\n", __func__);
  507. goto cleanup;
  508. }
  509. /* Register the release callback that will be called when the last
  510. reference to the device goes away. */
  511. vdev->dev.release = v4l2_device_release;
  512. if (nr != -1 && nr != vdev->num && warn_if_nr_in_use)
  513. printk(KERN_WARNING "%s: requested %s%d, got %s\n", __func__,
  514. name_base, nr, video_device_node_name(vdev));
  515. /* Part 5: Activate this minor. The char device can now be used. */
  516. set_bit(V4L2_FL_REGISTERED, &vdev->flags);
  517. mutex_lock(&videodev_lock);
  518. video_device[vdev->minor] = vdev;
  519. mutex_unlock(&videodev_lock);
  520. return 0;
  521. cleanup:
  522. mutex_lock(&videodev_lock);
  523. if (vdev->cdev)
  524. cdev_del(vdev->cdev);
  525. devnode_clear(vdev);
  526. mutex_unlock(&videodev_lock);
  527. /* Mark this video device as never having been registered. */
  528. vdev->minor = -1;
  529. return ret;
  530. }
  531. int video_register_device(struct video_device *vdev, int type, int nr)
  532. {
  533. return __video_register_device(vdev, type, nr, 1);
  534. }
  535. EXPORT_SYMBOL(video_register_device);
  536. int video_register_device_no_warn(struct video_device *vdev, int type, int nr)
  537. {
  538. return __video_register_device(vdev, type, nr, 0);
  539. }
  540. EXPORT_SYMBOL(video_register_device_no_warn);
  541. /**
  542. * video_unregister_device - unregister a video4linux device
  543. * @vdev: the device to unregister
  544. *
  545. * This unregisters the passed device. Future open calls will
  546. * be met with errors.
  547. */
  548. void video_unregister_device(struct video_device *vdev)
  549. {
  550. /* Check if vdev was ever registered at all */
  551. if (!vdev || !video_is_registered(vdev))
  552. return;
  553. mutex_lock(&videodev_lock);
  554. /* This must be in a critical section to prevent a race with v4l2_open.
  555. * Once this bit has been cleared video_get may never be called again.
  556. */
  557. clear_bit(V4L2_FL_REGISTERED, &vdev->flags);
  558. mutex_unlock(&videodev_lock);
  559. device_unregister(&vdev->dev);
  560. }
  561. EXPORT_SYMBOL(video_unregister_device);
  562. /*
  563. * Initialise video for linux
  564. */
  565. static int __init videodev_init(void)
  566. {
  567. dev_t dev = MKDEV(VIDEO_MAJOR, 0);
  568. int ret;
  569. printk(KERN_INFO "Linux video capture interface: v2.00\n");
  570. ret = register_chrdev_region(dev, VIDEO_NUM_DEVICES, VIDEO_NAME);
  571. if (ret < 0) {
  572. printk(KERN_WARNING "videodev: unable to get major %d\n",
  573. VIDEO_MAJOR);
  574. return ret;
  575. }
  576. ret = class_register(&video_class);
  577. if (ret < 0) {
  578. unregister_chrdev_region(dev, VIDEO_NUM_DEVICES);
  579. printk(KERN_WARNING "video_dev: class_register failed\n");
  580. return -EIO;
  581. }
  582. return 0;
  583. }
  584. static void __exit videodev_exit(void)
  585. {
  586. dev_t dev = MKDEV(VIDEO_MAJOR, 0);
  587. class_unregister(&video_class);
  588. unregister_chrdev_region(dev, VIDEO_NUM_DEVICES);
  589. }
  590. module_init(videodev_init)
  591. module_exit(videodev_exit)
  592. MODULE_AUTHOR("Alan Cox, Mauro Carvalho Chehab <mchehab@infradead.org>");
  593. MODULE_DESCRIPTION("Device registrar for Video4Linux drivers v2");
  594. MODULE_LICENSE("GPL");
  595. MODULE_ALIAS_CHARDEV_MAJOR(VIDEO_MAJOR);
  596. /*
  597. * Local variables:
  598. * c-basic-offset: 8
  599. * End:
  600. */