105 lines · plain
1.. SPDX-License-Identifier: GPL-2.02 3.. _media_using_camera_sensor_drivers:4 5Using camera sensor drivers6===========================7 8This section describes common practices for how the V4L2 sub-device interface is9used to control the camera sensor drivers.10 11You may also find :ref:`media_writing_camera_sensor_drivers` useful.12 13Frame size14----------15 16There are two distinct ways to configure the frame size produced by camera17sensors.18 19Freely configurable camera sensor drivers20~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~21 22Freely configurable camera sensor drivers expose the device's internal23processing pipeline as one or more sub-devices with different cropping and24scaling configurations. The output size of the device is the result of a series25of cropping and scaling operations from the device's pixel array's size.26 27An example of such a driver is the CCS driver.28 29Register list based drivers30~~~~~~~~~~~~~~~~~~~~~~~~~~~31 32Register list based drivers generally, instead of able to configure the device33they control based on user requests, are limited to a number of preset34configurations that combine a number of different parameters that on hardware35level are independent. How a driver picks such configuration is based on the36format set on a source pad at the end of the device's internal pipeline.37 38Most sensor drivers are implemented this way.39 40Frame interval configuration41----------------------------42 43There are two different methods for obtaining possibilities for different frame44intervals as well as configuring the frame interval. Which one to implement45depends on the type of the device.46 47Raw camera sensors48~~~~~~~~~~~~~~~~~~49 50Instead of a high level parameter such as frame interval, the frame interval is51a result of the configuration of a number of camera sensor implementation52specific parameters. Luckily, these parameters tend to be the same for more or53less all modern raw camera sensors.54 55The frame interval is calculated using the following equation::56 57 frame interval = (analogue crop width + horizontal blanking) *58 (analogue crop height + vertical blanking) / pixel rate59 60The formula is bus independent and is applicable for raw timing parameters on61large variety of devices beyond camera sensors. Devices that have no analogue62crop, use the full source image size, i.e. pixel array size.63 64Horizontal and vertical blanking are specified by ``V4L2_CID_HBLANK`` and65``V4L2_CID_VBLANK``, respectively. The unit of the ``V4L2_CID_HBLANK`` control66is pixels and the unit of the ``V4L2_CID_VBLANK`` is lines. The pixel rate in67the sensor's **pixel array** is specified by ``V4L2_CID_PIXEL_RATE`` in the same68sub-device. The unit of that control is pixels per second.69 70Register list based drivers need to implement read-only sub-device nodes for the71purpose. Devices that are not register list based need these to configure the72device's internal processing pipeline.73 74The first entity in the linear pipeline is the pixel array. The pixel array may75be followed by other entities that are there to allow configuring binning,76skipping, scaling or digital crop, see :ref:`VIDIOC_SUBDEV_G_SELECTION77<VIDIOC_SUBDEV_G_SELECTION>`.78 79USB cameras etc. devices80~~~~~~~~~~~~~~~~~~~~~~~~81 82USB video class hardware, as well as many cameras offering a similar higher83level interface natively, generally use the concept of frame interval (or frame84rate) on device level in firmware or hardware. This means lower level controls85implemented by raw cameras may not be used on uAPI (or even kAPI) to control the86frame interval on these devices.87 88Rotation, orientation and flipping89----------------------------------90 91Some systems have the camera sensor mounted upside down compared to its natural92mounting rotation. In such cases, drivers shall expose the information to93userspace with the :ref:`V4L2_CID_CAMERA_SENSOR_ROTATION94<v4l2-camera-sensor-rotation>` control.95 96Sensor drivers shall also report the sensor's mounting orientation with the97:ref:`V4L2_CID_CAMERA_SENSOR_ORIENTATION <v4l2-camera-sensor-orientation>`.98 99Sensor drivers that have any vertical or horizontal flips embedded in the100register programming sequences shall initialize the :ref:`V4L2_CID_HFLIP101<v4l2-cid-hflip>` and :ref:`V4L2_CID_VFLIP <v4l2-cid-vflip>` controls with the102values programmed by the register sequences. The default values of these103controls shall be 0 (disabled). Especially these controls shall not be inverted,104independently of the sensor's mounting rotation.105