soc-camera.txt 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. Soc-Camera Subsystem
  2. ====================
  3. Terminology
  4. -----------
  5. The following terms are used in this document:
  6. - camera / camera device / camera sensor - a video-camera sensor chip, capable
  7. of connecting to a variety of systems and interfaces, typically uses i2c for
  8. control and configuration, and a parallel or a serial bus for data.
  9. - camera host - an interface, to which a camera is connected. Typically a
  10. specialised interface, present on many SoCs, e.g., PXA27x and PXA3xx, SuperH,
  11. AVR32, i.MX27, i.MX31.
  12. - camera host bus - a connection between a camera host and a camera. Can be
  13. parallel or serial, consists of data and control lines, e.g., clock, vertical
  14. and horizontal synchronization signals.
  15. Purpose of the soc-camera subsystem
  16. -----------------------------------
  17. The soc-camera subsystem provides a unified API between camera host drivers and
  18. camera sensor drivers. It implements a V4L2 interface to the user, currently
  19. only the mmap method is supported.
  20. This subsystem has been written to connect drivers for System-on-Chip (SoC)
  21. video capture interfaces with drivers for CMOS camera sensor chips to enable
  22. the reuse of sensor drivers with various hosts. The subsystem has been designed
  23. to support multiple camera host interfaces and multiple cameras per interface,
  24. although most applications have only one camera sensor.
  25. Existing drivers
  26. ----------------
  27. As of 2.6.27-rc4 there are two host drivers in the mainline: pxa_camera.c for
  28. PXA27x SoCs and sh_mobile_ceu_camera.c for SuperH SoCs, and four sensor drivers:
  29. mt9m001.c, mt9m111.c, mt9v022.c and a generic soc_camera_platform.c driver. This
  30. list is not supposed to be updated, look for more examples in your tree.
  31. Camera host API
  32. ---------------
  33. A host camera driver is registered using the
  34. soc_camera_host_register(struct soc_camera_host *);
  35. function. The host object can be initialized as follows:
  36. static struct soc_camera_host pxa_soc_camera_host = {
  37. .drv_name = PXA_CAM_DRV_NAME,
  38. .ops = &pxa_soc_camera_host_ops,
  39. };
  40. All camera host methods are passed in a struct soc_camera_host_ops:
  41. static struct soc_camera_host_ops pxa_soc_camera_host_ops = {
  42. .owner = THIS_MODULE,
  43. .add = pxa_camera_add_device,
  44. .remove = pxa_camera_remove_device,
  45. .suspend = pxa_camera_suspend,
  46. .resume = pxa_camera_resume,
  47. .set_fmt_cap = pxa_camera_set_fmt_cap,
  48. .try_fmt_cap = pxa_camera_try_fmt_cap,
  49. .init_videobuf = pxa_camera_init_videobuf,
  50. .reqbufs = pxa_camera_reqbufs,
  51. .poll = pxa_camera_poll,
  52. .querycap = pxa_camera_querycap,
  53. .try_bus_param = pxa_camera_try_bus_param,
  54. .set_bus_param = pxa_camera_set_bus_param,
  55. };
  56. .add and .remove methods are called when a sensor is attached to or detached
  57. from the host, apart from performing host-internal tasks they shall also call
  58. sensor driver's .init and .release methods respectively. .suspend and .resume
  59. methods implement host's power-management functionality and its their
  60. responsibility to call respective sensor's methods. .try_bus_param and
  61. .set_bus_param are used to negotiate physical connection parameters between the
  62. host and the sensor. .init_videobuf is called by soc-camera core when a
  63. video-device is opened, further video-buffer management is implemented completely
  64. by the specific camera host driver. The rest of the methods are called from
  65. respective V4L2 operations.
  66. Camera API
  67. ----------
  68. Sensor drivers can use struct soc_camera_link, typically provided by the
  69. platform, and used to specify to which camera host bus the sensor is connected,
  70. and arbitrarily provide platform .power and .reset methods for the camera.
  71. soc_camera_device_register() and soc_camera_device_unregister() functions are
  72. used to add a sensor driver to or remove one from the system. The registration
  73. function takes a pointer to struct soc_camera_device as the only parameter.
  74. This struct can be initialized as follows:
  75. /* link to driver operations */
  76. icd->ops = &mt9m001_ops;
  77. /* link to the underlying physical (e.g., i2c) device */
  78. icd->control = &client->dev;
  79. /* window geometry */
  80. icd->x_min = 20;
  81. icd->y_min = 12;
  82. icd->x_current = 20;
  83. icd->y_current = 12;
  84. icd->width_min = 48;
  85. icd->width_max = 1280;
  86. icd->height_min = 32;
  87. icd->height_max = 1024;
  88. icd->y_skip_top = 1;
  89. /* camera bus ID, typically obtained from platform data */
  90. icd->iface = icl->bus_id;
  91. struct soc_camera_ops provides .probe and .remove methods, which are called by
  92. the soc-camera core, when a camera is matched against or removed from a camera
  93. host bus, .init, .release, .suspend, and .resume are called from the camera host
  94. driver as discussed above. Other members of this struct provide respective V4L2
  95. functionality.
  96. struct soc_camera_device also links to an array of struct soc_camera_data_format,
  97. listing pixel formats, supported by the camera.
  98. VIDIOC_S_CROP and VIDIOC_S_FMT behaviour
  99. ----------------------------------------
  100. Above user ioctls modify image geometry as follows:
  101. VIDIOC_S_CROP: sets location and sizes of the sensor window. Unit is one sensor
  102. pixel. Changing sensor window sizes preserves any scaling factors, therefore
  103. user window sizes change as well.
  104. VIDIOC_S_FMT: sets user window. Should preserve previously set sensor window as
  105. much as possible by modifying scaling factors. If the sensor window cannot be
  106. preserved precisely, it may be changed too.
  107. In soc-camera there are two locations, where scaling and cropping can taks
  108. place: in the camera driver and in the host driver. User ioctls are first passed
  109. to the host driver, which then generally passes them down to the camera driver.
  110. It is more efficient to perform scaling and cropping in the camera driver to
  111. save camera bus bandwidth and maximise the framerate. However, if the camera
  112. driver failed to set the required parameters with sufficient precision, the host
  113. driver may decide to also use its own scaling and cropping to fulfill the user's
  114. request.
  115. Camera drivers are interfaced to the soc-camera core and to host drivers over
  116. the v4l2-subdev API, which is completely functional, it doesn't pass any data.
  117. Therefore all camera drivers shall reply to .g_fmt() requests with their current
  118. output geometry. This is necessary to correctly configure the camera bus.
  119. .s_fmt() and .try_fmt() have to be implemented too. Sensor window and scaling
  120. factors have to be maintained by camera drivers internally. According to the
  121. V4L2 API all capture drivers must support the VIDIOC_CROPCAP ioctl, hence we
  122. rely on camera drivers implementing .cropcap(). If the camera driver does not
  123. support cropping, it may choose to not implement .s_crop(), but to enable
  124. cropping support by the camera host driver at least the .g_crop method must be
  125. implemented.
  126. User window geometry is kept in .user_width and .user_height fields in struct
  127. soc_camera_device and used by the soc-camera core and host drivers. The core
  128. updates these fields upon successful completion of a .s_fmt() call, but if these
  129. fields change elsewhere, e.g., during .s_crop() processing, the host driver is
  130. responsible for updating them.
  131. --
  132. Author: Guennadi Liakhovetski <g.liakhovetski@gmx.de>