手机自动对焦功能是通过将摄像头锁入音圈马达来实现的,音圈马达
简称(VCM),它主要有线圈,磁铁组和弹片构成,线圈通过上下两个弹片固定在磁铁组成,当给线圈通电时,线圈会产生磁场,线圈磁场和磁石组相互作用,线圈会向上移动,而锁在线圈里的摄像头便一起移动,当断电时,线圈在弹片弹力下返回,这样就实现了自动对焦功能。
这里重点是讲解一下关于高通平台camera的马达驱动,和驱动驱动一样,高通平台端的马达的入口函数也是
module_init();
module_init(msm_actuator_init_module);
msm_actuator_init_module()函数主要是实现了两个功能:一个是通过
platform_driver_register函数注册驱动
(
msm_actuator_platform_driver
),还有一个是将
msm_actuator_i2c_driver
挂载i2c总线上;
static struct platform_driver msm_actuator_platform_driver = {
.probe =
msm_actuator_platform_probe, //注册成功后就会调用这个探测函数(重要)
.driver = {
.name = "
qcom,
actuator",
.owner = THIS_MODULE,
.of_match_table =
msm_actuator_dt_match,
//通过设备树的compatible匹配资源,具体见下图
}
}
<span style="font-size:18px;color:#33cc00;">static int32_t msm_actuator_platform_probe(struct platform_device *pdev)
{
··············
rc = of_property_read_u32((&pdev->dev)->of_node, "cell-index",
&pdev->id); </span><span style="font-size:18px;color:#003333;">//获取设备资源信息</span><span style="font-size:18px;color:#33cc00;">
CDBG("cell-index %d, rc %d\n", pdev->id, rc);
if (rc < 0) {
kfree(msm_actuator_t);
pr_err("failed rc %d\n", rc);
return rc;
}</span>
<span style="color: rgb(51, 204, 0);font-size:18px; line-height: 1.5; font-family: 微软雅黑;"> /*初始化msm_actuator_t*/</span>
<span style="color: rgb(51, 204, 0);font-size:18px; line-height: 1.5; font-family: 微软雅黑;"> msm_actuator_t->act_v4l2_subdev_ops = &</span><span style="font-size:18px; line-height: 1.5; font-family: 微软雅黑;"><span style="color:#ff0000;">msm_actuator_subdev_ops</span></span><span style="color: rgb(51, 204, 0);font-size:18px; line-height: 1.5; font-family: 微软雅黑;">;</span>
<span style="color: rgb(51, 204, 0);font-size:18px; line-height: 1.5; font-family: 微软雅黑;"> msm_actuator_t->actuator_mutex = &msm_actuator_mutex; //互斥锁</span>