了解Embededlinux的摄像头驱动问题

 一、摄像头平台层

drive     rs   \media\video\mxc\capture\mxc_v     4l   2_capture.c

module_init(camera_init);

随后,进行加载下一个驱动,如果遇到摄像头设备层对应驱动,举例adv7180解码芯片

drivers\media\video\mxc\capture\adv7180.c

module_init(adv7180_init);

sta     ti   c __init int adv7180_init(void)
{
u8 err =     i2c   _add_driver(&adv7180_i2c_driver);

return err;
}

sta  TI c struct i2c_driver adv7180_i2c_driver = {
.driver = {
.owner = THIS_MODULE,
.name = "adv7180",
},
.probe = adv7180_probe,
.remove = adv7180_detach,
.id_table = adv7180_id,
};

sta  TI c __init int camera_init(void)
{

u8 err = platform_driver_regis     te   r(&mxc_v4l2_driver);//将mxc_v4l2_driver这个驱动注册到platform平台上面,如果有匹配的设备的话,就会调用到mxc_v4l2_driver里面的probe函数
return err;
}

sta  TI c struct platform_driver mxc_v4l2_driver = {
.driver = {
.name = "mxc_v4l2_capture",
},
.probe = mxc_v4l2_probe,
.remove = mxc_v4l2_remove,
.suspend = mxc_v4l2_suspend,
.resume = mxc_v4l2_resume,
.shutdown = NULL,
};

/*

*struct platform_device {
*  const char * name;
*  int  id;
*  struct device dev;
*  u32  num_resources;
*  struct resource * resource;
*  const struct platform_device_id *id_entry;
*  struct mfd_cell *mfd_cell;
*  struct pdev_archdata archdata;
*};

*/

sta  TI c int mxc_v4l2_probe(struct platform_device *pdev)

{

...

cam_data *cam = kmalloc(sizeof(cam_data), GFP_KERNEL);

init_camera_struct(cam, pdev);//初始化cam_data结构体

v4l2_int_device_register(cam->self);

...

}

/*私有数据的结构体关系

*struct cam_data           drivers\media\video\mxc\capture\mxc_v4l2_capture.h
*->struct video_device       include\media\v4l2-dev.h
*   ->struct device      include\     linux   \device.h
*     ->struct device_private   drivers\base\base.h
*       ->void *driver_data;

*/

static void init_camera_struct(cam_data *cam, struct platform_device *pdev)

{

...

cam->video_dev = video_device_alloc();//分配一个video_device结构体

*(cam->video_dev) = mxc_v4l_template;//设置ops操作->v4l2_file_operations->mxc_v4l_ioctl->mxc_v4l_do_ioctl->VIDIOC_*_IOCTL:{...}

video_set_drvdata(cam->video_dev, cam);//将cam设置为cam->video_dev的私有数据->dev_set_drvdata -> dev->p->driver_data = data;

cam->crop_bounds.left = 0;           //这里只是初始化crop参数默认值

cam->crop_bounds.w     idt   h = 640;

cam->crop_bounds.top = 0;

cam->crop_bounds.height = 480;

cam->crop_current = cam->crop_defrect = cam->crop_bounds;

cam->enc_callback = camera_callback;

cam->self = kmalloc(sizeof(struct v4l2_int_device), GFP_KERNEL);

cam->self->module = THIS_MODULE;
cam->self->type = v4l2_int_type_master;
cam->self->u.master = &mxc_v4l2_master;//后面会调用

...

}

int v4l2_int_device_register(struct v4l2_int_device *d)
{
...
v4l2_int_device_try_attach_all();

...
}

void v4l2_int_device_try_attach_all(void)

{

struct v4l2_int_device *m, *s;

list_for_each_entry(m, &int_list, head)
{

if (m->type != v4l2_int_type_master) continue;//从int_list链表中取出type类型为v4l2_int_type_master的结构体保存在m中

list_for_each_entry(s, &int_list, head)
{

if (s->type != v4l2_int_type_slave)continue;//从int_list链表中取出type类型为v4l2_int_type_slave的结构体保存在s中

if (s->u.slave->master)continue;//如果存在s->u.slave->master则跳过继续寻找

s->u.slave->master = m;//找到master设备和第一个没有设置master的slave设备,并将从设备的master设置为找到的master

if (m->u.master->attach(s))//调用m的u.master->atach(s)函数,即cam->self->u.master = &mxc_v4l2_master;设置的函数

{

...

}

}

}

}

static struct v4l2_int_master mxc_v4l2_master = {
.attach = mxc_v4l2_master_attach,
.detach = mxc_v4l2_master_detach,
};

static int mxc_v4l2_master_attach(struct v4l2_int_device *slave)

{

...

cam->crop_bounds.top = cam->crop_bounds.left = 0;//crop参数都是根据slave结构体来设置的,这里是根据真正slave设备中获取到的参数来填充crop参数
cam->crop_bounds.width = cam_fmt.fmt.     pi   x.width;
cam->crop_bounds.height = cam_fmt.fmt.pix.height;

cam->crop_defrect.top = cam->crop_defrect.left = 0;
cam->crop_defrect.width = cam_fmt.fmt.pix.width;
cam->crop_defrect.height = cam_fmt.fmt.pix.height;

cam->crop_current.top = cam->crop_current.left = 0;
cam->crop_current.width = cam_fmt.fmt.pix.width;
cam->crop_current.height = cam_fmt.fmt.pix.height;

...

}



了解Embededlinux的摄像头驱动问题_设计制作_电源/新能源
12
36
0
74

相关资讯

  1. 1、共享单车,不过是中国资本的局中局3066
  2. 2、如何顺利开一场交互评审会?1433
  3. 3、杰夫·贝索斯:善良比聪明更难选择比天赋更重要2889
  4. 4、从交易模式看游戏陪玩平台的运行逻辑(二)3679
  5. 5、WebQQ,终将逝去的实验工厂3697
  6. 6、在腾讯实习三个月,你后悔吗3560
  7. 7、2次跳槽都涨薪50%的经历,给你点求职建议3451
  8. 8、这六个技巧,写产品简历一定要记牢!3203
  9. 9、泡泡玛特破圈思考:盲盒的价值体现1634
  10. 10、也许你做的活动,你可能自己都没有参加的欲望4192
全部评论(0)
我也有话说
0
收藏
点赞
顶部