← Documents Documentation/userspace-api/media/drivers/camera-sensor.rst GitHub 원문 ↗

Linux 6.18.37 · Userspace API / Media / Drivers

Camera sensor driver 사용법

V4L2 sensor pipeline, frame interval과 mounting control의 공통 uAPI 관행을 설명합니다.

Source pathDocumentation/userspace-api/media/drivers/camera-sensor.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.

1. 요약·해설

원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.

요약·해설

camera-sensor.rst:1-106

raw sensor의 frame interval은 crop·blanking·pixel rate에서 계산하고, high-level camera는 device-level frame rate를 사용할 수 있습니다. mounting rotation과 flip control은 독립적으로 보고해야 합니다.

2. 영어 원문 전체

번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.

원문 전체 펼치기
1 .. SPDX-License-Identifier: GPL-2.0
2
3 .. _media_using_camera_sensor_drivers:
4
5 Using camera sensor drivers
6 ===========================
7
8 This section describes common practices for how the V4L2 sub-device interface is
9 used to control the camera sensor drivers.
10
11 You may also find :ref:`media_writing_camera_sensor_drivers` useful.
12
13 Sensor internal pipeline configuration
14 --------------------------------------
15
16 Camera sensors have an internal processing pipeline including cropping and
17 binning functionality. The sensor drivers belong to two distinct classes, freely
18 configurable and register list-based drivers, depending on how the driver
19 configures this functionality.
20
21 Freely configurable camera sensor drivers
22 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
23
24 Freely configurable camera sensor drivers expose the device's internal
25 processing pipeline as one or more sub-devices with different cropping and
26 scaling configurations. The output size of the device is the result of a series
27 of cropping and scaling operations from the device's pixel array's size.
28
29 An example of such a driver is the CCS driver.
30
31 Register list-based drivers
32 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
33
34 Register list-based drivers generally, instead of able to configure the device
35 they control based on user requests, are limited to a number of preset
36 configurations that combine a number of different parameters that on hardware
37 level are independent. How a driver picks such configuration is based on the
38 format set on a source pad at the end of the device's internal pipeline.
39
40 Most sensor drivers are implemented this way.
41
42 Frame interval configuration
43 ----------------------------
44
45 There are two different methods for obtaining possibilities for different frame
46 intervals as well as configuring the frame interval. Which one to implement
47 depends on the type of the device.
48
49 Raw camera sensors
50 ~~~~~~~~~~~~~~~~~~
51
52 Instead of a high level parameter such as frame interval, the frame interval is
53 a result of the configuration of a number of camera sensor implementation
54 specific parameters. Luckily, these parameters tend to be the same for more or
55 less all modern raw camera sensors.
56
57 The frame interval is calculated using the following equation::
58
59 frame interval = (analogue crop width + horizontal blanking) *
60 (analogue crop height + vertical blanking) / pixel rate
61
62 The formula is bus independent and is applicable for raw timing parameters on
63 large variety of devices beyond camera sensors. Devices that have no analogue
64 crop, use the full source image size, i.e. pixel array size.
65
66 Horizontal and vertical blanking are specified by ``V4L2_CID_HBLANK`` and
67 ``V4L2_CID_VBLANK``, respectively. The unit of the ``V4L2_CID_HBLANK`` control
68 is pixels and the unit of the ``V4L2_CID_VBLANK`` is lines. The pixel rate in
69 the sensor's **pixel array** is specified by ``V4L2_CID_PIXEL_RATE`` in the same
70 sub-device. The unit of that control is pixels per second.
71
72 Register list-based drivers need to implement read-only sub-device nodes for the
73 purpose. Devices that are not register list based need these to configure the
74 device's internal processing pipeline.
75
76 The first entity in the linear pipeline is the pixel array. The pixel array may
77 be followed by other entities that are there to allow configuring binning,
78 skipping, scaling or digital crop, see :ref:`VIDIOC_SUBDEV_G_SELECTION
79 <VIDIOC_SUBDEV_G_SELECTION>`.
80
81 USB cameras etc. devices
82 ~~~~~~~~~~~~~~~~~~~~~~~~
83
84 USB video class hardware, as well as many cameras offering a similar higher
85 level interface natively, generally use the concept of frame interval (or frame
86 rate) on device level in firmware or hardware. This means lower level controls
87 implemented by raw cameras may not be used on uAPI (or even kAPI) to control the
88 frame interval on these devices.
89
90 Rotation, orientation and flipping
91 ----------------------------------
92
93 Some systems have the camera sensor mounted upside down compared to its natural
94 mounting rotation. In such cases, drivers shall expose the information to
95 userspace with the :ref:`V4L2_CID_CAMERA_SENSOR_ROTATION
96 <v4l2-camera-sensor-rotation>` control.
97
98 Sensor drivers shall also report the sensor's mounting orientation with the
99 :ref:`V4L2_CID_CAMERA_SENSOR_ORIENTATION <v4l2-camera-sensor-orientation>`.
100
101 Sensor drivers that have any vertical or horizontal flips embedded in the
102 register programming sequences shall initialize the :ref:`V4L2_CID_HFLIP
103 <v4l2-cid-hflip>` and :ref:`V4L2_CID_VFLIP <v4l2-cid-vflip>` controls with the
104 values programmed by the register sequences. The default values of these
105 controls shall be 0 (disabled). Especially these controls shall not be inverted,
106 independently of the sensor's mounting rotation.
107

3. 한국어 전문 번역

영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.

V4L2 sub-device 관행

1-12

이 문서는 V4L2 sub-device interface로 camera sensor driver를 제어할 때의 공통 관행을 설명합니다.

driver 구현 측면은 `media_writing_camera_sensor_drivers` 문서도 함께 참고할 수 있습니다.

.. SPDX-License-Identifier: GPL-2.0

.. _media_using_camera_sensor_drivers:

Using camera sensor drivers
===========================

This section describes common practices for how the V4L2 sub-device interface is
used to control the camera sensor drivers.

You may also find :ref:`media_writing_camera_sensor_drivers` useful.

Sensor internal pipeline 구성

13-41

camera sensor 내부에는 crop과 binning을 포함한 processing pipeline이 있습니다. 이 기능을 구성하는 방식에 따라 driver는 freely configurable과 register list-based 두 부류로 나뉩니다.

freely configurable driver는 내부 pipeline을 서로 다른 crop·scale 구성을 가진 하나 이상의 sub-device로 노출합니다. 최종 output size는 pixel array size에서 시작해 일련의 crop과 scaling을 적용한 결과입니다.

CCS driver가 freely configurable 방식의 예입니다.

register list-based driver는 사용자의 각 요청에 맞춰 독립적인 hardware parameter를 자유롭게 조합하지 못하고, 여러 parameter를 묶은 제한된 preset configuration 중 하나를 사용합니다.

driver는 device internal pipeline 끝의 source pad에 설정된 format을 기준으로 preset을 고릅니다. 대부분의 sensor driver가 이 방식으로 구현됩니다.

Sensor driver 구성 방식
Driver 유형구성 모델선택 방식
Freely configurablecrop·scale stage를 sub-device로 노출pixel array에서 단계별 구성
Register list-based미리 정의된 parameter 묶음마지막 source pad format으로 preset 선택

pipeline 자유도와 format 선택 지점을 비교합니다.

Freely configurable pipeline
Pixel array sizeAnalogue cropBinning 또는 skippingScaling 또는 digital cropSource pad output size

output size는 pixel array에 연속 변환을 적용한 결과입니다.

Sensor internal pipeline configuration
--------------------------------------

Camera sensors have an internal processing pipeline including cropping and
binning functionality. The sensor drivers belong to two distinct classes, freely
configurable and register list-based drivers, depending on how the driver
configures this functionality.

Freely configurable camera sensor drivers
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Freely configurable camera sensor drivers expose the device's internal
processing pipeline as one or more sub-devices with different cropping and
scaling configurations. The output size of the device is the result of a series
of cropping and scaling operations from the device's pixel array's size.

An example of such a driver is the CCS driver.

Register list-based drivers
~~~~~~~~~~~~~~~~~~~~~~~~~~~

Register list-based drivers generally, instead of able to configure the device
they control based on user requests, are limited to a number of preset
configurations that combine a number of different parameters that on hardware
level are independent. How a driver picks such configuration is based on the
format set on a source pad at the end of the device's internal pipeline.

Most sensor drivers are implemented this way.

Raw camera의 frame interval

42-80

frame interval의 가능한 값 조회와 설정에는 두 방식이 있으며 device 유형에 따라 구현 방식을 선택합니다.

raw camera sensor에서는 frame interval이 하나의 high-level parameter가 아니라 sensor 구현별 여러 parameter 조합의 결과입니다. 다행히 현대 raw sensor의 핵심 parameter는 대체로 같습니다.

계산식은 `frame interval = (analogue crop width + horizontal blanking) * (analogue crop height + vertical blanking) / pixel rate`입니다.

이 식은 bus와 무관하며 camera sensor를 넘어 raw timing parameter를 사용하는 다양한 device에 적용됩니다. analogue crop이 없는 device는 전체 source image, 즉 pixel array size를 사용합니다.

horizontal blanking은 `V4L2_CID_HBLANK`로 pixel 단위, vertical blanking은 `V4L2_CID_VBLANK`로 line 단위 지정합니다. sensor pixel array의 pixel rate는 같은 sub-device의 `V4L2_CID_PIXEL_RATE`이며 단위는 pixels per second입니다.

register list-based driver는 이 값을 제공할 read-only sub-device node를 구현해야 합니다. 그 밖의 device는 이 control들로 internal processing pipeline을 구성합니다.

linear pipeline의 첫 entity는 pixel array입니다. 뒤에 binning, skipping, scaling 또는 digital crop을 구성하는 entity가 올 수 있으며 selection은 `VIDIOC_SUBDEV_G_SELECTION`을 사용합니다.

Raw frame timing parameter
Parameter단위역할
Analogue crop widthpixels한 line의 active width
V4L2_CID_HBLANKpixelsline horizontal blanking
Analogue crop heightlinesactive frame height
V4L2_CID_VBLANKlinesframe vertical blanking
V4L2_CID_PIXEL_RATEpixels/secondpixel array clock rate

각 control의 단위와 수식 역할을 보존합니다.

Raw frame interval 계산
crop width + HBLANKcrop height + VBLANK두 값을 곱해 frame당 pixel clock 수 계산V4L2_CID_PIXEL_RATE로 나눔frame interval 산출

total line length와 frame height를 pixel rate로 나눕니다.

Frame interval configuration
----------------------------

There are two different methods for obtaining possibilities for different frame
intervals as well as configuring the frame interval. Which one to implement
depends on the type of the device.

Raw camera sensors
~~~~~~~~~~~~~~~~~~

Instead of a high level parameter such as frame interval, the frame interval is
a result of the configuration of a number of camera sensor implementation
specific parameters. Luckily, these parameters tend to be the same for more or
less all modern raw camera sensors.

The frame interval is calculated using the following equation::

	frame interval = (analogue crop width + horizontal blanking) *
			 (analogue crop height + vertical blanking) / pixel rate

The formula is bus independent and is applicable for raw timing parameters on
large variety of devices beyond camera sensors. Devices that have no analogue
crop, use the full source image size, i.e. pixel array size.

Horizontal and vertical blanking are specified by ``V4L2_CID_HBLANK`` and
``V4L2_CID_VBLANK``, respectively. The unit of the ``V4L2_CID_HBLANK`` control
is pixels and the unit of the ``V4L2_CID_VBLANK`` is lines. The pixel rate in
the sensor's **pixel array** is specified by ``V4L2_CID_PIXEL_RATE`` in the same
sub-device. The unit of that control is pixels per second.

Register list-based drivers need to implement read-only sub-device nodes for the
purpose. Devices that are not register list based need these to configure the
device's internal processing pipeline.

The first entity in the linear pipeline is the pixel array. The pixel array may
be followed by other entities that are there to allow configuring binning,
skipping, scaling or digital crop, see :ref:`VIDIOC_SUBDEV_G_SELECTION
<VIDIOC_SUBDEV_G_SELECTION>`.

USB camera 등의 frame interval

81-89

USB Video Class hardware와 비슷한 high-level interface를 자체 제공하는 camera는 firmware 또는 hardware device level에서 frame interval이나 frame rate 개념을 직접 사용합니다.

따라서 raw camera의 low-level timing control은 이런 device의 frame interval을 제어하는 uAPI나 kAPI에 사용되지 않을 수 있습니다.

Frame interval API 선택
항목설명
Raw sensorHBLANK·VBLANK·PIXEL_RATE 조합
USB/high-level camerafirmware 또는 hardware frame interval/rate

device가 raw timing을 노출하는지 high-level rate를 제공하는지에 따라 달라집니다.

USB cameras etc. devices
~~~~~~~~~~~~~~~~~~~~~~~~

USB video class hardware, as well as many cameras offering a similar higher
level interface natively, generally use the concept of frame interval (or frame
rate) on device level in firmware or hardware. This means lower level controls
implemented by raw cameras may not be used on uAPI (or even kAPI) to control the
frame interval on these devices.

Rotation, orientation과 flip

90-106

system에 camera sensor가 자연스러운 mounting rotation과 비교해 거꾸로 장착될 수 있습니다. driver는 `V4L2_CID_CAMERA_SENSOR_ROTATION` control로 이 회전 정보를 userspace에 노출해야 합니다.

sensor의 mounting orientation도 `V4L2_CID_CAMERA_SENSOR_ORIENTATION`으로 보고해야 합니다.

register programming sequence에 vertical 또는 horizontal flip이 포함된 driver는 실제로 programming한 값으로 `V4L2_CID_HFLIP`과 `V4L2_CID_VFLIP`을 초기화해야 합니다.

두 flip control의 default는 0(disabled)이어야 하며 sensor mounting rotation과 관계없이 control 의미를 반전해서는 안 됩니다.

Camera mounting control
항목설명
V4L2_CID_CAMERA_SENSOR_ROTATION자연스러운 자세 대비 mounting rotation
V4L2_CID_CAMERA_SENSOR_ORIENTATIONsensor mounting orientation
V4L2_CID_HFLIPregister sequence의 horizontal flip, default 0
V4L2_CID_VFLIPregister sequence의 vertical flip, default 0

물리 장착 정보와 pixel flip 상태를 별도로 보고합니다.

Mounting metadata와 flip
물리 mounting rotation 파악ROTATION·ORIENTATION control 보고register sequence의 H/V flip 값 확인HFLIP·VFLIP 초기값 설정mounting rotation 때문에 flip 의미를 invert하지 않음

장착 회전과 image flip control은 서로 독립적으로 해석합니다.

Rotation, orientation and flipping
----------------------------------

Some systems have the camera sensor mounted upside down compared to its natural
mounting rotation. In such cases, drivers shall expose the information to
userspace with the :ref:`V4L2_CID_CAMERA_SENSOR_ROTATION
<v4l2-camera-sensor-rotation>` control.

Sensor drivers shall also report the sensor's mounting orientation with the
:ref:`V4L2_CID_CAMERA_SENSOR_ORIENTATION <v4l2-camera-sensor-orientation>`.

Sensor drivers that have any vertical or horizontal flips embedded in the
register programming sequences shall initialize the :ref:`V4L2_CID_HFLIP
<v4l2-cid-hflip>` and :ref:`V4L2_CID_VFLIP <v4l2-cid-vflip>` controls with the
values programmed by the register sequences. The default values of these
controls shall be 0 (disabled). Especially these controls shall not be inverted,
independently of the sensor's mounting rotation.