Camera--V4L2驱动学习记录

匿名 (未验证) 提交于 2019-12-03 00:21:02

Camera--V4L2驱动学习记录

Video for Linux Two



























1.V4l2_device
  1. struct v4l2_device{
  2. /*->to.
  3. :NULLifis
  4. iscase.g..*/
  5. *dev;
  6. /*to*/
  7. ;
  8. /*;if
  9. is.*/
  10. ;
  11. /*,+*/
  12. [V4L2_DEVICE_NAME_SIZE];
  13. /*sub-devices.*/
  14. (*notify)(*sd,
  15. int,*arg);
  16. };


  1. int(*dev,*v4l2_dev)
  2. {
  3. if(==NULL)
  4. -EINVAL;

  5. (&v4l2_dev->subdevs);
  6. (&v4l2_dev->lock);
  7. ->=;
  8. if(==NULL){
  9. /*If==NULL,thenin*/
  10. (!v4l2_dev->name[0]);
  11. ;
  12. }

  13. /*Setto+ifisempty.*/
  14. if(!v4l2_dev->name[0])
  15. (v4l2_dev->name,(v4l2_dev->name),"%s %s",
  16. ->driver->name,(dev));
  17. if(dev_get_drvdata(dev))
  18. (v4l2_dev,"Non-NULL drvdata on register\n");
  19. (dev,);
  20. ;
  21. }
  22. EXPORT_SYMBOL_GPL(v4l2_device_register);
  1. void v4l2_device_unregister(*v4l2_dev)
  2. {
  3. *sd,*next;

  4. if(==NULL)
  5. ;
  6. (v4l2_dev);

  7. /**/
  8. (sd,next,&v4l2_dev->subdevs,){
  9. (sd);
  10. #if(CONFIG_I2C)||(defined(CONFIG_I2C_MODULE)&&(MODULE))
  11. if(sd->&){
  12. *=(sd);

  13. /*to.
  14. onto
  15. for,if
  16. is,thenis.*/
  17. if(client)
  18. (client);
  19. }
  20. #endif
  21. }
  22. }
  23. EXPORT_SYMBOL_GPL(v4l2_device_unregister);
2.video_device
  1. /*
  2. *,.c
  3. *to
  4. *
  5. */

  6. struct video_device
  7. {
  8. /**/
  9. const*fops;

  10. /**/
  11. ;/**/
  12. *cdev;/**/

  13. /*Setorif*/
  14. *parent;/**/
  15. *v4l2_dev;/**/

  16. /**/
  17. [32];
  18. int;
  19. /*'minor'issetto-if*/
  20. int;
  21. ;
  22. /*toset/clear/*/
  23. ;
  24. /*toon*/
  25. int;

  26. int;/**/

  27. /**/
  28. ;/**/
  29. ;/**/

  30. /**/
  31. (*release)(*vdev);

  32. /**/
  33. const*ioctl_ops;
  34. };















  1. /**
  2. *-
  3. *:to
  4. *:to
  5. *:(==/dev/video0,==/dev/video1,...
  6. *-==)
  7. *:if
  8. *inand.
  9. *
  10. *and
  11. *onand
  12. *.
  13. *errorisifor
  14. *,orif.
  15. *
  16. *ison.
  17. *
  18. *
  19. *
  20. *%-
  21. *
  22. *%-
  23. *
  24. *%-(undecoded)
  25. *
  26. *%-
  27. */
  28. int(*vdev,int,int,
  29. int)
  30. {
  31. int=;
  32. int;
  33. int=;
  34. int=;
  35. const*name_base;
  36. *=(vdev);

  37. /*-1 marks this video device as never
  38. */
  39. ->=-1;

  40. /**/
  41. (!vdev->release);
  42. if(!vdev->release)
  43. -EINVAL;

  44. /*:*/
  45. (type){
  46. case:
  47. ="video";
  48. ;
  49. case:
  50. ="vtx";
  51. ;
  52. case:
  53. ="vbi";
  54. ;
  55. case:
  56. ="radio";
  57. ;
  58. :
  59. ("%s called with unknown type: %d\n",
  60. ,);
  61. -EINVAL;
  62. }

  63. ->=;
  64. ->=NULL;
  65. if(vdev->&&->v4l2_dev->dev)
  66. ->=->v4l2_dev->dev;

  67. /*:,and.*/
  68. #ifdef CONFIG_VIDEO_FIXED_MINOR_RANGES
  69. /*forfor
  70. *.
  71. *(notin)
  72. *-and
  73. *(new style).*/
  74. (type){
  75. case:
  76. =;
  77. =;
  78. ;
  79. case:
  80. =;
  81. =;
  82. ;
  83. case:
  84. =;
  85. =;
  86. ;
  87. case:
  88. =;
  89. =;
  90. ;
  91. :
  92. =;
  93. =;
  94. ;
  95. }
  96. #endif

  97. /**/
  98. (&videodev_lock);
  99. =(vdev,==-?:,);
  100. if(==)
  101. =(vdev,,);
  102. if(==){
  103. ("could not get a free device node number\n");
  104. (&videodev_lock);
  105. -ENFILE;
  106. }
  107. #ifdef CONFIG_VIDEO_FIXED_MINOR_RANGES
  108. /*-on-to*/
  109. =;
  110. #else
  111. /*and,
  112. .*/
  113. for(=;<;++)
  114. if(video_device[i]==NULL)
  115. ;
  116. if(==){
  117. (&videodev_lock);
  118. ("could not get a free minor\n");
  119. -ENFILE;
  120. }
  121. #endif
  122. ->=+;
  123. ->=;
  124. (vdev);

  125. /*not*/
  126. (video_device[vdev->minor]!=NULL);
  127. ->=(vdev);
  128. (&videodev_lock);

  129. /*:*/
  130. ->=();
  131. if(vdev->==NULL){
  132. =-ENOMEM;
  133. ;
  134. }
  135. if(vdev->fops->unlocked_ioctl)
  136. ->cdev->=&v4l2_unlocked_fops;
  137. else
  138. ->cdev->=&v4l2_fops;
  139. ->cdev->=->fops->owner;
  140. =(vdev->cdev,(VIDEO_MAJOR,->minor),);
  141. if(<){
  142. ("%s: cdev_add failed\n",);
  143. (vdev->cdev);
  144. ->=NULL;
  145. ;
  146. }

  147. /*:*/
  148. (&vdev->dev,,(vdev->dev));
  149. /*'s drvdata,
  150. .*/
  151. (vdev,);
  152. ->dev.class=&video_class;
  153. ->dev.=(VIDEO_MAJOR,->minor);
  154. if(vdev->parent)
  155. ->dev.=->parent;
  156. (&vdev->dev,"%s%d",,->num);
  157. =(&vdev->dev);
  158. if(<){
  159. ("%s: device_register failed\n",);
  160. ;
  161. }
  162. /*
  163. to.*/
  164. ->dev.=;

  165. if(!=-&&!=->&&)
  166. ("%s: requested %s%d, got %s%d\n",
  167. ,,,,->num);

  168. /*:.now.*/
  169. (&videodev_lock);
  170. [vdev->minor]=;
  171. (&videodev_lock);
  172. ;

  173. cleanup:
  174. (&videodev_lock);
  175. if(vdev->cdev)
  176. (vdev->cdev);
  177. (vdev);
  178. (&videodev_lock);
  179. /*.*/
  180. ->=-1;
  181. ;
  182. }

  183. int(*vdev,int,int)
  184. {
  185. (vdev,,,);
  186. }
  187. EXPORT_SYMBOL(video_register_device);

  188. /**
  189. *-
  190. *:to
  191. *
  192. *.
  193. *.
  194. */
  195. void video_unregister_device(*vdev)
  196. {
  197. /*if*/
  198. if(!||-><)
  199. ;

  200. (&videodev_lock);
  201. (V4L2_FL_UNREGISTERED,&vdev->flags);
  202. (&videodev_lock);
  203. (&vdev->dev);
  204. }
  205. EXPORT_SYMBOL(video_unregister_device);
3.v4l2_subdev

  1. /*Each,
  2. -orin.
  3. */
  4. {
  5. ;
  6. *owner;
  7. ;
  8. *v4l2_dev;
  9. const*ops;
  10. /**/
  11. [V4L2_SUBDEV_NAME_SIZE];
  12. /*to,is-*/
  13. ;
  14. /*toprivate*/
  15. *priv;
  16. };
4.v4l2_buffer
  1. {
  2. ;
  3. ;
  4. ;
  5. ;
  6. ;
  7. ;
  8. ;
  9. ;

  10. /*location*/
  11. ;
  12. {
  13. ;
  14. ;
  15. };
  16. ;
  17. ;
  18. ;
  19. };


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!