本为你主要讲解如何让摄像头ov13850支持自动对焦功能。摄像头的对角主要通过VCM马达驱动芯片DW9714来实现的。
一、环境
soc : rk3568
board: EVB1-DDR4-V10
软 件:Android 11
Linux:4.19.232
Camera:ov13850
二、DW9714
1.DW9714简介
DW9714专为自动对焦和光学变焦照相手机、数码相机和摄像机应用而设计,
由韩国动运国际有限公司(Dongwoon )设计生产。
工作电压可达3.6V。
DAC通过I2C串行接口控制,该接口以高达400kHz的时钟速率操作DAC。
DW9714集成了上电复位电路、掉电功能和精确匹配的检测电阻。
上电复位电路确保当电源上电时,DAC输出为0V,直到发生有效的写位值。它具有断电功能,可将器件的电流消耗降至最大1uA。
2. 特征
- 用于自动对焦的VCM驱动程序关机功能:XSD=低电平有效VCM的10位分辨率电流吸收为120mAI2C串行接口(可用于1.8V输入电平)集成电流检测电阻保证所有代码的单调性低至0.5uA(典型值)上电复位掉电功能2.3V至3.6V操作
3. 模块图
4. 引脚
序号 | Pin Name | I/O Description Note |
---|---|---|
1 | IOUT | Output current sink |
2 | VSS | 接地 |
3 | VDD | 供电 |
4 | SDA | I2C interface input (DATA) |
5 | SCL | I2C interface input/output (CLOCK) |
6 | XSD(1) | 关机模式,低有效 |
5. 参考电路
6. i2c时序
由以下时序可以看到,vcm9714利用I2C接口通信时,每次读/写,直接传输2个字节的数据,通信之前,不需要发送内部寄存器地址。
7. 寄存器格式
引脚 | 说明 |
---|---|
PD | Power down mode |
1: Power down mode (active high) | |
0: Normal operation mode | |
FLAG | 写操作时必须置为低 |
D[9:0] | Data input |
输出电流 = (D[9:0]/1023) X 120mA | |
最大电流 = 120mA +/- 5% | |
S[3:2] | Codes per step |
0: 0 (no SRC) – direct driving | |
1: 1 | |
2 :2 | |
3: 4 | |
S[1:0] | 步进周期 |
0: 81 | |
1: 162 | |
2: 324 | |
3: 648 |
三、驱动移植
vcm9714与rk3568连接图:
- 设备树:
@arch/arm64/boot/dts/rockchip/rk3568-evb1-ddr4-v10.dtsi
560 dw9714: dw9714@c {
561 compatible = "dongwoon,dw9714";
562 status = "okay";
563 reg = <0x0c>;
564 rockchip,camera-module-index = <0>;
565 rockchip,vcm-start-current = <10>;
566 rockchip,vcm-rated-current = <85>;
567 rockchip,vcm-step-mode = <5>;
568 rockchip,camera-module-facing = "back";
569 };
570
571 ov13850: ov13850@10 {
……
584 lens-focus = <&dw9714>;
……
591 };
其中,下面这两个属性,必须要和对应的的摄像头ov13850信息保持一致
rockchip,camera-module-index = <0>;
rockchip,camera-module-facing = "back";
摄像头支持的马达驱动信息通过以下属性关联
lens-focus = <&dw9714>;
- Makefile
@kerneldriversmediai2cMakefile
obj-$(CONFIG_VIDEO_DW9714) += dw9714.o
- Kconfig
@kerneldriversmediai2cKconfig
config VIDEO_DW9714
tristate "DW9714 lens voice coil support"
depends on I2C && VIDEO_V4L2 && MEDIA_CONTROLLER
depends on VIDEO_V4L2_SUBDEV_API
---help---
This is a driver for the DW9714 camera lens voice coil.
DW9714 is a 10 bit DAC with 120mA output current sink
capability. This is designed for linear control of
voice coil motors, controlled via I2C serial interface.
- 支持该驱动:
@ arch/arm64/configs/rockchip_defconfig
572 CONFIG_VIDEO_DW9714=y
- 驱动:
rk_android11.0_sdk_220718kerneldriversmediai2cdw9714.c
四、调试信息
1. 启动的驱动log
[ 0.800799] vm149c 4-000c: probing...
[ 0.800820] vm149c 4-000c: driver version: 00.01.00
[ 0.800834] vm149c 4-000c: could not get module rockchip,vcm-max-current from dts!
[ 0.800847] vm149c 4-000c: could not get module rockchip,vcm-start-current from dts!
[ 0.800860] vm149c 4-000c: could not get module rockchip,vcm-rated-current from dts!
[ 0.800872] vm149c 4-000c: could not get module rockchip,vcm-step-mode from dts!
[ 0.800907] vm149c 4-000c: probing successful
2. 查看拓扑结构
media-ctl -p
……………
- entity 74: m00_b_ov13850 4-0010 (1 pad, 1 link)
type V4L2 subdev subtype Sensor
device node name /dev/v4l-subdev4
pad0: Source
[fmt:SBGGR10/4224x3136]
-> "rockchip-csi2-dphy0":0 []
- entity 78: m00_b_gpio-flash (0 pad, 0 link)
type V4L2 subdev subtype Flash
device node name /dev/v4l-subdev5
- entity 79: m00_b_dw9714 4-000c (0 pad, 0 link)
type V4L2 subdev subtype Lens
device node name /dev/v4l-subdev6
五、驱动分析
vcm9714驱动比较简单,基于i2c总线,
核心就是要注册基于v4l2的subdev,
提供给用户层调用的核心回调函数如下:
- 获取并设置当前马达的pos
static const struct v4l2_ctrl_ops dw9714_vcm_ctrl_ops = {
.g_volatile_ctrl = dw9714_get_ctrl,
.s_ctrl = dw9714_set_ctrl,
};
static int dw9714_init_controls(struct dw9714_device *dev_vcm)
{
struct v4l2_ctrl_handler *hdl = &dev_vcm->ctrls_vcm;
const struct v4l2_ctrl_ops *ops = &dw9714_vcm_ctrl_ops;
v4l2_ctrl_handler_init(hdl, 1);
v4l2_ctrl_new_std(hdl, ops, V4L2_CID_FOCUS_ABSOLUTE,
0, VCMDRV_MAX_LOG, 1, VCMDRV_MAX_LOG);
……
}
static const struct v4l2_subdev_core_ops dw9714_core_ops = {
.ioctl = dw9714_ioctl,
};
static const struct v4l2_subdev_ops dw9714_ops = {
.core = &dw9714_core_ops,
};
static int dw9714_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
v4l2_i2c_subdev_init(&dw9714_dev->sd, client, &dw9714_ops);
}
所有camera原创文章已经汇总成pdf,