本為你主要講解如何讓攝像頭ov13850支持自動(dòng)對(duì)焦功能。攝像頭的對(duì)角主要通過(guò)VCM馬達(dá)驅(qū)動(dòng)芯片DW9714來(lái)實(shí)現(xiàn)的。
一、環(huán)境
soc??:?rk3568???
board:?EVB1-DDR4-V10
軟??件:Android?11
Linux:4.19.232
Camera:ov13850
二、DW9714
1.DW9714簡(jiǎn)介
DW9714專為自動(dòng)對(duì)焦和光學(xué)變焦照相手機(jī)、數(shù)碼相機(jī)和攝像機(jī)應(yīng)用而設(shè)計(jì),
由韓國(guó)動(dòng)運(yùn)國(guó)際有限公司(Dongwoon )設(shè)計(jì)生產(chǎn)。
工作電壓可達(dá)3.6V。
DAC通過(guò)I2C串行接口控制,該接口以高達(dá)400kHz的時(shí)鐘速率操作DAC。
DW9714集成了上電復(fù)位電路、掉電功能和精確匹配的檢測(cè)電阻。
上電復(fù)位電路確保當(dāng)電源上電時(shí),DAC輸出為0V,直到發(fā)生有效的寫位值。它具有斷電功能,可將器件的電流消耗降至最大1uA。
2. 特征
- 用于自動(dòng)對(duì)焦的VCM驅(qū)動(dòng)程序關(guān)機(jī)功能:XSD=低電平有效VCM的10位分辨率電流吸收為120mAI2C串行接口(可用于1.8V輸入電平)集成電流檢測(cè)電阻保證所有代碼的單調(diào)性低至0.5uA(典型值)上電復(fù)位掉電功能2.3V至3.6V操作
3. 模塊圖
4. 引腳
序號(hào) | 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) | 關(guān)機(jī)模式,低有效 |
5. 參考電路
6. i2c時(shí)序
由以下時(shí)序可以看到,vcm9714利用I2C接口通信時(shí),每次讀/寫,直接傳輸2個(gè)字節(jié)的數(shù)據(jù),通信之前,不需要發(fā)送內(nèi)部寄存器地址。
7. 寄存器格式
引腳 | 說(shuō)明 |
---|---|
PD | Power down mode |
1: Power down mode (active high) | |
0: Normal operation mode | |
FLAG | 寫操作時(shí)必須置為低 |
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] | 步進(jìn)周期 |
0: 81 | |
1: 162 | |
2: 324 | |
3: 648 |
三、驅(qū)動(dòng)移植
vcm9714與rk3568連接圖:
- 設(shè)備樹:
@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?????};
其中,下面這兩個(gè)屬性,必須要和對(duì)應(yīng)的的攝像頭ov13850信息保持一致
rockchip,camera-module-index?=?<0>;
rockchip,camera-module-facing?=?"back";
攝像頭支持的馬達(dá)驅(qū)動(dòng)信息通過(guò)以下屬性關(guān)聯(lián)
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.
- 支持該驅(qū)動(dòng):
@?arch/arm64/configs/rockchip_defconfig?
572?CONFIG_VIDEO_DW9714=y??
- 驅(qū)動(dòng):
rk_android11.0_sdk_220718kerneldriversmediai2cdw9714.c
四、調(diào)試信息
1. 啟動(dòng)的驅(qū)動(dòng)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. 查看拓?fù)浣Y(jié)構(gòu)
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
五、驅(qū)動(dòng)分析
vcm9714驅(qū)動(dòng)比較簡(jiǎn)單,基于i2c總線,
核心就是要注冊(cè)基于v4l2的subdev,
提供給用戶層調(diào)用的核心回調(diào)函數(shù)如下:
- 獲取并設(shè)置當(dāng)前馬達(dá)的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原創(chuàng)文章已經(jīng)匯總成pdf,