CGD Driver User Guide
CGD Driver User Guide
Revision <1.1>
ADAS VISION Page 1 of 18
AMCU_SW
ABSTRACT:
This is the Software User Guide Document for Generic Camera Driver for Linux OS.
KEYWORDS:
User Guide
APPROVED:
Revision History
VERSION DATE AUTHOR CHANGE DESCRIPTION
Table of Contents
Generic Camera Driver Software User Guide................................................................................ 1
1 Introduction ............................................................................................................................... 4
1.1 Purpose ................................................................................................................................ 4
1.2 Audience Description .......................................................................................................... 4
1.3 References ........................................................................................................................... 4
1.4 Definitions, Acronyms and Abbreviations .......................................................................... 4
1.5 Document Location ............................................................................................................. 5
2 General Description .................................................................................................................. 6
3 Functional Description.............................................................................................................. 7
3.1 Data types – generic ............................................................................................................ 7
3.2 Data types – camera specific ............................................................................................... 8
3.3 Kernel Space ....................................................................................................................... 9
3.4 User Space ......................................................................................................................... 11
4 High Level Design.................................................................................................................... 17
4.1 System Decomposition...................................................................................................... 17
4.2 File Structure ..................................................................................................................... 17
1 Introduction
The purpose of this document is to describe Generic camera driver. It is intended to serve as a
reference source during the development of VSDK based application.
1.1 Purpose
The purpose of this document is to define Generic camera driver internal behavior and user space
interface. It is intended to serve as a reference source during the driver implementation and future
use. For exact definitions and implementation details please check references and the source code.
1.3 References
Id Title Location
[1] Vision sdk git, folder:
SDI SW User Guide s32v234_sdk\docs\drivers
[2] S32v234 Reference Manual Available on demand
Table 1: References
Table 2: Acronyms
2 General Description
The cameras connected using MipiCsi (serial) or Viu (parallel) interfaces or intermediate HW like
serializer/deserilizer sets are being configured using I2C bus.
The aim of the Generic camera driver is to provide a user space level API for the commonly required
I2C functionality including device client management and register read/write access. It manage at
kernel level the I2C hardware.
On top of the I2C API the Generic camera driver also implements the specific configuration and
control for every type of camera supported by VSDK. Each type of camera has a specific set of
features and registers to be configured, which makes it impractical to create a common configuration
interface.
3 Functional Description
The Generic camera driver SW has 3 layers (see Figure 1). The first layer operates in kernel space
and implements the minimum required I2C device interaction. Internal behavior of the kernel space
layer will be described in detail in section 3.3.
The second layer is implemented as a user space abstraction layer for the low-level kernel driver API.
On top of the second layer a specific sensor device code is implemented. This third layer accomplishes
most of the driver functionality. Together the second and third layer are designated as Generic Camera
user library. The provided user level API is explained in section 3.4.
At the moment the following sensors are supported by the Generic camera driver:
• Sony IMX224MQV on MipiCsi-2,
• Omnivision Ov10640 VIU/MipiCsi-2,
• Omnivision Ov10635 camera connected to VIU interface,
• Maxim Serializer/Deserializer HW setup with 4 OV10640 cameras,
Omnivision Ov10640:
• Structure OV10640_Geometry:
Describes image geometry, frame frequency, exposure mode and embedded data configuration.
• Structure OV10640_Exposure:
Describes configuration of exposure control parameters.
• Enum OV10640_ExpTime:
Exposure type classified by duration.
• Structure OV10640_ChGain:
Channel gain configuration per channel.
Maxim serialiser/deserialiser:
• Enum MAXIM_CHNL:
Enumerates the channel indexes on the MAXIM serializer/deserializer board.
• Structure MAXIM_Cfg:
Describes Maxim HW setup configuration (CSI interface, sensor type, deserializer slots used).
Omnivision Ov10635:
• Structure OV10635_Geometry:
Describes image geometry, frame frequency, exposure mode and embedded data configuration.
• Structure OV10635_Exposure:
Describes configuration of exposure control parameters.
• Structure OV10635_ChGain:
Channel gain configuration per channel.
• Enum OV10635_ExpState:
Exposure status.
For Sony IMX224 the Generic camera driver module adds the functionality mentioned in Table 4.
Function; Ioctl Command Description
IOCTL_SONY_CONNECT Driver initialization. Sets-up MipiCsi2 port pins and
registers frame IRQ handler by calling the
SONY_DRV_Setup function.
IOCTL_SONY_DISCONNECT Unregisters the frame IRQ handler by calling the
SONY_DRV_Close function.
IOCTL_SONY_DRV_IrqHandler IRQ handler function to be registered with CSI driver
module.
For Ov10640 sensors the Generic camera driver module adds the functionality mentioned in Table 5.
Function; Ioctl Command Description
IOCTL_OV10640_CONNECT Driver initialization. Sets-up MipiCsi2 port pins and
registers frame IRQ handler by calling the
OV10640_DRV_Setup function.
IOCTL_OV10640_DISCONNECT Unregisters the frame IRQ handler by calling the
OV10640_DRV_Close function.
IOCTL_OV10640_DRV_IrqHandler IRQ handler function to be registered with CSI driver
module.
3.3.2 Usage
To register a new I2C device client CAM_DRV_ClientAdd() function has to be called providing
the sensor details in CamI2cCfg_t structure pointer. If not 0 CamI2cClient_t handle is
returned the function has succeeded. The returned handle is a kernel pointer to CamGeneric_t
structure retyped to uintptr_t. The camera structures are stored in a double-linked list inside the
kernel space part of the driver. The handles are used as a general identification of the camera devices
and are intended to be passed also to usespace.
To free a previously registered I2C device the CAM_DRV_ClientRem() function has to be invoked
providing the CamI2cClient_t handle as its parameter.
Any device specific configuration is supposed to be done from user space part of the driver by
invoking I2C transaction using one of the Read/Write functions or related IOCTL commands.
To implement functionality that requires to be executed in kernel space, e.g. handling of frame
start/end IRQ of the CSI HW to implement exposure control, list of IOCTL commands of the generic
camera driver is supposed to be extended. The extension should include the *CONNECT and
*DISCONNECT commands for the particular device as can be seen in the Sony IMX224 case.
3.4.1 API
Generic camera driver user level API mentioned in Table 6 is declared in isp_cam_generic.h
and defined in cam_user.cpp file.
Function Description
CAM_Open Opens “cam” special device file on Linux or calls
CAM_DRV_Setup in case of standalone environment.
CAM_Close Closes “cam” special device file on Linux or calls
CSI_DRV_Close in case of standalone environment.
CAM_ClientAdd Adds a device client for particular I2C bus and address.
CAM_ClientRem Removes given device client.
CAM_ReadBatch Executes batch of I2C read commands.
CAM_WriteBatch Executes batch of I2C write commands.
CAM_ReadSingle Reads a single register value over I2C.
CAM_WriteSingle Writes a single register value over I2C.
Besides the generic API, which can be used for all specific sensor device (Table 6), the Generic
camera user library contains also code, which is specific for each VSDK supported camera device.
Table 7 mentions functions that should be available for each support sensor but internally can
implementation differences. All function calls mentioned in the following table must be preceded
with prefix of the particular sensor. E.g. “SONY_”.
Function Description
Open Enables HW interaction (I2C client) and sets up internal structures.
Close Releases all resources including I2C client, reset of internal structures.
RegWrite Writes a value over I2C to Sony camera register.
For Sony IMX224 sensor isp_cam_sony.h and cam_sony.cpp files have been added to the
Generic camera library introducing API mentioned in Table 8. All function calls mentioned in the
following table are preceded with “SONY_” prefix.
Function Description
RegConfig Performs initial sensor setup over I2C.
ExposureStatusG Checks current status of exposure control state machine.
et
CsiEnable Enables CSI transmission from Sony camera.
CsiDisable Disables CSI transmission from Sony camera.
ConvGet Reads current setup of the conversion gain.
ConvLowSet Sets the conversion gain to low.
ConvHighSet Sets the conversion gain to high.
ExpLinesGet Reads current setup of the exposure line count.
ExpLinesSGet Reads current setup of the short exposure line count.
ExpLinesSet Sets up the exposure line count.
GainGet Reads current setup of the analog gain.
GainSet Sets up the analog gain value.
ExposureGet Returns current setup of the exposure parameters from the sensor. Has two
parameter SONY_IDX and SONY_Exposure_t*.
ExposureSet Applies provided setup of the exposure parameters to the sensor. Has two
parameter SONY_IDX and SONY_Exposure_t*.
ObWvGet Gets the number of optical black lines per frame.
ObWvSet Sets the number of optical blacklines per frame.
SyncGet Gets the sync mode of the camera (Master or Slave).
SyncSet Sets the sync mode of the camera (Master or Slave). Has to match HW
config.
VmaxGet Gets the maximum number of lines per frame.
VmaxSet Sets the maximum number of lines per frame.
HmaxGet Gets the maximum number of columns per frame.
HmaxSet Sets the maximum number of columns per frame.
CropWvGet Gets the crop window number of lines per frame.
Table 8: Camera generic user library API specific for SONY IMX224 sensor
For Maxim Serializer/Deserialzier setup the Generic camera user-space library adds the
functionality mentioned in Table 9. All function calls mentioned in the following table are preceded
with “MAXIM_” prefix.
Function Description
Open Enables HW interaction (I2C client) and setups internal structures. Has
one parameter MAXIM_Cfg_t*.
Close Release of all resources including I2C client, reset of internal structures.
Has one parameter MAXIM_Cfg_t*.
CsiEnable Starts the data receive for the specified virtual channel.
CsiDisable Stops the data receive for the specified virtual channel.
OV10640_InitComp Performs initial Ser/Des and Ov10640 sensor setup over I2C. Includes
lex assignment of unique I2C addresses for serializers and sensors on each of
4 deserializer channels.
OV10640_InitSimp Performs initial Ser/Des and Ov10640 sensor setup over I2C. Serializers
le and sensors on each of 4 deserializer channels are accessible only in
broadcasting mode.
OV10640_Exposure Configures Exposure parameters to the OV10640 cameras. Exposure
Set config is shared among the cameras.
OV10635_InitComp Performs initial Ser/Des and Ov10635 sensor setup over I2C. Includes
lex assignment of unique I2C addresses for serializers and sensors on each of
4 deserializer channels.
SONY_InitComplex Performs initial Ser/Des and Sony sensor setup over I2C. Includes
assignment of unique I2C addresses for serializers and sensors on each of
4 deserializer channels.
CAM_RegWrite Writes a value over I2C to Maxim connected camera register.
CAM_RegRead Reads a value over I2C from Maxim connected camera register.
SER_RegWrite Writes a value over I2C to Maxim connected serializer register.
SER_RegRead Reads a value over I2C from Maxim connected serializer register.
DES_RegWrite Writes a value over I2C to Maxim connected deserializer register.
DES_RegRead Reads a value over I2C from Maxim connected deserializer register.
Table 9: Generic camera user library API specific for MAXIM sensor Ser/Des setup
For Omnivision Ov10635 sensor with parallel interface the Generic camera user-space library adds
the functionality mentioned in Table 10. All function calls mentioned in the following table are
preceded with “OV10635_” prefix.
Function; Ioctl Command Description
Open Enables HW interaction (I2C client) and setups internal structures.
Has one parameter VIU_IDX.
Close Release of all resources including I2C client, reset of internal
structures. Has one parameter VIU_IDX.
RegConfig Performs initial sensor setup over I2C.
DataEnable Enables VIU transmission from camera.
DataDisable Disables VIU transmission from camera.
Table 10: Generic camera user library for Omnivision Ov10635 sensor
For Omnivision Ov10640 sensor with MipiCsi2 of parallel interface the Generic camera user-space
library adds the functionality mentioned in
RegWrite Writes a value over I2C to Ov10640 camera register.
ExposureAllExpSet Sets the exposures parameters (time and gains) for the
desired exposure type.
ExposureTotal Computes all the exposure parameters for the desired
exposure type.
ExposureComputationInd Computes the Exposure parameters for all the 3 exposure
types.
RegWrite Writes a value over I2C to Ov10640 camera register.
RegRead Reads a value over I2C from Ov10640 camera register.
Table 11: Generic camera user library API for Omnivision Ov10640 sensor